Ethereal-dev: [ethereal-dev] IPv6 fragment patch

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Jochen Friedrich <jochen+ethereal@xxxxxxxx>
Date: Sun, 19 Mar 2000 10:13:56 +0100 (CET)
Hi there,

this patch fixes dissecting IPv6 fragments. Fragment offsets are
calculated correctly and no protocol dissection is attempted for fragments
with offset > 0.

Cheers,
Jochen

Index: packet-ipv6.c
===================================================================
RCS file: /cvsroot/ethereal/packet-ipv6.c,v
retrieving revision 1.30
diff -c -r1.30 packet-ipv6.c
*** packet-ipv6.c	2000/03/14 06:03:22	1.30
--- packet-ipv6.c	2000/03/19 09:07:49
***************
*** 137,154 ****
  }
  
  static int
! dissect_frag6(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
      struct ip6_frag frag;
      int len;
  
      memcpy(&frag, (void *) &pd[offset], sizeof(frag));
      len = sizeof(frag);
! 
      if (check_col(fd, COL_INFO)) {
  	col_add_fstr(fd, COL_INFO,
  	    "IPv6 fragment (nxt=%s (0x%02x) off=0x%04x id=0x%x)",
  	    ipprotostr(frag.ip6f_nxt), frag.ip6f_nxt,
! 	    (frag.ip6f_offlg >> 3) & 0x1fff, frag.ip6f_ident);
      }
      return len;
  }
--- 137,155 ----
  }
  
  static int
! dissect_frag6(const u_char *pd, int offset, frame_data *fd, proto_tree *tree, 
!     int *fragstart) {
      struct ip6_frag frag;
      int len;
  
      memcpy(&frag, (void *) &pd[offset], sizeof(frag));
      len = sizeof(frag);
!     *fragstart = ntohs(frag.ip6f_offlg) & 0xfff8;
      if (check_col(fd, COL_INFO)) {
  	col_add_fstr(fd, COL_INFO,
  	    "IPv6 fragment (nxt=%s (0x%02x) off=0x%04x id=0x%x)",
  	    ipprotostr(frag.ip6f_nxt), frag.ip6f_nxt,
! 	    *fragstart, frag.ip6f_ident);
      }
      return len;
  }
***************
*** 254,259 ****
--- 255,261 ----
    guint8 nxt;
    int advance;
    int poffset;
+   int frag;
  
    struct ip6_hdr ipv6;
  
***************
*** 332,337 ****
--- 334,340 ----
    /* start of the new header (could be a extension header) */
    nxt = pd[poffset = offset + offsetof(struct ip6_hdr, ip6_nxt)];
    offset += sizeof(struct ip6_hdr);
+   frag = 0;
  
  again:
      switch (nxt) {
***************
*** 349,355 ****
  	offset += advance;
  	goto again;
      case IP_PROTO_FRAGMENT:
! 	advance = dissect_frag6(pd, offset, fd, tree);
  	nxt = pd[poffset = offset];
  	offset += advance;
  	goto again;
--- 352,358 ----
  	offset += advance;
  	goto again;
      case IP_PROTO_FRAGMENT:
! 	advance = dissect_frag6(pd, offset, fd, tree, &frag);
  	nxt = pd[poffset = offset];
  	offset += advance;
  	goto again;
***************
*** 357,363 ****
  #ifdef TEST_FINALHDR
  	proto_tree_add_item_hidden(ipv6_tree, hf_ipv6_final, poffset, 1, nxt);
  #endif
! 	dissect_icmpv6(pd, offset, fd, tree);
  	break;
      case IP_PROTO_NONE:
  #ifdef TEST_FINALHDR
--- 360,369 ----
  #ifdef TEST_FINALHDR
  	proto_tree_add_item_hidden(ipv6_tree, hf_ipv6_final, poffset, 1, nxt);
  #endif
! 	if (!frag)
! 		dissect_icmpv6(pd, offset, fd, tree);
! 	else
! 		dissect_data(pd, offset, fd, tree);
  	break;
      case IP_PROTO_NONE:
  #ifdef TEST_FINALHDR
***************
*** 384,396 ****
  #ifdef TEST_FINALHDR
  	proto_tree_add_item_hidden(ipv6_tree, hf_ipv6_final, poffset, 1, nxt);
  #endif
! 	dissect_tcp(pd, offset, fd, tree);
  	break;
      case IP_PROTO_UDP:
  #ifdef TEST_FINALHDR
  	proto_tree_add_item_hidden(ipv6_tree, hf_ipv6_final, poffset, 1, nxt);
  #endif
! 	dissect_udp(pd, offset, fd, tree);
  	break;
      case IP_PROTO_PIM:
  #ifdef TEST_FINALHDR
--- 390,408 ----
  #ifdef TEST_FINALHDR
  	proto_tree_add_item_hidden(ipv6_tree, hf_ipv6_final, poffset, 1, nxt);
  #endif
! 	if (!frag)
! 		dissect_tcp(pd, offset, fd, tree);
! 	else
! 		dissect_data(pd, offset, fd, tree);
  	break;
      case IP_PROTO_UDP:
  #ifdef TEST_FINALHDR
  	proto_tree_add_item_hidden(ipv6_tree, hf_ipv6_final, poffset, 1, nxt);
  #endif
! 	if (!frag)
! 		dissect_udp(pd, offset, fd, tree);
! 	else
! 		dissect_data(pd, offset, fd, tree);
  	break;
      case IP_PROTO_PIM:
  #ifdef TEST_FINALHDR

-- 
----------------------------------------------------------------------
Jochen Friedrich                          NWE Network-Engineering GmbH
                                                      Linux-Systemhaus

                                                      Wingertstr. 70/1 
6-bone: JF3-6BONE                                  D-68809 Neulussheim
e-mail: jochen@xxxxxx                      voice: +49 (0) 6205 3920-59 
web:   http://www.nwe.de                   fax:   +49 (0) 6205 3920-58
----------------------------------------------------------------------