mroute.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #ifndef __LINUX_MROUTE_H
  2. #define __LINUX_MROUTE_H
  3. #include <linux/in.h>
  4. #include <linux/pim.h>
  5. #include <linux/rhashtable.h>
  6. #include <net/sock.h>
  7. #include <net/fib_rules.h>
  8. #include <net/fib_notifier.h>
  9. #include <uapi/linux/mroute.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. struct vif_device {
  50. struct net_device *dev; /* Device we are using */
  51. struct netdev_phys_item_id dev_parent_id; /* Device parent ID */
  52. unsigned long bytes_in,bytes_out;
  53. unsigned long pkt_in,pkt_out; /* Statistics */
  54. unsigned long rate_limit; /* Traffic shaping (NI) */
  55. unsigned char threshold; /* TTL threshold */
  56. unsigned short flags; /* Control flags */
  57. __be32 local,remote; /* Addresses(remote for tunnels)*/
  58. int link; /* Physical interface index */
  59. };
  60. struct vif_entry_notifier_info {
  61. struct fib_notifier_info info;
  62. struct net_device *dev;
  63. vifi_t vif_index;
  64. unsigned short vif_flags;
  65. u32 tb_id;
  66. };
  67. #define VIFF_STATIC 0x8000
  68. #define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL)
  69. struct mr_table {
  70. struct list_head list;
  71. possible_net_t net;
  72. u32 id;
  73. struct sock __rcu *mroute_sk;
  74. struct timer_list ipmr_expire_timer;
  75. struct list_head mfc_unres_queue;
  76. struct vif_device vif_table[MAXVIFS];
  77. struct rhltable mfc_hash;
  78. struct list_head mfc_cache_list;
  79. int maxvif;
  80. atomic_t cache_resolve_queue_len;
  81. bool mroute_do_assert;
  82. bool mroute_do_pim;
  83. int mroute_reg_vif_num;
  84. };
  85. /* mfc_flags:
  86. * MFC_STATIC - the entry was added statically (not by a routing daemon)
  87. * MFC_OFFLOAD - the entry was offloaded to the hardware
  88. */
  89. enum {
  90. MFC_STATIC = BIT(0),
  91. MFC_OFFLOAD = BIT(1),
  92. };
  93. struct mfc_cache_cmp_arg {
  94. __be32 mfc_mcastgrp;
  95. __be32 mfc_origin;
  96. };
  97. /**
  98. * struct mfc_cache - multicast routing entries
  99. * @mnode: rhashtable list
  100. * @mfc_mcastgrp: destination multicast group address
  101. * @mfc_origin: source address
  102. * @cmparg: used for rhashtable comparisons
  103. * @mfc_parent: source interface (iif)
  104. * @mfc_flags: entry flags
  105. * @expires: unresolved entry expire time
  106. * @unresolved: unresolved cached skbs
  107. * @last_assert: time of last assert
  108. * @minvif: minimum VIF id
  109. * @maxvif: maximum VIF id
  110. * @bytes: bytes that have passed for this entry
  111. * @pkt: packets that have passed for this entry
  112. * @wrong_if: number of wrong source interface hits
  113. * @lastuse: time of last use of the group (traffic or update)
  114. * @ttls: OIF TTL threshold array
  115. * @refcount: reference count for this entry
  116. * @list: global entry list
  117. * @rcu: used for entry destruction
  118. */
  119. struct mfc_cache {
  120. struct rhlist_head mnode;
  121. union {
  122. struct {
  123. __be32 mfc_mcastgrp;
  124. __be32 mfc_origin;
  125. };
  126. struct mfc_cache_cmp_arg cmparg;
  127. };
  128. vifi_t mfc_parent;
  129. int mfc_flags;
  130. union {
  131. struct {
  132. unsigned long expires;
  133. struct sk_buff_head unresolved;
  134. } unres;
  135. struct {
  136. unsigned long last_assert;
  137. int minvif;
  138. int maxvif;
  139. unsigned long bytes;
  140. unsigned long pkt;
  141. unsigned long wrong_if;
  142. unsigned long lastuse;
  143. unsigned char ttls[MAXVIFS];
  144. refcount_t refcount;
  145. } res;
  146. } mfc_un;
  147. struct list_head list;
  148. struct rcu_head rcu;
  149. };
  150. struct mfc_entry_notifier_info {
  151. struct fib_notifier_info info;
  152. struct mfc_cache *mfc;
  153. u32 tb_id;
  154. };
  155. struct rtmsg;
  156. int ipmr_get_route(struct net *net, struct sk_buff *skb,
  157. __be32 saddr, __be32 daddr,
  158. struct rtmsg *rtm, u32 portid);
  159. #ifdef CONFIG_IP_MROUTE
  160. void ipmr_cache_free(struct mfc_cache *mfc_cache);
  161. #else
  162. static inline void ipmr_cache_free(struct mfc_cache *mfc_cache)
  163. {
  164. }
  165. #endif
  166. static inline void ipmr_cache_put(struct mfc_cache *c)
  167. {
  168. if (refcount_dec_and_test(&c->mfc_un.res.refcount))
  169. ipmr_cache_free(c);
  170. }
  171. static inline void ipmr_cache_hold(struct mfc_cache *c)
  172. {
  173. refcount_inc(&c->mfc_un.res.refcount);
  174. }
  175. #endif