2 * Routines for PPP Over Ethernet (PPPoE) packet disassembly (RFC2516)
4 * $Id: packet-pppoe.c,v 1.14 2001/01/04 04:15:30 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
39 static int proto_pppoed = -1;
41 static gint ett_pppoed = -1;
42 static gint ett_pppoed_tags = -1;
44 static int proto_pppoes = -1;
46 static dissector_handle_t payload_ppp_handle;
48 /* For lack of a better source, I made up the following defines. -jsj */
50 #define PPPOE_CODE_SESSION 0x00
51 #define PPPOE_CODE_PADO 0x7
52 #define PPPOE_CODE_PADI 0x9
53 #define PPPOE_CODE_PADR 0x19
54 #define PPPOE_CODE_PADS 0x65
55 #define PPPOE_CODE_PADT 0xa7
57 #define PPPOE_TAG_EOL 0x0000
58 #define PPPOE_TAG_SVC_NAME 0x0101
59 #define PPPOE_TAG_AC_NAME 0x0102
60 #define PPPOE_TAG_HOST_UNIQ 0x0103
61 #define PPPOE_TAG_AC_COOKIE 0x0104
62 #define PPPOE_TAG_VENDOR 0x0105
63 #define PPPOE_TAG_RELAY_ID 0x0110
64 #define PPPOE_TAG_SVC_ERR 0x0201
65 #define PPPOE_TAG_AC_ERR 0x0202
66 #define PPPOE_TAG_GENERIC_ERR 0x0203
69 pppoecode_to_str(guint8 codetype, const char *fmt) {
70 static const value_string code_vals[] = {
71 {PPPOE_CODE_SESSION, "Session Data" },
72 {PPPOE_CODE_PADO, "Active Discovery Offer (PADO)" },
73 {PPPOE_CODE_PADI, "Active Discovery Initiation (PADI)" },
74 {PPPOE_CODE_PADR, "Active Discovery Request (PADR)" },
75 {PPPOE_CODE_PADS, "Active Discovery Session-confirmation (PADS)"},
76 {PPPOE_CODE_PADT, "Active Discovery Terminate (PADT)" },
79 return val_to_str(codetype, code_vals, fmt);
83 pppoetag_to_str(guint16 tag_type, const char *fmt) {
84 static const value_string code_vals[] = {
85 {PPPOE_TAG_EOL, "End-Of-List" },
86 {PPPOE_TAG_SVC_NAME, "Service-Name" },
87 {PPPOE_TAG_AC_NAME, "AC-Name" },
88 {PPPOE_TAG_HOST_UNIQ, "Host-Uniq" },
89 {PPPOE_TAG_AC_COOKIE, "AC-Cookie" },
90 {PPPOE_TAG_VENDOR, "Vendor-Specific" },
91 {PPPOE_TAG_RELAY_ID, "Relay-Session-Id" },
92 {PPPOE_TAG_SVC_ERR, "Service-Name-Error"},
93 {PPPOE_TAG_AC_ERR, "AC-System-Error" },
94 {PPPOE_TAG_GENERIC_ERR,"Generic-Error" },
97 return val_to_str(tag_type, code_vals, fmt);
102 dissect_pppoe_tags(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, int payload_length) {
105 guint16 poe_tag_length;
108 proto_tree *pppoe_tree;
111 /* Start Decoding Here. */
114 ti = proto_tree_add_text(tree, tvb,offset,payload_length,"PPPoE Tags");
115 pppoe_tree = proto_item_add_subtree(ti, ett_pppoed_tags);
118 while(tagstart <= payload_length-2 ) {
120 poe_tag = tvb_get_ntohs(tvb, tagstart);
121 poe_tag_length = tvb_get_ntohs(tvb, tagstart + 2);
123 proto_tree_add_text(pppoe_tree, tvb,tagstart,4,
124 "Tag: %s", pppoetag_to_str(poe_tag,"Unknown (0x%02x)"));
127 case PPPOE_TAG_SVC_NAME:
128 case PPPOE_TAG_AC_NAME:
129 case PPPOE_TAG_SVC_ERR:
130 case PPPOE_TAG_AC_ERR:
131 case PPPOE_TAG_GENERIC_ERR:
132 /* tag value should be interpreted as a utf-8 unterminated string.*/
133 if(poe_tag_length > 0 ) {
134 /* really should do some limit checking here. :( */
135 proto_tree_add_text(pppoe_tree, tvb,tagstart+4,poe_tag_length,
137 tvb_format_text(tvb, tagstart+4,poe_tag_length ));
141 if(poe_tag_length > 0 ) {
142 proto_tree_add_text(pppoe_tree, tvb,tagstart+4,poe_tag_length,
143 " Binary Data: (%d bytes)", poe_tag_length );
147 if (poe_tag == PPPOE_TAG_EOL) break;
149 tagstart += 4 + poe_tag_length;
155 dissect_pppoed(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
156 guint8 pppoe_ver_type;
160 guint16 pppoe_session_id;
161 guint16 pppoe_length;
163 proto_tree *pppoe_tree;
166 CHECK_DISPLAY_AS_DATA(proto_pppoed, tvb, pinfo, tree);
168 pinfo->current_proto = "PPPoED";
170 if (check_col(pinfo->fd, COL_PROTOCOL)) {
171 col_set_str(pinfo->fd,COL_PROTOCOL, "PPPoED");
173 if (check_col(pinfo->fd,COL_INFO)) {
174 col_clear(pinfo->fd,COL_INFO);
177 /* Start Decoding Here. */
178 pppoe_ver_type = tvb_get_guint8(tvb, 0);
179 pppoe_ver = (pppoe_ver_type >> 4) & 0x0f;
180 pppoe_type = pppoe_ver_type & 0x0f;
181 pppoe_code = tvb_get_guint8(tvb, 1);
183 if (check_col(pinfo->fd,COL_INFO)) {
184 col_add_fstr(pinfo->fd,COL_INFO,pppoecode_to_str(pppoe_code,"Unknown code (0x%02x)"));
187 pppoe_session_id = tvb_get_ntohs(tvb, 2);
188 pppoe_length = tvb_get_ntohs(tvb, 4);
191 ti = proto_tree_add_item(tree, proto_pppoed, tvb,0,
192 pppoe_length+6, FALSE);
193 pppoe_tree = proto_item_add_subtree(ti, ett_pppoed);
194 proto_tree_add_text(pppoe_tree, tvb,0,1,
195 "Version: %u", pppoe_ver);
196 proto_tree_add_text(pppoe_tree, tvb,0,1,
197 "Type: %u", pppoe_type);
198 proto_tree_add_text(pppoe_tree, tvb,1,1,
199 "Code: %s", pppoecode_to_str(pppoe_code,"Unknown (0x%02x)"));
200 proto_tree_add_text(pppoe_tree, tvb,2,2,
201 "Session ID: %04x", pppoe_session_id);
202 proto_tree_add_text(pppoe_tree, tvb,4,2,
203 "Payload Length: %u", pppoe_length);
205 dissect_pppoe_tags(tvb,6,pinfo,tree,6+pppoe_length);
209 proto_register_pppoed(void)
211 static gint *ett[] = {
216 proto_pppoed = proto_register_protocol("PPP-over-Ethernet Discovery",
219 proto_register_subtree_array(ett, array_length(ett));
223 proto_reg_handoff_pppoed(void)
225 dissector_add("ethertype", ETHERTYPE_PPPOED, dissect_pppoed);
229 dissect_pppoes(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
230 guint8 pppoe_ver_type;
234 guint16 pppoe_session_id;
235 guint16 pppoe_length;
237 proto_tree *pppoe_tree;
241 CHECK_DISPLAY_AS_DATA(proto_pppoes, tvb, pinfo, tree);
243 pinfo->current_proto = "PPPoES";
245 if (check_col(pinfo->fd, COL_PROTOCOL)) {
246 col_set_str(pinfo->fd,COL_PROTOCOL, "PPPoES");
248 if (check_col(pinfo->fd,COL_INFO)) {
249 col_clear(pinfo->fd,COL_INFO);
252 /* Start Decoding Here. */
253 pppoe_ver_type = tvb_get_guint8(tvb, 0);
254 pppoe_ver = (pppoe_ver_type >> 4) & 0x0f;
255 pppoe_type = pppoe_ver_type & 0x0f;
256 pppoe_code = tvb_get_guint8(tvb, 1);
258 if (check_col(pinfo->fd,COL_INFO)) {
259 col_add_fstr(pinfo->fd,COL_INFO,
260 pppoecode_to_str(pppoe_code,"Unknown code (0x%02x)"));
263 pppoe_session_id = tvb_get_ntohs(tvb, 2);
264 pppoe_length = tvb_get_ntohs(tvb, 4);
267 ti = proto_tree_add_item(tree, proto_pppoes, tvb,0,
268 pppoe_length+6, FALSE);
269 pppoe_tree = proto_item_add_subtree(ti, ett_pppoed);
270 proto_tree_add_text(pppoe_tree, tvb,0,1,
271 "Version: %u", pppoe_ver);
272 proto_tree_add_text(pppoe_tree, tvb,0,1,
273 "Type: %u", pppoe_type);
274 proto_tree_add_text(pppoe_tree, tvb,1,1,
275 "Code: %s", pppoecode_to_str(pppoe_code,"Unknown (0x%02x)"));
276 proto_tree_add_text(pppoe_tree, tvb,2,2,
277 "Session ID: %04x", pppoe_session_id);
278 proto_tree_add_text(pppoe_tree, tvb,4,2,
279 "Payload Length: %u", pppoe_length);
281 /* dissect_ppp is apparently done as a 'top level' dissector,
282 * so this doesn't work:
283 * dissect_ppp(pd,offset+6,pinfo->fd,tree);
284 * Im gonna try fudging it.
286 next_tvb = tvb_new_subset(tvb,6,-1,-1);
287 call_dissector(payload_ppp_handle,next_tvb,pinfo,tree);
290 proto_register_pppoes(void)
292 proto_pppoes = proto_register_protocol("PPP-over-Ethernet Session",
297 proto_reg_handoff_pppoes(void)
299 dissector_add("ethertype", ETHERTYPE_PPPOES, dissect_pppoes);
302 * Get a handle for the PPP payload dissector.
304 payload_ppp_handle = find_dissector("payload_ppp");