Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * IP multicast routing support for mrouted 3.6/3.8 |
| 3 | * |
Alan Cox | 113aa83 | 2008-10-13 19:01:08 -0700 | [diff] [blame] | 4 | * (c) 1995 Alan Cox, <alan@lxorguk.ukuu.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Linux Consultancy and Custom Driver Development |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * Fixes: |
| 13 | * Michael Chastain : Incorrect size of copying. |
| 14 | * Alan Cox : Added the cache manager code |
| 15 | * Alan Cox : Fixed the clone/copy bug and device race. |
| 16 | * Mike McLagan : Routing by source |
| 17 | * Malcolm Beattie : Buffer handling fixes. |
| 18 | * Alexey Kuznetsov : Double buffer free and other fixes. |
| 19 | * SVR Anand : Fixed several multicast bugs and problems. |
| 20 | * Alexey Kuznetsov : Status, optimisations and more. |
| 21 | * Brad Parker : Better behaviour on mrouted upcall |
| 22 | * overflow. |
| 23 | * Carlos Picoto : PIMv1 Support |
| 24 | * Pavlin Ivanov Radoslavov: PIMv2 Registers must checksum only PIM header |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 25 | * Relax this requirement to work with older peers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | * |
| 27 | */ |
| 28 | |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 29 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/types.h> |
Alexey Dobriyan | 08009a7 | 2018-02-24 21:20:33 +0300 | [diff] [blame] | 31 | #include <linux/cache.h> |
Randy Dunlap | 4fc268d | 2006-01-11 12:17:47 -0800 | [diff] [blame] | 32 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/mm.h> |
| 35 | #include <linux/kernel.h> |
| 36 | #include <linux/fcntl.h> |
| 37 | #include <linux/stat.h> |
| 38 | #include <linux/socket.h> |
| 39 | #include <linux/in.h> |
| 40 | #include <linux/inet.h> |
| 41 | #include <linux/netdevice.h> |
| 42 | #include <linux/inetdevice.h> |
| 43 | #include <linux/igmp.h> |
| 44 | #include <linux/proc_fs.h> |
| 45 | #include <linux/seq_file.h> |
| 46 | #include <linux/mroute.h> |
| 47 | #include <linux/init.h> |
Kris Katterjohn | 46f25df | 2006-01-05 16:35:42 -0800 | [diff] [blame] | 48 | #include <linux/if_ether.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 49 | #include <linux/slab.h> |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 50 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <net/ip.h> |
| 52 | #include <net/protocol.h> |
| 53 | #include <linux/skbuff.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 54 | #include <net/route.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #include <net/icmp.h> |
| 56 | #include <net/udp.h> |
| 57 | #include <net/raw.h> |
| 58 | #include <linux/notifier.h> |
| 59 | #include <linux/if_arp.h> |
| 60 | #include <linux/netfilter_ipv4.h> |
Eric W. Biederman | 709b46e | 2011-01-29 16:15:56 +0000 | [diff] [blame] | 61 | #include <linux/compat.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 62 | #include <linux/export.h> |
Pravin B Shelar | c544193 | 2013-03-25 14:49:35 +0000 | [diff] [blame] | 63 | #include <net/ip_tunnels.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #include <net/checksum.h> |
Arnaldo Carvalho de Melo | dc5fc57 | 2007-03-25 23:06:12 -0700 | [diff] [blame] | 65 | #include <net/netlink.h> |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 66 | #include <net/fib_rules.h> |
Nicolas Dichtel | d67b8c6 | 2012-12-04 01:13:35 +0000 | [diff] [blame] | 67 | #include <linux/netconf.h> |
Nikolay Aleksandrov | ccbb0aa | 2015-11-26 15:23:50 +0100 | [diff] [blame] | 68 | #include <net/nexthop.h> |
Yotam Gigi | 5d8b3e6 | 2017-10-03 09:58:07 +0200 | [diff] [blame] | 69 | #include <net/switchdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 71 | struct ipmr_rule { |
| 72 | struct fib_rule common; |
| 73 | }; |
| 74 | |
| 75 | struct ipmr_result { |
| 76 | struct mr_table *mrt; |
| 77 | }; |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | /* Big lock, protecting vif table, mrt cache and mroute socket state. |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 80 | * Note that the changes are semaphored via rtnl_lock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | */ |
| 82 | |
| 83 | static DEFINE_RWLOCK(mrt_lock); |
| 84 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 85 | /* Multicast router control variables */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | /* Special spinlock for queue of unresolved entries */ |
| 88 | static DEFINE_SPINLOCK(mfc_unres_lock); |
| 89 | |
| 90 | /* We return to original Alan's scheme. Hash table of resolved |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 91 | * entries is changed only in process context and protected |
| 92 | * with weak lock mrt_lock. Queue of unresolved entries is protected |
| 93 | * with strong spinlock mfc_unres_lock. |
| 94 | * |
| 95 | * In this case data path is free of exclusive locks at all. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | */ |
| 97 | |
Alexey Dobriyan | 08009a7 | 2018-02-24 21:20:33 +0300 | [diff] [blame] | 98 | static struct kmem_cache *mrt_cachep __ro_after_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 100 | static struct mr_table *ipmr_new_table(struct net *net, u32 id); |
Francesco Ruggeri | acbb219 | 2012-08-24 07:38:35 +0000 | [diff] [blame] | 101 | static void ipmr_free_table(struct mr_table *mrt); |
| 102 | |
Rami Rosen | c4854ec | 2013-07-20 15:09:28 +0300 | [diff] [blame] | 103 | static void ip_mr_forward(struct net *net, struct mr_table *mrt, |
Donald Sharp | 4b1f0d3 | 2017-06-10 16:30:17 -0400 | [diff] [blame] | 104 | struct net_device *dev, struct sk_buff *skb, |
| 105 | struct mfc_cache *cache, int local); |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 106 | static int ipmr_cache_report(struct mr_table *mrt, |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 107 | struct sk_buff *pkt, vifi_t vifi, int assert); |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 108 | static int __ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb, |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 109 | struct mr_mfc *c, struct rtmsg *rtm); |
Nicolas Dichtel | 8cd3ac9 | 2012-12-04 01:13:40 +0000 | [diff] [blame] | 110 | static void mroute_netlink_event(struct mr_table *mrt, struct mfc_cache *mfc, |
| 111 | int cmd); |
Julien Gomes | 5a645dd | 2017-06-20 13:54:17 -0700 | [diff] [blame] | 112 | static void igmpmsg_netlink_event(struct mr_table *mrt, struct sk_buff *pkt); |
Nikolay Aleksandrov | 0e615e9 | 2015-11-20 13:54:19 +0100 | [diff] [blame] | 113 | static void mroute_clean_tables(struct mr_table *mrt, bool all); |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 114 | static void ipmr_expire_process(struct timer_list *t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 116 | #ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES |
| 117 | #define ipmr_for_each_table(mrt, net) \ |
| 118 | list_for_each_entry_rcu(mrt, &net->ipv4.mr_tables, list) |
| 119 | |
| 120 | static struct mr_table *ipmr_get_table(struct net *net, u32 id) |
| 121 | { |
| 122 | struct mr_table *mrt; |
| 123 | |
| 124 | ipmr_for_each_table(mrt, net) { |
| 125 | if (mrt->id == id) |
| 126 | return mrt; |
| 127 | } |
| 128 | return NULL; |
| 129 | } |
| 130 | |
David S. Miller | da91981 | 2011-03-12 02:04:50 -0500 | [diff] [blame] | 131 | static int ipmr_fib_lookup(struct net *net, struct flowi4 *flp4, |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 132 | struct mr_table **mrt) |
| 133 | { |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 134 | int err; |
Hannes Frederic Sowa | 95f4a45 | 2014-01-13 02:45:22 +0100 | [diff] [blame] | 135 | struct ipmr_result res; |
| 136 | struct fib_lookup_arg arg = { |
| 137 | .result = &res, |
| 138 | .flags = FIB_LOOKUP_NOREF, |
| 139 | }; |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 140 | |
David Ahern | e58e415 | 2016-10-31 15:54:00 -0700 | [diff] [blame] | 141 | /* update flow if oif or iif point to device enslaved to l3mdev */ |
| 142 | l3mdev_update_flow(net, flowi4_to_flowi(flp4)); |
| 143 | |
David S. Miller | da91981 | 2011-03-12 02:04:50 -0500 | [diff] [blame] | 144 | err = fib_rules_lookup(net->ipv4.mr_rules_ops, |
| 145 | flowi4_to_flowi(flp4), 0, &arg); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 146 | if (err < 0) |
| 147 | return err; |
| 148 | *mrt = res.mrt; |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static int ipmr_rule_action(struct fib_rule *rule, struct flowi *flp, |
| 153 | int flags, struct fib_lookup_arg *arg) |
| 154 | { |
| 155 | struct ipmr_result *res = arg->result; |
| 156 | struct mr_table *mrt; |
| 157 | |
| 158 | switch (rule->action) { |
| 159 | case FR_ACT_TO_TBL: |
| 160 | break; |
| 161 | case FR_ACT_UNREACHABLE: |
| 162 | return -ENETUNREACH; |
| 163 | case FR_ACT_PROHIBIT: |
| 164 | return -EACCES; |
| 165 | case FR_ACT_BLACKHOLE: |
| 166 | default: |
| 167 | return -EINVAL; |
| 168 | } |
| 169 | |
David Ahern | e58e415 | 2016-10-31 15:54:00 -0700 | [diff] [blame] | 170 | arg->table = fib_rule_get_table(rule, arg); |
| 171 | |
| 172 | mrt = ipmr_get_table(rule->fr_net, arg->table); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 173 | if (!mrt) |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 174 | return -EAGAIN; |
| 175 | res->mrt = mrt; |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | static int ipmr_rule_match(struct fib_rule *rule, struct flowi *fl, int flags) |
| 180 | { |
| 181 | return 1; |
| 182 | } |
| 183 | |
| 184 | static const struct nla_policy ipmr_rule_policy[FRA_MAX + 1] = { |
| 185 | FRA_GENERIC_POLICY, |
| 186 | }; |
| 187 | |
| 188 | static int ipmr_rule_configure(struct fib_rule *rule, struct sk_buff *skb, |
| 189 | struct fib_rule_hdr *frh, struct nlattr **tb) |
| 190 | { |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | static int ipmr_rule_compare(struct fib_rule *rule, struct fib_rule_hdr *frh, |
| 195 | struct nlattr **tb) |
| 196 | { |
| 197 | return 1; |
| 198 | } |
| 199 | |
| 200 | static int ipmr_rule_fill(struct fib_rule *rule, struct sk_buff *skb, |
| 201 | struct fib_rule_hdr *frh) |
| 202 | { |
| 203 | frh->dst_len = 0; |
| 204 | frh->src_len = 0; |
| 205 | frh->tos = 0; |
| 206 | return 0; |
| 207 | } |
| 208 | |
Andi Kleen | 04a6f82 | 2012-10-04 17:12:11 -0700 | [diff] [blame] | 209 | static const struct fib_rules_ops __net_initconst ipmr_rules_ops_template = { |
Patrick McHardy | 25239ce | 2010-04-26 16:02:05 +0200 | [diff] [blame] | 210 | .family = RTNL_FAMILY_IPMR, |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 211 | .rule_size = sizeof(struct ipmr_rule), |
| 212 | .addr_size = sizeof(u32), |
| 213 | .action = ipmr_rule_action, |
| 214 | .match = ipmr_rule_match, |
| 215 | .configure = ipmr_rule_configure, |
| 216 | .compare = ipmr_rule_compare, |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 217 | .fill = ipmr_rule_fill, |
| 218 | .nlgroup = RTNLGRP_IPV4_RULE, |
| 219 | .policy = ipmr_rule_policy, |
| 220 | .owner = THIS_MODULE, |
| 221 | }; |
| 222 | |
| 223 | static int __net_init ipmr_rules_init(struct net *net) |
| 224 | { |
| 225 | struct fib_rules_ops *ops; |
| 226 | struct mr_table *mrt; |
| 227 | int err; |
| 228 | |
| 229 | ops = fib_rules_register(&ipmr_rules_ops_template, net); |
| 230 | if (IS_ERR(ops)) |
| 231 | return PTR_ERR(ops); |
| 232 | |
| 233 | INIT_LIST_HEAD(&net->ipv4.mr_tables); |
| 234 | |
| 235 | mrt = ipmr_new_table(net, RT_TABLE_DEFAULT); |
Nikolay Aleksandrov | 1113ebb | 2015-11-21 15:57:24 +0100 | [diff] [blame] | 236 | if (IS_ERR(mrt)) { |
| 237 | err = PTR_ERR(mrt); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 238 | goto err1; |
| 239 | } |
| 240 | |
| 241 | err = fib_default_rule_add(ops, 0x7fff, RT_TABLE_DEFAULT, 0); |
| 242 | if (err < 0) |
| 243 | goto err2; |
| 244 | |
| 245 | net->ipv4.mr_rules_ops = ops; |
| 246 | return 0; |
| 247 | |
| 248 | err2: |
WANG Cong | f243e5a | 2015-03-25 14:45:03 -0700 | [diff] [blame] | 249 | ipmr_free_table(mrt); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 250 | err1: |
| 251 | fib_rules_unregister(ops); |
| 252 | return err; |
| 253 | } |
| 254 | |
| 255 | static void __net_exit ipmr_rules_exit(struct net *net) |
| 256 | { |
| 257 | struct mr_table *mrt, *next; |
| 258 | |
WANG Cong | ed78530 | 2015-03-31 11:01:45 -0700 | [diff] [blame] | 259 | rtnl_lock(); |
Eric Dumazet | 035320d | 2010-06-06 23:48:40 +0000 | [diff] [blame] | 260 | list_for_each_entry_safe(mrt, next, &net->ipv4.mr_tables, list) { |
| 261 | list_del(&mrt->list); |
Francesco Ruggeri | acbb219 | 2012-08-24 07:38:35 +0000 | [diff] [blame] | 262 | ipmr_free_table(mrt); |
Eric Dumazet | 035320d | 2010-06-06 23:48:40 +0000 | [diff] [blame] | 263 | } |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 264 | fib_rules_unregister(net->ipv4.mr_rules_ops); |
WANG Cong | 419df12 | 2015-03-31 11:01:46 -0700 | [diff] [blame] | 265 | rtnl_unlock(); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 266 | } |
Yotam Gigi | 4d65b94 | 2017-09-27 08:23:13 +0200 | [diff] [blame] | 267 | |
| 268 | static int ipmr_rules_dump(struct net *net, struct notifier_block *nb) |
| 269 | { |
| 270 | return fib_rules_dump(net, nb, RTNL_FAMILY_IPMR); |
| 271 | } |
| 272 | |
| 273 | static unsigned int ipmr_rules_seq_read(struct net *net) |
| 274 | { |
| 275 | return fib_rules_seq_read(net, RTNL_FAMILY_IPMR); |
| 276 | } |
Yotam Gigi | 478e4c2 | 2017-09-27 08:23:16 +0200 | [diff] [blame] | 277 | |
| 278 | bool ipmr_rule_default(const struct fib_rule *rule) |
| 279 | { |
| 280 | return fib_rule_matchall(rule) && rule->table == RT_TABLE_DEFAULT; |
| 281 | } |
| 282 | EXPORT_SYMBOL(ipmr_rule_default); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 283 | #else |
| 284 | #define ipmr_for_each_table(mrt, net) \ |
| 285 | for (mrt = net->ipv4.mrt; mrt; mrt = NULL) |
| 286 | |
| 287 | static struct mr_table *ipmr_get_table(struct net *net, u32 id) |
| 288 | { |
| 289 | return net->ipv4.mrt; |
| 290 | } |
| 291 | |
David S. Miller | da91981 | 2011-03-12 02:04:50 -0500 | [diff] [blame] | 292 | static int ipmr_fib_lookup(struct net *net, struct flowi4 *flp4, |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 293 | struct mr_table **mrt) |
| 294 | { |
| 295 | *mrt = net->ipv4.mrt; |
| 296 | return 0; |
| 297 | } |
| 298 | |
| 299 | static int __net_init ipmr_rules_init(struct net *net) |
| 300 | { |
Nikolay Aleksandrov | 1113ebb | 2015-11-21 15:57:24 +0100 | [diff] [blame] | 301 | struct mr_table *mrt; |
| 302 | |
| 303 | mrt = ipmr_new_table(net, RT_TABLE_DEFAULT); |
| 304 | if (IS_ERR(mrt)) |
| 305 | return PTR_ERR(mrt); |
| 306 | net->ipv4.mrt = mrt; |
| 307 | return 0; |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | static void __net_exit ipmr_rules_exit(struct net *net) |
| 311 | { |
WANG Cong | ed78530 | 2015-03-31 11:01:45 -0700 | [diff] [blame] | 312 | rtnl_lock(); |
Francesco Ruggeri | acbb219 | 2012-08-24 07:38:35 +0000 | [diff] [blame] | 313 | ipmr_free_table(net->ipv4.mrt); |
WANG Cong | ed78530 | 2015-03-31 11:01:45 -0700 | [diff] [blame] | 314 | net->ipv4.mrt = NULL; |
| 315 | rtnl_unlock(); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 316 | } |
Yotam Gigi | 4d65b94 | 2017-09-27 08:23:13 +0200 | [diff] [blame] | 317 | |
| 318 | static int ipmr_rules_dump(struct net *net, struct notifier_block *nb) |
| 319 | { |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | static unsigned int ipmr_rules_seq_read(struct net *net) |
| 324 | { |
| 325 | return 0; |
| 326 | } |
Yotam Gigi | 478e4c2 | 2017-09-27 08:23:16 +0200 | [diff] [blame] | 327 | |
| 328 | bool ipmr_rule_default(const struct fib_rule *rule) |
| 329 | { |
| 330 | return true; |
| 331 | } |
| 332 | EXPORT_SYMBOL(ipmr_rule_default); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 333 | #endif |
| 334 | |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 335 | static inline int ipmr_hash_cmp(struct rhashtable_compare_arg *arg, |
| 336 | const void *ptr) |
| 337 | { |
| 338 | const struct mfc_cache_cmp_arg *cmparg = arg->key; |
| 339 | struct mfc_cache *c = (struct mfc_cache *)ptr; |
| 340 | |
| 341 | return cmparg->mfc_mcastgrp != c->mfc_mcastgrp || |
| 342 | cmparg->mfc_origin != c->mfc_origin; |
| 343 | } |
| 344 | |
| 345 | static const struct rhashtable_params ipmr_rht_params = { |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 346 | .head_offset = offsetof(struct mr_mfc, mnode), |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 347 | .key_offset = offsetof(struct mfc_cache, cmparg), |
| 348 | .key_len = sizeof(struct mfc_cache_cmp_arg), |
| 349 | .nelem_hint = 3, |
| 350 | .locks_mul = 1, |
| 351 | .obj_cmpfn = ipmr_hash_cmp, |
| 352 | .automatic_shrinking = true, |
| 353 | }; |
| 354 | |
Yuval Mintz | 0bbbf0e | 2018-02-28 23:29:33 +0200 | [diff] [blame] | 355 | static void ipmr_new_table_set(struct mr_table *mrt, |
| 356 | struct net *net) |
| 357 | { |
| 358 | #ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES |
| 359 | list_add_tail_rcu(&mrt->list, &net->ipv4.mr_tables); |
| 360 | #endif |
| 361 | } |
| 362 | |
Yuval Mintz | 845c9a7 | 2018-02-28 23:29:35 +0200 | [diff] [blame] | 363 | static struct mfc_cache_cmp_arg ipmr_mr_table_ops_cmparg_any = { |
| 364 | .mfc_mcastgrp = htonl(INADDR_ANY), |
| 365 | .mfc_origin = htonl(INADDR_ANY), |
| 366 | }; |
| 367 | |
| 368 | static struct mr_table_ops ipmr_mr_table_ops = { |
| 369 | .rht_params = &ipmr_rht_params, |
| 370 | .cmparg_any = &ipmr_mr_table_ops_cmparg_any, |
| 371 | }; |
| 372 | |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 373 | static struct mr_table *ipmr_new_table(struct net *net, u32 id) |
| 374 | { |
| 375 | struct mr_table *mrt; |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 376 | |
Nikolay Aleksandrov | 1113ebb | 2015-11-21 15:57:24 +0100 | [diff] [blame] | 377 | /* "pimreg%u" should not exceed 16 bytes (IFNAMSIZ) */ |
| 378 | if (id != RT_TABLE_DEFAULT && id >= 1000000000) |
| 379 | return ERR_PTR(-EINVAL); |
| 380 | |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 381 | mrt = ipmr_get_table(net, id); |
Ian Morris | 00db412 | 2015-04-03 09:17:27 +0100 | [diff] [blame] | 382 | if (mrt) |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 383 | return mrt; |
| 384 | |
Yuval Mintz | 845c9a7 | 2018-02-28 23:29:35 +0200 | [diff] [blame] | 385 | return mr_table_alloc(net, id, &ipmr_mr_table_ops, |
Yuval Mintz | 0bbbf0e | 2018-02-28 23:29:33 +0200 | [diff] [blame] | 386 | ipmr_expire_process, ipmr_new_table_set); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 387 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
Francesco Ruggeri | acbb219 | 2012-08-24 07:38:35 +0000 | [diff] [blame] | 389 | static void ipmr_free_table(struct mr_table *mrt) |
| 390 | { |
| 391 | del_timer_sync(&mrt->ipmr_expire_timer); |
Nikolay Aleksandrov | 0e615e9 | 2015-11-20 13:54:19 +0100 | [diff] [blame] | 392 | mroute_clean_tables(mrt, true); |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 393 | rhltable_destroy(&mrt->mfc_hash); |
Francesco Ruggeri | acbb219 | 2012-08-24 07:38:35 +0000 | [diff] [blame] | 394 | kfree(mrt); |
| 395 | } |
| 396 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | /* Service routines creating virtual interfaces: DVMRP tunnels and PIMREG */ |
| 398 | |
Wang Chen | d607032 | 2008-07-14 20:55:26 -0700 | [diff] [blame] | 399 | static void ipmr_del_tunnel(struct net_device *dev, struct vifctl *v) |
| 400 | { |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 401 | struct net *net = dev_net(dev); |
| 402 | |
Wang Chen | d607032 | 2008-07-14 20:55:26 -0700 | [diff] [blame] | 403 | dev_close(dev); |
| 404 | |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 405 | dev = __dev_get_by_name(net, "tunl0"); |
Wang Chen | d607032 | 2008-07-14 20:55:26 -0700 | [diff] [blame] | 406 | if (dev) { |
Stephen Hemminger | 5bc3eb7 | 2008-11-19 21:52:05 -0800 | [diff] [blame] | 407 | const struct net_device_ops *ops = dev->netdev_ops; |
Wang Chen | d607032 | 2008-07-14 20:55:26 -0700 | [diff] [blame] | 408 | struct ifreq ifr; |
Wang Chen | d607032 | 2008-07-14 20:55:26 -0700 | [diff] [blame] | 409 | struct ip_tunnel_parm p; |
| 410 | |
| 411 | memset(&p, 0, sizeof(p)); |
| 412 | p.iph.daddr = v->vifc_rmt_addr.s_addr; |
| 413 | p.iph.saddr = v->vifc_lcl_addr.s_addr; |
| 414 | p.iph.version = 4; |
| 415 | p.iph.ihl = 5; |
| 416 | p.iph.protocol = IPPROTO_IPIP; |
| 417 | sprintf(p.name, "dvmrp%d", v->vifc_vifi); |
| 418 | ifr.ifr_ifru.ifru_data = (__force void __user *)&p; |
| 419 | |
Stephen Hemminger | 5bc3eb7 | 2008-11-19 21:52:05 -0800 | [diff] [blame] | 420 | if (ops->ndo_do_ioctl) { |
| 421 | mm_segment_t oldfs = get_fs(); |
| 422 | |
| 423 | set_fs(KERNEL_DS); |
| 424 | ops->ndo_do_ioctl(dev, &ifr, SIOCDELTUNNEL); |
| 425 | set_fs(oldfs); |
| 426 | } |
Wang Chen | d607032 | 2008-07-14 20:55:26 -0700 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
Nikolay Aleksandrov | a0b4773 | 2015-11-21 15:57:32 +0100 | [diff] [blame] | 430 | /* Initialize ipmr pimreg/tunnel in_device */ |
| 431 | static bool ipmr_init_vif_indev(const struct net_device *dev) |
| 432 | { |
| 433 | struct in_device *in_dev; |
| 434 | |
| 435 | ASSERT_RTNL(); |
| 436 | |
| 437 | in_dev = __in_dev_get_rtnl(dev); |
| 438 | if (!in_dev) |
| 439 | return false; |
| 440 | ipv4_devconf_setall(in_dev); |
| 441 | neigh_parms_data_state_setall(in_dev->arp_parms); |
| 442 | IPV4_DEVCONF(in_dev->cnf, RP_FILTER) = 0; |
| 443 | |
| 444 | return true; |
| 445 | } |
| 446 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 447 | static struct net_device *ipmr_new_tunnel(struct net *net, struct vifctl *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { |
| 449 | struct net_device *dev; |
| 450 | |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 451 | dev = __dev_get_by_name(net, "tunl0"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
| 453 | if (dev) { |
Stephen Hemminger | 5bc3eb7 | 2008-11-19 21:52:05 -0800 | [diff] [blame] | 454 | const struct net_device_ops *ops = dev->netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | int err; |
| 456 | struct ifreq ifr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | struct ip_tunnel_parm p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
| 459 | memset(&p, 0, sizeof(p)); |
| 460 | p.iph.daddr = v->vifc_rmt_addr.s_addr; |
| 461 | p.iph.saddr = v->vifc_lcl_addr.s_addr; |
| 462 | p.iph.version = 4; |
| 463 | p.iph.ihl = 5; |
| 464 | p.iph.protocol = IPPROTO_IPIP; |
| 465 | sprintf(p.name, "dvmrp%d", v->vifc_vifi); |
Stephen Hemminger | ba93ef7 | 2008-01-21 17:28:59 -0800 | [diff] [blame] | 466 | ifr.ifr_ifru.ifru_data = (__force void __user *)&p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
Stephen Hemminger | 5bc3eb7 | 2008-11-19 21:52:05 -0800 | [diff] [blame] | 468 | if (ops->ndo_do_ioctl) { |
| 469 | mm_segment_t oldfs = get_fs(); |
| 470 | |
| 471 | set_fs(KERNEL_DS); |
| 472 | err = ops->ndo_do_ioctl(dev, &ifr, SIOCADDTUNNEL); |
| 473 | set_fs(oldfs); |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 474 | } else { |
Stephen Hemminger | 5bc3eb7 | 2008-11-19 21:52:05 -0800 | [diff] [blame] | 475 | err = -EOPNOTSUPP; |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 476 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | dev = NULL; |
| 478 | |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 479 | if (err == 0 && |
| 480 | (dev = __dev_get_by_name(net, p.name)) != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | dev->flags |= IFF_MULTICAST; |
Nikolay Aleksandrov | a0b4773 | 2015-11-21 15:57:32 +0100 | [diff] [blame] | 482 | if (!ipmr_init_vif_indev(dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | goto failure; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | if (dev_open(dev)) |
| 485 | goto failure; |
Wang Chen | 7dc00c8 | 2008-07-14 20:56:34 -0700 | [diff] [blame] | 486 | dev_hold(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | return dev; |
| 490 | |
| 491 | failure: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | unregister_netdevice(dev); |
| 493 | return NULL; |
| 494 | } |
| 495 | |
Nikolay Aleksandrov | c316c62 | 2015-11-21 15:57:26 +0100 | [diff] [blame] | 496 | #if defined(CONFIG_IP_PIMSM_V1) || defined(CONFIG_IP_PIMSM_V2) |
Stephen Hemminger | 6fef4c0 | 2009-08-31 19:50:41 +0000 | [diff] [blame] | 497 | static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | { |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 499 | struct net *net = dev_net(dev); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 500 | struct mr_table *mrt; |
David S. Miller | da91981 | 2011-03-12 02:04:50 -0500 | [diff] [blame] | 501 | struct flowi4 fl4 = { |
| 502 | .flowi4_oif = dev->ifindex, |
Cong Wang | 6a66271 | 2014-04-15 16:25:34 -0700 | [diff] [blame] | 503 | .flowi4_iif = skb->skb_iif ? : LOOPBACK_IFINDEX, |
David S. Miller | da91981 | 2011-03-12 02:04:50 -0500 | [diff] [blame] | 504 | .flowi4_mark = skb->mark, |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 505 | }; |
| 506 | int err; |
| 507 | |
David S. Miller | da91981 | 2011-03-12 02:04:50 -0500 | [diff] [blame] | 508 | err = ipmr_fib_lookup(net, &fl4, &mrt); |
Ben Greear | e40dbc5 | 2010-07-15 13:22:33 +0000 | [diff] [blame] | 509 | if (err < 0) { |
| 510 | kfree_skb(skb); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 511 | return err; |
Ben Greear | e40dbc5 | 2010-07-15 13:22:33 +0000 | [diff] [blame] | 512 | } |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | read_lock(&mrt_lock); |
Pavel Emelyanov | cf3677a | 2008-05-21 14:17:33 -0700 | [diff] [blame] | 515 | dev->stats.tx_bytes += skb->len; |
| 516 | dev->stats.tx_packets++; |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 517 | ipmr_cache_report(mrt, skb, mrt->mroute_reg_vif_num, IGMPMSG_WHOLEPKT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | read_unlock(&mrt_lock); |
| 519 | kfree_skb(skb); |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 520 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Nicolas Dichtel | ee9b959 | 2015-04-02 17:07:03 +0200 | [diff] [blame] | 523 | static int reg_vif_get_iflink(const struct net_device *dev) |
| 524 | { |
| 525 | return 0; |
| 526 | } |
| 527 | |
Stephen Hemminger | 007c383 | 2008-11-20 20:28:35 -0800 | [diff] [blame] | 528 | static const struct net_device_ops reg_vif_netdev_ops = { |
| 529 | .ndo_start_xmit = reg_vif_xmit, |
Nicolas Dichtel | ee9b959 | 2015-04-02 17:07:03 +0200 | [diff] [blame] | 530 | .ndo_get_iflink = reg_vif_get_iflink, |
Stephen Hemminger | 007c383 | 2008-11-20 20:28:35 -0800 | [diff] [blame] | 531 | }; |
| 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | static void reg_vif_setup(struct net_device *dev) |
| 534 | { |
| 535 | dev->type = ARPHRD_PIMREG; |
Kris Katterjohn | 46f25df | 2006-01-05 16:35:42 -0800 | [diff] [blame] | 536 | dev->mtu = ETH_DATA_LEN - sizeof(struct iphdr) - 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | dev->flags = IFF_NOARP; |
Himangi Saraogi | 70cb4a4 | 2014-05-30 21:10:48 +0530 | [diff] [blame] | 538 | dev->netdev_ops = ®_vif_netdev_ops; |
David S. Miller | cf124db | 2017-05-08 12:52:56 -0400 | [diff] [blame] | 539 | dev->needs_free_netdev = true; |
Tom Goff | 403dbb9 | 2009-06-14 03:16:13 -0700 | [diff] [blame] | 540 | dev->features |= NETIF_F_NETNS_LOCAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | } |
| 542 | |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 543 | static struct net_device *ipmr_reg_vif(struct net *net, struct mr_table *mrt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | { |
| 545 | struct net_device *dev; |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 546 | char name[IFNAMSIZ]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 548 | if (mrt->id == RT_TABLE_DEFAULT) |
| 549 | sprintf(name, "pimreg"); |
| 550 | else |
| 551 | sprintf(name, "pimreg%u", mrt->id); |
| 552 | |
Tom Gundersen | c835a67 | 2014-07-14 16:37:24 +0200 | [diff] [blame] | 553 | dev = alloc_netdev(0, name, NET_NAME_UNKNOWN, reg_vif_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 555 | if (!dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | return NULL; |
| 557 | |
Tom Goff | 403dbb9 | 2009-06-14 03:16:13 -0700 | [diff] [blame] | 558 | dev_net_set(dev, net); |
| 559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | if (register_netdevice(dev)) { |
| 561 | free_netdev(dev); |
| 562 | return NULL; |
| 563 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
Nikolay Aleksandrov | a0b4773 | 2015-11-21 15:57:32 +0100 | [diff] [blame] | 565 | if (!ipmr_init_vif_indev(dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | goto failure; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | if (dev_open(dev)) |
| 568 | goto failure; |
| 569 | |
Wang Chen | 7dc00c8 | 2008-07-14 20:56:34 -0700 | [diff] [blame] | 570 | dev_hold(dev); |
| 571 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | return dev; |
| 573 | |
| 574 | failure: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | unregister_netdevice(dev); |
| 576 | return NULL; |
| 577 | } |
Nikolay Aleksandrov | c316c62 | 2015-11-21 15:57:26 +0100 | [diff] [blame] | 578 | |
| 579 | /* called with rcu_read_lock() */ |
| 580 | static int __pim_rcv(struct mr_table *mrt, struct sk_buff *skb, |
| 581 | unsigned int pimlen) |
| 582 | { |
| 583 | struct net_device *reg_dev = NULL; |
| 584 | struct iphdr *encap; |
| 585 | |
| 586 | encap = (struct iphdr *)(skb_transport_header(skb) + pimlen); |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 587 | /* Check that: |
Nikolay Aleksandrov | c316c62 | 2015-11-21 15:57:26 +0100 | [diff] [blame] | 588 | * a. packet is really sent to a multicast group |
| 589 | * b. packet is not a NULL-REGISTER |
| 590 | * c. packet is not truncated |
| 591 | */ |
| 592 | if (!ipv4_is_multicast(encap->daddr) || |
| 593 | encap->tot_len == 0 || |
| 594 | ntohs(encap->tot_len) + pimlen > skb->len) |
| 595 | return 1; |
| 596 | |
| 597 | read_lock(&mrt_lock); |
| 598 | if (mrt->mroute_reg_vif_num >= 0) |
| 599 | reg_dev = mrt->vif_table[mrt->mroute_reg_vif_num].dev; |
| 600 | read_unlock(&mrt_lock); |
| 601 | |
| 602 | if (!reg_dev) |
| 603 | return 1; |
| 604 | |
| 605 | skb->mac_header = skb->network_header; |
| 606 | skb_pull(skb, (u8 *)encap - skb->data); |
| 607 | skb_reset_network_header(skb); |
| 608 | skb->protocol = htons(ETH_P_IP); |
| 609 | skb->ip_summed = CHECKSUM_NONE; |
| 610 | |
| 611 | skb_tunnel_rx(skb, reg_dev, dev_net(reg_dev)); |
| 612 | |
| 613 | netif_rx(skb); |
| 614 | |
| 615 | return NET_RX_SUCCESS; |
| 616 | } |
| 617 | #else |
| 618 | static struct net_device *ipmr_reg_vif(struct net *net, struct mr_table *mrt) |
| 619 | { |
| 620 | return NULL; |
| 621 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | #endif |
| 623 | |
Yotam Gigi | 4d65b94 | 2017-09-27 08:23:13 +0200 | [diff] [blame] | 624 | static int call_ipmr_vif_entry_notifier(struct notifier_block *nb, |
| 625 | struct net *net, |
| 626 | enum fib_event_type event_type, |
| 627 | struct vif_device *vif, |
| 628 | vifi_t vif_index, u32 tb_id) |
| 629 | { |
| 630 | struct vif_entry_notifier_info info = { |
| 631 | .info = { |
| 632 | .family = RTNL_FAMILY_IPMR, |
| 633 | .net = net, |
| 634 | }, |
| 635 | .dev = vif->dev, |
| 636 | .vif_index = vif_index, |
| 637 | .vif_flags = vif->flags, |
| 638 | .tb_id = tb_id, |
| 639 | }; |
| 640 | |
| 641 | return call_fib_notifier(nb, net, event_type, &info.info); |
| 642 | } |
| 643 | |
Yotam Gigi | b362053 | 2017-09-27 08:23:14 +0200 | [diff] [blame] | 644 | static int call_ipmr_vif_entry_notifiers(struct net *net, |
| 645 | enum fib_event_type event_type, |
| 646 | struct vif_device *vif, |
| 647 | vifi_t vif_index, u32 tb_id) |
| 648 | { |
| 649 | struct vif_entry_notifier_info info = { |
| 650 | .info = { |
| 651 | .family = RTNL_FAMILY_IPMR, |
| 652 | .net = net, |
| 653 | }, |
| 654 | .dev = vif->dev, |
| 655 | .vif_index = vif_index, |
| 656 | .vif_flags = vif->flags, |
| 657 | .tb_id = tb_id, |
| 658 | }; |
| 659 | |
| 660 | ASSERT_RTNL(); |
| 661 | net->ipv4.ipmr_seq++; |
| 662 | return call_fib_notifiers(net, event_type, &info.info); |
| 663 | } |
| 664 | |
Yotam Gigi | 4d65b94 | 2017-09-27 08:23:13 +0200 | [diff] [blame] | 665 | static int call_ipmr_mfc_entry_notifier(struct notifier_block *nb, |
| 666 | struct net *net, |
| 667 | enum fib_event_type event_type, |
| 668 | struct mfc_cache *mfc, u32 tb_id) |
| 669 | { |
| 670 | struct mfc_entry_notifier_info info = { |
| 671 | .info = { |
| 672 | .family = RTNL_FAMILY_IPMR, |
| 673 | .net = net, |
| 674 | }, |
| 675 | .mfc = mfc, |
| 676 | .tb_id = tb_id |
| 677 | }; |
| 678 | |
| 679 | return call_fib_notifier(nb, net, event_type, &info.info); |
| 680 | } |
| 681 | |
Yotam Gigi | b362053 | 2017-09-27 08:23:14 +0200 | [diff] [blame] | 682 | static int call_ipmr_mfc_entry_notifiers(struct net *net, |
| 683 | enum fib_event_type event_type, |
| 684 | struct mfc_cache *mfc, u32 tb_id) |
| 685 | { |
| 686 | struct mfc_entry_notifier_info info = { |
| 687 | .info = { |
| 688 | .family = RTNL_FAMILY_IPMR, |
| 689 | .net = net, |
| 690 | }, |
| 691 | .mfc = mfc, |
| 692 | .tb_id = tb_id |
| 693 | }; |
| 694 | |
| 695 | ASSERT_RTNL(); |
| 696 | net->ipv4.ipmr_seq++; |
| 697 | return call_fib_notifiers(net, event_type, &info.info); |
| 698 | } |
| 699 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 700 | /** |
| 701 | * vif_delete - Delete a VIF entry |
Wang Chen | 7dc00c8 | 2008-07-14 20:56:34 -0700 | [diff] [blame] | 702 | * @notify: Set to 1, if the caller is a notifier_call |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | */ |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 704 | static int vif_delete(struct mr_table *mrt, int vifi, int notify, |
Eric Dumazet | d17fa6f | 2009-10-28 05:21:38 +0000 | [diff] [blame] | 705 | struct list_head *head) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | { |
Yotam Gigi | b362053 | 2017-09-27 08:23:14 +0200 | [diff] [blame] | 707 | struct net *net = read_pnet(&mrt->net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | struct vif_device *v; |
| 709 | struct net_device *dev; |
| 710 | struct in_device *in_dev; |
| 711 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 712 | if (vifi < 0 || vifi >= mrt->maxvif) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | return -EADDRNOTAVAIL; |
| 714 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 715 | v = &mrt->vif_table[vifi]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
Yotam Gigi | b362053 | 2017-09-27 08:23:14 +0200 | [diff] [blame] | 717 | if (VIF_EXISTS(mrt, vifi)) |
| 718 | call_ipmr_vif_entry_notifiers(net, FIB_EVENT_VIF_DEL, v, vifi, |
| 719 | mrt->id); |
| 720 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | write_lock_bh(&mrt_lock); |
| 722 | dev = v->dev; |
| 723 | v->dev = NULL; |
| 724 | |
| 725 | if (!dev) { |
| 726 | write_unlock_bh(&mrt_lock); |
| 727 | return -EADDRNOTAVAIL; |
| 728 | } |
| 729 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 730 | if (vifi == mrt->mroute_reg_vif_num) |
| 731 | mrt->mroute_reg_vif_num = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 733 | if (vifi + 1 == mrt->maxvif) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | int tmp; |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 735 | |
| 736 | for (tmp = vifi - 1; tmp >= 0; tmp--) { |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 737 | if (VIF_EXISTS(mrt, tmp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | break; |
| 739 | } |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 740 | mrt->maxvif = tmp+1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | write_unlock_bh(&mrt_lock); |
| 744 | |
| 745 | dev_set_allmulti(dev, -1); |
| 746 | |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 747 | in_dev = __in_dev_get_rtnl(dev); |
| 748 | if (in_dev) { |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 749 | IPV4_DEVCONF(in_dev->cnf, MC_FORWARDING)--; |
David Ahern | 3b02286 | 2017-03-28 14:28:02 -0700 | [diff] [blame] | 750 | inet_netconf_notify_devconf(dev_net(dev), RTM_NEWNETCONF, |
Nicolas Dichtel | d67b8c6 | 2012-12-04 01:13:35 +0000 | [diff] [blame] | 751 | NETCONFA_MC_FORWARDING, |
| 752 | dev->ifindex, &in_dev->cnf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | ip_rt_multicast_event(in_dev); |
| 754 | } |
| 755 | |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 756 | if (v->flags & (VIFF_TUNNEL | VIFF_REGISTER) && !notify) |
Eric Dumazet | d17fa6f | 2009-10-28 05:21:38 +0000 | [diff] [blame] | 757 | unregister_netdevice_queue(dev, head); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | |
| 759 | dev_put(dev); |
| 760 | return 0; |
| 761 | } |
| 762 | |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 763 | static void ipmr_cache_free_rcu(struct rcu_head *head) |
| 764 | { |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 765 | struct mr_mfc *c = container_of(head, struct mr_mfc, rcu); |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 766 | |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 767 | kmem_cache_free(mrt_cachep, (struct mfc_cache *)c); |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 768 | } |
| 769 | |
Yotam Gigi | 310ebbb | 2017-09-27 08:23:12 +0200 | [diff] [blame] | 770 | void ipmr_cache_free(struct mfc_cache *c) |
Benjamin Thery | 5c0a66f | 2009-01-22 04:56:17 +0000 | [diff] [blame] | 771 | { |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 772 | call_rcu(&c->_c.rcu, ipmr_cache_free_rcu); |
Benjamin Thery | 5c0a66f | 2009-01-22 04:56:17 +0000 | [diff] [blame] | 773 | } |
Yotam Gigi | 310ebbb | 2017-09-27 08:23:12 +0200 | [diff] [blame] | 774 | EXPORT_SYMBOL(ipmr_cache_free); |
Benjamin Thery | 5c0a66f | 2009-01-22 04:56:17 +0000 | [diff] [blame] | 775 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | /* Destroy an unresolved cache entry, killing queued skbs |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 777 | * and reporting error to netlink readers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | */ |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 779 | static void ipmr_destroy_unres(struct mr_table *mrt, struct mfc_cache *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | { |
Patrick McHardy | 8de53df | 2010-04-15 13:29:28 +0200 | [diff] [blame] | 781 | struct net *net = read_pnet(&mrt->net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | struct sk_buff *skb; |
Patrick McHardy | 9ef1d4c | 2005-06-28 12:55:30 -0700 | [diff] [blame] | 783 | struct nlmsgerr *e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 785 | atomic_dec(&mrt->cache_resolve_queue_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 787 | while ((skb = skb_dequeue(&c->_c.mfc_un.unres.unresolved))) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 788 | if (ip_hdr(skb)->version == 0) { |
Johannes Berg | af72868 | 2017-06-16 14:29:22 +0200 | [diff] [blame] | 789 | struct nlmsghdr *nlh = skb_pull(skb, |
| 790 | sizeof(struct iphdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | nlh->nlmsg_type = NLMSG_ERROR; |
Hong zhi guo | 573ce26 | 2013-03-27 06:47:04 +0000 | [diff] [blame] | 792 | nlh->nlmsg_len = nlmsg_msg_size(sizeof(struct nlmsgerr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | skb_trim(skb, nlh->nlmsg_len); |
Hong zhi guo | 573ce26 | 2013-03-27 06:47:04 +0000 | [diff] [blame] | 794 | e = nlmsg_data(nlh); |
Patrick McHardy | 9ef1d4c | 2005-06-28 12:55:30 -0700 | [diff] [blame] | 795 | e->error = -ETIMEDOUT; |
| 796 | memset(&e->msg, 0, sizeof(e->msg)); |
Thomas Graf | 2942e90 | 2006-08-15 00:30:25 -0700 | [diff] [blame] | 797 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 798 | rtnl_unicast(skb, net, NETLINK_CB(skb).portid); |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 799 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | kfree_skb(skb); |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 801 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | } |
| 803 | |
Benjamin Thery | 5c0a66f | 2009-01-22 04:56:17 +0000 | [diff] [blame] | 804 | ipmr_cache_free(c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | } |
| 806 | |
Patrick McHardy | e258beb | 2010-04-13 05:03:19 +0000 | [diff] [blame] | 807 | /* Timer process for the unresolved queue. */ |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 808 | static void ipmr_expire_process(struct timer_list *t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | { |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 810 | struct mr_table *mrt = from_timer(mrt, t, ipmr_expire_timer); |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 811 | struct mr_mfc *c, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | unsigned long expires; |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 813 | unsigned long now; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | |
| 815 | if (!spin_trylock(&mfc_unres_lock)) { |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 816 | mod_timer(&mrt->ipmr_expire_timer, jiffies+HZ/10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | return; |
| 818 | } |
| 819 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 820 | if (list_empty(&mrt->mfc_unres_queue)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | goto out; |
| 822 | |
| 823 | now = jiffies; |
| 824 | expires = 10*HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 826 | list_for_each_entry_safe(c, next, &mrt->mfc_unres_queue, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | if (time_after(c->mfc_un.unres.expires, now)) { |
| 828 | unsigned long interval = c->mfc_un.unres.expires - now; |
| 829 | if (interval < expires) |
| 830 | expires = interval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | continue; |
| 832 | } |
| 833 | |
Patrick McHardy | 862465f | 2010-04-13 05:03:21 +0000 | [diff] [blame] | 834 | list_del(&c->list); |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 835 | mroute_netlink_event(mrt, (struct mfc_cache *)c, RTM_DELROUTE); |
| 836 | ipmr_destroy_unres(mrt, (struct mfc_cache *)c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | } |
| 838 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 839 | if (!list_empty(&mrt->mfc_unres_queue)) |
| 840 | mod_timer(&mrt->ipmr_expire_timer, jiffies + expires); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | |
| 842 | out: |
| 843 | spin_unlock(&mfc_unres_lock); |
| 844 | } |
| 845 | |
| 846 | /* Fill oifs list. It is called under write locked mrt_lock. */ |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 847 | static void ipmr_update_thresholds(struct mr_table *mrt, struct mr_mfc *cache, |
Patrick McHardy | d658f8a | 2010-04-13 05:03:20 +0000 | [diff] [blame] | 848 | unsigned char *ttls) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | { |
| 850 | int vifi; |
| 851 | |
| 852 | cache->mfc_un.res.minvif = MAXVIFS; |
| 853 | cache->mfc_un.res.maxvif = 0; |
| 854 | memset(cache->mfc_un.res.ttls, 255, MAXVIFS); |
| 855 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 856 | for (vifi = 0; vifi < mrt->maxvif; vifi++) { |
| 857 | if (VIF_EXISTS(mrt, vifi) && |
Benjamin Thery | cf958ae3 | 2009-01-22 04:56:16 +0000 | [diff] [blame] | 858 | ttls[vifi] && ttls[vifi] < 255) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | cache->mfc_un.res.ttls[vifi] = ttls[vifi]; |
| 860 | if (cache->mfc_un.res.minvif > vifi) |
| 861 | cache->mfc_un.res.minvif = vifi; |
| 862 | if (cache->mfc_un.res.maxvif <= vifi) |
| 863 | cache->mfc_un.res.maxvif = vifi + 1; |
| 864 | } |
| 865 | } |
Nikolay Aleksandrov | 90b5ca1 | 2016-07-26 18:54:52 +0200 | [diff] [blame] | 866 | cache->mfc_un.res.lastuse = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 869 | static int vif_add(struct net *net, struct mr_table *mrt, |
| 870 | struct vifctl *vifc, int mrtsock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | { |
| 872 | int vifi = vifc->vifc_vifi; |
Yotam Gigi | 5d8b3e6 | 2017-10-03 09:58:07 +0200 | [diff] [blame] | 873 | struct switchdev_attr attr = { |
| 874 | .id = SWITCHDEV_ATTR_ID_PORT_PARENT_ID, |
| 875 | }; |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 876 | struct vif_device *v = &mrt->vif_table[vifi]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | struct net_device *dev; |
| 878 | struct in_device *in_dev; |
Wang Chen | d607032 | 2008-07-14 20:55:26 -0700 | [diff] [blame] | 879 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
| 881 | /* Is vif busy ? */ |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 882 | if (VIF_EXISTS(mrt, vifi)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | return -EADDRINUSE; |
| 884 | |
| 885 | switch (vifc->vifc_flags) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | case VIFF_REGISTER: |
Nikolay Aleksandrov | 1973a4e | 2015-11-26 15:23:48 +0100 | [diff] [blame] | 887 | if (!ipmr_pimsm_enabled()) |
Nikolay Aleksandrov | c316c62 | 2015-11-21 15:57:26 +0100 | [diff] [blame] | 888 | return -EINVAL; |
| 889 | /* Special Purpose VIF in PIM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | * All the packets will be sent to the daemon |
| 891 | */ |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 892 | if (mrt->mroute_reg_vif_num >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | return -EADDRINUSE; |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 894 | dev = ipmr_reg_vif(net, mrt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | if (!dev) |
| 896 | return -ENOBUFS; |
Wang Chen | d607032 | 2008-07-14 20:55:26 -0700 | [diff] [blame] | 897 | err = dev_set_allmulti(dev, 1); |
| 898 | if (err) { |
| 899 | unregister_netdevice(dev); |
Wang Chen | 7dc00c8 | 2008-07-14 20:56:34 -0700 | [diff] [blame] | 900 | dev_put(dev); |
Wang Chen | d607032 | 2008-07-14 20:55:26 -0700 | [diff] [blame] | 901 | return err; |
| 902 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | break; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 904 | case VIFF_TUNNEL: |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 905 | dev = ipmr_new_tunnel(net, vifc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | if (!dev) |
| 907 | return -ENOBUFS; |
Wang Chen | d607032 | 2008-07-14 20:55:26 -0700 | [diff] [blame] | 908 | err = dev_set_allmulti(dev, 1); |
| 909 | if (err) { |
| 910 | ipmr_del_tunnel(dev, vifc); |
Wang Chen | 7dc00c8 | 2008-07-14 20:56:34 -0700 | [diff] [blame] | 911 | dev_put(dev); |
Wang Chen | d607032 | 2008-07-14 20:55:26 -0700 | [diff] [blame] | 912 | return err; |
| 913 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | break; |
Ilia K | ee5e81f | 2009-09-16 05:53:07 +0000 | [diff] [blame] | 915 | case VIFF_USE_IFINDEX: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | case 0: |
Ilia K | ee5e81f | 2009-09-16 05:53:07 +0000 | [diff] [blame] | 917 | if (vifc->vifc_flags == VIFF_USE_IFINDEX) { |
| 918 | dev = dev_get_by_index(net, vifc->vifc_lcl_ifindex); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 919 | if (dev && !__in_dev_get_rtnl(dev)) { |
Ilia K | ee5e81f | 2009-09-16 05:53:07 +0000 | [diff] [blame] | 920 | dev_put(dev); |
| 921 | return -EADDRNOTAVAIL; |
| 922 | } |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 923 | } else { |
Ilia K | ee5e81f | 2009-09-16 05:53:07 +0000 | [diff] [blame] | 924 | dev = ip_dev_find(net, vifc->vifc_lcl_addr.s_addr); |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 925 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | if (!dev) |
| 927 | return -EADDRNOTAVAIL; |
Wang Chen | d607032 | 2008-07-14 20:55:26 -0700 | [diff] [blame] | 928 | err = dev_set_allmulti(dev, 1); |
Wang Chen | 7dc00c8 | 2008-07-14 20:56:34 -0700 | [diff] [blame] | 929 | if (err) { |
| 930 | dev_put(dev); |
Wang Chen | d607032 | 2008-07-14 20:55:26 -0700 | [diff] [blame] | 931 | return err; |
Wang Chen | 7dc00c8 | 2008-07-14 20:56:34 -0700 | [diff] [blame] | 932 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | break; |
| 934 | default: |
| 935 | return -EINVAL; |
| 936 | } |
| 937 | |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 938 | in_dev = __in_dev_get_rtnl(dev); |
| 939 | if (!in_dev) { |
Dan Carpenter | d0490cf | 2009-11-11 02:03:54 +0000 | [diff] [blame] | 940 | dev_put(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | return -EADDRNOTAVAIL; |
Dan Carpenter | d0490cf | 2009-11-11 02:03:54 +0000 | [diff] [blame] | 942 | } |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 943 | IPV4_DEVCONF(in_dev->cnf, MC_FORWARDING)++; |
David Ahern | 3b02286 | 2017-03-28 14:28:02 -0700 | [diff] [blame] | 944 | inet_netconf_notify_devconf(net, RTM_NEWNETCONF, NETCONFA_MC_FORWARDING, |
| 945 | dev->ifindex, &in_dev->cnf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | ip_rt_multicast_event(in_dev); |
| 947 | |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 948 | /* Fill in the VIF structures */ |
Yuval Mintz | 6853f21 | 2018-02-28 23:29:29 +0200 | [diff] [blame] | 949 | vif_device_init(v, dev, vifc->vifc_rate_limit, |
| 950 | vifc->vifc_threshold, |
| 951 | vifc->vifc_flags | (!mrtsock ? VIFF_STATIC : 0), |
| 952 | (VIFF_TUNNEL | VIFF_REGISTER)); |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 953 | |
Yotam Gigi | 5d8b3e6 | 2017-10-03 09:58:07 +0200 | [diff] [blame] | 954 | attr.orig_dev = dev; |
| 955 | if (!switchdev_port_attr_get(dev, &attr)) { |
| 956 | memcpy(v->dev_parent_id.id, attr.u.ppid.id, attr.u.ppid.id_len); |
| 957 | v->dev_parent_id.id_len = attr.u.ppid.id_len; |
| 958 | } else { |
| 959 | v->dev_parent_id.id_len = 0; |
| 960 | } |
Yuval Mintz | 6853f21 | 2018-02-28 23:29:29 +0200 | [diff] [blame] | 961 | |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 962 | v->local = vifc->vifc_lcl_addr.s_addr; |
| 963 | v->remote = vifc->vifc_rmt_addr.s_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | |
| 965 | /* And finish update writing critical data */ |
| 966 | write_lock_bh(&mrt_lock); |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 967 | v->dev = dev; |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 968 | if (v->flags & VIFF_REGISTER) |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 969 | mrt->mroute_reg_vif_num = vifi; |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 970 | if (vifi+1 > mrt->maxvif) |
| 971 | mrt->maxvif = vifi+1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | write_unlock_bh(&mrt_lock); |
Yotam Gigi | b362053 | 2017-09-27 08:23:14 +0200 | [diff] [blame] | 973 | call_ipmr_vif_entry_notifiers(net, FIB_EVENT_VIF_ADD, v, vifi, mrt->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | return 0; |
| 975 | } |
| 976 | |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 977 | /* called with rcu_read_lock() */ |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 978 | static struct mfc_cache *ipmr_cache_find(struct mr_table *mrt, |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 979 | __be32 origin, |
| 980 | __be32 mcastgrp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | { |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 982 | struct mfc_cache_cmp_arg arg = { |
| 983 | .mfc_mcastgrp = mcastgrp, |
| 984 | .mfc_origin = origin |
| 985 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | |
Yuval Mintz | 845c9a7 | 2018-02-28 23:29:35 +0200 | [diff] [blame] | 987 | return mr_mfc_find(mrt, &arg); |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | /* Look for a (*,G) entry */ |
| 991 | static struct mfc_cache *ipmr_cache_find_any(struct mr_table *mrt, |
| 992 | __be32 mcastgrp, int vifi) |
| 993 | { |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 994 | struct mfc_cache_cmp_arg arg = { |
| 995 | .mfc_mcastgrp = mcastgrp, |
| 996 | .mfc_origin = htonl(INADDR_ANY) |
| 997 | }; |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 998 | |
Nicolas Dichtel | 360eb5d | 2013-01-22 11:18:03 +0100 | [diff] [blame] | 999 | if (mcastgrp == htonl(INADDR_ANY)) |
Yuval Mintz | 845c9a7 | 2018-02-28 23:29:35 +0200 | [diff] [blame] | 1000 | return mr_mfc_find_any_parent(mrt, vifi); |
| 1001 | return mr_mfc_find_any(mrt, vifi, &arg); |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 1004 | /* Look for a (S,G,iif) entry if parent != -1 */ |
| 1005 | static struct mfc_cache *ipmr_cache_find_parent(struct mr_table *mrt, |
| 1006 | __be32 origin, __be32 mcastgrp, |
| 1007 | int parent) |
| 1008 | { |
| 1009 | struct mfc_cache_cmp_arg arg = { |
| 1010 | .mfc_mcastgrp = mcastgrp, |
| 1011 | .mfc_origin = origin, |
| 1012 | }; |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 1013 | |
Yuval Mintz | 845c9a7 | 2018-02-28 23:29:35 +0200 | [diff] [blame] | 1014 | return mr_mfc_find_parent(mrt, &arg, parent); |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 1015 | } |
| 1016 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 1017 | /* Allocate a multicast cache entry */ |
Patrick McHardy | d658f8a | 2010-04-13 05:03:20 +0000 | [diff] [blame] | 1018 | static struct mfc_cache *ipmr_cache_alloc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | { |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 1020 | struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_KERNEL); |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 1021 | |
Tom Goff | 70a0dec | 2016-06-23 16:11:57 -0400 | [diff] [blame] | 1022 | if (c) { |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1023 | c->_c.mfc_un.res.last_assert = jiffies - MFC_ASSERT_THRESH - 1; |
| 1024 | c->_c.mfc_un.res.minvif = MAXVIFS; |
| 1025 | refcount_set(&c->_c.mfc_un.res.refcount, 1); |
Tom Goff | 70a0dec | 2016-06-23 16:11:57 -0400 | [diff] [blame] | 1026 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | return c; |
| 1028 | } |
| 1029 | |
Patrick McHardy | d658f8a | 2010-04-13 05:03:20 +0000 | [diff] [blame] | 1030 | static struct mfc_cache *ipmr_cache_alloc_unres(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | { |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 1032 | struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC); |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 1033 | |
| 1034 | if (c) { |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1035 | skb_queue_head_init(&c->_c.mfc_un.unres.unresolved); |
| 1036 | c->_c.mfc_un.unres.expires = jiffies + 10 * HZ; |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 1037 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | return c; |
| 1039 | } |
| 1040 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 1041 | /* A cache entry has gone into a resolved state from queued */ |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1042 | static void ipmr_cache_resolve(struct net *net, struct mr_table *mrt, |
| 1043 | struct mfc_cache *uc, struct mfc_cache *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | { |
| 1045 | struct sk_buff *skb; |
Patrick McHardy | 9ef1d4c | 2005-06-28 12:55:30 -0700 | [diff] [blame] | 1046 | struct nlmsgerr *e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1048 | /* Play the pending entries through our router */ |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1049 | while ((skb = __skb_dequeue(&uc->_c.mfc_un.unres.unresolved))) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1050 | if (ip_hdr(skb)->version == 0) { |
Johannes Berg | af72868 | 2017-06-16 14:29:22 +0200 | [diff] [blame] | 1051 | struct nlmsghdr *nlh = skb_pull(skb, |
| 1052 | sizeof(struct iphdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1054 | if (__ipmr_fill_mroute(mrt, skb, &c->_c, |
| 1055 | nlmsg_data(nlh)) > 0) { |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1056 | nlh->nlmsg_len = skb_tail_pointer(skb) - |
| 1057 | (u8 *)nlh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | } else { |
| 1059 | nlh->nlmsg_type = NLMSG_ERROR; |
Hong zhi guo | 573ce26 | 2013-03-27 06:47:04 +0000 | [diff] [blame] | 1060 | nlh->nlmsg_len = nlmsg_msg_size(sizeof(struct nlmsgerr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | skb_trim(skb, nlh->nlmsg_len); |
Hong zhi guo | 573ce26 | 2013-03-27 06:47:04 +0000 | [diff] [blame] | 1062 | e = nlmsg_data(nlh); |
Patrick McHardy | 9ef1d4c | 2005-06-28 12:55:30 -0700 | [diff] [blame] | 1063 | e->error = -EMSGSIZE; |
| 1064 | memset(&e->msg, 0, sizeof(e->msg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | } |
Thomas Graf | 2942e90 | 2006-08-15 00:30:25 -0700 | [diff] [blame] | 1066 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1067 | rtnl_unicast(skb, net, NETLINK_CB(skb).portid); |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1068 | } else { |
Donald Sharp | 4b1f0d3 | 2017-06-10 16:30:17 -0400 | [diff] [blame] | 1069 | ip_mr_forward(net, mrt, skb->dev, skb, c, 0); |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1070 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | } |
| 1072 | } |
| 1073 | |
Julien Gomes | 5a645dd | 2017-06-20 13:54:17 -0700 | [diff] [blame] | 1074 | /* Bounce a cache query up to mrouted and netlink. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | * |
Nikolay Aleksandrov | c316c62 | 2015-11-21 15:57:26 +0100 | [diff] [blame] | 1076 | * Called under mrt_lock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | */ |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1078 | static int ipmr_cache_report(struct mr_table *mrt, |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 1079 | struct sk_buff *pkt, vifi_t vifi, int assert) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | { |
Arnaldo Carvalho de Melo | c9bdd4b | 2007-03-12 20:09:15 -0300 | [diff] [blame] | 1081 | const int ihl = ip_hdrlen(pkt); |
Nikolay Aleksandrov | c316c62 | 2015-11-21 15:57:26 +0100 | [diff] [blame] | 1082 | struct sock *mroute_sk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | struct igmphdr *igmp; |
| 1084 | struct igmpmsg *msg; |
Nikolay Aleksandrov | c316c62 | 2015-11-21 15:57:26 +0100 | [diff] [blame] | 1085 | struct sk_buff *skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | int ret; |
| 1087 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | if (assert == IGMPMSG_WHOLEPKT) |
| 1089 | skb = skb_realloc_headroom(pkt, sizeof(struct iphdr)); |
| 1090 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | skb = alloc_skb(128, GFP_ATOMIC); |
| 1092 | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1093 | if (!skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | return -ENOBUFS; |
| 1095 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | if (assert == IGMPMSG_WHOLEPKT) { |
| 1097 | /* Ugly, but we have no choice with this interface. |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1098 | * Duplicate old header, fix ihl, length etc. |
| 1099 | * And all this only to mangle msg->im_msgtype and |
| 1100 | * to set msg->im_mbz to "mbz" :-) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | */ |
Arnaldo Carvalho de Melo | 878c814 | 2007-03-11 22:38:29 -0300 | [diff] [blame] | 1102 | skb_push(skb, sizeof(struct iphdr)); |
| 1103 | skb_reset_network_header(skb); |
Arnaldo Carvalho de Melo | badff6d | 2007-03-13 13:06:52 -0300 | [diff] [blame] | 1104 | skb_reset_transport_header(skb); |
Arnaldo Carvalho de Melo | 0272ffc | 2007-03-12 20:05:39 -0300 | [diff] [blame] | 1105 | msg = (struct igmpmsg *)skb_network_header(skb); |
Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 1106 | memcpy(msg, skb_network_header(pkt), sizeof(struct iphdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | msg->im_msgtype = IGMPMSG_WHOLEPKT; |
| 1108 | msg->im_mbz = 0; |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1109 | msg->im_vif = mrt->mroute_reg_vif_num; |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1110 | ip_hdr(skb)->ihl = sizeof(struct iphdr) >> 2; |
| 1111 | ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(pkt)->tot_len) + |
| 1112 | sizeof(struct iphdr)); |
Nikolay Aleksandrov | c316c62 | 2015-11-21 15:57:26 +0100 | [diff] [blame] | 1113 | } else { |
| 1114 | /* Copy the IP header */ |
| 1115 | skb_set_network_header(skb, skb->len); |
| 1116 | skb_put(skb, ihl); |
| 1117 | skb_copy_to_linear_data(skb, pkt->data, ihl); |
| 1118 | /* Flag to the kernel this is a route add */ |
| 1119 | ip_hdr(skb)->protocol = 0; |
| 1120 | msg = (struct igmpmsg *)skb_network_header(skb); |
| 1121 | msg->im_vif = vifi; |
| 1122 | skb_dst_set(skb, dst_clone(skb_dst(pkt))); |
| 1123 | /* Add our header */ |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 1124 | igmp = skb_put(skb, sizeof(struct igmphdr)); |
Nikolay Aleksandrov | c316c62 | 2015-11-21 15:57:26 +0100 | [diff] [blame] | 1125 | igmp->type = assert; |
| 1126 | msg->im_msgtype = assert; |
| 1127 | igmp->code = 0; |
| 1128 | ip_hdr(skb)->tot_len = htons(skb->len); /* Fix the length */ |
| 1129 | skb->transport_header = skb->network_header; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1130 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | |
Eric Dumazet | 4c968709 | 2010-10-01 16:15:01 +0000 | [diff] [blame] | 1132 | rcu_read_lock(); |
| 1133 | mroute_sk = rcu_dereference(mrt->mroute_sk); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 1134 | if (!mroute_sk) { |
Eric Dumazet | 4c968709 | 2010-10-01 16:15:01 +0000 | [diff] [blame] | 1135 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | kfree_skb(skb); |
| 1137 | return -EINVAL; |
| 1138 | } |
| 1139 | |
Julien Gomes | 5a645dd | 2017-06-20 13:54:17 -0700 | [diff] [blame] | 1140 | igmpmsg_netlink_event(mrt, skb); |
| 1141 | |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1142 | /* Deliver to mrouted */ |
Eric Dumazet | 4c968709 | 2010-10-01 16:15:01 +0000 | [diff] [blame] | 1143 | ret = sock_queue_rcv_skb(mroute_sk, skb); |
| 1144 | rcu_read_unlock(); |
Benjamin Thery | 70a269e | 2009-01-22 04:56:15 +0000 | [diff] [blame] | 1145 | if (ret < 0) { |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 1146 | net_warn_ratelimited("mroute: pending queue full, dropping entries\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | kfree_skb(skb); |
| 1148 | } |
| 1149 | |
| 1150 | return ret; |
| 1151 | } |
| 1152 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 1153 | /* Queue a packet for resolution. It gets locked cache entry! */ |
| 1154 | static int ipmr_cache_unresolved(struct mr_table *mrt, vifi_t vifi, |
Donald Sharp | 4b1f0d3 | 2017-06-10 16:30:17 -0400 | [diff] [blame] | 1155 | struct sk_buff *skb, struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | { |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 1157 | const struct iphdr *iph = ip_hdr(skb); |
| 1158 | struct mfc_cache *c; |
Patrick McHardy | 862465f | 2010-04-13 05:03:21 +0000 | [diff] [blame] | 1159 | bool found = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | |
| 1162 | spin_lock_bh(&mfc_unres_lock); |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1163 | list_for_each_entry(c, &mrt->mfc_unres_queue, _c.list) { |
Patrick McHardy | e258beb | 2010-04-13 05:03:19 +0000 | [diff] [blame] | 1164 | if (c->mfc_mcastgrp == iph->daddr && |
Patrick McHardy | 862465f | 2010-04-13 05:03:21 +0000 | [diff] [blame] | 1165 | c->mfc_origin == iph->saddr) { |
| 1166 | found = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | break; |
Patrick McHardy | 862465f | 2010-04-13 05:03:21 +0000 | [diff] [blame] | 1168 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
Patrick McHardy | 862465f | 2010-04-13 05:03:21 +0000 | [diff] [blame] | 1171 | if (!found) { |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1172 | /* Create a new entry if allowable */ |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1173 | if (atomic_read(&mrt->cache_resolve_queue_len) >= 10 || |
Patrick McHardy | d658f8a | 2010-04-13 05:03:20 +0000 | [diff] [blame] | 1174 | (c = ipmr_cache_alloc_unres()) == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | spin_unlock_bh(&mfc_unres_lock); |
| 1176 | |
| 1177 | kfree_skb(skb); |
| 1178 | return -ENOBUFS; |
| 1179 | } |
| 1180 | |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1181 | /* Fill in the new cache entry */ |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1182 | c->_c.mfc_parent = -1; |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1183 | c->mfc_origin = iph->saddr; |
| 1184 | c->mfc_mcastgrp = iph->daddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1186 | /* Reflect first query at mrouted. */ |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1187 | err = ipmr_cache_report(mrt, skb, vifi, IGMPMSG_NOCACHE); |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1188 | |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 1189 | if (err < 0) { |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1190 | /* If the report failed throw the cache entry |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | out - Brad Parker |
| 1192 | */ |
| 1193 | spin_unlock_bh(&mfc_unres_lock); |
| 1194 | |
Benjamin Thery | 5c0a66f | 2009-01-22 04:56:17 +0000 | [diff] [blame] | 1195 | ipmr_cache_free(c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | kfree_skb(skb); |
| 1197 | return err; |
| 1198 | } |
| 1199 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1200 | atomic_inc(&mrt->cache_resolve_queue_len); |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1201 | list_add(&c->_c.list, &mrt->mfc_unres_queue); |
Nicolas Dichtel | 8cd3ac9 | 2012-12-04 01:13:40 +0000 | [diff] [blame] | 1202 | mroute_netlink_event(mrt, c, RTM_NEWROUTE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | |
David S. Miller | 278554b | 2010-05-12 00:05:35 -0700 | [diff] [blame] | 1204 | if (atomic_read(&mrt->cache_resolve_queue_len) == 1) |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1205 | mod_timer(&mrt->ipmr_expire_timer, |
| 1206 | c->_c.mfc_un.unres.expires); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | } |
| 1208 | |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1209 | /* See if we can append the packet */ |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1210 | if (c->_c.mfc_un.unres.unresolved.qlen > 3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | kfree_skb(skb); |
| 1212 | err = -ENOBUFS; |
| 1213 | } else { |
Donald Sharp | 4b1f0d3 | 2017-06-10 16:30:17 -0400 | [diff] [blame] | 1214 | if (dev) { |
| 1215 | skb->dev = dev; |
| 1216 | skb->skb_iif = dev->ifindex; |
| 1217 | } |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1218 | skb_queue_tail(&c->_c.mfc_un.unres.unresolved, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | err = 0; |
| 1220 | } |
| 1221 | |
| 1222 | spin_unlock_bh(&mfc_unres_lock); |
| 1223 | return err; |
| 1224 | } |
| 1225 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 1226 | /* MFC cache manipulation by user space mroute daemon */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 1228 | static int ipmr_mfc_delete(struct mr_table *mrt, struct mfcctl *mfc, int parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | { |
Yotam Gigi | b362053 | 2017-09-27 08:23:14 +0200 | [diff] [blame] | 1230 | struct net *net = read_pnet(&mrt->net); |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 1231 | struct mfc_cache *c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 1233 | /* The entries are added/deleted only under RTNL */ |
| 1234 | rcu_read_lock(); |
| 1235 | c = ipmr_cache_find_parent(mrt, mfc->mfcc_origin.s_addr, |
| 1236 | mfc->mfcc_mcastgrp.s_addr, parent); |
| 1237 | rcu_read_unlock(); |
| 1238 | if (!c) |
| 1239 | return -ENOENT; |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1240 | rhltable_remove(&mrt->mfc_hash, &c->_c.mnode, ipmr_rht_params); |
| 1241 | list_del_rcu(&c->_c.list); |
Yotam Gigi | b362053 | 2017-09-27 08:23:14 +0200 | [diff] [blame] | 1242 | call_ipmr_mfc_entry_notifiers(net, FIB_EVENT_ENTRY_DEL, c, mrt->id); |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 1243 | mroute_netlink_event(mrt, c, RTM_DELROUTE); |
Yotam Gigi | 310ebbb | 2017-09-27 08:23:12 +0200 | [diff] [blame] | 1244 | ipmr_cache_put(c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 1246 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | } |
| 1248 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1249 | static int ipmr_mfc_add(struct net *net, struct mr_table *mrt, |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 1250 | struct mfcctl *mfc, int mrtsock, int parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | { |
Patrick McHardy | 862465f | 2010-04-13 05:03:21 +0000 | [diff] [blame] | 1252 | struct mfc_cache *uc, *c; |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1253 | struct mr_mfc *_uc; |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 1254 | bool found; |
| 1255 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | |
Patrick McHardy | a50436f2 | 2010-03-17 06:04:14 +0000 | [diff] [blame] | 1257 | if (mfc->mfcc_parent >= MAXVIFS) |
| 1258 | return -ENFILE; |
| 1259 | |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 1260 | /* The entries are added/deleted only under RTNL */ |
| 1261 | rcu_read_lock(); |
| 1262 | c = ipmr_cache_find_parent(mrt, mfc->mfcc_origin.s_addr, |
| 1263 | mfc->mfcc_mcastgrp.s_addr, parent); |
| 1264 | rcu_read_unlock(); |
| 1265 | if (c) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | write_lock_bh(&mrt_lock); |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1267 | c->_c.mfc_parent = mfc->mfcc_parent; |
| 1268 | ipmr_update_thresholds(mrt, &c->_c, mfc->mfcc_ttls); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | if (!mrtsock) |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1270 | c->_c.mfc_flags |= MFC_STATIC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | write_unlock_bh(&mrt_lock); |
Yotam Gigi | b362053 | 2017-09-27 08:23:14 +0200 | [diff] [blame] | 1272 | call_ipmr_mfc_entry_notifiers(net, FIB_EVENT_ENTRY_REPLACE, c, |
| 1273 | mrt->id); |
Nicolas Dichtel | 8cd3ac9 | 2012-12-04 01:13:40 +0000 | [diff] [blame] | 1274 | mroute_netlink_event(mrt, c, RTM_NEWROUTE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | return 0; |
| 1276 | } |
| 1277 | |
Nicolas Dichtel | 360eb5d | 2013-01-22 11:18:03 +0100 | [diff] [blame] | 1278 | if (mfc->mfcc_mcastgrp.s_addr != htonl(INADDR_ANY) && |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 1279 | !ipv4_is_multicast(mfc->mfcc_mcastgrp.s_addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | return -EINVAL; |
| 1281 | |
Patrick McHardy | d658f8a | 2010-04-13 05:03:20 +0000 | [diff] [blame] | 1282 | c = ipmr_cache_alloc(); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 1283 | if (!c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | return -ENOMEM; |
| 1285 | |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 1286 | c->mfc_origin = mfc->mfcc_origin.s_addr; |
| 1287 | c->mfc_mcastgrp = mfc->mfcc_mcastgrp.s_addr; |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1288 | c->_c.mfc_parent = mfc->mfcc_parent; |
| 1289 | ipmr_update_thresholds(mrt, &c->_c, mfc->mfcc_ttls); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | if (!mrtsock) |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1291 | c->_c.mfc_flags |= MFC_STATIC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1293 | ret = rhltable_insert_key(&mrt->mfc_hash, &c->cmparg, &c->_c.mnode, |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 1294 | ipmr_rht_params); |
| 1295 | if (ret) { |
| 1296 | pr_err("ipmr: rhtable insert error %d\n", ret); |
| 1297 | ipmr_cache_free(c); |
| 1298 | return ret; |
| 1299 | } |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1300 | list_add_tail_rcu(&c->_c.list, &mrt->mfc_cache_list); |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 1301 | /* Check to see if we resolved a queued list. If so we |
| 1302 | * need to send on the frames and tidy up. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | */ |
Patrick McHardy | b0ebb73 | 2010-04-15 13:29:28 +0200 | [diff] [blame] | 1304 | found = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | spin_lock_bh(&mfc_unres_lock); |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1306 | list_for_each_entry(_uc, &mrt->mfc_unres_queue, list) { |
| 1307 | uc = (struct mfc_cache *)_uc; |
Patrick McHardy | e258beb | 2010-04-13 05:03:19 +0000 | [diff] [blame] | 1308 | if (uc->mfc_origin == c->mfc_origin && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | uc->mfc_mcastgrp == c->mfc_mcastgrp) { |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1310 | list_del(&_uc->list); |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1311 | atomic_dec(&mrt->cache_resolve_queue_len); |
Patrick McHardy | b0ebb73 | 2010-04-15 13:29:28 +0200 | [diff] [blame] | 1312 | found = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | break; |
| 1314 | } |
| 1315 | } |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1316 | if (list_empty(&mrt->mfc_unres_queue)) |
| 1317 | del_timer(&mrt->ipmr_expire_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | spin_unlock_bh(&mfc_unres_lock); |
| 1319 | |
Patrick McHardy | b0ebb73 | 2010-04-15 13:29:28 +0200 | [diff] [blame] | 1320 | if (found) { |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1321 | ipmr_cache_resolve(net, mrt, uc, c); |
Benjamin Thery | 5c0a66f | 2009-01-22 04:56:17 +0000 | [diff] [blame] | 1322 | ipmr_cache_free(uc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | } |
Yotam Gigi | b362053 | 2017-09-27 08:23:14 +0200 | [diff] [blame] | 1324 | call_ipmr_mfc_entry_notifiers(net, FIB_EVENT_ENTRY_ADD, c, mrt->id); |
Nicolas Dichtel | 8cd3ac9 | 2012-12-04 01:13:40 +0000 | [diff] [blame] | 1325 | mroute_netlink_event(mrt, c, RTM_NEWROUTE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | return 0; |
| 1327 | } |
| 1328 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 1329 | /* Close the multicast socket, and clear the vif tables etc */ |
Nikolay Aleksandrov | 0e615e9 | 2015-11-20 13:54:19 +0100 | [diff] [blame] | 1330 | static void mroute_clean_tables(struct mr_table *mrt, bool all) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | { |
Yotam Gigi | b362053 | 2017-09-27 08:23:14 +0200 | [diff] [blame] | 1332 | struct net *net = read_pnet(&mrt->net); |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1333 | struct mr_mfc *c, *tmp; |
| 1334 | struct mfc_cache *cache; |
Eric Dumazet | d17fa6f | 2009-10-28 05:21:38 +0000 | [diff] [blame] | 1335 | LIST_HEAD(list); |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 1336 | int i; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1337 | |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1338 | /* Shut down all active vif entries */ |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1339 | for (i = 0; i < mrt->maxvif; i++) { |
Nikolay Aleksandrov | 0e615e9 | 2015-11-20 13:54:19 +0100 | [diff] [blame] | 1340 | if (!all && (mrt->vif_table[i].flags & VIFF_STATIC)) |
| 1341 | continue; |
| 1342 | vif_delete(mrt, i, 0, &list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | } |
Eric Dumazet | d17fa6f | 2009-10-28 05:21:38 +0000 | [diff] [blame] | 1344 | unregister_netdevice_many(&list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1346 | /* Wipe the cache */ |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 1347 | list_for_each_entry_safe(c, tmp, &mrt->mfc_cache_list, list) { |
| 1348 | if (!all && (c->mfc_flags & MFC_STATIC)) |
| 1349 | continue; |
| 1350 | rhltable_remove(&mrt->mfc_hash, &c->mnode, ipmr_rht_params); |
| 1351 | list_del_rcu(&c->list); |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1352 | cache = (struct mfc_cache *)c; |
| 1353 | call_ipmr_mfc_entry_notifiers(net, FIB_EVENT_ENTRY_DEL, cache, |
Yotam Gigi | b362053 | 2017-09-27 08:23:14 +0200 | [diff] [blame] | 1354 | mrt->id); |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1355 | mroute_netlink_event(mrt, cache, RTM_DELROUTE); |
| 1356 | ipmr_cache_put(cache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1359 | if (atomic_read(&mrt->cache_resolve_queue_len) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | spin_lock_bh(&mfc_unres_lock); |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 1361 | list_for_each_entry_safe(c, tmp, &mrt->mfc_unres_queue, list) { |
Patrick McHardy | 862465f | 2010-04-13 05:03:21 +0000 | [diff] [blame] | 1362 | list_del(&c->list); |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1363 | cache = (struct mfc_cache *)c; |
| 1364 | mroute_netlink_event(mrt, cache, RTM_DELROUTE); |
| 1365 | ipmr_destroy_unres(mrt, cache); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | } |
| 1367 | spin_unlock_bh(&mfc_unres_lock); |
| 1368 | } |
| 1369 | } |
| 1370 | |
Eric Dumazet | 4c968709 | 2010-10-01 16:15:01 +0000 | [diff] [blame] | 1371 | /* called from ip_ra_control(), before an RCU grace period, |
| 1372 | * we dont need to call synchronize_rcu() here |
| 1373 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | static void mrtsock_destruct(struct sock *sk) |
| 1375 | { |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 1376 | struct net *net = sock_net(sk); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 1377 | struct mr_table *mrt; |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 1378 | |
WANG Cong | 1215e51 | 2017-04-12 12:32:13 -0700 | [diff] [blame] | 1379 | ASSERT_RTNL(); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 1380 | ipmr_for_each_table(mrt, net) { |
Eric Dumazet | 4c968709 | 2010-10-01 16:15:01 +0000 | [diff] [blame] | 1381 | if (sk == rtnl_dereference(mrt->mroute_sk)) { |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 1382 | IPV4_DEVCONF_ALL(net, MC_FORWARDING)--; |
David Ahern | 3b02286 | 2017-03-28 14:28:02 -0700 | [diff] [blame] | 1383 | inet_netconf_notify_devconf(net, RTM_NEWNETCONF, |
| 1384 | NETCONFA_MC_FORWARDING, |
Nicolas Dichtel | d67b8c6 | 2012-12-04 01:13:35 +0000 | [diff] [blame] | 1385 | NETCONFA_IFINDEX_ALL, |
| 1386 | net->ipv4.devconf_all); |
Stephen Hemminger | a9b3cd7 | 2011-08-01 16:19:00 +0000 | [diff] [blame] | 1387 | RCU_INIT_POINTER(mrt->mroute_sk, NULL); |
Nikolay Aleksandrov | 0e615e9 | 2015-11-20 13:54:19 +0100 | [diff] [blame] | 1388 | mroute_clean_tables(mrt, false); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 1389 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | } |
| 1392 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 1393 | /* Socket options and virtual interface manipulation. The whole |
| 1394 | * virtual interface system is a complete heap, but unfortunately |
| 1395 | * that's how BSD mrouted happens to think. Maybe one day with a proper |
| 1396 | * MOSPF/PIM router set up we can clean this up. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | */ |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1398 | |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1399 | int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, |
| 1400 | unsigned int optlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | { |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1402 | struct net *net = sock_net(sk); |
| 1403 | int val, ret = 0, parent = 0; |
| 1404 | struct mr_table *mrt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | struct vifctl vif; |
| 1406 | struct mfcctl mfc; |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1407 | u32 uval; |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 1408 | |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1409 | /* There's one exception to the lock - MRT_DONE which needs to unlock */ |
| 1410 | rtnl_lock(); |
Eric Dumazet | 5e1859f | 2012-11-25 06:41:45 +0000 | [diff] [blame] | 1411 | if (sk->sk_type != SOCK_RAW || |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1412 | inet_sk(sk)->inet_num != IPPROTO_IGMP) { |
| 1413 | ret = -EOPNOTSUPP; |
| 1414 | goto out_unlock; |
| 1415 | } |
Eric Dumazet | 5e1859f | 2012-11-25 06:41:45 +0000 | [diff] [blame] | 1416 | |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 1417 | mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT); |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1418 | if (!mrt) { |
| 1419 | ret = -ENOENT; |
| 1420 | goto out_unlock; |
| 1421 | } |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1422 | if (optname != MRT_INIT) { |
Eric Dumazet | 33d480c | 2011-08-11 19:30:52 +0000 | [diff] [blame] | 1423 | if (sk != rcu_access_pointer(mrt->mroute_sk) && |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1424 | !ns_capable(net->user_ns, CAP_NET_ADMIN)) { |
| 1425 | ret = -EACCES; |
| 1426 | goto out_unlock; |
| 1427 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1430 | switch (optname) { |
| 1431 | case MRT_INIT: |
Nikolay Aleksandrov | 42e6b89 | 2015-11-26 15:23:49 +0100 | [diff] [blame] | 1432 | if (optlen != sizeof(int)) { |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1433 | ret = -EINVAL; |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1434 | break; |
Nikolay Aleksandrov | 42e6b89 | 2015-11-26 15:23:49 +0100 | [diff] [blame] | 1435 | } |
| 1436 | if (rtnl_dereference(mrt->mroute_sk)) { |
| 1437 | ret = -EADDRINUSE; |
| 1438 | break; |
| 1439 | } |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1440 | |
| 1441 | ret = ip_ra_control(sk, 1, mrtsock_destruct); |
| 1442 | if (ret == 0) { |
Eric Dumazet | cf778b0 | 2012-01-12 04:41:32 +0000 | [diff] [blame] | 1443 | rcu_assign_pointer(mrt->mroute_sk, sk); |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 1444 | IPV4_DEVCONF_ALL(net, MC_FORWARDING)++; |
David Ahern | 3b02286 | 2017-03-28 14:28:02 -0700 | [diff] [blame] | 1445 | inet_netconf_notify_devconf(net, RTM_NEWNETCONF, |
| 1446 | NETCONFA_MC_FORWARDING, |
Nicolas Dichtel | d67b8c6 | 2012-12-04 01:13:35 +0000 | [diff] [blame] | 1447 | NETCONFA_IFINDEX_ALL, |
| 1448 | net->ipv4.devconf_all); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1449 | } |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1450 | break; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1451 | case MRT_DONE: |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1452 | if (sk != rcu_access_pointer(mrt->mroute_sk)) { |
| 1453 | ret = -EACCES; |
| 1454 | } else { |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1455 | ret = ip_ra_control(sk, 0, NULL); |
WANG Cong | 1215e51 | 2017-04-12 12:32:13 -0700 | [diff] [blame] | 1456 | goto out_unlock; |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1457 | } |
| 1458 | break; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1459 | case MRT_ADD_VIF: |
| 1460 | case MRT_DEL_VIF: |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1461 | if (optlen != sizeof(vif)) { |
| 1462 | ret = -EINVAL; |
| 1463 | break; |
| 1464 | } |
| 1465 | if (copy_from_user(&vif, optval, sizeof(vif))) { |
| 1466 | ret = -EFAULT; |
| 1467 | break; |
| 1468 | } |
| 1469 | if (vif.vifc_vifi >= MAXVIFS) { |
| 1470 | ret = -ENFILE; |
| 1471 | break; |
| 1472 | } |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 1473 | if (optname == MRT_ADD_VIF) { |
Eric Dumazet | 4c968709 | 2010-10-01 16:15:01 +0000 | [diff] [blame] | 1474 | ret = vif_add(net, mrt, &vif, |
| 1475 | sk == rtnl_dereference(mrt->mroute_sk)); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1476 | } else { |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1477 | ret = vif_delete(mrt, vif.vifc_vifi, 0, NULL); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1478 | } |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1479 | break; |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 1480 | /* Manipulate the forwarding caches. These live |
| 1481 | * in a sort of kernel/user symbiosis. |
| 1482 | */ |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1483 | case MRT_ADD_MFC: |
| 1484 | case MRT_DEL_MFC: |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 1485 | parent = -1; |
Gustavo A. R. Silva | fcfd6df | 2017-10-16 15:48:55 -0500 | [diff] [blame] | 1486 | /* fall through */ |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 1487 | case MRT_ADD_MFC_PROXY: |
| 1488 | case MRT_DEL_MFC_PROXY: |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1489 | if (optlen != sizeof(mfc)) { |
| 1490 | ret = -EINVAL; |
| 1491 | break; |
| 1492 | } |
| 1493 | if (copy_from_user(&mfc, optval, sizeof(mfc))) { |
| 1494 | ret = -EFAULT; |
| 1495 | break; |
| 1496 | } |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 1497 | if (parent == 0) |
| 1498 | parent = mfc.mfcc_parent; |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 1499 | if (optname == MRT_DEL_MFC || optname == MRT_DEL_MFC_PROXY) |
| 1500 | ret = ipmr_mfc_delete(mrt, &mfc, parent); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1501 | else |
Eric Dumazet | 4c968709 | 2010-10-01 16:15:01 +0000 | [diff] [blame] | 1502 | ret = ipmr_mfc_add(net, mrt, &mfc, |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 1503 | sk == rtnl_dereference(mrt->mroute_sk), |
| 1504 | parent); |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1505 | break; |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 1506 | /* Control PIM assert. */ |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1507 | case MRT_ASSERT: |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1508 | if (optlen != sizeof(val)) { |
| 1509 | ret = -EINVAL; |
| 1510 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | } |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1512 | if (get_user(val, (int __user *)optval)) { |
| 1513 | ret = -EFAULT; |
| 1514 | break; |
| 1515 | } |
| 1516 | mrt->mroute_do_assert = val; |
| 1517 | break; |
| 1518 | case MRT_PIM: |
Nikolay Aleksandrov | 1973a4e | 2015-11-26 15:23:48 +0100 | [diff] [blame] | 1519 | if (!ipmr_pimsm_enabled()) { |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1520 | ret = -ENOPROTOOPT; |
| 1521 | break; |
| 1522 | } |
| 1523 | if (optlen != sizeof(val)) { |
| 1524 | ret = -EINVAL; |
| 1525 | break; |
| 1526 | } |
| 1527 | if (get_user(val, (int __user *)optval)) { |
| 1528 | ret = -EFAULT; |
| 1529 | break; |
| 1530 | } |
| 1531 | |
| 1532 | val = !!val; |
| 1533 | if (val != mrt->mroute_do_pim) { |
| 1534 | mrt->mroute_do_pim = val; |
| 1535 | mrt->mroute_do_assert = val; |
| 1536 | } |
| 1537 | break; |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 1538 | case MRT_TABLE: |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1539 | if (!IS_BUILTIN(CONFIG_IP_MROUTE_MULTIPLE_TABLES)) { |
| 1540 | ret = -ENOPROTOOPT; |
| 1541 | break; |
| 1542 | } |
| 1543 | if (optlen != sizeof(uval)) { |
| 1544 | ret = -EINVAL; |
| 1545 | break; |
| 1546 | } |
| 1547 | if (get_user(uval, (u32 __user *)optval)) { |
| 1548 | ret = -EFAULT; |
| 1549 | break; |
| 1550 | } |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 1551 | |
Eric Dumazet | 4c968709 | 2010-10-01 16:15:01 +0000 | [diff] [blame] | 1552 | if (sk == rtnl_dereference(mrt->mroute_sk)) { |
| 1553 | ret = -EBUSY; |
| 1554 | } else { |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1555 | mrt = ipmr_new_table(net, uval); |
Nikolay Aleksandrov | 1113ebb | 2015-11-21 15:57:24 +0100 | [diff] [blame] | 1556 | if (IS_ERR(mrt)) |
| 1557 | ret = PTR_ERR(mrt); |
Eric Dumazet | 5e1859f | 2012-11-25 06:41:45 +0000 | [diff] [blame] | 1558 | else |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1559 | raw_sk(sk)->ipmr_table = uval; |
Eric Dumazet | 4c968709 | 2010-10-01 16:15:01 +0000 | [diff] [blame] | 1560 | } |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1561 | break; |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 1562 | /* Spurious command, or MRT_VERSION which you cannot set. */ |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1563 | default: |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1564 | ret = -ENOPROTOOPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | } |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1566 | out_unlock: |
| 1567 | rtnl_unlock(); |
Nikolay Aleksandrov | 29e97d2 | 2015-11-21 15:57:31 +0100 | [diff] [blame] | 1568 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | } |
| 1570 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 1571 | /* Getsock opt support for the multicast routing system. */ |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 1572 | int ip_mroute_getsockopt(struct sock *sk, int optname, char __user *optval, int __user *optlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | { |
| 1574 | int olr; |
| 1575 | int val; |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 1576 | struct net *net = sock_net(sk); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 1577 | struct mr_table *mrt; |
| 1578 | |
Eric Dumazet | 5e1859f | 2012-11-25 06:41:45 +0000 | [diff] [blame] | 1579 | if (sk->sk_type != SOCK_RAW || |
| 1580 | inet_sk(sk)->inet_num != IPPROTO_IGMP) |
| 1581 | return -EOPNOTSUPP; |
| 1582 | |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 1583 | mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 1584 | if (!mrt) |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 1585 | return -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | |
Nikolay Aleksandrov | fe9ef3c | 2015-11-21 15:57:28 +0100 | [diff] [blame] | 1587 | switch (optname) { |
| 1588 | case MRT_VERSION: |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 1589 | val = 0x0305; |
Nikolay Aleksandrov | fe9ef3c | 2015-11-21 15:57:28 +0100 | [diff] [blame] | 1590 | break; |
| 1591 | case MRT_PIM: |
Nikolay Aleksandrov | 1973a4e | 2015-11-26 15:23:48 +0100 | [diff] [blame] | 1592 | if (!ipmr_pimsm_enabled()) |
Nikolay Aleksandrov | c316c62 | 2015-11-21 15:57:26 +0100 | [diff] [blame] | 1593 | return -ENOPROTOOPT; |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1594 | val = mrt->mroute_do_pim; |
Nikolay Aleksandrov | fe9ef3c | 2015-11-21 15:57:28 +0100 | [diff] [blame] | 1595 | break; |
| 1596 | case MRT_ASSERT: |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1597 | val = mrt->mroute_do_assert; |
Nikolay Aleksandrov | fe9ef3c | 2015-11-21 15:57:28 +0100 | [diff] [blame] | 1598 | break; |
| 1599 | default: |
| 1600 | return -ENOPROTOOPT; |
Nikolay Aleksandrov | c316c62 | 2015-11-21 15:57:26 +0100 | [diff] [blame] | 1601 | } |
Nikolay Aleksandrov | fe9ef3c | 2015-11-21 15:57:28 +0100 | [diff] [blame] | 1602 | |
| 1603 | if (get_user(olr, optlen)) |
| 1604 | return -EFAULT; |
| 1605 | olr = min_t(unsigned int, olr, sizeof(int)); |
| 1606 | if (olr < 0) |
| 1607 | return -EINVAL; |
| 1608 | if (put_user(olr, optlen)) |
| 1609 | return -EFAULT; |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 1610 | if (copy_to_user(optval, &val, olr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | return -EFAULT; |
| 1612 | return 0; |
| 1613 | } |
| 1614 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 1615 | /* The IP multicast ioctl support routines. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg) |
| 1617 | { |
| 1618 | struct sioc_sg_req sr; |
| 1619 | struct sioc_vif_req vr; |
| 1620 | struct vif_device *vif; |
| 1621 | struct mfc_cache *c; |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 1622 | struct net *net = sock_net(sk); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 1623 | struct mr_table *mrt; |
| 1624 | |
| 1625 | mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 1626 | if (!mrt) |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 1627 | return -ENOENT; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1628 | |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1629 | switch (cmd) { |
| 1630 | case SIOCGETVIFCNT: |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 1631 | if (copy_from_user(&vr, arg, sizeof(vr))) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1632 | return -EFAULT; |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1633 | if (vr.vifi >= mrt->maxvif) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1634 | return -EINVAL; |
| 1635 | read_lock(&mrt_lock); |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1636 | vif = &mrt->vif_table[vr.vifi]; |
| 1637 | if (VIF_EXISTS(mrt, vr.vifi)) { |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 1638 | vr.icount = vif->pkt_in; |
| 1639 | vr.ocount = vif->pkt_out; |
| 1640 | vr.ibytes = vif->bytes_in; |
| 1641 | vr.obytes = vif->bytes_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | read_unlock(&mrt_lock); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1643 | |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 1644 | if (copy_to_user(arg, &vr, sizeof(vr))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | return -EFAULT; |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1646 | return 0; |
| 1647 | } |
| 1648 | read_unlock(&mrt_lock); |
| 1649 | return -EADDRNOTAVAIL; |
| 1650 | case SIOCGETSGCNT: |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 1651 | if (copy_from_user(&sr, arg, sizeof(sr))) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1652 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 1654 | rcu_read_lock(); |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1655 | c = ipmr_cache_find(mrt, sr.src.s_addr, sr.grp.s_addr); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1656 | if (c) { |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1657 | sr.pktcnt = c->_c.mfc_un.res.pkt; |
| 1658 | sr.bytecnt = c->_c.mfc_un.res.bytes; |
| 1659 | sr.wrong_if = c->_c.mfc_un.res.wrong_if; |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 1660 | rcu_read_unlock(); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1661 | |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 1662 | if (copy_to_user(arg, &sr, sizeof(sr))) |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1663 | return -EFAULT; |
| 1664 | return 0; |
| 1665 | } |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 1666 | rcu_read_unlock(); |
Stephen Hemminger | 132adf5 | 2007-03-08 20:44:43 -0800 | [diff] [blame] | 1667 | return -EADDRNOTAVAIL; |
| 1668 | default: |
| 1669 | return -ENOIOCTLCMD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | } |
| 1671 | } |
| 1672 | |
Eric W. Biederman | 709b46e | 2011-01-29 16:15:56 +0000 | [diff] [blame] | 1673 | #ifdef CONFIG_COMPAT |
| 1674 | struct compat_sioc_sg_req { |
| 1675 | struct in_addr src; |
| 1676 | struct in_addr grp; |
| 1677 | compat_ulong_t pktcnt; |
| 1678 | compat_ulong_t bytecnt; |
| 1679 | compat_ulong_t wrong_if; |
| 1680 | }; |
| 1681 | |
David S. Miller | ca6b8bb0 | 2011-02-03 17:24:28 -0800 | [diff] [blame] | 1682 | struct compat_sioc_vif_req { |
| 1683 | vifi_t vifi; /* Which iface */ |
| 1684 | compat_ulong_t icount; |
| 1685 | compat_ulong_t ocount; |
| 1686 | compat_ulong_t ibytes; |
| 1687 | compat_ulong_t obytes; |
| 1688 | }; |
| 1689 | |
Eric W. Biederman | 709b46e | 2011-01-29 16:15:56 +0000 | [diff] [blame] | 1690 | int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg) |
| 1691 | { |
David S. Miller | 0033d5a | 2011-02-03 17:21:31 -0800 | [diff] [blame] | 1692 | struct compat_sioc_sg_req sr; |
David S. Miller | ca6b8bb0 | 2011-02-03 17:24:28 -0800 | [diff] [blame] | 1693 | struct compat_sioc_vif_req vr; |
| 1694 | struct vif_device *vif; |
Eric W. Biederman | 709b46e | 2011-01-29 16:15:56 +0000 | [diff] [blame] | 1695 | struct mfc_cache *c; |
| 1696 | struct net *net = sock_net(sk); |
| 1697 | struct mr_table *mrt; |
| 1698 | |
| 1699 | mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 1700 | if (!mrt) |
Eric W. Biederman | 709b46e | 2011-01-29 16:15:56 +0000 | [diff] [blame] | 1701 | return -ENOENT; |
| 1702 | |
| 1703 | switch (cmd) { |
David S. Miller | ca6b8bb0 | 2011-02-03 17:24:28 -0800 | [diff] [blame] | 1704 | case SIOCGETVIFCNT: |
| 1705 | if (copy_from_user(&vr, arg, sizeof(vr))) |
| 1706 | return -EFAULT; |
| 1707 | if (vr.vifi >= mrt->maxvif) |
| 1708 | return -EINVAL; |
| 1709 | read_lock(&mrt_lock); |
| 1710 | vif = &mrt->vif_table[vr.vifi]; |
| 1711 | if (VIF_EXISTS(mrt, vr.vifi)) { |
| 1712 | vr.icount = vif->pkt_in; |
| 1713 | vr.ocount = vif->pkt_out; |
| 1714 | vr.ibytes = vif->bytes_in; |
| 1715 | vr.obytes = vif->bytes_out; |
| 1716 | read_unlock(&mrt_lock); |
| 1717 | |
| 1718 | if (copy_to_user(arg, &vr, sizeof(vr))) |
| 1719 | return -EFAULT; |
| 1720 | return 0; |
| 1721 | } |
| 1722 | read_unlock(&mrt_lock); |
| 1723 | return -EADDRNOTAVAIL; |
Eric W. Biederman | 709b46e | 2011-01-29 16:15:56 +0000 | [diff] [blame] | 1724 | case SIOCGETSGCNT: |
| 1725 | if (copy_from_user(&sr, arg, sizeof(sr))) |
| 1726 | return -EFAULT; |
| 1727 | |
| 1728 | rcu_read_lock(); |
| 1729 | c = ipmr_cache_find(mrt, sr.src.s_addr, sr.grp.s_addr); |
| 1730 | if (c) { |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1731 | sr.pktcnt = c->_c.mfc_un.res.pkt; |
| 1732 | sr.bytecnt = c->_c.mfc_un.res.bytes; |
| 1733 | sr.wrong_if = c->_c.mfc_un.res.wrong_if; |
Eric W. Biederman | 709b46e | 2011-01-29 16:15:56 +0000 | [diff] [blame] | 1734 | rcu_read_unlock(); |
| 1735 | |
| 1736 | if (copy_to_user(arg, &sr, sizeof(sr))) |
| 1737 | return -EFAULT; |
| 1738 | return 0; |
| 1739 | } |
| 1740 | rcu_read_unlock(); |
| 1741 | return -EADDRNOTAVAIL; |
| 1742 | default: |
| 1743 | return -ENOIOCTLCMD; |
| 1744 | } |
| 1745 | } |
| 1746 | #endif |
| 1747 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | static int ipmr_device_event(struct notifier_block *this, unsigned long event, void *ptr) |
| 1749 | { |
Jiri Pirko | 351638e | 2013-05-28 01:30:21 +0000 | [diff] [blame] | 1750 | struct net_device *dev = netdev_notifier_info_to_dev(ptr); |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 1751 | struct net *net = dev_net(dev); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 1752 | struct mr_table *mrt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | struct vif_device *v; |
| 1754 | int ct; |
Eric W. Biederman | e9dc865 | 2007-09-12 13:02:17 +0200 | [diff] [blame] | 1755 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | if (event != NETDEV_UNREGISTER) |
| 1757 | return NOTIFY_DONE; |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 1758 | |
| 1759 | ipmr_for_each_table(mrt, net) { |
| 1760 | v = &mrt->vif_table[0]; |
| 1761 | for (ct = 0; ct < mrt->maxvif; ct++, v++) { |
| 1762 | if (v->dev == dev) |
RongQing.Li | e92036a | 2011-11-23 23:10:52 +0000 | [diff] [blame] | 1763 | vif_delete(mrt, ct, 1, NULL); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 1764 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | } |
| 1766 | return NOTIFY_DONE; |
| 1767 | } |
| 1768 | |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 1769 | static struct notifier_block ip_mr_notifier = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | .notifier_call = ipmr_device_event, |
| 1771 | }; |
| 1772 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 1773 | /* Encapsulate a packet by attaching a valid IPIP header to it. |
| 1774 | * This avoids tunnel drivers and other mess and gives us the speed so |
| 1775 | * important for multicast video. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | */ |
Hannes Frederic Sowa | b6a7719 | 2015-03-25 17:07:44 +0100 | [diff] [blame] | 1777 | static void ip_encap(struct net *net, struct sk_buff *skb, |
| 1778 | __be32 saddr, __be32 daddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | { |
Arnaldo Carvalho de Melo | 8856dfa | 2007-03-10 19:40:39 -0300 | [diff] [blame] | 1780 | struct iphdr *iph; |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 1781 | const struct iphdr *old_iph = ip_hdr(skb); |
Arnaldo Carvalho de Melo | 8856dfa | 2007-03-10 19:40:39 -0300 | [diff] [blame] | 1782 | |
| 1783 | skb_push(skb, sizeof(struct iphdr)); |
Arnaldo Carvalho de Melo | b0e380b | 2007-04-10 21:21:55 -0700 | [diff] [blame] | 1784 | skb->transport_header = skb->network_header; |
Arnaldo Carvalho de Melo | 8856dfa | 2007-03-10 19:40:39 -0300 | [diff] [blame] | 1785 | skb_reset_network_header(skb); |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1786 | iph = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1788 | iph->version = 4; |
Arnaldo Carvalho de Melo | e023dd6 | 2007-03-12 20:09:36 -0300 | [diff] [blame] | 1789 | iph->tos = old_iph->tos; |
| 1790 | iph->ttl = old_iph->ttl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | iph->frag_off = 0; |
| 1792 | iph->daddr = daddr; |
| 1793 | iph->saddr = saddr; |
| 1794 | iph->protocol = IPPROTO_IPIP; |
| 1795 | iph->ihl = 5; |
| 1796 | iph->tot_len = htons(skb->len); |
Hannes Frederic Sowa | b6a7719 | 2015-03-25 17:07:44 +0100 | [diff] [blame] | 1797 | ip_select_ident(net, skb, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | ip_send_check(iph); |
| 1799 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); |
| 1801 | nf_reset(skb); |
| 1802 | } |
| 1803 | |
Eric W. Biederman | 0c4b51f | 2015-09-15 20:04:18 -0500 | [diff] [blame] | 1804 | static inline int ipmr_forward_finish(struct net *net, struct sock *sk, |
| 1805 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | { |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1807 | struct ip_options *opt = &(IPCB(skb)->opt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | |
David S. Miller | 73186df | 2015-11-03 13:41:45 -0500 | [diff] [blame] | 1809 | IP_INC_STATS(net, IPSTATS_MIB_OUTFORWDATAGRAMS); |
| 1810 | IP_ADD_STATS(net, IPSTATS_MIB_OUTOCTETS, skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | |
| 1812 | if (unlikely(opt->optlen)) |
| 1813 | ip_forward_options(skb); |
| 1814 | |
Eric W. Biederman | 13206b6 | 2015-10-07 16:48:35 -0500 | [diff] [blame] | 1815 | return dst_output(net, sk, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | } |
| 1817 | |
Yotam Gigi | a5bc929 | 2017-10-03 09:58:08 +0200 | [diff] [blame] | 1818 | #ifdef CONFIG_NET_SWITCHDEV |
| 1819 | static bool ipmr_forward_offloaded(struct sk_buff *skb, struct mr_table *mrt, |
| 1820 | int in_vifi, int out_vifi) |
| 1821 | { |
| 1822 | struct vif_device *out_vif = &mrt->vif_table[out_vifi]; |
| 1823 | struct vif_device *in_vif = &mrt->vif_table[in_vifi]; |
| 1824 | |
| 1825 | if (!skb->offload_mr_fwd_mark) |
| 1826 | return false; |
| 1827 | if (!out_vif->dev_parent_id.id_len || !in_vif->dev_parent_id.id_len) |
| 1828 | return false; |
| 1829 | return netdev_phys_item_id_same(&out_vif->dev_parent_id, |
| 1830 | &in_vif->dev_parent_id); |
| 1831 | } |
| 1832 | #else |
| 1833 | static bool ipmr_forward_offloaded(struct sk_buff *skb, struct mr_table *mrt, |
| 1834 | int in_vifi, int out_vifi) |
| 1835 | { |
| 1836 | return false; |
| 1837 | } |
| 1838 | #endif |
| 1839 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 1840 | /* Processing handlers for ipmr_forward */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1842 | static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt, |
Yotam Gigi | a5bc929 | 2017-10-03 09:58:08 +0200 | [diff] [blame] | 1843 | int in_vifi, struct sk_buff *skb, |
| 1844 | struct mfc_cache *c, int vifi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1846 | const struct iphdr *iph = ip_hdr(skb); |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1847 | struct vif_device *vif = &mrt->vif_table[vifi]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | struct net_device *dev; |
| 1849 | struct rtable *rt; |
David S. Miller | 31e4543d | 2011-05-03 20:25:42 -0700 | [diff] [blame] | 1850 | struct flowi4 fl4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | int encap = 0; |
| 1852 | |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 1853 | if (!vif->dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | goto out_free; |
| 1855 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | if (vif->flags & VIFF_REGISTER) { |
| 1857 | vif->pkt_out++; |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 1858 | vif->bytes_out += skb->len; |
Pavel Emelyanov | cf3677a | 2008-05-21 14:17:33 -0700 | [diff] [blame] | 1859 | vif->dev->stats.tx_bytes += skb->len; |
| 1860 | vif->dev->stats.tx_packets++; |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1861 | ipmr_cache_report(mrt, skb, vifi, IGMPMSG_WHOLEPKT); |
Ilpo Järvinen | 69ebbf5 | 2009-02-06 23:46:51 -0800 | [diff] [blame] | 1862 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | |
Yotam Gigi | a5bc929 | 2017-10-03 09:58:08 +0200 | [diff] [blame] | 1865 | if (ipmr_forward_offloaded(skb, mrt, in_vifi, vifi)) |
| 1866 | goto out_free; |
| 1867 | |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1868 | if (vif->flags & VIFF_TUNNEL) { |
David S. Miller | 31e4543d | 2011-05-03 20:25:42 -0700 | [diff] [blame] | 1869 | rt = ip_route_output_ports(net, &fl4, NULL, |
David S. Miller | 78fbfd8 | 2011-03-12 00:00:52 -0500 | [diff] [blame] | 1870 | vif->remote, vif->local, |
| 1871 | 0, 0, |
| 1872 | IPPROTO_IPIP, |
| 1873 | RT_TOS(iph->tos), vif->link); |
David S. Miller | b23dd4f | 2011-03-02 14:31:35 -0800 | [diff] [blame] | 1874 | if (IS_ERR(rt)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | goto out_free; |
| 1876 | encap = sizeof(struct iphdr); |
| 1877 | } else { |
David S. Miller | 31e4543d | 2011-05-03 20:25:42 -0700 | [diff] [blame] | 1878 | rt = ip_route_output_ports(net, &fl4, NULL, iph->daddr, 0, |
David S. Miller | 78fbfd8 | 2011-03-12 00:00:52 -0500 | [diff] [blame] | 1879 | 0, 0, |
| 1880 | IPPROTO_IPIP, |
| 1881 | RT_TOS(iph->tos), vif->link); |
David S. Miller | b23dd4f | 2011-03-02 14:31:35 -0800 | [diff] [blame] | 1882 | if (IS_ERR(rt)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | goto out_free; |
| 1884 | } |
| 1885 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1886 | dev = rt->dst.dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1888 | if (skb->len+encap > dst_mtu(&rt->dst) && (ntohs(iph->frag_off) & IP_DF)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | /* Do not fragment multicasts. Alas, IPv4 does not |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1890 | * allow to send ICMP, so that packets will disappear |
| 1891 | * to blackhole. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | */ |
David S. Miller | 73186df | 2015-11-03 13:41:45 -0500 | [diff] [blame] | 1893 | IP_INC_STATS(net, IPSTATS_MIB_FRAGFAILS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | ip_rt_put(rt); |
| 1895 | goto out_free; |
| 1896 | } |
| 1897 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1898 | encap += LL_RESERVED_SPACE(dev) + rt->dst.header_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | |
| 1900 | if (skb_cow(skb, encap)) { |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1901 | ip_rt_put(rt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | goto out_free; |
| 1903 | } |
| 1904 | |
| 1905 | vif->pkt_out++; |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 1906 | vif->bytes_out += skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | |
Eric Dumazet | adf3090 | 2009-06-02 05:19:30 +0000 | [diff] [blame] | 1908 | skb_dst_drop(skb); |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1909 | skb_dst_set(skb, &rt->dst); |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1910 | ip_decrease_ttl(ip_hdr(skb)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | |
| 1912 | /* FIXME: forward and output firewalls used to be called here. |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1913 | * What do we do with netfilter? -- RR |
| 1914 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | if (vif->flags & VIFF_TUNNEL) { |
Hannes Frederic Sowa | b6a7719 | 2015-03-25 17:07:44 +0100 | [diff] [blame] | 1916 | ip_encap(net, skb, vif->local, vif->remote); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | /* FIXME: extra output firewall step used to be here. --RR */ |
Pavel Emelyanov | 2f4c02d | 2008-05-21 14:16:14 -0700 | [diff] [blame] | 1918 | vif->dev->stats.tx_packets++; |
| 1919 | vif->dev->stats.tx_bytes += skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | } |
| 1921 | |
Lance Richardson | 9ee6c5d | 2016-11-02 16:36:17 -0400 | [diff] [blame] | 1922 | IPCB(skb)->flags |= IPSKB_FORWARDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 1924 | /* RFC1584 teaches, that DVMRP/PIM router must deliver packets locally |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | * not only before forwarding, but after forwarding on all output |
| 1926 | * interfaces. It is clear, if mrouter runs a multicasting |
| 1927 | * program, it should receive packets not depending to what interface |
| 1928 | * program is joined. |
| 1929 | * If we will not make it, the program will have to join on all |
| 1930 | * interfaces. On the other hand, multihoming host (or router, but |
| 1931 | * not mrouter) cannot join to more than one interface - it will |
| 1932 | * result in receiving multiple packets. |
| 1933 | */ |
Eric W. Biederman | 29a26a5 | 2015-09-15 20:04:16 -0500 | [diff] [blame] | 1934 | NF_HOOK(NFPROTO_IPV4, NF_INET_FORWARD, |
| 1935 | net, NULL, skb, skb->dev, dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | ipmr_forward_finish); |
| 1937 | return; |
| 1938 | |
| 1939 | out_free: |
| 1940 | kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | } |
| 1942 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1943 | static int ipmr_find_vif(struct mr_table *mrt, struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | { |
| 1945 | int ct; |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1946 | |
| 1947 | for (ct = mrt->maxvif-1; ct >= 0; ct--) { |
| 1948 | if (mrt->vif_table[ct].dev == dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | break; |
| 1950 | } |
| 1951 | return ct; |
| 1952 | } |
| 1953 | |
| 1954 | /* "local" means that we should preserve one skb (for local delivery) */ |
Rami Rosen | c4854ec | 2013-07-20 15:09:28 +0300 | [diff] [blame] | 1955 | static void ip_mr_forward(struct net *net, struct mr_table *mrt, |
Donald Sharp | 4b1f0d3 | 2017-06-10 16:30:17 -0400 | [diff] [blame] | 1956 | struct net_device *dev, struct sk_buff *skb, |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1957 | struct mfc_cache *c, int local) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | { |
Donald Sharp | 4b1f0d3 | 2017-06-10 16:30:17 -0400 | [diff] [blame] | 1959 | int true_vifi = ipmr_find_vif(mrt, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | int psend = -1; |
| 1961 | int vif, ct; |
| 1962 | |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1963 | vif = c->_c.mfc_parent; |
| 1964 | c->_c.mfc_un.res.pkt++; |
| 1965 | c->_c.mfc_un.res.bytes += skb->len; |
| 1966 | c->_c.mfc_un.res.lastuse = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1968 | if (c->mfc_origin == htonl(INADDR_ANY) && true_vifi >= 0) { |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 1969 | struct mfc_cache *cache_proxy; |
| 1970 | |
| 1971 | /* For an (*,G) entry, we only check that the incomming |
| 1972 | * interface is part of the static tree. |
| 1973 | */ |
Yuval Mintz | 845c9a7 | 2018-02-28 23:29:35 +0200 | [diff] [blame] | 1974 | cache_proxy = mr_mfc_find_any_parent(mrt, vif); |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 1975 | if (cache_proxy && |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1976 | cache_proxy->_c.mfc_un.res.ttls[true_vifi] < 255) |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 1977 | goto forward; |
| 1978 | } |
| 1979 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 1980 | /* Wrong interface: drop packet and (maybe) send PIM assert. */ |
Donald Sharp | 4b1f0d3 | 2017-06-10 16:30:17 -0400 | [diff] [blame] | 1981 | if (mrt->vif_table[vif].dev != dev) { |
David S. Miller | c753796 | 2010-11-11 17:07:48 -0800 | [diff] [blame] | 1982 | if (rt_is_output_route(skb_rtable(skb))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | /* It is our own packet, looped back. |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 1984 | * Very complicated situation... |
| 1985 | * |
| 1986 | * The best workaround until routing daemons will be |
| 1987 | * fixed is not to redistribute packet, if it was |
| 1988 | * send through wrong interface. It means, that |
| 1989 | * multicast applications WILL NOT work for |
| 1990 | * (S,G), which have default multicast route pointing |
| 1991 | * to wrong oif. In any case, it is not a good |
| 1992 | * idea to use multicasting applications on router. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | */ |
| 1994 | goto dont_forward; |
| 1995 | } |
| 1996 | |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 1997 | c->_c.mfc_un.res.wrong_if++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 1999 | if (true_vifi >= 0 && mrt->mroute_do_assert && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | /* pimsm uses asserts, when switching from RPT to SPT, |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 2001 | * so that we cannot check that packet arrived on an oif. |
| 2002 | * It is bad, but otherwise we would need to move pretty |
| 2003 | * large chunk of pimd to kernel. Ough... --ANK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | */ |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 2005 | (mrt->mroute_do_pim || |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2006 | c->_c.mfc_un.res.ttls[true_vifi] < 255) && |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 2007 | time_after(jiffies, |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2008 | c->_c.mfc_un.res.last_assert + |
| 2009 | MFC_ASSERT_THRESH)) { |
| 2010 | c->_c.mfc_un.res.last_assert = jiffies; |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 2011 | ipmr_cache_report(mrt, skb, true_vifi, IGMPMSG_WRONGVIF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | } |
| 2013 | goto dont_forward; |
| 2014 | } |
| 2015 | |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 2016 | forward: |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 2017 | mrt->vif_table[vif].pkt_in++; |
| 2018 | mrt->vif_table[vif].bytes_in += skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 2020 | /* Forward the frame */ |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2021 | if (c->mfc_origin == htonl(INADDR_ANY) && |
| 2022 | c->mfc_mcastgrp == htonl(INADDR_ANY)) { |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 2023 | if (true_vifi >= 0 && |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2024 | true_vifi != c->_c.mfc_parent && |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 2025 | ip_hdr(skb)->ttl > |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2026 | c->_c.mfc_un.res.ttls[c->_c.mfc_parent]) { |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 2027 | /* It's an (*,*) entry and the packet is not coming from |
| 2028 | * the upstream: forward the packet to the upstream |
| 2029 | * only. |
| 2030 | */ |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2031 | psend = c->_c.mfc_parent; |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 2032 | goto last_forward; |
| 2033 | } |
| 2034 | goto dont_forward; |
| 2035 | } |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2036 | for (ct = c->_c.mfc_un.res.maxvif - 1; |
| 2037 | ct >= c->_c.mfc_un.res.minvif; ct--) { |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 2038 | /* For (*,G) entry, don't forward to the incoming interface */ |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2039 | if ((c->mfc_origin != htonl(INADDR_ANY) || |
Nicolas Dichtel | 360eb5d | 2013-01-22 11:18:03 +0100 | [diff] [blame] | 2040 | ct != true_vifi) && |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2041 | ip_hdr(skb)->ttl > c->_c.mfc_un.res.ttls[ct]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | if (psend != -1) { |
| 2043 | struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 2044 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | if (skb2) |
Yotam Gigi | a5bc929 | 2017-10-03 09:58:08 +0200 | [diff] [blame] | 2046 | ipmr_queue_xmit(net, mrt, true_vifi, |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2047 | skb2, c, psend); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | } |
Jianjun Kong | c354e12 | 2008-11-03 00:28:02 -0800 | [diff] [blame] | 2049 | psend = ct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | } |
| 2051 | } |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 2052 | last_forward: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | if (psend != -1) { |
| 2054 | if (local) { |
| 2055 | struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 2056 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | if (skb2) |
Yotam Gigi | a5bc929 | 2017-10-03 09:58:08 +0200 | [diff] [blame] | 2058 | ipmr_queue_xmit(net, mrt, true_vifi, skb2, |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2059 | c, psend); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | } else { |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2061 | ipmr_queue_xmit(net, mrt, true_vifi, skb, c, psend); |
Rami Rosen | c4854ec | 2013-07-20 15:09:28 +0300 | [diff] [blame] | 2062 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | } |
| 2064 | } |
| 2065 | |
| 2066 | dont_forward: |
| 2067 | if (!local) |
| 2068 | kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | } |
| 2070 | |
David S. Miller | 417da66 | 2011-05-03 19:42:43 -0700 | [diff] [blame] | 2071 | static struct mr_table *ipmr_rt_fib_lookup(struct net *net, struct sk_buff *skb) |
David S. Miller | ee3f1aa | 2011-03-09 14:06:20 -0800 | [diff] [blame] | 2072 | { |
David S. Miller | 417da66 | 2011-05-03 19:42:43 -0700 | [diff] [blame] | 2073 | struct rtable *rt = skb_rtable(skb); |
| 2074 | struct iphdr *iph = ip_hdr(skb); |
David S. Miller | da91981 | 2011-03-12 02:04:50 -0500 | [diff] [blame] | 2075 | struct flowi4 fl4 = { |
David S. Miller | 417da66 | 2011-05-03 19:42:43 -0700 | [diff] [blame] | 2076 | .daddr = iph->daddr, |
| 2077 | .saddr = iph->saddr, |
Julian Anastasov | b0fe4a3 | 2011-07-23 02:00:41 +0000 | [diff] [blame] | 2078 | .flowi4_tos = RT_TOS(iph->tos), |
David S. Miller | 4fd551d | 2012-07-17 14:39:44 -0700 | [diff] [blame] | 2079 | .flowi4_oif = (rt_is_output_route(rt) ? |
| 2080 | skb->dev->ifindex : 0), |
| 2081 | .flowi4_iif = (rt_is_output_route(rt) ? |
Pavel Emelyanov | 1fb9489 | 2012-08-08 21:53:36 +0000 | [diff] [blame] | 2082 | LOOPBACK_IFINDEX : |
David S. Miller | 4fd551d | 2012-07-17 14:39:44 -0700 | [diff] [blame] | 2083 | skb->dev->ifindex), |
David Miller | b486988 | 2012-07-01 02:03:01 +0000 | [diff] [blame] | 2084 | .flowi4_mark = skb->mark, |
David S. Miller | ee3f1aa | 2011-03-09 14:06:20 -0800 | [diff] [blame] | 2085 | }; |
| 2086 | struct mr_table *mrt; |
| 2087 | int err; |
| 2088 | |
David S. Miller | da91981 | 2011-03-12 02:04:50 -0500 | [diff] [blame] | 2089 | err = ipmr_fib_lookup(net, &fl4, &mrt); |
David S. Miller | ee3f1aa | 2011-03-09 14:06:20 -0800 | [diff] [blame] | 2090 | if (err) |
| 2091 | return ERR_PTR(err); |
| 2092 | return mrt; |
| 2093 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 2095 | /* Multicast packets for forwarding arrive here |
| 2096 | * Called with rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | int ip_mr_input(struct sk_buff *skb) |
| 2099 | { |
| 2100 | struct mfc_cache *cache; |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 2101 | struct net *net = dev_net(skb->dev); |
Eric Dumazet | 511c3f9 | 2009-06-02 05:14:27 +0000 | [diff] [blame] | 2102 | int local = skb_rtable(skb)->rt_flags & RTCF_LOCAL; |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 2103 | struct mr_table *mrt; |
Thomas Winter | bcfc7d3 | 2017-05-16 10:14:44 +1200 | [diff] [blame] | 2104 | struct net_device *dev; |
| 2105 | |
| 2106 | /* skb->dev passed in is the loX master dev for vrfs. |
| 2107 | * As there are no vifs associated with loopback devices, |
| 2108 | * get the proper interface that does have a vif associated with it. |
| 2109 | */ |
| 2110 | dev = skb->dev; |
| 2111 | if (netif_is_l3_master(skb->dev)) { |
| 2112 | dev = dev_get_by_index_rcu(net, IPCB(skb)->iif); |
| 2113 | if (!dev) { |
| 2114 | kfree_skb(skb); |
| 2115 | return -ENODEV; |
| 2116 | } |
| 2117 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | |
| 2119 | /* Packet is looped back after forward, it should not be |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 2120 | * forwarded second time, but still can be delivered locally. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | */ |
Eric Dumazet | 4c968709 | 2010-10-01 16:15:01 +0000 | [diff] [blame] | 2122 | if (IPCB(skb)->flags & IPSKB_FORWARDED) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2123 | goto dont_forward; |
| 2124 | |
David S. Miller | 417da66 | 2011-05-03 19:42:43 -0700 | [diff] [blame] | 2125 | mrt = ipmr_rt_fib_lookup(net, skb); |
David S. Miller | ee3f1aa | 2011-03-09 14:06:20 -0800 | [diff] [blame] | 2126 | if (IS_ERR(mrt)) { |
| 2127 | kfree_skb(skb); |
| 2128 | return PTR_ERR(mrt); |
Ben Greear | e40dbc5 | 2010-07-15 13:22:33 +0000 | [diff] [blame] | 2129 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | if (!local) { |
Eric Dumazet | 4c968709 | 2010-10-01 16:15:01 +0000 | [diff] [blame] | 2131 | if (IPCB(skb)->opt.router_alert) { |
| 2132 | if (ip_call_ra_chain(skb)) |
| 2133 | return 0; |
| 2134 | } else if (ip_hdr(skb)->protocol == IPPROTO_IGMP) { |
| 2135 | /* IGMPv1 (and broken IGMPv2 implementations sort of |
| 2136 | * Cisco IOS <= 11.2(8)) do not put router alert |
| 2137 | * option to IGMP packets destined to routable |
| 2138 | * groups. It is very bad, because it means |
| 2139 | * that we can forward NO IGMP messages. |
| 2140 | */ |
| 2141 | struct sock *mroute_sk; |
| 2142 | |
| 2143 | mroute_sk = rcu_dereference(mrt->mroute_sk); |
| 2144 | if (mroute_sk) { |
| 2145 | nf_reset(skb); |
| 2146 | raw_rcv(mroute_sk, skb); |
| 2147 | return 0; |
| 2148 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | } |
| 2150 | } |
| 2151 | |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 2152 | /* already under rcu_read_lock() */ |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 2153 | cache = ipmr_cache_find(mrt, ip_hdr(skb)->saddr, ip_hdr(skb)->daddr); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 2154 | if (!cache) { |
Thomas Winter | bcfc7d3 | 2017-05-16 10:14:44 +1200 | [diff] [blame] | 2155 | int vif = ipmr_find_vif(mrt, dev); |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 2156 | |
| 2157 | if (vif >= 0) |
| 2158 | cache = ipmr_cache_find_any(mrt, ip_hdr(skb)->daddr, |
| 2159 | vif); |
| 2160 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 2162 | /* No usable cache entry */ |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 2163 | if (!cache) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | int vif; |
| 2165 | |
| 2166 | if (local) { |
| 2167 | struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); |
| 2168 | ip_local_deliver(skb); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 2169 | if (!skb2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | return -ENOBUFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | skb = skb2; |
| 2172 | } |
| 2173 | |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 2174 | read_lock(&mrt_lock); |
Thomas Winter | bcfc7d3 | 2017-05-16 10:14:44 +1200 | [diff] [blame] | 2175 | vif = ipmr_find_vif(mrt, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | if (vif >= 0) { |
Donald Sharp | 4b1f0d3 | 2017-06-10 16:30:17 -0400 | [diff] [blame] | 2177 | int err2 = ipmr_cache_unresolved(mrt, vif, skb, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | read_unlock(&mrt_lock); |
| 2179 | |
Eric Dumazet | 0eae88f | 2010-04-20 19:06:52 -0700 | [diff] [blame] | 2180 | return err2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | } |
| 2182 | read_unlock(&mrt_lock); |
| 2183 | kfree_skb(skb); |
| 2184 | return -ENODEV; |
| 2185 | } |
| 2186 | |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 2187 | read_lock(&mrt_lock); |
Donald Sharp | 4b1f0d3 | 2017-06-10 16:30:17 -0400 | [diff] [blame] | 2188 | ip_mr_forward(net, mrt, dev, skb, cache, local); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | read_unlock(&mrt_lock); |
| 2190 | |
| 2191 | if (local) |
| 2192 | return ip_local_deliver(skb); |
| 2193 | |
| 2194 | return 0; |
| 2195 | |
| 2196 | dont_forward: |
| 2197 | if (local) |
| 2198 | return ip_local_deliver(skb); |
| 2199 | kfree_skb(skb); |
| 2200 | return 0; |
| 2201 | } |
| 2202 | |
Ilpo Järvinen | b187920 | 2008-12-16 01:15:11 -0800 | [diff] [blame] | 2203 | #ifdef CONFIG_IP_PIMSM_V1 |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 2204 | /* Handle IGMP messages of PIMv1 */ |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 2205 | int pim_rcv_v1(struct sk_buff *skb) |
Ilpo Järvinen | b187920 | 2008-12-16 01:15:11 -0800 | [diff] [blame] | 2206 | { |
| 2207 | struct igmphdr *pim; |
Benjamin Thery | 4feb88e | 2009-01-22 04:56:23 +0000 | [diff] [blame] | 2208 | struct net *net = dev_net(skb->dev); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 2209 | struct mr_table *mrt; |
Ilpo Järvinen | b187920 | 2008-12-16 01:15:11 -0800 | [diff] [blame] | 2210 | |
| 2211 | if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(struct iphdr))) |
| 2212 | goto drop; |
| 2213 | |
| 2214 | pim = igmp_hdr(skb); |
| 2215 | |
David S. Miller | 417da66 | 2011-05-03 19:42:43 -0700 | [diff] [blame] | 2216 | mrt = ipmr_rt_fib_lookup(net, skb); |
David S. Miller | ee3f1aa | 2011-03-09 14:06:20 -0800 | [diff] [blame] | 2217 | if (IS_ERR(mrt)) |
| 2218 | goto drop; |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 2219 | if (!mrt->mroute_do_pim || |
Ilpo Järvinen | b187920 | 2008-12-16 01:15:11 -0800 | [diff] [blame] | 2220 | pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER) |
| 2221 | goto drop; |
| 2222 | |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 2223 | if (__pim_rcv(mrt, skb, sizeof(*pim))) { |
Ilpo Järvinen | b187920 | 2008-12-16 01:15:11 -0800 | [diff] [blame] | 2224 | drop: |
| 2225 | kfree_skb(skb); |
| 2226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | return 0; |
| 2228 | } |
| 2229 | #endif |
| 2230 | |
| 2231 | #ifdef CONFIG_IP_PIMSM_V2 |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 2232 | static int pim_rcv(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | { |
| 2234 | struct pimreghdr *pim; |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 2235 | struct net *net = dev_net(skb->dev); |
| 2236 | struct mr_table *mrt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | |
Ilpo Järvinen | b187920 | 2008-12-16 01:15:11 -0800 | [diff] [blame] | 2238 | if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(struct iphdr))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | goto drop; |
| 2240 | |
Arnaldo Carvalho de Melo | 9c70220 | 2007-04-25 18:04:18 -0700 | [diff] [blame] | 2241 | pim = (struct pimreghdr *)skb_transport_header(skb); |
Nikolay Aleksandrov | 56245ca | 2016-10-31 13:21:04 +0100 | [diff] [blame] | 2242 | if (pim->type != ((PIM_VERSION << 4) | (PIM_TYPE_REGISTER)) || |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 2243 | (pim->flags & PIM_NULL_REGISTER) || |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 2244 | (ip_compute_csum((void *)pim, sizeof(*pim)) != 0 && |
Al Viro | d3bc23e | 2006-11-14 21:24:49 -0800 | [diff] [blame] | 2245 | csum_fold(skb_checksum(skb, 0, skb->len, 0)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2246 | goto drop; |
| 2247 | |
David S. Miller | 417da66 | 2011-05-03 19:42:43 -0700 | [diff] [blame] | 2248 | mrt = ipmr_rt_fib_lookup(net, skb); |
David S. Miller | ee3f1aa | 2011-03-09 14:06:20 -0800 | [diff] [blame] | 2249 | if (IS_ERR(mrt)) |
| 2250 | goto drop; |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 2251 | if (__pim_rcv(mrt, skb, sizeof(*pim))) { |
Ilpo Järvinen | b187920 | 2008-12-16 01:15:11 -0800 | [diff] [blame] | 2252 | drop: |
| 2253 | kfree_skb(skb); |
| 2254 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | return 0; |
| 2256 | } |
| 2257 | #endif |
| 2258 | |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2259 | static int __ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb, |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2260 | struct mr_mfc *c, struct rtmsg *rtm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | { |
Nicolas Dichtel | adfa85e | 2012-12-04 01:13:37 +0000 | [diff] [blame] | 2262 | struct rta_mfc_stats mfcs; |
Nikolay Aleksandrov | 43b9e12 | 2016-07-14 19:28:27 +0300 | [diff] [blame] | 2263 | struct nlattr *mp_attr; |
| 2264 | struct rtnexthop *nhp; |
Nikolay Aleksandrov | b5036cd | 2016-09-20 16:17:22 +0200 | [diff] [blame] | 2265 | unsigned long lastuse; |
Nikolay Aleksandrov | 43b9e12 | 2016-07-14 19:28:27 +0300 | [diff] [blame] | 2266 | int ct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | |
Nicolas Dichtel | 7438189 | 2010-03-25 23:45:35 +0000 | [diff] [blame] | 2268 | /* If cache is unresolved, don't try to parse IIF and OIF */ |
Nikolay Aleksandrov | 1708ebc | 2017-01-03 12:13:39 +0100 | [diff] [blame] | 2269 | if (c->mfc_parent >= MAXVIFS) { |
| 2270 | rtm->rtm_flags |= RTNH_F_UNRESOLVED; |
Nicolas Dichtel | 7438189 | 2010-03-25 23:45:35 +0000 | [diff] [blame] | 2271 | return -ENOENT; |
Nikolay Aleksandrov | 1708ebc | 2017-01-03 12:13:39 +0100 | [diff] [blame] | 2272 | } |
Nicolas Dichtel | 7438189 | 2010-03-25 23:45:35 +0000 | [diff] [blame] | 2273 | |
Thomas Graf | 92a395e | 2012-06-26 23:36:13 +0000 | [diff] [blame] | 2274 | if (VIF_EXISTS(mrt, c->mfc_parent) && |
Yuval Mintz | 6853f21 | 2018-02-28 23:29:29 +0200 | [diff] [blame] | 2275 | nla_put_u32(skb, RTA_IIF, |
| 2276 | mrt->vif_table[c->mfc_parent].dev->ifindex) < 0) |
Thomas Graf | 92a395e | 2012-06-26 23:36:13 +0000 | [diff] [blame] | 2277 | return -EMSGSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | |
Yotam Gigi | c7c0bbe | 2017-09-27 08:23:15 +0200 | [diff] [blame] | 2279 | if (c->mfc_flags & MFC_OFFLOAD) |
| 2280 | rtm->rtm_flags |= RTNH_F_OFFLOAD; |
| 2281 | |
Thomas Graf | 92a395e | 2012-06-26 23:36:13 +0000 | [diff] [blame] | 2282 | if (!(mp_attr = nla_nest_start(skb, RTA_MULTIPATH))) |
| 2283 | return -EMSGSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | |
| 2285 | for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) { |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 2286 | if (VIF_EXISTS(mrt, ct) && c->mfc_un.res.ttls[ct] < 255) { |
Yuval Mintz | 6853f21 | 2018-02-28 23:29:29 +0200 | [diff] [blame] | 2287 | struct vif_device *vif; |
| 2288 | |
Thomas Graf | 92a395e | 2012-06-26 23:36:13 +0000 | [diff] [blame] | 2289 | if (!(nhp = nla_reserve_nohdr(skb, sizeof(*nhp)))) { |
| 2290 | nla_nest_cancel(skb, mp_attr); |
| 2291 | return -EMSGSIZE; |
| 2292 | } |
| 2293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | nhp->rtnh_flags = 0; |
| 2295 | nhp->rtnh_hops = c->mfc_un.res.ttls[ct]; |
Yuval Mintz | 6853f21 | 2018-02-28 23:29:29 +0200 | [diff] [blame] | 2296 | vif = &mrt->vif_table[ct]; |
| 2297 | nhp->rtnh_ifindex = vif->dev->ifindex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | nhp->rtnh_len = sizeof(*nhp); |
| 2299 | } |
| 2300 | } |
Thomas Graf | 92a395e | 2012-06-26 23:36:13 +0000 | [diff] [blame] | 2301 | |
| 2302 | nla_nest_end(skb, mp_attr); |
| 2303 | |
Nikolay Aleksandrov | b5036cd | 2016-09-20 16:17:22 +0200 | [diff] [blame] | 2304 | lastuse = READ_ONCE(c->mfc_un.res.lastuse); |
| 2305 | lastuse = time_after_eq(jiffies, lastuse) ? jiffies - lastuse : 0; |
| 2306 | |
Nicolas Dichtel | adfa85e | 2012-12-04 01:13:37 +0000 | [diff] [blame] | 2307 | mfcs.mfcs_packets = c->mfc_un.res.pkt; |
| 2308 | mfcs.mfcs_bytes = c->mfc_un.res.bytes; |
| 2309 | mfcs.mfcs_wrong_if = c->mfc_un.res.wrong_if; |
Nikolay Aleksandrov | 43b9e12 | 2016-07-14 19:28:27 +0300 | [diff] [blame] | 2310 | if (nla_put_64bit(skb, RTA_MFC_STATS, sizeof(mfcs), &mfcs, RTA_PAD) || |
Nikolay Aleksandrov | b5036cd | 2016-09-20 16:17:22 +0200 | [diff] [blame] | 2311 | nla_put_u64_64bit(skb, RTA_EXPIRES, jiffies_to_clock_t(lastuse), |
Nikolay Aleksandrov | 43b9e12 | 2016-07-14 19:28:27 +0300 | [diff] [blame] | 2312 | RTA_PAD)) |
Nicolas Dichtel | adfa85e | 2012-12-04 01:13:37 +0000 | [diff] [blame] | 2313 | return -EMSGSIZE; |
| 2314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | rtm->rtm_type = RTN_MULTICAST; |
| 2316 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
David S. Miller | 9a1b949 | 2011-05-04 12:18:54 -0700 | [diff] [blame] | 2319 | int ipmr_get_route(struct net *net, struct sk_buff *skb, |
| 2320 | __be32 saddr, __be32 daddr, |
David Ahern | 9f09eae | 2017-01-06 17:39:06 -0800 | [diff] [blame] | 2321 | struct rtmsg *rtm, u32 portid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | struct mfc_cache *cache; |
David S. Miller | 9a1b949 | 2011-05-04 12:18:54 -0700 | [diff] [blame] | 2324 | struct mr_table *mrt; |
| 2325 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 2327 | mrt = ipmr_get_table(net, RT_TABLE_DEFAULT); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 2328 | if (!mrt) |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 2329 | return -ENOENT; |
| 2330 | |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 2331 | rcu_read_lock(); |
David S. Miller | 9a1b949 | 2011-05-04 12:18:54 -0700 | [diff] [blame] | 2332 | cache = ipmr_cache_find(mrt, saddr, daddr); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 2333 | if (!cache && skb->dev) { |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 2334 | int vif = ipmr_find_vif(mrt, skb->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | |
Nicolas Dichtel | 660b26d | 2013-01-21 06:00:26 +0000 | [diff] [blame] | 2336 | if (vif >= 0) |
| 2337 | cache = ipmr_cache_find_any(mrt, daddr, vif); |
| 2338 | } |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 2339 | if (!cache) { |
Alexey Kuznetsov | 7228749 | 2006-07-25 16:45:12 -0700 | [diff] [blame] | 2340 | struct sk_buff *skb2; |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2341 | struct iphdr *iph; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | struct net_device *dev; |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 2343 | int vif = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | dev = skb->dev; |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 2346 | read_lock(&mrt_lock); |
Eric Dumazet | a8cb16d | 2010-10-01 16:15:29 +0000 | [diff] [blame] | 2347 | if (dev) |
| 2348 | vif = ipmr_find_vif(mrt, dev); |
| 2349 | if (vif < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | read_unlock(&mrt_lock); |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 2351 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | return -ENODEV; |
| 2353 | } |
Alexey Kuznetsov | 7228749 | 2006-07-25 16:45:12 -0700 | [diff] [blame] | 2354 | skb2 = skb_clone(skb, GFP_ATOMIC); |
| 2355 | if (!skb2) { |
| 2356 | read_unlock(&mrt_lock); |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 2357 | rcu_read_unlock(); |
Alexey Kuznetsov | 7228749 | 2006-07-25 16:45:12 -0700 | [diff] [blame] | 2358 | return -ENOMEM; |
| 2359 | } |
| 2360 | |
Nikolay Aleksandrov | 2cf7507 | 2016-09-25 23:08:31 +0200 | [diff] [blame] | 2361 | NETLINK_CB(skb2).portid = portid; |
Arnaldo Carvalho de Melo | e2d1bca | 2007-04-10 20:46:21 -0700 | [diff] [blame] | 2362 | skb_push(skb2, sizeof(struct iphdr)); |
| 2363 | skb_reset_network_header(skb2); |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2364 | iph = ip_hdr(skb2); |
| 2365 | iph->ihl = sizeof(struct iphdr) >> 2; |
David S. Miller | 9a1b949 | 2011-05-04 12:18:54 -0700 | [diff] [blame] | 2366 | iph->saddr = saddr; |
| 2367 | iph->daddr = daddr; |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 2368 | iph->version = 0; |
Donald Sharp | 4b1f0d3 | 2017-06-10 16:30:17 -0400 | [diff] [blame] | 2369 | err = ipmr_cache_unresolved(mrt, vif, skb2, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | read_unlock(&mrt_lock); |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 2371 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2372 | return err; |
| 2373 | } |
| 2374 | |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 2375 | read_lock(&mrt_lock); |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2376 | err = __ipmr_fill_mroute(mrt, skb, &cache->_c, rtm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | read_unlock(&mrt_lock); |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 2378 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | return err; |
| 2380 | } |
| 2381 | |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2382 | static int ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb, |
Nicolas Dichtel | 65886f4 | 2014-03-19 17:47:50 +0100 | [diff] [blame] | 2383 | u32 portid, u32 seq, struct mfc_cache *c, int cmd, |
| 2384 | int flags) |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2385 | { |
| 2386 | struct nlmsghdr *nlh; |
| 2387 | struct rtmsg *rtm; |
Nicolas Dichtel | 1eb99af | 2012-12-04 01:13:39 +0000 | [diff] [blame] | 2388 | int err; |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2389 | |
Nicolas Dichtel | 65886f4 | 2014-03-19 17:47:50 +0100 | [diff] [blame] | 2390 | nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rtm), flags); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 2391 | if (!nlh) |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2392 | return -EMSGSIZE; |
| 2393 | |
| 2394 | rtm = nlmsg_data(nlh); |
| 2395 | rtm->rtm_family = RTNL_FAMILY_IPMR; |
| 2396 | rtm->rtm_dst_len = 32; |
| 2397 | rtm->rtm_src_len = 32; |
| 2398 | rtm->rtm_tos = 0; |
| 2399 | rtm->rtm_table = mrt->id; |
David S. Miller | f3756b7 | 2012-04-01 20:39:02 -0400 | [diff] [blame] | 2400 | if (nla_put_u32(skb, RTA_TABLE, mrt->id)) |
| 2401 | goto nla_put_failure; |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2402 | rtm->rtm_type = RTN_MULTICAST; |
| 2403 | rtm->rtm_scope = RT_SCOPE_UNIVERSE; |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2404 | if (c->_c.mfc_flags & MFC_STATIC) |
Nicolas Dichtel | 9a68ac7 | 2012-12-04 01:13:38 +0000 | [diff] [blame] | 2405 | rtm->rtm_protocol = RTPROT_STATIC; |
| 2406 | else |
| 2407 | rtm->rtm_protocol = RTPROT_MROUTED; |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2408 | rtm->rtm_flags = 0; |
| 2409 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 2410 | if (nla_put_in_addr(skb, RTA_SRC, c->mfc_origin) || |
| 2411 | nla_put_in_addr(skb, RTA_DST, c->mfc_mcastgrp)) |
David S. Miller | f3756b7 | 2012-04-01 20:39:02 -0400 | [diff] [blame] | 2412 | goto nla_put_failure; |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2413 | err = __ipmr_fill_mroute(mrt, skb, &c->_c, rtm); |
Nicolas Dichtel | 1eb99af | 2012-12-04 01:13:39 +0000 | [diff] [blame] | 2414 | /* do not break the dump if cache is unresolved */ |
| 2415 | if (err < 0 && err != -ENOENT) |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2416 | goto nla_put_failure; |
| 2417 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2418 | nlmsg_end(skb, nlh); |
| 2419 | return 0; |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2420 | |
| 2421 | nla_put_failure: |
| 2422 | nlmsg_cancel(skb, nlh); |
| 2423 | return -EMSGSIZE; |
| 2424 | } |
| 2425 | |
Nicolas Dichtel | 8cd3ac9 | 2012-12-04 01:13:40 +0000 | [diff] [blame] | 2426 | static size_t mroute_msgsize(bool unresolved, int maxvif) |
| 2427 | { |
| 2428 | size_t len = |
| 2429 | NLMSG_ALIGN(sizeof(struct rtmsg)) |
| 2430 | + nla_total_size(4) /* RTA_TABLE */ |
| 2431 | + nla_total_size(4) /* RTA_SRC */ |
| 2432 | + nla_total_size(4) /* RTA_DST */ |
| 2433 | ; |
| 2434 | |
| 2435 | if (!unresolved) |
| 2436 | len = len |
| 2437 | + nla_total_size(4) /* RTA_IIF */ |
| 2438 | + nla_total_size(0) /* RTA_MULTIPATH */ |
| 2439 | + maxvif * NLA_ALIGN(sizeof(struct rtnexthop)) |
| 2440 | /* RTA_MFC_STATS */ |
Nicolas Dichtel | a9a0804 | 2016-04-21 18:58:26 +0200 | [diff] [blame] | 2441 | + nla_total_size_64bit(sizeof(struct rta_mfc_stats)) |
Nicolas Dichtel | 8cd3ac9 | 2012-12-04 01:13:40 +0000 | [diff] [blame] | 2442 | ; |
| 2443 | |
| 2444 | return len; |
| 2445 | } |
| 2446 | |
| 2447 | static void mroute_netlink_event(struct mr_table *mrt, struct mfc_cache *mfc, |
| 2448 | int cmd) |
| 2449 | { |
| 2450 | struct net *net = read_pnet(&mrt->net); |
| 2451 | struct sk_buff *skb; |
| 2452 | int err = -ENOBUFS; |
| 2453 | |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2454 | skb = nlmsg_new(mroute_msgsize(mfc->_c.mfc_parent >= MAXVIFS, |
| 2455 | mrt->maxvif), |
Nicolas Dichtel | 8cd3ac9 | 2012-12-04 01:13:40 +0000 | [diff] [blame] | 2456 | GFP_ATOMIC); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 2457 | if (!skb) |
Nicolas Dichtel | 8cd3ac9 | 2012-12-04 01:13:40 +0000 | [diff] [blame] | 2458 | goto errout; |
| 2459 | |
Nicolas Dichtel | 65886f4 | 2014-03-19 17:47:50 +0100 | [diff] [blame] | 2460 | err = ipmr_fill_mroute(mrt, skb, 0, 0, mfc, cmd, 0); |
Nicolas Dichtel | 8cd3ac9 | 2012-12-04 01:13:40 +0000 | [diff] [blame] | 2461 | if (err < 0) |
| 2462 | goto errout; |
| 2463 | |
| 2464 | rtnl_notify(skb, net, 0, RTNLGRP_IPV4_MROUTE, NULL, GFP_ATOMIC); |
| 2465 | return; |
| 2466 | |
| 2467 | errout: |
| 2468 | kfree_skb(skb); |
| 2469 | if (err < 0) |
| 2470 | rtnl_set_sk_err(net, RTNLGRP_IPV4_MROUTE, err); |
| 2471 | } |
| 2472 | |
Julien Gomes | 5a645dd | 2017-06-20 13:54:17 -0700 | [diff] [blame] | 2473 | static size_t igmpmsg_netlink_msgsize(size_t payloadlen) |
| 2474 | { |
| 2475 | size_t len = |
| 2476 | NLMSG_ALIGN(sizeof(struct rtgenmsg)) |
| 2477 | + nla_total_size(1) /* IPMRA_CREPORT_MSGTYPE */ |
| 2478 | + nla_total_size(4) /* IPMRA_CREPORT_VIF_ID */ |
| 2479 | + nla_total_size(4) /* IPMRA_CREPORT_SRC_ADDR */ |
| 2480 | + nla_total_size(4) /* IPMRA_CREPORT_DST_ADDR */ |
| 2481 | /* IPMRA_CREPORT_PKT */ |
| 2482 | + nla_total_size(payloadlen) |
| 2483 | ; |
| 2484 | |
| 2485 | return len; |
| 2486 | } |
| 2487 | |
| 2488 | static void igmpmsg_netlink_event(struct mr_table *mrt, struct sk_buff *pkt) |
| 2489 | { |
| 2490 | struct net *net = read_pnet(&mrt->net); |
| 2491 | struct nlmsghdr *nlh; |
| 2492 | struct rtgenmsg *rtgenm; |
| 2493 | struct igmpmsg *msg; |
| 2494 | struct sk_buff *skb; |
| 2495 | struct nlattr *nla; |
| 2496 | int payloadlen; |
| 2497 | |
| 2498 | payloadlen = pkt->len - sizeof(struct igmpmsg); |
| 2499 | msg = (struct igmpmsg *)skb_network_header(pkt); |
| 2500 | |
| 2501 | skb = nlmsg_new(igmpmsg_netlink_msgsize(payloadlen), GFP_ATOMIC); |
| 2502 | if (!skb) |
| 2503 | goto errout; |
| 2504 | |
| 2505 | nlh = nlmsg_put(skb, 0, 0, RTM_NEWCACHEREPORT, |
| 2506 | sizeof(struct rtgenmsg), 0); |
| 2507 | if (!nlh) |
| 2508 | goto errout; |
| 2509 | rtgenm = nlmsg_data(nlh); |
| 2510 | rtgenm->rtgen_family = RTNL_FAMILY_IPMR; |
| 2511 | if (nla_put_u8(skb, IPMRA_CREPORT_MSGTYPE, msg->im_msgtype) || |
| 2512 | nla_put_u32(skb, IPMRA_CREPORT_VIF_ID, msg->im_vif) || |
| 2513 | nla_put_in_addr(skb, IPMRA_CREPORT_SRC_ADDR, |
| 2514 | msg->im_src.s_addr) || |
| 2515 | nla_put_in_addr(skb, IPMRA_CREPORT_DST_ADDR, |
| 2516 | msg->im_dst.s_addr)) |
| 2517 | goto nla_put_failure; |
| 2518 | |
| 2519 | nla = nla_reserve(skb, IPMRA_CREPORT_PKT, payloadlen); |
| 2520 | if (!nla || skb_copy_bits(pkt, sizeof(struct igmpmsg), |
| 2521 | nla_data(nla), payloadlen)) |
| 2522 | goto nla_put_failure; |
| 2523 | |
| 2524 | nlmsg_end(skb, nlh); |
| 2525 | |
| 2526 | rtnl_notify(skb, net, 0, RTNLGRP_IPV4_MROUTE_R, NULL, GFP_ATOMIC); |
| 2527 | return; |
| 2528 | |
| 2529 | nla_put_failure: |
| 2530 | nlmsg_cancel(skb, nlh); |
| 2531 | errout: |
| 2532 | kfree_skb(skb); |
| 2533 | rtnl_set_sk_err(net, RTNLGRP_IPV4_MROUTE_R, -ENOBUFS); |
| 2534 | } |
| 2535 | |
Donald Sharp | 4f75ba6 | 2017-06-28 13:58:57 -0400 | [diff] [blame] | 2536 | static int ipmr_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, |
| 2537 | struct netlink_ext_ack *extack) |
| 2538 | { |
| 2539 | struct net *net = sock_net(in_skb->sk); |
| 2540 | struct nlattr *tb[RTA_MAX + 1]; |
| 2541 | struct sk_buff *skb = NULL; |
| 2542 | struct mfc_cache *cache; |
| 2543 | struct mr_table *mrt; |
| 2544 | struct rtmsg *rtm; |
| 2545 | __be32 src, grp; |
| 2546 | u32 tableid; |
| 2547 | int err; |
| 2548 | |
| 2549 | err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, |
| 2550 | rtm_ipv4_policy, extack); |
| 2551 | if (err < 0) |
| 2552 | goto errout; |
| 2553 | |
| 2554 | rtm = nlmsg_data(nlh); |
| 2555 | |
| 2556 | src = tb[RTA_SRC] ? nla_get_in_addr(tb[RTA_SRC]) : 0; |
| 2557 | grp = tb[RTA_DST] ? nla_get_in_addr(tb[RTA_DST]) : 0; |
| 2558 | tableid = tb[RTA_TABLE] ? nla_get_u32(tb[RTA_TABLE]) : 0; |
| 2559 | |
| 2560 | mrt = ipmr_get_table(net, tableid ? tableid : RT_TABLE_DEFAULT); |
Dan Carpenter | 2e3d232 | 2017-07-12 10:56:47 +0300 | [diff] [blame] | 2561 | if (!mrt) { |
| 2562 | err = -ENOENT; |
Donald Sharp | 4f75ba6 | 2017-06-28 13:58:57 -0400 | [diff] [blame] | 2563 | goto errout_free; |
| 2564 | } |
| 2565 | |
| 2566 | /* entries are added/deleted only under RTNL */ |
| 2567 | rcu_read_lock(); |
| 2568 | cache = ipmr_cache_find(mrt, src, grp); |
| 2569 | rcu_read_unlock(); |
| 2570 | if (!cache) { |
| 2571 | err = -ENOENT; |
| 2572 | goto errout_free; |
| 2573 | } |
| 2574 | |
| 2575 | skb = nlmsg_new(mroute_msgsize(false, mrt->maxvif), GFP_KERNEL); |
| 2576 | if (!skb) { |
| 2577 | err = -ENOBUFS; |
| 2578 | goto errout_free; |
| 2579 | } |
| 2580 | |
| 2581 | err = ipmr_fill_mroute(mrt, skb, NETLINK_CB(in_skb).portid, |
| 2582 | nlh->nlmsg_seq, cache, |
| 2583 | RTM_NEWROUTE, 0); |
| 2584 | if (err < 0) |
| 2585 | goto errout_free; |
| 2586 | |
| 2587 | err = rtnl_unicast(skb, net, NETLINK_CB(in_skb).portid); |
| 2588 | |
| 2589 | errout: |
| 2590 | return err; |
| 2591 | |
| 2592 | errout_free: |
| 2593 | kfree_skb(skb); |
| 2594 | goto errout; |
| 2595 | } |
| 2596 | |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2597 | static int ipmr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb) |
| 2598 | { |
| 2599 | struct net *net = sock_net(skb->sk); |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2600 | unsigned int t = 0, s_t; |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2601 | unsigned int e = 0, s_e; |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2602 | struct mr_table *mrt; |
| 2603 | struct mr_mfc *mfc; |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2604 | |
| 2605 | s_t = cb->args[0]; |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 2606 | s_e = cb->args[1]; |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2607 | |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 2608 | rcu_read_lock(); |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2609 | ipmr_for_each_table(mrt, net) { |
| 2610 | if (t < s_t) |
| 2611 | goto next_table; |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 2612 | list_for_each_entry_rcu(mfc, &mrt->mfc_cache_list, list) { |
| 2613 | if (e < s_e) |
| 2614 | goto next_entry; |
| 2615 | if (ipmr_fill_mroute(mrt, skb, |
| 2616 | NETLINK_CB(cb->skb).portid, |
| 2617 | cb->nlh->nlmsg_seq, |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2618 | (struct mfc_cache *)mfc, |
| 2619 | RTM_NEWROUTE, NLM_F_MULTI) < 0) |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 2620 | goto done; |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2621 | next_entry: |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 2622 | e++; |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2623 | } |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 2624 | e = 0; |
| 2625 | s_e = 0; |
| 2626 | |
Nicolas Dichtel | 1eb99af | 2012-12-04 01:13:39 +0000 | [diff] [blame] | 2627 | spin_lock_bh(&mfc_unres_lock); |
| 2628 | list_for_each_entry(mfc, &mrt->mfc_unres_queue, list) { |
| 2629 | if (e < s_e) |
| 2630 | goto next_entry2; |
| 2631 | if (ipmr_fill_mroute(mrt, skb, |
| 2632 | NETLINK_CB(cb->skb).portid, |
| 2633 | cb->nlh->nlmsg_seq, |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 2634 | (struct mfc_cache *)mfc, |
| 2635 | RTM_NEWROUTE, NLM_F_MULTI) < 0) { |
Nicolas Dichtel | 1eb99af | 2012-12-04 01:13:39 +0000 | [diff] [blame] | 2636 | spin_unlock_bh(&mfc_unres_lock); |
| 2637 | goto done; |
| 2638 | } |
| 2639 | next_entry2: |
| 2640 | e++; |
| 2641 | } |
| 2642 | spin_unlock_bh(&mfc_unres_lock); |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 2643 | e = 0; |
| 2644 | s_e = 0; |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2645 | next_table: |
| 2646 | t++; |
| 2647 | } |
| 2648 | done: |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 2649 | rcu_read_unlock(); |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2650 | |
Nikolay Aleksandrov | 8fb472c | 2017-01-12 15:53:33 +0100 | [diff] [blame] | 2651 | cb->args[1] = e; |
Patrick McHardy | cb6a4e4 | 2010-04-26 16:02:08 +0200 | [diff] [blame] | 2652 | cb->args[0] = t; |
| 2653 | |
| 2654 | return skb->len; |
| 2655 | } |
| 2656 | |
Nikolay Aleksandrov | ccbb0aa | 2015-11-26 15:23:50 +0100 | [diff] [blame] | 2657 | static const struct nla_policy rtm_ipmr_policy[RTA_MAX + 1] = { |
| 2658 | [RTA_SRC] = { .type = NLA_U32 }, |
| 2659 | [RTA_DST] = { .type = NLA_U32 }, |
| 2660 | [RTA_IIF] = { .type = NLA_U32 }, |
| 2661 | [RTA_TABLE] = { .type = NLA_U32 }, |
| 2662 | [RTA_MULTIPATH] = { .len = sizeof(struct rtnexthop) }, |
| 2663 | }; |
| 2664 | |
| 2665 | static bool ipmr_rtm_validate_proto(unsigned char rtm_protocol) |
| 2666 | { |
| 2667 | switch (rtm_protocol) { |
| 2668 | case RTPROT_STATIC: |
| 2669 | case RTPROT_MROUTED: |
| 2670 | return true; |
| 2671 | } |
| 2672 | return false; |
| 2673 | } |
| 2674 | |
| 2675 | static int ipmr_nla_get_ttls(const struct nlattr *nla, struct mfcctl *mfcc) |
| 2676 | { |
| 2677 | struct rtnexthop *rtnh = nla_data(nla); |
| 2678 | int remaining = nla_len(nla), vifi = 0; |
| 2679 | |
| 2680 | while (rtnh_ok(rtnh, remaining)) { |
| 2681 | mfcc->mfcc_ttls[vifi] = rtnh->rtnh_hops; |
| 2682 | if (++vifi == MAXVIFS) |
| 2683 | break; |
| 2684 | rtnh = rtnh_next(rtnh, &remaining); |
| 2685 | } |
| 2686 | |
| 2687 | return remaining > 0 ? -EINVAL : vifi; |
| 2688 | } |
| 2689 | |
| 2690 | /* returns < 0 on error, 0 for ADD_MFC and 1 for ADD_MFC_PROXY */ |
| 2691 | static int rtm_to_ipmr_mfcc(struct net *net, struct nlmsghdr *nlh, |
| 2692 | struct mfcctl *mfcc, int *mrtsock, |
David Ahern | c21ef3e | 2017-04-16 09:48:24 -0700 | [diff] [blame] | 2693 | struct mr_table **mrtret, |
| 2694 | struct netlink_ext_ack *extack) |
Nikolay Aleksandrov | ccbb0aa | 2015-11-26 15:23:50 +0100 | [diff] [blame] | 2695 | { |
| 2696 | struct net_device *dev = NULL; |
| 2697 | u32 tblid = RT_TABLE_DEFAULT; |
| 2698 | struct mr_table *mrt; |
| 2699 | struct nlattr *attr; |
| 2700 | struct rtmsg *rtm; |
| 2701 | int ret, rem; |
| 2702 | |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 2703 | ret = nlmsg_validate(nlh, sizeof(*rtm), RTA_MAX, rtm_ipmr_policy, |
David Ahern | c21ef3e | 2017-04-16 09:48:24 -0700 | [diff] [blame] | 2704 | extack); |
Nikolay Aleksandrov | ccbb0aa | 2015-11-26 15:23:50 +0100 | [diff] [blame] | 2705 | if (ret < 0) |
| 2706 | goto out; |
| 2707 | rtm = nlmsg_data(nlh); |
| 2708 | |
| 2709 | ret = -EINVAL; |
| 2710 | if (rtm->rtm_family != RTNL_FAMILY_IPMR || rtm->rtm_dst_len != 32 || |
| 2711 | rtm->rtm_type != RTN_MULTICAST || |
| 2712 | rtm->rtm_scope != RT_SCOPE_UNIVERSE || |
| 2713 | !ipmr_rtm_validate_proto(rtm->rtm_protocol)) |
| 2714 | goto out; |
| 2715 | |
| 2716 | memset(mfcc, 0, sizeof(*mfcc)); |
| 2717 | mfcc->mfcc_parent = -1; |
| 2718 | ret = 0; |
| 2719 | nlmsg_for_each_attr(attr, nlh, sizeof(struct rtmsg), rem) { |
| 2720 | switch (nla_type(attr)) { |
| 2721 | case RTA_SRC: |
| 2722 | mfcc->mfcc_origin.s_addr = nla_get_be32(attr); |
| 2723 | break; |
| 2724 | case RTA_DST: |
| 2725 | mfcc->mfcc_mcastgrp.s_addr = nla_get_be32(attr); |
| 2726 | break; |
| 2727 | case RTA_IIF: |
| 2728 | dev = __dev_get_by_index(net, nla_get_u32(attr)); |
| 2729 | if (!dev) { |
| 2730 | ret = -ENODEV; |
| 2731 | goto out; |
| 2732 | } |
| 2733 | break; |
| 2734 | case RTA_MULTIPATH: |
| 2735 | if (ipmr_nla_get_ttls(attr, mfcc) < 0) { |
| 2736 | ret = -EINVAL; |
| 2737 | goto out; |
| 2738 | } |
| 2739 | break; |
| 2740 | case RTA_PREFSRC: |
| 2741 | ret = 1; |
| 2742 | break; |
| 2743 | case RTA_TABLE: |
| 2744 | tblid = nla_get_u32(attr); |
| 2745 | break; |
| 2746 | } |
| 2747 | } |
| 2748 | mrt = ipmr_get_table(net, tblid); |
| 2749 | if (!mrt) { |
| 2750 | ret = -ENOENT; |
| 2751 | goto out; |
| 2752 | } |
| 2753 | *mrtret = mrt; |
| 2754 | *mrtsock = rtm->rtm_protocol == RTPROT_MROUTED ? 1 : 0; |
| 2755 | if (dev) |
| 2756 | mfcc->mfcc_parent = ipmr_find_vif(mrt, dev); |
| 2757 | |
| 2758 | out: |
| 2759 | return ret; |
| 2760 | } |
| 2761 | |
| 2762 | /* takes care of both newroute and delroute */ |
David Ahern | c21ef3e | 2017-04-16 09:48:24 -0700 | [diff] [blame] | 2763 | static int ipmr_rtm_route(struct sk_buff *skb, struct nlmsghdr *nlh, |
| 2764 | struct netlink_ext_ack *extack) |
Nikolay Aleksandrov | ccbb0aa | 2015-11-26 15:23:50 +0100 | [diff] [blame] | 2765 | { |
| 2766 | struct net *net = sock_net(skb->sk); |
| 2767 | int ret, mrtsock, parent; |
| 2768 | struct mr_table *tbl; |
| 2769 | struct mfcctl mfcc; |
| 2770 | |
| 2771 | mrtsock = 0; |
| 2772 | tbl = NULL; |
David Ahern | c21ef3e | 2017-04-16 09:48:24 -0700 | [diff] [blame] | 2773 | ret = rtm_to_ipmr_mfcc(net, nlh, &mfcc, &mrtsock, &tbl, extack); |
Nikolay Aleksandrov | ccbb0aa | 2015-11-26 15:23:50 +0100 | [diff] [blame] | 2774 | if (ret < 0) |
| 2775 | return ret; |
| 2776 | |
| 2777 | parent = ret ? mfcc.mfcc_parent : -1; |
| 2778 | if (nlh->nlmsg_type == RTM_NEWROUTE) |
| 2779 | return ipmr_mfc_add(net, tbl, &mfcc, mrtsock, parent); |
| 2780 | else |
| 2781 | return ipmr_mfc_delete(tbl, &mfcc, parent); |
| 2782 | } |
| 2783 | |
Nikolay Aleksandrov | 772c344 | 2017-06-07 18:02:32 +0300 | [diff] [blame] | 2784 | static bool ipmr_fill_table(struct mr_table *mrt, struct sk_buff *skb) |
| 2785 | { |
| 2786 | u32 queue_len = atomic_read(&mrt->cache_resolve_queue_len); |
| 2787 | |
| 2788 | if (nla_put_u32(skb, IPMRA_TABLE_ID, mrt->id) || |
| 2789 | nla_put_u32(skb, IPMRA_TABLE_CACHE_RES_QUEUE_LEN, queue_len) || |
| 2790 | nla_put_s32(skb, IPMRA_TABLE_MROUTE_REG_VIF_NUM, |
| 2791 | mrt->mroute_reg_vif_num) || |
| 2792 | nla_put_u8(skb, IPMRA_TABLE_MROUTE_DO_ASSERT, |
| 2793 | mrt->mroute_do_assert) || |
| 2794 | nla_put_u8(skb, IPMRA_TABLE_MROUTE_DO_PIM, mrt->mroute_do_pim)) |
| 2795 | return false; |
| 2796 | |
| 2797 | return true; |
| 2798 | } |
| 2799 | |
| 2800 | static bool ipmr_fill_vif(struct mr_table *mrt, u32 vifid, struct sk_buff *skb) |
| 2801 | { |
| 2802 | struct nlattr *vif_nest; |
| 2803 | struct vif_device *vif; |
| 2804 | |
| 2805 | /* if the VIF doesn't exist just continue */ |
| 2806 | if (!VIF_EXISTS(mrt, vifid)) |
| 2807 | return true; |
| 2808 | |
| 2809 | vif = &mrt->vif_table[vifid]; |
| 2810 | vif_nest = nla_nest_start(skb, IPMRA_VIF); |
| 2811 | if (!vif_nest) |
| 2812 | return false; |
| 2813 | if (nla_put_u32(skb, IPMRA_VIFA_IFINDEX, vif->dev->ifindex) || |
| 2814 | nla_put_u32(skb, IPMRA_VIFA_VIF_ID, vifid) || |
| 2815 | nla_put_u16(skb, IPMRA_VIFA_FLAGS, vif->flags) || |
| 2816 | nla_put_u64_64bit(skb, IPMRA_VIFA_BYTES_IN, vif->bytes_in, |
| 2817 | IPMRA_VIFA_PAD) || |
| 2818 | nla_put_u64_64bit(skb, IPMRA_VIFA_BYTES_OUT, vif->bytes_out, |
| 2819 | IPMRA_VIFA_PAD) || |
| 2820 | nla_put_u64_64bit(skb, IPMRA_VIFA_PACKETS_IN, vif->pkt_in, |
| 2821 | IPMRA_VIFA_PAD) || |
| 2822 | nla_put_u64_64bit(skb, IPMRA_VIFA_PACKETS_OUT, vif->pkt_out, |
| 2823 | IPMRA_VIFA_PAD) || |
| 2824 | nla_put_be32(skb, IPMRA_VIFA_LOCAL_ADDR, vif->local) || |
| 2825 | nla_put_be32(skb, IPMRA_VIFA_REMOTE_ADDR, vif->remote)) { |
| 2826 | nla_nest_cancel(skb, vif_nest); |
| 2827 | return false; |
| 2828 | } |
| 2829 | nla_nest_end(skb, vif_nest); |
| 2830 | |
| 2831 | return true; |
| 2832 | } |
| 2833 | |
| 2834 | static int ipmr_rtm_dumplink(struct sk_buff *skb, struct netlink_callback *cb) |
| 2835 | { |
| 2836 | struct net *net = sock_net(skb->sk); |
| 2837 | struct nlmsghdr *nlh = NULL; |
| 2838 | unsigned int t = 0, s_t; |
| 2839 | unsigned int e = 0, s_e; |
| 2840 | struct mr_table *mrt; |
| 2841 | |
| 2842 | s_t = cb->args[0]; |
| 2843 | s_e = cb->args[1]; |
| 2844 | |
| 2845 | ipmr_for_each_table(mrt, net) { |
| 2846 | struct nlattr *vifs, *af; |
| 2847 | struct ifinfomsg *hdr; |
| 2848 | u32 i; |
| 2849 | |
| 2850 | if (t < s_t) |
| 2851 | goto skip_table; |
| 2852 | nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, |
| 2853 | cb->nlh->nlmsg_seq, RTM_NEWLINK, |
| 2854 | sizeof(*hdr), NLM_F_MULTI); |
| 2855 | if (!nlh) |
| 2856 | break; |
| 2857 | |
| 2858 | hdr = nlmsg_data(nlh); |
| 2859 | memset(hdr, 0, sizeof(*hdr)); |
| 2860 | hdr->ifi_family = RTNL_FAMILY_IPMR; |
| 2861 | |
| 2862 | af = nla_nest_start(skb, IFLA_AF_SPEC); |
| 2863 | if (!af) { |
| 2864 | nlmsg_cancel(skb, nlh); |
| 2865 | goto out; |
| 2866 | } |
| 2867 | |
| 2868 | if (!ipmr_fill_table(mrt, skb)) { |
| 2869 | nlmsg_cancel(skb, nlh); |
| 2870 | goto out; |
| 2871 | } |
| 2872 | |
| 2873 | vifs = nla_nest_start(skb, IPMRA_TABLE_VIFS); |
| 2874 | if (!vifs) { |
| 2875 | nla_nest_end(skb, af); |
| 2876 | nlmsg_end(skb, nlh); |
| 2877 | goto out; |
| 2878 | } |
| 2879 | for (i = 0; i < mrt->maxvif; i++) { |
| 2880 | if (e < s_e) |
| 2881 | goto skip_entry; |
| 2882 | if (!ipmr_fill_vif(mrt, i, skb)) { |
| 2883 | nla_nest_end(skb, vifs); |
| 2884 | nla_nest_end(skb, af); |
| 2885 | nlmsg_end(skb, nlh); |
| 2886 | goto out; |
| 2887 | } |
| 2888 | skip_entry: |
| 2889 | e++; |
| 2890 | } |
| 2891 | s_e = 0; |
| 2892 | e = 0; |
| 2893 | nla_nest_end(skb, vifs); |
| 2894 | nla_nest_end(skb, af); |
| 2895 | nlmsg_end(skb, nlh); |
| 2896 | skip_table: |
| 2897 | t++; |
| 2898 | } |
| 2899 | |
| 2900 | out: |
| 2901 | cb->args[1] = e; |
| 2902 | cb->args[0] = t; |
| 2903 | |
| 2904 | return skb->len; |
| 2905 | } |
| 2906 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 2907 | #ifdef CONFIG_PROC_FS |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 2908 | /* The /proc interfaces to multicast routing : |
| 2909 | * /proc/net/ip_mr_cache & /proc/net/ip_mr_vif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | */ |
| 2911 | struct ipmr_vif_iter { |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 2912 | struct seq_net_private p; |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 2913 | struct mr_table *mrt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | int ct; |
| 2915 | }; |
| 2916 | |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 2917 | static struct vif_device *ipmr_vif_seq_idx(struct net *net, |
Yuval Mintz | 6853f21 | 2018-02-28 23:29:29 +0200 | [diff] [blame] | 2918 | struct ipmr_vif_iter *iter, |
| 2919 | loff_t pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | { |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 2921 | struct mr_table *mrt = iter->mrt; |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 2922 | |
| 2923 | for (iter->ct = 0; iter->ct < mrt->maxvif; ++iter->ct) { |
| 2924 | if (!VIF_EXISTS(mrt, iter->ct)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2925 | continue; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 2926 | if (pos-- == 0) |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 2927 | return &mrt->vif_table[iter->ct]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2928 | } |
| 2929 | return NULL; |
| 2930 | } |
| 2931 | |
| 2932 | static void *ipmr_vif_seq_start(struct seq_file *seq, loff_t *pos) |
Stephen Hemminger | ba93ef7 | 2008-01-21 17:28:59 -0800 | [diff] [blame] | 2933 | __acquires(mrt_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | { |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 2935 | struct ipmr_vif_iter *iter = seq->private; |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 2936 | struct net *net = seq_file_net(seq); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 2937 | struct mr_table *mrt; |
| 2938 | |
| 2939 | mrt = ipmr_get_table(net, RT_TABLE_DEFAULT); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 2940 | if (!mrt) |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 2941 | return ERR_PTR(-ENOENT); |
| 2942 | |
| 2943 | iter->mrt = mrt; |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 2944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 | read_lock(&mrt_lock); |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 2946 | return *pos ? ipmr_vif_seq_idx(net, seq->private, *pos - 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | : SEQ_START_TOKEN; |
| 2948 | } |
| 2949 | |
| 2950 | static void *ipmr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 2951 | { |
| 2952 | struct ipmr_vif_iter *iter = seq->private; |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 2953 | struct net *net = seq_file_net(seq); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 2954 | struct mr_table *mrt = iter->mrt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | |
| 2956 | ++*pos; |
| 2957 | if (v == SEQ_START_TOKEN) |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 2958 | return ipmr_vif_seq_idx(net, iter, 0); |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 2959 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 2960 | while (++iter->ct < mrt->maxvif) { |
| 2961 | if (!VIF_EXISTS(mrt, iter->ct)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | continue; |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 2963 | return &mrt->vif_table[iter->ct]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2964 | } |
| 2965 | return NULL; |
| 2966 | } |
| 2967 | |
| 2968 | static void ipmr_vif_seq_stop(struct seq_file *seq, void *v) |
Stephen Hemminger | ba93ef7 | 2008-01-21 17:28:59 -0800 | [diff] [blame] | 2969 | __releases(mrt_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | { |
| 2971 | read_unlock(&mrt_lock); |
| 2972 | } |
| 2973 | |
| 2974 | static int ipmr_vif_seq_show(struct seq_file *seq, void *v) |
| 2975 | { |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 2976 | struct ipmr_vif_iter *iter = seq->private; |
| 2977 | struct mr_table *mrt = iter->mrt; |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 2978 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | if (v == SEQ_START_TOKEN) { |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 2980 | seq_puts(seq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | "Interface BytesIn PktsIn BytesOut PktsOut Flags Local Remote\n"); |
| 2982 | } else { |
| 2983 | const struct vif_device *vif = v; |
Yuval Mintz | 6853f21 | 2018-02-28 23:29:29 +0200 | [diff] [blame] | 2984 | const char *name = vif->dev ? |
| 2985 | vif->dev->name : "none"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | |
| 2987 | seq_printf(seq, |
James Hogan | 91e6dd8 | 2018-01-30 09:48:02 +0000 | [diff] [blame] | 2988 | "%2td %-10s %8ld %7ld %8ld %7ld %05X %08X %08X\n", |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 2989 | vif - mrt->vif_table, |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 2990 | name, vif->bytes_in, vif->pkt_in, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | vif->bytes_out, vif->pkt_out, |
| 2992 | vif->flags, vif->local, vif->remote); |
| 2993 | } |
| 2994 | return 0; |
| 2995 | } |
| 2996 | |
Stephen Hemminger | f690808 | 2007-03-12 14:34:29 -0700 | [diff] [blame] | 2997 | static const struct seq_operations ipmr_vif_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | .start = ipmr_vif_seq_start, |
| 2999 | .next = ipmr_vif_seq_next, |
| 3000 | .stop = ipmr_vif_seq_stop, |
| 3001 | .show = ipmr_vif_seq_show, |
| 3002 | }; |
| 3003 | |
| 3004 | static int ipmr_vif_open(struct inode *inode, struct file *file) |
| 3005 | { |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 3006 | return seq_open_net(inode, file, &ipmr_vif_seq_ops, |
| 3007 | sizeof(struct ipmr_vif_iter)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | } |
| 3009 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 3010 | static const struct file_operations ipmr_vif_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | .open = ipmr_vif_open, |
| 3012 | .read = seq_read, |
| 3013 | .llseek = seq_lseek, |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 3014 | .release = seq_release_net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | }; |
| 3016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | static void *ipmr_mfc_seq_start(struct seq_file *seq, loff_t *pos) |
| 3018 | { |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 3019 | struct net *net = seq_file_net(seq); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 3020 | struct mr_table *mrt; |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 3021 | |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 3022 | mrt = ipmr_get_table(net, RT_TABLE_DEFAULT); |
Ian Morris | 51456b2 | 2015-04-03 09:17:26 +0100 | [diff] [blame] | 3023 | if (!mrt) |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 3024 | return ERR_PTR(-ENOENT); |
| 3025 | |
Yuval Mintz | c8d6196 | 2018-02-28 23:29:36 +0200 | [diff] [blame^] | 3026 | return mr_mfc_seq_start(seq, pos, mrt, &mfc_unres_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | static int ipmr_mfc_seq_show(struct seq_file *seq, void *v) |
| 3030 | { |
| 3031 | int n; |
| 3032 | |
| 3033 | if (v == SEQ_START_TOKEN) { |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 3034 | seq_puts(seq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | "Group Origin Iif Pkts Bytes Wrong Oifs\n"); |
| 3036 | } else { |
| 3037 | const struct mfc_cache *mfc = v; |
Yuval Mintz | c8d6196 | 2018-02-28 23:29:36 +0200 | [diff] [blame^] | 3038 | const struct mr_mfc_iter *it = seq->private; |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 3039 | const struct mr_table *mrt = it->mrt; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 3040 | |
Eric Dumazet | 0eae88f | 2010-04-20 19:06:52 -0700 | [diff] [blame] | 3041 | seq_printf(seq, "%08X %08X %-3hd", |
| 3042 | (__force u32) mfc->mfc_mcastgrp, |
| 3043 | (__force u32) mfc->mfc_origin, |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 3044 | mfc->_c.mfc_parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 3046 | if (it->cache != &mrt->mfc_unres_queue) { |
Benjamin Thery | 1ea472e | 2008-12-03 22:21:47 -0800 | [diff] [blame] | 3047 | seq_printf(seq, " %8lu %8lu %8lu", |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 3048 | mfc->_c.mfc_un.res.pkt, |
| 3049 | mfc->_c.mfc_un.res.bytes, |
| 3050 | mfc->_c.mfc_un.res.wrong_if); |
| 3051 | for (n = mfc->_c.mfc_un.res.minvif; |
| 3052 | n < mfc->_c.mfc_un.res.maxvif; n++) { |
Patrick McHardy | 0c12295 | 2010-04-13 05:03:22 +0000 | [diff] [blame] | 3053 | if (VIF_EXISTS(mrt, n) && |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 3054 | mfc->_c.mfc_un.res.ttls[n] < 255) |
Benjamin Thery | cf958ae3 | 2009-01-22 04:56:16 +0000 | [diff] [blame] | 3055 | seq_printf(seq, |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 3056 | " %2d:%-3d", |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 3057 | n, mfc->_c.mfc_un.res.ttls[n]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | } |
Benjamin Thery | 1ea472e | 2008-12-03 22:21:47 -0800 | [diff] [blame] | 3059 | } else { |
| 3060 | /* unresolved mfc_caches don't contain |
| 3061 | * pkt, bytes and wrong_if values |
| 3062 | */ |
| 3063 | seq_printf(seq, " %8lu %8lu %8lu", 0ul, 0ul, 0ul); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | } |
| 3065 | seq_putc(seq, '\n'); |
| 3066 | } |
| 3067 | return 0; |
| 3068 | } |
| 3069 | |
Stephen Hemminger | f690808 | 2007-03-12 14:34:29 -0700 | [diff] [blame] | 3070 | static const struct seq_operations ipmr_mfc_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | .start = ipmr_mfc_seq_start, |
Yuval Mintz | c8d6196 | 2018-02-28 23:29:36 +0200 | [diff] [blame^] | 3072 | .next = mr_mfc_seq_next, |
| 3073 | .stop = mr_mfc_seq_stop, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | .show = ipmr_mfc_seq_show, |
| 3075 | }; |
| 3076 | |
| 3077 | static int ipmr_mfc_open(struct inode *inode, struct file *file) |
| 3078 | { |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 3079 | return seq_open_net(inode, file, &ipmr_mfc_seq_ops, |
Yuval Mintz | c8d6196 | 2018-02-28 23:29:36 +0200 | [diff] [blame^] | 3080 | sizeof(struct mr_mfc_iter)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3081 | } |
| 3082 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 3083 | static const struct file_operations ipmr_mfc_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | .open = ipmr_mfc_open, |
| 3085 | .read = seq_read, |
| 3086 | .llseek = seq_lseek, |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 3087 | .release = seq_release_net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | }; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 3089 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3090 | |
| 3091 | #ifdef CONFIG_IP_PIMSM_V2 |
Alexey Dobriyan | 3261309 | 2009-09-14 12:21:47 +0000 | [diff] [blame] | 3092 | static const struct net_protocol pim_protocol = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3093 | .handler = pim_rcv, |
Tom Goff | 403dbb9 | 2009-06-14 03:16:13 -0700 | [diff] [blame] | 3094 | .netns_ok = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | }; |
| 3096 | #endif |
| 3097 | |
Yotam Gigi | 4d65b94 | 2017-09-27 08:23:13 +0200 | [diff] [blame] | 3098 | static unsigned int ipmr_seq_read(struct net *net) |
| 3099 | { |
| 3100 | ASSERT_RTNL(); |
| 3101 | |
| 3102 | return net->ipv4.ipmr_seq + ipmr_rules_seq_read(net); |
| 3103 | } |
| 3104 | |
| 3105 | static int ipmr_dump(struct net *net, struct notifier_block *nb) |
| 3106 | { |
| 3107 | struct mr_table *mrt; |
| 3108 | int err; |
| 3109 | |
| 3110 | err = ipmr_rules_dump(net, nb); |
| 3111 | if (err) |
| 3112 | return err; |
| 3113 | |
| 3114 | ipmr_for_each_table(mrt, net) { |
| 3115 | struct vif_device *v = &mrt->vif_table[0]; |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 3116 | struct mr_mfc *mfc; |
Yotam Gigi | 4d65b94 | 2017-09-27 08:23:13 +0200 | [diff] [blame] | 3117 | int vifi; |
| 3118 | |
| 3119 | /* Notifiy on table VIF entries */ |
| 3120 | read_lock(&mrt_lock); |
| 3121 | for (vifi = 0; vifi < mrt->maxvif; vifi++, v++) { |
| 3122 | if (!v->dev) |
| 3123 | continue; |
| 3124 | |
| 3125 | call_ipmr_vif_entry_notifier(nb, net, FIB_EVENT_VIF_ADD, |
| 3126 | v, vifi, mrt->id); |
| 3127 | } |
| 3128 | read_unlock(&mrt_lock); |
| 3129 | |
| 3130 | /* Notify on table MFC entries */ |
| 3131 | list_for_each_entry_rcu(mfc, &mrt->mfc_cache_list, list) |
| 3132 | call_ipmr_mfc_entry_notifier(nb, net, |
Yuval Mintz | 494fff5 | 2018-02-28 23:29:34 +0200 | [diff] [blame] | 3133 | FIB_EVENT_ENTRY_ADD, |
| 3134 | (struct mfc_cache *)mfc, |
Yotam Gigi | 4d65b94 | 2017-09-27 08:23:13 +0200 | [diff] [blame] | 3135 | mrt->id); |
| 3136 | } |
| 3137 | |
| 3138 | return 0; |
| 3139 | } |
| 3140 | |
| 3141 | static const struct fib_notifier_ops ipmr_notifier_ops_template = { |
| 3142 | .family = RTNL_FAMILY_IPMR, |
| 3143 | .fib_seq_read = ipmr_seq_read, |
| 3144 | .fib_dump = ipmr_dump, |
| 3145 | .owner = THIS_MODULE, |
| 3146 | }; |
| 3147 | |
Colin Ian King | ef739d8 | 2017-09-29 14:34:22 +0100 | [diff] [blame] | 3148 | static int __net_init ipmr_notifier_init(struct net *net) |
Yotam Gigi | 4d65b94 | 2017-09-27 08:23:13 +0200 | [diff] [blame] | 3149 | { |
| 3150 | struct fib_notifier_ops *ops; |
| 3151 | |
| 3152 | net->ipv4.ipmr_seq = 0; |
| 3153 | |
| 3154 | ops = fib_notifier_ops_register(&ipmr_notifier_ops_template, net); |
| 3155 | if (IS_ERR(ops)) |
| 3156 | return PTR_ERR(ops); |
| 3157 | net->ipv4.ipmr_notifier_ops = ops; |
| 3158 | |
| 3159 | return 0; |
| 3160 | } |
| 3161 | |
| 3162 | static void __net_exit ipmr_notifier_exit(struct net *net) |
| 3163 | { |
| 3164 | fib_notifier_ops_unregister(net->ipv4.ipmr_notifier_ops); |
| 3165 | net->ipv4.ipmr_notifier_ops = NULL; |
| 3166 | } |
| 3167 | |
Nikolay Aleksandrov | 7ef8f65 | 2015-11-21 15:57:27 +0100 | [diff] [blame] | 3168 | /* Setup for IP multicast routing */ |
Benjamin Thery | cf958ae3 | 2009-01-22 04:56:16 +0000 | [diff] [blame] | 3169 | static int __net_init ipmr_net_init(struct net *net) |
| 3170 | { |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 3171 | int err; |
Benjamin Thery | cf958ae3 | 2009-01-22 04:56:16 +0000 | [diff] [blame] | 3172 | |
Yotam Gigi | 4d65b94 | 2017-09-27 08:23:13 +0200 | [diff] [blame] | 3173 | err = ipmr_notifier_init(net); |
| 3174 | if (err) |
| 3175 | goto ipmr_notifier_fail; |
| 3176 | |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 3177 | err = ipmr_rules_init(net); |
| 3178 | if (err < 0) |
Yotam Gigi | 4d65b94 | 2017-09-27 08:23:13 +0200 | [diff] [blame] | 3179 | goto ipmr_rules_fail; |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 3180 | |
| 3181 | #ifdef CONFIG_PROC_FS |
| 3182 | err = -ENOMEM; |
Gao feng | d4beaa6 | 2013-02-18 01:34:54 +0000 | [diff] [blame] | 3183 | if (!proc_create("ip_mr_vif", 0, net->proc_net, &ipmr_vif_fops)) |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 3184 | goto proc_vif_fail; |
Gao feng | d4beaa6 | 2013-02-18 01:34:54 +0000 | [diff] [blame] | 3185 | if (!proc_create("ip_mr_cache", 0, net->proc_net, &ipmr_mfc_fops)) |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 3186 | goto proc_cache_fail; |
| 3187 | #endif |
Benjamin Thery | 2bb8b26 | 2009-01-22 04:56:18 +0000 | [diff] [blame] | 3188 | return 0; |
| 3189 | |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 3190 | #ifdef CONFIG_PROC_FS |
| 3191 | proc_cache_fail: |
Gao feng | ece31ff | 2013-02-18 01:34:56 +0000 | [diff] [blame] | 3192 | remove_proc_entry("ip_mr_vif", net->proc_net); |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 3193 | proc_vif_fail: |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 3194 | ipmr_rules_exit(net); |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 3195 | #endif |
Yotam Gigi | 4d65b94 | 2017-09-27 08:23:13 +0200 | [diff] [blame] | 3196 | ipmr_rules_fail: |
| 3197 | ipmr_notifier_exit(net); |
| 3198 | ipmr_notifier_fail: |
Benjamin Thery | cf958ae3 | 2009-01-22 04:56:16 +0000 | [diff] [blame] | 3199 | return err; |
| 3200 | } |
| 3201 | |
| 3202 | static void __net_exit ipmr_net_exit(struct net *net) |
| 3203 | { |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 3204 | #ifdef CONFIG_PROC_FS |
Gao feng | ece31ff | 2013-02-18 01:34:56 +0000 | [diff] [blame] | 3205 | remove_proc_entry("ip_mr_cache", net->proc_net); |
| 3206 | remove_proc_entry("ip_mr_vif", net->proc_net); |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 3207 | #endif |
Yotam Gigi | 4d65b94 | 2017-09-27 08:23:13 +0200 | [diff] [blame] | 3208 | ipmr_notifier_exit(net); |
Patrick McHardy | f0ad086 | 2010-04-13 05:03:23 +0000 | [diff] [blame] | 3209 | ipmr_rules_exit(net); |
Benjamin Thery | cf958ae3 | 2009-01-22 04:56:16 +0000 | [diff] [blame] | 3210 | } |
| 3211 | |
| 3212 | static struct pernet_operations ipmr_net_ops = { |
| 3213 | .init = ipmr_net_init, |
| 3214 | .exit = ipmr_net_exit, |
Kirill Tkhai | f84c682 | 2018-02-13 12:29:52 +0300 | [diff] [blame] | 3215 | .async = true, |
Benjamin Thery | cf958ae3 | 2009-01-22 04:56:16 +0000 | [diff] [blame] | 3216 | }; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 3217 | |
Wang Chen | 03d2f89 | 2008-07-03 12:13:36 +0800 | [diff] [blame] | 3218 | int __init ip_mr_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | { |
Wang Chen | 03d2f89 | 2008-07-03 12:13:36 +0800 | [diff] [blame] | 3220 | int err; |
| 3221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3222 | mrt_cachep = kmem_cache_create("ip_mrt_cache", |
| 3223 | sizeof(struct mfc_cache), |
Eric Dumazet | a8c9486 | 2010-10-01 16:15:08 +0000 | [diff] [blame] | 3224 | 0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 3225 | NULL); |
Wang Chen | 03d2f89 | 2008-07-03 12:13:36 +0800 | [diff] [blame] | 3226 | |
Benjamin Thery | cf958ae3 | 2009-01-22 04:56:16 +0000 | [diff] [blame] | 3227 | err = register_pernet_subsys(&ipmr_net_ops); |
| 3228 | if (err) |
| 3229 | goto reg_pernet_fail; |
| 3230 | |
Wang Chen | 03d2f89 | 2008-07-03 12:13:36 +0800 | [diff] [blame] | 3231 | err = register_netdevice_notifier(&ip_mr_notifier); |
| 3232 | if (err) |
| 3233 | goto reg_notif_fail; |
Tom Goff | 403dbb9 | 2009-06-14 03:16:13 -0700 | [diff] [blame] | 3234 | #ifdef CONFIG_IP_PIMSM_V2 |
| 3235 | if (inet_add_protocol(&pim_protocol, IPPROTO_PIM) < 0) { |
Joe Perches | 058bd4d | 2012-03-11 18:36:11 +0000 | [diff] [blame] | 3236 | pr_err("%s: can't add PIM protocol\n", __func__); |
Tom Goff | 403dbb9 | 2009-06-14 03:16:13 -0700 | [diff] [blame] | 3237 | err = -EAGAIN; |
| 3238 | goto add_proto_fail; |
| 3239 | } |
| 3240 | #endif |
Greg Rose | c7ac867 | 2011-06-10 01:27:09 +0000 | [diff] [blame] | 3241 | rtnl_register(RTNL_FAMILY_IPMR, RTM_GETROUTE, |
Florian Westphal | b97bac6 | 2017-08-09 20:41:48 +0200 | [diff] [blame] | 3242 | ipmr_rtm_getroute, ipmr_rtm_dumproute, 0); |
Nikolay Aleksandrov | ccbb0aa | 2015-11-26 15:23:50 +0100 | [diff] [blame] | 3243 | rtnl_register(RTNL_FAMILY_IPMR, RTM_NEWROUTE, |
Florian Westphal | b97bac6 | 2017-08-09 20:41:48 +0200 | [diff] [blame] | 3244 | ipmr_rtm_route, NULL, 0); |
Nikolay Aleksandrov | ccbb0aa | 2015-11-26 15:23:50 +0100 | [diff] [blame] | 3245 | rtnl_register(RTNL_FAMILY_IPMR, RTM_DELROUTE, |
Florian Westphal | b97bac6 | 2017-08-09 20:41:48 +0200 | [diff] [blame] | 3246 | ipmr_rtm_route, NULL, 0); |
Nikolay Aleksandrov | 772c344 | 2017-06-07 18:02:32 +0300 | [diff] [blame] | 3247 | |
| 3248 | rtnl_register(RTNL_FAMILY_IPMR, RTM_GETLINK, |
Florian Westphal | b97bac6 | 2017-08-09 20:41:48 +0200 | [diff] [blame] | 3249 | NULL, ipmr_rtm_dumplink, 0); |
Wang Chen | 03d2f89 | 2008-07-03 12:13:36 +0800 | [diff] [blame] | 3250 | return 0; |
Benjamin Thery | f6bb451 | 2009-01-22 04:56:22 +0000 | [diff] [blame] | 3251 | |
Tom Goff | 403dbb9 | 2009-06-14 03:16:13 -0700 | [diff] [blame] | 3252 | #ifdef CONFIG_IP_PIMSM_V2 |
| 3253 | add_proto_fail: |
| 3254 | unregister_netdevice_notifier(&ip_mr_notifier); |
| 3255 | #endif |
Benjamin Thery | c3e3889 | 2008-11-19 14:07:41 -0800 | [diff] [blame] | 3256 | reg_notif_fail: |
Benjamin Thery | cf958ae3 | 2009-01-22 04:56:16 +0000 | [diff] [blame] | 3257 | unregister_pernet_subsys(&ipmr_net_ops); |
| 3258 | reg_pernet_fail: |
Benjamin Thery | c3e3889 | 2008-11-19 14:07:41 -0800 | [diff] [blame] | 3259 | kmem_cache_destroy(mrt_cachep); |
Wang Chen | 03d2f89 | 2008-07-03 12:13:36 +0800 | [diff] [blame] | 3260 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | } |