blob: 9055cb380ee2411b438e9b4fab90fa9e8362cf17 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_ICMPV6_H
3#define _LINUX_ICMPV6_H
4
5#include <linux/skbuff.h>
Olivier Deprez0e641232021-09-23 10:07:05 +02006#include <linux/ipv6.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00007#include <uapi/linux/icmpv6.h>
8
9static inline struct icmp6hdr *icmp6_hdr(const struct sk_buff *skb)
10{
11 return (struct icmp6hdr *)skb_transport_header(skb);
12}
13
14#include <linux/netdevice.h>
15
16#if IS_ENABLED(CONFIG_IPV6)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000017
18typedef void ip6_icmp_send_t(struct sk_buff *skb, u8 type, u8 code, __u32 info,
Olivier Deprez0e641232021-09-23 10:07:05 +020019 const struct in6_addr *force_saddr,
20 const struct inet6_skb_parm *parm);
21void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
22 const struct in6_addr *force_saddr,
23 const struct inet6_skb_parm *parm);
24#if IS_BUILTIN(CONFIG_IPV6)
25static inline void __icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
26 const struct inet6_skb_parm *parm)
27{
28 icmp6_send(skb, type, code, info, NULL, parm);
29}
30static inline int inet6_register_icmp_sender(ip6_icmp_send_t *fn)
31{
32 BUILD_BUG_ON(fn != icmp6_send);
33 return 0;
34}
35static 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
41extern void __icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
42 const struct inet6_skb_parm *parm);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000043extern int inet6_register_icmp_sender(ip6_icmp_send_t *fn);
44extern int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn);
Olivier Deprez0e641232021-09-23 10:07:05 +020045#endif
46
47static 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
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000052int ip6_err_gen_icmpv6_unreach(struct sk_buff *skb, int nhs, int type,
53 unsigned int data_len);
54
Olivier Deprez0e641232021-09-23 10:07:05 +020055#if IS_ENABLED(CONFIG_NF_NAT)
56void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info);
57#else
58static 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}
63#endif
64
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000065#else
66
67static inline void icmpv6_send(struct sk_buff *skb,
68 u8 type, u8 code, __u32 info)
69{
Olivier Deprez0e641232021-09-23 10:07:05 +020070}
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000071
Olivier Deprez0e641232021-09-23 10:07:05 +020072static inline void icmpv6_ndo_send(struct sk_buff *skb,
73 u8 type, u8 code, __u32 info)
74{
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000075}
76#endif
77
78extern int icmpv6_init(void);
79extern int icmpv6_err_convert(u8 type, u8 code,
80 int *err);
81extern void icmpv6_cleanup(void);
82extern void icmpv6_param_prob(struct sk_buff *skb,
83 u8 code, int pos);
84
85struct flowi6;
86struct in6_addr;
87extern void icmpv6_flow_init(struct sock *sk,
88 struct flowi6 *fl6,
89 u8 type,
90 const struct in6_addr *saddr,
91 const struct in6_addr *daddr,
92 int oif);
Olivier Deprez157378f2022-04-04 15:47:50 +020093
94static inline bool icmpv6_is_err(int type)
95{
96 switch (type) {
97 case ICMPV6_DEST_UNREACH:
98 case ICMPV6_PKT_TOOBIG:
99 case ICMPV6_TIME_EXCEED:
100 case ICMPV6_PARAMPROB:
101 return true;
102 }
103
104 return false;
105}
106
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000107#endif