]>
The Tcpdump Group git mirrors - tcpdump/blob - print-pppoe.c
2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 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.
21 * Original code by Greg Stark <gsstark@mit.edu>
24 /* \summary: PPP-over-Ethernet (PPPoE) printer */
28 #include "netdissect-stdinc.h"
30 #include "netdissect-ctype.h"
32 #define ND_LONGJMP_FROM_TCHECK
33 #include "netdissect.h"
45 static const struct tok pppoecode2str
[] = {
46 { PPPOE_PADI
, "PADI" },
47 { PPPOE_PADO
, "PADO" },
48 { PPPOE_PADR
, "PADR" },
49 { PPPOE_PADS
, "PADS" },
50 { PPPOE_PADT
, "PADT" },
51 { 0, "" }, /* PPP Data */
58 PPPOE_SERVICE_NAME
= 0x0101,
59 PPPOE_AC_NAME
= 0x0102,
60 PPPOE_HOST_UNIQ
= 0x0103,
61 PPPOE_AC_COOKIE
= 0x0104,
62 PPPOE_VENDOR
= 0x0105,
63 PPPOE_RELAY_SID
= 0x0110,
64 PPPOE_MAX_PAYLOAD
= 0x0120,
65 PPPOE_SERVICE_NAME_ERROR
= 0x0201,
66 PPPOE_AC_SYSTEM_ERROR
= 0x0202,
67 PPPOE_GENERIC_ERROR
= 0x0203
70 static const struct tok pppoetag2str
[] = {
72 { PPPOE_SERVICE_NAME
, "Service-Name" },
73 { PPPOE_AC_NAME
, "AC-Name" },
74 { PPPOE_HOST_UNIQ
, "Host-Uniq" },
75 { PPPOE_AC_COOKIE
, "AC-Cookie" },
76 { PPPOE_VENDOR
, "Vendor-Specific" },
77 { PPPOE_RELAY_SID
, "Relay-Session-ID" },
78 { PPPOE_MAX_PAYLOAD
, "PPP-Max-Payload" },
79 { PPPOE_SERVICE_NAME_ERROR
, "Service-Name-Error" },
80 { PPPOE_AC_SYSTEM_ERROR
, "AC-System-Error" },
81 { PPPOE_GENERIC_ERROR
, "Generic-Error" },
85 #define PPPOE_HDRLEN 6
86 #define MAXTAGPRINT 80
89 pppoe_if_print(netdissect_options
*ndo
, const struct pcap_pkthdr
*h
, const u_char
*p
)
91 ndo
->ndo_protocol
= "pppoe";
92 ndo
->ndo_ll_hdr_len
+= pppoe_print(ndo
, p
, h
->len
);
96 pppoe_print(netdissect_options
*ndo
, const u_char
*bp
, u_int length
)
98 uint16_t pppoe_ver
, pppoe_type
, pppoe_code
, pppoe_sessionid
;
100 const u_char
*pppoe_packet
, *pppoe_payload
;
102 ndo
->ndo_protocol
= "pppoe";
103 if (length
< PPPOE_HDRLEN
) {
104 ND_PRINT(" (length %u < %u)", length
, PPPOE_HDRLEN
);
107 length
-= PPPOE_HDRLEN
;
109 ND_TCHECK_LEN(pppoe_packet
, PPPOE_HDRLEN
);
110 pppoe_ver
= (GET_U_1(pppoe_packet
) & 0xF0) >> 4;
111 pppoe_type
= (GET_U_1(pppoe_packet
) & 0x0F);
112 pppoe_code
= GET_U_1(pppoe_packet
+ 1);
113 pppoe_sessionid
= GET_BE_U_2(pppoe_packet
+ 2);
114 pppoe_length
= GET_BE_U_2(pppoe_packet
+ 4);
115 pppoe_payload
= pppoe_packet
+ PPPOE_HDRLEN
;
117 if (pppoe_ver
!= 1) {
118 ND_PRINT(" [ver %u]",pppoe_ver
);
120 if (pppoe_type
!= 1) {
121 ND_PRINT(" [type %u]",pppoe_type
);
124 ND_PRINT("PPPoE %s", tok2str(pppoecode2str
, "PAD-%x", pppoe_code
));
125 if (pppoe_code
== PPPOE_PADI
&& pppoe_length
> 1484 - PPPOE_HDRLEN
) {
126 ND_PRINT(" [len %u!]",pppoe_length
);
128 if (pppoe_length
> length
) {
129 ND_PRINT(" [len %u > %u!]", pppoe_length
, length
);
130 pppoe_length
= length
;
132 if (pppoe_sessionid
) {
133 ND_PRINT(" [ses 0x%x]", pppoe_sessionid
);
137 /* PPP session packets don't contain tags */
138 u_short tag_type
= 0xffff, tag_len
;
139 const u_char
*p
= pppoe_payload
;
143 * p points to current tag,
144 * tag_type is previous tag or 0xffff for first iteration
146 while (tag_type
&& p
< pppoe_payload
+ pppoe_length
) {
147 tag_type
= GET_BE_U_2(p
);
148 tag_len
= GET_BE_U_2(p
+ 2);
150 /* p points to tag_value */
153 unsigned ascii_count
= 0, garbage_count
= 0;
155 char tag_str
[MAXTAGPRINT
];
156 unsigned tag_str_len
= 0;
158 /* TODO print UTF-8 decoded text */
159 ND_TCHECK_LEN(p
, tag_len
);
160 for (v
= p
; v
< p
+ tag_len
&& tag_str_len
< MAXTAGPRINT
-1; v
++)
161 if (ND_ASCII_ISPRINT(GET_U_1(v
))) {
162 tag_str
[tag_str_len
++] = GET_U_1(v
);
165 tag_str
[tag_str_len
++] = '.';
168 tag_str
[tag_str_len
] = 0;
170 if (ascii_count
> garbage_count
) {
171 ND_PRINT(" [%s \"%*.*s\"]",
172 tok2str(pppoetag2str
, "TAG-0x%x", tag_type
),
177 /* Print hex, not fast to abuse printf but this doesn't get used much */
178 ND_PRINT(" [%s 0x", tok2str(pppoetag2str
, "TAG-0x%x", tag_type
));
179 for (v
=p
; v
<p
+tag_len
; v
++) {
180 ND_PRINT("%02X", GET_U_1(v
));
187 ND_PRINT(" [%s]", tok2str(pppoetag2str
,
188 "TAG-0x%x", tag_type
));
191 /* p points to next tag */
197 return (PPPOE_HDRLEN
+ ppp_print(ndo
, pppoe_payload
, pppoe_length
));
202 nd_print_invalid(ndo
);