draft-draves-ipngwg-router-selection-01 support.

fix icmp6 homeagent info option decoding (convert to tvb framework).
plug a memory leak.
sync some of mobile-ip6 #define symbol names with draft-ietf-ipngwg-2292bis-02.

svn path=/trunk/; revision=3497
This commit is contained in:
Jun-ichiro itojun Hagino 2001-06-01 23:53:49 +00:00
parent 40c78f3b80
commit 78d7c0ca28
2 changed files with 136 additions and 44 deletions

View File

@ -1,7 +1,7 @@
/* packet-icmpv6.c
* Routines for ICMPv6 packet disassembly
*
* $Id: packet-icmpv6.c,v 1.43 2001/05/27 04:14:53 guy Exp $
* $Id: packet-icmpv6.c,v 1.44 2001/06/01 23:53:48 itojun Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -97,6 +97,13 @@ static const value_string names_rrenum_matchcode[] = {
{ 0, NULL }
};
static const value_string names_router_pref[] = {
{ ND_RA_FLAG_RTPREF_HIGH, "High" },
{ ND_RA_FLAG_RTPREF_MEDIUM, "Meidum" },
{ ND_RA_FLAG_RTPREF_LOW, "Low" },
{ ND_RA_FLAG_RTPREF_RSV, "Reserved" },
};
static void
dissect_contained_icmpv6(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
{
@ -158,12 +165,20 @@ dissect_icmpv6opt(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tre
again:
if ((int)tvb_reported_length(tvb) <= offset)
return; /* No more options left */
return; /* No more options left */
opt = &nd_opt_hdr;
tvb_memcpy(tvb, (guint8 *)opt, offset, sizeof *opt);
len = opt->nd_opt_len << 3;
if (len == 0) {
proto_tree_add_text(icmp6opt_tree, tvb,
offset + offsetof(struct nd_opt_hdr, nd_opt_len), 1,
"Invalid option length: %u",
opt->nd_opt_len);
return; /* we must not try to decode this */
}
/* !!! specify length */
ti = proto_tree_add_text(tree, tvb, offset, len, "ICMPv6 options");
icmp6opt_tree = proto_item_add_subtree(ti, ett_icmpv6opt);
@ -184,14 +199,13 @@ again:
case ND_OPT_MTU:
typename = "MTU";
break;
case ND_OPT_ADVERTISEMENT_INTERVAL:
case ND_OPT_ADVINTERVAL:
typename = "Advertisement Interval";
break;
case ND_OPT_HOME_AGENT_INFORMATION:
case ND_OPT_HOMEAGENT_INFO:
typename = "Home Agent Information";
break;
default:
typename = "Unknown";
break;
}
@ -221,6 +235,7 @@ again:
}
proto_tree_add_text(icmp6opt_tree, tvb,
offset + sizeof(*opt), len, "Link-layer address: %s", t);
free(t);
break;
}
case ND_OPT_PREFIX_INFORMATION:
@ -240,15 +255,18 @@ again:
field_tree = proto_item_add_subtree(tf, ett_icmpv6flag);
proto_tree_add_text(field_tree, tvb, flagoff, 1, "%s",
decode_boolean_bitfield(pi->nd_opt_pi_flags_reserved,
0x80, 8, "Onlink", "Not onlink"));
ND_OPT_PI_FLAG_ONLINK, 8, "Onlink", "Not onlink"));
proto_tree_add_text(field_tree, tvb, flagoff, 1, "%s",
decode_boolean_bitfield(pi->nd_opt_pi_flags_reserved,
0x40, 8, "Auto", "Not auto"));
/* BT INSERT BEGIN */
ND_OPT_PI_FLAG_AUTO, 8, "Auto", "Not auto"));
proto_tree_add_text(field_tree, tvb, flagoff, 1, "%s",
decode_boolean_bitfield(pi->nd_opt_pi_flags_reserved,
0x20, 8, "Router Address", "Not router address"));
/* BT INSERT END */
ND_OPT_PI_FLAG_ROUTER, 8,
"Router Address", "Not router address"));
proto_tree_add_text(field_tree, tvb, flagoff, 1, "%s",
decode_boolean_bitfield(pi->nd_opt_pi_flags_reserved,
ND_OPT_PI_FLAG_SITEPREF, 8,
"Site prefix", "Not site prefix"));
proto_tree_add_text(icmp6opt_tree, tvb,
offset + offsetof(struct nd_opt_prefix_info, nd_opt_pi_valid_time),
4, "Valid lifetime: 0x%08x",
@ -272,16 +290,18 @@ again:
offset + offsetof(struct nd_opt_mtu, nd_opt_mtu_mtu), 4,
"MTU: %u", tvb_get_ntohl(tvb, offset + offsetof(struct nd_opt_mtu, nd_opt_mtu_mtu)));
break;
/* BT INSERT BEGIN */
case ND_OPT_ADVERTISEMENT_INTERVAL:
case ND_OPT_ADVINTERVAL:
proto_tree_add_text(icmp6opt_tree, tvb,
offset + offsetof(struct nd_opt_adv_int, nd_opt_adv_int_advint), 4,
"Advertisement Interval: %d",
tvb_get_ntohl(tvb, offset + offsetof(struct nd_opt_adv_int, nd_opt_adv_int_advint)));
break;
case ND_OPT_HOME_AGENT_INFORMATION:
case ND_OPT_HOMEAGENT_INFO:
{
struct nd_opt_ha_info *pi = (struct nd_opt_ha_info *)opt;
struct nd_opt_ha_info pibuf, *pi;
pi = &pibuf;
tvb_memcpy(tvb, (guint8 *)pi, offset, sizeof *pi);
proto_tree_add_text(icmp6opt_tree, tvb,
offset + offsetof(struct nd_opt_ha_info, nd_opt_ha_info_ha_pref),
2, "Home Agent Preference: %d",
@ -292,15 +312,62 @@ again:
pntohs(&pi->nd_opt_ha_info_ha_life));
break;
}
/* BT INSERT END */
}
case ND_OPT_ROUTE_INFO:
{
struct nd_opt_route_info ribuf, *ri;
struct e_in6_addr in6;
int l;
u_int32_t lifetime;
if (opt->nd_opt_len == 0) {
proto_tree_add_text(icmp6opt_tree, tvb,
offset + offsetof(struct nd_opt_hdr, nd_opt_len), 1,
"Invalid option length: %u",
opt->nd_opt_len);
return;
ri = &ribuf;
tvb_memcpy(tvb, (guint8 *)ri, offset, sizeof *ri);
memset(&in6, 0, sizeof(in6));
switch (ri->nd_opt_rti_len) {
case 1:
l = 0;
break;
case 2:
tvb_memcpy(tvb, (guint8 *)&in6, offset + sizeof(*ri), l = 8);
break;
case 3:
tvb_memcpy(tvb, (guint8 *)&in6, offset + sizeof(*ri), l = 16);
break;
default:
l = -1;
break;
}
if (l >= 0) {
proto_tree_add_text(icmp6opt_tree, tvb,
offset + offsetof(struct nd_opt_route_info, nd_opt_rti_prefixlen),
1, "Prefix length: %u", ri->nd_opt_rti_prefixlen);
tf = proto_tree_add_text(icmp6opt_tree, tvb,
offset + offsetof(struct nd_opt_route_info, nd_opt_rti_flags),
1, "Flags: 0x%02x", ri->nd_opt_rti_flags);
field_tree = proto_item_add_subtree(tf, ett_icmpv6flag);
proto_tree_add_text(field_tree, tvb,
offset + offsetof(struct nd_opt_route_info, nd_opt_rti_flags),
1, "%s",
decode_enumerated_bitfield(ri->nd_opt_rti_flags,
ND_RA_FLAG_RTPREF_MASK, 8, names_router_pref,
"Router preference: %s"));
lifetime = pntohl(&ri->nd_opt_rti_lifetime);
if (lifetime == 0xffffffff)
proto_tree_add_text(icmp6opt_tree, tvb,
offset + offsetof(struct nd_opt_route_info, nd_opt_rti_lifetime),
sizeof(ri->nd_opt_rti_lifetime), "Lifetime: infinity");
else
proto_tree_add_text(icmp6opt_tree, tvb,
offset + offsetof(struct nd_opt_route_info, nd_opt_rti_lifetime),
sizeof(ri->nd_opt_rti_lifetime), "Lifetime: %u", lifetime);
proto_tree_add_text(icmp6opt_tree, tvb,
offset + sizeof(*ri), l, "Prefix: %s", ip6_to_str(&in6));
} else {
proto_tree_add_text(icmp6opt_tree, tvb,
offset + offsetof(struct nd_opt_hdr, nd_opt_len), 1,
"Invalid option length: %u", opt->nd_opt_len);
}
break;
}
}
offset += (opt->nd_opt_len << 3);
@ -1144,15 +1211,17 @@ dissect_icmpv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
field_tree = proto_item_add_subtree(tf, ett_icmpv6flag);
proto_tree_add_text(field_tree, tvb, flagoff, 1, "%s",
decode_boolean_bitfield(ra_flags,
0x80, 8, "Managed", "Not managed"));
ND_RA_FLAG_MANAGED, 8, "Managed", "Not managed"));
proto_tree_add_text(field_tree, tvb, flagoff, 1, "%s",
decode_boolean_bitfield(ra_flags,
0x40, 8, "Other", "Not other"));
/* BT INSERT BEGIN */
ND_RA_FLAG_OTHER, 8, "Other", "Not other"));
proto_tree_add_text(field_tree, tvb, flagoff, 1, "%s",
decode_boolean_bitfield(ra_flags,
0x20, 8, "Home Agent", "Not Home Agent"));
/* BT INSERT END */
ND_RA_FLAG_HOME_AGENT, 8,
"Home Agent", "Not Home Agent"));
proto_tree_add_text(field_tree, tvb, flagoff, 1, "%s",
decode_enumerated_bitfield(ra_flags, ND_RA_FLAG_RTPREF_MASK, 8,
names_router_pref, "Router preference: %s"));
proto_tree_add_text(icmp6_tree, tvb,
offset + offsetof(struct nd_router_advert, nd_ra_router_lifetime),
2, "Router lifetime: %u",

View File

@ -1,7 +1,7 @@
/* packet-ipv6.h
* Definitions for IPv6 packet disassembly
*
* $Id: packet-ipv6.h,v 1.21 2001/04/23 03:56:57 guy Exp $
* $Id: packet-ipv6.h,v 1.22 2001/06/01 23:53:49 itojun Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -101,11 +101,21 @@ struct ip6_dest {
#define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */
#define IP6OPT_JUMBO_LEN 6
#define IP6OPT_RTALERT 0x05 /* 00 0 00101 */
#define IP6OPT_RTALERT_LEN 4
#define IP6OPT_RTALERT_MLD 0 /* Datagram contains MLD message */
#define IP6OPT_RTALERT_RSVP 1 /* Datagram contains RSVP message */
#define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */
#define IP6OPT_MINLEN 2
#define IP6OPT_BINDING_UPDATE 0xC6 /* 11 0 00110 */
#define IP6OPT_BINDING_ACK 0x07 /* 00 0 00111 */
#define IP6OPT_BINDING_REQUEST 0x08 /* 00 0 01000 */
#define IP6OPT_HOME_ADDRESS 0xC9 /* 11 0 01001 */
#define IP6OPT_EID 0x8a /* 10 0 01010 */
#define IP6OPT_MIPv6_UNIQUE_ID_SUB 0x02 /* 00 0 00010 */
#define IP6OPT_MIPv6_ALTERNATIVE_COA_SUB 0x04 /* 00 0 00100 */
#define IP6OPT_TYPE(o) ((o) & 0xC0)
#define IP6OPT_TYPE_SKIP 0x00
#define IP6OPT_TYPE_DISCARD 0x40
@ -114,15 +124,6 @@ struct ip6_dest {
#define IP6OPT_MUTABLE 0x20
/* BT INSERT BEGIN */
/* Mobile IP option types and sub-option types*/
#define IP6OPT_BINDING_UPDATE 0xC6 /* 11 0 00110 */
#define IP6OPT_BINDING_ACK 0x07 /* 00 0 00111 */
#define IP6OPT_BINDING_REQUEST 0x08 /* 00 0 01000 */
#define IP6OPT_HOME_ADDRESS 0xC9 /* 11 0 01001 */
#define IP6OPT_MIPv6_UNIQUE_ID_SUB 0x02 /* 00 0 00010 */
#define IP6OPT_MIPv6_ALTERNATIVE_COA_SUB 0x04 /* 00 0 00100 */
/* MIPv6 Lifetime */
#define MIP_INFINITY 0xffffffff /* Infinity lifetime */
@ -190,7 +191,6 @@ static const true_false_string ipv6_mipv6_bu_b_flag_value =
"Request for bicasting",
"Do not request for bicasting"
};
/* BT INSERT END */
/* Routing header */
struct ip6_rthdr {
@ -357,6 +357,19 @@ struct nd_router_advert { /* router advertisement */
#define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1]
#define ND_RA_FLAG_MANAGED 0x80
#define ND_RA_FLAG_OTHER 0x40
#define ND_RA_FLAG_HOME_AGENT 0x20
/*
* Router preference values based on draft-draves-ipngwg-router-selection-01.
* These are non-standard definitions.
*/
#define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */
#define ND_RA_FLAG_RTPREF_HIGH 0x08 /* 00001000 */
#define ND_RA_FLAG_RTPREF_MEDIUM 0x00 /* 00000000 */
#define ND_RA_FLAG_RTPREF_LOW 0x18 /* 00011000 */
#define ND_RA_FLAG_RTPREF_RSV 0x10 /* 00010000 */
#define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1]
struct nd_neighbor_solicit { /* neighbor solicitation */
@ -406,11 +419,11 @@ struct nd_opt_hdr { /* Neighbor discovery option header */
#define ND_OPT_TARGET_LINKADDR 2
#define ND_OPT_PREFIX_INFORMATION 3
#define ND_OPT_REDIRECTED_HEADER 4
/* BT INSERT BEGIN */
#define ND_OPT_ADVERTISEMENT_INTERVAL 7
#define ND_OPT_HOME_AGENT_INFORMATION 8
/* BT INSERT END */
#define ND_OPT_MTU 5
#define ND_OPT_ADVINTERVAL 7
#define ND_OPT_HOMEAGENT_INFO 8
/* draft-ietf-ipngwg-router-preference, not officially assigned yet */
#define ND_OPT_ROUTE_INFO 9
struct nd_opt_prefix_info { /* prefix information */
guint8 nd_opt_pi_type;
@ -425,6 +438,8 @@ struct nd_opt_prefix_info { /* prefix information */
#define ND_OPT_PI_FLAG_ONLINK 0x80
#define ND_OPT_PI_FLAG_AUTO 0x40
#define ND_OPT_PI_FLAG_ROUTER 0x20
#define ND_OPT_PI_FLAG_SITEPREF 0x10
struct nd_opt_rd_hdr { /* redirected header */
guint8 nd_opt_rh_type;
@ -440,7 +455,7 @@ struct nd_opt_mtu { /* MTU option */
guint16 nd_opt_mtu_reserved;
guint32 nd_opt_mtu_mtu;
};
/* BT INSERT BEGIN */
struct nd_opt_adv_int { /* Advertisement Interval option */
guint8 nd_opt_adv_int_type;
guint8 nd_opt_adv_int_len;
@ -456,7 +471,15 @@ struct nd_opt_ha_info { /* Home Agent Information option */
guint16 nd_opt_ha_info_ha_life;
};
/* BT INSERT END */
struct nd_opt_route_info { /* route info */
guint8 nd_opt_rti_type;
guint8 nd_opt_rti_len;
guint8 nd_opt_rti_prefixlen;
guint8 nd_opt_rti_flags;
guint32 nd_opt_rti_lifetime;
/* prefix follows */
};
/*
* icmp6 node information
*/