Tech-invite3GPPspaceIETFspace
96959493929190898887868584838281807978777675747372717069686766656463626160595857565554535251504948474645444342414039383736353433323130292827262524232221201918171615141312111009080706050403020100
in Index   Prev   Next

RFC 3542

Advanced Sockets Application Program Interface (API) for IPv6

Pages: 77
Informational
Errata
Obsoletes:  2292
Part 1 of 3 – Pages 1 to 17
None   None   Next

Top   ToC   RFC3542 - Page 1
Network Working Group                                         W. Stevens
Request for Comments: 3542                                     M. Thomas
Obsoletes: 2292                                               Consultant
Category: Informational                                      E. Nordmark
                                                                     Sun
                                                               T. Jinmei
                                                                 Toshiba
                                                                May 2003


     Advanced Sockets Application Program Interface (API) for IPv6

Status of this Memo

   This memo provides information for the Internet community.  It does
   not specify an Internet standard of any kind.  Distribution of this
   memo is unlimited.

Copyright Notice

   Copyright (C) The Internet Society (2003).  All Rights Reserved.

Abstract

This document provides sockets Application Program Interface (API) to support "advanced" IPv6 applications, as a supplement to a separate specification, RFC 3493. The expected applications include Ping, Traceroute, routing daemons and the like, which typically use raw sockets to access IPv6 or ICMPv6 header fields. This document proposes some portable interfaces for applications that use raw sockets under IPv6. There are other features of IPv6 that some applications will need to access: interface identification (specifying the outgoing interface and determining the incoming interface), IPv6 extension headers, and path Maximum Transmission Unit (MTU) information. This document provides API access to these features too. Additionally, some extended interfaces to libraries for the "r" commands are defined. The extension will provide better backward compatibility to existing implementations that are not IPv6-capable.
Top   ToC   RFC3542 - Page 2

Table of Contents

