icmpv6.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_ICMPV6_H
  3. #define _LINUX_ICMPV6_H
  4. #include <linux/skbuff.h>
  5. #include <linux/ipv6.h>
  6. #include <uapi/linux/icmpv6.h>
  7. static inline struct icmp6hdr *icmp6_hdr(const struct sk_buff *skb)
  8. {
  9. return (struct icmp6hdr *)skb_transport_header(skb);
  10. }
  11. #include <linux/netdevice.h>
  12. #if IS_ENABLED(CONFIG_IPV6)
  13. typedef void ip6_icmp_send_t(struct sk_buff *skb, u8 type, u8 code, __u32 info,
  14. const struct in6_addr *force_saddr,
  15. const struct inet6_skb_parm *parm);
  16. void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
  17. const struct in6_addr *force_saddr,
  18. const struct inet6_skb_parm *parm);
  19. #if IS_BUILTIN(CONFIG_IPV6)
  20. static inline void __icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
  21. const struct inet6_skb_parm *parm)
  22. {
  23. icmp6_send(skb, type, code, info, NULL, parm);
  24. }
  25. static inline int inet6_register_icmp_sender(ip6_icmp_send_t *fn)
  26. {
  27. BUILD_BUG_ON(fn != icmp6_send);
  28. return 0;
  29. }
  30. static inline int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn)
  31. {
  32. BUILD_BUG_ON(fn != icmp6_send);
  33. return 0;
  34. }
  35. #else
  36. extern void __icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
  37. const struct inet6_skb_parm *parm);
  38. extern int inet6_register_icmp_sender(ip6_icmp_send_t *fn);
  39. extern int inet6_unregister_icmp_sender(ip6_icmp_send_t *fn);
  40. #endif
  41. static inline void icmpv6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info)
  42. {
  43. __icmpv6_send(skb, type, code, info, IP6CB(skb));
  44. }
  45. int ip6_err_gen_icmpv6_unreach(struct sk_buff *skb, int nhs, int type,
  46. unsigned int data_len);
  47. #if IS_ENABLED(CONFIG_NF_NAT)
  48. void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info);
  49. #else
  50. static inline void icmpv6_ndo_send(struct sk_buff *skb_in, u8 type, u8 code, __u32 info)
  51. {
  52. struct inet6_skb_parm parm = { 0 };
  53. __icmpv6_send(skb_in, type, code, info, &parm);
  54. }
  55. #endif
  56. #else
  57. static inline void icmpv6_send(struct sk_buff *skb,
  58. u8 type, u8 code, __u32 info)
  59. {
  60. }
  61. static inline void icmpv6_ndo_send(struct sk_buff *skb,
  62. u8 type, u8 code, __u32 info)
  63. {
  64. }
  65. #endif
  66. extern int icmpv6_init(void);
  67. extern int icmpv6_err_convert(u8 type, u8 code,
  68. int *err);
  69. extern void icmpv6_cleanup(void);
  70. extern void icmpv6_param_prob(struct sk_buff *skb,
  71. u8 code, int pos);
  72. struct flowi6;
  73. struct in6_addr;
  74. extern void icmpv6_flow_init(struct sock *sk,
  75. struct flowi6 *fl6,
  76. u8 type,
  77. const struct in6_addr *saddr,
  78. const struct in6_addr *daddr,
  79. int oif);
  80. static inline bool icmpv6_is_err(int type)
  81. {
  82. switch (type) {
  83. case ICMPV6_DEST_UNREACH:
  84. case ICMPV6_PKT_TOOBIG:
  85. case ICMPV6_TIME_EXCEED:
  86. case ICMPV6_PARAMPROB:
  87. return true;
  88. }
  89. return false;
  90. }
  91. #endif