2 * Routines for pgm packet disassembly
4 * $Id: packet-pgm.c,v 1.19 2002/08/28 21:00:25 jmayer Exp $
6 * Copyright (c) 2000 by Talarian Corp
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1999 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include <epan/packet.h>
39 #include <epan/resolv.h>
40 #include <epan/strutil.h>
41 #include <epan/conversation.h>
44 #include <epan/proto.h>
46 void proto_reg_handoff_pgm(void);
47 static void proto_rereg_pgm(void);
49 typedef guint8 nchar_t;
50 typedef guint16 nshort_t;
51 typedef guint32 nlong_t;
53 /* The PGM main header */
55 nshort_t sport; /* source port */
56 nshort_t dport; /* destination port */
57 nchar_t type; /* PGM type */
58 nchar_t opts; /* options */
59 nshort_t cksum; /* checksum */
60 nchar_t gsi[6]; /* Global Source ID */
61 nshort_t tsdulen; /* TSDU length */
63 #define pgmhdr_ntoh(_p) \
64 (_p)->sport = g_ntohs((_p)->sport); \
65 (_p)->dport = g_ntohs((_p)->dport); \
66 (_p)->type = g_ntohs((_p)->type); \
67 (_p)->opts = g_ntohs((_p)->opts); \
68 (_p)->cksum = g_ntohs((_p)->cksum); \
69 (_p)->tsdulen = g_ntohs((_p)->tsdulen)
71 /* The PGM SPM header */
73 nlong_t sqn; /* SPM's sequence number */
74 nlong_t trail; /* Trailing edge sequence number */
75 nlong_t lead; /* Leading edge sequence number */
76 nshort_t path_afi; /* NLA AFI */
77 nshort_t res; /* reserved */
78 nlong_t path; /* Path NLA */
80 static const size_t PGM_SPM_SZ = sizeof(pgm_type)+sizeof(pgm_spm_t);
81 #define spm_ntoh(_p) \
82 (_p)->sqn = g_ntohl((_p)->sqn); \
83 (_p)->trail = g_ntohl((_p)->trail); \
84 (_p)->lead = g_ntohl((_p)->lead); \
85 (_p)->path_afi = g_ntohs((_p)->path_afi); \
86 (_p)->res = g_ntohs((_p)->res);
88 /* The PGM Data (ODATA/RDATA) header */
90 nlong_t sqn; /* Data Packet sequence number */
91 nlong_t trail; /* Trailing edge sequence number */
93 #define data_ntoh(_p) \
94 (_p)->sqn = g_ntohl((_p)->sqn); \
95 (_p)->trail = g_ntohl((_p)->trail)
96 static const size_t PGM_DATA_HDR_SZ = sizeof(pgm_type)+sizeof(pgm_data_t);
98 /* The PGM NAK (NAK/N-NAK/NCF) header */
100 nlong_t sqn; /* Requested sequence number */
101 nshort_t src_afi; /* NLA AFI for source (IPv4 is set to 1) */
102 nshort_t src_res; /* reserved */
103 nlong_t src; /* Source NLA */
104 nshort_t grp_afi; /* Multicast group AFI (IPv4 is set to 1) */
105 nshort_t grp_res; /* reserved */
106 nlong_t grp; /* Multicast group NLA */
108 static const size_t PGM_NAK_SZ = sizeof(pgm_type)+sizeof(pgm_nak_t);
109 #define nak_ntoh(_p) \
110 (_p)->sqn = g_ntohl((_p)->sqn); \
111 (_p)->src_afi = g_ntohs((_p)->src_afi); \
112 (_p)->src_res = g_ntohs((_p)->src_res); \
113 (_p)->grp_afi = g_ntohs((_p)->grp_afi); \
114 (_p)->grp_res = g_ntohs((_p)->grp_res)
116 /* The PGM ACK header (PGMCC) */
118 nlong_t rx_max_sqn; /* RX_MAX sequence number */
119 nlong_t bitmap; /* Received Packet Bitmap */
121 static const size_t PGM_ACK_SZ = sizeof(pgm_type)+sizeof(pgm_ack_t);
122 #define ack_ntoh(_p) \
123 (_p)->rx_max_sqn = g_ntohl((_p)->rx_max_sqn); \
124 (_p)->bitmap = g_ntohl((_p)->bitmap)
126 /* constants for hdr types */
127 #if defined(PGM_SPEC_01_PCKTS)
128 /* old spec-01 types */
129 #define PGM_SPM_PCKT 0x00
130 #define PGM_ODATA_PCKT 0x10
131 #define PGM_RDATA_PCKT 0x11
132 #define PGM_NAK_PCKT 0x20
133 #define PGM_NNAK_PCKT 0x21
134 #define PGM_NCF_PCKT 0x30
136 /* spec-02 types (as well as spec-04+) */
137 #define PGM_SPM_PCKT 0x00
138 #define PGM_ODATA_PCKT 0x04
139 #define PGM_RDATA_PCKT 0x05
140 #define PGM_NAK_PCKT 0x08
141 #define PGM_NNAK_PCKT 0x09
142 #define PGM_NCF_PCKT 0x0A
143 #define PGM_ACK_PCKT 0x0D
144 #endif /* PGM_SPEC_01_PCKTS */
146 /* port swapping on NAK and NNAKs or not (default is to swap) */
147 /* PGM_NO_PORT_SWAP */
149 /* option flags (main PGM header) */
151 #define PGM_OPT_NETSIG 0x02
152 #define PGM_OPT_VAR_PKTLEN 0x40
153 #define PGM_OPT_PARITY 0x80
156 #define PGM_OPT_LENGTH 0x00
157 #define PGM_OPT_END 0x80
158 #define PGM_OPT_FRAGMENT 0x01
159 #define PGM_OPT_NAK_LIST 0x02
160 #define PGM_OPT_JOIN 0x03
161 #define PGM_OPT_REDIRECT 0x07
162 #define PGM_OPT_SYN 0x0D
163 #define PGM_OPT_FIN 0x0E
164 #define PGM_OPT_RST 0x0F
165 #define PGM_OPT_PARITY_PRM 0x08
166 #define PGM_OPT_PARITY_GRP 0x09
167 #define PGM_OPT_CURR_TGSIZE 0x0A
168 #define PGM_OPT_PGMCC_DATA 0x12
169 #define PGM_OPT_PGMCC_FEEDBACK 0x13
171 static const nchar_t PGM_OPT_INVALID = 0x7F;
174 #define PGM_OPX_IGNORE 0x00
175 #define PGM_OPX_INVAL 0x01
176 #define PGM_OPX_DISCARD 0x10
197 } pgm_opt_nak_list_t;
200 * To squeeze the whole option into 255 bytes, we
201 * can only have 62 in the list
203 #define PGM_MAX_NAK_LIST_SZ (62)
210 nlong_t opt_join_min;
219 } pgm_opt_parity_prm_t;
221 /* OPT_PARITY_PRM P and O bits */
222 static const nchar_t PGM_OPT_PARITY_PRM_PRO = 0x2;
223 static const nchar_t PGM_OPT_PARITY_PRM_OND = 0x1;
231 } pgm_opt_parity_grp_t;
239 } pgm_opt_curr_tgsize_t;
250 } pgm_opt_pgmcc_data_t;
261 } pgm_opt_pgmcc_feedback_t;
264 * Udp port for UDP encapsulation
266 #define DEFAULT_UDP_ENCAP_UCAST_PORT 3055
267 #define DEFAULT_UDP_ENCAP_MCAST_PORT 3056
269 static int udp_encap_ucast_port = 0;
270 static int udp_encap_mcast_port = 0;
271 static int old_encap_ucast_port = 0;
272 static int old_encap_mcast_port = 0;
274 static int proto_pgm = -1;
275 static int ett_pgm = -1;
276 static int ett_pgm_optbits = -1;
277 static int ett_pgm_opts = -1;
278 static int ett_pgm_spm = -1;
279 static int ett_pgm_data = -1;
280 static int ett_pgm_nak = -1;
281 static int ett_pgm_ack = -1;
282 static int ett_pgm_opts_join = -1;
283 static int ett_pgm_opts_parityprm = -1;
284 static int ett_pgm_opts_paritygrp = -1;
285 static int ett_pgm_opts_naklist = -1;
286 static int ett_pgm_opts_ccdata = -1;
288 static int hf_pgm_main_sport = -1;
289 static int hf_pgm_main_dport = -1;
290 static int hf_pgm_main_type = -1;
291 static int hf_pgm_main_opts = -1;
292 static int hf_pgm_main_opts_opt = -1;
293 static int hf_pgm_main_opts_netsig = -1;
294 static int hf_pgm_main_opts_varlen = -1;
295 static int hf_pgm_main_opts_parity = -1;
296 static int hf_pgm_main_cksum = -1;
297 static int hf_pgm_main_gsi = -1;
298 static int hf_pgm_main_tsdulen = -1;
299 static int hf_pgm_spm_sqn = -1;
300 static int hf_pgm_spm_lead = -1;
301 static int hf_pgm_spm_trail = -1;
302 static int hf_pgm_spm_pathafi = -1;
303 static int hf_pgm_spm_res = -1;
304 static int hf_pgm_spm_path = -1;
305 static int hf_pgm_data_sqn = -1;
306 static int hf_pgm_data_trail = -1;
307 static int hf_pgm_nak_sqn = -1;
308 static int hf_pgm_nak_srcafi = -1;
309 static int hf_pgm_nak_srcres = -1;
310 static int hf_pgm_nak_src = -1;
311 static int hf_pgm_nak_grpafi = -1;
312 static int hf_pgm_nak_grpres = -1;
313 static int hf_pgm_nak_grp = -1;
314 static int hf_pgm_ack_sqn = -1;
315 static int hf_pgm_ack_bitmap = -1;
317 static int hf_pgm_opt_type = -1;
318 static int hf_pgm_opt_len = -1;
319 static int hf_pgm_opt_tlen = -1;
321 static int hf_pgm_genopt_type = -1;
322 static int hf_pgm_genopt_len = -1;
323 static int hf_pgm_genopt_opx = -1;
325 static int hf_pgm_opt_join_res = -1;
326 static int hf_pgm_opt_join_minjoin = -1;
328 static int hf_pgm_opt_parity_prm_po = -1;
329 static int hf_pgm_opt_parity_prm_prmtgsz = -1;
331 static int hf_pgm_opt_parity_grp_res = -1;
332 static int hf_pgm_opt_parity_grp_prmgrp = -1;
334 #ifdef PGM_UNUSED_HANDLES
335 static int hf_pgm_opt_curr_tgsize_type = -1;
336 static int hf_pgm_opt_curr_tgsize_len = -1;
337 static int hf_pgm_opt_curr_tgsize_opx = -1;
338 static int hf_pgm_opt_curr_tgsize_res = -1;
339 static int hf_pgm_opt_curr_tgsize_prmatgsz = -1;
342 static int hf_pgm_opt_nak_res = -1;
343 static int hf_pgm_opt_nak_list = -1;
345 static int hf_pgm_opt_ccdata_res = -1;
346 static int hf_pgm_opt_ccdata_tsp = -1;
347 static int hf_pgm_opt_ccdata_afi = -1;
348 static int hf_pgm_opt_ccdata_res2 = -1;
349 static int hf_pgm_opt_ccdata_acker = -1;
351 static int hf_pgm_opt_ccfeedbk_res = -1;
352 static int hf_pgm_opt_ccfeedbk_tsp = -1;
353 static int hf_pgm_opt_ccfeedbk_afi = -1;
354 static int hf_pgm_opt_ccfeedbk_lossrate = -1;
355 static int hf_pgm_opt_ccfeedbk_acker = -1;
357 static dissector_table_t subdissector_table;
358 static heur_dissector_list_t heur_subdissector_list;
359 static dissector_handle_t data_handle;
362 * As of the time this comment was typed
364 * http://search.ietf.org/internet-drafts/draft-speakman-pgm-spec-06.txt
366 * was the URL for the PGM draft.
370 optsstr(nchar_t opts)
372 static char msg[256];
379 sprintf(p, "Present");
380 p += strlen("Present");
382 if (opts & PGM_OPT_NETSIG){
390 if (opts & PGM_OPT_VAR_PKTLEN){
398 if (opts & PGM_OPT_PARITY){
407 sprintf(p, "0x%x", opts);
412 paritystr(nchar_t parity)
414 static char msg[256];
420 if (parity & PGM_OPT_PARITY_PRM_PRO){
421 sprintf(p, "Pro-active");
422 p += strlen("Pro-active");
424 if (parity & PGM_OPT_PARITY_PRM_OND){
433 sprintf(p, "0x%x", parity);
438 static const value_string opt_vals[] = {
439 { PGM_OPT_LENGTH, "Length" },
440 { PGM_OPT_END, "End" },
441 { PGM_OPT_FRAGMENT, "Fragment" },
442 { PGM_OPT_NAK_LIST, "NakList" },
443 { PGM_OPT_JOIN, "Join" },
444 { PGM_OPT_REDIRECT, "ReDirect" },
445 { PGM_OPT_SYN, "Syn" },
446 { PGM_OPT_FIN, "Fin" },
447 { PGM_OPT_RST, "Rst" },
448 { PGM_OPT_PARITY_PRM, "ParityPrm" },
449 { PGM_OPT_PARITY_GRP, "ParityGrp" },
450 { PGM_OPT_CURR_TGSIZE, "CurrTgsiz" },
451 { PGM_OPT_PGMCC_DATA, "CcData" },
452 { PGM_OPT_PGMCC_FEEDBACK, "CcFeedBack" },
456 static const value_string opx_vals[] = {
457 { PGM_OPX_IGNORE, "Ignore" },
458 { PGM_OPX_INVAL, "Inval" },
459 { PGM_OPX_DISCARD, "DisCard" },
464 dissect_pgmopts(tvbuff_t *tvb, int offset, proto_tree *tree,
468 proto_tree *opts_tree = NULL;
469 proto_tree *opt_tree = NULL;
470 pgm_opt_length_t opts;
471 pgm_opt_generic_t genopts;
472 int theend = 0, firsttime = 1;
474 tvb_memcpy(tvb, (guint8 *)&opts, offset, sizeof(opts));
475 opts.total_len = g_ntohs(opts.total_len);
477 tf = proto_tree_add_text(tree, tvb, offset,
479 "%s Options (Total Length %d)", pktname, opts.total_len);
480 opts_tree = proto_item_add_subtree(tf, ett_pgm_opts);
481 proto_tree_add_uint(opts_tree, hf_pgm_opt_type, tvb,
482 offset, 1, opts.type);
483 proto_tree_add_uint(opts_tree, hf_pgm_opt_len, tvb,
484 offset+1, 1, opts.len);
485 proto_tree_add_uint(opts_tree, hf_pgm_opt_tlen, tvb,
486 offset+2, 2, opts.total_len);
489 for (opts.total_len -= 4; opts.total_len > 0;){
490 tvb_memcpy(tvb, (guint8 *)&genopts, offset, sizeof(genopts));
491 if (genopts.type & PGM_OPT_END) {
492 genopts.type &= ~PGM_OPT_END;
495 tf = proto_tree_add_text(opts_tree, tvb, offset, genopts.len,
496 "Option: %s, Length: %u",
497 val_to_str(genopts.type, opt_vals, "Unknown (0x%02x)"),
499 if (genopts.len == 0)
502 switch(genopts.type) {
504 pgm_opt_join_t optdata;
506 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
507 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_join);
509 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
510 tvb, offset, 1, genopts.type);
512 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
513 offset+1, 1, genopts.len);
515 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx, tvb,
516 offset+2, 1, genopts.opx);
518 proto_tree_add_uint(opt_tree, hf_pgm_opt_join_res, tvb,
519 offset+3, 1, optdata.res);
521 proto_tree_add_uint(opt_tree, hf_pgm_opt_join_minjoin, tvb,
522 offset+4, 4, g_ntohl(optdata.opt_join_min));
526 case PGM_OPT_PARITY_PRM:{
527 pgm_opt_parity_prm_t optdata;
529 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
530 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_parityprm);
532 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
533 tvb, offset, 1, genopts.type);
535 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
536 offset+1, 1, genopts.len);
538 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
539 tvb, offset+2, 1, genopts.opx);
541 proto_tree_add_uint_format(opt_tree, hf_pgm_opt_parity_prm_po, tvb,
542 offset+3, 1, optdata.po, "Parity Parameters: %s (0x%x)",
543 paritystr(optdata.po), optdata.po);
545 proto_tree_add_uint(opt_tree, hf_pgm_opt_parity_prm_prmtgsz,
546 tvb, offset+4, 4, g_ntohl(optdata.prm_tgsz));
550 case PGM_OPT_PARITY_GRP:{
551 pgm_opt_parity_grp_t optdata;
553 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
554 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_paritygrp);
556 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
557 tvb, offset, 1, genopts.type);
559 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
560 offset+1, 1, genopts.len);
562 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
563 tvb, offset+2, 1, genopts.opx);
565 proto_tree_add_uint(opt_tree, hf_pgm_opt_parity_grp_res, tvb,
566 offset+3, 1, optdata.res);
568 proto_tree_add_uint(opt_tree, hf_pgm_opt_parity_grp_prmgrp,
569 tvb, offset+4, 4, g_ntohl(optdata.prm_grp));
573 case PGM_OPT_NAK_LIST:{
574 pgm_opt_nak_list_t optdata;
575 nlong_t naklist[PGM_MAX_NAK_LIST_SZ+1];
576 char nakbuf[8192], *ptr;
577 int i, j, naks, soffset = 0;
579 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
580 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_naklist);
582 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type, tvb,
583 offset, 1, genopts.type);
585 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
586 offset+1, 1, genopts.len);
588 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
589 tvb, offset+2, 1, genopts.opx);
591 proto_tree_add_uint(opt_tree, hf_pgm_opt_nak_res, tvb,
592 offset+3, 1, optdata.res);
594 optdata.len -= sizeof(pgm_opt_nak_list_t);
595 tvb_memcpy(tvb, (guint8 *)naklist, offset+4, optdata.len);
596 naks = (optdata.len/sizeof(nlong_t));
600 * Print out 8 per line
602 for (i=0; i < naks; i++) {
603 sprintf(nakbuf+soffset, "0x%lx ",
604 (unsigned long)g_ntohl(naklist[i]));
605 soffset = strlen(nakbuf);
606 if ((++j % 8) == 0) {
608 proto_tree_add_bytes_format(opt_tree,
609 hf_pgm_opt_nak_list, tvb, offset+4, optdata.len,
610 nakbuf, "List(%d): %s", naks, nakbuf);
613 proto_tree_add_bytes_format(opt_tree,
614 hf_pgm_opt_nak_list, tvb, offset+4, optdata.len,
615 nakbuf, "List: %s", nakbuf);
623 proto_tree_add_bytes_format(opt_tree,
624 hf_pgm_opt_nak_list, tvb, offset+4, optdata.len,
625 nakbuf, "List(%d): %s", naks, nakbuf);
628 proto_tree_add_bytes_format(opt_tree,
629 hf_pgm_opt_nak_list, tvb, offset+4, optdata.len,
630 nakbuf, "List: %s", nakbuf);
636 case PGM_OPT_PGMCC_DATA:{
637 pgm_opt_pgmcc_data_t optdata;
639 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
640 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_ccdata);
642 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
643 tvb, offset, 1, genopts.type);
645 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
646 offset+1, 1, genopts.len);
648 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
649 tvb, offset+2, 1, genopts.opx);
651 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccdata_res, tvb,
652 offset+3, 1, optdata.res);
654 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccdata_tsp, tvb,
655 offset+4, 4, optdata.tsp);
657 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccdata_afi, tvb,
658 offset+8, 2, g_ntohs(optdata.acker_afi));
660 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccdata_res2, tvb,
661 offset+10, 2, g_ntohs(optdata.res2));
663 switch (g_ntohs(optdata.acker_afi)) {
666 proto_tree_add_ipv4(opt_tree, hf_pgm_opt_ccdata_acker,
667 tvb, offset+12, 4, optdata.acker);
672 * XXX - the header is variable-length,
673 * as the length of the NLA depends on
676 * However, our structure for it is
677 * fixed-length, and assumes it's a 4-byte
685 case PGM_OPT_PGMCC_FEEDBACK:{
686 pgm_opt_pgmcc_feedback_t optdata;
688 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
689 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_ccdata);
691 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
692 tvb, offset, 1, genopts.type);
694 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
695 offset+1, 1, genopts.len);
697 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
698 tvb, offset+2, 1, genopts.opx);
700 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccfeedbk_res, tvb,
701 offset+3, 1, optdata.res);
703 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccfeedbk_tsp, tvb,
704 offset+4, 4, optdata.tsp);
706 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccfeedbk_afi, tvb,
707 offset+8, 2, g_ntohs(optdata.acker_afi));
709 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccfeedbk_lossrate, tvb,
710 offset+10, 2, g_ntohs(optdata.loss_rate));
712 switch (g_ntohs(optdata.acker_afi)) {
715 proto_tree_add_ipv4(opt_tree, hf_pgm_opt_ccfeedbk_acker,
716 tvb, offset+12, 4, optdata.acker);
721 * XXX - the header is variable-length,
722 * as the length of the NLA depends on
725 * However, our structure for it is
726 * fixed-length, and assumes it's a 4-byte
735 offset += genopts.len;
736 opts.total_len -= genopts.len;
742 static const value_string type_vals[] = {
743 { PGM_SPM_PCKT, "SPM" },
744 { PGM_RDATA_PCKT, "RDATA" },
745 { PGM_ODATA_PCKT, "ODATA" },
746 { PGM_NAK_PCKT, "NAK" },
747 { PGM_NNAK_PCKT, "NNAK" },
748 { PGM_NCF_PCKT, "NCF" },
749 { PGM_ACK_PCKT, "ACK" },
752 /* Determine if there is a sub-dissector and call it. This has been */
753 /* separated into a stand alone routine to other protocol dissectors */
754 /* can call to it, ie. socks */
757 decode_pgm_ports(tvbuff_t *tvb, int offset, packet_info *pinfo,
758 proto_tree *tree, pgm_type *pgmhdr)
763 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
765 /* do lookup with the subdissector table */
766 found = dissector_try_port(subdissector_table, pgmhdr->sport,
767 next_tvb, pinfo, tree);
771 found = dissector_try_port(subdissector_table, pgmhdr->dport,
772 next_tvb, pinfo, tree);
776 /* do lookup with the heuristic subdissector table */
777 if (dissector_try_heuristic(heur_subdissector_list, next_tvb, pinfo, tree))
780 /* Oh, well, we don't know this; dissect it as data. */
781 call_dissector(data_handle,next_tvb, pinfo, tree);
785 total_size(tvbuff_t *tvb, pgm_type *hdr)
787 int bytes = sizeof(pgm_type);
788 pgm_opt_length_t opts;
792 bytes += sizeof(pgm_spm_t);
797 bytes += sizeof(pgm_data_t);
803 bytes += sizeof(pgm_nak_t);
806 bytes += sizeof(pgm_ack_t);
809 if ((hdr->opts & PGM_OPT)) {
810 tvb_memcpy(tvb, (guint8 *)&opts, bytes, sizeof(opts));
811 bytes += g_ntohs(opts.total_len);
816 * dissect_pgm - The dissector for Pragmatic General Multicast
819 dissect_pgm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
821 proto_tree *pgm_tree = NULL;
822 proto_tree *opt_tree = NULL;
823 proto_tree *type_tree = NULL;
837 if (check_col(pinfo->cinfo, COL_PROTOCOL))
838 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PGM");
840 /* Clear out the Info column. */
841 if (check_col(pinfo->cinfo, COL_INFO))
842 col_clear(pinfo->cinfo, COL_INFO);
844 tvb_memcpy(tvb, (guint8 *)&pgmhdr, offset, sizeof(pgm_type));
845 hlen = sizeof(pgm_type);
846 pgmhdr.sport = g_ntohs(pgmhdr.sport);
847 pgmhdr.dport = g_ntohs(pgmhdr.dport);
848 pgmhdr.tsdulen = g_ntohs(pgmhdr.tsdulen);
850 pktname = val_to_str(pgmhdr.type, type_vals, "Unknown (0x%02x)");
852 gsi = bytes_to_str(pgmhdr.gsi, 6);
853 switch(pgmhdr.type) {
855 plen = sizeof(pgm_spm_t);
856 tvb_memcpy(tvb, (guint8 *)&spm, sizeof(pgm_type), plen);
858 if (check_col(pinfo->cinfo, COL_INFO)) {
859 col_add_fstr(pinfo->cinfo, COL_INFO,
860 "%-5s sqn 0x%x gsi %s", pktname, spm.sqn, gsi);
866 plen = sizeof(pgm_data_t);
867 tvb_memcpy(tvb, (guint8 *)&data, sizeof(pgm_type), plen);
869 if (check_col(pinfo->cinfo, COL_INFO)) {
870 col_add_fstr(pinfo->cinfo, COL_INFO,
871 "%-5s sqn 0x%x gsi %s tsdulen %d", pktname, data.sqn, gsi,
880 plen = sizeof(pgm_nak_t);
881 tvb_memcpy(tvb, (guint8 *)&nak, sizeof(pgm_type), plen);
883 if (check_col(pinfo->cinfo, COL_INFO)) {
884 col_add_fstr(pinfo->cinfo, COL_INFO,
885 "%-5s sqn 0x%x gsi %s", pktname, nak.sqn, gsi);
889 plen = sizeof(pgm_ack_t);
890 tvb_memcpy(tvb, (guint8 *)&ack, sizeof(pgm_type), plen);
892 if (check_col(pinfo->cinfo, COL_INFO)) {
893 col_add_fstr(pinfo->cinfo, COL_INFO,
894 "%-5s sqn 0x%x gsi %s", pktname, ack.rx_max_sqn, gsi);
903 ti = proto_tree_add_protocol_format(tree, proto_pgm,
904 tvb, offset, total_size(tvb, &pgmhdr),
905 "Pragmatic General Multicast: Type %s"
906 " SrcPort %u, DstPort %u, GSI %s", pktname,
907 pgmhdr.sport, pgmhdr.dport,
908 bytes_to_str(pgmhdr.gsi, 6));
910 pgm_tree = proto_item_add_subtree(ti, ett_pgm);
911 proto_tree_add_uint(pgm_tree, hf_pgm_main_sport, tvb, offset, 2,
913 proto_tree_add_uint(pgm_tree, hf_pgm_main_dport, tvb, offset+2,
915 proto_tree_add_uint(pgm_tree, hf_pgm_main_type, tvb,
916 offset+4, 1, pgmhdr.type);
918 tf = proto_tree_add_uint_format(pgm_tree, hf_pgm_main_opts, tvb,
919 offset+5, 1, pgmhdr.opts, "Options: %s (0x%x)",
920 optsstr(pgmhdr.opts), pgmhdr.opts);
921 opt_tree = proto_item_add_subtree(tf, ett_pgm_optbits);
923 proto_tree_add_boolean(opt_tree, hf_pgm_main_opts_opt, tvb,
924 offset+5, 1, (pgmhdr.opts & PGM_OPT));
925 proto_tree_add_boolean(opt_tree, hf_pgm_main_opts_netsig, tvb,
926 offset+5, 1, (pgmhdr.opts & PGM_OPT_NETSIG));
927 proto_tree_add_boolean(opt_tree, hf_pgm_main_opts_varlen, tvb,
928 offset+5, 1, (pgmhdr.opts & PGM_OPT_VAR_PKTLEN));
929 proto_tree_add_boolean(opt_tree, hf_pgm_main_opts_parity, tvb,
930 offset+5, 1, (pgmhdr.opts & PGM_OPT_PARITY));
932 proto_tree_add_uint(pgm_tree, hf_pgm_main_cksum, tvb, offset+6,
934 proto_tree_add_bytes(pgm_tree, hf_pgm_main_gsi, tvb, offset+8,
936 proto_tree_add_uint(pgm_tree, hf_pgm_main_tsdulen, tvb,
937 offset+14, 2, pgmhdr.tsdulen);
939 offset = sizeof(pgm_type);
940 tf = proto_tree_add_text(pgm_tree, tvb, offset, plen, "%s Packet",
942 switch(pgmhdr.type) {
944 type_tree = proto_item_add_subtree(tf, ett_pgm_spm);
946 proto_tree_add_uint(type_tree, hf_pgm_spm_sqn, tvb,
948 proto_tree_add_uint(type_tree, hf_pgm_spm_trail, tvb,
949 offset+4, 4, spm.trail);
950 proto_tree_add_uint(type_tree, hf_pgm_spm_lead, tvb,
951 offset+8, 4, spm.lead);
952 proto_tree_add_uint(type_tree, hf_pgm_spm_pathafi, tvb,
953 offset+10, 2, spm.path_afi);
954 proto_tree_add_uint(type_tree, hf_pgm_spm_res, tvb,
955 offset+12, 2, spm.res);
956 switch (spm.path_afi) {
959 proto_tree_add_ipv4(type_tree, hf_pgm_spm_path,
960 tvb, offset+14, 4, spm.path);
965 * XXX - the header is variable-length,
966 * as the length of the NLA depends on
969 * However, our structure for it is
970 * fixed-length, and assumes it's a 4-byte
976 if ((pgmhdr.opts & PGM_OPT) == FALSE)
980 dissect_pgmopts(tvb, offset, type_tree, pktname);
985 case PGM_ODATA_PCKT: {
986 type_tree = proto_item_add_subtree(tf, ett_pgm_data);
988 proto_tree_add_uint(type_tree, hf_pgm_spm_sqn, tvb,
989 offset, 4, data.sqn);
990 proto_tree_add_uint(type_tree, hf_pgm_spm_trail, tvb,
991 offset+4, 4, data.trail);
993 if ((pgmhdr.opts & PGM_OPT) == FALSE)
997 dissect_pgmopts(tvb, offset, type_tree, pktname);
1006 type_tree = proto_item_add_subtree(tf, ett_pgm_nak);
1008 proto_tree_add_uint(type_tree, hf_pgm_nak_sqn, tvb,
1009 offset, 4, nak.sqn);
1010 proto_tree_add_uint(type_tree, hf_pgm_nak_srcafi, tvb,
1011 offset+4, 2, nak.src_afi);
1012 proto_tree_add_uint(type_tree, hf_pgm_nak_srcres, tvb,
1013 offset+6, 2, nak.src_res);
1015 switch (nak.src_afi) {
1018 proto_tree_add_ipv4(type_tree, hf_pgm_nak_src,
1019 tvb, offset+8, 4, nak.src);
1024 * XXX - the header is variable-length,
1025 * as the length of the NLA depends on
1028 * However, our structure for it is
1029 * fixed-length, and assumes it's a 4-byte
1035 proto_tree_add_uint(type_tree, hf_pgm_nak_grpafi, tvb,
1036 offset+12, 2, nak.grp_afi);
1037 proto_tree_add_uint(type_tree, hf_pgm_nak_grpres, tvb,
1038 offset+14, 2, nak.grp_res);
1040 switch (nak.grp_afi) {
1043 proto_tree_add_ipv4(type_tree, hf_pgm_nak_grp,
1044 tvb, offset+16, 4, nak.grp);
1049 * XXX - the header is variable-length,
1050 * as the length of the NLA depends on
1053 * However, our structure for it is
1054 * fixed-length, and assumes it's a 4-byte
1060 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1064 dissect_pgmopts(tvb, offset, type_tree, pktname);
1068 type_tree = proto_item_add_subtree(tf, ett_pgm_ack);
1070 proto_tree_add_uint(type_tree, hf_pgm_ack_sqn, tvb,
1071 offset, 4, ack.rx_max_sqn);
1072 proto_tree_add_uint(type_tree, hf_pgm_ack_bitmap, tvb,
1073 offset+4, 4, ack.bitmap);
1075 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1079 dissect_pgmopts(tvb, offset, type_tree, pktname);
1087 * Now see if there are any sub-dissectors, if so call them
1089 offset = total_size(tvb, &pgmhdr);
1090 decode_pgm_ports(tvb, offset, pinfo, tree, &pgmhdr);
1094 static const true_false_string opts_present = {
1099 /* Register all the bits needed with the filtering engine */
1101 proto_register_pgm(void)
1103 static hf_register_info hf[] = {
1104 { &hf_pgm_main_sport,
1105 { "Source Port", "pgm.hdr.sport", FT_UINT16, BASE_DEC,
1106 NULL, 0x0, "", HFILL }},
1107 { &hf_pgm_main_dport,
1108 { "Destination Port", "pgm.hdr.dport", FT_UINT16, BASE_DEC,
1109 NULL, 0x0, "", HFILL }},
1110 { &hf_pgm_main_type,
1111 { "Type", "pgm.hdr.type", FT_UINT8, BASE_HEX,
1112 VALS(type_vals), 0x0, "", HFILL }},
1113 { &hf_pgm_main_opts,
1114 { "Options", "pgm.hdr.opts", FT_UINT8, BASE_HEX,
1115 NULL, 0x0, "", HFILL }},
1116 { &hf_pgm_main_opts_opt,
1117 { "Options", "pgm.hdr.opts.opt", FT_BOOLEAN, BASE_NONE,
1118 TFS(&opts_present), PGM_OPT, "", HFILL }},
1119 { &hf_pgm_main_opts_netsig,
1120 { "Network Significant Options", "pgm.hdr.opts.netsig",
1121 FT_BOOLEAN, BASE_NONE,
1122 TFS(&opts_present), PGM_OPT_NETSIG, "", HFILL }},
1123 { &hf_pgm_main_opts_varlen,
1124 { "Variable length Parity Packet Option", "pgm.hdr.opts.varlen",
1125 FT_BOOLEAN, BASE_NONE,
1126 TFS(&opts_present), PGM_OPT_VAR_PKTLEN, "", HFILL }},
1127 { &hf_pgm_main_opts_parity,
1128 { "Parity", "pgm.hdr.opts.parity", FT_BOOLEAN, BASE_NONE,
1129 TFS(&opts_present), PGM_OPT_PARITY, "", HFILL }},
1130 { &hf_pgm_main_cksum,
1131 { "Checksum", "pgm.hdr.cksum", FT_UINT16, BASE_HEX,
1132 NULL, 0x0, "", HFILL }},
1134 { "Global Source Identifier", "pgm.hdr.gsi", FT_BYTES, BASE_HEX,
1135 NULL, 0x0, "", HFILL }},
1136 { &hf_pgm_main_tsdulen,
1137 { "Transport Service Data Unit Length", "pgm.hdr.tsdulen", FT_UINT16,
1138 BASE_DEC, NULL, 0x0, "", HFILL }},
1140 { "Sequence number", "pgm.spm.sqn", FT_UINT32, BASE_HEX,
1141 NULL, 0x0, "", HFILL }},
1142 { &hf_pgm_spm_trail,
1143 { "Trailing Edge Sequence Number", "pgm.spm.trail", FT_UINT32, BASE_HEX,
1144 NULL, 0x0, "", HFILL }},
1146 { "Leading Edge Sequence Number", "pgm.spm.lead", FT_UINT32, BASE_HEX,
1147 NULL, 0x0, "", HFILL }},
1148 { &hf_pgm_spm_pathafi,
1149 { "Path NLA AFI", "pgm.spm.pathafi", FT_UINT16, BASE_DEC,
1150 VALS(afn_vals), 0x0, "", HFILL }},
1152 { "Reserved", "pgm.spm.res", FT_UINT16, BASE_HEX,
1153 NULL, 0x0, "", HFILL }},
1155 { "Path NLA", "pgm.spm.path", FT_IPv4, BASE_NONE,
1156 NULL, 0x0, "", HFILL }},
1158 { "Data Packet Sequence Number", "pgm.data.sqn", FT_UINT32, BASE_HEX,
1159 NULL, 0x0, "", HFILL }},
1160 { &hf_pgm_data_trail,
1161 { "Trailing Edge Sequence Number", "pgm.data.trail", FT_UINT32, BASE_HEX,
1162 NULL, 0x0, "", HFILL }},
1164 { "Requested Sequence Number", "pgm.nak.sqn", FT_UINT32, BASE_HEX,
1165 NULL, 0x0, "", HFILL }},
1166 { &hf_pgm_nak_srcafi,
1167 { "Source NLA AFI", "pgm.nak.srcafi", FT_UINT16, BASE_DEC,
1168 VALS(afn_vals), 0x0, "", HFILL }},
1169 { &hf_pgm_nak_srcres,
1170 { "Reserved", "pgm.nak.srcres", FT_UINT16, BASE_HEX,
1171 NULL, 0x0, "", HFILL }},
1173 { "Source NLA", "pgm.nak.src", FT_IPv4, BASE_NONE,
1174 NULL, 0x0, "", HFILL }},
1175 { &hf_pgm_nak_grpafi,
1176 { "Multicast Group AFI", "pgm.nak.grpafi", FT_UINT16, BASE_DEC,
1177 VALS(afn_vals), 0x0, "", HFILL }},
1178 { &hf_pgm_nak_grpres,
1179 { "Reserved", "pgm.nak.grpres", FT_UINT16, BASE_HEX,
1180 NULL, 0x0, "", HFILL }},
1182 { "Multicast Group NLA", "pgm.nak.grp", FT_IPv4, BASE_NONE,
1183 NULL, 0x0, "", HFILL }},
1185 { "Maximum Received Sequence Number", "pgm.ack.maxsqn", FT_UINT32,
1186 BASE_HEX, NULL, 0x0, "", HFILL }},
1187 { &hf_pgm_ack_bitmap,
1188 { "Packet Bitmap", "pgm.ack.bitmap", FT_UINT32, BASE_HEX,
1189 NULL, 0x0, "", HFILL }},
1191 { "Type", "pgm.opts.type", FT_UINT8, BASE_HEX,
1192 VALS(opt_vals), 0x0, "", HFILL }},
1194 { "Length", "pgm.opts.len", FT_UINT8, BASE_DEC,
1195 NULL, 0x0, "", HFILL }},
1197 { "Total Length", "pgm.opts.tlen", FT_UINT16, BASE_DEC,
1198 NULL, 0x0, "", HFILL }},
1199 { &hf_pgm_genopt_type,
1200 { "Type", "pgm.genopts.type", FT_UINT8, BASE_HEX,
1201 VALS(opt_vals), 0x0, "", HFILL }},
1202 { &hf_pgm_genopt_len,
1203 { "Length", "pgm.genopts.len", FT_UINT8, BASE_DEC,
1204 NULL, 0x0, "", HFILL }},
1205 { &hf_pgm_genopt_opx,
1206 { "Option Extensibility Bits", "pgm.genopts.opx", FT_UINT8, BASE_HEX,
1207 VALS(opx_vals), 0x0, "", HFILL }},
1208 { &hf_pgm_opt_parity_prm_po,
1209 { "Parity Parameters", "pgm.opts.parity_prm.op", FT_UINT8, BASE_HEX,
1210 NULL, 0x0, "", HFILL }},
1211 { &hf_pgm_opt_parity_prm_prmtgsz,
1212 { "Transmission Group Size", "pgm.opts.parity_prm.prm_grp",
1213 FT_UINT32, BASE_HEX,
1214 NULL, 0x0, "", HFILL }},
1215 { &hf_pgm_opt_join_res,
1216 { "Reserved", "pgm.opts.join.res", FT_UINT8, BASE_HEX,
1217 NULL, 0x0, "", HFILL }},
1218 { &hf_pgm_opt_join_minjoin,
1219 { "Minimum Sequence Number", "pgm.opts.join.min_join",
1220 FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
1221 { &hf_pgm_opt_parity_grp_res,
1222 { "Reserved", "pgm.opts.parity_prm.op", FT_UINT8, BASE_HEX,
1223 NULL, 0x0, "", HFILL }},
1224 { &hf_pgm_opt_parity_grp_prmgrp,
1225 { "Transmission Group Size", "pgm.opts.parity_prm.prm_grp",
1226 FT_UINT32, BASE_HEX,
1227 NULL, 0x0, "", HFILL }},
1228 { &hf_pgm_opt_nak_res,
1229 { "Reserved", "pgm.opts.nak.op", FT_UINT8, BASE_HEX,
1230 NULL, 0x0, "", HFILL }},
1231 { &hf_pgm_opt_nak_list,
1232 { "List", "pgm.opts.nak.list", FT_BYTES, BASE_NONE,
1233 NULL, 0x0, "", HFILL }},
1234 { &hf_pgm_opt_ccdata_res,
1235 { "Reserved", "pgm.opts.ccdata.res", FT_UINT8, BASE_DEC,
1236 NULL, 0x0, "", HFILL }},
1237 { &hf_pgm_opt_ccdata_tsp,
1238 { "Time Stamp", "pgm.opts.ccdata.tstamp", FT_UINT16, BASE_HEX,
1239 NULL, 0x0, "", HFILL }},
1240 { &hf_pgm_opt_ccdata_afi,
1241 { "Acker AFI", "pgm.opts.ccdata.afi", FT_UINT16, BASE_DEC,
1242 VALS(afn_vals), 0x0, "", HFILL }},
1243 { &hf_pgm_opt_ccdata_res2,
1244 { "Reserved", "pgm.opts.ccdata.res2", FT_UINT16, BASE_DEC,
1245 NULL, 0x0, "", HFILL }},
1246 { &hf_pgm_opt_ccdata_acker,
1247 { "Acker", "pgm.opts.ccdata.acker", FT_IPv4, BASE_NONE,
1248 NULL, 0x0, "", HFILL }},
1249 { &hf_pgm_opt_ccfeedbk_res,
1250 { "Reserved", "pgm.opts.ccdata.res", FT_UINT8, BASE_DEC,
1251 NULL, 0x0, "", HFILL }},
1252 { &hf_pgm_opt_ccfeedbk_tsp,
1253 { "Time Stamp", "pgm.opts.ccdata.tstamp", FT_UINT16, BASE_HEX,
1254 NULL, 0x0, "", HFILL }},
1255 { &hf_pgm_opt_ccfeedbk_afi,
1256 { "Acker AFI", "pgm.opts.ccdata.afi", FT_UINT16, BASE_DEC,
1257 VALS(afn_vals), 0x0, "", HFILL }},
1258 { &hf_pgm_opt_ccfeedbk_lossrate,
1259 { "Loss Rate", "pgm.opts.ccdata.lossrate", FT_UINT16, BASE_HEX,
1260 NULL, 0x0, "", HFILL }},
1261 { &hf_pgm_opt_ccfeedbk_acker,
1262 { "Acker", "pgm.opts.ccdata.acker", FT_IPv4, BASE_NONE,
1263 NULL, 0x0, "", HFILL }},
1265 static gint *ett[] = {
1274 &ett_pgm_opts_parityprm,
1275 &ett_pgm_opts_paritygrp,
1276 &ett_pgm_opts_naklist,
1277 &ett_pgm_opts_ccdata,
1279 module_t *pgm_module;
1281 proto_pgm = proto_register_protocol("Pragmatic General Multicast",
1284 proto_register_field_array(proto_pgm, hf, array_length(hf));
1285 proto_register_subtree_array(ett, array_length(ett));
1287 /* subdissector code */
1288 subdissector_table = register_dissector_table("pgm.port",
1289 "PGM port", FT_UINT16, BASE_DEC);
1290 register_heur_dissector_list("pgm", &heur_subdissector_list);
1293 * Register configuration preferences for UDP encapsulation
1294 * (Note: Initially the ports are set to zero so the
1295 * dissecting of PGM encapsulated in UPD packets
1296 * is off by default)
1298 pgm_module = prefs_register_protocol(proto_pgm, proto_rereg_pgm);
1300 prefs_register_uint_preference(pgm_module, "udp.encap_ucast_port",
1301 "PGM Encap Unicast Port (standard is 3055)",
1302 "PGM Encap is PGM packets encapsulated in UDP packets"
1303 " (Note: This option is off, i.e. port is 0, by default)",
1304 10, &udp_encap_ucast_port);
1305 old_encap_ucast_port = udp_encap_ucast_port;
1307 prefs_register_uint_preference(pgm_module, "udp.encap_mcast_port",
1308 "PGM Encap Multicast Port (standard is 3056)",
1309 "PGM Encap is PGM packets encapsulated in UDP packets"
1310 " (Note: This option is off, i.e. port is 0, by default)",
1311 10, &udp_encap_mcast_port);
1313 old_encap_mcast_port = udp_encap_mcast_port;
1316 static dissector_handle_t pgm_handle;
1318 /* The registration hand-off routine */
1320 proto_reg_handoff_pgm(void)
1322 pgm_handle = create_dissector_handle(dissect_pgm, proto_pgm);
1325 * Set up PGM Encap dissecting, which is off by default
1327 dissector_add("udp.port", udp_encap_ucast_port, pgm_handle);
1328 dissector_add("udp.port", udp_encap_mcast_port, pgm_handle);
1330 dissector_add("ip.proto", IP_PROTO_PGM, pgm_handle);
1332 data_handle = find_dissector("data");
1336 proto_rereg_pgm(void)
1339 * Remove the old ones
1341 dissector_delete("udp.port", old_encap_ucast_port, pgm_handle);
1342 dissector_delete("udp.port", old_encap_mcast_port, pgm_handle);
1347 dissector_add("udp.port", udp_encap_ucast_port, pgm_handle);
1348 dissector_add("udp.port", udp_encap_mcast_port, pgm_handle);