if_spppsubr.c (183550) | if_spppsubr.c (184682) |
---|---|
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 183550 2008-10-02 15:37:58Z zec $ | 21 * $FreeBSD: head/sys/net/if_spppsubr.c 184682 2008-11-05 12:02:25Z bz $ |
22 */ 23 24#include <sys/param.h> 25 26#include "opt_inet.h" 27#include "opt_inet6.h" 28#include "opt_ipx.h" 29 --- 337 unchanged lines hidden (view full) --- 367static void sppp_chap_close(struct sppp *sp); 368static void sppp_chap_TO(void *sp); 369static void sppp_chap_tlu(struct sppp *sp); 370static void sppp_chap_tld(struct sppp *sp); 371static void sppp_chap_scr(struct sppp *sp); 372 373static const char *sppp_auth_type_name(u_short proto, u_char type); 374static const char *sppp_cp_type_name(u_char type); | 22 */ 23 24#include <sys/param.h> 25 26#include "opt_inet.h" 27#include "opt_inet6.h" 28#include "opt_ipx.h" 29 --- 337 unchanged lines hidden (view full) --- 367static void sppp_chap_close(struct sppp *sp); 368static void sppp_chap_TO(void *sp); 369static void sppp_chap_tlu(struct sppp *sp); 370static void sppp_chap_tld(struct sppp *sp); 371static void sppp_chap_scr(struct sppp *sp); 372 373static const char *sppp_auth_type_name(u_short proto, u_char type); 374static const char *sppp_cp_type_name(u_char type); |
375#ifdef INET |
|
375static const char *sppp_dotted_quad(u_long addr); 376static const char *sppp_ipcp_opt_name(u_char opt); | 376static const char *sppp_dotted_quad(u_long addr); 377static const char *sppp_ipcp_opt_name(u_char opt); |
378#endif |
|
377#ifdef INET6 378static const char *sppp_ipv6cp_opt_name(u_char opt); 379#endif 380static const char *sppp_lcp_opt_name(u_char opt); 381static const char *sppp_phase_name(enum ppp_phase phase); 382static const char *sppp_proto_name(u_short proto); 383static const char *sppp_state_name(int state); 384static int sppp_params(struct sppp *sp, u_long cmd, void *data); 385static int sppp_strnlen(u_char *p, int max); 386static void sppp_keepalive(void *dummy); 387static void sppp_phase_network(struct sppp *sp); 388static void sppp_print_bytes(const u_char *p, u_short len); 389static void sppp_print_string(const char *p, u_short len); 390static void sppp_qflush(struct ifqueue *ifq); | 379#ifdef INET6 380static const char *sppp_ipv6cp_opt_name(u_char opt); 381#endif 382static const char *sppp_lcp_opt_name(u_char opt); 383static const char *sppp_phase_name(enum ppp_phase phase); 384static const char *sppp_proto_name(u_short proto); 385static const char *sppp_state_name(int state); 386static int sppp_params(struct sppp *sp, u_long cmd, void *data); 387static int sppp_strnlen(u_char *p, int max); 388static void sppp_keepalive(void *dummy); 389static void sppp_phase_network(struct sppp *sp); 390static void sppp_print_bytes(const u_char *p, u_short len); 391static void sppp_print_string(const char *p, u_short len); 392static void sppp_qflush(struct ifqueue *ifq); |
393#ifdef INET |
|
391static void sppp_set_ip_addr(struct sppp *sp, u_long src); | 394static void sppp_set_ip_addr(struct sppp *sp, u_long src); |
395#endif |
|
392#ifdef INET6 393static void sppp_get_ip6_addrs(struct sppp *sp, struct in6_addr *src, 394 struct in6_addr *dst, struct in6_addr *srcmask); 395#ifdef IPV6CP_MYIFID_DYN 396static void sppp_set_ip6_addr(struct sppp *sp, const struct in6_addr *src); 397static void sppp_gen_ip6_addr(struct sppp *sp, const struct in6_addr *src); 398#endif 399static void sppp_suggest_ip6_addr(struct sppp *sp, struct in6_addr *src); --- 118 unchanged lines hidden (view full) --- 518 * Process the received packet. 519 */ 520void 521sppp_input(struct ifnet *ifp, struct mbuf *m) 522{ 523 struct ppp_header *h; 524 int isr = -1; 525 struct sppp *sp = IFP2SP(ifp); | 396#ifdef INET6 397static void sppp_get_ip6_addrs(struct sppp *sp, struct in6_addr *src, 398 struct in6_addr *dst, struct in6_addr *srcmask); 399#ifdef IPV6CP_MYIFID_DYN 400static void sppp_set_ip6_addr(struct sppp *sp, const struct in6_addr *src); 401static void sppp_gen_ip6_addr(struct sppp *sp, const struct in6_addr *src); 402#endif 403static void sppp_suggest_ip6_addr(struct sppp *sp, struct in6_addr *src); --- 118 unchanged lines hidden (view full) --- 522 * Process the received packet. 523 */ 524void 525sppp_input(struct ifnet *ifp, struct mbuf *m) 526{ 527 struct ppp_header *h; 528 int isr = -1; 529 struct sppp *sp = IFP2SP(ifp); |
530 int debug, do_account = 0; 531#ifdef INET 532 int hlen, vjlen; |
|
526 u_char *iphdr; | 533 u_char *iphdr; |
527 int hlen, vjlen, do_account = 0; 528 int debug; | 534#endif |
529 530 SPPP_LOCK(sp); 531 debug = ifp->if_flags & IFF_DEBUG; 532 533 if (ifp->if_flags & IFF_UP) 534 /* Count received bytes, add FCS and one flag */ 535 ifp->if_ibytes += m->m_pkthdr.len + 3; 536 --- 258 unchanged lines hidden (view full) --- 795static int 796sppp_output(struct ifnet *ifp, struct mbuf *m, 797 struct sockaddr *dst, struct rtentry *rt) 798{ 799 struct sppp *sp = IFP2SP(ifp); 800 struct ppp_header *h; 801 struct ifqueue *ifq = NULL; 802 int s, error, rv = 0; | 535 536 SPPP_LOCK(sp); 537 debug = ifp->if_flags & IFF_DEBUG; 538 539 if (ifp->if_flags & IFF_UP) 540 /* Count received bytes, add FCS and one flag */ 541 ifp->if_ibytes += m->m_pkthdr.len + 3; 542 --- 258 unchanged lines hidden (view full) --- 801static int 802sppp_output(struct ifnet *ifp, struct mbuf *m, 803 struct sockaddr *dst, struct rtentry *rt) 804{ 805 struct sppp *sp = IFP2SP(ifp); 806 struct ppp_header *h; 807 struct ifqueue *ifq = NULL; 808 int s, error, rv = 0; |
809#ifdef INET |
|
803 int ipproto = PPP_IP; | 810 int ipproto = PPP_IP; |
811#endif |
|
804 int debug = ifp->if_flags & IFF_DEBUG; 805 806 s = splimp(); 807 SPPP_LOCK(sp); 808 809 if (!(ifp->if_flags & IFF_UP) || 810 (!(ifp->if_flags & IFF_AUTO) && 811 !(ifp->if_drv_flags & IFF_DRV_RUNNING))) { --- 2067 unchanged lines hidden (view full) --- 2879/* 2880 *--------------------------------------------------------------------------* 2881 * * 2882 * The IPCP implementation. * 2883 * * 2884 *--------------------------------------------------------------------------* 2885 */ 2886 | 812 int debug = ifp->if_flags & IFF_DEBUG; 813 814 s = splimp(); 815 SPPP_LOCK(sp); 816 817 if (!(ifp->if_flags & IFF_UP) || 818 (!(ifp->if_flags & IFF_AUTO) && 819 !(ifp->if_drv_flags & IFF_DRV_RUNNING))) { --- 2067 unchanged lines hidden (view full) --- 2887/* 2888 *--------------------------------------------------------------------------* 2889 * * 2890 * The IPCP implementation. * 2891 * * 2892 *--------------------------------------------------------------------------* 2893 */ 2894 |
2895#ifdef INET |
|
2887static void 2888sppp_ipcp_init(struct sppp *sp) 2889{ 2890 sp->ipcp.opts = 0; 2891 sp->ipcp.flags = 0; 2892 sp->state[IDX_IPCP] = STATE_INITIAL; 2893 sp->fail_counter[IDX_IPCP] = 0; 2894 sp->pp_seq[IDX_IPCP] = 0; --- 462 unchanged lines hidden (view full) --- 3357 opt[i++] = ouraddr >> 16; 3358 opt[i++] = ouraddr >> 8; 3359 opt[i++] = ouraddr; 3360 } 3361 3362 sp->confid[IDX_IPCP] = ++sp->pp_seq[IDX_IPCP]; 3363 sppp_cp_send(sp, PPP_IPCP, CONF_REQ, sp->confid[IDX_IPCP], i, &opt); 3364} | 2896static void 2897sppp_ipcp_init(struct sppp *sp) 2898{ 2899 sp->ipcp.opts = 0; 2900 sp->ipcp.flags = 0; 2901 sp->state[IDX_IPCP] = STATE_INITIAL; 2902 sp->fail_counter[IDX_IPCP] = 0; 2903 sp->pp_seq[IDX_IPCP] = 0; --- 462 unchanged lines hidden (view full) --- 3366 opt[i++] = ouraddr >> 16; 3367 opt[i++] = ouraddr >> 8; 3368 opt[i++] = ouraddr; 3369 } 3370 3371 sp->confid[IDX_IPCP] = ++sp->pp_seq[IDX_IPCP]; 3372 sppp_cp_send(sp, PPP_IPCP, CONF_REQ, sp->confid[IDX_IPCP], i, &opt); 3373} |
3374#else /* !INET */ 3375static void 3376sppp_ipcp_init(struct sppp *sp) 3377{ 3378} |
|
3365 | 3379 |
3380static void 3381sppp_ipcp_up(struct sppp *sp) 3382{ 3383} 3384 3385static void 3386sppp_ipcp_down(struct sppp *sp) 3387{ 3388} 3389 3390static void 3391sppp_ipcp_open(struct sppp *sp) 3392{ 3393} 3394 3395static void 3396sppp_ipcp_close(struct sppp *sp) 3397{ 3398} 3399 3400static void 3401sppp_ipcp_TO(void *cookie) 3402{ 3403} 3404 3405static int 3406sppp_ipcp_RCR(struct sppp *sp, struct lcp_header *h, int len) 3407{ 3408 return (0); 3409} 3410 3411static void 3412sppp_ipcp_RCN_rej(struct sppp *sp, struct lcp_header *h, int len) 3413{ 3414} 3415 3416static void 3417sppp_ipcp_RCN_nak(struct sppp *sp, struct lcp_header *h, int len) 3418{ 3419} 3420 3421static void 3422sppp_ipcp_tlu(struct sppp *sp) 3423{ 3424} 3425 3426static void 3427sppp_ipcp_tld(struct sppp *sp) 3428{ 3429} 3430 3431static void 3432sppp_ipcp_tls(struct sppp *sp) 3433{ 3434} 3435 3436static void 3437sppp_ipcp_tlf(struct sppp *sp) 3438{ 3439} 3440 3441static void 3442sppp_ipcp_scr(struct sppp *sp) 3443{ 3444} 3445#endif 3446 |
|
3366/* 3367 *--------------------------------------------------------------------------* 3368 * * 3369 * The IPv6CP implementation. * 3370 * * 3371 *--------------------------------------------------------------------------* 3372 */ 3373 --- 1490 unchanged lines hidden (view full) --- 4864 if (si && si->sin_addr.s_addr) 4865 ddst = si->sin_addr.s_addr; 4866 } 4867 4868 if (dst) *dst = ntohl(ddst); 4869 if (src) *src = ntohl(ssrc); 4870} 4871 | 3447/* 3448 *--------------------------------------------------------------------------* 3449 * * 3450 * The IPv6CP implementation. * 3451 * * 3452 *--------------------------------------------------------------------------* 3453 */ 3454 --- 1490 unchanged lines hidden (view full) --- 4945 if (si && si->sin_addr.s_addr) 4946 ddst = si->sin_addr.s_addr; 4947 } 4948 4949 if (dst) *dst = ntohl(ddst); 4950 if (src) *src = ntohl(ssrc); 4951} 4952 |
4953#ifdef INET |
|
4872/* 4873 * Set my IP address. Must be called at splimp. 4874 */ 4875static void 4876sppp_set_ip_addr(struct sppp *sp, u_long src) 4877{ 4878 INIT_VNET_INET(curvnet); 4879 STDDCL; --- 37 unchanged lines hidden (view full) --- 4917 error = rtinit(ifa, (int)RTM_ADD, RTF_HOST); 4918 if (debug && error) 4919 { 4920 log(LOG_DEBUG, SPP_FMT "sppp_set_ip_addr: rtinit ADD failed, error=%d", 4921 SPP_ARGS(ifp), error); 4922 } 4923 } 4924} | 4954/* 4955 * Set my IP address. Must be called at splimp. 4956 */ 4957static void 4958sppp_set_ip_addr(struct sppp *sp, u_long src) 4959{ 4960 INIT_VNET_INET(curvnet); 4961 STDDCL; --- 37 unchanged lines hidden (view full) --- 4999 error = rtinit(ifa, (int)RTM_ADD, RTF_HOST); 5000 if (debug && error) 5001 { 5002 log(LOG_DEBUG, SPP_FMT "sppp_set_ip_addr: rtinit ADD failed, error=%d", 5003 SPP_ARGS(ifp), error); 5004 } 5005 } 5006} |
5007#endif |
|
4925 4926#ifdef INET6 4927/* 4928 * Get both IPv6 addresses. 4929 */ 4930static void 4931sppp_get_ip6_addrs(struct sppp *sp, struct in6_addr *src, struct in6_addr *dst, 4932 struct in6_addr *srcmask) --- 354 unchanged lines hidden (view full) --- 5287 case LCP_OPT_MAGIC: return "magic"; 5288 case LCP_OPT_PROTO_COMP: return "proto-comp"; 5289 case LCP_OPT_ADDR_COMP: return "addr-comp"; 5290 } 5291 snprintf (buf, sizeof(buf), "lcp/0x%x", opt); 5292 return buf; 5293} 5294 | 5008 5009#ifdef INET6 5010/* 5011 * Get both IPv6 addresses. 5012 */ 5013static void 5014sppp_get_ip6_addrs(struct sppp *sp, struct in6_addr *src, struct in6_addr *dst, 5015 struct in6_addr *srcmask) --- 354 unchanged lines hidden (view full) --- 5370 case LCP_OPT_MAGIC: return "magic"; 5371 case LCP_OPT_PROTO_COMP: return "proto-comp"; 5372 case LCP_OPT_ADDR_COMP: return "addr-comp"; 5373 } 5374 snprintf (buf, sizeof(buf), "lcp/0x%x", opt); 5375 return buf; 5376} 5377 |
5378#ifdef INET |
|
5295static const char * 5296sppp_ipcp_opt_name(u_char opt) 5297{ 5298 static char buf[12]; 5299 switch (opt) { 5300 case IPCP_OPT_ADDRESSES: return "addresses"; 5301 case IPCP_OPT_COMPRESSION: return "compression"; 5302 case IPCP_OPT_ADDRESS: return "address"; 5303 } 5304 snprintf (buf, sizeof(buf), "ipcp/0x%x", opt); 5305 return buf; 5306} | 5379static const char * 5380sppp_ipcp_opt_name(u_char opt) 5381{ 5382 static char buf[12]; 5383 switch (opt) { 5384 case IPCP_OPT_ADDRESSES: return "addresses"; 5385 case IPCP_OPT_COMPRESSION: return "compression"; 5386 case IPCP_OPT_ADDRESS: return "address"; 5387 } 5388 snprintf (buf, sizeof(buf), "ipcp/0x%x", opt); 5389 return buf; 5390} |
5391#endif |
|
5307 5308#ifdef INET6 5309static const char * 5310sppp_ipv6cp_opt_name(u_char opt) 5311{ 5312 static char buf[12]; 5313 switch (opt) { 5314 case IPV6CP_OPT_IFID: return "ifid"; --- 69 unchanged lines hidden (view full) --- 5384 * using only them, but we don't rely on it. */ 5385 if (c < ' ' || c > '~') 5386 log(-1, "\\x%x", c); 5387 else 5388 log(-1, "%c", c); 5389 } 5390} 5391 | 5392 5393#ifdef INET6 5394static const char * 5395sppp_ipv6cp_opt_name(u_char opt) 5396{ 5397 static char buf[12]; 5398 switch (opt) { 5399 case IPV6CP_OPT_IFID: return "ifid"; --- 69 unchanged lines hidden (view full) --- 5469 * using only them, but we don't rely on it. */ 5470 if (c < ' ' || c > '~') 5471 log(-1, "\\x%x", c); 5472 else 5473 log(-1, "%c", c); 5474 } 5475} 5476 |
5477#ifdef INET |
|
5392static const char * 5393sppp_dotted_quad(u_long addr) 5394{ 5395 static char s[16]; 5396 sprintf(s, "%d.%d.%d.%d", 5397 (int)((addr >> 24) & 0xff), 5398 (int)((addr >> 16) & 0xff), 5399 (int)((addr >> 8) & 0xff), 5400 (int)(addr & 0xff)); 5401 return s; 5402} | 5478static const char * 5479sppp_dotted_quad(u_long addr) 5480{ 5481 static char s[16]; 5482 sprintf(s, "%d.%d.%d.%d", 5483 (int)((addr >> 24) & 0xff), 5484 (int)((addr >> 16) & 0xff), 5485 (int)((addr >> 8) & 0xff), 5486 (int)(addr & 0xff)); 5487 return s; 5488} |
5489#endif |
|
5403 5404static int 5405sppp_strnlen(u_char *p, int max) 5406{ 5407 int len; 5408 5409 for (len = 0; len < max && *p; ++p) 5410 ++len; 5411 return len; 5412} 5413 5414/* a dummy, used to drop uninteresting events */ 5415static void 5416sppp_null(struct sppp *unused) 5417{ 5418 /* do just nothing */ 5419} | 5490 5491static int 5492sppp_strnlen(u_char *p, int max) 5493{ 5494 int len; 5495 5496 for (len = 0; len < max && *p; ++p) 5497 ++len; 5498 return len; 5499} 5500 5501/* a dummy, used to drop uninteresting events */ 5502static void 5503sppp_null(struct sppp *unused) 5504{ 5505 /* do just nothing */ 5506} |