2 * Routines for pgm packet disassembly
4 * $Id: packet-pgm.c,v 1.21 2003/09/03 20:58:09 guy 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>
40 #include <epan/resolv.h>
41 #include <epan/strutil.h>
44 #include <epan/proto.h>
47 * Flag to control whether to check the PGM checksum.
49 static gboolean pgm_check_checksum = TRUE;
51 void proto_reg_handoff_pgm(void);
52 static void proto_rereg_pgm(void);
54 typedef guint8 nchar_t;
55 typedef guint16 nshort_t;
56 typedef guint32 nlong_t;
58 /* The PGM main header */
60 nshort_t sport; /* source port */
61 nshort_t dport; /* destination port */
62 nchar_t type; /* PGM type */
63 nchar_t opts; /* options */
64 nshort_t cksum; /* checksum */
65 nchar_t gsi[6]; /* Global Source ID */
66 nshort_t tsdulen; /* TSDU length */
68 #define pgmhdr_ntoh(_p) \
69 (_p)->sport = g_ntohs((_p)->sport); \
70 (_p)->dport = g_ntohs((_p)->dport); \
71 (_p)->type = g_ntohs((_p)->type); \
72 (_p)->opts = g_ntohs((_p)->opts); \
73 (_p)->cksum = g_ntohs((_p)->cksum); \
74 (_p)->tsdulen = g_ntohs((_p)->tsdulen)
76 /* The PGM SPM header */
78 nlong_t sqn; /* SPM's sequence number */
79 nlong_t trail; /* Trailing edge sequence number */
80 nlong_t lead; /* Leading edge sequence number */
81 nshort_t path_afi; /* NLA AFI */
82 nshort_t res; /* reserved */
83 nlong_t path; /* Path NLA */
85 static const size_t PGM_SPM_SZ = sizeof(pgm_type)+sizeof(pgm_spm_t);
86 #define spm_ntoh(_p) \
87 (_p)->sqn = g_ntohl((_p)->sqn); \
88 (_p)->trail = g_ntohl((_p)->trail); \
89 (_p)->lead = g_ntohl((_p)->lead); \
90 (_p)->path_afi = g_ntohs((_p)->path_afi); \
91 (_p)->res = g_ntohs((_p)->res);
93 /* The PGM Data (ODATA/RDATA) header */
95 nlong_t sqn; /* Data Packet sequence number */
96 nlong_t trail; /* Trailing edge sequence number */
98 #define data_ntoh(_p) \
99 (_p)->sqn = g_ntohl((_p)->sqn); \
100 (_p)->trail = g_ntohl((_p)->trail)
101 static const size_t PGM_DATA_HDR_SZ = sizeof(pgm_type)+sizeof(pgm_data_t);
103 /* The PGM NAK (NAK/N-NAK/NCF) header */
105 nlong_t sqn; /* Requested sequence number */
106 nshort_t src_afi; /* NLA AFI for source (IPv4 is set to 1) */
107 nshort_t src_res; /* reserved */
108 nlong_t src; /* Source NLA */
109 nshort_t grp_afi; /* Multicast group AFI (IPv4 is set to 1) */
110 nshort_t grp_res; /* reserved */
111 nlong_t grp; /* Multicast group NLA */
113 static const size_t PGM_NAK_SZ = sizeof(pgm_type)+sizeof(pgm_nak_t);
114 #define nak_ntoh(_p) \
115 (_p)->sqn = g_ntohl((_p)->sqn); \
116 (_p)->src_afi = g_ntohs((_p)->src_afi); \
117 (_p)->src_res = g_ntohs((_p)->src_res); \
118 (_p)->grp_afi = g_ntohs((_p)->grp_afi); \
119 (_p)->grp_res = g_ntohs((_p)->grp_res)
121 /* The PGM POLL header */
123 nlong_t sqn; /* POLL sequence number */
124 nshort_t round; /* POLL Round */
125 nshort_t subtype; /* POLL subtype */
126 nshort_t path_afi; /* NLA AFI for last hop router (IPv4 is set to 1) */
127 nshort_t res; /* reserved */
128 nlong_t path; /* Last hop router NLA */
129 nlong_t backoff_ivl; /* POLL backoff interval */
130 nlong_t rand_str; /* POLL random string */
131 nlong_t matching_bmask; /* POLL matching bitmask */
133 static const size_t PGM_POLL_SZ = sizeof(pgm_type)+sizeof(pgm_poll_t);
134 #define poll_ntoh(_p) \
135 (_p)->sqn = g_ntohl((_p)->sqn); \
136 (_p)->round = g_ntohs((_p)->round); \
137 (_p)->subtype = g_ntohs((_p)->subtype); \
138 (_p)->path_afi = g_ntohs((_p)->path_afi); \
139 (_p)->res = g_ntohs((_p)->res); \
140 (_p)->backoff_ivl = g_ntohl((_p)->backoff_ivl); \
141 (_p)->rand_str = g_ntohl((_p)->rand_str); \
142 (_p)->matching_bmask = g_ntohl((_p)->matching_bmask)
144 /* The PGM POLR header */
146 nlong_t sqn; /* POLR sequence number */
147 nshort_t round; /* POLR Round */
148 nshort_t res; /* reserved */
150 static const size_t PGM_POLR_SZ = sizeof(pgm_type)+sizeof(pgm_polr_t);
151 #define polr_ntoh(_p) \
152 (_p)->sqn = g_ntohl((_p)->sqn); \
153 (_p)->round = g_ntohs((_p)->round); \
154 (_p)->res = g_ntohs((_p)->res)
156 /* The PGM ACK header (PGMCC) */
158 nlong_t rx_max_sqn; /* RX_MAX sequence number */
159 nlong_t bitmap; /* Received Packet Bitmap */
161 static const size_t PGM_ACK_SZ = sizeof(pgm_type)+sizeof(pgm_ack_t);
162 #define ack_ntoh(_p) \
163 (_p)->rx_max_sqn = g_ntohl((_p)->rx_max_sqn); \
164 (_p)->bitmap = g_ntohl((_p)->bitmap)
166 /* constants for hdr types */
167 #if defined(PGM_SPEC_01_PCKTS)
168 /* old spec-01 types */
169 #define PGM_SPM_PCKT 0x00
170 #define PGM_ODATA_PCKT 0x10
171 #define PGM_RDATA_PCKT 0x11
172 #define PGM_NAK_PCKT 0x20
173 #define PGM_NNAK_PCKT 0x21
174 #define PGM_NCF_PCKT 0x30
176 /* spec-02 types (as well as spec-04+) */
177 #define PGM_SPM_PCKT 0x00
178 #define PGM_ODATA_PCKT 0x04
179 #define PGM_RDATA_PCKT 0x05
180 #define PGM_NAK_PCKT 0x08
181 #define PGM_NNAK_PCKT 0x09
182 #define PGM_NCF_PCKT 0x0A
183 #define PGM_POLL_PCKT 0x01
184 #define PGM_POLR_PCKT 0x02
185 #define PGM_ACK_PCKT 0x0D
186 #endif /* PGM_SPEC_01_PCKTS */
188 /* port swapping on NAK and NNAKs or not (default is to swap) */
189 /* PGM_NO_PORT_SWAP */
191 /* option flags (main PGM header) */
193 #define PGM_OPT_NETSIG 0x02
194 #define PGM_OPT_VAR_PKTLEN 0x40
195 #define PGM_OPT_PARITY 0x80
198 #define PGM_OPT_LENGTH 0x00
199 #define PGM_OPT_END 0x80
200 #define PGM_OPT_FRAGMENT 0x01
201 #define PGM_OPT_NAK_LIST 0x02
202 #define PGM_OPT_JOIN 0x03
203 #define PGM_OPT_REDIRECT 0x07
204 #define PGM_OPT_SYN 0x0D
205 #define PGM_OPT_FIN 0x0E
206 #define PGM_OPT_RST 0x0F
207 #define PGM_OPT_PARITY_PRM 0x08
208 #define PGM_OPT_PARITY_GRP 0x09
209 #define PGM_OPT_CURR_TGSIZE 0x0A
210 #define PGM_OPT_PGMCC_DATA 0x12
211 #define PGM_OPT_PGMCC_FEEDBACK 0x13
212 #define PGM_OPT_NAK_BO_IVL 0x04
213 #define PGM_OPT_NAK_BO_RNG 0x05
216 #define PGM_POLL_GENERAL 0x0
217 #define PGM_POLL_DLR 0x1
219 static const nchar_t PGM_OPT_INVALID = 0x7F;
222 #define PGM_OPX_IGNORE 0x00
223 #define PGM_OPX_INVAL 0x01
224 #define PGM_OPX_DISCARD 0x10
245 } pgm_opt_nak_list_t;
248 * To squeeze the whole option into 255 bytes, we
249 * can only have 62 in the list
251 #define PGM_MAX_NAK_LIST_SZ (62)
258 nlong_t opt_join_min;
267 } pgm_opt_parity_prm_t;
269 /* OPT_PARITY_PRM P and O bits */
270 static const nchar_t PGM_OPT_PARITY_PRM_PRO = 0x2;
271 static const nchar_t PGM_OPT_PARITY_PRM_OND = 0x1;
279 } pgm_opt_parity_grp_t;
287 } pgm_opt_curr_tgsize_t;
298 } pgm_opt_pgmcc_data_t;
309 } pgm_opt_pgmcc_feedback_t;
318 } pgm_opt_nak_bo_ivl_t;
327 } pgm_opt_nak_bo_rng_t;
337 } pgm_opt_redirect_t;
346 nlong_t total_length;
347 } pgm_opt_fragment_t;
350 * Udp port for UDP encapsulation
352 #define DEFAULT_UDP_ENCAP_UCAST_PORT 3055
353 #define DEFAULT_UDP_ENCAP_MCAST_PORT 3056
355 static int udp_encap_ucast_port = 0;
356 static int udp_encap_mcast_port = 0;
357 static int old_encap_ucast_port = 0;
358 static int old_encap_mcast_port = 0;
360 static int proto_pgm = -1;
361 static int ett_pgm = -1;
362 static int ett_pgm_optbits = -1;
363 static int ett_pgm_opts = -1;
364 static int ett_pgm_spm = -1;
365 static int ett_pgm_data = -1;
366 static int ett_pgm_nak = -1;
367 static int ett_pgm_poll = -1;
368 static int ett_pgm_polr = -1;
369 static int ett_pgm_ack = -1;
370 static int ett_pgm_opts_join = -1;
371 static int ett_pgm_opts_parityprm = -1;
372 static int ett_pgm_opts_paritygrp = -1;
373 static int ett_pgm_opts_naklist = -1;
374 static int ett_pgm_opts_ccdata = -1;
375 static int ett_pgm_opts_nak_bo_ivl = -1;
376 static int ett_pgm_opts_nak_bo_rng = -1;
377 static int ett_pgm_opts_redirect = -1;
378 static int ett_pgm_opts_fragment = -1;
380 static int hf_pgm_main_sport = -1;
381 static int hf_pgm_main_dport = -1;
382 static int hf_pgm_main_type = -1;
383 static int hf_pgm_main_opts = -1;
384 static int hf_pgm_main_opts_opt = -1;
385 static int hf_pgm_main_opts_netsig = -1;
386 static int hf_pgm_main_opts_varlen = -1;
387 static int hf_pgm_main_opts_parity = -1;
388 static int hf_pgm_main_cksum = -1;
389 static int hf_pgm_main_cksum_bad = -1;
390 static int hf_pgm_main_gsi = -1;
391 static int hf_pgm_main_tsdulen = -1;
392 static int hf_pgm_spm_sqn = -1;
393 static int hf_pgm_spm_lead = -1;
394 static int hf_pgm_spm_trail = -1;
395 static int hf_pgm_spm_pathafi = -1;
396 static int hf_pgm_spm_res = -1;
397 static int hf_pgm_spm_path = -1;
398 static int hf_pgm_data_sqn = -1;
399 static int hf_pgm_data_trail = -1;
400 static int hf_pgm_nak_sqn = -1;
401 static int hf_pgm_nak_srcafi = -1;
402 static int hf_pgm_nak_srcres = -1;
403 static int hf_pgm_nak_src = -1;
404 static int hf_pgm_nak_grpafi = -1;
405 static int hf_pgm_nak_grpres = -1;
406 static int hf_pgm_nak_grp = -1;
407 static int hf_pgm_poll_sqn = -1;
408 static int hf_pgm_poll_round = -1;
409 static int hf_pgm_poll_subtype = -1;
410 static int hf_pgm_poll_pathafi = -1;
411 static int hf_pgm_poll_res = -1;
412 static int hf_pgm_poll_path = -1;
413 static int hf_pgm_poll_backoff_ivl = -1;
414 static int hf_pgm_poll_rand_str = -1;
415 static int hf_pgm_poll_matching_bmask = -1;
416 static int hf_pgm_polr_sqn = -1;
417 static int hf_pgm_polr_round = -1;
418 static int hf_pgm_polr_res = -1;
419 static int hf_pgm_ack_sqn = -1;
420 static int hf_pgm_ack_bitmap = -1;
422 static int hf_pgm_opt_type = -1;
423 static int hf_pgm_opt_len = -1;
424 static int hf_pgm_opt_tlen = -1;
426 static int hf_pgm_genopt_type = -1;
427 static int hf_pgm_genopt_len = -1;
428 static int hf_pgm_genopt_opx = -1;
430 static int hf_pgm_opt_join_res = -1;
431 static int hf_pgm_opt_join_minjoin = -1;
433 static int hf_pgm_opt_parity_prm_po = -1;
434 static int hf_pgm_opt_parity_prm_prmtgsz = -1;
436 static int hf_pgm_opt_parity_grp_res = -1;
437 static int hf_pgm_opt_parity_grp_prmgrp = -1;
439 #ifdef PGM_UNUSED_HANDLES
440 static int hf_pgm_opt_curr_tgsize_type = -1;
441 static int hf_pgm_opt_curr_tgsize_len = -1;
442 static int hf_pgm_opt_curr_tgsize_opx = -1;
443 static int hf_pgm_opt_curr_tgsize_res = -1;
444 static int hf_pgm_opt_curr_tgsize_prmatgsz = -1;
447 static int hf_pgm_opt_nak_res = -1;
448 static int hf_pgm_opt_nak_list = -1;
450 static int hf_pgm_opt_ccdata_res = -1;
451 static int hf_pgm_opt_ccdata_tsp = -1;
452 static int hf_pgm_opt_ccdata_afi = -1;
453 static int hf_pgm_opt_ccdata_res2 = -1;
454 static int hf_pgm_opt_ccdata_acker = -1;
456 static int hf_pgm_opt_ccfeedbk_res = -1;
457 static int hf_pgm_opt_ccfeedbk_tsp = -1;
458 static int hf_pgm_opt_ccfeedbk_afi = -1;
459 static int hf_pgm_opt_ccfeedbk_lossrate = -1;
460 static int hf_pgm_opt_ccfeedbk_acker = -1;
462 static int hf_pgm_opt_nak_bo_ivl_res = -1;
463 static int hf_pgm_opt_nak_bo_ivl_bo_ivl = -1;
464 static int hf_pgm_opt_nak_bo_ivl_bo_ivl_sqn = -1;
466 static int hf_pgm_opt_nak_bo_rng_res = -1;
467 static int hf_pgm_opt_nak_bo_rng_min_bo_ivl = -1;
468 static int hf_pgm_opt_nak_bo_rng_max_bo_ivl = -1;
470 static int hf_pgm_opt_redirect_res = -1;
471 static int hf_pgm_opt_redirect_afi = -1;
472 static int hf_pgm_opt_redirect_res2 = -1;
473 static int hf_pgm_opt_redirect_dlr = -1;
475 static int hf_pgm_opt_fragment_res = -1;
476 static int hf_pgm_opt_fragment_first_sqn = -1;
477 static int hf_pgm_opt_fragment_offset = -1;
478 static int hf_pgm_opt_fragment_total_length = -1;
480 static dissector_table_t subdissector_table;
481 static heur_dissector_list_t heur_subdissector_list;
482 static dissector_handle_t data_handle;
485 * As of the time this comment was typed
487 * http://search.ietf.org/internet-drafts/draft-speakman-pgm-spec-06.txt
489 * was the URL for the PGM draft.
493 optsstr(nchar_t opts)
495 static char msg[256];
502 sprintf(p, "Present");
503 p += strlen("Present");
505 if (opts & PGM_OPT_NETSIG){
513 if (opts & PGM_OPT_VAR_PKTLEN){
521 if (opts & PGM_OPT_PARITY){
530 sprintf(p, "0x%x", opts);
535 paritystr(nchar_t parity)
537 static char msg[256];
543 if (parity & PGM_OPT_PARITY_PRM_PRO){
544 sprintf(p, "Pro-active");
545 p += strlen("Pro-active");
547 if (parity & PGM_OPT_PARITY_PRM_OND){
556 sprintf(p, "0x%x", parity);
561 static const value_string opt_vals[] = {
562 { PGM_OPT_LENGTH, "Length" },
563 { PGM_OPT_END, "End" },
564 { PGM_OPT_FRAGMENT, "Fragment" },
565 { PGM_OPT_NAK_LIST, "NakList" },
566 { PGM_OPT_JOIN, "Join" },
567 { PGM_OPT_REDIRECT, "ReDirect" },
568 { PGM_OPT_SYN, "Syn" },
569 { PGM_OPT_FIN, "Fin" },
570 { PGM_OPT_RST, "Rst" },
571 { PGM_OPT_PARITY_PRM, "ParityPrm" },
572 { PGM_OPT_PARITY_GRP, "ParityGrp" },
573 { PGM_OPT_CURR_TGSIZE, "CurrTgsiz" },
574 { PGM_OPT_PGMCC_DATA, "CcData" },
575 { PGM_OPT_PGMCC_FEEDBACK, "CcFeedBack" },
576 { PGM_OPT_NAK_BO_IVL, "NakBackOffIvl" },
577 { PGM_OPT_NAK_BO_RNG, "NakBackOffRng" },
578 { PGM_OPT_FRAGMENT, "Fragment" },
582 static const value_string opx_vals[] = {
583 { PGM_OPX_IGNORE, "Ignore" },
584 { PGM_OPX_INVAL, "Inval" },
585 { PGM_OPX_DISCARD, "DisCard" },
590 dissect_pgmopts(tvbuff_t *tvb, int offset, proto_tree *tree,
594 proto_tree *opts_tree = NULL;
595 proto_tree *opt_tree = NULL;
596 pgm_opt_length_t opts;
597 pgm_opt_generic_t genopts;
598 int theend = 0, firsttime = 1;
600 tvb_memcpy(tvb, (guint8 *)&opts, offset, sizeof(opts));
601 opts.total_len = g_ntohs(opts.total_len);
603 tf = proto_tree_add_text(tree, tvb, offset,
605 "%s Options (Total Length %d)", pktname, opts.total_len);
606 opts_tree = proto_item_add_subtree(tf, ett_pgm_opts);
607 proto_tree_add_uint(opts_tree, hf_pgm_opt_type, tvb,
608 offset, 1, opts.type);
609 proto_tree_add_uint(opts_tree, hf_pgm_opt_len, tvb,
610 offset+1, 1, opts.len);
611 proto_tree_add_uint(opts_tree, hf_pgm_opt_tlen, tvb,
612 offset+2, 2, opts.total_len);
615 for (opts.total_len -= 4; opts.total_len > 0;){
616 tvb_memcpy(tvb, (guint8 *)&genopts, offset, sizeof(genopts));
617 if (genopts.type & PGM_OPT_END) {
618 genopts.type &= ~PGM_OPT_END;
621 tf = proto_tree_add_text(opts_tree, tvb, offset, genopts.len,
622 "Option: %s, Length: %u",
623 val_to_str(genopts.type, opt_vals, "Unknown (0x%02x)"),
625 if (genopts.len == 0)
628 switch(genopts.type) {
630 pgm_opt_join_t optdata;
632 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
633 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_join);
635 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
636 tvb, offset, 1, genopts.type);
638 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
639 offset+1, 1, genopts.len);
641 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx, tvb,
642 offset+2, 1, genopts.opx);
644 proto_tree_add_uint(opt_tree, hf_pgm_opt_join_res, tvb,
645 offset+3, 1, optdata.res);
647 proto_tree_add_uint(opt_tree, hf_pgm_opt_join_minjoin, tvb,
648 offset+4, 4, g_ntohl(optdata.opt_join_min));
652 case PGM_OPT_PARITY_PRM:{
653 pgm_opt_parity_prm_t optdata;
655 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
656 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_parityprm);
658 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
659 tvb, offset, 1, genopts.type);
661 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
662 offset+1, 1, genopts.len);
664 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
665 tvb, offset+2, 1, genopts.opx);
667 proto_tree_add_uint_format(opt_tree, hf_pgm_opt_parity_prm_po, tvb,
668 offset+3, 1, optdata.po, "Parity Parameters: %s (0x%x)",
669 paritystr(optdata.po), optdata.po);
671 proto_tree_add_uint(opt_tree, hf_pgm_opt_parity_prm_prmtgsz,
672 tvb, offset+4, 4, g_ntohl(optdata.prm_tgsz));
676 case PGM_OPT_PARITY_GRP:{
677 pgm_opt_parity_grp_t optdata;
679 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
680 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_paritygrp);
682 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
683 tvb, offset, 1, genopts.type);
685 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
686 offset+1, 1, genopts.len);
688 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
689 tvb, offset+2, 1, genopts.opx);
691 proto_tree_add_uint(opt_tree, hf_pgm_opt_parity_grp_res, tvb,
692 offset+3, 1, optdata.res);
694 proto_tree_add_uint(opt_tree, hf_pgm_opt_parity_grp_prmgrp,
695 tvb, offset+4, 4, g_ntohl(optdata.prm_grp));
699 case PGM_OPT_NAK_LIST:{
700 pgm_opt_nak_list_t optdata;
701 nlong_t naklist[PGM_MAX_NAK_LIST_SZ+1];
702 char nakbuf[8192], *ptr;
703 int i, j, naks, soffset = 0;
705 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
706 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_naklist);
708 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type, tvb,
709 offset, 1, genopts.type);
711 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
712 offset+1, 1, genopts.len);
714 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
715 tvb, offset+2, 1, genopts.opx);
717 proto_tree_add_uint(opt_tree, hf_pgm_opt_nak_res, tvb,
718 offset+3, 1, optdata.res);
720 optdata.len -= sizeof(pgm_opt_nak_list_t);
721 tvb_memcpy(tvb, (guint8 *)naklist, offset+4, optdata.len);
722 naks = (optdata.len/sizeof(nlong_t));
726 * Print out 8 per line
728 for (i=0; i < naks; i++) {
729 sprintf(nakbuf+soffset, "0x%lx ",
730 (unsigned long)g_ntohl(naklist[i]));
731 soffset = strlen(nakbuf);
732 if ((++j % 8) == 0) {
734 proto_tree_add_bytes_format(opt_tree,
735 hf_pgm_opt_nak_list, tvb, offset+4, optdata.len,
736 nakbuf, "List(%d): %s", naks, nakbuf);
739 proto_tree_add_bytes_format(opt_tree,
740 hf_pgm_opt_nak_list, tvb, offset+4, optdata.len,
741 nakbuf, "List: %s", nakbuf);
749 proto_tree_add_bytes_format(opt_tree,
750 hf_pgm_opt_nak_list, tvb, offset+4, optdata.len,
751 nakbuf, "List(%d): %s", naks, nakbuf);
754 proto_tree_add_bytes_format(opt_tree,
755 hf_pgm_opt_nak_list, tvb, offset+4, optdata.len,
756 nakbuf, "List: %s", nakbuf);
762 case PGM_OPT_PGMCC_DATA:{
763 pgm_opt_pgmcc_data_t optdata;
765 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
766 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_ccdata);
768 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
769 tvb, offset, 1, genopts.type);
771 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
772 offset+1, 1, genopts.len);
774 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
775 tvb, offset+2, 1, genopts.opx);
777 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccdata_res, tvb,
778 offset+3, 1, optdata.res);
780 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccdata_tsp, tvb,
781 offset+4, 4, optdata.tsp);
783 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccdata_afi, tvb,
784 offset+8, 2, g_ntohs(optdata.acker_afi));
786 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccdata_res2, tvb,
787 offset+10, 2, g_ntohs(optdata.res2));
789 switch (g_ntohs(optdata.acker_afi)) {
792 proto_tree_add_ipv4(opt_tree, hf_pgm_opt_ccdata_acker,
793 tvb, offset+12, 4, optdata.acker);
798 * XXX - the header is variable-length,
799 * as the length of the NLA depends on
802 * However, our structure for it is
803 * fixed-length, and assumes it's a 4-byte
811 case PGM_OPT_PGMCC_FEEDBACK:{
812 pgm_opt_pgmcc_feedback_t optdata;
814 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
815 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_ccdata);
817 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
818 tvb, offset, 1, genopts.type);
820 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
821 offset+1, 1, genopts.len);
823 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
824 tvb, offset+2, 1, genopts.opx);
826 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccfeedbk_res, tvb,
827 offset+3, 1, optdata.res);
829 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccfeedbk_tsp, tvb,
830 offset+4, 4, optdata.tsp);
832 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccfeedbk_afi, tvb,
833 offset+8, 2, g_ntohs(optdata.acker_afi));
835 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccfeedbk_lossrate, tvb,
836 offset+10, 2, g_ntohs(optdata.loss_rate));
838 switch (g_ntohs(optdata.acker_afi)) {
841 proto_tree_add_ipv4(opt_tree, hf_pgm_opt_ccfeedbk_acker,
842 tvb, offset+12, 4, optdata.acker);
847 * XXX - the header is variable-length,
848 * as the length of the NLA depends on
851 * However, our structure for it is
852 * fixed-length, and assumes it's a 4-byte
860 case PGM_OPT_NAK_BO_IVL:{
861 pgm_opt_nak_bo_ivl_t optdata;
863 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
864 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_nak_bo_ivl);
866 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
867 tvb, offset, 1, genopts.type);
869 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
870 offset+1, 1, genopts.len);
872 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx, tvb,
873 offset+2, 1, genopts.opx);
875 proto_tree_add_uint(opt_tree, hf_pgm_opt_nak_bo_ivl_res, tvb,
876 offset+3, 1, optdata.res);
878 proto_tree_add_uint(opt_tree, hf_pgm_opt_nak_bo_ivl_bo_ivl, tvb,
879 offset+4, 4, g_ntohl(optdata.bo_ivl));
881 proto_tree_add_uint(opt_tree, hf_pgm_opt_nak_bo_ivl_bo_ivl_sqn, tvb,
882 offset+8, 4, g_ntohl(optdata.bo_ivl_sqn));
886 case PGM_OPT_NAK_BO_RNG:{
887 pgm_opt_nak_bo_rng_t optdata;
889 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
890 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_nak_bo_rng);
892 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
893 tvb, offset, 1, genopts.type);
895 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
896 offset+1, 1, genopts.len);
898 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx, tvb,
899 offset+2, 1, genopts.opx);
901 proto_tree_add_uint(opt_tree, hf_pgm_opt_nak_bo_rng_res, tvb,
902 offset+3, 1, optdata.res);
904 proto_tree_add_uint(opt_tree, hf_pgm_opt_nak_bo_rng_min_bo_ivl, tvb,
905 offset+4, 4, g_ntohl(optdata.min_bo_ivl));
907 proto_tree_add_uint(opt_tree, hf_pgm_opt_nak_bo_rng_max_bo_ivl, tvb,
908 offset+8, 4, g_ntohl(optdata.max_bo_ivl));
912 case PGM_OPT_REDIRECT:{
913 pgm_opt_redirect_t optdata;
915 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
916 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_redirect);
918 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
919 tvb, offset, 1, genopts.type);
921 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
922 offset+1, 1, genopts.len);
924 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
925 tvb, offset+2, 1, genopts.opx);
927 proto_tree_add_uint(opt_tree, hf_pgm_opt_redirect_res, tvb,
928 offset+3, 1, optdata.res);
930 proto_tree_add_uint(opt_tree, hf_pgm_opt_redirect_afi, tvb,
931 offset+4, 2, g_ntohs(optdata.afi));
933 proto_tree_add_uint(opt_tree, hf_pgm_opt_redirect_res2, tvb,
934 offset+6, 2, g_ntohs(optdata.res2));
936 switch (g_ntohs(optdata.afi)) {
939 proto_tree_add_ipv4(opt_tree, hf_pgm_opt_redirect_dlr,
940 tvb, offset+8, 4, optdata.dlr);
945 * XXX - the header is variable-length,
946 * as the length of the NLA depends on
949 * However, our structure for it is
950 * fixed-length, and assumes it's a 4-byte
958 case PGM_OPT_FRAGMENT:{
959 pgm_opt_fragment_t optdata;
961 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
962 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_fragment);
964 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
965 tvb, offset, 1, genopts.type);
967 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
968 offset+1, 1, genopts.len);
970 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx, tvb,
971 offset+2, 1, genopts.opx);
973 proto_tree_add_uint(opt_tree, hf_pgm_opt_fragment_res, tvb,
974 offset+3, 1, optdata.res);
976 proto_tree_add_uint(opt_tree, hf_pgm_opt_fragment_first_sqn, tvb,
977 offset+4, 4, g_ntohl(optdata.first_sqn));
979 proto_tree_add_uint(opt_tree, hf_pgm_opt_fragment_offset, tvb,
980 offset+8, 4, g_ntohl(optdata.offset));
982 proto_tree_add_uint(opt_tree, hf_pgm_opt_fragment_total_length, tvb,
983 offset+12, 4, g_ntohl(optdata.total_length));
988 offset += genopts.len;
989 opts.total_len -= genopts.len;
995 static const value_string type_vals[] = {
996 { PGM_SPM_PCKT, "SPM" },
997 { PGM_RDATA_PCKT, "RDATA" },
998 { PGM_ODATA_PCKT, "ODATA" },
999 { PGM_NAK_PCKT, "NAK" },
1000 { PGM_NNAK_PCKT, "NNAK" },
1001 { PGM_NCF_PCKT, "NCF" },
1002 { PGM_POLL_PCKT, "POLL" },
1003 { PGM_POLR_PCKT, "POLR" },
1004 { PGM_ACK_PCKT, "ACK" },
1008 static const value_string poll_subtype_vals[] = {
1009 { PGM_POLL_GENERAL, "General" },
1010 { PGM_POLL_DLR, "DLR" },
1013 /* Determine if there is a sub-dissector and call it. This has been */
1014 /* separated into a stand alone routine to other protocol dissectors */
1015 /* can call to it, ie. socks */
1018 decode_pgm_ports(tvbuff_t *tvb, int offset, packet_info *pinfo,
1019 proto_tree *tree, pgm_type *pgmhdr)
1024 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
1026 /* do lookup with the subdissector table */
1027 found = dissector_try_port(subdissector_table, pgmhdr->sport,
1028 next_tvb, pinfo, tree);
1032 found = dissector_try_port(subdissector_table, pgmhdr->dport,
1033 next_tvb, pinfo, tree);
1037 /* do lookup with the heuristic subdissector table */
1038 if (dissector_try_heuristic(heur_subdissector_list, next_tvb, pinfo, tree))
1041 /* Oh, well, we don't know this; dissect it as data. */
1042 call_dissector(data_handle,next_tvb, pinfo, tree);
1046 total_size(tvbuff_t *tvb, pgm_type *hdr)
1048 int bytes = sizeof(pgm_type);
1049 pgm_opt_length_t opts;
1053 bytes += sizeof(pgm_spm_t);
1056 case PGM_RDATA_PCKT:
1057 case PGM_ODATA_PCKT:
1058 bytes += sizeof(pgm_data_t);
1064 bytes += sizeof(pgm_nak_t);
1067 bytes += sizeof(pgm_poll_t);
1070 bytes += sizeof(pgm_polr_t);
1073 bytes += sizeof(pgm_ack_t);
1076 if ((hdr->opts & PGM_OPT)) {
1077 tvb_memcpy(tvb, (guint8 *)&opts, bytes, sizeof(opts));
1078 bytes += g_ntohs(opts.total_len);
1083 * dissect_pgm - The dissector for Pragmatic General Multicast
1086 dissect_pgm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1088 proto_tree *pgm_tree = NULL;
1089 proto_tree *opt_tree = NULL;
1090 proto_tree *type_tree = NULL;
1102 const char *pktname;
1103 const char *pollstname;
1106 guint pgmlen, reportedlen;
1108 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1109 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PGM");
1111 /* Clear out the Info column. */
1112 if (check_col(pinfo->cinfo, COL_INFO))
1113 col_clear(pinfo->cinfo, COL_INFO);
1115 tvb_memcpy(tvb, (guint8 *)&pgmhdr, offset, sizeof(pgm_type));
1116 hlen = sizeof(pgm_type);
1117 pgmhdr.sport = g_ntohs(pgmhdr.sport);
1118 pgmhdr.dport = g_ntohs(pgmhdr.dport);
1119 pgmhdr.tsdulen = g_ntohs(pgmhdr.tsdulen);
1120 pgmhdr.cksum = g_ntohs(pgmhdr.cksum);
1122 pktname = val_to_str(pgmhdr.type, type_vals, "Unknown (0x%02x)");
1124 gsi = bytes_to_str(pgmhdr.gsi, 6);
1125 switch(pgmhdr.type) {
1127 plen = sizeof(pgm_spm_t);
1128 tvb_memcpy(tvb, (guint8 *)&spm, sizeof(pgm_type), plen);
1130 if (check_col(pinfo->cinfo, COL_INFO)) {
1131 col_add_fstr(pinfo->cinfo, COL_INFO,
1132 "%-5s sqn 0x%x gsi %s", pktname, spm.sqn, gsi);
1136 case PGM_RDATA_PCKT:
1137 case PGM_ODATA_PCKT:
1138 plen = sizeof(pgm_data_t);
1139 tvb_memcpy(tvb, (guint8 *)&data, sizeof(pgm_type), plen);
1141 if (check_col(pinfo->cinfo, COL_INFO)) {
1142 col_add_fstr(pinfo->cinfo, COL_INFO,
1143 "%-5s sqn 0x%x gsi %s tsdulen %d", pktname, data.sqn, gsi,
1152 plen = sizeof(pgm_nak_t);
1153 tvb_memcpy(tvb, (guint8 *)&nak, sizeof(pgm_type), plen);
1155 if (check_col(pinfo->cinfo, COL_INFO)) {
1156 col_add_fstr(pinfo->cinfo, COL_INFO,
1157 "%-5s sqn 0x%x gsi %s", pktname, nak.sqn, gsi);
1161 plen = sizeof(pgm_poll_t);
1162 tvb_memcpy(tvb, (guint8 *)&poll, sizeof(pgm_type), plen);
1164 pollstname = val_to_str(poll.subtype, poll_subtype_vals, "Unknown (0x%02x)");
1165 if (check_col(pinfo->cinfo, COL_INFO)) {
1166 col_add_fstr(pinfo->cinfo, COL_INFO,
1167 "%-5s sqn 0x%x gsi %s subtype %s", pktname, poll.sqn, gsi, pollstname);
1171 plen = sizeof(pgm_polr_t);
1172 tvb_memcpy(tvb, (guint8 *)&polr, sizeof(pgm_type), plen);
1174 if (check_col(pinfo->cinfo, COL_INFO)) {
1175 col_add_fstr(pinfo->cinfo, COL_INFO,
1176 "%-5s sqn 0x%x gsi %s", pktname, polr.sqn, gsi);
1180 plen = sizeof(pgm_ack_t);
1181 tvb_memcpy(tvb, (guint8 *)&ack, sizeof(pgm_type), plen);
1183 if (check_col(pinfo->cinfo, COL_INFO)) {
1184 col_add_fstr(pinfo->cinfo, COL_INFO,
1185 "%-5s sqn 0x%x gsi %s", pktname, ack.rx_max_sqn, gsi);
1194 ti = proto_tree_add_protocol_format(tree, proto_pgm,
1195 tvb, offset, total_size(tvb, &pgmhdr),
1196 "Pragmatic General Multicast: Type %s"
1197 " SrcPort %u, DstPort %u, GSI %s", pktname,
1198 pgmhdr.sport, pgmhdr.dport,
1199 bytes_to_str(pgmhdr.gsi, 6));
1201 pgm_tree = proto_item_add_subtree(ti, ett_pgm);
1202 proto_tree_add_uint(pgm_tree, hf_pgm_main_sport, tvb, offset, 2,
1204 proto_tree_add_uint(pgm_tree, hf_pgm_main_dport, tvb, offset+2,
1206 proto_tree_add_uint(pgm_tree, hf_pgm_main_type, tvb,
1207 offset+4, 1, pgmhdr.type);
1209 tf = proto_tree_add_uint_format(pgm_tree, hf_pgm_main_opts, tvb,
1210 offset+5, 1, pgmhdr.opts, "Options: %s (0x%x)",
1211 optsstr(pgmhdr.opts), pgmhdr.opts);
1212 opt_tree = proto_item_add_subtree(tf, ett_pgm_optbits);
1214 proto_tree_add_boolean(opt_tree, hf_pgm_main_opts_opt, tvb,
1215 offset+5, 1, (pgmhdr.opts & PGM_OPT));
1216 proto_tree_add_boolean(opt_tree, hf_pgm_main_opts_netsig, tvb,
1217 offset+5, 1, (pgmhdr.opts & PGM_OPT_NETSIG));
1218 proto_tree_add_boolean(opt_tree, hf_pgm_main_opts_varlen, tvb,
1219 offset+5, 1, (pgmhdr.opts & PGM_OPT_VAR_PKTLEN));
1220 proto_tree_add_boolean(opt_tree, hf_pgm_main_opts_parity, tvb,
1221 offset+5, 1, (pgmhdr.opts & PGM_OPT_PARITY));
1223 reportedlen = tvb_reported_length(tvb);
1224 pgmlen = tvb_length(tvb);
1225 if (pgm_check_checksum && pgmlen >= reportedlen) {
1227 guint16 computed_cksum;
1229 cksum_vec[0].ptr = tvb_get_ptr(tvb, offset, pgmlen);
1230 cksum_vec[0].len = pgmlen;
1231 computed_cksum = in_cksum(&cksum_vec[0], 1);
1232 if (computed_cksum == 0) {
1233 proto_tree_add_uint_format(pgm_tree, hf_pgm_main_cksum, tvb,
1234 offset+6, 2, pgmhdr.cksum, "Checksum: 0x%04x (correct)", pgmhdr.cksum);
1236 proto_tree_add_boolean_hidden(pgm_tree, hf_pgm_main_cksum_bad, tvb,
1238 proto_tree_add_uint_format(pgm_tree, hf_pgm_main_cksum, tvb,
1239 offset+6, 2, pgmhdr.cksum, "Checksum: 0x%04x (incorrect, should be 0x%04x)",
1240 pgmhdr.cksum, in_cksum_shouldbe(pgmhdr.cksum, computed_cksum));
1243 proto_tree_add_uint(pgm_tree, hf_pgm_main_cksum, tvb, offset+6,
1247 proto_tree_add_bytes(pgm_tree, hf_pgm_main_gsi, tvb, offset+8,
1249 proto_tree_add_uint(pgm_tree, hf_pgm_main_tsdulen, tvb,
1250 offset+14, 2, pgmhdr.tsdulen);
1252 offset = sizeof(pgm_type);
1253 tf = proto_tree_add_text(pgm_tree, tvb, offset, plen, "%s Packet",
1255 switch(pgmhdr.type) {
1257 type_tree = proto_item_add_subtree(tf, ett_pgm_spm);
1259 proto_tree_add_uint(type_tree, hf_pgm_spm_sqn, tvb,
1260 offset, 4, spm.sqn);
1261 proto_tree_add_uint(type_tree, hf_pgm_spm_trail, tvb,
1262 offset+4, 4, spm.trail);
1263 proto_tree_add_uint(type_tree, hf_pgm_spm_lead, tvb,
1264 offset+8, 4, spm.lead);
1265 proto_tree_add_uint(type_tree, hf_pgm_spm_pathafi, tvb,
1266 offset+12, 2, spm.path_afi);
1267 proto_tree_add_uint(type_tree, hf_pgm_spm_res, tvb,
1268 offset+14, 2, spm.res);
1269 switch (spm.path_afi) {
1272 proto_tree_add_ipv4(type_tree, hf_pgm_spm_path,
1273 tvb, offset+16, 4, spm.path);
1278 * XXX - the header is variable-length,
1279 * as the length of the NLA depends on
1282 * However, our structure for it is
1283 * fixed-length, and assumes it's a 4-byte
1289 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1293 dissect_pgmopts(tvb, offset, type_tree, pktname);
1297 case PGM_RDATA_PCKT:
1298 case PGM_ODATA_PCKT: {
1299 type_tree = proto_item_add_subtree(tf, ett_pgm_data);
1301 proto_tree_add_uint(type_tree, hf_pgm_spm_sqn, tvb,
1302 offset, 4, data.sqn);
1303 proto_tree_add_uint(type_tree, hf_pgm_spm_trail, tvb,
1304 offset+4, 4, data.trail);
1306 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1310 dissect_pgmopts(tvb, offset, type_tree, pktname);
1319 type_tree = proto_item_add_subtree(tf, ett_pgm_nak);
1321 proto_tree_add_uint(type_tree, hf_pgm_nak_sqn, tvb,
1322 offset, 4, nak.sqn);
1323 proto_tree_add_uint(type_tree, hf_pgm_nak_srcafi, tvb,
1324 offset+4, 2, nak.src_afi);
1325 proto_tree_add_uint(type_tree, hf_pgm_nak_srcres, tvb,
1326 offset+6, 2, nak.src_res);
1328 switch (nak.src_afi) {
1331 proto_tree_add_ipv4(type_tree, hf_pgm_nak_src,
1332 tvb, offset+8, 4, nak.src);
1337 * XXX - the header is variable-length,
1338 * as the length of the NLA depends on
1341 * However, our structure for it is
1342 * fixed-length, and assumes it's a 4-byte
1348 proto_tree_add_uint(type_tree, hf_pgm_nak_grpafi, tvb,
1349 offset+12, 2, nak.grp_afi);
1350 proto_tree_add_uint(type_tree, hf_pgm_nak_grpres, tvb,
1351 offset+14, 2, nak.grp_res);
1353 switch (nak.grp_afi) {
1356 proto_tree_add_ipv4(type_tree, hf_pgm_nak_grp,
1357 tvb, offset+16, 4, nak.grp);
1362 * XXX - the header is variable-length,
1363 * as the length of the NLA depends on
1366 * However, our structure for it is
1367 * fixed-length, and assumes it's a 4-byte
1373 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1377 dissect_pgmopts(tvb, offset, type_tree, pktname);
1381 type_tree = proto_item_add_subtree(tf, ett_pgm_poll);
1383 proto_tree_add_uint(type_tree, hf_pgm_poll_sqn, tvb,
1384 offset, 4, poll.sqn);
1385 proto_tree_add_uint(type_tree, hf_pgm_poll_round, tvb,
1386 offset+4, 2, poll.round);
1387 proto_tree_add_uint(type_tree, hf_pgm_poll_subtype, tvb,
1388 offset+6, 2, poll.subtype);
1389 proto_tree_add_uint(type_tree, hf_pgm_poll_pathafi, tvb,
1390 offset+8, 2, poll.path_afi);
1391 proto_tree_add_uint(type_tree, hf_pgm_poll_res, tvb,
1392 offset+10, 2, poll.res);
1394 switch (poll.path_afi) {
1397 proto_tree_add_ipv4(type_tree, hf_pgm_poll_path,
1398 tvb, offset+12, 4, poll.path);
1403 * XXX - the header is variable-length,
1404 * as the length of the NLA depends on
1407 * However, our structure for it is
1408 * fixed-length, and assumes it's a 4-byte
1414 proto_tree_add_uint(type_tree, hf_pgm_poll_backoff_ivl, tvb,
1415 offset+16, 4, poll.backoff_ivl);
1416 proto_tree_add_uint(type_tree, hf_pgm_poll_rand_str, tvb,
1417 offset+20, 4, poll.rand_str);
1418 proto_tree_add_uint(type_tree, hf_pgm_poll_matching_bmask, tvb,
1419 offset+24, 4, poll.matching_bmask);
1421 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1425 dissect_pgmopts(tvb, offset, type_tree, pktname);
1429 type_tree = proto_item_add_subtree(tf, ett_pgm_polr);
1431 proto_tree_add_uint(type_tree, hf_pgm_polr_sqn, tvb,
1432 offset, 4, polr.sqn);
1433 proto_tree_add_uint(type_tree, hf_pgm_polr_round, tvb,
1434 offset+4, 2, polr.round);
1435 proto_tree_add_uint(type_tree, hf_pgm_polr_res, tvb,
1436 offset+6, 2, polr.res);
1438 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1442 dissect_pgmopts(tvb, offset, type_tree, pktname);
1446 type_tree = proto_item_add_subtree(tf, ett_pgm_ack);
1448 proto_tree_add_uint(type_tree, hf_pgm_ack_sqn, tvb,
1449 offset, 4, ack.rx_max_sqn);
1450 proto_tree_add_uint(type_tree, hf_pgm_ack_bitmap, tvb,
1451 offset+4, 4, ack.bitmap);
1453 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1457 dissect_pgmopts(tvb, offset, type_tree, pktname);
1465 * Now see if there are any sub-dissectors, if so call them
1467 offset = total_size(tvb, &pgmhdr);
1468 decode_pgm_ports(tvb, offset, pinfo, tree, &pgmhdr);
1472 static const true_false_string opts_present = {
1477 /* Register all the bits needed with the filtering engine */
1479 proto_register_pgm(void)
1481 static hf_register_info hf[] = {
1482 { &hf_pgm_main_sport,
1483 { "Source Port", "pgm.hdr.sport", FT_UINT16, BASE_DEC,
1484 NULL, 0x0, "", HFILL }},
1485 { &hf_pgm_main_dport,
1486 { "Destination Port", "pgm.hdr.dport", FT_UINT16, BASE_DEC,
1487 NULL, 0x0, "", HFILL }},
1488 { &hf_pgm_main_type,
1489 { "Type", "pgm.hdr.type", FT_UINT8, BASE_HEX,
1490 VALS(type_vals), 0x0, "", HFILL }},
1491 { &hf_pgm_main_opts,
1492 { "Options", "pgm.hdr.opts", FT_UINT8, BASE_HEX,
1493 NULL, 0x0, "", HFILL }},
1494 { &hf_pgm_main_opts_opt,
1495 { "Options", "pgm.hdr.opts.opt", FT_BOOLEAN, BASE_NONE,
1496 TFS(&opts_present), PGM_OPT, "", HFILL }},
1497 { &hf_pgm_main_opts_netsig,
1498 { "Network Significant Options", "pgm.hdr.opts.netsig",
1499 FT_BOOLEAN, BASE_NONE,
1500 TFS(&opts_present), PGM_OPT_NETSIG, "", HFILL }},
1501 { &hf_pgm_main_opts_varlen,
1502 { "Variable length Parity Packet Option", "pgm.hdr.opts.varlen",
1503 FT_BOOLEAN, BASE_NONE,
1504 TFS(&opts_present), PGM_OPT_VAR_PKTLEN, "", HFILL }},
1505 { &hf_pgm_main_opts_parity,
1506 { "Parity", "pgm.hdr.opts.parity", FT_BOOLEAN, BASE_NONE,
1507 TFS(&opts_present), PGM_OPT_PARITY, "", HFILL }},
1508 { &hf_pgm_main_cksum,
1509 { "Checksum", "pgm.hdr.cksum", FT_UINT16, BASE_HEX,
1510 NULL, 0x0, "", HFILL }},
1511 { &hf_pgm_main_cksum_bad,
1512 { "Bad Checksum", "pgm.hdr.cksum_bad", FT_BOOLEAN, BASE_NONE,
1513 NULL, 0x0, "", HFILL }},
1515 { "Global Source Identifier", "pgm.hdr.gsi", FT_BYTES, BASE_HEX,
1516 NULL, 0x0, "", HFILL }},
1517 { &hf_pgm_main_tsdulen,
1518 { "Transport Service Data Unit Length", "pgm.hdr.tsdulen", FT_UINT16,
1519 BASE_DEC, NULL, 0x0, "", HFILL }},
1521 { "Sequence number", "pgm.spm.sqn", FT_UINT32, BASE_HEX,
1522 NULL, 0x0, "", HFILL }},
1523 { &hf_pgm_spm_trail,
1524 { "Trailing Edge Sequence Number", "pgm.spm.trail", FT_UINT32, BASE_HEX,
1525 NULL, 0x0, "", HFILL }},
1527 { "Leading Edge Sequence Number", "pgm.spm.lead", FT_UINT32, BASE_HEX,
1528 NULL, 0x0, "", HFILL }},
1529 { &hf_pgm_spm_pathafi,
1530 { "Path NLA AFI", "pgm.spm.pathafi", FT_UINT16, BASE_DEC,
1531 VALS(afn_vals), 0x0, "", HFILL }},
1533 { "Reserved", "pgm.spm.res", FT_UINT16, BASE_HEX,
1534 NULL, 0x0, "", HFILL }},
1536 { "Path NLA", "pgm.spm.path", FT_IPv4, BASE_NONE,
1537 NULL, 0x0, "", HFILL }},
1539 { "Data Packet Sequence Number", "pgm.data.sqn", FT_UINT32, BASE_HEX,
1540 NULL, 0x0, "", HFILL }},
1541 { &hf_pgm_data_trail,
1542 { "Trailing Edge Sequence Number", "pgm.data.trail", FT_UINT32, BASE_HEX,
1543 NULL, 0x0, "", HFILL }},
1545 { "Requested Sequence Number", "pgm.nak.sqn", FT_UINT32, BASE_HEX,
1546 NULL, 0x0, "", HFILL }},
1547 { &hf_pgm_nak_srcafi,
1548 { "Source NLA AFI", "pgm.nak.srcafi", FT_UINT16, BASE_DEC,
1549 VALS(afn_vals), 0x0, "", HFILL }},
1550 { &hf_pgm_nak_srcres,
1551 { "Reserved", "pgm.nak.srcres", FT_UINT16, BASE_HEX,
1552 NULL, 0x0, "", HFILL }},
1554 { "Source NLA", "pgm.nak.src", FT_IPv4, BASE_NONE,
1555 NULL, 0x0, "", HFILL }},
1556 { &hf_pgm_nak_grpafi,
1557 { "Multicast Group AFI", "pgm.nak.grpafi", FT_UINT16, BASE_DEC,
1558 VALS(afn_vals), 0x0, "", HFILL }},
1559 { &hf_pgm_nak_grpres,
1560 { "Reserved", "pgm.nak.grpres", FT_UINT16, BASE_HEX,
1561 NULL, 0x0, "", HFILL }},
1563 { "Multicast Group NLA", "pgm.nak.grp", FT_IPv4, BASE_NONE,
1564 NULL, 0x0, "", HFILL }},
1566 { "Sequence Number", "pgm.poll.sqn", FT_UINT32, BASE_HEX,
1567 NULL, 0x0, "", HFILL }},
1568 { &hf_pgm_poll_round,
1569 { "Round", "pgm.poll.round", FT_UINT16, BASE_DEC,
1570 NULL, 0x0, "", HFILL }},
1571 { &hf_pgm_poll_subtype,
1572 { "Subtype", "pgm.poll.subtype", FT_UINT16, BASE_HEX,
1573 VALS(poll_subtype_vals), 0x0, "", HFILL }},
1574 { &hf_pgm_poll_pathafi,
1575 { "Path NLA AFI", "pgm.poll.pathafi", FT_UINT16, BASE_DEC,
1576 VALS(afn_vals), 0x0, "", HFILL }},
1578 { "Reserved", "pgm.poll.res", FT_UINT16, BASE_HEX,
1579 NULL, 0x0, "", HFILL }},
1580 { &hf_pgm_poll_path,
1581 { "Path NLA", "pgm.poll.path", FT_IPv4, BASE_NONE,
1582 NULL, 0x0, "", HFILL }},
1583 { &hf_pgm_poll_backoff_ivl,
1584 { "Back-off Interval", "pgm.poll.backoff_ivl", FT_UINT32, BASE_DEC,
1585 NULL, 0x0, "", HFILL }},
1586 { &hf_pgm_poll_rand_str,
1587 { "Random String", "pgm.poll.rand_str", FT_UINT32, BASE_HEX,
1588 NULL, 0x0, "", HFILL }},
1589 { &hf_pgm_poll_matching_bmask,
1590 { "Matching Bitmask", "pgm.poll.matching_bmask", FT_UINT32, BASE_HEX,
1591 NULL, 0x0, "", HFILL }},
1593 { "Sequence Number", "pgm.polr.sqn", FT_UINT32, BASE_HEX,
1594 NULL, 0x0, "", HFILL }},
1595 { &hf_pgm_polr_round,
1596 { "Round", "pgm.polr.round", FT_UINT16, BASE_DEC,
1597 NULL, 0x0, "", HFILL }},
1599 { "Reserved", "pgm.polr.res", FT_UINT16, BASE_HEX,
1600 NULL, 0x0, "", HFILL }},
1602 { "Maximum Received Sequence Number", "pgm.ack.maxsqn", FT_UINT32,
1603 BASE_HEX, NULL, 0x0, "", HFILL }},
1604 { &hf_pgm_ack_bitmap,
1605 { "Packet Bitmap", "pgm.ack.bitmap", FT_UINT32, BASE_HEX,
1606 NULL, 0x0, "", HFILL }},
1608 { "Type", "pgm.opts.type", FT_UINT8, BASE_HEX,
1609 VALS(opt_vals), 0x0, "", HFILL }},
1611 { "Length", "pgm.opts.len", FT_UINT8, BASE_DEC,
1612 NULL, 0x0, "", HFILL }},
1614 { "Total Length", "pgm.opts.tlen", FT_UINT16, BASE_DEC,
1615 NULL, 0x0, "", HFILL }},
1616 { &hf_pgm_genopt_type,
1617 { "Type", "pgm.genopts.type", FT_UINT8, BASE_HEX,
1618 VALS(opt_vals), 0x0, "", HFILL }},
1619 { &hf_pgm_genopt_len,
1620 { "Length", "pgm.genopts.len", FT_UINT8, BASE_DEC,
1621 NULL, 0x0, "", HFILL }},
1622 { &hf_pgm_genopt_opx,
1623 { "Option Extensibility Bits", "pgm.genopts.opx", FT_UINT8, BASE_HEX,
1624 VALS(opx_vals), 0x0, "", HFILL }},
1625 { &hf_pgm_opt_parity_prm_po,
1626 { "Parity Parameters", "pgm.opts.parity_prm.op", FT_UINT8, BASE_HEX,
1627 NULL, 0x0, "", HFILL }},
1628 { &hf_pgm_opt_parity_prm_prmtgsz,
1629 { "Transmission Group Size", "pgm.opts.parity_prm.prm_grp",
1630 FT_UINT32, BASE_HEX,
1631 NULL, 0x0, "", HFILL }},
1632 { &hf_pgm_opt_join_res,
1633 { "Reserved", "pgm.opts.join.res", FT_UINT8, BASE_HEX,
1634 NULL, 0x0, "", HFILL }},
1635 { &hf_pgm_opt_join_minjoin,
1636 { "Minimum Sequence Number", "pgm.opts.join.min_join",
1637 FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
1638 { &hf_pgm_opt_parity_grp_res,
1639 { "Reserved", "pgm.opts.parity_prm.op", FT_UINT8, BASE_HEX,
1640 NULL, 0x0, "", HFILL }},
1641 { &hf_pgm_opt_parity_grp_prmgrp,
1642 { "Transmission Group Size", "pgm.opts.parity_prm.prm_grp",
1643 FT_UINT32, BASE_HEX,
1644 NULL, 0x0, "", HFILL }},
1645 { &hf_pgm_opt_nak_res,
1646 { "Reserved", "pgm.opts.nak.op", FT_UINT8, BASE_HEX,
1647 NULL, 0x0, "", HFILL }},
1648 { &hf_pgm_opt_nak_list,
1649 { "List", "pgm.opts.nak.list", FT_BYTES, BASE_NONE,
1650 NULL, 0x0, "", HFILL }},
1651 { &hf_pgm_opt_ccdata_res,
1652 { "Reserved", "pgm.opts.ccdata.res", FT_UINT8, BASE_DEC,
1653 NULL, 0x0, "", HFILL }},
1654 { &hf_pgm_opt_ccdata_tsp,
1655 { "Time Stamp", "pgm.opts.ccdata.tstamp", FT_UINT16, BASE_HEX,
1656 NULL, 0x0, "", HFILL }},
1657 { &hf_pgm_opt_ccdata_afi,
1658 { "Acker AFI", "pgm.opts.ccdata.afi", FT_UINT16, BASE_DEC,
1659 VALS(afn_vals), 0x0, "", HFILL }},
1660 { &hf_pgm_opt_ccdata_res2,
1661 { "Reserved", "pgm.opts.ccdata.res2", FT_UINT16, BASE_DEC,
1662 NULL, 0x0, "", HFILL }},
1663 { &hf_pgm_opt_ccdata_acker,
1664 { "Acker", "pgm.opts.ccdata.acker", FT_IPv4, BASE_NONE,
1665 NULL, 0x0, "", HFILL }},
1666 { &hf_pgm_opt_ccfeedbk_res,
1667 { "Reserved", "pgm.opts.ccdata.res", FT_UINT8, BASE_DEC,
1668 NULL, 0x0, "", HFILL }},
1669 { &hf_pgm_opt_ccfeedbk_tsp,
1670 { "Time Stamp", "pgm.opts.ccdata.tstamp", FT_UINT16, BASE_HEX,
1671 NULL, 0x0, "", HFILL }},
1672 { &hf_pgm_opt_ccfeedbk_afi,
1673 { "Acker AFI", "pgm.opts.ccdata.afi", FT_UINT16, BASE_DEC,
1674 VALS(afn_vals), 0x0, "", HFILL }},
1675 { &hf_pgm_opt_ccfeedbk_lossrate,
1676 { "Loss Rate", "pgm.opts.ccdata.lossrate", FT_UINT16, BASE_HEX,
1677 NULL, 0x0, "", HFILL }},
1678 { &hf_pgm_opt_ccfeedbk_acker,
1679 { "Acker", "pgm.opts.ccdata.acker", FT_IPv4, BASE_NONE,
1680 NULL, 0x0, "", HFILL }},
1681 { &hf_pgm_opt_nak_bo_ivl_res,
1682 { "Reserved", "pgm.opts.nak_bo_ivl.res", FT_UINT8, BASE_HEX,
1683 NULL, 0x0, "", HFILL }},
1684 { &hf_pgm_opt_nak_bo_ivl_bo_ivl,
1685 { "Back-off Interval", "pgm.opts.nak_bo_ivl.bo_ivl", FT_UINT32, BASE_DEC,
1686 NULL, 0x0, "", HFILL }},
1687 { &hf_pgm_opt_nak_bo_ivl_bo_ivl_sqn,
1688 { "Back-off Interval Sequence Number", "pgm.opts.nak_bo_ivl.bo_ivl_sqn", FT_UINT32, BASE_HEX,
1689 NULL, 0x0, "", HFILL }},
1690 { &hf_pgm_opt_nak_bo_rng_res,
1691 { "Reserved", "pgm.opts.nak_bo_rng.res", FT_UINT8, BASE_HEX,
1692 NULL, 0x0, "", HFILL }},
1693 { &hf_pgm_opt_nak_bo_rng_min_bo_ivl,
1694 { "Min Back-off Interval", "pgm.opts.nak_bo_rng.min_bo_ivl", FT_UINT32, BASE_DEC,
1695 NULL, 0x0, "", HFILL }},
1696 { &hf_pgm_opt_nak_bo_rng_max_bo_ivl,
1697 { "Max Back-off Interval", "pgm.opts.nak_bo_rng.max_bo_ivl", FT_UINT32, BASE_DEC,
1698 NULL, 0x0, "", HFILL }},
1699 { &hf_pgm_opt_redirect_res,
1700 { "Reserved", "pgm.opts.redirect.res", FT_UINT8, BASE_DEC,
1701 NULL, 0x0, "", HFILL }},
1702 { &hf_pgm_opt_redirect_afi,
1703 { "DLR AFI", "pgm.opts.redirect.afi", FT_UINT16, BASE_DEC,
1704 VALS(afn_vals), 0x0, "", HFILL }},
1705 { &hf_pgm_opt_redirect_res2,
1706 { "Reserved", "pgm.opts.redirect.res2", FT_UINT16, BASE_HEX,
1707 NULL, 0x0, "", HFILL }},
1708 { &hf_pgm_opt_redirect_dlr,
1709 { "DLR", "pgm.opts.redirect.dlr", FT_IPv4, BASE_NONE,
1710 NULL, 0x0, "", HFILL }},
1711 { &hf_pgm_opt_fragment_res,
1712 { "Reserved", "pgm.opts.fragment.res", FT_UINT8, BASE_HEX,
1713 NULL, 0x0, "", HFILL }},
1714 { &hf_pgm_opt_fragment_first_sqn,
1715 { "First Sequence Number", "pgm.opts.fragment.first_sqn", FT_UINT32, BASE_HEX,
1716 NULL, 0x0, "", HFILL }},
1717 { &hf_pgm_opt_fragment_total_length,
1718 { "Total Length", "pgm.opts.fragment.total_length", FT_UINT32, BASE_DEC,
1719 NULL, 0x0, "", HFILL }},
1721 static gint *ett[] = {
1732 &ett_pgm_opts_parityprm,
1733 &ett_pgm_opts_paritygrp,
1734 &ett_pgm_opts_naklist,
1735 &ett_pgm_opts_ccdata,
1736 &ett_pgm_opts_nak_bo_ivl,
1737 &ett_pgm_opts_nak_bo_rng,
1738 &ett_pgm_opts_redirect,
1739 &ett_pgm_opts_fragment,
1741 module_t *pgm_module;
1743 proto_pgm = proto_register_protocol("Pragmatic General Multicast",
1746 proto_register_field_array(proto_pgm, hf, array_length(hf));
1747 proto_register_subtree_array(ett, array_length(ett));
1749 /* subdissector code */
1750 subdissector_table = register_dissector_table("pgm.port",
1751 "PGM port", FT_UINT16, BASE_DEC);
1752 register_heur_dissector_list("pgm", &heur_subdissector_list);
1755 * Register configuration preferences for UDP encapsulation
1756 * (Note: Initially the ports are set to zero so the
1757 * dissecting of PGM encapsulated in UPD packets
1758 * is off by default)
1760 pgm_module = prefs_register_protocol(proto_pgm, proto_rereg_pgm);
1762 prefs_register_bool_preference(pgm_module, "check_checksum",
1763 "Check the validity of the PGM checksum when possible",
1764 "Whether to check the validity of the PGM checksum",
1765 &pgm_check_checksum);
1767 prefs_register_uint_preference(pgm_module, "udp.encap_ucast_port",
1768 "PGM Encap Unicast Port (standard is 3055)",
1769 "PGM Encap is PGM packets encapsulated in UDP packets"
1770 " (Note: This option is off, i.e. port is 0, by default)",
1771 10, &udp_encap_ucast_port);
1772 old_encap_ucast_port = udp_encap_ucast_port;
1774 prefs_register_uint_preference(pgm_module, "udp.encap_mcast_port",
1775 "PGM Encap Multicast Port (standard is 3056)",
1776 "PGM Encap is PGM packets encapsulated in UDP packets"
1777 " (Note: This option is off, i.e. port is 0, by default)",
1778 10, &udp_encap_mcast_port);
1780 old_encap_mcast_port = udp_encap_mcast_port;
1783 static dissector_handle_t pgm_handle;
1785 /* The registration hand-off routine */
1787 proto_reg_handoff_pgm(void)
1789 pgm_handle = create_dissector_handle(dissect_pgm, proto_pgm);
1792 * Set up PGM Encap dissecting, which is off by default
1794 dissector_add("udp.port", udp_encap_ucast_port, pgm_handle);
1795 dissector_add("udp.port", udp_encap_mcast_port, pgm_handle);
1797 dissector_add("ip.proto", IP_PROTO_PGM, pgm_handle);
1799 data_handle = find_dissector("data");
1803 proto_rereg_pgm(void)
1806 * Remove the old ones
1808 dissector_delete("udp.port", old_encap_ucast_port, pgm_handle);
1809 dissector_delete("udp.port", old_encap_mcast_port, pgm_handle);
1814 dissector_add("udp.port", udp_encap_ucast_port, pgm_handle);
1815 dissector_add("udp.port", udp_encap_mcast_port, pgm_handle);