]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/ipv6.h
net: track link status of ipv6 nexthops
[mirror_ubuntu-bionic-kernel.git] / include / linux / ipv6.h
CommitLineData
1da177e4
LT
1#ifndef _IPV6_H
2#define _IPV6_H
3
607ca46e 4#include <uapi/linux/ipv6.h>
1da177e4 5
1da177e4 6#define ipv6_optlen(p) (((p)->hdrlen+1) << 3)
1431fb31 7#define ipv6_authlen(p) (((p)->hdrlen+2) << 2)
1da177e4
LT
8/*
9 * This structure contains configuration options per IPv6 link.
10 */
11struct ipv6_devconf {
12 __s32 forwarding;
13 __s32 hop_limit;
14 __s32 mtu6;
15 __s32 accept_ra;
16 __s32 accept_redirects;
17 __s32 autoconf;
18 __s32 dad_transmits;
19 __s32 rtr_solicits;
20 __s32 rtr_solicit_interval;
21 __s32 rtr_solicit_delay;
22 __s32 force_mld_version;
fc4eba58
HFS
23 __s32 mldv1_unsolicited_report_interval;
24 __s32 mldv2_unsolicited_report_interval;
1da177e4
LT
25 __s32 use_tempaddr;
26 __s32 temp_valid_lft;
27 __s32 temp_prefered_lft;
28 __s32 regen_max_retry;
29 __s32 max_desync_factor;
1da177e4 30 __s32 max_addresses;
65f5c7c1 31 __s32 accept_ra_defrtr;
8013d1d7 32 __s32 accept_ra_min_hop_limit;
c4fd30eb 33 __s32 accept_ra_pinfo;
930d6ff2
YH
34#ifdef CONFIG_IPV6_ROUTER_PREF
35 __s32 accept_ra_rtr_pref;
52e16356 36 __s32 rtr_probe_interval;
09c884d4
YH
37#ifdef CONFIG_IPV6_ROUTE_INFO
38 __s32 accept_ra_rt_info_max_plen;
39#endif
930d6ff2 40#endif
fbea49e1 41 __s32 proxy_ndp;
0bcbc926 42 __s32 accept_source_route;
d9333196 43 __s32 accept_ra_from_local;
95c385b4
NH
44#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
45 __s32 optimistic_dad;
7fd2561e 46 __s32 use_optimistic;
7bc570c8
YH
47#endif
48#ifdef CONFIG_IPV6_MROUTE
49 __s32 mc_forwarding;
95c385b4 50#endif
778d80be 51 __s32 disable_ipv6;
1b34be74 52 __s32 accept_dad;
f7734fdf 53 __s32 force_tllao;
5cb04436 54 __s32 ndisc_notify;
b800c3b9 55 __s32 suppress_frag_ndisc;
c2943f14 56 __s32 accept_ra_mtu;
3d1bec99
HFS
57 struct ipv6_stable_secret {
58 bool initialized;
59 struct in6_addr secret;
60 } stable_secret;
3985e8a3 61 __s32 use_oif_addrs_only;
1da177e4
LT
62 void *sysctl;
63};
56d417b1
BH
64
65struct ipv6_params {
66 __s32 disable_ipv6;
67 __s32 autoconf;
68};
69extern struct ipv6_params ipv6_defaults;
1da177e4 70#include <linux/icmpv6.h>
1da177e4
LT
71#include <linux/tcp.h>
72#include <linux/udp.h>
73
14c85021
ACM
74#include <net/inet_sock.h>
75
0660e03f
ACM
76static inline struct ipv6hdr *ipv6_hdr(const struct sk_buff *skb)
77{
78 return (struct ipv6hdr *)skb_network_header(skb);
79}
80
6a674e9c
JG
81static inline struct ipv6hdr *inner_ipv6_hdr(const struct sk_buff *skb)
82{
83 return (struct ipv6hdr *)skb_inner_network_header(skb);
84}
85
39b89160
ACM
86static inline struct ipv6hdr *ipipv6_hdr(const struct sk_buff *skb)
87{
9c70220b 88 return (struct ipv6hdr *)skb_transport_header(skb);
39b89160
ACM
89}
90
1da177e4
LT
91/*
92 This structure contains results of exthdrs parsing
93 as offsets from skb->nh.
94 */
95
96struct inet6_skb_parm {
97 int iif;
dd3332bf 98 __be16 ra;
1da177e4
LT
99 __u16 dst0;
100 __u16 srcrt;
101 __u16 dst1;
333fad53 102 __u16 lastopt;
e7c38157 103 __u16 nhoff;
3e3850e9 104 __u16 flags;
59fbb3a6 105#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
8dd7368d
DM
106 __u16 dsthao;
107#endif
4cdd3408 108 __u16 frag_max_size;
3e3850e9
PM
109
110#define IP6SKB_XFRM_TRANSFORMED 1
7bc570c8 111#define IP6SKB_FORWARDED 2
9c6eb28a 112#define IP6SKB_REROUTED 4
dd3332bf 113#define IP6SKB_ROUTERALERT 8
f46078cf 114#define IP6SKB_FRAGMENTED 16
8b58a398 115#define IP6SKB_HOPBYHOP 32
1da177e4
LT
116};
117
118#define IP6CB(skb) ((struct inet6_skb_parm*)((skb)->cb))
4b340ae2 119#define IP6CBMTU(skb) ((struct ip6_mtuinfo *)((skb)->cb))
1da177e4 120
505cbfc5
ACM
121static inline int inet6_iif(const struct sk_buff *skb)
122{
123 return IP6CB(skb)->iif;
124}
125
ca304b61
ACM
126struct tcp6_request_sock {
127 struct tcp_request_sock tcp6rsk_tcp;
ca304b61 128};
2e6599cb 129
20283d84
HX
130struct ipv6_mc_socklist;
131struct ipv6_ac_socklist;
132struct ipv6_fl_socklist;
133
366e41d9
VY
134struct inet6_cork {
135 struct ipv6_txoptions *opt;
136 u8 hop_limit;
137 u8 tclass;
138};
139
1da177e4
LT
140/**
141 * struct ipv6_pinfo - ipv6 private area
142 *
143 * In the struct sock hierarchy (tcp6_sock, upd6_sock, etc)
144 * this _must_ be the last member, so that inet6_sk_generic
145 * is able to calculate its offset from the base struct sock
146 * by using the struct proto->slab_obj_size member. -acme
147 */
148struct ipv6_pinfo {
149 struct in6_addr saddr;
b24a2516 150 struct in6_pktinfo sticky_pktinfo;
d3818c92 151 const struct in6_addr *daddr_cache;
8e1ef0a9 152#ifdef CONFIG_IPV6_SUBTREES
d3818c92 153 const struct in6_addr *saddr_cache;
8e1ef0a9 154#endif
1da177e4 155
90bcaf7b 156 __be32 flow_label;
1da177e4 157 __u32 frag_size;
1d5d236d
YH
158
159 /*
160 * Packed in 16bits.
161 * Omit one shift by by putting the signed field at MSB.
162 */
163#if defined(__BIG_ENDIAN_BITFIELD)
164 __s16 hop_limit:9;
165 __u16 __unused_1:7;
166#else
167 __u16 __unused_1:7;
168 __s16 hop_limit:9;
169#endif
170
171#if defined(__BIG_ENDIAN_BITFIELD)
172 /* Packed in 16bits. */
173 __s16 mcast_hops:9;
174 __u16 __unused_2:6,
175 mc_loop:1;
176#else
177 __u16 mc_loop:1,
178 __unused_2:6;
179 __s16 mcast_hops:9;
180#endif
c4062dfc 181 int ucast_oif;
1da177e4
LT
182 int mcast_oif;
183
184 /* pktoption flags */
185 union {
186 struct {
4c752098
YH
187 __u16 srcrt:1,
188 osrcrt:1,
1da177e4 189 rxinfo:1,
333fad53 190 rxoinfo:1,
1da177e4 191 rxhlim:1,
333fad53 192 rxohlim:1,
1da177e4 193 hopopts:1,
333fad53 194 ohopopts:1,
1da177e4 195 dstopts:1,
333fad53 196 odstopts:1,
41a1f8ea 197 rxflow:1,
793b1473 198 rxtclass:1,
6c468622
BS
199 rxpmtu:1,
200 rxorigdstaddr:1;
201 /* 2 bits hole */
1da177e4 202 } bits;
333fad53 203 __u16 all;
1da177e4
LT
204 } rxopt;
205
206 /* sockopt flags */
793b1473 207 __u16 recverr:1,
1da177e4 208 sndflow:1,
df3687ff 209 repflow:1,
93b36cf3 210 pmtudisc:3,
9fe516ba 211 padding:1, /* 1 bit hole */
793b1473 212 srcprefs:3, /* 001: prefer temporary address
7cbca67c
YH
213 * 010: prefer public address
214 * 100: prefer care-of address
215 */
cb1ce2ef
TH
216 dontfrag:1,
217 autoflowlabel:1;
e802af9c 218 __u8 min_hopcount;
41a1f8ea 219 __u8 tclass;
1397ed35 220 __be32 rcv_flowinfo;
1da177e4
LT
221
222 __u32 dst_cookie;
5d299f3d 223 __u32 rx_dst_cookie;
1da177e4 224
456b61bc 225 struct ipv6_mc_socklist __rcu *ipv6_mc_list;
1da177e4 226 struct ipv6_ac_socklist *ipv6_ac_list;
18367681 227 struct ipv6_fl_socklist __rcu *ipv6_fl_list;
1da177e4
LT
228
229 struct ipv6_txoptions *opt;
230 struct sk_buff *pktoptions;
4b340ae2 231 struct sk_buff *rxpmtu;
366e41d9 232 struct inet6_cork cork;
1da177e4
LT
233};
234
235/* WARNING: don't change the layout of the members in {raw,udp,tcp}6_sock! */
236struct raw6_sock {
237 /* inet_sock has to be the first member of raw6_sock */
238 struct inet_sock inet;
239 __u32 checksum; /* perform checksum */
240 __u32 offset; /* checksum offset */
241 struct icmp6_filter filter;
d1db275d 242 __u32 ip6mr_table;
1da177e4
LT
243 /* ipv6_pinfo has to be the last member of raw6_sock, see inet6_sk_generic */
244 struct ipv6_pinfo inet6;
245};
246
247struct udp6_sock {
248 struct udp_sock udp;
249 /* ipv6_pinfo has to be the last member of udp6_sock, see inet6_sk_generic */
250 struct ipv6_pinfo inet6;
251};
252
253struct tcp6_sock {
254 struct tcp_sock tcp;
255 /* ipv6_pinfo has to be the last member of tcp6_sock, see inet6_sk_generic */
256 struct ipv6_pinfo inet6;
257};
258
b9750ce1
ACM
259extern int inet6_sk_rebuild_header(struct sock *sk);
260
48ee3569
DM
261struct tcp6_timewait_sock {
262 struct tcp_timewait_sock tcp6tw_tcp;
48ee3569
DM
263};
264
dfd56b8b 265#if IS_ENABLED(CONFIG_IPV6)
1da177e4
LT
266static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
267{
268 return inet_sk(__sk)->pinet6;
269}
270
271static inline struct raw6_sock *raw6_sk(const struct sock *sk)
272{
273 return (struct raw6_sock *)sk;
274}
275
276static inline void inet_sk_copy_descendant(struct sock *sk_to,
277 const struct sock *sk_from)
278{
279 int ancestor_size = sizeof(struct inet_sock);
280
281 if (sk_from->sk_family == PF_INET6)
282 ancestor_size += sizeof(struct ipv6_pinfo);
283
284 __inet_sk_copy_descendant(sk_to, sk_from, ancestor_size);
285}
286
9fe516ba
ED
287#define __ipv6_only_sock(sk) (sk->sk_ipv6only)
288#define ipv6_only_sock(sk) (__ipv6_only_sock(sk))
4b261c75
HFS
289#define ipv6_sk_rxinfo(sk) ((sk)->sk_family == PF_INET6 && \
290 inet6_sk(sk)->rxopt.bits.rxinfo)
8feaf0c0 291
efe4208f 292static inline const struct in6_addr *inet6_rcv_saddr(const struct sock *sk)
8feaf0c0 293{
efe4208f
ED
294 if (sk->sk_family == AF_INET6)
295 return &sk->sk_v6_rcv_saddr;
296 return NULL;
8feaf0c0
ACM
297}
298
463c84b9 299static inline int inet_v6_ipv6only(const struct sock *sk)
8feaf0c0 300{
9fe516ba
ED
301 /* ipv6only field is at same position for timewait and other sockets */
302 return ipv6_only_sock(sk);
8feaf0c0 303}
1da177e4
LT
304#else
305#define __ipv6_only_sock(sk) 0
306#define ipv6_only_sock(sk) 0
4b261c75 307#define ipv6_sk_rxinfo(sk) 0
1da177e4
LT
308
309static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
310{
311 return NULL;
312}
313
ca304b61
ACM
314static inline struct inet6_request_sock *
315 inet6_rsk(const struct request_sock *rsk)
316{
317 return NULL;
318}
319
1da177e4
LT
320static inline struct raw6_sock *raw6_sk(const struct sock *sk)
321{
322 return NULL;
323}
324
0fa1a53e 325#define inet6_rcv_saddr(__sk) NULL
8feaf0c0 326#define tcp_twsk_ipv6only(__sk) 0
463c84b9 327#define inet_v6_ipv6only(__sk) 0
dfd56b8b 328#endif /* IS_ENABLED(CONFIG_IPV6) */
8feaf0c0 329#endif /* _IPV6_H */