1/*
2 * Synchronous PPP/Cisco/Frame Relay link level subroutines.
3 * Keepalive protocol implemented in both Cisco and PPP modes.
4 */
5/*-
6 * Copyright (C) 1994-2000 Cronyx Engineering.
7 * Author: Serge Vakulenko, <vak@cronyx.ru>
8 *
--- 4 unchanged lines hidden (view full) ---
13 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 *
15 * Authors grant any other persons or organisations permission to use
16 * or modify this software as long as this message is kept with the software,
17 * all derivative works or modified versions.
18 *
19 * From: Version 2.4, Thu Apr 30 17:17:21 MSD 1997
20 *
21 * $FreeBSD: head/sys/net/if_spppsubr.c 241394 2012-10-10 08:36:38Z kevlo $
22 */
23
24#include <sys/param.h>
25
26#include "opt_inet.h"
27#include "opt_inet6.h"
28#include "opt_ipx.h"
29
--- 756 unchanged lines hidden (view full) ---
786 */
787static int
788sppp_output(struct ifnet *ifp, struct mbuf *m,
789 struct sockaddr *dst, struct route *ro)
790{
791 struct sppp *sp = IFP2SP(ifp);
792 struct ppp_header *h;
793 struct ifqueue *ifq = NULL;
794 int s, error, rv = 0;
795#ifdef INET
796 int ipproto = PPP_IP;
797#endif
798 int debug = ifp->if_flags & IFF_DEBUG;
799
800 s = splimp();
801 SPPP_LOCK(sp);
802
803 if (!(ifp->if_flags & IFF_UP) ||
804 (!(ifp->if_flags & IFF_AUTO) &&
805 !(ifp->if_drv_flags & IFF_DRV_RUNNING))) {
806#ifdef INET6
807 drop:
808#endif
809 m_freem (m);
810 SPPP_UNLOCK(sp);
811 splx (s);
812 return (ENETDOWN);
813 }
814
815 if ((ifp->if_flags & IFF_AUTO) &&
816 !(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
817#ifdef INET6
818 /*
819 * XXX
--- 7 unchanged lines hidden (view full) ---
827 !(sp->confflags & CONF_ENABLE_IPV6))
828 goto drop;
829#endif
830 /*
831 * Interface is not yet running, but auto-dial. Need
832 * to start LCP for it.
833 */
834 ifp->if_drv_flags |= IFF_DRV_RUNNING;
835 splx(s);
836 lcp.Open(sp);
837 s = splimp();
838 }
839
840#ifdef INET
841 if (dst->sa_family == AF_INET) {
842 /* XXX Check mbuf length here? */
843 struct ip *ip = mtod (m, struct ip*);
844 struct tcphdr *tcp = (struct tcphdr*) ((long*)ip + ip->ip_hl);
845
--- 7 unchanged lines hidden (view full) ---
853 * - don't let packets with src ip addr 0 thru
854 * - we flag TCP packets with src ip 0 as an error
855 */
856
857 if(ip->ip_src.s_addr == INADDR_ANY) /* -hm */
858 {
859 m_freem(m);
860 SPPP_UNLOCK(sp);
861 splx(s);
862 if(ip->ip_p == IPPROTO_TCP)
863 return(EADDRNOTAVAIL);
864 else
865 return(0);
866 }
867
868 /*
869 * Put low delay, telnet, rlogin and ftp control packets
--- 28 unchanged lines hidden (view full) ---
898 ipproto = PPP_VJ_UCOMP;
899 break;
900 case TYPE_IP:
901 ipproto = PPP_IP;
902 break;
903 default:
904 m_freem(m);
905 SPPP_UNLOCK(sp);
906 splx(s);
907 return (EINVAL);
908 }
909 }
910#endif
911
912#ifdef INET6
913 if (dst->sa_family == AF_INET6) {
914 /* XXX do something tricky here? */
--- 13 unchanged lines hidden (view full) ---
928 */
929 M_PREPEND (m, PPP_HEADER_LEN, M_DONTWAIT);
930 if (! m) {
931nobufs: if (debug)
932 log(LOG_DEBUG, SPP_FMT "no memory for transmit header\n",
933 SPP_ARGS(ifp));
934 ++ifp->if_oerrors;
935 SPPP_UNLOCK(sp);
936 splx (s);
937 return (ENOBUFS);
938 }
939 /*
940 * May want to check size of packet
941 * (albeit due to the implementation it's always enough)
942 */
943 h = mtod (m, struct ppp_header*);
944 if (sp->pp_mode == IFF_CISCO) {
--- 50 unchanged lines hidden (view full) ---
995 h->protocol = htons (sp->pp_mode == IFF_CISCO ?
996 ETHERTYPE_IPX : PPP_IPX);
997 break;
998#endif
999 default:
1000 m_freem (m);
1001 ++ifp->if_oerrors;
1002 SPPP_UNLOCK(sp);
1003 splx (s);
1004 return (EAFNOSUPPORT);
1005 }
1006
1007 /*
1008 * Queue message on interface, and start output if interface
1009 * not yet active.
1010 */
1011out:
1012 if (ifq != NULL)
1013 error = !(IF_HANDOFF_ADJ(ifq, m, ifp, 3));
1014 else
1015 IFQ_HANDOFF_ADJ(ifp, m, 3, error);
1016 if (error) {
1017 ++ifp->if_oerrors;
1018 SPPP_UNLOCK(sp);
1019 splx (s);
1020 return (rv? rv: ENOBUFS);
1021 }
1022 SPPP_UNLOCK(sp);
1023 splx (s);
1024 /*
1025 * Unlike in sppp_input(), we can always bump the timestamp
1026 * here since sppp_output() is only called on behalf of
1027 * network-layer traffic; control-layer traffic is handled
1028 * by sppp_cp_send().
1029 */
1030 sp->pp_last_sent = time_uptime;
1031 return (0);
--- 100 unchanged lines hidden (view full) ---
1132
1133/*
1134 * Check if the output queue is empty.
1135 */
1136int
1137sppp_isempty(struct ifnet *ifp)
1138{
1139 struct sppp *sp = IFP2SP(ifp);
1140 int empty, s;
1141
1142 s = splimp();
1143 SPPP_LOCK(sp);
1144 empty = !sp->pp_fastq.ifq_head && !sp->pp_cpq.ifq_head &&
1145 !SP2IFP(sp)->if_snd.ifq_head;
1146 SPPP_UNLOCK(sp);
1147 splx(s);
1148 return (empty);
1149}
1150
1151/*
1152 * Get next packet to send.
1153 */
1154struct mbuf *
1155sppp_dequeue(struct ifnet *ifp)
1156{
1157 struct sppp *sp = IFP2SP(ifp);
1158 struct mbuf *m;
1159 int s;
1160
1161 s = splimp();
1162 SPPP_LOCK(sp);
1163 /*
1164 * Process only the control protocol queue until we have at
1165 * least one NCP open.
1166 *
1167 * Do always serve all three queues in Cisco mode.
1168 */
1169 IF_DEQUEUE(&sp->pp_cpq, m);
1170 if (m == NULL &&
1171 (sppp_ncp_check(sp) || sp->pp_mode == IFF_CISCO ||
1172 sp->pp_mode == PP_FR)) {
1173 IF_DEQUEUE(&sp->pp_fastq, m);
1174 if (m == NULL)
1175 IF_DEQUEUE (&SP2IFP(sp)->if_snd, m);
1176 }
1177 SPPP_UNLOCK(sp);
1178 splx(s);
1179 return m;
1180}
1181
1182/*
1183 * Pick the next packet, do not remove it from the queue.
1184 */
1185struct mbuf *
1186sppp_pick(struct ifnet *ifp)
1187{
1188 struct sppp *sp = IFP2SP(ifp);
1189 struct mbuf *m;
1190 int s;
1191
1192 s = splimp ();
1193 SPPP_LOCK(sp);
1194
1195 m = sp->pp_cpq.ifq_head;
1196 if (m == NULL &&
1197 (sp->pp_phase == PHASE_NETWORK ||
1198 sp->pp_mode == IFF_CISCO ||
1199 sp->pp_mode == PP_FR))
1200 if ((m = sp->pp_fastq.ifq_head) == NULL)
1201 m = SP2IFP(sp)->if_snd.ifq_head;
1202 SPPP_UNLOCK(sp);
1203 splx (s);
1204 return (m);
1205}
1206
1207/*
1208 * Process an ioctl request. Called on low priority level.
1209 */
1210int
1211sppp_ioctl(struct ifnet *ifp, IOCTL_CMD_T cmd, void *data)
1212{
1213 struct ifreq *ifr = (struct ifreq*) data;
1214 struct sppp *sp = IFP2SP(ifp);
1215 int s, rv, going_up, going_down, newmode;
1216
1217 s = splimp();
1218 SPPP_LOCK(sp);
1219 rv = 0;
1220 switch (cmd) {
1221 case SIOCAIFADDR:
1222 case SIOCSIFDSTADDR:
1223 break;
1224
1225 case SIOCSIFADDR:
--- 89 unchanged lines hidden (view full) ---
1315 case SIOCSIFGENERIC:
1316 rv = sppp_params(sp, cmd, data);
1317 break;
1318
1319 default:
1320 rv = ENOTTY;
1321 }
1322 SPPP_UNLOCK(sp);
1323 splx(s);
1324 return rv;
1325}
1326
1327/*
1328 * Cisco framing implementation.
1329 */
1330
1331/*
--- 733 unchanged lines hidden (view full) ---
2065 break;
2066 }
2067}
2068
2069static void
2070sppp_to_event(const struct cp *cp, struct sppp *sp)
2071{
2072 STDDCL;
2073 int s;
2074
2075 s = splimp();
2076 SPPP_LOCK(sp);
2077 if (debug)
2078 log(LOG_DEBUG, SPP_FMT "%s TO(%s) rst_counter = %d\n",
2079 SPP_ARGS(ifp), cp->name,
2080 sppp_state_name(sp->state[cp->protoidx]),
2081 sp->rst_counter[cp->protoidx]);
2082
2083 if (--sp->rst_counter[cp->protoidx] < 0)
--- 33 unchanged lines hidden (view full) ---
2117 case STATE_ACK_SENT:
2118 (cp->scr)(sp);
2119 callout_reset(&sp->ch[cp->protoidx], sp->lcp.timeout,
2120 cp->TO, (void *)sp);
2121 break;
2122 }
2123
2124 SPPP_UNLOCK(sp);
2125 splx(s);
2126}
2127
2128/*
2129 * Change the state of a control protocol in the state automaton.
2130 * Takes care of starting/stopping the restart timer.
2131 */
2132static void
2133sppp_cp_change_state(const struct cp *cp, struct sppp *sp, int newstate)
--- 1886 unchanged lines hidden (view full) ---
4020/*
4021 * Handle incoming CHAP packets.
4022 */
4023static void
4024sppp_chap_input(struct sppp *sp, struct mbuf *m)
4025{
4026 STDDCL;
4027 struct lcp_header *h;
4028 int len, x;
4029 u_char *value, *name, digest[AUTHKEYLEN], dsize;
4030 int value_len, name_len;
4031 MD5_CTX ctx;
4032
4033 len = m->m_pkthdr.len;
4034 if (len < 4) {
4035 if (debug)
4036 log(LOG_DEBUG,
--- 60 unchanged lines hidden (view full) ---
4097 log(LOG_DEBUG, SPP_FMT "chap success",
4098 SPP_ARGS(ifp));
4099 if (len > 4) {
4100 log(-1, ": ");
4101 sppp_print_string((char*)(h + 1), len - 4);
4102 }
4103 log(-1, "\n");
4104 }
4105 x = splimp();
4106 SPPP_LOCK(sp);
4107 sp->pp_flags &= ~PP_NEEDAUTH;
4108 if (sp->myauth.proto == PPP_CHAP &&
4109 (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) &&
4110 (sp->lcp.protos & (1 << IDX_CHAP)) == 0) {
4111 /*
4112 * We are authenticator for CHAP but didn't
4113 * complete yet. Leave it to tlu to proceed
4114 * to network phase.
4115 */
4116 SPPP_UNLOCK(sp);
4117 splx(x);
4118 break;
4119 }
4120 SPPP_UNLOCK(sp);
4121 splx(x);
4122 sppp_phase_network(sp);
4123 break;
4124
4125 case CHAP_FAILURE:
4126 if (debug) {
4127 log(LOG_INFO, SPP_FMT "chap failure",
4128 SPP_ARGS(ifp));
4129 if (len > 4) {
--- 145 unchanged lines hidden (view full) ---
4275 sppp_cp_change_state(&chap, sp, STATE_CLOSED);
4276}
4277
4278static void
4279sppp_chap_TO(void *cookie)
4280{
4281 struct sppp *sp = (struct sppp *)cookie;
4282 STDDCL;
4283 int s;
4284
4285 s = splimp();
4286 SPPP_LOCK(sp);
4287 if (debug)
4288 log(LOG_DEBUG, SPP_FMT "chap TO(%s) rst_counter = %d\n",
4289 SPP_ARGS(ifp),
4290 sppp_state_name(sp->state[IDX_CHAP]),
4291 sp->rst_counter[IDX_CHAP]);
4292
4293 if (--sp->rst_counter[IDX_CHAP] < 0)
--- 14 unchanged lines hidden (view full) ---
4308 case STATE_REQ_SENT:
4309 chap.scr(sp);
4310 /* sppp_cp_change_state() will restart the timer */
4311 sppp_cp_change_state(&chap, sp, STATE_REQ_SENT);
4312 break;
4313 }
4314
4315 SPPP_UNLOCK(sp);
4316 splx(s);
4317}
4318
4319static void
4320sppp_chap_tlu(struct sppp *sp)
4321{
4322 STDDCL;
4323 int i, x;
4324
4325 i = 0;
4326 sp->rst_counter[IDX_CHAP] = sp->lcp.max_configure;
4327
4328 /*
4329 * Some broken CHAP implementations (Conware CoNet, firmware
4330 * 4.0.?) don't want to re-authenticate their CHAP once the
4331 * initial challenge-response exchange has taken place.
--- 14 unchanged lines hidden (view full) ---
4346 SPP_ARGS(ifp),
4347 sp->pp_phase == PHASE_NETWORK? "reconfirmed": "tlu");
4348 if ((sp->hisauth.flags & AUTHFLAG_NORECHALLENGE) == 0)
4349 log(-1, "next re-challenge in %d seconds\n", i);
4350 else
4351 log(-1, "re-challenging supressed\n");
4352 }
4353
4354 x = splimp();
4355 SPPP_LOCK(sp);
4356 /* indicate to LCP that we need to be closed down */
4357 sp->lcp.protos |= (1 << IDX_CHAP);
4358
4359 if (sp->pp_flags & PP_NEEDAUTH) {
4360 /*
4361 * Remote is authenticator, but his auth proto didn't
4362 * complete yet. Defer the transition to network
4363 * phase.
4364 */
4365 SPPP_UNLOCK(sp);
4366 splx(x);
4367 return;
4368 }
4369 SPPP_UNLOCK(sp);
4370 splx(x);
4371
4372 /*
4373 * If we are already in phase network, we are done here. This
4374 * is the case if this is a dummy tlu event after a re-challenge.
4375 */
4376 if (sp->pp_phase != PHASE_NETWORK)
4377 sppp_phase_network(sp);
4378}
--- 52 unchanged lines hidden (view full) ---
4431
4432/*
4433 * Handle incoming PAP packets. */
4434static void
4435sppp_pap_input(struct sppp *sp, struct mbuf *m)
4436{
4437 STDDCL;
4438 struct lcp_header *h;
4439 int len, x;
4440 u_char *name, *passwd, mlen;
4441 int name_len, passwd_len;
4442
4443 len = m->m_pkthdr.len;
4444 if (len < 5) {
4445 if (debug)
4446 log(LOG_DEBUG,
4447 SPP_FMT "pap invalid packet length: %d bytes\n",
--- 70 unchanged lines hidden (view full) ---
4518 SPP_ARGS(ifp));
4519 name_len = *((char *)h);
4520 if (len > 5 && name_len) {
4521 log(-1, ": ");
4522 sppp_print_string((char*)(h+1), name_len);
4523 }
4524 log(-1, "\n");
4525 }
4526 x = splimp();
4527 SPPP_LOCK(sp);
4528 sp->pp_flags &= ~PP_NEEDAUTH;
4529 if (sp->myauth.proto == PPP_PAP &&
4530 (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) &&
4531 (sp->lcp.protos & (1 << IDX_PAP)) == 0) {
4532 /*
4533 * We are authenticator for PAP but didn't
4534 * complete yet. Leave it to tlu to proceed
4535 * to network phase.
4536 */
4537 SPPP_UNLOCK(sp);
4538 splx(x);
4539 break;
4540 }
4541 SPPP_UNLOCK(sp);
4542 splx(x);
4543 sppp_phase_network(sp);
4544 break;
4545
4546 case PAP_NAK:
4547 callout_stop (&sp->pap_my_to_ch);
4548 if (debug) {
4549 log(LOG_INFO, SPP_FMT "pap failure",
4550 SPP_ARGS(ifp));
--- 64 unchanged lines hidden (view full) ---
4615 * That's the timeout routine if we are authenticator. Since the
4616 * authenticator is basically passive in PAP, we can't do much here.
4617 */
4618static void
4619sppp_pap_TO(void *cookie)
4620{
4621 struct sppp *sp = (struct sppp *)cookie;
4622 STDDCL;
4623 int s;
4624
4625 s = splimp();
4626 SPPP_LOCK(sp);
4627 if (debug)
4628 log(LOG_DEBUG, SPP_FMT "pap TO(%s) rst_counter = %d\n",
4629 SPP_ARGS(ifp),
4630 sppp_state_name(sp->state[IDX_PAP]),
4631 sp->rst_counter[IDX_PAP]);
4632
4633 if (--sp->rst_counter[IDX_PAP] < 0)
--- 9 unchanged lines hidden (view full) ---
4643 switch (sp->state[IDX_PAP]) {
4644 case STATE_REQ_SENT:
4645 /* sppp_cp_change_state() will restart the timer */
4646 sppp_cp_change_state(&pap, sp, STATE_REQ_SENT);
4647 break;
4648 }
4649
4650 SPPP_UNLOCK(sp);
4651 splx(s);
4652}
4653
4654/*
4655 * That's the timeout handler if we are peer. Since the peer is active,
4656 * we need to retransmit our PAP request since it is apparently lost.
4657 * XXX We should impose a max counter.
4658 */
4659static void
--- 10 unchanged lines hidden (view full) ---
4670 pap.scr(sp);
4671 SPPP_UNLOCK(sp);
4672}
4673
4674static void
4675sppp_pap_tlu(struct sppp *sp)
4676{
4677 STDDCL;
4678 int x;
4679
4680 sp->rst_counter[IDX_PAP] = sp->lcp.max_configure;
4681
4682 if (debug)
4683 log(LOG_DEBUG, SPP_FMT "%s tlu\n",
4684 SPP_ARGS(ifp), pap.name);
4685
4686 x = splimp();
4687 SPPP_LOCK(sp);
4688 /* indicate to LCP that we need to be closed down */
4689 sp->lcp.protos |= (1 << IDX_PAP);
4690
4691 if (sp->pp_flags & PP_NEEDAUTH) {
4692 /*
4693 * Remote is authenticator, but his auth proto didn't
4694 * complete yet. Defer the transition to network
4695 * phase.
4696 */
4697 SPPP_UNLOCK(sp);
4698 splx(x);
4699 return;
4700 }
4701 SPPP_UNLOCK(sp);
4702 splx(x);
4703 sppp_phase_network(sp);
4704}
4705
4706static void
4707sppp_pap_tld(struct sppp *sp)
4708{
4709 STDDCL;
4710
--- 121 unchanged lines hidden (view full) ---
4832/*
4833 * Send keepalive packets, every 10 seconds.
4834 */
4835static void
4836sppp_keepalive(void *dummy)
4837{
4838 struct sppp *sp = (struct sppp*)dummy;
4839 struct ifnet *ifp = SP2IFP(sp);
4840 int s;
4841
4842 s = splimp();
4843 SPPP_LOCK(sp);
4844 /* Keepalive mode disabled or channel down? */
4845 if (! (sp->pp_flags & PP_KEEPALIVE) ||
4846 ! (ifp->if_drv_flags & IFF_DRV_RUNNING))
4847 goto out;
4848
4849 if (sp->pp_mode == PP_FR) {
4850 sppp_fr_keepalive (sp);
--- 26 unchanged lines hidden (view full) ---
4877 else if (sp->pp_phase >= PHASE_AUTHENTICATE) {
4878 long nmagic = htonl (sp->lcp.magic);
4879 sp->lcp.echoid = ++sp->pp_seq[IDX_LCP];
4880 sppp_cp_send (sp, PPP_LCP, ECHO_REQ,
4881 sp->lcp.echoid, 4, &nmagic);
4882 }
4883out:
4884 SPPP_UNLOCK(sp);
4885 splx(s);
4886 callout_reset(&sp->keepalive_callout, hz * 10, sppp_keepalive,
4887 (void *)sp);
4888}
4889
4890/*
4891 * Get both IP addresses.
4892 */
4893void
--- 33 unchanged lines hidden (view full) ---
4927 if_addr_runlock(ifp);
4928
4929 if (dst) *dst = ntohl(ddst);
4930 if (src) *src = ntohl(ssrc);
4931}
4932
4933#ifdef INET
4934/*
4935 * Set my IP address. Must be called at splimp.
4936 */
4937static void
4938sppp_set_ip_addr(struct sppp *sp, u_long src)
4939{
4940 STDDCL;
4941 struct ifaddr *ifa;
4942 struct sockaddr_in *si;
4943 struct in_ifaddr *ia;
--- 100 unchanged lines hidden (view full) ---
5044 */
5045static void
5046sppp_gen_ip6_addr(struct sppp *sp, struct in6_addr *addr)
5047{
5048 /* TBD */
5049}
5050
5051/*
5052 * Set my IPv6 address. Must be called at splimp.
5053 */
5054static void
5055sppp_set_ip6_addr(struct sppp *sp, const struct in6_addr *src)
5056{
5057 STDDCL;
5058 struct ifaddr *ifa;
5059 struct sockaddr_in6 *sin6;
5060
--- 431 unchanged lines hidden ---
2 * Synchronous PPP/Cisco/Frame Relay link level subroutines.
3 * Keepalive protocol implemented in both Cisco and PPP modes.
4 */
5/*-
6 * Copyright (C) 1994-2000 Cronyx Engineering.
7 * Author: Serge Vakulenko, <vak@cronyx.ru>
8 *
--- 4 unchanged lines hidden (view full) ---
13 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 *
15 * Authors grant any other persons or organisations permission to use
16 * or modify this software as long as this message is kept with the software,
17 * all derivative works or modified versions.
18 *
19 * From: Version 2.4, Thu Apr 30 17:17:21 MSD 1997
20 *
21 * $FreeBSD: head/sys/net/if_spppsubr.c 241394 2012-10-10 08:36:38Z kevlo $
22 */
23
24#include <sys/param.h>
25
26#include "opt_inet.h"
27#include "opt_inet6.h"
28#include "opt_ipx.h"
29
--- 756 unchanged lines hidden (view full) ---
786 */
787static int
788sppp_output(struct ifnet *ifp, struct mbuf *m,
789 struct sockaddr *dst, struct route *ro)
790{
791 struct sppp *sp = IFP2SP(ifp);
792 struct ppp_header *h;
793 struct ifqueue *ifq = NULL;
794 int s, error, rv = 0;
795#ifdef INET
796 int ipproto = PPP_IP;
797#endif
798 int debug = ifp->if_flags & IFF_DEBUG;
799
800 s = splimp();
801 SPPP_LOCK(sp);
802
803 if (!(ifp->if_flags & IFF_UP) ||
804 (!(ifp->if_flags & IFF_AUTO) &&
805 !(ifp->if_drv_flags & IFF_DRV_RUNNING))) {
806#ifdef INET6
807 drop:
808#endif
809 m_freem (m);
810 SPPP_UNLOCK(sp);
811 splx (s);
812 return (ENETDOWN);
813 }
814
815 if ((ifp->if_flags & IFF_AUTO) &&
816 !(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
817#ifdef INET6
818 /*
819 * XXX
--- 7 unchanged lines hidden (view full) ---
827 !(sp->confflags & CONF_ENABLE_IPV6))
828 goto drop;
829#endif
830 /*
831 * Interface is not yet running, but auto-dial. Need
832 * to start LCP for it.
833 */
834 ifp->if_drv_flags |= IFF_DRV_RUNNING;
835 splx(s);
836 lcp.Open(sp);
837 s = splimp();
838 }
839
840#ifdef INET
841 if (dst->sa_family == AF_INET) {
842 /* XXX Check mbuf length here? */
843 struct ip *ip = mtod (m, struct ip*);
844 struct tcphdr *tcp = (struct tcphdr*) ((long*)ip + ip->ip_hl);
845
--- 7 unchanged lines hidden (view full) ---
853 * - don't let packets with src ip addr 0 thru
854 * - we flag TCP packets with src ip 0 as an error
855 */
856
857 if(ip->ip_src.s_addr == INADDR_ANY) /* -hm */
858 {
859 m_freem(m);
860 SPPP_UNLOCK(sp);
861 splx(s);
862 if(ip->ip_p == IPPROTO_TCP)
863 return(EADDRNOTAVAIL);
864 else
865 return(0);
866 }
867
868 /*
869 * Put low delay, telnet, rlogin and ftp control packets
--- 28 unchanged lines hidden (view full) ---
898 ipproto = PPP_VJ_UCOMP;
899 break;
900 case TYPE_IP:
901 ipproto = PPP_IP;
902 break;
903 default:
904 m_freem(m);
905 SPPP_UNLOCK(sp);
906 splx(s);
907 return (EINVAL);
908 }
909 }
910#endif
911
912#ifdef INET6
913 if (dst->sa_family == AF_INET6) {
914 /* XXX do something tricky here? */
--- 13 unchanged lines hidden (view full) ---
928 */
929 M_PREPEND (m, PPP_HEADER_LEN, M_DONTWAIT);
930 if (! m) {
931nobufs: if (debug)
932 log(LOG_DEBUG, SPP_FMT "no memory for transmit header\n",
933 SPP_ARGS(ifp));
934 ++ifp->if_oerrors;
935 SPPP_UNLOCK(sp);
936 splx (s);
937 return (ENOBUFS);
938 }
939 /*
940 * May want to check size of packet
941 * (albeit due to the implementation it's always enough)
942 */
943 h = mtod (m, struct ppp_header*);
944 if (sp->pp_mode == IFF_CISCO) {
--- 50 unchanged lines hidden (view full) ---
995 h->protocol = htons (sp->pp_mode == IFF_CISCO ?
996 ETHERTYPE_IPX : PPP_IPX);
997 break;
998#endif
999 default:
1000 m_freem (m);
1001 ++ifp->if_oerrors;
1002 SPPP_UNLOCK(sp);
1003 splx (s);
1004 return (EAFNOSUPPORT);
1005 }
1006
1007 /*
1008 * Queue message on interface, and start output if interface
1009 * not yet active.
1010 */
1011out:
1012 if (ifq != NULL)
1013 error = !(IF_HANDOFF_ADJ(ifq, m, ifp, 3));
1014 else
1015 IFQ_HANDOFF_ADJ(ifp, m, 3, error);
1016 if (error) {
1017 ++ifp->if_oerrors;
1018 SPPP_UNLOCK(sp);
1019 splx (s);
1020 return (rv? rv: ENOBUFS);
1021 }
1022 SPPP_UNLOCK(sp);
1023 splx (s);
1024 /*
1025 * Unlike in sppp_input(), we can always bump the timestamp
1026 * here since sppp_output() is only called on behalf of
1027 * network-layer traffic; control-layer traffic is handled
1028 * by sppp_cp_send().
1029 */
1030 sp->pp_last_sent = time_uptime;
1031 return (0);
--- 100 unchanged lines hidden (view full) ---
1132
1133/*
1134 * Check if the output queue is empty.
1135 */
1136int
1137sppp_isempty(struct ifnet *ifp)
1138{
1139 struct sppp *sp = IFP2SP(ifp);
1140 int empty, s;
1141
1142 s = splimp();
1143 SPPP_LOCK(sp);
1144 empty = !sp->pp_fastq.ifq_head && !sp->pp_cpq.ifq_head &&
1145 !SP2IFP(sp)->if_snd.ifq_head;
1146 SPPP_UNLOCK(sp);
1147 splx(s);
1148 return (empty);
1149}
1150
1151/*
1152 * Get next packet to send.
1153 */
1154struct mbuf *
1155sppp_dequeue(struct ifnet *ifp)
1156{
1157 struct sppp *sp = IFP2SP(ifp);
1158 struct mbuf *m;
1159 int s;
1160
1161 s = splimp();
1162 SPPP_LOCK(sp);
1163 /*
1164 * Process only the control protocol queue until we have at
1165 * least one NCP open.
1166 *
1167 * Do always serve all three queues in Cisco mode.
1168 */
1169 IF_DEQUEUE(&sp->pp_cpq, m);
1170 if (m == NULL &&
1171 (sppp_ncp_check(sp) || sp->pp_mode == IFF_CISCO ||
1172 sp->pp_mode == PP_FR)) {
1173 IF_DEQUEUE(&sp->pp_fastq, m);
1174 if (m == NULL)
1175 IF_DEQUEUE (&SP2IFP(sp)->if_snd, m);
1176 }
1177 SPPP_UNLOCK(sp);
1178 splx(s);
1179 return m;
1180}
1181
1182/*
1183 * Pick the next packet, do not remove it from the queue.
1184 */
1185struct mbuf *
1186sppp_pick(struct ifnet *ifp)
1187{
1188 struct sppp *sp = IFP2SP(ifp);
1189 struct mbuf *m;
1190 int s;
1191
1192 s = splimp ();
1193 SPPP_LOCK(sp);
1194
1195 m = sp->pp_cpq.ifq_head;
1196 if (m == NULL &&
1197 (sp->pp_phase == PHASE_NETWORK ||
1198 sp->pp_mode == IFF_CISCO ||
1199 sp->pp_mode == PP_FR))
1200 if ((m = sp->pp_fastq.ifq_head) == NULL)
1201 m = SP2IFP(sp)->if_snd.ifq_head;
1202 SPPP_UNLOCK(sp);
1203 splx (s);
1204 return (m);
1205}
1206
1207/*
1208 * Process an ioctl request. Called on low priority level.
1209 */
1210int
1211sppp_ioctl(struct ifnet *ifp, IOCTL_CMD_T cmd, void *data)
1212{
1213 struct ifreq *ifr = (struct ifreq*) data;
1214 struct sppp *sp = IFP2SP(ifp);
1215 int s, rv, going_up, going_down, newmode;
1216
1217 s = splimp();
1218 SPPP_LOCK(sp);
1219 rv = 0;
1220 switch (cmd) {
1221 case SIOCAIFADDR:
1222 case SIOCSIFDSTADDR:
1223 break;
1224
1225 case SIOCSIFADDR:
--- 89 unchanged lines hidden (view full) ---
1315 case SIOCSIFGENERIC:
1316 rv = sppp_params(sp, cmd, data);
1317 break;
1318
1319 default:
1320 rv = ENOTTY;
1321 }
1322 SPPP_UNLOCK(sp);
1323 splx(s);
1324 return rv;
1325}
1326
1327/*
1328 * Cisco framing implementation.
1329 */
1330
1331/*
--- 733 unchanged lines hidden (view full) ---
2065 break;
2066 }
2067}
2068
2069static void
2070sppp_to_event(const struct cp *cp, struct sppp *sp)
2071{
2072 STDDCL;
2073 int s;
2074
2075 s = splimp();
2076 SPPP_LOCK(sp);
2077 if (debug)
2078 log(LOG_DEBUG, SPP_FMT "%s TO(%s) rst_counter = %d\n",
2079 SPP_ARGS(ifp), cp->name,
2080 sppp_state_name(sp->state[cp->protoidx]),
2081 sp->rst_counter[cp->protoidx]);
2082
2083 if (--sp->rst_counter[cp->protoidx] < 0)
--- 33 unchanged lines hidden (view full) ---
2117 case STATE_ACK_SENT:
2118 (cp->scr)(sp);
2119 callout_reset(&sp->ch[cp->protoidx], sp->lcp.timeout,
2120 cp->TO, (void *)sp);
2121 break;
2122 }
2123
2124 SPPP_UNLOCK(sp);
2125 splx(s);
2126}
2127
2128/*
2129 * Change the state of a control protocol in the state automaton.
2130 * Takes care of starting/stopping the restart timer.
2131 */
2132static void
2133sppp_cp_change_state(const struct cp *cp, struct sppp *sp, int newstate)
--- 1886 unchanged lines hidden (view full) ---
4020/*
4021 * Handle incoming CHAP packets.
4022 */
4023static void
4024sppp_chap_input(struct sppp *sp, struct mbuf *m)
4025{
4026 STDDCL;
4027 struct lcp_header *h;
4028 int len, x;
4029 u_char *value, *name, digest[AUTHKEYLEN], dsize;
4030 int value_len, name_len;
4031 MD5_CTX ctx;
4032
4033 len = m->m_pkthdr.len;
4034 if (len < 4) {
4035 if (debug)
4036 log(LOG_DEBUG,
--- 60 unchanged lines hidden (view full) ---
4097 log(LOG_DEBUG, SPP_FMT "chap success",
4098 SPP_ARGS(ifp));
4099 if (len > 4) {
4100 log(-1, ": ");
4101 sppp_print_string((char*)(h + 1), len - 4);
4102 }
4103 log(-1, "\n");
4104 }
4105 x = splimp();
4106 SPPP_LOCK(sp);
4107 sp->pp_flags &= ~PP_NEEDAUTH;
4108 if (sp->myauth.proto == PPP_CHAP &&
4109 (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) &&
4110 (sp->lcp.protos & (1 << IDX_CHAP)) == 0) {
4111 /*
4112 * We are authenticator for CHAP but didn't
4113 * complete yet. Leave it to tlu to proceed
4114 * to network phase.
4115 */
4116 SPPP_UNLOCK(sp);
4117 splx(x);
4118 break;
4119 }
4120 SPPP_UNLOCK(sp);
4121 splx(x);
4122 sppp_phase_network(sp);
4123 break;
4124
4125 case CHAP_FAILURE:
4126 if (debug) {
4127 log(LOG_INFO, SPP_FMT "chap failure",
4128 SPP_ARGS(ifp));
4129 if (len > 4) {
--- 145 unchanged lines hidden (view full) ---
4275 sppp_cp_change_state(&chap, sp, STATE_CLOSED);
4276}
4277
4278static void
4279sppp_chap_TO(void *cookie)
4280{
4281 struct sppp *sp = (struct sppp *)cookie;
4282 STDDCL;
4283 int s;
4284
4285 s = splimp();
4286 SPPP_LOCK(sp);
4287 if (debug)
4288 log(LOG_DEBUG, SPP_FMT "chap TO(%s) rst_counter = %d\n",
4289 SPP_ARGS(ifp),
4290 sppp_state_name(sp->state[IDX_CHAP]),
4291 sp->rst_counter[IDX_CHAP]);
4292
4293 if (--sp->rst_counter[IDX_CHAP] < 0)
--- 14 unchanged lines hidden (view full) ---
4308 case STATE_REQ_SENT:
4309 chap.scr(sp);
4310 /* sppp_cp_change_state() will restart the timer */
4311 sppp_cp_change_state(&chap, sp, STATE_REQ_SENT);
4312 break;
4313 }
4314
4315 SPPP_UNLOCK(sp);
4316 splx(s);
4317}
4318
4319static void
4320sppp_chap_tlu(struct sppp *sp)
4321{
4322 STDDCL;
4323 int i, x;
4324
4325 i = 0;
4326 sp->rst_counter[IDX_CHAP] = sp->lcp.max_configure;
4327
4328 /*
4329 * Some broken CHAP implementations (Conware CoNet, firmware
4330 * 4.0.?) don't want to re-authenticate their CHAP once the
4331 * initial challenge-response exchange has taken place.
--- 14 unchanged lines hidden (view full) ---
4346 SPP_ARGS(ifp),
4347 sp->pp_phase == PHASE_NETWORK? "reconfirmed": "tlu");
4348 if ((sp->hisauth.flags & AUTHFLAG_NORECHALLENGE) == 0)
4349 log(-1, "next re-challenge in %d seconds\n", i);
4350 else
4351 log(-1, "re-challenging supressed\n");
4352 }
4353
4354 x = splimp();
4355 SPPP_LOCK(sp);
4356 /* indicate to LCP that we need to be closed down */
4357 sp->lcp.protos |= (1 << IDX_CHAP);
4358
4359 if (sp->pp_flags & PP_NEEDAUTH) {
4360 /*
4361 * Remote is authenticator, but his auth proto didn't
4362 * complete yet. Defer the transition to network
4363 * phase.
4364 */
4365 SPPP_UNLOCK(sp);
4366 splx(x);
4367 return;
4368 }
4369 SPPP_UNLOCK(sp);
4370 splx(x);
4371
4372 /*
4373 * If we are already in phase network, we are done here. This
4374 * is the case if this is a dummy tlu event after a re-challenge.
4375 */
4376 if (sp->pp_phase != PHASE_NETWORK)
4377 sppp_phase_network(sp);
4378}
--- 52 unchanged lines hidden (view full) ---
4431
4432/*
4433 * Handle incoming PAP packets. */
4434static void
4435sppp_pap_input(struct sppp *sp, struct mbuf *m)
4436{
4437 STDDCL;
4438 struct lcp_header *h;
4439 int len, x;
4440 u_char *name, *passwd, mlen;
4441 int name_len, passwd_len;
4442
4443 len = m->m_pkthdr.len;
4444 if (len < 5) {
4445 if (debug)
4446 log(LOG_DEBUG,
4447 SPP_FMT "pap invalid packet length: %d bytes\n",
--- 70 unchanged lines hidden (view full) ---
4518 SPP_ARGS(ifp));
4519 name_len = *((char *)h);
4520 if (len > 5 && name_len) {
4521 log(-1, ": ");
4522 sppp_print_string((char*)(h+1), name_len);
4523 }
4524 log(-1, "\n");
4525 }
4526 x = splimp();
4527 SPPP_LOCK(sp);
4528 sp->pp_flags &= ~PP_NEEDAUTH;
4529 if (sp->myauth.proto == PPP_PAP &&
4530 (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) &&
4531 (sp->lcp.protos & (1 << IDX_PAP)) == 0) {
4532 /*
4533 * We are authenticator for PAP but didn't
4534 * complete yet. Leave it to tlu to proceed
4535 * to network phase.
4536 */
4537 SPPP_UNLOCK(sp);
4538 splx(x);
4539 break;
4540 }
4541 SPPP_UNLOCK(sp);
4542 splx(x);
4543 sppp_phase_network(sp);
4544 break;
4545
4546 case PAP_NAK:
4547 callout_stop (&sp->pap_my_to_ch);
4548 if (debug) {
4549 log(LOG_INFO, SPP_FMT "pap failure",
4550 SPP_ARGS(ifp));
--- 64 unchanged lines hidden (view full) ---
4615 * That's the timeout routine if we are authenticator. Since the
4616 * authenticator is basically passive in PAP, we can't do much here.
4617 */
4618static void
4619sppp_pap_TO(void *cookie)
4620{
4621 struct sppp *sp = (struct sppp *)cookie;
4622 STDDCL;
4623 int s;
4624
4625 s = splimp();
4626 SPPP_LOCK(sp);
4627 if (debug)
4628 log(LOG_DEBUG, SPP_FMT "pap TO(%s) rst_counter = %d\n",
4629 SPP_ARGS(ifp),
4630 sppp_state_name(sp->state[IDX_PAP]),
4631 sp->rst_counter[IDX_PAP]);
4632
4633 if (--sp->rst_counter[IDX_PAP] < 0)
--- 9 unchanged lines hidden (view full) ---
4643 switch (sp->state[IDX_PAP]) {
4644 case STATE_REQ_SENT:
4645 /* sppp_cp_change_state() will restart the timer */
4646 sppp_cp_change_state(&pap, sp, STATE_REQ_SENT);
4647 break;
4648 }
4649
4650 SPPP_UNLOCK(sp);
4651 splx(s);
4652}
4653
4654/*
4655 * That's the timeout handler if we are peer. Since the peer is active,
4656 * we need to retransmit our PAP request since it is apparently lost.
4657 * XXX We should impose a max counter.
4658 */
4659static void
--- 10 unchanged lines hidden (view full) ---
4670 pap.scr(sp);
4671 SPPP_UNLOCK(sp);
4672}
4673
4674static void
4675sppp_pap_tlu(struct sppp *sp)
4676{
4677 STDDCL;
4678 int x;
4679
4680 sp->rst_counter[IDX_PAP] = sp->lcp.max_configure;
4681
4682 if (debug)
4683 log(LOG_DEBUG, SPP_FMT "%s tlu\n",
4684 SPP_ARGS(ifp), pap.name);
4685
4686 x = splimp();
4687 SPPP_LOCK(sp);
4688 /* indicate to LCP that we need to be closed down */
4689 sp->lcp.protos |= (1 << IDX_PAP);
4690
4691 if (sp->pp_flags & PP_NEEDAUTH) {
4692 /*
4693 * Remote is authenticator, but his auth proto didn't
4694 * complete yet. Defer the transition to network
4695 * phase.
4696 */
4697 SPPP_UNLOCK(sp);
4698 splx(x);
4699 return;
4700 }
4701 SPPP_UNLOCK(sp);
4702 splx(x);
4703 sppp_phase_network(sp);
4704}
4705
4706static void
4707sppp_pap_tld(struct sppp *sp)
4708{
4709 STDDCL;
4710
--- 121 unchanged lines hidden (view full) ---
4832/*
4833 * Send keepalive packets, every 10 seconds.
4834 */
4835static void
4836sppp_keepalive(void *dummy)
4837{
4838 struct sppp *sp = (struct sppp*)dummy;
4839 struct ifnet *ifp = SP2IFP(sp);
4840 int s;
4841
4842 s = splimp();
4843 SPPP_LOCK(sp);
4844 /* Keepalive mode disabled or channel down? */
4845 if (! (sp->pp_flags & PP_KEEPALIVE) ||
4846 ! (ifp->if_drv_flags & IFF_DRV_RUNNING))
4847 goto out;
4848
4849 if (sp->pp_mode == PP_FR) {
4850 sppp_fr_keepalive (sp);
--- 26 unchanged lines hidden (view full) ---
4877 else if (sp->pp_phase >= PHASE_AUTHENTICATE) {
4878 long nmagic = htonl (sp->lcp.magic);
4879 sp->lcp.echoid = ++sp->pp_seq[IDX_LCP];
4880 sppp_cp_send (sp, PPP_LCP, ECHO_REQ,
4881 sp->lcp.echoid, 4, &nmagic);
4882 }
4883out:
4884 SPPP_UNLOCK(sp);
4885 splx(s);
4886 callout_reset(&sp->keepalive_callout, hz * 10, sppp_keepalive,
4887 (void *)sp);
4888}
4889
4890/*
4891 * Get both IP addresses.
4892 */
4893void
--- 33 unchanged lines hidden (view full) ---
4927 if_addr_runlock(ifp);
4928
4929 if (dst) *dst = ntohl(ddst);
4930 if (src) *src = ntohl(ssrc);
4931}
4932
4933#ifdef INET
4934/*
4935 * Set my IP address. Must be called at splimp.
4936 */
4937static void
4938sppp_set_ip_addr(struct sppp *sp, u_long src)
4939{
4940 STDDCL;
4941 struct ifaddr *ifa;
4942 struct sockaddr_in *si;
4943 struct in_ifaddr *ia;
--- 100 unchanged lines hidden (view full) ---
5044 */
5045static void
5046sppp_gen_ip6_addr(struct sppp *sp, struct in6_addr *addr)
5047{
5048 /* TBD */
5049}
5050
5051/*
5052 * Set my IPv6 address. Must be called at splimp.
5053 */
5054static void
5055sppp_set_ip6_addr(struct sppp *sp, const struct in6_addr *src)
5056{
5057 STDDCL;
5058 struct ifaddr *ifa;
5059 struct sockaddr_in6 *sin6;
5060
--- 431 unchanged lines hidden ---