1*0a6a1f1dSLionel Sambuc.\" $NetBSD: inet6_opt_init.3,v 1.2 2014/01/04 15:37:26 wiz Exp $ 22fe8fb19SBen Gras.\" $KAME: inet6_opt_init.3,v 1.7 2004/12/27 05:08:23 itojun Exp $ 32fe8fb19SBen Gras.\" 42fe8fb19SBen Gras.\" Copyright (C) 2004 WIDE Project. 52fe8fb19SBen Gras.\" All rights reserved. 62fe8fb19SBen Gras.\" 72fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without 82fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions 92fe8fb19SBen Gras.\" are met: 102fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright 112fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer. 122fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright 132fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer in the 142fe8fb19SBen Gras.\" documentation and/or other materials provided with the distribution. 152fe8fb19SBen Gras.\" 3. Neither the name of the project nor the names of its contributors 162fe8fb19SBen Gras.\" may be used to endorse or promote products derived from this software 172fe8fb19SBen Gras.\" without specific prior written permission. 182fe8fb19SBen Gras.\" 192fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 202fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 212fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 222fe8fb19SBen Gras.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 232fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 242fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 252fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 262fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 272fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 282fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 292fe8fb19SBen Gras.\" SUCH DAMAGE. 302fe8fb19SBen Gras.\" 312fe8fb19SBen Gras.Dd December 23, 2004 322fe8fb19SBen Gras.Dt INET6_OPT_INIT 3 332fe8fb19SBen Gras.Os 342fe8fb19SBen Gras.\" 352fe8fb19SBen Gras.Sh NAME 362fe8fb19SBen Gras.Nm inet6_opt_init , 372fe8fb19SBen Gras.Nm inet6_opt_append , 382fe8fb19SBen Gras.Nm inet6_opt_finish , 392fe8fb19SBen Gras.Nm inet6_opt_set_val , 402fe8fb19SBen Gras.Nm inet6_opt_next , 412fe8fb19SBen Gras.Nm inet6_opt_find , 422fe8fb19SBen Gras.Nm inet6_opt_get_val 432fe8fb19SBen Gras.Nd IPv6 Hop-by-Hop and Destination Options manipulation 442fe8fb19SBen Gras.\" 452fe8fb19SBen Gras.Sh SYNOPSIS 462fe8fb19SBen Gras.In netinet/in.h 472fe8fb19SBen Gras.Ft "int" 482fe8fb19SBen Gras.Fn inet6_opt_init "void *extbuf" "socklen_t extlen" 492fe8fb19SBen Gras.Ft "int" 502fe8fb19SBen Gras.Fn inet6_opt_append "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t type" "socklen_t len" "u_int8_t align" "void **databufp" 512fe8fb19SBen Gras.Ft "int" 522fe8fb19SBen Gras.Fn inet6_opt_finish "void *extbuf" "socklen_t extlen" "int offset" 532fe8fb19SBen Gras.Ft "int" 542fe8fb19SBen Gras.Fn inet6_opt_set_val "void *databuf" "int offset" "void *val" "socklen_t vallen" 552fe8fb19SBen Gras.Ft "int" 562fe8fb19SBen Gras.Fn inet6_opt_next "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t *typep" "socklen_t *lenp" "void **databufp" 572fe8fb19SBen Gras.Ft "int" 582fe8fb19SBen Gras.Fn inet6_opt_find "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t type" "socklen_t *lenp" "void **databufp" 592fe8fb19SBen Gras.Ft "int" 602fe8fb19SBen Gras.Fn inet6_opt_get_val "void *databuf" "socklen_t offset" "void *val" "socklen_t vallen" 612fe8fb19SBen Gras.\" 622fe8fb19SBen Gras.Sh DESCRIPTION 632fe8fb19SBen GrasBuilding and parsing the Hop-by-Hop and Destination options is 642fe8fb19SBen Grascomplicated. 652fe8fb19SBen GrasThe advanced sockets API defines a set of functions to 662fe8fb19SBen Grashelp applications create and manipulate Hop-by-Hope and Destination 672fe8fb19SBen Grasoptions. 682fe8fb19SBen Gras.\"This man page describes the functions specified in 692fe8fb19SBen Gras.\"IETF Draft RFC3542 while the 702fe8fb19SBen Gras.\".Xr inet6_options_space 3 712fe8fb19SBen Gras.\"man page documents the functions defined in RFC 2292. 722fe8fb19SBen Gras.\"It is expected 732fe8fb19SBen Gras.\"that this set of functions will supersede those in RFC 2292 but for 742fe8fb19SBen Gras.\"the time being both APIs are retained. 752fe8fb19SBen GrasThese functions use the 762fe8fb19SBen Grasformatting rules specified in Appendix B in RFC2460, i.e., that the 772fe8fb19SBen Graslargest field is placed last in the option. 782fe8fb19SBen GrasThe function prototypes 792fe8fb19SBen Grasfor these functions are all contained in the 802fe8fb19SBen Gras.In netinet/in.h 812fe8fb19SBen Grasheader file. 822fe8fb19SBen Gras.\" 832fe8fb19SBen Gras.Ss inet6_opt_init 842fe8fb19SBen GrasThe 852fe8fb19SBen Gras.Fn inet6_opt_init 862fe8fb19SBen Grasfunction 872fe8fb19SBen Grasreturns the number of bytes needed for an empty 882fe8fb19SBen Grasextension header, one without any options. 892fe8fb19SBen GrasIf the 902fe8fb19SBen Gras.Va extbuf 912fe8fb19SBen Grasargument points to a valid section of memory 922fe8fb19SBen Grasthen the 932fe8fb19SBen Gras.Fn inet6_opt_init 942fe8fb19SBen Grasfunction also initializes the extension header's length field. 952fe8fb19SBen GrasWhen attempting to initialize an extension buffer passed in the 962fe8fb19SBen Gras.Va extbuf argument 972fe8fb19SBen Gras.Fa extlen 982fe8fb19SBen Grasmust be a positive multiple of 8 or else the function fails and 992fe8fb19SBen Grasreturns \-1 to the caller. 1002fe8fb19SBen Gras.\" 1012fe8fb19SBen Gras.Ss inet6_opt_append 1022fe8fb19SBen GrasThe 1032fe8fb19SBen Gras.Fn inet6_opt_append 1042fe8fb19SBen Grasfunction can perform to different jobs. 1052fe8fb19SBen GrasWhen a valid 1062fe8fb19SBen Gras.Fa extbuf 1072fe8fb19SBen Grasargument is supplied it appends an option to the extension buffer and 1082fe8fb19SBen Grasreturns the updated total length as well as a pointer to the newly 1092fe8fb19SBen Grascreated option in 1102fe8fb19SBen Gras.Fa databufp . 1112fe8fb19SBen GrasIf the value 1122fe8fb19SBen Grasof 1132fe8fb19SBen Gras.Fa extbuf 1142fe8fb19SBen Grasis 1152fe8fb19SBen Gras.Dv NULL 1162fe8fb19SBen Grasthen the 1172fe8fb19SBen Gras.Fn inet6_opt_append function only reports what the total length would 1182fe8fb19SBen Grasbe if the option were actually appended. 1192fe8fb19SBen GrasThe 1202fe8fb19SBen Gras.Fa len 1212fe8fb19SBen Grasand 1222fe8fb19SBen Gras.Fa align 1232fe8fb19SBen Grasarguments specify the length of the option and the required data 1242fe8fb19SBen Grasalignment which must be used when appending the option. 1252fe8fb19SBen GrasThe 1262fe8fb19SBen Gras.Fa offset 1272fe8fb19SBen Grasargument should be the length returned by the 1282fe8fb19SBen Gras.Fn inet6_opt_init 1292fe8fb19SBen Grasfunction or a previous call to 1302fe8fb19SBen Gras.Fn inet6_opt_append . 1312fe8fb19SBen Gras.Pp 1322fe8fb19SBen GrasThe 1332fe8fb19SBen Gras.Fa type 1342fe8fb19SBen Grasargument is the 8-bit option type. 1352fe8fb19SBen Gras.Pp 1362fe8fb19SBen GrasAfter 1372fe8fb19SBen Gras.Fn inet6_opt_append 1382fe8fb19SBen Grashas been called, the application can use the buffer pointed to by 1392fe8fb19SBen Gras.Fa databufp 1402fe8fb19SBen Grasdirectly, or use 1412fe8fb19SBen Gras.Fn inet6_opt_set_val 1422fe8fb19SBen Grasto specify the data to be contained in the option. 1432fe8fb19SBen Gras.Pp 1442fe8fb19SBen GrasOption types of 1452fe8fb19SBen Gras.Li 0 1462fe8fb19SBen Grasand 1472fe8fb19SBen Gras.Li 1 1482fe8fb19SBen Grasare reserved for the 1492fe8fb19SBen Gras.Li Pad1 1502fe8fb19SBen Grasand 1512fe8fb19SBen Gras.Li PadN 1522fe8fb19SBen Grasoptions. 1532fe8fb19SBen GrasAll other values from 2 through 255 may be used by applications. 1542fe8fb19SBen Gras.Pp 1552fe8fb19SBen GrasThe length of the option data is contained in an 8-bit value and so 1562fe8fb19SBen Grasmay contain any value from 0 through 255. 1572fe8fb19SBen Gras.Pp 1582fe8fb19SBen GrasThe 1592fe8fb19SBen Gras.Fa align 1602fe8fb19SBen Grasparameter must have a value of 1, 2, 4, or 8 and cannot exceed the 1612fe8fb19SBen Grasvalue of 1622fe8fb19SBen Gras.Fa len . 1632fe8fb19SBen GrasThe alignment values represent no alignment, 16 bit, 32 bit and 64 bit 1642fe8fb19SBen Grasalignments respectively. 1652fe8fb19SBen Gras.\" 1662fe8fb19SBen Gras.Ss inet6_opt_finish 1672fe8fb19SBen GrasThe 1682fe8fb19SBen Gras.Fn inet6_opt_finish 1692fe8fb19SBen Grascalculates the final padding necessary to make the extension header a 1702fe8fb19SBen Grasmultiple of 8 bytes, as required by the IPv6 extension header 1712fe8fb19SBen Grasspecification, and returns the extension header's updated total 1722fe8fb19SBen Graslength. 1732fe8fb19SBen GrasThe 1742fe8fb19SBen Gras.Fa offset 1752fe8fb19SBen Grasargument should be the length returned by 1762fe8fb19SBen Gras.Fn inet6_opt_init 1772fe8fb19SBen Grasor 1782fe8fb19SBen Gras.Fn inet6_opt_append . 1792fe8fb19SBen GrasWhen 1802fe8fb19SBen Gras.Fa extbuf 1812fe8fb19SBen Grasis not 1822fe8fb19SBen Gras.Dv NULL 1832fe8fb19SBen Grasthe function also sets up the appropriate padding bytes by inserting a 1842fe8fb19SBen GrasPad1 or PadN option of the proper length. 1852fe8fb19SBen Gras.Pp 1862fe8fb19SBen GrasIf the extension header is too small to contain the proper padding 1872fe8fb19SBen Grasthen an error of \-1 is returned to the caller. 1882fe8fb19SBen Gras.\" 1892fe8fb19SBen Gras.Ss inet6_opt_set_val 1902fe8fb19SBen GrasThe 1912fe8fb19SBen Gras.Fn inet6_opt_set_val 1922fe8fb19SBen Grasfunction inserts data items of various sizes into the data portion of 1932fe8fb19SBen Grasthe option. 1942fe8fb19SBen GrasThe 1952fe8fb19SBen Gras.Fa databuf 1962fe8fb19SBen Grasargument is a pointer to memory that was returned by the 1972fe8fb19SBen Gras.Fn inet6_opt_append 1982fe8fb19SBen Grascall and the 1992fe8fb19SBen Gras.Fa offset argument specifies where the option should be placed in the 2002fe8fb19SBen Grasdata buffer. 2012fe8fb19SBen GrasThe 2022fe8fb19SBen Gras.Fa val 2032fe8fb19SBen Grasargument points to an area of memory containing the data to be 2042fe8fb19SBen Grasinserted into the extension header, and the 2052fe8fb19SBen Gras.Fa vallen 2062fe8fb19SBen Grasargument indicates how much data to copy. 2072fe8fb19SBen Gras.Pp 2082fe8fb19SBen GrasThe caller should ensure that each field is aligned on its natural 2092fe8fb19SBen Grasboundaries as described in Appendix B of RFC2460. 2102fe8fb19SBen Gras.Pp 2112fe8fb19SBen GrasThe function returns the offset for the next field which is calculated as 2122fe8fb19SBen Gras.Fa offset 2132fe8fb19SBen Gras+ 2142fe8fb19SBen Gras.Fa vallen 2152fe8fb19SBen Grasand is used when composing options with multiple fields. 2162fe8fb19SBen Gras.\" 2172fe8fb19SBen Gras.Ss inet6_opt_next 2182fe8fb19SBen GrasThe 2192fe8fb19SBen Gras.Fn inet6_opt_next 2202fe8fb19SBen Grasfunction parses received extension headers. 2212fe8fb19SBen GrasThe 2222fe8fb19SBen Gras.Fa extbuf 2232fe8fb19SBen Grasand 2242fe8fb19SBen Gras.Fa extlen 2252fe8fb19SBen Grasarguments specify the location and length of the extension header 2262fe8fb19SBen Grasbeing parsed. 2272fe8fb19SBen GrasThe 2282fe8fb19SBen Gras.Fa offset 2292fe8fb19SBen Grasargument should either be zero, for the first option, or the length value 2302fe8fb19SBen Grasreturned by a previous call to 2312fe8fb19SBen Gras.Fn inet6_opt_next 2322fe8fb19SBen Grasor 2332fe8fb19SBen Gras.Fn inet6_opt_find . 2342fe8fb19SBen GrasThe return value specifies the position where to continue scanning the 2352fe8fb19SBen Grasextension buffer. 2362fe8fb19SBen GrasThe option is returned in the arguments 2372fe8fb19SBen Gras.Fa typep , lenp , 2382fe8fb19SBen Grasand 2392fe8fb19SBen Gras.Fa databufp . 2402fe8fb19SBen Gras.Fa typep , lenp , 2412fe8fb19SBen Grasand 2422fe8fb19SBen Gras.Fa databufp 2432fe8fb19SBen Graspoint to the 8-bit option type, the 8-bit option length and the option 2442fe8fb19SBen Grasdata respectively. 2452fe8fb19SBen GrasThis function does not return any PAD1 or PADN options. 2462fe8fb19SBen GrasWhen an error occurs or there are no more options the return 2472fe8fb19SBen Grasvalue is \-1. 2482fe8fb19SBen Gras.\" 2492fe8fb19SBen Gras.Ss inet6_opt_find 2502fe8fb19SBen GrasThe 2512fe8fb19SBen Gras.Fn inet6_opt_find 2522fe8fb19SBen Grasfunction searches the extension buffer for a particular option type, 2532fe8fb19SBen Graspassed in through the 2542fe8fb19SBen Gras.Fa type 2552fe8fb19SBen Grasargument. 2562fe8fb19SBen GrasIf the option is found then the 2572fe8fb19SBen Gras.Fa lenp 2582fe8fb19SBen Grasand 2592fe8fb19SBen Gras.Fa databufp 2602fe8fb19SBen Grasarguments are updated to point to the option's length and data 2612fe8fb19SBen Grasrespectively. 2622fe8fb19SBen Gras.Fa extbuf 2632fe8fb19SBen Grasand 2642fe8fb19SBen Gras.Fa extlen 2652fe8fb19SBen Grasmust point to a valid extension buffer and give its length. 2662fe8fb19SBen GrasThe 2672fe8fb19SBen Gras.Fa offset 2682fe8fb19SBen Grasargument can be used to search from a location anywhere in the 2692fe8fb19SBen Grasextension header. 2702fe8fb19SBen Gras.Ss inet6_opt_get_val 2712fe8fb19SBen GrasThe 2722fe8fb19SBen Gras.Fn inet6_opt_get_val 2732fe8fb19SBen Grasfunction extracts data items of various sizes in the data portion of 2742fe8fb19SBen Grasthe option. 2752fe8fb19SBen GrasThe 2762fe8fb19SBen Gras.Fa databuf 2772fe8fb19SBen Grasis a pointer returned by the 2782fe8fb19SBen Gras.Fn inet6_opt_next 2792fe8fb19SBen Grasor 2802fe8fb19SBen Gras.Fn inet6_opt_find 2812fe8fb19SBen Grasfunctions. 2822fe8fb19SBen GrasThe 2832fe8fb19SBen Gras.Fa val 2842fe8fb19SBen Grasargument points where the data will be extracted. 2852fe8fb19SBen GrasThe 2862fe8fb19SBen Gras.Fa offset 2872fe8fb19SBen Grasargument specifies from where in the data portion of the option the 2882fe8fb19SBen Grasvalue should be extracted; the first byte of option data is specified 2892fe8fb19SBen Grasby an offset of zero. 2902fe8fb19SBen Gras.Pp 2912fe8fb19SBen GrasIt is expected that each field is aligned on its natural boundaries as 2922fe8fb19SBen Grasdescribed in Appendix B of RFC2460. 2932fe8fb19SBen Gras.Pp 2942fe8fb19SBen GrasThe function returns the offset for the next field 2952fe8fb19SBen Grasby calculating 2962fe8fb19SBen Gras.Fa offset 2972fe8fb19SBen Gras+ 2982fe8fb19SBen Gras.Fa vallen 2992fe8fb19SBen Graswhich can be used when extracting option content with multiple fields. 3002fe8fb19SBen GrasRobust receivers must verify alignment before calling this function. 3012fe8fb19SBen Gras.\" 3022fe8fb19SBen Gras.Sh EXAMPLES 3032fe8fb19SBen GrasRFC3542 gives comprehensive examples in Section 23. 3042fe8fb19SBen Gras.Pp 3052fe8fb19SBen GrasKAME also provides examples in the 3062fe8fb19SBen Gras.Pa advapitest 3072fe8fb19SBen Grasdirectory of its kit. 3082fe8fb19SBen Gras.\" 309*0a6a1f1dSLionel Sambuc.Sh DIAGNOSTICS 310*0a6a1f1dSLionel SambucAll the functions return 311*0a6a1f1dSLionel Sambuc\-1 312*0a6a1f1dSLionel Sambucon an error. 313*0a6a1f1dSLionel Sambuc.\" 3142fe8fb19SBen Gras.Sh SEE ALSO 3152fe8fb19SBen Gras.Rs 3162fe8fb19SBen Gras.%A W. Stevens 3172fe8fb19SBen Gras.%A M. Thomas 3182fe8fb19SBen Gras.%A E. Nordmark 3192fe8fb19SBen Gras.%A T. Jinmei 3202fe8fb19SBen Gras.%T "Advanced Sockets API for IPv6" 3212fe8fb19SBen Gras.%N RFC3542 3222fe8fb19SBen Gras.%D October 2002 3232fe8fb19SBen Gras.Re 3242fe8fb19SBen Gras.Rs 3252fe8fb19SBen Gras.%A S. Deering 3262fe8fb19SBen Gras.%A R. Hinden 3272fe8fb19SBen Gras.%T "Internet Protocol, Version 6 (IPv6) Specification" 3282fe8fb19SBen Gras.%N RFC2460 3292fe8fb19SBen Gras.%D December 1998 3302fe8fb19SBen Gras.Re 3312fe8fb19SBen Gras.Sh STANDARDS 3322fe8fb19SBen GrasThe functions are documented in 3332fe8fb19SBen Gras.Dq Advanced Sockets API for IPv6 3342fe8fb19SBen Gras.Pq RFC3542 . 3352fe8fb19SBen Gras.\" 336*0a6a1f1dSLionel Sambuc.Sh HISTORY 337*0a6a1f1dSLionel SambucThe implementation first appeared in KAME advanced networking kit. 338