if_spppsubr.c (138855) | if_spppsubr.c (139365) |
---|---|
1/* | 1/* |
2 * Synchronous PPP/Cisco link level subroutines. | 2 * Synchronous PPP/Cisco/Frame Relay link level subroutines. |
3 * Keepalive protocol implemented in both Cisco and PPP modes. 4 * | 3 * Keepalive protocol implemented in both Cisco and PPP modes. 4 * |
5 * Copyright (C) 1994-1996 Cronyx Engineering Ltd. | 5 * Copyright (C) 1994-2000 Cronyx Engineering. |
6 * Author: Serge Vakulenko, <vak@cronyx.ru> 7 * 8 * Heavily revamped to conform to RFC 1661. 9 * Copyright (C) 1997, 2001 Joerg Wunsch. 10 * 11 * This software is distributed with NO WARRANTIES, not even the implied 12 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 * 14 * Authors grant any other persons or organisations permission to use 15 * or modify this software as long as this message is kept with the software, 16 * all derivative works or modified versions. 17 * 18 * From: Version 2.4, Thu Apr 30 17:17:21 MSD 1997 19 * | 6 * Author: Serge Vakulenko, <vak@cronyx.ru> 7 * 8 * Heavily revamped to conform to RFC 1661. 9 * Copyright (C) 1997, 2001 Joerg Wunsch. 10 * 11 * This software is distributed with NO WARRANTIES, not even the implied 12 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 * 14 * Authors grant any other persons or organisations permission to use 15 * or modify this software as long as this message is kept with the software, 16 * all derivative works or modified versions. 17 * 18 * From: Version 2.4, Thu Apr 30 17:17:21 MSD 1997 19 * |
20 * $FreeBSD: head/sys/net/if_spppsubr.c 138855 2004-12-14 18:18:54Z rik $ | 20 * $FreeBSD: head/sys/net/if_spppsubr.c 139365 2004-12-28 00:07:57Z rik $ |
21 */ 22 23#include <sys/param.h> 24 25#if defined(__FreeBSD__) && __FreeBSD__ >= 3 26#include "opt_inet.h" 27#include "opt_inet6.h" 28#include "opt_ipx.h" --- 375 unchanged lines hidden (view full) --- 404static const char *sppp_ipv6cp_opt_name(u_char opt); 405#endif 406static const char *sppp_lcp_opt_name(u_char opt); 407static const char *sppp_phase_name(enum ppp_phase phase); 408static const char *sppp_proto_name(u_short proto); 409static const char *sppp_state_name(int state); 410static int sppp_params(struct sppp *sp, u_long cmd, void *data); 411static int sppp_strnlen(u_char *p, int max); | 21 */ 22 23#include <sys/param.h> 24 25#if defined(__FreeBSD__) && __FreeBSD__ >= 3 26#include "opt_inet.h" 27#include "opt_inet6.h" 28#include "opt_ipx.h" --- 375 unchanged lines hidden (view full) --- 404static const char *sppp_ipv6cp_opt_name(u_char opt); 405#endif 406static const char *sppp_lcp_opt_name(u_char opt); 407static const char *sppp_phase_name(enum ppp_phase phase); 408static const char *sppp_proto_name(u_short proto); 409static const char *sppp_state_name(int state); 410static int sppp_params(struct sppp *sp, u_long cmd, void *data); 411static int sppp_strnlen(u_char *p, int max); |
412static void sppp_get_ip_addrs(struct sppp *sp, u_long *src, u_long *dst, 413 u_long *srcmask); | |
414static void sppp_keepalive(void *dummy); 415static void sppp_phase_network(struct sppp *sp); 416static void sppp_print_bytes(const u_char *p, u_short len); 417static void sppp_print_string(const char *p, u_short len); 418static void sppp_qflush(struct ifqueue *ifq); 419static void sppp_set_ip_addr(struct sppp *sp, u_long src); 420#ifdef INET6 421static void sppp_get_ip6_addrs(struct sppp *sp, struct in6_addr *src, --- 124 unchanged lines hidden (view full) --- 546 m_freem (m); 547 SPPP_UNLOCK(sp); 548 drop2: 549 ++ifp->if_ierrors; 550 ++ifp->if_iqdrops; 551 return; 552 } 553 | 412static void sppp_keepalive(void *dummy); 413static void sppp_phase_network(struct sppp *sp); 414static void sppp_print_bytes(const u_char *p, u_short len); 415static void sppp_print_string(const char *p, u_short len); 416static void sppp_qflush(struct ifqueue *ifq); 417static void sppp_set_ip_addr(struct sppp *sp, u_long src); 418#ifdef INET6 419static void sppp_get_ip6_addrs(struct sppp *sp, struct in6_addr *src, --- 124 unchanged lines hidden (view full) --- 544 m_freem (m); 545 SPPP_UNLOCK(sp); 546 drop2: 547 ++ifp->if_ierrors; 548 ++ifp->if_iqdrops; 549 return; 550 } 551 |
552 if (sp->pp_mode == PP_FR) { 553 sppp_fr_input (sp, m); 554 SPPP_UNLOCK(sp); 555 return; 556 } 557 |
|
554 /* Get PPP header. */ 555 h = mtod (m, struct ppp_header*); 556 m_adj (m, PPP_HEADER_LEN); 557 558 switch (h->address) { 559 case PPP_ALLSTATIONS: 560 if (h->control != PPP_UI) 561 goto invalid; --- 320 unchanged lines hidden (view full) --- 882 else if (INTERACTIVE (ntohs (tcp->th_sport))) 883 ifq = &sp->pp_fastq; 884 else if (INTERACTIVE (ntohs (tcp->th_dport))) 885 ifq = &sp->pp_fastq; 886 887 /* 888 * Do IP Header compression 889 */ | 558 /* Get PPP header. */ 559 h = mtod (m, struct ppp_header*); 560 m_adj (m, PPP_HEADER_LEN); 561 562 switch (h->address) { 563 case PPP_ALLSTATIONS: 564 if (h->control != PPP_UI) 565 goto invalid; --- 320 unchanged lines hidden (view full) --- 886 else if (INTERACTIVE (ntohs (tcp->th_sport))) 887 ifq = &sp->pp_fastq; 888 else if (INTERACTIVE (ntohs (tcp->th_dport))) 889 ifq = &sp->pp_fastq; 890 891 /* 892 * Do IP Header compression 893 */ |
890 if (sp->pp_mode != IFF_CISCO && | 894 if (sp->pp_mode != IFF_CISCO && sp->pp_mode != PP_FR && |
891 (sp->ipcp.flags & IPCP_VJ) && ip->ip_p == IPPROTO_TCP) 892 switch (sl_compress_tcp(m, ip, sp->pp_comp, 893 sp->ipcp.compress_cid)) { 894 case TYPE_COMPRESSED_TCP: 895 ipproto = PPP_VJ_COMP; 896 break; 897 case TYPE_UNCOMPRESSED_TCP: 898 ipproto = PPP_VJ_UCOMP; --- 11 unchanged lines hidden (view full) --- 910#endif 911 912#ifdef INET6 913 if (dst->sa_family == AF_INET6) { 914 /* XXX do something tricky here? */ 915 } 916#endif 917 | 895 (sp->ipcp.flags & IPCP_VJ) && ip->ip_p == IPPROTO_TCP) 896 switch (sl_compress_tcp(m, ip, sp->pp_comp, 897 sp->ipcp.compress_cid)) { 898 case TYPE_COMPRESSED_TCP: 899 ipproto = PPP_VJ_COMP; 900 break; 901 case TYPE_UNCOMPRESSED_TCP: 902 ipproto = PPP_VJ_UCOMP; --- 11 unchanged lines hidden (view full) --- 914#endif 915 916#ifdef INET6 917 if (dst->sa_family == AF_INET6) { 918 /* XXX do something tricky here? */ 919 } 920#endif 921 |
922 if (sp->pp_mode == PP_FR) { 923 /* Add frame relay header. */ 924 m = sppp_fr_header (sp, m, dst->sa_family); 925 if (! m) 926 goto nobufs; 927 goto out; 928 } 929 |
|
918 /* 919 * Prepend general data packet PPP header. For now, IP only. 920 */ 921 M_PREPEND (m, PPP_HEADER_LEN, M_DONTWAIT); 922 if (! m) { | 930 /* 931 * Prepend general data packet PPP header. For now, IP only. 932 */ 933 M_PREPEND (m, PPP_HEADER_LEN, M_DONTWAIT); 934 if (! m) { |
923 if (debug) | 935nobufs: if (debug) |
924 log(LOG_DEBUG, SPP_FMT "no memory for transmit header\n", 925 SPP_ARGS(ifp)); 926 ++ifp->if_oerrors; 927 SPPP_UNLOCK(sp); 928 splx (s); 929 return (ENOBUFS); 930 } 931 /* --- 63 unchanged lines hidden (view full) --- 995 splx (s); 996 return (EAFNOSUPPORT); 997 } 998 999 /* 1000 * Queue message on interface, and start output if interface 1001 * not yet active. 1002 */ | 936 log(LOG_DEBUG, SPP_FMT "no memory for transmit header\n", 937 SPP_ARGS(ifp)); 938 ++ifp->if_oerrors; 939 SPPP_UNLOCK(sp); 940 splx (s); 941 return (ENOBUFS); 942 } 943 /* --- 63 unchanged lines hidden (view full) --- 1007 splx (s); 1008 return (EAFNOSUPPORT); 1009 } 1010 1011 /* 1012 * Queue message on interface, and start output if interface 1013 * not yet active. 1014 */ |
1015out: |
|
1003 if (ifq != NULL) 1004 error = !(IF_HANDOFF_ADJ(ifq, m, ifp, 3)); 1005 else 1006 IFQ_HANDOFF_ADJ(ifp, m, 3, error); 1007 if (error) { 1008 ++ifp->if_oerrors; 1009 SPPP_UNLOCK(sp); 1010 splx (s); --- 146 unchanged lines hidden (view full) --- 1157 /* 1158 * Process only the control protocol queue until we have at 1159 * least one NCP open. 1160 * 1161 * Do always serve all three queues in Cisco mode. 1162 */ 1163 IF_DEQUEUE(&sp->pp_cpq, m); 1164 if (m == NULL && | 1016 if (ifq != NULL) 1017 error = !(IF_HANDOFF_ADJ(ifq, m, ifp, 3)); 1018 else 1019 IFQ_HANDOFF_ADJ(ifp, m, 3, error); 1020 if (error) { 1021 ++ifp->if_oerrors; 1022 SPPP_UNLOCK(sp); 1023 splx (s); --- 146 unchanged lines hidden (view full) --- 1170 /* 1171 * Process only the control protocol queue until we have at 1172 * least one NCP open. 1173 * 1174 * Do always serve all three queues in Cisco mode. 1175 */ 1176 IF_DEQUEUE(&sp->pp_cpq, m); 1177 if (m == NULL && |
1165 (sppp_ncp_check(sp) || sp->pp_mode == IFF_CISCO)) { | 1178 (sppp_ncp_check(sp) || sp->pp_mode == IFF_CISCO || 1179 sp->pp_mode == PP_FR)) { |
1166 IF_DEQUEUE(&sp->pp_fastq, m); 1167 if (m == NULL) 1168 IF_DEQUEUE (&sp->pp_if.if_snd, m); 1169 } 1170 SPPP_UNLOCK(sp); 1171 splx(s); 1172 return m; 1173} --- 9 unchanged lines hidden (view full) --- 1183 int s; 1184 1185 s = splimp (); 1186 SPPP_LOCK(sp); 1187 1188 m = sp->pp_cpq.ifq_head; 1189 if (m == NULL && 1190 (sp->pp_phase == PHASE_NETWORK || | 1180 IF_DEQUEUE(&sp->pp_fastq, m); 1181 if (m == NULL) 1182 IF_DEQUEUE (&sp->pp_if.if_snd, m); 1183 } 1184 SPPP_UNLOCK(sp); 1185 splx(s); 1186 return m; 1187} --- 9 unchanged lines hidden (view full) --- 1197 int s; 1198 1199 s = splimp (); 1200 SPPP_LOCK(sp); 1201 1202 m = sp->pp_cpq.ifq_head; 1203 if (m == NULL && 1204 (sp->pp_phase == PHASE_NETWORK || |
1191 sp->pp_mode == IFF_CISCO)) | 1205 sp->pp_mode == IFF_CISCO || 1206 sp->pp_mode == PP_FR)) |
1192 if ((m = sp->pp_fastq.ifq_head) == NULL) 1193 m = sp->pp_if.if_snd.ifq_head; 1194 SPPP_UNLOCK(sp); 1195 splx (s); 1196 return (m); 1197} 1198 1199/* --- 28 unchanged lines hidden (view full) --- 1228 newmode = ifp->if_flags & IFF_PASSIVE; 1229 if (!newmode) 1230 newmode = ifp->if_flags & IFF_AUTO; 1231 if (!newmode) 1232 newmode = ifp->if_flags & IFF_CISCO; 1233 ifp->if_flags &= ~(IFF_PASSIVE | IFF_AUTO | IFF_CISCO); 1234 ifp->if_flags |= newmode; 1235 | 1207 if ((m = sp->pp_fastq.ifq_head) == NULL) 1208 m = sp->pp_if.if_snd.ifq_head; 1209 SPPP_UNLOCK(sp); 1210 splx (s); 1211 return (m); 1212} 1213 1214/* --- 28 unchanged lines hidden (view full) --- 1243 newmode = ifp->if_flags & IFF_PASSIVE; 1244 if (!newmode) 1245 newmode = ifp->if_flags & IFF_AUTO; 1246 if (!newmode) 1247 newmode = ifp->if_flags & IFF_CISCO; 1248 ifp->if_flags &= ~(IFF_PASSIVE | IFF_AUTO | IFF_CISCO); 1249 ifp->if_flags |= newmode; 1250 |
1251 if (!newmode) 1252 newmode = sp->pp_flags & PP_FR; 1253 |
|
1236 if (newmode != sp->pp_mode) { 1237 going_down = 1; 1238 if (!going_up) 1239 going_up = ifp->if_flags & IFF_RUNNING; 1240 } 1241 1242 if (going_down) { | 1254 if (newmode != sp->pp_mode) { 1255 going_down = 1; 1256 if (!going_up) 1257 going_up = ifp->if_flags & IFF_RUNNING; 1258 } 1259 1260 if (going_down) { |
1243 if (sp->pp_mode != IFF_CISCO) | 1261 if (sp->pp_mode != IFF_CISCO && 1262 sp->pp_mode != PP_FR) |
1244 lcp.Close(sp); 1245 else if (sp->pp_tlf) 1246 (sp->pp_tlf)(sp); 1247 sppp_flush_unlocked(ifp); 1248 ifp->if_flags &= ~IFF_RUNNING; 1249 sp->pp_mode = newmode; 1250 } 1251 1252 if (going_up) { | 1263 lcp.Close(sp); 1264 else if (sp->pp_tlf) 1265 (sp->pp_tlf)(sp); 1266 sppp_flush_unlocked(ifp); 1267 ifp->if_flags &= ~IFF_RUNNING; 1268 sp->pp_mode = newmode; 1269 } 1270 1271 if (going_up) { |
1253 if (sp->pp_mode != IFF_CISCO) | 1272 if (sp->pp_mode != IFF_CISCO && 1273 sp->pp_mode != PP_FR) |
1254 lcp.Close(sp); 1255 sp->pp_mode = newmode; 1256 if (sp->pp_mode == 0) { 1257 ifp->if_flags |= IFF_RUNNING; 1258 lcp.Open(sp); 1259 } | 1274 lcp.Close(sp); 1275 sp->pp_mode = newmode; 1276 if (sp->pp_mode == 0) { 1277 ifp->if_flags |= IFF_RUNNING; 1278 lcp.Open(sp); 1279 } |
1260 if (sp->pp_mode == IFF_CISCO) { | 1280 if ((sp->pp_mode == IFF_CISCO) || 1281 (sp->pp_mode == PP_FR)) { |
1261 if (sp->pp_tls) 1262 (sp->pp_tls)(sp); 1263 ifp->if_flags |= IFF_RUNNING; 1264 } 1265 } 1266 1267 break; 1268 --- 3495 unchanged lines hidden (view full) --- 4764 4765 s = splimp(); 4766 SPPP_LOCK(sp); 4767 /* Keepalive mode disabled or channel down? */ 4768 if (! (sp->pp_flags & PP_KEEPALIVE) || 4769 ! (ifp->if_flags & IFF_RUNNING)) 4770 goto out; 4771 | 1282 if (sp->pp_tls) 1283 (sp->pp_tls)(sp); 1284 ifp->if_flags |= IFF_RUNNING; 1285 } 1286 } 1287 1288 break; 1289 --- 3495 unchanged lines hidden (view full) --- 4785 4786 s = splimp(); 4787 SPPP_LOCK(sp); 4788 /* Keepalive mode disabled or channel down? */ 4789 if (! (sp->pp_flags & PP_KEEPALIVE) || 4790 ! (ifp->if_flags & IFF_RUNNING)) 4791 goto out; 4792 |
4793 if (sp->pp_mode == PP_FR) { 4794 sppp_fr_keepalive (sp); 4795 goto out; 4796 } 4797 |
|
4772 /* No keepalive in PPP mode if LCP not opened yet. */ 4773 if (sp->pp_mode != IFF_CISCO && 4774 sp->pp_phase < PHASE_AUTHENTICATE) 4775 goto out; 4776 4777 if (sp->pp_alivecnt == MAXALIVECNT) { 4778 /* No keepalive packets got. Stop the interface. */ 4779 printf (SPP_FMT "down\n", SPP_ARGS(ifp)); --- 23 unchanged lines hidden (view full) --- 4803 splx(s); 4804 callout_reset(&sp->keepalive_callout, hz * 10, sppp_keepalive, 4805 (void *)sp); 4806} 4807 4808/* 4809 * Get both IP addresses. 4810 */ | 4798 /* No keepalive in PPP mode if LCP not opened yet. */ 4799 if (sp->pp_mode != IFF_CISCO && 4800 sp->pp_phase < PHASE_AUTHENTICATE) 4801 goto out; 4802 4803 if (sp->pp_alivecnt == MAXALIVECNT) { 4804 /* No keepalive packets got. Stop the interface. */ 4805 printf (SPP_FMT "down\n", SPP_ARGS(ifp)); --- 23 unchanged lines hidden (view full) --- 4829 splx(s); 4830 callout_reset(&sp->keepalive_callout, hz * 10, sppp_keepalive, 4831 (void *)sp); 4832} 4833 4834/* 4835 * Get both IP addresses. 4836 */ |
4811static void | 4837void |
4812sppp_get_ip_addrs(struct sppp *sp, u_long *src, u_long *dst, u_long *srcmask) 4813{ 4814 struct ifnet *ifp = &sp->pp_if; 4815 struct ifaddr *ifa; 4816 struct sockaddr_in *si, *sm; 4817 u_long ssrc, ddst; 4818 4819 sm = NULL; --- 629 unchanged lines hidden --- | 4838sppp_get_ip_addrs(struct sppp *sp, u_long *src, u_long *dst, u_long *srcmask) 4839{ 4840 struct ifnet *ifp = &sp->pp_if; 4841 struct ifaddr *ifa; 4842 struct sockaddr_in *si, *sm; 4843 u_long ssrc, ddst; 4844 4845 sm = NULL; --- 629 unchanged lines hidden --- |