Deleted Added
full compact
if_spppsubr.c (241394) if_spppsubr.c (241686)
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 *
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 $
21 * $FreeBSD: head/sys/net/if_spppsubr.c 241686 2012-10-18 13:57:24Z andre $
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;
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;
794 int error, rv = 0;
795#ifdef INET
796 int ipproto = PPP_IP;
797#endif
798 int debug = ifp->if_flags & IFF_DEBUG;
799
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);
800 SPPP_LOCK(sp);
801
802 if (!(ifp->if_flags & IFF_UP) ||
803 (!(ifp->if_flags & IFF_AUTO) &&
804 !(ifp->if_drv_flags & IFF_DRV_RUNNING))) {
805#ifdef INET6
806 drop:
807#endif
808 m_freem (m);
809 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;
810 return (ENETDOWN);
811 }
812
813 if ((ifp->if_flags & IFF_AUTO) &&
814 !(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
815#ifdef INET6
816 /*
817 * XXX

--- 7 unchanged lines hidden (view full) ---

825 !(sp->confflags & CONF_ENABLE_IPV6))
826 goto drop;
827#endif
828 /*
829 * Interface is not yet running, but auto-dial. Need
830 * to start LCP for it.
831 */
832 ifp->if_drv_flags |= IFF_DRV_RUNNING;
835 splx(s);
836 lcp.Open(sp);
833 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);
834 }
835
836#ifdef INET
837 if (dst->sa_family == AF_INET) {
838 /* XXX Check mbuf length here? */
839 struct ip *ip = mtod (m, struct ip*);
840 struct tcphdr *tcp = (struct tcphdr*) ((long*)ip + ip->ip_hl);
841

--- 7 unchanged lines hidden (view full) ---

849 * - don't let packets with src ip addr 0 thru
850 * - we flag TCP packets with src ip 0 as an error
851 */
852
853 if(ip->ip_src.s_addr == INADDR_ANY) /* -hm */
854 {
855 m_freem(m);
856 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);
857 if(ip->ip_p == IPPROTO_TCP)
858 return(EADDRNOTAVAIL);
859 else
860 return(0);
861 }
862
863 /*
864 * Put low delay, telnet, rlogin and ftp control packets

--- 28 unchanged lines hidden (view full) ---

893 ipproto = PPP_VJ_UCOMP;
894 break;
895 case TYPE_IP:
896 ipproto = PPP_IP;
897 break;
898 default:
899 m_freem(m);
900 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);
901 return (EINVAL);
902 }
903 }
904#endif
905
906#ifdef INET6
907 if (dst->sa_family == AF_INET6) {
908 /* XXX do something tricky here? */

--- 13 unchanged lines hidden (view full) ---

922 */
923 M_PREPEND (m, PPP_HEADER_LEN, M_DONTWAIT);
924 if (! m) {
925nobufs: if (debug)
926 log(LOG_DEBUG, SPP_FMT "no memory for transmit header\n",
927 SPP_ARGS(ifp));
928 ++ifp->if_oerrors;
929 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);
930 return (ENOBUFS);
931 }
932 /*
933 * May want to check size of packet
934 * (albeit due to the implementation it's always enough)
935 */
936 h = mtod (m, struct ppp_header*);
937 if (sp->pp_mode == IFF_CISCO) {

--- 50 unchanged lines hidden (view full) ---

988 h->protocol = htons (sp->pp_mode == IFF_CISCO ?
989 ETHERTYPE_IPX : PPP_IPX);
990 break;
991#endif
992 default:
993 m_freem (m);
994 ++ifp->if_oerrors;
995 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);
996 return (EAFNOSUPPORT);
997 }
998
999 /*
1000 * Queue message on interface, and start output if interface
1001 * not yet active.
1002 */
1003out:
1004 if (ifq != NULL)
1005 error = !(IF_HANDOFF_ADJ(ifq, m, ifp, 3));
1006 else
1007 IFQ_HANDOFF_ADJ(ifp, m, 3, error);
1008 if (error) {
1009 ++ifp->if_oerrors;
1010 SPPP_UNLOCK(sp);
1019 splx (s);
1020 return (rv? rv: ENOBUFS);
1021 }
1022 SPPP_UNLOCK(sp);
1011 return (rv? rv: ENOBUFS);
1012 }
1013 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);
1014 /*
1015 * Unlike in sppp_input(), we can always bump the timestamp
1016 * here since sppp_output() is only called on behalf of
1017 * network-layer traffic; control-layer traffic is handled
1018 * by sppp_cp_send().
1019 */
1020 sp->pp_last_sent = time_uptime;
1021 return (0);

--- 100 unchanged lines hidden (view full) ---

1122
1123/*
1124 * Check if the output queue is empty.
1125 */
1126int
1127sppp_isempty(struct ifnet *ifp)
1128{
1129 struct sppp *sp = IFP2SP(ifp);
1140 int empty, s;
1130 int empty;
1141
1131
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);
1132 SPPP_LOCK(sp);
1133 empty = !sp->pp_fastq.ifq_head && !sp->pp_cpq.ifq_head &&
1134 !SP2IFP(sp)->if_snd.ifq_head;
1135 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;
1136 return (empty);
1137}
1138
1139/*
1140 * Get next packet to send.
1141 */
1142struct mbuf *
1143sppp_dequeue(struct ifnet *ifp)
1144{
1145 struct sppp *sp = IFP2SP(ifp);
1146 struct mbuf *m;
1159 int s;
1160
1147
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);
1148 SPPP_LOCK(sp);
1149 /*
1150 * Process only the control protocol queue until we have at
1151 * least one NCP open.
1152 *
1153 * Do always serve all three queues in Cisco mode.
1154 */
1155 IF_DEQUEUE(&sp->pp_cpq, m);
1156 if (m == NULL &&
1157 (sppp_ncp_check(sp) || sp->pp_mode == IFF_CISCO ||
1158 sp->pp_mode == PP_FR)) {
1159 IF_DEQUEUE(&sp->pp_fastq, m);
1160 if (m == NULL)
1161 IF_DEQUEUE (&SP2IFP(sp)->if_snd, m);
1162 }
1163 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;
1164 return m;
1165}
1166
1167/*
1168 * Pick the next packet, do not remove it from the queue.
1169 */
1170struct mbuf *
1171sppp_pick(struct ifnet *ifp)
1172{
1173 struct sppp *sp = IFP2SP(ifp);
1174 struct mbuf *m;
1190 int s;
1191
1175
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);
1176 SPPP_LOCK(sp);
1177
1178 m = sp->pp_cpq.ifq_head;
1179 if (m == NULL &&
1180 (sp->pp_phase == PHASE_NETWORK ||
1181 sp->pp_mode == IFF_CISCO ||
1182 sp->pp_mode == PP_FR))
1183 if ((m = sp->pp_fastq.ifq_head) == NULL)
1184 m = SP2IFP(sp)->if_snd.ifq_head;
1185 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);
1186 return (m);
1187}
1188
1189/*
1190 * Process an ioctl request. Called on low priority level.
1191 */
1192int
1193sppp_ioctl(struct ifnet *ifp, IOCTL_CMD_T cmd, void *data)
1194{
1195 struct ifreq *ifr = (struct ifreq*) data;
1196 struct sppp *sp = IFP2SP(ifp);
1215 int s, rv, going_up, going_down, newmode;
1197 int rv, going_up, going_down, newmode;
1216
1198
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);
1199 SPPP_LOCK(sp);
1200 rv = 0;
1201 switch (cmd) {
1202 case SIOCAIFADDR:
1203 case SIOCSIFDSTADDR:
1204 break;
1205
1206 case SIOCSIFADDR:

--- 89 unchanged lines hidden (view full) ---

1296 case SIOCSIFGENERIC:
1297 rv = sppp_params(sp, cmd, data);
1298 break;
1299
1300 default:
1301 rv = ENOTTY;
1302 }
1303 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;
1304 return rv;
1305}
1306
1307/*
1308 * Cisco framing implementation.
1309 */
1310
1311/*

--- 733 unchanged lines hidden (view full) ---

2045 break;
2046 }
2047}
2048
2049static void
2050sppp_to_event(const struct cp *cp, struct sppp *sp)
2051{
2052 STDDCL;
2073 int s;
2074
2053
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);
2054 SPPP_LOCK(sp);
2055 if (debug)
2056 log(LOG_DEBUG, SPP_FMT "%s TO(%s) rst_counter = %d\n",
2057 SPP_ARGS(ifp), cp->name,
2058 sppp_state_name(sp->state[cp->protoidx]),
2059 sp->rst_counter[cp->protoidx]);
2060
2061 if (--sp->rst_counter[cp->protoidx] < 0)

--- 33 unchanged lines hidden (view full) ---

2095 case STATE_ACK_SENT:
2096 (cp->scr)(sp);
2097 callout_reset(&sp->ch[cp->protoidx], sp->lcp.timeout,
2098 cp->TO, (void *)sp);
2099 break;
2100 }
2101
2102 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;
2103}
2104
2105/*
2106 * Change the state of a control protocol in the state automaton.
2107 * Takes care of starting/stopping the restart timer.
2108 */
2109static void
2110sppp_cp_change_state(const struct cp *cp, struct sppp *sp, int newstate)