1. Introduction .............................................. 3 2. Common Structures and Definitions ......................... 5 2.1 The ip6_hdr Structure ................................ 6 2.1.1 IPv6 Next Header Values ....................... 6 2.1.2 IPv6 Extension Headers ........................ 7 2.1.3 IPv6 Options .................................. 8 2.2 The icmp6_hdr Structure .............................. 10 2.2.1 ICMPv6 Type and Code Values ................... 10 2.2.2 ICMPv6 Neighbor Discovery Definitions ......... 11 2.2.3 Multicast Listener Discovery Definitions ...... 14 2.2.4 ICMPv6 Router Renumbering Definitions ......... 14 2.3 Address Testing Macros ............................... 16 2.4 Protocols File ....................................... 16 3. IPv6 Raw Sockets .......................................... 17 3.1 Checksums ............................................ 18 3.2 ICMPv6 Type Filtering ................................ 19 3.3 ICMPv6 Verification of Received Packets .............. 22 4. Access to IPv6 and Extension Headers ...................... 22 4.1 TCP Implications ..................................... 24 4.2 UDP and Raw Socket Implications ...................... 25 5. Extensions to Socket Ancillary Data ....................... 26 5.1 CMSG_NXTHDR .......................................... 26 5.2 CMSG_SPACE ........................................... 26 5.3 CMSG_LEN ............................................. 27 6. Packet Information ........................................ 27 6.1 Specifying/Receiving the Interface ................... 28 6.2 Specifying/Receiving Source/Destination Address ...... 29 6.3 Specifying/Receiving the Hop Limit ................... 29 6.4 Specifying the Next Hop Address ...................... 30 6.5 Specifying/Receiving the Traffic Class value ......... 31 6.6 Additional Errors with sendmsg() and setsockopt() .... 32 6.7 Summary of Outgoing Interface Selection .............. 32 7. Routing Header Option ..................................... 33 7.1 inet6_rth_space ...................................... 35 7.2 inet6_rth_init ....................................... 35 7.3 inet6_rth_add ........................................ 36 7.4 inet6_rth_reverse .................................... 36 7.5 inet6_rth_segments ................................... 36 7.6 inet6_rth_getaddr .................................... 36 8. Hop-By-Hop Options ........................................ 37 8.1 Receiving Hop-by-Hop Options ......................... 38 8.2 Sending Hop-by-Hop Options ........................... 38 9. Destination Options ....................................... 39 9.1 Receiving Destination Options ........................ 39 9.2 Sending Destination Options .......................... 39 10. Hop-by-Hop and Destination Options Processing ............. 40
Top   ToC   RFC3542 - Page 3
        10.1  inet6_opt_init ...................................... 41
        10.2  inet6_opt_append .................................... 41
        10.3  inet6_opt_finish .................................... 42
        10.4  inet6_opt_set_val ................................... 42
        10.5  inet6_opt_next ...................................... 42
        10.6  inet6_opt_find ...................................... 43
        10.7  inet6_opt_get_val ................................... 43
   11.  Additional Advanced API Functions ......................... 44
        11.1  Sending with the Minimum MTU ........................ 44
        11.2  Sending without Fragmentation ....................... 45
        11.3  Path MTU Discovery and UDP .......................... 46
        11.4  Determining the Current Path MTU .................... 47
   12.  Ordering of Ancillary Data and IPv6 Extension Headers ..... 48
   13.  IPv6-Specific Options with IPv4-Mapped IPv6 Addresses ..... 50
   14.  Extended interfaces for rresvport, rcmd and rexec ......... 51
        14.1  rresvport_af ........................................ 51
        14.2  rcmd_af ............................................. 51
        14.3  rexec_af ............................................ 52
   15.  Summary of New Definitions ................................ 52
   16.  Security Considerations ................................... 56
   17.  Changes from RFC 2292 ..................................... 57
   18.  References ................................................ 59
   19.  Acknowledgments ........................................... 59
   20.  Appendix A: Ancillary Data Overview ....................... 60
        20.1  The msghdr Structure ................................ 60
        20.2  The cmsghdr Structure ............................... 61
        20.3  Ancillary Data Object Macros ........................ 62
              20.3.1  CMSG_FIRSTHDR ............................... 63
              20.3.2  CMSG_NXTHDR ................................. 64
              20.3.3  CMSG_DATA ................................... 65
              20.3.4  CMSG_SPACE .................................. 65
              20.3.5  CMSG_LEN .................................... 65
   21.  Appendix B: Examples Using the inet6_rth_XXX() Functions .. 65
        21.1  Sending a Routing Header ............................ 65
        21.2  Receiving Routing Headers ........................... 70
   22.  Appendix C: Examples Using the inet6_opt_XXX() Functions .. 72
        22.1  Building Options .................................... 72
        22.2  Parsing Received Options ............................ 74
   23.  Authors' Addresses ........................................ 76
   24.  Full Copyright Statement .................................. 77

1. Introduction

