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