diff options
-rw-r--r-- | epan/dissectors/packet-6lowpan.c | 62 | ||||
-rw-r--r-- | epan/dissectors/packet-ipv6.c | 32 | ||||
-rw-r--r-- | epan/dissectors/packet-ipv6.h | 25 |
3 files changed, 59 insertions, 60 deletions
diff --git a/epan/dissectors/packet-6lowpan.c b/epan/dissectors/packet-6lowpan.c index 6835974b37..52483e6fcd 100644 --- a/epan/dissectors/packet-6lowpan.c +++ b/epan/dissectors/packet-6lowpan.c @@ -498,7 +498,7 @@ static gboolean lowpan_dlsrc_to_ifcid (packet_info *pinfo, guint8 *ifcid); static gboolean lowpan_dldst_to_ifcid (packet_info *pinfo, guint8 *ifcid); static void lowpan_addr16_to_ifcid (guint16 addr, guint8 *ifcid); static void lowpan_addr16_with_panid_to_ifcid(guint16 panid, guint16 addr, guint8 *ifcid); -static tvbuff_t * lowpan_reassemble_ipv6 (tvbuff_t *tvb, packet_info *pinfo, struct ip6_hdr * ipv6, struct lowpan_nhdr * nhdr_list); +static tvbuff_t * lowpan_reassemble_ipv6 (tvbuff_t *tvb, packet_info *pinfo, struct ws_ip6_hdr *ipv6, struct lowpan_nhdr *nhdr_list); static guint8 lowpan_parse_nhc_proto (tvbuff_t *tvb, gint offset); /* Context table helpers */ @@ -835,7 +835,7 @@ lowpan_dldst_to_ifcid(packet_info *pinfo, guint8 *ifcid) *--------------------------------------------------------------- */ static tvbuff_t * -lowpan_reassemble_ipv6(tvbuff_t *tvb, packet_info *pinfo, struct ip6_hdr *ipv6, struct lowpan_nhdr *nhdr_list) +lowpan_reassemble_ipv6(tvbuff_t *tvb, packet_info *pinfo, struct ws_ip6_hdr *ipv6, struct lowpan_nhdr *nhdr_list) { gint length = 0; gint reported = 0; @@ -851,9 +851,9 @@ lowpan_reassemble_ipv6(tvbuff_t *tvb, packet_info *pinfo, struct ip6_hdr *ipv6, ipv6->ip6_plen = g_ntohs(reported); /* Allocate a buffer for the packet and copy in the IPv6 header. */ - buffer = (guint8 *)wmem_alloc(pinfo->pool, length + sizeof(struct ip6_hdr)); - memcpy(buffer, ipv6, sizeof(struct ip6_hdr)); - cursor = buffer + sizeof(struct ip6_hdr); + buffer = (guint8 *)wmem_alloc(pinfo->pool, length + IPv6_HDR_SIZE); + memcpy(buffer, ipv6, IPv6_HDR_SIZE); + cursor = buffer + IPv6_HDR_SIZE; /* Add the next headers into the buffer. */ for (nhdr = nhdr_list; nhdr; nhdr = nhdr->next) { @@ -862,7 +862,7 @@ lowpan_reassemble_ipv6(tvbuff_t *tvb, packet_info *pinfo, struct ip6_hdr *ipv6, }; /* Return the reassembled packet. */ - return tvb_new_child_real_data(tvb, buffer, length + (int)sizeof(struct ip6_hdr), reported + (int)sizeof(struct ip6_hdr)); + return tvb_new_child_real_data(tvb, buffer, length + IPv6_HDR_SIZE, reported + IPv6_HDR_SIZE); } /* lowpan_reassemble_ipv6 */ /*FUNCTION:------------------------------------------------------ @@ -1108,7 +1108,8 @@ dissect_6lowpan_hc1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint dg tvbuff_t * ipv6_tvb; /* IPv6 header. */ guint8 ipv6_class; - struct ip6_hdr ipv6; + guint32 ipv6_flow; + struct ws_ip6_hdr ipv6; struct lowpan_nhdr *nhdr_list; static const int * hc1_encodings[] = { &hf_6lowpan_hc1_source_prefix, @@ -1176,9 +1177,9 @@ dissect_6lowpan_hc1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint dg bit_offset = offset << 3; /* Parse hop limit */ - ipv6.ip6_hops = tvb_get_bits8(tvb, bit_offset, LOWPAN_IPV6_HOP_LIMIT_BITS); + ipv6.ip6_hlim = tvb_get_bits8(tvb, bit_offset, LOWPAN_IPV6_HOP_LIMIT_BITS); proto_tree_add_uint(tree, hf_6lowpan_hop_limit, tvb, bit_offset>>3, - BITS_TO_BYTE_LEN(bit_offset, LOWPAN_IPV6_HOP_LIMIT_BITS), ipv6.ip6_hops); + BITS_TO_BYTE_LEN(bit_offset, LOWPAN_IPV6_HOP_LIMIT_BITS), ipv6.ip6_hlim); bit_offset += LOWPAN_IPV6_HOP_LIMIT_BITS; /*===================================================== @@ -1245,7 +1246,7 @@ dissect_6lowpan_hc1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint dg /* Parse the traffic class and flow label. */ ipv6_class = 0; - ipv6.ip6_flow = 0; + ipv6_flow = 0; if (!(hc1_encoding & LOWPAN_HC1_TRAFFIC_CLASS)) { /* Parse the traffic class. */ ipv6_class = tvb_get_bits8(tvb, bit_offset, LOWPAN_IPV6_TRAFFIC_CLASS_BITS); @@ -1254,16 +1255,17 @@ dissect_6lowpan_hc1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint dg bit_offset += LOWPAN_IPV6_TRAFFIC_CLASS_BITS; /* Parse the flow label. */ - ipv6.ip6_flow = tvb_get_bits32(tvb, bit_offset, LOWPAN_IPV6_FLOW_LABEL_BITS, ENC_BIG_ENDIAN); + ipv6_flow = tvb_get_bits32(tvb, bit_offset, LOWPAN_IPV6_FLOW_LABEL_BITS, ENC_BIG_ENDIAN); proto_tree_add_uint(tree, hf_6lowpan_flow_label, tvb, bit_offset>>3, - BITS_TO_BYTE_LEN(bit_offset, LOWPAN_IPV6_FLOW_LABEL_BITS), ipv6.ip6_flow); + BITS_TO_BYTE_LEN(bit_offset, LOWPAN_IPV6_FLOW_LABEL_BITS), ipv6_flow); bit_offset += LOWPAN_IPV6_FLOW_LABEL_BITS; } /* Rebuild the IPv6 flow label, traffic class and version fields. */ - ipv6.ip6_flow |= ((guint32)ipv6_class << LOWPAN_IPV6_FLOW_LABEL_BITS); - ipv6.ip6_flow |= ((guint32)0x6 << (LOWPAN_IPV6_TRAFFIC_CLASS_BITS + LOWPAN_IPV6_FLOW_LABEL_BITS)); - ipv6.ip6_flow = g_ntohl(ipv6.ip6_flow); + ipv6.ip6_ctl_flow = ipv6_flow; + ipv6.ip6_ctl_flow |= ((guint32)ipv6_class << LOWPAN_IPV6_FLOW_LABEL_BITS); + ipv6.ip6_ctl_flow |= ((guint32)0x6 << (LOWPAN_IPV6_TRAFFIC_CLASS_BITS + LOWPAN_IPV6_FLOW_LABEL_BITS)); + ipv6.ip6_ctl_flow = g_ntohl(ipv6.ip6_ctl_flow); /* Parse the IPv6 next header field. */ if (next_header == LOWPAN_HC1_NEXT_UDP) { @@ -1330,11 +1332,11 @@ dissect_6lowpan_hc1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint dg } /* Compute the length from the fragmentation headers. */ else if (dgram_size >= 0) { - if (dgram_size < (gint)sizeof(struct ip6_hdr)) { + if (dgram_size < IPv6_HDR_SIZE) { /* Datagram size is too small */ return NULL; } - udp.length = dgram_size - (gint)sizeof(struct ip6_hdr); + udp.length = dgram_size - IPv6_HDR_SIZE; } /* Compute the length from the tvbuff size. */ else { @@ -1380,7 +1382,7 @@ dissect_6lowpan_hc1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint dg nhdr_list->reported = tvb_reported_length_remaining(tvb, offset); } else { - nhdr_list->reported = dgram_size - (int)sizeof(struct ip6_hdr); + nhdr_list->reported = dgram_size - IPv6_HDR_SIZE; } tvb_memcpy(tvb, LOWPAN_NHDR_DATA(nhdr_list), offset, nhdr_list->length); } @@ -1440,7 +1442,7 @@ dissect_6lowpan_iphc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint d guint8 ipv6_dscp = 0; guint8 ipv6_ecn = 0; guint32 ipv6_flowlabel = 0; - struct ip6_hdr ipv6; + struct ws_ip6_hdr ipv6; tvbuff_t * ipv6_tvb; /* Next header chain */ struct lowpan_nhdr *nhdr_list; @@ -1559,11 +1561,11 @@ dissect_6lowpan_iphc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint d } /* Rebuild the IPv6 flow label, traffic class and version fields. */ - ipv6.ip6_flow = ipv6_flowlabel; - ipv6.ip6_flow |= ((guint32)ipv6_ecn << LOWPAN_IPV6_FLOW_LABEL_BITS); - ipv6.ip6_flow |= ((guint32)ipv6_dscp << (LOWPAN_IPHC_ECN_BITS + LOWPAN_IPV6_FLOW_LABEL_BITS)); - ipv6.ip6_flow |= ((guint32)0x6 << (LOWPAN_IPV6_TRAFFIC_CLASS_BITS + LOWPAN_IPV6_FLOW_LABEL_BITS)); - ipv6.ip6_flow = g_ntohl(ipv6.ip6_flow); + ipv6.ip6_ctl_flow = ipv6_flowlabel; + ipv6.ip6_ctl_flow |= ((guint32)ipv6_ecn << LOWPAN_IPV6_FLOW_LABEL_BITS); + ipv6.ip6_ctl_flow |= ((guint32)ipv6_dscp << (LOWPAN_IPHC_ECN_BITS + LOWPAN_IPV6_FLOW_LABEL_BITS)); + ipv6.ip6_ctl_flow |= ((guint32)0x6 << (LOWPAN_IPV6_TRAFFIC_CLASS_BITS + LOWPAN_IPV6_FLOW_LABEL_BITS)); + ipv6.ip6_ctl_flow = g_ntohl(ipv6.ip6_ctl_flow); /* Convert back to byte offsets. */ offset >>= 3; @@ -1792,7 +1794,7 @@ dissect_6lowpan_iphc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint d ipv6.ip6_nxt = lowpan_parse_nhc_proto(tvb, offset); /* Parse the 6LoWPAN NHC fields. */ - nhdr_list = dissect_6lowpan_iphc_nhc(tvb, pinfo, tree, offset, dgram_size - (int)sizeof(struct ip6_hdr), siid, diid); + nhdr_list = dissect_6lowpan_iphc_nhc(tvb, pinfo, tree, offset, dgram_size - IPv6_HDR_SIZE, siid, diid); } /* Create an extension header for the remaining payload. */ else { @@ -1805,7 +1807,7 @@ dissect_6lowpan_iphc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gint d nhdr_list->reported = tvb_reported_length_remaining(tvb, offset); } else { - nhdr_list->reported = dgram_size - (int)sizeof(struct ip6_hdr); + nhdr_list->reported = dgram_size - IPv6_HDR_SIZE; } tvb_memcpy(tvb, LOWPAN_NHDR_DATA(nhdr_list), offset, nhdr_list->length); } @@ -2395,17 +2397,17 @@ dissect_6lowpan_frag_first(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, } else if (tvb_get_bits8(frag_tvb, 0, LOWPAN_PATTERN_HC1_BITS) == LOWPAN_PATTERN_HC1) { /* Check if the datagram size is sane. */ - if (dgram_size < (gint)sizeof(struct ip6_hdr)) { + if (dgram_size < IPv6_HDR_SIZE) { expert_add_info_format(pinfo, length_item, &ei_6lowpan_bad_ipv6_header_length, - "Length is less than IPv6 header length %u", (guint)sizeof(struct ip6_hdr)); + "Length is less than IPv6 header length %u", IPv6_HDR_SIZE); } frag_tvb = dissect_6lowpan_hc1(frag_tvb, pinfo, tree, dgram_size, siid, diid); } else if (tvb_get_bits8(frag_tvb, 0, LOWPAN_PATTERN_IPHC_BITS) == LOWPAN_PATTERN_IPHC) { /* Check if the datagram size is sane. */ - if (dgram_size < (gint)sizeof(struct ip6_hdr)) { + if (dgram_size < IPv6_HDR_SIZE) { expert_add_info_format(pinfo, length_item, &ei_6lowpan_bad_ipv6_header_length, - "Length is less than IPv6 header length %u", (guint)sizeof(struct ip6_hdr)); + "Length is less than IPv6 header length %u", IPv6_HDR_SIZE); } frag_tvb = dissect_6lowpan_iphc(frag_tvb, pinfo, tree, dgram_size, siid, diid); } diff --git a/epan/dissectors/packet-ipv6.c b/epan/dissectors/packet-ipv6.c index 762ecde635..1a31ddc0dd 100644 --- a/epan/dissectors/packet-ipv6.c +++ b/epan/dissectors/packet-ipv6.c @@ -61,10 +61,7 @@ void proto_register_ipv6(void); void proto_reg_handoff_ipv6(void); -#define IPv6_HDR_SIZE 40 -#define IPv6_ADDR_SIZE 16 - -#define IPv6_HDR_TCLS(ipv6) ((guint8)(g_ntohl((ipv6)->ip6_flow) >> 20)) +#define IPv6_HDR_TCLS(ipv6) _ipv6_hdr_tcls(ipv6) /* Option types and related macros */ #define IP6OPT_PAD1 0x00 /* 00 0 00000 = 0 */ @@ -339,6 +336,15 @@ extern const struct e_in6_addr *tvb_get_ptr_ipv6(tvbuff_t tvb, int offset); #define tvb_get_ptr_ipv6(tvb, offset) \ ((const struct e_in6_addr *)tvb_get_ptr(tvb, offset, IPv6_ADDR_SIZE)) +static inline guint8 _ipv6_hdr_tcls(const struct ws_ip6_hdr *hdr) +{ + guint8 hi, low; + const guint8 *p = (const guint8 *)hdr; + + hi = p[0] << 4; + low = p[1] >> 4; + return (hi & 0xf0) | (low & 0x0f); +} static ipv6_meta_t *get_ipv6_meta_data(packet_info *pinfo) { @@ -387,11 +393,11 @@ static int ipv6_conversation_packet(void *pct, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip) { conv_hash_t *hash = (conv_hash_t*) pct; - const struct ip6_hdr *ip6h = (const struct ip6_hdr *)vip; + const struct ws_ip6_hdr *ip6h = (const struct ws_ip6_hdr *)vip; address src; address dst; - /* Addresses aren't implemented as 'address' type in struct ip6_hdr */ + /* Addresses aren't implemented as 'address' type in struct ws_ip6_hdr */ src.type = dst.type = AT_IPv6; src.len = dst.len = sizeof(struct e_in6_addr); src.data = &ip6h->ip6_src; @@ -416,11 +422,11 @@ static int ipv6_hostlist_packet(void *pit, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip) { conv_hash_t *hash = (conv_hash_t*) pit; - const struct ip6_hdr *ip6h = (const struct ip6_hdr *)vip; + const struct ws_ip6_hdr *ip6h = (const struct ws_ip6_hdr *)vip; address src; address dst; - /* Addresses aren't implemented as 'address' type in struct ip6_hdr */ + /* Addresses aren't implemented as 'address' type in struct ws_ip6_hdr */ set_address(&src, AT_IPv6, sizeof(struct e_in6_addr), &ip6h->ip6_src); set_address(&dst, AT_IPv6, sizeof(struct e_in6_addr), &ip6h->ip6_dst); @@ -1840,7 +1846,7 @@ dissect_ipv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_ in the ip.proto dissector table may need it */ ws_ip iph; - struct ip6_hdr *ipv6; + struct ws_ip6_hdr *ipv6; offset = 0; @@ -1860,9 +1866,9 @@ dissect_ipv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_ ipv6_tree = proto_item_add_subtree(ipv6_item, ett_ipv6_proto); memset(&iph, 0, sizeof(iph)); - ipv6 = (struct ip6_hdr*)tvb_memdup(wmem_packet_scope(), tvb, offset, sizeof(struct ip6_hdr)); + ipv6 = (struct ws_ip6_hdr*)tvb_memdup(wmem_packet_scope(), tvb, offset, IPv6_HDR_SIZE); - version = hi_nibble(ipv6->ip6_vfc); + version = hi_nibble(*(guint8 *)ipv6); ti_ipv6_version = proto_tree_add_item(ipv6_tree, hf_ipv6_version, tvb, offset + IP6H_CTL_VFC, 1, ENC_BIG_ENDIAN); pi = proto_tree_add_item(ipv6_tree, hf_ip_version, tvb, @@ -2119,7 +2125,7 @@ dissect_ipv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_ nxt = tvb_get_guint8(tvb, offset + 6); /* Save next header value for Decode As dialog */ p_add_proto_data(pinfo->pool, pinfo, proto_ipv6, (pinfo->curr_layer_num<<8) | IPV6_PROTO_NXT_HDR, GUINT_TO_POINTER((guint)nxt)); - offset += (int)sizeof(struct ip6_hdr); + offset += IPv6_HDR_SIZE; advance = 0; if (nxt == IP_PROTO_HOPOPTS) { @@ -2169,7 +2175,7 @@ dissect_ipv6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_ tvb_reported_length(tvb) - 40); } /* Adjust the length of this tvbuff to include only the IPv6 datagram. */ - set_actual_length(tvb, plen + (guint)sizeof (struct ip6_hdr)); + set_actual_length(tvb, plen + IPv6_HDR_SIZE); plen -= advance; save_fragmented = pinfo->fragmented; diff --git a/epan/dissectors/packet-ipv6.h b/epan/dissectors/packet-ipv6.h index 3d0b3485ae..2815408252 100644 --- a/epan/dissectors/packet-ipv6.h +++ b/epan/dissectors/packet-ipv6.h @@ -26,31 +26,22 @@ #include <epan/ipv6.h> +#define IPv6_HDR_SIZE 40 +#define IPv6_ADDR_SIZE 16 + /* * Definition for internet protocol version 6. * RFC 2460 */ -struct ip6_hdr { - union { - struct ip6_hdrctl { - guint32 ip6_un1_flow; /* version, class, flow */ - guint16 ip6_un1_plen; /* payload length */ - guint8 ip6_un1_nxt; /* next header */ - guint8 ip6_un1_hlim; /* hop limit */ - } ip6_un1; - guint8 ip6_un2_vfc; /* 4 bits version, 4 bits class */ - } ip6_ctlun; +struct ws_ip6_hdr { + guint32 ip6_ctl_flow; /* version, class, flow */ + guint16 ip6_plen; /* payload length */ + guint8 ip6_nxt; /* next header */ + guint8 ip6_hlim; /* hop limit */ struct e_in6_addr ip6_src; /* source address */ struct e_in6_addr ip6_dst; /* destination address */ }; -#define ip6_vfc ip6_ctlun.ip6_un2_vfc -#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow -#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen -#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt -#define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim -#define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim - /* Offsets of fields within an IPv6 header. */ #define IP6H_CTL 0 #define IP6H_CTL_FLOW 0 |