if_spppsubr.c revision 11189
1/* 2 * Synchronous PPP/Cisco link level subroutines. 3 * Keepalive protocol implemented in both Cisco and PPP modes. 4 * 5 * Copyright (C) 1994 Cronyx Ltd. 6 * Author: Serge Vakulenko, <vak@zebub.msk.su> 7 * 8 * This software is distributed with NO WARRANTIES, not even the implied 9 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 * 11 * Authors grant any other persons or organisations permission to use 12 * or modify this software as long as this message is kept with the software, 13 * all derivative works or modified versions. 14 * 15 * Version 1.9, Wed Oct 4 18:58:15 MSK 1995 16 */ 17#undef DEBUG 18 19#include <sys/param.h> 20#include <sys/systm.h> 21#include <sys/kernel.h> 22#include <sys/ioctl.h> 23#include <sys/socket.h> 24#include <sys/mbuf.h> 25 26#include <net/if.h> 27#include <net/netisr.h> 28#include <net/if_types.h> 29 30#ifdef INET 31#include <netinet/in.h> 32#include <netinet/in_systm.h> 33#include <netinet/in_var.h> 34#include <netinet/ip.h> 35#include <netinet/tcp.h> 36#include <netinet/if_ether.h> 37#endif 38 39#ifdef NS 40#include <netns/ns.h> 41#include <netns/ns_if.h> 42#endif 43 44#ifdef ISO 45#include <netiso/argo_debug.h> 46#include <netiso/iso.h> 47#include <netiso/iso_var.h> 48#include <netiso/iso_snpac.h> 49#endif 50 51#include <net/if_sppp.h> 52 53#ifdef DEBUG 54#define print(s) printf s 55#else 56#define print(s) {/*void*/} 57#endif 58 59#define MAXALIVECNT 3 /* max. alive packets */ 60 61#define PPP_ALLSTATIONS 0xff /* All-Stations broadcast address */ 62#define PPP_UI 0x03 /* Unnumbered Information */ 63#define PPP_IP 0x0021 /* Internet Protocol */ 64#define PPP_ISO 0x0023 /* ISO OSI Protocol */ 65#define PPP_XNS 0x0025 /* Xerox NS Protocol */ 66#define PPP_LCP 0xc021 /* Link Control Protocol */ 67#define PPP_IPCP 0x8021 /* Internet Protocol Control Protocol */ 68 69#define LCP_CONF_REQ 1 /* PPP LCP configure request */ 70#define LCP_CONF_ACK 2 /* PPP LCP configure acknowledge */ 71#define LCP_CONF_NAK 3 /* PPP LCP configure negative ack */ 72#define LCP_CONF_REJ 4 /* PPP LCP configure reject */ 73#define LCP_TERM_REQ 5 /* PPP LCP terminate request */ 74#define LCP_TERM_ACK 6 /* PPP LCP terminate acknowledge */ 75#define LCP_CODE_REJ 7 /* PPP LCP code reject */ 76#define LCP_PROTO_REJ 8 /* PPP LCP protocol reject */ 77#define LCP_ECHO_REQ 9 /* PPP LCP echo request */ 78#define LCP_ECHO_REPLY 10 /* PPP LCP echo reply */ 79#define LCP_DISC_REQ 11 /* PPP LCP discard request */ 80 81#define LCP_OPT_MRU 1 /* maximum receive unit */ 82#define LCP_OPT_ASYNC_MAP 2 /* async control character map */ 83#define LCP_OPT_AUTH_PROTO 3 /* authentication protocol */ 84#define LCP_OPT_QUAL_PROTO 4 /* quality protocol */ 85#define LCP_OPT_MAGIC 5 /* magic number */ 86#define LCP_OPT_RESERVED 6 /* reserved */ 87#define LCP_OPT_PROTO_COMP 7 /* protocol field compression */ 88#define LCP_OPT_ADDR_COMP 8 /* address/control field compression */ 89 90#define IPCP_CONF_REQ LCP_CONF_REQ /* PPP IPCP configure request */ 91#define IPCP_CONF_ACK LCP_CONF_ACK /* PPP IPCP configure acknowledge */ 92#define IPCP_CONF_NAK LCP_CONF_NAK /* PPP IPCP configure negative ack */ 93#define IPCP_CONF_REJ LCP_CONF_REJ /* PPP IPCP configure reject */ 94#define IPCP_TERM_REQ LCP_TERM_REQ /* PPP IPCP terminate request */ 95#define IPCP_TERM_ACK LCP_TERM_ACK /* PPP IPCP terminate acknowledge */ 96#define IPCP_CODE_REJ LCP_CODE_REJ /* PPP IPCP code reject */ 97 98#define CISCO_MULTICAST 0x8f /* Cisco multicast address */ 99#define CISCO_UNICAST 0x0f /* Cisco unicast address */ 100#define CISCO_KEEPALIVE 0x8035 /* Cisco keepalive protocol */ 101#define CISCO_ADDR_REQ 0 /* Cisco address request */ 102#define CISCO_ADDR_REPLY 1 /* Cisco address reply */ 103#define CISCO_KEEPALIVE_REQ 2 /* Cisco keepalive request */ 104 105struct ppp_header { 106 u_char address; 107 u_char control; 108 u_short protocol; 109}; 110#define PPP_HEADER_LEN sizeof (struct ppp_header) 111 112struct lcp_header { 113 u_char type; 114 u_char ident; 115 u_short len; 116}; 117#define LCP_HEADER_LEN sizeof (struct lcp_header) 118 119struct cisco_packet { 120 u_long type; 121 u_long par1; 122 u_long par2; 123 u_short rel; 124 u_short time0; 125 u_short time1; 126}; 127#define CISCO_PACKET_LEN 18 128 129struct sppp *spppq; 130 131/* 132 * The following disgusting hack gets around the problem that IP TOS 133 * can't be set yet. We want to put "interactive" traffic on a high 134 * priority queue. To decide if traffic is interactive, we check that 135 * a) it is TCP and b) one of its ports is telnet, rlogin or ftp control. 136 */ 137static u_short interactive_ports[8] = { 138 0, 513, 0, 0, 139 0, 21, 0, 23, 140}; 141#define INTERACTIVE(p) (interactive_ports[(p) & 7] == (p)) 142 143/* 144 * Timeout routine activation macros. 145 */ 146#define TIMO(p,s) if (! ((p)->pp_flags & PP_TIMO)) { \ 147 timeout (sppp_cp_timeout, (void*) (p), (s)*hz); \ 148 (p)->pp_flags |= PP_TIMO; } 149#define UNTIMO(p) if ((p)->pp_flags & PP_TIMO) { \ 150 untimeout (sppp_cp_timeout, (void*) (p)); \ 151 (p)->pp_flags &= ~PP_TIMO; } 152 153void sppp_keepalive (void *dummy); 154void sppp_cp_send (struct sppp *sp, u_short proto, u_char type, 155 u_char ident, u_short len, void *data); 156void sppp_cisco_send (struct sppp *sp, int type, long par1, long par2); 157void sppp_lcp_input (struct sppp *sp, struct mbuf *m); 158void sppp_cisco_input (struct sppp *sp, struct mbuf *m); 159void sppp_ipcp_input (struct sppp *sp, struct mbuf *m); 160void sppp_lcp_open (struct sppp *sp); 161void sppp_ipcp_open (struct sppp *sp); 162int sppp_lcp_conf_parse_options (struct sppp *sp, struct lcp_header *h, 163 int len, u_long *magic); 164void sppp_cp_timeout (void *arg); 165char *sppp_lcp_type_name (u_char type); 166char *sppp_ipcp_type_name (u_char type); 167void sppp_print_bytes (u_char *p, u_short len); 168 169/* 170 * Flush interface queue. 171 */ 172static void qflush (struct ifqueue *ifq) 173{ 174 struct mbuf *m, *n; 175 176 n = ifq->ifq_head; 177 while ((m = n)) { 178 n = m->m_act; 179 m_freem (m); 180 } 181 ifq->ifq_head = 0; 182 ifq->ifq_tail = 0; 183 ifq->ifq_len = 0; 184} 185 186/* 187 * Process the received packet. 188 */ 189void sppp_input (struct ifnet *ifp, struct mbuf *m) 190{ 191 struct ppp_header *h; 192 struct sppp *sp = (struct sppp*) ifp; 193 struct ifqueue *inq = 0; 194 int s; 195 196 ifp->if_lastchange = time; 197 if (ifp->if_flags & IFF_UP) 198 /* Count received bytes, add FCS and one flag */ 199 ifp->if_ibytes += m->m_pkthdr.len + 3; 200 201 if (m->m_pkthdr.len <= PPP_HEADER_LEN) { 202 /* Too small packet, drop it. */ 203 if (ifp->if_flags & IFF_DEBUG) 204 printf ("%s%d: input packet is too small, %d bytes\n", 205 ifp->if_name, ifp->if_unit, m->m_pkthdr.len); 206drop: ++ifp->if_iqdrops; 207 m_freem (m); 208 return; 209 } 210 211 /* Get PPP header. */ 212 h = mtod (m, struct ppp_header*); 213 m_adj (m, PPP_HEADER_LEN); 214 215 switch (h->address) { 216 default: /* Invalid PPP packet. */ 217invalid: if (ifp->if_flags & IFF_DEBUG) 218 printf ("%s%d: invalid input packet <0x%x 0x%x 0x%x>\n", 219 ifp->if_name, ifp->if_unit, 220 h->address, h->control, ntohs (h->protocol)); 221 goto drop; 222 case PPP_ALLSTATIONS: 223 if (h->control != PPP_UI) 224 goto invalid; 225 if (sp->pp_flags & PP_CISCO) { 226 if (ifp->if_flags & IFF_DEBUG) 227 printf ("%s%d: PPP packet in Cisco mode <0x%x 0x%x 0x%x>\n", 228 ifp->if_name, ifp->if_unit, 229 h->address, h->control, ntohs (h->protocol)); 230 goto drop; 231 } 232 switch (ntohs (h->protocol)) { 233 default: 234 if (sp->lcp.state == LCP_STATE_OPENED) 235 sppp_cp_send (sp, PPP_LCP, LCP_PROTO_REJ, 236 ++sp->pp_seq, m->m_pkthdr.len + 2, 237 &h->protocol); 238 if (ifp->if_flags & IFF_DEBUG) 239 printf ("%s%d: invalid input protocol <0x%x 0x%x 0x%x>\n", 240 ifp->if_name, ifp->if_unit, 241 h->address, h->control, ntohs (h->protocol)); 242 ++ifp->if_noproto; 243 goto drop; 244 case PPP_LCP: 245 sppp_lcp_input ((struct sppp*) ifp, m); 246 m_freem (m); 247 return; 248#ifdef INET 249 case PPP_IPCP: 250 if (sp->lcp.state == LCP_STATE_OPENED) 251 sppp_ipcp_input ((struct sppp*) ifp, m); 252 m_freem (m); 253 return; 254 case PPP_IP: 255 if (sp->ipcp.state == IPCP_STATE_OPENED) { 256 schednetisr (NETISR_IP); 257 inq = &ipintrq; 258 } 259 break; 260#endif 261#ifdef NS 262 case PPP_XNS: 263 /* XNS IDPCP not implemented yet */ 264 if (sp->lcp.state == LCP_STATE_OPENED) { 265 schednetisr (NETISR_NS); 266 inq = &nsintrq; 267 } 268 break; 269#endif 270#ifdef ISO 271 case PPP_ISO: 272 /* OSI NLCP not implemented yet */ 273 if (sp->lcp.state == LCP_STATE_OPENED) { 274 schednetisr (NETISR_ISO); 275 inq = &clnlintrq; 276 } 277 break; 278#endif 279 } 280 break; 281 case CISCO_MULTICAST: 282 case CISCO_UNICAST: 283 /* Don't check the control field here (RFC 1547). */ 284 if (! (sp->pp_flags & PP_CISCO)) { 285 if (ifp->if_flags & IFF_DEBUG) 286 printf ("%s%d: Cisco packet in PPP mode <0x%x 0x%x 0x%x>\n", 287 ifp->if_name, ifp->if_unit, 288 h->address, h->control, ntohs (h->protocol)); 289 goto drop; 290 } 291 switch (ntohs (h->protocol)) { 292 default: 293 ++ifp->if_noproto; 294 goto invalid; 295 case CISCO_KEEPALIVE: 296 sppp_cisco_input ((struct sppp*) ifp, m); 297 m_freem (m); 298 return; 299#ifdef INET 300 case ETHERTYPE_IP: 301 schednetisr (NETISR_IP); 302 inq = &ipintrq; 303 break; 304#endif 305#ifdef NS 306 case ETHERTYPE_NS: 307 schednetisr (NETISR_NS); 308 inq = &nsintrq; 309 break; 310#endif 311 } 312 break; 313 } 314 315 if (! (ifp->if_flags & IFF_UP) || ! inq) 316 goto drop; 317 318 /* Check queue. */ 319 s = splimp (); 320 if (IF_QFULL (inq)) { 321 /* Queue overflow. */ 322 IF_DROP (inq); 323 splx (s); 324 if (ifp->if_flags & IFF_DEBUG) 325 printf ("%s%d: protocol queue overflow\n", 326 ifp->if_name, ifp->if_unit); 327 goto drop; 328 } 329 IF_ENQUEUE (inq, m); 330 splx (s); 331} 332 333/* 334 * Enqueue transmit packet. 335 */ 336int sppp_output (struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rt) 337{ 338 struct sppp *sp = (struct sppp*) ifp; 339 struct ppp_header *h; 340 struct ifqueue *ifq; 341 int s = splimp (); 342 343 if (! (ifp->if_flags & IFF_UP) || ! (ifp->if_flags & IFF_RUNNING)) { 344 m_freem (m); 345 splx (s); 346 return (ENETDOWN); 347 } 348 349 ifq = &ifp->if_snd; 350#ifdef INET 351 /* 352 * Put low delay, telnet, rlogin and ftp control packets 353 * in front of the queue. 354 */ 355 { 356 struct ip *ip = mtod (m, struct ip*); 357 struct tcphdr *tcp = (struct tcphdr*) ((long*)ip + ip->ip_hl); 358 359 if (! IF_QFULL (&sp->pp_fastq) && ((ip->ip_tos & IPTOS_LOWDELAY) || 360 ip->ip_p == IPPROTO_TCP && 361 m->m_len >= sizeof (struct ip) + sizeof (struct tcphdr) && 362 (INTERACTIVE (ntohs (tcp->th_sport)) || 363 INTERACTIVE (ntohs (tcp->th_dport))))) 364 ifq = &sp->pp_fastq; 365 } 366#endif 367 368 /* 369 * Prepend general data packet PPP header. For now, IP only. 370 */ 371 M_PREPEND (m, PPP_HEADER_LEN, M_DONTWAIT); 372 if (! m) { 373 if (ifp->if_flags & IFF_DEBUG) 374 printf ("%s%d: no memory for transmit header\n", 375 ifp->if_name, ifp->if_unit); 376 splx (s); 377 return (ENOBUFS); 378 } 379 h = mtod (m, struct ppp_header*); 380 if (sp->pp_flags & PP_CISCO) { 381 h->address = CISCO_MULTICAST; /* broadcast address */ 382 h->control = 0; 383 } else { 384 h->address = PPP_ALLSTATIONS; /* broadcast address */ 385 h->control = PPP_UI; /* Unnumbered Info */ 386 } 387 388 switch (dst->sa_family) { 389#ifdef INET 390 case AF_INET: /* Internet Protocol */ 391 if (sp->pp_flags & PP_CISCO) 392 h->protocol = htons (ETHERTYPE_IP); 393 else if (sp->ipcp.state == IPCP_STATE_OPENED) 394 h->protocol = htons (PPP_IP); 395 else { 396 m_freem (m); 397 splx (s); 398 return (ENETDOWN); 399 } 400 break; 401#endif 402#ifdef NS 403 case AF_NS: /* Xerox NS Protocol */ 404 h->protocol = htons ((sp->pp_flags & PP_CISCO) ? 405 ETHERTYPE_NS : PPP_XNS); 406 break; 407#endif 408#ifdef ISO 409 case AF_ISO: /* ISO OSI Protocol */ 410 if (sp->pp_flags & PP_CISCO) 411 goto nosupport; 412 h->protocol = htons (PPP_ISO); 413 break; 414#endif 415nosupport: 416 default: 417 m_freem (m); 418 splx (s); 419 return (EAFNOSUPPORT); 420 } 421 422 /* 423 * Queue message on interface, and start output if interface 424 * not yet active. 425 */ 426 if (IF_QFULL (ifq)) { 427 IF_DROP (&ifp->if_snd); 428 m_freem (m); 429 splx (s); 430 return (ENOBUFS); 431 } 432 IF_ENQUEUE (ifq, m); 433 if (! (ifp->if_flags & IFF_OACTIVE)) 434 (*ifp->if_start) (ifp); 435 436 /* 437 * Count output packets and bytes. 438 * The packet length includes header, FCS and 1 flag, 439 * according to RFC 1333. 440 */ 441 ifp->if_obytes += m->m_pkthdr.len + 3; 442 ifp->if_lastchange = time; 443 splx (s); 444 return (0); 445} 446 447void sppp_attach (struct ifnet *ifp) 448{ 449 struct sppp *sp = (struct sppp*) ifp; 450 451 /* Initialize keepalive handler. */ 452 if (! spppq) 453 timeout (sppp_keepalive, 0, hz * 10); 454 455 /* Insert new entry into the keepalive list. */ 456 sp->pp_next = spppq; 457 spppq = sp; 458 459 sp->pp_if.if_type = IFT_PPP; 460 sp->pp_if.if_output = sppp_output; 461 sp->pp_fastq.ifq_maxlen = 32; 462 sp->pp_loopcnt = 0; 463 sp->pp_alivecnt = 0; 464 sp->pp_seq = 0; 465 sp->pp_rseq = 0; 466 sp->lcp.magic = 0; 467 sp->lcp.state = LCP_STATE_CLOSED; 468 sp->ipcp.state = IPCP_STATE_CLOSED; 469} 470 471void sppp_detach (struct ifnet *ifp) 472{ 473 struct sppp **q, *p, *sp = (struct sppp*) ifp; 474 475 /* Remove the entry from the keepalive list. */ 476 for (q = &spppq; (p = *q); q = &p->pp_next) 477 if (p == sp) { 478 *q = p->pp_next; 479 break; 480 } 481 482 /* Stop keepalive handler. */ 483 if (! spppq) 484 untimeout (sppp_keepalive, 0); 485 UNTIMO (sp); 486} 487 488/* 489 * Flush the interface output queue. 490 */ 491void sppp_flush (struct ifnet *ifp) 492{ 493 struct sppp *sp = (struct sppp*) ifp; 494 495 qflush (&sp->pp_if.if_snd); 496 qflush (&sp->pp_fastq); 497} 498 499/* 500 * Check if the output queue is empty. 501 */ 502int sppp_isempty (struct ifnet *ifp) 503{ 504 struct sppp *sp = (struct sppp*) ifp; 505 int empty, s = splimp (); 506 507 empty = !sp->pp_fastq.ifq_head && !sp->pp_if.if_snd.ifq_head; 508 splx (s); 509 return (empty); 510} 511 512/* 513 * Get next packet to send. 514 */ 515struct mbuf *sppp_dequeue (struct ifnet *ifp) 516{ 517 struct sppp *sp = (struct sppp*) ifp; 518 struct mbuf *m; 519 int s = splimp (); 520 521 IF_DEQUEUE (&sp->pp_fastq, m); 522 if (! m) 523 IF_DEQUEUE (&sp->pp_if.if_snd, m); 524 splx (s); 525 return (m); 526} 527 528/* 529 * Send keepalive packets, every 10 seconds. 530 */ 531void sppp_keepalive (void *dummy) 532{ 533 struct sppp *sp; 534 int s = splimp (); 535 536 for (sp=spppq; sp; sp=sp->pp_next) { 537 struct ifnet *ifp = &sp->pp_if; 538 539 /* Keepalive mode disabled or channel down? */ 540 if (! (sp->pp_flags & PP_KEEPALIVE) || 541 ! (ifp->if_flags & IFF_RUNNING)) 542 continue; 543 544 /* No keepalive in PPP mode if LCP not opened yet. */ 545 if (! (sp->pp_flags & PP_CISCO) && 546 sp->lcp.state != LCP_STATE_OPENED) 547 continue; 548 549 if (sp->pp_alivecnt == MAXALIVECNT) { 550 /* No keepalive packets got. Stop the interface. */ 551 printf ("%s%d: down\n", ifp->if_name, ifp->if_unit); 552 if_down (ifp); 553 qflush (&sp->pp_fastq); 554 if (! (sp->pp_flags & PP_CISCO)) { 555 /* Shut down the PPP link. */ 556 sp->lcp.state = LCP_STATE_CLOSED; 557 sp->ipcp.state = IPCP_STATE_CLOSED; 558 UNTIMO (sp); 559 /* Initiate negotiation. */ 560 sppp_lcp_open (sp); 561 } 562 } 563 if (sp->pp_alivecnt <= MAXALIVECNT) 564 ++sp->pp_alivecnt; 565 if (sp->pp_flags & PP_CISCO) 566 sppp_cisco_send (sp, CISCO_KEEPALIVE_REQ, ++sp->pp_seq, 567 sp->pp_rseq); 568 else if (sp->lcp.state == LCP_STATE_OPENED) { 569 long nmagic = htonl (sp->lcp.magic); 570 sp->lcp.echoid = ++sp->pp_seq; 571 sppp_cp_send (sp, PPP_LCP, LCP_ECHO_REQ, 572 sp->lcp.echoid, 4, &nmagic); 573 } 574 } 575 splx (s); 576 timeout (sppp_keepalive, 0, hz * 10); 577} 578 579/* 580 * Handle incoming PPP Link Control Protocol packets. 581 */ 582void sppp_lcp_input (struct sppp *sp, struct mbuf *m) 583{ 584 struct lcp_header *h; 585 struct ifnet *ifp = &sp->pp_if; 586 int len = m->m_pkthdr.len; 587 u_char *p, opt[6]; 588 u_long rmagic; 589 590 if (len < 4) { 591 if (ifp->if_flags & IFF_DEBUG) 592 printf ("%s%d: invalid lcp packet length: %d bytes\n", 593 ifp->if_name, ifp->if_unit, len); 594 return; 595 } 596 h = mtod (m, struct lcp_header*); 597 if (ifp->if_flags & IFF_DEBUG) { 598 char state = '?'; 599 switch (sp->lcp.state) { 600 case LCP_STATE_CLOSED: state = 'C'; break; 601 case LCP_STATE_ACK_RCVD: state = 'R'; break; 602 case LCP_STATE_ACK_SENT: state = 'S'; break; 603 case LCP_STATE_OPENED: state = 'O'; break; 604 } 605 printf ("%s%d: lcp input(%c): %d bytes <%s id=%xh len=%xh", 606 ifp->if_name, ifp->if_unit, state, len, 607 sppp_lcp_type_name (h->type), h->ident, ntohs (h->len)); 608 if (len > 4) 609 sppp_print_bytes ((u_char*) (h+1), len-4); 610 printf (">\n"); 611 } 612 if (len > ntohs (h->len)) 613 len = ntohs (h->len); 614 switch (h->type) { 615 default: 616 /* Unknown packet type -- send Code-Reject packet. */ 617 sppp_cp_send (sp, PPP_LCP, LCP_CODE_REJ, ++sp->pp_seq, 618 m->m_pkthdr.len, h); 619 break; 620 case LCP_CONF_REQ: 621 if (len < 4) { 622 if (ifp->if_flags & IFF_DEBUG) 623 printf ("%s%d: invalid lcp configure request packet length: %d bytes\n", 624 ifp->if_name, ifp->if_unit, len); 625 break; 626 } 627 if (len>4 && !sppp_lcp_conf_parse_options (sp, h, len, &rmagic)) 628 goto badreq; 629 if (rmagic == sp->lcp.magic) { 630 /* Local and remote magics equal -- loopback? */ 631 if (sp->pp_loopcnt >= MAXALIVECNT*5) { 632 printf ("%s%d: loopback\n", 633 ifp->if_name, ifp->if_unit); 634 sp->pp_loopcnt = 0; 635 if (ifp->if_flags & IFF_UP) { 636 if_down (ifp); 637 qflush (&sp->pp_fastq); 638 } 639 } else if (ifp->if_flags & IFF_DEBUG) 640 printf ("%s%d: conf req: magic glitch\n", 641 ifp->if_name, ifp->if_unit); 642 ++sp->pp_loopcnt; 643 644 /* MUST send Conf-Nack packet. */ 645 rmagic = ~sp->lcp.magic; 646 opt[0] = LCP_OPT_MAGIC; 647 opt[1] = sizeof (opt); 648 opt[2] = rmagic >> 24; 649 opt[3] = rmagic >> 16; 650 opt[4] = rmagic >> 8; 651 opt[5] = rmagic; 652 sppp_cp_send (sp, PPP_LCP, LCP_CONF_NAK, 653 h->ident, sizeof (opt), &opt); 654badreq: 655 switch (sp->lcp.state) { 656 case LCP_STATE_OPENED: 657 /* Initiate renegotiation. */ 658 sppp_lcp_open (sp); 659 /* fall through... */ 660 case LCP_STATE_ACK_SENT: 661 /* Go to closed state. */ 662 sp->lcp.state = LCP_STATE_CLOSED; 663 sp->ipcp.state = IPCP_STATE_CLOSED; 664 } 665 break; 666 } 667 /* Send Configure-Ack packet. */ 668 sp->pp_loopcnt = 0; 669 sppp_cp_send (sp, PPP_LCP, LCP_CONF_ACK, 670 h->ident, len-4, h+1); 671 /* Change the state. */ 672 switch (sp->lcp.state) { 673 case LCP_STATE_CLOSED: 674 sp->lcp.state = LCP_STATE_ACK_SENT; 675 break; 676 case LCP_STATE_ACK_RCVD: 677 sp->lcp.state = LCP_STATE_OPENED; 678 sppp_ipcp_open (sp); 679 break; 680 case LCP_STATE_OPENED: 681 /* Remote magic changed -- close session. */ 682 sp->lcp.state = LCP_STATE_CLOSED; 683 sp->ipcp.state = IPCP_STATE_CLOSED; 684 /* Initiate renegotiation. */ 685 sppp_lcp_open (sp); 686 break; 687 } 688 break; 689 case LCP_CONF_ACK: 690 if (h->ident != sp->lcp.confid) 691 break; 692 UNTIMO (sp); 693 if (! (ifp->if_flags & IFF_UP) && 694 (ifp->if_flags & IFF_RUNNING)) { 695 /* Coming out of loopback mode. */ 696 ifp->if_flags |= IFF_UP; 697 printf ("%s%d: up\n", ifp->if_name, ifp->if_unit); 698 } 699 switch (sp->lcp.state) { 700 case LCP_STATE_CLOSED: 701 sp->lcp.state = LCP_STATE_ACK_RCVD; 702 TIMO (sp, 5); 703 break; 704 case LCP_STATE_ACK_SENT: 705 sp->lcp.state = LCP_STATE_OPENED; 706 sppp_ipcp_open (sp); 707 break; 708 } 709 break; 710 case LCP_CONF_NAK: 711 if (h->ident != sp->lcp.confid) 712 break; 713 p = (u_char*) (h+1); 714 if (len>=10 && p[0] == LCP_OPT_MAGIC && p[1] >= 4) { 715 rmagic = (u_long)p[2] << 24 | 716 (u_long)p[3] << 16 | p[4] << 8 | p[5]; 717 if (rmagic == ~sp->lcp.magic) { 718 if (ifp->if_flags & IFF_DEBUG) 719 printf ("%s%d: conf nak: magic glitch\n", 720 ifp->if_name, ifp->if_unit); 721 sp->lcp.magic += time.tv_sec + time.tv_usec; 722 } else 723 sp->lcp.magic = rmagic; 724 } 725 if (sp->lcp.state != LCP_STATE_ACK_SENT) { 726 /* Go to closed state. */ 727 sp->lcp.state = LCP_STATE_CLOSED; 728 sp->ipcp.state = IPCP_STATE_CLOSED; 729 } 730 /* The link will be renegotiated after timeout, 731 * to avoid endless req-nack loop. */ 732 UNTIMO (sp); 733 TIMO (sp, 2); 734 break; 735 case LCP_CONF_REJ: 736 if (h->ident != sp->lcp.confid) 737 break; 738 UNTIMO (sp); 739 /* Initiate renegotiation. */ 740 sppp_lcp_open (sp); 741 if (sp->lcp.state != LCP_STATE_ACK_SENT) { 742 /* Go to closed state. */ 743 sp->lcp.state = LCP_STATE_CLOSED; 744 sp->ipcp.state = IPCP_STATE_CLOSED; 745 } 746 break; 747 case LCP_TERM_REQ: 748 UNTIMO (sp); 749 /* Send Terminate-Ack packet. */ 750 sppp_cp_send (sp, PPP_LCP, LCP_TERM_ACK, h->ident, 0, 0); 751 /* Go to closed state. */ 752 sp->lcp.state = LCP_STATE_CLOSED; 753 sp->ipcp.state = IPCP_STATE_CLOSED; 754 /* Initiate renegotiation. */ 755 sppp_lcp_open (sp); 756 break; 757 case LCP_TERM_ACK: 758 case LCP_CODE_REJ: 759 case LCP_PROTO_REJ: 760 /* Ignore for now. */ 761 break; 762 case LCP_DISC_REQ: 763 /* Discard the packet. */ 764 break; 765 case LCP_ECHO_REQ: 766 if (len < 8) { 767 if (ifp->if_flags & IFF_DEBUG) 768 printf ("%s%d: invalid lcp echo request packet length: %d bytes\n", 769 ifp->if_name, ifp->if_unit, len); 770 break; 771 } 772 if (ntohl (*(long*)(h+1)) == sp->lcp.magic) { 773 /* Line loopback mode detected. */ 774 printf ("%s%d: loopback\n", ifp->if_name, ifp->if_unit); 775 if_down (ifp); 776 qflush (&sp->pp_fastq); 777 778 /* Shut down the PPP link. */ 779 sp->lcp.state = LCP_STATE_CLOSED; 780 sp->ipcp.state = IPCP_STATE_CLOSED; 781 UNTIMO (sp); 782 /* Initiate negotiation. */ 783 sppp_lcp_open (sp); 784 break; 785 } 786 *(long*)(h+1) = htonl (sp->lcp.magic); 787 sppp_cp_send (sp, PPP_LCP, LCP_ECHO_REPLY, h->ident, len-4, h+1); 788 break; 789 case LCP_ECHO_REPLY: 790 if (h->ident != sp->lcp.echoid) 791 break; 792 if (len < 8) { 793 if (ifp->if_flags & IFF_DEBUG) 794 printf ("%s%d: invalid lcp echo reply packet length: %d bytes\n", 795 ifp->if_name, ifp->if_unit, len); 796 break; 797 } 798 if (ntohl (*(long*)(h+1)) != sp->lcp.magic) 799 sp->pp_alivecnt = 0; 800 break; 801 } 802} 803 804/* 805 * Handle incoming Cisco keepalive protocol packets. 806 */ 807void sppp_cisco_input (struct sppp *sp, struct mbuf *m) 808{ 809 struct cisco_packet *h; 810 struct ifaddr *ifa; 811 struct ifnet *ifp = &sp->pp_if; 812 813 if (m->m_pkthdr.len != CISCO_PACKET_LEN) { 814 if (ifp->if_flags & IFF_DEBUG) 815 printf ("%s%d: invalid cisco packet length: %d bytes\n", 816 ifp->if_name, ifp->if_unit, m->m_pkthdr.len); 817 return; 818 } 819 h = mtod (m, struct cisco_packet*); 820 if (ifp->if_flags & IFF_DEBUG) 821 printf ("%s%d: cisco input: %d bytes <%lxh %lxh %lxh %xh %xh-%xh>\n", 822 ifp->if_name, ifp->if_unit, m->m_pkthdr.len, 823 ntohl (h->type), h->par1, h->par2, h->rel, 824 h->time0, h->time1); 825 switch (ntohl (h->type)) { 826 default: 827 if (ifp->if_flags & IFF_DEBUG) 828 printf ("%s%d: unknown cisco packet type: 0x%lx\n", 829 ifp->if_name, ifp->if_unit, ntohl (h->type)); 830 break; 831 case CISCO_ADDR_REPLY: 832 /* Reply on address request, ignore */ 833 break; 834 case CISCO_KEEPALIVE_REQ: 835 sp->pp_alivecnt = 0; 836 sp->pp_rseq = ntohl (h->par1); 837 if (sp->pp_seq == sp->pp_rseq) { 838 /* Local and remote sequence numbers are equal. 839 * Probably, the line is in loopback mode. */ 840 if (sp->pp_loopcnt >= MAXALIVECNT) { 841 printf ("%s%d: loopback\n", 842 ifp->if_name, ifp->if_unit); 843 sp->pp_loopcnt = 0; 844 if (ifp->if_flags & IFF_UP) { 845 if_down (ifp); 846 qflush (&sp->pp_fastq); 847 } 848 } 849 ++sp->pp_loopcnt; 850 851 /* Generate new local sequence number */ 852 sp->pp_seq ^= time.tv_sec ^ time.tv_usec; 853 break; 854 } 855 sp->pp_loopcnt = 0; 856 if (! (ifp->if_flags & IFF_UP) && 857 (ifp->if_flags & IFF_RUNNING)) { 858 ifp->if_flags |= IFF_UP; 859 printf ("%s%d: up\n", ifp->if_name, ifp->if_unit); 860 } 861 break; 862 case CISCO_ADDR_REQ: 863 for (ifa=ifp->if_addrlist; ifa; ifa=ifa->ifa_next) 864 if (ifa->ifa_addr->sa_family == AF_INET) 865 break; 866 if (! ifa) { 867 if (ifp->if_flags & IFF_DEBUG) 868 printf ("%s%d: unknown address for cisco request\n", 869 ifp->if_name, ifp->if_unit); 870 return; 871 } 872 sppp_cisco_send (sp, CISCO_ADDR_REPLY, 873 ntohl (((struct sockaddr_in*)ifa->ifa_addr)->sin_addr.s_addr), 874 ntohl (((struct sockaddr_in*)ifa->ifa_netmask)->sin_addr.s_addr)); 875 break; 876 } 877} 878 879/* 880 * Send PPP LCP packet. 881 */ 882void sppp_cp_send (struct sppp *sp, u_short proto, u_char type, 883 u_char ident, u_short len, void *data) 884{ 885 struct ppp_header *h; 886 struct lcp_header *lh; 887 struct mbuf *m; 888 struct ifnet *ifp = &sp->pp_if; 889 890 if (len > MHLEN - PPP_HEADER_LEN - LCP_HEADER_LEN) 891 len = MHLEN - PPP_HEADER_LEN - LCP_HEADER_LEN; 892 MGETHDR (m, M_DONTWAIT, MT_DATA); 893 if (! m) 894 return; 895 m->m_pkthdr.len = m->m_len = PPP_HEADER_LEN + LCP_HEADER_LEN + len; 896 m->m_pkthdr.rcvif = 0; 897 898 h = mtod (m, struct ppp_header*); 899 h->address = PPP_ALLSTATIONS; /* broadcast address */ 900 h->control = PPP_UI; /* Unnumbered Info */ 901 h->protocol = htons (proto); /* Link Control Protocol */ 902 903 lh = (struct lcp_header*) (h + 1); 904 lh->type = type; 905 lh->ident = ident; 906 lh->len = htons (LCP_HEADER_LEN + len); 907 if (len) 908 bcopy (data, lh+1, len); 909 910 if (ifp->if_flags & IFF_DEBUG) { 911 printf ("%s%d: %s output <%s id=%xh len=%xh", 912 ifp->if_name, ifp->if_unit, 913 proto==PPP_LCP ? "lcp" : "ipcp", 914 proto==PPP_LCP ? sppp_lcp_type_name (lh->type) : 915 sppp_ipcp_type_name (lh->type), lh->ident, 916 ntohs (lh->len)); 917 if (len) 918 sppp_print_bytes ((u_char*) (lh+1), len); 919 printf (">\n"); 920 } 921 if (IF_QFULL (&sp->pp_fastq)) { 922 IF_DROP (&ifp->if_snd); 923 m_freem (m); 924 } else 925 IF_ENQUEUE (&sp->pp_fastq, m); 926 if (! (ifp->if_flags & IFF_OACTIVE)) 927 (*ifp->if_start) (ifp); 928 ifp->if_obytes += m->m_pkthdr.len + 3; 929} 930 931/* 932 * Send Cisco keepalive packet. 933 */ 934void sppp_cisco_send (struct sppp *sp, int type, long par1, long par2) 935{ 936 struct ppp_header *h; 937 struct cisco_packet *ch; 938 struct mbuf *m; 939 struct ifnet *ifp = &sp->pp_if; 940 u_long t = (time.tv_sec - boottime.tv_sec) * 1000; 941 942 MGETHDR (m, M_DONTWAIT, MT_DATA); 943 if (! m) 944 return; 945 m->m_pkthdr.len = m->m_len = PPP_HEADER_LEN + CISCO_PACKET_LEN; 946 m->m_pkthdr.rcvif = 0; 947 948 h = mtod (m, struct ppp_header*); 949 h->address = CISCO_MULTICAST; 950 h->control = 0; 951 h->protocol = htons (CISCO_KEEPALIVE); 952 953 ch = (struct cisco_packet*) (h + 1); 954 ch->type = htonl (type); 955 ch->par1 = htonl (par1); 956 ch->par2 = htonl (par2); 957 ch->rel = -1; 958 ch->time0 = htons ((u_short) (t >> 16)); 959 ch->time1 = htons ((u_short) t); 960 961 if (ifp->if_flags & IFF_DEBUG) 962 printf ("%s%d: cisco output: <%lxh %lxh %lxh %xh %xh-%xh>\n", 963 ifp->if_name, ifp->if_unit, ntohl (ch->type), ch->par1, 964 ch->par2, ch->rel, ch->time0, ch->time1); 965 966 if (IF_QFULL (&sp->pp_fastq)) { 967 IF_DROP (&ifp->if_snd); 968 m_freem (m); 969 } else 970 IF_ENQUEUE (&sp->pp_fastq, m); 971 if (! (ifp->if_flags & IFF_OACTIVE)) 972 (*ifp->if_start) (ifp); 973 ifp->if_obytes += m->m_pkthdr.len + 3; 974} 975 976/* 977 * Process an ioctl request. Called on low priority level. 978 */ 979int sppp_ioctl (struct ifnet *ifp, int cmd, void *data) 980{ 981 struct ifreq *ifr = (struct ifreq*) data; 982 struct sppp *sp = (struct sppp*) ifp; 983 int s, going_up, going_down; 984 985 switch (cmd) { 986 default: 987 return (EINVAL); 988 989 case SIOCAIFADDR: 990 case SIOCSIFDSTADDR: 991 break; 992 993 case SIOCSIFADDR: 994 ifp->if_flags |= IFF_UP; 995 /* fall through... */ 996 997 case SIOCSIFFLAGS: 998 if (sp->pp_flags & PP_CISCO) 999 break; 1000 s = splimp (); 1001 going_up = (ifp->if_flags & IFF_UP) && 1002 ! (ifp->if_flags & IFF_RUNNING); 1003 going_down = ! (ifp->if_flags & IFF_UP) && 1004 (ifp->if_flags & IFF_RUNNING); 1005 if (going_up || going_down) { 1006 /* Shut down the PPP link. */ 1007 ifp->if_flags &= ~IFF_RUNNING; 1008 sp->lcp.state = LCP_STATE_CLOSED; 1009 sp->ipcp.state = IPCP_STATE_CLOSED; 1010 UNTIMO (sp); 1011 } 1012 if (going_up) { 1013 /* Interface is starting -- initiate negotiation. */ 1014 ifp->if_flags |= IFF_RUNNING; 1015 sppp_lcp_open (sp); 1016 } 1017 splx (s); 1018 break; 1019 1020#ifdef SIOCSIFMTU 1021#ifndef ifr_mtu 1022#define ifr_mtu ifr_metric 1023#endif 1024 case SIOCSIFMTU: 1025 if (ifr->ifr_mtu < 128 || ifr->ifr_mtu > PP_MTU) 1026 return (EINVAL); 1027 ifp->if_mtu = ifr->ifr_mtu; 1028 break; 1029#endif 1030#ifdef SLIOCSETMTU 1031 case SLIOCSETMTU: 1032 if (*(short*)data < 128 || *(short*)data > PP_MTU) 1033 return (EINVAL); 1034 ifp->if_mtu = *(short*)data; 1035 break; 1036#endif 1037#ifdef SIOCGIFMTU 1038 case SIOCGIFMTU: 1039 ifr->ifr_mtu = ifp->if_mtu; 1040 break; 1041#endif 1042#ifdef SLIOCGETMTU 1043 case SLIOCGETMTU: 1044 *(short*)data = ifp->if_mtu; 1045 break; 1046#endif 1047#ifdef MULTICAST 1048 case SIOCADDMULTI: 1049 case SIOCDELMULTI: 1050 break; 1051#endif 1052 } 1053 return (0); 1054} 1055 1056/* 1057 * Analyze the LCP Configure-Request options list 1058 * for the presence of unknown options. 1059 * If the request contains unknown options, build and 1060 * send Configure-reject packet, containing only unknown options. 1061 */ 1062int sppp_lcp_conf_parse_options (struct sppp *sp, struct lcp_header *h, 1063 int len, u_long *magic) 1064{ 1065 u_char *buf, *r, *p; 1066 int rlen; 1067 1068 len -= 4; 1069 buf = r = malloc (len, M_TEMP, M_NOWAIT); 1070 if (! buf) 1071 return (0); 1072 1073 p = (void*) (h+1); 1074 for (rlen=0; len>1 && p[1]; len-=p[1], p+=p[1]) { 1075 switch (*p) { 1076 case LCP_OPT_MAGIC: 1077 /* Magic number -- extract. */ 1078 if (len >= 6 && p[1] == 6) { 1079 *magic = (u_long)p[2] << 24 | 1080 (u_long)p[3] << 16 | p[4] << 8 | p[5]; 1081 continue; 1082 } 1083 break; 1084 case LCP_OPT_ASYNC_MAP: 1085 /* Async control character map -- check to be zero. */ 1086 if (len >= 6 && p[1] == 6 && ! p[2] && ! p[3] && 1087 ! p[4] && ! p[5]) 1088 continue; 1089 break; 1090 case LCP_OPT_MRU: 1091 /* Maximum receive unit -- always OK. */ 1092 continue; 1093 default: 1094 /* Others not supported. */ 1095 break; 1096 } 1097 /* Add the option to rejected list. */ 1098 bcopy (p, r, p[1]); 1099 r += p[1]; 1100 rlen += p[1]; 1101 } 1102 if (rlen) 1103 sppp_cp_send (sp, PPP_LCP, LCP_CONF_REJ, h->ident, rlen, buf); 1104 free (buf, M_TEMP); 1105 return (rlen == 0); 1106} 1107 1108void sppp_ipcp_input (struct sppp *sp, struct mbuf *m) 1109{ 1110 struct lcp_header *h; 1111 struct ifnet *ifp = &sp->pp_if; 1112 int len = m->m_pkthdr.len; 1113 1114 if (len < 4) { 1115 /* if (ifp->if_flags & IFF_DEBUG) */ 1116 printf ("%s%d: invalid ipcp packet length: %d bytes\n", 1117 ifp->if_name, ifp->if_unit, len); 1118 return; 1119 } 1120 h = mtod (m, struct lcp_header*); 1121 if (ifp->if_flags & IFF_DEBUG) { 1122 printf ("%s%d: ipcp input: %d bytes <%s id=%xh len=%xh", 1123 ifp->if_name, ifp->if_unit, len, 1124 sppp_ipcp_type_name (h->type), h->ident, ntohs (h->len)); 1125 if (len > 4) 1126 sppp_print_bytes ((u_char*) (h+1), len-4); 1127 printf (">\n"); 1128 } 1129 if (len > ntohs (h->len)) 1130 len = ntohs (h->len); 1131 switch (h->type) { 1132 default: 1133 /* Unknown packet type -- send Code-Reject packet. */ 1134 sppp_cp_send (sp, PPP_IPCP, IPCP_CODE_REJ, ++sp->pp_seq, len, h); 1135 break; 1136 case IPCP_CONF_REQ: 1137 if (len < 4) { 1138 if (ifp->if_flags & IFF_DEBUG) 1139 printf ("%s%d: invalid ipcp configure request packet length: %d bytes\n", 1140 ifp->if_name, ifp->if_unit, len); 1141 return; 1142 } 1143 if (len > 4) { 1144 sppp_cp_send (sp, PPP_IPCP, LCP_CONF_REJ, h->ident, 1145 len-4, h+1); 1146 1147 switch (sp->ipcp.state) { 1148 case IPCP_STATE_OPENED: 1149 /* Initiate renegotiation. */ 1150 sppp_ipcp_open (sp); 1151 /* fall through... */ 1152 case IPCP_STATE_ACK_SENT: 1153 /* Go to closed state. */ 1154 sp->ipcp.state = IPCP_STATE_CLOSED; 1155 } 1156 } else { 1157 /* Send Configure-Ack packet. */ 1158 sppp_cp_send (sp, PPP_IPCP, IPCP_CONF_ACK, h->ident, 1159 0, 0); 1160 /* Change the state. */ 1161 if (sp->ipcp.state == IPCP_STATE_ACK_RCVD) 1162 sp->ipcp.state = IPCP_STATE_OPENED; 1163 else 1164 sp->ipcp.state = IPCP_STATE_ACK_SENT; 1165 } 1166 break; 1167 case IPCP_CONF_ACK: 1168 if (h->ident != sp->ipcp.confid) 1169 break; 1170 UNTIMO (sp); 1171 switch (sp->ipcp.state) { 1172 case IPCP_STATE_CLOSED: 1173 sp->ipcp.state = IPCP_STATE_ACK_RCVD; 1174 TIMO (sp, 5); 1175 break; 1176 case IPCP_STATE_ACK_SENT: 1177 sp->ipcp.state = IPCP_STATE_OPENED; 1178 break; 1179 } 1180 break; 1181 case IPCP_CONF_NAK: 1182 case IPCP_CONF_REJ: 1183 if (h->ident != sp->ipcp.confid) 1184 break; 1185 UNTIMO (sp); 1186 /* Initiate renegotiation. */ 1187 sppp_ipcp_open (sp); 1188 if (sp->ipcp.state != IPCP_STATE_ACK_SENT) 1189 /* Go to closed state. */ 1190 sp->ipcp.state = IPCP_STATE_CLOSED; 1191 break; 1192 case IPCP_TERM_REQ: 1193 /* Send Terminate-Ack packet. */ 1194 sppp_cp_send (sp, PPP_IPCP, IPCP_TERM_ACK, h->ident, 0, 0); 1195 /* Go to closed state. */ 1196 sp->ipcp.state = IPCP_STATE_CLOSED; 1197 /* Initiate renegotiation. */ 1198 sppp_ipcp_open (sp); 1199 break; 1200 case IPCP_TERM_ACK: 1201 /* Ignore for now. */ 1202 case IPCP_CODE_REJ: 1203 /* Ignore for now. */ 1204 break; 1205 } 1206} 1207 1208void sppp_lcp_open (struct sppp *sp) 1209{ 1210 char opt[6]; 1211 1212 if (! sp->lcp.magic) 1213 sp->lcp.magic = time.tv_sec + time.tv_usec; 1214 opt[0] = LCP_OPT_MAGIC; 1215 opt[1] = sizeof (opt); 1216 opt[2] = sp->lcp.magic >> 24; 1217 opt[3] = sp->lcp.magic >> 16; 1218 opt[4] = sp->lcp.magic >> 8; 1219 opt[5] = sp->lcp.magic; 1220 sp->lcp.confid = ++sp->pp_seq; 1221 sppp_cp_send (sp, PPP_LCP, LCP_CONF_REQ, sp->lcp.confid, 1222 sizeof (opt), &opt); 1223 TIMO (sp, 2); 1224} 1225 1226void sppp_ipcp_open (struct sppp *sp) 1227{ 1228 sp->ipcp.confid = ++sp->pp_seq; 1229 sppp_cp_send (sp, PPP_IPCP, IPCP_CONF_REQ, sp->ipcp.confid, 0, 0); 1230 TIMO (sp, 2); 1231} 1232 1233/* 1234 * Process PPP control protocol timeouts. 1235 */ 1236void sppp_cp_timeout (void *arg) 1237{ 1238 struct sppp *sp = (struct sppp*) arg; 1239 int s = splimp (); 1240 1241 sp->pp_flags &= ~PP_TIMO; 1242 if (! (sp->pp_if.if_flags & IFF_RUNNING) || (sp->pp_flags & PP_CISCO)) { 1243 splx (s); 1244 return; 1245 } 1246 switch (sp->lcp.state) { 1247 case LCP_STATE_CLOSED: 1248 /* No ACK for Configure-Request, retry. */ 1249 sppp_lcp_open (sp); 1250 break; 1251 case LCP_STATE_ACK_RCVD: 1252 /* ACK got, but no Configure-Request for peer, retry. */ 1253 sppp_lcp_open (sp); 1254 sp->lcp.state = LCP_STATE_CLOSED; 1255 break; 1256 case LCP_STATE_ACK_SENT: 1257 /* ACK sent but no ACK for Configure-Request, retry. */ 1258 sppp_lcp_open (sp); 1259 break; 1260 case LCP_STATE_OPENED: 1261 /* LCP is already OK, try IPCP. */ 1262 switch (sp->ipcp.state) { 1263 case IPCP_STATE_CLOSED: 1264 /* No ACK for Configure-Request, retry. */ 1265 sppp_ipcp_open (sp); 1266 break; 1267 case IPCP_STATE_ACK_RCVD: 1268 /* ACK got, but no Configure-Request for peer, retry. */ 1269 sppp_ipcp_open (sp); 1270 sp->ipcp.state = IPCP_STATE_CLOSED; 1271 break; 1272 case IPCP_STATE_ACK_SENT: 1273 /* ACK sent but no ACK for Configure-Request, retry. */ 1274 sppp_ipcp_open (sp); 1275 break; 1276 case IPCP_STATE_OPENED: 1277 /* IPCP is OK. */ 1278 break; 1279 } 1280 break; 1281 } 1282 splx (s); 1283} 1284 1285char *sppp_lcp_type_name (u_char type) 1286{ 1287 static char buf [8]; 1288 switch (type) { 1289 case LCP_CONF_REQ: return ("conf-req"); 1290 case LCP_CONF_ACK: return ("conf-ack"); 1291 case LCP_CONF_NAK: return ("conf-nack"); 1292 case LCP_CONF_REJ: return ("conf-rej"); 1293 case LCP_TERM_REQ: return ("term-req"); 1294 case LCP_TERM_ACK: return ("term-ack"); 1295 case LCP_CODE_REJ: return ("code-rej"); 1296 case LCP_PROTO_REJ: return ("proto-rej"); 1297 case LCP_ECHO_REQ: return ("echo-req"); 1298 case LCP_ECHO_REPLY: return ("echo-reply"); 1299 case LCP_DISC_REQ: return ("discard-req"); 1300 } 1301 sprintf (buf, "%xh", type); 1302 return (buf); 1303} 1304 1305char *sppp_ipcp_type_name (u_char type) 1306{ 1307 static char buf [8]; 1308 switch (type) { 1309 case IPCP_CONF_REQ: return ("conf-req"); 1310 case IPCP_CONF_ACK: return ("conf-ack"); 1311 case IPCP_CONF_NAK: return ("conf-nack"); 1312 case IPCP_CONF_REJ: return ("conf-rej"); 1313 case IPCP_TERM_REQ: return ("term-req"); 1314 case IPCP_TERM_ACK: return ("term-ack"); 1315 case IPCP_CODE_REJ: return ("code-rej"); 1316 } 1317 sprintf (buf, "%xh", type); 1318 return (buf); 1319} 1320 1321void sppp_print_bytes (u_char *p, u_short len) 1322{ 1323 printf (" %x", *p++); 1324 while (--len > 0) 1325 printf ("-%x", *p++); 1326} 1327