Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef _IPV6_H |
3 | #define _IPV6_H | |
4 | ||
607ca46e | 5 | #include <uapi/linux/ipv6.h> |
096361b1 | 6 | #include <linux/cache.h> |
1da177e4 | 7 | |
1da177e4 | 8 | #define ipv6_optlen(p) (((p)->hdrlen+1) << 3) |
1431fb31 | 9 | #define ipv6_authlen(p) (((p)->hdrlen+2) << 2) |
1da177e4 LT |
10 | /* |
11 | * This structure contains configuration options per IPv6 link. | |
12 | */ | |
13 | struct ipv6_devconf { | |
096361b1 ED |
14 | /* RX & TX fastpath fields. */ |
15 | __cacheline_group_begin(ipv6_devconf_read_txrx); | |
16 | __s32 disable_ipv6; | |
1da177e4 LT |
17 | __s32 hop_limit; |
18 | __s32 mtu6; | |
096361b1 ED |
19 | __s32 forwarding; |
20 | __s32 disable_policy; | |
21 | __s32 proxy_ndp; | |
22 | __cacheline_group_end(ipv6_devconf_read_txrx); | |
23 | ||
1da177e4 LT |
24 | __s32 accept_ra; |
25 | __s32 accept_redirects; | |
26 | __s32 autoconf; | |
27 | __s32 dad_transmits; | |
28 | __s32 rtr_solicits; | |
29 | __s32 rtr_solicit_interval; | |
bd11f074 | 30 | __s32 rtr_solicit_max_interval; |
1da177e4 LT |
31 | __s32 rtr_solicit_delay; |
32 | __s32 force_mld_version; | |
fc4eba58 HFS |
33 | __s32 mldv1_unsolicited_report_interval; |
34 | __s32 mldv2_unsolicited_report_interval; | |
1da177e4 LT |
35 | __s32 use_tempaddr; |
36 | __s32 temp_valid_lft; | |
37 | __s32 temp_prefered_lft; | |
a5fcea2d | 38 | __s32 regen_min_advance; |
1da177e4 LT |
39 | __s32 regen_max_retry; |
40 | __s32 max_desync_factor; | |
1da177e4 | 41 | __s32 max_addresses; |
65f5c7c1 | 42 | __s32 accept_ra_defrtr; |
6b2e04bc | 43 | __u32 ra_defrtr_metric; |
8013d1d7 | 44 | __s32 accept_ra_min_hop_limit; |
5027d54a | 45 | __s32 accept_ra_min_lft; |
c4fd30eb | 46 | __s32 accept_ra_pinfo; |
35103d11 | 47 | __s32 ignore_routes_with_linkdown; |
930d6ff2 YH |
48 | #ifdef CONFIG_IPV6_ROUTER_PREF |
49 | __s32 accept_ra_rtr_pref; | |
52e16356 | 50 | __s32 rtr_probe_interval; |
09c884d4 | 51 | #ifdef CONFIG_IPV6_ROUTE_INFO |
bbea124b | 52 | __s32 accept_ra_rt_info_min_plen; |
09c884d4 YH |
53 | __s32 accept_ra_rt_info_max_plen; |
54 | #endif | |
930d6ff2 | 55 | #endif |
0bcbc926 | 56 | __s32 accept_source_route; |
d9333196 | 57 | __s32 accept_ra_from_local; |
95c385b4 NH |
58 | #ifdef CONFIG_IPV6_OPTIMISTIC_DAD |
59 | __s32 optimistic_dad; | |
7fd2561e | 60 | __s32 use_optimistic; |
7bc570c8 YH |
61 | #endif |
62 | #ifdef CONFIG_IPV6_MROUTE | |
145c7a79 | 63 | atomic_t mc_forwarding; |
95c385b4 | 64 | #endif |
abbc3043 | 65 | __s32 drop_unicast_in_l2_multicast; |
1b34be74 | 66 | __s32 accept_dad; |
f7734fdf | 67 | __s32 force_tllao; |
5cb04436 | 68 | __s32 ndisc_notify; |
b800c3b9 | 69 | __s32 suppress_frag_ndisc; |
c2943f14 | 70 | __s32 accept_ra_mtu; |
7a02bf89 | 71 | __s32 drop_unsolicited_na; |
3e0b8f52 | 72 | __s32 accept_untracked_na; |
3d1bec99 HFS |
73 | struct ipv6_stable_secret { |
74 | bool initialized; | |
75 | struct in6_addr secret; | |
76 | } stable_secret; | |
3985e8a3 | 77 | __s32 use_oif_addrs_only; |
f1705ec1 | 78 | __s32 keep_addr_on_down; |
1ababeba | 79 | __s32 seg6_enabled; |
bf355b8d DL |
80 | #ifdef CONFIG_IPV6_SEG6_HMAC |
81 | __s32 seg6_require_hmac; | |
82 | #endif | |
adc176c5 | 83 | __u32 enhanced_dad; |
d35a00b8 | 84 | __u32 addr_gen_mode; |
2210d6b2 | 85 | __s32 ndisc_tclass; |
8610c7c6 | 86 | __s32 rpl_seg_enabled; |
9ee11f0f JI |
87 | __u32 ioam6_id; |
88 | __u32 ioam6_id_wide; | |
89 | __u8 ioam6_enabled; | |
18ac597a | 90 | __u8 ndisc_evict_nocarrier; |
473267a4 | 91 | __u8 ra_honor_pio_life; |
607ea7cd KK |
92 | |
93 | struct ctl_table_header *sysctl_header; | |
1da177e4 | 94 | }; |
56d417b1 BH |
95 | |
96 | struct ipv6_params { | |
97 | __s32 disable_ipv6; | |
98 | __s32 autoconf; | |
99 | }; | |
100 | extern struct ipv6_params ipv6_defaults; | |
1da177e4 LT |
101 | #include <linux/tcp.h> |
102 | #include <linux/udp.h> | |
103 | ||
14c85021 ACM |
104 | #include <net/inet_sock.h> |
105 | ||
0660e03f ACM |
106 | static inline struct ipv6hdr *ipv6_hdr(const struct sk_buff *skb) |
107 | { | |
108 | return (struct ipv6hdr *)skb_network_header(skb); | |
109 | } | |
110 | ||
6a674e9c JG |
111 | static inline struct ipv6hdr *inner_ipv6_hdr(const struct sk_buff *skb) |
112 | { | |
113 | return (struct ipv6hdr *)skb_inner_network_header(skb); | |
114 | } | |
115 | ||
39b89160 ACM |
116 | static inline struct ipv6hdr *ipipv6_hdr(const struct sk_buff *skb) |
117 | { | |
9c70220b | 118 | return (struct ipv6hdr *)skb_transport_header(skb); |
39b89160 ACM |
119 | } |
120 | ||
ba5ea614 LL |
121 | static inline unsigned int ipv6_transport_len(const struct sk_buff *skb) |
122 | { | |
123 | return ntohs(ipv6_hdr(skb)->payload_len) + sizeof(struct ipv6hdr) - | |
124 | skb_network_header_len(skb); | |
125 | } | |
126 | ||
1da177e4 LT |
127 | /* |
128 | This structure contains results of exthdrs parsing | |
129 | as offsets from skb->nh. | |
130 | */ | |
131 | ||
132 | struct inet6_skb_parm { | |
133 | int iif; | |
dd3332bf | 134 | __be16 ra; |
1da177e4 LT |
135 | __u16 dst0; |
136 | __u16 srcrt; | |
137 | __u16 dst1; | |
333fad53 | 138 | __u16 lastopt; |
e7c38157 | 139 | __u16 nhoff; |
3e3850e9 | 140 | __u16 flags; |
59fbb3a6 | 141 | #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE) |
8dd7368d DM |
142 | __u16 dsthao; |
143 | #endif | |
4cdd3408 | 144 | __u16 frag_max_size; |
e4129440 | 145 | __u16 srhoff; |
3e3850e9 PM |
146 | |
147 | #define IP6SKB_XFRM_TRANSFORMED 1 | |
7bc570c8 | 148 | #define IP6SKB_FORWARDED 2 |
9c6eb28a | 149 | #define IP6SKB_REROUTED 4 |
dd3332bf | 150 | #define IP6SKB_ROUTERALERT 8 |
f46078cf | 151 | #define IP6SKB_FRAGMENTED 16 |
8b58a398 | 152 | #define IP6SKB_HOPBYHOP 32 |
74b20582 | 153 | #define IP6SKB_L3SLAVE 64 |
cb891fa6 | 154 | #define IP6SKB_JUMBOGRAM 128 |
e4129440 | 155 | #define IP6SKB_SEG6 256 |
80e425b6 | 156 | #define IP6SKB_FAKEJUMBO 512 |
8423be89 | 157 | #define IP6SKB_MULTIPATH 1024 |
1da177e4 LT |
158 | }; |
159 | ||
74b20582 | 160 | #if defined(CONFIG_NET_L3_MASTER_DEV) |
a04a480d | 161 | static inline bool ipv6_l3mdev_skb(__u16 flags) |
74b20582 DA |
162 | { |
163 | return flags & IP6SKB_L3SLAVE; | |
164 | } | |
165 | #else | |
a04a480d | 166 | static inline bool ipv6_l3mdev_skb(__u16 flags) |
74b20582 DA |
167 | { |
168 | return false; | |
169 | } | |
170 | #endif | |
171 | ||
1da177e4 | 172 | #define IP6CB(skb) ((struct inet6_skb_parm*)((skb)->cb)) |
4b340ae2 | 173 | #define IP6CBMTU(skb) ((struct ip6_mtuinfo *)((skb)->cb)) |
1da177e4 | 174 | |
505cbfc5 ACM |
175 | static inline int inet6_iif(const struct sk_buff *skb) |
176 | { | |
a04a480d | 177 | bool l3_slave = ipv6_l3mdev_skb(IP6CB(skb)->flags); |
74b20582 DA |
178 | |
179 | return l3_slave ? skb->skb_iif : IP6CB(skb)->iif; | |
505cbfc5 | 180 | } |
cb891fa6 PA |
181 | |
182 | static inline bool inet6_is_jumbogram(const struct sk_buff *skb) | |
183 | { | |
184 | return !!(IP6CB(skb)->flags & IP6SKB_JUMBOGRAM); | |
185 | } | |
1801b570 DA |
186 | |
187 | /* can not be used in TCP layer after tcp_v6_fill_cb */ | |
188 | static inline int inet6_sdif(const struct sk_buff *skb) | |
189 | { | |
190 | #if IS_ENABLED(CONFIG_NET_L3_MASTER_DEV) | |
191 | if (skb && ipv6_l3mdev_skb(IP6CB(skb)->flags)) | |
192 | return IP6CB(skb)->iif; | |
193 | #endif | |
194 | return 0; | |
195 | } | |
505cbfc5 | 196 | |
ca304b61 ACM |
197 | struct tcp6_request_sock { |
198 | struct tcp_request_sock tcp6rsk_tcp; | |
ca304b61 | 199 | }; |
2e6599cb | 200 | |
20283d84 HX |
201 | struct ipv6_mc_socklist; |
202 | struct ipv6_ac_socklist; | |
203 | struct ipv6_fl_socklist; | |
204 | ||
366e41d9 VY |
205 | struct inet6_cork { |
206 | struct ipv6_txoptions *opt; | |
207 | u8 hop_limit; | |
208 | u8 tclass; | |
209 | }; | |
210 | ||
f5f80e32 | 211 | /* struct ipv6_pinfo - ipv6 private area */ |
1da177e4 LT |
212 | struct ipv6_pinfo { |
213 | struct in6_addr saddr; | |
b24a2516 | 214 | struct in6_pktinfo sticky_pktinfo; |
d3818c92 | 215 | const struct in6_addr *daddr_cache; |
8e1ef0a9 | 216 | #ifdef CONFIG_IPV6_SUBTREES |
d3818c92 | 217 | const struct in6_addr *saddr_cache; |
8e1ef0a9 | 218 | #endif |
1da177e4 | 219 | |
90bcaf7b | 220 | __be32 flow_label; |
1da177e4 | 221 | __u32 frag_size; |
1d5d236d | 222 | |
b0adfba7 | 223 | s16 hop_limit; |
2da23eb0 | 224 | u8 mcast_hops; |
1d5d236d | 225 | |
c4062dfc | 226 | int ucast_oif; |
1da177e4 LT |
227 | int mcast_oif; |
228 | ||
229 | /* pktoption flags */ | |
230 | union { | |
231 | struct { | |
4c752098 YH |
232 | __u16 srcrt:1, |
233 | osrcrt:1, | |
1da177e4 | 234 | rxinfo:1, |
333fad53 | 235 | rxoinfo:1, |
1da177e4 | 236 | rxhlim:1, |
333fad53 | 237 | rxohlim:1, |
1da177e4 | 238 | hopopts:1, |
333fad53 | 239 | ohopopts:1, |
1da177e4 | 240 | dstopts:1, |
333fad53 | 241 | odstopts:1, |
41a1f8ea | 242 | rxflow:1, |
793b1473 | 243 | rxtclass:1, |
6c468622 | 244 | rxpmtu:1, |
0cc0aa61 WB |
245 | rxorigdstaddr:1, |
246 | recvfragsize:1; | |
247 | /* 1 bits hole */ | |
1da177e4 | 248 | } bits; |
333fad53 | 249 | __u16 all; |
1da177e4 LT |
250 | } rxopt; |
251 | ||
252 | /* sockopt flags */ | |
fa17a6d8 | 253 | __u8 srcprefs; /* 001: prefer temporary address |
7cbca67c YH |
254 | * 010: prefer public address |
255 | * 100: prefer care-of address | |
256 | */ | |
6b724bc4 | 257 | __u8 pmtudisc; |
e802af9c | 258 | __u8 min_hopcount; |
41a1f8ea | 259 | __u8 tclass; |
1397ed35 | 260 | __be32 rcv_flowinfo; |
1da177e4 LT |
261 | |
262 | __u32 dst_cookie; | |
263 | ||
456b61bc | 264 | struct ipv6_mc_socklist __rcu *ipv6_mc_list; |
1da177e4 | 265 | struct ipv6_ac_socklist *ipv6_ac_list; |
18367681 | 266 | struct ipv6_fl_socklist __rcu *ipv6_fl_list; |
1da177e4 | 267 | |
45f6fad8 | 268 | struct ipv6_txoptions __rcu *opt; |
1da177e4 | 269 | struct sk_buff *pktoptions; |
4b340ae2 | 270 | struct sk_buff *rxpmtu; |
366e41d9 | 271 | struct inet6_cork cork; |
1da177e4 LT |
272 | }; |
273 | ||
d986f521 ED |
274 | /* We currently use available bits from inet_sk(sk)->inet_flags, |
275 | * this could change in the future. | |
276 | */ | |
277 | #define inet6_test_bit(nr, sk) \ | |
278 | test_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags) | |
279 | #define inet6_set_bit(nr, sk) \ | |
280 | set_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags) | |
281 | #define inet6_clear_bit(nr, sk) \ | |
282 | clear_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags) | |
283 | #define inet6_assign_bit(nr, sk, val) \ | |
284 | assign_bit(INET_FLAGS_##nr, &inet_sk(sk)->inet_flags, val) | |
285 | ||
1da177e4 LT |
286 | /* WARNING: don't change the layout of the members in {raw,udp,tcp}6_sock! */ |
287 | struct raw6_sock { | |
288 | /* inet_sock has to be the first member of raw6_sock */ | |
289 | struct inet_sock inet; | |
290 | __u32 checksum; /* perform checksum */ | |
291 | __u32 offset; /* checksum offset */ | |
292 | struct icmp6_filter filter; | |
d1db275d | 293 | __u32 ip6mr_table; |
f5f80e32 | 294 | |
1da177e4 LT |
295 | struct ipv6_pinfo inet6; |
296 | }; | |
297 | ||
298 | struct udp6_sock { | |
299 | struct udp_sock udp; | |
f5f80e32 | 300 | |
1da177e4 LT |
301 | struct ipv6_pinfo inet6; |
302 | }; | |
303 | ||
304 | struct tcp6_sock { | |
305 | struct tcp_sock tcp; | |
f5f80e32 | 306 | |
1da177e4 LT |
307 | struct ipv6_pinfo inet6; |
308 | }; | |
309 | ||
b9750ce1 ACM |
310 | extern int inet6_sk_rebuild_header(struct sock *sk); |
311 | ||
48ee3569 DM |
312 | struct tcp6_timewait_sock { |
313 | struct tcp_timewait_sock tcp6tw_tcp; | |
48ee3569 DM |
314 | }; |
315 | ||
dfd56b8b | 316 | #if IS_ENABLED(CONFIG_IPV6) |
e4348637 DA |
317 | bool ipv6_mod_enabled(void); |
318 | ||
e7eadb4d | 319 | static inline struct ipv6_pinfo *inet6_sk(const struct sock *__sk) |
1da177e4 | 320 | { |
e7eadb4d | 321 | return sk_fullsock(__sk) ? inet_sk(__sk)->pinet6 : NULL; |
1da177e4 LT |
322 | } |
323 | ||
47fcae28 | 324 | #define raw6_sk(ptr) container_of_const(ptr, struct raw6_sock, inet.sk) |
1da177e4 | 325 | |
89e9c728 | 326 | #define ipv6_only_sock(sk) (sk->sk_ipv6only) |
4b261c75 HFS |
327 | #define ipv6_sk_rxinfo(sk) ((sk)->sk_family == PF_INET6 && \ |
328 | inet6_sk(sk)->rxopt.bits.rxinfo) | |
8feaf0c0 | 329 | |
efe4208f | 330 | static inline const struct in6_addr *inet6_rcv_saddr(const struct sock *sk) |
8feaf0c0 | 331 | { |
efe4208f ED |
332 | if (sk->sk_family == AF_INET6) |
333 | return &sk->sk_v6_rcv_saddr; | |
334 | return NULL; | |
8feaf0c0 ACM |
335 | } |
336 | ||
463c84b9 | 337 | static inline int inet_v6_ipv6only(const struct sock *sk) |
8feaf0c0 | 338 | { |
9fe516ba ED |
339 | /* ipv6only field is at same position for timewait and other sockets */ |
340 | return ipv6_only_sock(sk); | |
8feaf0c0 | 341 | } |
1da177e4 | 342 | #else |
1da177e4 | 343 | #define ipv6_only_sock(sk) 0 |
4b261c75 | 344 | #define ipv6_sk_rxinfo(sk) 0 |
1da177e4 | 345 | |
e4348637 DA |
346 | static inline bool ipv6_mod_enabled(void) |
347 | { | |
348 | return false; | |
349 | } | |
350 | ||
1da177e4 LT |
351 | static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk) |
352 | { | |
353 | return NULL; | |
354 | } | |
355 | ||
356 | static inline struct raw6_sock *raw6_sk(const struct sock *sk) | |
357 | { | |
358 | return NULL; | |
359 | } | |
360 | ||
0fa1a53e | 361 | #define inet6_rcv_saddr(__sk) NULL |
463c84b9 | 362 | #define inet_v6_ipv6only(__sk) 0 |
dfd56b8b | 363 | #endif /* IS_ENABLED(CONFIG_IPV6) */ |
8feaf0c0 | 364 | #endif /* _IPV6_H */ |