GNU Linux-libre 4.9.301-gnu1
[releases.git] / include / linux / icmpv6.h
1 #ifndef _LINUX_ICMPV6_H
2 #define _LINUX_ICMPV6_H
3
4 #include <linux/skbuff.h>
5 #include <linux/ipv6.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                              const struct inet6_skb_parm *parm);
20 void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
21                 const struct in6_addr *force_saddr,
22                 const struct inet6_skb_parm *parm);
23 #if IS_BUILTIN(CONFIG_IPV6)
24 static inline void __icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
25                                  const struct inet6_skb_parm *parm)
26 {
27         icmp6_send(skb, type, code, info, NULL, parm);
28 }
29 static inline int inet6_register_icmp_sender(ip6_icmp_send_t *fn)
30 {
31         BUILD_BUG_ON(fn != icmp6_send);
32         return 0;
33 }
34 static inline int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn)
35 {
36         BUILD_BUG_ON(fn != icmp6_send);
37         return 0;
38 }
39 #else
40 extern void __icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
41                           const struct inet6_skb_parm *parm);
42 extern int inet6_register_icmp_sender(ip6_icmp_send_t *fn);
43 extern int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn);
44 #endif
45
46 static inline void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info)
47 {
48         __icmpv6_send(skb, type, code, info, IP6CB(skb));
49 }
50
51 int ip6_err_gen_icmpv6_unreach(struct sk_buff *skb, int nhs, int type,
52                                unsigned int data_len);
53
54 #if IS_ENABLED(CONFIG_NF_NAT)
55 void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info);
56 #else
57 static inline void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info)
58 {
59         struct inet6_skb_parm parm = { 0 };
60         __icmpv6_send(skb_in, type, code, info, &parm);
61 }
62 #endif
63
64 #else
65
66 static inline void icmpv6_send(struct sk_buff *skb,
67                                u8 type, u8 code, __u32 info)
68 {
69 }
70
71 static inline void icmpv6_ndo_send(struct sk_buff *skb,
72                                    u8 type, u8 code, __u32 info)
73 {
74 }
75 #endif
76
77 extern int                              icmpv6_init(void);
78 extern int                              icmpv6_err_convert(u8 type, u8 code,
79                                                            int *err);
80 extern void                             icmpv6_cleanup(void);
81 extern void                             icmpv6_param_prob(struct sk_buff *skb,
82                                                           u8 code, int pos);
83
84 struct flowi6;
85 struct in6_addr;
86 extern void                             icmpv6_flow_init(struct sock *sk,
87                                                          struct flowi6 *fl6,
88                                                          u8 type,
89                                                          const struct in6_addr *saddr,
90                                                          const struct in6_addr *daddr,
91                                                          int oif);
92 #endif