2 * Routines for PPP Over Ethernet (PPPoE) packet disassembly (RFC2516)
4 * $Id: packet-pppoe.c,v 1.25 2002/10/21 18:17:41 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #include <epan/packet.h>
31 #include <epan/strutil.h>
34 static int proto_pppoed = -1;
36 static gint ett_pppoed = -1;
37 static gint ett_pppoed_tags = -1;
39 static int proto_pppoes = -1;
41 static dissector_handle_t ppp_handle;
43 /* For lack of a better source, I made up the following defines. -jsj */
45 #define PPPOE_CODE_SESSION 0x00
46 #define PPPOE_CODE_PADO 0x7
47 #define PPPOE_CODE_PADI 0x9
48 #define PPPOE_CODE_PADR 0x19
49 #define PPPOE_CODE_PADS 0x65
50 #define PPPOE_CODE_PADT 0xa7
52 #define PPPOE_TAG_EOL 0x0000
53 #define PPPOE_TAG_SVC_NAME 0x0101
54 #define PPPOE_TAG_AC_NAME 0x0102
55 #define PPPOE_TAG_HOST_UNIQ 0x0103
56 #define PPPOE_TAG_AC_COOKIE 0x0104
57 #define PPPOE_TAG_VENDOR 0x0105
58 #define PPPOE_TAG_RELAY_ID 0x0110
59 #define PPPOE_TAG_SVC_ERR 0x0201
60 #define PPPOE_TAG_AC_ERR 0x0202
61 #define PPPOE_TAG_GENERIC_ERR 0x0203
64 pppoecode_to_str(guint8 codetype, const char *fmt) {
65 static const value_string code_vals[] = {
66 {PPPOE_CODE_SESSION, "Session Data" },
67 {PPPOE_CODE_PADO, "Active Discovery Offer (PADO)" },
68 {PPPOE_CODE_PADI, "Active Discovery Initiation (PADI)" },
69 {PPPOE_CODE_PADR, "Active Discovery Request (PADR)" },
70 {PPPOE_CODE_PADS, "Active Discovery Session-confirmation (PADS)"},
71 {PPPOE_CODE_PADT, "Active Discovery Terminate (PADT)" },
74 return val_to_str(codetype, code_vals, fmt);
78 pppoetag_to_str(guint16 tag_type, const char *fmt) {
79 static const value_string code_vals[] = {
80 {PPPOE_TAG_EOL, "End-Of-List" },
81 {PPPOE_TAG_SVC_NAME, "Service-Name" },
82 {PPPOE_TAG_AC_NAME, "AC-Name" },
83 {PPPOE_TAG_HOST_UNIQ, "Host-Uniq" },
84 {PPPOE_TAG_AC_COOKIE, "AC-Cookie" },
85 {PPPOE_TAG_VENDOR, "Vendor-Specific" },
86 {PPPOE_TAG_RELAY_ID, "Relay-Session-Id" },
87 {PPPOE_TAG_SVC_ERR, "Service-Name-Error"},
88 {PPPOE_TAG_AC_ERR, "AC-System-Error" },
89 {PPPOE_TAG_GENERIC_ERR,"Generic-Error" },
92 return val_to_str(tag_type, code_vals, fmt);
97 dissect_pppoe_tags(tvbuff_t *tvb, int offset, proto_tree *tree, int payload_length) {
100 guint16 poe_tag_length;
103 proto_tree *pppoe_tree;
106 /* Start Decoding Here. */
109 ti = proto_tree_add_text(tree, tvb,offset,payload_length,"PPPoE Tags");
110 pppoe_tree = proto_item_add_subtree(ti, ett_pppoed_tags);
113 while(tagstart <= payload_length-2 ) {
115 poe_tag = tvb_get_ntohs(tvb, tagstart);
116 poe_tag_length = tvb_get_ntohs(tvb, tagstart + 2);
118 proto_tree_add_text(pppoe_tree, tvb,tagstart,4,
119 "Tag: %s", pppoetag_to_str(poe_tag,"Unknown (0x%02x)"));
122 case PPPOE_TAG_SVC_NAME:
123 case PPPOE_TAG_AC_NAME:
124 case PPPOE_TAG_SVC_ERR:
125 case PPPOE_TAG_AC_ERR:
126 case PPPOE_TAG_GENERIC_ERR:
127 /* tag value should be interpreted as a utf-8 unterminated string.*/
128 if(poe_tag_length > 0 ) {
129 /* really should do some limit checking here. :( */
130 proto_tree_add_text(pppoe_tree, tvb,tagstart+4,poe_tag_length,
132 tvb_format_text(tvb, tagstart+4,poe_tag_length ));
136 if(poe_tag_length > 0 ) {
137 proto_tree_add_text(pppoe_tree, tvb,tagstart+4,poe_tag_length,
138 " Binary Data: (%d bytes)", poe_tag_length );
142 if (poe_tag == PPPOE_TAG_EOL) break;
144 tagstart += 4 + poe_tag_length;
150 dissect_pppoed(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
151 guint8 pppoe_ver_type;
155 guint16 pppoe_session_id;
156 guint16 pppoe_length;
158 proto_tree *pppoe_tree;
161 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
162 col_set_str(pinfo->cinfo,COL_PROTOCOL, "PPPoED");
164 if (check_col(pinfo->cinfo,COL_INFO)) {
165 col_clear(pinfo->cinfo,COL_INFO);
168 /* Start Decoding Here. */
169 pppoe_ver_type = tvb_get_guint8(tvb, 0);
170 pppoe_ver = (pppoe_ver_type >> 4) & 0x0f;
171 pppoe_type = pppoe_ver_type & 0x0f;
172 pppoe_code = tvb_get_guint8(tvb, 1);
174 if (check_col(pinfo->cinfo,COL_INFO)) {
175 col_add_fstr(pinfo->cinfo,COL_INFO,pppoecode_to_str(pppoe_code,"Unknown code (0x%02x)"));
178 pppoe_session_id = tvb_get_ntohs(tvb, 2);
179 pppoe_length = tvb_get_ntohs(tvb, 4);
182 ti = proto_tree_add_item(tree, proto_pppoed, tvb,0,
183 pppoe_length+6, FALSE);
184 pppoe_tree = proto_item_add_subtree(ti, ett_pppoed);
185 proto_tree_add_text(pppoe_tree, tvb,0,1,
186 "Version: %u", pppoe_ver);
187 proto_tree_add_text(pppoe_tree, tvb,0,1,
188 "Type: %u", pppoe_type);
189 proto_tree_add_text(pppoe_tree, tvb,1,1,
190 "Code: %s", pppoecode_to_str(pppoe_code,"Unknown (0x%02x)"));
191 proto_tree_add_text(pppoe_tree, tvb,2,2,
192 "Session ID: %04x", pppoe_session_id);
193 proto_tree_add_text(pppoe_tree, tvb,4,2,
194 "Payload Length: %u", pppoe_length);
196 dissect_pppoe_tags(tvb,6,tree,6+pppoe_length);
200 proto_register_pppoed(void)
202 static gint *ett[] = {
207 proto_pppoed = proto_register_protocol("PPP-over-Ethernet Discovery",
210 proto_register_subtree_array(ett, array_length(ett));
214 proto_reg_handoff_pppoed(void)
216 dissector_handle_t pppoed_handle;
218 pppoed_handle = create_dissector_handle(dissect_pppoed, proto_pppoed);
219 dissector_add("ethertype", ETHERTYPE_PPPOED, pppoed_handle);
223 dissect_pppoes(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
224 guint8 pppoe_ver_type;
228 guint16 pppoe_session_id;
229 guint16 pppoe_length;
230 gint length, reported_length;
232 proto_tree *pppoe_tree;
236 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
237 col_set_str(pinfo->cinfo,COL_PROTOCOL, "PPPoES");
239 if (check_col(pinfo->cinfo,COL_INFO)) {
240 col_clear(pinfo->cinfo,COL_INFO);
243 /* Start Decoding Here. */
244 pppoe_ver_type = tvb_get_guint8(tvb, 0);
245 pppoe_ver = (pppoe_ver_type >> 4) & 0x0f;
246 pppoe_type = pppoe_ver_type & 0x0f;
247 pppoe_code = tvb_get_guint8(tvb, 1);
249 if (check_col(pinfo->cinfo,COL_INFO)) {
250 col_add_fstr(pinfo->cinfo,COL_INFO,
251 pppoecode_to_str(pppoe_code,"Unknown code (0x%02x)"));
254 pppoe_session_id = tvb_get_ntohs(tvb, 2);
255 pppoe_length = tvb_get_ntohs(tvb, 4);
258 ti = proto_tree_add_item(tree, proto_pppoes, tvb,0,
260 pppoe_tree = proto_item_add_subtree(ti, ett_pppoed);
261 proto_tree_add_text(pppoe_tree, tvb,0,1,
262 "Version: %u", pppoe_ver);
263 proto_tree_add_text(pppoe_tree, tvb,0,1,
264 "Type: %u", pppoe_type);
265 proto_tree_add_text(pppoe_tree, tvb,1,1,
266 "Code: %s", pppoecode_to_str(pppoe_code,"Unknown (0x%02x)"));
267 proto_tree_add_text(pppoe_tree, tvb,2,2,
268 "Session ID: %04x", pppoe_session_id);
269 proto_tree_add_text(pppoe_tree, tvb,4,2,
270 "Payload Length: %u", pppoe_length);
272 /* dissect_ppp is apparently done as a 'top level' dissector,
273 * so this doesn't work:
274 * dissect_ppp(pd,offset+6,pinfo->fd,tree);
275 * Im gonna try fudging it.
277 length = tvb_length_remaining(tvb, 6);
278 reported_length = tvb_reported_length_remaining(tvb, 6);
279 g_assert(length >= 0);
280 g_assert(reported_length >= 0);
281 if (length > reported_length)
282 length = reported_length;
283 if ((guint)length > pppoe_length)
284 length = pppoe_length;
285 if ((guint)reported_length > pppoe_length)
286 reported_length = pppoe_length;
287 next_tvb = tvb_new_subset(tvb,6,length,reported_length);
288 call_dissector(ppp_handle,next_tvb,pinfo,tree);
291 proto_register_pppoes(void)
293 proto_pppoes = proto_register_protocol("PPP-over-Ethernet Session",
298 proto_reg_handoff_pppoes(void)
300 dissector_handle_t pppoes_handle;
302 pppoes_handle = create_dissector_handle(dissect_pppoes, proto_pppoes);
303 dissector_add("ethertype", ETHERTYPE_PPPOES, pppoes_handle);
306 * Get a handle for the PPP dissector.
308 ppp_handle = find_dissector("ppp");