blob: 9055cb380ee2411b438e9b4fab90fa9e8362cf17 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _LINUX_ICMPV6_H
3#define _LINUX_ICMPV6_H
4
Arnaldo Carvalho de Melocc70ab22007-03-13 14:03:22 -03005#include <linux/skbuff.h>
Jason A. Donenfeldce4feb02021-02-23 14:18:58 +01006#include <linux/ipv6.h>
David Howells607ca462012-10-13 10:46:48 +01007#include <uapi/linux/icmpv6.h>
Arnaldo Carvalho de Melocc70ab22007-03-13 14:03:22 -03008
9static inline struct icmp6hdr *icmp6_hdr(const struct sk_buff *skb)
10{
Arnaldo Carvalho de Melo9c702202007-04-25 18:04:18 -070011 return (struct icmp6hdr *)skb_transport_header(skb);
Arnaldo Carvalho de Melocc70ab22007-03-13 14:03:22 -030012}
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#include <linux/netdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Pravin B Shelar5f5624c2013-04-25 11:08:30 +000016#if IS_ENABLED(CONFIG_IPV6)
Pravin B Shelar5f5624c2013-04-25 11:08:30 +000017
Eric Dumazetb1cadc12016-06-18 21:52:02 -070018typedef void ip6_icmp_send_t(struct sk_buff *skb, u8 type, u8 code, __u32 info,
Jason A. Donenfeldce4feb02021-02-23 14:18:58 +010019 const struct in6_addr *force_saddr,
20 const struct inet6_skb_parm *parm);
Eric Dumazetcc7a21b2020-06-19 12:02:59 -070021void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
Jason A. Donenfeldce4feb02021-02-23 14:18:58 +010022 const struct in6_addr *force_saddr,
23 const struct inet6_skb_parm *parm);
Leon Romanovskyb60108e2021-02-03 15:51:09 +020024#if IS_BUILTIN(CONFIG_IPV6)
Jason A. Donenfeldce4feb02021-02-23 14:18:58 +010025static inline void __icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
26 const struct inet6_skb_parm *parm)
Eric Dumazetcc7a21b2020-06-19 12:02:59 -070027{
Jason A. Donenfeldce4feb02021-02-23 14:18:58 +010028 icmp6_send(skb, type, code, info, NULL, parm);
Eric Dumazetcc7a21b2020-06-19 12:02:59 -070029}
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
Jason A. Donenfeldce4feb02021-02-23 14:18:58 +010041extern void __icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
42 const struct inet6_skb_parm *parm);
Pravin B Shelar5f5624c2013-04-25 11:08:30 +000043extern int inet6_register_icmp_sender(ip6_icmp_send_t *fn);
44extern int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn);
Eric Dumazetcc7a21b2020-06-19 12:02:59 -070045#endif
46
Jason A. Donenfeldce4feb02021-02-23 14:18:58 +010047static 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
Eric Dumazet20e19542016-06-18 21:52:06 -070052int ip6_err_gen_icmpv6_unreach(struct sk_buff *skb, int nhs, int type,
53 unsigned int data_len);
Pravin B Shelar5f5624c2013-04-25 11:08:30 +000054
Jason A. Donenfelda8e41f62020-02-25 18:05:35 +080055#if IS_ENABLED(CONFIG_NF_NAT)
56void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info);
57#else
Jason A. Donenfeldce4feb02021-02-23 14:18:58 +010058static 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}
Jason A. Donenfelda8e41f62020-02-25 18:05:35 +080063#endif
64
Pravin B Shelar5f5624c2013-04-25 11:08:30 +000065#else
66
67static inline void icmpv6_send(struct sk_buff *skb,
68 u8 type, u8 code, __u32 info)
69{
Pravin B Shelar5f5624c2013-04-25 11:08:30 +000070}
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Jason A. Donenfelda8e41f62020-02-25 18:05:35 +080072static inline void icmpv6_ndo_send(struct sk_buff *skb,
73 u8 type, u8 code, __u32 info)
74{
75}
Jason A. Donenfeld0b417132020-02-11 20:47:05 +010076#endif
77
Denis V. Lunev9b0f9762008-02-29 11:13:15 -080078extern int icmpv6_init(void);
Brian Haleyd5fdd6b2009-06-23 04:31:07 -070079extern int icmpv6_err_convert(u8 type, u8 code,
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 int *err);
81extern void icmpv6_cleanup(void);
82extern void icmpv6_param_prob(struct sk_buff *skb,
Brian Haleyd5fdd6b2009-06-23 04:31:07 -070083 u8 code, int pos);
YOSHIFUJI Hideaki95e41e92007-12-06 15:43:30 -080084
David S. Miller4c9483b2011-03-12 16:22:43 -050085struct flowi6;
David S. Millerf59d4382008-03-05 20:58:10 -080086struct in6_addr;
YOSHIFUJI Hideaki95e41e92007-12-06 15:43:30 -080087extern void icmpv6_flow_init(struct sock *sk,
David S. Miller4c9483b2011-03-12 16:22:43 -050088 struct flowi6 *fl6,
YOSHIFUJI Hideaki95e41e92007-12-06 15:43:30 -080089 u8 type,
90 const struct in6_addr *saddr,
91 const struct in6_addr *daddr,
92 int oif);
Matteo Croce15122462019-11-02 01:12:03 +010093
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107#endif