2 * Routines for pgm packet disassembly
4 * $Id: packet-pgm.c,v 1.20 2003/03/12 04:04:13 gerald 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>
42 #include <epan/conversation.h>
45 #include <epan/proto.h>
48 * Flag to control whether to check the PGM checksum.
50 static gboolean pgm_check_checksum = TRUE;
52 void proto_reg_handoff_pgm(void);
53 static void proto_rereg_pgm(void);
55 typedef guint8 nchar_t;
56 typedef guint16 nshort_t;
57 typedef guint32 nlong_t;
59 /* The PGM main header */
61 nshort_t sport; /* source port */
62 nshort_t dport; /* destination port */
63 nchar_t type; /* PGM type */
64 nchar_t opts; /* options */
65 nshort_t cksum; /* checksum */
66 nchar_t gsi[6]; /* Global Source ID */
67 nshort_t tsdulen; /* TSDU length */
69 #define pgmhdr_ntoh(_p) \
70 (_p)->sport = g_ntohs((_p)->sport); \
71 (_p)->dport = g_ntohs((_p)->dport); \
72 (_p)->type = g_ntohs((_p)->type); \
73 (_p)->opts = g_ntohs((_p)->opts); \
74 (_p)->cksum = g_ntohs((_p)->cksum); \
75 (_p)->tsdulen = g_ntohs((_p)->tsdulen)
77 /* The PGM SPM header */
79 nlong_t sqn; /* SPM's sequence number */
80 nlong_t trail; /* Trailing edge sequence number */
81 nlong_t lead; /* Leading edge sequence number */
82 nshort_t path_afi; /* NLA AFI */
83 nshort_t res; /* reserved */
84 nlong_t path; /* Path NLA */
86 static const size_t PGM_SPM_SZ = sizeof(pgm_type)+sizeof(pgm_spm_t);
87 #define spm_ntoh(_p) \
88 (_p)->sqn = g_ntohl((_p)->sqn); \
89 (_p)->trail = g_ntohl((_p)->trail); \
90 (_p)->lead = g_ntohl((_p)->lead); \
91 (_p)->path_afi = g_ntohs((_p)->path_afi); \
92 (_p)->res = g_ntohs((_p)->res);
94 /* The PGM Data (ODATA/RDATA) header */
96 nlong_t sqn; /* Data Packet sequence number */
97 nlong_t trail; /* Trailing edge sequence number */
99 #define data_ntoh(_p) \
100 (_p)->sqn = g_ntohl((_p)->sqn); \
101 (_p)->trail = g_ntohl((_p)->trail)
102 static const size_t PGM_DATA_HDR_SZ = sizeof(pgm_type)+sizeof(pgm_data_t);
104 /* The PGM NAK (NAK/N-NAK/NCF) header */
106 nlong_t sqn; /* Requested sequence number */
107 nshort_t src_afi; /* NLA AFI for source (IPv4 is set to 1) */
108 nshort_t src_res; /* reserved */
109 nlong_t src; /* Source NLA */
110 nshort_t grp_afi; /* Multicast group AFI (IPv4 is set to 1) */
111 nshort_t grp_res; /* reserved */
112 nlong_t grp; /* Multicast group NLA */
114 static const size_t PGM_NAK_SZ = sizeof(pgm_type)+sizeof(pgm_nak_t);
115 #define nak_ntoh(_p) \
116 (_p)->sqn = g_ntohl((_p)->sqn); \
117 (_p)->src_afi = g_ntohs((_p)->src_afi); \
118 (_p)->src_res = g_ntohs((_p)->src_res); \
119 (_p)->grp_afi = g_ntohs((_p)->grp_afi); \
120 (_p)->grp_res = g_ntohs((_p)->grp_res)
122 /* The PGM POLL header */
124 nlong_t sqn; /* POLL sequence number */
125 nshort_t round; /* POLL Round */
126 nshort_t subtype; /* POLL subtype */
127 nshort_t path_afi; /* NLA AFI for last hop router (IPv4 is set to 1) */
128 nshort_t res; /* reserved */
129 nlong_t path; /* Last hop router NLA */
130 nlong_t backoff_ivl; /* POLL backoff interval */
131 nlong_t rand_str; /* POLL random string */
132 nlong_t matching_bmask; /* POLL matching bitmask */
134 static const size_t PGM_POLL_SZ = sizeof(pgm_type)+sizeof(pgm_poll_t);
135 #define poll_ntoh(_p) \
136 (_p)->sqn = g_ntohl((_p)->sqn); \
137 (_p)->round = g_ntohs((_p)->round); \
138 (_p)->subtype = g_ntohs((_p)->subtype); \
139 (_p)->path_afi = g_ntohs((_p)->path_afi); \
140 (_p)->res = g_ntohs((_p)->res); \
141 (_p)->backoff_ivl = g_ntohl((_p)->backoff_ivl); \
142 (_p)->rand_str = g_ntohl((_p)->rand_str); \
143 (_p)->matching_bmask = g_ntohl((_p)->matching_bmask)
145 /* The PGM POLR header */
147 nlong_t sqn; /* POLR sequence number */
148 nshort_t round; /* POLR Round */
149 nshort_t res; /* reserved */
151 static const size_t PGM_POLR_SZ = sizeof(pgm_type)+sizeof(pgm_polr_t);
152 #define polr_ntoh(_p) \
153 (_p)->sqn = g_ntohl((_p)->sqn); \
154 (_p)->round = g_ntohs((_p)->round); \
155 (_p)->res = g_ntohs((_p)->res)
157 /* The PGM ACK header (PGMCC) */
159 nlong_t rx_max_sqn; /* RX_MAX sequence number */
160 nlong_t bitmap; /* Received Packet Bitmap */
162 static const size_t PGM_ACK_SZ = sizeof(pgm_type)+sizeof(pgm_ack_t);
163 #define ack_ntoh(_p) \
164 (_p)->rx_max_sqn = g_ntohl((_p)->rx_max_sqn); \
165 (_p)->bitmap = g_ntohl((_p)->bitmap)
167 /* constants for hdr types */
168 #if defined(PGM_SPEC_01_PCKTS)
169 /* old spec-01 types */
170 #define PGM_SPM_PCKT 0x00
171 #define PGM_ODATA_PCKT 0x10
172 #define PGM_RDATA_PCKT 0x11
173 #define PGM_NAK_PCKT 0x20
174 #define PGM_NNAK_PCKT 0x21
175 #define PGM_NCF_PCKT 0x30
177 /* spec-02 types (as well as spec-04+) */
178 #define PGM_SPM_PCKT 0x00
179 #define PGM_ODATA_PCKT 0x04
180 #define PGM_RDATA_PCKT 0x05
181 #define PGM_NAK_PCKT 0x08
182 #define PGM_NNAK_PCKT 0x09
183 #define PGM_NCF_PCKT 0x0A
184 #define PGM_POLL_PCKT 0x01
185 #define PGM_POLR_PCKT 0x02
186 #define PGM_ACK_PCKT 0x0D
187 #endif /* PGM_SPEC_01_PCKTS */
189 /* port swapping on NAK and NNAKs or not (default is to swap) */
190 /* PGM_NO_PORT_SWAP */
192 /* option flags (main PGM header) */
194 #define PGM_OPT_NETSIG 0x02
195 #define PGM_OPT_VAR_PKTLEN 0x40
196 #define PGM_OPT_PARITY 0x80
199 #define PGM_OPT_LENGTH 0x00
200 #define PGM_OPT_END 0x80
201 #define PGM_OPT_FRAGMENT 0x01
202 #define PGM_OPT_NAK_LIST 0x02
203 #define PGM_OPT_JOIN 0x03
204 #define PGM_OPT_REDIRECT 0x07
205 #define PGM_OPT_SYN 0x0D
206 #define PGM_OPT_FIN 0x0E
207 #define PGM_OPT_RST 0x0F
208 #define PGM_OPT_PARITY_PRM 0x08
209 #define PGM_OPT_PARITY_GRP 0x09
210 #define PGM_OPT_CURR_TGSIZE 0x0A
211 #define PGM_OPT_PGMCC_DATA 0x12
212 #define PGM_OPT_PGMCC_FEEDBACK 0x13
213 #define PGM_OPT_NAK_BO_IVL 0x04
214 #define PGM_OPT_NAK_BO_RNG 0x05
217 #define PGM_POLL_GENERAL 0x0
218 #define PGM_POLL_DLR 0x1
220 static const nchar_t PGM_OPT_INVALID = 0x7F;
223 #define PGM_OPX_IGNORE 0x00
224 #define PGM_OPX_INVAL 0x01
225 #define PGM_OPX_DISCARD 0x10
246 } pgm_opt_nak_list_t;
249 * To squeeze the whole option into 255 bytes, we
250 * can only have 62 in the list
252 #define PGM_MAX_NAK_LIST_SZ (62)
259 nlong_t opt_join_min;
268 } pgm_opt_parity_prm_t;
270 /* OPT_PARITY_PRM P and O bits */
271 static const nchar_t PGM_OPT_PARITY_PRM_PRO = 0x2;
272 static const nchar_t PGM_OPT_PARITY_PRM_OND = 0x1;
280 } pgm_opt_parity_grp_t;
288 } pgm_opt_curr_tgsize_t;
299 } pgm_opt_pgmcc_data_t;
310 } pgm_opt_pgmcc_feedback_t;
319 } pgm_opt_nak_bo_ivl_t;
328 } pgm_opt_nak_bo_rng_t;
338 } pgm_opt_redirect_t;
347 nlong_t total_length;
348 } pgm_opt_fragment_t;
351 * Udp port for UDP encapsulation
353 #define DEFAULT_UDP_ENCAP_UCAST_PORT 3055
354 #define DEFAULT_UDP_ENCAP_MCAST_PORT 3056
356 static int udp_encap_ucast_port = 0;
357 static int udp_encap_mcast_port = 0;
358 static int old_encap_ucast_port = 0;
359 static int old_encap_mcast_port = 0;
361 static int proto_pgm = -1;
362 static int ett_pgm = -1;
363 static int ett_pgm_optbits = -1;
364 static int ett_pgm_opts = -1;
365 static int ett_pgm_spm = -1;
366 static int ett_pgm_data = -1;
367 static int ett_pgm_nak = -1;
368 static int ett_pgm_poll = -1;
369 static int ett_pgm_polr = -1;
370 static int ett_pgm_ack = -1;
371 static int ett_pgm_opts_join = -1;
372 static int ett_pgm_opts_parityprm = -1;
373 static int ett_pgm_opts_paritygrp = -1;
374 static int ett_pgm_opts_naklist = -1;
375 static int ett_pgm_opts_ccdata = -1;
376 static int ett_pgm_opts_nak_bo_ivl = -1;
377 static int ett_pgm_opts_nak_bo_rng = -1;
378 static int ett_pgm_opts_redirect = -1;
379 static int ett_pgm_opts_fragment = -1;
381 static int hf_pgm_main_sport = -1;
382 static int hf_pgm_main_dport = -1;
383 static int hf_pgm_main_type = -1;
384 static int hf_pgm_main_opts = -1;
385 static int hf_pgm_main_opts_opt = -1;
386 static int hf_pgm_main_opts_netsig = -1;
387 static int hf_pgm_main_opts_varlen = -1;
388 static int hf_pgm_main_opts_parity = -1;
389 static int hf_pgm_main_cksum = -1;
390 static int hf_pgm_main_cksum_bad = -1;
391 static int hf_pgm_main_gsi = -1;
392 static int hf_pgm_main_tsdulen = -1;
393 static int hf_pgm_spm_sqn = -1;
394 static int hf_pgm_spm_lead = -1;
395 static int hf_pgm_spm_trail = -1;
396 static int hf_pgm_spm_pathafi = -1;
397 static int hf_pgm_spm_res = -1;
398 static int hf_pgm_spm_path = -1;
399 static int hf_pgm_data_sqn = -1;
400 static int hf_pgm_data_trail = -1;
401 static int hf_pgm_nak_sqn = -1;
402 static int hf_pgm_nak_srcafi = -1;
403 static int hf_pgm_nak_srcres = -1;
404 static int hf_pgm_nak_src = -1;
405 static int hf_pgm_nak_grpafi = -1;
406 static int hf_pgm_nak_grpres = -1;
407 static int hf_pgm_nak_grp = -1;
408 static int hf_pgm_poll_sqn = -1;
409 static int hf_pgm_poll_round = -1;
410 static int hf_pgm_poll_subtype = -1;
411 static int hf_pgm_poll_pathafi = -1;
412 static int hf_pgm_poll_res = -1;
413 static int hf_pgm_poll_path = -1;
414 static int hf_pgm_poll_backoff_ivl = -1;
415 static int hf_pgm_poll_rand_str = -1;
416 static int hf_pgm_poll_matching_bmask = -1;
417 static int hf_pgm_polr_sqn = -1;
418 static int hf_pgm_polr_round = -1;
419 static int hf_pgm_polr_res = -1;
420 static int hf_pgm_ack_sqn = -1;
421 static int hf_pgm_ack_bitmap = -1;
423 static int hf_pgm_opt_type = -1;
424 static int hf_pgm_opt_len = -1;
425 static int hf_pgm_opt_tlen = -1;
427 static int hf_pgm_genopt_type = -1;
428 static int hf_pgm_genopt_len = -1;
429 static int hf_pgm_genopt_opx = -1;
431 static int hf_pgm_opt_join_res = -1;
432 static int hf_pgm_opt_join_minjoin = -1;
434 static int hf_pgm_opt_parity_prm_po = -1;
435 static int hf_pgm_opt_parity_prm_prmtgsz = -1;
437 static int hf_pgm_opt_parity_grp_res = -1;
438 static int hf_pgm_opt_parity_grp_prmgrp = -1;
440 #ifdef PGM_UNUSED_HANDLES
441 static int hf_pgm_opt_curr_tgsize_type = -1;
442 static int hf_pgm_opt_curr_tgsize_len = -1;
443 static int hf_pgm_opt_curr_tgsize_opx = -1;
444 static int hf_pgm_opt_curr_tgsize_res = -1;
445 static int hf_pgm_opt_curr_tgsize_prmatgsz = -1;
448 static int hf_pgm_opt_nak_res = -1;
449 static int hf_pgm_opt_nak_list = -1;
451 static int hf_pgm_opt_ccdata_res = -1;
452 static int hf_pgm_opt_ccdata_tsp = -1;
453 static int hf_pgm_opt_ccdata_afi = -1;
454 static int hf_pgm_opt_ccdata_res2 = -1;
455 static int hf_pgm_opt_ccdata_acker = -1;
457 static int hf_pgm_opt_ccfeedbk_res = -1;
458 static int hf_pgm_opt_ccfeedbk_tsp = -1;
459 static int hf_pgm_opt_ccfeedbk_afi = -1;
460 static int hf_pgm_opt_ccfeedbk_lossrate = -1;
461 static int hf_pgm_opt_ccfeedbk_acker = -1;
463 static int hf_pgm_opt_nak_bo_ivl_res = -1;
464 static int hf_pgm_opt_nak_bo_ivl_bo_ivl = -1;
465 static int hf_pgm_opt_nak_bo_ivl_bo_ivl_sqn = -1;
467 static int hf_pgm_opt_nak_bo_rng_res = -1;
468 static int hf_pgm_opt_nak_bo_rng_min_bo_ivl = -1;
469 static int hf_pgm_opt_nak_bo_rng_max_bo_ivl = -1;
471 static int hf_pgm_opt_redirect_res = -1;
472 static int hf_pgm_opt_redirect_afi = -1;
473 static int hf_pgm_opt_redirect_res2 = -1;
474 static int hf_pgm_opt_redirect_dlr = -1;
476 static int hf_pgm_opt_fragment_res = -1;
477 static int hf_pgm_opt_fragment_first_sqn = -1;
478 static int hf_pgm_opt_fragment_offset = -1;
479 static int hf_pgm_opt_fragment_total_length = -1;
481 static dissector_table_t subdissector_table;
482 static heur_dissector_list_t heur_subdissector_list;
483 static dissector_handle_t data_handle;
486 * As of the time this comment was typed
488 * http://search.ietf.org/internet-drafts/draft-speakman-pgm-spec-06.txt
490 * was the URL for the PGM draft.
494 optsstr(nchar_t opts)
496 static char msg[256];
503 sprintf(p, "Present");
504 p += strlen("Present");
506 if (opts & PGM_OPT_NETSIG){
514 if (opts & PGM_OPT_VAR_PKTLEN){
522 if (opts & PGM_OPT_PARITY){
531 sprintf(p, "0x%x", opts);
536 paritystr(nchar_t parity)
538 static char msg[256];
544 if (parity & PGM_OPT_PARITY_PRM_PRO){
545 sprintf(p, "Pro-active");
546 p += strlen("Pro-active");
548 if (parity & PGM_OPT_PARITY_PRM_OND){
557 sprintf(p, "0x%x", parity);
562 static const value_string opt_vals[] = {
563 { PGM_OPT_LENGTH, "Length" },
564 { PGM_OPT_END, "End" },
565 { PGM_OPT_FRAGMENT, "Fragment" },
566 { PGM_OPT_NAK_LIST, "NakList" },
567 { PGM_OPT_JOIN, "Join" },
568 { PGM_OPT_REDIRECT, "ReDirect" },
569 { PGM_OPT_SYN, "Syn" },
570 { PGM_OPT_FIN, "Fin" },
571 { PGM_OPT_RST, "Rst" },
572 { PGM_OPT_PARITY_PRM, "ParityPrm" },
573 { PGM_OPT_PARITY_GRP, "ParityGrp" },
574 { PGM_OPT_CURR_TGSIZE, "CurrTgsiz" },
575 { PGM_OPT_PGMCC_DATA, "CcData" },
576 { PGM_OPT_PGMCC_FEEDBACK, "CcFeedBack" },
577 { PGM_OPT_NAK_BO_IVL, "NakBackOffIvl" },
578 { PGM_OPT_NAK_BO_RNG, "NakBackOffRng" },
579 { PGM_OPT_FRAGMENT, "Fragment" },
583 static const value_string opx_vals[] = {
584 { PGM_OPX_IGNORE, "Ignore" },
585 { PGM_OPX_INVAL, "Inval" },
586 { PGM_OPX_DISCARD, "DisCard" },
591 dissect_pgmopts(tvbuff_t *tvb, int offset, proto_tree *tree,
595 proto_tree *opts_tree = NULL;
596 proto_tree *opt_tree = NULL;
597 pgm_opt_length_t opts;
598 pgm_opt_generic_t genopts;
599 int theend = 0, firsttime = 1;
601 tvb_memcpy(tvb, (guint8 *)&opts, offset, sizeof(opts));
602 opts.total_len = g_ntohs(opts.total_len);
604 tf = proto_tree_add_text(tree, tvb, offset,
606 "%s Options (Total Length %d)", pktname, opts.total_len);
607 opts_tree = proto_item_add_subtree(tf, ett_pgm_opts);
608 proto_tree_add_uint(opts_tree, hf_pgm_opt_type, tvb,
609 offset, 1, opts.type);
610 proto_tree_add_uint(opts_tree, hf_pgm_opt_len, tvb,
611 offset+1, 1, opts.len);
612 proto_tree_add_uint(opts_tree, hf_pgm_opt_tlen, tvb,
613 offset+2, 2, opts.total_len);
616 for (opts.total_len -= 4; opts.total_len > 0;){
617 tvb_memcpy(tvb, (guint8 *)&genopts, offset, sizeof(genopts));
618 if (genopts.type & PGM_OPT_END) {
619 genopts.type &= ~PGM_OPT_END;
622 tf = proto_tree_add_text(opts_tree, tvb, offset, genopts.len,
623 "Option: %s, Length: %u",
624 val_to_str(genopts.type, opt_vals, "Unknown (0x%02x)"),
626 if (genopts.len == 0)
629 switch(genopts.type) {
631 pgm_opt_join_t optdata;
633 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
634 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_join);
636 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
637 tvb, offset, 1, genopts.type);
639 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
640 offset+1, 1, genopts.len);
642 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx, tvb,
643 offset+2, 1, genopts.opx);
645 proto_tree_add_uint(opt_tree, hf_pgm_opt_join_res, tvb,
646 offset+3, 1, optdata.res);
648 proto_tree_add_uint(opt_tree, hf_pgm_opt_join_minjoin, tvb,
649 offset+4, 4, g_ntohl(optdata.opt_join_min));
653 case PGM_OPT_PARITY_PRM:{
654 pgm_opt_parity_prm_t optdata;
656 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
657 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_parityprm);
659 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
660 tvb, offset, 1, genopts.type);
662 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
663 offset+1, 1, genopts.len);
665 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
666 tvb, offset+2, 1, genopts.opx);
668 proto_tree_add_uint_format(opt_tree, hf_pgm_opt_parity_prm_po, tvb,
669 offset+3, 1, optdata.po, "Parity Parameters: %s (0x%x)",
670 paritystr(optdata.po), optdata.po);
672 proto_tree_add_uint(opt_tree, hf_pgm_opt_parity_prm_prmtgsz,
673 tvb, offset+4, 4, g_ntohl(optdata.prm_tgsz));
677 case PGM_OPT_PARITY_GRP:{
678 pgm_opt_parity_grp_t optdata;
680 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
681 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_paritygrp);
683 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
684 tvb, offset, 1, genopts.type);
686 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
687 offset+1, 1, genopts.len);
689 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
690 tvb, offset+2, 1, genopts.opx);
692 proto_tree_add_uint(opt_tree, hf_pgm_opt_parity_grp_res, tvb,
693 offset+3, 1, optdata.res);
695 proto_tree_add_uint(opt_tree, hf_pgm_opt_parity_grp_prmgrp,
696 tvb, offset+4, 4, g_ntohl(optdata.prm_grp));
700 case PGM_OPT_NAK_LIST:{
701 pgm_opt_nak_list_t optdata;
702 nlong_t naklist[PGM_MAX_NAK_LIST_SZ+1];
703 char nakbuf[8192], *ptr;
704 int i, j, naks, soffset = 0;
706 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
707 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_naklist);
709 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type, tvb,
710 offset, 1, genopts.type);
712 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
713 offset+1, 1, genopts.len);
715 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
716 tvb, offset+2, 1, genopts.opx);
718 proto_tree_add_uint(opt_tree, hf_pgm_opt_nak_res, tvb,
719 offset+3, 1, optdata.res);
721 optdata.len -= sizeof(pgm_opt_nak_list_t);
722 tvb_memcpy(tvb, (guint8 *)naklist, offset+4, optdata.len);
723 naks = (optdata.len/sizeof(nlong_t));
727 * Print out 8 per line
729 for (i=0; i < naks; i++) {
730 sprintf(nakbuf+soffset, "0x%lx ",
731 (unsigned long)g_ntohl(naklist[i]));
732 soffset = strlen(nakbuf);
733 if ((++j % 8) == 0) {
735 proto_tree_add_bytes_format(opt_tree,
736 hf_pgm_opt_nak_list, tvb, offset+4, optdata.len,
737 nakbuf, "List(%d): %s", naks, nakbuf);
740 proto_tree_add_bytes_format(opt_tree,
741 hf_pgm_opt_nak_list, tvb, offset+4, optdata.len,
742 nakbuf, "List: %s", nakbuf);
750 proto_tree_add_bytes_format(opt_tree,
751 hf_pgm_opt_nak_list, tvb, offset+4, optdata.len,
752 nakbuf, "List(%d): %s", naks, nakbuf);
755 proto_tree_add_bytes_format(opt_tree,
756 hf_pgm_opt_nak_list, tvb, offset+4, optdata.len,
757 nakbuf, "List: %s", nakbuf);
763 case PGM_OPT_PGMCC_DATA:{
764 pgm_opt_pgmcc_data_t optdata;
766 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
767 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_ccdata);
769 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
770 tvb, offset, 1, genopts.type);
772 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
773 offset+1, 1, genopts.len);
775 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
776 tvb, offset+2, 1, genopts.opx);
778 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccdata_res, tvb,
779 offset+3, 1, optdata.res);
781 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccdata_tsp, tvb,
782 offset+4, 4, optdata.tsp);
784 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccdata_afi, tvb,
785 offset+8, 2, g_ntohs(optdata.acker_afi));
787 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccdata_res2, tvb,
788 offset+10, 2, g_ntohs(optdata.res2));
790 switch (g_ntohs(optdata.acker_afi)) {
793 proto_tree_add_ipv4(opt_tree, hf_pgm_opt_ccdata_acker,
794 tvb, offset+12, 4, optdata.acker);
799 * XXX - the header is variable-length,
800 * as the length of the NLA depends on
803 * However, our structure for it is
804 * fixed-length, and assumes it's a 4-byte
812 case PGM_OPT_PGMCC_FEEDBACK:{
813 pgm_opt_pgmcc_feedback_t optdata;
815 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
816 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_ccdata);
818 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
819 tvb, offset, 1, genopts.type);
821 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
822 offset+1, 1, genopts.len);
824 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
825 tvb, offset+2, 1, genopts.opx);
827 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccfeedbk_res, tvb,
828 offset+3, 1, optdata.res);
830 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccfeedbk_tsp, tvb,
831 offset+4, 4, optdata.tsp);
833 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccfeedbk_afi, tvb,
834 offset+8, 2, g_ntohs(optdata.acker_afi));
836 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccfeedbk_lossrate, tvb,
837 offset+10, 2, g_ntohs(optdata.loss_rate));
839 switch (g_ntohs(optdata.acker_afi)) {
842 proto_tree_add_ipv4(opt_tree, hf_pgm_opt_ccfeedbk_acker,
843 tvb, offset+12, 4, optdata.acker);
848 * XXX - the header is variable-length,
849 * as the length of the NLA depends on
852 * However, our structure for it is
853 * fixed-length, and assumes it's a 4-byte
861 case PGM_OPT_NAK_BO_IVL:{
862 pgm_opt_nak_bo_ivl_t optdata;
864 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
865 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_nak_bo_ivl);
867 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
868 tvb, offset, 1, genopts.type);
870 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
871 offset+1, 1, genopts.len);
873 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx, tvb,
874 offset+2, 1, genopts.opx);
876 proto_tree_add_uint(opt_tree, hf_pgm_opt_nak_bo_ivl_res, tvb,
877 offset+3, 1, optdata.res);
879 proto_tree_add_uint(opt_tree, hf_pgm_opt_nak_bo_ivl_bo_ivl, tvb,
880 offset+4, 4, g_ntohl(optdata.bo_ivl));
882 proto_tree_add_uint(opt_tree, hf_pgm_opt_nak_bo_ivl_bo_ivl_sqn, tvb,
883 offset+8, 4, g_ntohl(optdata.bo_ivl_sqn));
887 case PGM_OPT_NAK_BO_RNG:{
888 pgm_opt_nak_bo_rng_t optdata;
890 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
891 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_nak_bo_rng);
893 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
894 tvb, offset, 1, genopts.type);
896 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
897 offset+1, 1, genopts.len);
899 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx, tvb,
900 offset+2, 1, genopts.opx);
902 proto_tree_add_uint(opt_tree, hf_pgm_opt_nak_bo_rng_res, tvb,
903 offset+3, 1, optdata.res);
905 proto_tree_add_uint(opt_tree, hf_pgm_opt_nak_bo_rng_min_bo_ivl, tvb,
906 offset+4, 4, g_ntohl(optdata.min_bo_ivl));
908 proto_tree_add_uint(opt_tree, hf_pgm_opt_nak_bo_rng_max_bo_ivl, tvb,
909 offset+8, 4, g_ntohl(optdata.max_bo_ivl));
913 case PGM_OPT_REDIRECT:{
914 pgm_opt_redirect_t optdata;
916 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
917 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_redirect);
919 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
920 tvb, offset, 1, genopts.type);
922 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
923 offset+1, 1, genopts.len);
925 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
926 tvb, offset+2, 1, genopts.opx);
928 proto_tree_add_uint(opt_tree, hf_pgm_opt_redirect_res, tvb,
929 offset+3, 1, optdata.res);
931 proto_tree_add_uint(opt_tree, hf_pgm_opt_redirect_afi, tvb,
932 offset+4, 2, g_ntohs(optdata.afi));
934 proto_tree_add_uint(opt_tree, hf_pgm_opt_redirect_res2, tvb,
935 offset+6, 2, g_ntohs(optdata.res2));
937 switch (g_ntohs(optdata.afi)) {
940 proto_tree_add_ipv4(opt_tree, hf_pgm_opt_redirect_dlr,
941 tvb, offset+8, 4, optdata.dlr);
946 * XXX - the header is variable-length,
947 * as the length of the NLA depends on
950 * However, our structure for it is
951 * fixed-length, and assumes it's a 4-byte
959 case PGM_OPT_FRAGMENT:{
960 pgm_opt_fragment_t optdata;
962 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
963 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_fragment);
965 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
966 tvb, offset, 1, genopts.type);
968 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
969 offset+1, 1, genopts.len);
971 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx, tvb,
972 offset+2, 1, genopts.opx);
974 proto_tree_add_uint(opt_tree, hf_pgm_opt_fragment_res, tvb,
975 offset+3, 1, optdata.res);
977 proto_tree_add_uint(opt_tree, hf_pgm_opt_fragment_first_sqn, tvb,
978 offset+4, 4, g_ntohl(optdata.first_sqn));
980 proto_tree_add_uint(opt_tree, hf_pgm_opt_fragment_offset, tvb,
981 offset+8, 4, g_ntohl(optdata.offset));
983 proto_tree_add_uint(opt_tree, hf_pgm_opt_fragment_total_length, tvb,
984 offset+12, 4, g_ntohl(optdata.total_length));
989 offset += genopts.len;
990 opts.total_len -= genopts.len;
996 static const value_string type_vals[] = {
997 { PGM_SPM_PCKT, "SPM" },
998 { PGM_RDATA_PCKT, "RDATA" },
999 { PGM_ODATA_PCKT, "ODATA" },
1000 { PGM_NAK_PCKT, "NAK" },
1001 { PGM_NNAK_PCKT, "NNAK" },
1002 { PGM_NCF_PCKT, "NCF" },
1003 { PGM_POLL_PCKT, "POLL" },
1004 { PGM_POLR_PCKT, "POLR" },
1005 { PGM_ACK_PCKT, "ACK" },
1009 static const value_string poll_subtype_vals[] = {
1010 { PGM_POLL_GENERAL, "General" },
1011 { PGM_POLL_DLR, "DLR" },
1014 /* Determine if there is a sub-dissector and call it. This has been */
1015 /* separated into a stand alone routine to other protocol dissectors */
1016 /* can call to it, ie. socks */
1019 decode_pgm_ports(tvbuff_t *tvb, int offset, packet_info *pinfo,
1020 proto_tree *tree, pgm_type *pgmhdr)
1025 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
1027 /* do lookup with the subdissector table */
1028 found = dissector_try_port(subdissector_table, pgmhdr->sport,
1029 next_tvb, pinfo, tree);
1033 found = dissector_try_port(subdissector_table, pgmhdr->dport,
1034 next_tvb, pinfo, tree);
1038 /* do lookup with the heuristic subdissector table */
1039 if (dissector_try_heuristic(heur_subdissector_list, next_tvb, pinfo, tree))
1042 /* Oh, well, we don't know this; dissect it as data. */
1043 call_dissector(data_handle,next_tvb, pinfo, tree);
1047 total_size(tvbuff_t *tvb, pgm_type *hdr)
1049 int bytes = sizeof(pgm_type);
1050 pgm_opt_length_t opts;
1054 bytes += sizeof(pgm_spm_t);
1057 case PGM_RDATA_PCKT:
1058 case PGM_ODATA_PCKT:
1059 bytes += sizeof(pgm_data_t);
1065 bytes += sizeof(pgm_nak_t);
1068 bytes += sizeof(pgm_poll_t);
1071 bytes += sizeof(pgm_polr_t);
1074 bytes += sizeof(pgm_ack_t);
1077 if ((hdr->opts & PGM_OPT)) {
1078 tvb_memcpy(tvb, (guint8 *)&opts, bytes, sizeof(opts));
1079 bytes += g_ntohs(opts.total_len);
1084 * dissect_pgm - The dissector for Pragmatic General Multicast
1087 dissect_pgm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1089 proto_tree *pgm_tree = NULL;
1090 proto_tree *opt_tree = NULL;
1091 proto_tree *type_tree = NULL;
1103 const char *pktname;
1104 const char *pollstname;
1107 guint pgmlen, reportedlen;
1109 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1110 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PGM");
1112 /* Clear out the Info column. */
1113 if (check_col(pinfo->cinfo, COL_INFO))
1114 col_clear(pinfo->cinfo, COL_INFO);
1116 tvb_memcpy(tvb, (guint8 *)&pgmhdr, offset, sizeof(pgm_type));
1117 hlen = sizeof(pgm_type);
1118 pgmhdr.sport = g_ntohs(pgmhdr.sport);
1119 pgmhdr.dport = g_ntohs(pgmhdr.dport);
1120 pgmhdr.tsdulen = g_ntohs(pgmhdr.tsdulen);
1121 pgmhdr.cksum = g_ntohs(pgmhdr.cksum);
1123 pktname = val_to_str(pgmhdr.type, type_vals, "Unknown (0x%02x)");
1125 gsi = bytes_to_str(pgmhdr.gsi, 6);
1126 switch(pgmhdr.type) {
1128 plen = sizeof(pgm_spm_t);
1129 tvb_memcpy(tvb, (guint8 *)&spm, sizeof(pgm_type), plen);
1131 if (check_col(pinfo->cinfo, COL_INFO)) {
1132 col_add_fstr(pinfo->cinfo, COL_INFO,
1133 "%-5s sqn 0x%x gsi %s", pktname, spm.sqn, gsi);
1137 case PGM_RDATA_PCKT:
1138 case PGM_ODATA_PCKT:
1139 plen = sizeof(pgm_data_t);
1140 tvb_memcpy(tvb, (guint8 *)&data, sizeof(pgm_type), plen);
1142 if (check_col(pinfo->cinfo, COL_INFO)) {
1143 col_add_fstr(pinfo->cinfo, COL_INFO,
1144 "%-5s sqn 0x%x gsi %s tsdulen %d", pktname, data.sqn, gsi,
1153 plen = sizeof(pgm_nak_t);
1154 tvb_memcpy(tvb, (guint8 *)&nak, sizeof(pgm_type), plen);
1156 if (check_col(pinfo->cinfo, COL_INFO)) {
1157 col_add_fstr(pinfo->cinfo, COL_INFO,
1158 "%-5s sqn 0x%x gsi %s", pktname, nak.sqn, gsi);
1162 plen = sizeof(pgm_poll_t);
1163 tvb_memcpy(tvb, (guint8 *)&poll, sizeof(pgm_type), plen);
1165 pollstname = val_to_str(poll.subtype, poll_subtype_vals, "Unknown (0x%02x)");
1166 if (check_col(pinfo->cinfo, COL_INFO)) {
1167 col_add_fstr(pinfo->cinfo, COL_INFO,
1168 "%-5s sqn 0x%x gsi %s subtype %s", pktname, poll.sqn, gsi, pollstname);
1172 plen = sizeof(pgm_polr_t);
1173 tvb_memcpy(tvb, (guint8 *)&polr, sizeof(pgm_type), plen);
1175 if (check_col(pinfo->cinfo, COL_INFO)) {
1176 col_add_fstr(pinfo->cinfo, COL_INFO,
1177 "%-5s sqn 0x%x gsi %s", pktname, polr.sqn, gsi);
1181 plen = sizeof(pgm_ack_t);
1182 tvb_memcpy(tvb, (guint8 *)&ack, sizeof(pgm_type), plen);
1184 if (check_col(pinfo->cinfo, COL_INFO)) {
1185 col_add_fstr(pinfo->cinfo, COL_INFO,
1186 "%-5s sqn 0x%x gsi %s", pktname, ack.rx_max_sqn, gsi);
1195 ti = proto_tree_add_protocol_format(tree, proto_pgm,
1196 tvb, offset, total_size(tvb, &pgmhdr),
1197 "Pragmatic General Multicast: Type %s"
1198 " SrcPort %u, DstPort %u, GSI %s", pktname,
1199 pgmhdr.sport, pgmhdr.dport,
1200 bytes_to_str(pgmhdr.gsi, 6));
1202 pgm_tree = proto_item_add_subtree(ti, ett_pgm);
1203 proto_tree_add_uint(pgm_tree, hf_pgm_main_sport, tvb, offset, 2,
1205 proto_tree_add_uint(pgm_tree, hf_pgm_main_dport, tvb, offset+2,
1207 proto_tree_add_uint(pgm_tree, hf_pgm_main_type, tvb,
1208 offset+4, 1, pgmhdr.type);
1210 tf = proto_tree_add_uint_format(pgm_tree, hf_pgm_main_opts, tvb,
1211 offset+5, 1, pgmhdr.opts, "Options: %s (0x%x)",
1212 optsstr(pgmhdr.opts), pgmhdr.opts);
1213 opt_tree = proto_item_add_subtree(tf, ett_pgm_optbits);
1215 proto_tree_add_boolean(opt_tree, hf_pgm_main_opts_opt, tvb,
1216 offset+5, 1, (pgmhdr.opts & PGM_OPT));
1217 proto_tree_add_boolean(opt_tree, hf_pgm_main_opts_netsig, tvb,
1218 offset+5, 1, (pgmhdr.opts & PGM_OPT_NETSIG));
1219 proto_tree_add_boolean(opt_tree, hf_pgm_main_opts_varlen, tvb,
1220 offset+5, 1, (pgmhdr.opts & PGM_OPT_VAR_PKTLEN));
1221 proto_tree_add_boolean(opt_tree, hf_pgm_main_opts_parity, tvb,
1222 offset+5, 1, (pgmhdr.opts & PGM_OPT_PARITY));
1224 reportedlen = tvb_reported_length(tvb);
1225 pgmlen = tvb_length(tvb);
1226 if (pgm_check_checksum && pgmlen >= reportedlen) {
1228 guint16 computed_cksum;
1230 cksum_vec[0].ptr = tvb_get_ptr(tvb, offset, pgmlen);
1231 cksum_vec[0].len = pgmlen;
1232 computed_cksum = in_cksum(&cksum_vec[0], 1);
1233 if (computed_cksum == 0) {
1234 proto_tree_add_uint_format(pgm_tree, hf_pgm_main_cksum, tvb,
1235 offset+6, 2, pgmhdr.cksum, "Checksum: 0x%04x (correct)", pgmhdr.cksum);
1237 proto_tree_add_boolean_hidden(pgm_tree, hf_pgm_main_cksum_bad, tvb,
1239 proto_tree_add_uint_format(pgm_tree, hf_pgm_main_cksum, tvb,
1240 offset+6, 2, pgmhdr.cksum, "Checksum: 0x%04x (incorrect, should be 0x%04x)",
1241 pgmhdr.cksum, in_cksum_shouldbe(pgmhdr.cksum, computed_cksum));
1244 proto_tree_add_uint(pgm_tree, hf_pgm_main_cksum, tvb, offset+6,
1248 proto_tree_add_bytes(pgm_tree, hf_pgm_main_gsi, tvb, offset+8,
1250 proto_tree_add_uint(pgm_tree, hf_pgm_main_tsdulen, tvb,
1251 offset+14, 2, pgmhdr.tsdulen);
1253 offset = sizeof(pgm_type);
1254 tf = proto_tree_add_text(pgm_tree, tvb, offset, plen, "%s Packet",
1256 switch(pgmhdr.type) {
1258 type_tree = proto_item_add_subtree(tf, ett_pgm_spm);
1260 proto_tree_add_uint(type_tree, hf_pgm_spm_sqn, tvb,
1261 offset, 4, spm.sqn);
1262 proto_tree_add_uint(type_tree, hf_pgm_spm_trail, tvb,
1263 offset+4, 4, spm.trail);
1264 proto_tree_add_uint(type_tree, hf_pgm_spm_lead, tvb,
1265 offset+8, 4, spm.lead);
1266 proto_tree_add_uint(type_tree, hf_pgm_spm_pathafi, tvb,
1267 offset+12, 2, spm.path_afi);
1268 proto_tree_add_uint(type_tree, hf_pgm_spm_res, tvb,
1269 offset+14, 2, spm.res);
1270 switch (spm.path_afi) {
1273 proto_tree_add_ipv4(type_tree, hf_pgm_spm_path,
1274 tvb, offset+16, 4, spm.path);
1279 * XXX - the header is variable-length,
1280 * as the length of the NLA depends on
1283 * However, our structure for it is
1284 * fixed-length, and assumes it's a 4-byte
1290 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1294 dissect_pgmopts(tvb, offset, type_tree, pktname);
1298 case PGM_RDATA_PCKT:
1299 case PGM_ODATA_PCKT: {
1300 type_tree = proto_item_add_subtree(tf, ett_pgm_data);
1302 proto_tree_add_uint(type_tree, hf_pgm_spm_sqn, tvb,
1303 offset, 4, data.sqn);
1304 proto_tree_add_uint(type_tree, hf_pgm_spm_trail, tvb,
1305 offset+4, 4, data.trail);
1307 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1311 dissect_pgmopts(tvb, offset, type_tree, pktname);
1320 type_tree = proto_item_add_subtree(tf, ett_pgm_nak);
1322 proto_tree_add_uint(type_tree, hf_pgm_nak_sqn, tvb,
1323 offset, 4, nak.sqn);
1324 proto_tree_add_uint(type_tree, hf_pgm_nak_srcafi, tvb,
1325 offset+4, 2, nak.src_afi);
1326 proto_tree_add_uint(type_tree, hf_pgm_nak_srcres, tvb,
1327 offset+6, 2, nak.src_res);
1329 switch (nak.src_afi) {
1332 proto_tree_add_ipv4(type_tree, hf_pgm_nak_src,
1333 tvb, offset+8, 4, nak.src);
1338 * XXX - the header is variable-length,
1339 * as the length of the NLA depends on
1342 * However, our structure for it is
1343 * fixed-length, and assumes it's a 4-byte
1349 proto_tree_add_uint(type_tree, hf_pgm_nak_grpafi, tvb,
1350 offset+12, 2, nak.grp_afi);
1351 proto_tree_add_uint(type_tree, hf_pgm_nak_grpres, tvb,
1352 offset+14, 2, nak.grp_res);
1354 switch (nak.grp_afi) {
1357 proto_tree_add_ipv4(type_tree, hf_pgm_nak_grp,
1358 tvb, offset+16, 4, nak.grp);
1363 * XXX - the header is variable-length,
1364 * as the length of the NLA depends on
1367 * However, our structure for it is
1368 * fixed-length, and assumes it's a 4-byte
1374 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1378 dissect_pgmopts(tvb, offset, type_tree, pktname);
1382 type_tree = proto_item_add_subtree(tf, ett_pgm_poll);
1384 proto_tree_add_uint(type_tree, hf_pgm_poll_sqn, tvb,
1385 offset, 4, poll.sqn);
1386 proto_tree_add_uint(type_tree, hf_pgm_poll_round, tvb,
1387 offset+4, 2, poll.round);
1388 proto_tree_add_uint(type_tree, hf_pgm_poll_subtype, tvb,
1389 offset+6, 2, poll.subtype);
1390 proto_tree_add_uint(type_tree, hf_pgm_poll_pathafi, tvb,
1391 offset+8, 2, poll.path_afi);
1392 proto_tree_add_uint(type_tree, hf_pgm_poll_res, tvb,
1393 offset+10, 2, poll.res);
1395 switch (poll.path_afi) {
1398 proto_tree_add_ipv4(type_tree, hf_pgm_poll_path,
1399 tvb, offset+12, 4, poll.path);
1404 * XXX - the header is variable-length,
1405 * as the length of the NLA depends on
1408 * However, our structure for it is
1409 * fixed-length, and assumes it's a 4-byte
1415 proto_tree_add_uint(type_tree, hf_pgm_poll_backoff_ivl, tvb,
1416 offset+16, 4, poll.backoff_ivl);
1417 proto_tree_add_uint(type_tree, hf_pgm_poll_rand_str, tvb,
1418 offset+20, 4, poll.rand_str);
1419 proto_tree_add_uint(type_tree, hf_pgm_poll_matching_bmask, tvb,
1420 offset+24, 4, poll.matching_bmask);
1422 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1426 dissect_pgmopts(tvb, offset, type_tree, pktname);
1430 type_tree = proto_item_add_subtree(tf, ett_pgm_polr);
1432 proto_tree_add_uint(type_tree, hf_pgm_polr_sqn, tvb,
1433 offset, 4, polr.sqn);
1434 proto_tree_add_uint(type_tree, hf_pgm_polr_round, tvb,
1435 offset+4, 2, polr.round);
1436 proto_tree_add_uint(type_tree, hf_pgm_polr_res, tvb,
1437 offset+6, 2, polr.res);
1439 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1443 dissect_pgmopts(tvb, offset, type_tree, pktname);
1447 type_tree = proto_item_add_subtree(tf, ett_pgm_ack);
1449 proto_tree_add_uint(type_tree, hf_pgm_ack_sqn, tvb,
1450 offset, 4, ack.rx_max_sqn);
1451 proto_tree_add_uint(type_tree, hf_pgm_ack_bitmap, tvb,
1452 offset+4, 4, ack.bitmap);
1454 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1458 dissect_pgmopts(tvb, offset, type_tree, pktname);
1466 * Now see if there are any sub-dissectors, if so call them
1468 offset = total_size(tvb, &pgmhdr);
1469 decode_pgm_ports(tvb, offset, pinfo, tree, &pgmhdr);
1473 static const true_false_string opts_present = {
1478 /* Register all the bits needed with the filtering engine */
1480 proto_register_pgm(void)
1482 static hf_register_info hf[] = {
1483 { &hf_pgm_main_sport,
1484 { "Source Port", "pgm.hdr.sport", FT_UINT16, BASE_DEC,
1485 NULL, 0x0, "", HFILL }},
1486 { &hf_pgm_main_dport,
1487 { "Destination Port", "pgm.hdr.dport", FT_UINT16, BASE_DEC,
1488 NULL, 0x0, "", HFILL }},
1489 { &hf_pgm_main_type,
1490 { "Type", "pgm.hdr.type", FT_UINT8, BASE_HEX,
1491 VALS(type_vals), 0x0, "", HFILL }},
1492 { &hf_pgm_main_opts,
1493 { "Options", "pgm.hdr.opts", FT_UINT8, BASE_HEX,
1494 NULL, 0x0, "", HFILL }},
1495 { &hf_pgm_main_opts_opt,
1496 { "Options", "pgm.hdr.opts.opt", FT_BOOLEAN, BASE_NONE,
1497 TFS(&opts_present), PGM_OPT, "", HFILL }},
1498 { &hf_pgm_main_opts_netsig,
1499 { "Network Significant Options", "pgm.hdr.opts.netsig",
1500 FT_BOOLEAN, BASE_NONE,
1501 TFS(&opts_present), PGM_OPT_NETSIG, "", HFILL }},
1502 { &hf_pgm_main_opts_varlen,
1503 { "Variable length Parity Packet Option", "pgm.hdr.opts.varlen",
1504 FT_BOOLEAN, BASE_NONE,
1505 TFS(&opts_present), PGM_OPT_VAR_PKTLEN, "", HFILL }},
1506 { &hf_pgm_main_opts_parity,
1507 { "Parity", "pgm.hdr.opts.parity", FT_BOOLEAN, BASE_NONE,
1508 TFS(&opts_present), PGM_OPT_PARITY, "", HFILL }},
1509 { &hf_pgm_main_cksum,
1510 { "Checksum", "pgm.hdr.cksum", FT_UINT16, BASE_HEX,
1511 NULL, 0x0, "", HFILL }},
1512 { &hf_pgm_main_cksum_bad,
1513 { "Bad Checksum", "pgm.hdr.cksum_bad", FT_BOOLEAN, BASE_NONE,
1514 NULL, 0x0, "", HFILL }},
1516 { "Global Source Identifier", "pgm.hdr.gsi", FT_BYTES, BASE_HEX,
1517 NULL, 0x0, "", HFILL }},
1518 { &hf_pgm_main_tsdulen,
1519 { "Transport Service Data Unit Length", "pgm.hdr.tsdulen", FT_UINT16,
1520 BASE_DEC, NULL, 0x0, "", HFILL }},
1522 { "Sequence number", "pgm.spm.sqn", FT_UINT32, BASE_HEX,
1523 NULL, 0x0, "", HFILL }},
1524 { &hf_pgm_spm_trail,
1525 { "Trailing Edge Sequence Number", "pgm.spm.trail", FT_UINT32, BASE_HEX,
1526 NULL, 0x0, "", HFILL }},
1528 { "Leading Edge Sequence Number", "pgm.spm.lead", FT_UINT32, BASE_HEX,
1529 NULL, 0x0, "", HFILL }},
1530 { &hf_pgm_spm_pathafi,
1531 { "Path NLA AFI", "pgm.spm.pathafi", FT_UINT16, BASE_DEC,
1532 VALS(afn_vals), 0x0, "", HFILL }},
1534 { "Reserved", "pgm.spm.res", FT_UINT16, BASE_HEX,
1535 NULL, 0x0, "", HFILL }},
1537 { "Path NLA", "pgm.spm.path", FT_IPv4, BASE_NONE,
1538 NULL, 0x0, "", HFILL }},
1540 { "Data Packet Sequence Number", "pgm.data.sqn", FT_UINT32, BASE_HEX,
1541 NULL, 0x0, "", HFILL }},
1542 { &hf_pgm_data_trail,
1543 { "Trailing Edge Sequence Number", "pgm.data.trail", FT_UINT32, BASE_HEX,
1544 NULL, 0x0, "", HFILL }},
1546 { "Requested Sequence Number", "pgm.nak.sqn", FT_UINT32, BASE_HEX,
1547 NULL, 0x0, "", HFILL }},
1548 { &hf_pgm_nak_srcafi,
1549 { "Source NLA AFI", "pgm.nak.srcafi", FT_UINT16, BASE_DEC,
1550 VALS(afn_vals), 0x0, "", HFILL }},
1551 { &hf_pgm_nak_srcres,
1552 { "Reserved", "pgm.nak.srcres", FT_UINT16, BASE_HEX,
1553 NULL, 0x0, "", HFILL }},
1555 { "Source NLA", "pgm.nak.src", FT_IPv4, BASE_NONE,
1556 NULL, 0x0, "", HFILL }},
1557 { &hf_pgm_nak_grpafi,
1558 { "Multicast Group AFI", "pgm.nak.grpafi", FT_UINT16, BASE_DEC,
1559 VALS(afn_vals), 0x0, "", HFILL }},
1560 { &hf_pgm_nak_grpres,
1561 { "Reserved", "pgm.nak.grpres", FT_UINT16, BASE_HEX,
1562 NULL, 0x0, "", HFILL }},
1564 { "Multicast Group NLA", "pgm.nak.grp", FT_IPv4, BASE_NONE,
1565 NULL, 0x0, "", HFILL }},
1567 { "Sequence Number", "pgm.poll.sqn", FT_UINT32, BASE_HEX,
1568 NULL, 0x0, "", HFILL }},
1569 { &hf_pgm_poll_round,
1570 { "Round", "pgm.poll.round", FT_UINT16, BASE_DEC,
1571 NULL, 0x0, "", HFILL }},
1572 { &hf_pgm_poll_subtype,
1573 { "Subtype", "pgm.poll.subtype", FT_UINT16, BASE_HEX,
1574 VALS(poll_subtype_vals), 0x0, "", HFILL }},
1575 { &hf_pgm_poll_pathafi,
1576 { "Path NLA AFI", "pgm.poll.pathafi", FT_UINT16, BASE_DEC,
1577 VALS(afn_vals), 0x0, "", HFILL }},
1579 { "Reserved", "pgm.poll.res", FT_UINT16, BASE_HEX,
1580 NULL, 0x0, "", HFILL }},
1581 { &hf_pgm_poll_path,
1582 { "Path NLA", "pgm.poll.path", FT_IPv4, BASE_NONE,
1583 NULL, 0x0, "", HFILL }},
1584 { &hf_pgm_poll_backoff_ivl,
1585 { "Back-off Interval", "pgm.poll.backoff_ivl", FT_UINT32, BASE_DEC,
1586 NULL, 0x0, "", HFILL }},
1587 { &hf_pgm_poll_rand_str,
1588 { "Random String", "pgm.poll.rand_str", FT_UINT32, BASE_HEX,
1589 NULL, 0x0, "", HFILL }},
1590 { &hf_pgm_poll_matching_bmask,
1591 { "Matching Bitmask", "pgm.poll.matching_bmask", FT_UINT32, BASE_HEX,
1592 NULL, 0x0, "", HFILL }},
1594 { "Sequence Number", "pgm.polr.sqn", FT_UINT32, BASE_HEX,
1595 NULL, 0x0, "", HFILL }},
1596 { &hf_pgm_polr_round,
1597 { "Round", "pgm.polr.round", FT_UINT16, BASE_DEC,
1598 NULL, 0x0, "", HFILL }},
1600 { "Reserved", "pgm.polr.res", FT_UINT16, BASE_HEX,
1601 NULL, 0x0, "", HFILL }},
1603 { "Maximum Received Sequence Number", "pgm.ack.maxsqn", FT_UINT32,
1604 BASE_HEX, NULL, 0x0, "", HFILL }},
1605 { &hf_pgm_ack_bitmap,
1606 { "Packet Bitmap", "pgm.ack.bitmap", FT_UINT32, BASE_HEX,
1607 NULL, 0x0, "", HFILL }},
1609 { "Type", "pgm.opts.type", FT_UINT8, BASE_HEX,
1610 VALS(opt_vals), 0x0, "", HFILL }},
1612 { "Length", "pgm.opts.len", FT_UINT8, BASE_DEC,
1613 NULL, 0x0, "", HFILL }},
1615 { "Total Length", "pgm.opts.tlen", FT_UINT16, BASE_DEC,
1616 NULL, 0x0, "", HFILL }},
1617 { &hf_pgm_genopt_type,
1618 { "Type", "pgm.genopts.type", FT_UINT8, BASE_HEX,
1619 VALS(opt_vals), 0x0, "", HFILL }},
1620 { &hf_pgm_genopt_len,
1621 { "Length", "pgm.genopts.len", FT_UINT8, BASE_DEC,
1622 NULL, 0x0, "", HFILL }},
1623 { &hf_pgm_genopt_opx,
1624 { "Option Extensibility Bits", "pgm.genopts.opx", FT_UINT8, BASE_HEX,
1625 VALS(opx_vals), 0x0, "", HFILL }},
1626 { &hf_pgm_opt_parity_prm_po,
1627 { "Parity Parameters", "pgm.opts.parity_prm.op", FT_UINT8, BASE_HEX,
1628 NULL, 0x0, "", HFILL }},
1629 { &hf_pgm_opt_parity_prm_prmtgsz,
1630 { "Transmission Group Size", "pgm.opts.parity_prm.prm_grp",
1631 FT_UINT32, BASE_HEX,
1632 NULL, 0x0, "", HFILL }},
1633 { &hf_pgm_opt_join_res,
1634 { "Reserved", "pgm.opts.join.res", FT_UINT8, BASE_HEX,
1635 NULL, 0x0, "", HFILL }},
1636 { &hf_pgm_opt_join_minjoin,
1637 { "Minimum Sequence Number", "pgm.opts.join.min_join",
1638 FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
1639 { &hf_pgm_opt_parity_grp_res,
1640 { "Reserved", "pgm.opts.parity_prm.op", FT_UINT8, BASE_HEX,
1641 NULL, 0x0, "", HFILL }},
1642 { &hf_pgm_opt_parity_grp_prmgrp,
1643 { "Transmission Group Size", "pgm.opts.parity_prm.prm_grp",
1644 FT_UINT32, BASE_HEX,
1645 NULL, 0x0, "", HFILL }},
1646 { &hf_pgm_opt_nak_res,
1647 { "Reserved", "pgm.opts.nak.op", FT_UINT8, BASE_HEX,
1648 NULL, 0x0, "", HFILL }},
1649 { &hf_pgm_opt_nak_list,
1650 { "List", "pgm.opts.nak.list", FT_BYTES, BASE_NONE,
1651 NULL, 0x0, "", HFILL }},
1652 { &hf_pgm_opt_ccdata_res,
1653 { "Reserved", "pgm.opts.ccdata.res", FT_UINT8, BASE_DEC,
1654 NULL, 0x0, "", HFILL }},
1655 { &hf_pgm_opt_ccdata_tsp,
1656 { "Time Stamp", "pgm.opts.ccdata.tstamp", FT_UINT16, BASE_HEX,
1657 NULL, 0x0, "", HFILL }},
1658 { &hf_pgm_opt_ccdata_afi,
1659 { "Acker AFI", "pgm.opts.ccdata.afi", FT_UINT16, BASE_DEC,
1660 VALS(afn_vals), 0x0, "", HFILL }},
1661 { &hf_pgm_opt_ccdata_res2,
1662 { "Reserved", "pgm.opts.ccdata.res2", FT_UINT16, BASE_DEC,
1663 NULL, 0x0, "", HFILL }},
1664 { &hf_pgm_opt_ccdata_acker,
1665 { "Acker", "pgm.opts.ccdata.acker", FT_IPv4, BASE_NONE,
1666 NULL, 0x0, "", HFILL }},
1667 { &hf_pgm_opt_ccfeedbk_res,
1668 { "Reserved", "pgm.opts.ccdata.res", FT_UINT8, BASE_DEC,
1669 NULL, 0x0, "", HFILL }},
1670 { &hf_pgm_opt_ccfeedbk_tsp,
1671 { "Time Stamp", "pgm.opts.ccdata.tstamp", FT_UINT16, BASE_HEX,
1672 NULL, 0x0, "", HFILL }},
1673 { &hf_pgm_opt_ccfeedbk_afi,
1674 { "Acker AFI", "pgm.opts.ccdata.afi", FT_UINT16, BASE_DEC,
1675 VALS(afn_vals), 0x0, "", HFILL }},
1676 { &hf_pgm_opt_ccfeedbk_lossrate,
1677 { "Loss Rate", "pgm.opts.ccdata.lossrate", FT_UINT16, BASE_HEX,
1678 NULL, 0x0, "", HFILL }},
1679 { &hf_pgm_opt_ccfeedbk_acker,
1680 { "Acker", "pgm.opts.ccdata.acker", FT_IPv4, BASE_NONE,
1681 NULL, 0x0, "", HFILL }},
1682 { &hf_pgm_opt_nak_bo_ivl_res,
1683 { "Reserved", "pgm.opts.nak_bo_ivl.res", FT_UINT8, BASE_HEX,
1684 NULL, 0x0, "", HFILL }},
1685 { &hf_pgm_opt_nak_bo_ivl_bo_ivl,
1686 { "Back-off Interval", "pgm.opts.nak_bo_ivl.bo_ivl", FT_UINT32, BASE_DEC,
1687 NULL, 0x0, "", HFILL }},
1688 { &hf_pgm_opt_nak_bo_ivl_bo_ivl_sqn,
1689 { "Back-off Interval Sequence Number", "pgm.opts.nak_bo_ivl.bo_ivl_sqn", FT_UINT32, BASE_HEX,
1690 NULL, 0x0, "", HFILL }},
1691 { &hf_pgm_opt_nak_bo_rng_res,
1692 { "Reserved", "pgm.opts.nak_bo_rng.res", FT_UINT8, BASE_HEX,
1693 NULL, 0x0, "", HFILL }},
1694 { &hf_pgm_opt_nak_bo_rng_min_bo_ivl,
1695 { "Min Back-off Interval", "pgm.opts.nak_bo_rng.min_bo_ivl", FT_UINT32, BASE_DEC,
1696 NULL, 0x0, "", HFILL }},
1697 { &hf_pgm_opt_nak_bo_rng_max_bo_ivl,
1698 { "Max Back-off Interval", "pgm.opts.nak_bo_rng.max_bo_ivl", FT_UINT32, BASE_DEC,
1699 NULL, 0x0, "", HFILL }},
1700 { &hf_pgm_opt_redirect_res,
1701 { "Reserved", "pgm.opts.redirect.res", FT_UINT8, BASE_DEC,
1702 NULL, 0x0, "", HFILL }},
1703 { &hf_pgm_opt_redirect_afi,
1704 { "DLR AFI", "pgm.opts.redirect.afi", FT_UINT16, BASE_DEC,
1705 VALS(afn_vals), 0x0, "", HFILL }},
1706 { &hf_pgm_opt_redirect_res2,
1707 { "Reserved", "pgm.opts.redirect.res2", FT_UINT16, BASE_HEX,
1708 NULL, 0x0, "", HFILL }},
1709 { &hf_pgm_opt_redirect_dlr,
1710 { "DLR", "pgm.opts.redirect.dlr", FT_IPv4, BASE_NONE,
1711 NULL, 0x0, "", HFILL }},
1712 { &hf_pgm_opt_fragment_res,
1713 { "Reserved", "pgm.opts.fragment.res", FT_UINT8, BASE_HEX,
1714 NULL, 0x0, "", HFILL }},
1715 { &hf_pgm_opt_fragment_first_sqn,
1716 { "First Sequence Number", "pgm.opts.fragment.first_sqn", FT_UINT32, BASE_HEX,
1717 NULL, 0x0, "", HFILL }},
1718 { &hf_pgm_opt_fragment_total_length,
1719 { "Total Length", "pgm.opts.fragment.total_length", FT_UINT32, BASE_DEC,
1720 NULL, 0x0, "", HFILL }},
1722 static gint *ett[] = {
1733 &ett_pgm_opts_parityprm,
1734 &ett_pgm_opts_paritygrp,
1735 &ett_pgm_opts_naklist,
1736 &ett_pgm_opts_ccdata,
1737 &ett_pgm_opts_nak_bo_ivl,
1738 &ett_pgm_opts_nak_bo_rng,
1739 &ett_pgm_opts_redirect,
1740 &ett_pgm_opts_fragment,
1742 module_t *pgm_module;
1744 proto_pgm = proto_register_protocol("Pragmatic General Multicast",
1747 proto_register_field_array(proto_pgm, hf, array_length(hf));
1748 proto_register_subtree_array(ett, array_length(ett));
1750 /* subdissector code */
1751 subdissector_table = register_dissector_table("pgm.port",
1752 "PGM port", FT_UINT16, BASE_DEC);
1753 register_heur_dissector_list("pgm", &heur_subdissector_list);
1756 * Register configuration preferences for UDP encapsulation
1757 * (Note: Initially the ports are set to zero so the
1758 * dissecting of PGM encapsulated in UPD packets
1759 * is off by default)
1761 pgm_module = prefs_register_protocol(proto_pgm, proto_rereg_pgm);
1763 prefs_register_bool_preference(pgm_module, "check_checksum",
1764 "Check the validity of the PGM checksum when possible",
1765 "Whether to check the validity of the PGM checksum",
1766 &pgm_check_checksum);
1768 prefs_register_uint_preference(pgm_module, "udp.encap_ucast_port",
1769 "PGM Encap Unicast Port (standard is 3055)",
1770 "PGM Encap is PGM packets encapsulated in UDP packets"
1771 " (Note: This option is off, i.e. port is 0, by default)",
1772 10, &udp_encap_ucast_port);
1773 old_encap_ucast_port = udp_encap_ucast_port;
1775 prefs_register_uint_preference(pgm_module, "udp.encap_mcast_port",
1776 "PGM Encap Multicast Port (standard is 3056)",
1777 "PGM Encap is PGM packets encapsulated in UDP packets"
1778 " (Note: This option is off, i.e. port is 0, by default)",
1779 10, &udp_encap_mcast_port);
1781 old_encap_mcast_port = udp_encap_mcast_port;
1784 static dissector_handle_t pgm_handle;
1786 /* The registration hand-off routine */
1788 proto_reg_handoff_pgm(void)
1790 pgm_handle = create_dissector_handle(dissect_pgm, proto_pgm);
1793 * Set up PGM Encap dissecting, which is off by default
1795 dissector_add("udp.port", udp_encap_ucast_port, pgm_handle);
1796 dissector_add("udp.port", udp_encap_mcast_port, pgm_handle);
1798 dissector_add("ip.proto", IP_PROTO_PGM, pgm_handle);
1800 data_handle = find_dissector("data");
1804 proto_rereg_pgm(void)
1807 * Remove the old ones
1809 dissector_delete("udp.port", old_encap_ucast_port, pgm_handle);
1810 dissector_delete("udp.port", old_encap_mcast_port, pgm_handle);
1815 dissector_add("udp.port", udp_encap_ucast_port, pgm_handle);
1816 dissector_add("udp.port", udp_encap_mcast_port, pgm_handle);