1 /*
2  *	Types and definitions for AF_INET6
3  *	Linux INET6 implementation
4  *
5  *	Authors:
6  *	Pedro Roque		<roque@di.fc.ul.pt>
7  *
8  *	Sources:
9  *	IPv6 Program Interfaces for BSD Systems
10  *      <draft-ietf-ipngwg-bsd-api-05.txt>
11  *
12  *	Advanced Sockets API for IPv6
13  *	<draft-stevens-advanced-api-00.txt>
14  *
15  *	This program is free software; you can redistribute it and/or
16  *      modify it under the terms of the GNU General Public License
17  *      as published by the Free Software Foundation; either version
18  *      2 of the License, or (at your option) any later version.
19  */
20 
21 #ifndef _LINUX_IN6_H
22 #define _LINUX_IN6_H
23 
24 #include <linux/types.h>
25 
26 /*
27  *	IPv6 address structure
28  */
29 
30 struct in6_addr {
31 	union {
32 		__u8		u6_addr8[16];
33 		__be16		u6_addr16[8];
34 		__be32		u6_addr32[4];
35 	} in6_u;
36 #define s6_addr			in6_u.u6_addr8
37 #define s6_addr16		in6_u.u6_addr16
38 #define s6_addr32		in6_u.u6_addr32
39 };
40 
41 /* IPv6 Wildcard Address (::) and Loopback Address (::1) defined in RFC2553
42  * NOTE: Be aware the IN6ADDR_* constants and in6addr_* externals are defined
43  * in network byte order, not in host byte order as are the IPv4 equivalents
44  */
45 #ifdef __KERNEL__
46 extern const struct in6_addr in6addr_any;
47 #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
48 extern const struct in6_addr in6addr_loopback;
49 #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
50 extern const struct in6_addr in6addr_linklocal_allnodes;
51 #define IN6ADDR_LINKLOCAL_ALLNODES_INIT	\
52 		{ { { 0xff,2,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
53 extern const struct in6_addr in6addr_linklocal_allrouters;
54 #define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
55 		{ { { 0xff,2,0,0,0,0,0,0,0,0,0,0,0,0,0,2 } } }
56 #endif
57 
58 struct sockaddr_in6 {
59 	unsigned short int	sin6_family;    /* AF_INET6 */
60 	__be16			sin6_port;      /* Transport layer port # */
61 	__be32			sin6_flowinfo;  /* IPv6 flow information */
62 	struct in6_addr		sin6_addr;      /* IPv6 address */
63 	__u32			sin6_scope_id;  /* scope id (new in RFC2553) */
64 };
65 
66 struct ipv6_mreq {
67 	/* IPv6 multicast address of group */
68 	struct in6_addr ipv6mr_multiaddr;
69 
70 	/* local IPv6 address of interface */
71 	int		ipv6mr_ifindex;
72 };
73 
74 #define ipv6mr_acaddr	ipv6mr_multiaddr
75 
76 struct in6_flowlabel_req {
77 	struct in6_addr	flr_dst;
78 	__be32	flr_label;
79 	__u8	flr_action;
80 	__u8	flr_share;
81 	__u16	flr_flags;
82 	__u16 	flr_expires;
83 	__u16	flr_linger;
84 	__u32	__flr_pad;
85 	/* Options in format of IPV6_PKTOPTIONS */
86 };
87 
88 #define IPV6_FL_A_GET	0
89 #define IPV6_FL_A_PUT	1
90 #define IPV6_FL_A_RENEW	2
91 
92 #define IPV6_FL_F_CREATE	1
93 #define IPV6_FL_F_EXCL		2
94 
95 #define IPV6_FL_S_NONE		0
96 #define IPV6_FL_S_EXCL		1
97 #define IPV6_FL_S_PROCESS	2
98 #define IPV6_FL_S_USER		3
99 #define IPV6_FL_S_ANY		255
100 
101 
102 /*
103  *	Bitmask constant declarations to help applications select out the
104  *	flow label and priority fields.
105  *
106  *	Note that this are in host byte order while the flowinfo field of
107  *	sockaddr_in6 is in network byte order.
108  */
109 
110 #define IPV6_FLOWINFO_FLOWLABEL		0x000fffff
111 #define IPV6_FLOWINFO_PRIORITY		0x0ff00000
112 
113 /* These definitions are obsolete */
114 #define IPV6_PRIORITY_UNCHARACTERIZED	0x0000
115 #define IPV6_PRIORITY_FILLER		0x0100
116 #define IPV6_PRIORITY_UNATTENDED	0x0200
117 #define IPV6_PRIORITY_RESERVED1		0x0300
118 #define IPV6_PRIORITY_BULK		0x0400
119 #define IPV6_PRIORITY_RESERVED2		0x0500
120 #define IPV6_PRIORITY_INTERACTIVE	0x0600
121 #define IPV6_PRIORITY_CONTROL		0x0700
122 #define IPV6_PRIORITY_8			0x0800
123 #define IPV6_PRIORITY_9			0x0900
124 #define IPV6_PRIORITY_10		0x0a00
125 #define IPV6_PRIORITY_11		0x0b00
126 #define IPV6_PRIORITY_12		0x0c00
127 #define IPV6_PRIORITY_13		0x0d00
128 #define IPV6_PRIORITY_14		0x0e00
129 #define IPV6_PRIORITY_15		0x0f00
130 
131 /*
132  *	IPV6 extension headers
133  */
134 #define IPPROTO_HOPOPTS		0	/* IPv6 hop-by-hop options	*/
135 #define IPPROTO_ROUTING		43	/* IPv6 routing header		*/
136 #define IPPROTO_FRAGMENT	44	/* IPv6 fragmentation header	*/
137 #define IPPROTO_ICMPV6		58	/* ICMPv6			*/
138 #define IPPROTO_NONE		59	/* IPv6 no next header		*/
139 #define IPPROTO_DSTOPTS		60	/* IPv6 destination options	*/
140 #define IPPROTO_MH		135	/* IPv6 mobility header		*/
141 
142 /*
143  *	IPv6 TLV options.
144  */
145 #define IPV6_TLV_PAD0		0
146 #define IPV6_TLV_PADN		1
147 #define IPV6_TLV_ROUTERALERT	5
148 #define IPV6_TLV_JUMBO		194
149 #define IPV6_TLV_HAO		201	/* home address option */
150 
151 /*
152  *	IPV6 socket options
153  */
154 
155 #define IPV6_ADDRFORM		1
156 #define IPV6_2292PKTINFO	2
157 #define IPV6_2292HOPOPTS	3
158 #define IPV6_2292DSTOPTS	4
159 #define IPV6_2292RTHDR		5
160 #define IPV6_2292PKTOPTIONS	6
161 #define IPV6_CHECKSUM		7
162 #define IPV6_2292HOPLIMIT	8
163 #define IPV6_NEXTHOP		9
164 #define IPV6_AUTHHDR		10	/* obsolete */
165 #define IPV6_FLOWINFO		11
166 
167 #define IPV6_UNICAST_HOPS	16
168 #define IPV6_MULTICAST_IF	17
169 #define IPV6_MULTICAST_HOPS	18
170 #define IPV6_MULTICAST_LOOP	19
171 #define IPV6_ADD_MEMBERSHIP	20
172 #define IPV6_DROP_MEMBERSHIP	21
173 #define IPV6_ROUTER_ALERT	22
174 #define IPV6_MTU_DISCOVER	23
175 #define IPV6_MTU		24
176 #define IPV6_RECVERR		25
177 #define IPV6_V6ONLY		26
178 #define IPV6_JOIN_ANYCAST	27
179 #define IPV6_LEAVE_ANYCAST	28
180 
181 /* IPV6_MTU_DISCOVER values */
182 #define IPV6_PMTUDISC_DONT		0
183 #define IPV6_PMTUDISC_WANT		1
184 #define IPV6_PMTUDISC_DO		2
185 #define IPV6_PMTUDISC_PROBE		3
186 
187 /* Flowlabel */
188 #define IPV6_FLOWLABEL_MGR	32
189 #define IPV6_FLOWINFO_SEND	33
190 
191 #define IPV6_IPSEC_POLICY	34
192 #define IPV6_XFRM_POLICY	35
193 
194 /*
195  * Multicast:
196  * Following socket options are shared between IPv4 and IPv6.
197  *
198  * MCAST_JOIN_GROUP		42
199  * MCAST_BLOCK_SOURCE		43
200  * MCAST_UNBLOCK_SOURCE		44
201  * MCAST_LEAVE_GROUP		45
202  * MCAST_JOIN_SOURCE_GROUP	46
203  * MCAST_LEAVE_SOURCE_GROUP	47
204  * MCAST_MSFILTER		48
205  */
206 
207 /*
208  * Advanced API (RFC3542) (1)
209  *
210  * Note: IPV6_RECVRTHDRDSTOPTS does not exist. see net/ipv6/datagram.c.
211  */
212 
213 #define IPV6_RECVPKTINFO	49
214 #define IPV6_PKTINFO		50
215 #define IPV6_RECVHOPLIMIT	51
216 #define IPV6_HOPLIMIT		52
217 #define IPV6_RECVHOPOPTS	53
218 #define IPV6_HOPOPTS		54
219 #define IPV6_RTHDRDSTOPTS	55
220 #define IPV6_RECVRTHDR		56
221 #define IPV6_RTHDR		57
222 #define IPV6_RECVDSTOPTS	58
223 #define IPV6_DSTOPTS		59
224 #define IPV6_RECVPATHMTU	60
225 #define IPV6_PATHMTU		61
226 #define IPV6_DONTFRAG		62
227 #if 0	/* not yet */
228 #define IPV6_USE_MIN_MTU	63
229 #endif
230 
231 /*
232  * Netfilter (1)
233  *
234  * Following socket options are used in ip6_tables;
235  * see include/linux/netfilter_ipv6/ip6_tables.h.
236  *
237  * IP6T_SO_SET_REPLACE / IP6T_SO_GET_INFO		64
238  * IP6T_SO_SET_ADD_COUNTERS / IP6T_SO_GET_ENTRIES	65
239  */
240 
241 /*
242  * Advanced API (RFC3542) (2)
243  */
244 #define IPV6_RECVTCLASS		66
245 #define IPV6_TCLASS		67
246 
247 /*
248  * Netfilter (2)
249  *
250  * Following socket options are used in ip6_tables;
251  * see include/linux/netfilter_ipv6/ip6_tables.h.
252  *
253  * IP6T_SO_GET_REVISION_MATCH	68
254  * IP6T_SO_GET_REVISION_TARGET	69
255  */
256 
257 /* RFC5014: Source address selection */
258 #define IPV6_ADDR_PREFERENCES	72
259 
260 #define IPV6_PREFER_SRC_TMP		0x0001
261 #define IPV6_PREFER_SRC_PUBLIC		0x0002
262 #define IPV6_PREFER_SRC_PUBTMP_DEFAULT	0x0100
263 #define IPV6_PREFER_SRC_COA		0x0004
264 #define IPV6_PREFER_SRC_HOME		0x0400
265 #define IPV6_PREFER_SRC_CGA		0x0008
266 #define IPV6_PREFER_SRC_NONCGA		0x0800
267 
268 /* RFC5082: Generalized Ttl Security Mechanism */
269 #define IPV6_MINHOPCOUNT		73
270 
271 #define IPV6_ORIGDSTADDR        74
272 #define IPV6_RECVORIGDSTADDR    IPV6_ORIGDSTADDR
273 #define IPV6_TRANSPARENT        75
274 
275 /*
276  * Multicast Routing:
277  * see include/linux/mroute6.h.
278  *
279  * MRT6_INIT			200
280  * MRT6_DONE			201
281  * MRT6_ADD_MIF			202
282  * MRT6_DEL_MIF			203
283  * MRT6_ADD_MFC			204
284  * MRT6_DEL_MFC			205
285  * MRT6_VERSION			206
286  * MRT6_ASSERT			207
287  * MRT6_PIM			208
288  * (reserved)			209
289  */
290 #endif
291