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