A separate specification [RFC-3493] contains changes to the sockets API to support IP version 6. Those changes are for TCP and UDP-based applications. This document defines some of the "advanced" features of the sockets API that are required for applications to take advantage of additional features of IPv6.
Top   ToC   RFC3542 - Page 4
   Today, the portability of applications using IPv4 raw sockets is
   quite high, but this is mainly because most IPv4 implementations
   started from a common base (the Berkeley source code) or at least
   started with the Berkeley header files.  This allows programs such as
   Ping and Traceroute, for example, to compile with minimal effort on
   many hosts that support the sockets API.  With IPv6, however, there
   is no common source code base that implementors are starting from,
   and the possibility for divergence at this level between different
   implementations is high.  To avoid a complete lack of portability
   amongst applications that use raw IPv6 sockets, some standardization
   is necessary.

   There are also features from the basic IPv6 specification that are
   not addressed in [RFC-3493]: sending and receiving Routing headers,
   Hop-by-Hop options, and Destination options, specifying the outgoing
   interface, being told of the receiving interface, and control of path
   MTU information.

   This document updates and replaces RFC 2292.  This revision is based
   on implementation experience of RFC 2292, as well as some additional
   extensions that have been found to be useful through the IPv6
   deployment.  Note, however, that further work on this document may
   still be needed.  Once the API specification becomes mature and is
   deployed among implementations, it may be formally standardized by a
   more appropriate body, such as has been done with the Basic API
   [RFC-3493].

   This document can be divided into the following main sections.

   1. Definitions of the basic constants and structures required for
      applications to use raw IPv6 sockets.  This includes structure
      definitions for the IPv6 and ICMPv6 headers and all associated
      constants (e.g., values for the Next Header field).

   2. Some basic semantic definitions for IPv6 raw sockets.  For
      example, a raw ICMPv4 socket requires the application to calculate
      and store the ICMPv4 header checksum.  But with IPv6 this would
      require the application to choose the source IPv6 address because
      the source address is part of the pseudo header that ICMPv6 now
      uses for its checksum computation.  It should be defined that with
      a raw ICMPv6 socket the kernel always calculates and stores the
      ICMPv6 header checksum.

   3. Packet information: how applications can obtain the received
      interface, destination address, and received hop limit, along with
      specifying these values on a per-packet basis.  There are a class
      of applications that need this capability and the technique should
      be portable.
Top   ToC   RFC3542 - Page 5
   4. Access to the optional Routing header, Hop-by-Hop options, and
      Destination options extension headers.

   5. Additional features required for improved IPv6 application
      portability.

   The packet information along with access to the extension headers
   (Routing header, Hop-by-Hop options, and Destination options) are
   specified using the "ancillary data" fields that were added to the
   4.3BSD Reno sockets API in 1990.  The reason is that these ancillary
   data fields are part of the Posix standard [POSIX] and should
   therefore be adopted by most vendors.

   This document does not address application access to either the
   authentication header or the encapsulating security payload header.

   Many examples in this document omit error checking in favor of
   brevity and clarity.

   We note that some of the functions and socket options defined in this
   document may have error returns that are not defined in this
   document.  Some of these possible error returns will be recognized
   only as implementations proceed.

   Datatypes in this document follow the Posix format: intN_t means a
   signed integer of exactly N bits (e.g., int16_t) and uintN_t means an
   unsigned integer of exactly N bits (e.g., uint32_t).

   Note that we use the (unofficial) terminology ICMPv4, IGMPv4, and
   ARPv4 to avoid any confusion with the newer ICMPv6 protocol.

2. Common Structures and Definitions

Many advanced applications examine fields in the IPv6 header and set and examine fields in the various ICMPv6 headers. Common structure definitions for these protocol headers are required, along with common constant definitions for the structure members. This API assumes that the fields in the protocol headers are left in the network byte order, which is big-endian for the Internet protocols. If not, then either these constants or the fields being tested must be converted at run-time, using something like htons() or htonl(). Two new header files are defined: <netinet/ip6.h> and <netinet/icmp6.h>.
Top   ToC   RFC3542 - Page 6
   When an include file is specified, that include file is allowed to
   include other files that do the actual declaration or definition.

2.1. The ip6_hdr Structure

