This is the mail archive of the libc-hacker@cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

I think ip6.h should change


The definition of ip6_hdr in ip6.h does not comply with RFC 2460.
The reason is that the new header format is 8 bits for traffic class
and 20 bits for flow label rather than 4 bits priority and 24 bits
flow label. I also think it's a good idea to use bit fields.

Hence I suggest that the old definition below

struct ip6_hdr 
  {
    union 
      {
	struct ip6_hdrctl 
	  {
	    uint32_t ip6_un1_flow;   /* 24 bits of flow-ID */
	    uint16_t ip6_un1_plen;   /* payload length */
	    uint8_t  ip6_un1_nxt;    /* next header */
	    uint8_t  ip6_un1_hlim;   /* hop limit */
	  } ip6_un1;
	uint8_t ip6_un2_vfc;       /* 4 bits version, 4 bits priority */
      } ip6_ctlun;
    struct in6_addr ip6_src;      /* source address */
    struct 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

be replaced with something like this

struct ip6_hdr 
  {
    struct ip6_hdrctl 
      {
#if __BYTE_ORDER == __LITTLE_ENDIAN
 	uint32_t ip6_ctl_flow:20,   /* flow label */
                 ip6_ctl_class:8,   /* traffic class */
                 ip6_ctl_version:4; /* version */
#elif __BYTE_ORDER == __BIG_ENDIAN
	uint32_t ip6_ctl_version:4, /* version */
                 ip6_ctl_class:8,   /* traffic class */
                 ip6_ctl_flow:20;   /* flow label */
#else
# error "Please fix <bits/endian.h>"
#endif
	uint16_t ip6_ctl_plen;   /* payload length */
	uint8_t  ip6_ctl_nxt;    /* next header */
	uint8_t  ip6_ctl_hlim;   /* hop limit */
      } ip6_ctl;
    struct in6_addr ip6_src;      /* source address */
    struct in6_addr ip6_dst;      /* destination address */
  };

#define ip6_version ip6_ctl.ip6_ctl_version
#define ip6_class   ip6_ctl.ip6_ctl_class
#define ip6_flow    ip6_ctl.ip6_ctl_flow
#define ip6_plen    ip6_ctl.ip6_ctl_plen
#define ip6_nxt     ip6_ctl.ip6_ctl_nxt
#define ip6_hlim    ip6_ctl.ip6_ctl_hlim
#define ip6_hops    ip6_ctl.ip6_ctl_hlim

Is the ip6_hdrctl struct really necessary? These changes look good to
me, but I'm no expert in these matters. In particular I'm not quite
sure about the endian stuff. I did it similar to ip.h. The definition
definitely needs to change though, and it's better to change it now,
while there are not that much code that depends on it.

I've attached a patch for ip6.h In addition to the above, it also fixes
a couple of typos in the comments.

Stig

-- 
Duct tape is like the force.  It has a light side, and a dark side, and
it holds the universe together ...
                -- Carl Zwanzig
--- /usr/include/netinet/ip6.h	Fri Jan  1 22:38:56 1999
+++ ip6.h	Sun Jan  3 13:10:41 1999
@@ -24,33 +24,40 @@
 
 struct ip6_hdr 
   {
-    union 
+    struct ip6_hdrctl 
       {
-	struct ip6_hdrctl 
-	  {
-	    uint32_t ip6_un1_flow;   /* 24 bits of flow-ID */
-	    uint16_t ip6_un1_plen;   /* payload length */
-	    uint8_t  ip6_un1_nxt;    /* next header */
-	    uint8_t  ip6_un1_hlim;   /* hop limit */
-	  } ip6_un1;
-	uint8_t ip6_un2_vfc;       /* 4 bits version, 4 bits priority */
-      } ip6_ctlun;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ 	uint32_t ip6_ctl_flow:20,   /* flow label */
+                 ip6_ctl_class:8,   /* traffic class */
+                 ip6_ctl_version:4; /* version */
+#elif __BYTE_ORDER == __BIG_ENDIAN
+	uint32_t ip6_ctl_version:4, /* version */
+                 ip6_ctl_class:8,   /* traffic class */
+                 ip6_ctl_flow:20;   /* flow label */
+#else
+# error "Please fix <bits/endian.h>"
+#endif
+	uint16_t ip6_ctl_plen;   /* payload length */
+	uint8_t  ip6_ctl_nxt;    /* next header */
+	uint8_t  ip6_ctl_hlim;   /* hop limit */
+      } ip6_ctl;
     struct in6_addr ip6_src;      /* source address */
     struct 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
+#define ip6_version ip6_ctl.ip6_ctl_version
+#define ip6_class   ip6_ctl.ip6_ctl_class
+#define ip6_flow    ip6_ctl.ip6_ctl_flow
+#define ip6_plen    ip6_ctl.ip6_ctl_plen
+#define ip6_nxt     ip6_ctl.ip6_ctl_nxt
+#define ip6_hlim    ip6_ctl.ip6_ctl_hlim
+#define ip6_hops    ip6_ctl.ip6_ctl_hlim
 
-/* Hop-by-Hop options header.  */
+/* Hop-by-Hop options header */
 struct ip6_hbh 
   {
-    uint8_t  ip6h_nxt;        /* next hesder.  */
-    uint8_t  ip6h_len;        /* length in units of 8 octets.  */
+    uint8_t  ip6h_nxt;        /* next header */
+    uint8_t  ip6h_len;        /* length in units of 8 octets */
     /* followed by options */
   };
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]