1 #ifndef __LINUX_MROUTE_H 2 #define __LINUX_MROUTE_H 3 4 #include <linux/in.h> 5 #include <linux/pim.h> 6 #include <linux/rhashtable.h> 7 #include <net/sock.h> 8 #include <net/fib_rules.h> 9 #include <net/fib_notifier.h> 10 #include <uapi/linux/mroute.h> 11 12 #ifdef CONFIG_IP_MROUTE 13 static inline int ip_mroute_opt(int opt) 14 { 15 return opt >= MRT_BASE && opt <= MRT_MAX; 16 } 17 18 int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int); 19 int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *); 20 int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg); 21 int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg); 22 int ip_mr_init(void); 23 bool ipmr_rule_default(const struct fib_rule *rule); 24 #else 25 static inline int ip_mroute_setsockopt(struct sock *sock, int optname, 26 char __user *optval, unsigned int optlen) 27 { 28 return -ENOPROTOOPT; 29 } 30 31 static inline int ip_mroute_getsockopt(struct sock *sock, int optname, 32 char __user *optval, int __user *optlen) 33 { 34 return -ENOPROTOOPT; 35 } 36 37 static inline int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg) 38 { 39 return -ENOIOCTLCMD; 40 } 41 42 static inline int ip_mr_init(void) 43 { 44 return 0; 45 } 46 47 static inline int ip_mroute_opt(int opt) 48 { 49 return 0; 50 } 51 52 static inline bool ipmr_rule_default(const struct fib_rule *rule) 53 { 54 return true; 55 } 56 #endif 57 58 struct vif_device { 59 struct net_device *dev; /* Device we are using */ 60 struct netdev_phys_item_id dev_parent_id; /* Device parent ID */ 61 unsigned long bytes_in,bytes_out; 62 unsigned long pkt_in,pkt_out; /* Statistics */ 63 unsigned long rate_limit; /* Traffic shaping (NI) */ 64 unsigned char threshold; /* TTL threshold */ 65 unsigned short flags; /* Control flags */ 66 __be32 local,remote; /* Addresses(remote for tunnels)*/ 67 int link; /* Physical interface index */ 68 }; 69 70 struct vif_entry_notifier_info { 71 struct fib_notifier_info info; 72 struct net_device *dev; 73 vifi_t vif_index; 74 unsigned short vif_flags; 75 u32 tb_id; 76 }; 77 78 #define VIFF_STATIC 0x8000 79 80 #define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL) 81 82 struct mr_table { 83 struct list_head list; 84 possible_net_t net; 85 u32 id; 86 struct sock __rcu *mroute_sk; 87 struct timer_list ipmr_expire_timer; 88 struct list_head mfc_unres_queue; 89 struct vif_device vif_table[MAXVIFS]; 90 struct rhltable mfc_hash; 91 struct list_head mfc_cache_list; 92 int maxvif; 93 atomic_t cache_resolve_queue_len; 94 bool mroute_do_assert; 95 bool mroute_do_pim; 96 int mroute_reg_vif_num; 97 }; 98 99 /* mfc_flags: 100 * MFC_STATIC - the entry was added statically (not by a routing daemon) 101 * MFC_OFFLOAD - the entry was offloaded to the hardware 102 */ 103 enum { 104 MFC_STATIC = BIT(0), 105 MFC_OFFLOAD = BIT(1), 106 }; 107 108 struct mfc_cache_cmp_arg { 109 __be32 mfc_mcastgrp; 110 __be32 mfc_origin; 111 }; 112 113 /** 114 * struct mfc_cache - multicast routing entries 115 * @mnode: rhashtable list 116 * @mfc_mcastgrp: destination multicast group address 117 * @mfc_origin: source address 118 * @cmparg: used for rhashtable comparisons 119 * @mfc_parent: source interface (iif) 120 * @mfc_flags: entry flags 121 * @expires: unresolved entry expire time 122 * @unresolved: unresolved cached skbs 123 * @last_assert: time of last assert 124 * @minvif: minimum VIF id 125 * @maxvif: maximum VIF id 126 * @bytes: bytes that have passed for this entry 127 * @pkt: packets that have passed for this entry 128 * @wrong_if: number of wrong source interface hits 129 * @lastuse: time of last use of the group (traffic or update) 130 * @ttls: OIF TTL threshold array 131 * @refcount: reference count for this entry 132 * @list: global entry list 133 * @rcu: used for entry destruction 134 */ 135 struct mfc_cache { 136 struct rhlist_head mnode; 137 union { 138 struct { 139 __be32 mfc_mcastgrp; 140 __be32 mfc_origin; 141 }; 142 struct mfc_cache_cmp_arg cmparg; 143 }; 144 vifi_t mfc_parent; 145 int mfc_flags; 146 147 union { 148 struct { 149 unsigned long expires; 150 struct sk_buff_head unresolved; 151 } unres; 152 struct { 153 unsigned long last_assert; 154 int minvif; 155 int maxvif; 156 unsigned long bytes; 157 unsigned long pkt; 158 unsigned long wrong_if; 159 unsigned long lastuse; 160 unsigned char ttls[MAXVIFS]; 161 refcount_t refcount; 162 } res; 163 } mfc_un; 164 struct list_head list; 165 struct rcu_head rcu; 166 }; 167 168 struct mfc_entry_notifier_info { 169 struct fib_notifier_info info; 170 struct mfc_cache *mfc; 171 u32 tb_id; 172 }; 173 174 struct rtmsg; 175 int ipmr_get_route(struct net *net, struct sk_buff *skb, 176 __be32 saddr, __be32 daddr, 177 struct rtmsg *rtm, u32 portid); 178 179 #ifdef CONFIG_IP_MROUTE 180 void ipmr_cache_free(struct mfc_cache *mfc_cache); 181 #else 182 static inline void ipmr_cache_free(struct mfc_cache *mfc_cache) 183 { 184 } 185 #endif 186 187 static inline void ipmr_cache_put(struct mfc_cache *c) 188 { 189 if (refcount_dec_and_test(&c->mfc_un.res.refcount)) 190 ipmr_cache_free(c); 191 } 192 static inline void ipmr_cache_hold(struct mfc_cache *c) 193 { 194 refcount_inc(&c->mfc_un.res.refcount); 195 } 196 197 #endif 198