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