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