--- 1886 unchanged lines hidden (view full) ---

3997/*
3998 * Handle incoming CHAP packets.
3999 */
4000static void
4001sppp_chap_input(struct sppp *sp, struct mbuf *m)
4002{
4003 STDDCL;
4004 struct lcp_header *h;
4028 int len, x;
4005 int len;
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 }
4006 u_char *value, *name, digest[AUTHKEYLEN], dsize;
4007 int value_len, name_len;
4008 MD5_CTX ctx;
4009
4010 len = m->m_pkthdr.len;
4011 if (len < 4) {
4012 if (debug)
4013 log(LOG_DEBUG,

--- 60 unchanged lines hidden (view full) ---

4074 log(LOG_DEBUG, SPP_FMT "chap success",
4075 SPP_ARGS(ifp));
4076 if (len > 4) {
4077 log(-1, ": ");
4078 sppp_print_string((char*)(h + 1), len - 4);
4079 }
4080 log(-1, "\n");
4081 }
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);
4082 SPPP_LOCK(sp);
4083 sp->pp_flags &= ~PP_NEEDAUTH;
4084 if (sp->myauth.proto == PPP_CHAP &&
4085 (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) &&
4086 (sp->lcp.protos & (1 << IDX_CHAP)) == 0) {
4087 /*
4088 * We are authenticator for CHAP but didn't
4089 * complete yet. Leave it to tlu to proceed
4090 * to network phase.
4091 */
4092 SPPP_UNLOCK(sp);
4117 splx(x);
4118 break;
4119 }
4120 SPPP_UNLOCK(sp);
4093 break;
4094 }
4095 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;
4096 sppp_phase_network(sp);
4097 break;
4098
4099 case CHAP_FAILURE:
4100 if (debug) {
4101 log(LOG_INFO, SPP_FMT "chap failure",
4102 SPP_ARGS(ifp));
4103 if (len > 4) {

--- 145 unchanged lines hidden (view full) ---

4249 sppp_cp_change_state(&chap, sp, STATE_CLOSED);
4250}
4251
4252static void
4253sppp_chap_TO(void *cookie)
4254{
4255 struct sppp *sp = (struct sppp *)cookie;
4256 STDDCL;
4283 int s;
4284
4257
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);
4258 SPPP_LOCK(sp);
4259 if (debug)
4260 log(LOG_DEBUG, SPP_FMT "chap TO(%s) rst_counter = %d\n",
4261 SPP_ARGS(ifp),
4262 sppp_state_name(sp->state[IDX_CHAP]),
4263 sp->rst_counter[IDX_CHAP]);
4264
4265 if (--sp->rst_counter[IDX_CHAP] < 0)

--- 14 unchanged lines hidden (view full) ---

4280 case STATE_REQ_SENT:
4281 chap.scr(sp);
4282 /* sppp_cp_change_state() will restart the timer */
4283 sppp_cp_change_state(&chap, sp, STATE_REQ_SENT);
4284 break;
4285 }
4286
4287 SPPP_UNLOCK(sp);
4316 splx(s);
4317}
4318
4319static void
4320sppp_chap_tlu(struct sppp *sp)
4321{
4322 STDDCL;
4288}
4289
4290static void
4291sppp_chap_tlu(struct sppp *sp)
4292{
4293 STDDCL;
4323 int i, x;
4294 int i;
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
4295
4296 i = 0;
4297 sp->rst_counter[IDX_CHAP] = sp->lcp.max_configure;
4298
4299 /*
4300 * Some broken CHAP implementations (Conware CoNet, firmware
4301 * 4.0.?) don't want to re-authenticate their CHAP once the
4302 * initial challenge-response exchange has taken place.

--- 14 unchanged lines hidden (view full) ---

4317 SPP_ARGS(ifp),
4318 sp->pp_phase == PHASE_NETWORK? "reconfirmed": "tlu");
4319 if ((sp->hisauth.flags & AUTHFLAG_NORECHALLENGE) == 0)
4320 log(-1, "next re-challenge in %d seconds\n", i);
4321 else
4322 log(-1, "re-challenging supressed\n");
4323 }
4324
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);
4325 SPPP_LOCK(sp);
4326 /* indicate to LCP that we need to be closed down */
4327 sp->lcp.protos |= (1 << IDX_CHAP);
4328
4329 if (sp->pp_flags & PP_NEEDAUTH) {
4330 /*
4331 * Remote is authenticator, but his auth proto didn't
4332 * complete yet. Defer the transition to network
4333 * phase.
4334 */
4335 SPPP_UNLOCK(sp);
4366 splx(x);
4367 return;
4368 }
4369 SPPP_UNLOCK(sp);
4336 return;
4337 }
4338 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;
4339
4340 /*
4341 * If we are already in phase network, we are done here. This
4342 * is the case if this is a dummy tlu event after a re-challenge.
4343 */
4344 if (sp->pp_phase != PHASE_NETWORK)
4345 sppp_phase_network(sp);
4346}

