Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef _LINUX_ICMPV6_H |
3 | #define _LINUX_ICMPV6_H | |
4 | ||
cc70ab26 | 5 | #include <linux/skbuff.h> |
ee576c47 | 6 | #include <linux/ipv6.h> |
607ca46e | 7 | #include <uapi/linux/icmpv6.h> |
cc70ab26 ACM |
8 | |
9 | static inline struct icmp6hdr *icmp6_hdr(const struct sk_buff *skb) | |
10 | { | |
9c70220b | 11 | return (struct icmp6hdr *)skb_transport_header(skb); |
cc70ab26 | 12 | } |
1da177e4 LT |
13 | |
14 | #include <linux/netdevice.h> | |
1da177e4 | 15 | |
5f5624cf | 16 | #if IS_ENABLED(CONFIG_IPV6) |
5f5624cf | 17 | |
b1cadc1a | 18 | typedef void ip6_icmp_send_t(struct sk_buff *skb, u8 type, u8 code, __u32 info, |
ee576c47 JD |
19 | const struct in6_addr *force_saddr, |
20 | const struct inet6_skb_parm *parm); | |
cc7a21b6 | 21 | void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, |
ee576c47 JD |
22 | const struct in6_addr *force_saddr, |
23 | const struct inet6_skb_parm *parm); | |
1faba27f | 24 | #if IS_BUILTIN(CONFIG_IPV6) |
ee576c47 JD |
25 | static inline void __icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, |
26 | const struct inet6_skb_parm *parm) | |
cc7a21b6 | 27 | { |
ee576c47 | 28 | icmp6_send(skb, type, code, info, NULL, parm); |
cc7a21b6 ED |
29 | } |
30 | static inline int inet6_register_icmp_sender(ip6_icmp_send_t *fn) | |
31 | { | |
32 | BUILD_BUG_ON(fn != icmp6_send); | |
33 | return 0; | |
34 | } | |
35 | static inline int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn) | |
36 | { | |
37 | BUILD_BUG_ON(fn != icmp6_send); | |
38 | return 0; | |
39 | } | |
40 | #else | |
ee576c47 JD |
41 | extern void __icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, |
42 | const struct inet6_skb_parm *parm); | |
5f5624cf PS |
43 | extern int inet6_register_icmp_sender(ip6_icmp_send_t *fn); |
44 | extern int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn); | |
cc7a21b6 ED |
45 | #endif |
46 | ||
ee576c47 JD |
47 | static inline void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info) |
48 | { | |
49 | __icmpv6_send(skb, type, code, info, IP6CB(skb)); | |
50 | } | |
51 | ||
20e1954f ED |
52 | int ip6_err_gen_icmpv6_unreach(struct sk_buff *skb, int nhs, int type, |
53 | unsigned int data_len); | |
5f5624cf | 54 | |
a8e41f60 JD |
55 | #if IS_ENABLED(CONFIG_NF_NAT) |
56 | void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info); | |
57 | #else | |
ee576c47 JD |
58 | static inline void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info) |
59 | { | |
60 | struct inet6_skb_parm parm = { 0 }; | |
61 | __icmpv6_send(skb_in, type, code, info, &parm); | |
62 | } | |
a8e41f60 JD |
63 | #endif |
64 | ||
5f5624cf PS |
65 | #else |
66 | ||
67 | static inline void icmpv6_send(struct sk_buff *skb, | |
68 | u8 type, u8 code, __u32 info) | |
69 | { | |
5f5624cf | 70 | } |
1da177e4 | 71 | |
a8e41f60 JD |
72 | static inline void icmpv6_ndo_send(struct sk_buff *skb, |
73 | u8 type, u8 code, __u32 info) | |
74 | { | |
75 | } | |
0b41713b JD |
76 | #endif |
77 | ||
9b0f976f | 78 | extern int icmpv6_init(void); |
d5fdd6ba | 79 | extern int icmpv6_err_convert(u8 type, u8 code, |
1da177e4 LT |
80 | int *err); |
81 | extern void icmpv6_cleanup(void); | |
1ad6d548 MD |
82 | extern void icmpv6_param_prob_reason(struct sk_buff *skb, |
83 | u8 code, int pos, | |
84 | enum skb_drop_reason reason); | |
95e41e93 | 85 | |
4c9483b2 | 86 | struct flowi6; |
f59d4389 | 87 | struct in6_addr; |
95e41e93 | 88 | extern void icmpv6_flow_init(struct sock *sk, |
4c9483b2 | 89 | struct flowi6 *fl6, |
95e41e93 YH |
90 | u8 type, |
91 | const struct in6_addr *saddr, | |
92 | const struct in6_addr *daddr, | |
93 | int oif); | |
15122464 | 94 | |
1ad6d548 MD |
95 | static inline void icmpv6_param_prob(struct sk_buff *skb, u8 code, int pos) |
96 | { | |
97 | icmpv6_param_prob_reason(skb, code, pos, | |
98 | SKB_DROP_REASON_NOT_SPECIFIED); | |
99 | } | |
100 | ||
15122464 MC |
101 | static inline bool icmpv6_is_err(int type) |
102 | { | |
103 | switch (type) { | |
104 | case ICMPV6_DEST_UNREACH: | |
105 | case ICMPV6_PKT_TOOBIG: | |
106 | case ICMPV6_TIME_EXCEED: | |
107 | case ICMPV6_PARAMPROB: | |
108 | return true; | |
109 | } | |
110 | ||
111 | return false; | |
112 | } | |
113 | ||
1da177e4 | 114 | #endif |