if_spppsubr.c (39981) | if_spppsubr.c (40008) |
---|---|
1/* 2 * Synchronous PPP/Cisco link level subroutines. 3 * Keepalive protocol implemented in both Cisco and PPP modes. 4 * 5 * Copyright (C) 1994-1996 Cronyx Engineering Ltd. 6 * Author: Serge Vakulenko, <vak@cronyx.ru> 7 * 8 * Heavily revamped to conform to RFC 1661. 9 * Copyright (C) 1997, 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 * | 1/* 2 * Synchronous PPP/Cisco link level subroutines. 3 * Keepalive protocol implemented in both Cisco and PPP modes. 4 * 5 * Copyright (C) 1994-1996 Cronyx Engineering Ltd. 6 * Author: Serge Vakulenko, <vak@cronyx.ru> 7 * 8 * Heavily revamped to conform to RFC 1661. 9 * Copyright (C) 1997, 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 * $Id: if_spppsubr.c,v 1.42 1998/08/17 00:29:34 bde Exp $ | 20 * $Id: if_spppsubr.c,v 1.43 1998/10/05 21:02:30 joerg Exp $ |
21 */ 22 | 21 */ 22 |
23#include <sys/param.h> 24 25#if defined (__FreeBSD__) |
|
23#include "opt_inet.h" 24#include "opt_ipx.h" | 26#include "opt_inet.h" 27#include "opt_ipx.h" |
28#endif |
|
25 | 29 |
26#include <sys/param.h> | 30#ifdef NetBSD1_3 31# if NetBSD1_3 > 6 32# include "opt_inet.h" 33# include "opt_iso.h" 34# endif 35#endif 36 |
27#include <sys/systm.h> 28#include <sys/kernel.h> 29#include <sys/sockio.h> 30#include <sys/socket.h> 31#include <sys/syslog.h> 32#include <sys/malloc.h> 33#include <sys/mbuf.h> | 37#include <sys/systm.h> 38#include <sys/kernel.h> 39#include <sys/sockio.h> 40#include <sys/socket.h> 41#include <sys/syslog.h> 42#include <sys/malloc.h> 43#include <sys/mbuf.h> |
44 45#if defined (__OpenBSD__) 46#include <sys/md5k.h> 47#else |
|
34#include <sys/md5.h> | 48#include <sys/md5.h> |
49#endif |
|
35 36#include <net/if.h> 37#include <net/netisr.h> 38#include <net/if_types.h> 39 | 50 51#include <net/if.h> 52#include <net/netisr.h> 53#include <net/if_types.h> 54 |
40#include <machine/stdarg.h> | 55#if defined (__FreeBSD__) |
41#include <machine/random.h> | 56#include <machine/random.h> |
57#endif 58#if defined (__NetBSD__) || defined (__OpenBSD__) 59#include <machine/cpu.h> /* XXX for softnet */ 60#endif 61#include <machine/stdarg.h> |
|
42 43#ifdef INET 44#include <netinet/in.h> 45#include <netinet/in_systm.h> 46#include <netinet/in_var.h> 47#include <netinet/ip.h> 48#include <netinet/tcp.h> | 62 63#ifdef INET 64#include <netinet/in.h> 65#include <netinet/in_systm.h> 66#include <netinet/in_var.h> 67#include <netinet/ip.h> 68#include <netinet/tcp.h> |
49#include <netinet/if_ether.h> | 69# if defined (__FreeBSD__) || defined (__OpenBSD__) 70# include <netinet/if_ether.h> 71# else 72# include <net/ethertypes.h> 73# endif |
50#else | 74#else |
51#error Huh? sppp without INET? | 75# error Huh? sppp without INET? |
52#endif 53 54#ifdef IPX 55#include <netipx/ipx.h> 56#include <netipx/ipx_if.h> 57#endif 58 59#ifdef NS --- 5 unchanged lines hidden (view full) --- 65#include <netiso/argo_debug.h> 66#include <netiso/iso.h> 67#include <netiso/iso_var.h> 68#include <netiso/iso_snpac.h> 69#endif 70 71#include <net/if_sppp.h> 72 | 76#endif 77 78#ifdef IPX 79#include <netipx/ipx.h> 80#include <netipx/ipx_if.h> 81#endif 82 83#ifdef NS --- 5 unchanged lines hidden (view full) --- 89#include <netiso/argo_debug.h> 90#include <netiso/iso.h> 91#include <netiso/iso_var.h> 92#include <netiso/iso_snpac.h> 93#endif 94 95#include <net/if_sppp.h> 96 |
97#if defined (__FreeBSD__) 98# define UNTIMEOUT(fun, arg, handle) \ 99 untimeout(fun, arg, handle) 100#else 101# define UNTIMEOUT(fun, arg, handle) \ 102 untimeout(fun, arg) 103#endif |
|
73#define MAXALIVECNT 3 /* max. alive packets */ 74 75/* 76 * Interface flags that can be set in an ifconfig command. 77 * 78 * Setting link0 will make the link passive, i.e. it will be marked 79 * as being administrative openable, but won't be opened to begin 80 * with. Incoming calls will be answered, or subsequent calls with --- 133 unchanged lines hidden (view full) --- 214 void (*tlu)(struct sppp *sp); 215 void (*tld)(struct sppp *sp); 216 void (*tls)(struct sppp *sp); 217 void (*tlf)(struct sppp *sp); 218 void (*scr)(struct sppp *sp); 219}; 220 221static struct sppp *spppq; | 104#define MAXALIVECNT 3 /* max. alive packets */ 105 106/* 107 * Interface flags that can be set in an ifconfig command. 108 * 109 * Setting link0 will make the link passive, i.e. it will be marked 110 * as being administrative openable, but won't be opened to begin 111 * with. Incoming calls will be answered, or subsequent calls with --- 133 unchanged lines hidden (view full) --- 245 void (*tlu)(struct sppp *sp); 246 void (*tld)(struct sppp *sp); 247 void (*tls)(struct sppp *sp); 248 void (*tlf)(struct sppp *sp); 249 void (*scr)(struct sppp *sp); 250}; 251 252static struct sppp *spppq; |
253#if defined (__FreeBSD__) |
|
222static struct callout_handle keepalive_ch; | 254static struct callout_handle keepalive_ch; |
255#endif |
|
223 | 256 |
257#if defined (__FreeBSD__) 258#define SPP_FMT "%s%d: " 259#define SPP_ARGS(ifp) (ifp)->if_name, (ifp)->if_unit 260#else 261#define SPP_FMT "%s: " 262#define SPP_ARGS(ifp) (ifp)->if_xname 263#endif 264 |
|
224/* 225 * The following disgusting hack gets around the problem that IP TOS 226 * can't be set yet. We want to put "interactive" traffic on a high 227 * priority queue. To decide if traffic is interactive, we check that 228 * a) it is TCP and b) one of its ports is telnet, rlogin or ftp control. 229 * 230 * XXX is this really still necessary? - joerg - 231 */ --- 13 unchanged lines hidden (view full) --- 245 246static void sppp_cisco_send(struct sppp *sp, int type, long par1, long par2); 247static void sppp_cisco_input(struct sppp *sp, struct mbuf *m); 248 249static void sppp_cp_input(const struct cp *cp, struct sppp *sp, 250 struct mbuf *m); 251static void sppp_cp_send(struct sppp *sp, u_short proto, u_char type, 252 u_char ident, u_short len, void *data); | 265/* 266 * The following disgusting hack gets around the problem that IP TOS 267 * can't be set yet. We want to put "interactive" traffic on a high 268 * priority queue. To decide if traffic is interactive, we check that 269 * a) it is TCP and b) one of its ports is telnet, rlogin or ftp control. 270 * 271 * XXX is this really still necessary? - joerg - 272 */ --- 13 unchanged lines hidden (view full) --- 286 287static void sppp_cisco_send(struct sppp *sp, int type, long par1, long par2); 288static void sppp_cisco_input(struct sppp *sp, struct mbuf *m); 289 290static void sppp_cp_input(const struct cp *cp, struct sppp *sp, 291 struct mbuf *m); 292static void sppp_cp_send(struct sppp *sp, u_short proto, u_char type, 293 u_char ident, u_short len, void *data); |
294#ifdef notyet |
|
253static void sppp_cp_timeout(void *arg); | 295static void sppp_cp_timeout(void *arg); |
296#endif |
|
254static void sppp_cp_change_state(const struct cp *cp, struct sppp *sp, 255 int newstate); 256static void sppp_auth_send(const struct cp *cp, 257 struct sppp *sp, u_char type, u_char id, 258 ...); 259 260static void sppp_up_event(const struct cp *cp, struct sppp *sp); 261static void sppp_down_event(const struct cp *cp, struct sppp *sp); --- 133 unchanged lines hidden (view full) --- 395 if (ifp->if_flags & IFF_UP) 396 /* Count received bytes, add FCS and one flag */ 397 ifp->if_ibytes += m->m_pkthdr.len + 3; 398 399 if (m->m_pkthdr.len <= PPP_HEADER_LEN) { 400 /* Too small packet, drop it. */ 401 if (debug) 402 log(LOG_DEBUG, | 297static void sppp_cp_change_state(const struct cp *cp, struct sppp *sp, 298 int newstate); 299static void sppp_auth_send(const struct cp *cp, 300 struct sppp *sp, u_char type, u_char id, 301 ...); 302 303static void sppp_up_event(const struct cp *cp, struct sppp *sp); 304static void sppp_down_event(const struct cp *cp, struct sppp *sp); --- 133 unchanged lines hidden (view full) --- 438 if (ifp->if_flags & IFF_UP) 439 /* Count received bytes, add FCS and one flag */ 440 ifp->if_ibytes += m->m_pkthdr.len + 3; 441 442 if (m->m_pkthdr.len <= PPP_HEADER_LEN) { 443 /* Too small packet, drop it. */ 444 if (debug) 445 log(LOG_DEBUG, |
403 "%s%d: input packet is too small, %d bytes\n", 404 ifp->if_name, ifp->if_unit, m->m_pkthdr.len); | 446 SPP_FMT "input packet is too small, %d bytes\n", 447 SPP_ARGS(ifp), m->m_pkthdr.len); |
405 drop: 406 ++ifp->if_ierrors; 407 ++ifp->if_iqdrops; 408 m_freem (m); 409 return; 410 } 411 412 /* Get PPP header. */ 413 h = mtod (m, struct ppp_header*); 414 m_adj (m, PPP_HEADER_LEN); 415 416 switch (h->address) { 417 case PPP_ALLSTATIONS: 418 if (h->control != PPP_UI) 419 goto invalid; 420 if (sp->pp_flags & PP_CISCO) { 421 if (debug) 422 log(LOG_DEBUG, | 448 drop: 449 ++ifp->if_ierrors; 450 ++ifp->if_iqdrops; 451 m_freem (m); 452 return; 453 } 454 455 /* Get PPP header. */ 456 h = mtod (m, struct ppp_header*); 457 m_adj (m, PPP_HEADER_LEN); 458 459 switch (h->address) { 460 case PPP_ALLSTATIONS: 461 if (h->control != PPP_UI) 462 goto invalid; 463 if (sp->pp_flags & PP_CISCO) { 464 if (debug) 465 log(LOG_DEBUG, |
423 "%s%d: PPP packet in Cisco mode " | 466 SPP_FMT "PPP packet in Cisco mode " |
424 "<addr=0x%x ctrl=0x%x proto=0x%x>\n", | 467 "<addr=0x%x ctrl=0x%x proto=0x%x>\n", |
425 ifp->if_name, ifp->if_unit, | 468 SPP_ARGS(ifp), |
426 h->address, h->control, ntohs(h->protocol)); 427 goto drop; 428 } 429 switch (ntohs (h->protocol)) { 430 default: 431 if (sp->state[IDX_LCP] == STATE_OPENED) 432 sppp_cp_send (sp, PPP_LCP, PROTO_REJ, 433 ++sp->pp_seq, m->m_pkthdr.len + 2, 434 &h->protocol); 435 if (debug) 436 log(LOG_DEBUG, | 469 h->address, h->control, ntohs(h->protocol)); 470 goto drop; 471 } 472 switch (ntohs (h->protocol)) { 473 default: 474 if (sp->state[IDX_LCP] == STATE_OPENED) 475 sppp_cp_send (sp, PPP_LCP, PROTO_REJ, 476 ++sp->pp_seq, m->m_pkthdr.len + 2, 477 &h->protocol); 478 if (debug) 479 log(LOG_DEBUG, |
437 "%s%d: invalid input protocol " | 480 SPP_FMT "invalid input protocol " |
438 "<addr=0x%x ctrl=0x%x proto=0x%x>\n", | 481 "<addr=0x%x ctrl=0x%x proto=0x%x>\n", |
439 ifp->if_name, ifp->if_unit, | 482 SPP_ARGS(ifp), |
440 h->address, h->control, ntohs(h->protocol)); 441 ++ifp->if_noproto; 442 goto drop; 443 case PPP_LCP: 444 sppp_cp_input(&lcp, sp, m); 445 m_freem (m); 446 return; 447 case PPP_PAP: --- 49 unchanged lines hidden (view full) --- 497 } 498 break; 499 case CISCO_MULTICAST: 500 case CISCO_UNICAST: 501 /* Don't check the control field here (RFC 1547). */ 502 if (! (sp->pp_flags & PP_CISCO)) { 503 if (debug) 504 log(LOG_DEBUG, | 483 h->address, h->control, ntohs(h->protocol)); 484 ++ifp->if_noproto; 485 goto drop; 486 case PPP_LCP: 487 sppp_cp_input(&lcp, sp, m); 488 m_freem (m); 489 return; 490 case PPP_PAP: --- 49 unchanged lines hidden (view full) --- 540 } 541 break; 542 case CISCO_MULTICAST: 543 case CISCO_UNICAST: 544 /* Don't check the control field here (RFC 1547). */ 545 if (! (sp->pp_flags & PP_CISCO)) { 546 if (debug) 547 log(LOG_DEBUG, |
505 "%s%d: Cisco packet in PPP mode " | 548 SPP_FMT "Cisco packet in PPP mode " |
506 "<addr=0x%x ctrl=0x%x proto=0x%x>\n", | 549 "<addr=0x%x ctrl=0x%x proto=0x%x>\n", |
507 ifp->if_name, ifp->if_unit, | 550 SPP_ARGS(ifp), |
508 h->address, h->control, ntohs(h->protocol)); 509 goto drop; 510 } 511 switch (ntohs (h->protocol)) { 512 default: 513 ++ifp->if_noproto; 514 goto invalid; 515 case CISCO_KEEPALIVE: --- 19 unchanged lines hidden (view full) --- 535 break; 536#endif 537 } 538 break; 539 default: /* Invalid PPP packet. */ 540 invalid: 541 if (debug) 542 log(LOG_DEBUG, | 551 h->address, h->control, ntohs(h->protocol)); 552 goto drop; 553 } 554 switch (ntohs (h->protocol)) { 555 default: 556 ++ifp->if_noproto; 557 goto invalid; 558 case CISCO_KEEPALIVE: --- 19 unchanged lines hidden (view full) --- 578 break; 579#endif 580 } 581 break; 582 default: /* Invalid PPP packet. */ 583 invalid: 584 if (debug) 585 log(LOG_DEBUG, |
543 "%s%d: invalid input packet " | 586 SPP_FMT "invalid input packet " |
544 "<addr=0x%x ctrl=0x%x proto=0x%x>\n", | 587 "<addr=0x%x ctrl=0x%x proto=0x%x>\n", |
545 ifp->if_name, ifp->if_unit, | 588 SPP_ARGS(ifp), |
546 h->address, h->control, ntohs(h->protocol)); 547 goto drop; 548 } 549 550 if (! (ifp->if_flags & IFF_UP) || ! inq) 551 goto drop; 552 553 /* Check queue. */ 554 s = splimp(); 555 if (IF_QFULL (inq)) { 556 /* Queue overflow. */ 557 IF_DROP(inq); 558 splx(s); 559 if (debug) | 589 h->address, h->control, ntohs(h->protocol)); 590 goto drop; 591 } 592 593 if (! (ifp->if_flags & IFF_UP) || ! inq) 594 goto drop; 595 596 /* Check queue. */ 597 s = splimp(); 598 if (IF_QFULL (inq)) { 599 /* Queue overflow. */ 600 IF_DROP(inq); 601 splx(s); 602 if (debug) |
560 log(LOG_DEBUG, "%s%d: protocol queue overflow\n", 561 ifp->if_name, ifp->if_unit); | 603 log(LOG_DEBUG, SPP_FMT "protocol queue overflow\n", 604 SPP_ARGS(ifp)); |
562 goto drop; 563 } 564 IF_ENQUEUE(inq, m); 565 splx(s); 566} 567 568/* 569 * Enqueue transmit packet. --- 29 unchanged lines hidden (view full) --- 599 600 ifq = &ifp->if_snd; 601#ifdef INET 602 /* 603 * Put low delay, telnet, rlogin and ftp control packets 604 * in front of the queue. 605 */ 606 if (dst->sa_family == AF_INET) { | 605 goto drop; 606 } 607 IF_ENQUEUE(inq, m); 608 splx(s); 609} 610 611/* 612 * Enqueue transmit packet. --- 29 unchanged lines hidden (view full) --- 642 643 ifq = &ifp->if_snd; 644#ifdef INET 645 /* 646 * Put low delay, telnet, rlogin and ftp control packets 647 * in front of the queue. 648 */ 649 if (dst->sa_family == AF_INET) { |
650 /* XXX Check mbuf length here? */ |
|
607 struct ip *ip = mtod (m, struct ip*); 608 struct tcphdr *tcp = (struct tcphdr*) ((long*)ip + ip->ip_hl); 609 610 if (! IF_QFULL (&sp->pp_fastq) && 611 ((ip->ip_tos & IPTOS_LOWDELAY) || | 651 struct ip *ip = mtod (m, struct ip*); 652 struct tcphdr *tcp = (struct tcphdr*) ((long*)ip + ip->ip_hl); 653 654 if (! IF_QFULL (&sp->pp_fastq) && 655 ((ip->ip_tos & IPTOS_LOWDELAY) || |
612 ip->ip_p == IPPROTO_TCP && | 656 ((ip->ip_p == IPPROTO_TCP && |
613 m->m_len >= sizeof (struct ip) + sizeof (struct tcphdr) && | 657 m->m_len >= sizeof (struct ip) + sizeof (struct tcphdr) && |
614 (INTERACTIVE (ntohs (tcp->th_sport)) || | 658 (INTERACTIVE (ntohs (tcp->th_sport)))) || |
615 INTERACTIVE (ntohs (tcp->th_dport))))) 616 ifq = &sp->pp_fastq; 617 } 618#endif 619 620 /* 621 * Prepend general data packet PPP header. For now, IP only. 622 */ 623 M_PREPEND (m, PPP_HEADER_LEN, M_DONTWAIT); 624 if (! m) { 625 if (ifp->if_flags & IFF_DEBUG) | 659 INTERACTIVE (ntohs (tcp->th_dport))))) 660 ifq = &sp->pp_fastq; 661 } 662#endif 663 664 /* 665 * Prepend general data packet PPP header. For now, IP only. 666 */ 667 M_PREPEND (m, PPP_HEADER_LEN, M_DONTWAIT); 668 if (! m) { 669 if (ifp->if_flags & IFF_DEBUG) |
626 log(LOG_DEBUG, "%s%d: no memory for transmit header\n", 627 ifp->if_name, ifp->if_unit); | 670 log(LOG_DEBUG, SPP_FMT "no memory for transmit header\n", 671 SPP_ARGS(ifp)); |
628 ++ifp->if_oerrors; 629 splx (s); 630 return (ENOBUFS); 631 } | 672 ++ifp->if_oerrors; 673 splx (s); 674 return (ENOBUFS); 675 } |
676 /* 677 * May want to check size of packet 678 * (albeit due to the implementation it's always enough) 679 */ |
|
632 h = mtod (m, struct ppp_header*); 633 if (sp->pp_flags & PP_CISCO) { 634 h->address = CISCO_UNICAST; /* unicast address */ 635 h->control = 0; 636 } else { 637 h->address = PPP_ALLSTATIONS; /* broadcast address */ 638 h->control = PPP_UI; /* Unnumbered Info */ 639 } --- 73 unchanged lines hidden (view full) --- 713 714void 715sppp_attach(struct ifnet *ifp) 716{ 717 struct sppp *sp = (struct sppp*) ifp; 718 719 /* Initialize keepalive handler. */ 720 if (! spppq) | 680 h = mtod (m, struct ppp_header*); 681 if (sp->pp_flags & PP_CISCO) { 682 h->address = CISCO_UNICAST; /* unicast address */ 683 h->control = 0; 684 } else { 685 h->address = PPP_ALLSTATIONS; /* broadcast address */ 686 h->control = PPP_UI; /* Unnumbered Info */ 687 } --- 73 unchanged lines hidden (view full) --- 761 762void 763sppp_attach(struct ifnet *ifp) 764{ 765 struct sppp *sp = (struct sppp*) ifp; 766 767 /* Initialize keepalive handler. */ 768 if (! spppq) |
721 keepalive_ch = timeout(sppp_keepalive, 0, hz * 10); | 769#if defined (__FreeBSD__) 770 keepalive_ch = 771#endif 772 timeout(sppp_keepalive, 0, hz * 10); |
722 723 /* Insert new entry into the keepalive list. */ 724 sp->pp_next = spppq; 725 spppq = sp; 726 727 sp->pp_if.if_type = IFT_PPP; 728 sp->pp_if.if_output = sppp_output; 729 sp->pp_fastq.ifq_maxlen = 32; --- 22 unchanged lines hidden (view full) --- 752 for (q = &spppq; (p = *q); q = &p->pp_next) 753 if (p == sp) { 754 *q = p->pp_next; 755 break; 756 } 757 758 /* Stop keepalive handler. */ 759 if (! spppq) | 773 774 /* Insert new entry into the keepalive list. */ 775 sp->pp_next = spppq; 776 spppq = sp; 777 778 sp->pp_if.if_type = IFT_PPP; 779 sp->pp_if.if_output = sppp_output; 780 sp->pp_fastq.ifq_maxlen = 32; --- 22 unchanged lines hidden (view full) --- 803 for (q = &spppq; (p = *q); q = &p->pp_next) 804 if (p == sp) { 805 *q = p->pp_next; 806 break; 807 } 808 809 /* Stop keepalive handler. */ 810 if (! spppq) |
760 untimeout(sppp_keepalive, 0, keepalive_ch); | 811 UNTIMEOUT(sppp_keepalive, 0, keepalive_ch); |
761 762 for (i = 0; i < IDX_COUNT; i++) | 812 813 for (i = 0; i < IDX_COUNT; i++) |
763 untimeout((cps[i])->TO, (void *)sp, sp->ch[i]); 764 untimeout(sppp_pap_my_TO, (void *)sp, sp->pap_my_to_ch); | 814 UNTIMEOUT((cps[i])->TO, (void *)sp, sp->ch[i]); 815 UNTIMEOUT(sppp_pap_my_TO, (void *)sp, sp->pap_my_to_ch); |
765} 766 767/* 768 * Flush the interface output queue. 769 */ 770void 771sppp_flush(struct ifnet *ifp) 772{ --- 173 unchanged lines hidden (view full) --- 946{ 947 STDDCL; 948 struct cisco_packet *h; 949 u_long me, mymask; 950 951 if (m->m_pkthdr.len < CISCO_PACKET_LEN) { 952 if (debug) 953 log(LOG_DEBUG, | 816} 817 818/* 819 * Flush the interface output queue. 820 */ 821void 822sppp_flush(struct ifnet *ifp) 823{ --- 173 unchanged lines hidden (view full) --- 997{ 998 STDDCL; 999 struct cisco_packet *h; 1000 u_long me, mymask; 1001 1002 if (m->m_pkthdr.len < CISCO_PACKET_LEN) { 1003 if (debug) 1004 log(LOG_DEBUG, |
954 "%s%d: cisco invalid packet length: %d bytes\n", 955 ifp->if_name, ifp->if_unit, m->m_pkthdr.len); | 1005 SPP_FMT "cisco invalid packet length: %d bytes\n", 1006 SPP_ARGS(ifp), m->m_pkthdr.len); |
956 return; 957 } 958 h = mtod (m, struct cisco_packet*); 959 if (debug) 960 log(LOG_DEBUG, | 1007 return; 1008 } 1009 h = mtod (m, struct cisco_packet*); 1010 if (debug) 1011 log(LOG_DEBUG, |
961 "%s%d: cisco input: %d bytes " | 1012 SPP_FMT "cisco input: %d bytes " |
962 "<0x%lx 0x%lx 0x%lx 0x%x 0x%x-0x%x>\n", | 1013 "<0x%lx 0x%lx 0x%lx 0x%x 0x%x-0x%x>\n", |
963 ifp->if_name, ifp->if_unit, m->m_pkthdr.len, 964 ntohl (h->type), h->par1, h->par2, h->rel, 965 h->time0, h->time1); | 1014 SPP_ARGS(ifp), m->m_pkthdr.len, 1015 (u_long)ntohl (h->type), (u_long)h->par1, (u_long)h->par2, (u_int)h->rel, 1016 (u_int)h->time0, (u_int)h->time1); |
966 switch (ntohl (h->type)) { 967 default: 968 if (debug) | 1017 switch (ntohl (h->type)) { 1018 default: 1019 if (debug) |
969 addlog("%s%d: cisco unknown packet type: 0x%lx\n", 970 ifp->if_name, ifp->if_unit, ntohl (h->type)); | 1020 addlog(SPP_FMT "cisco unknown packet type: 0x%lx\n", 1021 SPP_ARGS(ifp), (u_long)ntohl (h->type)); |
971 break; 972 case CISCO_ADDR_REPLY: 973 /* Reply on address request, ignore */ 974 break; 975 case CISCO_KEEPALIVE_REQ: 976 sp->pp_alivecnt = 0; 977 sp->pp_rseq = ntohl (h->par1); 978 if (sp->pp_seq == sp->pp_rseq) { 979 /* Local and remote sequence numbers are equal. 980 * Probably, the line is in loopback mode. */ 981 if (sp->pp_loopcnt >= MAXALIVECNT) { | 1022 break; 1023 case CISCO_ADDR_REPLY: 1024 /* Reply on address request, ignore */ 1025 break; 1026 case CISCO_KEEPALIVE_REQ: 1027 sp->pp_alivecnt = 0; 1028 sp->pp_rseq = ntohl (h->par1); 1029 if (sp->pp_seq == sp->pp_rseq) { 1030 /* Local and remote sequence numbers are equal. 1031 * Probably, the line is in loopback mode. */ 1032 if (sp->pp_loopcnt >= MAXALIVECNT) { |
982 printf ("%s%d: loopback\n", 983 ifp->if_name, ifp->if_unit); | 1033 printf (SPP_FMT "loopback\n", 1034 SPP_ARGS(ifp)); |
984 sp->pp_loopcnt = 0; 985 if (ifp->if_flags & IFF_UP) { 986 if_down (ifp); 987 sppp_qflush (&sp->pp_cpq); 988 } 989 } 990 ++sp->pp_loopcnt; 991 992 /* Generate new local sequence number */ | 1035 sp->pp_loopcnt = 0; 1036 if (ifp->if_flags & IFF_UP) { 1037 if_down (ifp); 1038 sppp_qflush (&sp->pp_cpq); 1039 } 1040 } 1041 ++sp->pp_loopcnt; 1042 1043 /* Generate new local sequence number */ |
1044#if defined (__FreeBSD__) |
|
993 sp->pp_seq = random(); | 1045 sp->pp_seq = random(); |
1046#else 1047 sp->pp_seq ^= time.tv_sec ^ time.tv_usec; 1048#endif |
|
994 break; 995 } 996 sp->pp_loopcnt = 0; 997 if (! (ifp->if_flags & IFF_UP) && 998 (ifp->if_flags & IFF_RUNNING)) { 999 if_up(ifp); | 1049 break; 1050 } 1051 sp->pp_loopcnt = 0; 1052 if (! (ifp->if_flags & IFF_UP) && 1053 (ifp->if_flags & IFF_RUNNING)) { 1054 if_up(ifp); |
1000 printf ("%s%d: up\n", ifp->if_name, ifp->if_unit); | 1055 printf (SPP_FMT "up\n", SPP_ARGS(ifp)); |
1001 } 1002 break; 1003 case CISCO_ADDR_REQ: 1004 sppp_get_ip_addrs(sp, &me, 0, &mymask); 1005 if (me != 0L) 1006 sppp_cisco_send(sp, CISCO_ADDR_REPLY, me, mymask); 1007 break; 1008 } --- 4 unchanged lines hidden (view full) --- 1013 */ 1014static void 1015sppp_cisco_send(struct sppp *sp, int type, long par1, long par2) 1016{ 1017 STDDCL; 1018 struct ppp_header *h; 1019 struct cisco_packet *ch; 1020 struct mbuf *m; | 1056 } 1057 break; 1058 case CISCO_ADDR_REQ: 1059 sppp_get_ip_addrs(sp, &me, 0, &mymask); 1060 if (me != 0L) 1061 sppp_cisco_send(sp, CISCO_ADDR_REPLY, me, mymask); 1062 break; 1063 } --- 4 unchanged lines hidden (view full) --- 1068 */ 1069static void 1070sppp_cisco_send(struct sppp *sp, int type, long par1, long par2) 1071{ 1072 STDDCL; 1073 struct ppp_header *h; 1074 struct cisco_packet *ch; 1075 struct mbuf *m; |
1076#if defined (__FreeBSD__) |
|
1021 struct timeval tv; | 1077 struct timeval tv; |
1078#else 1079 u_long t = (time.tv_sec - boottime.tv_sec) * 1000; 1080#endif |
|
1022 | 1081 |
1082#if defined (__FreeBSD__) |
|
1023 getmicrouptime(&tv); | 1083 getmicrouptime(&tv); |
1084#endif |
|
1024 1025 MGETHDR (m, M_DONTWAIT, MT_DATA); 1026 if (! m) 1027 return; 1028 m->m_pkthdr.len = m->m_len = PPP_HEADER_LEN + CISCO_PACKET_LEN; 1029 m->m_pkthdr.rcvif = 0; 1030 1031 h = mtod (m, struct ppp_header*); 1032 h->address = CISCO_MULTICAST; 1033 h->control = 0; 1034 h->protocol = htons (CISCO_KEEPALIVE); 1035 1036 ch = (struct cisco_packet*) (h + 1); 1037 ch->type = htonl (type); 1038 ch->par1 = htonl (par1); 1039 ch->par2 = htonl (par2); 1040 ch->rel = -1; | 1085 1086 MGETHDR (m, M_DONTWAIT, MT_DATA); 1087 if (! m) 1088 return; 1089 m->m_pkthdr.len = m->m_len = PPP_HEADER_LEN + CISCO_PACKET_LEN; 1090 m->m_pkthdr.rcvif = 0; 1091 1092 h = mtod (m, struct ppp_header*); 1093 h->address = CISCO_MULTICAST; 1094 h->control = 0; 1095 h->protocol = htons (CISCO_KEEPALIVE); 1096 1097 ch = (struct cisco_packet*) (h + 1); 1098 ch->type = htonl (type); 1099 ch->par1 = htonl (par1); 1100 ch->par2 = htonl (par2); 1101 ch->rel = -1; |
1102 1103#if defined (__FreeBSD__) |
|
1041 ch->time0 = htons ((u_short) (tv.tv_sec >> 16)); 1042 ch->time1 = htons ((u_short) tv.tv_sec); | 1104 ch->time0 = htons ((u_short) (tv.tv_sec >> 16)); 1105 ch->time1 = htons ((u_short) tv.tv_sec); |
1106#else 1107 ch->time0 = htons ((u_short) (t >> 16)); 1108 ch->time1 = htons ((u_short) t); 1109#endif |
|
1043 1044 if (debug) 1045 log(LOG_DEBUG, | 1110 1111 if (debug) 1112 log(LOG_DEBUG, |
1046 "%s%d: cisco output: <0x%lx 0x%lx 0x%lx 0x%x 0x%x-0x%x>\n", 1047 ifp->if_name, ifp->if_unit, ntohl (ch->type), ch->par1, 1048 ch->par2, ch->rel, ch->time0, ch->time1); | 1113 SPP_FMT "cisco output: <0x%lx 0x%lx 0x%lx 0x%x 0x%x-0x%x>\n", 1114 SPP_ARGS(ifp), (u_long)ntohl (ch->type), (u_long)ch->par1, 1115 (u_long)ch->par2, (u_int)ch->rel, (u_int)ch->time0, (u_int)ch->time1); |
1049 1050 if (IF_QFULL (&sp->pp_cpq)) { 1051 IF_DROP (&sp->pp_fastq); 1052 IF_DROP (&ifp->if_snd); 1053 m_freem (m); 1054 } else 1055 IF_ENQUEUE (&sp->pp_cpq, m); 1056 if (! (ifp->if_flags & IFF_OACTIVE)) --- 33 unchanged lines hidden (view full) --- 1090 lh = (struct lcp_header*) (h + 1); 1091 lh->type = type; 1092 lh->ident = ident; 1093 lh->len = htons (LCP_HEADER_LEN + len); 1094 if (len) 1095 bcopy (data, lh+1, len); 1096 1097 if (debug) { | 1116 1117 if (IF_QFULL (&sp->pp_cpq)) { 1118 IF_DROP (&sp->pp_fastq); 1119 IF_DROP (&ifp->if_snd); 1120 m_freem (m); 1121 } else 1122 IF_ENQUEUE (&sp->pp_cpq, m); 1123 if (! (ifp->if_flags & IFF_OACTIVE)) --- 33 unchanged lines hidden (view full) --- 1157 lh = (struct lcp_header*) (h + 1); 1158 lh->type = type; 1159 lh->ident = ident; 1160 lh->len = htons (LCP_HEADER_LEN + len); 1161 if (len) 1162 bcopy (data, lh+1, len); 1163 1164 if (debug) { |
1098 log(LOG_DEBUG, "%s%d: %s output <%s id=0x%x len=%d", 1099 ifp->if_name, ifp->if_unit, | 1165 log(LOG_DEBUG, SPP_FMT "%s output <%s id=0x%x len=%d", 1166 SPP_ARGS(ifp), |
1100 sppp_proto_name(proto), 1101 sppp_cp_type_name (lh->type), lh->ident, 1102 ntohs (lh->len)); 1103 if (len) 1104 sppp_print_bytes ((u_char*) (lh+1), len); 1105 addlog(">\n"); 1106 } 1107 if (IF_QFULL (&sp->pp_cpq)) { --- 18 unchanged lines hidden (view full) --- 1126 struct lcp_header *h; 1127 int len = m->m_pkthdr.len; 1128 int rv; 1129 u_char *p; 1130 1131 if (len < 4) { 1132 if (debug) 1133 log(LOG_DEBUG, | 1167 sppp_proto_name(proto), 1168 sppp_cp_type_name (lh->type), lh->ident, 1169 ntohs (lh->len)); 1170 if (len) 1171 sppp_print_bytes ((u_char*) (lh+1), len); 1172 addlog(">\n"); 1173 } 1174 if (IF_QFULL (&sp->pp_cpq)) { --- 18 unchanged lines hidden (view full) --- 1193 struct lcp_header *h; 1194 int len = m->m_pkthdr.len; 1195 int rv; 1196 u_char *p; 1197 1198 if (len < 4) { 1199 if (debug) 1200 log(LOG_DEBUG, |
1134 "%s%d: %s invalid packet length: %d bytes\n", 1135 ifp->if_name, ifp->if_unit, cp->name, len); | 1201 SPP_FMT "%s invalid packet length: %d bytes\n", 1202 SPP_ARGS(ifp), cp->name, len); |
1136 return; 1137 } 1138 h = mtod (m, struct lcp_header*); 1139 if (debug) { 1140 log(LOG_DEBUG, | 1203 return; 1204 } 1205 h = mtod (m, struct lcp_header*); 1206 if (debug) { 1207 log(LOG_DEBUG, |
1141 "%s%d: %s input(%s): <%s id=0x%x len=%d", 1142 ifp->if_name, ifp->if_unit, cp->name, | 1208 SPP_FMT "%s input(%s): <%s id=0x%x len=%d", 1209 SPP_ARGS(ifp), cp->name, |
1143 sppp_state_name(sp->state[cp->protoidx]), 1144 sppp_cp_type_name (h->type), h->ident, ntohs (h->len)); 1145 if (len > 4) 1146 sppp_print_bytes ((u_char*) (h+1), len-4); 1147 addlog(">\n"); 1148 } 1149 if (len > ntohs (h->len)) 1150 len = ntohs (h->len); 1151 p = (u_char *)(h + 1); 1152 switch (h->type) { 1153 case CONF_REQ: 1154 if (len < 4) { 1155 if (debug) | 1210 sppp_state_name(sp->state[cp->protoidx]), 1211 sppp_cp_type_name (h->type), h->ident, ntohs (h->len)); 1212 if (len > 4) 1213 sppp_print_bytes ((u_char*) (h+1), len-4); 1214 addlog(">\n"); 1215 } 1216 if (len > ntohs (h->len)) 1217 len = ntohs (h->len); 1218 p = (u_char *)(h + 1); 1219 switch (h->type) { 1220 case CONF_REQ: 1221 if (len < 4) { 1222 if (debug) |
1156 addlog("%s%d: %s invalid conf-req length %d\n", 1157 ifp->if_name, ifp->if_unit, cp->name, | 1223 addlog(SPP_FMT "%s invalid conf-req length %d\n", 1224 SPP_ARGS(ifp), cp->name, |
1158 len); 1159 ++ifp->if_ierrors; 1160 break; 1161 } 1162 /* handle states where RCR doesn't get a SCA/SCN */ 1163 switch (sp->state[cp->protoidx]) { 1164 case STATE_CLOSING: 1165 case STATE_STOPPING: --- 19 unchanged lines hidden (view full) --- 1185 (cp->scr)(sp); 1186 sppp_cp_change_state(cp, sp, rv? 1187 STATE_ACK_SENT: STATE_REQ_SENT); 1188 break; 1189 case STATE_ACK_RCVD: 1190 if (rv) { 1191 sppp_cp_change_state(cp, sp, STATE_OPENED); 1192 if (debug) | 1225 len); 1226 ++ifp->if_ierrors; 1227 break; 1228 } 1229 /* handle states where RCR doesn't get a SCA/SCN */ 1230 switch (sp->state[cp->protoidx]) { 1231 case STATE_CLOSING: 1232 case STATE_STOPPING: --- 19 unchanged lines hidden (view full) --- 1252 (cp->scr)(sp); 1253 sppp_cp_change_state(cp, sp, rv? 1254 STATE_ACK_SENT: STATE_REQ_SENT); 1255 break; 1256 case STATE_ACK_RCVD: 1257 if (rv) { 1258 sppp_cp_change_state(cp, sp, STATE_OPENED); 1259 if (debug) |
1193 log(LOG_DEBUG, "%s%d: %s tlu\n", 1194 ifp->if_name, ifp->if_unit, | 1260 log(LOG_DEBUG, SPP_FMT "%s tlu\n", 1261 SPP_ARGS(ifp), |
1195 cp->name); 1196 (cp->tlu)(sp); 1197 } else 1198 sppp_cp_change_state(cp, sp, STATE_ACK_RCVD); 1199 break; 1200 default: | 1262 cp->name); 1263 (cp->tlu)(sp); 1264 } else 1265 sppp_cp_change_state(cp, sp, STATE_ACK_RCVD); 1266 break; 1267 default: |
1201 printf("%s%d: %s illegal %s in state %s\n", 1202 ifp->if_name, ifp->if_unit, cp->name, | 1268 printf(SPP_FMT "%s illegal %s in state %s\n", 1269 SPP_ARGS(ifp), cp->name, |
1203 sppp_cp_type_name(h->type), 1204 sppp_state_name(sp->state[cp->protoidx])); 1205 ++ifp->if_ierrors; 1206 } 1207 break; 1208 case CONF_ACK: 1209 if (h->ident != sp->confid[cp->protoidx]) { 1210 if (debug) | 1270 sppp_cp_type_name(h->type), 1271 sppp_state_name(sp->state[cp->protoidx])); 1272 ++ifp->if_ierrors; 1273 } 1274 break; 1275 case CONF_ACK: 1276 if (h->ident != sp->confid[cp->protoidx]) { 1277 if (debug) |
1211 addlog("%s%d: %s id mismatch 0x%x != 0x%x\n", 1212 ifp->if_name, ifp->if_unit, cp->name, | 1278 addlog(SPP_FMT "%s id mismatch 0x%x != 0x%x\n", 1279 SPP_ARGS(ifp), cp->name, |
1213 h->ident, sp->confid[cp->protoidx]); 1214 ++ifp->if_ierrors; 1215 break; 1216 } 1217 switch (sp->state[cp->protoidx]) { 1218 case STATE_CLOSED: 1219 case STATE_STOPPED: 1220 sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, 0, 0); --- 11 unchanged lines hidden (view full) --- 1232 case STATE_ACK_RCVD: 1233 (cp->scr)(sp); 1234 sppp_cp_change_state(cp, sp, STATE_REQ_SENT); 1235 break; 1236 case STATE_ACK_SENT: 1237 sp->rst_counter[cp->protoidx] = sp->lcp.max_configure; 1238 sppp_cp_change_state(cp, sp, STATE_OPENED); 1239 if (debug) | 1280 h->ident, sp->confid[cp->protoidx]); 1281 ++ifp->if_ierrors; 1282 break; 1283 } 1284 switch (sp->state[cp->protoidx]) { 1285 case STATE_CLOSED: 1286 case STATE_STOPPED: 1287 sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, 0, 0); --- 11 unchanged lines hidden (view full) --- 1299 case STATE_ACK_RCVD: 1300 (cp->scr)(sp); 1301 sppp_cp_change_state(cp, sp, STATE_REQ_SENT); 1302 break; 1303 case STATE_ACK_SENT: 1304 sp->rst_counter[cp->protoidx] = sp->lcp.max_configure; 1305 sppp_cp_change_state(cp, sp, STATE_OPENED); 1306 if (debug) |
1240 log(LOG_DEBUG, "%s%d: %s tlu\n", 1241 ifp->if_name, ifp->if_unit, cp->name); | 1307 log(LOG_DEBUG, SPP_FMT "%s tlu\n", 1308 SPP_ARGS(ifp), cp->name); |
1242 (cp->tlu)(sp); 1243 break; 1244 default: | 1309 (cp->tlu)(sp); 1310 break; 1311 default: |
1245 printf("%s%d: %s illegal %s in state %s\n", 1246 ifp->if_name, ifp->if_unit, cp->name, | 1312 printf(SPP_FMT "%s illegal %s in state %s\n", 1313 SPP_ARGS(ifp), cp->name, |
1247 sppp_cp_type_name(h->type), 1248 sppp_state_name(sp->state[cp->protoidx])); 1249 ++ifp->if_ierrors; 1250 } 1251 break; 1252 case CONF_NAK: 1253 case CONF_REJ: 1254 if (h->ident != sp->confid[cp->protoidx]) { 1255 if (debug) | 1314 sppp_cp_type_name(h->type), 1315 sppp_state_name(sp->state[cp->protoidx])); 1316 ++ifp->if_ierrors; 1317 } 1318 break; 1319 case CONF_NAK: 1320 case CONF_REJ: 1321 if (h->ident != sp->confid[cp->protoidx]) { 1322 if (debug) |
1256 addlog("%s%d: %s id mismatch 0x%x != 0x%x\n", 1257 ifp->if_name, ifp->if_unit, cp->name, | 1323 addlog(SPP_FMT "%s id mismatch 0x%x != 0x%x\n", 1324 SPP_ARGS(ifp), cp->name, |
1258 h->ident, sp->confid[cp->protoidx]); 1259 ++ifp->if_ierrors; 1260 break; 1261 } 1262 if (h->type == CONF_NAK) 1263 (cp->RCN_nak)(sp, h, len); 1264 else /* CONF_REJ */ 1265 (cp->RCN_rej)(sp, h, len); --- 14 unchanged lines hidden (view full) --- 1280 case STATE_ACK_RCVD: 1281 sppp_cp_change_state(cp, sp, STATE_ACK_SENT); 1282 (cp->scr)(sp); 1283 break; 1284 case STATE_CLOSING: 1285 case STATE_STOPPING: 1286 break; 1287 default: | 1325 h->ident, sp->confid[cp->protoidx]); 1326 ++ifp->if_ierrors; 1327 break; 1328 } 1329 if (h->type == CONF_NAK) 1330 (cp->RCN_nak)(sp, h, len); 1331 else /* CONF_REJ */ 1332 (cp->RCN_rej)(sp, h, len); --- 14 unchanged lines hidden (view full) --- 1347 case STATE_ACK_RCVD: 1348 sppp_cp_change_state(cp, sp, STATE_ACK_SENT); 1349 (cp->scr)(sp); 1350 break; 1351 case STATE_CLOSING: 1352 case STATE_STOPPING: 1353 break; 1354 default: |
1288 printf("%s%d: %s illegal %s in state %s\n", 1289 ifp->if_name, ifp->if_unit, cp->name, | 1355 printf(SPP_FMT "%s illegal %s in state %s\n", 1356 SPP_ARGS(ifp), cp->name, |
1290 sppp_cp_type_name(h->type), 1291 sppp_state_name(sp->state[cp->protoidx])); 1292 ++ifp->if_ierrors; 1293 } 1294 break; 1295 1296 case TERM_REQ: 1297 switch (sp->state[cp->protoidx]) { --- 4 unchanged lines hidden (view full) --- 1302 case STATE_CLOSED: 1303 case STATE_STOPPED: 1304 case STATE_CLOSING: 1305 case STATE_STOPPING: 1306 case STATE_REQ_SENT: 1307 sta: 1308 /* Send Terminate-Ack packet. */ 1309 if (debug) | 1357 sppp_cp_type_name(h->type), 1358 sppp_state_name(sp->state[cp->protoidx])); 1359 ++ifp->if_ierrors; 1360 } 1361 break; 1362 1363 case TERM_REQ: 1364 switch (sp->state[cp->protoidx]) { --- 4 unchanged lines hidden (view full) --- 1369 case STATE_CLOSED: 1370 case STATE_STOPPED: 1371 case STATE_CLOSING: 1372 case STATE_STOPPING: 1373 case STATE_REQ_SENT: 1374 sta: 1375 /* Send Terminate-Ack packet. */ 1376 if (debug) |
1310 log(LOG_DEBUG, "%s%d: %s send terminate-ack\n", 1311 ifp->if_name, ifp->if_unit, cp->name); | 1377 log(LOG_DEBUG, SPP_FMT "%s send terminate-ack\n", 1378 SPP_ARGS(ifp), cp->name); |
1312 sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, 0, 0); 1313 break; 1314 case STATE_OPENED: 1315 (cp->tld)(sp); 1316 sp->rst_counter[cp->protoidx] = 0; 1317 sppp_cp_change_state(cp, sp, STATE_STOPPING); 1318 goto sta; 1319 break; 1320 default: | 1379 sppp_cp_send(sp, cp->proto, TERM_ACK, h->ident, 0, 0); 1380 break; 1381 case STATE_OPENED: 1382 (cp->tld)(sp); 1383 sp->rst_counter[cp->protoidx] = 0; 1384 sppp_cp_change_state(cp, sp, STATE_STOPPING); 1385 goto sta; 1386 break; 1387 default: |
1321 printf("%s%d: %s illegal %s in state %s\n", 1322 ifp->if_name, ifp->if_unit, cp->name, | 1388 printf(SPP_FMT "%s illegal %s in state %s\n", 1389 SPP_ARGS(ifp), cp->name, |
1323 sppp_cp_type_name(h->type), 1324 sppp_state_name(sp->state[cp->protoidx])); 1325 ++ifp->if_ierrors; 1326 } 1327 break; 1328 case TERM_ACK: 1329 switch (sp->state[cp->protoidx]) { 1330 case STATE_CLOSED: --- 13 unchanged lines hidden (view full) --- 1344 sppp_cp_change_state(cp, sp, STATE_REQ_SENT); 1345 break; 1346 case STATE_OPENED: 1347 (cp->tld)(sp); 1348 (cp->scr)(sp); 1349 sppp_cp_change_state(cp, sp, STATE_ACK_RCVD); 1350 break; 1351 default: | 1390 sppp_cp_type_name(h->type), 1391 sppp_state_name(sp->state[cp->protoidx])); 1392 ++ifp->if_ierrors; 1393 } 1394 break; 1395 case TERM_ACK: 1396 switch (sp->state[cp->protoidx]) { 1397 case STATE_CLOSED: --- 13 unchanged lines hidden (view full) --- 1411 sppp_cp_change_state(cp, sp, STATE_REQ_SENT); 1412 break; 1413 case STATE_OPENED: 1414 (cp->tld)(sp); 1415 (cp->scr)(sp); 1416 sppp_cp_change_state(cp, sp, STATE_ACK_RCVD); 1417 break; 1418 default: |
1352 printf("%s%d: %s illegal %s in state %s\n", 1353 ifp->if_name, ifp->if_unit, cp->name, | 1419 printf(SPP_FMT "%s illegal %s in state %s\n", 1420 SPP_ARGS(ifp), cp->name, |
1354 sppp_cp_type_name(h->type), 1355 sppp_state_name(sp->state[cp->protoidx])); 1356 ++ifp->if_ierrors; 1357 } 1358 break; 1359 case CODE_REJ: 1360 case PROTO_REJ: 1361 /* XXX catastrophic rejects (RXJ-) aren't handled yet. */ 1362 log(LOG_INFO, | 1421 sppp_cp_type_name(h->type), 1422 sppp_state_name(sp->state[cp->protoidx])); 1423 ++ifp->if_ierrors; 1424 } 1425 break; 1426 case CODE_REJ: 1427 case PROTO_REJ: 1428 /* XXX catastrophic rejects (RXJ-) aren't handled yet. */ 1429 log(LOG_INFO, |
1363 "%s%d: %s: ignoring RXJ (%s) for proto 0x%x, " | 1430 SPP_FMT "%s: ignoring RXJ (%s) for proto 0x%x, " |
1364 "danger will robinson\n", | 1431 "danger will robinson\n", |
1365 ifp->if_name, ifp->if_unit, cp->name, | 1432 SPP_ARGS(ifp), cp->name, |
1366 sppp_cp_type_name(h->type), ntohs(*((u_short *)p))); 1367 switch (sp->state[cp->protoidx]) { 1368 case STATE_CLOSED: 1369 case STATE_STOPPED: 1370 case STATE_REQ_SENT: 1371 case STATE_ACK_SENT: 1372 case STATE_CLOSING: 1373 case STATE_STOPPING: 1374 case STATE_OPENED: 1375 break; 1376 case STATE_ACK_RCVD: 1377 sppp_cp_change_state(cp, sp, STATE_REQ_SENT); 1378 break; 1379 default: | 1433 sppp_cp_type_name(h->type), ntohs(*((u_short *)p))); 1434 switch (sp->state[cp->protoidx]) { 1435 case STATE_CLOSED: 1436 case STATE_STOPPED: 1437 case STATE_REQ_SENT: 1438 case STATE_ACK_SENT: 1439 case STATE_CLOSING: 1440 case STATE_STOPPING: 1441 case STATE_OPENED: 1442 break; 1443 case STATE_ACK_RCVD: 1444 sppp_cp_change_state(cp, sp, STATE_REQ_SENT); 1445 break; 1446 default: |
1380 printf("%s%d: %s illegal %s in state %s\n", 1381 ifp->if_name, ifp->if_unit, cp->name, | 1447 printf(SPP_FMT "%s illegal %s in state %s\n", 1448 SPP_ARGS(ifp), cp->name, |
1382 sppp_cp_type_name(h->type), 1383 sppp_state_name(sp->state[cp->protoidx])); 1384 ++ifp->if_ierrors; 1385 } 1386 break; 1387 case DISC_REQ: 1388 if (cp->proto != PPP_LCP) 1389 goto illegal; 1390 /* Discard the packet. */ 1391 break; 1392 case ECHO_REQ: 1393 if (cp->proto != PPP_LCP) 1394 goto illegal; 1395 if (sp->state[cp->protoidx] != STATE_OPENED) { 1396 if (debug) | 1449 sppp_cp_type_name(h->type), 1450 sppp_state_name(sp->state[cp->protoidx])); 1451 ++ifp->if_ierrors; 1452 } 1453 break; 1454 case DISC_REQ: 1455 if (cp->proto != PPP_LCP) 1456 goto illegal; 1457 /* Discard the packet. */ 1458 break; 1459 case ECHO_REQ: 1460 if (cp->proto != PPP_LCP) 1461 goto illegal; 1462 if (sp->state[cp->protoidx] != STATE_OPENED) { 1463 if (debug) |
1397 addlog("%s%d: lcp echo req but lcp closed\n", 1398 ifp->if_name, ifp->if_unit); | 1464 addlog(SPP_FMT "lcp echo req but lcp closed\n", 1465 SPP_ARGS(ifp)); |
1399 ++ifp->if_ierrors; 1400 break; 1401 } 1402 if (len < 8) { 1403 if (debug) | 1466 ++ifp->if_ierrors; 1467 break; 1468 } 1469 if (len < 8) { 1470 if (debug) |
1404 addlog("%s%d: invalid lcp echo request " | 1471 addlog(SPP_FMT "invalid lcp echo request " |
1405 "packet length: %d bytes\n", | 1472 "packet length: %d bytes\n", |
1406 ifp->if_name, ifp->if_unit, len); | 1473 SPP_ARGS(ifp), len); |
1407 break; 1408 } 1409 if (ntohl (*(long*)(h+1)) == sp->lcp.magic) { 1410 /* Line loopback mode detected. */ | 1474 break; 1475 } 1476 if (ntohl (*(long*)(h+1)) == sp->lcp.magic) { 1477 /* Line loopback mode detected. */ |
1411 printf("%s%d: loopback\n", ifp->if_name, ifp->if_unit); | 1478 printf(SPP_FMT "loopback\n", SPP_ARGS(ifp)); |
1412 if_down (ifp); 1413 sppp_qflush (&sp->pp_cpq); 1414 1415 /* Shut down the PPP link. */ 1416 /* XXX */ 1417 lcp.Down(sp); 1418 lcp.Up(sp); 1419 break; 1420 } 1421 *(long*)(h+1) = htonl (sp->lcp.magic); 1422 if (debug) | 1479 if_down (ifp); 1480 sppp_qflush (&sp->pp_cpq); 1481 1482 /* Shut down the PPP link. */ 1483 /* XXX */ 1484 lcp.Down(sp); 1485 lcp.Up(sp); 1486 break; 1487 } 1488 *(long*)(h+1) = htonl (sp->lcp.magic); 1489 if (debug) |
1423 addlog("%s%d: got lcp echo req, sending echo rep\n", 1424 ifp->if_name, ifp->if_unit); | 1490 addlog(SPP_FMT "got lcp echo req, sending echo rep\n", 1491 SPP_ARGS(ifp)); |
1425 sppp_cp_send (sp, PPP_LCP, ECHO_REPLY, h->ident, len-4, h+1); 1426 break; 1427 case ECHO_REPLY: 1428 if (cp->proto != PPP_LCP) 1429 goto illegal; 1430 if (h->ident != sp->lcp.echoid) { 1431 ++ifp->if_ierrors; 1432 break; 1433 } 1434 if (len < 8) { 1435 if (debug) | 1492 sppp_cp_send (sp, PPP_LCP, ECHO_REPLY, h->ident, len-4, h+1); 1493 break; 1494 case ECHO_REPLY: 1495 if (cp->proto != PPP_LCP) 1496 goto illegal; 1497 if (h->ident != sp->lcp.echoid) { 1498 ++ifp->if_ierrors; 1499 break; 1500 } 1501 if (len < 8) { 1502 if (debug) |
1436 addlog("%s%d: lcp invalid echo reply " | 1503 addlog(SPP_FMT "lcp invalid echo reply " |
1437 "packet length: %d bytes\n", | 1504 "packet length: %d bytes\n", |
1438 ifp->if_name, ifp->if_unit, len); | 1505 SPP_ARGS(ifp), len); |
1439 break; 1440 } 1441 if (debug) | 1506 break; 1507 } 1508 if (debug) |
1442 addlog("%s%d: lcp got echo rep\n", 1443 ifp->if_name, ifp->if_unit); | 1509 addlog(SPP_FMT "lcp got echo rep\n", 1510 SPP_ARGS(ifp)); |
1444 if (ntohl (*(long*)(h+1)) != sp->lcp.magic) 1445 sp->pp_alivecnt = 0; 1446 break; 1447 default: 1448 /* Unknown packet type -- send Code-Reject packet. */ 1449 illegal: 1450 if (debug) | 1511 if (ntohl (*(long*)(h+1)) != sp->lcp.magic) 1512 sp->pp_alivecnt = 0; 1513 break; 1514 default: 1515 /* Unknown packet type -- send Code-Reject packet. */ 1516 illegal: 1517 if (debug) |
1451 addlog("%s%d: %s send code-rej for 0x%x\n", 1452 ifp->if_name, ifp->if_unit, cp->name, h->type); | 1518 addlog(SPP_FMT "%s send code-rej for 0x%x\n", 1519 SPP_ARGS(ifp), cp->name, h->type); |
1453 sppp_cp_send(sp, cp->proto, CODE_REJ, ++sp->pp_seq, 1454 m->m_pkthdr.len, h); 1455 ++ifp->if_ierrors; 1456 } 1457} 1458 1459 1460/* 1461 * The generic part of all Up/Down/Open/Close/TO event handlers. 1462 * Basically, the state transition handling in the automaton. 1463 */ 1464static void 1465sppp_up_event(const struct cp *cp, struct sppp *sp) 1466{ 1467 STDDCL; 1468 1469 if (debug) | 1520 sppp_cp_send(sp, cp->proto, CODE_REJ, ++sp->pp_seq, 1521 m->m_pkthdr.len, h); 1522 ++ifp->if_ierrors; 1523 } 1524} 1525 1526 1527/* 1528 * The generic part of all Up/Down/Open/Close/TO event handlers. 1529 * Basically, the state transition handling in the automaton. 1530 */ 1531static void 1532sppp_up_event(const struct cp *cp, struct sppp *sp) 1533{ 1534 STDDCL; 1535 1536 if (debug) |
1470 log(LOG_DEBUG, "%s%d: %s up(%s)\n", 1471 ifp->if_name, ifp->if_unit, cp->name, | 1537 log(LOG_DEBUG, SPP_FMT "%s up(%s)\n", 1538 SPP_ARGS(ifp), cp->name, |
1472 sppp_state_name(sp->state[cp->protoidx])); 1473 1474 switch (sp->state[cp->protoidx]) { 1475 case STATE_INITIAL: 1476 sppp_cp_change_state(cp, sp, STATE_CLOSED); 1477 break; 1478 case STATE_STARTING: 1479 sp->rst_counter[cp->protoidx] = sp->lcp.max_configure; 1480 (cp->scr)(sp); 1481 sppp_cp_change_state(cp, sp, STATE_REQ_SENT); 1482 break; 1483 default: | 1539 sppp_state_name(sp->state[cp->protoidx])); 1540 1541 switch (sp->state[cp->protoidx]) { 1542 case STATE_INITIAL: 1543 sppp_cp_change_state(cp, sp, STATE_CLOSED); 1544 break; 1545 case STATE_STARTING: 1546 sp->rst_counter[cp->protoidx] = sp->lcp.max_configure; 1547 (cp->scr)(sp); 1548 sppp_cp_change_state(cp, sp, STATE_REQ_SENT); 1549 break; 1550 default: |
1484 printf("%s%d: %s illegal up in state %s\n", 1485 ifp->if_name, ifp->if_unit, cp->name, | 1551 printf(SPP_FMT "%s illegal up in state %s\n", 1552 SPP_ARGS(ifp), cp->name, |
1486 sppp_state_name(sp->state[cp->protoidx])); 1487 } 1488} 1489 1490static void 1491sppp_down_event(const struct cp *cp, struct sppp *sp) 1492{ 1493 STDDCL; 1494 1495 if (debug) | 1553 sppp_state_name(sp->state[cp->protoidx])); 1554 } 1555} 1556 1557static void 1558sppp_down_event(const struct cp *cp, struct sppp *sp) 1559{ 1560 STDDCL; 1561 1562 if (debug) |
1496 log(LOG_DEBUG, "%s%d: %s down(%s)\n", 1497 ifp->if_name, ifp->if_unit, cp->name, | 1563 log(LOG_DEBUG, SPP_FMT "%s down(%s)\n", 1564 SPP_ARGS(ifp), cp->name, |
1498 sppp_state_name(sp->state[cp->protoidx])); 1499 1500 switch (sp->state[cp->protoidx]) { 1501 case STATE_CLOSED: 1502 case STATE_CLOSING: 1503 sppp_cp_change_state(cp, sp, STATE_INITIAL); 1504 break; 1505 case STATE_STOPPED: --- 5 unchanged lines hidden (view full) --- 1511 case STATE_ACK_SENT: 1512 sppp_cp_change_state(cp, sp, STATE_STARTING); 1513 break; 1514 case STATE_OPENED: 1515 (cp->tld)(sp); 1516 sppp_cp_change_state(cp, sp, STATE_STARTING); 1517 break; 1518 default: | 1565 sppp_state_name(sp->state[cp->protoidx])); 1566 1567 switch (sp->state[cp->protoidx]) { 1568 case STATE_CLOSED: 1569 case STATE_CLOSING: 1570 sppp_cp_change_state(cp, sp, STATE_INITIAL); 1571 break; 1572 case STATE_STOPPED: --- 5 unchanged lines hidden (view full) --- 1578 case STATE_ACK_SENT: 1579 sppp_cp_change_state(cp, sp, STATE_STARTING); 1580 break; 1581 case STATE_OPENED: 1582 (cp->tld)(sp); 1583 sppp_cp_change_state(cp, sp, STATE_STARTING); 1584 break; 1585 default: |
1519 printf("%s%d: %s illegal down in state %s\n", 1520 ifp->if_name, ifp->if_unit, cp->name, | 1586 printf(SPP_FMT "%s illegal down in state %s\n", 1587 SPP_ARGS(ifp), cp->name, |
1521 sppp_state_name(sp->state[cp->protoidx])); 1522 } 1523} 1524 1525 1526static void 1527sppp_open_event(const struct cp *cp, struct sppp *sp) 1528{ 1529 STDDCL; 1530 1531 if (debug) | 1588 sppp_state_name(sp->state[cp->protoidx])); 1589 } 1590} 1591 1592 1593static void 1594sppp_open_event(const struct cp *cp, struct sppp *sp) 1595{ 1596 STDDCL; 1597 1598 if (debug) |
1532 log(LOG_DEBUG, "%s%d: %s open(%s)\n", 1533 ifp->if_name, ifp->if_unit, cp->name, | 1599 log(LOG_DEBUG, SPP_FMT "%s open(%s)\n", 1600 SPP_ARGS(ifp), cp->name, |
1534 sppp_state_name(sp->state[cp->protoidx])); 1535 1536 switch (sp->state[cp->protoidx]) { 1537 case STATE_INITIAL: 1538 (cp->tls)(sp); 1539 sppp_cp_change_state(cp, sp, STATE_STARTING); 1540 break; 1541 case STATE_STARTING: --- 18 unchanged lines hidden (view full) --- 1560 1561 1562static void 1563sppp_close_event(const struct cp *cp, struct sppp *sp) 1564{ 1565 STDDCL; 1566 1567 if (debug) | 1601 sppp_state_name(sp->state[cp->protoidx])); 1602 1603 switch (sp->state[cp->protoidx]) { 1604 case STATE_INITIAL: 1605 (cp->tls)(sp); 1606 sppp_cp_change_state(cp, sp, STATE_STARTING); 1607 break; 1608 case STATE_STARTING: --- 18 unchanged lines hidden (view full) --- 1627 1628 1629static void 1630sppp_close_event(const struct cp *cp, struct sppp *sp) 1631{ 1632 STDDCL; 1633 1634 if (debug) |
1568 log(LOG_DEBUG, "%s%d: %s close(%s)\n", 1569 ifp->if_name, ifp->if_unit, cp->name, | 1635 log(LOG_DEBUG, SPP_FMT "%s close(%s)\n", 1636 SPP_ARGS(ifp), cp->name, |
1570 sppp_state_name(sp->state[cp->protoidx])); 1571 1572 switch (sp->state[cp->protoidx]) { 1573 case STATE_INITIAL: 1574 case STATE_CLOSED: 1575 case STATE_CLOSING: 1576 break; 1577 case STATE_STARTING: --- 22 unchanged lines hidden (view full) --- 1600static void 1601sppp_to_event(const struct cp *cp, struct sppp *sp) 1602{ 1603 STDDCL; 1604 int s; 1605 1606 s = splimp(); 1607 if (debug) | 1637 sppp_state_name(sp->state[cp->protoidx])); 1638 1639 switch (sp->state[cp->protoidx]) { 1640 case STATE_INITIAL: 1641 case STATE_CLOSED: 1642 case STATE_CLOSING: 1643 break; 1644 case STATE_STARTING: --- 22 unchanged lines hidden (view full) --- 1667static void 1668sppp_to_event(const struct cp *cp, struct sppp *sp) 1669{ 1670 STDDCL; 1671 int s; 1672 1673 s = splimp(); 1674 if (debug) |
1608 log(LOG_DEBUG, "%s%d: %s TO(%s) rst_counter = %d\n", 1609 ifp->if_name, ifp->if_unit, cp->name, | 1675 log(LOG_DEBUG, SPP_FMT "%s TO(%s) rst_counter = %d\n", 1676 SPP_ARGS(ifp), cp->name, |
1610 sppp_state_name(sp->state[cp->protoidx]), 1611 sp->rst_counter[cp->protoidx]); 1612 1613 if (--sp->rst_counter[cp->protoidx] < 0) 1614 /* TO- event */ 1615 switch (sp->state[cp->protoidx]) { 1616 case STATE_CLOSING: 1617 (cp->tlf)(sp); --- 12 unchanged lines hidden (view full) --- 1630 } 1631 else 1632 /* TO+ event */ 1633 switch (sp->state[cp->protoidx]) { 1634 case STATE_CLOSING: 1635 case STATE_STOPPING: 1636 sppp_cp_send(sp, cp->proto, TERM_REQ, ++sp->pp_seq, 1637 0, 0); | 1677 sppp_state_name(sp->state[cp->protoidx]), 1678 sp->rst_counter[cp->protoidx]); 1679 1680 if (--sp->rst_counter[cp->protoidx] < 0) 1681 /* TO- event */ 1682 switch (sp->state[cp->protoidx]) { 1683 case STATE_CLOSING: 1684 (cp->tlf)(sp); --- 12 unchanged lines hidden (view full) --- 1697 } 1698 else 1699 /* TO+ event */ 1700 switch (sp->state[cp->protoidx]) { 1701 case STATE_CLOSING: 1702 case STATE_STOPPING: 1703 sppp_cp_send(sp, cp->proto, TERM_REQ, ++sp->pp_seq, 1704 0, 0); |
1638 sp->ch[cp->protoidx] = timeout(cp->TO, (void *)sp, 1639 sp->lcp.timeout); | 1705#if defined (__FreeBSD__) 1706 sp->ch[cp->protoidx] = 1707#endif 1708 timeout(cp->TO, (void *)sp, sp->lcp.timeout); |
1640 break; 1641 case STATE_REQ_SENT: 1642 case STATE_ACK_RCVD: 1643 (cp->scr)(sp); 1644 /* sppp_cp_change_state() will restart the timer */ 1645 sppp_cp_change_state(cp, sp, STATE_REQ_SENT); 1646 break; 1647 case STATE_ACK_SENT: 1648 (cp->scr)(sp); | 1709 break; 1710 case STATE_REQ_SENT: 1711 case STATE_ACK_RCVD: 1712 (cp->scr)(sp); 1713 /* sppp_cp_change_state() will restart the timer */ 1714 sppp_cp_change_state(cp, sp, STATE_REQ_SENT); 1715 break; 1716 case STATE_ACK_SENT: 1717 (cp->scr)(sp); |
1649 sp->ch[cp->protoidx] = timeout(cp->TO, (void *)sp, 1650 sp->lcp.timeout); | 1718#if defined (__FreeBSD__) 1719 sp->ch[cp->protoidx] = 1720#endif 1721 timeout(cp->TO, (void *)sp, sp->lcp.timeout); |
1651 break; 1652 } 1653 1654 splx(s); 1655} 1656 1657/* 1658 * Change the state of a control protocol in the state automaton. 1659 * Takes care of starting/stopping the restart timer. 1660 */ 1661void 1662sppp_cp_change_state(const struct cp *cp, struct sppp *sp, int newstate) 1663{ 1664 sp->state[cp->protoidx] = newstate; 1665 | 1722 break; 1723 } 1724 1725 splx(s); 1726} 1727 1728/* 1729 * Change the state of a control protocol in the state automaton. 1730 * Takes care of starting/stopping the restart timer. 1731 */ 1732void 1733sppp_cp_change_state(const struct cp *cp, struct sppp *sp, int newstate) 1734{ 1735 sp->state[cp->protoidx] = newstate; 1736 |
1666 untimeout(cp->TO, (void *)sp, sp->ch[cp->protoidx]); | 1737 UNTIMEOUT(cp->TO, (void *)sp, sp->ch[cp->protoidx]); |
1667 switch (newstate) { 1668 case STATE_INITIAL: 1669 case STATE_STARTING: 1670 case STATE_CLOSED: 1671 case STATE_STOPPED: 1672 case STATE_OPENED: 1673 break; 1674 case STATE_CLOSING: 1675 case STATE_STOPPING: 1676 case STATE_REQ_SENT: 1677 case STATE_ACK_RCVD: 1678 case STATE_ACK_SENT: | 1738 switch (newstate) { 1739 case STATE_INITIAL: 1740 case STATE_STARTING: 1741 case STATE_CLOSED: 1742 case STATE_STOPPED: 1743 case STATE_OPENED: 1744 break; 1745 case STATE_CLOSING: 1746 case STATE_STOPPING: 1747 case STATE_REQ_SENT: 1748 case STATE_ACK_RCVD: 1749 case STATE_ACK_SENT: |
1679 sp->ch[cp->protoidx] = timeout(cp->TO, (void *)sp, 1680 sp->lcp.timeout); | 1750#if defined (__FreeBSD__) 1751 sp->ch[cp->protoidx] = 1752#endif 1753 timeout(cp->TO, (void *)sp, sp->lcp.timeout); |
1681 break; 1682 } 1683} 1684/* 1685 *--------------------------------------------------------------------------* 1686 * * 1687 * The LCP implementation. * 1688 * * --- 15 unchanged lines hidden (view full) --- 1704 * running on a fast link. XXX We should probably implement 1705 * the exponential backoff option. Note that these values are 1706 * relevant for all control protocols, not just LCP only. 1707 */ 1708 sp->lcp.timeout = 1 * hz; 1709 sp->lcp.max_terminate = 2; 1710 sp->lcp.max_configure = 10; 1711 sp->lcp.max_failure = 10; | 1754 break; 1755 } 1756} 1757/* 1758 *--------------------------------------------------------------------------* 1759 * * 1760 * The LCP implementation. * 1761 * * --- 15 unchanged lines hidden (view full) --- 1777 * running on a fast link. XXX We should probably implement 1778 * the exponential backoff option. Note that these values are 1779 * relevant for all control protocols, not just LCP only. 1780 */ 1781 sp->lcp.timeout = 1 * hz; 1782 sp->lcp.max_terminate = 2; 1783 sp->lcp.max_configure = 10; 1784 sp->lcp.max_failure = 10; |
1785#if defined (__FreeBSD__) |
|
1712 callout_handle_init(&sp->ch[IDX_LCP]); | 1786 callout_handle_init(&sp->ch[IDX_LCP]); |
1787#endif |
|
1713} 1714 1715static void 1716sppp_lcp_up(struct sppp *sp) 1717{ 1718 STDDCL; 1719 1720 /* 1721 * If this interface is passive or dial-on-demand, and we are 1722 * still in Initial state, it means we've got an incoming 1723 * call. Activate the interface. 1724 */ 1725 if ((ifp->if_flags & (IFF_AUTO | IFF_PASSIVE)) != 0) { 1726 if (debug) 1727 log(LOG_DEBUG, | 1788} 1789 1790static void 1791sppp_lcp_up(struct sppp *sp) 1792{ 1793 STDDCL; 1794 1795 /* 1796 * If this interface is passive or dial-on-demand, and we are 1797 * still in Initial state, it means we've got an incoming 1798 * call. Activate the interface. 1799 */ 1800 if ((ifp->if_flags & (IFF_AUTO | IFF_PASSIVE)) != 0) { 1801 if (debug) 1802 log(LOG_DEBUG, |
1728 "%s%d: Up event", ifp->if_name, ifp->if_unit); | 1803 SPP_FMT "Up event", SPP_ARGS(ifp)); |
1729 ifp->if_flags |= IFF_RUNNING; 1730 if (sp->state[IDX_LCP] == STATE_INITIAL) { 1731 if (debug) 1732 addlog("(incoming call)\n"); 1733 sp->pp_flags |= PP_CALLIN; 1734 lcp.Open(sp); 1735 } else if (debug) 1736 addlog("\n"); --- 13 unchanged lines hidden (view full) --- 1750 * If this is neither a dial-on-demand nor a passive 1751 * interface, simulate an ``ifconfig down'' action, so the 1752 * administrator can force a redial by another ``ifconfig 1753 * up''. XXX For leased line operation, should we immediately 1754 * try to reopen the connection here? 1755 */ 1756 if ((ifp->if_flags & (IFF_AUTO | IFF_PASSIVE)) == 0) { 1757 log(LOG_INFO, | 1804 ifp->if_flags |= IFF_RUNNING; 1805 if (sp->state[IDX_LCP] == STATE_INITIAL) { 1806 if (debug) 1807 addlog("(incoming call)\n"); 1808 sp->pp_flags |= PP_CALLIN; 1809 lcp.Open(sp); 1810 } else if (debug) 1811 addlog("\n"); --- 13 unchanged lines hidden (view full) --- 1825 * If this is neither a dial-on-demand nor a passive 1826 * interface, simulate an ``ifconfig down'' action, so the 1827 * administrator can force a redial by another ``ifconfig 1828 * up''. XXX For leased line operation, should we immediately 1829 * try to reopen the connection here? 1830 */ 1831 if ((ifp->if_flags & (IFF_AUTO | IFF_PASSIVE)) == 0) { 1832 log(LOG_INFO, |
1758 "%s%d: Down event (carrier loss), taking interface down.\n", 1759 ifp->if_name, ifp->if_unit); | 1833 SPP_FMT "Down event (carrier loss), taking interface down.\n", 1834 SPP_ARGS(ifp)); |
1760 if_down(ifp); 1761 } else { 1762 if (debug) 1763 log(LOG_DEBUG, | 1835 if_down(ifp); 1836 } else { 1837 if (debug) 1838 log(LOG_DEBUG, |
1764 "%s%d: Down event (carrier loss)\n", 1765 ifp->if_name, ifp->if_unit); | 1839 SPP_FMT "Down event (carrier loss)\n", 1840 SPP_ARGS(ifp)); |
1766 } 1767 sp->pp_flags &= ~PP_CALLIN; 1768 if (sp->state[IDX_LCP] != STATE_INITIAL) 1769 lcp.Close(sp); 1770 ifp->if_flags &= ~IFF_RUNNING; 1771} 1772 1773static void --- 39 unchanged lines hidden (view full) --- 1813 1814 len -= 4; 1815 origlen = len; 1816 buf = r = malloc (len, M_TEMP, M_NOWAIT); 1817 if (! buf) 1818 return (0); 1819 1820 if (debug) | 1841 } 1842 sp->pp_flags &= ~PP_CALLIN; 1843 if (sp->state[IDX_LCP] != STATE_INITIAL) 1844 lcp.Close(sp); 1845 ifp->if_flags &= ~IFF_RUNNING; 1846} 1847 1848static void --- 39 unchanged lines hidden (view full) --- 1888 1889 len -= 4; 1890 origlen = len; 1891 buf = r = malloc (len, M_TEMP, M_NOWAIT); 1892 if (! buf) 1893 return (0); 1894 1895 if (debug) |
1821 log(LOG_DEBUG, "%s%d: lcp parse opts: ", 1822 ifp->if_name, ifp->if_unit); | 1896 log(LOG_DEBUG, SPP_FMT "lcp parse opts: ", 1897 SPP_ARGS(ifp)); |
1823 1824 /* pass 1: check for things that need to be rejected */ 1825 p = (void*) (h+1); 1826 for (rlen=0; len>1 && p[1]; len-=p[1], p+=p[1]) { 1827 if (debug) 1828 addlog(" %s ", sppp_lcp_opt_name(*p)); 1829 switch (*p) { 1830 case LCP_OPT_MAGIC: --- 57 unchanged lines hidden (view full) --- 1888 } else if (debug) 1889 addlog("\n"); 1890 1891 /* 1892 * pass 2: check for option values that are unacceptable and 1893 * thus require to be nak'ed. 1894 */ 1895 if (debug) | 1898 1899 /* pass 1: check for things that need to be rejected */ 1900 p = (void*) (h+1); 1901 for (rlen=0; len>1 && p[1]; len-=p[1], p+=p[1]) { 1902 if (debug) 1903 addlog(" %s ", sppp_lcp_opt_name(*p)); 1904 switch (*p) { 1905 case LCP_OPT_MAGIC: --- 57 unchanged lines hidden (view full) --- 1963 } else if (debug) 1964 addlog("\n"); 1965 1966 /* 1967 * pass 2: check for option values that are unacceptable and 1968 * thus require to be nak'ed. 1969 */ 1970 if (debug) |
1896 log(LOG_DEBUG, "%s%d: lcp parse opt values: ", 1897 ifp->if_name, ifp->if_unit); | 1971 log(LOG_DEBUG, SPP_FMT "lcp parse opt values: ", 1972 SPP_ARGS(ifp)); |
1898 1899 p = (void*) (h+1); 1900 len = origlen; 1901 for (rlen=0; len>1 && p[1]; len-=p[1], p+=p[1]) { 1902 if (debug) 1903 addlog(" %s ", sppp_lcp_opt_name(*p)); 1904 switch (*p) { 1905 case LCP_OPT_MAGIC: --- 4 unchanged lines hidden (view full) --- 1910 if (debug) 1911 addlog("0x%lx ", nmagic); 1912 continue; 1913 } 1914 /* 1915 * Local and remote magics equal -- loopback? 1916 */ 1917 if (sp->pp_loopcnt >= MAXALIVECNT*5) { | 1973 1974 p = (void*) (h+1); 1975 len = origlen; 1976 for (rlen=0; len>1 && p[1]; len-=p[1], p+=p[1]) { 1977 if (debug) 1978 addlog(" %s ", sppp_lcp_opt_name(*p)); 1979 switch (*p) { 1980 case LCP_OPT_MAGIC: --- 4 unchanged lines hidden (view full) --- 1985 if (debug) 1986 addlog("0x%lx ", nmagic); 1987 continue; 1988 } 1989 /* 1990 * Local and remote magics equal -- loopback? 1991 */ 1992 if (sp->pp_loopcnt >= MAXALIVECNT*5) { |
1918 printf ("%s%d: loopback\n", 1919 ifp->if_name, ifp->if_unit); | 1993 printf (SPP_FMT "loopback\n", 1994 SPP_ARGS(ifp)); |
1920 sp->pp_loopcnt = 0; 1921 if (ifp->if_flags & IFF_UP) { 1922 if_down(ifp); 1923 sppp_qflush(&sp->pp_cpq); 1924 /* XXX ? */ 1925 lcp.Down(sp); 1926 lcp.Up(sp); 1927 } --- 98 unchanged lines hidden (view full) --- 2026 u_char *buf, *p; 2027 2028 len -= 4; 2029 buf = malloc (len, M_TEMP, M_NOWAIT); 2030 if (!buf) 2031 return; 2032 2033 if (debug) | 1995 sp->pp_loopcnt = 0; 1996 if (ifp->if_flags & IFF_UP) { 1997 if_down(ifp); 1998 sppp_qflush(&sp->pp_cpq); 1999 /* XXX ? */ 2000 lcp.Down(sp); 2001 lcp.Up(sp); 2002 } --- 98 unchanged lines hidden (view full) --- 2101 u_char *buf, *p; 2102 2103 len -= 4; 2104 buf = malloc (len, M_TEMP, M_NOWAIT); 2105 if (!buf) 2106 return; 2107 2108 if (debug) |
2034 log(LOG_DEBUG, "%s%d: lcp rej opts: ", 2035 ifp->if_name, ifp->if_unit); | 2109 log(LOG_DEBUG, SPP_FMT "lcp rej opts: ", 2110 SPP_ARGS(ifp)); |
2036 2037 p = (void*) (h+1); 2038 for (; len > 1 && p[1]; len -= p[1], p += p[1]) { 2039 if (debug) 2040 addlog(" %s ", sppp_lcp_opt_name(*p)); 2041 switch (*p) { 2042 case LCP_OPT_MAGIC: 2043 /* Magic number -- can't use it, use 0 */ --- 46 unchanged lines hidden (view full) --- 2090 u_long magic; 2091 2092 len -= 4; 2093 buf = malloc (len, M_TEMP, M_NOWAIT); 2094 if (!buf) 2095 return; 2096 2097 if (debug) | 2111 2112 p = (void*) (h+1); 2113 for (; len > 1 && p[1]; len -= p[1], p += p[1]) { 2114 if (debug) 2115 addlog(" %s ", sppp_lcp_opt_name(*p)); 2116 switch (*p) { 2117 case LCP_OPT_MAGIC: 2118 /* Magic number -- can't use it, use 0 */ --- 46 unchanged lines hidden (view full) --- 2165 u_long magic; 2166 2167 len -= 4; 2168 buf = malloc (len, M_TEMP, M_NOWAIT); 2169 if (!buf) 2170 return; 2171 2172 if (debug) |
2098 log(LOG_DEBUG, "%s%d: lcp nak opts: ", 2099 ifp->if_name, ifp->if_unit); | 2173 log(LOG_DEBUG, SPP_FMT "lcp nak opts: ", 2174 SPP_ARGS(ifp)); |
2100 2101 p = (void*) (h+1); 2102 for (; len > 1 && p[1]; len -= p[1], p += p[1]) { 2103 if (debug) 2104 addlog(" %s ", sppp_lcp_opt_name(*p)); 2105 switch (*p) { 2106 case LCP_OPT_MAGIC: 2107 /* Magic number -- renegotiate */ --- 4 unchanged lines hidden (view full) --- 2112 /* 2113 * If the remote magic is our negated one, 2114 * this looks like a loopback problem. 2115 * Suggest a new magic to make sure. 2116 */ 2117 if (magic == ~sp->lcp.magic) { 2118 if (debug) 2119 addlog("magic glitch "); | 2175 2176 p = (void*) (h+1); 2177 for (; len > 1 && p[1]; len -= p[1], p += p[1]) { 2178 if (debug) 2179 addlog(" %s ", sppp_lcp_opt_name(*p)); 2180 switch (*p) { 2181 case LCP_OPT_MAGIC: 2182 /* Magic number -- renegotiate */ --- 4 unchanged lines hidden (view full) --- 2187 /* 2188 * If the remote magic is our negated one, 2189 * this looks like a loopback problem. 2190 * Suggest a new magic to make sure. 2191 */ 2192 if (magic == ~sp->lcp.magic) { 2193 if (debug) 2194 addlog("magic glitch "); |
2195#if defined (__FreeBSD__) |
|
2120 sp->lcp.magic = random(); | 2196 sp->lcp.magic = random(); |
2197#else 2198 sp->lcp.magic = time.tv_sec + time.tv_usec; 2199#endif |
|
2121 } else { 2122 sp->lcp.magic = magic; 2123 if (debug) | 2200 } else { 2201 sp->lcp.magic = magic; 2202 if (debug) |
2124 addlog("magic %lu ", magic); | 2203 addlog("%lu ", magic); |
2125 } 2126 } 2127 break; 2128 case LCP_OPT_MRU: 2129 /* 2130 * Peer wants to advise us to negotiate an MRU. 2131 * Agree on it if it's reasonable, or use 2132 * default otherwise. --- 23 unchanged lines hidden (view full) --- 2156 addlog("\n"); 2157 free (buf, M_TEMP); 2158 return; 2159} 2160 2161static void 2162sppp_lcp_tlu(struct sppp *sp) 2163{ | 2204 } 2205 } 2206 break; 2207 case LCP_OPT_MRU: 2208 /* 2209 * Peer wants to advise us to negotiate an MRU. 2210 * Agree on it if it's reasonable, or use 2211 * default otherwise. --- 23 unchanged lines hidden (view full) --- 2235 addlog("\n"); 2236 free (buf, M_TEMP); 2237 return; 2238} 2239 2240static void 2241sppp_lcp_tlu(struct sppp *sp) 2242{ |
2164 STDDCL; | 2243 struct ifnet *ifp = &sp->pp_if; |
2165 int i; 2166 u_long mask; 2167 2168 /* XXX ? */ 2169 if (! (ifp->if_flags & IFF_UP) && 2170 (ifp->if_flags & IFF_RUNNING)) { 2171 /* Coming out of loopback mode. */ 2172 if_up(ifp); | 2244 int i; 2245 u_long mask; 2246 2247 /* XXX ? */ 2248 if (! (ifp->if_flags & IFF_UP) && 2249 (ifp->if_flags & IFF_RUNNING)) { 2250 /* Coming out of loopback mode. */ 2251 if_up(ifp); |
2173 printf ("%s%d: up\n", ifp->if_name, ifp->if_unit); | 2252 printf (SPP_FMT "up\n", SPP_ARGS(ifp)); |
2174 } 2175 2176 for (i = 0; i < IDX_COUNT; i++) 2177 if ((cps[i])->flags & CP_QUAL) 2178 (cps[i])->Open(sp); 2179 2180 if ((sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) != 0 || 2181 (sp->pp_flags & PP_NEEDAUTH) != 0) 2182 sp->pp_phase = PHASE_AUTHENTICATE; 2183 else 2184 sp->pp_phase = PHASE_NETWORK; 2185 | 2253 } 2254 2255 for (i = 0; i < IDX_COUNT; i++) 2256 if ((cps[i])->flags & CP_QUAL) 2257 (cps[i])->Open(sp); 2258 2259 if ((sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) != 0 || 2260 (sp->pp_flags & PP_NEEDAUTH) != 0) 2261 sp->pp_phase = PHASE_AUTHENTICATE; 2262 else 2263 sp->pp_phase = PHASE_NETWORK; 2264 |
2186 log(LOG_INFO, "%s%d: phase %s\n", ifp->if_name, ifp->if_unit, | 2265 log(LOG_INFO, SPP_FMT "phase %s\n", SPP_ARGS(ifp), |
2187 sppp_phase_name(sp->pp_phase)); 2188 2189 /* 2190 * Open all authentication protocols. This is even required 2191 * if we already proceeded to network phase, since it might be 2192 * that remote wants us to authenticate, so we might have to 2193 * send a PAP request. Undesired authentication protocols 2194 * don't do anything when they get an Open event. --- 17 unchanged lines hidden (view full) --- 2212 if (sp->pp_phase == PHASE_NETWORK) 2213 /* if no NCP is starting, close down */ 2214 sppp_lcp_check_and_close(sp); 2215} 2216 2217static void 2218sppp_lcp_tld(struct sppp *sp) 2219{ | 2266 sppp_phase_name(sp->pp_phase)); 2267 2268 /* 2269 * Open all authentication protocols. This is even required 2270 * if we already proceeded to network phase, since it might be 2271 * that remote wants us to authenticate, so we might have to 2272 * send a PAP request. Undesired authentication protocols 2273 * don't do anything when they get an Open event. --- 17 unchanged lines hidden (view full) --- 2291 if (sp->pp_phase == PHASE_NETWORK) 2292 /* if no NCP is starting, close down */ 2293 sppp_lcp_check_and_close(sp); 2294} 2295 2296static void 2297sppp_lcp_tld(struct sppp *sp) 2298{ |
2220 STDDCL; | 2299 struct ifnet *ifp = &sp->pp_if; |
2221 int i; 2222 u_long mask; 2223 2224 sp->pp_phase = PHASE_TERMINATE; 2225 | 2300 int i; 2301 u_long mask; 2302 2303 sp->pp_phase = PHASE_TERMINATE; 2304 |
2226 log(LOG_INFO, "%s%d: phase %s\n", ifp->if_name, ifp->if_unit, | 2305 log(LOG_INFO, SPP_FMT "phase %s\n", SPP_ARGS(ifp), |
2227 sppp_phase_name(sp->pp_phase)); 2228 2229 /* 2230 * Take upper layers down. We send the Down event first and 2231 * the Close second to prevent the upper layers from sending 2232 * ``a flurry of terminate-request packets'', as the RFC 2233 * describes it. 2234 */ 2235 for (i = 0, mask = 1; i < IDX_COUNT; i++, mask <<= 1) 2236 if (sp->lcp.protos & mask && ((cps[i])->flags & CP_LCP) == 0) { 2237 (cps[i])->Down(sp); 2238 (cps[i])->Close(sp); 2239 } 2240} 2241 2242static void 2243sppp_lcp_tls(struct sppp *sp) 2244{ | 2306 sppp_phase_name(sp->pp_phase)); 2307 2308 /* 2309 * Take upper layers down. We send the Down event first and 2310 * the Close second to prevent the upper layers from sending 2311 * ``a flurry of terminate-request packets'', as the RFC 2312 * describes it. 2313 */ 2314 for (i = 0, mask = 1; i < IDX_COUNT; i++, mask <<= 1) 2315 if (sp->lcp.protos & mask && ((cps[i])->flags & CP_LCP) == 0) { 2316 (cps[i])->Down(sp); 2317 (cps[i])->Close(sp); 2318 } 2319} 2320 2321static void 2322sppp_lcp_tls(struct sppp *sp) 2323{ |
2245 STDDCL; | 2324 struct ifnet *ifp = &sp->pp_if; |
2246 2247 sp->pp_phase = PHASE_ESTABLISH; 2248 | 2325 2326 sp->pp_phase = PHASE_ESTABLISH; 2327 |
2249 log(LOG_INFO, "%s%d: phase %s\n", ifp->if_name, ifp->if_unit, | 2328 log(LOG_INFO, SPP_FMT "phase %s\n", SPP_ARGS(ifp), |
2250 sppp_phase_name(sp->pp_phase)); 2251 2252 /* Notify lower layer if desired. */ 2253 if (sp->pp_tls) 2254 (sp->pp_tls)(sp); 2255} 2256 2257static void 2258sppp_lcp_tlf(struct sppp *sp) 2259{ | 2329 sppp_phase_name(sp->pp_phase)); 2330 2331 /* Notify lower layer if desired. */ 2332 if (sp->pp_tls) 2333 (sp->pp_tls)(sp); 2334} 2335 2336static void 2337sppp_lcp_tlf(struct sppp *sp) 2338{ |
2260 STDDCL; | 2339 struct ifnet *ifp = &sp->pp_if; |
2261 2262 sp->pp_phase = PHASE_DEAD; | 2340 2341 sp->pp_phase = PHASE_DEAD; |
2263 log(LOG_INFO, "%s%d: phase %s\n", ifp->if_name, ifp->if_unit, | 2342 log(LOG_INFO, SPP_FMT "phase %s\n", SPP_ARGS(ifp), |
2264 sppp_phase_name(sp->pp_phase)); 2265 2266 /* Notify lower layer if desired. */ 2267 if (sp->pp_tlf) 2268 (sp->pp_tlf)(sp); 2269} 2270 2271static void 2272sppp_lcp_scr(struct sppp *sp) 2273{ 2274 char opt[6 /* magicnum */ + 4 /* mru */ + 5 /* chap */]; 2275 int i = 0; 2276 u_short authproto; 2277 2278 if (sp->lcp.opts & (1 << LCP_OPT_MAGIC)) { 2279 if (! sp->lcp.magic) | 2343 sppp_phase_name(sp->pp_phase)); 2344 2345 /* Notify lower layer if desired. */ 2346 if (sp->pp_tlf) 2347 (sp->pp_tlf)(sp); 2348} 2349 2350static void 2351sppp_lcp_scr(struct sppp *sp) 2352{ 2353 char opt[6 /* magicnum */ + 4 /* mru */ + 5 /* chap */]; 2354 int i = 0; 2355 u_short authproto; 2356 2357 if (sp->lcp.opts & (1 << LCP_OPT_MAGIC)) { 2358 if (! sp->lcp.magic) |
2359#if defined (__FreeBSD__) |
|
2280 sp->lcp.magic = random(); | 2360 sp->lcp.magic = random(); |
2361#else 2362 sp->lcp.magic = time.tv_sec + time.tv_usec; 2363#endif |
|
2281 opt[i++] = LCP_OPT_MAGIC; 2282 opt[i++] = 6; 2283 opt[i++] = sp->lcp.magic >> 24; 2284 opt[i++] = sp->lcp.magic >> 16; 2285 opt[i++] = sp->lcp.magic >> 8; 2286 opt[i++] = sp->lcp.magic; 2287 } 2288 --- 59 unchanged lines hidden (view full) --- 2348 2349static void 2350sppp_ipcp_init(struct sppp *sp) 2351{ 2352 sp->ipcp.opts = 0; 2353 sp->ipcp.flags = 0; 2354 sp->state[IDX_IPCP] = STATE_INITIAL; 2355 sp->fail_counter[IDX_IPCP] = 0; | 2364 opt[i++] = LCP_OPT_MAGIC; 2365 opt[i++] = 6; 2366 opt[i++] = sp->lcp.magic >> 24; 2367 opt[i++] = sp->lcp.magic >> 16; 2368 opt[i++] = sp->lcp.magic >> 8; 2369 opt[i++] = sp->lcp.magic; 2370 } 2371 --- 59 unchanged lines hidden (view full) --- 2431 2432static void 2433sppp_ipcp_init(struct sppp *sp) 2434{ 2435 sp->ipcp.opts = 0; 2436 sp->ipcp.flags = 0; 2437 sp->state[IDX_IPCP] = STATE_INITIAL; 2438 sp->fail_counter[IDX_IPCP] = 0; |
2439#if defined (__FreeBSD__) |
|
2356 callout_handle_init(&sp->ch[IDX_IPCP]); | 2440 callout_handle_init(&sp->ch[IDX_IPCP]); |
2441#endif |
|
2357} 2358 2359static void 2360sppp_ipcp_up(struct sppp *sp) 2361{ 2362 sppp_up_event(&ipcp, sp); 2363} 2364 --- 14 unchanged lines hidden (view full) --- 2379 * If we don't have his address, this probably means our 2380 * interface doesn't want to talk IP at all. (This could 2381 * be the case if somebody wants to speak only IPX, for 2382 * example.) Don't open IPCP in this case. 2383 */ 2384 if (hisaddr == 0L) { 2385 /* XXX this message should go away */ 2386 if (debug) | 2442} 2443 2444static void 2445sppp_ipcp_up(struct sppp *sp) 2446{ 2447 sppp_up_event(&ipcp, sp); 2448} 2449 --- 14 unchanged lines hidden (view full) --- 2464 * If we don't have his address, this probably means our 2465 * interface doesn't want to talk IP at all. (This could 2466 * be the case if somebody wants to speak only IPX, for 2467 * example.) Don't open IPCP in this case. 2468 */ 2469 if (hisaddr == 0L) { 2470 /* XXX this message should go away */ 2471 if (debug) |
2387 log(LOG_DEBUG, "%s%d: ipcp_open(): no IP interface\n", 2388 ifp->if_name, ifp->if_unit); | 2472 log(LOG_DEBUG, SPP_FMT "ipcp_open(): no IP interface\n", 2473 SPP_ARGS(ifp)); |
2389 return; 2390 } 2391 2392 if (myaddr == 0L) { 2393 /* 2394 * I don't have an assigned address, so i need to 2395 * negotiate my address. 2396 */ --- 41 unchanged lines hidden (view full) --- 2438 * conf-nak with an `address' option. We might need it below. 2439 */ 2440 buf = r = malloc ((len < 6? 6: len), M_TEMP, M_NOWAIT); 2441 if (! buf) 2442 return (0); 2443 2444 /* pass 1: see if we can recognize them */ 2445 if (debug) | 2474 return; 2475 } 2476 2477 if (myaddr == 0L) { 2478 /* 2479 * I don't have an assigned address, so i need to 2480 * negotiate my address. 2481 */ --- 41 unchanged lines hidden (view full) --- 2523 * conf-nak with an `address' option. We might need it below. 2524 */ 2525 buf = r = malloc ((len < 6? 6: len), M_TEMP, M_NOWAIT); 2526 if (! buf) 2527 return (0); 2528 2529 /* pass 1: see if we can recognize them */ 2530 if (debug) |
2446 log(LOG_DEBUG, "%s%d: ipcp parse opts: ", 2447 ifp->if_name, ifp->if_unit); | 2531 log(LOG_DEBUG, SPP_FMT "ipcp parse opts: ", 2532 SPP_ARGS(ifp)); |
2448 p = (void*) (h+1); 2449 for (rlen=0; len>1 && p[1]; len-=p[1], p+=p[1]) { 2450 if (debug) 2451 addlog(" %s ", sppp_ipcp_opt_name(*p)); 2452 switch (*p) { 2453#ifdef notyet 2454 case IPCP_OPT_COMPRESSION: 2455 if (len >= 6 && p[1] >= 6) { --- 29 unchanged lines hidden (view full) --- 2485 sppp_cp_send (sp, PPP_IPCP, CONF_REJ, h->ident, rlen, buf); 2486 return 0; 2487 } else if (debug) 2488 addlog("\n"); 2489 2490 /* pass 2: parse option values */ 2491 sppp_get_ip_addrs(sp, 0, &hisaddr, 0); 2492 if (debug) | 2533 p = (void*) (h+1); 2534 for (rlen=0; len>1 && p[1]; len-=p[1], p+=p[1]) { 2535 if (debug) 2536 addlog(" %s ", sppp_ipcp_opt_name(*p)); 2537 switch (*p) { 2538#ifdef notyet 2539 case IPCP_OPT_COMPRESSION: 2540 if (len >= 6 && p[1] >= 6) { --- 29 unchanged lines hidden (view full) --- 2570 sppp_cp_send (sp, PPP_IPCP, CONF_REJ, h->ident, rlen, buf); 2571 return 0; 2572 } else if (debug) 2573 addlog("\n"); 2574 2575 /* pass 2: parse option values */ 2576 sppp_get_ip_addrs(sp, 0, &hisaddr, 0); 2577 if (debug) |
2493 log(LOG_DEBUG, "%s%d: ipcp parse opt values: ", 2494 ifp->if_name, ifp->if_unit); | 2578 log(LOG_DEBUG, SPP_FMT "ipcp parse opt values: ", 2579 SPP_ARGS(ifp)); |
2495 p = (void*) (h+1); 2496 len = origlen; 2497 for (rlen=0; len>1 && p[1]; len-=p[1], p+=p[1]) { 2498 if (debug) 2499 addlog(" %s ", sppp_ipcp_opt_name(*p)); 2500 switch (*p) { 2501#ifdef notyet 2502 case IPCP_OPT_COMPRESSION: --- 94 unchanged lines hidden (view full) --- 2597 int debug = ifp->if_flags & IFF_DEBUG; 2598 2599 len -= 4; 2600 buf = malloc (len, M_TEMP, M_NOWAIT); 2601 if (!buf) 2602 return; 2603 2604 if (debug) | 2580 p = (void*) (h+1); 2581 len = origlen; 2582 for (rlen=0; len>1 && p[1]; len-=p[1], p+=p[1]) { 2583 if (debug) 2584 addlog(" %s ", sppp_ipcp_opt_name(*p)); 2585 switch (*p) { 2586#ifdef notyet 2587 case IPCP_OPT_COMPRESSION: --- 94 unchanged lines hidden (view full) --- 2682 int debug = ifp->if_flags & IFF_DEBUG; 2683 2684 len -= 4; 2685 buf = malloc (len, M_TEMP, M_NOWAIT); 2686 if (!buf) 2687 return; 2688 2689 if (debug) |
2605 log(LOG_DEBUG, "%s%d: ipcp rej opts: ", 2606 ifp->if_name, ifp->if_unit); | 2690 log(LOG_DEBUG, SPP_FMT "ipcp rej opts: ", 2691 SPP_ARGS(ifp)); |
2607 2608 p = (void*) (h+1); 2609 for (; len > 1 && p[1]; len -= p[1], p += p[1]) { 2610 if (debug) 2611 addlog(" %s ", sppp_ipcp_opt_name(*p)); 2612 switch (*p) { 2613 case IPCP_OPT_ADDRESS: 2614 /* --- 28 unchanged lines hidden (view full) --- 2643 u_long wantaddr; 2644 2645 len -= 4; 2646 buf = malloc (len, M_TEMP, M_NOWAIT); 2647 if (!buf) 2648 return; 2649 2650 if (debug) | 2692 2693 p = (void*) (h+1); 2694 for (; len > 1 && p[1]; len -= p[1], p += p[1]) { 2695 if (debug) 2696 addlog(" %s ", sppp_ipcp_opt_name(*p)); 2697 switch (*p) { 2698 case IPCP_OPT_ADDRESS: 2699 /* --- 28 unchanged lines hidden (view full) --- 2728 u_long wantaddr; 2729 2730 len -= 4; 2731 buf = malloc (len, M_TEMP, M_NOWAIT); 2732 if (!buf) 2733 return; 2734 2735 if (debug) |
2651 log(LOG_DEBUG, "%s%d: ipcp nak opts: ", 2652 ifp->if_name, ifp->if_unit); | 2736 log(LOG_DEBUG, SPP_FMT "ipcp nak opts: ", 2737 SPP_ARGS(ifp)); |
2653 2654 p = (void*) (h+1); 2655 for (; len > 1 && p[1]; len -= p[1], p += p[1]) { 2656 if (debug) 2657 addlog(" %s ", sppp_ipcp_opt_name(*p)); 2658 switch (*p) { 2659 case IPCP_OPT_ADDRESS: 2660 /* --- 191 unchanged lines hidden (view full) --- 2852 u_char *value, *name, digest[AUTHKEYLEN], dsize; 2853 int value_len, name_len; 2854 MD5_CTX ctx; 2855 2856 len = m->m_pkthdr.len; 2857 if (len < 4) { 2858 if (debug) 2859 log(LOG_DEBUG, | 2738 2739 p = (void*) (h+1); 2740 for (; len > 1 && p[1]; len -= p[1], p += p[1]) { 2741 if (debug) 2742 addlog(" %s ", sppp_ipcp_opt_name(*p)); 2743 switch (*p) { 2744 case IPCP_OPT_ADDRESS: 2745 /* --- 191 unchanged lines hidden (view full) --- 2937 u_char *value, *name, digest[AUTHKEYLEN], dsize; 2938 int value_len, name_len; 2939 MD5_CTX ctx; 2940 2941 len = m->m_pkthdr.len; 2942 if (len < 4) { 2943 if (debug) 2944 log(LOG_DEBUG, |
2860 "%s%d: chap invalid packet length: %d bytes\n", 2861 ifp->if_name, ifp->if_unit, len); | 2945 SPP_FMT "chap invalid packet length: %d bytes\n", 2946 SPP_ARGS(ifp), len); |
2862 return; 2863 } 2864 h = mtod (m, struct lcp_header*); 2865 if (len > ntohs (h->len)) 2866 len = ntohs (h->len); 2867 2868 switch (h->type) { 2869 /* challenge, failure and success are his authproto */ 2870 case CHAP_CHALLENGE: 2871 value = 1 + (u_char*)(h+1); 2872 value_len = value[-1]; 2873 name = value + value_len; 2874 name_len = len - value_len - 5; 2875 if (name_len < 0) { 2876 if (debug) { 2877 log(LOG_DEBUG, | 2947 return; 2948 } 2949 h = mtod (m, struct lcp_header*); 2950 if (len > ntohs (h->len)) 2951 len = ntohs (h->len); 2952 2953 switch (h->type) { 2954 /* challenge, failure and success are his authproto */ 2955 case CHAP_CHALLENGE: 2956 value = 1 + (u_char*)(h+1); 2957 value_len = value[-1]; 2958 name = value + value_len; 2959 name_len = len - value_len - 5; 2960 if (name_len < 0) { 2961 if (debug) { 2962 log(LOG_DEBUG, |
2878 "%s%d: chap corrupted challenge " | 2963 SPP_FMT "chap corrupted challenge " |
2879 "<%s id=0x%x len=%d", | 2964 "<%s id=0x%x len=%d", |
2880 ifp->if_name, ifp->if_unit, | 2965 SPP_ARGS(ifp), |
2881 sppp_auth_type_name(PPP_CHAP, h->type), 2882 h->ident, ntohs(h->len)); 2883 if (len > 4) 2884 sppp_print_bytes((u_char*) (h+1), len-4); 2885 addlog(">\n"); 2886 } 2887 break; 2888 } 2889 2890 if (debug) { 2891 log(LOG_DEBUG, | 2966 sppp_auth_type_name(PPP_CHAP, h->type), 2967 h->ident, ntohs(h->len)); 2968 if (len > 4) 2969 sppp_print_bytes((u_char*) (h+1), len-4); 2970 addlog(">\n"); 2971 } 2972 break; 2973 } 2974 2975 if (debug) { 2976 log(LOG_DEBUG, |
2892 "%s%d: chap input <%s id=0x%x len=%d name=", 2893 ifp->if_name, ifp->if_unit, | 2977 SPP_FMT "chap input <%s id=0x%x len=%d name=", 2978 SPP_ARGS(ifp), |
2894 sppp_auth_type_name(PPP_CHAP, h->type), h->ident, 2895 ntohs(h->len)); 2896 sppp_print_string((char*) name, name_len); 2897 addlog(" value-size=%d value=", value_len); 2898 sppp_print_bytes(value, value_len); 2899 addlog(">\n"); 2900 } 2901 --- 4 unchanged lines hidden (view full) --- 2906 sppp_strnlen(sp->myauth.secret, AUTHKEYLEN)); 2907 MD5Update(&ctx, value, value_len); 2908 MD5Final(digest, &ctx); 2909 dsize = sizeof digest; 2910 2911 sppp_auth_send(&chap, sp, CHAP_RESPONSE, h->ident, 2912 sizeof dsize, (const char *)&dsize, 2913 sizeof digest, digest, | 2979 sppp_auth_type_name(PPP_CHAP, h->type), h->ident, 2980 ntohs(h->len)); 2981 sppp_print_string((char*) name, name_len); 2982 addlog(" value-size=%d value=", value_len); 2983 sppp_print_bytes(value, value_len); 2984 addlog(">\n"); 2985 } 2986 --- 4 unchanged lines hidden (view full) --- 2991 sppp_strnlen(sp->myauth.secret, AUTHKEYLEN)); 2992 MD5Update(&ctx, value, value_len); 2993 MD5Final(digest, &ctx); 2994 dsize = sizeof digest; 2995 2996 sppp_auth_send(&chap, sp, CHAP_RESPONSE, h->ident, 2997 sizeof dsize, (const char *)&dsize, 2998 sizeof digest, digest, |
2914 sppp_strnlen(sp->myauth.name, AUTHNAMELEN), | 2999 (size_t)sppp_strnlen(sp->myauth.name, AUTHNAMELEN), |
2915 sp->myauth.name, 2916 0); 2917 break; 2918 2919 case CHAP_SUCCESS: 2920 if (debug) { | 3000 sp->myauth.name, 3001 0); 3002 break; 3003 3004 case CHAP_SUCCESS: 3005 if (debug) { |
2921 log(LOG_DEBUG, "%s%d: chap success", 2922 ifp->if_name, ifp->if_unit); | 3006 log(LOG_DEBUG, SPP_FMT "chap success", 3007 SPP_ARGS(ifp)); |
2923 if (len > 4) { 2924 addlog(": "); 2925 sppp_print_string((char*)(h + 1), len - 4); 2926 } 2927 addlog("\n"); 2928 } 2929 x = splimp(); 2930 sp->pp_flags &= ~PP_NEEDAUTH; --- 9 unchanged lines hidden (view full) --- 2940 break; 2941 } 2942 splx(x); 2943 sppp_phase_network(sp); 2944 break; 2945 2946 case CHAP_FAILURE: 2947 if (debug) { | 3008 if (len > 4) { 3009 addlog(": "); 3010 sppp_print_string((char*)(h + 1), len - 4); 3011 } 3012 addlog("\n"); 3013 } 3014 x = splimp(); 3015 sp->pp_flags &= ~PP_NEEDAUTH; --- 9 unchanged lines hidden (view full) --- 3025 break; 3026 } 3027 splx(x); 3028 sppp_phase_network(sp); 3029 break; 3030 3031 case CHAP_FAILURE: 3032 if (debug) { |
2948 log(LOG_INFO, "%s%d: chap failure", 2949 ifp->if_name, ifp->if_unit); | 3033 log(LOG_INFO, SPP_FMT "chap failure", 3034 SPP_ARGS(ifp)); |
2950 if (len > 4) { 2951 addlog(": "); 2952 sppp_print_string((char*)(h + 1), len - 4); 2953 } 2954 addlog("\n"); 2955 } else | 3035 if (len > 4) { 3036 addlog(": "); 3037 sppp_print_string((char*)(h + 1), len - 4); 3038 } 3039 addlog("\n"); 3040 } else |
2956 log(LOG_INFO, "%s%d: chap failure\n", 2957 ifp->if_name, ifp->if_unit); | 3041 log(LOG_INFO, SPP_FMT "chap failure\n", 3042 SPP_ARGS(ifp)); |
2958 /* await LCP shutdown by authenticator */ 2959 break; 2960 2961 /* response is my authproto */ 2962 case CHAP_RESPONSE: 2963 value = 1 + (u_char*)(h+1); 2964 value_len = value[-1]; 2965 name = value + value_len; 2966 name_len = len - value_len - 5; 2967 if (name_len < 0) { 2968 if (debug) { 2969 log(LOG_DEBUG, | 3043 /* await LCP shutdown by authenticator */ 3044 break; 3045 3046 /* response is my authproto */ 3047 case CHAP_RESPONSE: 3048 value = 1 + (u_char*)(h+1); 3049 value_len = value[-1]; 3050 name = value + value_len; 3051 name_len = len - value_len - 5; 3052 if (name_len < 0) { 3053 if (debug) { 3054 log(LOG_DEBUG, |
2970 "%s%d: chap corrupted response " | 3055 SPP_FMT "chap corrupted response " |
2971 "<%s id=0x%x len=%d", | 3056 "<%s id=0x%x len=%d", |
2972 ifp->if_name, ifp->if_unit, | 3057 SPP_ARGS(ifp), |
2973 sppp_auth_type_name(PPP_CHAP, h->type), 2974 h->ident, ntohs(h->len)); 2975 if (len > 4) 2976 sppp_print_bytes((u_char*)(h+1), len-4); 2977 addlog(">\n"); 2978 } 2979 break; 2980 } 2981 if (h->ident != sp->confid[IDX_CHAP]) { 2982 if (debug) 2983 log(LOG_DEBUG, | 3058 sppp_auth_type_name(PPP_CHAP, h->type), 3059 h->ident, ntohs(h->len)); 3060 if (len > 4) 3061 sppp_print_bytes((u_char*)(h+1), len-4); 3062 addlog(">\n"); 3063 } 3064 break; 3065 } 3066 if (h->ident != sp->confid[IDX_CHAP]) { 3067 if (debug) 3068 log(LOG_DEBUG, |
2984 "%s%d: chap dropping response for old ID " | 3069 SPP_FMT "chap dropping response for old ID " |
2985 "(got %d, expected %d)\n", | 3070 "(got %d, expected %d)\n", |
2986 ifp->if_name, ifp->if_unit, | 3071 SPP_ARGS(ifp), |
2987 h->ident, sp->confid[IDX_CHAP]); 2988 break; 2989 } 2990 if (name_len != sppp_strnlen(sp->hisauth.name, AUTHNAMELEN) 2991 || bcmp(name, sp->hisauth.name, name_len) != 0) { | 3072 h->ident, sp->confid[IDX_CHAP]); 3073 break; 3074 } 3075 if (name_len != sppp_strnlen(sp->hisauth.name, AUTHNAMELEN) 3076 || bcmp(name, sp->hisauth.name, name_len) != 0) { |
2992 log(LOG_INFO, "%s%d: chap response, his name ", 2993 ifp->if_name, ifp->if_unit); | 3077 log(LOG_INFO, SPP_FMT "chap response, his name ", 3078 SPP_ARGS(ifp)); |
2994 sppp_print_string(name, name_len); 2995 addlog(" != expected "); 2996 sppp_print_string(sp->hisauth.name, 2997 sppp_strnlen(sp->hisauth.name, AUTHNAMELEN)); 2998 addlog("\n"); 2999 } 3000 if (debug) { | 3079 sppp_print_string(name, name_len); 3080 addlog(" != expected "); 3081 sppp_print_string(sp->hisauth.name, 3082 sppp_strnlen(sp->hisauth.name, AUTHNAMELEN)); 3083 addlog("\n"); 3084 } 3085 if (debug) { |
3001 log(LOG_DEBUG, "%s%d: chap input(%s) " | 3086 log(LOG_DEBUG, SPP_FMT "chap input(%s) " |
3002 "<%s id=0x%x len=%d name=", | 3087 "<%s id=0x%x len=%d name=", |
3003 ifp->if_name, ifp->if_unit, | 3088 SPP_ARGS(ifp), |
3004 sppp_state_name(sp->state[IDX_CHAP]), 3005 sppp_auth_type_name(PPP_CHAP, h->type), 3006 h->ident, ntohs (h->len)); 3007 sppp_print_string((char*)name, name_len); 3008 addlog(" value-size=%d value=", value_len); 3009 sppp_print_bytes(value, value_len); 3010 addlog(">\n"); 3011 } 3012 if (value_len != AUTHKEYLEN) { 3013 if (debug) 3014 log(LOG_DEBUG, | 3089 sppp_state_name(sp->state[IDX_CHAP]), 3090 sppp_auth_type_name(PPP_CHAP, h->type), 3091 h->ident, ntohs (h->len)); 3092 sppp_print_string((char*)name, name_len); 3093 addlog(" value-size=%d value=", value_len); 3094 sppp_print_bytes(value, value_len); 3095 addlog(">\n"); 3096 } 3097 if (value_len != AUTHKEYLEN) { 3098 if (debug) 3099 log(LOG_DEBUG, |
3015 "%s%d: chap bad hash value length: " | 3100 SPP_FMT "chap bad hash value length: " |
3016 "%d bytes, should be %d\n", | 3101 "%d bytes, should be %d\n", |
3017 ifp->if_name, ifp->if_unit, value_len, | 3102 SPP_ARGS(ifp), value_len, |
3018 AUTHKEYLEN); 3019 break; 3020 } 3021 3022 MD5Init(&ctx); 3023 MD5Update(&ctx, &h->ident, 1); 3024 MD5Update(&ctx, sp->hisauth.secret, 3025 sppp_strnlen(sp->hisauth.secret, AUTHKEYLEN)); --- 22 unchanged lines hidden (view full) --- 3048 sppp_cp_change_state(&chap, sp, STATE_OPENED); 3049 chap.tlu(sp); 3050 } 3051 break; 3052 3053 default: 3054 /* Unknown CHAP packet type -- ignore. */ 3055 if (debug) { | 3103 AUTHKEYLEN); 3104 break; 3105 } 3106 3107 MD5Init(&ctx); 3108 MD5Update(&ctx, &h->ident, 1); 3109 MD5Update(&ctx, sp->hisauth.secret, 3110 sppp_strnlen(sp->hisauth.secret, AUTHKEYLEN)); --- 22 unchanged lines hidden (view full) --- 3133 sppp_cp_change_state(&chap, sp, STATE_OPENED); 3134 chap.tlu(sp); 3135 } 3136 break; 3137 3138 default: 3139 /* Unknown CHAP packet type -- ignore. */ 3140 if (debug) { |
3056 log(LOG_DEBUG, "%s%d: chap unknown input(%s) " | 3141 log(LOG_DEBUG, SPP_FMT "chap unknown input(%s) " |
3057 "<0x%x id=0x%xh len=%d", | 3142 "<0x%x id=0x%xh len=%d", |
3058 ifp->if_name, ifp->if_unit, | 3143 SPP_ARGS(ifp), |
3059 sppp_state_name(sp->state[IDX_CHAP]), 3060 h->type, h->ident, ntohs(h->len)); 3061 if (len > 4) 3062 sppp_print_bytes((u_char*)(h+1), len-4); 3063 addlog(">\n"); 3064 } 3065 break; 3066 3067 } 3068} 3069 3070static void 3071sppp_chap_init(struct sppp *sp) 3072{ 3073 /* Chap doesn't have STATE_INITIAL at all. */ 3074 sp->state[IDX_CHAP] = STATE_CLOSED; 3075 sp->fail_counter[IDX_CHAP] = 0; | 3144 sppp_state_name(sp->state[IDX_CHAP]), 3145 h->type, h->ident, ntohs(h->len)); 3146 if (len > 4) 3147 sppp_print_bytes((u_char*)(h+1), len-4); 3148 addlog(">\n"); 3149 } 3150 break; 3151 3152 } 3153} 3154 3155static void 3156sppp_chap_init(struct sppp *sp) 3157{ 3158 /* Chap doesn't have STATE_INITIAL at all. */ 3159 sp->state[IDX_CHAP] = STATE_CLOSED; 3160 sp->fail_counter[IDX_CHAP] = 0; |
3161#if defined (__FreeBSD__) |
|
3076 callout_handle_init(&sp->ch[IDX_CHAP]); | 3162 callout_handle_init(&sp->ch[IDX_CHAP]); |
3163#endif |
|
3077} 3078 3079static void 3080sppp_chap_open(struct sppp *sp) 3081{ 3082 if (sp->myauth.proto == PPP_CHAP && 3083 (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) != 0) { 3084 /* we are authenticator for CHAP, start it */ --- 15 unchanged lines hidden (view full) --- 3100sppp_chap_TO(void *cookie) 3101{ 3102 struct sppp *sp = (struct sppp *)cookie; 3103 STDDCL; 3104 int s; 3105 3106 s = splimp(); 3107 if (debug) | 3164} 3165 3166static void 3167sppp_chap_open(struct sppp *sp) 3168{ 3169 if (sp->myauth.proto == PPP_CHAP && 3170 (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) != 0) { 3171 /* we are authenticator for CHAP, start it */ --- 15 unchanged lines hidden (view full) --- 3187sppp_chap_TO(void *cookie) 3188{ 3189 struct sppp *sp = (struct sppp *)cookie; 3190 STDDCL; 3191 int s; 3192 3193 s = splimp(); 3194 if (debug) |
3108 log(LOG_DEBUG, "%s%d: chap TO(%s) rst_counter = %d\n", 3109 ifp->if_name, ifp->if_unit, | 3195 log(LOG_DEBUG, SPP_FMT "chap TO(%s) rst_counter = %d\n", 3196 SPP_ARGS(ifp), |
3110 sppp_state_name(sp->state[IDX_CHAP]), 3111 sp->rst_counter[IDX_CHAP]); 3112 3113 if (--sp->rst_counter[IDX_CHAP] < 0) 3114 /* TO- event */ 3115 switch (sp->state[IDX_CHAP]) { 3116 case STATE_REQ_SENT: 3117 chap.tld(sp); --- 33 unchanged lines hidden (view full) --- 3151 */ 3152 if ((sp->hisauth.flags & AUTHFLAG_NORECHALLENGE) == 0) { 3153 /* 3154 * Compute the re-challenge timeout. This will yield 3155 * a number between 300 and 810 seconds. 3156 */ 3157 i = 300 + ((unsigned)(random() & 0xff00) >> 7); 3158 | 3197 sppp_state_name(sp->state[IDX_CHAP]), 3198 sp->rst_counter[IDX_CHAP]); 3199 3200 if (--sp->rst_counter[IDX_CHAP] < 0) 3201 /* TO- event */ 3202 switch (sp->state[IDX_CHAP]) { 3203 case STATE_REQ_SENT: 3204 chap.tld(sp); --- 33 unchanged lines hidden (view full) --- 3238 */ 3239 if ((sp->hisauth.flags & AUTHFLAG_NORECHALLENGE) == 0) { 3240 /* 3241 * Compute the re-challenge timeout. This will yield 3242 * a number between 300 and 810 seconds. 3243 */ 3244 i = 300 + ((unsigned)(random() & 0xff00) >> 7); 3245 |
3159 sp->ch[IDX_CHAP] = timeout(chap.TO, (void *)sp, i * hz); | 3246#if defined (__FreeBSD__) 3247 sp->ch[IDX_CHAP] = 3248#endif 3249 timeout(chap.TO, (void *)sp, i * hz); |
3160 } 3161 3162 if (debug) { 3163 log(LOG_DEBUG, | 3250 } 3251 3252 if (debug) { 3253 log(LOG_DEBUG, |
3164 "%s%d: chap %s, ", 3165 ifp->if_name, ifp->if_unit, | 3254 SPP_FMT "chap %s, ", 3255 SPP_ARGS(ifp), |
3166 sp->pp_phase == PHASE_NETWORK? "reconfirmed": "tlu"); 3167 if ((sp->hisauth.flags & AUTHFLAG_NORECHALLENGE) == 0) 3168 addlog("next re-challenge in %d seconds\n", i); 3169 else 3170 addlog("re-challenging supressed\n"); 3171 } 3172 3173 x = splimp(); --- 20 unchanged lines hidden (view full) --- 3194} 3195 3196static void 3197sppp_chap_tld(struct sppp *sp) 3198{ 3199 STDDCL; 3200 3201 if (debug) | 3256 sp->pp_phase == PHASE_NETWORK? "reconfirmed": "tlu"); 3257 if ((sp->hisauth.flags & AUTHFLAG_NORECHALLENGE) == 0) 3258 addlog("next re-challenge in %d seconds\n", i); 3259 else 3260 addlog("re-challenging supressed\n"); 3261 } 3262 3263 x = splimp(); --- 20 unchanged lines hidden (view full) --- 3284} 3285 3286static void 3287sppp_chap_tld(struct sppp *sp) 3288{ 3289 STDDCL; 3290 3291 if (debug) |
3202 log(LOG_DEBUG, "%s%d: chap tld\n", ifp->if_name, ifp->if_unit); 3203 untimeout(chap.TO, (void *)sp, sp->ch[IDX_CHAP]); | 3292 log(LOG_DEBUG, SPP_FMT "chap tld\n", SPP_ARGS(ifp)); 3293 UNTIMEOUT(chap.TO, (void *)sp, sp->ch[IDX_CHAP]); |
3204 sp->lcp.protos &= ~(1 << IDX_CHAP); 3205 3206 lcp.Close(sp); 3207} 3208 3209static void 3210sppp_chap_scr(struct sppp *sp) 3211{ 3212 struct timeval tv; 3213 u_long *ch, seed; 3214 u_char clen; 3215 3216 /* Compute random challenge. */ 3217 ch = (u_long *)sp->myauth.challenge; | 3294 sp->lcp.protos &= ~(1 << IDX_CHAP); 3295 3296 lcp.Close(sp); 3297} 3298 3299static void 3300sppp_chap_scr(struct sppp *sp) 3301{ 3302 struct timeval tv; 3303 u_long *ch, seed; 3304 u_char clen; 3305 3306 /* Compute random challenge. */ 3307 ch = (u_long *)sp->myauth.challenge; |
3218 /* 3219 * XXX: This is bad!, there is a well known relationship between the 3220 * four groups of four bytes in the challenge, that improves the 3221 * predictability quite a lot. 3222 */ | 3308#if defined (__FreeBSD__) |
3223 read_random(&seed, sizeof seed); | 3309 read_random(&seed, sizeof seed); |
3310#else 3311 microtime(&tv); 3312 seed = tv.tv_sec ^ tv.tv_usec; 3313#endif |
|
3224 ch[0] = seed ^ random(); 3225 ch[1] = seed ^ random(); 3226 ch[2] = seed ^ random(); 3227 ch[3] = seed ^ random(); 3228 clen = AUTHKEYLEN; 3229 3230 sp->confid[IDX_CHAP] = ++sp->pp_seq; 3231 3232 sppp_auth_send(&chap, sp, CHAP_CHALLENGE, sp->confid[IDX_CHAP], 3233 sizeof clen, (const char *)&clen, | 3314 ch[0] = seed ^ random(); 3315 ch[1] = seed ^ random(); 3316 ch[2] = seed ^ random(); 3317 ch[3] = seed ^ random(); 3318 clen = AUTHKEYLEN; 3319 3320 sp->confid[IDX_CHAP] = ++sp->pp_seq; 3321 3322 sppp_auth_send(&chap, sp, CHAP_CHALLENGE, sp->confid[IDX_CHAP], 3323 sizeof clen, (const char *)&clen, |
3234 AUTHKEYLEN, sp->myauth.challenge, 3235 sppp_strnlen(sp->myauth.name, AUTHNAMELEN), | 3324 (size_t)AUTHKEYLEN, sp->myauth.challenge, 3325 (size_t)sppp_strnlen(sp->myauth.name, AUTHNAMELEN), |
3236 sp->myauth.name, 3237 0); 3238} 3239/* 3240 *--------------------------------------------------------------------------* 3241 * * 3242 * The PAP implementation. * 3243 * * --- 16 unchanged lines hidden (view full) --- 3260 int len, x; 3261 u_char *name, *passwd, mlen; 3262 int name_len, passwd_len; 3263 3264 len = m->m_pkthdr.len; 3265 if (len < 5) { 3266 if (debug) 3267 log(LOG_DEBUG, | 3326 sp->myauth.name, 3327 0); 3328} 3329/* 3330 *--------------------------------------------------------------------------* 3331 * * 3332 * The PAP implementation. * 3333 * * --- 16 unchanged lines hidden (view full) --- 3350 int len, x; 3351 u_char *name, *passwd, mlen; 3352 int name_len, passwd_len; 3353 3354 len = m->m_pkthdr.len; 3355 if (len < 5) { 3356 if (debug) 3357 log(LOG_DEBUG, |
3268 "%s%d: pap invalid packet length: %d bytes\n", 3269 ifp->if_name, ifp->if_unit, len); | 3358 SPP_FMT "pap invalid packet length: %d bytes\n", 3359 SPP_ARGS(ifp), len); |
3270 return; 3271 } 3272 h = mtod (m, struct lcp_header*); 3273 if (len > ntohs (h->len)) 3274 len = ntohs (h->len); 3275 switch (h->type) { 3276 /* PAP request is my authproto */ 3277 case PAP_REQ: 3278 name = 1 + (u_char*)(h+1); 3279 name_len = name[-1]; 3280 passwd = name + name_len + 1; 3281 if (name_len > len - 6 || 3282 (passwd_len = passwd[-1]) > len - 6 - name_len) { 3283 if (debug) { | 3360 return; 3361 } 3362 h = mtod (m, struct lcp_header*); 3363 if (len > ntohs (h->len)) 3364 len = ntohs (h->len); 3365 switch (h->type) { 3366 /* PAP request is my authproto */ 3367 case PAP_REQ: 3368 name = 1 + (u_char*)(h+1); 3369 name_len = name[-1]; 3370 passwd = name + name_len + 1; 3371 if (name_len > len - 6 || 3372 (passwd_len = passwd[-1]) > len - 6 - name_len) { 3373 if (debug) { |
3284 log(LOG_DEBUG, "%s%d: pap corrupted input " | 3374 log(LOG_DEBUG, SPP_FMT "pap corrupted input " |
3285 "<%s id=0x%x len=%d", | 3375 "<%s id=0x%x len=%d", |
3286 ifp->if_name, ifp->if_unit, | 3376 SPP_ARGS(ifp), |
3287 sppp_auth_type_name(PPP_PAP, h->type), 3288 h->ident, ntohs(h->len)); 3289 if (len > 4) 3290 sppp_print_bytes((u_char*)(h+1), len-4); 3291 addlog(">\n"); 3292 } 3293 break; 3294 } 3295 if (debug) { | 3377 sppp_auth_type_name(PPP_PAP, h->type), 3378 h->ident, ntohs(h->len)); 3379 if (len > 4) 3380 sppp_print_bytes((u_char*)(h+1), len-4); 3381 addlog(">\n"); 3382 } 3383 break; 3384 } 3385 if (debug) { |
3296 log(LOG_DEBUG, "%s%d: pap input(%s) " | 3386 log(LOG_DEBUG, SPP_FMT "pap input(%s) " |
3297 "<%s id=0x%x len=%d name=", | 3387 "<%s id=0x%x len=%d name=", |
3298 ifp->if_name, ifp->if_unit, | 3388 SPP_ARGS(ifp), |
3299 sppp_state_name(sp->state[IDX_PAP]), 3300 sppp_auth_type_name(PPP_PAP, h->type), 3301 h->ident, ntohs(h->len)); 3302 sppp_print_string((char*)name, name_len); 3303 addlog(" passwd="); 3304 sppp_print_string((char*)passwd, passwd_len); 3305 addlog(">\n"); 3306 } --- 22 unchanged lines hidden (view full) --- 3329 if (sp->state[IDX_PAP] == STATE_REQ_SENT) { 3330 sppp_cp_change_state(&pap, sp, STATE_OPENED); 3331 pap.tlu(sp); 3332 } 3333 break; 3334 3335 /* ack and nak are his authproto */ 3336 case PAP_ACK: | 3389 sppp_state_name(sp->state[IDX_PAP]), 3390 sppp_auth_type_name(PPP_PAP, h->type), 3391 h->ident, ntohs(h->len)); 3392 sppp_print_string((char*)name, name_len); 3393 addlog(" passwd="); 3394 sppp_print_string((char*)passwd, passwd_len); 3395 addlog(">\n"); 3396 } --- 22 unchanged lines hidden (view full) --- 3419 if (sp->state[IDX_PAP] == STATE_REQ_SENT) { 3420 sppp_cp_change_state(&pap, sp, STATE_OPENED); 3421 pap.tlu(sp); 3422 } 3423 break; 3424 3425 /* ack and nak are his authproto */ 3426 case PAP_ACK: |
3337 untimeout(sppp_pap_my_TO, (void *)sp, sp->pap_my_to_ch); | 3427 UNTIMEOUT(sppp_pap_my_TO, (void *)sp, sp->pap_my_to_ch); |
3338 if (debug) { | 3428 if (debug) { |
3339 log(LOG_DEBUG, "%s%d: pap success", 3340 ifp->if_name, ifp->if_unit); | 3429 log(LOG_DEBUG, SPP_FMT "pap success", 3430 SPP_ARGS(ifp)); |
3341 name_len = *((char *)h); 3342 if (len > 5 && name_len) { 3343 addlog(": "); 3344 sppp_print_string((char*)(h+1), name_len); 3345 } 3346 addlog("\n"); 3347 } 3348 x = splimp(); --- 9 unchanged lines hidden (view full) --- 3358 splx(x); 3359 break; 3360 } 3361 splx(x); 3362 sppp_phase_network(sp); 3363 break; 3364 3365 case PAP_NAK: | 3431 name_len = *((char *)h); 3432 if (len > 5 && name_len) { 3433 addlog(": "); 3434 sppp_print_string((char*)(h+1), name_len); 3435 } 3436 addlog("\n"); 3437 } 3438 x = splimp(); --- 9 unchanged lines hidden (view full) --- 3448 splx(x); 3449 break; 3450 } 3451 splx(x); 3452 sppp_phase_network(sp); 3453 break; 3454 3455 case PAP_NAK: |
3366 untimeout(sppp_pap_my_TO, (void *)sp, sp->pap_my_to_ch); | 3456 UNTIMEOUT(sppp_pap_my_TO, (void *)sp, sp->pap_my_to_ch); |
3367 if (debug) { | 3457 if (debug) { |
3368 log(LOG_INFO, "%s%d: pap failure", 3369 ifp->if_name, ifp->if_unit); | 3458 log(LOG_INFO, SPP_FMT "pap failure", 3459 SPP_ARGS(ifp)); |
3370 name_len = *((char *)h); 3371 if (len > 5 && name_len) { 3372 addlog(": "); 3373 sppp_print_string((char*)(h+1), name_len); 3374 } 3375 addlog("\n"); 3376 } else | 3460 name_len = *((char *)h); 3461 if (len > 5 && name_len) { 3462 addlog(": "); 3463 sppp_print_string((char*)(h+1), name_len); 3464 } 3465 addlog("\n"); 3466 } else |
3377 log(LOG_INFO, "%s%d: pap failure\n", 3378 ifp->if_name, ifp->if_unit); | 3467 log(LOG_INFO, SPP_FMT "pap failure\n", 3468 SPP_ARGS(ifp)); |
3379 /* await LCP shutdown by authenticator */ 3380 break; 3381 3382 default: 3383 /* Unknown PAP packet type -- ignore. */ 3384 if (debug) { | 3469 /* await LCP shutdown by authenticator */ 3470 break; 3471 3472 default: 3473 /* Unknown PAP packet type -- ignore. */ 3474 if (debug) { |
3385 log(LOG_DEBUG, "%s%d: pap corrupted input " | 3475 log(LOG_DEBUG, SPP_FMT "pap corrupted input " |
3386 "<0x%x id=0x%x len=%d", | 3476 "<0x%x id=0x%x len=%d", |
3387 ifp->if_name, ifp->if_unit, | 3477 SPP_ARGS(ifp), |
3388 h->type, h->ident, ntohs(h->len)); 3389 if (len > 4) 3390 sppp_print_bytes((u_char*)(h+1), len-4); 3391 addlog(">\n"); 3392 } 3393 break; 3394 3395 } 3396} 3397 3398static void 3399sppp_pap_init(struct sppp *sp) 3400{ 3401 /* PAP doesn't have STATE_INITIAL at all. */ 3402 sp->state[IDX_PAP] = STATE_CLOSED; 3403 sp->fail_counter[IDX_PAP] = 0; | 3478 h->type, h->ident, ntohs(h->len)); 3479 if (len > 4) 3480 sppp_print_bytes((u_char*)(h+1), len-4); 3481 addlog(">\n"); 3482 } 3483 break; 3484 3485 } 3486} 3487 3488static void 3489sppp_pap_init(struct sppp *sp) 3490{ 3491 /* PAP doesn't have STATE_INITIAL at all. */ 3492 sp->state[IDX_PAP] = STATE_CLOSED; 3493 sp->fail_counter[IDX_PAP] = 0; |
3494#if defined (__FreeBSD__) |
|
3404 callout_handle_init(&sp->ch[IDX_PAP]); 3405 callout_handle_init(&sp->pap_my_to_ch); | 3495 callout_handle_init(&sp->ch[IDX_PAP]); 3496 callout_handle_init(&sp->pap_my_to_ch); |
3497#endif |
|
3406} 3407 3408static void 3409sppp_pap_open(struct sppp *sp) 3410{ 3411 if (sp->hisauth.proto == PPP_PAP && 3412 (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) != 0) { 3413 /* we are authenticator for PAP, start our timer */ 3414 sp->rst_counter[IDX_PAP] = sp->lcp.max_configure; 3415 sppp_cp_change_state(&pap, sp, STATE_REQ_SENT); 3416 } 3417 if (sp->myauth.proto == PPP_PAP) { 3418 /* we are peer, send a request, and start a timer */ 3419 pap.scr(sp); | 3498} 3499 3500static void 3501sppp_pap_open(struct sppp *sp) 3502{ 3503 if (sp->hisauth.proto == PPP_PAP && 3504 (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) != 0) { 3505 /* we are authenticator for PAP, start our timer */ 3506 sp->rst_counter[IDX_PAP] = sp->lcp.max_configure; 3507 sppp_cp_change_state(&pap, sp, STATE_REQ_SENT); 3508 } 3509 if (sp->myauth.proto == PPP_PAP) { 3510 /* we are peer, send a request, and start a timer */ 3511 pap.scr(sp); |
3420 sp->pap_my_to_ch = timeout(sppp_pap_my_TO, (void *)sp, 3421 sp->lcp.timeout); | 3512#if defined (__FreeBSD__) 3513 sp->pap_my_to_ch = 3514#endif 3515 timeout(sppp_pap_my_TO, (void *)sp, sp->lcp.timeout); |
3422 } 3423} 3424 3425static void 3426sppp_pap_close(struct sppp *sp) 3427{ 3428 if (sp->state[IDX_PAP] != STATE_CLOSED) 3429 sppp_cp_change_state(&pap, sp, STATE_CLOSED); --- 7 unchanged lines hidden (view full) --- 3437sppp_pap_TO(void *cookie) 3438{ 3439 struct sppp *sp = (struct sppp *)cookie; 3440 STDDCL; 3441 int s; 3442 3443 s = splimp(); 3444 if (debug) | 3516 } 3517} 3518 3519static void 3520sppp_pap_close(struct sppp *sp) 3521{ 3522 if (sp->state[IDX_PAP] != STATE_CLOSED) 3523 sppp_cp_change_state(&pap, sp, STATE_CLOSED); --- 7 unchanged lines hidden (view full) --- 3531sppp_pap_TO(void *cookie) 3532{ 3533 struct sppp *sp = (struct sppp *)cookie; 3534 STDDCL; 3535 int s; 3536 3537 s = splimp(); 3538 if (debug) |
3445 log(LOG_DEBUG, "%s%d: pap TO(%s) rst_counter = %d\n", 3446 ifp->if_name, ifp->if_unit, | 3539 log(LOG_DEBUG, SPP_FMT "pap TO(%s) rst_counter = %d\n", 3540 SPP_ARGS(ifp), |
3447 sppp_state_name(sp->state[IDX_PAP]), 3448 sp->rst_counter[IDX_PAP]); 3449 3450 if (--sp->rst_counter[IDX_PAP] < 0) 3451 /* TO- event */ 3452 switch (sp->state[IDX_PAP]) { 3453 case STATE_REQ_SENT: 3454 pap.tld(sp); --- 19 unchanged lines hidden (view full) --- 3474 */ 3475static void 3476sppp_pap_my_TO(void *cookie) 3477{ 3478 struct sppp *sp = (struct sppp *)cookie; 3479 STDDCL; 3480 3481 if (debug) | 3541 sppp_state_name(sp->state[IDX_PAP]), 3542 sp->rst_counter[IDX_PAP]); 3543 3544 if (--sp->rst_counter[IDX_PAP] < 0) 3545 /* TO- event */ 3546 switch (sp->state[IDX_PAP]) { 3547 case STATE_REQ_SENT: 3548 pap.tld(sp); --- 19 unchanged lines hidden (view full) --- 3568 */ 3569static void 3570sppp_pap_my_TO(void *cookie) 3571{ 3572 struct sppp *sp = (struct sppp *)cookie; 3573 STDDCL; 3574 3575 if (debug) |
3482 log(LOG_DEBUG, "%s%d: pap peer TO\n", 3483 ifp->if_name, ifp->if_unit); | 3576 log(LOG_DEBUG, SPP_FMT "pap peer TO\n", 3577 SPP_ARGS(ifp)); |
3484 3485 pap.scr(sp); 3486} 3487 3488static void 3489sppp_pap_tlu(struct sppp *sp) 3490{ 3491 STDDCL; 3492 int x; 3493 3494 sp->rst_counter[IDX_PAP] = sp->lcp.max_configure; 3495 3496 if (debug) | 3578 3579 pap.scr(sp); 3580} 3581 3582static void 3583sppp_pap_tlu(struct sppp *sp) 3584{ 3585 STDDCL; 3586 int x; 3587 3588 sp->rst_counter[IDX_PAP] = sp->lcp.max_configure; 3589 3590 if (debug) |
3497 log(LOG_DEBUG, "%s%d: %s tlu\n", 3498 ifp->if_name, ifp->if_unit, pap.name); | 3591 log(LOG_DEBUG, SPP_FMT "%s tlu\n", 3592 SPP_ARGS(ifp), pap.name); |
3499 3500 x = splimp(); 3501 /* indicate to LCP that we need to be closed down */ 3502 sp->lcp.protos |= (1 << IDX_PAP); 3503 3504 if (sp->pp_flags & PP_NEEDAUTH) { 3505 /* 3506 * Remote is authenticator, but his auth proto didn't --- 8 unchanged lines hidden (view full) --- 3515} 3516 3517static void 3518sppp_pap_tld(struct sppp *sp) 3519{ 3520 STDDCL; 3521 3522 if (debug) | 3593 3594 x = splimp(); 3595 /* indicate to LCP that we need to be closed down */ 3596 sp->lcp.protos |= (1 << IDX_PAP); 3597 3598 if (sp->pp_flags & PP_NEEDAUTH) { 3599 /* 3600 * Remote is authenticator, but his auth proto didn't --- 8 unchanged lines hidden (view full) --- 3609} 3610 3611static void 3612sppp_pap_tld(struct sppp *sp) 3613{ 3614 STDDCL; 3615 3616 if (debug) |
3523 log(LOG_DEBUG, "%s%d: pap tld\n", ifp->if_name, ifp->if_unit); 3524 untimeout(pap.TO, (void *)sp, sp->ch[IDX_PAP]); 3525 untimeout(sppp_pap_my_TO, (void *)sp, sp->pap_my_to_ch); | 3617 log(LOG_DEBUG, SPP_FMT "pap tld\n", SPP_ARGS(ifp)); 3618 UNTIMEOUT(pap.TO, (void *)sp, sp->ch[IDX_PAP]); 3619 UNTIMEOUT(sppp_pap_my_TO, (void *)sp, sp->pap_my_to_ch); |
3526 sp->lcp.protos &= ~(1 << IDX_PAP); 3527 3528 lcp.Close(sp); 3529} 3530 3531static void 3532sppp_pap_scr(struct sppp *sp) 3533{ | 3620 sp->lcp.protos &= ~(1 << IDX_PAP); 3621 3622 lcp.Close(sp); 3623} 3624 3625static void 3626sppp_pap_scr(struct sppp *sp) 3627{ |
3534 STDDCL; | |
3535 u_char idlen, pwdlen; 3536 3537 sp->confid[IDX_PAP] = ++sp->pp_seq; 3538 pwdlen = sppp_strnlen(sp->myauth.secret, AUTHKEYLEN); 3539 idlen = sppp_strnlen(sp->myauth.name, AUTHNAMELEN); 3540 3541 sppp_auth_send(&pap, sp, PAP_REQ, sp->confid[IDX_PAP], 3542 sizeof idlen, (const char *)&idlen, | 3628 u_char idlen, pwdlen; 3629 3630 sp->confid[IDX_PAP] = ++sp->pp_seq; 3631 pwdlen = sppp_strnlen(sp->myauth.secret, AUTHKEYLEN); 3632 idlen = sppp_strnlen(sp->myauth.name, AUTHNAMELEN); 3633 3634 sppp_auth_send(&pap, sp, PAP_REQ, sp->confid[IDX_PAP], 3635 sizeof idlen, (const char *)&idlen, |
3543 (unsigned)idlen, sp->myauth.name, | 3636 (size_t)idlen, sp->myauth.name, |
3544 sizeof pwdlen, (const char *)&pwdlen, | 3637 sizeof pwdlen, (const char *)&pwdlen, |
3545 (unsigned)pwdlen, sp->myauth.secret, | 3638 (size_t)pwdlen, sp->myauth.secret, |
3546 0); 3547} 3548/* 3549 * Random miscellaneous functions. 3550 */ 3551 3552/* 3553 * Send a PAP or CHAP proto packet. 3554 * 3555 * Varadic function, each of the elements for the ellipsis is of type | 3639 0); 3640} 3641/* 3642 * Random miscellaneous functions. 3643 */ 3644 3645/* 3646 * Send a PAP or CHAP proto packet. 3647 * 3648 * Varadic function, each of the elements for the ellipsis is of type |
3556 * ``unsigned mlen, const u_char *msg''. Processing will stop iff | 3649 * ``size_t mlen, const u_char *msg''. Processing will stop iff |
3557 * mlen == 0. 3558 */ 3559 3560static void 3561sppp_auth_send(const struct cp *cp, struct sppp *sp, u_char type, u_char id, 3562 ...) 3563{ 3564 STDDCL; 3565 struct ppp_header *h; 3566 struct lcp_header *lh; 3567 struct mbuf *m; 3568 u_char *p; 3569 int len; | 3650 * mlen == 0. 3651 */ 3652 3653static void 3654sppp_auth_send(const struct cp *cp, struct sppp *sp, u_char type, u_char id, 3655 ...) 3656{ 3657 STDDCL; 3658 struct ppp_header *h; 3659 struct lcp_header *lh; 3660 struct mbuf *m; 3661 u_char *p; 3662 int len; |
3570 unsigned mlen; | 3663 size_t mlen; |
3571 const char *msg; 3572 va_list ap; 3573 3574 MGETHDR (m, M_DONTWAIT, MT_DATA); 3575 if (! m) 3576 return; 3577 m->m_pkthdr.rcvif = 0; 3578 --- 5 unchanged lines hidden (view full) --- 3584 lh = (struct lcp_header*)(h + 1); 3585 lh->type = type; 3586 lh->ident = id; 3587 p = (u_char*) (lh+1); 3588 3589 va_start(ap, id); 3590 len = 0; 3591 | 3664 const char *msg; 3665 va_list ap; 3666 3667 MGETHDR (m, M_DONTWAIT, MT_DATA); 3668 if (! m) 3669 return; 3670 m->m_pkthdr.rcvif = 0; 3671 --- 5 unchanged lines hidden (view full) --- 3677 lh = (struct lcp_header*)(h + 1); 3678 lh->type = type; 3679 lh->ident = id; 3680 p = (u_char*) (lh+1); 3681 3682 va_start(ap, id); 3683 len = 0; 3684 |
3592 while ((mlen = va_arg(ap, unsigned)) != 0) { | 3685 while ((mlen = va_arg(ap, size_t)) != 0) { |
3593 msg = va_arg(ap, const char *); 3594 len += mlen; 3595 if (len > MHLEN - PPP_HEADER_LEN - LCP_HEADER_LEN) { 3596 va_end(ap); 3597 m_freem(m); 3598 return; 3599 } 3600 3601 bcopy(msg, p, mlen); 3602 p += mlen; 3603 } 3604 va_end(ap); 3605 3606 m->m_pkthdr.len = m->m_len = PPP_HEADER_LEN + LCP_HEADER_LEN + len; 3607 lh->len = htons (LCP_HEADER_LEN + len); 3608 3609 if (debug) { | 3686 msg = va_arg(ap, const char *); 3687 len += mlen; 3688 if (len > MHLEN - PPP_HEADER_LEN - LCP_HEADER_LEN) { 3689 va_end(ap); 3690 m_freem(m); 3691 return; 3692 } 3693 3694 bcopy(msg, p, mlen); 3695 p += mlen; 3696 } 3697 va_end(ap); 3698 3699 m->m_pkthdr.len = m->m_len = PPP_HEADER_LEN + LCP_HEADER_LEN + len; 3700 lh->len = htons (LCP_HEADER_LEN + len); 3701 3702 if (debug) { |
3610 log(LOG_DEBUG, "%s%d: %s output <%s id=0x%x len=%d", 3611 ifp->if_name, ifp->if_unit, cp->name, | 3703 log(LOG_DEBUG, SPP_FMT "%s output <%s id=0x%x len=%d", 3704 SPP_ARGS(ifp), cp->name, |
3612 sppp_auth_type_name(cp->proto, lh->type), 3613 lh->ident, ntohs(lh->len)); 3614 if (len) 3615 sppp_print_bytes((u_char*) (lh+1), len); 3616 addlog(">\n"); 3617 } 3618 if (IF_QFULL (&sp->pp_cpq)) { 3619 IF_DROP (&sp->pp_fastq); --- 45 unchanged lines hidden (view full) --- 3665 3666 /* No keepalive in PPP mode if LCP not opened yet. */ 3667 if (! (sp->pp_flags & PP_CISCO) && 3668 sp->pp_phase < PHASE_AUTHENTICATE) 3669 continue; 3670 3671 if (sp->pp_alivecnt == MAXALIVECNT) { 3672 /* No keepalive packets got. Stop the interface. */ | 3705 sppp_auth_type_name(cp->proto, lh->type), 3706 lh->ident, ntohs(lh->len)); 3707 if (len) 3708 sppp_print_bytes((u_char*) (lh+1), len); 3709 addlog(">\n"); 3710 } 3711 if (IF_QFULL (&sp->pp_cpq)) { 3712 IF_DROP (&sp->pp_fastq); --- 45 unchanged lines hidden (view full) --- 3758 3759 /* No keepalive in PPP mode if LCP not opened yet. */ 3760 if (! (sp->pp_flags & PP_CISCO) && 3761 sp->pp_phase < PHASE_AUTHENTICATE) 3762 continue; 3763 3764 if (sp->pp_alivecnt == MAXALIVECNT) { 3765 /* No keepalive packets got. Stop the interface. */ |
3673 printf ("%s%d: down\n", ifp->if_name, ifp->if_unit); | 3766 printf (SPP_FMT "down\n", SPP_ARGS(ifp)); |
3674 if_down (ifp); 3675 sppp_qflush (&sp->pp_cpq); 3676 if (! (sp->pp_flags & PP_CISCO)) { 3677 /* XXX */ 3678 /* Shut down the PPP link. */ 3679 lcp.Down(sp); 3680 /* Initiate negotiation. XXX */ 3681 lcp.Up(sp); --- 7 unchanged lines hidden (view full) --- 3689 else if (sp->pp_phase >= PHASE_AUTHENTICATE) { 3690 long nmagic = htonl (sp->lcp.magic); 3691 sp->lcp.echoid = ++sp->pp_seq; 3692 sppp_cp_send (sp, PPP_LCP, ECHO_REQ, 3693 sp->lcp.echoid, 4, &nmagic); 3694 } 3695 } 3696 splx(s); | 3767 if_down (ifp); 3768 sppp_qflush (&sp->pp_cpq); 3769 if (! (sp->pp_flags & PP_CISCO)) { 3770 /* XXX */ 3771 /* Shut down the PPP link. */ 3772 lcp.Down(sp); 3773 /* Initiate negotiation. XXX */ 3774 lcp.Up(sp); --- 7 unchanged lines hidden (view full) --- 3782 else if (sp->pp_phase >= PHASE_AUTHENTICATE) { 3783 long nmagic = htonl (sp->lcp.magic); 3784 sp->lcp.echoid = ++sp->pp_seq; 3785 sppp_cp_send (sp, PPP_LCP, ECHO_REQ, 3786 sp->lcp.echoid, 4, &nmagic); 3787 } 3788 } 3789 splx(s); |
3697 keepalive_ch = timeout(sppp_keepalive, 0, hz * 10); | 3790#if defined (__FreeBSD__) 3791 keepalive_ch = 3792#endif 3793 timeout(sppp_keepalive, 0, hz * 10); |
3698} 3699 3700/* 3701 * Get both IP addresses. 3702 */ 3703static void 3704sppp_get_ip_addrs(struct sppp *sp, u_long *src, u_long *dst, u_long *srcmask) 3705{ 3706 struct ifnet *ifp = &sp->pp_if; 3707 struct ifaddr *ifa; 3708 struct sockaddr_in *si, *sm; 3709 u_long ssrc, ddst; 3710 3711 ssrc = ddst = 0L; 3712 /* 3713 * Pick the first AF_INET address from the list, 3714 * aliases don't make any sense on a p2p link anyway. 3715 */ | 3794} 3795 3796/* 3797 * Get both IP addresses. 3798 */ 3799static void 3800sppp_get_ip_addrs(struct sppp *sp, u_long *src, u_long *dst, u_long *srcmask) 3801{ 3802 struct ifnet *ifp = &sp->pp_if; 3803 struct ifaddr *ifa; 3804 struct sockaddr_in *si, *sm; 3805 u_long ssrc, ddst; 3806 3807 ssrc = ddst = 0L; 3808 /* 3809 * Pick the first AF_INET address from the list, 3810 * aliases don't make any sense on a p2p link anyway. 3811 */ |
3812#if defined (__FreeBSD__) |
|
3716 for (ifa = ifp->if_addrhead.tqh_first, si = 0; 3717 ifa; 3718 ifa = ifa->ifa_link.tqe_next) | 3813 for (ifa = ifp->if_addrhead.tqh_first, si = 0; 3814 ifa; 3815 ifa = ifa->ifa_link.tqe_next) |
3816#else 3817 for (ifa = ifp->if_addrlist.tqh_first, si = 0; 3818 ifa; 3819 ifa = ifa->ifa_list.tqe_next) 3820#endif |
|
3719 if (ifa->ifa_addr->sa_family == AF_INET) { 3720 si = (struct sockaddr_in *)ifa->ifa_addr; 3721 sm = (struct sockaddr_in *)ifa->ifa_netmask; 3722 if (si) 3723 break; 3724 } 3725 if (ifa) { 3726 if (si && si->sin_addr.s_addr) { --- 12 unchanged lines hidden (view full) --- 3739} 3740 3741/* 3742 * Set my IP address. Must be called at splimp. 3743 */ 3744static void 3745sppp_set_ip_addr(struct sppp *sp, u_long src) 3746{ | 3821 if (ifa->ifa_addr->sa_family == AF_INET) { 3822 si = (struct sockaddr_in *)ifa->ifa_addr; 3823 sm = (struct sockaddr_in *)ifa->ifa_netmask; 3824 if (si) 3825 break; 3826 } 3827 if (ifa) { 3828 if (si && si->sin_addr.s_addr) { --- 12 unchanged lines hidden (view full) --- 3841} 3842 3843/* 3844 * Set my IP address. Must be called at splimp. 3845 */ 3846static void 3847sppp_set_ip_addr(struct sppp *sp, u_long src) 3848{ |
3747 struct ifnet *ifp = &sp->pp_if; | 3849 STDDCL; |
3748 struct ifaddr *ifa; 3749 struct sockaddr_in *si; | 3850 struct ifaddr *ifa; 3851 struct sockaddr_in *si; |
3750 u_long ssrc, ddst; | |
3751 3752 /* 3753 * Pick the first AF_INET address from the list, 3754 * aliases don't make any sense on a p2p link anyway. 3755 */ | 3852 3853 /* 3854 * Pick the first AF_INET address from the list, 3855 * aliases don't make any sense on a p2p link anyway. 3856 */ |
3857 3858#if defined (__FreeBSD__) |
|
3756 for (ifa = ifp->if_addrhead.tqh_first, si = 0; 3757 ifa; 3758 ifa = ifa->ifa_link.tqe_next) | 3859 for (ifa = ifp->if_addrhead.tqh_first, si = 0; 3860 ifa; 3861 ifa = ifa->ifa_link.tqe_next) |
3759 if (ifa->ifa_addr->sa_family == AF_INET) { | 3862#else 3863 for (ifa = ifp->if_addrlist.tqh_first, si = 0; 3864 ifa; 3865 ifa = ifa->ifa_list.tqe_next) 3866#endif 3867 { 3868 if (ifa->ifa_addr->sa_family == AF_INET) 3869 { |
3760 si = (struct sockaddr_in *)ifa->ifa_addr; 3761 if (si) 3762 break; 3763 } | 3870 si = (struct sockaddr_in *)ifa->ifa_addr; 3871 if (si) 3872 break; 3873 } |
3874 } 3875 |
|
3764 if (ifa && si) 3765 si->sin_addr.s_addr = htonl(src); 3766} 3767 3768static int 3769sppp_params(struct sppp *sp, u_long cmd, void *data) 3770{ 3771 u_long subcmd; --- 101 unchanged lines hidden (view full) --- 3873sppp_phase_network(struct sppp *sp) 3874{ 3875 struct ifnet *ifp = &sp->pp_if; 3876 int i; 3877 u_long mask; 3878 3879 sp->pp_phase = PHASE_NETWORK; 3880 | 3876 if (ifa && si) 3877 si->sin_addr.s_addr = htonl(src); 3878} 3879 3880static int 3881sppp_params(struct sppp *sp, u_long cmd, void *data) 3882{ 3883 u_long subcmd; --- 101 unchanged lines hidden (view full) --- 3985sppp_phase_network(struct sppp *sp) 3986{ 3987 struct ifnet *ifp = &sp->pp_if; 3988 int i; 3989 u_long mask; 3990 3991 sp->pp_phase = PHASE_NETWORK; 3992 |
3881 log(LOG_INFO, "%s%d: phase %s\n", ifp->if_name, ifp->if_unit, | 3993 log(LOG_INFO, SPP_FMT "phase %s\n", SPP_ARGS(ifp), |
3882 sppp_phase_name(sp->pp_phase)); 3883 3884 /* Notify NCPs now. */ 3885 for (i = 0; i < IDX_COUNT; i++) 3886 if ((cps[i])->flags & CP_NCP) 3887 (cps[i])->Open(sp); 3888 3889 /* Send Up events to all NCPs. */ --- 123 unchanged lines hidden (view full) --- 4013 } 4014 sprintf(buf, "0x%x", (unsigned)proto); 4015 return buf; 4016} 4017 4018static void 4019sppp_print_bytes(const u_char *p, u_short len) 4020{ | 3994 sppp_phase_name(sp->pp_phase)); 3995 3996 /* Notify NCPs now. */ 3997 for (i = 0; i < IDX_COUNT; i++) 3998 if ((cps[i])->flags & CP_NCP) 3999 (cps[i])->Open(sp); 4000 4001 /* Send Up events to all NCPs. */ --- 123 unchanged lines hidden (view full) --- 4125 } 4126 sprintf(buf, "0x%x", (unsigned)proto); 4127 return buf; 4128} 4129 4130static void 4131sppp_print_bytes(const u_char *p, u_short len) 4132{ |
4021 addlog(" %x", *p++); | 4133 addlog(" %02x", *p++); |
4022 while (--len > 0) | 4134 while (--len > 0) |
4023 addlog("-%x", *p++); | 4135 addlog("-%02x", *p++); |
4024} 4025 4026static void 4027sppp_print_string(const char *p, u_short len) 4028{ 4029 u_char c; 4030 4031 while (len-- > 0) { --- 8 unchanged lines hidden (view full) --- 4040 } 4041} 4042 4043static const char * 4044sppp_dotted_quad(u_long addr) 4045{ 4046 static char s[16]; 4047 sprintf(s, "%d.%d.%d.%d", | 4136} 4137 4138static void 4139sppp_print_string(const char *p, u_short len) 4140{ 4141 u_char c; 4142 4143 while (len-- > 0) { --- 8 unchanged lines hidden (view full) --- 4152 } 4153} 4154 4155static const char * 4156sppp_dotted_quad(u_long addr) 4157{ 4158 static char s[16]; 4159 sprintf(s, "%d.%d.%d.%d", |
4048 (int)(addr >> 24) & 0xff, 4049 (int)(addr >> 16) & 0xff, 4050 (int)(addr >> 8) & 0xff, | 4160 (int)((addr >> 24) & 0xff), 4161 (int)((addr >> 16) & 0xff), 4162 (int)((addr >> 8) & 0xff), |
4051 (int)(addr & 0xff)); 4052 return s; 4053} 4054 4055static int 4056sppp_strnlen(u_char *p, int max) 4057{ 4058 int len; --- 19 unchanged lines hidden --- | 4163 (int)(addr & 0xff)); 4164 return s; 4165} 4166 4167static int 4168sppp_strnlen(u_char *p, int max) 4169{ 4170 int len; --- 19 unchanged lines hidden --- |