The following structure is defined as a result of including <netinet/ip6.h>. Note that this is a new header. struct ip6_hdr { union { struct ip6_hdrctl { uint32_t ip6_un1_flow; /* 4 bits version, 8 bits TC, 20 bits 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, top 4 bits tclass */ } 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

2.1.1. IPv6 Next Header Values

IPv6 defines many new values for the Next Header field. The following constants are defined as a result of including <netinet/in.h>. #define IPPROTO_HOPOPTS 0 /* IPv6 Hop-by-Hop options */ #define IPPROTO_IPV6 41 /* IPv6 header */ #define IPPROTO_ROUTING 43 /* IPv6 Routing header */ #define IPPROTO_FRAGMENT 44 /* IPv6 fragment header */ #define IPPROTO_ESP 50 /* encapsulating security payload */ #define IPPROTO_AH 51 /* authentication header */ #define IPPROTO_ICMPV6 58 /* ICMPv6 */ #define IPPROTO_NONE 59 /* IPv6 no next header */ #define IPPROTO_DSTOPTS 60 /* IPv6 Destination options */
Top   ToC   RFC3542 - Page 7
   Berkeley-derived IPv4 implementations also define IPPROTO_IP to be 0.
   This should not be a problem since IPPROTO_IP is used only with IPv4
   sockets and IPPROTO_HOPOPTS only with IPv6 sockets.

2.1.2. IPv6 Extension Headers

Six extension headers are defined for IPv6. We define structures for all except the Authentication header and Encapsulating Security Payload header, both of which are beyond the scope of this document. The following structures are defined as a result of including <netinet/ip6.h>. /* Hop-by-Hop options header */ struct ip6_hbh { uint8_t ip6h_nxt; /* next header */ uint8_t ip6h_len; /* length in units of 8 octets */ /* followed by options */ }; /* Destination options header */ struct ip6_dest { uint8_t ip6d_nxt; /* next header */ uint8_t ip6d_len; /* length in units of 8 octets */ /* followed by options */ }; /* Routing header */ struct ip6_rthdr { uint8_t ip6r_nxt; /* next header */ uint8_t ip6r_len; /* length in units of 8 octets */ uint8_t ip6r_type; /* routing type */ uint8_t ip6r_segleft; /* segments left */ /* followed by routing type specific data */ }; /* Type 0 Routing header */ struct ip6_rthdr0 { uint8_t ip6r0_nxt; /* next header */ uint8_t ip6r0_len; /* length in units of 8 octets */ uint8_t ip6r0_type; /* always zero */ uint8_t ip6r0_segleft; /* segments left */ uint32_t ip6r0_reserved; /* reserved field */ /* followed by up to 127 struct in6_addr */ };
Top   ToC   RFC3542 - Page 8
      /* Fragment header */
      struct ip6_frag {
        uint8_t   ip6f_nxt;       /* next header */
        uint8_t   ip6f_reserved;  /* reserved field */
        uint16_t  ip6f_offlg;     /* offset, reserved, and flag */
        uint32_t  ip6f_ident;     /* identification */
      };

      #if     BYTE_ORDER == BIG_ENDIAN
      #define IP6F_OFF_MASK       0xfff8  /* mask out offset from
                                             ip6f_offlg */
      #define IP6F_RESERVED_MASK  0x0006  /* reserved bits in
                                             ip6f_offlg */
      #define IP6F_MORE_FRAG      0x0001  /* more-fragments flag */
      #else   /* BYTE_ORDER == LITTLE_ENDIAN */
      #define IP6F_OFF_MASK       0xf8ff  /* mask out offset from
                                             ip6f_offlg */
      #define IP6F_RESERVED_MASK  0x0600  /* reserved bits in
                                             ip6f_offlg */
      #define IP6F_MORE_FRAG      0x0100  /* more-fragments flag */
      #endif

2.1.3. IPv6 Options

Several options are defined for IPv6, and we define structures and macro definitions for some of them below. The following structures are defined as a result of including <netinet/ip6.h>. /* IPv6 options */ struct ip6_opt { uint8_t ip6o_type; uint8_t ip6o_len; }; /* * The high-order 3 bits of the option type define the behavior * when processing an unknown option and whether or not the option * content changes in flight. */ #define IP6OPT_TYPE(o) ((o) & 0xc0) #define IP6OPT_TYPE_SKIP 0x00 #define IP6OPT_TYPE_DISCARD 0x40 #define IP6OPT_TYPE_FORCEICMP 0x80 #define IP6OPT_TYPE_ICMP 0xc0 #define IP6OPT_MUTABLE 0x20 #define IP6OPT_PAD1 0x00 /* 00 0 00000 */ #define IP6OPT_PADN 0x01 /* 00 0 00001 */
Top   ToC   RFC3542 - Page 9
      #define IP6OPT_JUMBO          0xc2  /* 11 0 00010 */
      #define IP6OPT_NSAP_ADDR      0xc3  /* 11 0 00011 */
      #define IP6OPT_TUNNEL_LIMIT   0x04  /* 00 0 00100 */
      #define IP6OPT_ROUTER_ALERT   0x05  /* 00 0 00101 */

      /* Jumbo Payload Option */
      struct ip6_opt_jumbo {
        uint8_t  ip6oj_type;
        uint8_t  ip6oj_len;
        uint8_t  ip6oj_jumbo_len[4];
      };
      #define IP6OPT_JUMBO_LEN   6

      /* NSAP Address Option */
      struct ip6_opt_nsap {
        uint8_t  ip6on_type;
        uint8_t  ip6on_len;
        uint8_t  ip6on_src_nsap_len;
        uint8_t  ip6on_dst_nsap_len;
          /* followed by source NSAP */
          /* followed by destination NSAP */
      };

      /* Tunnel Limit Option */
      struct ip6_opt_tunnel {
        uint8_t  ip6ot_type;
        uint8_t  ip6ot_len;
        uint8_t  ip6ot_encap_limit;
      };

      /* Router Alert Option */
      struct ip6_opt_router {
        uint8_t  ip6or_type;
        uint8_t  ip6or_len;
        uint8_t  ip6or_value[2];
      };

      /* Router alert values (in network byte order) */
      #ifdef _BIG_ENDIAN
      #define IP6_ALERT_MLD      0x0000
      #define IP6_ALERT_RSVP     0x0001
      #define  IP6_ALERT_AN      0x0002
      #else
      #define IP6_ALERT_MLD      0x0000
      #define IP6_ALERT_RSVP     0x0100
      #define IP6_ALERT_AN       0x0200
      #endif
Top   ToC   RFC3542 - Page 10

2.2. The icmp6_hdr Structure

The ICMPv6 header is needed by numerous IPv6 applications including Ping, Traceroute, router discovery daemons, and neighbor discovery daemons. The following structure is defined as a result of including <netinet/icmp6.h>. Note that this is a new header. struct icmp6_hdr { uint8_t icmp6_type; /* type field */ uint8_t icmp6_code; /* code field */ uint16_t icmp6_cksum; /* checksum field */ union { uint32_t icmp6_un_data32[1]; /* type-specific field */ uint16_t icmp6_un_data16[2]; /* type-specific field */ uint8_t icmp6_un_data8[4]; /* type-specific field */ } icmp6_dataun; }; #define icmp6_data32 icmp6_dataun.icmp6_un_data32 #define icmp6_data16 icmp6_dataun.icmp6_un_data16 #define icmp6_data8 icmp6_dataun.icmp6_un_data8 #define icmp6_pptr icmp6_data32[0] /* parameter prob */ #define icmp6_mtu icmp6_data32[0] /* packet too big */ #define icmp6_id icmp6_data16[0] /* echo request/reply */ #define icmp6_seq icmp6_data16[1] /* echo request/reply */ #define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */

2.2.1. ICMPv6 Type and Code Values

In addition to a common structure for the ICMPv6 header, common definitions are required for the ICMPv6 type and code fields. The following constants are also defined as a result of including <netinet/icmp6.h>. #define ICMP6_DST_UNREACH 1 #define ICMP6_PACKET_TOO_BIG 2 #define ICMP6_TIME_EXCEEDED 3 #define ICMP6_PARAM_PROB 4 #define ICMP6_INFOMSG_MASK 0x80 /* all informational messages */ #define ICMP6_ECHO_REQUEST 128 #define ICMP6_ECHO_REPLY 129 #define ICMP6_DST_UNREACH_NOROUTE 0 /* no route to destination */
Top   ToC   RFC3542 - Page 11
      #define ICMP6_DST_UNREACH_ADMIN       1 /* communication with
                                                 destination */
                                              /* admin. prohibited */
      #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source
                                                 address */
      #define ICMP6_DST_UNREACH_ADDR        3 /* address unreachable */
      #define ICMP6_DST_UNREACH_NOPORT      4 /* bad port */

      #define ICMP6_TIME_EXCEED_TRANSIT     0 /* Hop Limit == 0 in
                                                 transit */
      #define ICMP6_TIME_EXCEED_REASSEMBLY  1 /* Reassembly time out */

      #define ICMP6_PARAMPROB_HEADER        0 /* erroneous header
                                                 field */
      #define ICMP6_PARAMPROB_NEXTHEADER    1 /* unrecognized
                                                 Next Header */
      #define ICMP6_PARAMPROB_OPTION        2 /* unrecognized
                                                 IPv6 option */

   The five ICMP message types defined by IPv6 neighbor discovery (133-
   137) are defined in the next section.

2.2.2. ICMPv6 Neighbor Discovery Definitions

The following structures and definitions are defined as a result of including <netinet/icmp6.h>. #define ND_ROUTER_SOLICIT 133 #define ND_ROUTER_ADVERT 134 #define ND_NEIGHBOR_SOLICIT 135 #define ND_NEIGHBOR_ADVERT 136 #define ND_REDIRECT 137 struct nd_router_solicit { /* router solicitation */ struct icmp6_hdr nd_rs_hdr; /* could be followed by options */ }; #define nd_rs_type nd_rs_hdr.icmp6_type #define nd_rs_code nd_rs_hdr.icmp6_code #define nd_rs_cksum nd_rs_hdr.icmp6_cksum #define nd_rs_reserved nd_rs_hdr.icmp6_data32[0]
Top   ToC   RFC3542 - Page 12
      struct nd_router_advert {      /* router advertisement */
        struct icmp6_hdr  nd_ra_hdr;
        uint32_t   nd_ra_reachable;   /* reachable time */
        uint32_t   nd_ra_retransmit;  /* retransmit timer */
          /* could be followed by options */
      };

      #define nd_ra_type               nd_ra_hdr.icmp6_type
      #define nd_ra_code               nd_ra_hdr.icmp6_code
      #define nd_ra_cksum              nd_ra_hdr.icmp6_cksum
      #define nd_ra_curhoplimit        nd_ra_hdr.icmp6_data8[0]
      #define nd_ra_flags_reserved     nd_ra_hdr.icmp6_data8[1]
      #define ND_RA_FLAG_MANAGED       0x80
      #define ND_RA_FLAG_OTHER         0x40
      #define nd_ra_router_lifetime    nd_ra_hdr.icmp6_data16[1]

      struct nd_neighbor_solicit {   /* neighbor solicitation */
        struct icmp6_hdr  nd_ns_hdr;
        struct in6_addr   nd_ns_target; /* target address */
          /* could be followed by options */
      };

      #define nd_ns_type               nd_ns_hdr.icmp6_type
      #define nd_ns_code               nd_ns_hdr.icmp6_code
      #define nd_ns_cksum              nd_ns_hdr.icmp6_cksum
      #define nd_ns_reserved           nd_ns_hdr.icmp6_data32[0]

      struct nd_neighbor_advert {    /* neighbor advertisement */
        struct icmp6_hdr  nd_na_hdr;
        struct in6_addr   nd_na_target; /* target address */
          /* could be followed by options */
      };

      #define nd_na_type               nd_na_hdr.icmp6_type
      #define nd_na_code               nd_na_hdr.icmp6_code
      #define nd_na_cksum              nd_na_hdr.icmp6_cksum
      #define nd_na_flags_reserved     nd_na_hdr.icmp6_data32[0]
      #if     BYTE_ORDER == BIG_ENDIAN
      #define ND_NA_FLAG_ROUTER        0x80000000
      #define ND_NA_FLAG_SOLICITED     0x40000000
      #define ND_NA_FLAG_OVERRIDE      0x20000000
      #else   /* BYTE_ORDER == LITTLE_ENDIAN */
      #define ND_NA_FLAG_ROUTER        0x00000080
      #define ND_NA_FLAG_SOLICITED     0x00000040
      #define ND_NA_FLAG_OVERRIDE      0x00000020
      #endif
Top   ToC   RFC3542 - Page 13
      struct nd_redirect {           /* redirect */
        struct icmp6_hdr  nd_rd_hdr;
        struct in6_addr   nd_rd_target; /* target address */
        struct in6_addr   nd_rd_dst;    /* destination address */
          /* could be followed by options */
      };

      #define nd_rd_type               nd_rd_hdr.icmp6_type
      #define nd_rd_code               nd_rd_hdr.icmp6_code
      #define nd_rd_cksum              nd_rd_hdr.icmp6_cksum
      #define nd_rd_reserved           nd_rd_hdr.icmp6_data32[0]

      struct nd_opt_hdr {         /* Neighbor discovery option header */
        uint8_t  nd_opt_type;
        uint8_t  nd_opt_len;      /* in units of 8 octets */
          /* followed by option specific data */
      };

      #define  ND_OPT_SOURCE_LINKADDR       1
      #define  ND_OPT_TARGET_LINKADDR       2
      #define  ND_OPT_PREFIX_INFORMATION    3
      #define  ND_OPT_REDIRECTED_HEADER     4
      #define  ND_OPT_MTU                   5

      struct nd_opt_prefix_info {    /* prefix information */
        uint8_t   nd_opt_pi_type;
        uint8_t   nd_opt_pi_len;
        uint8_t   nd_opt_pi_prefix_len;
        uint8_t   nd_opt_pi_flags_reserved;
        uint32_t  nd_opt_pi_valid_time;
        uint32_t  nd_opt_pi_preferred_time;
        uint32_t  nd_opt_pi_reserved2;
        struct in6_addr  nd_opt_pi_prefix;
      };

      #define ND_OPT_PI_FLAG_ONLINK        0x80
      #define ND_OPT_PI_FLAG_AUTO          0x40

      struct nd_opt_rd_hdr {         /* redirected header */
        uint8_t   nd_opt_rh_type;
        uint8_t   nd_opt_rh_len;
        uint16_t  nd_opt_rh_reserved1;
        uint32_t  nd_opt_rh_reserved2;
          /* followed by IP header and data */
      };
Top   ToC   RFC3542 - Page 14
      struct nd_opt_mtu {            /* MTU option */
        uint8_t   nd_opt_mtu_type;
        uint8_t   nd_opt_mtu_len;
        uint16_t  nd_opt_mtu_reserved;
        uint32_t  nd_opt_mtu_mtu;
      };

   We note that the nd_na_flags_reserved flags have the same byte
   ordering problems as we showed with ip6f_offlg.

2.2.3. Multicast Listener Discovery Definitions

The following structures and definitions are defined as a result of including <netinet/icmp6.h>. #define MLD_LISTENER_QUERY 130 #define MLD_LISTENER_REPORT 131 #define MLD_LISTENER_REDUCTION 132 struct mld_hdr { struct icmp6_hdr mld_icmp6_hdr; struct in6_addr mld_addr; /* multicast address */ }; #define mld_type mld_icmp6_hdr.icmp6_type #define mld_code mld_icmp6_hdr.icmp6_code #define mld_cksum mld_icmp6_hdr.icmp6_cksum #define mld_maxdelay mld_icmp6_hdr.icmp6_data16[0] #define mld_reserved mld_icmp6_hdr.icmp6_data16[1]

2.2.4. ICMPv6 Router Renumbering Definitions

The following structures and definitions are defined as a result of including <netinet/icmp6.h>. #define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */ struct icmp6_router_renum { /* router renumbering header */ struct icmp6_hdr rr_hdr; uint8_t rr_segnum; uint8_t rr_flags; uint16_t rr_maxdelay; uint32_t rr_reserved; }; #define rr_type rr_hdr.icmp6_type #define rr_code rr_hdr.icmp6_code #define rr_cksum rr_hdr.icmp6_cksum #define rr_seqnum rr_hdr.icmp6_data32[0]
Top   ToC   RFC3542 - Page 15
      /* Router renumbering flags */
      #define ICMP6_RR_FLAGS_TEST        0x80
      #define ICMP6_RR_FLAGS_REQRESULT   0x40
      #define ICMP6_RR_FLAGS_FORCEAPPLY  0x20
      #define ICMP6_RR_FLAGS_SPECSITE    0x10
      #define ICMP6_RR_FLAGS_PREVDONE    0x08


      struct rr_pco_match {    /* match prefix part */
        uint8_t          rpm_code;
        uint8_t          rpm_len;
        uint8_t          rpm_ordinal;
        uint8_t          rpm_matchlen;
        uint8_t          rpm_minlen;
        uint8_t          rpm_maxlen;
        uint16_t         rpm_reserved;
        struct in6_addr  rpm_prefix;
      };

      /* PCO code values */
      #define RPM_PCO_ADD              1
      #define RPM_PCO_CHANGE           2
      #define RPM_PCO_SETGLOBAL        3

      struct rr_pco_use {    /* use prefix part */
        uint8_t          rpu_uselen;
        uint8_t          rpu_keeplen;
        uint8_t          rpu_ramask;
        uint8_t          rpu_raflags;
        uint32_t         rpu_vltime;
        uint32_t         rpu_pltime;
        uint32_t         rpu_flags;
        struct in6_addr  rpu_prefix;
      };
      #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK   0x20
      #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO     0x10

      #if BYTE_ORDER == BIG_ENDIAN
      #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000
      #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000
      #elif BYTE_ORDER == LITTLE_ENDIAN
      #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80
      #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40
      #endif
Top   ToC   RFC3542 - Page 16
      struct rr_result {    /* router renumbering result message */
        uint16_t         rrr_flags;
        uint8_t          rrr_ordinal;
        uint8_t          rrr_matchedlen;
        uint32_t         rrr_ifid;
        struct in6_addr  rrr_prefix;
      };

      #if BYTE_ORDER == BIG_ENDIAN
      #define ICMP6_RR_RESULT_FLAGS_OOB        0x0002
      #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN  0x0001
      #elif BYTE_ORDER == LITTLE_ENDIAN
      #define ICMP6_RR_RESULT_FLAGS_OOB        0x0200
      #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN  0x0100
      #endif

2.3. Address Testing Macros

The basic API ([RFC-3493]) defines some macros for testing an IPv6 address for certain properties. This API extends those definitions with additional address testing macros, defined as a result of including <netinet/in.h>. int IN6_ARE_ADDR_EQUAL(const struct in6_addr *, const struct in6_addr *); This macro returns non-zero if the addresses are equal; otherwise it returns zero.

2.4. Protocols File

Many hosts provide the file /etc/protocols that contains the names of the various IP protocols and their protocol number (e.g., the value of the protocol field in the IPv4 header for that protocol, such as 1 for ICMP). Some programs then call the function getprotobyname() to obtain the protocol value that is then specified as the third argument to the socket() function. For example, the Ping program contains code of the form struct protoent *proto; proto = getprotobyname("icmp"); s = socket(AF_INET, SOCK_RAW, proto->p_proto); Common names are required for the new IPv6 protocols in this file, to provide portability of applications that call the getprotoXXX() functions.
Top   ToC   RFC3542 - Page 17
   We define the following protocol names with the values shown.  These
   are taken under http://www.iana.org/numbers.html.

      hopopt           0    # hop-by-hop options for ipv6
      ipv6            41    # ipv6
      ipv6-route      43    # routing header for ipv6
      ipv6-frag       44    # fragment header for ipv6
      esp             50    # encapsulating security payload for ipv6
      ah              51    # authentication header for ipv6
      ipv6-icmp       58    # icmp for ipv6
      ipv6-nonxt      59    # no next header for ipv6
      ipv6-opts       60    # destination options for ipv6



(page 17 continued on part 2)

Next Section