xref: /openbmc/linux/include/linux/icmpv6.h (revision 5bc67a85)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds #ifndef _LINUX_ICMPV6_H
31da177e4SLinus Torvalds #define _LINUX_ICMPV6_H
41da177e4SLinus Torvalds 
5cc70ab26SArnaldo Carvalho de Melo #include <linux/skbuff.h>
6ee576c47SJason A. Donenfeld #include <linux/ipv6.h>
7607ca46eSDavid Howells #include <uapi/linux/icmpv6.h>
8cc70ab26SArnaldo Carvalho de Melo 
icmp6_hdr(const struct sk_buff * skb)9cc70ab26SArnaldo Carvalho de Melo static inline struct icmp6hdr *icmp6_hdr(const struct sk_buff *skb)
10cc70ab26SArnaldo Carvalho de Melo {
119c70220bSArnaldo Carvalho de Melo 	return (struct icmp6hdr *)skb_transport_header(skb);
12cc70ab26SArnaldo Carvalho de Melo }
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds #include <linux/netdevice.h>
151da177e4SLinus Torvalds 
165f5624cfSPravin B Shelar #if IS_ENABLED(CONFIG_IPV6)
175f5624cfSPravin B Shelar 
18b1cadc1aSEric Dumazet typedef void ip6_icmp_send_t(struct sk_buff *skb, u8 type, u8 code, __u32 info,
19ee576c47SJason A. Donenfeld 			     const struct in6_addr *force_saddr,
20ee576c47SJason A. Donenfeld 			     const struct inet6_skb_parm *parm);
21cc7a21b6SEric Dumazet void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
22ee576c47SJason A. Donenfeld 		const struct in6_addr *force_saddr,
23ee576c47SJason A. Donenfeld 		const struct inet6_skb_parm *parm);
241faba27fSLeon Romanovsky #if IS_BUILTIN(CONFIG_IPV6)
__icmpv6_send(struct sk_buff * skb,u8 type,u8 code,__u32 info,const struct inet6_skb_parm * parm)25ee576c47SJason A. Donenfeld static inline void __icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
26ee576c47SJason A. Donenfeld 				 const struct inet6_skb_parm *parm)
27cc7a21b6SEric Dumazet {
28ee576c47SJason A. Donenfeld 	icmp6_send(skb, type, code, info, NULL, parm);
29cc7a21b6SEric Dumazet }
inet6_register_icmp_sender(ip6_icmp_send_t * fn)30cc7a21b6SEric Dumazet static inline int inet6_register_icmp_sender(ip6_icmp_send_t *fn)
31cc7a21b6SEric Dumazet {
32cc7a21b6SEric Dumazet 	BUILD_BUG_ON(fn != icmp6_send);
33cc7a21b6SEric Dumazet 	return 0;
34cc7a21b6SEric Dumazet }
inet6_unregister_icmp_sender(ip6_icmp_send_t * fn)35cc7a21b6SEric Dumazet static inline int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn)
36cc7a21b6SEric Dumazet {
37cc7a21b6SEric Dumazet 	BUILD_BUG_ON(fn != icmp6_send);
38cc7a21b6SEric Dumazet 	return 0;
39cc7a21b6SEric Dumazet }
40cc7a21b6SEric Dumazet #else
41ee576c47SJason A. Donenfeld extern void __icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
42ee576c47SJason A. Donenfeld 			  const struct inet6_skb_parm *parm);
435f5624cfSPravin B Shelar extern int inet6_register_icmp_sender(ip6_icmp_send_t *fn);
445f5624cfSPravin B Shelar extern int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn);
45cc7a21b6SEric Dumazet #endif
46cc7a21b6SEric Dumazet 
icmpv6_send(struct sk_buff * skb,u8 type,u8 code,__u32 info)47ee576c47SJason A. Donenfeld static inline void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info)
48ee576c47SJason A. Donenfeld {
49ee576c47SJason A. Donenfeld 	__icmpv6_send(skb, type, code, info, IP6CB(skb));
50ee576c47SJason A. Donenfeld }
51ee576c47SJason A. Donenfeld 
5220e1954fSEric Dumazet int ip6_err_gen_icmpv6_unreach(struct sk_buff *skb, int nhs, int type,
5320e1954fSEric Dumazet 			       unsigned int data_len);
545f5624cfSPravin B Shelar 
55a8e41f60SJason A. Donenfeld #if IS_ENABLED(CONFIG_NF_NAT)
56a8e41f60SJason A. Donenfeld void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info);
57a8e41f60SJason A. Donenfeld #else
icmpv6_ndo_send(struct sk_buff * skb_in,u8 type,u8 code,__u32 info)58ee576c47SJason A. Donenfeld static inline void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info)
59ee576c47SJason A. Donenfeld {
60ee576c47SJason A. Donenfeld 	struct inet6_skb_parm parm = { 0 };
61ee576c47SJason A. Donenfeld 	__icmpv6_send(skb_in, type, code, info, &parm);
62ee576c47SJason A. Donenfeld }
63a8e41f60SJason A. Donenfeld #endif
64a8e41f60SJason A. Donenfeld 
655f5624cfSPravin B Shelar #else
665f5624cfSPravin B Shelar 
icmpv6_send(struct sk_buff * skb,u8 type,u8 code,__u32 info)675f5624cfSPravin B Shelar static inline void icmpv6_send(struct sk_buff *skb,
685f5624cfSPravin B Shelar 			       u8 type, u8 code, __u32 info)
695f5624cfSPravin B Shelar {
705f5624cfSPravin B Shelar }
711da177e4SLinus Torvalds 
icmpv6_ndo_send(struct sk_buff * skb,u8 type,u8 code,__u32 info)72a8e41f60SJason A. Donenfeld static inline void icmpv6_ndo_send(struct sk_buff *skb,
73a8e41f60SJason A. Donenfeld 				   u8 type, u8 code, __u32 info)
74a8e41f60SJason A. Donenfeld {
75a8e41f60SJason A. Donenfeld }
760b41713bSJason A. Donenfeld #endif
770b41713bSJason A. Donenfeld 
789b0f976fSDenis V. Lunev extern int				icmpv6_init(void);
79d5fdd6baSBrian Haley extern int				icmpv6_err_convert(u8 type, u8 code,
801da177e4SLinus Torvalds 							   int *err);
811da177e4SLinus Torvalds extern void				icmpv6_cleanup(void);
821ad6d548SMenglong Dong extern void				icmpv6_param_prob_reason(struct sk_buff *skb,
831ad6d548SMenglong Dong 								 u8 code, int pos,
841ad6d548SMenglong Dong 								 enum skb_drop_reason reason);
8595e41e93SYOSHIFUJI Hideaki 
864c9483b2SDavid S. Miller struct flowi6;
87f59d4389SDavid S. Miller struct in6_addr;
88*5bc67a85SGuillaume Nault 
89*5bc67a85SGuillaume Nault void icmpv6_flow_init(const struct sock *sk, struct flowi6 *fl6, u8 type,
9095e41e93SYOSHIFUJI Hideaki 		      const struct in6_addr *saddr,
91*5bc67a85SGuillaume Nault 		      const struct in6_addr *daddr, int oif);
9215122464SMatteo Croce 
icmpv6_param_prob(struct sk_buff * skb,u8 code,int pos)931ad6d548SMenglong Dong static inline void icmpv6_param_prob(struct sk_buff *skb, u8 code, int pos)
941ad6d548SMenglong Dong {
951ad6d548SMenglong Dong 	icmpv6_param_prob_reason(skb, code, pos,
961ad6d548SMenglong Dong 				 SKB_DROP_REASON_NOT_SPECIFIED);
971ad6d548SMenglong Dong }
981ad6d548SMenglong Dong 
icmpv6_is_err(int type)9915122464SMatteo Croce static inline bool icmpv6_is_err(int type)
10015122464SMatteo Croce {
10115122464SMatteo Croce 	switch (type) {
10215122464SMatteo Croce 	case ICMPV6_DEST_UNREACH:
10315122464SMatteo Croce 	case ICMPV6_PKT_TOOBIG:
10415122464SMatteo Croce 	case ICMPV6_TIME_EXCEED:
10515122464SMatteo Croce 	case ICMPV6_PARAMPROB:
10615122464SMatteo Croce 		return true;
10715122464SMatteo Croce 	}
10815122464SMatteo Croce 
10915122464SMatteo Croce 	return false;
11015122464SMatteo Croce }
11115122464SMatteo Croce 
1121da177e4SLinus Torvalds #endif
113