Back to index

glibc  2.9
ip6.h
Go to the documentation of this file.
00001 /* Copyright (C) 1991-1997, 2001, 2003, 2006 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #ifndef _NETINET_IP6_H
00020 #define _NETINET_IP6_H 1
00021 
00022 #include <inttypes.h>
00023 #include <netinet/in.h>
00024 
00025 struct ip6_hdr
00026   {
00027     union
00028       {
00029        struct ip6_hdrctl
00030          {
00031            uint32_t ip6_un1_flow;   /* 4 bits version, 8 bits TC,
00032                                    20 bits flow-ID */
00033            uint16_t ip6_un1_plen;   /* payload length */
00034            uint8_t  ip6_un1_nxt;    /* next header */
00035            uint8_t  ip6_un1_hlim;   /* hop limit */
00036          } ip6_un1;
00037        uint8_t ip6_un2_vfc;       /* 4 bits version, top 4 bits tclass */
00038       } ip6_ctlun;
00039     struct in6_addr ip6_src;      /* source address */
00040     struct in6_addr ip6_dst;      /* destination address */
00041   };
00042 
00043 #define ip6_vfc   ip6_ctlun.ip6_un2_vfc
00044 #define ip6_flow  ip6_ctlun.ip6_un1.ip6_un1_flow
00045 #define ip6_plen  ip6_ctlun.ip6_un1.ip6_un1_plen
00046 #define ip6_nxt   ip6_ctlun.ip6_un1.ip6_un1_nxt
00047 #define ip6_hlim  ip6_ctlun.ip6_un1.ip6_un1_hlim
00048 #define ip6_hops  ip6_ctlun.ip6_un1.ip6_un1_hlim
00049 
00050 /* Generic extension header.  */
00051 struct ip6_ext
00052   {
00053     uint8_t  ip6e_nxt;             /* next header.  */
00054     uint8_t  ip6e_len;             /* length in units of 8 octets.  */
00055   };
00056 
00057 /* Hop-by-Hop options header.  */
00058 struct ip6_hbh
00059   {
00060     uint8_t  ip6h_nxt;             /* next header.  */
00061     uint8_t  ip6h_len;             /* length in units of 8 octets.  */
00062     /* followed by options */
00063   };
00064 
00065 /* Destination options header */
00066 struct ip6_dest
00067   {
00068     uint8_t  ip6d_nxt;             /* next header */
00069     uint8_t  ip6d_len;             /* length in units of 8 octets */
00070     /* followed by options */
00071   };
00072 
00073 /* Routing header */
00074 struct ip6_rthdr
00075   {
00076     uint8_t  ip6r_nxt;             /* next header */
00077     uint8_t  ip6r_len;             /* length in units of 8 octets */
00078     uint8_t  ip6r_type;            /* routing type */
00079     uint8_t  ip6r_segleft;  /* segments left */
00080     /* followed by routing type specific data */
00081   };
00082 
00083 /* Type 0 Routing header */
00084 struct ip6_rthdr0
00085   {
00086     uint8_t  ip6r0_nxt;            /* next header */
00087     uint8_t  ip6r0_len;            /* length in units of 8 octets */
00088     uint8_t  ip6r0_type;    /* always zero */
00089     uint8_t  ip6r0_segleft; /* segments left */
00090     uint8_t  ip6r0_reserved;       /* reserved field */
00091     uint8_t  ip6r0_slmap[3];       /* strict/loose bit map */
00092     /* followed by up to 127 struct in6_addr */
00093     struct in6_addr ip6r0_addr[0];
00094   };
00095 
00096 /* Fragment header */
00097 struct ip6_frag
00098   {
00099     uint8_t   ip6f_nxt;            /* next header */
00100     uint8_t   ip6f_reserved;       /* reserved field */
00101     uint16_t  ip6f_offlg;   /* offset, reserved, and flag */
00102     uint32_t  ip6f_ident;   /* identification */
00103   };
00104 
00105 #if BYTE_ORDER == BIG_ENDIAN
00106 # define IP6F_OFF_MASK       0xfff8  /* mask out offset from _offlg */
00107 # define IP6F_RESERVED_MASK  0x0006  /* reserved bits in ip6f_offlg */
00108 # define IP6F_MORE_FRAG      0x0001  /* more-fragments flag */
00109 #else   /* BYTE_ORDER == LITTLE_ENDIAN */
00110 # define IP6F_OFF_MASK       0xf8ff  /* mask out offset from _offlg */
00111 # define IP6F_RESERVED_MASK  0x0600  /* reserved bits in ip6f_offlg */
00112 # define IP6F_MORE_FRAG      0x0100  /* more-fragments flag */
00113 #endif
00114 
00115 /* IPv6 options */
00116 struct ip6_opt
00117   {
00118     uint8_t  ip6o_type;
00119     uint8_t  ip6o_len;
00120   };
00121 
00122 /* The high-order 3 bits of the option type define the behavior
00123  * when processing an unknown option and whether or not the option
00124  * content changes in flight.
00125  */
00126 #define IP6OPT_TYPE(o)             ((o) & 0xc0)
00127 #define IP6OPT_TYPE_SKIP    0x00
00128 #define IP6OPT_TYPE_DISCARD 0x40
00129 #define IP6OPT_TYPE_FORCEICMP      0x80
00130 #define IP6OPT_TYPE_ICMP    0xc0
00131 #define IP6OPT_TYPE_MUTABLE 0x20
00132 
00133 /* Special option types for padding.  */
00134 #define IP6OPT_PAD1  0
00135 #define IP6OPT_PADN  1
00136 
00137 #define IP6OPT_JUMBO        0xc2
00138 #define IP6OPT_NSAP_ADDR    0xc3
00139 #define IP6OPT_TUNNEL_LIMIT 0x04
00140 #define IP6OPT_ROUTER_ALERT 0x05
00141 
00142 /* Jumbo Payload Option */
00143 struct ip6_opt_jumbo
00144   {
00145     uint8_t  ip6oj_type;
00146     uint8_t  ip6oj_len;
00147     uint8_t  ip6oj_jumbo_len[4];
00148   };
00149 #define IP6OPT_JUMBO_LEN    6
00150 
00151 /* NSAP Address Option */
00152 struct ip6_opt_nsap
00153   {
00154     uint8_t  ip6on_type;
00155     uint8_t  ip6on_len;
00156     uint8_t  ip6on_src_nsap_len;
00157     uint8_t  ip6on_dst_nsap_len;
00158       /* followed by source NSAP */
00159       /* followed by destination NSAP */
00160   };
00161 
00162 /* Tunnel Limit Option */
00163 struct ip6_opt_tunnel
00164   {
00165     uint8_t  ip6ot_type;
00166     uint8_t  ip6ot_len;
00167     uint8_t  ip6ot_encap_limit;
00168   };
00169 
00170 /* Router Alert Option */
00171 struct ip6_opt_router
00172   {
00173     uint8_t  ip6or_type;
00174     uint8_t  ip6or_len;
00175     uint8_t  ip6or_value[2];
00176   };
00177 
00178 /* Router alert values (in network byte order) */
00179 #if BYTE_ORDER == BIG_ENDIAN
00180 # define IP6_ALERT_MLD      0x0000
00181 # define IP6_ALERT_RSVP     0x0001
00182 # define IP6_ALERT_AN       0x0002
00183 #else /* BYTE_ORDER == LITTLE_ENDING */
00184 # define IP6_ALERT_MLD      0x0000
00185 # define IP6_ALERT_RSVP     0x0100
00186 # define IP6_ALERT_AN       0x0200
00187 #endif
00188 
00189 #endif /* netinet/ip6.h */