1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.19 2002-12-18 08:53:23 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <tcpdump-stdinc.h>
#include <stdio.h>
#include <string.h>
#include "interface.h"
#include "addrtoname.h"
#include "ppp.h"
#include "ethertype.h"
#include "ether.h"
#include "extract.h" /* must come after interface.h */
/* Codes */
enum {
PPPOE_PADI = 0x09,
PPPOE_PADO = 0x07,
PPPOE_PADR = 0x19,
PPPOE_PADS = 0x65,
PPPOE_PADT = 0xa7
};
static struct tok pppoecode2str[] = {
{ PPPOE_PADI, "PADI" },
{ PPPOE_PADO, "PADO" },
{ PPPOE_PADR, "PADR" },
{ PPPOE_PADS, "PADS" },
{ PPPOE_PADT, "PADT" },
{ 0, "" }, /* PPP Data */
{ 0, NULL }
};
/* Tags */
enum {
PPPOE_EOL = 0,
PPPOE_SERVICE_NAME = 0x0101,
PPPOE_AC_NAME = 0x0102,
PPPOE_HOST_UNIQ = 0x0103,
PPPOE_AC_COOKIE = 0x0104,
PPPOE_VENDOR = 0x0105,
PPPOE_RELAY_SID = 0x0110,
PPPOE_SERVICE_NAME_ERROR = 0x0201,
PPPOE_AC_SYSTEM_ERROR = 0x0202,
PPPOE_GENERIC_ERROR = 0x0203
};
static struct tok pppoetag2str[] = {
{ PPPOE_EOL, "EOL" },
{ PPPOE_SERVICE_NAME, "Service-Name" },
{ PPPOE_AC_NAME, "AC-Name" },
{ PPPOE_HOST_UNIQ, "Host-Uniq" },
{ PPPOE_AC_COOKIE, "AC-Cookie" },
{ PPPOE_VENDOR, "Vendor-Specific" },
{ PPPOE_RELAY_SID, "Relay-Session-ID" },
{ PPPOE_SERVICE_NAME_ERROR, "Service-Name-Error" },
{ PPPOE_AC_SYSTEM_ERROR, "AC-System-Error" },
{ PPPOE_GENERIC_ERROR, "Generic-Error" },
{ 0, NULL }
};
#define PPPOE_HDRLEN 6
void
pppoe_if_print(u_char *user _U_, const struct pcap_pkthdr *h,
register const u_char *p)
{
register u_int length = h->len;
register u_int caplen = h->caplen;
u_int hdr_len;
++infodelay;
ts_print(&h->ts);
/*
* Some printers want to check that they're not walking off the
* end of the packet.
* Rather than pass it all the way down, we set this global.
*/
snapend = p + caplen;
hdr_len = pppoe_print(p, length);
/*
* If "-x" was specified, print stuff past the PPPoE and PPP headers,
* if there's anything to print.
*/
if (xflag && caplen > hdr_len)
default_print(p + hdr_len, caplen - hdr_len);
putchar('\n');
--infodelay;
if (infoprint)
info(0);
}
u_int
pppoe_print(register const u_char *bp, u_int length)
{
u_short pppoe_ver, pppoe_type, pppoe_code, pppoe_sessionid, pppoe_length;
const u_char *pppoe_packet, *pppoe_payload;
pppoe_packet = bp;
if (pppoe_packet > snapend) {
printf("[|pppoe]");
return (PPPOE_HDRLEN);
}
pppoe_ver = (pppoe_packet[0] & 0xF0) >> 4;
pppoe_type = (pppoe_packet[0] & 0x0F);
pppoe_code = pppoe_packet[1];
pppoe_sessionid = EXTRACT_16BITS(pppoe_packet + 2);
pppoe_length = EXTRACT_16BITS(pppoe_packet + 4);
pppoe_payload = pppoe_packet + PPPOE_HDRLEN;
if (snapend < pppoe_payload) {
printf(" truncated PPPoE");
return (PPPOE_HDRLEN);
}
if (pppoe_ver != 1) {
printf(" [ver %d]",pppoe_ver);
}
if (pppoe_type != 1) {
printf(" [type %d]",pppoe_type);
}
printf("PPPoE %s", tok2str(pppoecode2str, "PAD-%x", pppoe_code));
if (pppoe_code == PPPOE_PADI && pppoe_length > 1484 - PPPOE_HDRLEN) {
printf(" [len %d!]",pppoe_length);
}
if (pppoe_sessionid) {
printf(" [ses 0x%x]", pppoe_sessionid);
}
if (pppoe_payload + pppoe_length < snapend) {
#if 0
const u_char *x = pppoe_payload + pppoe_length;
printf(" [length %d (%d extra bytes)]",
pppoe_length, snapend - pppoe_payload - pppoe_length);
default_print(x, snapend - x);
#endif
snapend = pppoe_payload+pppoe_length;
}
if (pppoe_code) {
/* PPP session packets don't contain tags */
u_short tag_type = 0xffff, tag_len;
const u_char *p = pppoe_payload;
/*
* loop invariant:
* p points to next tag,
* tag_type is previous tag or 0xffff for first iteration
*/
while (tag_type && p + 4 < pppoe_payload + length &&
p + 4 < snapend) {
tag_type = EXTRACT_16BITS(p);
tag_len = EXTRACT_16BITS(p + 2);
p += 4;
/* p points to tag_value */
if (tag_len) {
int isascii = 1;
const u_char *v = p;
u_short l;
for (v = p; v < p + tag_len; v++)
if (*v >= 127 || *v < 32) {
isascii = 0;
break;
}
/* TODO print UTF8 decoded text */
if (isascii) {
l = (tag_len < 80 ? tag_len : 80);
printf(" [%s \"%*.*s\"]",
tok2str(pppoetag2str, "TAG-0x%x", tag_type),
l, l, p);
} else
printf(" [%s UTF8]",
tok2str(pppoetag2str, "TAG-0x%x", tag_type));
} else
printf(" [%s]", tok2str(pppoetag2str,
"TAG-0x%x", tag_type));
p += tag_len;
/* p points to next tag */
}
return (0);
} else {
/* PPPoE data */
printf(" ");
return (PPPOE_HDRLEN + ppp_print(pppoe_payload, pppoe_length));
}
}
|