--- 52 unchanged lines hidden (view full) ---

4399
4400/*
4401 * Handle incoming PAP packets. */
4402static void
4403sppp_pap_input(struct sppp *sp, struct mbuf *m)
4404{
4405 STDDCL;
4406 struct lcp_header *h;
4439 int len, x;
4407 int len;
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 }
4408 u_char *name, *passwd, mlen;
4409 int name_len, passwd_len;
4410
4411 len = m->m_pkthdr.len;
4412 if (len < 5) {
4413 if (debug)
4414 log(LOG_DEBUG,
4415 SPP_FMT "pap invalid packet length: %d bytes\n",

--- 70 unchanged lines hidden (view full) ---

4486 SPP_ARGS(ifp));
4487 name_len = *((char *)h);
4488 if (len > 5 && name_len) {
4489 log(-1, ": ");
4490 sppp_print_string((char*)(h+1), name_len);
4491 }
4492 log(-1, "\n");
4493 }
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);
4494 SPPP_LOCK(sp);
4495 sp->pp_flags &= ~PP_NEEDAUTH;
4496 if (sp->myauth.proto == PPP_PAP &&
4497 (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) &&
4498 (sp->lcp.protos & (1 << IDX_PAP)) == 0) {
4499 /*
4500 * We are authenticator for PAP but didn't
4501 * complete yet. Leave it to tlu to proceed
4502 * to network phase.
4503 */
4504 SPPP_UNLOCK(sp);
4538 splx(x);
4539 break;
4540 }
4541 SPPP_UNLOCK(sp);
4505 break;
4506 }
4507 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;
4508 sppp_phase_network(sp);
4509 break;
4510
4511 case PAP_NAK:
4512 callout_stop (&sp->pap_my_to_ch);
4513 if (debug) {
4514 log(LOG_INFO, SPP_FMT "pap failure",
4515 SPP_ARGS(ifp));

--- 64 unchanged lines hidden (view full) ---

4580 * That's the timeout routine if we are authenticator. Since the
4581 * authenticator is basically passive in PAP, we can't do much here.
4582 */
4583static void
4584sppp_pap_TO(void *cookie)
4585{
4586 struct sppp *sp = (struct sppp *)cookie;
4587 STDDCL;
4623 int s;
4624
4588
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);
4589 SPPP_LOCK(sp);
4590 if (debug)
4591 log(LOG_DEBUG, SPP_FMT "pap TO(%s) rst_counter = %d\n",
4592 SPP_ARGS(ifp),
4593 sppp_state_name(sp->state[IDX_PAP]),
4594 sp->rst_counter[IDX_PAP]);
4595
4596 if (--sp->rst_counter[IDX_PAP] < 0)

--- 9 unchanged lines hidden (view full) ---

4606 switch (sp->state[IDX_PAP]) {
4607 case STATE_REQ_SENT:
4608 /* sppp_cp_change_state() will restart the timer */
4609 sppp_cp_change_state(&pap, sp, STATE_REQ_SENT);
4610 break;
4611 }
4612
4613 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;
4614}
4615
4616/*
4617 * That's the timeout handler if we are peer. Since the peer is active,
4618 * we need to retransmit our PAP request since it is apparently lost.
4619 * XXX We should impose a max counter.
4620 */
4621static void

