2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 static const char rcsid[] =
24 "@(#) $Header: print-ppp.c,v 1.26 97/06/12 14:21:29 leres Exp $ (LBL)";
27 #include <sys/param.h>
29 #include <sys/socket.h>
31 #include <sys/ioctl.h>
39 #include <netinet/in.h>
40 #include <netinet/in_systm.h>
41 #include <netinet/ip.h>
48 #include <net/ethernet.h>
49 #include "ethertype.h"
51 #include <net/ppp_defs.h>
52 #include "interface.h"
53 #include "addrtoname.h"
61 static struct protonames protonames[] = {
63 * Protocol field values.
65 PPP_IP, "IP", /* Internet Protocol */
66 PPP_XNS, "XNS", /* Xerox NS */
67 PPP_IPX, "IPX", /* IPX Datagram (RFC1552) */
68 PPP_VJC_COMP, "VJC_UNCOMP", /* VJ compressed TCP */
69 PPP_VJC_UNCOMP, "VJC_UNCOMP", /* VJ uncompressed TCP */
70 PPP_COMP, "COMP", /* compressed packet */
71 PPP_IPCP, "IPCP", /* IP Control Protocol */
72 PPP_IPXCP, "IPXCP", /* IPX Control Protocol (RFC1552) */
73 PPP_CCP, "CCP", /* Compression Control Protocol */
74 PPP_LCP, "LCP", /* Link Control Protocol */
75 PPP_PAP, "PAP", /* Password Authentication Protocol */
76 PPP_LQR, "LQR", /* Link Quality Report protocol */
77 PPP_CHAP, "CHAP", /* Cryptographic Handshake Auth. Proto*/
82 #define LCP_CONF_REQ 1
83 #define LCP_CONF_ACK 2
84 #define LCP_CONF_NAK 3
85 #define LCP_CONF_REJ 4
86 #define LCP_TERM_REQ 5
87 #define LCP_TERM_ACK 6
88 #define LCP_CODE_REJ 7
89 #define LCP_PROT_REJ 8
90 #define LCP_ECHO_REQ 9
91 #define LCP_ECHO_RPL 10
92 #define LCP_DISC_REQ 11
94 #define LCP_MIN LCP_CONF_REQ
95 #define LCP_MAX LCP_DISC_REQ
97 static char *lcpcodes[] = {
99 * LCP code values (RFC1661, pp26)
114 #define LCPOPT_VEXT 0
116 #define LCPOPT_ACCM 2
121 #define LCPOPT_ACFC 8
124 #define LCPOPT_MAX 24
126 static char *lcpconfopts[] = {
129 "Async-Ctrl-Char-Map",
135 "Add-Ctrl-Field-Compr",
137 "Self-Describing-Pad",
139 "Multi-Link-Procedure",
143 "Nominal-Data-Encap",
149 "Multilink-Plus-Proc",
150 "Link-Discriminator",
161 #define CHAP_CODEMIN 1
162 #define CHAP_CODEMAX 4
164 static char *chapcode[] = {
177 #define PAP_CODEMIN 1
178 #define PAP_CODEMAX 3
180 static char *papcode[] = {
181 "Authenticate-Request",
192 static int handle_lcp(const u_char *p, int length);
193 static int print_lcp_config_options(u_char *p);
194 static int handle_chap(const u_char *p, int length);
195 static int handle_ipcp(const u_char *p, int length);
196 static int handle_pap(const u_char *p, int length);
198 /* Standard PPP printer */
200 ppp_hdlc_print(const u_char *p, int length)
202 int proto = PPP_PROTOCOL(p);
206 printf("ID-%03d ", *(p+5));
208 for (i = (sizeof(protonames) / sizeof(protonames[0])) - 1; i >= 0; --i)
210 if (proto == protonames[i].protocol)
212 printf("%s: ", protonames[i].name);
217 handle_lcp(p, length);
220 handle_chap(p, length);
223 handle_pap(p, length);
226 handle_ipcp(p, length);
234 printf("%04x: ", proto);
238 /* print LCP frame */
241 handle_lcp(const u_char *p, int length)
248 if((x >= LCP_MIN) && (x <= LCP_MAX))
250 printf("%s", lcpcodes[x-1]);
270 if((j = print_lcp_config_options(ptr)) == 0)
280 printf(", Magic-Number=%d", ((*(p+8) << 24) + (*(p+9) << 16) + (*(p+10) << 8) + (*(p+11))));
292 /* LCP config options */
295 print_lcp_config_options(u_char *p)
300 if((opt >= LCPOPT_MIN) && (opt <= LCPOPT_MAX))
301 printf(", %s", lcpconfopts[opt]);
307 printf("=%d", (*(p+2) << 8) + *(p+3));
312 if(*(p+2) == 0xc0 && *(p+3) == 0x23)
316 else if(*(p+2) == 0xc2 && *(p+3) == 0x23)
322 printf("unknown-algorithm-%d", *(p+4));
332 else if(*(p+2) == 0xc2 && *(p+3) == 0x27)
336 else if(*(p+2) == 0xc0 && *(p+3) == 0x27)
340 else if(*(p+2) == 0xc1 && *(p+3) == 0x23)
353 if(*(p+2) == 0xc0 && *(p+3) == 0x25)
362 printf("=%d", ((*(p+2) << 24) + (*(p+3) << 16) + (*(p+4) << 8) + (*(p+5))));
378 handle_chap(const u_char *p, int length)
385 if((x >= CHAP_CODEMIN) && (x <= CHAP_CODEMAX))
387 printf("%s", chapcode[x-1]);
402 x = *(p+8); /* value size */
405 printf("%02x", *ptr++);
406 x = length - *(p+8) - 1;
409 printf("%c", *ptr++);
417 handle_pap(const u_char *p, int length)
424 if((x >= PAP_CODEMIN) && (x <= PAP_CODEMAX))
426 printf("%s", papcode[x-1]);
439 printf(", Peer-Id=");
440 x = *(p+8); /* peerid size */
443 printf("%c", *ptr++);
447 printf("%c", *ptr++);
458 handle_ipcp(const u_char *p, int length)
469 printf("IP-Addresses");
470 printf(", Src=%d.%d.%d.%d", *(p+10), *(p+11), *(p+12), *(p+13));
471 printf(", Dst=%d.%d.%d.%d", *(p+14), *(p+15), *(p+16), *(p+17));
475 printf("IP-Compression-Protocol");
479 printf("IP-Address=%d.%d.%d.%d", *(p+10), *(p+11), *(p+12), *(p+13));
485 ppp_if_print(u_char *user, const struct pcap_pkthdr *h,
486 register const u_char *p)
488 register u_int length = h->len;
489 register u_int caplen = h->caplen;
493 if (caplen < PPP_HDRLEN) {
499 * Some printers want to get back at the link level addresses,
500 * and/or check that they're not walking off the end of the packet.
501 * Rather than pass them all the way down, we set these globals.
504 snapend = p + caplen;
507 ppp_hdlc_print(p, length);
509 length -= PPP_HDRLEN;
511 switch(PPP_PROTOCOL(p)) {
514 ip_print((const u_char *)(p + PPP_HDRLEN), length);
518 ipx_print((const u_char *)(p + PPP_HDRLEN), length);
523 ppp_hdlc_print(p, length);
525 default_print((const u_char *)(p + PPP_HDRLEN),
526 caplen - PPP_HDRLEN);
530 default_print((const u_char *)(p + PPP_HDRLEN),
531 caplen - PPP_HDRLEN);
536 /* proto type to string mapping */
537 static struct tok ptype2str[] = {
539 { PPP_VJNC, "VJNC" },
542 { PPP_IPCP, "IPCP" },
546 #define PPP_BSDI_HDRLEN 24
548 /* BSD/OS specific PPP printer */
550 ppp_bsdos_if_print(u_char *user, const struct pcap_pkthdr *h,
551 register const u_char *p)
553 register u_int length = h->len;
554 register u_int caplen = h->caplen;
555 register int hdrlength;
560 if (caplen < PPP_BSDI_HDRLEN) {
566 * Some printers want to get back at the link level addresses,
567 * and/or check that they're not walking off the end of the packet.
568 * Rather than pass them all the way down, we set these globals.
571 snapend = p + caplen;
574 if (p[0] == PPP_ADDRESS && p[1] == PPP_CONTROL) {
576 printf("%02x %02x ", p[0], p[1]);
582 printf("%d ", length);
583 /* Retrieve the protocol type */
585 /* Compressed protocol field */
588 printf("%02x ", ptype);
592 /* Un-compressed protocol field */
593 ptype = ntohs(*(u_short *)p);
595 printf("%04x ", ptype);
605 printf("%s ", tok2str(ptype2str, "proto-#%d", ptype));
608 default_print((const u_char *)p, caplen - hdrlength);