Home | History | Annotate | Line # | Download | only in dist
print-igmp.c revision 1.1.1.6
      1      1.1  christos /*
      2      1.1  christos  * Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996
      3      1.1  christos  *  The Regents of the University of California.  All rights reserved.
      4      1.1  christos  *
      5      1.1  christos  * Redistribution and use in source and binary forms, with or without
      6      1.1  christos  * modification, are permitted provided that: (1) source code distributions
      7      1.1  christos  * retain the above copyright notice and this paragraph in its entirety, (2)
      8      1.1  christos  * distributions including binary code include the above copyright notice and
      9      1.1  christos  * this paragraph in its entirety in the documentation or other materials
     10      1.1  christos  * provided with the distribution, and (3) all advertising materials mentioning
     11      1.1  christos  * features or use of this software display the following acknowledgement:
     12      1.1  christos  * ``This product includes software developed by the University of California,
     13      1.1  christos  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
     14      1.1  christos  * the University nor the names of its contributors may be used to endorse
     15      1.1  christos  * or promote products derived from this software without specific prior
     16      1.1  christos  * written permission.
     17      1.1  christos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
     18      1.1  christos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
     19      1.1  christos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
     20      1.1  christos  */
     21      1.1  christos 
     22  1.1.1.6       spz /* \summary: Internet Group Management Protocol (IGMP) printer */
     23  1.1.1.6       spz 
     24      1.1  christos #ifdef HAVE_CONFIG_H
     25      1.1  christos #include "config.h"
     26      1.1  christos #endif
     27      1.1  christos 
     28  1.1.1.5  christos #include <netdissect-stdinc.h>
     29      1.1  christos 
     30  1.1.1.5  christos #include "netdissect.h"
     31      1.1  christos #include "addrtoname.h"
     32  1.1.1.5  christos #include "extract.h"
     33      1.1  christos 
     34      1.1  christos #ifndef IN_CLASSD
     35      1.1  christos #define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000)
     36      1.1  christos #endif
     37      1.1  christos 
     38  1.1.1.4  christos static const char tstr[] = "[|igmp]";
     39  1.1.1.4  christos 
     40      1.1  christos /* (following from ipmulti/mrouted/prune.h) */
     41      1.1  christos 
     42      1.1  christos /*
     43      1.1  christos  * The packet format for a traceroute request.
     44      1.1  christos  */
     45      1.1  christos struct tr_query {
     46  1.1.1.4  christos     uint32_t  tr_src;          /* traceroute source */
     47  1.1.1.4  christos     uint32_t  tr_dst;          /* traceroute destination */
     48  1.1.1.4  christos     uint32_t  tr_raddr;        /* traceroute response address */
     49  1.1.1.4  christos     uint32_t  tr_rttlqid;      /* response ttl and qid */
     50      1.1  christos };
     51      1.1  christos 
     52      1.1  christos #define TR_GETTTL(x)        (int)(((x) >> 24) & 0xff)
     53      1.1  christos #define TR_GETQID(x)        ((x) & 0x00ffffff)
     54      1.1  christos 
     55      1.1  christos /*
     56      1.1  christos  * Traceroute response format.  A traceroute response has a tr_query at the
     57      1.1  christos  * beginning, followed by one tr_resp for each hop taken.
     58      1.1  christos  */
     59      1.1  christos struct tr_resp {
     60  1.1.1.4  christos     uint32_t tr_qarr;          /* query arrival time */
     61  1.1.1.4  christos     uint32_t tr_inaddr;        /* incoming interface address */
     62  1.1.1.4  christos     uint32_t tr_outaddr;       /* outgoing interface address */
     63  1.1.1.4  christos     uint32_t tr_rmtaddr;       /* parent address in source tree */
     64  1.1.1.4  christos     uint32_t tr_vifin;         /* input packet count on interface */
     65  1.1.1.4  christos     uint32_t tr_vifout;        /* output packet count on interface */
     66  1.1.1.4  christos     uint32_t tr_pktcnt;        /* total incoming packets for src-grp */
     67  1.1.1.4  christos     uint8_t  tr_rproto;      /* routing proto deployed on router */
     68  1.1.1.4  christos     uint8_t  tr_fttl;        /* ttl required to forward on outvif */
     69  1.1.1.4  christos     uint8_t  tr_smask;       /* subnet mask for src addr */
     70  1.1.1.4  christos     uint8_t  tr_rflags;      /* forwarding error codes */
     71      1.1  christos };
     72      1.1  christos 
     73      1.1  christos /* defs within mtrace */
     74      1.1  christos #define TR_QUERY 1
     75      1.1  christos #define TR_RESP 2
     76      1.1  christos 
     77      1.1  christos /* fields for tr_rflags (forwarding error codes) */
     78      1.1  christos #define TR_NO_ERR   0
     79      1.1  christos #define TR_WRONG_IF 1
     80      1.1  christos #define TR_PRUNED   2
     81      1.1  christos #define TR_OPRUNED  3
     82      1.1  christos #define TR_SCOPED   4
     83      1.1  christos #define TR_NO_RTE   5
     84      1.1  christos #define TR_NO_FWD   7
     85      1.1  christos #define TR_NO_SPACE 0x81
     86      1.1  christos #define TR_OLD_ROUTER   0x82
     87      1.1  christos 
     88      1.1  christos /* fields for tr_rproto (routing protocol) */
     89      1.1  christos #define TR_PROTO_DVMRP  1
     90      1.1  christos #define TR_PROTO_MOSPF  2
     91      1.1  christos #define TR_PROTO_PIM    3
     92      1.1  christos #define TR_PROTO_CBT    4
     93      1.1  christos 
     94      1.1  christos /* igmpv3 report types */
     95  1.1.1.3  christos static const struct tok igmpv3report2str[] = {
     96      1.1  christos 	{ 1,	"is_in" },
     97      1.1  christos 	{ 2,	"is_ex" },
     98      1.1  christos 	{ 3,	"to_in" },
     99      1.1  christos 	{ 4,	"to_ex" },
    100      1.1  christos 	{ 5,	"allow" },
    101      1.1  christos 	{ 6,	"block" },
    102      1.1  christos 	{ 0,	NULL }
    103      1.1  christos };
    104      1.1  christos 
    105      1.1  christos static void
    106  1.1.1.4  christos print_mtrace(netdissect_options *ndo,
    107  1.1.1.4  christos              register const u_char *bp, register u_int len)
    108      1.1  christos {
    109      1.1  christos     register const struct tr_query *tr = (const struct tr_query *)(bp + 8);
    110      1.1  christos 
    111  1.1.1.4  christos     ND_TCHECK(*tr);
    112      1.1  christos     if (len < 8 + sizeof (struct tr_query)) {
    113  1.1.1.4  christos 	ND_PRINT((ndo, " [invalid len %d]", len));
    114      1.1  christos 	return;
    115      1.1  christos     }
    116  1.1.1.4  christos     ND_PRINT((ndo, "mtrace %u: %s to %s reply-to %s",
    117      1.1  christos         TR_GETQID(EXTRACT_32BITS(&tr->tr_rttlqid)),
    118  1.1.1.4  christos         ipaddr_string(ndo, &tr->tr_src), ipaddr_string(ndo, &tr->tr_dst),
    119  1.1.1.4  christos         ipaddr_string(ndo, &tr->tr_raddr)));
    120      1.1  christos     if (IN_CLASSD(EXTRACT_32BITS(&tr->tr_raddr)))
    121  1.1.1.4  christos         ND_PRINT((ndo, " with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr->tr_rttlqid))));
    122      1.1  christos     return;
    123      1.1  christos trunc:
    124  1.1.1.4  christos     ND_PRINT((ndo, "%s", tstr));
    125      1.1  christos }
    126      1.1  christos 
    127      1.1  christos static void
    128  1.1.1.4  christos print_mresp(netdissect_options *ndo,
    129  1.1.1.4  christos             register const u_char *bp, register u_int len)
    130      1.1  christos {
    131      1.1  christos     register const struct tr_query *tr = (const struct tr_query *)(bp + 8);
    132      1.1  christos 
    133  1.1.1.4  christos     ND_TCHECK(*tr);
    134      1.1  christos     if (len < 8 + sizeof (struct tr_query)) {
    135  1.1.1.4  christos 	ND_PRINT((ndo, " [invalid len %d]", len));
    136      1.1  christos 	return;
    137      1.1  christos     }
    138  1.1.1.4  christos     ND_PRINT((ndo, "mresp %lu: %s to %s reply-to %s",
    139      1.1  christos         (u_long)TR_GETQID(EXTRACT_32BITS(&tr->tr_rttlqid)),
    140  1.1.1.4  christos         ipaddr_string(ndo, &tr->tr_src), ipaddr_string(ndo, &tr->tr_dst),
    141  1.1.1.4  christos         ipaddr_string(ndo, &tr->tr_raddr)));
    142      1.1  christos     if (IN_CLASSD(EXTRACT_32BITS(&tr->tr_raddr)))
    143  1.1.1.4  christos         ND_PRINT((ndo, " with-ttl %d", TR_GETTTL(EXTRACT_32BITS(&tr->tr_rttlqid))));
    144      1.1  christos     return;
    145      1.1  christos trunc:
    146  1.1.1.4  christos     ND_PRINT((ndo, "%s", tstr));
    147      1.1  christos }
    148      1.1  christos 
    149      1.1  christos static void
    150  1.1.1.4  christos print_igmpv3_report(netdissect_options *ndo,
    151  1.1.1.4  christos                     register const u_char *bp, register u_int len)
    152      1.1  christos {
    153      1.1  christos     u_int group, nsrcs, ngroups;
    154      1.1  christos     register u_int i, j;
    155      1.1  christos 
    156      1.1  christos     /* Minimum len is 16, and should be a multiple of 4 */
    157      1.1  christos     if (len < 16 || len & 0x03) {
    158  1.1.1.4  christos 	ND_PRINT((ndo, " [invalid len %d]", len));
    159      1.1  christos 	return;
    160      1.1  christos     }
    161  1.1.1.4  christos     ND_TCHECK2(bp[6], 2);
    162      1.1  christos     ngroups = EXTRACT_16BITS(&bp[6]);
    163  1.1.1.4  christos     ND_PRINT((ndo, ", %d group record(s)", ngroups));
    164  1.1.1.4  christos     if (ndo->ndo_vflag > 0) {
    165      1.1  christos 	/* Print the group records */
    166      1.1  christos 	group = 8;
    167      1.1  christos         for (i=0; i<ngroups; i++) {
    168      1.1  christos 	    if (len < group+8) {
    169  1.1.1.4  christos 		ND_PRINT((ndo, " [invalid number of groups]"));
    170      1.1  christos 		return;
    171      1.1  christos 	    }
    172  1.1.1.4  christos 	    ND_TCHECK2(bp[group+4], 4);
    173  1.1.1.4  christos             ND_PRINT((ndo, " [gaddr %s", ipaddr_string(ndo, &bp[group+4])));
    174  1.1.1.4  christos 	    ND_PRINT((ndo, " %s", tok2str(igmpv3report2str, " [v3-report-#%d]",
    175  1.1.1.4  christos 								bp[group])));
    176      1.1  christos             nsrcs = EXTRACT_16BITS(&bp[group+2]);
    177      1.1  christos 	    /* Check the number of sources and print them */
    178      1.1  christos 	    if (len < group+8+(nsrcs<<2)) {
    179  1.1.1.4  christos 		ND_PRINT((ndo, " [invalid number of sources %d]", nsrcs));
    180      1.1  christos 		return;
    181      1.1  christos 	    }
    182  1.1.1.4  christos             if (ndo->ndo_vflag == 1)
    183  1.1.1.4  christos                 ND_PRINT((ndo, ", %d source(s)", nsrcs));
    184      1.1  christos             else {
    185      1.1  christos 		/* Print the sources */
    186  1.1.1.4  christos                 ND_PRINT((ndo, " {"));
    187      1.1  christos                 for (j=0; j<nsrcs; j++) {
    188  1.1.1.4  christos 		    ND_TCHECK2(bp[group+8+(j<<2)], 4);
    189  1.1.1.4  christos 		    ND_PRINT((ndo, " %s", ipaddr_string(ndo, &bp[group+8+(j<<2)])));
    190      1.1  christos 		}
    191  1.1.1.4  christos                 ND_PRINT((ndo, " }"));
    192      1.1  christos             }
    193      1.1  christos 	    /* Next group record */
    194      1.1  christos             group += 8 + (nsrcs << 2);
    195  1.1.1.4  christos 	    ND_PRINT((ndo, "]"));
    196      1.1  christos         }
    197      1.1  christos     }
    198      1.1  christos     return;
    199      1.1  christos trunc:
    200  1.1.1.4  christos     ND_PRINT((ndo, "%s", tstr));
    201      1.1  christos }
    202      1.1  christos 
    203      1.1  christos static void
    204  1.1.1.4  christos print_igmpv3_query(netdissect_options *ndo,
    205  1.1.1.4  christos                    register const u_char *bp, register u_int len)
    206      1.1  christos {
    207      1.1  christos     u_int mrc;
    208  1.1.1.6       spz     u_int mrt;
    209      1.1  christos     u_int nsrcs;
    210      1.1  christos     register u_int i;
    211      1.1  christos 
    212  1.1.1.4  christos     ND_PRINT((ndo, " v3"));
    213      1.1  christos     /* Minimum len is 12, and should be a multiple of 4 */
    214      1.1  christos     if (len < 12 || len & 0x03) {
    215  1.1.1.4  christos 	ND_PRINT((ndo, " [invalid len %d]", len));
    216      1.1  christos 	return;
    217      1.1  christos     }
    218  1.1.1.4  christos     ND_TCHECK(bp[1]);
    219      1.1  christos     mrc = bp[1];
    220      1.1  christos     if (mrc < 128) {
    221      1.1  christos 	mrt = mrc;
    222      1.1  christos     } else {
    223      1.1  christos         mrt = ((mrc & 0x0f) | 0x10) << (((mrc & 0x70) >> 4) + 3);
    224      1.1  christos     }
    225      1.1  christos     if (mrc != 100) {
    226  1.1.1.4  christos 	ND_PRINT((ndo, " [max resp time "));
    227  1.1.1.2  christos         if (mrt < 600) {
    228  1.1.1.4  christos             ND_PRINT((ndo, "%.1fs", mrt * 0.1));
    229  1.1.1.2  christos         } else {
    230  1.1.1.6       spz             unsigned_relts_print(ndo, mrt / 10);
    231  1.1.1.2  christos         }
    232  1.1.1.4  christos 	ND_PRINT((ndo, "]"));
    233      1.1  christos     }
    234  1.1.1.4  christos     ND_TCHECK2(bp[4], 4);
    235      1.1  christos     if (EXTRACT_32BITS(&bp[4]) == 0)
    236      1.1  christos 	return;
    237  1.1.1.4  christos     ND_PRINT((ndo, " [gaddr %s", ipaddr_string(ndo, &bp[4])));
    238  1.1.1.4  christos     ND_TCHECK2(bp[10], 2);
    239      1.1  christos     nsrcs = EXTRACT_16BITS(&bp[10]);
    240      1.1  christos     if (nsrcs > 0) {
    241      1.1  christos 	if (len < 12 + (nsrcs << 2))
    242  1.1.1.4  christos 	    ND_PRINT((ndo, " [invalid number of sources]"));
    243  1.1.1.4  christos 	else if (ndo->ndo_vflag > 1) {
    244  1.1.1.4  christos 	    ND_PRINT((ndo, " {"));
    245      1.1  christos 	    for (i=0; i<nsrcs; i++) {
    246  1.1.1.4  christos 		ND_TCHECK2(bp[12+(i<<2)], 4);
    247  1.1.1.4  christos 		ND_PRINT((ndo, " %s", ipaddr_string(ndo, &bp[12+(i<<2)])));
    248      1.1  christos 	    }
    249  1.1.1.4  christos 	    ND_PRINT((ndo, " }"));
    250      1.1  christos 	} else
    251  1.1.1.4  christos 	    ND_PRINT((ndo, ", %d source(s)", nsrcs));
    252      1.1  christos     }
    253  1.1.1.4  christos     ND_PRINT((ndo, "]"));
    254      1.1  christos     return;
    255      1.1  christos trunc:
    256  1.1.1.4  christos     ND_PRINT((ndo, "%s", tstr));
    257      1.1  christos }
    258      1.1  christos 
    259      1.1  christos void
    260  1.1.1.4  christos igmp_print(netdissect_options *ndo,
    261  1.1.1.4  christos            register const u_char *bp, register u_int len)
    262      1.1  christos {
    263  1.1.1.2  christos     struct cksum_vec vec[1];
    264  1.1.1.2  christos 
    265  1.1.1.4  christos     if (ndo->ndo_qflag) {
    266  1.1.1.4  christos         ND_PRINT((ndo, "igmp"));
    267      1.1  christos         return;
    268      1.1  christos     }
    269      1.1  christos 
    270  1.1.1.4  christos     ND_TCHECK(bp[0]);
    271      1.1  christos     switch (bp[0]) {
    272      1.1  christos     case 0x11:
    273  1.1.1.4  christos         ND_PRINT((ndo, "igmp query"));
    274      1.1  christos 	if (len >= 12)
    275  1.1.1.4  christos 	    print_igmpv3_query(ndo, bp, len);
    276      1.1  christos 	else {
    277  1.1.1.4  christos             ND_TCHECK(bp[1]);
    278      1.1  christos 	    if (bp[1]) {
    279  1.1.1.4  christos 		ND_PRINT((ndo, " v2"));
    280      1.1  christos 		if (bp[1] != 100)
    281  1.1.1.4  christos 		    ND_PRINT((ndo, " [max resp time %d]", bp[1]));
    282      1.1  christos 	    } else
    283  1.1.1.4  christos 		ND_PRINT((ndo, " v1"));
    284  1.1.1.4  christos             ND_TCHECK2(bp[4], 4);
    285      1.1  christos 	    if (EXTRACT_32BITS(&bp[4]))
    286  1.1.1.4  christos                 ND_PRINT((ndo, " [gaddr %s]", ipaddr_string(ndo, &bp[4])));
    287      1.1  christos             if (len != 8)
    288  1.1.1.4  christos                 ND_PRINT((ndo, " [len %d]", len));
    289      1.1  christos 	}
    290      1.1  christos         break;
    291      1.1  christos     case 0x12:
    292  1.1.1.4  christos         ND_TCHECK2(bp[4], 4);
    293  1.1.1.4  christos         ND_PRINT((ndo, "igmp v1 report %s", ipaddr_string(ndo, &bp[4])));
    294      1.1  christos         if (len != 8)
    295  1.1.1.4  christos             ND_PRINT((ndo, " [len %d]", len));
    296      1.1  christos         break;
    297      1.1  christos     case 0x16:
    298  1.1.1.4  christos         ND_TCHECK2(bp[4], 4);
    299  1.1.1.4  christos         ND_PRINT((ndo, "igmp v2 report %s", ipaddr_string(ndo, &bp[4])));
    300      1.1  christos         break;
    301      1.1  christos     case 0x22:
    302  1.1.1.4  christos         ND_PRINT((ndo, "igmp v3 report"));
    303  1.1.1.4  christos 	print_igmpv3_report(ndo, bp, len);
    304      1.1  christos         break;
    305      1.1  christos     case 0x17:
    306  1.1.1.4  christos         ND_TCHECK2(bp[4], 4);
    307  1.1.1.4  christos         ND_PRINT((ndo, "igmp leave %s", ipaddr_string(ndo, &bp[4])));
    308      1.1  christos         break;
    309      1.1  christos     case 0x13:
    310  1.1.1.4  christos         ND_PRINT((ndo, "igmp dvmrp"));
    311      1.1  christos         if (len < 8)
    312  1.1.1.4  christos             ND_PRINT((ndo, " [len %d]", len));
    313      1.1  christos         else
    314  1.1.1.4  christos             dvmrp_print(ndo, bp, len);
    315      1.1  christos         break;
    316      1.1  christos     case 0x14:
    317  1.1.1.4  christos         ND_PRINT((ndo, "igmp pimv1"));
    318  1.1.1.4  christos         pimv1_print(ndo, bp, len);
    319      1.1  christos         break;
    320      1.1  christos     case 0x1e:
    321  1.1.1.4  christos         print_mresp(ndo, bp, len);
    322      1.1  christos         break;
    323      1.1  christos     case 0x1f:
    324  1.1.1.4  christos         print_mtrace(ndo, bp, len);
    325      1.1  christos         break;
    326      1.1  christos     default:
    327  1.1.1.4  christos         ND_PRINT((ndo, "igmp-%d", bp[0]));
    328      1.1  christos         break;
    329      1.1  christos     }
    330      1.1  christos 
    331  1.1.1.6       spz     if (ndo->ndo_vflag && len >= 4 && ND_TTEST2(bp[0], len)) {
    332      1.1  christos         /* Check the IGMP checksum */
    333  1.1.1.2  christos         vec[0].ptr = bp;
    334  1.1.1.2  christos         vec[0].len = len;
    335  1.1.1.2  christos         if (in_cksum(vec, 1))
    336  1.1.1.4  christos             ND_PRINT((ndo, " bad igmp cksum %x!", EXTRACT_16BITS(&bp[2])));
    337      1.1  christos     }
    338      1.1  christos     return;
    339      1.1  christos trunc:
    340  1.1.1.4  christos     ND_PRINT((ndo, "%s", tstr));
    341      1.1  christos }
    342