--- 10 unchanged lines hidden (view full) ---

4632 pap.scr(sp);
4633 SPPP_UNLOCK(sp);
4634}
4635
4636static void
4637sppp_pap_tlu(struct sppp *sp)
4638{
4639 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
4640
4641 sp->rst_counter[IDX_PAP] = sp->lcp.max_configure;
4642
4643 if (debug)
4644 log(LOG_DEBUG, SPP_FMT "%s tlu\n",
4645 SPP_ARGS(ifp), pap.name);
4646
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);
4647 SPPP_LOCK(sp);
4648 /* indicate to LCP that we need to be closed down */
4649 sp->lcp.protos |= (1 << IDX_PAP);
4650
4651 if (sp->pp_flags & PP_NEEDAUTH) {
4652 /*
4653 * Remote is authenticator, but his auth proto didn't
4654 * complete yet. Defer the transition to network
4655 * phase.
4656 */
4657 SPPP_UNLOCK(sp);
4698 splx(x);
4699 return;
4700 }
4701 SPPP_UNLOCK(sp);
4658 return;
4659 }
4660 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);
4661 sppp_phase_network(sp);
4662}
4663
4664static void
4665sppp_pap_tld(struct sppp *sp)
4666{
4667 STDDCL;
4668

--- 121 unchanged lines hidden (view full) ---

4790/*
4791 * Send keepalive packets, every 10 seconds.
4792 */
4793static void
4794sppp_keepalive(void *dummy)
4795{
4796 struct sppp *sp = (struct sppp*)dummy;
4797 struct ifnet *ifp = SP2IFP(sp);
4840 int s;
4841
4798
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);
4799 SPPP_LOCK(sp);
4800 /* Keepalive mode disabled or channel down? */
4801 if (! (sp->pp_flags & PP_KEEPALIVE) ||
4802 ! (ifp->if_drv_flags & IFF_DRV_RUNNING))
4803 goto out;
4804
4805 if (sp->pp_mode == PP_FR) {
4806 sppp_fr_keepalive (sp);

--- 26 unchanged lines hidden (view full) ---

4833 else if (sp->pp_phase >= PHASE_AUTHENTICATE) {
4834 long nmagic = htonl (sp->lcp.magic);
4835 sp->lcp.echoid = ++sp->pp_seq[IDX_LCP];
4836 sppp_cp_send (sp, PPP_LCP, ECHO_REQ,
4837 sp->lcp.echoid, 4, &nmagic);
4838 }
4839out:
4840 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/*
4841 callout_reset(&sp->keepalive_callout, hz * 10, sppp_keepalive,
4842 (void *)sp);
4843}
4844
4845/*
4846 * Get both IP addresses.
4847 */
4848void

--- 33 unchanged lines hidden (view full) ---

4882 if_addr_runlock(ifp);
4883
4884 if (dst) *dst = ntohl(ddst);
4885 if (src) *src = ntohl(ssrc);
4886}
4887
4888#ifdef INET
4889/*
4935 * Set my IP address. Must be called at splimp.
4890 * Set my IP address.
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/*
4891 */
4892static void
4893sppp_set_ip_addr(struct sppp *sp, u_long src)
4894{
4895 STDDCL;
4896 struct ifaddr *ifa;
4897 struct sockaddr_in *si;
4898 struct in_ifaddr *ia;

--- 100 unchanged lines hidden (view full) ---

4999 */
5000static void
5001sppp_gen_ip6_addr(struct sppp *sp, struct in6_addr *addr)
5002{
5003 /* TBD */
5004}
5005
5006/*
5052 * Set my IPv6 address. Must be called at splimp.
5007 * Set my IPv6 address.
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 ---
5008 */
5009static void
5010sppp_set_ip6_addr(struct sppp *sp, const struct in6_addr *src)
5011{
5012 STDDCL;
5013 struct ifaddr *ifa;
5014 struct sockaddr_in6 *sin6;
5015

--- 431 unchanged lines hidden ---