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> 6607ca46eSDavid Howells #include <uapi/linux/icmpv6.h> 7cc70ab26SArnaldo Carvalho de Melo 8cc70ab26SArnaldo Carvalho de Melo static inline struct icmp6hdr *icmp6_hdr(const struct sk_buff *skb) 9cc70ab26SArnaldo Carvalho de Melo { 109c70220bSArnaldo Carvalho de Melo return (struct icmp6hdr *)skb_transport_header(skb); 11cc70ab26SArnaldo Carvalho de Melo } 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds #include <linux/netdevice.h> 141da177e4SLinus Torvalds 155f5624cfSPravin B Shelar #if IS_ENABLED(CONFIG_IPV6) 165f5624cfSPravin B Shelar 17b1cadc1aSEric Dumazet typedef void ip6_icmp_send_t(struct sk_buff *skb, u8 type, u8 code, __u32 info, 18b1cadc1aSEric Dumazet const struct in6_addr *force_saddr); 19*cc7a21b6SEric Dumazet #if IS_BUILTIN(CONFIG_IPV6) 20*cc7a21b6SEric Dumazet void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, 21*cc7a21b6SEric Dumazet const struct in6_addr *force_saddr); 22*cc7a21b6SEric Dumazet static inline void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info) 23*cc7a21b6SEric Dumazet { 24*cc7a21b6SEric Dumazet icmp6_send(skb, type, code, info, NULL); 25*cc7a21b6SEric Dumazet } 26*cc7a21b6SEric Dumazet static inline int inet6_register_icmp_sender(ip6_icmp_send_t *fn) 27*cc7a21b6SEric Dumazet { 28*cc7a21b6SEric Dumazet BUILD_BUG_ON(fn != icmp6_send); 29*cc7a21b6SEric Dumazet return 0; 30*cc7a21b6SEric Dumazet } 31*cc7a21b6SEric Dumazet static inline int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn) 32*cc7a21b6SEric Dumazet { 33*cc7a21b6SEric Dumazet BUILD_BUG_ON(fn != icmp6_send); 34*cc7a21b6SEric Dumazet return 0; 35*cc7a21b6SEric Dumazet } 36*cc7a21b6SEric Dumazet #else 37*cc7a21b6SEric Dumazet extern void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info); 385f5624cfSPravin B Shelar extern int inet6_register_icmp_sender(ip6_icmp_send_t *fn); 395f5624cfSPravin B Shelar extern int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn); 40*cc7a21b6SEric Dumazet #endif 41*cc7a21b6SEric Dumazet 4220e1954fSEric Dumazet int ip6_err_gen_icmpv6_unreach(struct sk_buff *skb, int nhs, int type, 4320e1954fSEric Dumazet unsigned int data_len); 445f5624cfSPravin B Shelar 45a8e41f60SJason A. Donenfeld #if IS_ENABLED(CONFIG_NF_NAT) 46a8e41f60SJason A. Donenfeld void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info); 47a8e41f60SJason A. Donenfeld #else 48a8e41f60SJason A. Donenfeld #define icmpv6_ndo_send icmpv6_send 49a8e41f60SJason A. Donenfeld #endif 50a8e41f60SJason A. Donenfeld 515f5624cfSPravin B Shelar #else 525f5624cfSPravin B Shelar 535f5624cfSPravin B Shelar static inline void icmpv6_send(struct sk_buff *skb, 545f5624cfSPravin B Shelar u8 type, u8 code, __u32 info) 555f5624cfSPravin B Shelar { 565f5624cfSPravin B Shelar } 571da177e4SLinus Torvalds 58a8e41f60SJason A. Donenfeld static inline void icmpv6_ndo_send(struct sk_buff *skb, 59a8e41f60SJason A. Donenfeld u8 type, u8 code, __u32 info) 60a8e41f60SJason A. Donenfeld { 61a8e41f60SJason A. Donenfeld } 620b41713bSJason A. Donenfeld #endif 630b41713bSJason A. Donenfeld 649b0f976fSDenis V. Lunev extern int icmpv6_init(void); 65d5fdd6baSBrian Haley extern int icmpv6_err_convert(u8 type, u8 code, 661da177e4SLinus Torvalds int *err); 671da177e4SLinus Torvalds extern void icmpv6_cleanup(void); 681da177e4SLinus Torvalds extern void icmpv6_param_prob(struct sk_buff *skb, 69d5fdd6baSBrian Haley u8 code, int pos); 7095e41e93SYOSHIFUJI Hideaki 714c9483b2SDavid S. Miller struct flowi6; 72f59d4389SDavid S. Miller struct in6_addr; 7395e41e93SYOSHIFUJI Hideaki extern void icmpv6_flow_init(struct sock *sk, 744c9483b2SDavid S. Miller struct flowi6 *fl6, 7595e41e93SYOSHIFUJI Hideaki u8 type, 7695e41e93SYOSHIFUJI Hideaki const struct in6_addr *saddr, 7795e41e93SYOSHIFUJI Hideaki const struct in6_addr *daddr, 7895e41e93SYOSHIFUJI Hideaki int oif); 7915122464SMatteo Croce 8015122464SMatteo Croce static inline bool icmpv6_is_err(int type) 8115122464SMatteo Croce { 8215122464SMatteo Croce switch (type) { 8315122464SMatteo Croce case ICMPV6_DEST_UNREACH: 8415122464SMatteo Croce case ICMPV6_PKT_TOOBIG: 8515122464SMatteo Croce case ICMPV6_TIME_EXCEED: 8615122464SMatteo Croce case ICMPV6_PARAMPROB: 8715122464SMatteo Croce return true; 8815122464SMatteo Croce } 8915122464SMatteo Croce 9015122464SMatteo Croce return false; 9115122464SMatteo Croce } 9215122464SMatteo Croce 931da177e4SLinus Torvalds #endif 94