2 * Routines for pgm packet disassembly
4 * $Id: packet-pgm.c,v 1.16 2002/04/29 08:20: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.
31 #ifdef HAVE_SYS_TYPES_H
32 #include <sys/types.h>
35 #ifdef HAVE_SYS_SOCKET_H
36 #include <sys/socket.h>
39 #ifdef HAVE_NETINET_IN_H
40 #include <netinet/in.h>
48 #include <epan/packet.h>
51 #include <epan/resolv.h>
52 #include <epan/strutil.h>
53 #include <epan/conversation.h>
56 #include <epan/proto.h>
58 void proto_reg_handoff_pgm(void);
59 static void proto_rereg_pgm(void);
61 typedef guint8 nchar_t;
62 typedef guint16 nshort_t;
63 typedef guint32 nlong_t;
65 /* The PGM main header */
67 nshort_t sport; /* source port */
68 nshort_t dport; /* destination port */
69 nchar_t type; /* PGM type */
70 nchar_t opts; /* options */
71 nshort_t cksum; /* checksum */
72 nchar_t gsi[6]; /* Global Source ID */
73 nshort_t tsdulen; /* TSDU length */
75 #define pgmhdr_ntoh(_p) \
76 (_p)->sport = ntohs((_p)->sport); \
77 (_p)->dport = ntohs((_p)->dport); \
78 (_p)->type = ntohs((_p)->type); \
79 (_p)->opts = ntohs((_p)->opts); \
80 (_p)->cksum = ntohs((_p)->cksum); \
81 (_p)->tsdulen = ntohs((_p)->tsdulen)
83 /* The PGM SPM header */
85 nlong_t sqn; /* SPM's sequence number */
86 nlong_t trail; /* Trailing edge sequence number */
87 nlong_t lead; /* Leading edge sequence number */
88 nshort_t path_afi; /* NLA AFI */
89 nshort_t res; /* reserved */
90 nlong_t path; /* Path NLA */
92 static const size_t PGM_SPM_SZ = sizeof(pgm_type)+sizeof(pgm_spm_t);
93 #define spm_ntoh(_p) \
94 (_p)->sqn = ntohl((_p)->sqn); \
95 (_p)->trail = ntohl((_p)->trail); \
96 (_p)->lead = ntohl((_p)->lead); \
97 (_p)->path_afi = ntohs((_p)->path_afi); \
98 (_p)->res = ntohs((_p)->res);
100 /* The PGM Data (ODATA/RDATA) header */
102 nlong_t sqn; /* Data Packet sequence number */
103 nlong_t trail; /* Trailing edge sequence number */
105 #define data_ntoh(_p) \
106 (_p)->sqn = ntohl((_p)->sqn); \
107 (_p)->trail = ntohl((_p)->trail)
108 static const size_t PGM_DATA_HDR_SZ = sizeof(pgm_type)+sizeof(pgm_data_t);
110 /* The PGM NAK (NAK/N-NAK/NCF) header */
112 nlong_t sqn; /* Requested sequence number */
113 nshort_t src_afi; /* NLA AFI for source (IPv4 is set to 1) */
114 nshort_t src_res; /* reserved */
115 nlong_t src; /* Source NLA */
116 nshort_t grp_afi; /* Multicast group AFI (IPv4 is set to 1) */
117 nshort_t grp_res; /* reserved */
118 nlong_t grp; /* Multicast group NLA */
120 static const size_t PGM_NAK_SZ = sizeof(pgm_type)+sizeof(pgm_nak_t);
121 #define nak_ntoh(_p) \
122 (_p)->sqn = ntohl((_p)->sqn); \
123 (_p)->src_afi = ntohs((_p)->src_afi); \
124 (_p)->src_res = ntohs((_p)->src_res); \
125 (_p)->grp_afi = ntohs((_p)->grp_afi); \
126 (_p)->grp_res = ntohs((_p)->grp_res)
128 /* The PGM ACK header (PGMCC) */
130 nlong_t rx_max_sqn; /* RX_MAX sequence number */
131 nlong_t bitmap; /* Received Packet Bitmap */
133 static const size_t PGM_ACK_SZ = sizeof(pgm_type)+sizeof(pgm_ack_t);
134 #define ack_ntoh(_p) \
135 (_p)->rx_max_sqn = ntohl((_p)->rx_max_sqn); \
136 (_p)->bitmap = ntohl((_p)->bitmap)
138 /* constants for hdr types */
139 #if defined(PGM_SPEC_01_PCKTS)
140 /* old spec-01 types */
141 #define PGM_SPM_PCKT 0x00
142 #define PGM_ODATA_PCKT 0x10
143 #define PGM_RDATA_PCKT 0x11
144 #define PGM_NAK_PCKT 0x20
145 #define PGM_NNAK_PCKT 0x21
146 #define PGM_NCF_PCKT 0x30
148 /* spec-02 types (as well as spec-04+) */
149 #define PGM_SPM_PCKT 0x00
150 #define PGM_ODATA_PCKT 0x04
151 #define PGM_RDATA_PCKT 0x05
152 #define PGM_NAK_PCKT 0x08
153 #define PGM_NNAK_PCKT 0x09
154 #define PGM_NCF_PCKT 0x0A
155 #define PGM_ACK_PCKT 0x0D
156 #endif /* PGM_SPEC_01_PCKTS */
158 /* port swapping on NAK and NNAKs or not (default is to swap) */
159 /* PGM_NO_PORT_SWAP */
161 /* option flags (main PGM header) */
163 #define PGM_OPT_NETSIG 0x02
164 #define PGM_OPT_VAR_PKTLEN 0x40
165 #define PGM_OPT_PARITY 0x80
168 #define PGM_OPT_LENGTH 0x00
169 #define PGM_OPT_END 0x80
170 #define PGM_OPT_FRAGMENT 0x01
171 #define PGM_OPT_NAK_LIST 0x02
172 #define PGM_OPT_JOIN 0x03
173 #define PGM_OPT_REDIRECT 0x07
174 #define PGM_OPT_SYN 0x0D
175 #define PGM_OPT_FIN 0x0E
176 #define PGM_OPT_RST 0x0F
177 #define PGM_OPT_PARITY_PRM 0x08
178 #define PGM_OPT_PARITY_GRP 0x09
179 #define PGM_OPT_CURR_TGSIZE 0x0A
180 #define PGM_OPT_PGMCC_DATA 0x12
181 #define PGM_OPT_PGMCC_FEEDBACK 0x13
183 static const nchar_t PGM_OPT_INVALID = 0x7F;
186 #define PGM_OPX_IGNORE 0x00
187 #define PGM_OPX_INVAL 0x01
188 #define PGM_OPX_DISCARD 0x10
209 } pgm_opt_nak_list_t;
212 * To squeeze the whole option into 255 bytes, we
213 * can only have 62 in the list
215 #define PGM_MAX_NAK_LIST_SZ (62)
222 nlong_t opt_join_min;
231 } pgm_opt_parity_prm_t;
233 /* OPT_PARITY_PRM P and O bits */
234 static const nchar_t PGM_OPT_PARITY_PRM_PRO = 0x2;
235 static const nchar_t PGM_OPT_PARITY_PRM_OND = 0x1;
243 } pgm_opt_parity_grp_t;
251 } pgm_opt_curr_tgsize_t;
262 } pgm_opt_pgmcc_data_t;
273 } pgm_opt_pgmcc_feedback_t;
276 * Udp port for UDP encapsulation
278 #define DEFAULT_UDP_ENCAP_UCAST_PORT 3055
279 #define DEFAULT_UDP_ENCAP_MCAST_PORT 3056
281 static int udp_encap_ucast_port = 0;
282 static int udp_encap_mcast_port = 0;
283 static int old_encap_ucast_port = 0;
284 static int old_encap_mcast_port = 0;
286 static int proto_pgm = -1;
287 static int ett_pgm = -1;
288 static int ett_pgm_optbits = -1;
289 static int ett_pgm_opts = -1;
290 static int ett_pgm_spm = -1;
291 static int ett_pgm_data = -1;
292 static int ett_pgm_nak = -1;
293 static int ett_pgm_ack = -1;
294 static int ett_pgm_opts_join = -1;
295 static int ett_pgm_opts_parityprm = -1;
296 static int ett_pgm_opts_paritygrp = -1;
297 static int ett_pgm_opts_naklist = -1;
298 static int ett_pgm_opts_ccdata = -1;
300 static int hf_pgm_main_sport = -1;
301 static int hf_pgm_main_dport = -1;
302 static int hf_pgm_main_type = -1;
303 static int hf_pgm_main_opts = -1;
304 static int hf_pgm_main_opts_opt = -1;
305 static int hf_pgm_main_opts_netsig = -1;
306 static int hf_pgm_main_opts_varlen = -1;
307 static int hf_pgm_main_opts_parity = -1;
308 static int hf_pgm_main_cksum = -1;
309 static int hf_pgm_main_gsi = -1;
310 static int hf_pgm_main_tsdulen = -1;
311 static int hf_pgm_spm_sqn = -1;
312 static int hf_pgm_spm_lead = -1;
313 static int hf_pgm_spm_trail = -1;
314 static int hf_pgm_spm_pathafi = -1;
315 static int hf_pgm_spm_res = -1;
316 static int hf_pgm_spm_path = -1;
317 static int hf_pgm_data_sqn = -1;
318 static int hf_pgm_data_trail = -1;
319 static int hf_pgm_nak_sqn = -1;
320 static int hf_pgm_nak_srcafi = -1;
321 static int hf_pgm_nak_srcres = -1;
322 static int hf_pgm_nak_src = -1;
323 static int hf_pgm_nak_grpafi = -1;
324 static int hf_pgm_nak_grpres = -1;
325 static int hf_pgm_nak_grp = -1;
326 static int hf_pgm_ack_sqn = -1;
327 static int hf_pgm_ack_bitmap = -1;
329 static int hf_pgm_opt_type = -1;
330 static int hf_pgm_opt_len = -1;
331 static int hf_pgm_opt_tlen = -1;
333 static int hf_pgm_genopt_type = -1;
334 static int hf_pgm_genopt_len = -1;
335 static int hf_pgm_genopt_opx = -1;
337 static int hf_pgm_opt_join_res = -1;
338 static int hf_pgm_opt_join_minjoin = -1;
340 static int hf_pgm_opt_parity_prm_po = -1;
341 static int hf_pgm_opt_parity_prm_prmtgsz = -1;
343 static int hf_pgm_opt_parity_grp_res = -1;
344 static int hf_pgm_opt_parity_grp_prmgrp = -1;
346 #ifdef PGM_UNUSED_HANDLES
347 static int hf_pgm_opt_curr_tgsize_type = -1;
348 static int hf_pgm_opt_curr_tgsize_len = -1;
349 static int hf_pgm_opt_curr_tgsize_opx = -1;
350 static int hf_pgm_opt_curr_tgsize_res = -1;
351 static int hf_pgm_opt_curr_tgsize_prmatgsz = -1;
354 static int hf_pgm_opt_nak_res = -1;
355 static int hf_pgm_opt_nak_list = -1;
357 static int hf_pgm_opt_ccdata_res = -1;
358 static int hf_pgm_opt_ccdata_tsp = -1;
359 static int hf_pgm_opt_ccdata_afi = -1;
360 static int hf_pgm_opt_ccdata_res2 = -1;
361 static int hf_pgm_opt_ccdata_acker = -1;
363 static int hf_pgm_opt_ccfeedbk_res = -1;
364 static int hf_pgm_opt_ccfeedbk_tsp = -1;
365 static int hf_pgm_opt_ccfeedbk_afi = -1;
366 static int hf_pgm_opt_ccfeedbk_lossrate = -1;
367 static int hf_pgm_opt_ccfeedbk_acker = -1;
369 static dissector_table_t subdissector_table;
370 static heur_dissector_list_t heur_subdissector_list;
371 static dissector_handle_t data_handle;
374 * As of the time this comment was typed
376 * http://search.ietf.org/internet-drafts/draft-speakman-pgm-spec-06.txt
378 * was the URL for the PGM draft.
382 optsstr(nchar_t opts)
384 static char msg[256];
391 sprintf(p, "Present");
392 p += strlen("Present");
394 if (opts & PGM_OPT_NETSIG){
402 if (opts & PGM_OPT_VAR_PKTLEN){
410 if (opts & PGM_OPT_PARITY){
419 sprintf(p, "0x%x", opts);
424 paritystr(nchar_t parity)
426 static char msg[256];
432 if (parity & PGM_OPT_PARITY_PRM_PRO){
433 sprintf(p, "Pro-active");
434 p += strlen("Pro-active");
436 if (parity & PGM_OPT_PARITY_PRM_OND){
445 sprintf(p, "0x%x", parity);
450 static const value_string opt_vals[] = {
451 { PGM_OPT_LENGTH, "Length" },
452 { PGM_OPT_END, "End" },
453 { PGM_OPT_FRAGMENT, "Fragment" },
454 { PGM_OPT_NAK_LIST, "NakList" },
455 { PGM_OPT_JOIN, "Join" },
456 { PGM_OPT_REDIRECT, "ReDirect" },
457 { PGM_OPT_SYN, "Syn" },
458 { PGM_OPT_FIN, "Fin" },
459 { PGM_OPT_RST, "Rst" },
460 { PGM_OPT_PARITY_PRM, "ParityPrm" },
461 { PGM_OPT_PARITY_GRP, "ParityGrp" },
462 { PGM_OPT_CURR_TGSIZE, "CurrTgsiz" },
463 { PGM_OPT_PGMCC_DATA, "CcData" },
464 { PGM_OPT_PGMCC_FEEDBACK, "CcFeedBack" },
468 static const value_string opx_vals[] = {
469 { PGM_OPX_IGNORE, "Ignore" },
470 { PGM_OPX_INVAL, "Inval" },
471 { PGM_OPX_DISCARD, "DisCard" },
476 dissect_pgmopts(tvbuff_t *tvb, int offset, proto_tree *tree,
480 proto_tree *opts_tree = NULL;
481 proto_tree *opt_tree = NULL;
482 pgm_opt_length_t opts;
483 pgm_opt_generic_t genopts;
484 int theend = 0, firsttime = 1;
486 tvb_memcpy(tvb, (guint8 *)&opts, offset, sizeof(opts));
487 opts.total_len = ntohs(opts.total_len);
489 tf = proto_tree_add_text(tree, tvb, offset,
491 "%s Options (Total Length %d)", pktname, opts.total_len);
492 opts_tree = proto_item_add_subtree(tf, ett_pgm_opts);
493 proto_tree_add_uint(opts_tree, hf_pgm_opt_type, tvb,
494 offset, 1, opts.type);
495 proto_tree_add_uint(opts_tree, hf_pgm_opt_len, tvb,
496 offset+1, 1, opts.len);
497 proto_tree_add_uint(opts_tree, hf_pgm_opt_tlen, tvb,
498 offset+2, 2, opts.total_len);
501 for (opts.total_len -= 4; opts.total_len > 0;){
502 tvb_memcpy(tvb, (guint8 *)&genopts, offset, sizeof(genopts));
503 if (genopts.type & PGM_OPT_END) {
504 genopts.type &= ~PGM_OPT_END;
507 tf = proto_tree_add_text(opts_tree, tvb, offset, genopts.len,
508 "Option: %s, Length: %u",
509 val_to_str(genopts.type, opt_vals, "Unknown (0x%02x)"),
511 if (genopts.len == 0)
514 switch(genopts.type) {
516 pgm_opt_join_t optdata;
518 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
519 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_join);
521 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
522 tvb, offset, 1, genopts.type);
524 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
525 offset+1, 1, genopts.len);
527 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx, tvb,
528 offset+2, 1, genopts.opx);
530 proto_tree_add_uint(opt_tree, hf_pgm_opt_join_res, tvb,
531 offset+3, 1, optdata.res);
533 proto_tree_add_uint(opt_tree, hf_pgm_opt_join_minjoin, tvb,
534 offset+4, 4, ntohl(optdata.opt_join_min));
538 case PGM_OPT_PARITY_PRM:{
539 pgm_opt_parity_prm_t optdata;
541 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
542 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_parityprm);
544 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
545 tvb, offset, 1, genopts.type);
547 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
548 offset+1, 1, genopts.len);
550 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
551 tvb, offset+2, 1, genopts.opx);
553 proto_tree_add_uint_format(opt_tree, hf_pgm_opt_parity_prm_po, tvb,
554 offset+3, 1, optdata.po, "Parity Parameters: %s (0x%x)",
555 paritystr(optdata.po), optdata.po);
557 proto_tree_add_uint(opt_tree, hf_pgm_opt_parity_prm_prmtgsz,
558 tvb, offset+4, 4, ntohl(optdata.prm_tgsz));
562 case PGM_OPT_PARITY_GRP:{
563 pgm_opt_parity_grp_t optdata;
565 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
566 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_paritygrp);
568 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
569 tvb, offset, 1, genopts.type);
571 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
572 offset+1, 1, genopts.len);
574 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
575 tvb, offset+2, 1, genopts.opx);
577 proto_tree_add_uint(opt_tree, hf_pgm_opt_parity_grp_res, tvb,
578 offset+3, 1, optdata.res);
580 proto_tree_add_uint(opt_tree, hf_pgm_opt_parity_grp_prmgrp,
581 tvb, offset+4, 4, ntohl(optdata.prm_grp));
585 case PGM_OPT_NAK_LIST:{
586 pgm_opt_nak_list_t optdata;
587 nlong_t naklist[PGM_MAX_NAK_LIST_SZ+1];
588 char nakbuf[8192], *ptr;
589 int i, j, naks, soffset = 0;
591 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
592 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_naklist);
594 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type, tvb,
595 offset, 1, genopts.type);
597 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
598 offset+1, 1, genopts.len);
600 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
601 tvb, offset+2, 1, genopts.opx);
603 proto_tree_add_uint(opt_tree, hf_pgm_opt_nak_res, tvb,
604 offset+3, 1, optdata.res);
606 optdata.len -= sizeof(pgm_opt_nak_list_t);
607 tvb_memcpy(tvb, (guint8 *)naklist, offset+4, optdata.len);
608 naks = (optdata.len/sizeof(nlong_t));
612 * Print out 8 per line
614 for (i=0; i < naks; i++) {
615 sprintf(nakbuf+soffset, "0x%lx ",
616 (unsigned long)ntohl(naklist[i]));
617 soffset = strlen(nakbuf);
618 if ((++j % 8) == 0) {
620 proto_tree_add_bytes_format(opt_tree,
621 hf_pgm_opt_nak_list, tvb, offset+4, optdata.len,
622 nakbuf, "List(%d): %s", naks, nakbuf);
625 proto_tree_add_bytes_format(opt_tree,
626 hf_pgm_opt_nak_list, tvb, offset+4, optdata.len,
627 nakbuf, "List: %s", nakbuf);
635 proto_tree_add_bytes_format(opt_tree,
636 hf_pgm_opt_nak_list, tvb, offset+4, optdata.len,
637 nakbuf, "List(%d): %s", naks, nakbuf);
640 proto_tree_add_bytes_format(opt_tree,
641 hf_pgm_opt_nak_list, tvb, offset+4, optdata.len,
642 nakbuf, "List: %s", nakbuf);
648 case PGM_OPT_PGMCC_DATA:{
649 pgm_opt_pgmcc_data_t optdata;
651 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
652 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_ccdata);
654 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
655 tvb, offset, 1, genopts.type);
657 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
658 offset+1, 1, genopts.len);
660 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
661 tvb, offset+2, 1, genopts.opx);
663 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccdata_res, tvb,
664 offset+3, 1, optdata.res);
666 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccdata_tsp, tvb,
667 offset+4, 4, optdata.tsp);
669 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccdata_afi, tvb,
670 offset+8, 2, ntohs(optdata.acker_afi));
672 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccdata_res2, tvb,
673 offset+10, 2, ntohs(optdata.res2));
675 switch (ntohs(optdata.acker_afi)) {
678 proto_tree_add_ipv4(opt_tree, hf_pgm_opt_ccdata_acker,
679 tvb, offset+12, 4, optdata.acker);
684 * XXX - the header is variable-length,
685 * as the length of the NLA depends on
688 * However, our structure for it is
689 * fixed-length, and assumes it's a 4-byte
697 case PGM_OPT_PGMCC_FEEDBACK:{
698 pgm_opt_pgmcc_feedback_t optdata;
700 tvb_memcpy(tvb, (guint8 *)&optdata, offset, sizeof(optdata));
701 opt_tree = proto_item_add_subtree(tf, ett_pgm_opts_ccdata);
703 proto_tree_add_uint(opt_tree, hf_pgm_genopt_type,
704 tvb, offset, 1, genopts.type);
706 proto_tree_add_uint(opt_tree, hf_pgm_genopt_len, tvb,
707 offset+1, 1, genopts.len);
709 proto_tree_add_uint(opt_tree, hf_pgm_genopt_opx,
710 tvb, offset+2, 1, genopts.opx);
712 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccfeedbk_res, tvb,
713 offset+3, 1, optdata.res);
715 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccfeedbk_tsp, tvb,
716 offset+4, 4, optdata.tsp);
718 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccfeedbk_afi, tvb,
719 offset+8, 2, ntohs(optdata.acker_afi));
721 proto_tree_add_uint(opt_tree, hf_pgm_opt_ccfeedbk_lossrate, tvb,
722 offset+10, 2, ntohs(optdata.loss_rate));
724 switch (ntohs(optdata.acker_afi)) {
727 proto_tree_add_ipv4(opt_tree, hf_pgm_opt_ccfeedbk_acker,
728 tvb, offset+12, 4, optdata.acker);
733 * XXX - the header is variable-length,
734 * as the length of the NLA depends on
737 * However, our structure for it is
738 * fixed-length, and assumes it's a 4-byte
747 offset += genopts.len;
748 opts.total_len -= genopts.len;
754 static const value_string type_vals[] = {
755 { PGM_SPM_PCKT, "SPM" },
756 { PGM_RDATA_PCKT, "RDATA" },
757 { PGM_ODATA_PCKT, "ODATA" },
758 { PGM_NAK_PCKT, "NAK" },
759 { PGM_NNAK_PCKT, "NNAK" },
760 { PGM_NCF_PCKT, "NCF" },
761 { PGM_ACK_PCKT, "ACK" },
764 /* Determine if there is a sub-dissector and call it. This has been */
765 /* separated into a stand alone routine to other protocol dissectors */
766 /* can call to it, ie. socks */
769 decode_pgm_ports(tvbuff_t *tvb, int offset, packet_info *pinfo,
770 proto_tree *tree, pgm_type *pgmhdr)
775 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
777 /* do lookup with the subdissector table */
778 found = dissector_try_port(subdissector_table, pgmhdr->sport,
779 next_tvb, pinfo, tree);
783 found = dissector_try_port(subdissector_table, pgmhdr->dport,
784 next_tvb, pinfo, tree);
788 /* do lookup with the heuristic subdissector table */
789 if (dissector_try_heuristic(heur_subdissector_list, next_tvb, pinfo, tree))
792 /* Oh, well, we don't know this; dissect it as data. */
793 call_dissector(data_handle,next_tvb, pinfo, tree);
797 total_size(tvbuff_t *tvb, pgm_type *hdr)
799 int bytes = sizeof(pgm_type);
800 pgm_opt_length_t opts;
804 bytes += sizeof(pgm_spm_t);
809 bytes += sizeof(pgm_data_t);
815 bytes += sizeof(pgm_nak_t);
818 bytes += sizeof(pgm_ack_t);
821 if ((hdr->opts & PGM_OPT)) {
822 tvb_memcpy(tvb, (guint8 *)&opts, bytes, sizeof(opts));
823 bytes += ntohs(opts.total_len);
828 * dissect_pgm - The dissector for Pragmatic General Multicast
831 dissect_pgm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
833 proto_tree *pgm_tree = NULL;
834 proto_tree *opt_tree = NULL;
835 proto_tree *type_tree = NULL;
849 if (check_col(pinfo->cinfo, COL_PROTOCOL))
850 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PGM");
852 /* Clear out the Info column. */
853 if (check_col(pinfo->cinfo, COL_INFO))
854 col_clear(pinfo->cinfo, COL_INFO);
856 tvb_memcpy(tvb, (guint8 *)&pgmhdr, offset, sizeof(pgm_type));
857 hlen = sizeof(pgm_type);
858 pgmhdr.sport = ntohs(pgmhdr.sport);
859 pgmhdr.dport = ntohs(pgmhdr.dport);
860 pgmhdr.tsdulen = ntohs(pgmhdr.tsdulen);
862 pktname = val_to_str(pgmhdr.type, type_vals, "Unknown (0x%02x)");
864 gsi = bytes_to_str(pgmhdr.gsi, 6);
865 switch(pgmhdr.type) {
867 plen = sizeof(pgm_spm_t);
868 tvb_memcpy(tvb, (guint8 *)&spm, sizeof(pgm_type), plen);
870 if (check_col(pinfo->cinfo, COL_INFO)) {
871 col_add_fstr(pinfo->cinfo, COL_INFO,
872 "%-5s sqn 0x%x gsi %s", pktname, spm.sqn, gsi);
878 plen = sizeof(pgm_data_t);
879 tvb_memcpy(tvb, (guint8 *)&data, sizeof(pgm_type), plen);
881 if (check_col(pinfo->cinfo, COL_INFO)) {
882 col_add_fstr(pinfo->cinfo, COL_INFO,
883 "%-5s sqn 0x%x gsi %s tsdulen %d", pktname, data.sqn, gsi,
892 plen = sizeof(pgm_nak_t);
893 tvb_memcpy(tvb, (guint8 *)&nak, sizeof(pgm_type), plen);
895 if (check_col(pinfo->cinfo, COL_INFO)) {
896 col_add_fstr(pinfo->cinfo, COL_INFO,
897 "%-5s sqn 0x%x gsi %s", pktname, nak.sqn, gsi);
901 plen = sizeof(pgm_ack_t);
902 tvb_memcpy(tvb, (guint8 *)&ack, sizeof(pgm_type), plen);
904 if (check_col(pinfo->cinfo, COL_INFO)) {
905 col_add_fstr(pinfo->cinfo, COL_INFO,
906 "%-5s sqn 0x%x gsi %s", pktname, ack.rx_max_sqn, gsi);
915 ti = proto_tree_add_protocol_format(tree, proto_pgm,
916 tvb, offset, total_size(tvb, &pgmhdr),
917 "Pragmatic General Multicast: Type %s"
918 " SrcPort %u, DstPort %u, GSI %s", pktname,
919 pgmhdr.sport, pgmhdr.dport,
920 bytes_to_str(pgmhdr.gsi, 6));
922 pgm_tree = proto_item_add_subtree(ti, ett_pgm);
923 proto_tree_add_uint(pgm_tree, hf_pgm_main_sport, tvb, offset, 2,
925 proto_tree_add_uint(pgm_tree, hf_pgm_main_dport, tvb, offset+2,
927 proto_tree_add_uint(pgm_tree, hf_pgm_main_type, tvb,
928 offset+4, 1, pgmhdr.type);
930 tf = proto_tree_add_uint_format(pgm_tree, hf_pgm_main_opts, tvb,
931 offset+5, 1, pgmhdr.opts, "Options: %s (0x%x)",
932 optsstr(pgmhdr.opts), pgmhdr.opts);
933 opt_tree = proto_item_add_subtree(tf, ett_pgm_optbits);
935 proto_tree_add_boolean(opt_tree, hf_pgm_main_opts_opt, tvb,
936 offset+5, 1, (pgmhdr.opts & PGM_OPT));
937 proto_tree_add_boolean(opt_tree, hf_pgm_main_opts_netsig, tvb,
938 offset+5, 1, (pgmhdr.opts & PGM_OPT_NETSIG));
939 proto_tree_add_boolean(opt_tree, hf_pgm_main_opts_varlen, tvb,
940 offset+5, 1, (pgmhdr.opts & PGM_OPT_VAR_PKTLEN));
941 proto_tree_add_boolean(opt_tree, hf_pgm_main_opts_parity, tvb,
942 offset+5, 1, (pgmhdr.opts & PGM_OPT_PARITY));
944 proto_tree_add_uint(pgm_tree, hf_pgm_main_cksum, tvb, offset+6,
946 proto_tree_add_bytes(pgm_tree, hf_pgm_main_gsi, tvb, offset+8,
948 proto_tree_add_uint(pgm_tree, hf_pgm_main_tsdulen, tvb,
949 offset+14, 2, pgmhdr.tsdulen);
951 offset = sizeof(pgm_type);
952 tf = proto_tree_add_text(pgm_tree, tvb, offset, plen, "%s Packet",
954 switch(pgmhdr.type) {
956 type_tree = proto_item_add_subtree(tf, ett_pgm_spm);
958 proto_tree_add_uint(type_tree, hf_pgm_spm_sqn, tvb,
960 proto_tree_add_uint(type_tree, hf_pgm_spm_trail, tvb,
961 offset+4, 4, spm.trail);
962 proto_tree_add_uint(type_tree, hf_pgm_spm_lead, tvb,
963 offset+8, 4, spm.lead);
964 proto_tree_add_uint(type_tree, hf_pgm_spm_pathafi, tvb,
965 offset+10, 2, spm.path_afi);
966 proto_tree_add_uint(type_tree, hf_pgm_spm_res, tvb,
967 offset+12, 2, spm.res);
968 switch (spm.path_afi) {
971 proto_tree_add_ipv4(type_tree, hf_pgm_spm_path,
972 tvb, offset+14, 4, spm.path);
977 * XXX - the header is variable-length,
978 * as the length of the NLA depends on
981 * However, our structure for it is
982 * fixed-length, and assumes it's a 4-byte
988 if ((pgmhdr.opts & PGM_OPT) == FALSE)
992 dissect_pgmopts(tvb, offset, type_tree, pktname);
997 case PGM_ODATA_PCKT: {
998 type_tree = proto_item_add_subtree(tf, ett_pgm_data);
1000 proto_tree_add_uint(type_tree, hf_pgm_spm_sqn, tvb,
1001 offset, 4, data.sqn);
1002 proto_tree_add_uint(type_tree, hf_pgm_spm_trail, tvb,
1003 offset+4, 4, data.trail);
1005 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1009 dissect_pgmopts(tvb, offset, type_tree, pktname);
1018 type_tree = proto_item_add_subtree(tf, ett_pgm_nak);
1020 proto_tree_add_uint(type_tree, hf_pgm_nak_sqn, tvb,
1021 offset, 4, nak.sqn);
1022 proto_tree_add_uint(type_tree, hf_pgm_nak_srcafi, tvb,
1023 offset+4, 2, nak.src_afi);
1024 proto_tree_add_uint(type_tree, hf_pgm_nak_srcres, tvb,
1025 offset+6, 2, nak.src_res);
1027 switch (nak.src_afi) {
1030 proto_tree_add_ipv4(type_tree, hf_pgm_nak_src,
1031 tvb, offset+8, 4, nak.src);
1036 * XXX - the header is variable-length,
1037 * as the length of the NLA depends on
1040 * However, our structure for it is
1041 * fixed-length, and assumes it's a 4-byte
1047 proto_tree_add_uint(type_tree, hf_pgm_nak_grpafi, tvb,
1048 offset+12, 2, nak.grp_afi);
1049 proto_tree_add_uint(type_tree, hf_pgm_nak_grpres, tvb,
1050 offset+14, 2, nak.grp_res);
1052 switch (nak.grp_afi) {
1055 proto_tree_add_ipv4(type_tree, hf_pgm_nak_grp,
1056 tvb, offset+16, 4, nak.grp);
1061 * XXX - the header is variable-length,
1062 * as the length of the NLA depends on
1065 * However, our structure for it is
1066 * fixed-length, and assumes it's a 4-byte
1072 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1076 dissect_pgmopts(tvb, offset, type_tree, pktname);
1080 type_tree = proto_item_add_subtree(tf, ett_pgm_ack);
1082 proto_tree_add_uint(type_tree, hf_pgm_ack_sqn, tvb,
1083 offset, 4, ack.rx_max_sqn);
1084 proto_tree_add_uint(type_tree, hf_pgm_ack_bitmap, tvb,
1085 offset+4, 4, ack.bitmap);
1087 if ((pgmhdr.opts & PGM_OPT) == FALSE)
1091 dissect_pgmopts(tvb, offset, type_tree, pktname);
1099 * Now see if there are any sub-dissectors, if so call them
1101 offset = total_size(tvb, &pgmhdr);
1102 decode_pgm_ports(tvb, offset, pinfo, tree, &pgmhdr);
1106 static const true_false_string opts_present = {
1111 /* Register all the bits needed with the filtering engine */
1113 proto_register_pgm(void)
1115 static hf_register_info hf[] = {
1116 { &hf_pgm_main_sport,
1117 { "Source Port", "pgm.hdr.sport", FT_UINT16, BASE_DEC,
1118 NULL, 0x0, "", HFILL }},
1119 { &hf_pgm_main_dport,
1120 { "Destination Port", "pgm.hdr.dport", FT_UINT16, BASE_DEC,
1121 NULL, 0x0, "", HFILL }},
1122 { &hf_pgm_main_type,
1123 { "Type", "pgm.hdr.type", FT_UINT8, BASE_HEX,
1124 VALS(type_vals), 0x0, "", HFILL }},
1125 { &hf_pgm_main_opts,
1126 { "Options", "pgm.hdr.opts", FT_UINT8, BASE_HEX,
1127 NULL, 0x0, "", HFILL }},
1128 { &hf_pgm_main_opts_opt,
1129 { "Options", "pgm.hdr.opts.opt", FT_BOOLEAN, BASE_NONE,
1130 TFS(&opts_present), PGM_OPT, "", HFILL }},
1131 { &hf_pgm_main_opts_netsig,
1132 { "Network Significant Options", "pgm.hdr.opts.netsig",
1133 FT_BOOLEAN, BASE_NONE,
1134 TFS(&opts_present), PGM_OPT_NETSIG, "", HFILL }},
1135 { &hf_pgm_main_opts_varlen,
1136 { "Variable length Parity Packet Option", "pgm.hdr.opts.varlen",
1137 FT_BOOLEAN, BASE_NONE,
1138 TFS(&opts_present), PGM_OPT_VAR_PKTLEN, "", HFILL }},
1139 { &hf_pgm_main_opts_parity,
1140 { "Parity", "pgm.hdr.opts.parity", FT_BOOLEAN, BASE_NONE,
1141 TFS(&opts_present), PGM_OPT_PARITY, "", HFILL }},
1142 { &hf_pgm_main_cksum,
1143 { "Checksum", "pgm.hdr.cksum", FT_UINT16, BASE_HEX,
1144 NULL, 0x0, "", HFILL }},
1146 { "Global Source Identifier", "pgm.hdr.gsi", FT_BYTES, BASE_HEX,
1147 NULL, 0x0, "", HFILL }},
1148 { &hf_pgm_main_tsdulen,
1149 { "Transport Service Data Unit Length", "pgm.hdr.tsdulen", FT_UINT16,
1150 BASE_DEC, NULL, 0x0, "", HFILL }},
1152 { "Sequence number", "pgm.spm.sqn", FT_UINT32, BASE_HEX,
1153 NULL, 0x0, "", HFILL }},
1154 { &hf_pgm_spm_trail,
1155 { "Trailing Edge Sequence Number", "pgm.spm.trail", FT_UINT32, BASE_HEX,
1156 NULL, 0x0, "", HFILL }},
1158 { "Leading Edge Sequence Number", "pgm.spm.lead", FT_UINT32, BASE_HEX,
1159 NULL, 0x0, "", HFILL }},
1160 { &hf_pgm_spm_pathafi,
1161 { "Path NLA AFI", "pgm.spm.pathafi", FT_UINT16, BASE_DEC,
1162 VALS(afn_vals), 0x0, "", HFILL }},
1164 { "Reserved", "pgm.spm.res", FT_UINT16, BASE_HEX,
1165 NULL, 0x0, "", HFILL }},
1167 { "Path NLA", "pgm.spm.path", FT_IPv4, BASE_NONE,
1168 NULL, 0x0, "", HFILL }},
1170 { "Data Packet Sequence Number", "pgm.data.sqn", FT_UINT32, BASE_HEX,
1171 NULL, 0x0, "", HFILL }},
1172 { &hf_pgm_data_trail,
1173 { "Trailing Edge Sequence Number", "pgm.data.trail", FT_UINT32, BASE_HEX,
1174 NULL, 0x0, "", HFILL }},
1176 { "Requested Sequence Number", "pgm.nak.sqn", FT_UINT32, BASE_HEX,
1177 NULL, 0x0, "", HFILL }},
1178 { &hf_pgm_nak_srcafi,
1179 { "Source NLA AFI", "pgm.nak.srcafi", FT_UINT16, BASE_DEC,
1180 VALS(afn_vals), 0x0, "", HFILL }},
1181 { &hf_pgm_nak_srcres,
1182 { "Reserved", "pgm.nak.srcres", FT_UINT16, BASE_HEX,
1183 NULL, 0x0, "", HFILL }},
1185 { "Source NLA", "pgm.nak.src", FT_IPv4, BASE_NONE,
1186 NULL, 0x0, "", HFILL }},
1187 { &hf_pgm_nak_grpafi,
1188 { "Multicast Group AFI", "pgm.nak.grpafi", FT_UINT16, BASE_DEC,
1189 VALS(afn_vals), 0x0, "", HFILL }},
1190 { &hf_pgm_nak_grpres,
1191 { "Reserved", "pgm.nak.grpres", FT_UINT16, BASE_HEX,
1192 NULL, 0x0, "", HFILL }},
1194 { "Multicast Group NLA", "pgm.nak.grp", FT_IPv4, BASE_NONE,
1195 NULL, 0x0, "", HFILL }},
1197 { "Maximum Received Sequence Number", "pgm.ack.maxsqn", FT_UINT32,
1198 BASE_HEX, NULL, 0x0, "", HFILL }},
1199 { &hf_pgm_ack_bitmap,
1200 { "Packet Bitmap", "pgm.ack.bitmap", FT_UINT32, BASE_HEX,
1201 NULL, 0x0, "", HFILL }},
1203 { "Type", "pgm.opts.type", FT_UINT8, BASE_HEX,
1204 VALS(opt_vals), 0x0, "", HFILL }},
1206 { "Length", "pgm.opts.len", FT_UINT8, BASE_DEC,
1207 NULL, 0x0, "", HFILL }},
1209 { "Total Length", "pgm.opts.tlen", FT_UINT16, BASE_DEC,
1210 NULL, 0x0, "", HFILL }},
1211 { &hf_pgm_genopt_type,
1212 { "Type", "pgm.genopts.type", FT_UINT8, BASE_HEX,
1213 VALS(opt_vals), 0x0, "", HFILL }},
1214 { &hf_pgm_genopt_len,
1215 { "Length", "pgm.genopts.len", FT_UINT8, BASE_DEC,
1216 NULL, 0x0, "", HFILL }},
1217 { &hf_pgm_genopt_opx,
1218 { "Option Extensibility Bits", "pgm.genopts.opx", FT_UINT8, BASE_HEX,
1219 VALS(opx_vals), 0x0, "", HFILL }},
1220 { &hf_pgm_opt_parity_prm_po,
1221 { "Parity Parameters", "pgm.opts.parity_prm.op", FT_UINT8, BASE_HEX,
1222 NULL, 0x0, "", HFILL }},
1223 { &hf_pgm_opt_parity_prm_prmtgsz,
1224 { "Transmission Group Size", "pgm.opts.parity_prm.prm_grp",
1225 FT_UINT32, BASE_HEX,
1226 NULL, 0x0, "", HFILL }},
1227 { &hf_pgm_opt_join_res,
1228 { "Reserved", "pgm.opts.join.res", FT_UINT8, BASE_HEX,
1229 NULL, 0x0, "", HFILL }},
1230 { &hf_pgm_opt_join_minjoin,
1231 { "Minimum Sequence Number", "pgm.opts.join.min_join",
1232 FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
1233 { &hf_pgm_opt_parity_grp_res,
1234 { "Reserved", "pgm.opts.parity_prm.op", FT_UINT8, BASE_HEX,
1235 NULL, 0x0, "", HFILL }},
1236 { &hf_pgm_opt_parity_grp_prmgrp,
1237 { "Transmission Group Size", "pgm.opts.parity_prm.prm_grp",
1238 FT_UINT32, BASE_HEX,
1239 NULL, 0x0, "", HFILL }},
1240 { &hf_pgm_opt_nak_res,
1241 { "Reserved", "pgm.opts.nak.op", FT_UINT8, BASE_HEX,
1242 NULL, 0x0, "", HFILL }},
1243 { &hf_pgm_opt_nak_list,
1244 { "List", "pgm.opts.nak.list", FT_BYTES, BASE_NONE,
1245 NULL, 0x0, "", HFILL }},
1246 { &hf_pgm_opt_ccdata_res,
1247 { "Reserved", "pgm.opts.ccdata.res", FT_UINT8, BASE_DEC,
1248 NULL, 0x0, "", HFILL }},
1249 { &hf_pgm_opt_ccdata_tsp,
1250 { "Time Stamp", "pgm.opts.ccdata.tstamp", FT_UINT16, BASE_HEX,
1251 NULL, 0x0, "", HFILL }},
1252 { &hf_pgm_opt_ccdata_afi,
1253 { "Acker AFI", "pgm.opts.ccdata.afi", FT_UINT16, BASE_DEC,
1254 VALS(afn_vals), 0x0, "", HFILL }},
1255 { &hf_pgm_opt_ccdata_res2,
1256 { "Reserved", "pgm.opts.ccdata.res2", FT_UINT16, BASE_DEC,
1257 NULL, 0x0, "", HFILL }},
1258 { &hf_pgm_opt_ccdata_acker,
1259 { "Acker", "pgm.opts.ccdata.acker", FT_IPv4, BASE_NONE,
1260 NULL, 0x0, "", HFILL }},
1261 { &hf_pgm_opt_ccfeedbk_res,
1262 { "Reserved", "pgm.opts.ccdata.res", FT_UINT8, BASE_DEC,
1263 NULL, 0x0, "", HFILL }},
1264 { &hf_pgm_opt_ccfeedbk_tsp,
1265 { "Time Stamp", "pgm.opts.ccdata.tstamp", FT_UINT16, BASE_HEX,
1266 NULL, 0x0, "", HFILL }},
1267 { &hf_pgm_opt_ccfeedbk_afi,
1268 { "Acker AFI", "pgm.opts.ccdata.afi", FT_UINT16, BASE_DEC,
1269 VALS(afn_vals), 0x0, "", HFILL }},
1270 { &hf_pgm_opt_ccfeedbk_lossrate,
1271 { "Loss Rate", "pgm.opts.ccdata.lossrate", FT_UINT16, BASE_HEX,
1272 NULL, 0x0, "", HFILL }},
1273 { &hf_pgm_opt_ccfeedbk_acker,
1274 { "Acker", "pgm.opts.ccdata.acker", FT_IPv4, BASE_NONE,
1275 NULL, 0x0, "", HFILL }},
1277 static gint *ett[] = {
1286 &ett_pgm_opts_parityprm,
1287 &ett_pgm_opts_paritygrp,
1288 &ett_pgm_opts_naklist,
1289 &ett_pgm_opts_ccdata,
1291 module_t *pgm_module;
1293 proto_pgm = proto_register_protocol("Pragmatic General Multicast",
1296 proto_register_field_array(proto_pgm, hf, array_length(hf));
1297 proto_register_subtree_array(ett, array_length(ett));
1299 /* subdissector code */
1300 subdissector_table = register_dissector_table("pgm.port",
1301 "PGM port", FT_UINT16, BASE_DEC);
1302 register_heur_dissector_list("pgm", &heur_subdissector_list);
1305 * Register configuration preferences for UDP encapsulation
1306 * (Note: Initially the ports are set to zero so the
1307 * dissecting of PGM encapsulated in UPD packets
1308 * is off by default)
1310 pgm_module = prefs_register_protocol(proto_pgm, proto_rereg_pgm);
1312 prefs_register_uint_preference(pgm_module, "udp.encap_ucast_port",
1313 "PGM Encap Unicast Port (standard is 3055)",
1314 "PGM Encap is PGM packets encapsulated in UDP packets"
1315 " (Note: This option is off, i.e. port is 0, by default)",
1316 10, &udp_encap_ucast_port);
1317 old_encap_ucast_port = udp_encap_ucast_port;
1319 prefs_register_uint_preference(pgm_module, "udp.encap_mcast_port",
1320 "PGM Encap Multicast Port (standard is 3056)",
1321 "PGM Encap is PGM packets encapsulated in UDP packets"
1322 " (Note: This option is off, i.e. port is 0, by default)",
1323 10, &udp_encap_mcast_port);
1325 old_encap_mcast_port = udp_encap_mcast_port;
1328 static dissector_handle_t pgm_handle;
1330 /* The registration hand-off routine */
1332 proto_reg_handoff_pgm(void)
1334 pgm_handle = create_dissector_handle(dissect_pgm, proto_pgm);
1337 * Set up PGM Encap dissecting, which is off by default
1339 dissector_add("udp.port", udp_encap_ucast_port, pgm_handle);
1340 dissector_add("udp.port", udp_encap_mcast_port, pgm_handle);
1342 dissector_add("ip.proto", IP_PROTO_PGM, pgm_handle);
1344 data_handle = find_dissector("data");
1348 proto_rereg_pgm(void)
1351 * Remove the old ones
1353 dissector_delete("udp.port", old_encap_ucast_port, pgm_handle);
1354 dissector_delete("udp.port", old_encap_mcast_port, pgm_handle);
1359 dissector_add("udp.port", udp_encap_ucast_port, pgm_handle);
1360 dissector_add("udp.port", udp_encap_mcast_port, pgm_handle);