Back to index

glibc  2.9
icmp6.h
Go to the documentation of this file.
00001 /* Copyright (C) 1991-1997,2000,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_ICMP6_H
00020 #define _NETINET_ICMP6_H 1
00021 
00022 #include <inttypes.h>
00023 #include <string.h>
00024 #include <sys/types.h>
00025 #include <netinet/in.h>
00026 
00027 #define ICMP6_FILTER 1
00028 
00029 #define ICMP6_FILTER_BLOCK         1
00030 #define ICMP6_FILTER_PASS          2
00031 #define ICMP6_FILTER_BLOCKOTHERS   3
00032 #define ICMP6_FILTER_PASSONLY             4
00033 
00034 struct icmp6_filter
00035   {
00036     uint32_t icmp6_filt[8];
00037   };
00038 
00039 struct icmp6_hdr
00040   {
00041     uint8_t     icmp6_type;   /* type field */
00042     uint8_t     icmp6_code;   /* code field */
00043     uint16_t    icmp6_cksum;  /* checksum field */
00044     union
00045       {
00046        uint32_t  icmp6_un_data32[1]; /* type-specific field */
00047        uint16_t  icmp6_un_data16[2]; /* type-specific field */
00048        uint8_t   icmp6_un_data8[4];  /* type-specific field */
00049       } icmp6_dataun;
00050   };
00051 
00052 #define icmp6_data32    icmp6_dataun.icmp6_un_data32
00053 #define icmp6_data16    icmp6_dataun.icmp6_un_data16
00054 #define icmp6_data8     icmp6_dataun.icmp6_un_data8
00055 #define icmp6_pptr      icmp6_data32[0]  /* parameter prob */
00056 #define icmp6_mtu       icmp6_data32[0]  /* packet too big */
00057 #define icmp6_id        icmp6_data16[0]  /* echo request/reply */
00058 #define icmp6_seq       icmp6_data16[1]  /* echo request/reply */
00059 #define icmp6_maxdelay  icmp6_data16[0]  /* mcast group membership */
00060 
00061 #define ICMP6_DST_UNREACH             1
00062 #define ICMP6_PACKET_TOO_BIG          2
00063 #define ICMP6_TIME_EXCEEDED           3
00064 #define ICMP6_PARAM_PROB              4
00065 
00066 #define ICMP6_INFOMSG_MASK  0x80    /* all informational messages */
00067 
00068 #define ICMP6_ECHO_REQUEST          128
00069 #define ICMP6_ECHO_REPLY            129
00070 #define MLD_LISTENER_QUERY          130
00071 #define MLD_LISTENER_REPORT         131
00072 #define MLD_LISTENER_REDUCTION      132
00073 
00074 #define ICMP6_DST_UNREACH_NOROUTE     0 /* no route to destination */
00075 #define ICMP6_DST_UNREACH_ADMIN       1 /* communication with destination */
00076                                         /* administratively prohibited */
00077 #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */
00078 #define ICMP6_DST_UNREACH_ADDR        3 /* address unreachable */
00079 #define ICMP6_DST_UNREACH_NOPORT      4 /* bad port */
00080 
00081 #define ICMP6_TIME_EXCEED_TRANSIT     0 /* Hop Limit == 0 in transit */
00082 #define ICMP6_TIME_EXCEED_REASSEMBLY  1 /* Reassembly time out */
00083 
00084 #define ICMP6_PARAMPROB_HEADER        0 /* erroneous header field */
00085 #define ICMP6_PARAMPROB_NEXTHEADER    1 /* unrecognized Next Header */
00086 #define ICMP6_PARAMPROB_OPTION        2 /* unrecognized IPv6 option */
00087 
00088 #define ICMP6_FILTER_WILLPASS(type, filterp) \
00089        ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0)
00090 
00091 #define ICMP6_FILTER_WILLBLOCK(type, filterp) \
00092        ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0)
00093 
00094 #define ICMP6_FILTER_SETPASS(type, filterp) \
00095        ((((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31))))
00096 
00097 #define ICMP6_FILTER_SETBLOCK(type, filterp) \
00098        ((((filterp)->icmp6_filt[(type) >> 5]) |=  (1 << ((type) & 31))))
00099 
00100 #define ICMP6_FILTER_SETPASSALL(filterp) \
00101        memset (filterp, 0, sizeof (struct icmp6_filter));
00102 
00103 #define ICMP6_FILTER_SETBLOCKALL(filterp) \
00104        memset (filterp, 0xFF, sizeof (struct icmp6_filter));
00105 
00106 #define ND_ROUTER_SOLICIT           133
00107 #define ND_ROUTER_ADVERT            134
00108 #define ND_NEIGHBOR_SOLICIT         135
00109 #define ND_NEIGHBOR_ADVERT          136
00110 #define ND_REDIRECT                 137
00111 
00112 struct nd_router_solicit      /* router solicitation */
00113   {
00114     struct icmp6_hdr  nd_rs_hdr;
00115     /* could be followed by options */
00116   };
00117 
00118 #define nd_rs_type               nd_rs_hdr.icmp6_type
00119 #define nd_rs_code               nd_rs_hdr.icmp6_code
00120 #define nd_rs_cksum              nd_rs_hdr.icmp6_cksum
00121 #define nd_rs_reserved           nd_rs_hdr.icmp6_data32[0]
00122 
00123 struct nd_router_advert       /* router advertisement */
00124   {
00125     struct icmp6_hdr  nd_ra_hdr;
00126     uint32_t   nd_ra_reachable;   /* reachable time */
00127     uint32_t   nd_ra_retransmit;  /* retransmit timer */
00128     /* could be followed by options */
00129   };
00130 
00131 #define nd_ra_type               nd_ra_hdr.icmp6_type
00132 #define nd_ra_code               nd_ra_hdr.icmp6_code
00133 #define nd_ra_cksum              nd_ra_hdr.icmp6_cksum
00134 #define nd_ra_curhoplimit        nd_ra_hdr.icmp6_data8[0]
00135 #define nd_ra_flags_reserved     nd_ra_hdr.icmp6_data8[1]
00136 #define ND_RA_FLAG_MANAGED       0x80
00137 #define ND_RA_FLAG_OTHER         0x40
00138 #define ND_RA_FLAG_HOME_AGENT    0x20
00139 #define nd_ra_router_lifetime    nd_ra_hdr.icmp6_data16[1]
00140 
00141 struct nd_neighbor_solicit    /* neighbor solicitation */
00142   {
00143     struct icmp6_hdr  nd_ns_hdr;
00144     struct in6_addr   nd_ns_target; /* target address */
00145     /* could be followed by options */
00146   };
00147 
00148 #define nd_ns_type               nd_ns_hdr.icmp6_type
00149 #define nd_ns_code               nd_ns_hdr.icmp6_code
00150 #define nd_ns_cksum              nd_ns_hdr.icmp6_cksum
00151 #define nd_ns_reserved           nd_ns_hdr.icmp6_data32[0]
00152 
00153 struct nd_neighbor_advert     /* neighbor advertisement */
00154   {
00155     struct icmp6_hdr  nd_na_hdr;
00156     struct in6_addr   nd_na_target; /* target address */
00157     /* could be followed by options */
00158   };
00159 
00160 #define nd_na_type               nd_na_hdr.icmp6_type
00161 #define nd_na_code               nd_na_hdr.icmp6_code
00162 #define nd_na_cksum              nd_na_hdr.icmp6_cksum
00163 #define nd_na_flags_reserved     nd_na_hdr.icmp6_data32[0]
00164 #if     BYTE_ORDER == BIG_ENDIAN
00165 #define ND_NA_FLAG_ROUTER        0x80000000
00166 #define ND_NA_FLAG_SOLICITED     0x40000000
00167 #define ND_NA_FLAG_OVERRIDE      0x20000000
00168 #else   /* BYTE_ORDER == LITTLE_ENDIAN */
00169 #define ND_NA_FLAG_ROUTER        0x00000080
00170 #define ND_NA_FLAG_SOLICITED     0x00000040
00171 #define ND_NA_FLAG_OVERRIDE      0x00000020
00172 #endif
00173 
00174 struct nd_redirect            /* redirect */
00175   {
00176     struct icmp6_hdr  nd_rd_hdr;
00177     struct in6_addr   nd_rd_target; /* target address */
00178     struct in6_addr   nd_rd_dst;    /* destination address */
00179     /* could be followed by options */
00180   };
00181 
00182 #define nd_rd_type               nd_rd_hdr.icmp6_type
00183 #define nd_rd_code               nd_rd_hdr.icmp6_code
00184 #define nd_rd_cksum              nd_rd_hdr.icmp6_cksum
00185 #define nd_rd_reserved           nd_rd_hdr.icmp6_data32[0]
00186 
00187 struct nd_opt_hdr             /* Neighbor discovery option header */
00188   {
00189     uint8_t  nd_opt_type;
00190     uint8_t  nd_opt_len;        /* in units of 8 octets */
00191     /* followed by option specific data */
00192   };
00193 
00194 #define ND_OPT_SOURCE_LINKADDR            1
00195 #define ND_OPT_TARGET_LINKADDR            2
00196 #define ND_OPT_PREFIX_INFORMATION  3
00197 #define ND_OPT_REDIRECTED_HEADER   4
00198 #define ND_OPT_MTU                 5
00199 #define ND_OPT_RTR_ADV_INTERVAL           7
00200 #define ND_OPT_HOME_AGENT_INFO            8
00201 
00202 struct nd_opt_prefix_info     /* prefix information */
00203   {
00204     uint8_t   nd_opt_pi_type;
00205     uint8_t   nd_opt_pi_len;
00206     uint8_t   nd_opt_pi_prefix_len;
00207     uint8_t   nd_opt_pi_flags_reserved;
00208     uint32_t  nd_opt_pi_valid_time;
00209     uint32_t  nd_opt_pi_preferred_time;
00210     uint32_t  nd_opt_pi_reserved2;
00211     struct in6_addr  nd_opt_pi_prefix;
00212   };
00213 
00214 #define ND_OPT_PI_FLAG_ONLINK      0x80
00215 #define ND_OPT_PI_FLAG_AUTO 0x40
00216 #define ND_OPT_PI_FLAG_RADDR       0x20
00217 
00218 struct nd_opt_rd_hdr          /* redirected header */
00219   {
00220     uint8_t   nd_opt_rh_type;
00221     uint8_t   nd_opt_rh_len;
00222     uint16_t  nd_opt_rh_reserved1;
00223     uint32_t  nd_opt_rh_reserved2;
00224     /* followed by IP header and data */
00225   };
00226 
00227 struct nd_opt_mtu             /* MTU option */
00228   {
00229     uint8_t   nd_opt_mtu_type;
00230     uint8_t   nd_opt_mtu_len;
00231     uint16_t  nd_opt_mtu_reserved;
00232     uint32_t  nd_opt_mtu_mtu;
00233   };
00234 
00235 struct mld_hdr
00236   {
00237     struct icmp6_hdr    mld_icmp6_hdr;
00238     struct in6_addr     mld_addr; /* multicast address */
00239   };
00240 
00241 #define mld_type        mld_icmp6_hdr.icmp6_type
00242 #define mld_code        mld_icmp6_hdr.icmp6_code
00243 #define mld_cksum       mld_icmp6_hdr.icmp6_cksum
00244 #define mld_maxdelay    mld_icmp6_hdr.icmp6_data16[0]
00245 #define mld_reserved    mld_icmp6_hdr.icmp6_data16[1]
00246 
00247 #define ICMP6_ROUTER_RENUMBERING    138
00248 
00249 struct icmp6_router_renum    /* router renumbering header */
00250   {
00251     struct icmp6_hdr    rr_hdr;
00252     uint8_t             rr_segnum;
00253     uint8_t             rr_flags;
00254     uint16_t            rr_maxdelay;
00255     uint32_t            rr_reserved;
00256   };
00257 
00258 #define rr_type             rr_hdr.icmp6_type
00259 #define rr_code         rr_hdr.icmp6_code
00260 #define rr_cksum        rr_hdr.icmp6_cksum
00261 #define rr_seqnum       rr_hdr.icmp6_data32[0]
00262 
00263 /* Router renumbering flags */
00264 #define ICMP6_RR_FLAGS_TEST             0x80
00265 #define ICMP6_RR_FLAGS_REQRESULT        0x40
00266 #define ICMP6_RR_FLAGS_FORCEAPPLY       0x20
00267 #define ICMP6_RR_FLAGS_SPECSITE         0x10
00268 #define ICMP6_RR_FLAGS_PREVDONE         0x08
00269 
00270 struct rr_pco_match    /* match prefix part */
00271   {
00272     uint8_t             rpm_code;
00273     uint8_t             rpm_len;
00274     uint8_t             rpm_ordinal;
00275     uint8_t             rpm_matchlen;
00276     uint8_t             rpm_minlen;
00277     uint8_t             rpm_maxlen;
00278     uint16_t            rpm_reserved;
00279     struct in6_addr     rpm_prefix;
00280   };
00281 
00282 /* PCO code values */
00283 #define RPM_PCO_ADD             1
00284 #define RPM_PCO_CHANGE          2
00285 #define RPM_PCO_SETGLOBAL       3
00286 
00287 struct rr_pco_use      /* use prefix part */
00288   {
00289     uint8_t             rpu_uselen;
00290     uint8_t             rpu_keeplen;
00291     uint8_t             rpu_ramask;
00292     uint8_t             rpu_raflags;
00293     uint32_t            rpu_vltime;
00294     uint32_t            rpu_pltime;
00295     uint32_t            rpu_flags;
00296     struct in6_addr     rpu_prefix;
00297   };
00298 
00299 #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK  0x20
00300 #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO    0x10
00301 
00302 #if BYTE_ORDER == BIG_ENDIAN
00303 # define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000
00304 # define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000
00305 #elif BYTE_ORDER == LITTLE_ENDIAN
00306 # define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80
00307 # define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40
00308 #endif
00309 
00310 struct rr_result       /* router renumbering result message */
00311   {
00312     uint16_t            rrr_flags;
00313     uint8_t             rrr_ordinal;
00314     uint8_t             rrr_matchedlen;
00315     uint32_t            rrr_ifid;
00316     struct in6_addr     rrr_prefix;
00317   };
00318 
00319 #if BYTE_ORDER == BIG_ENDIAN
00320 # define ICMP6_RR_RESULT_FLAGS_OOB       0x0002
00321 # define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0001
00322 #elif BYTE_ORDER == LITTLE_ENDIAN
00323 # define ICMP6_RR_RESULT_FLAGS_OOB       0x0200
00324 # define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100
00325 #endif
00326 
00327 /* Mobile IPv6 extension: Advertisement Interval.  */
00328 struct nd_opt_adv_interval
00329   {
00330     uint8_t   nd_opt_adv_interval_type;
00331     uint8_t   nd_opt_adv_interval_len;
00332     uint16_t  nd_opt_adv_interval_reserved;
00333     uint32_t  nd_opt_adv_interval_ival;
00334   };
00335 
00336 /* Mobile IPv6 extension: Home Agent Info.  */
00337 struct nd_opt_home_agent_info
00338   {
00339     uint8_t   nd_opt_home_agent_info_type;
00340     uint8_t   nd_opt_home_agent_info_len;
00341     uint16_t  nd_opt_home_agent_info_reserved;
00342     int16_t   nd_opt_home_agent_info_preference;
00343     uint16_t  nd_opt_home_agent_info_lifetime;
00344   };
00345 
00346 #endif /* netinet/icmpv6.h */