if_spppsubr.c (148385) | if_spppsubr.c (148887) |
---|---|
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 148385 2005-07-25 12:31:43Z ume $ | 21 * $FreeBSD: head/sys/net/if_spppsubr.c 148887 2005-08-09 10:20:02Z rwatson $ |
22 */ 23 24#include <sys/param.h> 25 26#if defined(__FreeBSD__) && __FreeBSD__ >= 3 27#include "opt_inet.h" 28#include "opt_inet6.h" 29#include "opt_ipx.h" --- 804 unchanged lines hidden (view full) --- 834 struct ifqueue *ifq = NULL; 835 int s, error, rv = 0; 836 int ipproto = PPP_IP; 837 int debug = ifp->if_flags & IFF_DEBUG; 838 839 s = splimp(); 840 SPPP_LOCK(sp); 841 | 22 */ 23 24#include <sys/param.h> 25 26#if defined(__FreeBSD__) && __FreeBSD__ >= 3 27#include "opt_inet.h" 28#include "opt_inet6.h" 29#include "opt_ipx.h" --- 804 unchanged lines hidden (view full) --- 834 struct ifqueue *ifq = NULL; 835 int s, error, rv = 0; 836 int ipproto = PPP_IP; 837 int debug = ifp->if_flags & IFF_DEBUG; 838 839 s = splimp(); 840 SPPP_LOCK(sp); 841 |
842 if ((ifp->if_flags & IFF_UP) == 0 || 843 (ifp->if_flags & (IFF_RUNNING | IFF_AUTO)) == 0) { | 842 if (!(ifp->if_flags & IFF_UP) || 843 (!(ifp->if_flags & IFF_AUTO) && 844 !(ifp->if_drv_flags & IFF_DRV_RUNNING))) { |
844#ifdef INET6 845 drop: 846#endif 847 m_freem (m); 848 SPPP_UNLOCK(sp); 849 splx (s); 850 return (ENETDOWN); 851 } 852 | 845#ifdef INET6 846 drop: 847#endif 848 m_freem (m); 849 SPPP_UNLOCK(sp); 850 splx (s); 851 return (ENETDOWN); 852 } 853 |
853 if ((ifp->if_flags & (IFF_RUNNING | IFF_AUTO)) == IFF_AUTO) { | 854 if ((ifp->if_flags & IFF_AUTO) && 855 !(ifp->if_drv_flags & IFF_DRV_RUNNING)) { |
854#ifdef INET6 855 /* 856 * XXX 857 * 858 * Hack to prevent the initialization-time generated 859 * IPv6 multicast packet to erroneously cause a 860 * dialout event in case IPv6 has been 861 * administratively disabled on that interface. 862 */ 863 if (dst->sa_family == AF_INET6 && 864 !(sp->confflags & CONF_ENABLE_IPV6)) 865 goto drop; 866#endif 867 /* 868 * Interface is not yet running, but auto-dial. Need 869 * to start LCP for it. 870 */ | 856#ifdef INET6 857 /* 858 * XXX 859 * 860 * Hack to prevent the initialization-time generated 861 * IPv6 multicast packet to erroneously cause a 862 * dialout event in case IPv6 has been 863 * administratively disabled on that interface. 864 */ 865 if (dst->sa_family == AF_INET6 && 866 !(sp->confflags & CONF_ENABLE_IPV6)) 867 goto drop; 868#endif 869 /* 870 * Interface is not yet running, but auto-dial. Need 871 * to start LCP for it. 872 */ |
871 ifp->if_flags |= IFF_RUNNING; | 873 ifp->if_drv_flags |= IFF_DRV_RUNNING; |
872 splx(s); 873 lcp.Open(sp); 874 s = splimp(); 875 } 876 877#ifdef INET 878 if (dst->sa_family == AF_INET) { 879 /* XXX Check mbuf length here? */ --- 383 unchanged lines hidden (view full) --- 1263 1264 case SIOCSIFADDR: 1265 /* set the interface "up" when assigning an IP address */ 1266 ifp->if_flags |= IFF_UP; 1267 /* FALLTHROUGH */ 1268 1269 case SIOCSIFFLAGS: 1270 going_up = ifp->if_flags & IFF_UP && | 874 splx(s); 875 lcp.Open(sp); 876 s = splimp(); 877 } 878 879#ifdef INET 880 if (dst->sa_family == AF_INET) { 881 /* XXX Check mbuf length here? */ --- 383 unchanged lines hidden (view full) --- 1265 1266 case SIOCSIFADDR: 1267 /* set the interface "up" when assigning an IP address */ 1268 ifp->if_flags |= IFF_UP; 1269 /* FALLTHROUGH */ 1270 1271 case SIOCSIFFLAGS: 1272 going_up = ifp->if_flags & IFF_UP && |
1271 (ifp->if_flags & IFF_RUNNING) == 0; | 1273 (ifp->if_drv_flags & IFF_DRV_RUNNING) == 0; |
1272 going_down = (ifp->if_flags & IFF_UP) == 0 && | 1274 going_down = (ifp->if_flags & IFF_UP) == 0 && |
1273 ifp->if_flags & IFF_RUNNING; | 1275 ifp->if_drv_flags & IFF_DRV_RUNNING; |
1274 1275 newmode = ifp->if_flags & IFF_PASSIVE; 1276 if (!newmode) 1277 newmode = ifp->if_flags & IFF_AUTO; 1278 if (!newmode) 1279 newmode = ifp->if_flags & IFF_CISCO; 1280 ifp->if_flags &= ~(IFF_PASSIVE | IFF_AUTO | IFF_CISCO); 1281 ifp->if_flags |= newmode; 1282 1283 if (!newmode) 1284 newmode = sp->pp_flags & PP_FR; 1285 1286 if (newmode != sp->pp_mode) { 1287 going_down = 1; 1288 if (!going_up) | 1276 1277 newmode = ifp->if_flags & IFF_PASSIVE; 1278 if (!newmode) 1279 newmode = ifp->if_flags & IFF_AUTO; 1280 if (!newmode) 1281 newmode = ifp->if_flags & IFF_CISCO; 1282 ifp->if_flags &= ~(IFF_PASSIVE | IFF_AUTO | IFF_CISCO); 1283 ifp->if_flags |= newmode; 1284 1285 if (!newmode) 1286 newmode = sp->pp_flags & PP_FR; 1287 1288 if (newmode != sp->pp_mode) { 1289 going_down = 1; 1290 if (!going_up) |
1289 going_up = ifp->if_flags & IFF_RUNNING; | 1291 going_up = ifp->if_drv_flags & IFF_DRV_RUNNING; |
1290 } 1291 1292 if (going_down) { 1293 if (sp->pp_mode != IFF_CISCO && 1294 sp->pp_mode != PP_FR) 1295 lcp.Close(sp); 1296 else if (sp->pp_tlf) 1297 (sp->pp_tlf)(sp); 1298 sppp_flush_unlocked(ifp); | 1292 } 1293 1294 if (going_down) { 1295 if (sp->pp_mode != IFF_CISCO && 1296 sp->pp_mode != PP_FR) 1297 lcp.Close(sp); 1298 else if (sp->pp_tlf) 1299 (sp->pp_tlf)(sp); 1300 sppp_flush_unlocked(ifp); |
1299 ifp->if_flags &= ~IFF_RUNNING; | 1301 ifp->if_drv_flags &= ~IFF_DRV_RUNNING; |
1300 sp->pp_mode = newmode; 1301 } 1302 1303 if (going_up) { 1304 if (sp->pp_mode != IFF_CISCO && 1305 sp->pp_mode != PP_FR) 1306 lcp.Close(sp); 1307 sp->pp_mode = newmode; 1308 if (sp->pp_mode == 0) { | 1302 sp->pp_mode = newmode; 1303 } 1304 1305 if (going_up) { 1306 if (sp->pp_mode != IFF_CISCO && 1307 sp->pp_mode != PP_FR) 1308 lcp.Close(sp); 1309 sp->pp_mode = newmode; 1310 if (sp->pp_mode == 0) { |
1309 ifp->if_flags |= IFF_RUNNING; | 1311 ifp->if_drv_flags |= IFF_DRV_RUNNING; |
1310 lcp.Open(sp); 1311 } 1312 if ((sp->pp_mode == IFF_CISCO) || 1313 (sp->pp_mode == PP_FR)) { 1314 if (sp->pp_tls) 1315 (sp->pp_tls)(sp); | 1312 lcp.Open(sp); 1313 } 1314 if ((sp->pp_mode == IFF_CISCO) || 1315 (sp->pp_mode == PP_FR)) { 1316 if (sp->pp_tls) 1317 (sp->pp_tls)(sp); |
1316 ifp->if_flags |= IFF_RUNNING; | 1318 ifp->if_drv_flags |= IFF_DRV_RUNNING; |
1317 } 1318 } 1319 1320 break; 1321 1322#ifdef SIOCSIFMTU 1323#ifndef ifr_mtu 1324#define ifr_mtu ifr_metric --- 98 unchanged lines hidden (view full) --- 1423 sp->pp_seq[IDX_LCP] = random(); 1424#else 1425 sp->pp_seq[IDX_LCP] ^= time.tv_sec ^ time.tv_usec; 1426#endif 1427 break; 1428 } 1429 sp->pp_loopcnt = 0; 1430 if (! (ifp->if_flags & IFF_UP) && | 1319 } 1320 } 1321 1322 break; 1323 1324#ifdef SIOCSIFMTU 1325#ifndef ifr_mtu 1326#define ifr_mtu ifr_metric --- 98 unchanged lines hidden (view full) --- 1425 sp->pp_seq[IDX_LCP] = random(); 1426#else 1427 sp->pp_seq[IDX_LCP] ^= time.tv_sec ^ time.tv_usec; 1428#endif 1429 break; 1430 } 1431 sp->pp_loopcnt = 0; 1432 if (! (ifp->if_flags & IFF_UP) && |
1431 (ifp->if_flags & IFF_RUNNING)) { | 1433 (ifp->if_drv_flags & IFF_DRV_RUNNING)) { |
1432 if_up(ifp); 1433 printf (SPP_FMT "up\n", SPP_ARGS(ifp)); 1434 } 1435 break; 1436 case CISCO_ADDR_REQ: 1437 sppp_get_ip_addrs(sp, &me, 0, &mymask); 1438 if (me != 0L) 1439 sppp_cisco_send(sp, CISCO_ADDR_REPLY, me, mymask); --- 823 unchanged lines hidden (view full) --- 2263 * If this interface is passive or dial-on-demand, and we are 2264 * still in Initial state, it means we've got an incoming 2265 * call. Activate the interface. 2266 */ 2267 if ((ifp->if_flags & (IFF_AUTO | IFF_PASSIVE)) != 0) { 2268 if (debug) 2269 log(LOG_DEBUG, 2270 SPP_FMT "Up event", SPP_ARGS(ifp)); | 1434 if_up(ifp); 1435 printf (SPP_FMT "up\n", SPP_ARGS(ifp)); 1436 } 1437 break; 1438 case CISCO_ADDR_REQ: 1439 sppp_get_ip_addrs(sp, &me, 0, &mymask); 1440 if (me != 0L) 1441 sppp_cisco_send(sp, CISCO_ADDR_REPLY, me, mymask); --- 823 unchanged lines hidden (view full) --- 2265 * If this interface is passive or dial-on-demand, and we are 2266 * still in Initial state, it means we've got an incoming 2267 * call. Activate the interface. 2268 */ 2269 if ((ifp->if_flags & (IFF_AUTO | IFF_PASSIVE)) != 0) { 2270 if (debug) 2271 log(LOG_DEBUG, 2272 SPP_FMT "Up event", SPP_ARGS(ifp)); |
2271 ifp->if_flags |= IFF_RUNNING; | 2273 ifp->if_drv_flags |= IFF_DRV_RUNNING; |
2272 if (sp->state[IDX_LCP] == STATE_INITIAL) { 2273 if (debug) 2274 log(-1, "(incoming call)\n"); 2275 sp->pp_flags |= PP_CALLIN; 2276 lcp.Open(sp); 2277 } else if (debug) 2278 log(-1, "\n"); 2279 } else if ((ifp->if_flags & (IFF_AUTO | IFF_PASSIVE)) == 0 && 2280 (sp->state[IDX_LCP] == STATE_INITIAL)) { | 2274 if (sp->state[IDX_LCP] == STATE_INITIAL) { 2275 if (debug) 2276 log(-1, "(incoming call)\n"); 2277 sp->pp_flags |= PP_CALLIN; 2278 lcp.Open(sp); 2279 } else if (debug) 2280 log(-1, "\n"); 2281 } else if ((ifp->if_flags & (IFF_AUTO | IFF_PASSIVE)) == 0 && 2282 (sp->state[IDX_LCP] == STATE_INITIAL)) { |
2281 ifp->if_flags |= IFF_RUNNING; | 2283 ifp->if_drv_flags |= IFF_DRV_RUNNING; |
2282 lcp.Open(sp); 2283 } 2284 2285 sppp_up_event(&lcp, sp); 2286} 2287 2288static void 2289sppp_lcp_down(struct sppp *sp) --- 17 unchanged lines hidden (view full) --- 2307 } else { 2308 if (debug) 2309 log(LOG_DEBUG, 2310 SPP_FMT "Down event (carrier loss)\n", 2311 SPP_ARGS(ifp)); 2312 sp->pp_flags &= ~PP_CALLIN; 2313 if (sp->state[IDX_LCP] != STATE_INITIAL) 2314 lcp.Close(sp); | 2284 lcp.Open(sp); 2285 } 2286 2287 sppp_up_event(&lcp, sp); 2288} 2289 2290static void 2291sppp_lcp_down(struct sppp *sp) --- 17 unchanged lines hidden (view full) --- 2309 } else { 2310 if (debug) 2311 log(LOG_DEBUG, 2312 SPP_FMT "Down event (carrier loss)\n", 2313 SPP_ARGS(ifp)); 2314 sp->pp_flags &= ~PP_CALLIN; 2315 if (sp->state[IDX_LCP] != STATE_INITIAL) 2316 lcp.Close(sp); |
2315 ifp->if_flags &= ~IFF_RUNNING; | 2317 ifp->if_drv_flags &= ~IFF_DRV_RUNNING; |
2316 } 2317} 2318 2319static void 2320sppp_lcp_open(struct sppp *sp) 2321{ 2322 sppp_open_event(&lcp, sp); 2323} --- 389 unchanged lines hidden (view full) --- 2713sppp_lcp_tlu(struct sppp *sp) 2714{ 2715 STDDCL; 2716 int i; 2717 u_long mask; 2718 2719 /* XXX ? */ 2720 if (! (ifp->if_flags & IFF_UP) && | 2318 } 2319} 2320 2321static void 2322sppp_lcp_open(struct sppp *sp) 2323{ 2324 sppp_open_event(&lcp, sp); 2325} --- 389 unchanged lines hidden (view full) --- 2715sppp_lcp_tlu(struct sppp *sp) 2716{ 2717 STDDCL; 2718 int i; 2719 u_long mask; 2720 2721 /* XXX ? */ 2722 if (! (ifp->if_flags & IFF_UP) && |
2721 (ifp->if_flags & IFF_RUNNING)) { | 2723 (ifp->if_drv_flags & IFF_DRV_RUNNING)) { |
2722 /* Coming out of loopback mode. */ 2723 if_up(ifp); 2724 printf (SPP_FMT "up\n", SPP_ARGS(ifp)); 2725 } 2726 2727 for (i = 0; i < IDX_COUNT; i++) 2728 if ((cps[i])->flags & CP_QUAL) 2729 (cps[i])->Open(sp); --- 2084 unchanged lines hidden (view full) --- 4814 struct sppp *sp = (struct sppp*)dummy; 4815 struct ifnet *ifp = SP2IFP(sp); 4816 int s; 4817 4818 s = splimp(); 4819 SPPP_LOCK(sp); 4820 /* Keepalive mode disabled or channel down? */ 4821 if (! (sp->pp_flags & PP_KEEPALIVE) || | 2724 /* Coming out of loopback mode. */ 2725 if_up(ifp); 2726 printf (SPP_FMT "up\n", SPP_ARGS(ifp)); 2727 } 2728 2729 for (i = 0; i < IDX_COUNT; i++) 2730 if ((cps[i])->flags & CP_QUAL) 2731 (cps[i])->Open(sp); --- 2084 unchanged lines hidden (view full) --- 4816 struct sppp *sp = (struct sppp*)dummy; 4817 struct ifnet *ifp = SP2IFP(sp); 4818 int s; 4819 4820 s = splimp(); 4821 SPPP_LOCK(sp); 4822 /* Keepalive mode disabled or channel down? */ 4823 if (! (sp->pp_flags & PP_KEEPALIVE) || |
4822 ! (ifp->if_flags & IFF_RUNNING)) | 4824 ! (ifp->if_drv_flags & IFF_DRV_RUNNING)) |
4823 goto out; 4824 4825 if (sp->pp_mode == PP_FR) { 4826 sppp_fr_keepalive (sp); 4827 goto out; 4828 } 4829 4830 /* No keepalive in PPP mode if LCP not opened yet. */ --- 676 unchanged lines hidden --- | 4825 goto out; 4826 4827 if (sp->pp_mode == PP_FR) { 4828 sppp_fr_keepalive (sp); 4829 goto out; 4830 } 4831 4832 /* No keepalive in PPP mode if LCP not opened yet. */ --- 676 unchanged lines hidden --- |