idnits 2.17.1 draft-stevens-advanced-api-01.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- ** Cannot find the required boilerplate sections (Copyright, IPR, etc.) in this document. Expected boilerplate is as follows today (2024-04-25) according to https://trustee.ietf.org/license-info : IETF Trust Legal Provisions of 28-dec-2009, Section 6.a: This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79. IETF Trust Legal Provisions of 28-dec-2009, Section 6.b(i), paragraph 2: Copyright (c) 2024 IETF Trust and the persons identified as the document authors. All rights reserved. IETF Trust Legal Provisions of 28-dec-2009, Section 6.b(i), paragraph 3: This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- ** Missing expiration date. The document expiration date should appear on the first and last page. ** The document seems to lack a 1id_guidelines paragraph about Internet-Drafts being working documents. ** The document seems to lack a 1id_guidelines paragraph about 6 months document validity. ** The document seems to lack a 1id_guidelines paragraph about the list of current Internet-Drafts. ** The document seems to lack a 1id_guidelines paragraph about the list of Shadow Directories. == No 'Intended status' indicated for this document; assuming Proposed Standard Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack an IANA Considerations section. (See Section 2.2 of https://www.ietf.org/id-info/checklist for how to handle the case when there are no actions for IANA.) ** The document seems to lack separate sections for Informative/Normative References. All references will be assumed normative when checking for downward references. ** There are 113 instances of too long lines in the document, the longest one being 11 characters in excess of 72. ** The abstract seems to contain references ([2]), which it shouldn't. Please replace those with straight textual mentions of the documents in question. == There are 5 instances of lines with non-RFC2606-compliant FQDNs in the document. ** The document seems to lack a both a reference to RFC 2119 and the recommended RFC 2119 boilerplate, even if it appears to use RFC 2119 keywords. RFC 2119 keyword, line 473: '... via raw sockets MUST be in network by...' Miscellaneous warnings: ---------------------------------------------------------------------------- == Line 247 has weird spacing: '...ip6_vfc ip6_...' == Line 248 has weird spacing: '...p6_flow ip6_c...' == Line 249 has weird spacing: '...p6_plen ip6_c...' == Line 250 has weird spacing: '...ip6_nxt ip6_...' == Line 251 has weird spacing: '...p6_hlim ip6_c...' == (33 more instances...) -- The document seems to lack a disclaimer for pre-RFC5378 work, but may have content which was first submitted before 10 November 2008. If you have contacted all the original authors and they are all willing to grant the BCP78 rights to the IETF Trust, then this is fine, and you can ignore this comment. If not, you may need to add the pre-RFC5378 disclaimer. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (February 15, 1997) is 9931 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Missing Reference: '0' is mentioned on line 393, but not defined == Missing Reference: '8' is mentioned on line 615, but not defined ** Obsolete normative reference: RFC 1883 (ref. '1') (Obsoleted by RFC 2460) -- Unexpected draft version: The latest known version of draft-ietf-ipngwg-bsd-api is -06, but you're referring to -07. ** Downref: Normative reference to an Informational draft: draft-ietf-ipngwg-bsd-api (ref. '2') ** Obsolete normative reference: RFC 1981 (ref. '3') (Obsoleted by RFC 8201) ** Obsolete normative reference: RFC 1970 (ref. '4') (Obsoleted by RFC 2461) == Outdated reference: A later version (-15) exists of draft-ietf-rsvp-spec-14 Summary: 15 errors (**), 0 flaws (~~), 11 warnings (==), 4 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 INTERNET-DRAFT W. Richard Stevens (Consultant) 3 Expires: August 15, 1997 Matt Thomas (Digital) 4 February 15, 1997 6 Advanced Sockets API for IPv6 7 9 Abstract 11 Specifications are in progress for changes to the sockets API to 12 support IP version 6 [2]. These changes are for TCP and UDP-based 13 applications and will support most end-user applications in use 14 today: Telnet and FTP clients and servers, HTTP clients and servers, 15 and the like. 17 But another class of applications exists that will also be run under 18 IPv6. We call these "advanced" applications and today this includes 19 programs such as Ping, Traceroute, routing daemons, multicast routing 20 daemons, router discovery daemons, and the like. The API feature 21 typically used by these programs that make them "advanced" is a raw 22 socket to access ICMPv4, IGMPv4, or IPv4, along with some knowledge 23 of the packet header formats used by these protocols. To provide 24 portability for applications that use raw sockets under IPv6, some 25 standardization is needed for the advanced API features. 27 There are other features of IPv6 that some applications will need to 28 access: interface identification (specifying the outgoing interface 29 and determining the incoming interface) and IPv6 extension headers 30 that are not addressed in [2]: Hop-by-Hop options, Destination 31 options, and the Routing header (source routing). This document 32 provides API access to these features too. 34 Status of this Memo 36 This document is an Internet Draft. Internet Drafts are working 37 documents of the Internet Engineering Task Force (IETF), its Areas, 38 and its Working Groups. Note that other groups may also distribute 39 working documents as Internet Drafts. 41 Internet Drafts are draft documents valid for a maximum of six 42 months. Internet Drafts may be updated, replaced, or obsoleted by 43 other documents at any time. It is not appropriate to use Internet 44 Drafts as reference material or to cite them other than as a "working 45 draft" or "work in progress". 47 To learn the current status of any Internet-Draft, please check the 48 "1id-abstracts.txt" listing contained in the internet-drafts Shadow 49 Directories on: ftp.is.co.za (Africa), nic.nordu.net (Europe), 50 ds.internic.net (US East Coast), ftp.isi.edu (US West Coast), and 51 munnari.oz.au (Pacific Rim). 53 Table of Contents 55 1. Introduction .................................................... 5 57 2. Common Structures and Definitions ............................... 6 58 2.1. The ip6hdr Structure ....................................... 6 59 2.1.1. IPv6 Next Header Values ............................. 7 60 2.2. The icmp6hdr Structure ..................................... 7 61 2.2.1. ICMPv6 Type and Code Values ......................... 8 62 2.2.2. ICMPv6 Neighbor Discovery Type and Code Values ...... 9 63 2.3. Address Testing Functions .................................. 11 64 2.4. Protocols File ............................................. 12 66 3. IPv6 Raw Sockets ................................................ 12 67 3.1. Checksums .................................................. 13 68 3.2. ICMPv6 Type Filtering ...................................... 13 70 4. Ancillary Data .................................................. 16 71 4.1. The msghdr Structure ....................................... 17 72 4.2. The cmsghdr Structure ...................................... 17 73 4.3. Ancillary Data Object Functions ............................ 19 74 4.3.1. CMSG_FIRSTHDR ....................................... 19 75 4.3.2. CMSG_NXTHDR ......................................... 20 76 4.3.3. CMSG_DATA ........................................... 21 77 4.3.4. CMSG_SPACE .......................................... 22 78 4.3.5. CMSG_LENGTH ......................................... 22 79 4.4. Summary of Options Described Using Ancillary Data .......... 22 80 4.5. TCP Access to Ancillary Data ............................... 24 82 5. Packet Information .............................................. 25 83 5.1. Specifying/Receiving the Interface ......................... 26 84 5.2. Specifying/Receiving Source/Destination Address ............ 27 85 5.3. Specifying/Receiving the Hop Limit ......................... 27 86 5.4. Specifying the Next Hop Address ............................ 28 87 5.5. Additional Errors with sendmsg() ........................... 28 89 6. Flow Labels ..................................................... 29 90 6.1. inet6_flow_assign .......................................... 31 91 6.2. inet6_flow_free ............................................ 32 92 6.3. inet6_flow_reuse ........................................... 32 94 7. Hop-By-Hop Options .............................................. 33 95 7.1. Receiving Hop-by-Hop Options ............................... 34 96 7.2. Sending Hop-by-Hop Options ................................. 35 97 7.3. Hop-by-Hop and Destination Options Processing .............. 35 98 7.3.1. inet6_option_space .................................. 35 99 7.3.2. inet6_option_init ................................... 36 100 7.3.3. inet6_option_append ................................. 36 101 7.3.4. inet6_option_alloc .................................. 37 102 7.3.5. inet6_option_next ................................... 38 103 7.3.6. inet6_option_find ................................... 38 104 7.3.7. Options Examples .................................... 39 106 8. Destination Options ............................................. 45 107 8.1. Receiving Destination Options .............................. 45 108 8.2. Sending Destination Options ................................ 46 110 9. Source Route Option ............................................. 46 111 9.1. inet6_srcrt_space .......................................... 47 112 9.2. inet6_srcrt_init ........................................... 48 113 9.3. inet6_srcrt_add ............................................ 48 114 9.4. inet6_srcrt_lasthop ........................................ 49 115 9.5. inet6_srcrt_reverse ........................................ 49 116 9.6. inet6_srcrt_segments ....................................... 49 117 9.7. inet6_srcrt_getaddr ........................................ 50 118 9.8. inet6_srcrt_getflags ....................................... 50 119 9.9. Source Route Example ....................................... 50 121 10. Ordering of Ancillary Data and IPv6 Extension Headers ........... 55 123 11. IPv6-Specific Options with IPv4-Mapped IPv6 Addresses ........... 57 125 12. rresvport_af .................................................... 57 127 13. Future Items .................................................... 58 128 13.1. Path MTU Discovery and UDP ................................ 58 129 13.2. Neighbor Reachability and UDP ............................. 58 131 14. Security Considerations ......................................... 59 133 15. Change History .................................................. 59 135 16. References ...................................................... 61 137 17. Acknowledgments ................................................. 61 139 18. Authors' Addresses .............................................. 62 141 1. Introduction 143 Specifications are in progress for changes to the sockets API to 144 support IP version 6 [2]. These changes are for TCP and UDP-based 145 applications. The current document defines some the "advanced" 146 features of the sockets API that are required for applications to 147 take advantage of additional features of IPv6. 149 Today, the portability of applications using IPv4 raw sockets is 150 quite high, but this is mainly because most IPv4 implementations 151 started from a common base (the Berkeley source code) or at least 152 started with the Berkeley headers. This allows programs such as Ping 153 and Traceroute, for example, to compile with minimal effort on many 154 hosts that support the sockets API. With IPv6, however, there is no 155 common source code base that implementors are starting from, and the 156 possibility for divergence at this level between different 157 implementations is high. To avoid a complete lack of portability 158 amongst applications that use raw IPv6 sockets, some standardization 159 is necessary. 161 There are also features from the basic IPv6 specification that are 162 not addressed in [2]: sending and receiving Hop-by-Hop options, 163 Destination options, and Routing headers, specifying the outgoing 164 interface, and being told of the receiving interface. 166 This document can be divided into the following main sections. 168 1. Definitions of the basic constants and structures required for 169 applications to use raw IPv6 sockets. This includes structure 170 definitions for the IPv6 and ICMPv6 headers and all associated 171 constants (e.g., values for the Next Header field). 173 2. Some basic semantic definitions for IPv6 raw sockets. For 174 example, a raw ICMPv4 socket requires the application to 175 calculate and store the ICMPv4 header checksum. But with IPv6 176 this would require the application to choose the source IPv6 177 address because the source address is part of the pseudo header 178 that ICMPv6 now uses for its checksum computation. It should be 179 defined that with a raw ICMPv6 socket the kernel always 180 calculates and stores the ICMPv6 header checksum. 182 3. Packet information: how applications can obtain the received 183 interface, destination address, and received hop limit, along 184 with specifying these values on a per-packet basis. There are a 185 class of applications that need this capability and the technique 186 should be portable. 188 4. Access to the optional Hop-by-Hop, Destination, and Routing 189 headers. 191 5. Additional features required for IPv6 application portability. 193 The packet information along with access to the extension headers 194 (Hop-by-Hop options, Destination options, and Routing header) are 195 specified using the "ancillary data" fields that were added to the 196 4.3BSD Reno sockets API in 1990. The reason is that these ancillary 197 data fields are part of the Posix.1g standard (which should be 198 approved in 1997) and should therefore be adopted by most vendors. 200 This document does not address application access to either the 201 authentication header or the encapsulating security payload header. 203 All examples in this document omit error checking in favor of brevity 204 and clarity. 206 We note that many of the functions and socket options defined in this 207 document may have error returns that are not defined in this 208 document. Many of these possible error returns will be recognized 209 only as implementations proceed. 211 Datatypes in this document follow the Posix.1g format: u_intN_t means 212 an unsigned integer of exactly N bits (e.g., u_int16_t) and u_intNm_t 213 means an unsigned integer of at least N bits (e.g., u_int32m_t). 215 Note that we use the (unofficial) terminology ICMPv4, IGMPv4, and 216 ARPv4 to avoid any confusion with the newer ICMPv6 protocol. 218 2. Common Structures and Definitions 220 Many advanced applications examine fields in the IPv6 header and set 221 and examine fields in the various ICMPv6 headers. Common structure 222 definitions for these headers are required, along with common 223 constant definitions for the structure members. 225 When an include file is specified, that include file is allowed to 226 include other files that do the actual declaration or definition. 228 2.1. The ip6hdr Structure 230 The following structure is defined as a result of including 231 . Note that this is a new header. 233 struct ip6hdr { 234 union { 235 struct ip6hdrctl { 236 u_int32_t ctl6_flow; /* 24 bits of flow-ID */ 237 u_int16_t ctl6_plen; /* payload length */ 238 u_int8_t ctl6_nxt; /* next header */ 239 u_int8_t ctl6_hlim; /* hop limit */ 240 } un_ctl6; 241 u_int8_t un_vfc; /* 4 bits version, 4 bits priority */ 242 } ip6_ctlun; 243 struct in6_addr ip6_src; /* source address */ 244 struct in6_addr ip6_dst; /* destination address */ 245 }; 247 #define ip6_vfc ip6_ctlun.un_vfc 248 #define ip6_flow ip6_ctlun.un_ctl6.ctl6_flow 249 #define ip6_plen ip6_ctlun.un_ctl6.ctl6_plen 250 #define ip6_nxt ip6_ctlun.un_ctl6.ctl6_nxt 251 #define ip6_hlim ip6_ctlun.un_ctl6.ctl6_hlim 252 #define ip6_hops ip6_ctlun.un_ctl6.ctl6_hlim 254 2.1.1. IPv6 Next Header Values 256 IPv6 defines many new values for the Next Header field. The 257 following constants are defined as a result of including 258 . 260 #define IPPROTO_HOPOPTS 0 /* IPv6 Hop-by-Hop options */ 261 #define IPPROTO_IPV6 41 /* IPv6 header */ 262 #define IPPROTO_ROUTING 43 /* IPv6 Routing header */ 263 #define IPPROTO_FRAGMENT 44 /* IPv6 fragmentation header */ 264 #define IPPROTO_ESP 50 /* encapsulating security payload */ 265 #define IPPROTO_AH 51 /* authentication header */ 266 #define IPPROTO_ICMPV6 58 /* ICMPv6 */ 267 #define IPPROTO_NONE 59 /* IPv6 no next header */ 268 #define IPPROTO_DSTOPTS 60 /* IPv6 Destination options */ 270 Berkeley-derived IPv4 implementations also define IPPROTO_IP to be 0. 271 This should not be a problem since IPPROTO_IP is used only with IPv4 272 sockets and IPPROTO_HOPOPTS only with IPv6 sockets. 274 2.2. The icmp6hdr Structure 276 The ICMPv6 header is needed by numerous IPv6 applications including 277 Ping, Traceroute, router discovery daemons, and neighbor discovery 278 daemons. The following structure is defined as a result of including 279 . Note that this is a new header. 281 struct icmp6hdr { 282 u_int8_t icmp6_type; /* type field */ 283 u_int8_t icmp6_code; /* code field */ 284 u_int16_t icmp6_cksum; /* checksum field */ 285 union { 286 u_int32_t icmp6_un_data32[1]; /* type-specific field */ 287 u_int16_t icmp6_un_data16[2]; /* type-specific field */ 288 u_int8_t icmp6_un_data8[4]; /* type-specific field */ 289 } icmp6_dataun; 290 }; 292 #define icmp6_data32 icmp6_dataun.icmp6_un_data32 293 #define icmp6_data16 icmp6_dataun.icmp6_un_data16 294 #define icmp6_data8 icmp6_dataun.icmp6_un_data8 295 #define icmp6_pptr icmp6_data32[0] /* parameter prob */ 296 #define icmp6_mtu icmp6_data32[0] /* packet too big */ 297 #define icmp6_id icmp6_data16[0] /* echo request/reply */ 298 #define icmp6_seq icmp6_data16[1] /* echo request/reply */ 299 #define icmp6_maxdelay icmp6_data16[0] /* mcast group membership */ 301 2.2.1. ICMPv6 Type and Code Values 303 In addition to a common structure for the ICMPv6 header, common 304 definitions are required for the ICMPv6 type and code fields. The 305 following constants are also defined as a result of including 306 . 308 #define ICMPV6_DEST_UNREACH 1 309 #define ICMPV6_PACKET_TOOBIG 2 310 #define ICMPV6_TIME_EXCEEDED 3 311 #define ICMPV6_PARAMPROB 4 313 #define ICMPV6_INFOMSG_MASK 0x80 /* all informational messages */ 315 #define ICMPV6_ECHOREQUEST 128 316 #define ICMPV6_ECHOREPLY 129 317 #define ICMPV6_MGM_QUERY 130 318 #define ICMPV6_MGM_REPORT 131 319 #define ICMPV6_MGM_REDUCTION 132 321 #define ICMPV6_DEST_UNREACH_NOROUTE 0 /* no route to destination */ 322 #define ICMPV6_DEST_UNREACH_ADMIN 1 /* communication with destination */ 323 /* administratively prohibited */ 324 #define ICMPV6_DEST_UNREACH_NOTNEIGHBOR 2 /* not a neighbor */ 325 #define ICMPV6_DEST_UNREACH_ADDR 3 /* address unreachable */ 326 #define ICMPV6_DEST_UNREACH_NOPORT 4 /* bad port */ 328 #define ICMPV6_TIME_EXCEED_HOPS 0 /* Hop Limit == 0 in transit */ 329 #define ICMPV6_TIME_EXCEED_REASSEMBLY 1 /* Reassembly time out */ 331 #define ICMPV6_PARAMPROB_HEADER 0 /* erroneous header field */ 332 #define ICMPV6_PARAMPROB_NEXTHEADER 1 /* unrecognized Next Header */ 333 #define ICMPV6_PARAMPROB_OPTION 2 /* unrecognized IPv6 option */ 335 The five ICMP message types defined by IPv6 neighbor discovery 336 (133-137) are defined in the next section. 338 2.2.2. ICMPv6 Neighbor Discovery Type and Code Values 340 The following constants are defined as a result of including 341 . 343 #define ND6_ROUTER_SOLICITATION 133 344 #define ND6_ROUTER_ADVERTISEMENT 134 345 #define ND6_NEIGHBOR_SOLICITATION 135 346 #define ND6_NEIGHBOR_ADVERTISEMENT 136 347 #define ND6_REDIRECT 137 349 enum nd6_option { 350 ND6_OPT_SOURCE_LINKADDR=1, 351 ND6_OPT_TARGET_LINKADDR=2, 352 ND6_OPT_PREFIX_INFORMATION=3, 353 ND6_OPT_REDIRECTED_HEADER=4, 354 ND6_OPT_MTU=5, 355 ND6_OPT_ENDOFLIST=256 356 }; 358 struct nd_router_solicit { /* router solicitation */ 359 struct icmp6_hdr rsol_hdr; 360 }; 362 #define rsol_type rsol_hdr.icmp6_type 363 #define rsol_code rsol_hdr.icmp6_code 364 #define rsol_cksum rsol_hdr.icmp6_cksum 365 #define rsol_reserved rsol_hdr.icmp6_data32[0] 367 struct nd_router_advert { /* router advertisement */ 368 struct icmp6_hdr radv_hdr; 369 u_int32_t radv_reachable; /* reachable time */ 370 u_int32_t radv_retransmit; /* reachable retransmit time */ 371 }; 373 #define radv_type radv_hdr.icmp6_type 374 #define radv_code radv_hdr.icmp6_code 375 #define radv_cksum radv_hdr.icmp6_cksum 376 #define radv_maxhoplimit radv_hdr.icmp6_data8[0] 377 #define radv_m_o_res radv_hdr.icmp6_data8[1] 378 #define ND6_RADV_M_BIT 0x80 379 #define ND6_RADV_O_BIT 0x40 380 #define radv_router_lifetime radv_hdr.icmp6_data16[1] 382 struct nd6_nsolicitation { /* neighbor solicitation */ 383 struct icmp6_hdr nsol6_hdr; 384 struct in6_addr nsol6_target; 385 }; 387 struct nd6_nadvertisement { /* neighbor advertisement */ 388 struct icmp6_hdr nadv6_hdr; 389 struct in6_addr nadv6_target; 391 }; 393 #define nadv6_flags nadv6_hdr.icmp6_data32[0] 394 #define ND6_NADVERFLAG_ISROUTER 0x80 395 #define ND6_NADVERFLAG_SOLICITED 0x40 396 #define ND6_NADVERFLAG_OVERRIDE 0x20 398 struct nd6_redirect { /* redirect */ 399 struct icmp6_hdr redirect_hdr; 400 struct in6_addr redirect_target; 401 struct in6_addr redirect_destination; 402 }; 404 struct nd6_opt_prefix_info { /* prefix information */ 405 u_int8_t opt_type; 406 u_int8_t opt_length; 407 u_int8_t opt_prefix_length; 408 u_int8_t opt_l_a_res; 409 u_int32_t opt_valid_life; 410 u_int32_t opt_preferred_life; 411 u_int32_t opt_reserved2; 412 struct in6_addr opt_prefix; 413 }; 415 #define ND6_OPT_PI_L_BIT 0x80 416 #define ND6_OPT_PI_A_BIT 0x40 418 struct nd6_opt_mtu { /* MTU option */ 419 u_int8_t opt_type; 420 u_int8_t opt_length; 421 u_int16_t opt_reserved; 422 u_int32_t opt_mtu; 423 }; 425 2.3. Address Testing Functions 427 The basic API ([2]) defines some functions for testing an IPv6 428 address for certain properties. This API extends those definitions 429 with additional address testing functions. 431 int in6_are_addr_equal(const struct in6_addr *, 432 const struct in6_addr *); 434 2.4. Protocols File 436 Many hosts provide the file /etc/protocols that contains the names of 437 the various IP protocols and their protocol number (e.g., the value 438 of the protocol field in the IPv4 header for that protocol, such as 1 439 for ICMP). Some programs then call the function getprotobyname() to 440 obtain the protocol value that is then specified as the third 441 argument to the socket() function. For example, the Ping program 442 contains 444 struct protoent *proto; 446 proto = getprotobyname("icmp"); 448 s = socket(AF_INET, SOCK_RAW, proto->p_proto); 450 Common names are required for the new IPv6 protocols in this file, to 451 provide portability of applications that call the getprotoXXX() 452 functions. 454 We define the two protocol names 456 ipv6 457 icmpv6 459 with values 0 and 58 (decimal), respectively. 461 3. IPv6 Raw Sockets 463 Raw sockets bypass the transport layer (TCP or UDP). With IPv4, raw 464 sockets are used to access ICMPv4, IGMPv4, and to read and write IPv4 465 datagrams containing a protocol field that the kernel does not 466 process. An example of the latter is a routing daemon for OSPF, 467 since it uses IPv4 protocol field 89. With IPv6 raw sockets will be 468 used for ICMPv6 and to read and write IPv6 datagrams containing a 469 Next Header field that the kernel does not process. Examples of the 470 latter are a routing daemon for OSPF for IPv6 and RSVP (protocol 471 field 46). 473 All data sent via raw sockets MUST be in network byte order and all 474 data received via raw sockets will be in network byte order. This 475 differs from the IPv4 raw sockets, which did not specify a byte 476 ordering and typically used the host's byte order. 478 Another difference from IPv4 raw sockets is that complete packets 479 (that is, IPv6 packets with extension headers) cannot be transferred 480 via the IPv6 raw sockets API. Instead, ancillary data objects are 481 used to transfer the extension headers, as described later in this 482 document. Should an application need access to the complete IPv6 483 packet, some other technique, such as the datalink interfaces BPF or 484 DLPI, must be used. 486 All fields in the IPv6 header that an application might want to 487 change (i.e., everything other than the version number) can be 488 modified by the application. All fields in a received IPv6 header 489 (other than the version number and Next Header fields) and all 490 extension headers are also made available to the application. Hence 491 there is no need for a socket option similar to the IPv4 IP_HDRINCL 492 socket option. 494 When we say "an ICMPv6 raw socket" we mean a socket created by 495 calling the socket function with the three arguments PF_INET6, 496 SOCK_RAW, and IPPROTO_ICMPV6. 498 3.1. Checksums 500 The kernel will calculate and insert the ICMPv6 checksum for ICMPv6 501 raw sockets, since this checksum is mandatory. 503 For other raw IPv6 sockets (that is, for raw IPv6 sockets created 504 with a third argument other than IPPROTO_ICMPV6), the application 505 must set the new IPV6_CHECKSUM socket option to have the kernel 506 compute and store a checksum. This option prevents applications from 507 having to perform source address selection on the packets they send. 508 The checksum will incorporate the IPv6 pseudo-header, defined in 509 Section 8.1 of [1]. This new socket option also specifies an integer 510 offset into the user data of where the checksum is to be placed. 512 int offset = 2; 513 setsockopt(fd, IPPROTO_IPV6, IPV6_CHECKSUM, &offset, sizeof(offset)); 515 By default, this socket option is disabled, which means the kernel 516 will not calculate and store a checksum. If the offset is set to -1 517 this tells the kernel not to calculate and store a checksum. 519 (Note: Since the checksum is always calculated by the kernel for an 520 ICMPv6 socket, applications are not able to generate ICMPv6 packets 521 with incorrect checksums (presumably for testing purposes) using this 522 API.) 524 3.2. ICMPv6 Type Filtering 526 ICMPv4 raw sockets receive most ICMPv4 messages received by the 527 kernel. (We say "most" and not "all" because Berkeley-derived 528 kernels never pass echo requests, timestamp requests, or address mask 529 requests to a raw socket. Instead these three messages are processed 530 entirely by the kernel.) But ICMPv6 is a superset of ICMPv4, also 531 including the functionality of IGMPv4 and ARPv4. This means that an 532 ICMPv6 raw socket can potentially receive many more messages than 533 would be received with an ICMPv4 raw socket: ICMP messages similar to 534 ICMPv4, along with neighbor solicitations, neighbor advertisements, 535 and the three group membership messages. 537 Most applications using an ICMPv6 raw socket care about only a small 538 subset of the ICMPv6 message types. To transfer extraneous ICMPv6 539 messages from the kernel to user can incur a significant overhead. 540 Therefore this API includes a method of filtering ICMPv6 messages by 541 the ICMPv6 type field. 543 Each ICMPv6 raw socket has an associated filter whose datatype is 544 defined as 546 struct icmpv6_filter; 548 This structure, along with the functions and constants defined later 549 in this section, are defined as a result of including the 550 header. 552 The current filter is fetched and stored using getsockopt() and 553 setsockopt() with a level of IPPROTO_ICMPV6 and an option name of 554 ICMPV6_FILTER. 556 Six functions operate on an icmp6_filter structure: 558 void ICMPV6_FILTER_SETPASSALL (struct icmp6_filter *); 559 void ICMPV6_FILTER_SETBLOCKALL(struct icmp6_filter *); 561 void ICMPV6_FILTER_SETPASS ( int, struct icmp6_filter *); 562 void ICMPV6_FILTER_SETBLOCK( int, struct icmp6_filter *); 564 int ICMPV6_FILTER_WILLPASS (int, const struct icmp6_filter *); 565 int ICMPV6_FILTER_WILLBLOCK(int, const struct icmp6_filter *); 567 The first argument to the last four functions (an integer) is an 568 ICMPv6 message type, between 0 and 255. The pointer argument to all 569 six functions is a pointer to a filter that is modified by the first 570 four functions examined by the last two functions. 572 The first two functions, SETPASSALL and SETBLOCKALL, let us specify 573 that all ICMPv6 messages are passed to the application or that all 574 ICMPv6 messages are blocked from being passed to the application. 576 The next two functions, SETPASS and SETBLOCK, let us specify that 577 messages of a given ICMPv6 type should be passed to the application 578 or not passed to the application (blocked). 580 The final two functions, WILLPASS and WILLBLOCK, return true or false 581 depending whether the specified message type is passed to the 582 application or blocked from being passed to the application by the 583 filter pointed to by the second argument. 585 When an ICMPv6 raw socket is created, it will by default pass all 586 ICMPv6 message types to the application. 588 As an example, a Ping program could execute the following: 590 struct icmp6_filter myfilt; 592 fd = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6); 594 ICMPV6_FILTER_SETBLOCKALL(&myfilt); 595 ICMPV6_FILTER_SETPASS(ICMPV6_ECHOREPLY, &myfilt); 596 setsockopt(fd, IPPROTO_ICMPV6, ICMPV6_FILTER, &myfilt, sizeof(myfilt)); 598 The filter structure is declared and then initialized to block all 599 messages types. The filter structure is then changed to allow ICMPv6 600 echo reply messages to be passed to the application and the filter is 601 installed using setsockopt(). 603 The icmp6_filter structure is similar to the fd_set datatype used 604 with the select() function in the sockets API. The icmp6_filter 605 structure is an opaque datatype and the application should not care 606 how it is implemented. All the application does with this datatype 607 is allocate a variable of this type, pass a pointer to a variable of 608 this type to getsockopt() and setsockopt(), and operate on a variable 609 of this type using the six functions that we just defined. 611 Nevertheless, it is worth showing a simple implementation of this 612 datatype and the six functions, which can be implemented as C macros. 614 struct icmp6_filter { 615 u_int32m_t data[8]; /* 8*32 = 256 bits */ 616 }; 618 #define ICMPV6_FILTER_WILLPASS(type, filterp) \ 619 ((((filterp)->data[(type) >> 5]) & (1 << ((type) & 31))) != 0) 620 #define ICMPV6_FILTER_WILLBLOCK(type, filterp) \ 621 ((((filterp)->data[(type) >> 5]) & (1 << ((type) & 31))) == 0) 622 #define ICMPV6_FILTER_SETPASS(type, filterp) \ 623 ((((filterp)->data[(type) >> 5]) |= (1 << ((type) & 31)))) 624 #define ICMPV6_FILTER_SETBLOCK(type, filterp) \ 625 ((((filterp)->data[(type) >> 5]) &= ~(1 << ((type) & 31)))) 626 #define ICMPV6_FILTER_SETPASSALL(filterp) \ 627 memset((filterp), 0xFF, sizeof(struct icmp6_filter)) 628 #define ICMPV6_FILTER_SETBLOCKALL(filterp) \ 629 memset((filterp), 0, sizeof(struct icmp6_filter)) 631 4. Ancillary Data 633 4.2BSD allowed file descriptors to be transferred between separate 634 processes across a UNIX domain socket using the sendmsg() and 635 recvmsg() functions. Two members of the msghdr structure, 636 msg_accrights and msg_accrightslen, were used to send and receive the 637 descriptors. When the OSI protocols were added to 4.3BSD Reno in 638 1990 the names of these two fields in the msghdr structure were 639 changed to msg_control and msg_controllen, because they were used by 640 the OSI protocols for "control information", although the comments in 641 the source code call this "ancillary data". 643 Other than the OSI protocols, the use of ancillary data has been 644 rare. In 4.4BSD, for example, the only use of ancillary data with 645 IPv4 is to return the destination address of a received UDP datagram 646 if the IP_RECVDSTADDR socket option is set. With Unix domain sockets 647 ancillary data is still used to send and receive descriptors. 649 Nevertheless the ancillary data fields of the msghdr structure 650 provide a clean way to pass information in addition to the data that 651 is being read or written. The inclusion of the msg_control and 652 msg_controllen members of the msghdr structure along with the cmsghdr 653 structure that is pointed to by the msg_control member is required by 654 the Posix.1g sockets API standard (which should be completed during 655 1997). 657 In this document ancillary data is used to exchange the following 658 optional information between the application and the kernel: 660 1. the send/receive interface and source/destination address, 661 2. the hop limit, 662 3. next hop address, 663 4. Hop-by-Hop options, 664 5. Destination options, and 665 6. Routing header. 667 Before describing these uses in detail, we review the definition of 668 the msghdr structure itself, the cmsghdr structure that defines an 669 ancillary data object, and some functions that operate on the 670 ancillary data objects. 672 4.1. The msghdr Structure 674 The msghdr structure is used by the recvmsg() and sendmsg() 675 functions. Its Posix.1g definition is: 677 struct msghdr { 678 void *msg_name; /* ptr to socket address structure */ 679 size_t msg_namelen; /* size of socket address structure */ 680 struct iovec *msg_iov; /* scatter/gather array */ 681 size_t msg_iovlen; /* # elements in msg_iov */ 682 void *msg_control; /* ancillary data */ 683 size_t msg_controllen; /* ancillary data buffer length */ 684 int msg_flags; /* flags on received message */ 685 }; 687 The structure is declared as a result of including . 689 (Note: Before Posix.1g the two "void *" pointers were typically "char 690 *", and the three size_t members were typically integers. The change 691 in msg_control to a "void *" pointer affects any code that increments 692 this pointer.) 694 Most Berkeley-derived implementations limit the amount of ancillary 695 data in a call to sendmsg() to no more than 108 bytes (an mbuf). 696 This API requires a minimum of 10240 bytes of ancillary data, but it 697 is recommended that the amount be limited only by the buffer space 698 reserved by the socket (which can be modified by the SO_SNDBUF socket 699 option). (Note: This magic number 10240 was picked as a value that 700 should always be large enough. 108 bytes is clearly too small as the 701 maximum size of a Type 0 Routing header is 376 bytes.) 703 4.2. The cmsghdr Structure 704 The cmsghdr structure describes ancillary data objects transferred by 705 recvmsg() and sendmsg(). Its Posix.1g definition is: 707 struct cmsghdr { 708 size_t cmsg_len; /* #bytes, including this header */ 709 int cmsg_level; /* originating protocol */ 710 int cmsg_type; /* protocol-specific type */ 711 /* followed by unsigned char cmsg_data[]; */ 712 }; 714 This structure is declared as a result of including . 716 As shown in this definition, normally there is no member with the 717 name cmsg_data[]. Instead, the data portion is accessed using the 718 CMSG_xxx() functions, as described shortly. Nevertheless, it is 719 common to refer to the cmsg_data[] member. 721 (Note: Before Posix.1g the cmsg_len member was an integer, and not a 722 size_t. On a 32-bit architecture this probably has no effect, but on 723 a 64-bit architecture this could change the size of this member from 724 4 bytes to 8 bytes and force 8 byte alignment for the structure.) 726 When ancillary data is sent or received, any number of ancillary data 727 objects can be specified by the msg_control and msg_controllen 728 members of the msghdr structure, because each object is preceded by a 729 cmsghdr structure defining the object's length (the cmsg_len member). 730 Historically Berkeley-derived implementations have passed only one 731 object at a time, but this API allows multiple objects to be passed 732 in a single call to sendmsg() or recvmsg(). The following example 733 shows two ancillary data objects in a control buffer. 735 |<--------------------------- msg_controllen -------------------------->| 736 | | 737 |<----- ancillary data object ----->|<----- ancillary data object ----->| 738 |<---------- CMSG_SPACE() --------->|<---------- CMSG_SPACE() --------->| 739 | | | 740 |<---------- cmsg_len ---------->| |<--------- cmsg_len ----------->| | 741 |<-------- CMSG_LENGTH() ------->| |<------- CMSG_LENGTH() -------->| | 742 | | | | | 743 +-----+-----+-----+--+-----------+--+-----+-----+-----+--+-----------+--+ 744 |cmsg_|cmsg_|cmsg_|XX| |XX|cmsg_|cmsg_|cmsg_|XX| |XX| 745 |len |level|type |XX|cmsg_data[]|XX|len |level|type |XX|cmsg_data[]|XX| 746 +-----+-----+-----+--+-----------+--+-----+-----+-----+--+-----------+--+ 747 ^ 748 | 749 msg_control 750 points here 751 The fields shown as "XX" are possible padding, between the cmsghdr 752 structure and the data, and between the data and the next cmsghdr 753 structure, if required by the implementation. 755 4.3. Ancillary Data Object Functions 757 To aid in the manipulation of ancillary data objects, three functions 758 from 4.4BSD are defined by Posix.1g: CMSG_DATA(), CMSG_NXTHDR(), and 759 CMSG_FIRSTHDR(). Before describing these functions, we show the 760 following example of how they might be used with a call to recvmsg(). 762 struct msghdr msg; 763 struct cmsghdr *cmsgptr; 765 /* fill in msg */ 767 /* call recvmsg() */ 769 for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL; 770 cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) { 771 if (cmsgptr->cmsg_level == ... && cmsgptr->cmsg_type == ... ) { 772 u_char *ptr; 774 ptr = CMSG_DATA(cmsgptr); 775 /* process data pointed to by ptr */ 776 } 777 } 779 We now describe the three Posix.1g functions, followed by two more 780 that are new with this API: CMSG_SPACE() and CMSG_LENGTH(). All 781 these functions are defined as a result of including . 783 4.3.1. CMSG_FIRSTHDR 785 struct cmsghdr *CMSG_FIRSTHDR(const struct msghdr *mhdr); 787 CMSG_FIRSTHDR() returns a pointer to the first cmsghdr structure in 788 the msghdr structure pointed to by mhdr. The function returns NULL 789 if there is no ancillary data pointed to the by msghdr structure 790 (that is, if either msg_control is NULL or if msg_controllen is less 791 than the size of a cmsghdr structure). 793 One possible implementation could be 794 #define CMSG_FIRSTHDR(mhdr) \ 795 ( (mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ 796 (struct cmsghdr *)(mhdr)->msg_control : \ 797 (struct cmsghdr *)NULL ) 799 (Note: Most existing implementations do not test the value of 800 msg_controllen, and just return the value of msg_control. The value 801 of msg_controllen must be tested, because if the application asks 802 recvmsg() to return ancillary data, by setting msg_control to point 803 to the application's buffer and setting msg_controllen to the length 804 of this buffer, the kernel indicates that no ancillary data is 805 available by setting msg_controllen to 0 on return. It is also 806 easier to put this test into this macro, than making the application 807 perform the test.) 809 4.3.2. CMSG_NXTHDR 811 struct cmsghdr *CMSG_NXTHDR(const struct msghdr *mhdr, 812 const struct cmsghdr *cmsg); 814 CMSG_NXTHDR() returns a pointer to the cmsghdr structure describing 815 the next ancillary data object. mhdr is a pointer to a msghdr 816 structure and cmsg is a pointer to a cmsghdr structure. If there is 817 not another ancillary data object, the return value is NULL. 819 The following behavior of this function is new to this API: if the 820 value of the cmsg pointer is NULL, a pointer to the cmsghdr structure 821 describing the first ancillary data object is returned. That is, 822 CMSG_NXTHDR(mhdr, NULL) is equivalent to CMSG_FIRSTHDR(mhdr). If 823 there are no ancillary data objects, the return value is NULL. This 824 provides an alternative way of coding the processing loop shown 825 earlier: 827 struct msghdr msg; 828 struct cmsghdr *cmsgptr = NULL; 830 /* fill in msg */ 832 /* call recvmsg() */ 834 while ((cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) != NULL) { 835 if (cmsgptr->cmsg_level == ... && cmsgptr->cmsg_type == ... ) { 836 u_char *ptr; 838 ptr = CMSG_DATA(cmsgptr); 839 /* process data pointed to by ptr */ 840 } 841 } 843 One possible implementation could be: 845 #define CMSG_NXTHDR(mhdr, cmsg) \ 846 ( ((cmsg) == NULL) ? CMSG_FIRSTHDR(mhdr) : \ 847 (((u_char *)(cmsg) + ALIGN((cmsg)->cmsg_len) \ 848 + ALIGN(sizeof(struct cmsghdr)) > \ 849 (u_char *)((mhdr)->msg_control) + (mhdr)->msg_controllen) ? \ 850 (struct cmsghdr *)NULL : \ 851 (struct cmsghdr *)((u_char *)(cmsg) + ALIGN((cmsg)->cmsg_len))) ) 853 The macro ALIGN(), which is implementation dependent, rounds its 854 argument up to the next even multiple of whatever alignment is 855 required (probably a multiple of 4 or 8 bytes). 857 4.3.3. CMSG_DATA 859 unsigned char *CMSG_DATA(const struct cmsghdr *cmsg); 861 CMSG_DATA() returns a pointer to the data (what is called the 862 cmsg_data[] member, even though such a member is not defined in the 863 structure) following a cmsghdr structure. 865 One possible implementation could be: 867 #define CMSG_DATA(cmsg) ( (u_char *)(cmsg) + \ 868 ALIGN(sizeof(struct cmsghdr)) ) 870 4.3.4. CMSG_SPACE 872 unsigned int CMSG_SPACE(unsigned int length); 874 This function is new with this API. Given the length of an ancillary 875 data object, CMSG_SPACE() returns the space required by the object 876 and its cmsghdr structure, including any padding needed to satisfy 877 alignment requirements. This function can be used, for example, to 878 allocate space dynamically for the ancillary data. This function 879 should not be used to initialize the cmsg_len member of a cmsghdr 880 structure; instead use the CMSG_LENGTH() function. 882 One possible implementation could be: 884 #define CMSG_SPACE(cmsg) ( ALIGN(sizeof(struct cmsghdr)) + \ 885 ALIGN(length) ) 887 4.3.5. CMSG_LENGTH 889 unsigned int CMSG_LENGTH(unsigned int length); 891 This function is new with this API. Given the length of an ancillary 892 data object, CMSG_LENGTH() returns the value to store in the cmsg_len 893 member of the cmsghdr structure, taking into account any padding 894 needed to satisfy alignment requirements. 896 One possible implementation could be: 898 #define CMSG_LENGTH(cmsg) ( ALIGN(sizeof(struct cmsghdr)) + length ) 900 4.4. Summary of Options Described Using Ancillary Data 902 There are six types of optional information described in this 903 document that are passed between the application and the kernel using 904 ancillary data: 906 1. the send/receive interface and source/destination address, 907 2. the hop limit, 908 3. next hop address, 909 4. Hop-by-Hop options, 910 5. Destination options, and 911 6. Routing header. 913 First, to receive any of this optional information (other than the 914 next hop address, which can only be set), the application must call 915 setsockopt() to turn on the corresponding flag: 917 int on = 1; 919 setsockopt(fd, IPPROTO_IPV6, IPV6_PKTINFO, &on, sizeof(on)); 920 setsockopt(fd, IPPROTO_IPV6, IPV6_HOPLIMIT, &on, sizeof(on)); 921 setsockopt(fd, IPPROTO_IPV6, IPV6_HOPOPTS, &on, sizeof(on)); 922 setsockopt(fd, IPPROTO_IPV6, IPV6_DSTOPTS, &on, sizeof(on)); 923 setsockopt(fd, IPPROTO_IPV6, IPV6_SRCRT, &on, sizeof(on)); 925 When any of these options are enabled, the corresponding data is 926 returned as control information by recvmsg(), as one or more 927 ancillary data objects. 929 Nothing special need be done to send any of this optional 930 information; the application just calls sendmsg() and specifies one 931 or more ancillary data objects as control information. 933 We also summarize the three cmsghdr fields that describe the 934 ancillary data objects: 936 cmsg_level cmsg_type cmsg_data[] #times 937 ------------ ------------ ------------------------ ------ 938 IPPROTO_IPV6 IPV6_PKTINFO in6_pktinfo structure once 939 IPPROTO_IPV6 IPV6_HOPLIMIT int once 940 IPPROTO_IPV6 IPV6_NEXTHOP socket address structure once 941 IPPROTO_IPV6 IPV6_HOPOPTS implementation dependent mult. 942 IPPROTO_IPV6 IPV6_DSTOPTS implementation dependent mult. 943 IPPROTO_IPV6 IPV6_SRCRT implementation dependent once 945 The final column indicates how many times an ancillary data object of 946 that type can appear as control information. The Hop-by-Hop and 947 Destination options can appear multiple times, while all the others 948 can appear only one time. 950 All these options are described in detail in following sections. All 951 the constants beginning with IPV6_ are defined as a result of 952 including the header. 954 (Note: It is up to the implementation what it passes as ancillary 955 data for the Hop-by-Hop option, Destination option, and source route 956 option, since the API to these features is through a set of 957 inet6_option_XXX() and inet6_srcrt_XXX() functions that we define 958 later. These functions serve two purposes: to simplify the interface 959 to these features (instead of requiring the application to know the 960 intimate details of the extension header formats), and to hide the 961 actual implementation from the application. Nevertheless, we show 962 some examples of these features that store the actual extension 963 header as the ancillary data. Implementations need not use this 964 technique.) 966 4.5. TCP Access to Ancillary Data 968 The summary in the previous section assumes a UDP socket. Sending 969 and receiving ancillary data is easy with UDP: the application calls 970 sendmsg() and recvmsg() instead of sendto() and recvfrom(). 972 But there might be cases where a TCP application wants to send or 973 receive this optional information. For example, a TCP client might 974 want to specify a source route and this needs to be done before 975 calling connect(). Similarly a TCP server might want to know the 976 received interface after accept() returns along with any Destination 977 options. 979 One new socket option is defined to allow TCP access to these 980 optional fields, although it is valid to use this with UDP or raw 981 sockets as well. Setting the socket option specifies any of the 982 optional output fields: 984 setsockopt(fd, IPPROTO_IPV6, IPV6_PKTOPTIONS, &buf, len); 986 The fourth argument points to a buffer containing one or more 987 ancillary data objects, and the fifth argument is the total length of 988 all these objects. The application fills in this buffer exactly as 989 if the buffer were being passed to sendmsg() as control information. 991 The corresponding receive option 993 getsockopt(fd, IPPROTO_IPV6, IPV6_PKTOPTIONS, &buf, &len); 995 returns a buffer with one or more ancillary data objects for all the 996 optional receive information that the application has previously 997 specified that it wants to receive. The fourth argument points to 998 the buffer that is filled in by the call. The fifth argument is a 999 pointer to a value-result integer: when the function is called the 1000 integer specifies the size of the buffer pointed to by the fourth 1001 argument, and on return this integer contains the actual number of 1002 bytes that were returned. The application processes this buffer 1003 exactly as if the buffer were returned by recvmsg() as control 1004 information. 1006 When using getsockopt() with the IPV6_PKTOPTIONS option, only the 1007 options from the most recently received segment are retained and 1008 returned to the caller. Also, none of the ancillary data that we 1009 describe in this document is ever returned as control information by 1010 recvmsg() on a TCP socket. 1012 The options set by calling setsockopt() for IPV6_PKTOPTIONS are 1013 called "sticky" options because once set they apply to all packets 1014 sent on that socket. They may, however, be overridden with ancillary 1015 data specified in a call to sendmsg(). 1017 But the following three options are considered a set: Hop-by-Hop, 1018 Destination, and Routing header options. If any of these three 1019 options are specified in a call to sendmsg(), then none of these 1020 three from the socket's sticky options are sent for this packet. For 1021 example, if the application calls setsockopt() for IPV6_PKTOPTIONS 1022 and sets sticky values for the Hop-by-Hop and Destination options, 1023 but then calls sendmsg() specifying just a Routing header as an 1024 ancillary data object, then only the Routing header is sent with this 1025 packet. The two sticky options, Hop-by-Hop and Destination, are not 1026 sent for this packet. 1028 5. Packet Information 1030 There are four pieces of information that an application can specify 1031 for an outgoing packet using ancillary data: 1033 1. the source IPv6 address, 1034 2. the outgoing interface index, 1035 3. the outgoing hop limit, and 1036 4. the next hop address. 1038 Three similar pieces of information can be returned for a received 1039 packet as ancillary data: 1041 1. the destination IPv6 address, 1042 2. the arriving interface index, and 1043 3. the arriving hop limit. 1045 The flow label can also be considered as packet information, but its 1046 semantics differ from these three, so we describe it in Section 6. 1048 The first two pieces of information are contained in an in6_pktinfo 1049 structure that is sent as ancillary data with sendmsg() and received 1050 as ancillary data with recvmsg(). This structure is defined as a 1051 result of including the header. 1053 struct in6_pktinfo { 1054 struct in6_addr ipi6_addr; /* src/dst IPv6 address */ 1055 int ipi6_ifindex; /* send/recv interface index */ 1056 }; 1058 In the cmsghdr structure containing this ancillary data, the 1059 cmsg_level member will be IPPROTO_IPV6, the cmsg_type member will be 1060 IPV6_PKTINFO, and the first byte of cmsg_data[] will be the first 1061 byte of the in6_pktinfo structure. 1063 This information is returned as ancillary data by recvmsg() only if 1064 the application has enabled the IPV6_PKTINFO socket option: 1066 int on = 1; 1067 setsockopt(fd, IPPROTO_IPV6, IPV6_PKTINFO, &on, sizeof(on)); 1069 Nothing special need be done to send this information: just specify 1070 the control information as ancillary data for sendmsg(). 1072 (Note: The hop limit is not contained in the in6_pktinfo structure 1073 for the following reason. Some UDP servers want to respond to client 1074 requests by sending their reply out the same interface on which the 1075 request was received and with the source IPv6 address of the reply 1076 equal to the destination IPv6 address of the request. To do this the 1077 application can enable just the IPV6_PKTINFO socket option and then 1078 use the received control information from recvmsg() as the outgoing 1079 control information for sendmsg(). The application need not examine 1080 or modify the in6_pktinfo structure at all. But if the hop limit 1081 were contained in this structure, the application would have to parse 1082 the received control information and change the hop limit member, 1083 since the received hop limit is not the desired value for an outgoing 1084 packet.) 1086 5.1. Specifying/Receiving the Interface 1088 Interfaces on an IPv6 node are identified by a small positive 1089 integer, as described in Section 4 of [2]. That document also 1090 describes a function to map an interface name to its interface index, 1091 a function to map an interface index to its interface name, and a 1092 function to return all the interface names and indexes. Notice from 1093 this document that no interface is ever assigned an index of 0. 1095 When specifying the outgoing interface, if the ipi6_ifindex value is 1096 0, the kernel will choose the outgoing interface. If the application 1097 specifies an outgoing interface for a multicast packet, the interface 1098 specified by the ancillary data overrides any interface specified by 1099 the IPV6_ADD_MEMBERSHIP socket option (described in [2]), for that 1100 call to sendmsg() only. 1102 When the IPV6_PKTINFO socket option is enabled, the received 1103 interface index is always returned as the ipi6_index member of the 1104 in6_pktinfo structure. 1106 5.2. Specifying/Receiving Source/Destination Address 1108 The source IPv6 address can be specified by calling bind() before 1109 each output operation, but supplying the source address together with 1110 the data requires less overhead (i.e., fewer system calls) and 1111 requires less state to be stored and protected in a multithreaded 1112 application. 1114 When specifying the source IPv6 address as ancillary data, if the 1115 ipi6_addr member of the in6_pktinfo structure is the unspecified 1116 address (IN6ADDR_ANY_INIT), then (a) if an address is currently bound 1117 to the socket, it is used as the source address, or (b) if no address 1118 is currently bound to the socket, the kernel will choose the source 1119 address. If the ipi6_addr member is not the unspecified address, but 1120 the socket has already bound a source address, then the ipi6_addr 1121 value overrides the already-bound source address for this output 1122 operation only. 1124 When the in6_pktinfo structure is returned as ancillary data by 1125 recvmsg(), the ipi6_addr member contains the destination IPv6 address 1126 from the received packet. 1128 5.3. Specifying/Receiving the Hop Limit 1130 The outgoing hop limit is normally specified with either the 1131 IPV6_UNICAST_HOPS socket option or the IPV6_MULTICAST_HOPS socket 1132 option, both of which are described in [2]. Specifying the hop limit 1133 as ancillary data lets the application override either the kernel's 1134 default or a previously specified value, for either a unicast 1135 destination or a multicast destination, for a single output 1136 operation. Returning the received hop limit is useful for programs 1137 such as Traceroute and for IPv6 applications that need to verify that 1138 the received hop limit is 255 (e.g., that the packet has not been 1139 forwarded). 1141 The received hop limit is returned as ancillary data by recvmsg() 1142 only if the application has enabled the IPV6_HOPLIMIT socket option: 1144 int on = 1; 1145 setsockopt(fd, IPPROTO_IPV6, IPV6_HOPLIMIT, &on, sizeof(on)); 1147 In the cmsghdr structure containing this ancillary data, the 1148 cmsg_level member will be IPPROTO_IPV6, the cmsg_type member will be 1149 IPV6_HOPLIMIT, and the first byte of cmsg_data[] will be the first 1150 byte of the integer hop limit. 1152 Nothing special need be done to specify the outgoing hop limit: just 1153 specify the control information as ancillary data for sendmsg(). As 1154 specified in [2], the interpretation of the integer hop limit value 1155 is 1157 x < -1: return an error of EINVAL 1158 x == -1: use kernel default 1159 0 <= x <= 255: use x 1160 x >= 256: return an error of EINVAL 1162 5.4. Specifying the Next Hop Address 1164 The IPV6_NEXTHOP ancillary data object specifies the next hop for the 1165 datagram as a socket address structure. In the cmsghdr structure 1166 containing this ancillary data, the cmsg_level member will be 1167 IPPROTO_IPV6, the cmsg_type member will be IPV6_NEXTHOP, and the 1168 first byte of cmsg_data[] will be the first byte of the socket 1169 address structure. 1171 This is a privileged option. 1173 If the socket address structure contains an IPv6 address (e.g., the 1174 sin6_family member is AF_INET6), then the node identified by that 1175 address must be a neighbor of the sending host. If that address 1176 equals the destination IPv6 address of the datagram, then this is 1177 equivalent to the existing SO_DONTROUTE socket option. 1179 5.5. Additional Errors with sendmsg() 1181 With the IPV6_PKTINFO socket option there are no additional errors 1182 possible with the call to recvmsg(). But when specifying the 1183 outgoing interface or the source address, additional errors are 1184 possible from sendmsg(): 1186 ENXIO The interface specified by ipi6_ifindex does not exist. 1188 ENETDOWN The interface specified by ipi6_ifindex is not enabled 1189 for IPv6 use. 1191 EADDRNOTAVAIL ipi6_ifindex specifies an interface but the address 1192 ipi6_addr is not available for use on that interface. 1194 EHOSTUNREACH No route to the destination exists over the interface 1195 specified by ifi6_ifindex. 1197 6. Flow Labels 1199 IPv6 allows packets to be explicitly labeled as belonging to a flow 1200 of related packets (Section 6 of [1]). All packets with a given IPv6 1201 source address that share the same flow label must have the following 1202 fields in common as well: destination address (unicast or multicast), 1203 priority, Hop-by-Hop options header, and if a Routing header is 1204 present, all extension headers up to and including the Routing 1205 header. Flow label values must be uniformly distributed in the range 1206 [1, 2^24-1] so that routers may use any portion of the flow label as 1207 a hash key to access stored state for the flow. 1209 The following points must be considered in designing an API to 1210 specify flow labels. 1212 - Space is already allocated in the sockaddr_in6 structure for the 1213 flow label. This implies that the process specifies the value 1214 (setting it to 0 to indicate no flow), in a call to connect() for 1215 a connected socket, or in a call to sendto() or sendmsg() for an 1216 unconnected socket. (Note: The sin6_flowinfo field performs 1217 double duty, carrying both the outgoing flow and the incoming 1218 flow. UDP applications that read requests using recvfrom() and 1219 then send a reply using sendto() must not use the incoming flow 1220 label for the outgoing reply.) 1222 - Generation of flow labels should be in the kernel, since they must 1223 be unique for a given source address, destination address and 1224 priority. The kernel also must keep track of the assigned flow 1225 labels to prevent them from being reused by a new flow within the 1226 flow-state lifetime (6 seconds default). 1228 - These first two points imply that the kernel assigns the flow 1229 label, but the process needs a way to obtain its value from the 1230 kernel. 1232 - To assign a flow label the process must specify the destination 1233 address and priority. (Note: The use of the priority field in the 1234 IPv6 header is still subject to change. The basic API spec [2] 1235 removed all references to this field for this reason. Therefore 1236 it is unspecified how a process specifies a nonzero priority 1237 field.) 1239 - All packets belonging to the same flow must also have the same 1240 Hop-by-Hop header and, if a Routing header is present, all 1241 extension headers up to and including the Routing header. 1242 Therefore, when a process asks to have a flow label assigned, it 1243 should also specify these extension headers that must remain 1244 constant for the flow. 1246 - For a connected socket (TCP or UDP) the process must be able 1247 specify a flow label either when the connection is established (as 1248 part of the sockaddr_in6 structure that is passed to connect()), 1249 or after the connection is established (the kernel should notice 1250 that the socket is already connected when it is asked to assign 1251 the flow label, and then start using it for that socket). On 1252 these connected sockets the process calls write() or send(), and 1253 does not specify a sockaddr_in6 structure with the flow 1254 label--hence the requirement that the kernel store the value and 1255 automatically use it. 1257 - For an unconnected UDP socket the process must ask the kernel to 1258 assign the flow label, obtain the value, and then use that value 1259 in subsequent calls to sendto() or sendmsg(). 1261 - It should be possible for a UDP application that will communicate 1262 with N peer processes to assign up to N different flow labels to a 1263 given socket. The process obtains the N values from the kernel 1264 and then uses the correct one for each of the N peers. 1266 - getpeername() can return the assigned flow label for a connected 1267 socket, but this function cannot be used to return the flow label 1268 for an unconnected socket. 1270 - Flows are defined between a source and destination. It should be 1271 possible for multiple sockets between a given source and 1272 destination to share the same flow label. This implies that it 1273 must be possible for a flow label assigned to one socket to be 1274 "reused" to another socket. 1276 One way a TCP client could do this, for example, is to obtain a 1277 flow to a given destination and then simply use that flow label in 1278 the socket address structures for multiple connect()s to the same 1279 server (e.g., Web clients). But it should also be possible to use 1280 some already assigned flow on an already connected socket, 1281 implying some way to tell the kernel to use an already assigned 1282 flow on a given socket. 1284 - There is some error checking that the kernel could perform with 1285 regard to flow labels, and the API should not address these, but 1286 leave them up to the implementation. For example, what if the 1287 process asks the kernel to allocate a flow label to DST1 for 1288 SOCKFD1 but then calls connect(SOCKFD1) connecting to DST2 using 1289 the flow label that was assigned to DST1? Or when a UDP 1290 application allocates multiple flow labels, but uses them 1291 incorrectly? Or when a UDP application allocates a flow to a 1292 destination, but then sends datagrams with the flow label set to 1293 0? 1295 - Flow labels are often mentioned along with RSVP, but the 1296 interaction between RSVP reservations and IPv6 flow labels is 1297 unclear (Section 1.2 of [5]). We note that RSVP is receiver- 1298 driven, while IPv6 flows labels must be chosen by the sender. 1300 - Lastly, the use of flow labels is still experimental. All this 1301 API can provide is some way to allocate flow labels within the 1302 rules provided in [1], allowing the kernel to enforce the 1303 requirements on common packet fields and freeing the application 1304 from the burden of selecting unique pseudo-random flow labels. 1306 The interface to the flow label feature is through three 1307 inet6_flow_XXX() functions. The function prototypes for these 1308 functions are all in the header. 1310 6.1. inet6_flow_assign 1312 int inet6_flow_assign(int fd, struct sockaddr_in6 *sin6, 1313 const void *buf, size_t len); 1315 To cause a flow label to be assigned the application must specify the 1316 socket, destination address, priority, and the optional headers that 1317 are not allowed to change for the flow. 1319 The socket address structure pointed to by sin6 specifies the 1320 destination address and priority. The flow label and port number 1321 fields are ignored. 1323 The buffer specified by the buf and len arguments contains the Hop- 1324 by-Hop options, the Destination options that precede the option 1325 Routing header, and the optional Routing header. The format of the 1326 buffer is a sequence of ancillary data objects, as described with the 1327 IPV6_PKTOPTIONS socket option. 1329 The flow label is assigned and returned in the sin6_flowinfo member 1330 of the socket address structure. 1332 This function returns 0 on success, -1 on error. 1334 If an earlier connect() or accept() has already connected the socket 1335 to the destination address supplied in this call, then subsequent 1336 output operations will have the assigned flow label in the IPv6 1337 header. 1339 If the socket is not connected then the application must use the 1340 returned flow label in a subsequent call to connect(), sendto(), or 1341 sendmsg(). 1343 (Note: It makes no sense to assign a flow to a listening TCP socket, 1344 since a destination address is required to assign the flow.) (Note: 1345 Since the socket address structure pointed to by the second argument 1346 is both a value and a result, implementations might consider using 1347 ioctl() for flow label access. Note that if this function were 1348 implemented using setsockopt() followed by getsockopt(), it would not 1349 be thread safe.) 1351 6.2. inet6_flow_free 1353 int inet6_flow_free(int fd, const struct sockaddr_in6 *sin6); 1355 A previously assigned flow label can be explicitly freed. If this 1356 function is not called, the flow label is automatically freed on the 1357 last close of the socket. 1359 The flow label field in the socket address structure specifies the 1360 flow label that is being freed. 1362 This function returns 0 on success, -1 on error. 1364 6.3. inet6_flow_reuse 1366 int inet6_flow_reuse(int currfd, int newfd, 1367 const struct sockaddr_in6 *sin6); 1369 A flow label assigned to one socket can be used on another socket 1370 (subject to the basic limitations of flow labels, of course, such as 1371 packets belonging to the flow from both sockets having the same 1372 destination address, etc.). This function needs to be called only if 1373 the new socket is already connected. If the new socket is not 1374 already connected, the application can just specify the known flow 1375 label in a call to connect(), sendto(), or sendmsg(). 1377 This function specifies that the flow label previously assigned to 1378 the socket currfd is also to be used on the socket newfd. 1380 The caller must fill in the destination address, priority, and flow 1381 label fields of the socket address structure. 1383 If the socket newfd is already connected to the destination address, 1384 subsequent output operations will have the assigned flow label in the 1385 IPv6 header. 1387 This function returns 0 on success, -1 on error. 1389 7. Hop-By-Hop Options 1391 A variable number of Hop-by-Hop options can appear in a single Hop- 1392 by-Hop options header. Each option in the header is TLV-encoded with 1393 a type, length, and value. 1395 Today only three Hop-by-Hop options are defined for IPv6 [1]: Jumbo 1396 Payload, Pad1, and PadN, although a proposal exists for a router- 1397 alert Hop-by-Hop option. The Jumbo Payload option should not be 1398 passed back to an application and an application should receive an 1399 error if it attempts to set it. This option is processed entirely by 1400 the kernel. It is indirectly specified by datagram-based 1401 applications as the size of the datagram to send and indirectly 1402 passed back to these applications as the length of the received 1403 datagram. The two pad options are for alignment purposes and are 1404 automatically inserted by a sending kernel when needed and ignored by 1405 the receiving kernel. This section of the API is therefore defined 1406 for future Hop-by-Hop options that an application may need to specify 1407 and receive. 1409 Individual Hop-by-Hop options (and Destination options, which are 1410 described shortly, and which are similar to the Hop-by-Hop options) 1411 may have specific alignment requirements. For example, the 4-byte 1412 Jumbo Payload length should appear on a 4-byte boundary, and IPv6 1413 addresses are normally aligned on an 8-byte boundary. These 1414 requirements and the terminology used with these options are 1415 discussed in Section 4.2 and Appendix A of [1]. The alignment of 1416 each option is specified by two values, called x and y, written as 1417 "xn + y". This states that the option must appear at an integer 1418 multiple of x bytes from the beginning of the options header (x can 1419 have the values 1, 2, 4, or 8), plus y bytes (y can have a value 1420 between 0 and 7, inclusive). The Pad1 and PadN options are inserted 1421 as needed to maintain the required alignment. Whatever code builds 1422 either a Hop-by-Hop options header or a Destination options header 1423 must know the values of x and y for each option. 1425 Multiple Hop-by-Hop options can be specified by the application. 1426 Normally one ancillary data object describes all the Hop-by-Hop 1427 options (since each option is itself TLV-encoded) but the application 1428 can specify multiple ancillary data objects for the Hop-by-Hop 1429 options, each object specifying one or more options. Care must be 1430 taken designing the API for these options since 1432 1. it may be possible for some future Hop-by-Hop options to be 1433 generated by the application and processed entirely by the 1434 application (e.g., the kernel may not know the alignment 1435 restrictions for the option), 1437 2. it must be possible for the kernel to insert its own Hop-by-Hop 1438 options in an outgoing packet (e.g., the Jumbo Payload option), 1440 3. the application can place one or more Hop-by-Hop options into a 1441 single ancillary data object, 1443 3. if the application specifies multiple ancillary data objects, 1444 each containing one or more Hop-by-Hop options, the kernel must 1445 combine these a single Hop-by-Hop options header, and 1447 4. it must be possible for the kernel to remove some Hop-by-Hop 1448 options from a received packet before returning the remaining 1449 Hop-by-Hop options to the application. (This removal might 1450 consist of the kernel converting the option into a pad option of 1451 the same length.) 1453 Finally, we note that access to some Hop-by-Hop options or to some 1454 Destination options, might require special privilege. That is, 1455 normal applications (without special privilege) might be forbidden 1456 from setting certain options in outgoing packets, and might never see 1457 certain options in received packets. 1459 7.1. Receiving Hop-by-Hop Options 1461 To receive Hop-by-Hop options the application must enable the 1462 IPV6_HOPOPTS socket option: 1464 int on = 1; 1465 setsockopt(fd, IPPROTO_IPV6, IPV6_HOPOPTS, &on, sizeof(on)); 1467 All the Hop-by-Hop options are returned as one ancillary data object 1468 described by a cmsghdr structure. The cmsg_level member will be 1469 IPPROTO_IPV6 and the cmsg_type member will be IPV6_HOPOPTS. These 1470 options are then processed by calling the inet6_option_next() and 1471 inet6_option_find() functions, described shortly. 1473 7.2. Sending Hop-by-Hop Options 1475 To send one or more Hop-by-Hop options, the application just 1476 specifies them as ancillary data in a call to sendmsg(). No socket 1477 option need be set. 1479 Normally all the Hop-by-Hop options are specified by a single 1480 ancillary data object. Multiple ancillary data objects, each 1481 containing one or more Hop-by-Hop options, can also be specified, in 1482 which case the kernel will combine all the Hop-by-Hop options into a 1483 single Hop-by-Hop extension header. But it should be more efficient 1484 to use a single ancillary data object to describe all the Hop-by-Hop 1485 options. The cmsg_level member is set to IPPROTO_IPV6 and the 1486 cmsg_type member is set to IPV6_HOPOPTS. The option is normally 1487 constructed using the inet6_option_init(), inet6_option_append(), and 1488 inet6_option_alloc() functions, described shortly. 1490 Additional errors may be possible from sendmsg() if the specified 1491 option is in error. 1493 7.3. Hop-by-Hop and Destination Options Processing 1495 Building and parsing the Hop-by-Hop and Destination options is 1496 complicated for the reasons given earlier. We therefore define a set 1497 of functions to help the application. The function prototypes for 1498 these functions are all in the header. 1500 7.3.1. inet6_option_space 1502 int inet6_option_space(int nbytes); 1504 This function returns the number of bytes required to hold an option 1505 when it is stored as ancillary data, including the cmsghdr structure 1506 at the beginning, and any padding at the end (to make its size a 1507 multiple of 8 bytes). The argument is the size of the structure 1508 defining the option, which must include any pad bytes at the 1509 beginning (the value y in the alignment term "xn + y"), the type 1510 byte, the length byte, and the option data. 1512 (Note: If multiple options are stored in a single ancillary data 1513 object, which is the recommended technique, this function 1514 overestimates the amount of space required by the size of N-1 cmsghdr 1515 structures, where N is the number of options to be stored in the 1516 object. This is of little consequence, since it is assumed that most 1517 Hop-by-Hop option headers and Destination option headers carry only 1518 one option (p. 33 of [1]).) 1520 7.3.2. inet6_option_init 1522 int inet6_option_init(void *bp, struct cmsghdr **cmsgp, int type); 1524 This function is called once per ancillary data object that will 1525 contain either Hop-by-Hop or Destination options. It returns 0 on 1526 success or -1 on an error. 1528 bp is a pointer to previously allocated space that will contain the 1529 ancillary data object. It must be large enough to contain all the 1530 individual options to be added by later calls to 1531 inet6_option_append() and inet6_option_alloc(). 1533 cmsgp is a pointer to a pointer to a cmsghdr structure. *cmsgp is 1534 initialized by this function to point to the cmsghdr structure 1535 constructed by this function in the buffer pointed to by bp. 1537 type is either IPV6_HOPOPTS or IPV6_DSTOPTS. This type is stored in 1538 the cmsg_type member of the cmsghdr structure pointed to by *cmsgp. 1540 7.3.3. inet6_option_append 1542 int inet6_option_append(struct cmsghdr *cmsg, const u_int8_t *typep, 1543 int multx, int plusy); 1545 This function appends a Hop-by-Hop option or a Destination option 1546 into an ancillary data object that has been initialized by 1547 inet6_option_init(). This function returns 0 if it succeeds or -1 on 1548 an error. 1550 cmsg is a pointer to the cmsghdr structure that must have been 1551 initialized by inet6_option_init(). 1553 typep is a pointer to the 8-bit option type. It is assumed that this 1554 field is immediately followed by the 8-bit option data length field, 1555 which is then followed immediately by the option data. The caller 1556 initializes these three fields (the type-length-value, or TLV) before 1557 calling this function. 1559 The option type must have a value from 2 to 255, inclusive. (0 and 1 1560 are reserved for the Pad1 and PadN options, respectively.) 1562 The option data length must have a value between 0 and 255, 1563 inclusive, and is the length of the option data that follows. 1565 multx is the value x in the alignment term "xn + y" described 1566 earlier. It must have a value of 1, 2, 4, or 8. 1568 plusy is the value y in the alignment term "xn + y" described 1569 earlier. It must have a value between 0 and 7, inclusive. 1571 7.3.4. inet6_option_alloc 1573 u_int8_t *inet6_option_alloc(struct cmsghdr *cmsg, int datalen, 1574 int multx, int plusy); 1576 This function appends a Hop-by-Hop option or a Destination option 1577 into an ancillary data object that has been initialized by 1578 inet6_option_init(). This function returns a pointer to the 8-bit 1579 option type field that starts the option on success, or NULL on an 1580 error. 1582 The difference between this function and inet6_option_append() is 1583 that the latter copies the contents of a previously built option into 1584 the ancillary data object while the current function returns a 1585 pointer to the space in the data object where the option's TLV must 1586 then be built by the caller. 1588 cmsg is a pointer to the cmsghdr structure that must have been 1589 initialized by inet6_option_init(). 1591 datalen is the value of the option data length byte for this option. 1592 This value is required as an argument to allow the function to 1593 determine if padding must be appended at the end of the option. (The 1594 inet6_option_append() function does not need a data length argument 1595 since the option data length must already be stored by the caller.) 1597 multx is the value x in the alignment term "xn + y" described 1598 earlier. It must have a value of 1, 2, 4, or 8. 1600 plusy is the value y in the alignment term "xn + y" described 1601 earlier. It must have a value between 0 and 7, inclusive. 1603 7.3.5. inet6_option_next 1605 int inet6_option_next(const struct cmsghdr *cmsg, u_int8_t **tptrp); 1607 This function processes the next Hop-by-Hop option or Destination 1608 option in an ancillary data object. If another option remains to be 1609 processed, the return value of the function is 0 and *tptrp points to 1610 the 8-bit option type field (which is followed by the 8-bit option 1611 data length, followed by the option data). If no more options remain 1612 to be processed, the return value is -1 and *tptrp is NULL. If an 1613 error occurs, the return value is -1 and *tptrp is not NULL. 1615 cmsg is a pointer to cmsghdr structure of which cmsg_level equals 1616 IPPROTO_IPV6 and cmsg_type equals either IPV6_HOPOPTS or 1617 IPV6_DSTOPTS. 1619 tptrp is a pointer to a pointer to an 8-bit byte and *tptrp is used 1620 by the function to remember its place in the ancillary data object 1621 each time the function is called. The first time this function is 1622 called for a given ancillary data object, *tptrp must be set to NULL. 1623 Each time this function returns success, *tptrp points to the 8-bit 1624 option type field for the next option to be processed. 1626 7.3.6. inet6_option_find 1628 int inet6_option_find(const struct cmsghdr *cmsg, u_int8_t *tptrp, 1629 int type); 1631 This function is similar to the previously described 1632 inet6_option_next() function, except this function lets the caller 1633 specify the option type to be searched for, instead of always 1634 returning the next option in the ancillary data object. 1636 cmsg is a pointer to cmsghdr structure of which cmsg_level equals 1637 IPPROTO_IPV6 and cmsg_type equals either IPV6_HOPOPTS or 1638 IPV6_DSTOPTS. 1640 tptrp is a pointer to a pointer to an 8-bit byte and *tptrp is used 1641 by the function to remember its place in the ancillary data object 1642 each time the function is called. The first time this function is 1643 called for a given ancillary data object, *tptrp must be set to NULL. 1645 This function starts searching for an option of the specified type 1646 beginning after the value of *tptrp. If an option of the specified 1647 type is located, this function returns 0 and *tptrp points to the 1648 8-bit option type field for the option of the specified type. If an 1649 option of the specified type is not located, the return value is -1 1650 and *tptrp is NULL. If an error occurs, the return value is -1 and 1651 *tptrp is not NULL. 1653 7.3.7. Options Examples 1655 We now provide an example that builds two Hop-by-Hop options. First 1656 we define two options, called X and Y, taken from the example in 1657 Appendix A of [1]. We assume that all options will have structure 1658 definitions similar to what is shown below. 1660 /* option X and option Y are defined in [1], pp. 33-34 */ 1661 #define IPV6_OPT_X_TYPE X /* replace X with assigned value */ 1662 #define IPV6_OPT_X_LEN 12 1663 #define IPV6_OPT_X_MULTX 8 /* 8n + 2 alignment */ 1664 #define IPV6_OPT_X_OFFSETY 2 1666 struct ipv6_opt_X { 1667 u_int8_t opt_X_pad[IPV6_OPT_X_OFFSETY]; 1668 u_int8_t opt_X_type; 1669 u_int8_t opt_X_len; 1670 u_int32_t opt_X_val1; 1671 u_int64_t opt_X_val2; 1672 }; 1674 #define IPV6_OPT_Y_TYPE Y /* replace Y with assigned value */ 1675 #define IPV6_OPT_Y_LEN 7 1676 #define IPV6_OPT_Y_MULTX 4 /* 4n + 3 alignment */ 1677 #define IPV6_OPT_Y_OFFSETY 3 1679 struct ipv6_opt_Y { 1680 u_int8_t opt_Y_pad[IPV6_OPT_Y_OFFSETY]; 1681 u_int8_t opt_Y_type; 1682 u_int8_t opt_Y_len; 1683 u_int8_t opt_Y_val1; 1684 u_int16_t opt_Y_val2; 1685 u_int32_t opt_Y_val3; 1686 }; 1688 We now show the code fragment to build one ancillary data object 1689 containing both options. 1691 struct msghdr msg; 1692 struct cmsghdr *cmsgptr; 1693 struct ipv6_opt_X optX; 1694 struct ipv6_opt_Y optY; 1696 msg.msg_control = malloc(sizeof(optX) + sizeof(optY)); 1698 inet6_option_init(msg.msg_control, &cmsgptr, IPV6_HOPOPTS); 1700 optX.opt_X_type = IPV6_OPT_X_TYPE; 1701 optX.opt_X_len = IPV6_OPT_X_LEN; 1702 optX.opt_X_val1 = <32-bit value>; 1703 optX.opt_X_val2 = <64-bit value>; 1704 inet6_option_append(cmsgptr, &optX.opt_X_type, 1705 IPV6_OPT_X_MULTX, IPV6_OPT_X_OFFSETY); 1707 optY.opt_Y_type = IPV6_OPT_Y_TYPE; 1708 optY.opt_Y_len = IPV6_OPT_Y_LEN; 1709 optY.opt_Y_val1 = <8-bit value>; 1710 optY.opt_Y_val2 = <16-bit value>; 1711 optY.opt_Y_val3 = <32-bit value>; 1712 inet6_option_append(cmsgptr, &optY.opt_Y_type, 1713 IPV6_OPT_Y_MULTX, IPV6_OPT_Y_OFFSETY); 1715 msg.msg_controllen = CMSG_SPACE(cmsgptr->cmsg_len); 1717 The call to inet6_option_init() builds the cmsghdr structure in the 1718 control buffer. 1720 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1721 | cmsg_len = CMSG_LENGTH(0) = 12 | 1722 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1723 | cmsg_level = IPPROTO_IPV6 | 1724 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1725 | cmsg_type = IPV6_HOPOPTS | 1726 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1728 Here we assume a 32-bit architecture where sizeof(struct cmsghdr) 1729 equals 12, with a desired alignment of 4-byte boundaries (that is, 1730 the ALIGN() macro shown in the sample implementations of the 1731 CMSG_xxx() functions rounds up to a multiple of 4). 1733 The first call to inet6_option_append() appends the X option. Since 1734 this is the first option in the ancillary data object, 2 bytes are 1735 allocated for the Next Header byte and for the Hdr Ext Len byte. The 1736 former will be set by the kernel, depending on the type of header 1737 that follows this header, and the latter byte is set to 1. These 2 1738 bytes form the 2 bytes of padding (IPV6_OPT_X_OFFSETY) required at 1739 the beginning of this option. 1741 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1742 | cmsg_len = 28 | 1743 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1744 | cmsg_level = IPPROTO_IPV6 | 1745 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1746 | cmsg_type = IPV6_HOPOPTS | 1747 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1748 | Next Header | Hdr Ext Len=1 | Option Type=X |Opt Data Len=12| 1749 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1750 | 4-octet field | 1751 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1752 | | 1753 + 8-octet field + 1754 | | 1755 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1757 The cmsg_len member of the cmsghdr structure is incremented by 16, 1758 the size of the option. 1760 The next call to inet6_option_append() appends the Y option to the 1761 ancillary data object. 1763 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1764 | cmsg_len = 44 | 1765 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1766 | cmsg_level = IPPROTO_IPV6 | 1767 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1768 | cmsg_type = IPV6_HOPOPTS | 1769 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1770 | Next Header | Hdr Ext Len=3 | Option Type=X |Opt Data Len=12| 1771 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1772 | 4-octet field | 1773 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1774 | | 1775 + 8-octet field + 1776 | | 1777 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1778 | PadN Option=1 |Opt Data Len=1 | 0 | Option Type=Y | 1779 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1780 |Opt Data Len=7 | 1-octet field | 2-octet field | 1781 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1782 | 4-octet field | 1783 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1784 | PadN Option=1 |Opt Data Len=2 | 0 | 0 | 1785 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1787 16 bytes are appended by this function, so cmsg_len becomes 44. The 1788 inet6_option_append() function notices that the appended data 1789 requires 4 bytes of padding at the end, to make the size of the 1790 ancillary data object a multiple of 8, and appends the PadN option 1791 before returning. The Hdr Ext Len byte is incremented by 2 to become 1792 3. 1794 Alternately, the application could build two ancillary data objects, 1795 one per option, although this will probably be less efficient than 1796 combining the two options into a single ancillary data object (as 1797 just shown). The kernel must combine these into a single Hop-by-Hop 1798 extension header in the final IPv6 packet. 1800 struct msghdr msg; 1801 struct cmsghdr *cmsgptr; 1802 struct ipv6_opt_X optX; 1803 struct ipv6_opt_Y optY; 1805 msg.msg_control = malloc(sizeof(optX) + sizeof(optY)); 1807 inet6_option_init(msg.msg_control, &cmsgptr, IPPROTO_HOPOPTS); 1809 optX.opt_X_type = IPV6_OPT_X_TYPE; 1810 optX.opt_X_len = IPV6_OPT_X_LEN; 1811 optX.opt_X_val1 = <32-bit value>; 1812 optX.opt_X_val2 = <64-bit value>; 1813 inet6_option_append(cmsgptr, &optX.opt_X_type, 1814 IPV6_OPT_X_MULTX, IPV6_OPT_X_OFFSETY); 1815 msg.msg_controllen = CMSG_SPACE(cmsgptr->cmsg_len); 1817 inet6_option_init((u_char *)msg.msg_control + msg.msg_controllen, 1818 &cmsgptr, IPPROTO_HOPOPTS); 1820 optY.opt_Y_type = IPV6_OPT_Y_TYPE; 1821 optY.opt_Y_len = IPV6_OPT_Y_LEN; 1822 optY.opt_Y_val1 = <8-bit value>; 1823 optY.opt_Y_val2 = <16-bit value>; 1824 optY.opt_Y_val3 = <32-bit value>; 1825 inet6_option_append(cmsgptr, &optY.opt_Y_type, 1826 IPV6_OPT_Y_MULTX, IPV6_OPT_Y_OFFSETY); 1827 msg.msg_controllen += CMSG_SPACE(cmsgptr->cmsg_len); 1829 Each call to inet6_option_init() builds a new cmsghdr structure, and 1830 the final result looks like the following: 1832 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1833 | cmsg_len = 28 | 1834 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1835 | cmsg_level = IPPROTO_IPV6 | 1836 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1837 | cmsg_type = IPV6_HOPOPTS | 1838 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1839 | Next Header | Hdr Ext Len=1 | Option Type=X |Opt Data Len=12| 1840 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1841 | 4-octet field | 1842 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1843 | | 1844 + 8-octet field + 1845 | | 1846 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1847 | cmsg_len = 28 | 1848 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1849 | cmsg_level = IPPROTO_IPV6 | 1850 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1851 | cmsg_type = IPV6_HOPOPTS | 1852 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1853 | Next Header | Hdr Ext Len=1 | Pad1 Option=0 | Option Type=Y | 1854 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1855 |Opt Data Len=7 | 1-octet field | 2-octet field | 1856 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1857 | 4-octet field | 1858 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1859 | PadN Option=1 |Opt Data Len=2 | 0 | 0 | 1860 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1862 When the kernel combines these two options into a single Hop-by-Hop 1863 extension header, the first 3 bytes of the second ancillary data 1864 object (the Next Header byte, the Hdr Ext Len byte, and the Pad1 1865 option) will be combined into a PadN option occupying 3 bytes. 1867 The following code fragment is a redo of the first example shown 1868 (building two options in a single ancillary data object) but this 1869 time we use inet6_option_alloc(). 1871 u_int8_t *typep; 1872 struct msghdr msg; 1873 struct cmsghdr *cmsgptr; 1874 struct ipv6_opt_X *optXp; /* now a pointer, not a struct */ 1875 struct ipv6_opt_Y *optYp; /* now a pointer, not a struct */ 1877 msg.msg_control = malloc(sizeof(*optXp) + sizeof(*optYp)); 1878 inet6_option_init(msg.msg_control, &cmsgptr, IPV6_HOPOPTS); 1880 typep = inet6_option_append(cmsgptr, IPV6_OPT_X_LEN, 1881 IPV6_OPT_X_MULTX, IPV6_OPT_X_OFFSETY); 1882 optXp = (struct ipv6_opt_X *) (typep - IPV6_OPT_X_OFFSETY); 1883 optXp->opt_X_type = IPV6_OPT_X_TYPE; 1884 optXp->opt_X_len = IPV6_OPT_X_LEN; 1885 optXp->opt_X_val1 = <32-bit value>; 1886 optXp->opt_X_val2 = <64-bit value>; 1888 typep = inet6_option_append(cmsgptr, IPV6_OPT_Y_LEN, 1889 IPV6_OPT_Y_MULTX, IPV6_OPT_Y_OFFSETY); 1890 optYp = (struct ipv6_opt_Y *) (typep - IPV6_OPT_Y_OFFSETY); 1891 optYp->opt_Y_type = IPV6_OPT_Y_TYPE; 1892 optYp->opt_Y_len = IPV6_OPT_Y_LEN; 1893 optYp->opt_Y_val1 = <8-bit value>; 1894 optYp->opt_Y_val2 = <16-bit value>; 1895 optYp->opt_Y_val3 = <32-bit value>; 1897 msg.msg_controllen = CMSG_SPACE(cmsgptr->cmsg_len); 1899 Notice that inet6_option_alloc() returns a pointer to the 8-bit 1900 option type field. If the program wants a pointer to an option 1901 structure that includes the padding at the front (as shown in our 1902 definitions of the ipv6_opt_X and ipv6_opt_Y structures), the y- 1903 offset at the beginning of the structure must be subtracted from the 1904 returned pointer. 1906 The following code fragment shows the processing of Hop-by-Hop 1907 options using the inet6_option_next() function. 1909 struct msghdr msg; 1910 struct cmsghdr *cmsgptr; 1912 /* fill in msg */ 1914 /* call recvmsg() */ 1916 for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL; 1917 cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) { 1918 if (cmsgptr->cmsg_level == IPPROTO_IPV6 && 1919 cmsgptr->cmsg_type == IPV6_HOPOPTS) { 1921 u_int8_t *tptr = NULL; 1923 while (inet6_option_next(cmsgptr, &tptr) == 0) { 1924 if (*tptr == IPV6_OPT_X_TYPE) { 1925 struct ipv6_opt_X *optXp; 1926 optXp = (struct ipv6_opt_X *) (tptr - IPV6_OPT_X_OFFSETY); 1927 optXp->opt_X_val1; 1928 optXp->opt_X_val2; 1930 } else if (*tptr == IPV6_OPT_Y_TYPE) { 1931 struct ipv6_opt_Y *optYp; 1933 optYp = (struct ipv6_opt_Y *) (tptr - IPV6_OPT_Y_OFFSETY); 1934 optYp->opt_Y_val1; 1935 optYp->opt_Y_val2; 1936 optYp->opt_Y_val3; 1937 } 1938 } 1939 if (tptr != NULL) 1940 ; 1941 } 1942 } 1944 8. Destination Options 1946 A variable number of Destination options can appear in one or more 1947 Destination option headers. As defined in [1], a Destination options 1948 header appearing before a Routing header is processed by the first 1949 destination plus any subsequent destinations specified in the Routing 1950 header, while a Destination options header appearing after a Routing 1951 header is processed only by the final destination. As with the Hop- 1952 by-Hop options, each option in a Destination options header is TLV- 1953 encoded with a type, length, and value. 1955 Today no Destination options are defined for IPv6 [1], although 1956 proposals exist to use Destination options with mobility and 1957 anycasting. 1959 8.1. Receiving Destination Options 1961 To receive Destination options the application must enable the 1962 IPV6_DSTOPTS socket option: 1964 int on = 1; 1965 setsockopt(fd, IPPROTO_IPV6, IPV6_DSTOPTS, &on, sizeof(on)); 1967 All the Destination options appearing before a Routing header are 1968 returned as one ancillary data object described by a cmsghdr 1969 structure and all the Destination options appearing after a Routing 1970 header are returned as another ancillary data object described by a 1971 cmsghdr structure. For these ancillary data objects, the cmsg_level 1972 member will be IPPROTO_IPV6 and the cmsg_type member will be 1973 IPV6_HOPOPTS. These options are then processed by calling the 1974 inet6_option_next() and inet6_option_find() functions. 1976 8.2. Sending Destination Options 1978 To send one or more Destination options, the application just 1979 specifies them as ancillary data in a call to sendmsg(). No socket 1980 option need be set. 1982 As described earlier, one set of Destination options can appear 1983 before a Routing header, and one set can appear after a Routing 1984 header. Each set can consist of one or more options. 1986 Normally all the Destination options in a set are specified by a 1987 single ancillary data object, since each option is itself TLV- 1988 encoded. Multiple ancillary data objects, each containing one or 1989 more Destination options, can also be specified, in which case the 1990 kernel will combine all the Destination options in the set into a 1991 single Destination extension header. But it should be more efficient 1992 to use a single ancillary data object to describe all the Destination 1993 options in a set. The cmsg_level member is set to IPPROTO_IPV6 and 1994 the cmsg_type member is set to IPV6_DSTOPTS. The option is normally 1995 constructed using the inet6_option_init(), inet6_option_append(), and 1996 inet6_option_alloc() functions. 1998 Additional errors may be possible from sendmsg() if the specified 1999 option is in error. 2001 9. Source Route Option 2003 Source routing in IPv6 is accomplished by specifying a Routing header 2004 as an extension header. There can be different types of Routing 2005 headers, but IPv6 currently defines only the Type 0 Routing header 2006 [1]. This type supports up to 23 intermediate nodes. With this 2007 maximum number of intermediate nodes, a source, and a destination, 2008 there are 24 hops, each of which is defined as a strict or loose hop. 2010 Source routing with IPv4 sockets API (the IP_OPTIONS socket option) 2011 requires the application to build the source route in the format that 2012 appears as the IPv4 header option, requiring intimate knowledge of 2013 the IPv4 options format. This IPv6 API, however, defines eight 2014 functions that the application calls to build and examine a Routing 2015 header. Four functions build a Routing header: 2017 inet6_srcrt_space() - return #bytes required for ancillary data 2018 inet6_srcrt_init() - initialize ancillary data for Routing header 2019 inet6_srcrt_add() - add IPv6 address & flags to Routing header 2020 inet6_srcrt_lasthop() - specify the flags for the final hop 2022 Four functions deal with a returned Routing header: 2024 inet6_srcrt_reverse() - reverse a Routing header 2025 inet6_srcrt_segments() - return #segments in a Routing header 2026 inet6_srcrt_getaddr() - fetch one address from a Routing header 2027 inet6_srcrt_getflags() - fetch one flag from a Routing header 2029 The function prototypes for these functions are all in the 2030 header. 2032 A Routing header is passed between the application and the kernel as 2033 an ancillary data object. The cmsg_level member has a value of 2034 IPPROTO_IPV6 and the cmsg_type member has a value of IPV6_SRCRT. The 2035 contents of the cmsg_data[] member is implementation dependent and 2036 should not be accessed directly by the application, but should be 2037 accessed using the eight functions that we are about to describe. 2039 The following constants are defined in the header: 2041 #define IPV6_SRCRT_LOOSE 0 /* this hop need not be a neighbor */ 2042 #define IPV6_SRCRT_STRICT 1 /* this hop must be a neighbor */ 2044 #define IPV6_SRCRT_TYPE_0 0 /* IPv6 Routing header type 0 */ 2046 When a Routing header is specified, the destination address specified 2047 for connect(), sendto(), or sendmsg() is the final destination 2048 address of the datagram. The Routing header then contains the 2049 addresses of all the intermediate nodes. 2051 9.1. inet6_srcrt_space 2053 size_t inet6_srcrt_space(int type, int segments); 2055 This function returns the number of bytes required to hold a Routing 2056 header of the specified type containing the specified number of 2057 segments (addresses). The number of segments must be between 1 and 2058 23, inclusive. The return value includes the size of the cmsghdr 2059 structure that precedes the Routing header, and any required padding. 2061 If the return value is 0, then either the type of the Routing header 2062 is not supported by this implementation or the number of segments is 2063 invalid for this type of Routing header. 2065 (Note: This function returns the size but does not allocate the space 2066 required for the ancillary data. This allows an application to 2067 allocate a larger buffer, if other ancillary data objects are 2068 desired, since all the ancillary data objects must be specified to 2069 sendmsg() as a single msg_control buffer.) 2071 9.2. inet6_srcrt_init 2073 struct cmsghdr *inet6_srcrt_init(void *bp, int type); 2075 This function initializes the buffer pointed to by bp to contain a 2076 cmsghdr structure followed by a Routing header of the specified type. 2077 The cmsg_len member of the cmsghdr structure is initialized to the 2078 size of the structure plus the amount of space required by the 2079 Routing header. The cmsg_level and cmsg_type members are also 2080 initialized as required. 2082 The caller must allocate the buffer and its size can be determined by 2083 calling inet6_srcrt_space(). 2085 The return value is the pointer to the cmsghdr structure, and this is 2086 then used as the first argument to the next two functions. If the 2087 type of Routing header is not supported by the implementation, the 2088 return value is NULL. 2090 9.3. inet6_srcrt_add 2092 int inet6_srcrt_add(struct cmsghdr *cmsg, 2093 const struct in6_addr *addr, unsigned int flags); 2095 This function adds the address pointed to by addr to the end of the 2096 Routing header being constructed and sets the type of this hop to the 2097 value of flags. For an IPv6 Type 0 Routing header, flags must be 2098 either IPV6_SRCRT_LOOSE or IPV6_SRCRT_STRICT. 2100 If successful, the cmsg_len member of the cmsghdr structure is 2101 updated to account for the new address in the Routing header and the 2102 return value of the function is 0. 2104 If the address would exceed the limits of the Routing header, the 2105 return value of the function is ENOSPC. If flags specifies an 2106 invalid value for the Routing header, the return value of the 2107 function is EINVAL. 2109 9.4. inet6_srcrt_lasthop 2111 int inet6_srcrt_lasthop(struct cmsghdr *cmsg, 2112 unsigned int flags); 2114 This function specifies the Strict/Loose flag for the final hop of a 2115 source route. For an IPv6 Type 0 Routing header, flags must be 2116 either IPV6_SRCRT_LOOSE or IPV6_SRCRT_STRICT. 2118 Notice that a source route that specifies N intermediate nodes 2119 requires N+1 Strict/Loose flags. This requires N calls to 2120 inet6_srcrt_add() followed by one call to inet6_srcrt_lasthop(). 2122 9.5. inet6_srcrt_reverse 2124 int inet6_srcrt_reverse(const struct cmsghdr *in, struct cmsghdr *out); 2126 This function takes a Routing header that was received as ancillary 2127 data (pointed to by the first argument) and writes a new Routing 2128 header that sends datagrams along the reverse of that route. Both 2129 arguments are allowed to point to the same buffer (that is, the 2130 reversal can occur in place). The return value of the function is 0 2131 on success. 2133 If the type of Routing header in not supported by the implementation, 2134 the return value of the function is EOPNOTSUPP. If the Routing 2135 header information is invalid, the return value of the function is 2136 EINVAL. 2138 9.6. inet6_srcrt_segments 2140 int inet6_srcrt_segments(const struct cmsghdr *cmsg) 2142 This function returns the number of segments (addresses) contained in 2143 the Routing header described by cmsg. On success the return value is 2144 between 1 and 23, inclusive. The return value is -1 if the cmsghdr 2145 structure does not describe a valid Routing header or is a Routing 2146 header of an unsupported type. 2148 9.7. inet6_srcrt_getaddr 2150 struct in6_addr *inet6_srcrt_getaddr(struct cmsghdr *cmsg, int index); 2152 This function returns a pointer to the IPv6 address specified by 2153 index (which must have a value between 1 and the value returned by 2154 inet6_srcrt_segments()) in the Routing header described by cmsg. An 2155 application should first call inet6_srcrt_segments() to obtain the 2156 number of segments in the Routing header. 2158 If offset refers to an address beyond the end of the Routing header, 2159 the return value is NULL. 2161 9.8. inet6_srcrt_getflags 2163 int inet6_srcrt_getflags(const struct cmsghdr *cmsg, int offset); 2165 This function returns the flags value indexed by offset (which must 2166 have a value between 0 and the value returned by 2167 inet6_srcrt_segments()) in the Routing header described by cmsg. For 2168 an IPv6 Type 0 Routing header the return value will be either 2169 IPV6_SRCRT_LOOSE or IPV6_SRCRT_STRICT. 2171 If offset refers to a segment beyond the end of the Routing header, 2172 the return value is -1. 2174 (Note: Addresses are indexed starting at 1, and flags starting at 0, 2175 to maintain consistency with the terminology and figures in [1].) 2177 9.9. Source Route Example 2179 As an example of these source routing functions, we go through the 2180 function calls for the example on p. 18 of [1]. The source is S, the 2181 destination is D, and the three intermediate nodes are I1, I2, and 2182 I3. f0, f1, f2, and f3 are the Strict/Loose flags for each hop. 2184 f0 f1 f2 f3 2185 S -----> I1 -----> I2 -----> I3 -----> D 2187 src: * S S S S S 2188 dst: D I1 I2 I3 D D 2189 A[1]: I1 I2 I1 I1 I1 I1 2190 A[2]: I2 I3 I3 I2 I2 I2 2191 A[3]: I3 D D D I3 I3 2192 #seg: 3 3 2 1 0 3 2194 check: f0 f1 f2 f3 2196 src and dst are the source and destination IPv6 addresses in the IPv6 2197 header. A[1], A[2], and A[3] are the three addresses in the Routing 2198 header. #seg is the Segments Left field in the Routing header. 2199 check indicates which bit of the Strict/Loose Bit Map (0 through 3, 2200 specified as f0 through f3) that node checks. 2202 The six values in the column beneath node S are the values in the 2203 Routing header specified by the application using sendmsg(). The 2204 function calls by the sender would look like: 2206 void *ptr; 2207 struct msghdr msg; 2208 struct cmsghdr *cmsgptr; 2209 struct sockaddr_in6 I1, I2, I3, D; 2210 unsigned int f0, f1, f2, f3; 2212 ptr = malloc(inet6_srcrt_space(IPV6_SRCRT_TYPE_0, 3)); 2213 cmsgptr = inet6_srcrt_init(ptr, IPV6_SRCRT_TYPE_0); 2215 inet6_srcrt_add(cmsgptr, &I1.sin6_addr, f0); 2216 inet6_srcrt_add(cmsgptr, &I2.sin6_addr, f1); 2217 inet6_srcrt_add(cmsgptr, &I3.sin6_addr, f2); 2218 inet6_srcrt_lasthop(cmsgptr, f3); 2220 msg.msg_control = ptr; 2221 msg.msg_controllen = CMSG_LENGTH(cmsgptr->cmsg_len); 2223 /* finish filling in msg{}, msg_name = D */ 2224 /* call sendmsg() */ 2226 We also assume that the source address for the socket is not 2227 specified (i.e., the asterisk in the figure). 2229 The four columns of six values that are then shown between the five 2230 nodes are the values of the fields in the packet while the packet is 2231 in transit between the two nodes. Notice that before the packet is 2232 sent by the source node S, the source address is chosen (replacing 2233 the asterisk), I1 becomes the destination address of the datagram, 2234 the two addresses A[2] and A[3] are "shifted up", and D is moved to 2235 A[3]. If f0 is IPV6_SRCRT_STRICT, then I1 must be a neighbor of S. 2237 The columns of values that are shown beneath the destination node are 2238 the values returned by recvmsg(), assuming the application has 2239 enabled both the IPV6_PKTINFO and IPV6_SRCRT socket options. The 2240 source address is S (contained in the sockaddr_in6 structure pointed 2241 to by the msg_name member), the destination address is D (returned as 2242 an ancillary data object in an in6_pktinfo structure), and the 2243 ancillary data object specifying the source route will contain three 2244 addresses (I1, I2, and I3) and four flags (f0, f1, f2, and f3). The 2245 number of segments in the Routing header is known from the Hdr Ext 2246 Len field in the Routing header (a value of 6, indicating 3 2247 addresses). 2249 The return value from inet6_srcrt_segments() will be 3 and 2250 inet6_srcrt_getaddr(1) will return I1, inet6_srcrt_getaddr(2) will 2251 return I2, and inet6_srcrt_getaddr(3) will return I3, The return 2252 value from inet6_srcrt_flags(0) will be f0, inet6_srcrt_flags(1) will 2253 return f1, inet6_srcrt_flags(2) will return f2, and 2254 inet6_srcrt_flags(3) will return f3. 2256 If the receiving application then calls inet6_srcrt_reverse(), the 2257 order of the three addresses will become I3, I2, and I1, and the 2258 order of the four Strict/Loose flags will become f3, f2, f1, and f0. 2260 We can also show what an implementation might store in the ancillary 2261 data object as the Routing header is being built by the sending 2262 process. If we assume a 32-bit architecture where sizeof(struct 2263 cmsghdr) equals 12, with a desired alignment of 4-byte boundaries, 2264 then the call to inet6_srcrt_space(3) returns 68: 12 bytes for the 2265 cmsghdr structure and 56 bytes for the Routing header (8 + 3*16). 2267 The call to inet6_srcrt_init() initializes the ancillary data object 2268 to contain a Type 0 Routing header: 2270 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2271 | cmsg_len = 20 | 2272 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2273 | cmsg_level = IPPROTO_IPV6 | 2274 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2275 | cmsg_type = IPV6_SRCRT | 2276 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2277 | Next Header | Hdr Ext Len=0 | Routing Type=0| Seg Left=0 | 2278 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2279 | Reserved | Strict/Loose Bit Map | 2280 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2282 The first call to inet6_srcrt_add() adds I1 to the list. 2284 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2285 | cmsg_len = 36 | 2286 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2287 | cmsg_level = IPPROTO_IPV6 | 2288 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2289 | cmsg_type = IPV6_SRCRT | 2290 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2291 | Next Header | Hdr Ext Len=2 | Routing Type=0| Seg Left=1 | 2292 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2293 | Reserved |X| Strict/Loose Bit Map | 2294 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2295 | | 2296 + + 2297 | | 2298 + Address[1] = I1 + 2299 | | 2300 + + 2301 | | 2302 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2304 Bit 0 of the Strict/Loose Bit Map contains the value f0, which we 2305 just mark as X. cmsg_len is incremented by 16, the Hdr Ext Len field 2306 is incremented by 2, and the Segments Left field is incremented by 1. 2308 The next call to inet6_srcrt_add() adds I2 to the list. 2310 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2311 | cmsg_len = 52 | 2312 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2313 | cmsg_level = IPPROTO_IPV6 | 2314 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2315 | cmsg_type = IPV6_SRCRT | 2316 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2317 | Next Header | Hdr Ext Len=4 | Routing Type=0| Seg Left=2 | 2318 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2319 | Reserved |X|X| Strict/Loose Bit Map | 2320 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2321 | | 2322 + + 2323 | | 2324 + Address[1] = I1 + 2325 | | 2326 + + 2327 | | 2328 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2329 | | 2330 + + 2331 | | 2332 + Address[2] = I2 + 2333 | | 2334 + + 2335 | | 2336 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2338 The next bit of the Strict/Loose Bit Map contains the value f1. 2339 cmsg_len is incremented by 16, the Hdr Ext Len field is incremented 2340 by 2, and the Segments Left field is incremented by 1. 2342 The last call to inet6_srcrt_add() adds I3 to the list. 2344 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2345 | cmsg_len = 68 | 2346 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2347 | cmsg_level = IPPROTO_IPV6 | 2348 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2349 | cmsg_type = IPV6_SRCRT | 2350 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2351 | Next Header | Hdr Ext Len=6 | Routing Type=0| Seg Left=3 | 2352 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2353 | Reserved |X|X|X| Strict/Loose Bit Map | 2354 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2355 | | 2356 + + 2357 | | 2358 + Address[1] = I1 + 2359 | | 2360 + + 2361 | | 2362 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2363 | | 2364 + + 2365 | | 2366 + Address[2] = I2 + 2367 | | 2368 + + 2369 | | 2370 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2371 | | 2372 + + 2373 | | 2374 + Address[3] = I3 + 2375 | | 2376 + + 2377 | | 2378 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2380 The next bit of the Strict/Loose Bit Map contains the value f2. 2381 cmsg_len is incremented by 16, the Hdr Ext Len field is incremented 2382 by 2, and the Segments Left field is incremented by 1. 2384 Finally, the call to inet6_srcrt_lasthop() sets the next bit of the 2385 Strict/Loose Bit Map to the value specified by f3. All the lengths 2386 remain unchanged. 2388 10. Ordering of Ancillary Data and IPv6 Extension Headers 2389 Three IPv6 extension headers can be specified by the application and 2390 returned to the application using ancillary data with sendmsg() and 2391 recvmsg(): Hop-by-Hop options, Destination options, and the Routing 2392 header. When multiple ancillary data objects are transferred via 2393 sendmsg() or recvmsg() and these objects represent any of these three 2394 extension headers, their placement in the control buffer is directly 2395 tied to their location in the corresponding IPv6 datagram. This API 2396 imposes some ordering constraints when using multiple ancillary data 2397 objects with sendmsg(). 2399 When multiple IPv6 Hop-by-Hop options having the same option type are 2400 specified, these options will be inserted into the Hop-by-Hop options 2401 header in the same order as they appear in the control buffer. But 2402 when multiple Hop-by-Hop options having different option types are 2403 specified, these options may be reordered by the kernel to reduce 2404 padding in the Hop-by-Hop options header. Hop-by-hop options may 2405 appear anywhere in the control buffer and will always be collected by 2406 the kernel and placed into a single Hop-by-Hop options header that 2407 immediately follows the IPv6 header. 2409 Similar rules apply to the Destination options: (1) those of the same 2410 type will appear in the same order as they are specified, and (2) 2411 those of differing types may be reordered. But the kernel will build 2412 up to two Destination options headers: one to precede the Routing 2413 header and one to follow the Routing header. If the application 2414 specifies a Routing header then all Destination options that appear 2415 in the control buffer before the Routing header will appear in a 2416 Destination options header before the Routing header and these 2417 options might be reordered, subject to the two rules that we just 2418 stated. Similarly all Destination options that appear in the control 2419 buffer after the Routing header will appear in a Destination options 2420 header after the Routing header, and these options might be 2421 reordered, subject to the two rules that we just stated. 2423 As an example, assume that an application specifies control 2424 information to sendmsg() containing six ancillary data objects: the 2425 first containing two Hop-by-Hop options, the second containing one 2426 Destination option, the third containing two Destination options, the 2427 fourth containing a source route, the fifth containing a Hop-by-Hop 2428 option, and the sixth containing two Destination options. We also 2429 assume that all the Hop-by-Hop options are of different types, as are 2430 all the Destination options. We number these options 1-9, 2431 corresponding to their order in the control buffer, and show them on 2432 the left below. 2434 In the middle we show the final arrangement of the options in the 2435 extension headers built by the kernel. On the right we show the four 2436 ancillary data objects returned to the receiving application. 2438 Sender's Receiver's 2439 Ancillary Data --> IPv6 Extension --> Ancillary Data 2440 Objects Headers Objects 2441 ------------------ --------------- -------------- 2442 HOPOPT-1,2 (first) HOPHDR(J,7,1,2) HOPOPT-7,1,2 2443 DSTOPT-3 DSTHDR(4,5,3) DSTOPT-4,5,3 2444 DSTOPT-4,5 RTGHDR(6) SRCRT-6 2445 SRCRT-6 DSTHDR(8,9) DSTOPT-8,9 2446 HOPOPT-7 2447 DSTOPT-8,9 (last) 2449 The sender's two Hop-by-Hop ancillary data objects are reordered, as 2450 are the first two Destination ancillary data objects. We also show a 2451 Jumbo Payload option (denoted as J) inserted by the kernel before the 2452 sender's three Hop-by-Hop options. The first three Destination 2453 options must appear in a Destination header before the Routing 2454 header, and the final two Destination options must appear in a 2455 Destination header after the Routing header. 2457 If Destination options are specified in the control buffer after a 2458 Routing header, or if Destination options are specified without a 2459 Routing header, the kernel will place those Destination options after 2460 an authentication header and/or an encapsulating security payload 2461 header, if present. 2463 11. IPv6-Specific Options with IPv4-Mapped IPv6 Addresses 2465 The various socket options and ancillary data specifications defined 2466 in this document apply only to true IPv6 sockets. It is possible to 2467 create an IPv6 socket that actually sends and receives IPv4 packets, 2468 using IPv4-mapped IPv6 addresses, but the mapping of the options 2469 defined in this document to an IPv4 datagram is beyond the scope of 2470 this document. 2472 In general, attempting to specify an IPv6-only option, such as the 2473 Hop-by-Hop options, Destination options, or Routing header on an IPv6 2474 socket that is using IPv4-mapped IPv6 addresses, will probably result 2475 in an error. Some implementations, however, may provide access to 2476 the packet information (source/destination address, send/receive 2477 interface, and hop limit) on an IPv6 socket that is using IPv4-mapped 2478 IPv6 addresses. 2480 12. rresvport_af 2482 The rresvport() function is used by the rcmd() function, and this 2483 function is in turn called by many of the "r" commands such as 2484 rlogin. While new applications are not being written to use the 2485 rcmd() function, legacy applications such as rlogin will continue to 2486 use it and these will be ported to IPv6. 2488 rresvport() creates an IPv4/TCP socket and binds a "reserved port" to 2489 the socket. Instead of defining an IPv6 version of this function we 2490 define a new function that takes an address family as its argument. 2492 #include 2494 int rresvport_af(int *port, int family); 2496 This function behaves the same as the existing rresvport() function, 2497 but instead of creating an IPv4/TCP socket, it can also create an 2498 IPv6/TCP socket. The family argument is either AF_INET or AF_INET6, 2499 and a new error return is EAFNOSUPPORT if the address family is not 2500 supported. 2502 (Note: There is little consensus on which header defines the 2503 rresvport() and rcmd() function prototypes. 4.4BSD defines it in 2504 , others in , and others don't define the function 2505 prototypes at all.) 2507 (Note: We define this function only, and do not define something like 2508 rcmd_af() or rcmd6(). The reason is that rcmd() calls 2509 gethostbyname(), which returns the type of address: AF_INET or 2510 AF_INET6. It should therefore be possible to modify rcmd() to 2511 support either IPv4 or IPv6, based on the address family returned by 2512 gethostbyname().) 2514 13. Future Items 2516 Some additional items may require standardization, but no concrete 2517 proposals have been made for the API to perform these tasks. These 2518 may be addressed in a later document. 2520 13.1. Path MTU Discovery and UDP 2522 A standard method may be desirable for a UDP application to determine 2523 the "maximum send transport-message size" (Section 5.1 of [3]) to a 2524 given destination. This would let the UDP application send smaller 2525 datagrams to the destination, avoiding fragmentation. 2527 13.2. Neighbor Reachability and UDP 2528 A standard method may be desirable for a UDP application to tell the 2529 kernel that it is making forward progress with a given peer (Section 2530 7.3.1 of [4]). This could save unneeded neighbor solicitations and 2531 neighbor advertisements. 2533 14. Security Considerations 2535 Allowing an application to pick flow labels at will could permit 2536 interference with the routing of packets sent by another application 2537 from the same host, or theft of a bandwidth reservation or other 2538 network state created on behalf of another user. 2540 The setting of certain Hop-by-Hop options and Destination options may 2541 be restricted to privileged processes. Similarly some Hop-by-Hop 2542 options and Destination options may not be returned to nonprivileged 2543 applications. 2545 15. Change History 2547 Changes from the October 1996 Edition (-00 draft) 2549 - Numerous rationale added using the format (Note: ...). 2551 - Added note that not all errors may be defined. 2553 - Added note about ICMPv4, IGMPv4, and ARPv4 terminology. 2555 - Changed the name of to . 2557 - Change some names in Section 2.2.1: ICMPV6_PKT_TOOBIG to 2558 ICMPV6_PACKET_TOOBIG, ICMPV6_TIME_EXCEED to ICMPV6_TIME_EXCEEDED, 2559 ICMPV6_ECHORQST to ICMPV6_ECHOREQUEST, ICMPV6_ECHORPLY to 2560 ICMPV6_ECHOREPLY, ICMPV6_PARAMPROB_HDR to 2561 ICMPV6_PARAMPROB_HEADER, ICMPV6_PARAMPROB_NXT_HDR to 2562 ICMPV6_PARAMPROB_NEXTHEADER, and ICMPV6_PARAMPROB_OPTS to 2563 ICMPV6_PARAMPROB_OPTION. 2565 - Prepend the prefix "icmp6_" to the three members of the 2566 icmp6_dataun union of the icmp6hdr structure (Section 2.2). 2568 - Moved the neighbor discovery definitions into the 2569 header, instead of being in their own header 2570 (Section 2.2.1). 2572 - Changed Section 2.3 ("Address Testing"). The basic macros are 2573 now in the basic API. 2575 - Added the new Section 2.4 on "Protocols File". 2577 - Added note to raw sockets description that something like BPF or 2578 DLPI must be used to read or write entire IPv6 packets. 2580 - Corrected example of IPV6_CHECKSUM socket option (Section 3.1). 2581 Also defined value of -1 to disable. 2583 - Noted that defines all the ICMPv6 filtering 2584 constants, macros, and structures (Section 3.2). 2586 - Added note on magic number 10240 for amount of ancillary data 2587 (Section 4.1). 2589 - Added possible padding to picture of ancillary data (Section 2590 4.2). 2592 - Defined header for CMSG_xxx() functions (Section 2593 4.2). 2595 - Note that the data returned by getsockopt(IPV6_PKTOPTIONS) for a 2596 TCP socket is just from the optional headers, if present, of the 2597 most recently received segment. Also note that control 2598 information is never returned by recvmsg() for a TCP socket. 2600 - Changed header for struct in6_pktinfo from to 2601 (Section 5). 2603 - Removed the old Sections 5.1 and 5.2, because the interface 2604 identification functions went into the basic API. 2606 - Redid Section 5 to support the hop limit field. 2608 - New Section 5.4 ("Next Hop Address"). 2610 - New Section 6 ("Flow Labels"). 2612 - Changed all of Sections 7 and 8 dealing with Hop-by-Hop and 2613 Destination options. We now define a set of inet6_option_XXX() 2614 functions. 2616 - Changed header for IPV6_SRCRT_xxx constants from 2617 to (Section 9). 2619 - Add inet6_srcrt_lasthop() function, and fix errors in description 2620 of source routing (Section 9). 2622 - Reworded some of the source routing descriptions to conform to 2623 the terminology in [1]. 2625 - Added the example from [1] for the Routing header (Section 9.9). 2626 IP " -" 4n Expanded the example in Section 10 to show multiple 2627 options per ancillary data object, and to show the receiver's 2628 ancillary data objects. 2630 - New Section 11 ("IPv6-Specific Options with IPv4-Mapped IPv6 2631 Addresses"). 2633 - New Section 12 ("rresvport_af"). 2635 - Redid old Section 10 ("Additional Items") into new Section 13 2636 ("Future Items"). 2638 16. References 2640 [1] Deering, S., Hinden, R., "Internet Protocol, Version 6 (IPv6), 2641 Specification", RFC 1883, Dec. 1995. 2643 [2] Gilligan, R. E., Thomson, S., Bound, J., Stevens, W., "Basic 2644 Socket Interface Extensions for IPv6", Internet-Draft, draft- 2645 ietf-ipngwg-bsd-api-07.txt, January 1997. 2647 [3] McCann, J., Deering, S., Mogul, J, "Path MTU Discovery for IP 2648 version 6", RFC 1981, Aug. 1996. 2650 [4] Narten, T., Nordmark, E., Simpson, W., "Neighbor Discovery for 2651 IP Version 6 (IPv6)", RFC 1970, Aug. 1996. 2653 [5] Braden, R., Zhang, L., Berson, S., Herzog, S., Jamin, S., 2654 "Resource ReSerVation Protocol (RSVP) -- Version 1 Functional 2655 Specification", Internet-Draft, draft-ietf-rsvp-spec-14.txt, 2656 November 1996. 2658 17. Acknowledgments 2660 Matt Thomas and Jim Bound have been working on the technical details 2661 in this draft for over a year. Keith Sklower is the original 2662 implementor of ancillary data in the BSD networking code. Craig Metz 2663 provided lots of feedback, suggestions, and comments based on his 2664 implementing many of these features as the document was being 2665 written. 2667 Matt Crawford designed the flow label interface. 2669 The following provided comments on earlier drafts: Hamid Asayesh, Ran 2670 Atkinson, Karl Auerbach, Matt Crawford, Sam T. Denton, Richard 2671 Draves, Bob Gilligan, Tim Hartrick, Masaki Hirabaru, Yoshinobu Inoue, 2672 Mukesh Kacker, A. N. Kuznetsov, John Moy, Thomas Narten, Erik 2673 Nordmark, Tom Pusateri, Pedro Roque, Peter Sjodin, Stephen P. 2674 Spackman, Quaizar Vohra, Carl Williams, Steve Wise, and Kazu 2675 Yamamoto. 2677 18. Authors' Addresses 2679 W. Richard Stevens 2680 1202 E. Paseo del Zorro 2681 Tucson, AZ 85718 2682 Email: rstevens@kohala.com 2684 Matt Thomas 2685 Digital Equipment Corporation 2686 550 King St, LKG2-2/Q5 2687 Littleton, MA 01460 2688 Email: thomas@lkg.dec.com