Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Linux NET3: Internet Group Management Protocol [IGMP] |
| 3 | * |
| 4 | * This code implements the IGMP protocol as defined in RFC1112. There has |
| 5 | * been a further revision of this protocol since which is now supported. |
| 6 | * |
| 7 | * If you have trouble with this module be careful what gcc you have used, |
| 8 | * the older version didn't come out right using gcc 2.5.8, the newer one |
| 9 | * seems to fall out with gcc 2.6.2. |
| 10 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * Authors: |
Alan Cox | 113aa83 | 2008-10-13 19:01:08 -0700 | [diff] [blame] | 12 | * Alan Cox <alan@lxorguk.ukuu.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License |
| 16 | * as published by the Free Software Foundation; either version |
| 17 | * 2 of the License, or (at your option) any later version. |
| 18 | * |
| 19 | * Fixes: |
| 20 | * |
| 21 | * Alan Cox : Added lots of __inline__ to optimise |
| 22 | * the memory usage of all the tiny little |
| 23 | * functions. |
| 24 | * Alan Cox : Dumped the header building experiment. |
| 25 | * Alan Cox : Minor tweaks ready for multicast routing |
| 26 | * and extended IGMP protocol. |
| 27 | * Alan Cox : Removed a load of inline directives. Gcc 2.5.8 |
| 28 | * writes utterly bogus code otherwise (sigh) |
| 29 | * fixed IGMP loopback to behave in the manner |
| 30 | * desired by mrouted, fixed the fact it has been |
| 31 | * broken since 1.3.6 and cleaned up a few minor |
| 32 | * points. |
| 33 | * |
| 34 | * Chih-Jen Chang : Tried to revise IGMP to Version 2 |
| 35 | * Tsu-Sheng Tsao E-mail: chihjenc@scf.usc.edu and tsusheng@scf.usc.edu |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 36 | * The enhancements are mainly based on Steve Deering's |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | * ipmulti-3.5 source code. |
| 38 | * Chih-Jen Chang : Added the igmp_get_mrouter_info and |
| 39 | * Tsu-Sheng Tsao igmp_set_mrouter_info to keep track of |
| 40 | * the mrouted version on that device. |
| 41 | * Chih-Jen Chang : Added the max_resp_time parameter to |
| 42 | * Tsu-Sheng Tsao igmp_heard_query(). Using this parameter |
| 43 | * to identify the multicast router version |
| 44 | * and do what the IGMP version 2 specified. |
| 45 | * Chih-Jen Chang : Added a timer to revert to IGMP V2 router |
| 46 | * Tsu-Sheng Tsao if the specified time expired. |
| 47 | * Alan Cox : Stop IGMP from 0.0.0.0 being accepted. |
| 48 | * Alan Cox : Use GFP_ATOMIC in the right places. |
| 49 | * Christian Daudt : igmp timer wasn't set for local group |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 50 | * memberships but was being deleted, |
| 51 | * which caused a "del_timer() called |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | * from %p with timer not initialized\n" |
| 53 | * message (960131). |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 54 | * Christian Daudt : removed del_timer from |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | * igmp_timer_expire function (960205). |
| 56 | * Christian Daudt : igmp_heard_report now only calls |
| 57 | * igmp_timer_expire if tm->running is |
| 58 | * true (960216). |
| 59 | * Malcolm Beattie : ttl comparison wrong in igmp_rcv made |
| 60 | * igmp_heard_query never trigger. Expiry |
| 61 | * miscalculation fixed in igmp_heard_query |
| 62 | * and random() made to return unsigned to |
| 63 | * prevent negative expiry times. |
| 64 | * Alexey Kuznetsov: Wrong group leaving behaviour, backport |
| 65 | * fix from pending 2.1.x patches. |
| 66 | * Alan Cox: Forget to enable FDDI support earlier. |
| 67 | * Alexey Kuznetsov: Fixed leaving groups on device down. |
| 68 | * Alexey Kuznetsov: Accordance to igmp-v2-06 draft. |
| 69 | * David L Stevens: IGMPv3 support, with help from |
| 70 | * Vinay Kulkarni |
| 71 | */ |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 74 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #include <asm/uaccess.h> |
| 76 | #include <asm/system.h> |
| 77 | #include <linux/types.h> |
| 78 | #include <linux/kernel.h> |
| 79 | #include <linux/jiffies.h> |
| 80 | #include <linux/string.h> |
| 81 | #include <linux/socket.h> |
| 82 | #include <linux/sockios.h> |
| 83 | #include <linux/in.h> |
| 84 | #include <linux/inet.h> |
| 85 | #include <linux/netdevice.h> |
| 86 | #include <linux/skbuff.h> |
| 87 | #include <linux/inetdevice.h> |
| 88 | #include <linux/igmp.h> |
| 89 | #include <linux/if_arp.h> |
| 90 | #include <linux/rtnetlink.h> |
| 91 | #include <linux/times.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 92 | |
Eric W. Biederman | 457c4cb | 2007-09-12 12:01:34 +0200 | [diff] [blame] | 93 | #include <net/net_namespace.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 94 | #include <net/arp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | #include <net/ip.h> |
| 96 | #include <net/protocol.h> |
| 97 | #include <net/route.h> |
| 98 | #include <net/sock.h> |
| 99 | #include <net/checksum.h> |
| 100 | #include <linux/netfilter_ipv4.h> |
| 101 | #ifdef CONFIG_IP_MROUTE |
| 102 | #include <linux/mroute.h> |
| 103 | #endif |
| 104 | #ifdef CONFIG_PROC_FS |
| 105 | #include <linux/proc_fs.h> |
| 106 | #include <linux/seq_file.h> |
| 107 | #endif |
| 108 | |
| 109 | #define IP_MAX_MEMBERSHIPS 20 |
| 110 | #define IP_MAX_MSF 10 |
| 111 | |
| 112 | #ifdef CONFIG_IP_MULTICAST |
| 113 | /* Parameter names and values are taken from igmp-v2-06 draft */ |
| 114 | |
| 115 | #define IGMP_V1_Router_Present_Timeout (400*HZ) |
| 116 | #define IGMP_V2_Router_Present_Timeout (400*HZ) |
| 117 | #define IGMP_Unsolicited_Report_Interval (10*HZ) |
| 118 | #define IGMP_Query_Response_Interval (10*HZ) |
| 119 | #define IGMP_Unsolicited_Report_Count 2 |
| 120 | |
| 121 | |
| 122 | #define IGMP_Initial_Report_Delay (1) |
| 123 | |
| 124 | /* IGMP_Initial_Report_Delay is not from IGMP specs! |
| 125 | * IGMP specs require to report membership immediately after |
| 126 | * joining a group, but we delay the first report by a |
| 127 | * small interval. It seems more natural and still does not |
| 128 | * contradict to specs provided this delay is small enough. |
| 129 | */ |
| 130 | |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 131 | #define IGMP_V1_SEEN(in_dev) \ |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 132 | (IPV4_DEVCONF_ALL(dev_net(in_dev->dev), FORCE_IGMP_VERSION) == 1 || \ |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 133 | IN_DEV_CONF_GET((in_dev), FORCE_IGMP_VERSION) == 1 || \ |
| 134 | ((in_dev)->mr_v1_seen && \ |
| 135 | time_before(jiffies, (in_dev)->mr_v1_seen))) |
| 136 | #define IGMP_V2_SEEN(in_dev) \ |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 137 | (IPV4_DEVCONF_ALL(dev_net(in_dev->dev), FORCE_IGMP_VERSION) == 2 || \ |
Herbert Xu | 42f811b | 2007-06-04 23:34:44 -0700 | [diff] [blame] | 138 | IN_DEV_CONF_GET((in_dev), FORCE_IGMP_VERSION) == 2 || \ |
| 139 | ((in_dev)->mr_v2_seen && \ |
| 140 | time_before(jiffies, (in_dev)->mr_v2_seen))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | static void igmpv3_add_delrec(struct in_device *in_dev, struct ip_mc_list *im); |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 143 | static void igmpv3_del_delrec(struct in_device *in_dev, __be32 multiaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | static void igmpv3_clear_delrec(struct in_device *in_dev); |
| 145 | static int sf_setstate(struct ip_mc_list *pmc); |
| 146 | static void sf_markstate(struct ip_mc_list *pmc); |
| 147 | #endif |
| 148 | static void ip_mc_clear_src(struct ip_mc_list *pmc); |
Al Viro | 8f935bb | 2006-09-27 18:30:07 -0700 | [diff] [blame] | 149 | static int ip_mc_add_src(struct in_device *in_dev, __be32 *pmca, int sfmode, |
| 150 | int sfcount, __be32 *psfsrc, int delta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 152 | |
| 153 | static void ip_mc_list_reclaim(struct rcu_head *head) |
| 154 | { |
| 155 | kfree(container_of(head, struct ip_mc_list, rcu)); |
| 156 | } |
| 157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | static void ip_ma_put(struct ip_mc_list *im) |
| 159 | { |
| 160 | if (atomic_dec_and_test(&im->refcnt)) { |
| 161 | in_dev_put(im->interface); |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 162 | call_rcu(&im->rcu, ip_mc_list_reclaim); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
David S. Miller | d9aa938 | 2010-11-15 08:52:02 -0800 | [diff] [blame] | 166 | #define for_each_pmc_rcu(in_dev, pmc) \ |
| 167 | for (pmc = rcu_dereference(in_dev->mc_list); \ |
| 168 | pmc != NULL; \ |
| 169 | pmc = rcu_dereference(pmc->next_rcu)) |
| 170 | |
| 171 | #define for_each_pmc_rtnl(in_dev, pmc) \ |
| 172 | for (pmc = rtnl_dereference(in_dev->mc_list); \ |
| 173 | pmc != NULL; \ |
| 174 | pmc = rtnl_dereference(pmc->next_rcu)) |
| 175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | #ifdef CONFIG_IP_MULTICAST |
| 177 | |
| 178 | /* |
| 179 | * Timer management |
| 180 | */ |
| 181 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 182 | static void igmp_stop_timer(struct ip_mc_list *im) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | { |
| 184 | spin_lock_bh(&im->lock); |
| 185 | if (del_timer(&im->timer)) |
| 186 | atomic_dec(&im->refcnt); |
Jianjun Kong | a7e9ff7 | 2008-11-03 00:26:09 -0800 | [diff] [blame] | 187 | im->tm_running = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | im->reporter = 0; |
| 189 | im->unsolicit_count = 0; |
| 190 | spin_unlock_bh(&im->lock); |
| 191 | } |
| 192 | |
| 193 | /* It must be called with locked im->lock */ |
| 194 | static void igmp_start_timer(struct ip_mc_list *im, int max_delay) |
| 195 | { |
Jianjun Kong | a7e9ff7 | 2008-11-03 00:26:09 -0800 | [diff] [blame] | 196 | int tv = net_random() % max_delay; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Jianjun Kong | a7e9ff7 | 2008-11-03 00:26:09 -0800 | [diff] [blame] | 198 | im->tm_running = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | if (!mod_timer(&im->timer, jiffies+tv+2)) |
| 200 | atomic_inc(&im->refcnt); |
| 201 | } |
| 202 | |
| 203 | static void igmp_gq_start_timer(struct in_device *in_dev) |
| 204 | { |
| 205 | int tv = net_random() % in_dev->mr_maxdelay; |
| 206 | |
| 207 | in_dev->mr_gq_running = 1; |
| 208 | if (!mod_timer(&in_dev->mr_gq_timer, jiffies+tv+2)) |
| 209 | in_dev_hold(in_dev); |
| 210 | } |
| 211 | |
| 212 | static void igmp_ifc_start_timer(struct in_device *in_dev, int delay) |
| 213 | { |
| 214 | int tv = net_random() % delay; |
| 215 | |
| 216 | if (!mod_timer(&in_dev->mr_ifc_timer, jiffies+tv+2)) |
| 217 | in_dev_hold(in_dev); |
| 218 | } |
| 219 | |
| 220 | static void igmp_mod_timer(struct ip_mc_list *im, int max_delay) |
| 221 | { |
| 222 | spin_lock_bh(&im->lock); |
| 223 | im->unsolicit_count = 0; |
| 224 | if (del_timer(&im->timer)) { |
| 225 | if ((long)(im->timer.expires-jiffies) < max_delay) { |
| 226 | add_timer(&im->timer); |
Jianjun Kong | a7e9ff7 | 2008-11-03 00:26:09 -0800 | [diff] [blame] | 227 | im->tm_running = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | spin_unlock_bh(&im->lock); |
| 229 | return; |
| 230 | } |
| 231 | atomic_dec(&im->refcnt); |
| 232 | } |
| 233 | igmp_start_timer(im, max_delay); |
| 234 | spin_unlock_bh(&im->lock); |
| 235 | } |
| 236 | |
| 237 | |
| 238 | /* |
| 239 | * Send an IGMP report. |
| 240 | */ |
| 241 | |
| 242 | #define IGMP_SIZE (sizeof(struct igmphdr)+sizeof(struct iphdr)+4) |
| 243 | |
| 244 | |
| 245 | static int is_in(struct ip_mc_list *pmc, struct ip_sf_list *psf, int type, |
| 246 | int gdeleted, int sdeleted) |
| 247 | { |
| 248 | switch (type) { |
| 249 | case IGMPV3_MODE_IS_INCLUDE: |
| 250 | case IGMPV3_MODE_IS_EXCLUDE: |
| 251 | if (gdeleted || sdeleted) |
| 252 | return 0; |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 253 | if (!(pmc->gsquery && !psf->sf_gsresp)) { |
| 254 | if (pmc->sfmode == MCAST_INCLUDE) |
| 255 | return 1; |
| 256 | /* don't include if this source is excluded |
| 257 | * in all filters |
| 258 | */ |
| 259 | if (psf->sf_count[MCAST_INCLUDE]) |
| 260 | return type == IGMPV3_MODE_IS_INCLUDE; |
| 261 | return pmc->sfcount[MCAST_EXCLUDE] == |
| 262 | psf->sf_count[MCAST_EXCLUDE]; |
| 263 | } |
| 264 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | case IGMPV3_CHANGE_TO_INCLUDE: |
| 266 | if (gdeleted || sdeleted) |
| 267 | return 0; |
| 268 | return psf->sf_count[MCAST_INCLUDE] != 0; |
| 269 | case IGMPV3_CHANGE_TO_EXCLUDE: |
| 270 | if (gdeleted || sdeleted) |
| 271 | return 0; |
| 272 | if (pmc->sfcount[MCAST_EXCLUDE] == 0 || |
| 273 | psf->sf_count[MCAST_INCLUDE]) |
| 274 | return 0; |
| 275 | return pmc->sfcount[MCAST_EXCLUDE] == |
| 276 | psf->sf_count[MCAST_EXCLUDE]; |
| 277 | case IGMPV3_ALLOW_NEW_SOURCES: |
| 278 | if (gdeleted || !psf->sf_crcount) |
| 279 | return 0; |
| 280 | return (pmc->sfmode == MCAST_INCLUDE) ^ sdeleted; |
| 281 | case IGMPV3_BLOCK_OLD_SOURCES: |
| 282 | if (pmc->sfmode == MCAST_INCLUDE) |
| 283 | return gdeleted || (psf->sf_crcount && sdeleted); |
| 284 | return psf->sf_crcount && !gdeleted && !sdeleted; |
| 285 | } |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | static int |
| 290 | igmp_scount(struct ip_mc_list *pmc, int type, int gdeleted, int sdeleted) |
| 291 | { |
| 292 | struct ip_sf_list *psf; |
| 293 | int scount = 0; |
| 294 | |
| 295 | for (psf=pmc->sources; psf; psf=psf->sf_next) { |
| 296 | if (!is_in(pmc, psf, type, gdeleted, sdeleted)) |
| 297 | continue; |
| 298 | scount++; |
| 299 | } |
| 300 | return scount; |
| 301 | } |
| 302 | |
| 303 | static struct sk_buff *igmpv3_newpack(struct net_device *dev, int size) |
| 304 | { |
| 305 | struct sk_buff *skb; |
| 306 | struct rtable *rt; |
| 307 | struct iphdr *pip; |
| 308 | struct igmpv3_report *pig; |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 309 | struct net *net = dev_net(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Johannes Berg | f5184d2 | 2008-05-12 20:48:31 -0700 | [diff] [blame] | 311 | skb = alloc_skb(size + LL_ALLOCATED_SPACE(dev), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | if (skb == NULL) |
| 313 | return NULL; |
| 314 | |
| 315 | { |
| 316 | struct flowi fl = { .oif = dev->ifindex, |
Changli Gao | 5811662 | 2010-11-12 18:43:55 +0000 | [diff] [blame] | 317 | .fl4_dst = IGMPV3_ALL_MCR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | .proto = IPPROTO_IGMP }; |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 319 | if (ip_route_output_key(net, &rt, &fl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | kfree_skb(skb); |
| 321 | return NULL; |
| 322 | } |
| 323 | } |
| 324 | if (rt->rt_src == 0) { |
| 325 | kfree_skb(skb); |
| 326 | ip_rt_put(rt); |
| 327 | return NULL; |
| 328 | } |
| 329 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 330 | skb_dst_set(skb, &rt->dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | skb->dev = dev; |
| 332 | |
| 333 | skb_reserve(skb, LL_RESERVED_SPACE(dev)); |
| 334 | |
Arnaldo Carvalho de Melo | 7e28ecc | 2007-03-10 18:40:59 -0300 | [diff] [blame] | 335 | skb_reset_network_header(skb); |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 336 | pip = ip_hdr(skb); |
Arnaldo Carvalho de Melo | 7e28ecc | 2007-03-10 18:40:59 -0300 | [diff] [blame] | 337 | skb_put(skb, sizeof(struct iphdr) + 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | pip->version = 4; |
| 340 | pip->ihl = (sizeof(struct iphdr)+4)>>2; |
| 341 | pip->tos = 0xc0; |
| 342 | pip->frag_off = htons(IP_DF); |
| 343 | pip->ttl = 1; |
| 344 | pip->daddr = rt->rt_dst; |
| 345 | pip->saddr = rt->rt_src; |
| 346 | pip->protocol = IPPROTO_IGMP; |
| 347 | pip->tot_len = 0; /* filled in later */ |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 348 | ip_select_ident(pip, &rt->dst, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | ((u8*)&pip[1])[0] = IPOPT_RA; |
| 350 | ((u8*)&pip[1])[1] = 4; |
| 351 | ((u8*)&pip[1])[2] = 0; |
| 352 | ((u8*)&pip[1])[3] = 0; |
| 353 | |
Arnaldo Carvalho de Melo | b0e380b | 2007-04-10 21:21:55 -0700 | [diff] [blame] | 354 | skb->transport_header = skb->network_header + sizeof(struct iphdr) + 4; |
Arnaldo Carvalho de Melo | d10ba34 | 2007-03-14 21:05:37 -0300 | [diff] [blame] | 355 | skb_put(skb, sizeof(*pig)); |
Arnaldo Carvalho de Melo | d9edf9e | 2007-03-13 14:19:23 -0300 | [diff] [blame] | 356 | pig = igmpv3_report_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | pig->type = IGMPV3_HOST_MEMBERSHIP_REPORT; |
| 358 | pig->resv1 = 0; |
| 359 | pig->csum = 0; |
| 360 | pig->resv2 = 0; |
| 361 | pig->ngrec = 0; |
| 362 | return skb; |
| 363 | } |
| 364 | |
| 365 | static int igmpv3_sendpack(struct sk_buff *skb) |
| 366 | { |
Arnaldo Carvalho de Melo | d9edf9e | 2007-03-13 14:19:23 -0300 | [diff] [blame] | 367 | struct igmphdr *pig = igmp_hdr(skb); |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 368 | const int igmplen = skb->tail - skb->transport_header; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Arnaldo Carvalho de Melo | d9edf9e | 2007-03-13 14:19:23 -0300 | [diff] [blame] | 370 | pig->csum = ip_compute_csum(igmp_hdr(skb), igmplen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Herbert Xu | c439cb2 | 2008-01-11 19:14:00 -0800 | [diff] [blame] | 372 | return ip_local_out(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | static int grec_size(struct ip_mc_list *pmc, int type, int gdel, int sdel) |
| 376 | { |
Jianjun Kong | a7e9ff7 | 2008-11-03 00:26:09 -0800 | [diff] [blame] | 377 | return sizeof(struct igmpv3_grec) + 4*igmp_scount(pmc, type, gdel, sdel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | static struct sk_buff *add_grhead(struct sk_buff *skb, struct ip_mc_list *pmc, |
| 381 | int type, struct igmpv3_grec **ppgr) |
| 382 | { |
| 383 | struct net_device *dev = pmc->interface->dev; |
| 384 | struct igmpv3_report *pih; |
| 385 | struct igmpv3_grec *pgr; |
| 386 | |
| 387 | if (!skb) |
| 388 | skb = igmpv3_newpack(dev, dev->mtu); |
| 389 | if (!skb) |
| 390 | return NULL; |
| 391 | pgr = (struct igmpv3_grec *)skb_put(skb, sizeof(struct igmpv3_grec)); |
| 392 | pgr->grec_type = type; |
| 393 | pgr->grec_auxwords = 0; |
| 394 | pgr->grec_nsrcs = 0; |
| 395 | pgr->grec_mca = pmc->multiaddr; |
Arnaldo Carvalho de Melo | d9edf9e | 2007-03-13 14:19:23 -0300 | [diff] [blame] | 396 | pih = igmpv3_report_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | pih->ngrec = htons(ntohs(pih->ngrec)+1); |
| 398 | *ppgr = pgr; |
| 399 | return skb; |
| 400 | } |
| 401 | |
| 402 | #define AVAILABLE(skb) ((skb) ? ((skb)->dev ? (skb)->dev->mtu - (skb)->len : \ |
| 403 | skb_tailroom(skb)) : 0) |
| 404 | |
| 405 | static struct sk_buff *add_grec(struct sk_buff *skb, struct ip_mc_list *pmc, |
| 406 | int type, int gdeleted, int sdeleted) |
| 407 | { |
| 408 | struct net_device *dev = pmc->interface->dev; |
| 409 | struct igmpv3_report *pih; |
| 410 | struct igmpv3_grec *pgr = NULL; |
| 411 | struct ip_sf_list *psf, *psf_next, *psf_prev, **psf_list; |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 412 | int scount, stotal, first, isquery, truncate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
| 414 | if (pmc->multiaddr == IGMP_ALL_HOSTS) |
| 415 | return skb; |
| 416 | |
| 417 | isquery = type == IGMPV3_MODE_IS_INCLUDE || |
| 418 | type == IGMPV3_MODE_IS_EXCLUDE; |
| 419 | truncate = type == IGMPV3_MODE_IS_EXCLUDE || |
| 420 | type == IGMPV3_CHANGE_TO_EXCLUDE; |
| 421 | |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 422 | stotal = scount = 0; |
| 423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | psf_list = sdeleted ? &pmc->tomb : &pmc->sources; |
| 425 | |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 426 | if (!*psf_list) |
| 427 | goto empty_source; |
| 428 | |
Arnaldo Carvalho de Melo | d9edf9e | 2007-03-13 14:19:23 -0300 | [diff] [blame] | 429 | pih = skb ? igmpv3_report_hdr(skb) : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
| 431 | /* EX and TO_EX get a fresh packet, if needed */ |
| 432 | if (truncate) { |
| 433 | if (pih && pih->ngrec && |
| 434 | AVAILABLE(skb) < grec_size(pmc, type, gdeleted, sdeleted)) { |
| 435 | if (skb) |
| 436 | igmpv3_sendpack(skb); |
| 437 | skb = igmpv3_newpack(dev, dev->mtu); |
| 438 | } |
| 439 | } |
| 440 | first = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | psf_prev = NULL; |
| 442 | for (psf=*psf_list; psf; psf=psf_next) { |
Al Viro | ea4d9e7 | 2006-09-27 18:30:52 -0700 | [diff] [blame] | 443 | __be32 *psrc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
| 445 | psf_next = psf->sf_next; |
| 446 | |
| 447 | if (!is_in(pmc, psf, type, gdeleted, sdeleted)) { |
| 448 | psf_prev = psf; |
| 449 | continue; |
| 450 | } |
| 451 | |
| 452 | /* clear marks on query responses */ |
| 453 | if (isquery) |
| 454 | psf->sf_gsresp = 0; |
| 455 | |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 456 | if (AVAILABLE(skb) < sizeof(__be32) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | first*sizeof(struct igmpv3_grec)) { |
| 458 | if (truncate && !first) |
| 459 | break; /* truncate these */ |
| 460 | if (pgr) |
| 461 | pgr->grec_nsrcs = htons(scount); |
| 462 | if (skb) |
| 463 | igmpv3_sendpack(skb); |
| 464 | skb = igmpv3_newpack(dev, dev->mtu); |
| 465 | first = 1; |
| 466 | scount = 0; |
| 467 | } |
| 468 | if (first) { |
| 469 | skb = add_grhead(skb, pmc, type, &pgr); |
| 470 | first = 0; |
| 471 | } |
Alexey Dobriyan | cc63f70 | 2007-02-06 14:35:25 -0800 | [diff] [blame] | 472 | if (!skb) |
| 473 | return NULL; |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 474 | psrc = (__be32 *)skb_put(skb, sizeof(__be32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | *psrc = psf->sf_inaddr; |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 476 | scount++; stotal++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | if ((type == IGMPV3_ALLOW_NEW_SOURCES || |
| 478 | type == IGMPV3_BLOCK_OLD_SOURCES) && psf->sf_crcount) { |
| 479 | psf->sf_crcount--; |
| 480 | if ((sdeleted || gdeleted) && psf->sf_crcount == 0) { |
| 481 | if (psf_prev) |
| 482 | psf_prev->sf_next = psf->sf_next; |
| 483 | else |
| 484 | *psf_list = psf->sf_next; |
| 485 | kfree(psf); |
| 486 | continue; |
| 487 | } |
| 488 | } |
| 489 | psf_prev = psf; |
| 490 | } |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 491 | |
| 492 | empty_source: |
| 493 | if (!stotal) { |
| 494 | if (type == IGMPV3_ALLOW_NEW_SOURCES || |
| 495 | type == IGMPV3_BLOCK_OLD_SOURCES) |
| 496 | return skb; |
| 497 | if (pmc->crcount || isquery) { |
| 498 | /* make sure we have room for group header */ |
| 499 | if (skb && AVAILABLE(skb)<sizeof(struct igmpv3_grec)) { |
| 500 | igmpv3_sendpack(skb); |
| 501 | skb = NULL; /* add_grhead will get a new one */ |
| 502 | } |
| 503 | skb = add_grhead(skb, pmc, type, &pgr); |
| 504 | } |
| 505 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | if (pgr) |
| 507 | pgr->grec_nsrcs = htons(scount); |
| 508 | |
| 509 | if (isquery) |
| 510 | pmc->gsquery = 0; /* clear query state on report */ |
| 511 | return skb; |
| 512 | } |
| 513 | |
| 514 | static int igmpv3_send_report(struct in_device *in_dev, struct ip_mc_list *pmc) |
| 515 | { |
| 516 | struct sk_buff *skb = NULL; |
| 517 | int type; |
| 518 | |
| 519 | if (!pmc) { |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 520 | rcu_read_lock(); |
| 521 | for_each_pmc_rcu(in_dev, pmc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | if (pmc->multiaddr == IGMP_ALL_HOSTS) |
| 523 | continue; |
| 524 | spin_lock_bh(&pmc->lock); |
| 525 | if (pmc->sfcount[MCAST_EXCLUDE]) |
| 526 | type = IGMPV3_MODE_IS_EXCLUDE; |
| 527 | else |
| 528 | type = IGMPV3_MODE_IS_INCLUDE; |
| 529 | skb = add_grec(skb, pmc, type, 0, 0); |
| 530 | spin_unlock_bh(&pmc->lock); |
| 531 | } |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 532 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | } else { |
| 534 | spin_lock_bh(&pmc->lock); |
| 535 | if (pmc->sfcount[MCAST_EXCLUDE]) |
| 536 | type = IGMPV3_MODE_IS_EXCLUDE; |
| 537 | else |
| 538 | type = IGMPV3_MODE_IS_INCLUDE; |
| 539 | skb = add_grec(skb, pmc, type, 0, 0); |
| 540 | spin_unlock_bh(&pmc->lock); |
| 541 | } |
| 542 | if (!skb) |
| 543 | return 0; |
| 544 | return igmpv3_sendpack(skb); |
| 545 | } |
| 546 | |
| 547 | /* |
| 548 | * remove zero-count source records from a source filter list |
| 549 | */ |
| 550 | static void igmpv3_clear_zeros(struct ip_sf_list **ppsf) |
| 551 | { |
| 552 | struct ip_sf_list *psf_prev, *psf_next, *psf; |
| 553 | |
| 554 | psf_prev = NULL; |
| 555 | for (psf=*ppsf; psf; psf = psf_next) { |
| 556 | psf_next = psf->sf_next; |
| 557 | if (psf->sf_crcount == 0) { |
| 558 | if (psf_prev) |
| 559 | psf_prev->sf_next = psf->sf_next; |
| 560 | else |
| 561 | *ppsf = psf->sf_next; |
| 562 | kfree(psf); |
| 563 | } else |
| 564 | psf_prev = psf; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | static void igmpv3_send_cr(struct in_device *in_dev) |
| 569 | { |
| 570 | struct ip_mc_list *pmc, *pmc_prev, *pmc_next; |
| 571 | struct sk_buff *skb = NULL; |
| 572 | int type, dtype; |
| 573 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 574 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | spin_lock_bh(&in_dev->mc_tomb_lock); |
| 576 | |
| 577 | /* deleted MCA's */ |
| 578 | pmc_prev = NULL; |
| 579 | for (pmc=in_dev->mc_tomb; pmc; pmc=pmc_next) { |
| 580 | pmc_next = pmc->next; |
| 581 | if (pmc->sfmode == MCAST_INCLUDE) { |
| 582 | type = IGMPV3_BLOCK_OLD_SOURCES; |
| 583 | dtype = IGMPV3_BLOCK_OLD_SOURCES; |
| 584 | skb = add_grec(skb, pmc, type, 1, 0); |
| 585 | skb = add_grec(skb, pmc, dtype, 1, 1); |
| 586 | } |
| 587 | if (pmc->crcount) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | if (pmc->sfmode == MCAST_EXCLUDE) { |
| 589 | type = IGMPV3_CHANGE_TO_INCLUDE; |
| 590 | skb = add_grec(skb, pmc, type, 1, 0); |
| 591 | } |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 592 | pmc->crcount--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | if (pmc->crcount == 0) { |
| 594 | igmpv3_clear_zeros(&pmc->tomb); |
| 595 | igmpv3_clear_zeros(&pmc->sources); |
| 596 | } |
| 597 | } |
| 598 | if (pmc->crcount == 0 && !pmc->tomb && !pmc->sources) { |
| 599 | if (pmc_prev) |
| 600 | pmc_prev->next = pmc_next; |
| 601 | else |
| 602 | in_dev->mc_tomb = pmc_next; |
| 603 | in_dev_put(pmc->interface); |
| 604 | kfree(pmc); |
| 605 | } else |
| 606 | pmc_prev = pmc; |
| 607 | } |
| 608 | spin_unlock_bh(&in_dev->mc_tomb_lock); |
| 609 | |
| 610 | /* change recs */ |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 611 | for_each_pmc_rcu(in_dev, pmc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | spin_lock_bh(&pmc->lock); |
| 613 | if (pmc->sfcount[MCAST_EXCLUDE]) { |
| 614 | type = IGMPV3_BLOCK_OLD_SOURCES; |
| 615 | dtype = IGMPV3_ALLOW_NEW_SOURCES; |
| 616 | } else { |
| 617 | type = IGMPV3_ALLOW_NEW_SOURCES; |
| 618 | dtype = IGMPV3_BLOCK_OLD_SOURCES; |
| 619 | } |
| 620 | skb = add_grec(skb, pmc, type, 0, 0); |
| 621 | skb = add_grec(skb, pmc, dtype, 0, 1); /* deleted sources */ |
| 622 | |
| 623 | /* filter mode changes */ |
| 624 | if (pmc->crcount) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | if (pmc->sfmode == MCAST_EXCLUDE) |
| 626 | type = IGMPV3_CHANGE_TO_EXCLUDE; |
| 627 | else |
| 628 | type = IGMPV3_CHANGE_TO_INCLUDE; |
| 629 | skb = add_grec(skb, pmc, type, 0, 0); |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 630 | pmc->crcount--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
| 632 | spin_unlock_bh(&pmc->lock); |
| 633 | } |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 634 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
| 636 | if (!skb) |
| 637 | return; |
| 638 | (void) igmpv3_sendpack(skb); |
| 639 | } |
| 640 | |
| 641 | static int igmp_send_report(struct in_device *in_dev, struct ip_mc_list *pmc, |
| 642 | int type) |
| 643 | { |
| 644 | struct sk_buff *skb; |
| 645 | struct iphdr *iph; |
| 646 | struct igmphdr *ih; |
| 647 | struct rtable *rt; |
| 648 | struct net_device *dev = in_dev->dev; |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 649 | struct net *net = dev_net(dev); |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 650 | __be32 group = pmc ? pmc->multiaddr : 0; |
| 651 | __be32 dst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
| 653 | if (type == IGMPV3_HOST_MEMBERSHIP_REPORT) |
| 654 | return igmpv3_send_report(in_dev, pmc); |
| 655 | else if (type == IGMP_HOST_LEAVE_MESSAGE) |
| 656 | dst = IGMP_ALL_ROUTER; |
| 657 | else |
| 658 | dst = group; |
| 659 | |
| 660 | { |
| 661 | struct flowi fl = { .oif = dev->ifindex, |
Changli Gao | 5811662 | 2010-11-12 18:43:55 +0000 | [diff] [blame] | 662 | .fl4_dst = dst, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | .proto = IPPROTO_IGMP }; |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 664 | if (ip_route_output_key(net, &rt, &fl)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | return -1; |
| 666 | } |
| 667 | if (rt->rt_src == 0) { |
| 668 | ip_rt_put(rt); |
| 669 | return -1; |
| 670 | } |
| 671 | |
Jianjun Kong | a7e9ff7 | 2008-11-03 00:26:09 -0800 | [diff] [blame] | 672 | skb = alloc_skb(IGMP_SIZE+LL_ALLOCATED_SPACE(dev), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | if (skb == NULL) { |
| 674 | ip_rt_put(rt); |
| 675 | return -1; |
| 676 | } |
| 677 | |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 678 | skb_dst_set(skb, &rt->dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | |
| 680 | skb_reserve(skb, LL_RESERVED_SPACE(dev)); |
| 681 | |
Arnaldo Carvalho de Melo | 7e28ecc | 2007-03-10 18:40:59 -0300 | [diff] [blame] | 682 | skb_reset_network_header(skb); |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 683 | iph = ip_hdr(skb); |
Arnaldo Carvalho de Melo | 7e28ecc | 2007-03-10 18:40:59 -0300 | [diff] [blame] | 684 | skb_put(skb, sizeof(struct iphdr) + 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
| 686 | iph->version = 4; |
| 687 | iph->ihl = (sizeof(struct iphdr)+4)>>2; |
| 688 | iph->tos = 0xc0; |
| 689 | iph->frag_off = htons(IP_DF); |
| 690 | iph->ttl = 1; |
| 691 | iph->daddr = dst; |
| 692 | iph->saddr = rt->rt_src; |
| 693 | iph->protocol = IPPROTO_IGMP; |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 694 | ip_select_ident(iph, &rt->dst, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | ((u8*)&iph[1])[0] = IPOPT_RA; |
| 696 | ((u8*)&iph[1])[1] = 4; |
| 697 | ((u8*)&iph[1])[2] = 0; |
| 698 | ((u8*)&iph[1])[3] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | |
| 700 | ih = (struct igmphdr *)skb_put(skb, sizeof(struct igmphdr)); |
Jianjun Kong | a7e9ff7 | 2008-11-03 00:26:09 -0800 | [diff] [blame] | 701 | ih->type = type; |
| 702 | ih->code = 0; |
| 703 | ih->csum = 0; |
| 704 | ih->group = group; |
| 705 | ih->csum = ip_compute_csum((void *)ih, sizeof(struct igmphdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
Herbert Xu | c439cb2 | 2008-01-11 19:14:00 -0800 | [diff] [blame] | 707 | return ip_local_out(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | static void igmp_gq_timer_expire(unsigned long data) |
| 711 | { |
| 712 | struct in_device *in_dev = (struct in_device *)data; |
| 713 | |
| 714 | in_dev->mr_gq_running = 0; |
| 715 | igmpv3_send_report(in_dev, NULL); |
| 716 | __in_dev_put(in_dev); |
| 717 | } |
| 718 | |
| 719 | static void igmp_ifc_timer_expire(unsigned long data) |
| 720 | { |
| 721 | struct in_device *in_dev = (struct in_device *)data; |
| 722 | |
| 723 | igmpv3_send_cr(in_dev); |
| 724 | if (in_dev->mr_ifc_count) { |
| 725 | in_dev->mr_ifc_count--; |
| 726 | igmp_ifc_start_timer(in_dev, IGMP_Unsolicited_Report_Interval); |
| 727 | } |
| 728 | __in_dev_put(in_dev); |
| 729 | } |
| 730 | |
| 731 | static void igmp_ifc_event(struct in_device *in_dev) |
| 732 | { |
| 733 | if (IGMP_V1_SEEN(in_dev) || IGMP_V2_SEEN(in_dev)) |
| 734 | return; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 735 | in_dev->mr_ifc_count = in_dev->mr_qrv ? in_dev->mr_qrv : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | IGMP_Unsolicited_Report_Count; |
| 737 | igmp_ifc_start_timer(in_dev, 1); |
| 738 | } |
| 739 | |
| 740 | |
| 741 | static void igmp_timer_expire(unsigned long data) |
| 742 | { |
| 743 | struct ip_mc_list *im=(struct ip_mc_list *)data; |
| 744 | struct in_device *in_dev = im->interface; |
| 745 | |
| 746 | spin_lock(&im->lock); |
Jianjun Kong | a7e9ff7 | 2008-11-03 00:26:09 -0800 | [diff] [blame] | 747 | im->tm_running = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | |
| 749 | if (im->unsolicit_count) { |
| 750 | im->unsolicit_count--; |
| 751 | igmp_start_timer(im, IGMP_Unsolicited_Report_Interval); |
| 752 | } |
| 753 | im->reporter = 1; |
| 754 | spin_unlock(&im->lock); |
| 755 | |
| 756 | if (IGMP_V1_SEEN(in_dev)) |
| 757 | igmp_send_report(in_dev, im, IGMP_HOST_MEMBERSHIP_REPORT); |
| 758 | else if (IGMP_V2_SEEN(in_dev)) |
| 759 | igmp_send_report(in_dev, im, IGMPV2_HOST_MEMBERSHIP_REPORT); |
| 760 | else |
| 761 | igmp_send_report(in_dev, im, IGMPV3_HOST_MEMBERSHIP_REPORT); |
| 762 | |
| 763 | ip_ma_put(im); |
| 764 | } |
| 765 | |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 766 | /* mark EXCLUDE-mode sources */ |
Al Viro | ea4d9e7 | 2006-09-27 18:30:52 -0700 | [diff] [blame] | 767 | static int igmp_xmarksources(struct ip_mc_list *pmc, int nsrcs, __be32 *srcs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | { |
| 769 | struct ip_sf_list *psf; |
| 770 | int i, scount; |
| 771 | |
| 772 | scount = 0; |
| 773 | for (psf=pmc->sources; psf; psf=psf->sf_next) { |
| 774 | if (scount == nsrcs) |
| 775 | break; |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 776 | for (i=0; i<nsrcs; i++) { |
| 777 | /* skip inactive filters */ |
| 778 | if (pmc->sfcount[MCAST_INCLUDE] || |
| 779 | pmc->sfcount[MCAST_EXCLUDE] != |
| 780 | psf->sf_count[MCAST_EXCLUDE]) |
| 781 | continue; |
| 782 | if (srcs[i] == psf->sf_inaddr) { |
| 783 | scount++; |
| 784 | break; |
| 785 | } |
| 786 | } |
| 787 | } |
| 788 | pmc->gsquery = 0; |
| 789 | if (scount == nsrcs) /* all sources excluded */ |
| 790 | return 0; |
| 791 | return 1; |
| 792 | } |
| 793 | |
Al Viro | ea4d9e7 | 2006-09-27 18:30:52 -0700 | [diff] [blame] | 794 | static int igmp_marksources(struct ip_mc_list *pmc, int nsrcs, __be32 *srcs) |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 795 | { |
| 796 | struct ip_sf_list *psf; |
| 797 | int i, scount; |
| 798 | |
| 799 | if (pmc->sfmode == MCAST_EXCLUDE) |
| 800 | return igmp_xmarksources(pmc, nsrcs, srcs); |
| 801 | |
| 802 | /* mark INCLUDE-mode sources */ |
| 803 | scount = 0; |
| 804 | for (psf=pmc->sources; psf; psf=psf->sf_next) { |
| 805 | if (scount == nsrcs) |
| 806 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | for (i=0; i<nsrcs; i++) |
| 808 | if (srcs[i] == psf->sf_inaddr) { |
| 809 | psf->sf_gsresp = 1; |
| 810 | scount++; |
| 811 | break; |
| 812 | } |
| 813 | } |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 814 | if (!scount) { |
| 815 | pmc->gsquery = 0; |
| 816 | return 0; |
| 817 | } |
| 818 | pmc->gsquery = 1; |
| 819 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 822 | static void igmp_heard_report(struct in_device *in_dev, __be32 group) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | { |
| 824 | struct ip_mc_list *im; |
| 825 | |
| 826 | /* Timers are only set for non-local groups */ |
| 827 | |
| 828 | if (group == IGMP_ALL_HOSTS) |
| 829 | return; |
| 830 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 831 | rcu_read_lock(); |
| 832 | for_each_pmc_rcu(in_dev, im) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | if (im->multiaddr == group) { |
| 834 | igmp_stop_timer(im); |
| 835 | break; |
| 836 | } |
| 837 | } |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 838 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | static void igmp_heard_query(struct in_device *in_dev, struct sk_buff *skb, |
| 842 | int len) |
| 843 | { |
Arnaldo Carvalho de Melo | d9edf9e | 2007-03-13 14:19:23 -0300 | [diff] [blame] | 844 | struct igmphdr *ih = igmp_hdr(skb); |
| 845 | struct igmpv3_query *ih3 = igmpv3_query_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | struct ip_mc_list *im; |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 847 | __be32 group = ih->group; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | int max_delay; |
| 849 | int mark = 0; |
| 850 | |
| 851 | |
David Stevens | 5b7c840 | 2010-09-30 14:29:40 +0000 | [diff] [blame] | 852 | if (len == 8) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | if (ih->code == 0) { |
| 854 | /* Alas, old v1 router presents here. */ |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 855 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | max_delay = IGMP_Query_Response_Interval; |
| 857 | in_dev->mr_v1_seen = jiffies + |
| 858 | IGMP_V1_Router_Present_Timeout; |
| 859 | group = 0; |
| 860 | } else { |
| 861 | /* v2 router present */ |
| 862 | max_delay = ih->code*(HZ/IGMP_TIMER_SCALE); |
| 863 | in_dev->mr_v2_seen = jiffies + |
| 864 | IGMP_V2_Router_Present_Timeout; |
| 865 | } |
| 866 | /* cancel the interface change timer */ |
| 867 | in_dev->mr_ifc_count = 0; |
| 868 | if (del_timer(&in_dev->mr_ifc_timer)) |
| 869 | __in_dev_put(in_dev); |
| 870 | /* clear deleted report items */ |
| 871 | igmpv3_clear_delrec(in_dev); |
| 872 | } else if (len < 12) { |
| 873 | return; /* ignore bogus packet; freed by caller */ |
David Stevens | 5b7c840 | 2010-09-30 14:29:40 +0000 | [diff] [blame] | 874 | } else if (IGMP_V1_SEEN(in_dev)) { |
| 875 | /* This is a v3 query with v1 queriers present */ |
| 876 | max_delay = IGMP_Query_Response_Interval; |
| 877 | group = 0; |
| 878 | } else if (IGMP_V2_SEEN(in_dev)) { |
| 879 | /* this is a v3 query with v2 queriers present; |
| 880 | * Interpretation of the max_delay code is problematic here. |
| 881 | * A real v2 host would use ih_code directly, while v3 has a |
| 882 | * different encoding. We use the v3 encoding as more likely |
| 883 | * to be intended in a v3 query. |
| 884 | */ |
| 885 | max_delay = IGMPV3_MRC(ih3->code)*(HZ/IGMP_TIMER_SCALE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | } else { /* v3 */ |
| 887 | if (!pskb_may_pull(skb, sizeof(struct igmpv3_query))) |
| 888 | return; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 889 | |
Arnaldo Carvalho de Melo | d9edf9e | 2007-03-13 14:19:23 -0300 | [diff] [blame] | 890 | ih3 = igmpv3_query_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | if (ih3->nsrcs) { |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 892 | if (!pskb_may_pull(skb, sizeof(struct igmpv3_query) |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 893 | + ntohs(ih3->nsrcs)*sizeof(__be32))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | return; |
Arnaldo Carvalho de Melo | d9edf9e | 2007-03-13 14:19:23 -0300 | [diff] [blame] | 895 | ih3 = igmpv3_query_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | max_delay = IGMPV3_MRC(ih3->code)*(HZ/IGMP_TIMER_SCALE); |
| 899 | if (!max_delay) |
| 900 | max_delay = 1; /* can't mod w/ 0 */ |
| 901 | in_dev->mr_maxdelay = max_delay; |
| 902 | if (ih3->qrv) |
| 903 | in_dev->mr_qrv = ih3->qrv; |
| 904 | if (!group) { /* general query */ |
| 905 | if (ih3->nsrcs) |
| 906 | return; /* no sources allowed */ |
| 907 | igmp_gq_start_timer(in_dev); |
| 908 | return; |
| 909 | } |
| 910 | /* mark sources to include, if group & source-specific */ |
| 911 | mark = ih3->nsrcs != 0; |
| 912 | } |
| 913 | |
| 914 | /* |
| 915 | * - Start the timers in all of our membership records |
| 916 | * that the query applies to for the interface on |
| 917 | * which the query arrived excl. those that belong |
| 918 | * to a "local" group (224.0.0.X) |
| 919 | * - For timers already running check if they need to |
| 920 | * be reset. |
| 921 | * - Use the igmp->igmp_code field as the maximum |
| 922 | * delay possible |
| 923 | */ |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 924 | rcu_read_lock(); |
| 925 | for_each_pmc_rcu(in_dev, im) { |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 926 | int changed; |
| 927 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | if (group && group != im->multiaddr) |
| 929 | continue; |
| 930 | if (im->multiaddr == IGMP_ALL_HOSTS) |
| 931 | continue; |
| 932 | spin_lock_bh(&im->lock); |
| 933 | if (im->tm_running) |
| 934 | im->gsquery = im->gsquery && mark; |
| 935 | else |
| 936 | im->gsquery = mark; |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 937 | changed = !im->gsquery || |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 938 | igmp_marksources(im, ntohs(ih3->nsrcs), ih3->srcs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | spin_unlock_bh(&im->lock); |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 940 | if (changed) |
| 941 | igmp_mod_timer(im, max_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | } |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 943 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Eric Dumazet | 9a57a9d | 2010-06-07 03:17:10 +0000 | [diff] [blame] | 946 | /* called in rcu_read_lock() section */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | int igmp_rcv(struct sk_buff *skb) |
| 948 | { |
| 949 | /* This basically follows the spec line by line -- see RFC1112 */ |
| 950 | struct igmphdr *ih; |
Eric Dumazet | 9a57a9d | 2010-06-07 03:17:10 +0000 | [diff] [blame] | 951 | struct in_device *in_dev = __in_dev_get_rcu(skb->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | int len = skb->len; |
| 953 | |
Denis V. Lunev | cd557bc | 2008-02-09 23:22:26 -0800 | [diff] [blame] | 954 | if (in_dev == NULL) |
| 955 | goto drop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | |
Herbert Xu | fb286bb | 2005-11-10 13:01:24 -0800 | [diff] [blame] | 957 | if (!pskb_may_pull(skb, sizeof(struct igmphdr))) |
Eric Dumazet | 9a57a9d | 2010-06-07 03:17:10 +0000 | [diff] [blame] | 958 | goto drop; |
Herbert Xu | fb286bb | 2005-11-10 13:01:24 -0800 | [diff] [blame] | 959 | |
| 960 | switch (skb->ip_summed) { |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 961 | case CHECKSUM_COMPLETE: |
Al Viro | d3bc23e | 2006-11-14 21:24:49 -0800 | [diff] [blame] | 962 | if (!csum_fold(skb->csum)) |
Herbert Xu | fb286bb | 2005-11-10 13:01:24 -0800 | [diff] [blame] | 963 | break; |
| 964 | /* fall through */ |
| 965 | case CHECKSUM_NONE: |
| 966 | skb->csum = 0; |
| 967 | if (__skb_checksum_complete(skb)) |
Eric Dumazet | 9a57a9d | 2010-06-07 03:17:10 +0000 | [diff] [blame] | 968 | goto drop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | } |
| 970 | |
Arnaldo Carvalho de Melo | d9edf9e | 2007-03-13 14:19:23 -0300 | [diff] [blame] | 971 | ih = igmp_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | switch (ih->type) { |
| 973 | case IGMP_HOST_MEMBERSHIP_QUERY: |
| 974 | igmp_heard_query(in_dev, skb, len); |
| 975 | break; |
| 976 | case IGMP_HOST_MEMBERSHIP_REPORT: |
| 977 | case IGMPV2_HOST_MEMBERSHIP_REPORT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | /* Is it our report looped back? */ |
David S. Miller | c753796 | 2010-11-11 17:07:48 -0800 | [diff] [blame] | 979 | if (rt_is_output_route(skb_rtable(skb))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | break; |
David Stevens | 24c6927 | 2005-12-02 20:32:59 -0800 | [diff] [blame] | 981 | /* don't rely on MC router hearing unicast reports */ |
| 982 | if (skb->pkt_type == PACKET_MULTICAST || |
| 983 | skb->pkt_type == PACKET_BROADCAST) |
| 984 | igmp_heard_report(in_dev, ih->group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | break; |
| 986 | case IGMP_PIM: |
| 987 | #ifdef CONFIG_IP_PIMSM_V1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | return pim_rcv_v1(skb); |
| 989 | #endif |
Herbert Xu | c6b471e | 2010-02-07 17:26:30 +0000 | [diff] [blame] | 990 | case IGMPV3_HOST_MEMBERSHIP_REPORT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | case IGMP_DVMRP: |
| 992 | case IGMP_TRACE: |
| 993 | case IGMP_HOST_LEAVE_MESSAGE: |
| 994 | case IGMP_MTRACE: |
| 995 | case IGMP_MTRACE_RESP: |
| 996 | break; |
| 997 | default: |
Linus Torvalds | dd1c185 | 2006-01-31 13:11:41 -0800 | [diff] [blame] | 998 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | } |
Herbert Xu | fb286bb | 2005-11-10 13:01:24 -0800 | [diff] [blame] | 1000 | |
Denis V. Lunev | cd557bc | 2008-02-09 23:22:26 -0800 | [diff] [blame] | 1001 | drop: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | kfree_skb(skb); |
| 1003 | return 0; |
| 1004 | } |
| 1005 | |
| 1006 | #endif |
| 1007 | |
| 1008 | |
| 1009 | /* |
| 1010 | * Add a filter to a device |
| 1011 | */ |
| 1012 | |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 1013 | static void ip_mc_filter_add(struct in_device *in_dev, __be32 addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | { |
| 1015 | char buf[MAX_ADDR_LEN]; |
| 1016 | struct net_device *dev = in_dev->dev; |
| 1017 | |
| 1018 | /* Checking for IFF_MULTICAST here is WRONG-WRONG-WRONG. |
| 1019 | We will get multicast token leakage, when IFF_MULTICAST |
| 1020 | is changed. This check should be done in dev->set_multicast_list |
| 1021 | routine. Something sort of: |
| 1022 | if (dev->mc_list && dev->flags&IFF_MULTICAST) { do it; } |
| 1023 | --ANK |
| 1024 | */ |
| 1025 | if (arp_mc_map(addr, buf, dev, 0) == 0) |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1026 | dev_mc_add(dev, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | /* |
| 1030 | * Remove a filter from a device |
| 1031 | */ |
| 1032 | |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 1033 | static void ip_mc_filter_del(struct in_device *in_dev, __be32 addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | { |
| 1035 | char buf[MAX_ADDR_LEN]; |
| 1036 | struct net_device *dev = in_dev->dev; |
| 1037 | |
| 1038 | if (arp_mc_map(addr, buf, dev, 0) == 0) |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1039 | dev_mc_del(dev, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | #ifdef CONFIG_IP_MULTICAST |
| 1043 | /* |
| 1044 | * deleted ip_mc_list manipulation |
| 1045 | */ |
| 1046 | static void igmpv3_add_delrec(struct in_device *in_dev, struct ip_mc_list *im) |
| 1047 | { |
| 1048 | struct ip_mc_list *pmc; |
| 1049 | |
| 1050 | /* this is an "ip_mc_list" for convenience; only the fields below |
| 1051 | * are actually used. In particular, the refcnt and users are not |
| 1052 | * used for management of the delete list. Using the same structure |
| 1053 | * for deleted items allows change reports to use common code with |
| 1054 | * non-deleted or query-response MCA's. |
| 1055 | */ |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 1056 | pmc = kzalloc(sizeof(*pmc), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | if (!pmc) |
| 1058 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | spin_lock_bh(&im->lock); |
| 1060 | pmc->interface = im->interface; |
| 1061 | in_dev_hold(in_dev); |
| 1062 | pmc->multiaddr = im->multiaddr; |
| 1063 | pmc->crcount = in_dev->mr_qrv ? in_dev->mr_qrv : |
| 1064 | IGMP_Unsolicited_Report_Count; |
| 1065 | pmc->sfmode = im->sfmode; |
| 1066 | if (pmc->sfmode == MCAST_INCLUDE) { |
| 1067 | struct ip_sf_list *psf; |
| 1068 | |
| 1069 | pmc->tomb = im->tomb; |
| 1070 | pmc->sources = im->sources; |
| 1071 | im->tomb = im->sources = NULL; |
| 1072 | for (psf=pmc->sources; psf; psf=psf->sf_next) |
| 1073 | psf->sf_crcount = pmc->crcount; |
| 1074 | } |
| 1075 | spin_unlock_bh(&im->lock); |
| 1076 | |
| 1077 | spin_lock_bh(&in_dev->mc_tomb_lock); |
| 1078 | pmc->next = in_dev->mc_tomb; |
| 1079 | in_dev->mc_tomb = pmc; |
| 1080 | spin_unlock_bh(&in_dev->mc_tomb_lock); |
| 1081 | } |
| 1082 | |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 1083 | static void igmpv3_del_delrec(struct in_device *in_dev, __be32 multiaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | { |
| 1085 | struct ip_mc_list *pmc, *pmc_prev; |
| 1086 | struct ip_sf_list *psf, *psf_next; |
| 1087 | |
| 1088 | spin_lock_bh(&in_dev->mc_tomb_lock); |
| 1089 | pmc_prev = NULL; |
| 1090 | for (pmc=in_dev->mc_tomb; pmc; pmc=pmc->next) { |
| 1091 | if (pmc->multiaddr == multiaddr) |
| 1092 | break; |
| 1093 | pmc_prev = pmc; |
| 1094 | } |
| 1095 | if (pmc) { |
| 1096 | if (pmc_prev) |
| 1097 | pmc_prev->next = pmc->next; |
| 1098 | else |
| 1099 | in_dev->mc_tomb = pmc->next; |
| 1100 | } |
| 1101 | spin_unlock_bh(&in_dev->mc_tomb_lock); |
| 1102 | if (pmc) { |
| 1103 | for (psf=pmc->tomb; psf; psf=psf_next) { |
| 1104 | psf_next = psf->sf_next; |
| 1105 | kfree(psf); |
| 1106 | } |
| 1107 | in_dev_put(pmc->interface); |
| 1108 | kfree(pmc); |
| 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | static void igmpv3_clear_delrec(struct in_device *in_dev) |
| 1113 | { |
| 1114 | struct ip_mc_list *pmc, *nextpmc; |
| 1115 | |
| 1116 | spin_lock_bh(&in_dev->mc_tomb_lock); |
| 1117 | pmc = in_dev->mc_tomb; |
| 1118 | in_dev->mc_tomb = NULL; |
| 1119 | spin_unlock_bh(&in_dev->mc_tomb_lock); |
| 1120 | |
| 1121 | for (; pmc; pmc = nextpmc) { |
| 1122 | nextpmc = pmc->next; |
| 1123 | ip_mc_clear_src(pmc); |
| 1124 | in_dev_put(pmc->interface); |
| 1125 | kfree(pmc); |
| 1126 | } |
| 1127 | /* clear dead sources, too */ |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1128 | rcu_read_lock(); |
| 1129 | for_each_pmc_rcu(in_dev, pmc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | struct ip_sf_list *psf, *psf_next; |
| 1131 | |
| 1132 | spin_lock_bh(&pmc->lock); |
| 1133 | psf = pmc->tomb; |
| 1134 | pmc->tomb = NULL; |
| 1135 | spin_unlock_bh(&pmc->lock); |
| 1136 | for (; psf; psf=psf_next) { |
| 1137 | psf_next = psf->sf_next; |
| 1138 | kfree(psf); |
| 1139 | } |
| 1140 | } |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1141 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | } |
| 1143 | #endif |
| 1144 | |
| 1145 | static void igmp_group_dropped(struct ip_mc_list *im) |
| 1146 | { |
| 1147 | struct in_device *in_dev = im->interface; |
| 1148 | #ifdef CONFIG_IP_MULTICAST |
| 1149 | int reporter; |
| 1150 | #endif |
| 1151 | |
| 1152 | if (im->loaded) { |
| 1153 | im->loaded = 0; |
| 1154 | ip_mc_filter_del(in_dev, im->multiaddr); |
| 1155 | } |
| 1156 | |
| 1157 | #ifdef CONFIG_IP_MULTICAST |
| 1158 | if (im->multiaddr == IGMP_ALL_HOSTS) |
| 1159 | return; |
| 1160 | |
| 1161 | reporter = im->reporter; |
| 1162 | igmp_stop_timer(im); |
| 1163 | |
| 1164 | if (!in_dev->dead) { |
| 1165 | if (IGMP_V1_SEEN(in_dev)) |
| 1166 | goto done; |
| 1167 | if (IGMP_V2_SEEN(in_dev)) { |
| 1168 | if (reporter) |
| 1169 | igmp_send_report(in_dev, im, IGMP_HOST_LEAVE_MESSAGE); |
| 1170 | goto done; |
| 1171 | } |
| 1172 | /* IGMPv3 */ |
| 1173 | igmpv3_add_delrec(in_dev, im); |
| 1174 | |
| 1175 | igmp_ifc_event(in_dev); |
| 1176 | } |
| 1177 | done: |
| 1178 | #endif |
| 1179 | ip_mc_clear_src(im); |
| 1180 | } |
| 1181 | |
| 1182 | static void igmp_group_added(struct ip_mc_list *im) |
| 1183 | { |
| 1184 | struct in_device *in_dev = im->interface; |
| 1185 | |
| 1186 | if (im->loaded == 0) { |
| 1187 | im->loaded = 1; |
| 1188 | ip_mc_filter_add(in_dev, im->multiaddr); |
| 1189 | } |
| 1190 | |
| 1191 | #ifdef CONFIG_IP_MULTICAST |
| 1192 | if (im->multiaddr == IGMP_ALL_HOSTS) |
| 1193 | return; |
| 1194 | |
| 1195 | if (in_dev->dead) |
| 1196 | return; |
| 1197 | if (IGMP_V1_SEEN(in_dev) || IGMP_V2_SEEN(in_dev)) { |
| 1198 | spin_lock_bh(&im->lock); |
| 1199 | igmp_start_timer(im, IGMP_Initial_Report_Delay); |
| 1200 | spin_unlock_bh(&im->lock); |
| 1201 | return; |
| 1202 | } |
| 1203 | /* else, v3 */ |
| 1204 | |
| 1205 | im->crcount = in_dev->mr_qrv ? in_dev->mr_qrv : |
| 1206 | IGMP_Unsolicited_Report_Count; |
| 1207 | igmp_ifc_event(in_dev); |
| 1208 | #endif |
| 1209 | } |
| 1210 | |
| 1211 | |
| 1212 | /* |
| 1213 | * Multicast list managers |
| 1214 | */ |
| 1215 | |
| 1216 | |
| 1217 | /* |
| 1218 | * A socket has joined a multicast group on device dev. |
| 1219 | */ |
| 1220 | |
Al Viro | 8f935bb | 2006-09-27 18:30:07 -0700 | [diff] [blame] | 1221 | void ip_mc_inc_group(struct in_device *in_dev, __be32 addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | { |
| 1223 | struct ip_mc_list *im; |
| 1224 | |
| 1225 | ASSERT_RTNL(); |
| 1226 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1227 | for_each_pmc_rtnl(in_dev, im) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | if (im->multiaddr == addr) { |
| 1229 | im->users++; |
| 1230 | ip_mc_add_src(in_dev, &addr, MCAST_EXCLUDE, 0, NULL, 0); |
| 1231 | goto out; |
| 1232 | } |
| 1233 | } |
| 1234 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1235 | im = kzalloc(sizeof(*im), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | if (!im) |
| 1237 | goto out; |
| 1238 | |
Jianjun Kong | a7e9ff7 | 2008-11-03 00:26:09 -0800 | [diff] [blame] | 1239 | im->users = 1; |
| 1240 | im->interface = in_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | in_dev_hold(in_dev); |
Jianjun Kong | a7e9ff7 | 2008-11-03 00:26:09 -0800 | [diff] [blame] | 1242 | im->multiaddr = addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | /* initial mode is (EX, empty) */ |
| 1244 | im->sfmode = MCAST_EXCLUDE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | im->sfcount[MCAST_EXCLUDE] = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | atomic_set(&im->refcnt, 1); |
| 1247 | spin_lock_init(&im->lock); |
| 1248 | #ifdef CONFIG_IP_MULTICAST |
Pavel Emelyanov | b24b8a2 | 2008-01-23 21:20:07 -0800 | [diff] [blame] | 1249 | setup_timer(&im->timer, &igmp_timer_expire, (unsigned long)im); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | im->unsolicit_count = IGMP_Unsolicited_Report_Count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | #endif |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1252 | |
| 1253 | im->next_rcu = in_dev->mc_list; |
Rami Rosen | b8bae41 | 2008-10-07 15:34:37 -0700 | [diff] [blame] | 1254 | in_dev->mc_count++; |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1255 | rcu_assign_pointer(in_dev->mc_list, im); |
| 1256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | #ifdef CONFIG_IP_MULTICAST |
| 1258 | igmpv3_del_delrec(in_dev, im->multiaddr); |
| 1259 | #endif |
| 1260 | igmp_group_added(im); |
| 1261 | if (!in_dev->dead) |
| 1262 | ip_rt_multicast_event(in_dev); |
| 1263 | out: |
| 1264 | return; |
| 1265 | } |
Eric Dumazet | 4bc2f18 | 2010-07-09 21:22:10 +0000 | [diff] [blame] | 1266 | EXPORT_SYMBOL(ip_mc_inc_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | |
| 1268 | /* |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 1269 | * Resend IGMP JOIN report; used for bonding. |
| 1270 | */ |
| 1271 | void ip_mc_rejoin_group(struct ip_mc_list *im) |
| 1272 | { |
Geert Uytterhoeven | 0888266 | 2007-03-12 17:02:37 -0700 | [diff] [blame] | 1273 | #ifdef CONFIG_IP_MULTICAST |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 1274 | struct in_device *in_dev = im->interface; |
| 1275 | |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 1276 | if (im->multiaddr == IGMP_ALL_HOSTS) |
| 1277 | return; |
| 1278 | |
Flavio Leitner | e12b453 | 2010-10-05 14:23:58 +0000 | [diff] [blame] | 1279 | /* a failover is happening and switches |
| 1280 | * must be notified immediately */ |
| 1281 | if (IGMP_V1_SEEN(in_dev)) |
| 1282 | igmp_send_report(in_dev, im, IGMP_HOST_MEMBERSHIP_REPORT); |
| 1283 | else if (IGMP_V2_SEEN(in_dev)) |
| 1284 | igmp_send_report(in_dev, im, IGMPV2_HOST_MEMBERSHIP_REPORT); |
| 1285 | else |
| 1286 | igmp_send_report(in_dev, im, IGMPV3_HOST_MEMBERSHIP_REPORT); |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 1287 | #endif |
| 1288 | } |
Eric Dumazet | 4bc2f18 | 2010-07-09 21:22:10 +0000 | [diff] [blame] | 1289 | EXPORT_SYMBOL(ip_mc_rejoin_group); |
Jay Vosburgh | a816c7c | 2007-02-28 17:03:37 -0800 | [diff] [blame] | 1290 | |
| 1291 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | * A socket has left a multicast group on device dev |
| 1293 | */ |
| 1294 | |
Al Viro | 8f935bb | 2006-09-27 18:30:07 -0700 | [diff] [blame] | 1295 | void ip_mc_dec_group(struct in_device *in_dev, __be32 addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | { |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1297 | struct ip_mc_list *i; |
| 1298 | struct ip_mc_list __rcu **ip; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | ASSERT_RTNL(); |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1301 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1302 | for (ip = &in_dev->mc_list; |
| 1303 | (i = rtnl_dereference(*ip)) != NULL; |
| 1304 | ip = &i->next_rcu) { |
Jianjun Kong | a7e9ff7 | 2008-11-03 00:26:09 -0800 | [diff] [blame] | 1305 | if (i->multiaddr == addr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | if (--i->users == 0) { |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1307 | *ip = i->next_rcu; |
Rami Rosen | b8bae41 | 2008-10-07 15:34:37 -0700 | [diff] [blame] | 1308 | in_dev->mc_count--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | igmp_group_dropped(i); |
| 1310 | |
| 1311 | if (!in_dev->dead) |
| 1312 | ip_rt_multicast_event(in_dev); |
| 1313 | |
| 1314 | ip_ma_put(i); |
| 1315 | return; |
| 1316 | } |
| 1317 | break; |
| 1318 | } |
| 1319 | } |
| 1320 | } |
Eric Dumazet | 4bc2f18 | 2010-07-09 21:22:10 +0000 | [diff] [blame] | 1321 | EXPORT_SYMBOL(ip_mc_dec_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 1323 | /* Device changing type */ |
| 1324 | |
| 1325 | void ip_mc_unmap(struct in_device *in_dev) |
| 1326 | { |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1327 | struct ip_mc_list *pmc; |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 1328 | |
| 1329 | ASSERT_RTNL(); |
| 1330 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1331 | for_each_pmc_rtnl(in_dev, pmc) |
| 1332 | igmp_group_dropped(pmc); |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | void ip_mc_remap(struct in_device *in_dev) |
| 1336 | { |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1337 | struct ip_mc_list *pmc; |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 1338 | |
| 1339 | ASSERT_RTNL(); |
| 1340 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1341 | for_each_pmc_rtnl(in_dev, pmc) |
| 1342 | igmp_group_added(pmc); |
Moni Shoua | 75c7850 | 2009-09-15 02:37:40 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | /* Device going down */ |
| 1346 | |
| 1347 | void ip_mc_down(struct in_device *in_dev) |
| 1348 | { |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1349 | struct ip_mc_list *pmc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | |
| 1351 | ASSERT_RTNL(); |
| 1352 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1353 | for_each_pmc_rtnl(in_dev, pmc) |
| 1354 | igmp_group_dropped(pmc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | |
| 1356 | #ifdef CONFIG_IP_MULTICAST |
| 1357 | in_dev->mr_ifc_count = 0; |
| 1358 | if (del_timer(&in_dev->mr_ifc_timer)) |
| 1359 | __in_dev_put(in_dev); |
| 1360 | in_dev->mr_gq_running = 0; |
| 1361 | if (del_timer(&in_dev->mr_gq_timer)) |
| 1362 | __in_dev_put(in_dev); |
| 1363 | igmpv3_clear_delrec(in_dev); |
| 1364 | #endif |
| 1365 | |
| 1366 | ip_mc_dec_group(in_dev, IGMP_ALL_HOSTS); |
| 1367 | } |
| 1368 | |
| 1369 | void ip_mc_init_dev(struct in_device *in_dev) |
| 1370 | { |
| 1371 | ASSERT_RTNL(); |
| 1372 | |
| 1373 | in_dev->mc_tomb = NULL; |
| 1374 | #ifdef CONFIG_IP_MULTICAST |
| 1375 | in_dev->mr_gq_running = 0; |
Pavel Emelyanov | b24b8a2 | 2008-01-23 21:20:07 -0800 | [diff] [blame] | 1376 | setup_timer(&in_dev->mr_gq_timer, igmp_gq_timer_expire, |
| 1377 | (unsigned long)in_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | in_dev->mr_ifc_count = 0; |
Rami Rosen | b8bae41 | 2008-10-07 15:34:37 -0700 | [diff] [blame] | 1379 | in_dev->mc_count = 0; |
Pavel Emelyanov | b24b8a2 | 2008-01-23 21:20:07 -0800 | [diff] [blame] | 1380 | setup_timer(&in_dev->mr_ifc_timer, igmp_ifc_timer_expire, |
| 1381 | (unsigned long)in_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | in_dev->mr_qrv = IGMP_Unsolicited_Report_Count; |
| 1383 | #endif |
| 1384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | spin_lock_init(&in_dev->mc_tomb_lock); |
| 1386 | } |
| 1387 | |
| 1388 | /* Device going up */ |
| 1389 | |
| 1390 | void ip_mc_up(struct in_device *in_dev) |
| 1391 | { |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1392 | struct ip_mc_list *pmc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | |
| 1394 | ASSERT_RTNL(); |
| 1395 | |
| 1396 | ip_mc_inc_group(in_dev, IGMP_ALL_HOSTS); |
| 1397 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1398 | for_each_pmc_rtnl(in_dev, pmc) |
| 1399 | igmp_group_added(pmc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | /* |
| 1403 | * Device is about to be destroyed: clean up. |
| 1404 | */ |
| 1405 | |
| 1406 | void ip_mc_destroy_dev(struct in_device *in_dev) |
| 1407 | { |
| 1408 | struct ip_mc_list *i; |
| 1409 | |
| 1410 | ASSERT_RTNL(); |
| 1411 | |
| 1412 | /* Deactivate timers */ |
| 1413 | ip_mc_down(in_dev); |
| 1414 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1415 | while ((i = rtnl_dereference(in_dev->mc_list)) != NULL) { |
| 1416 | in_dev->mc_list = i->next_rcu; |
Rami Rosen | b8bae41 | 2008-10-07 15:34:37 -0700 | [diff] [blame] | 1417 | in_dev->mc_count--; |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | igmp_group_dropped(i); |
| 1420 | ip_ma_put(i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
Eric Dumazet | 9e917dc | 2010-10-19 00:39:18 +0000 | [diff] [blame] | 1424 | /* RTNL is locked */ |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 1425 | static struct in_device *ip_mc_find_dev(struct net *net, struct ip_mreqn *imr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | { |
Changli Gao | 5811662 | 2010-11-12 18:43:55 +0000 | [diff] [blame] | 1427 | struct flowi fl = { .fl4_dst = imr->imr_multiaddr.s_addr }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | struct rtable *rt; |
| 1429 | struct net_device *dev = NULL; |
| 1430 | struct in_device *idev = NULL; |
| 1431 | |
| 1432 | if (imr->imr_ifindex) { |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 1433 | idev = inetdev_by_index(net, imr->imr_ifindex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | return idev; |
| 1435 | } |
| 1436 | if (imr->imr_address.s_addr) { |
Eric Dumazet | 9e917dc | 2010-10-19 00:39:18 +0000 | [diff] [blame] | 1437 | dev = __ip_dev_find(net, imr->imr_address.s_addr, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | if (!dev) |
| 1439 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 1442 | if (!dev && !ip_route_output_key(net, &rt, &fl)) { |
Changli Gao | d8d1f30 | 2010-06-10 23:31:35 -0700 | [diff] [blame] | 1443 | dev = rt->dst.dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | ip_rt_put(rt); |
| 1445 | } |
| 1446 | if (dev) { |
| 1447 | imr->imr_ifindex = dev->ifindex; |
Herbert Xu | e5ed639 | 2005-10-03 14:35:55 -0700 | [diff] [blame] | 1448 | idev = __in_dev_get_rtnl(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | } |
| 1450 | return idev; |
| 1451 | } |
| 1452 | |
| 1453 | /* |
| 1454 | * Join a socket to a group |
| 1455 | */ |
Brian Haley | ab32ea5 | 2006-09-22 14:15:41 -0700 | [diff] [blame] | 1456 | int sysctl_igmp_max_memberships __read_mostly = IP_MAX_MEMBERSHIPS; |
| 1457 | int sysctl_igmp_max_msf __read_mostly = IP_MAX_MSF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | |
| 1459 | |
| 1460 | static int ip_mc_del1_src(struct ip_mc_list *pmc, int sfmode, |
Al Viro | 8f935bb | 2006-09-27 18:30:07 -0700 | [diff] [blame] | 1461 | __be32 *psfsrc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | { |
| 1463 | struct ip_sf_list *psf, *psf_prev; |
| 1464 | int rv = 0; |
| 1465 | |
| 1466 | psf_prev = NULL; |
| 1467 | for (psf=pmc->sources; psf; psf=psf->sf_next) { |
| 1468 | if (psf->sf_inaddr == *psfsrc) |
| 1469 | break; |
| 1470 | psf_prev = psf; |
| 1471 | } |
| 1472 | if (!psf || psf->sf_count[sfmode] == 0) { |
| 1473 | /* source filter not found, or count wrong => bug */ |
| 1474 | return -ESRCH; |
| 1475 | } |
| 1476 | psf->sf_count[sfmode]--; |
| 1477 | if (psf->sf_count[sfmode] == 0) { |
| 1478 | ip_rt_multicast_event(pmc->interface); |
| 1479 | } |
| 1480 | if (!psf->sf_count[MCAST_INCLUDE] && !psf->sf_count[MCAST_EXCLUDE]) { |
| 1481 | #ifdef CONFIG_IP_MULTICAST |
| 1482 | struct in_device *in_dev = pmc->interface; |
| 1483 | #endif |
| 1484 | |
| 1485 | /* no more filters for this source */ |
| 1486 | if (psf_prev) |
| 1487 | psf_prev->sf_next = psf->sf_next; |
| 1488 | else |
| 1489 | pmc->sources = psf->sf_next; |
| 1490 | #ifdef CONFIG_IP_MULTICAST |
| 1491 | if (psf->sf_oldin && |
| 1492 | !IGMP_V1_SEEN(in_dev) && !IGMP_V2_SEEN(in_dev)) { |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1493 | psf->sf_crcount = in_dev->mr_qrv ? in_dev->mr_qrv : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | IGMP_Unsolicited_Report_Count; |
| 1495 | psf->sf_next = pmc->tomb; |
| 1496 | pmc->tomb = psf; |
| 1497 | rv = 1; |
| 1498 | } else |
| 1499 | #endif |
| 1500 | kfree(psf); |
| 1501 | } |
| 1502 | return rv; |
| 1503 | } |
| 1504 | |
| 1505 | #ifndef CONFIG_IP_MULTICAST |
| 1506 | #define igmp_ifc_event(x) do { } while (0) |
| 1507 | #endif |
| 1508 | |
Al Viro | 8f935bb | 2006-09-27 18:30:07 -0700 | [diff] [blame] | 1509 | static int ip_mc_del_src(struct in_device *in_dev, __be32 *pmca, int sfmode, |
| 1510 | int sfcount, __be32 *psfsrc, int delta) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | { |
| 1512 | struct ip_mc_list *pmc; |
| 1513 | int changerec = 0; |
| 1514 | int i, err; |
| 1515 | |
| 1516 | if (!in_dev) |
| 1517 | return -ENODEV; |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1518 | rcu_read_lock(); |
| 1519 | for_each_pmc_rcu(in_dev, pmc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | if (*pmca == pmc->multiaddr) |
| 1521 | break; |
| 1522 | } |
| 1523 | if (!pmc) { |
| 1524 | /* MCA not found?? bug */ |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1525 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | return -ESRCH; |
| 1527 | } |
| 1528 | spin_lock_bh(&pmc->lock); |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1529 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | #ifdef CONFIG_IP_MULTICAST |
| 1531 | sf_markstate(pmc); |
| 1532 | #endif |
| 1533 | if (!delta) { |
| 1534 | err = -EINVAL; |
| 1535 | if (!pmc->sfcount[sfmode]) |
| 1536 | goto out_unlock; |
| 1537 | pmc->sfcount[sfmode]--; |
| 1538 | } |
| 1539 | err = 0; |
| 1540 | for (i=0; i<sfcount; i++) { |
| 1541 | int rv = ip_mc_del1_src(pmc, sfmode, &psfsrc[i]); |
| 1542 | |
| 1543 | changerec |= rv > 0; |
| 1544 | if (!err && rv < 0) |
| 1545 | err = rv; |
| 1546 | } |
| 1547 | if (pmc->sfmode == MCAST_EXCLUDE && |
| 1548 | pmc->sfcount[MCAST_EXCLUDE] == 0 && |
| 1549 | pmc->sfcount[MCAST_INCLUDE]) { |
| 1550 | #ifdef CONFIG_IP_MULTICAST |
| 1551 | struct ip_sf_list *psf; |
| 1552 | #endif |
| 1553 | |
| 1554 | /* filter mode change */ |
| 1555 | pmc->sfmode = MCAST_INCLUDE; |
| 1556 | #ifdef CONFIG_IP_MULTICAST |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1557 | pmc->crcount = in_dev->mr_qrv ? in_dev->mr_qrv : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | IGMP_Unsolicited_Report_Count; |
| 1559 | in_dev->mr_ifc_count = pmc->crcount; |
| 1560 | for (psf=pmc->sources; psf; psf = psf->sf_next) |
| 1561 | psf->sf_crcount = 0; |
| 1562 | igmp_ifc_event(pmc->interface); |
| 1563 | } else if (sf_setstate(pmc) || changerec) { |
| 1564 | igmp_ifc_event(pmc->interface); |
| 1565 | #endif |
| 1566 | } |
| 1567 | out_unlock: |
| 1568 | spin_unlock_bh(&pmc->lock); |
| 1569 | return err; |
| 1570 | } |
| 1571 | |
| 1572 | /* |
| 1573 | * Add multicast single-source filter to the interface list |
| 1574 | */ |
| 1575 | static int ip_mc_add1_src(struct ip_mc_list *pmc, int sfmode, |
Al Viro | 8f935bb | 2006-09-27 18:30:07 -0700 | [diff] [blame] | 1576 | __be32 *psfsrc, int delta) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | { |
| 1578 | struct ip_sf_list *psf, *psf_prev; |
| 1579 | |
| 1580 | psf_prev = NULL; |
| 1581 | for (psf=pmc->sources; psf; psf=psf->sf_next) { |
| 1582 | if (psf->sf_inaddr == *psfsrc) |
| 1583 | break; |
| 1584 | psf_prev = psf; |
| 1585 | } |
| 1586 | if (!psf) { |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 1587 | psf = kzalloc(sizeof(*psf), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | if (!psf) |
| 1589 | return -ENOBUFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | psf->sf_inaddr = *psfsrc; |
| 1591 | if (psf_prev) { |
| 1592 | psf_prev->sf_next = psf; |
| 1593 | } else |
| 1594 | pmc->sources = psf; |
| 1595 | } |
| 1596 | psf->sf_count[sfmode]++; |
| 1597 | if (psf->sf_count[sfmode] == 1) { |
| 1598 | ip_rt_multicast_event(pmc->interface); |
| 1599 | } |
| 1600 | return 0; |
| 1601 | } |
| 1602 | |
| 1603 | #ifdef CONFIG_IP_MULTICAST |
| 1604 | static void sf_markstate(struct ip_mc_list *pmc) |
| 1605 | { |
| 1606 | struct ip_sf_list *psf; |
| 1607 | int mca_xcount = pmc->sfcount[MCAST_EXCLUDE]; |
| 1608 | |
| 1609 | for (psf=pmc->sources; psf; psf=psf->sf_next) |
| 1610 | if (pmc->sfcount[MCAST_EXCLUDE]) { |
| 1611 | psf->sf_oldin = mca_xcount == |
| 1612 | psf->sf_count[MCAST_EXCLUDE] && |
| 1613 | !psf->sf_count[MCAST_INCLUDE]; |
| 1614 | } else |
| 1615 | psf->sf_oldin = psf->sf_count[MCAST_INCLUDE] != 0; |
| 1616 | } |
| 1617 | |
| 1618 | static int sf_setstate(struct ip_mc_list *pmc) |
| 1619 | { |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 1620 | struct ip_sf_list *psf, *dpsf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | int mca_xcount = pmc->sfcount[MCAST_EXCLUDE]; |
| 1622 | int qrv = pmc->interface->mr_qrv; |
| 1623 | int new_in, rv; |
| 1624 | |
| 1625 | rv = 0; |
| 1626 | for (psf=pmc->sources; psf; psf=psf->sf_next) { |
| 1627 | if (pmc->sfcount[MCAST_EXCLUDE]) { |
| 1628 | new_in = mca_xcount == psf->sf_count[MCAST_EXCLUDE] && |
| 1629 | !psf->sf_count[MCAST_INCLUDE]; |
| 1630 | } else |
| 1631 | new_in = psf->sf_count[MCAST_INCLUDE] != 0; |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 1632 | if (new_in) { |
| 1633 | if (!psf->sf_oldin) { |
Al Viro | 76edc60 | 2006-02-01 05:54:35 -0500 | [diff] [blame] | 1634 | struct ip_sf_list *prev = NULL; |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 1635 | |
| 1636 | for (dpsf=pmc->tomb; dpsf; dpsf=dpsf->sf_next) { |
| 1637 | if (dpsf->sf_inaddr == psf->sf_inaddr) |
| 1638 | break; |
| 1639 | prev = dpsf; |
| 1640 | } |
| 1641 | if (dpsf) { |
| 1642 | if (prev) |
| 1643 | prev->sf_next = dpsf->sf_next; |
| 1644 | else |
| 1645 | pmc->tomb = dpsf->sf_next; |
| 1646 | kfree(dpsf); |
| 1647 | } |
| 1648 | psf->sf_crcount = qrv; |
| 1649 | rv++; |
| 1650 | } |
| 1651 | } else if (psf->sf_oldin) { |
| 1652 | |
| 1653 | psf->sf_crcount = 0; |
| 1654 | /* |
| 1655 | * add or update "delete" records if an active filter |
| 1656 | * is now inactive |
| 1657 | */ |
| 1658 | for (dpsf=pmc->tomb; dpsf; dpsf=dpsf->sf_next) |
| 1659 | if (dpsf->sf_inaddr == psf->sf_inaddr) |
| 1660 | break; |
| 1661 | if (!dpsf) { |
Joe Perches | 3ed37a6 | 2010-05-31 17:23:21 +0000 | [diff] [blame] | 1662 | dpsf = kmalloc(sizeof(*dpsf), GFP_ATOMIC); |
David L Stevens | ad12583 | 2006-01-18 14:20:56 -0800 | [diff] [blame] | 1663 | if (!dpsf) |
| 1664 | continue; |
| 1665 | *dpsf = *psf; |
| 1666 | /* pmc->lock held by callers */ |
| 1667 | dpsf->sf_next = pmc->tomb; |
| 1668 | pmc->tomb = dpsf; |
| 1669 | } |
| 1670 | dpsf->sf_crcount = qrv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | rv++; |
| 1672 | } |
| 1673 | } |
| 1674 | return rv; |
| 1675 | } |
| 1676 | #endif |
| 1677 | |
| 1678 | /* |
| 1679 | * Add multicast source filter list to the interface list |
| 1680 | */ |
Al Viro | 8f935bb | 2006-09-27 18:30:07 -0700 | [diff] [blame] | 1681 | static int ip_mc_add_src(struct in_device *in_dev, __be32 *pmca, int sfmode, |
| 1682 | int sfcount, __be32 *psfsrc, int delta) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | { |
| 1684 | struct ip_mc_list *pmc; |
| 1685 | int isexclude; |
| 1686 | int i, err; |
| 1687 | |
| 1688 | if (!in_dev) |
| 1689 | return -ENODEV; |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1690 | rcu_read_lock(); |
| 1691 | for_each_pmc_rcu(in_dev, pmc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | if (*pmca == pmc->multiaddr) |
| 1693 | break; |
| 1694 | } |
| 1695 | if (!pmc) { |
| 1696 | /* MCA not found?? bug */ |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1697 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | return -ESRCH; |
| 1699 | } |
| 1700 | spin_lock_bh(&pmc->lock); |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1701 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | |
| 1703 | #ifdef CONFIG_IP_MULTICAST |
| 1704 | sf_markstate(pmc); |
| 1705 | #endif |
| 1706 | isexclude = pmc->sfmode == MCAST_EXCLUDE; |
| 1707 | if (!delta) |
| 1708 | pmc->sfcount[sfmode]++; |
| 1709 | err = 0; |
| 1710 | for (i=0; i<sfcount; i++) { |
| 1711 | err = ip_mc_add1_src(pmc, sfmode, &psfsrc[i], delta); |
| 1712 | if (err) |
| 1713 | break; |
| 1714 | } |
| 1715 | if (err) { |
| 1716 | int j; |
| 1717 | |
| 1718 | pmc->sfcount[sfmode]--; |
| 1719 | for (j=0; j<i; j++) |
| 1720 | (void) ip_mc_del1_src(pmc, sfmode, &psfsrc[i]); |
| 1721 | } else if (isexclude != (pmc->sfcount[MCAST_EXCLUDE] != 0)) { |
| 1722 | #ifdef CONFIG_IP_MULTICAST |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | struct ip_sf_list *psf; |
Stephen Hemminger | cfcabdc | 2007-10-09 01:59:42 -0700 | [diff] [blame] | 1724 | in_dev = pmc->interface; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | #endif |
| 1726 | |
| 1727 | /* filter mode change */ |
| 1728 | if (pmc->sfcount[MCAST_EXCLUDE]) |
| 1729 | pmc->sfmode = MCAST_EXCLUDE; |
| 1730 | else if (pmc->sfcount[MCAST_INCLUDE]) |
| 1731 | pmc->sfmode = MCAST_INCLUDE; |
| 1732 | #ifdef CONFIG_IP_MULTICAST |
| 1733 | /* else no filters; keep old mode for reports */ |
| 1734 | |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1735 | pmc->crcount = in_dev->mr_qrv ? in_dev->mr_qrv : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | IGMP_Unsolicited_Report_Count; |
| 1737 | in_dev->mr_ifc_count = pmc->crcount; |
| 1738 | for (psf=pmc->sources; psf; psf = psf->sf_next) |
| 1739 | psf->sf_crcount = 0; |
| 1740 | igmp_ifc_event(in_dev); |
| 1741 | } else if (sf_setstate(pmc)) { |
| 1742 | igmp_ifc_event(in_dev); |
| 1743 | #endif |
| 1744 | } |
| 1745 | spin_unlock_bh(&pmc->lock); |
| 1746 | return err; |
| 1747 | } |
| 1748 | |
| 1749 | static void ip_mc_clear_src(struct ip_mc_list *pmc) |
| 1750 | { |
| 1751 | struct ip_sf_list *psf, *nextpsf; |
| 1752 | |
| 1753 | for (psf=pmc->tomb; psf; psf=nextpsf) { |
| 1754 | nextpsf = psf->sf_next; |
| 1755 | kfree(psf); |
| 1756 | } |
| 1757 | pmc->tomb = NULL; |
| 1758 | for (psf=pmc->sources; psf; psf=nextpsf) { |
| 1759 | nextpsf = psf->sf_next; |
| 1760 | kfree(psf); |
| 1761 | } |
| 1762 | pmc->sources = NULL; |
| 1763 | pmc->sfmode = MCAST_EXCLUDE; |
Denis Lukianov | de9daad | 2005-09-14 20:53:42 -0700 | [diff] [blame] | 1764 | pmc->sfcount[MCAST_INCLUDE] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | pmc->sfcount[MCAST_EXCLUDE] = 1; |
| 1766 | } |
| 1767 | |
| 1768 | |
| 1769 | /* |
| 1770 | * Join a multicast group |
| 1771 | */ |
| 1772 | int ip_mc_join_group(struct sock *sk , struct ip_mreqn *imr) |
| 1773 | { |
| 1774 | int err; |
Al Viro | 8f935bb | 2006-09-27 18:30:07 -0700 | [diff] [blame] | 1775 | __be32 addr = imr->imr_multiaddr.s_addr; |
Jianjun Kong | a7e9ff7 | 2008-11-03 00:26:09 -0800 | [diff] [blame] | 1776 | struct ip_mc_socklist *iml = NULL, *i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | struct in_device *in_dev; |
| 1778 | struct inet_sock *inet = inet_sk(sk); |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 1779 | struct net *net = sock_net(sk); |
David L Stevens | ca9b907 | 2005-07-08 17:38:07 -0700 | [diff] [blame] | 1780 | int ifindex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | int count = 0; |
| 1782 | |
Joe Perches | f97c1e0 | 2007-12-16 13:45:43 -0800 | [diff] [blame] | 1783 | if (!ipv4_is_multicast(addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | return -EINVAL; |
| 1785 | |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 1786 | rtnl_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 1788 | in_dev = ip_mc_find_dev(net, imr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | |
| 1790 | if (!in_dev) { |
| 1791 | iml = NULL; |
| 1792 | err = -ENODEV; |
| 1793 | goto done; |
| 1794 | } |
| 1795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | err = -EADDRINUSE; |
David L Stevens | ca9b907 | 2005-07-08 17:38:07 -0700 | [diff] [blame] | 1797 | ifindex = imr->imr_ifindex; |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1798 | for_each_pmc_rtnl(inet, i) { |
David L Stevens | ca9b907 | 2005-07-08 17:38:07 -0700 | [diff] [blame] | 1799 | if (i->multi.imr_multiaddr.s_addr == addr && |
| 1800 | i->multi.imr_ifindex == ifindex) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | count++; |
| 1803 | } |
| 1804 | err = -ENOBUFS; |
David L Stevens | ca9b907 | 2005-07-08 17:38:07 -0700 | [diff] [blame] | 1805 | if (count >= sysctl_igmp_max_memberships) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | goto done; |
Jianjun Kong | a7e9ff7 | 2008-11-03 00:26:09 -0800 | [diff] [blame] | 1807 | iml = sock_kmalloc(sk, sizeof(*iml), GFP_KERNEL); |
David L Stevens | ca9b907 | 2005-07-08 17:38:07 -0700 | [diff] [blame] | 1808 | if (iml == NULL) |
| 1809 | goto done; |
| 1810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | memcpy(&iml->multi, imr, sizeof(*imr)); |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1812 | iml->next_rcu = inet->mc_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | iml->sflist = NULL; |
| 1814 | iml->sfmode = MCAST_EXCLUDE; |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 1815 | rcu_assign_pointer(inet->mc_list, iml); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | ip_mc_inc_group(in_dev, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | done: |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 1819 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | return err; |
| 1821 | } |
Eric Dumazet | 4bc2f18 | 2010-07-09 21:22:10 +0000 | [diff] [blame] | 1822 | EXPORT_SYMBOL(ip_mc_join_group); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 1824 | static void ip_sf_socklist_reclaim(struct rcu_head *rp) |
| 1825 | { |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1826 | kfree(container_of(rp, struct ip_sf_socklist, rcu)); |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 1827 | /* sk_omem_alloc should have been decreased by the caller*/ |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 1828 | } |
| 1829 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | static int ip_mc_leave_src(struct sock *sk, struct ip_mc_socklist *iml, |
| 1831 | struct in_device *in_dev) |
| 1832 | { |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1833 | struct ip_sf_socklist *psf = rtnl_dereference(iml->sflist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | int err; |
| 1835 | |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 1836 | if (psf == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | /* any-source empty exclude case */ |
| 1838 | return ip_mc_del_src(in_dev, &iml->multi.imr_multiaddr.s_addr, |
| 1839 | iml->sfmode, 0, NULL, 0); |
| 1840 | } |
| 1841 | err = ip_mc_del_src(in_dev, &iml->multi.imr_multiaddr.s_addr, |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 1842 | iml->sfmode, psf->sl_count, psf->sl_addr, 0); |
| 1843 | rcu_assign_pointer(iml->sflist, NULL); |
| 1844 | /* decrease mem now to avoid the memleak warning */ |
| 1845 | atomic_sub(IP_SFLSIZE(psf->sl_max), &sk->sk_omem_alloc); |
| 1846 | call_rcu(&psf->rcu, ip_sf_socklist_reclaim); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | return err; |
| 1848 | } |
| 1849 | |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 1850 | |
| 1851 | static void ip_mc_socklist_reclaim(struct rcu_head *rp) |
| 1852 | { |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1853 | kfree(container_of(rp, struct ip_mc_socklist, rcu)); |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 1854 | /* sk_omem_alloc should have been decreased by the caller*/ |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 1855 | } |
| 1856 | |
| 1857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | /* |
| 1859 | * Ask a socket to leave a group. |
| 1860 | */ |
| 1861 | |
| 1862 | int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr) |
| 1863 | { |
| 1864 | struct inet_sock *inet = inet_sk(sk); |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1865 | struct ip_mc_socklist *iml; |
| 1866 | struct ip_mc_socklist __rcu **imlp; |
David L Stevens | 84b42ba | 2005-07-08 17:48:38 -0700 | [diff] [blame] | 1867 | struct in_device *in_dev; |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 1868 | struct net *net = sock_net(sk); |
Al Viro | 8f935bb | 2006-09-27 18:30:07 -0700 | [diff] [blame] | 1869 | __be32 group = imr->imr_multiaddr.s_addr; |
David L Stevens | 84b42ba | 2005-07-08 17:48:38 -0700 | [diff] [blame] | 1870 | u32 ifindex; |
David L Stevens | acd6e00 | 2006-08-17 16:27:39 -0700 | [diff] [blame] | 1871 | int ret = -EADDRNOTAVAIL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | |
| 1873 | rtnl_lock(); |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 1874 | in_dev = ip_mc_find_dev(net, imr); |
David L Stevens | 84b42ba | 2005-07-08 17:48:38 -0700 | [diff] [blame] | 1875 | ifindex = imr->imr_ifindex; |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1876 | for (imlp = &inet->mc_list; |
| 1877 | (iml = rtnl_dereference(*imlp)) != NULL; |
| 1878 | imlp = &iml->next_rcu) { |
David L Stevens | acd6e00 | 2006-08-17 16:27:39 -0700 | [diff] [blame] | 1879 | if (iml->multi.imr_multiaddr.s_addr != group) |
| 1880 | continue; |
| 1881 | if (ifindex) { |
| 1882 | if (iml->multi.imr_ifindex != ifindex) |
| 1883 | continue; |
| 1884 | } else if (imr->imr_address.s_addr && imr->imr_address.s_addr != |
| 1885 | iml->multi.imr_address.s_addr) |
| 1886 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | |
David L Stevens | acd6e00 | 2006-08-17 16:27:39 -0700 | [diff] [blame] | 1888 | (void) ip_mc_leave_src(sk, iml, in_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1890 | *imlp = iml->next_rcu; |
David L Stevens | acd6e00 | 2006-08-17 16:27:39 -0700 | [diff] [blame] | 1891 | |
| 1892 | if (in_dev) |
David L Stevens | 84b42ba | 2005-07-08 17:48:38 -0700 | [diff] [blame] | 1893 | ip_mc_dec_group(in_dev, group); |
David L Stevens | acd6e00 | 2006-08-17 16:27:39 -0700 | [diff] [blame] | 1894 | rtnl_unlock(); |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 1895 | /* decrease mem now to avoid the memleak warning */ |
| 1896 | atomic_sub(sizeof(*iml), &sk->sk_omem_alloc); |
| 1897 | call_rcu(&iml->rcu, ip_mc_socklist_reclaim); |
David L Stevens | acd6e00 | 2006-08-17 16:27:39 -0700 | [diff] [blame] | 1898 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | } |
David L Stevens | acd6e00 | 2006-08-17 16:27:39 -0700 | [diff] [blame] | 1900 | if (!in_dev) |
| 1901 | ret = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | rtnl_unlock(); |
David L Stevens | acd6e00 | 2006-08-17 16:27:39 -0700 | [diff] [blame] | 1903 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | int ip_mc_source(int add, int omode, struct sock *sk, struct |
| 1907 | ip_mreq_source *mreqs, int ifindex) |
| 1908 | { |
| 1909 | int err; |
| 1910 | struct ip_mreqn imr; |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 1911 | __be32 addr = mreqs->imr_multiaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | struct ip_mc_socklist *pmc; |
| 1913 | struct in_device *in_dev = NULL; |
| 1914 | struct inet_sock *inet = inet_sk(sk); |
| 1915 | struct ip_sf_socklist *psl; |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 1916 | struct net *net = sock_net(sk); |
David L Stevens | 8cdaaa1 | 2005-07-08 17:39:23 -0700 | [diff] [blame] | 1917 | int leavegroup = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | int i, j, rv; |
| 1919 | |
Joe Perches | f97c1e0 | 2007-12-16 13:45:43 -0800 | [diff] [blame] | 1920 | if (!ipv4_is_multicast(addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | return -EINVAL; |
| 1922 | |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 1923 | rtnl_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | |
| 1925 | imr.imr_multiaddr.s_addr = mreqs->imr_multiaddr; |
| 1926 | imr.imr_address.s_addr = mreqs->imr_interface; |
| 1927 | imr.imr_ifindex = ifindex; |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 1928 | in_dev = ip_mc_find_dev(net, &imr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | |
| 1930 | if (!in_dev) { |
| 1931 | err = -ENODEV; |
| 1932 | goto done; |
| 1933 | } |
| 1934 | err = -EADDRNOTAVAIL; |
| 1935 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1936 | for_each_pmc_rtnl(inet, pmc) { |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 1937 | if ((pmc->multi.imr_multiaddr.s_addr == |
| 1938 | imr.imr_multiaddr.s_addr) && |
| 1939 | (pmc->multi.imr_ifindex == imr.imr_ifindex)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | break; |
| 1941 | } |
David L Stevens | 917f2f1 | 2005-07-08 17:45:16 -0700 | [diff] [blame] | 1942 | if (!pmc) { /* must have a prior join */ |
| 1943 | err = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | goto done; |
David L Stevens | 917f2f1 | 2005-07-08 17:45:16 -0700 | [diff] [blame] | 1945 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | /* if a source filter was set, must be the same mode as before */ |
| 1947 | if (pmc->sflist) { |
David L Stevens | 917f2f1 | 2005-07-08 17:45:16 -0700 | [diff] [blame] | 1948 | if (pmc->sfmode != omode) { |
| 1949 | err = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | goto done; |
David L Stevens | 917f2f1 | 2005-07-08 17:45:16 -0700 | [diff] [blame] | 1951 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | } else if (pmc->sfmode != omode) { |
| 1953 | /* allow mode switches for empty-set filters */ |
| 1954 | ip_mc_add_src(in_dev, &mreqs->imr_multiaddr, omode, 0, NULL, 0); |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1955 | ip_mc_del_src(in_dev, &mreqs->imr_multiaddr, pmc->sfmode, 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | NULL, 0); |
| 1957 | pmc->sfmode = omode; |
| 1958 | } |
| 1959 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 1960 | psl = rtnl_dereference(pmc->sflist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | if (!add) { |
| 1962 | if (!psl) |
David L Stevens | 917f2f1 | 2005-07-08 17:45:16 -0700 | [diff] [blame] | 1963 | goto done; /* err = -EADDRNOTAVAIL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | rv = !0; |
| 1965 | for (i=0; i<psl->sl_count; i++) { |
| 1966 | rv = memcmp(&psl->sl_addr[i], &mreqs->imr_sourceaddr, |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 1967 | sizeof(__be32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | if (rv == 0) |
| 1969 | break; |
| 1970 | } |
| 1971 | if (rv) /* source not found */ |
David L Stevens | 917f2f1 | 2005-07-08 17:45:16 -0700 | [diff] [blame] | 1972 | goto done; /* err = -EADDRNOTAVAIL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | |
David L Stevens | 8cdaaa1 | 2005-07-08 17:39:23 -0700 | [diff] [blame] | 1974 | /* special case - (INCLUDE, empty) == LEAVE_GROUP */ |
| 1975 | if (psl->sl_count == 1 && omode == MCAST_INCLUDE) { |
| 1976 | leavegroup = 1; |
| 1977 | goto done; |
| 1978 | } |
| 1979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | /* update the interface filter */ |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 1981 | ip_mc_del_src(in_dev, &mreqs->imr_multiaddr, omode, 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | &mreqs->imr_sourceaddr, 1); |
| 1983 | |
| 1984 | for (j=i+1; j<psl->sl_count; j++) |
| 1985 | psl->sl_addr[j-1] = psl->sl_addr[j]; |
| 1986 | psl->sl_count--; |
| 1987 | err = 0; |
| 1988 | goto done; |
| 1989 | } |
| 1990 | /* else, add a new source to the filter */ |
| 1991 | |
| 1992 | if (psl && psl->sl_count >= sysctl_igmp_max_msf) { |
| 1993 | err = -ENOBUFS; |
| 1994 | goto done; |
| 1995 | } |
| 1996 | if (!psl || psl->sl_count == psl->sl_max) { |
| 1997 | struct ip_sf_socklist *newpsl; |
| 1998 | int count = IP_SFBLOCK; |
| 1999 | |
| 2000 | if (psl) |
| 2001 | count += psl->sl_max; |
Kris Katterjohn | 8b3a700 | 2006-01-11 15:56:43 -0800 | [diff] [blame] | 2002 | newpsl = sock_kmalloc(sk, IP_SFLSIZE(count), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | if (!newpsl) { |
| 2004 | err = -ENOBUFS; |
| 2005 | goto done; |
| 2006 | } |
| 2007 | newpsl->sl_max = count; |
| 2008 | newpsl->sl_count = count - IP_SFBLOCK; |
| 2009 | if (psl) { |
| 2010 | for (i=0; i<psl->sl_count; i++) |
| 2011 | newpsl->sl_addr[i] = psl->sl_addr[i]; |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 2012 | /* decrease mem now to avoid the memleak warning */ |
| 2013 | atomic_sub(IP_SFLSIZE(psl->sl_max), &sk->sk_omem_alloc); |
| 2014 | call_rcu(&psl->rcu, ip_sf_socklist_reclaim); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | } |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 2016 | rcu_assign_pointer(pmc->sflist, newpsl); |
| 2017 | psl = newpsl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | } |
| 2019 | rv = 1; /* > 0 for insert logic below if sl_count is 0 */ |
| 2020 | for (i=0; i<psl->sl_count; i++) { |
| 2021 | rv = memcmp(&psl->sl_addr[i], &mreqs->imr_sourceaddr, |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 2022 | sizeof(__be32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | if (rv == 0) |
| 2024 | break; |
| 2025 | } |
| 2026 | if (rv == 0) /* address already there is an error */ |
| 2027 | goto done; |
| 2028 | for (j=psl->sl_count-1; j>=i; j--) |
| 2029 | psl->sl_addr[j+1] = psl->sl_addr[j]; |
| 2030 | psl->sl_addr[i] = mreqs->imr_sourceaddr; |
| 2031 | psl->sl_count++; |
| 2032 | err = 0; |
| 2033 | /* update the interface list */ |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 2034 | ip_mc_add_src(in_dev, &mreqs->imr_multiaddr, omode, 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | &mreqs->imr_sourceaddr, 1); |
| 2036 | done: |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 2037 | rtnl_unlock(); |
David L Stevens | 8cdaaa1 | 2005-07-08 17:39:23 -0700 | [diff] [blame] | 2038 | if (leavegroup) |
| 2039 | return ip_mc_leave_group(sk, &imr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | return err; |
| 2041 | } |
| 2042 | |
| 2043 | int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf, int ifindex) |
| 2044 | { |
David L Stevens | 9951f03 | 2005-07-08 17:47:28 -0700 | [diff] [blame] | 2045 | int err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | struct ip_mreqn imr; |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 2047 | __be32 addr = msf->imsf_multiaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | struct ip_mc_socklist *pmc; |
| 2049 | struct in_device *in_dev; |
| 2050 | struct inet_sock *inet = inet_sk(sk); |
| 2051 | struct ip_sf_socklist *newpsl, *psl; |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 2052 | struct net *net = sock_net(sk); |
David L Stevens | 9951f03 | 2005-07-08 17:47:28 -0700 | [diff] [blame] | 2053 | int leavegroup = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | |
Joe Perches | f97c1e0 | 2007-12-16 13:45:43 -0800 | [diff] [blame] | 2055 | if (!ipv4_is_multicast(addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | return -EINVAL; |
| 2057 | if (msf->imsf_fmode != MCAST_INCLUDE && |
| 2058 | msf->imsf_fmode != MCAST_EXCLUDE) |
| 2059 | return -EINVAL; |
| 2060 | |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 2061 | rtnl_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | |
| 2063 | imr.imr_multiaddr.s_addr = msf->imsf_multiaddr; |
| 2064 | imr.imr_address.s_addr = msf->imsf_interface; |
| 2065 | imr.imr_ifindex = ifindex; |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 2066 | in_dev = ip_mc_find_dev(net, &imr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | |
| 2068 | if (!in_dev) { |
| 2069 | err = -ENODEV; |
| 2070 | goto done; |
| 2071 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | |
David L Stevens | 9951f03 | 2005-07-08 17:47:28 -0700 | [diff] [blame] | 2073 | /* special case - (INCLUDE, empty) == LEAVE_GROUP */ |
| 2074 | if (msf->imsf_fmode == MCAST_INCLUDE && msf->imsf_numsrc == 0) { |
| 2075 | leavegroup = 1; |
| 2076 | goto done; |
| 2077 | } |
| 2078 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2079 | for_each_pmc_rtnl(inet, pmc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | if (pmc->multi.imr_multiaddr.s_addr == msf->imsf_multiaddr && |
| 2081 | pmc->multi.imr_ifindex == imr.imr_ifindex) |
| 2082 | break; |
| 2083 | } |
David L Stevens | 917f2f1 | 2005-07-08 17:45:16 -0700 | [diff] [blame] | 2084 | if (!pmc) { /* must have a prior join */ |
| 2085 | err = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | goto done; |
David L Stevens | 917f2f1 | 2005-07-08 17:45:16 -0700 | [diff] [blame] | 2087 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | if (msf->imsf_numsrc) { |
Kris Katterjohn | 8b3a700 | 2006-01-11 15:56:43 -0800 | [diff] [blame] | 2089 | newpsl = sock_kmalloc(sk, IP_SFLSIZE(msf->imsf_numsrc), |
| 2090 | GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | if (!newpsl) { |
| 2092 | err = -ENOBUFS; |
| 2093 | goto done; |
| 2094 | } |
| 2095 | newpsl->sl_max = newpsl->sl_count = msf->imsf_numsrc; |
| 2096 | memcpy(newpsl->sl_addr, msf->imsf_slist, |
| 2097 | msf->imsf_numsrc * sizeof(msf->imsf_slist[0])); |
| 2098 | err = ip_mc_add_src(in_dev, &msf->imsf_multiaddr, |
| 2099 | msf->imsf_fmode, newpsl->sl_count, newpsl->sl_addr, 0); |
| 2100 | if (err) { |
| 2101 | sock_kfree_s(sk, newpsl, IP_SFLSIZE(newpsl->sl_max)); |
| 2102 | goto done; |
| 2103 | } |
Yan Zheng | 8713dbf | 2005-10-28 08:02:08 +0800 | [diff] [blame] | 2104 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | newpsl = NULL; |
Yan Zheng | 8713dbf | 2005-10-28 08:02:08 +0800 | [diff] [blame] | 2106 | (void) ip_mc_add_src(in_dev, &msf->imsf_multiaddr, |
| 2107 | msf->imsf_fmode, 0, NULL, 0); |
| 2108 | } |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2109 | psl = rtnl_dereference(pmc->sflist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | if (psl) { |
| 2111 | (void) ip_mc_del_src(in_dev, &msf->imsf_multiaddr, pmc->sfmode, |
| 2112 | psl->sl_count, psl->sl_addr, 0); |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 2113 | /* decrease mem now to avoid the memleak warning */ |
| 2114 | atomic_sub(IP_SFLSIZE(psl->sl_max), &sk->sk_omem_alloc); |
| 2115 | call_rcu(&psl->rcu, ip_sf_socklist_reclaim); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | } else |
| 2117 | (void) ip_mc_del_src(in_dev, &msf->imsf_multiaddr, pmc->sfmode, |
| 2118 | 0, NULL, 0); |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 2119 | rcu_assign_pointer(pmc->sflist, newpsl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | pmc->sfmode = msf->imsf_fmode; |
David L Stevens | 917f2f1 | 2005-07-08 17:45:16 -0700 | [diff] [blame] | 2121 | err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | done: |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 2123 | rtnl_unlock(); |
David L Stevens | 9951f03 | 2005-07-08 17:47:28 -0700 | [diff] [blame] | 2124 | if (leavegroup) |
| 2125 | err = ip_mc_leave_group(sk, &imr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2126 | return err; |
| 2127 | } |
| 2128 | |
| 2129 | int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf, |
| 2130 | struct ip_msfilter __user *optval, int __user *optlen) |
| 2131 | { |
| 2132 | int err, len, count, copycount; |
| 2133 | struct ip_mreqn imr; |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 2134 | __be32 addr = msf->imsf_multiaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | struct ip_mc_socklist *pmc; |
| 2136 | struct in_device *in_dev; |
| 2137 | struct inet_sock *inet = inet_sk(sk); |
| 2138 | struct ip_sf_socklist *psl; |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 2139 | struct net *net = sock_net(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | |
Joe Perches | f97c1e0 | 2007-12-16 13:45:43 -0800 | [diff] [blame] | 2141 | if (!ipv4_is_multicast(addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | return -EINVAL; |
| 2143 | |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 2144 | rtnl_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | |
| 2146 | imr.imr_multiaddr.s_addr = msf->imsf_multiaddr; |
| 2147 | imr.imr_address.s_addr = msf->imsf_interface; |
| 2148 | imr.imr_ifindex = 0; |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 2149 | in_dev = ip_mc_find_dev(net, &imr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | |
| 2151 | if (!in_dev) { |
| 2152 | err = -ENODEV; |
| 2153 | goto done; |
| 2154 | } |
| 2155 | err = -EADDRNOTAVAIL; |
| 2156 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2157 | for_each_pmc_rtnl(inet, pmc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | if (pmc->multi.imr_multiaddr.s_addr == msf->imsf_multiaddr && |
| 2159 | pmc->multi.imr_ifindex == imr.imr_ifindex) |
| 2160 | break; |
| 2161 | } |
| 2162 | if (!pmc) /* must have a prior join */ |
| 2163 | goto done; |
| 2164 | msf->imsf_fmode = pmc->sfmode; |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2165 | psl = rtnl_dereference(pmc->sflist); |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 2166 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2167 | if (!psl) { |
| 2168 | len = 0; |
| 2169 | count = 0; |
| 2170 | } else { |
| 2171 | count = psl->sl_count; |
| 2172 | } |
| 2173 | copycount = count < msf->imsf_numsrc ? count : msf->imsf_numsrc; |
| 2174 | len = copycount * sizeof(psl->sl_addr[0]); |
| 2175 | msf->imsf_numsrc = count; |
| 2176 | if (put_user(IP_MSFILTER_SIZE(copycount), optlen) || |
| 2177 | copy_to_user(optval, msf, IP_MSFILTER_SIZE(0))) { |
| 2178 | return -EFAULT; |
| 2179 | } |
| 2180 | if (len && |
| 2181 | copy_to_user(&optval->imsf_slist[0], psl->sl_addr, len)) |
| 2182 | return -EFAULT; |
| 2183 | return 0; |
| 2184 | done: |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 2185 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | return err; |
| 2187 | } |
| 2188 | |
| 2189 | int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf, |
| 2190 | struct group_filter __user *optval, int __user *optlen) |
| 2191 | { |
| 2192 | int err, i, count, copycount; |
| 2193 | struct sockaddr_in *psin; |
Al Viro | 6300772 | 2006-09-27 18:31:32 -0700 | [diff] [blame] | 2194 | __be32 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | struct ip_mc_socklist *pmc; |
| 2196 | struct inet_sock *inet = inet_sk(sk); |
| 2197 | struct ip_sf_socklist *psl; |
| 2198 | |
| 2199 | psin = (struct sockaddr_in *)&gsf->gf_group; |
| 2200 | if (psin->sin_family != AF_INET) |
| 2201 | return -EINVAL; |
| 2202 | addr = psin->sin_addr.s_addr; |
Joe Perches | f97c1e0 | 2007-12-16 13:45:43 -0800 | [diff] [blame] | 2203 | if (!ipv4_is_multicast(addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | return -EINVAL; |
| 2205 | |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 2206 | rtnl_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | |
| 2208 | err = -EADDRNOTAVAIL; |
| 2209 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2210 | for_each_pmc_rtnl(inet, pmc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | if (pmc->multi.imr_multiaddr.s_addr == addr && |
| 2212 | pmc->multi.imr_ifindex == gsf->gf_interface) |
| 2213 | break; |
| 2214 | } |
| 2215 | if (!pmc) /* must have a prior join */ |
| 2216 | goto done; |
| 2217 | gsf->gf_fmode = pmc->sfmode; |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2218 | psl = rtnl_dereference(pmc->sflist); |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 2219 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | count = psl ? psl->sl_count : 0; |
| 2221 | copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc; |
| 2222 | gsf->gf_numsrc = count; |
| 2223 | if (put_user(GROUP_FILTER_SIZE(copycount), optlen) || |
| 2224 | copy_to_user(optval, gsf, GROUP_FILTER_SIZE(0))) { |
| 2225 | return -EFAULT; |
| 2226 | } |
| 2227 | for (i=0; i<copycount; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | struct sockaddr_storage ss; |
| 2229 | |
| 2230 | psin = (struct sockaddr_in *)&ss; |
| 2231 | memset(&ss, 0, sizeof(ss)); |
| 2232 | psin->sin_family = AF_INET; |
| 2233 | psin->sin_addr.s_addr = psl->sl_addr[i]; |
| 2234 | if (copy_to_user(&optval->gf_slist[i], &ss, sizeof(ss))) |
| 2235 | return -EFAULT; |
| 2236 | } |
| 2237 | return 0; |
| 2238 | done: |
Stephen Hemminger | 6756ae4 | 2006-03-20 22:23:58 -0800 | [diff] [blame] | 2239 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2240 | return err; |
| 2241 | } |
| 2242 | |
| 2243 | /* |
| 2244 | * check if a multicast source filter allows delivery for a given <src,dst,intf> |
| 2245 | */ |
Al Viro | c0cda06 | 2006-09-27 18:31:10 -0700 | [diff] [blame] | 2246 | int ip_mc_sf_allow(struct sock *sk, __be32 loc_addr, __be32 rmt_addr, int dif) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | { |
| 2248 | struct inet_sock *inet = inet_sk(sk); |
| 2249 | struct ip_mc_socklist *pmc; |
| 2250 | struct ip_sf_socklist *psl; |
| 2251 | int i; |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 2252 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 2254 | ret = 1; |
Joe Perches | f97c1e0 | 2007-12-16 13:45:43 -0800 | [diff] [blame] | 2255 | if (!ipv4_is_multicast(loc_addr)) |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 2256 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2257 | |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 2258 | rcu_read_lock(); |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2259 | for_each_pmc_rcu(inet, pmc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | if (pmc->multi.imr_multiaddr.s_addr == loc_addr && |
| 2261 | pmc->multi.imr_ifindex == dif) |
| 2262 | break; |
| 2263 | } |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 2264 | ret = inet->mc_all; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | if (!pmc) |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 2266 | goto unlock; |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2267 | psl = rcu_dereference(pmc->sflist); |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 2268 | ret = (pmc->sfmode == MCAST_EXCLUDE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | if (!psl) |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 2270 | goto unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | |
| 2272 | for (i=0; i<psl->sl_count; i++) { |
| 2273 | if (psl->sl_addr[i] == rmt_addr) |
| 2274 | break; |
| 2275 | } |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 2276 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | if (pmc->sfmode == MCAST_INCLUDE && i >= psl->sl_count) |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 2278 | goto unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | if (pmc->sfmode == MCAST_EXCLUDE && i < psl->sl_count) |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 2280 | goto unlock; |
| 2281 | ret = 1; |
| 2282 | unlock: |
| 2283 | rcu_read_unlock(); |
| 2284 | out: |
| 2285 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | /* |
| 2289 | * A socket is closing. |
| 2290 | */ |
| 2291 | |
| 2292 | void ip_mc_drop_socket(struct sock *sk) |
| 2293 | { |
| 2294 | struct inet_sock *inet = inet_sk(sk); |
| 2295 | struct ip_mc_socklist *iml; |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 2296 | struct net *net = sock_net(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | |
| 2298 | if (inet->mc_list == NULL) |
| 2299 | return; |
| 2300 | |
| 2301 | rtnl_lock(); |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2302 | while ((iml = rtnl_dereference(inet->mc_list)) != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | struct in_device *in_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2305 | inet->mc_list = iml->next_rcu; |
Daniel Lezcano | 877aced | 2008-08-13 16:15:57 -0700 | [diff] [blame] | 2306 | in_dev = inetdev_by_index(net, iml->multi.imr_ifindex); |
Michal Ruzicka | bb699cbc | 2006-08-15 00:20:17 -0700 | [diff] [blame] | 2307 | (void) ip_mc_leave_src(sk, iml, in_dev); |
Eric Dumazet | 18943d2 | 2010-11-08 11:15:54 +0000 | [diff] [blame] | 2308 | if (in_dev != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | ip_mc_dec_group(in_dev, iml->multi.imr_multiaddr.s_addr); |
Flavio Leitner | c85bb41 | 2010-02-02 07:32:29 -0800 | [diff] [blame] | 2310 | /* decrease mem now to avoid the memleak warning */ |
| 2311 | atomic_sub(sizeof(*iml), &sk->sk_omem_alloc); |
| 2312 | call_rcu(&iml->rcu, ip_mc_socklist_reclaim); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | } |
| 2314 | rtnl_unlock(); |
| 2315 | } |
| 2316 | |
Al Viro | a60c492 | 2006-09-26 21:28:34 -0700 | [diff] [blame] | 2317 | int ip_check_mc(struct in_device *in_dev, __be32 mc_addr, __be32 src_addr, u16 proto) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | { |
| 2319 | struct ip_mc_list *im; |
| 2320 | struct ip_sf_list *psf; |
| 2321 | int rv = 0; |
| 2322 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2323 | rcu_read_lock(); |
| 2324 | for_each_pmc_rcu(in_dev, im) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | if (im->multiaddr == mc_addr) |
| 2326 | break; |
| 2327 | } |
| 2328 | if (im && proto == IPPROTO_IGMP) { |
| 2329 | rv = 1; |
| 2330 | } else if (im) { |
| 2331 | if (src_addr) { |
| 2332 | for (psf=im->sources; psf; psf=psf->sf_next) { |
| 2333 | if (psf->sf_inaddr == src_addr) |
| 2334 | break; |
| 2335 | } |
| 2336 | if (psf) |
| 2337 | rv = psf->sf_count[MCAST_INCLUDE] || |
| 2338 | psf->sf_count[MCAST_EXCLUDE] != |
| 2339 | im->sfcount[MCAST_EXCLUDE]; |
| 2340 | else |
| 2341 | rv = im->sfcount[MCAST_EXCLUDE] != 0; |
| 2342 | } else |
| 2343 | rv = 1; /* unspecified source; tentatively allow */ |
| 2344 | } |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2345 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | return rv; |
| 2347 | } |
| 2348 | |
| 2349 | #if defined(CONFIG_PROC_FS) |
| 2350 | struct igmp_mc_iter_state { |
Alexey Dobriyan | 7091e72 | 2008-12-25 16:42:51 -0800 | [diff] [blame] | 2351 | struct seq_net_private p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | struct net_device *dev; |
| 2353 | struct in_device *in_dev; |
| 2354 | }; |
| 2355 | |
| 2356 | #define igmp_mc_seq_private(seq) ((struct igmp_mc_iter_state *)(seq)->private) |
| 2357 | |
| 2358 | static inline struct ip_mc_list *igmp_mc_get_first(struct seq_file *seq) |
| 2359 | { |
Alexey Dobriyan | 7091e72 | 2008-12-25 16:42:51 -0800 | [diff] [blame] | 2360 | struct net *net = seq_file_net(seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | struct ip_mc_list *im = NULL; |
| 2362 | struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq); |
| 2363 | |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 2364 | state->in_dev = NULL; |
stephen hemminger | 61fbab7 | 2009-11-10 07:54:55 +0000 | [diff] [blame] | 2365 | for_each_netdev_rcu(net, state->dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | struct in_device *in_dev; |
Eric Dumazet | 6baff15 | 2009-11-11 17:48:52 +0000 | [diff] [blame] | 2367 | |
| 2368 | in_dev = __in_dev_get_rcu(state->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | if (!in_dev) |
| 2370 | continue; |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2371 | im = rcu_dereference(in_dev->mc_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2372 | if (im) { |
| 2373 | state->in_dev = in_dev; |
| 2374 | break; |
| 2375 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2376 | } |
| 2377 | return im; |
| 2378 | } |
| 2379 | |
| 2380 | static struct ip_mc_list *igmp_mc_get_next(struct seq_file *seq, struct ip_mc_list *im) |
| 2381 | { |
| 2382 | struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq); |
Eric Dumazet | 6baff15 | 2009-11-11 17:48:52 +0000 | [diff] [blame] | 2383 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2384 | im = rcu_dereference(im->next_rcu); |
| 2385 | while (!im) { |
Eric Dumazet | 6baff15 | 2009-11-11 17:48:52 +0000 | [diff] [blame] | 2386 | state->dev = next_net_device_rcu(state->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | if (!state->dev) { |
| 2388 | state->in_dev = NULL; |
| 2389 | break; |
| 2390 | } |
Eric Dumazet | 6baff15 | 2009-11-11 17:48:52 +0000 | [diff] [blame] | 2391 | state->in_dev = __in_dev_get_rcu(state->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | if (!state->in_dev) |
| 2393 | continue; |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2394 | im = rcu_dereference(state->in_dev->mc_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | } |
| 2396 | return im; |
| 2397 | } |
| 2398 | |
| 2399 | static struct ip_mc_list *igmp_mc_get_idx(struct seq_file *seq, loff_t pos) |
| 2400 | { |
| 2401 | struct ip_mc_list *im = igmp_mc_get_first(seq); |
| 2402 | if (im) |
| 2403 | while (pos && (im = igmp_mc_get_next(seq, im)) != NULL) |
| 2404 | --pos; |
| 2405 | return pos ? NULL : im; |
| 2406 | } |
| 2407 | |
| 2408 | static void *igmp_mc_seq_start(struct seq_file *seq, loff_t *pos) |
stephen hemminger | 61fbab7 | 2009-11-10 07:54:55 +0000 | [diff] [blame] | 2409 | __acquires(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | { |
stephen hemminger | 61fbab7 | 2009-11-10 07:54:55 +0000 | [diff] [blame] | 2411 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | return *pos ? igmp_mc_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; |
| 2413 | } |
| 2414 | |
| 2415 | static void *igmp_mc_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 2416 | { |
| 2417 | struct ip_mc_list *im; |
| 2418 | if (v == SEQ_START_TOKEN) |
| 2419 | im = igmp_mc_get_first(seq); |
| 2420 | else |
| 2421 | im = igmp_mc_get_next(seq, v); |
| 2422 | ++*pos; |
| 2423 | return im; |
| 2424 | } |
| 2425 | |
| 2426 | static void igmp_mc_seq_stop(struct seq_file *seq, void *v) |
stephen hemminger | 61fbab7 | 2009-11-10 07:54:55 +0000 | [diff] [blame] | 2427 | __releases(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | { |
| 2429 | struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq); |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2430 | |
| 2431 | state->in_dev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | state->dev = NULL; |
stephen hemminger | 61fbab7 | 2009-11-10 07:54:55 +0000 | [diff] [blame] | 2433 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | static int igmp_mc_seq_show(struct seq_file *seq, void *v) |
| 2437 | { |
| 2438 | if (v == SEQ_START_TOKEN) |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 2439 | seq_puts(seq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | "Idx\tDevice : Count Querier\tGroup Users Timer\tReporter\n"); |
| 2441 | else { |
| 2442 | struct ip_mc_list *im = (struct ip_mc_list *)v; |
| 2443 | struct igmp_mc_iter_state *state = igmp_mc_seq_private(seq); |
| 2444 | char *querier; |
| 2445 | #ifdef CONFIG_IP_MULTICAST |
| 2446 | querier = IGMP_V1_SEEN(state->in_dev) ? "V1" : |
| 2447 | IGMP_V2_SEEN(state->in_dev) ? "V2" : |
| 2448 | "V3"; |
| 2449 | #else |
| 2450 | querier = "NONE"; |
| 2451 | #endif |
| 2452 | |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2453 | if (rcu_dereference(state->in_dev->mc_list) == im) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | seq_printf(seq, "%d\t%-10s: %5d %7s\n", |
Rami Rosen | b8bae41 | 2008-10-07 15:34:37 -0700 | [diff] [blame] | 2455 | state->dev->ifindex, state->dev->name, state->in_dev->mc_count, querier); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | } |
| 2457 | |
| 2458 | seq_printf(seq, |
Alexey Dobriyan | 338fcf9 | 2006-06-05 21:04:39 -0700 | [diff] [blame] | 2459 | "\t\t\t\t%08X %5d %d:%08lX\t\t%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | im->multiaddr, im->users, |
| 2461 | im->tm_running, im->tm_running ? |
| 2462 | jiffies_to_clock_t(im->timer.expires-jiffies) : 0, |
| 2463 | im->reporter); |
| 2464 | } |
| 2465 | return 0; |
| 2466 | } |
| 2467 | |
Stephen Hemminger | f690808 | 2007-03-12 14:34:29 -0700 | [diff] [blame] | 2468 | static const struct seq_operations igmp_mc_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | .start = igmp_mc_seq_start, |
| 2470 | .next = igmp_mc_seq_next, |
| 2471 | .stop = igmp_mc_seq_stop, |
| 2472 | .show = igmp_mc_seq_show, |
| 2473 | }; |
| 2474 | |
| 2475 | static int igmp_mc_seq_open(struct inode *inode, struct file *file) |
| 2476 | { |
Alexey Dobriyan | 7091e72 | 2008-12-25 16:42:51 -0800 | [diff] [blame] | 2477 | return seq_open_net(inode, file, &igmp_mc_seq_ops, |
Pavel Emelyanov | cf7732e | 2007-10-10 02:29:29 -0700 | [diff] [blame] | 2478 | sizeof(struct igmp_mc_iter_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 2481 | static const struct file_operations igmp_mc_seq_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | .owner = THIS_MODULE, |
| 2483 | .open = igmp_mc_seq_open, |
| 2484 | .read = seq_read, |
| 2485 | .llseek = seq_lseek, |
Alexey Dobriyan | 7091e72 | 2008-12-25 16:42:51 -0800 | [diff] [blame] | 2486 | .release = seq_release_net, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | }; |
| 2488 | |
| 2489 | struct igmp_mcf_iter_state { |
Alexey Dobriyan | 7091e72 | 2008-12-25 16:42:51 -0800 | [diff] [blame] | 2490 | struct seq_net_private p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | struct net_device *dev; |
| 2492 | struct in_device *idev; |
| 2493 | struct ip_mc_list *im; |
| 2494 | }; |
| 2495 | |
| 2496 | #define igmp_mcf_seq_private(seq) ((struct igmp_mcf_iter_state *)(seq)->private) |
| 2497 | |
| 2498 | static inline struct ip_sf_list *igmp_mcf_get_first(struct seq_file *seq) |
| 2499 | { |
Alexey Dobriyan | 7091e72 | 2008-12-25 16:42:51 -0800 | [diff] [blame] | 2500 | struct net *net = seq_file_net(seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | struct ip_sf_list *psf = NULL; |
| 2502 | struct ip_mc_list *im = NULL; |
| 2503 | struct igmp_mcf_iter_state *state = igmp_mcf_seq_private(seq); |
| 2504 | |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 2505 | state->idev = NULL; |
| 2506 | state->im = NULL; |
stephen hemminger | 61fbab7 | 2009-11-10 07:54:55 +0000 | [diff] [blame] | 2507 | for_each_netdev_rcu(net, state->dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | struct in_device *idev; |
Eric Dumazet | 6baff15 | 2009-11-11 17:48:52 +0000 | [diff] [blame] | 2509 | idev = __in_dev_get_rcu(state->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | if (unlikely(idev == NULL)) |
| 2511 | continue; |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2512 | im = rcu_dereference(idev->mc_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2513 | if (likely(im != NULL)) { |
| 2514 | spin_lock_bh(&im->lock); |
| 2515 | psf = im->sources; |
| 2516 | if (likely(psf != NULL)) { |
| 2517 | state->im = im; |
| 2518 | state->idev = idev; |
| 2519 | break; |
| 2520 | } |
| 2521 | spin_unlock_bh(&im->lock); |
| 2522 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2523 | } |
| 2524 | return psf; |
| 2525 | } |
| 2526 | |
| 2527 | static struct ip_sf_list *igmp_mcf_get_next(struct seq_file *seq, struct ip_sf_list *psf) |
| 2528 | { |
| 2529 | struct igmp_mcf_iter_state *state = igmp_mcf_seq_private(seq); |
| 2530 | |
| 2531 | psf = psf->sf_next; |
| 2532 | while (!psf) { |
| 2533 | spin_unlock_bh(&state->im->lock); |
| 2534 | state->im = state->im->next; |
| 2535 | while (!state->im) { |
Eric Dumazet | 6baff15 | 2009-11-11 17:48:52 +0000 | [diff] [blame] | 2536 | state->dev = next_net_device_rcu(state->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | if (!state->dev) { |
| 2538 | state->idev = NULL; |
| 2539 | goto out; |
| 2540 | } |
Eric Dumazet | 6baff15 | 2009-11-11 17:48:52 +0000 | [diff] [blame] | 2541 | state->idev = __in_dev_get_rcu(state->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | if (!state->idev) |
| 2543 | continue; |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2544 | state->im = rcu_dereference(state->idev->mc_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | } |
| 2546 | if (!state->im) |
| 2547 | break; |
| 2548 | spin_lock_bh(&state->im->lock); |
| 2549 | psf = state->im->sources; |
| 2550 | } |
| 2551 | out: |
| 2552 | return psf; |
| 2553 | } |
| 2554 | |
| 2555 | static struct ip_sf_list *igmp_mcf_get_idx(struct seq_file *seq, loff_t pos) |
| 2556 | { |
| 2557 | struct ip_sf_list *psf = igmp_mcf_get_first(seq); |
| 2558 | if (psf) |
| 2559 | while (pos && (psf = igmp_mcf_get_next(seq, psf)) != NULL) |
| 2560 | --pos; |
| 2561 | return pos ? NULL : psf; |
| 2562 | } |
| 2563 | |
| 2564 | static void *igmp_mcf_seq_start(struct seq_file *seq, loff_t *pos) |
stephen hemminger | 61fbab7 | 2009-11-10 07:54:55 +0000 | [diff] [blame] | 2565 | __acquires(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2566 | { |
stephen hemminger | 61fbab7 | 2009-11-10 07:54:55 +0000 | [diff] [blame] | 2567 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | return *pos ? igmp_mcf_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; |
| 2569 | } |
| 2570 | |
| 2571 | static void *igmp_mcf_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 2572 | { |
| 2573 | struct ip_sf_list *psf; |
| 2574 | if (v == SEQ_START_TOKEN) |
| 2575 | psf = igmp_mcf_get_first(seq); |
| 2576 | else |
| 2577 | psf = igmp_mcf_get_next(seq, v); |
| 2578 | ++*pos; |
| 2579 | return psf; |
| 2580 | } |
| 2581 | |
| 2582 | static void igmp_mcf_seq_stop(struct seq_file *seq, void *v) |
stephen hemminger | 61fbab7 | 2009-11-10 07:54:55 +0000 | [diff] [blame] | 2583 | __releases(rcu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2584 | { |
| 2585 | struct igmp_mcf_iter_state *state = igmp_mcf_seq_private(seq); |
| 2586 | if (likely(state->im != NULL)) { |
| 2587 | spin_unlock_bh(&state->im->lock); |
| 2588 | state->im = NULL; |
| 2589 | } |
Eric Dumazet | 1d7138d | 2010-11-12 05:46:50 +0000 | [diff] [blame] | 2590 | state->idev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | state->dev = NULL; |
stephen hemminger | 61fbab7 | 2009-11-10 07:54:55 +0000 | [diff] [blame] | 2592 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | static int igmp_mcf_seq_show(struct seq_file *seq, void *v) |
| 2596 | { |
| 2597 | struct ip_sf_list *psf = (struct ip_sf_list *)v; |
| 2598 | struct igmp_mcf_iter_state *state = igmp_mcf_seq_private(seq); |
| 2599 | |
| 2600 | if (v == SEQ_START_TOKEN) { |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 2601 | seq_printf(seq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | "%3s %6s " |
| 2603 | "%10s %10s %6s %6s\n", "Idx", |
| 2604 | "Device", "MCA", |
| 2605 | "SRC", "INC", "EXC"); |
| 2606 | } else { |
| 2607 | seq_printf(seq, |
| 2608 | "%3d %6.6s 0x%08x " |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 2609 | "0x%08x %6lu %6lu\n", |
| 2610 | state->dev->ifindex, state->dev->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | ntohl(state->im->multiaddr), |
| 2612 | ntohl(psf->sf_inaddr), |
| 2613 | psf->sf_count[MCAST_INCLUDE], |
| 2614 | psf->sf_count[MCAST_EXCLUDE]); |
| 2615 | } |
| 2616 | return 0; |
| 2617 | } |
| 2618 | |
Stephen Hemminger | f690808 | 2007-03-12 14:34:29 -0700 | [diff] [blame] | 2619 | static const struct seq_operations igmp_mcf_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 | .start = igmp_mcf_seq_start, |
| 2621 | .next = igmp_mcf_seq_next, |
| 2622 | .stop = igmp_mcf_seq_stop, |
| 2623 | .show = igmp_mcf_seq_show, |
| 2624 | }; |
| 2625 | |
| 2626 | static int igmp_mcf_seq_open(struct inode *inode, struct file *file) |
| 2627 | { |
Alexey Dobriyan | 7091e72 | 2008-12-25 16:42:51 -0800 | [diff] [blame] | 2628 | return seq_open_net(inode, file, &igmp_mcf_seq_ops, |
Pavel Emelyanov | cf7732e | 2007-10-10 02:29:29 -0700 | [diff] [blame] | 2629 | sizeof(struct igmp_mcf_iter_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 2632 | static const struct file_operations igmp_mcf_seq_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | .owner = THIS_MODULE, |
| 2634 | .open = igmp_mcf_seq_open, |
| 2635 | .read = seq_read, |
| 2636 | .llseek = seq_lseek, |
Alexey Dobriyan | 7091e72 | 2008-12-25 16:42:51 -0800 | [diff] [blame] | 2637 | .release = seq_release_net, |
| 2638 | }; |
| 2639 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 2640 | static int __net_init igmp_net_init(struct net *net) |
Alexey Dobriyan | 7091e72 | 2008-12-25 16:42:51 -0800 | [diff] [blame] | 2641 | { |
| 2642 | struct proc_dir_entry *pde; |
| 2643 | |
| 2644 | pde = proc_net_fops_create(net, "igmp", S_IRUGO, &igmp_mc_seq_fops); |
| 2645 | if (!pde) |
| 2646 | goto out_igmp; |
| 2647 | pde = proc_net_fops_create(net, "mcfilter", S_IRUGO, &igmp_mcf_seq_fops); |
| 2648 | if (!pde) |
| 2649 | goto out_mcfilter; |
| 2650 | return 0; |
| 2651 | |
| 2652 | out_mcfilter: |
| 2653 | proc_net_remove(net, "igmp"); |
| 2654 | out_igmp: |
| 2655 | return -ENOMEM; |
| 2656 | } |
| 2657 | |
Alexey Dobriyan | 2c8c1e7 | 2010-01-17 03:35:32 +0000 | [diff] [blame] | 2658 | static void __net_exit igmp_net_exit(struct net *net) |
Alexey Dobriyan | 7091e72 | 2008-12-25 16:42:51 -0800 | [diff] [blame] | 2659 | { |
| 2660 | proc_net_remove(net, "mcfilter"); |
| 2661 | proc_net_remove(net, "igmp"); |
| 2662 | } |
| 2663 | |
| 2664 | static struct pernet_operations igmp_net_ops = { |
| 2665 | .init = igmp_net_init, |
| 2666 | .exit = igmp_net_exit, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | }; |
| 2668 | |
| 2669 | int __init igmp_mc_proc_init(void) |
| 2670 | { |
Alexey Dobriyan | 7091e72 | 2008-12-25 16:42:51 -0800 | [diff] [blame] | 2671 | return register_pernet_subsys(&igmp_net_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | } |
| 2673 | #endif |