mroute.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LINUX_MROUTE_H
  3. #define __LINUX_MROUTE_H
  4. #include <linux/in.h>
  5. #include <linux/pim.h>
  6. #include <net/fib_rules.h>
  7. #include <net/fib_notifier.h>
  8. #include <uapi/linux/mroute.h>
  9. #include <linux/mroute_base.h>
  10. #ifdef CONFIG_IP_MROUTE
  11. static inline int ip_mroute_opt(int opt)
  12. {
  13. return opt >= MRT_BASE && opt <= MRT_MAX;
  14. }
  15. int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int);
  16. int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
  17. int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
  18. int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
  19. int ip_mr_init(void);
  20. bool ipmr_rule_default(const struct fib_rule *rule);
  21. #else
  22. static inline int ip_mroute_setsockopt(struct sock *sock, int optname,
  23. char __user *optval, unsigned int optlen)
  24. {
  25. return -ENOPROTOOPT;
  26. }
  27. static inline int ip_mroute_getsockopt(struct sock *sock, int optname,
  28. char __user *optval, int __user *optlen)
  29. {
  30. return -ENOPROTOOPT;
  31. }
  32. static inline int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
  33. {
  34. return -ENOIOCTLCMD;
  35. }
  36. static inline int ip_mr_init(void)
  37. {
  38. return 0;
  39. }
  40. static inline int ip_mroute_opt(int opt)
  41. {
  42. return 0;
  43. }
  44. static inline bool ipmr_rule_default(const struct fib_rule *rule)
  45. {
  46. return true;
  47. }
  48. #endif
  49. #define VIFF_STATIC 0x8000
  50. struct mfc_cache_cmp_arg {
  51. __be32 mfc_mcastgrp;
  52. __be32 mfc_origin;
  53. };
  54. /**
  55. * struct mfc_cache - multicast routing entries
  56. * @_c: Common multicast routing information; has to be first [for casting]
  57. * @mfc_mcastgrp: destination multicast group address
  58. * @mfc_origin: source address
  59. * @cmparg: used for rhashtable comparisons
  60. */
  61. struct mfc_cache {
  62. struct mr_mfc _c;
  63. union {
  64. struct {
  65. __be32 mfc_mcastgrp;
  66. __be32 mfc_origin;
  67. };
  68. struct mfc_cache_cmp_arg cmparg;
  69. };
  70. };
  71. struct mfc_entry_notifier_info {
  72. struct fib_notifier_info info;
  73. struct mfc_cache *mfc;
  74. u32 tb_id;
  75. };
  76. struct rtmsg;
  77. int ipmr_get_route(struct net *net, struct sk_buff *skb,
  78. __be32 saddr, __be32 daddr,
  79. struct rtmsg *rtm, u32 portid);
  80. #ifdef CONFIG_IP_MROUTE
  81. void ipmr_cache_free(struct mfc_cache *mfc_cache);
  82. #else
  83. static inline void ipmr_cache_free(struct mfc_cache *mfc_cache)
  84. {
  85. }
  86. #endif
  87. static inline void ipmr_cache_put(struct mfc_cache *c)
  88. {
  89. if (refcount_dec_and_test(&c->_c.mfc_un.res.refcount))
  90. ipmr_cache_free(c);
  91. }
  92. static inline void ipmr_cache_hold(struct mfc_cache *c)
  93. {
  94. refcount_inc(&c->_c.mfc_un.res.refcount);
  95. }
  96. #endif