Merge tag 'powerpc-5.9-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[linux-2.6-microblaze.git] / include / linux / icmpv6.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_ICMPV6_H
3 #define _LINUX_ICMPV6_H
4
5 #include <linux/skbuff.h>
6 #include <uapi/linux/icmpv6.h>
7
8 static inline struct icmp6hdr *icmp6_hdr(const struct sk_buff *skb)
9 {
10         return (struct icmp6hdr *)skb_transport_header(skb);
11 }
12
13 #include <linux/netdevice.h>
14
15 #if IS_ENABLED(CONFIG_IPV6)
16
17 typedef void ip6_icmp_send_t(struct sk_buff *skb, u8 type, u8 code, __u32 info,
18                              const struct in6_addr *force_saddr);
19 #if IS_BUILTIN(CONFIG_IPV6)
20 void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
21                 const struct in6_addr *force_saddr);
22 static inline void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info)
23 {
24         icmp6_send(skb, type, code, info, NULL);
25 }
26 static inline int inet6_register_icmp_sender(ip6_icmp_send_t *fn)
27 {
28         BUILD_BUG_ON(fn != icmp6_send);
29         return 0;
30 }
31 static inline int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn)
32 {
33         BUILD_BUG_ON(fn != icmp6_send);
34         return 0;
35 }
36 #else
37 extern void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info);
38 extern int inet6_register_icmp_sender(ip6_icmp_send_t *fn);
39 extern int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn);
40 #endif
41
42 int ip6_err_gen_icmpv6_unreach(struct sk_buff *skb, int nhs, int type,
43                                unsigned int data_len);
44
45 #if IS_ENABLED(CONFIG_NF_NAT)
46 void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info);
47 #else
48 #define icmpv6_ndo_send icmpv6_send
49 #endif
50
51 #else
52
53 static inline void icmpv6_send(struct sk_buff *skb,
54                                u8 type, u8 code, __u32 info)
55 {
56 }
57
58 static inline void icmpv6_ndo_send(struct sk_buff *skb,
59                                    u8 type, u8 code, __u32 info)
60 {
61 }
62 #endif
63
64 extern int                              icmpv6_init(void);
65 extern int                              icmpv6_err_convert(u8 type, u8 code,
66                                                            int *err);
67 extern void                             icmpv6_cleanup(void);
68 extern void                             icmpv6_param_prob(struct sk_buff *skb,
69                                                           u8 code, int pos);
70
71 struct flowi6;
72 struct in6_addr;
73 extern void                             icmpv6_flow_init(struct sock *sk,
74                                                          struct flowi6 *fl6,
75                                                          u8 type,
76                                                          const struct in6_addr *saddr,
77                                                          const struct in6_addr *daddr,
78                                                          int oif);
79
80 static inline bool icmpv6_is_err(int type)
81 {
82         switch (type) {
83         case ICMPV6_DEST_UNREACH:
84         case ICMPV6_PKT_TOOBIG:
85         case ICMPV6_TIME_EXCEED:
86         case ICMPV6_PARAMPROB:
87                 return true;
88         }
89
90         return false;
91 }
92
93 #endif