2000-11-02 10:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that: (1) source code distributions
|
|
|
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
|
|
|
* distributions including binary code include the above copyright notice and
|
|
|
|
* this paragraph in its entirety in the documentation or other materials
|
|
|
|
* provided with the distribution, and (3) all advertising materials mentioning
|
|
|
|
* features or use of this software display the following acknowledgement:
|
|
|
|
* ``This product includes software developed by the University of California,
|
|
|
|
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
|
|
|
* the University nor the names of its contributors may be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*/
|
|
|
|
|
2016-08-14 21:42:19 +08:00
|
|
|
/* \summary: Internet Group Management Protocol (IGMP) printer */
|
|
|
|
|
2017-11-24 05:30:32 +08:00
|
|
|
/*
|
|
|
|
* specification:
|
|
|
|
*
|
|
|
|
* RFC 2236 for IGMPv2
|
|
|
|
* RFC 3376 for IGMPv3
|
|
|
|
* draft-asaeda-mboned-mtrace-v2 for the mtrace message
|
|
|
|
*/
|
|
|
|
|
2018-01-22 04:27:08 +08:00
|
|
|
#include <config.h>
|
2000-11-02 10:18:28 +08:00
|
|
|
|
2018-01-20 22:59:49 +08:00
|
|
|
#include "netdissect-stdinc.h"
|
2000-11-02 10:18:28 +08:00
|
|
|
|
2015-09-06 05:35:58 +08:00
|
|
|
#include "netdissect.h"
|
2000-11-02 10:18:28 +08:00
|
|
|
#include "addrtoname.h"
|
2015-09-07 21:01:46 +08:00
|
|
|
#include "extract.h"
|
2000-11-02 10:18:28 +08:00
|
|
|
|
|
|
|
#ifndef IN_CLASSD
|
|
|
|
#define IN_CLASSD(i) (((int32_t)(i) & 0xf0000000) == 0xe0000000)
|
|
|
|
#endif
|
|
|
|
|
2013-12-26 22:08:06 +08:00
|
|
|
|
2000-11-02 10:18:28 +08:00
|
|
|
/* (following from ipmulti/mrouted/prune.h) */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The packet format for a traceroute request.
|
|
|
|
*/
|
|
|
|
struct tr_query {
|
2017-11-24 05:30:32 +08:00
|
|
|
nd_uint32_t tr_src; /* traceroute source */
|
|
|
|
nd_uint32_t tr_dst; /* traceroute destination */
|
|
|
|
nd_uint32_t tr_raddr; /* traceroute response address */
|
|
|
|
nd_uint8_t tr_rttl; /* response ttl */
|
|
|
|
nd_uint24_t tr_qid; /* qid */
|
2002-12-11 15:13:49 +08:00
|
|
|
};
|
2000-11-02 10:18:28 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Traceroute response format. A traceroute response has a tr_query at the
|
|
|
|
* beginning, followed by one tr_resp for each hop taken.
|
|
|
|
*/
|
|
|
|
struct tr_resp {
|
2018-01-12 03:26:02 +08:00
|
|
|
nd_uint32_t tr_qarr; /* query arrival time */
|
|
|
|
nd_uint32_t tr_inaddr; /* incoming interface address */
|
|
|
|
nd_uint32_t tr_outaddr; /* outgoing interface address */
|
|
|
|
nd_uint32_t tr_rmtaddr; /* parent address in source tree */
|
|
|
|
nd_uint32_t tr_vifin; /* input packet count on interface */
|
|
|
|
nd_uint32_t tr_vifout; /* output packet count on interface */
|
|
|
|
nd_uint32_t tr_pktcnt; /* total incoming packets for src-grp */
|
|
|
|
nd_uint8_t tr_rproto; /* routing proto deployed on router */
|
|
|
|
nd_uint8_t tr_fttl; /* ttl required to forward on outvif */
|
|
|
|
nd_uint8_t tr_smask; /* subnet mask for src addr */
|
|
|
|
nd_uint8_t tr_rflags; /* forwarding error codes */
|
2002-12-11 15:13:49 +08:00
|
|
|
};
|
2000-11-02 10:18:28 +08:00
|
|
|
|
|
|
|
/* defs within mtrace */
|
|
|
|
#define TR_QUERY 1
|
|
|
|
#define TR_RESP 2
|
|
|
|
|
|
|
|
/* fields for tr_rflags (forwarding error codes) */
|
|
|
|
#define TR_NO_ERR 0
|
|
|
|
#define TR_WRONG_IF 1
|
|
|
|
#define TR_PRUNED 2
|
|
|
|
#define TR_OPRUNED 3
|
|
|
|
#define TR_SCOPED 4
|
|
|
|
#define TR_NO_RTE 5
|
|
|
|
#define TR_NO_FWD 7
|
|
|
|
#define TR_NO_SPACE 0x81
|
|
|
|
#define TR_OLD_ROUTER 0x82
|
|
|
|
|
|
|
|
/* fields for tr_rproto (routing protocol) */
|
|
|
|
#define TR_PROTO_DVMRP 1
|
|
|
|
#define TR_PROTO_MOSPF 2
|
|
|
|
#define TR_PROTO_PIM 3
|
|
|
|
#define TR_PROTO_CBT 4
|
|
|
|
|
|
|
|
/* igmpv3 report types */
|
2013-09-25 00:46:24 +08:00
|
|
|
static const struct tok igmpv3report2str[] = {
|
2000-11-02 10:18:28 +08:00
|
|
|
{ 1, "is_in" },
|
|
|
|
{ 2, "is_ex" },
|
|
|
|
{ 3, "to_in" },
|
|
|
|
{ 4, "to_ex" },
|
|
|
|
{ 5, "allow" },
|
|
|
|
{ 6, "block" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2002-06-12 01:08:37 +08:00
|
|
|
static void
|
2014-03-19 17:57:56 +08:00
|
|
|
print_mtrace(netdissect_options *ndo,
|
2020-09-30 10:36:06 +08:00
|
|
|
const char *typename,
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *bp, u_int len)
|
2000-11-02 10:18:28 +08:00
|
|
|
{
|
2017-12-14 02:17:47 +08:00
|
|
|
const struct tr_query *tr = (const struct tr_query *)(bp + 8);
|
2000-11-02 10:18:28 +08:00
|
|
|
|
2002-09-06 05:25:34 +08:00
|
|
|
if (len < 8 + sizeof (struct tr_query)) {
|
2018-01-12 03:26:02 +08:00
|
|
|
ND_PRINT(" [invalid len %u]", len);
|
2002-09-06 05:25:34 +08:00
|
|
|
return;
|
|
|
|
}
|
2020-09-30 10:36:06 +08:00
|
|
|
ND_PRINT("%s %u: %s to %s reply-to %s",
|
|
|
|
typename,
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_3(tr->tr_qid),
|
2020-01-20 11:55:38 +08:00
|
|
|
GET_IPADDR_STRING(tr->tr_src), GET_IPADDR_STRING(tr->tr_dst),
|
|
|
|
GET_IPADDR_STRING(tr->tr_raddr));
|
2018-06-16 23:23:21 +08:00
|
|
|
if (IN_CLASSD(GET_BE_U_4(tr->tr_raddr)))
|
|
|
|
ND_PRINT(" with-ttl %u", GET_U_1(tr->tr_rttl));
|
2000-11-02 10:18:28 +08:00
|
|
|
}
|
|
|
|
|
2002-06-12 01:08:37 +08:00
|
|
|
static void
|
2014-03-19 17:57:56 +08:00
|
|
|
print_igmpv3_report(netdissect_options *ndo,
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *bp, u_int len)
|
2000-11-02 10:18:28 +08:00
|
|
|
{
|
2001-09-18 05:57:50 +08:00
|
|
|
u_int group, nsrcs, ngroups;
|
2017-12-14 02:17:47 +08:00
|
|
|
u_int i, j;
|
2000-11-02 10:18:28 +08:00
|
|
|
|
|
|
|
/* Minimum len is 16, and should be a multiple of 4 */
|
|
|
|
if (len < 16 || len & 0x03) {
|
2018-01-12 03:26:02 +08:00
|
|
|
ND_PRINT(" [invalid len %u]", len);
|
2002-06-12 01:08:37 +08:00
|
|
|
return;
|
2000-11-02 10:18:28 +08:00
|
|
|
}
|
2018-06-16 23:23:21 +08:00
|
|
|
ngroups = GET_BE_U_2(bp + 6);
|
2018-01-12 03:26:02 +08:00
|
|
|
ND_PRINT(", %u group record(s)", ngroups);
|
2014-03-19 17:57:56 +08:00
|
|
|
if (ndo->ndo_vflag > 0) {
|
2000-11-02 10:18:28 +08:00
|
|
|
/* Print the group records */
|
2002-06-12 01:08:37 +08:00
|
|
|
group = 8;
|
2000-11-02 10:18:28 +08:00
|
|
|
for (i=0; i<ngroups; i++) {
|
|
|
|
if (len < group+8) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" [invalid number of groups]");
|
2000-11-02 10:18:28 +08:00
|
|
|
return;
|
|
|
|
}
|
2020-01-20 11:55:38 +08:00
|
|
|
ND_PRINT(" [gaddr %s", GET_IPADDR_STRING(bp + group + 4));
|
2018-01-12 03:26:02 +08:00
|
|
|
ND_PRINT(" %s", tok2str(igmpv3report2str, " [v3-report-#%u]",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_U_1(bp + group)));
|
|
|
|
nsrcs = GET_BE_U_2(bp + group + 2);
|
2000-11-02 10:18:28 +08:00
|
|
|
/* Check the number of sources and print them */
|
|
|
|
if (len < group+8+(nsrcs<<2)) {
|
2018-01-12 03:26:02 +08:00
|
|
|
ND_PRINT(" [invalid number of sources %u]", nsrcs);
|
2000-11-02 10:18:28 +08:00
|
|
|
return;
|
|
|
|
}
|
2014-03-19 17:57:56 +08:00
|
|
|
if (ndo->ndo_vflag == 1)
|
2018-01-12 03:26:02 +08:00
|
|
|
ND_PRINT(", %u source(s)", nsrcs);
|
2000-11-02 10:18:28 +08:00
|
|
|
else {
|
|
|
|
/* Print the sources */
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" {");
|
2000-11-02 10:18:28 +08:00
|
|
|
for (j=0; j<nsrcs; j++) {
|
2020-01-20 11:55:38 +08:00
|
|
|
ND_PRINT(" %s", GET_IPADDR_STRING(bp + group + 8 + (j << 2)));
|
2000-11-02 10:18:28 +08:00
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" }");
|
2000-11-02 10:18:28 +08:00
|
|
|
}
|
|
|
|
/* Next group record */
|
|
|
|
group += 8 + (nsrcs << 2);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("]");
|
2000-11-02 10:18:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-03-19 17:57:56 +08:00
|
|
|
print_igmpv3_query(netdissect_options *ndo,
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *bp, u_int len)
|
2000-11-02 10:18:28 +08:00
|
|
|
{
|
2001-09-18 05:57:50 +08:00
|
|
|
u_int mrc;
|
2015-08-09 03:53:36 +08:00
|
|
|
u_int mrt;
|
2001-09-18 05:57:50 +08:00
|
|
|
u_int nsrcs;
|
2017-12-14 02:17:47 +08:00
|
|
|
u_int i;
|
2000-11-02 10:18:28 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" v3");
|
2000-11-02 10:18:28 +08:00
|
|
|
/* Minimum len is 12, and should be a multiple of 4 */
|
|
|
|
if (len < 12 || len & 0x03) {
|
2018-01-12 03:26:02 +08:00
|
|
|
ND_PRINT(" [invalid len %u]", len);
|
2002-06-12 01:08:37 +08:00
|
|
|
return;
|
2000-11-02 10:18:28 +08:00
|
|
|
}
|
2018-06-16 23:23:21 +08:00
|
|
|
mrc = GET_U_1(bp + 1);
|
2001-05-11 10:13:19 +08:00
|
|
|
if (mrc < 128) {
|
|
|
|
mrt = mrc;
|
|
|
|
} else {
|
|
|
|
mrt = ((mrc & 0x0f) | 0x10) << (((mrc & 0x70) >> 4) + 3);
|
|
|
|
}
|
|
|
|
if (mrc != 100) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" [max resp time ");
|
2012-02-14 00:32:14 +08:00
|
|
|
if (mrt < 600) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%.1fs", mrt * 0.1);
|
2012-02-14 00:27:08 +08:00
|
|
|
} else {
|
2015-08-09 03:53:36 +08:00
|
|
|
unsigned_relts_print(ndo, mrt / 10);
|
2012-02-14 00:27:08 +08:00
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("]");
|
2001-05-11 10:13:19 +08:00
|
|
|
}
|
2018-06-16 23:23:21 +08:00
|
|
|
if (GET_BE_U_4(bp + 4) == 0)
|
2000-11-02 10:18:28 +08:00
|
|
|
return;
|
2020-01-20 11:55:38 +08:00
|
|
|
ND_PRINT(" [gaddr %s", GET_IPADDR_STRING(bp + 4));
|
2018-06-16 23:23:21 +08:00
|
|
|
nsrcs = GET_BE_U_2(bp + 10);
|
2000-11-02 10:18:28 +08:00
|
|
|
if (nsrcs > 0) {
|
|
|
|
if (len < 12 + (nsrcs << 2))
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" [invalid number of sources]");
|
2014-03-19 17:57:56 +08:00
|
|
|
else if (ndo->ndo_vflag > 1) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" {");
|
2000-11-02 10:18:28 +08:00
|
|
|
for (i=0; i<nsrcs; i++) {
|
2020-01-20 11:55:38 +08:00
|
|
|
ND_PRINT(" %s", GET_IPADDR_STRING(bp + 12 + (i << 2)));
|
2000-11-02 10:18:28 +08:00
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" }");
|
2000-11-02 10:18:28 +08:00
|
|
|
} else
|
2018-01-12 03:26:02 +08:00
|
|
|
ND_PRINT(", %u source(s)", nsrcs);
|
2000-11-02 10:18:28 +08:00
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("]");
|
2000-11-02 10:18:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-19 17:57:56 +08:00
|
|
|
igmp_print(netdissect_options *ndo,
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *bp, u_int len)
|
2000-11-02 10:18:28 +08:00
|
|
|
{
|
2011-06-14 05:08:51 +08:00
|
|
|
struct cksum_vec vec[1];
|
|
|
|
|
2018-03-14 23:54:17 +08:00
|
|
|
ndo->ndo_protocol = "igmp";
|
2014-03-19 17:57:56 +08:00
|
|
|
if (ndo->ndo_qflag) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("igmp");
|
2000-11-02 10:18:28 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-16 23:23:21 +08:00
|
|
|
switch (GET_U_1(bp)) {
|
2000-11-02 10:18:28 +08:00
|
|
|
case 0x11:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("igmp query");
|
2000-11-02 10:18:28 +08:00
|
|
|
if (len >= 12)
|
2014-03-19 17:57:56 +08:00
|
|
|
print_igmpv3_query(ndo, bp, len);
|
2000-11-02 10:18:28 +08:00
|
|
|
else {
|
2018-06-16 23:23:21 +08:00
|
|
|
if (GET_U_1(bp + 1)) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" v2");
|
2018-06-16 23:23:21 +08:00
|
|
|
if (GET_U_1(bp + 1) != 100)
|
|
|
|
ND_PRINT(" [max resp time %u]", GET_U_1(bp + 1));
|
2000-11-02 10:18:28 +08:00
|
|
|
} else
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" v1");
|
2018-06-16 23:23:21 +08:00
|
|
|
if (GET_BE_U_4(bp + 4))
|
2020-01-20 11:55:38 +08:00
|
|
|
ND_PRINT(" [gaddr %s]", GET_IPADDR_STRING(bp + 4));
|
2000-11-02 10:18:28 +08:00
|
|
|
if (len != 8)
|
2018-01-12 03:26:02 +08:00
|
|
|
ND_PRINT(" [len %u]", len);
|
2000-11-02 10:18:28 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x12:
|
2020-01-20 11:55:38 +08:00
|
|
|
ND_PRINT("igmp v1 report %s", GET_IPADDR_STRING(bp + 4));
|
2000-11-02 10:18:28 +08:00
|
|
|
if (len != 8)
|
2018-01-12 03:26:02 +08:00
|
|
|
ND_PRINT(" [len %u]", len);
|
2000-11-02 10:18:28 +08:00
|
|
|
break;
|
|
|
|
case 0x16:
|
2020-01-20 11:55:38 +08:00
|
|
|
ND_PRINT("igmp v2 report %s", GET_IPADDR_STRING(bp + 4));
|
2000-11-02 10:18:28 +08:00
|
|
|
break;
|
|
|
|
case 0x22:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("igmp v3 report");
|
2014-03-19 17:57:56 +08:00
|
|
|
print_igmpv3_report(ndo, bp, len);
|
2000-11-02 10:18:28 +08:00
|
|
|
break;
|
|
|
|
case 0x17:
|
2020-01-20 11:55:38 +08:00
|
|
|
ND_PRINT("igmp leave %s", GET_IPADDR_STRING(bp + 4));
|
2000-11-02 10:18:28 +08:00
|
|
|
break;
|
|
|
|
case 0x13:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("igmp dvmrp");
|
2000-11-02 10:18:28 +08:00
|
|
|
if (len < 8)
|
2018-01-12 03:26:02 +08:00
|
|
|
ND_PRINT(" [len %u]", len);
|
2000-11-02 10:18:28 +08:00
|
|
|
else
|
2014-03-21 20:48:24 +08:00
|
|
|
dvmrp_print(ndo, bp, len);
|
2000-11-02 10:18:28 +08:00
|
|
|
break;
|
|
|
|
case 0x14:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("igmp pimv1");
|
2014-03-25 19:05:59 +08:00
|
|
|
pimv1_print(ndo, bp, len);
|
2000-11-02 10:18:28 +08:00
|
|
|
break;
|
|
|
|
case 0x1e:
|
2020-09-30 10:36:06 +08:00
|
|
|
print_mtrace(ndo, "mresp", bp, len);
|
2000-11-02 10:18:28 +08:00
|
|
|
break;
|
|
|
|
case 0x1f:
|
2020-09-30 10:36:06 +08:00
|
|
|
print_mtrace(ndo, "mtrace", bp, len);
|
2000-11-02 10:18:28 +08:00
|
|
|
break;
|
|
|
|
default:
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT("igmp-%u", GET_U_1(bp));
|
2000-11-02 10:18:28 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-12-11 19:46:51 +08:00
|
|
|
if (ndo->ndo_vflag && len >= 4 && ND_TTEST_LEN(bp, len)) {
|
2000-11-02 10:18:28 +08:00
|
|
|
/* Check the IGMP checksum */
|
2011-06-14 05:08:51 +08:00
|
|
|
vec[0].ptr = bp;
|
|
|
|
vec[0].len = len;
|
|
|
|
if (in_cksum(vec, 1))
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(" bad igmp cksum %x!", GET_BE_U_2(bp + 2));
|
2000-11-02 10:18:28 +08:00
|
|
|
}
|
|
|
|
}
|