2 * Routines for PPP Over Ethernet (PPPoE) packet disassembly (RFC2516)
4 * $Id: packet-pppoe.c,v 1.21 2002/01/21 07:36:38 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.
29 #ifdef HAVE_SYS_TYPES_H
30 # include <sys/types.h>
34 #include <epan/packet.h>
35 #include <epan/strutil.h>
38 static int proto_pppoed = -1;
40 static gint ett_pppoed = -1;
41 static gint ett_pppoed_tags = -1;
43 static int proto_pppoes = -1;
45 static dissector_handle_t ppp_handle;
47 /* For lack of a better source, I made up the following defines. -jsj */
49 #define PPPOE_CODE_SESSION 0x00
50 #define PPPOE_CODE_PADO 0x7
51 #define PPPOE_CODE_PADI 0x9
52 #define PPPOE_CODE_PADR 0x19
53 #define PPPOE_CODE_PADS 0x65
54 #define PPPOE_CODE_PADT 0xa7
56 #define PPPOE_TAG_EOL 0x0000
57 #define PPPOE_TAG_SVC_NAME 0x0101
58 #define PPPOE_TAG_AC_NAME 0x0102
59 #define PPPOE_TAG_HOST_UNIQ 0x0103
60 #define PPPOE_TAG_AC_COOKIE 0x0104
61 #define PPPOE_TAG_VENDOR 0x0105
62 #define PPPOE_TAG_RELAY_ID 0x0110
63 #define PPPOE_TAG_SVC_ERR 0x0201
64 #define PPPOE_TAG_AC_ERR 0x0202
65 #define PPPOE_TAG_GENERIC_ERR 0x0203
68 pppoecode_to_str(guint8 codetype, const char *fmt) {
69 static const value_string code_vals[] = {
70 {PPPOE_CODE_SESSION, "Session Data" },
71 {PPPOE_CODE_PADO, "Active Discovery Offer (PADO)" },
72 {PPPOE_CODE_PADI, "Active Discovery Initiation (PADI)" },
73 {PPPOE_CODE_PADR, "Active Discovery Request (PADR)" },
74 {PPPOE_CODE_PADS, "Active Discovery Session-confirmation (PADS)"},
75 {PPPOE_CODE_PADT, "Active Discovery Terminate (PADT)" },
78 return val_to_str(codetype, code_vals, fmt);
82 pppoetag_to_str(guint16 tag_type, const char *fmt) {
83 static const value_string code_vals[] = {
84 {PPPOE_TAG_EOL, "End-Of-List" },
85 {PPPOE_TAG_SVC_NAME, "Service-Name" },
86 {PPPOE_TAG_AC_NAME, "AC-Name" },
87 {PPPOE_TAG_HOST_UNIQ, "Host-Uniq" },
88 {PPPOE_TAG_AC_COOKIE, "AC-Cookie" },
89 {PPPOE_TAG_VENDOR, "Vendor-Specific" },
90 {PPPOE_TAG_RELAY_ID, "Relay-Session-Id" },
91 {PPPOE_TAG_SVC_ERR, "Service-Name-Error"},
92 {PPPOE_TAG_AC_ERR, "AC-System-Error" },
93 {PPPOE_TAG_GENERIC_ERR,"Generic-Error" },
96 return val_to_str(tag_type, code_vals, fmt);
101 dissect_pppoe_tags(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, int payload_length) {
104 guint16 poe_tag_length;
107 proto_tree *pppoe_tree;
110 /* Start Decoding Here. */
113 ti = proto_tree_add_text(tree, tvb,offset,payload_length,"PPPoE Tags");
114 pppoe_tree = proto_item_add_subtree(ti, ett_pppoed_tags);
117 while(tagstart <= payload_length-2 ) {
119 poe_tag = tvb_get_ntohs(tvb, tagstart);
120 poe_tag_length = tvb_get_ntohs(tvb, tagstart + 2);
122 proto_tree_add_text(pppoe_tree, tvb,tagstart,4,
123 "Tag: %s", pppoetag_to_str(poe_tag,"Unknown (0x%02x)"));
126 case PPPOE_TAG_SVC_NAME:
127 case PPPOE_TAG_AC_NAME:
128 case PPPOE_TAG_SVC_ERR:
129 case PPPOE_TAG_AC_ERR:
130 case PPPOE_TAG_GENERIC_ERR:
131 /* tag value should be interpreted as a utf-8 unterminated string.*/
132 if(poe_tag_length > 0 ) {
133 /* really should do some limit checking here. :( */
134 proto_tree_add_text(pppoe_tree, tvb,tagstart+4,poe_tag_length,
136 tvb_format_text(tvb, tagstart+4,poe_tag_length ));
140 if(poe_tag_length > 0 ) {
141 proto_tree_add_text(pppoe_tree, tvb,tagstart+4,poe_tag_length,
142 " Binary Data: (%d bytes)", poe_tag_length );
146 if (poe_tag == PPPOE_TAG_EOL) break;
148 tagstart += 4 + poe_tag_length;
154 dissect_pppoed(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
155 guint8 pppoe_ver_type;
159 guint16 pppoe_session_id;
160 guint16 pppoe_length;
162 proto_tree *pppoe_tree;
165 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
166 col_set_str(pinfo->cinfo,COL_PROTOCOL, "PPPoED");
168 if (check_col(pinfo->cinfo,COL_INFO)) {
169 col_clear(pinfo->cinfo,COL_INFO);
172 /* Start Decoding Here. */
173 pppoe_ver_type = tvb_get_guint8(tvb, 0);
174 pppoe_ver = (pppoe_ver_type >> 4) & 0x0f;
175 pppoe_type = pppoe_ver_type & 0x0f;
176 pppoe_code = tvb_get_guint8(tvb, 1);
178 if (check_col(pinfo->cinfo,COL_INFO)) {
179 col_add_fstr(pinfo->cinfo,COL_INFO,pppoecode_to_str(pppoe_code,"Unknown code (0x%02x)"));
182 pppoe_session_id = tvb_get_ntohs(tvb, 2);
183 pppoe_length = tvb_get_ntohs(tvb, 4);
186 ti = proto_tree_add_item(tree, proto_pppoed, tvb,0,
187 pppoe_length+6, FALSE);
188 pppoe_tree = proto_item_add_subtree(ti, ett_pppoed);
189 proto_tree_add_text(pppoe_tree, tvb,0,1,
190 "Version: %u", pppoe_ver);
191 proto_tree_add_text(pppoe_tree, tvb,0,1,
192 "Type: %u", pppoe_type);
193 proto_tree_add_text(pppoe_tree, tvb,1,1,
194 "Code: %s", pppoecode_to_str(pppoe_code,"Unknown (0x%02x)"));
195 proto_tree_add_text(pppoe_tree, tvb,2,2,
196 "Session ID: %04x", pppoe_session_id);
197 proto_tree_add_text(pppoe_tree, tvb,4,2,
198 "Payload Length: %u", pppoe_length);
200 dissect_pppoe_tags(tvb,6,pinfo,tree,6+pppoe_length);
204 proto_register_pppoed(void)
206 static gint *ett[] = {
211 proto_pppoed = proto_register_protocol("PPP-over-Ethernet Discovery",
214 proto_register_subtree_array(ett, array_length(ett));
218 proto_reg_handoff_pppoed(void)
220 dissector_handle_t pppoed_handle;
222 pppoed_handle = create_dissector_handle(dissect_pppoed, proto_pppoed);
223 dissector_add("ethertype", ETHERTYPE_PPPOED, pppoed_handle);
227 dissect_pppoes(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
228 guint8 pppoe_ver_type;
232 guint16 pppoe_session_id;
233 guint16 pppoe_length;
235 proto_tree *pppoe_tree;
239 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
240 col_set_str(pinfo->cinfo,COL_PROTOCOL, "PPPoES");
242 if (check_col(pinfo->cinfo,COL_INFO)) {
243 col_clear(pinfo->cinfo,COL_INFO);
246 /* Start Decoding Here. */
247 pppoe_ver_type = tvb_get_guint8(tvb, 0);
248 pppoe_ver = (pppoe_ver_type >> 4) & 0x0f;
249 pppoe_type = pppoe_ver_type & 0x0f;
250 pppoe_code = tvb_get_guint8(tvb, 1);
252 if (check_col(pinfo->cinfo,COL_INFO)) {
253 col_add_fstr(pinfo->cinfo,COL_INFO,
254 pppoecode_to_str(pppoe_code,"Unknown code (0x%02x)"));
257 pppoe_session_id = tvb_get_ntohs(tvb, 2);
258 pppoe_length = tvb_get_ntohs(tvb, 4);
261 ti = proto_tree_add_item(tree, proto_pppoes, tvb,0,
262 pppoe_length+6, FALSE);
263 pppoe_tree = proto_item_add_subtree(ti, ett_pppoed);
264 proto_tree_add_text(pppoe_tree, tvb,0,1,
265 "Version: %u", pppoe_ver);
266 proto_tree_add_text(pppoe_tree, tvb,0,1,
267 "Type: %u", pppoe_type);
268 proto_tree_add_text(pppoe_tree, tvb,1,1,
269 "Code: %s", pppoecode_to_str(pppoe_code,"Unknown (0x%02x)"));
270 proto_tree_add_text(pppoe_tree, tvb,2,2,
271 "Session ID: %04x", pppoe_session_id);
272 proto_tree_add_text(pppoe_tree, tvb,4,2,
273 "Payload Length: %u", pppoe_length);
275 /* dissect_ppp is apparently done as a 'top level' dissector,
276 * so this doesn't work:
277 * dissect_ppp(pd,offset+6,pinfo->fd,tree);
278 * Im gonna try fudging it.
280 next_tvb = tvb_new_subset(tvb,6,-1,-1);
281 call_dissector(ppp_handle,next_tvb,pinfo,tree);
284 proto_register_pppoes(void)
286 proto_pppoes = proto_register_protocol("PPP-over-Ethernet Session",
291 proto_reg_handoff_pppoes(void)
293 dissector_handle_t pppoes_handle;
295 pppoes_handle = create_dissector_handle(dissect_pppoes, proto_pppoes);
296 dissector_add("ethertype", ETHERTYPE_PPPOES, pppoes_handle);
299 * Get a handle for the PPP dissector.
301 ppp_handle = find_dissector("ppp");