mroute.h 4.6 KB

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