cregit-Linux how code gets into the kernel

Release 4.11 net/ipv6/mcast.c

Directory: net/ipv6
/*
 *      Multicast support for IPv6
 *      Linux INET6 implementation
 *
 *      Authors:
 *      Pedro Roque             <roque@di.fc.ul.pt>
 *
 *      Based on linux/ipv4/igmp.c and linux/ipv4/ip_sockglue.c
 *
 *      This program is free software; you can redistribute it and/or
 *      modify it under the terms of the GNU General Public License
 *      as published by the Free Software Foundation; either version
 *      2 of the License, or (at your option) any later version.
 */

/* Changes:
 *
 *      yoshfuji        : fix format of router-alert option
 *      YOSHIFUJI Hideaki @USAGI:
 *              Fixed source address for MLD message based on
 *              <draft-ietf-magma-mld-source-05.txt>.
 *      YOSHIFUJI Hideaki @USAGI:
 *              - Ignore Queries for invalid addresses.
 *              - MLD for link-local addresses.
 *      David L Stevens <dlstevens@us.ibm.com>:
 *              - MLDv2 support
 */

#include <linux/module.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/socket.h>
#include <linux/sockios.h>
#include <linux/jiffies.h>
#include <linux/times.h>
#include <linux/net.h>
#include <linux/in.h>
#include <linux/in6.h>
#include <linux/netdevice.h>
#include <linux/if_arp.h>
#include <linux/route.h>
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
#include <linux/pkt_sched.h>
#include <net/mld.h>

#include <linux/netfilter.h>
#include <linux/netfilter_ipv6.h>

#include <net/net_namespace.h>
#include <net/sock.h>
#include <net/snmp.h>

#include <net/ipv6.h>
#include <net/protocol.h>
#include <net/if_inet6.h>
#include <net/ndisc.h>
#include <net/addrconf.h>
#include <net/ip6_route.h>
#include <net/inet_common.h>

#include <net/ip6_checksum.h>

/* Ensure that we have struct in6_addr aligned on 32bit word. */

static void *__mld2_query_bugs[] __attribute__((__unused__)) = {
	BUILD_BUG_ON_NULL(offsetof(struct mld2_query, mld2q_srcs) % 4),
	BUILD_BUG_ON_NULL(offsetof(struct mld2_report, mld2r_grec) % 4),
	BUILD_BUG_ON_NULL(offsetof(struct mld2_grec, grec_mca) % 4)
};


static struct in6_addr mld2_all_mcr = MLD2_ALL_MCR_INIT;

static void igmp6_join_group(struct ifmcaddr6 *ma);
static void igmp6_leave_group(struct ifmcaddr6 *ma);
static void igmp6_timer_handler(unsigned long data);

static void mld_gq_timer_expire(unsigned long data);
static void mld_ifc_timer_expire(unsigned long data);
static void mld_ifc_event(struct inet6_dev *idev);
static void mld_add_delrec(struct inet6_dev *idev, struct ifmcaddr6 *pmc);
static void mld_del_delrec(struct inet6_dev *idev, struct ifmcaddr6 *pmc);
static void mld_clear_delrec(struct inet6_dev *idev);
static bool mld_in_v1_mode(const struct inet6_dev *idev);
static int sf_setstate(struct ifmcaddr6 *pmc);
static void sf_markstate(struct ifmcaddr6 *pmc);
static void ip6_mc_clear_src(struct ifmcaddr6 *pmc);
static int ip6_mc_del_src(struct inet6_dev *idev, const struct in6_addr *pmca,
			  int sfmode, int sfcount, const struct in6_addr *psfsrc,
			  int delta);
static int ip6_mc_add_src(struct inet6_dev *idev, const struct in6_addr *pmca,
			  int sfmode, int sfcount, const struct in6_addr *psfsrc,
			  int delta);
static int ip6_mc_leave_src(struct sock *sk, struct ipv6_mc_socklist *iml,
			    struct inet6_dev *idev);


#define MLD_QRV_DEFAULT		2
/* RFC3810, 9.2. Query Interval */

#define MLD_QI_DEFAULT		(125 * HZ)
/* RFC3810, 9.3. Query Response Interval */

#define MLD_QRI_DEFAULT		(10 * HZ)

/* RFC3810, 8.1 Query Version Distinctions */

#define MLD_V1_QUERY_LEN	24

#define MLD_V2_QUERY_LEN_MIN	28


#define IPV6_MLD_MAX_MSF	64


int sysctl_mld_max_msf __read_mostly = IPV6_MLD_MAX_MSF;

int sysctl_mld_qrv __read_mostly = MLD_QRV_DEFAULT;

/*
 *      socket join on multicast group
 */


#define for_each_pmc_rcu(np, pmc)				\
	for (pmc = rcu_dereference(np->ipv6_mc_list);           \
             pmc != NULL;                                       \
             pmc = rcu_dereference(pmc->next))


static int unsolicited_report_interval(struct inet6_dev *idev) { int iv; if (mld_in_v1_mode(idev)) iv = idev->cnf.mldv1_unsolicited_report_interval; else iv = idev->cnf.mldv2_unsolicited_report_interval; return iv > 0 ? iv : 1; }

Contributors

PersonTokensPropCommitsCommitProp
Hannes Frederic Sowa4697.87%150.00%
Daniel Borkmann12.13%150.00%
Total47100.00%2100.00%


int ipv6_sock_mc_join(struct sock *sk, int ifindex, const struct in6_addr *addr) { struct net_device *dev = NULL; struct ipv6_mc_socklist *mc_lst; struct ipv6_pinfo *np = inet6_sk(sk); struct net *net = sock_net(sk); int err; ASSERT_RTNL(); if (!ipv6_addr_is_multicast(addr)) return -EINVAL; rcu_read_lock(); for_each_pmc_rcu(np, mc_lst) { if ((ifindex == 0 || mc_lst->ifindex == ifindex) && ipv6_addr_equal(&mc_lst->addr, addr)) { rcu_read_unlock(); return -EADDRINUSE; } } rcu_read_unlock(); mc_lst = sock_kmalloc(sk, sizeof(struct ipv6_mc_socklist), GFP_KERNEL); if (!mc_lst) return -ENOMEM; mc_lst->next = NULL; mc_lst->addr = *addr; if (ifindex == 0) { struct rt6_info *rt; rt = rt6_lookup(net, addr, NULL, 0, 0); if (rt) { dev = rt->dst.dev; ip6_rt_put(rt); } } else dev = __dev_get_by_index(net, ifindex); if (!dev) { sock_kfree_s(sk, mc_lst, sizeof(*mc_lst)); return -ENODEV; } mc_lst->ifindex = dev->ifindex; mc_lst->sfmode = MCAST_EXCLUDE; rwlock_init(&mc_lst->sflock); mc_lst->sflist = NULL; /* * now add/increase the group membership on the device */ err = ipv6_dev_mc_inc(dev, addr); if (err) { sock_kfree_s(sk, mc_lst, sizeof(*mc_lst)); return err; } mc_lst->next = np->ipv6_mc_list; rcu_assign_pointer(np->ipv6_mc_list, mc_lst); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)16050.96%416.67%
David L Stevens9329.62%312.50%
Eric Dumazet154.78%14.17%
Daniel Lezcano103.18%28.33%
Hideaki Yoshifuji / 吉藤英明92.87%416.67%
Linus Torvalds82.55%14.17%
Madhu Challa72.23%14.17%
David S. Miller30.96%14.17%
Alexey Dobriyan20.64%14.17%
Ian Morris20.64%14.17%
Américo Wang20.64%28.33%
Eric W. Biedermann10.32%14.17%
Al Viro10.32%14.17%
Marcelo Ricardo Leitner10.32%14.17%
Total314100.00%24100.00%

EXPORT_SYMBOL(ipv6_sock_mc_join); /* * socket leave on multicast group */
int ipv6_sock_mc_drop(struct sock *sk, int ifindex, const struct in6_addr *addr) { struct ipv6_pinfo *np = inet6_sk(sk); struct ipv6_mc_socklist *mc_lst; struct ipv6_mc_socklist __rcu **lnk; struct net *net = sock_net(sk); ASSERT_RTNL(); if (!ipv6_addr_is_multicast(addr)) return -EINVAL; for (lnk = &np->ipv6_mc_list; (mc_lst = rtnl_dereference(*lnk)) != NULL; lnk = &mc_lst->next) { if ((ifindex == 0 || mc_lst->ifindex == ifindex) && ipv6_addr_equal(&mc_lst->addr, addr)) { struct net_device *dev; *lnk = mc_lst->next; dev = __dev_get_by_index(net, mc_lst->ifindex); if (dev) { struct inet6_dev *idev = __in6_dev_get(dev); (void) ip6_mc_leave_src(sk, mc_lst, idev); if (idev) __ipv6_dev_mc_dec(idev, &mc_lst->addr); } else (void) ip6_mc_leave_src(sk, mc_lst, NULL); atomic_sub(sizeof(*mc_lst), &sk->sk_omem_alloc); kfree_rcu(mc_lst, rcu); return 0; } } return -EADDRNOTAVAIL; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)11550.44%625.00%
David L Stevens4017.54%28.33%
Eric Dumazet187.89%28.33%
Daniel Lezcano125.26%14.17%
Li Wei125.26%14.17%
Madhu Challa83.51%14.17%
Alexey Kuznetsov83.51%14.17%
Hideaki Yoshifuji / 吉藤英明62.63%416.67%
David S. Miller31.32%14.17%
Américo Wang20.88%28.33%
Lai Jiangshan20.88%14.17%
Marcelo Ricardo Leitner10.44%14.17%
Eric W. Biedermann10.44%14.17%
Total228100.00%24100.00%

EXPORT_SYMBOL(ipv6_sock_mc_drop); /* called with rcu_read_lock() */
static struct inet6_dev *ip6_mc_find_dev_rcu(struct net *net, const struct in6_addr *group, int ifindex) { struct net_device *dev = NULL; struct inet6_dev *idev = NULL; if (ifindex == 0) { struct rt6_info *rt = rt6_lookup(net, group, NULL, 0, 0); if (rt) { dev = rt->dst.dev; ip6_rt_put(rt); } } else dev = dev_get_by_index_rcu(net, ifindex); if (!dev) return NULL; idev = __in6_dev_get(dev); if (!idev) return NULL; read_lock_bh(&idev->lock); if (idev->dead) { read_unlock_bh(&idev->lock); return NULL; } return idev; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens6746.53%16.67%
Linus Torvalds (pre-git)4329.86%533.33%
Eric Dumazet1711.81%213.33%
Daniel Lezcano85.56%213.33%
Al Viro32.08%16.67%
David S. Miller32.08%16.67%
Américo Wang10.69%16.67%
Eric W. Biedermann10.69%16.67%
Adrian Bunk10.69%16.67%
Total144100.00%15100.00%


void __ipv6_sock_mc_close(struct sock *sk) { struct ipv6_pinfo *np = inet6_sk(sk); struct ipv6_mc_socklist *mc_lst; struct net *net = sock_net(sk); ASSERT_RTNL(); while ((mc_lst = rtnl_dereference(np->ipv6_mc_list)) != NULL) { struct net_device *dev; np->ipv6_mc_list = mc_lst->next; dev = __dev_get_by_index(net, mc_lst->ifindex); if (dev) { struct inet6_dev *idev = __in6_dev_get(dev); (void) ip6_mc_leave_src(sk, mc_lst, idev); if (idev) __ipv6_dev_mc_dec(idev, &mc_lst->addr); } else (void) ip6_mc_leave_src(sk, mc_lst, NULL); atomic_sub(sizeof(*mc_lst), &sk->sk_omem_alloc); kfree_rcu(mc_lst, rcu); } }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens7850.32%212.50%
Linus Torvalds (pre-git)3019.35%212.50%
Eric Dumazet149.03%212.50%
David S. Miller117.10%16.25%
Daniel Lezcano85.16%16.25%
Américo Wang53.23%318.75%
Hideaki Yoshifuji / 吉藤英明42.58%212.50%
Lai Jiangshan21.29%16.25%
Sabrina Dubroca21.29%16.25%
Eric W. Biedermann10.65%16.25%
Total155100.00%16100.00%


void ipv6_sock_mc_close(struct sock *sk) { struct ipv6_pinfo *np = inet6_sk(sk); if (!rcu_access_pointer(np->ipv6_mc_list)) return; rtnl_lock(); __ipv6_sock_mc_close(sk); rtnl_unlock(); }

Contributors

PersonTokensPropCommitsCommitProp
Américo Wang3890.48%133.33%
Sabrina Dubroca37.14%133.33%
Linus Torvalds (pre-git)12.38%133.33%
Total42100.00%3100.00%


int ip6_mc_source(int add, int omode, struct sock *sk, struct group_source_req *pgsr) { struct in6_addr *source, *group; struct ipv6_mc_socklist *pmc; struct inet6_dev *idev; struct ipv6_pinfo *inet6 = inet6_sk(sk); struct ip6_sf_socklist *psl; struct net *net = sock_net(sk); int i, j, rv; int leavegroup = 0; int pmclocked = 0; int err; source = &((struct sockaddr_in6 *)&pgsr->gsr_source)->sin6_addr; group = &((struct sockaddr_in6 *)&pgsr->gsr_group)->sin6_addr; if (!ipv6_addr_is_multicast(group)) return -EINVAL; rcu_read_lock(); idev = ip6_mc_find_dev_rcu(net, group, pgsr->gsr_interface); if (!idev) { rcu_read_unlock(); return -ENODEV; } err = -EADDRNOTAVAIL; for_each_pmc_rcu(inet6, pmc) { if (pgsr->gsr_interface && pmc->ifindex != pgsr->gsr_interface) continue; if (ipv6_addr_equal(&pmc->addr, group)) break; } if (!pmc) { /* must have a prior join */ err = -EINVAL; goto done; } /* if a source filter was set, must be the same mode as before */ if (pmc->sflist) { if (pmc->sfmode != omode) { err = -EINVAL; goto done; } } else if (pmc->sfmode != omode) { /* allow mode switches for empty-set filters */ ip6_mc_add_src(idev, group, omode, 0, NULL, 0); ip6_mc_del_src(idev, group, pmc->sfmode, 0, NULL, 0); pmc->sfmode = omode; } write_lock(&pmc->sflock); pmclocked = 1; psl = pmc->sflist; if (!add) { if (!psl) goto done; /* err = -EADDRNOTAVAIL */ rv = !0; for (i = 0; i < psl->sl_count; i++) { rv = !ipv6_addr_equal(&psl->sl_addr[i], source); if (rv == 0) break; } if (rv) /* source not found */ goto done; /* err = -EADDRNOTAVAIL */ /* special case - (INCLUDE, empty) == LEAVE_GROUP */ if (psl->sl_count == 1 && omode == MCAST_INCLUDE) { leavegroup = 1; goto done; } /* update the interface filter */ ip6_mc_del_src(idev, group, omode, 1, source, 1); for (j = i+1; j < psl->sl_count; j++) psl->sl_addr[j-1] = psl->sl_addr[j]; psl->sl_count--; err = 0; goto done; } /* else, add a new source to the filter */ if (psl && psl->sl_count >= sysctl_mld_max_msf) { err = -ENOBUFS; goto done; } if (!psl || psl->sl_count == psl->sl_max) { struct ip6_sf_socklist *newpsl; int count = IP6_SFBLOCK; if (psl) count += psl->sl_max; newpsl = sock_kmalloc(sk, IP6_SFLSIZE(count), GFP_ATOMIC); if (!newpsl) { err = -ENOBUFS; goto done; } newpsl->sl_max = count; newpsl->sl_count = count - IP6_SFBLOCK; if (psl) { for (i = 0; i < psl->sl_count; i++) newpsl->sl_addr[i] = psl->sl_addr[i]; sock_kfree_s(sk, psl, IP6_SFLSIZE(psl->sl_max)); } pmc->sflist = psl = newpsl; } rv = 1; /* > 0 for insert logic below if sl_count is 0 */ for (i = 0; i < psl->sl_count; i++) { rv = !ipv6_addr_equal(&psl->sl_addr[i], source); if (rv == 0) /* There is an error in the address. */ goto done; } for (j = psl->sl_count-1; j >= i; j--) psl->sl_addr[j+1] = psl->sl_addr[j]; psl->sl_addr[i] = *source; psl->sl_count++; err = 0; /* update the interface list */ ip6_mc_add_src(idev, group, omode, 1, source, 1); done: if (pmclocked) write_unlock(&pmc->sflock); read_unlock_bh(&idev->lock); rcu_read_unlock(); if (leavegroup) err = ipv6_sock_mc_drop(sk, pgsr->gsr_interface, group); return err; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens58174.30%726.92%
Linus Torvalds (pre-git)14718.80%726.92%
Eric Dumazet172.17%27.69%
Chris Wright101.28%13.85%
Daniel Lezcano91.15%13.85%
Hideaki Yoshifuji / 吉藤英明91.15%415.38%
Marcelo Ricardo Leitner30.38%13.85%
Al Viro20.26%13.85%
Andrew Morton20.26%13.85%
Jean Sacren20.26%13.85%
Total782100.00%26100.00%


int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf) { const struct in6_addr *group; struct ipv6_mc_socklist *pmc; struct inet6_dev *idev; struct ipv6_pinfo *inet6 = inet6_sk(sk); struct ip6_sf_socklist *newpsl, *psl; struct net *net = sock_net(sk); int leavegroup = 0; int i, err; group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr; if (!ipv6_addr_is_multicast(group)) return -EINVAL; if (gsf->gf_fmode != MCAST_INCLUDE && gsf->gf_fmode != MCAST_EXCLUDE) return -EINVAL; rcu_read_lock(); idev = ip6_mc_find_dev_rcu(net, group, gsf->gf_interface); if (!idev) { rcu_read_unlock(); return -ENODEV; } err = 0; if (gsf->gf_fmode == MCAST_INCLUDE && gsf->gf_numsrc == 0) { leavegroup = 1; goto done; } for_each_pmc_rcu(inet6, pmc) { if (pmc->ifindex != gsf->gf_interface) continue; if (ipv6_addr_equal(&pmc->addr, group)) break; } if (!pmc) { /* must have a prior join */ err = -EINVAL; goto done; } if (gsf->gf_numsrc) { newpsl = sock_kmalloc(sk, IP6_SFLSIZE(gsf->gf_numsrc), GFP_ATOMIC); if (!newpsl) { err = -ENOBUFS; goto done; } newpsl->sl_max = newpsl->sl_count = gsf->gf_numsrc; for (i = 0; i < newpsl->sl_count; ++i) { struct sockaddr_in6 *psin6; psin6 = (struct sockaddr_in6 *)&gsf->gf_slist[i]; newpsl->sl_addr[i] = psin6->sin6_addr; } err = ip6_mc_add_src(idev, group, gsf->gf_fmode, newpsl->sl_count, newpsl->sl_addr, 0); if (err) { sock_kfree_s(sk, newpsl, IP6_SFLSIZE(newpsl->sl_max)); goto done; } } else { newpsl = NULL; (void) ip6_mc_add_src(idev, group, gsf->gf_fmode, 0, NULL, 0); } write_lock(&pmc->sflock); psl = pmc->sflist; if (psl) { (void) ip6_mc_del_src(idev, group, pmc->sfmode, psl->sl_count, psl->sl_addr, 0); sock_kfree_s(sk, psl, IP6_SFLSIZE(psl->sl_max)); } else (void) ip6_mc_del_src(idev, group, pmc->sfmode, 0, NULL, 0); pmc->sflist = newpsl; pmc->sfmode = gsf->gf_fmode; write_unlock(&pmc->sflock); err = 0; done: read_unlock_bh(&idev->lock); rcu_read_unlock(); if (leavegroup) err = ipv6_sock_mc_drop(sk, gsf->gf_interface, group); return err; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens39374.01%421.05%
Linus Torvalds (pre-git)7614.31%526.32%
Yan Zheng224.14%15.26%
Eric Dumazet203.77%315.79%
Daniel Lezcano91.69%15.26%
Hideaki Yoshifuji / 吉藤英明50.94%315.79%
David S. Miller40.75%15.26%
Al Viro20.38%15.26%
Total531100.00%19100.00%


int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf, struct group_filter __user *optval, int __user *optlen) { int err, i, count, copycount; const struct in6_addr *group; struct ipv6_mc_socklist *pmc; struct inet6_dev *idev; struct ipv6_pinfo *inet6 = inet6_sk(sk); struct ip6_sf_socklist *psl; struct net *net = sock_net(sk); group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr; if (!ipv6_addr_is_multicast(group)) return -EINVAL; rcu_read_lock(); idev = ip6_mc_find_dev_rcu(net, group, gsf->gf_interface); if (!idev) { rcu_read_unlock(); return -ENODEV; } err = -EADDRNOTAVAIL; /* changes to the ipv6_mc_list require the socket lock and * rtnl lock. We have the socket lock and rcu read lock, * so reading the list is safe. */ for_each_pmc_rcu(inet6, pmc) { if (pmc->ifindex != gsf->gf_interface) continue; if (ipv6_addr_equal(group, &pmc->addr)) break; } if (!pmc) /* must have a prior join */ goto done; gsf->gf_fmode = pmc->sfmode; psl = pmc->sflist; count = psl ? psl->sl_count : 0; read_unlock_bh(&idev->lock); rcu_read_unlock(); copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc; gsf->gf_numsrc = count; if (put_user(GROUP_FILTER_SIZE(copycount), optlen) || copy_to_user(optval, gsf, GROUP_FILTER_SIZE(0))) { return -EFAULT; } /* changes to psl require the socket lock, and a write lock * on pmc->sflock. We have the socket lock so reading here is safe. */ for (i = 0; i < copycount; i++) { struct sockaddr_in6 *psin6; struct sockaddr_storage ss; psin6 = (struct sockaddr_in6 *)&ss; memset(&ss, 0, sizeof(ss)); psin6->sin6_family = AF_INET6; psin6->sin6_addr = psl->sl_addr[i]; if (copy_to_user(&optval->gf_slist[i], &ss, sizeof(ss))) return -EFAULT; } return 0; done: read_unlock_bh(&idev->lock); rcu_read_unlock(); return err; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens25968.88%16.25%
Linus Torvalds (pre-git)7921.01%637.50%
Eric Dumazet205.32%318.75%
Daniel Lezcano92.39%16.25%
Hideaki Yoshifuji / 吉藤英明51.33%318.75%
Al Viro20.53%16.25%
Américo Wang20.53%16.25%
Total376100.00%16100.00%


bool inet6_mc_check(struct sock *sk, const struct in6_addr *mc_addr, const struct in6_addr *src_addr) { struct ipv6_pinfo *np = inet6_sk(sk); struct ipv6_mc_socklist *mc; struct ip6_sf_socklist *psl; bool rv = true; rcu_read_lock(); for_each_pmc_rcu(np, mc) { if (ipv6_addr_equal(&mc->addr, mc_addr)) break; } if (!mc) { rcu_read_unlock(); return true; } read_lock(&mc->sflock); psl = mc->sflist; if (!psl) { rv = mc->sfmode == MCAST_EXCLUDE; } else { int i; for (i = 0; i < psl->sl_count; i++) { if (ipv6_addr_equal(&psl->sl_addr[i], src_addr)) break; } if (mc->sfmode == MCAST_INCLUDE && i >= psl->sl_count) rv = false; if (mc->sfmode == MCAST_EXCLUDE && i < psl->sl_count) rv = false; } read_unlock(&mc->sflock); rcu_read_unlock(); return rv; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens12059.41%323.08%
Linus Torvalds (pre-git)5426.73%430.77%
Eric Dumazet178.42%215.38%
Hideaki Yoshifuji / 吉藤英明62.97%323.08%
Linus Torvalds52.48%17.69%
Total202100.00%13100.00%


static void igmp6_group_added(struct ifmcaddr6 *mc) { struct net_device *dev = mc->idev->dev; char buf[MAX_ADDR_LEN]; if (IPV6_ADDR_MC_SCOPE(&mc->mca_addr) < IPV6_ADDR_SCOPE_LINKLOCAL) return; spin_lock_bh(&mc->mca_lock); if (!(mc->mca_flags&MAF_LOADED)) { mc->mca_flags |= MAF_LOADED; if (ndisc_mc_map(&mc->mca_addr, buf, dev, 0) == 0) dev_mc_add(dev, buf); } spin_unlock_bh(&mc->mca_lock); if (!(dev->flags & IFF_UP) || (mc->mca_flags & MAF_NOREPORT)) return; if (mld_in_v1_mode(mc->idev)) { igmp6_join_group(mc); return; } /* else v2 */ mc->mca_crcount = mc->idev->mc_qrv; mld_ifc_event(mc->idev); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens8655.13%110.00%
Linus Torvalds (pre-git)5333.97%550.00%
Hideaki Yoshifuji / 吉藤英明148.97%220.00%
Linus Torvalds21.28%110.00%
Daniel Borkmann10.64%110.00%
Total156100.00%10100.00%


static void igmp6_group_dropped(struct ifmcaddr6 *mc) { struct net_device *dev = mc->idev->dev; char buf[MAX_ADDR_LEN]; if (IPV6_ADDR_MC_SCOPE(&mc->mca_addr) < IPV6_ADDR_SCOPE_LINKLOCAL) return; spin_lock_bh(&mc->mca_lock); if (mc->mca_flags&MAF_LOADED) { mc->mca_flags &= ~MAF_LOADED; if (ndisc_mc_map(&mc->mca_addr, buf, dev, 0) == 0) dev_mc_del(dev, buf); } spin_unlock_bh(&mc->mca_lock); if (mc->mca_flags & MAF_NOREPORT) return; if (!mc->idev->dead) igmp6_leave_group(mc); spin_lock_bh(&mc->mca_lock); if (del_timer(&mc->mca_timer)) atomic_dec(&mc->mca_refcnt); spin_unlock_bh(&mc->mca_lock); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens8151.92%216.67%
Linus Torvalds (pre-git)4528.85%433.33%
Hideaki Yoshifuji / 吉藤英明148.97%216.67%
Hangbin Liu95.77%18.33%
Krishna Kumar53.21%18.33%
Jiri Pirko10.64%18.33%
Stephen Rothwell10.64%18.33%
Total156100.00%12100.00%

/* * deleted ifmcaddr6 manipulation */
static void mld_add_delrec(struct inet6_dev *idev, struct ifmcaddr6 *im) { struct ifmcaddr6 *pmc; /* this is an "ifmcaddr6" for convenience; only the fields below * are actually used. In particular, the refcnt and users are not * used for management of the delete list. Using the same structure * for deleted items allows change reports to use common code with * non-deleted or query-response MCA's. */ pmc = kzalloc(sizeof(*pmc), GFP_ATOMIC); if (!pmc) return; spin_lock_bh(&im->mca_lock); spin_lock_init(&pmc->mca_lock); pmc->idev = im->idev; in6_dev_hold(idev); pmc->mca_addr = im->mca_addr; pmc->mca_crcount = idev->mc_qrv; pmc->mca_sfmode = im->mca_sfmode; if (pmc->mca_sfmode == MCAST_INCLUDE) { struct ip6_sf_list *psf; pmc->mca_tomb = im->mca_tomb; pmc->mca_sources = im->mca_sources; im->mca_tomb = im->mca_sources = NULL; for (psf = pmc->mca_sources; psf; psf = psf->sf_next) psf->sf_crcount = pmc->mca_crcount; } spin_unlock_bh(&im->mca_lock); spin_lock_bh(&idev->mc_lock); pmc->next = idev->mc_tomb; idev->mc_tomb = pmc; spin_unlock_bh(&idev->mc_lock); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens15679.19%111.11%
Linus Torvalds (pre-git)3316.75%444.44%
Andrew Morton42.03%111.11%
Stephen Hemminger21.02%111.11%
Al Viro10.51%111.11%
Ingo Oeser10.51%111.11%
Total197100.00%9100.00%


static void mld_del_delrec(struct inet6_dev *idev, struct ifmcaddr6 *im) { struct ifmcaddr6 *pmc, *pmc_prev; struct ip6_sf_list *psf; struct in6_addr *pmca = &im->mca_addr; spin_lock_bh(&idev->mc_lock); pmc_prev = NULL; for (pmc = idev->mc_tomb; pmc; pmc = pmc->next) { if (ipv6_addr_equal(&pmc->mca_addr, pmca)) break; pmc_prev = pmc; } if (pmc) { if (pmc_prev) pmc_prev->next = pmc->next; else idev->mc_tomb = pmc->next; } spin_unlock_bh(&idev->mc_lock); spin_lock_bh(&im->mca_lock); if (pmc) { im->idev = pmc->idev; im->mca_crcount = idev->mc_qrv; im->mca_sfmode = pmc->mca_sfmode; if (pmc->mca_sfmode == MCAST_INCLUDE) { im->mca_tomb = pmc->mca_tomb; im->mca_sources = pmc->mca_sources; for (psf = im->mca_sources; psf; psf = psf->sf_next) psf->sf_crcount = im->mca_crcount; } in6_dev_put(pmc->idev); kfree(pmc); } spin_unlock_bh(&im->mca_lock); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens9340.61%110.00%
Hangbin Liu8838.43%220.00%
Linus Torvalds (pre-git)4419.21%440.00%
Stephen Hemminger20.87%110.00%
Hideaki Yoshifuji / 吉藤英明10.44%110.00%
Al Viro10.44%110.00%
Total229100.00%10100.00%


static void mld_clear_delrec(struct inet6_dev *idev) { struct ifmcaddr6 *pmc, *nextpmc; spin_lock_bh(&idev->mc_lock); pmc = idev->mc_tomb; idev->mc_tomb = NULL; spin_unlock_bh(&idev->mc_lock); for (; pmc; pmc = nextpmc) { nextpmc = pmc->next; ip6_mc_clear_src(pmc); in6_dev_put(pmc->idev); kfree(pmc); } /* clear dead sources, too */ read_lock_bh(&idev->lock); for (pmc = idev->mc_list; pmc; pmc = pmc->next) { struct ip6_sf_list *psf, *psf_next; spin_lock_bh(&pmc->mca_lock); psf = pmc->mca_tomb; pmc->mca_tomb = NULL; spin_unlock_bh(&pmc->mca_lock); for (; psf; psf = psf_next) { psf_next = psf->sf_next; kfree(psf); } } read_unlock_bh(&idev->lock); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens14784.48%116.67%
Linus Torvalds (pre-git)2011.49%233.33%
Hideaki Yoshifuji / 吉藤英明31.72%116.67%
Stephen Hemminger21.15%116.67%
Al Viro21.15%116.67%
Total174100.00%6100.00%


static void mca_get(struct ifmcaddr6 *mc) { atomic_inc(&mc->mca_refcnt); }

Contributors

PersonTokensPropCommitsCommitProp
Américo Wang19100.00%1100.00%
Total19100.00%1100.00%


static void ma_put(struct ifmcaddr6 *mc) { if (atomic_dec_and_test(&mc->mca_refcnt)) { in6_dev_put(mc->idev); kfree(mc); } }

Contributors

PersonTokensPropCommitsCommitProp
Américo Wang35100.00%1100.00%
Total35100.00%1100.00%


static struct ifmcaddr6 *mca_alloc(struct inet6_dev *idev, const struct in6_addr *addr) { struct ifmcaddr6 *mc; mc = kzalloc(sizeof(*mc), GFP_ATOMIC); if (!mc) return NULL; setup_timer(&mc->mca_timer, igmp6_timer_handler, (unsigned long)mc); mc->mca_addr = *addr; mc->idev = idev; /* reference taken by caller */ mc->mca_users = 1; /* mca_stamp should be updated upon changes */ mc->mca_cstamp = mc->mca_tstamp = jiffies; atomic_set(&mc->mca_refcnt, 1); spin_lock_init(&mc->mca_lock); /* initial mode is (EX, empty) */ mc->mca_sfmode = MCAST_EXCLUDE; mc->mca_sfcount[MCAST_EXCLUDE] = 1; if (ipv6_addr_is_ll_all_nodes(&mc->mca_addr) || IPV6_ADDR_MC_SCOPE(&mc->mca_addr) < IPV6_ADDR_SCOPE_LINKLOCAL) mc->mca_flags |= MAF_NOREPORT; return mc; }

Contributors

PersonTokensPropCommitsCommitProp
Américo Wang15499.35%150.00%
Ian Morris10.65%150.00%
Total155100.00%2100.00%

/* * device multicast group inc (add if not found) */
int ipv6_dev_mc_inc(struct net_device *dev, const struct in6_addr *addr) { struct ifmcaddr6 *mc; struct inet6_dev *idev; ASSERT_RTNL(); /* we need to take a reference on idev */ idev = in6_dev_get(dev); if (!idev) return -EINVAL; write_lock_bh(&idev->lock); if (idev->dead) { write_unlock_bh(&idev->lock); in6_dev_put(idev); return -ENODEV; } for (mc = idev->mc_list; mc; mc = mc->next) { if (ipv6_addr_equal(&mc->mca_addr, addr)) { mc->mca_users++; write_unlock_bh(&idev->lock); ip6_mc_add_src(idev, &mc->mca_addr, MCAST_EXCLUDE, 0, NULL, 0); in6_dev_put(idev); return 0; } } mc = mca_alloc(idev, addr); if (!mc) { write_unlock_bh(&idev->lock); in6_dev_put(idev); return -ENOMEM; } mc->next = idev->mc_list; idev->mc_list = mc; /* Hold this for the code below before we unlock, * it is already exposed via idev->mc_list. */ mca_get(mc); write_unlock_bh(&idev->lock); mld_del_delrec(idev, mc); igmp6_group_added(mc); ma_put(mc); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens21392.21%112.50%
Américo Wang104.33%112.50%
Sabrina Dubroca31.30%112.50%
Hideaki Yoshifuji / 吉藤英明20.87%225.00%
Ian Morris10.43%112.50%
Eric Dumazet10.43%112.50%
Al Viro10.43%112.50%
Total231100.00%8100.00%

/* * device multicast group del */
int __ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr) { struct ifmcaddr6 *ma, **map; ASSERT_RTNL(); write_lock_bh(&idev->lock); for (map = &idev->mc_list; (ma = *map) != NULL; map = &ma->next) { if (ipv6_addr_equal(&ma->mca_addr, addr)) { if (--ma->mca_users == 0) { *map = ma->next; write_unlock_bh(&idev->lock); igmp6_group_dropped(ma); ip6_mc_clear_src(ma); ma_put(ma); return 0; } write_unlock_bh(&idev->lock); return 0; } } write_unlock_bh(&idev->lock); return -ENOENT; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens12385.42%116.67%
David S. Miller117.64%116.67%
Hangbin Liu53.47%116.67%
Sabrina Dubroca32.08%116.67%
Hideaki Yoshifuji / 吉藤英明21.39%233.33%
Total144100.00%6100.00%


int ipv6_dev_mc_dec(struct net_device *dev, const struct in6_addr *addr) { struct inet6_dev *idev; int err; ASSERT_RTNL(); idev = __in6_dev_get(dev); if (!idev) err = -ENODEV; else err = __ipv6_dev_mc_dec(idev, addr); return err; }

Contributors

PersonTokensPropCommitsCommitProp
David S. Miller3968.42%120.00%
Eric Dumazet1322.81%120.00%
David L Stevens35.26%120.00%
Américo Wang11.75%120.00%
Hideaki Yoshifuji / 吉藤英明11.75%120.00%
Total57100.00%5100.00%

/* * check if the interface/address pair is valid */
bool ipv6_chk_mcast_addr(struct net_device *dev, const struct in6_addr *group, const struct in6_addr *src_addr) { struct inet6_dev *idev; struct ifmcaddr6 *mc; bool rv = false; rcu_read_lock(); idev = __in6_dev_get(dev); if (idev) { read_lock_bh(&idev->lock); for (mc = idev->mc_list; mc; mc = mc->next) { if (ipv6_addr_equal(&mc->mca_addr, group)) break; } if (mc) { if (src_addr && !ipv6_addr_any(src_addr)) { struct ip6_sf_list *psf; spin_lock_bh(&mc->mca_lock); for (psf = mc->mca_sources; psf; psf = psf->sf_next) { if (ipv6_addr_equal(&psf->sf_addr, src_addr)) break; } if (psf) rv = psf->sf_count[MCAST_INCLUDE] || psf->sf_count[MCAST_EXCLUDE] != mc->mca_sfcount[MCAST_EXCLUDE]; else rv = mc->mca_sfcount[MCAST_EXCLUDE] != 0; spin_unlock_bh(&mc->mca_lock); } else rv = true; /* don't filter unspecified source */ } read_unlock_bh(&idev->lock); } rcu_read_unlock(); return rv; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens20693.21%342.86%
Eric Dumazet114.98%228.57%
Hideaki Yoshifuji / 吉藤英明41.81%228.57%
Total221100.00%7100.00%


static void mld_gq_start_timer(struct inet6_dev *idev) { unsigned long tv = prandom_u32() % idev->mc_maxdelay; idev->mc_gq_running = 1; if (!mod_timer(&idev->mc_gq_timer, jiffies+tv+2)) in6_dev_hold(idev); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens4692.00%125.00%
Daniel Borkmann24.00%125.00%
Aruna-Hewapathirane12.00%125.00%
Hideaki Yoshifuji / 吉藤英明12.00%125.00%
Total50100.00%4100.00%


static void mld_gq_stop_timer(struct inet6_dev *idev) { idev->mc_gq_running = 0; if (del_timer(&idev->mc_gq_timer)) __in6_dev_put(idev); }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Borkmann32100.00%1100.00%
Total32100.00%1100.00%


static void mld_ifc_start_timer(struct inet6_dev *idev, unsigned long delay) { unsigned long tv = prandom_u32() % delay; if (!mod_timer(&idev->mc_ifc_timer, jiffies+tv+2)) in6_dev_hold(idev); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens4086.96%125.00%
Daniel Borkmann48.70%125.00%
Hideaki Yoshifuji / 吉藤英明12.17%125.00%
Aruna-Hewapathirane12.17%125.00%
Total46100.00%4100.00%


static void mld_ifc_stop_timer(struct inet6_dev *idev) { idev->mc_ifc_count = 0; if (del_timer(&idev->mc_ifc_timer)) __in6_dev_put(idev); }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Borkmann32100.00%1100.00%
Total32100.00%1100.00%


static void mld_dad_start_timer(struct inet6_dev *idev, unsigned long delay) { unsigned long tv = prandom_u32() % delay; if (!mod_timer(&idev->mc_dad_timer, jiffies+tv+2)) in6_dev_hold(idev); }

Contributors

PersonTokensPropCommitsCommitProp
Hannes Frederic Sowa4189.13%133.33%
Daniel Borkmann48.70%133.33%
Aruna-Hewapathirane12.17%133.33%
Total46100.00%3100.00%


static void mld_dad_stop_timer(struct inet6_dev *idev) { if (del_timer(&idev->mc_dad_timer)) __in6_dev_put(idev); }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Borkmann26100.00%1100.00%
Total26100.00%1100.00%

/* * IGMP handling (alias multicast ICMPv6 messages) */
static void igmp6_group_queried(struct ifmcaddr6 *ma, unsigned long resptime) { unsigned long delay = resptime; /* Do not start timer for these addresses */ if (ipv6_addr_is_ll_all_nodes(&ma->mca_addr) || IPV6_ADDR_MC_SCOPE(&ma->mca_addr) < IPV6_ADDR_SCOPE_LINKLOCAL) return; if (del_timer(&ma->mca_timer)) { atomic_dec(&ma->mca_refcnt); delay = ma->mca_timer.expires - jiffies; } if (delay >= resptime) delay = prandom_u32() % resptime; ma->mca_timer.expires = jiffies + delay; if (!mod_timer(&ma->mca_timer, jiffies + delay)) atomic_inc(&ma->mca_refcnt); ma->mca_flags |= MAF_TIMER_RUNNING; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens12499.20%375.00%
Aruna-Hewapathirane10.80%125.00%
Total125100.00%4100.00%

/* mark EXCLUDE-mode sources */
static bool mld_xmarksources(struct ifmcaddr6 *pmc, int nsrcs, const struct in6_addr *srcs) { struct ip6_sf_list *psf; int i, scount; scount = 0; for (psf = pmc->mca_sources; psf; psf = psf->sf_next) { if (scount == nsrcs) break; for (i = 0; i < nsrcs; i++) { /* skip inactive filters */ if (psf->sf_count[MCAST_INCLUDE] || pmc->mca_sfcount[MCAST_EXCLUDE] != psf->sf_count[MCAST_EXCLUDE]) break; if (ipv6_addr_equal(&srcs[i], &psf->sf_addr)) { scount++; break; } } } pmc->mca_flags &= ~MAF_GSQUERY; if (scount == nsrcs) /* all sources excluded */ return false; return true; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens13495.04%120.00%
Eric Dumazet42.84%240.00%
Zheng Yan21.42%120.00%
Li RongQing10.71%120.00%
Total141100.00%5100.00%


static bool mld_marksources(struct ifmcaddr6 *pmc, int nsrcs, const struct in6_addr *srcs) { struct ip6_sf_list *psf; int i, scount; if (pmc->mca_sfmode == MCAST_EXCLUDE) return mld_xmarksources(pmc, nsrcs, srcs); /* mark INCLUDE-mode sources */ scount = 0; for (psf = pmc->mca_sources; psf; psf = psf->sf_next) { if (scount == nsrcs) break; for (i = 0; i < nsrcs; i++) { if (ipv6_addr_equal(&srcs[i], &psf->sf_addr)) { psf->sf_gsresp = 1; scount++; break; } } } if (!scount) { pmc->mca_flags &= ~MAF_GSQUERY; return false; } pmc->mca_flags |= MAF_GSQUERY; return true; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens14296.60%240.00%
Eric Dumazet42.72%240.00%
Hideaki Yoshifuji / 吉藤英明10.68%120.00%
Total147100.00%5100.00%


static int mld_force_mld_version(const struct inet6_dev *idev) { /* Normally, both are 0 here. If enforcement to a particular is * being used, individual device enforcement will have a lower * precedence over 'all' device (.../conf/all/force_mld_version). */ if (dev_net(idev->dev)->ipv6.devconf_all->force_mld_version != 0) return dev_net(idev->dev)->ipv6.devconf_all->force_mld_version; else return idev->cnf.force_mld_version; }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Borkmann52100.00%2100.00%
Total52100.00%2100.00%


static bool mld_in_v2_mode_only(const struct inet6_dev *idev) { return mld_force_mld_version(idev) == 2; }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Borkmann20100.00%1100.00%
Total20100.00%1100.00%


static bool mld_in_v1_mode_only(const struct inet6_dev *idev) { return mld_force_mld_version(idev) == 1; }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Borkmann20100.00%2100.00%
Total20100.00%2100.00%


static bool mld_in_v1_mode(const struct inet6_dev *idev) { if (mld_in_v2_mode_only(idev)) return false; if (mld_in_v1_mode_only(idev)) return true; if (idev->mc_v1_seen && time_before(jiffies, idev->mc_v1_seen)) return true; return false; }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Borkmann53100.00%2100.00%
Total53100.00%2100.00%


static void mld_set_v1_mode(struct inet6_dev *idev) { /* RFC3810, relevant sections: * - 9.1. Robustness Variable * - 9.2. Query Interval * - 9.3. Query Response Interval * - 9.12. Older Version Querier Present Timeout */ unsigned long switchback; switchback = (idev->mc_qrv * idev->mc_qi) + idev->mc_qri; idev->mc_v1_seen = jiffies + switchback; }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Borkmann40100.00%1100.00%
Total40100.00%1100.00%


static void mld_update_qrv(struct inet6_dev *idev, const struct mld2_query *mlh2) { /* RFC3810, relevant sections: * - 5.1.8. QRV (Querier's Robustness Variable) * - 9.1. Robustness Variable */ /* The value of the Robustness Variable MUST NOT be zero, * and SHOULD NOT be one. Catch this here if we ever run * into such a case in future. */ const int min_qrv = min(MLD_QRV_DEFAULT, sysctl_mld_qrv); WARN_ON(idev->mc_qrv == 0); if (mlh2->mld2q_qrv > 0) idev->mc_qrv = mlh2->mld2q_qrv; if (unlikely(idev->mc_qrv < min_qrv)) { net_warn_ratelimited("IPv6: MLD: clamping QRV from %u to %u!\n", idev->mc_qrv, min_qrv); idev->mc_qrv = min_qrv; } }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Borkmann7183.53%150.00%
Hannes Frederic Sowa1416.47%150.00%
Total85100.00%2100.00%


static void mld_update_qi(struct inet6_dev *idev, const struct mld2_query *mlh2) { /* RFC3810, relevant sections: * - 5.1.9. QQIC (Querier's Query Interval Code) * - 9.2. Query Interval * - 9.12. Older Version Querier Present Timeout * (the [Query Interval] in the last Query received) */ unsigned long mc_qqi; if (mlh2->mld2q_qqic < 128) { mc_qqi = mlh2->mld2q_qqic; } else { unsigned long mc_man, mc_exp; mc_exp = MLDV2_QQIC_EXP(mlh2->mld2q_qqic); mc_man = MLDV2_QQIC_MAN(mlh2->mld2q_qqic); mc_qqi = (mc_man | 0x10) << (mc_exp + 3); } idev->mc_qi = mc_qqi * HZ; }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Borkmann87100.00%1100.00%
Total87100.00%1100.00%


static void mld_update_qri(struct inet6_dev *idev, const struct mld2_query *mlh2) { /* RFC3810, relevant sections: * - 5.1.3. Maximum Response Code * - 9.3. Query Response Interval */ idev->mc_qri = msecs_to_jiffies(mldv2_mrc(mlh2)); }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Borkmann30100.00%2100.00%
Total30100.00%2100.00%


static int mld_process_v1(struct inet6_dev *idev, struct mld_msg *mld, unsigned long *max_delay, bool v1_query) { unsigned long mldv1_md; /* Ignore v1 queries */ if (mld_in_v2_mode_only(idev)) return -EINVAL; mldv1_md = ntohs(mld->mld_maxdelay); /* When in MLDv1 fallback and a MLDv2 router start-up being * unaware of current MLDv1 operation, the MRC == MRD mapping * only works when the exponential algorithm is not being * used (as MLDv1 is unaware of such things). * * According to the RFC author, the MLDv2 implementations * he's aware of all use a MRC < 32768 on start up queries. * * Thus, should we *ever* encounter something else larger * than that, just assume the maximum possible within our * reach. */ if (!v1_query) mldv1_md = min(mldv1_md, MLDV1_MRD_MAX_COMPAT); *max_delay = max(msecs_to_jiffies(mldv1_md), 1UL); /* MLDv1 router present: we need to go into v1 mode *only* * when an MLDv1 query is received as per section 9.12. of * RFC3810! And we know from RFC2710 section 3.7 that MLDv1 * queries MUST be of exactly 24 octets. */ if (v1_query) mld_set_v1_mode(idev); /* cancel MLDv2 report timer */ mld_gq_stop_timer(idev); /* cancel the interface change timer */ mld_ifc_stop_timer(idev); /* clear deleted report items */ mld_clear_delrec(idev); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Borkmann108100.00%3100.00%
Total108100.00%3100.00%


static int mld_process_v2(struct inet6_dev *idev, struct mld2_query *mld, unsigned long *max_delay) { *max_delay = max(msecs_to_jiffies(mldv2_mrc(mld)), 1UL); mld_update_qrv(idev, mld); mld_update_qi(idev, mld); mld_update_qri(idev, mld); idev->mc_maxdelay = *max_delay; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Borkmann68100.00%1100.00%
Total68100.00%1100.00%

/* called with rcu_read_lock() */
int igmp6_event_query(struct sk_buff *skb) { struct mld2_query *mlh2 = NULL; struct ifmcaddr6 *ma; const struct in6_addr *group; unsigned long max_delay; struct inet6_dev *idev; struct mld_msg *mld; int group_type; int mark = 0; int len, err; if (!pskb_may_pull(skb, sizeof(struct in6_addr))) return -EINVAL; /* compute payload length excluding extension headers */ len = ntohs(ipv6_hdr(skb)->payload_len) + sizeof(struct ipv6hdr); len -= skb_network_header_len(skb); /* RFC3810 6.2 * Upon reception of an MLD message that contains a Query, the node * checks if the source address of the message is a valid link-local * address, if the Hop Limit is set to 1, and if the Router Alert * option is present in the Hop-By-Hop Options header of the IPv6 * packet. If any of these checks fails, the packet is dropped. */ if (!(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL) || ipv6_hdr(skb)->hop_limit != 1 || !(IP6CB(skb)->flags & IP6SKB_ROUTERALERT) || IP6CB(skb)->ra != htons(IPV6_OPT_ROUTERALERT_MLD)) return -EINVAL; idev = __in6_dev_get(skb->dev); if (!idev) return 0; mld = (struct mld_msg *)icmp6_hdr(skb); group = &mld->mld_mca; group_type = ipv6_addr_type(group); if (group_type != IPV6_ADDR_ANY && !(group_type&IPV6_ADDR_MULTICAST)) return -EINVAL; if (len < MLD_V1_QUERY_LEN) { return -EINVAL; } else if (len == MLD_V1_QUERY_LEN || mld_in_v1_mode(idev)) { err = mld_process_v1(idev, mld, &max_delay, len == MLD_V1_QUERY_LEN); if (err < 0) return err; } else if (len >= MLD_V2_QUERY_LEN_MIN) { int srcs_offset = sizeof(struct mld2_query) - sizeof(struct icmp6hdr); if (!pskb_may_pull(skb, srcs_offset)) return -EINVAL; mlh2 = (struct mld2_query *)skb_transport_header(skb); err = mld_process_v2(idev, mlh2, &max_delay); if (err < 0) return err; if (group_type == IPV6_ADDR_ANY) { /* general query */ if (mlh2->mld2q_nsrcs) return -EINVAL; /* no sources allowed */ mld_gq_start_timer(idev); return 0; } /* mark sources to include, if group & source-specific */ if (mlh2->mld2q_nsrcs != 0) { if (!pskb_may_pull(skb, srcs_offset + ntohs(mlh2->mld2q_nsrcs) * sizeof(struct in6_addr))) return -EINVAL; mlh2 = (struct mld2_query *)skb_transport_header(skb); mark = 1; } } else { return -EINVAL; } read_lock_bh(&idev->lock); if (group_type == IPV6_ADDR_ANY) { for (ma = idev->mc_list; ma; ma = ma->next) { spin_lock_bh(&ma->mca_lock); igmp6_group_queried(ma, max_delay); spin_unlock_bh(&ma->mca_lock); } } else { for (ma = idev->mc_list; ma; ma = ma->next) { if (!ipv6_addr_equal(group, &ma->mca_addr)) continue; spin_lock_bh(&ma->mca_lock); if (ma->mca_flags & MAF_TIMER_RUNNING) { /* gsquery <- gsquery && mark */ if (!mark) ma->mca_flags &= ~MAF_GSQUERY; } else { /* gsquery <- mark */ if (mark) ma->mca_flags |= MAF_GSQUERY; else ma->mca_flags &= ~MAF_GSQUERY; } if (!(ma->mca_flags & MAF_GSQUERY) || mld_marksources(ma, ntohs(mlh2->mld2q_nsrcs), mlh2->mld2q_srcs)) igmp6_group_queried(ma, max_delay); spin_unlock_bh(&ma->mca_lock); break; } } read_unlock_bh(&idev->lock); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens41065.60%315.79%
Yan Zheng8012.80%15.26%
Daniel Borkmann609.60%526.32%
Hangbin Liu345.44%15.26%
Hideaki Yoshifuji / 吉藤英明203.20%210.53%
Arnaldo Carvalho de Melo182.88%421.05%
Eric Dumazet20.32%210.53%
Ian Morris10.16%15.26%
Total625100.00%19100.00%

/* called with rcu_read_lock() */
int igmp6_event_report(struct sk_buff *skb) { struct ifmcaddr6 *ma; struct inet6_dev *idev; struct mld_msg *mld; int addr_type; /* Our own report looped back. Ignore it. */ if (skb->pkt_type == PACKET_LOOPBACK) return 0; /* send our report if the MC router may not have heard this report */ if (skb->pkt_type != PACKET_MULTICAST && skb->pkt_type != PACKET_BROADCAST) return 0; if (!pskb_may_pull(skb, sizeof(*mld) - sizeof(struct icmp6hdr))) return -EINVAL; mld = (struct mld_msg *)icmp6_hdr(skb); /* Drop reports with not link local source */ addr_type = ipv6_addr_type(&ipv6_hdr(skb)->saddr); if (addr_type != IPV6_ADDR_ANY && !(addr_type&IPV6_ADDR_LINKLOCAL)) return -EINVAL; idev = __in6_dev_get(skb->dev); if (!idev) return -ENODEV; /* * Cancel the timer for this group */ read_lock_bh(&idev->lock); for (ma = idev->mc_list; ma; ma = ma->next) { if (ipv6_addr_equal(&ma->mca_addr, &mld->mld_mca)) { spin_lock(&ma->mca_lock); if (del_timer(&ma->mca_timer)) atomic_dec(&ma->mca_refcnt); ma->mca_flags &= ~(MAF_LAST_REPORTER|MAF_TIMER_RUNNING); spin_unlock(&ma->mca_lock); break; } } read_unlock_bh(&idev->lock); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens21688.52%225.00%
Hideaki Yoshifuji / 吉藤英明208.20%225.00%
Arnaldo Carvalho de Melo62.46%225.00%
Ian Morris10.41%112.50%
Eric Dumazet10.41%112.50%
Total244100.00%8100.00%


static bool is_in(struct ifmcaddr6 *pmc, struct ip6_sf_list *psf, int type, int gdeleted, int sdeleted) { switch (type) { case MLD2_MODE_IS_INCLUDE: case MLD2_MODE_IS_EXCLUDE: if (gdeleted || sdeleted) return false; if (!((pmc->mca_flags & MAF_GSQUERY) && !psf->sf_gsresp)) { if (pmc->mca_sfmode == MCAST_INCLUDE) return true; /* don't include if this source is excluded * in all filters */ if (psf->sf_count[MCAST_INCLUDE]) return type == MLD2_MODE_IS_INCLUDE; return pmc->mca_sfcount[MCAST_EXCLUDE] == psf->sf_count[MCAST_EXCLUDE]; } return false; case MLD2_CHANGE_TO_INCLUDE: if (gdeleted || sdeleted) return false; return psf->sf_count[MCAST_INCLUDE] != 0; case MLD2_CHANGE_TO_EXCLUDE: if (gdeleted || sdeleted) return false; if (pmc->mca_sfcount[MCAST_EXCLUDE] == 0 || psf->sf_count[MCAST_INCLUDE]) return false; return pmc->mca_sfcount[MCAST_EXCLUDE] == psf->sf_count[MCAST_EXCLUDE]; case MLD2_ALLOW_NEW_SOURCES: if (gdeleted || !psf->sf_crcount) return false; return (pmc->mca_sfmode == MCAST_INCLUDE) ^ sdeleted; case MLD2_BLOCK_OLD_SOURCES: if (pmc->mca_sfmode == MCAST_INCLUDE) return gdeleted || (psf->sf_crcount && sdeleted); return psf->sf_crcount && !gdeleted && !sdeleted; } return false; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens23396.28%375.00%
Eric Dumazet93.72%125.00%
Total242100.00%4100.00%


static int mld_scount(struct ifmcaddr6 *pmc, int type, int gdeleted, int sdeleted) { struct ip6_sf_list *psf; int scount = 0; for (psf = pmc->mca_sources; psf; psf = psf->sf_next) { if (!is_in(pmc, psf, type, gdeleted, sdeleted)) continue; scount++; } return scount; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens71100.00%1100.00%
Total71100.00%1100.00%


static void ip6_mc_hdr(struct sock *sk, struct sk_buff *skb, struct net_device *dev, const struct in6_addr *saddr, const struct in6_addr *daddr, int proto, int len) { struct ipv6hdr *hdr; skb->protocol = htons(ETH_P_IPV6); skb->dev = dev; skb_reset_network_header(skb); skb_put(skb, sizeof(struct ipv6hdr)); hdr = ipv6_hdr(skb); ip6_flow_hdr(hdr, 0, 0); hdr->payload_len = htons(len); hdr->nexthdr = proto; hdr->hop_limit = inet6_sk(sk)->hop_limit; hdr->saddr = *saddr; hdr->daddr = *daddr; }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明131100.00%1100.00%
Total131100.00%1100.00%


static struct sk_buff *mld_newpack(struct inet6_dev *idev, unsigned int mtu) { struct net_device *dev = idev->dev; struct net *net = dev_net(dev); struct sock *sk = net->ipv6.igmp_sk; struct sk_buff *skb; struct mld2_report *pmr; struct in6_addr addr_buf; const struct in6_addr *saddr; int hlen = LL_RESERVED_SPACE(dev); int tlen = dev->needed_tailroom; unsigned int size = mtu + hlen + tlen; int err; u8 ra[8] = { IPPROTO_ICMPV6, 0, IPV6_TLV_ROUTERALERT, 2, 0, 0, IPV6_TLV_PADN, 0 }; /* we assume size > sizeof(ra) here */ /* limit our allocations to order-0 page */ size = min_t(int, size, SKB_MAX_ORDER(0, 0)); skb = sock_alloc_send_skb(sk, size, 1, &err); if (!skb) return NULL; skb->priority = TC_PRIO_CONTROL; skb_reserve(skb, hlen); skb_tailroom_reserve(skb, mtu, tlen); if (__ipv6_get_lladdr(idev, &addr_buf, IFA_F_TENTATIVE)) { /* <draft-ietf-magma-mld-source-05.txt>: * use unspecified address as the source address * when a valid link-local address is not available. */ saddr = &in6addr_any; } else saddr = &addr_buf; ip6_mc_hdr(sk, skb, dev, saddr, &mld2_all_mcr, NEXTHDR_HOP, 0); memcpy(skb_put(skb, sizeof(ra)), ra, sizeof(ra)); skb_set_transport_header(skb, skb_tail_pointer(skb) - skb->data); skb_put(skb, sizeof(*pmr)); pmr = (struct mld2_report *)skb_transport_header(skb); pmr->mld2r_type = ICMPV6_MLD2_REPORT; pmr->mld2r_resv1 = 0; pmr->mld2r_cksum = 0; pmr->mld2r_resv2 = 0; pmr->mld2r_ngrec = 0; return skb; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens17856.51%210.00%
Hideaki Yoshifuji / 吉藤英明278.57%630.00%
Arnaldo Carvalho de Melo216.67%210.00%
Daniel Borkmann175.40%15.00%
Eric Dumazet175.40%15.00%
Herbert Xu154.76%15.00%
Américo Wang134.13%15.00%
Daniel Lezcano113.49%15.00%
Benjamin Poirier61.90%15.00%
Hannes Frederic Sowa61.90%15.00%
Neil Horman20.63%15.00%
Al Viro10.32%15.00%
Stephen Hemminger10.32%15.00%
Total315100.00%20100.00%


static void mld_sendpack(struct sk_buff *skb) { struct ipv6hdr *pip6 = ipv6_hdr(skb); struct mld2_report *pmr = (struct mld2_report *)skb_transport_header(skb); int payload_len, mldlen; struct inet6_dev *idev; struct net *net = dev_net(skb->dev); int err; struct flowi6 fl6; struct dst_entry *dst; rcu_read_lock(); idev = __in6_dev_get(skb->dev); IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_OUT, skb->len); payload_len = (skb_tail_pointer(skb) - skb_network_header(skb)) - sizeof(*pip6); mldlen = skb_tail_pointer(skb) - skb_transport_header(skb); pip6->payload_len = htons(payload_len); pmr->mld2r_cksum = csum_ipv6_magic(&pip6->saddr, &pip6->daddr, mldlen, IPPROTO_ICMPV6, csum_partial(skb_transport_header(skb), mldlen, 0)); icmpv6_flow_init(net->ipv6.igmp_sk, &fl6, ICMPV6_MLD2_REPORT, &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr, skb->dev->ifindex); dst = icmp6_dst_alloc(skb->dev, &fl6); err = 0; if (IS_ERR(dst)) { err = PTR_ERR(dst); dst = NULL; } skb_dst_set(skb, dst); if (err) goto err_out; payload_len = skb->len; err = NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, net, net->ipv6.igmp_sk, skb, NULL, skb->dev, dst_output); out: if (!err) { ICMP6MSGOUT_INC_STATS(net, idev, ICMPV6_MLD2_REPORT); ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTMSGS); } else { IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS); } rcu_read_unlock(); return; err_out: kfree_skb(skb); goto out; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens12235.78%39.38%
Hideaki Yoshifuji / 吉藤英明6719.65%515.62%
David S. Miller4011.73%412.50%
Eric Dumazet267.62%26.25%
Arnaldo Carvalho de Melo133.81%39.38%
Daniel Lezcano133.81%13.12%
Simon Horman123.52%13.12%
Neil Horman123.52%13.12%
Shirley Ma92.64%13.12%
Denis V. Lunev82.35%412.50%
Randy Dunlap82.35%13.12%
Hannes Frederic Sowa51.47%13.12%
Eric W. Biedermann30.88%26.25%
Jan Engelhardt10.29%13.12%
Alexey Dobriyan10.29%13.12%
Patrick McHardy10.29%13.12%
Total341100.00%32100.00%


static int grec_size(struct ifmcaddr6 *pmc, int type, int gdel, int sdel) { return sizeof(struct mld2_grec) + 16 * mld_scount(pmc,type,gdel,sdel); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens3997.50%150.00%
Yan Zheng12.50%150.00%
Total40100.00%2100.00%


static struct sk_buff *add_grhead(struct sk_buff *skb, struct ifmcaddr6 *pmc, int type, struct mld2_grec **ppgr) { struct net_device *dev = pmc->idev->dev; struct mld2_report *pmr; struct mld2_grec *pgr; if (!skb) skb = mld_newpack(pmc->idev, dev->mtu); if (!skb) return NULL; pgr = (struct mld2_grec *)skb_put(skb, sizeof(struct mld2_grec)); pgr->grec_type = type; pgr->grec_auxwords = 0; pgr->grec_nsrcs = 0; pgr->grec_mca = pmc->mca_addr; /* structure copy */ pmr = (struct mld2_report *)skb_transport_header(skb); pmr->mld2r_ngrec = htons(ntohs(pmr->mld2r_ngrec)+1); *ppgr = pgr; return skb; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens14694.19%120.00%
Américo Wang31.94%120.00%
Arnaldo Carvalho de Melo31.94%120.00%
Hideaki Yoshifuji / 吉藤英明21.29%120.00%
Al Viro10.65%120.00%
Total155100.00%5100.00%

#define AVAILABLE(skb) ((skb) ? skb_availroom(skb) : 0)
static struct sk_buff *add_grec(struct sk_buff *skb, struct ifmcaddr6 *pmc, int type, int gdeleted, int sdeleted, int crsend) { struct inet6_dev *idev = pmc->idev; struct net_device *dev = idev->dev; struct mld2_report *pmr; struct mld2_grec *pgr = NULL; struct ip6_sf_list *psf, *psf_next, *psf_prev, **psf_list; int scount, stotal, first, isquery, truncate; if (pmc->mca_flags & MAF_NOREPORT) return skb; isquery = type == MLD2_MODE_IS_INCLUDE || type == MLD2_MODE_IS_EXCLUDE; truncate = type == MLD2_MODE_IS_EXCLUDE || type == MLD2_CHANGE_TO_EXCLUDE; stotal = scount = 0; psf_list = sdeleted ? &pmc->mca_tomb : &pmc->mca_sources; if (!*psf_list) goto empty_source; pmr = skb ? (struct mld2_report *)skb_transport_header(skb) : NULL; /* EX and TO_EX get a fresh packet, if needed */ if (truncate) { if (pmr && pmr->mld2r_ngrec && AVAILABLE(skb) < grec_size(pmc, type, gdeleted, sdeleted)) { if (skb) mld_sendpack(skb); skb = mld_newpack(idev, dev->mtu); } } first = 1; psf_prev = NULL; for (psf = *psf_list; psf; psf = psf_next) { struct in6_addr *psrc; psf_next = psf->sf_next; if (!is_in(pmc, psf, type, gdeleted, sdeleted)) { psf_prev = psf; continue; } /* Based on RFC3810 6.1. Should not send source-list change * records when there is a filter mode change. */ if (((gdeleted && pmc->mca_sfmode == MCAST_EXCLUDE) || (!gdeleted && pmc->mca_crcount)) && (type == MLD2_ALLOW_NEW_SOURCES || type == MLD2_BLOCK_OLD_SOURCES) && psf->sf_crcount) goto decrease_sf_crcount; /* clear marks on query responses */ if (isquery) psf->sf_gsresp = 0; if (AVAILABLE(skb) < sizeof(*psrc) + first*sizeof(struct mld2_grec)) { if (truncate && !first) break; /* truncate these */ if (pgr) pgr->grec_nsrcs = htons(scount); if (skb) mld_sendpack(skb); skb = mld_newpack(idev, dev->mtu); first = 1; scount = 0; } if (first) { skb = add_grhead(skb, pmc, type, &pgr); first = 0; } if (!skb) return NULL; psrc = (struct in6_addr *)skb_put(skb, sizeof(*psrc)); *psrc = psf->sf_addr; scount++; stotal++; if ((type == MLD2_ALLOW_NEW_SOURCES || type == MLD2_BLOCK_OLD_SOURCES) && psf->sf_crcount) { decrease_sf_crcount: psf->sf_crcount--; if ((sdeleted || gdeleted) && psf->sf_crcount == 0) { if (psf_prev) psf_prev->sf_next = psf->sf_next; else *psf_list = psf->sf_next; kfree(psf); continue; } } psf_prev = psf; } empty_source: if (!stotal) { if (type == MLD2_ALLOW_NEW_SOURCES || type == MLD2_BLOCK_OLD_SOURCES) return skb; if (pmc->mca_crcount || isquery || crsend) { /* make sure we have room for group header */ if (skb && AVAILABLE(skb) < sizeof(struct mld2_grec)) { mld_sendpack(skb); skb = NULL; /* add_grhead will get a new one */ } skb = add_grhead(skb, pmc, type, &pgr); } } if (pgr) pgr->grec_nsrcs = htons(scount); if (isquery) pmc->mca_flags &= ~MAF_GSQUERY; /* clear query state */ return skb; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens56188.35%330.00%
Hangbin Liu436.77%110.00%
Américo Wang111.73%110.00%
Alexey Dobriyan81.26%110.00%
Flavio Leitner50.79%110.00%
Al Viro30.47%110.00%
Arnaldo Carvalho de Melo30.47%110.00%
Hideaki Yoshifuji / 吉藤英明10.16%110.00%
Total635100.00%10100.00%


static void mld_send_report(struct inet6_dev *idev, struct ifmcaddr6 *pmc) { struct sk_buff *skb = NULL; int type; read_lock_bh(&idev->lock); if (!pmc) { for (pmc = idev->mc_list; pmc; pmc = pmc->next) { if (pmc->mca_flags & MAF_NOREPORT) continue; spin_lock_bh(&pmc->mca_lock); if (pmc->mca_sfcount[MCAST_EXCLUDE]) type = MLD2_MODE_IS_EXCLUDE; else type = MLD2_MODE_IS_INCLUDE; skb = add_grec(skb, pmc, type, 0, 0, 0); spin_unlock_bh(&pmc->mca_lock); } } else { spin_lock_bh(&pmc->mca_lock); if (pmc->mca_sfcount[MCAST_EXCLUDE]) type = MLD2_MODE_IS_EXCLUDE; else type = MLD2_MODE_IS_INCLUDE; skb = add_grec(skb, pmc, type, 0, 0, 0); spin_unlock_bh(&pmc->mca_lock); } read_unlock_bh(&idev->lock); if (skb) mld_sendpack(skb); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens17190.00%125.00%
Américo Wang147.37%125.00%
Flavio Leitner42.11%125.00%
Al Viro10.53%125.00%
Total190100.00%4100.00%

/* * remove zero-count source records from a source filter list */
static void mld_clear_zeros(struct ip6_sf_list **ppsf) { struct ip6_sf_list *psf_prev, *psf_next, *psf; psf_prev = NULL; for (psf = *ppsf; psf; psf = psf_next) { psf_next = psf->sf_next; if (psf->sf_crcount == 0) { if (psf_prev) psf_prev->sf_next = psf->sf_next; else *ppsf = psf->sf_next; kfree(psf); } else psf_prev = psf; } }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens8798.86%150.00%
Al Viro11.14%150.00%
Total88100.00%2100.00%


static void mld_send_cr(struct inet6_dev *idev) { struct ifmcaddr6 *pmc, *pmc_prev, *pmc_next; struct sk_buff *skb = NULL; int type, dtype; read_lock_bh(&idev->lock); spin_lock(&idev->mc_lock); /* deleted MCA's */ pmc_prev = NULL; for (pmc = idev->mc_tomb; pmc; pmc = pmc_next) { pmc_next = pmc->next; if (pmc->mca_sfmode == MCAST_INCLUDE) { type = MLD2_BLOCK_OLD_SOURCES; dtype = MLD2_BLOCK_OLD_SOURCES; skb = add_grec(skb, pmc, type, 1, 0, 0); skb = add_grec(skb, pmc, dtype, 1, 1, 0); } if (pmc->mca_crcount) { if (pmc->mca_sfmode == MCAST_EXCLUDE) { type = MLD2_CHANGE_TO_INCLUDE; skb = add_grec(skb, pmc, type, 1, 0, 0); } pmc->mca_crcount--; if (pmc->mca_crcount == 0) { mld_clear_zeros(&pmc->mca_tomb); mld_clear_zeros(&pmc->mca_sources); } } if (pmc->mca_crcount == 0 && !pmc->mca_tomb && !pmc->mca_sources) { if (pmc_prev) pmc_prev->next = pmc_next; else idev->mc_tomb = pmc_next; in6_dev_put(pmc->idev); kfree(pmc); } else pmc_prev = pmc; } spin_unlock(&idev->mc_lock); /* change recs */ for (pmc = idev->mc_list; pmc; pmc = pmc->next) { spin_lock_bh(&pmc->mca_lock); if (pmc->mca_sfcount[MCAST_EXCLUDE]) { type = MLD2_BLOCK_OLD_SOURCES; dtype = MLD2_ALLOW_NEW_SOURCES; } else { type = MLD2_ALLOW_NEW_SOURCES; dtype = MLD2_BLOCK_OLD_SOURCES; } skb = add_grec(skb, pmc, type, 0, 0, 0); skb = add_grec(skb, pmc, dtype, 0, 1, 0); /* deleted sources */ /* filter mode changes */ if (pmc->mca_crcount) { if (pmc->mca_sfmode == MCAST_EXCLUDE) type = MLD2_CHANGE_TO_EXCLUDE; else type = MLD2_CHANGE_TO_INCLUDE; skb = add_grec(skb, pmc, type, 0, 0, 0); pmc->mca_crcount--; } spin_unlock_bh(&pmc->mca_lock); } read_unlock_bh(&idev->lock); if (!skb) return; (void) mld_sendpack(skb); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens41596.29%240.00%
Flavio Leitner122.78%120.00%
Al Viro20.46%120.00%
Stephen Hemminger20.46%120.00%
Total431100.00%5100.00%


static void igmp6_send(struct in6_addr *addr, struct net_device *dev, int type) { struct net *net = dev_net(dev); struct sock *sk = net->ipv6.igmp_sk; struct inet6_dev *idev; struct sk_buff *skb; struct mld_msg *hdr; const struct in6_addr *snd_addr, *saddr; struct in6_addr addr_buf; int hlen = LL_RESERVED_SPACE(dev); int tlen = dev->needed_tailroom; int err, len, payload_len, full_len; u8 ra[8] = { IPPROTO_ICMPV6, 0, IPV6_TLV_ROUTERALERT, 2, 0, 0, IPV6_TLV_PADN, 0 }; struct flowi6 fl6; struct dst_entry *dst; if (type == ICMPV6_MGM_REDUCTION) snd_addr = &in6addr_linklocal_allrouters; else snd_addr = addr; len = sizeof(struct icmp6hdr) + sizeof(struct in6_addr); payload_len = len + sizeof(ra); full_len = sizeof(struct ipv6hdr) + payload_len; rcu_read_lock(); IP6_UPD_PO_STATS(net, __in6_dev_get(dev), IPSTATS_MIB_OUT, full_len); rcu_read_unlock(); skb = sock_alloc_send_skb(sk, hlen + tlen + full_len, 1, &err); if (!skb) { rcu_read_lock(); IP6_INC_STATS(net, __in6_dev_get(dev), IPSTATS_MIB_OUTDISCARDS); rcu_read_unlock(); return; } skb->priority = TC_PRIO_CONTROL; skb_reserve(skb, hlen); if (ipv6_get_lladdr(dev, &addr_buf, IFA_F_TENTATIVE)) { /* <draft-ietf-magma-mld-source-05.txt>: * use unspecified address as the source address * when a valid link-local address is not available. */ saddr = &in6addr_any; } else saddr = &addr_buf; ip6_mc_hdr(sk, skb, dev, saddr, snd_addr, NEXTHDR_HOP, payload_len); memcpy(skb_put(skb, sizeof(ra)), ra, sizeof(ra)); hdr = (struct mld_msg *) skb_put(skb, sizeof(struct mld_msg)); memset(hdr, 0, sizeof(struct mld_msg)); hdr->mld_type = type; hdr->mld_mca = *addr; hdr->mld_cksum = csum_ipv6_magic(saddr, snd_addr, len, IPPROTO_ICMPV6, csum_partial(hdr, len, 0)); rcu_read_lock(); idev = __in6_dev_get(skb->dev); icmpv6_flow_init(sk, &fl6, type, &ipv6_hdr(skb)->saddr, &ipv6_hdr(skb)->daddr, skb->dev->ifindex); dst = icmp6_dst_alloc(skb->dev, &fl6); if (IS_ERR(dst)) { err = PTR_ERR(dst); goto err_out; } skb_dst_set(skb, dst); err = NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT, net, sk, skb, NULL, skb->dev, dst_output); out: if (!err) { ICMP6MSGOUT_INC_STATS(net, idev, type); ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTMSGS); } else IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS); rcu_read_unlock(); return; err_out: kfree_skb(skb); goto out; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens28653.16%411.11%
Hideaki Yoshifuji / 吉藤英明10519.52%925.00%
David S. Miller254.65%411.11%
Neil Horman224.09%25.56%
Herbert Xu193.53%12.78%
Eric Dumazet183.35%25.56%
Randy Dunlap183.35%12.78%
Daniel Lezcano112.04%12.78%
Shirley Ma112.04%12.78%
Denis V. Lunev81.49%38.33%
Hannes Frederic Sowa61.12%12.78%
Eric W. Biedermann30.56%25.56%
Alexey Dobriyan30.56%25.56%
Jan Engelhardt10.19%12.78%
Ian Morris10.19%12.78%
Patrick McHardy10.19%12.78%
Total538100.00%36100.00%


static void mld_send_initial_cr(struct inet6_dev *idev) { struct sk_buff *skb; struct ifmcaddr6 *pmc; int type; if (mld_in_v1_mode(idev)) return; skb = NULL; read_lock_bh(&idev->lock); for (pmc = idev->mc_list; pmc; pmc = pmc->next) { spin_lock_bh(&pmc->mca_lock); if (pmc->mca_sfcount[MCAST_EXCLUDE]) type = MLD2_CHANGE_TO_EXCLUDE; else type = MLD2_CHANGE_TO_INCLUDE; skb = add_grec(skb, pmc, type, 0, 0, 1); spin_unlock_bh(&pmc->mca_lock); } read_unlock_bh(&idev->lock); if (skb) mld_sendpack(skb); }

Contributors

PersonTokensPropCommitsCommitProp
Flavio Leitner7154.62%133.33%
Hannes Frederic Sowa5844.62%133.33%
Daniel Borkmann10.77%133.33%
Total130100.00%3100.00%


void ipv6_mc_dad_complete(struct inet6_dev *idev) { idev->mc_dad_count = idev->mc_qrv; if (idev->mc_dad_count) { mld_send_initial_cr(idev); idev->mc_dad_count--; if (idev->mc_dad_count) mld_dad_start_timer(idev, idev->mc_maxdelay); } }

Contributors

PersonTokensPropCommitsCommitProp
Hannes Frederic Sowa5098.04%150.00%
Flavio Leitner11.96%150.00%
Total51100.00%2100.00%


static void mld_dad_timer_expire(unsigned long data) { struct inet6_dev *idev = (struct inet6_dev *)data; mld_send_initial_cr(idev); if (idev->mc_dad_count) { idev->mc_dad_count--; if (idev->mc_dad_count) mld_dad_start_timer(idev, idev->mc_maxdelay); } in6_dev_put(idev); }

Contributors

PersonTokensPropCommitsCommitProp
Hannes Frederic Sowa5896.67%133.33%
Salam Noureddine11.67%133.33%
Flavio Leitner11.67%133.33%
Total60100.00%3100.00%


static int ip6_mc_del1_src(struct ifmcaddr6 *pmc, int sfmode, const struct in6_addr *psfsrc) { struct ip6_sf_list *psf, *psf_prev; int rv = 0; psf_prev = NULL; for (psf = pmc->mca_sources; psf; psf = psf->sf_next) { if (ipv6_addr_equal(&psf->sf_addr, psfsrc)) break; psf_prev = psf; } if (!psf || psf->sf_count[sfmode] == 0) { /* source filter not found, or count wrong => bug */ return -ESRCH; } psf->sf_count[sfmode]--; if (!psf->sf_count[MCAST_INCLUDE] && !psf->sf_count[MCAST_EXCLUDE]) { struct inet6_dev *idev = pmc->idev; /* no more filters for this source */ if (psf_prev) psf_prev->sf_next = psf->sf_next; else pmc->mca_sources = psf->sf_next; if (psf->sf_oldin && !(pmc->mca_flags & MAF_NOREPORT) && !mld_in_v1_mode(idev)) { psf->sf_crcount = idev->mc_qrv; psf->sf_next = pmc->mca_tomb; pmc->mca_tomb = psf; rv = 1; } else kfree(psf); } return rv; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens20698.10%120.00%
Daniel Borkmann10.48%120.00%
Hideaki Yoshifuji / 吉藤英明10.48%120.00%
Eric Dumazet10.48%120.00%
Al Viro10.48%120.00%
Total210100.00%5100.00%


static int ip6_mc_del_src(struct inet6_dev *idev, const struct in6_addr *pmca, int sfmode, int sfcount, const struct in6_addr *psfsrc, int delta) { struct ifmcaddr6 *pmc; int changerec = 0; int i, err; if (!idev) return -ENODEV; read_lock_bh(&idev->lock); for (pmc = idev->mc_list; pmc; pmc = pmc->next) { if (ipv6_addr_equal(pmca, &pmc->mca_addr)) break; } if (!pmc) { /* MCA not found?? bug */ read_unlock_bh(&idev->lock); return -ESRCH; } spin_lock_bh(&pmc->mca_lock); sf_markstate(pmc); if (!delta) { if (!pmc->mca_sfcount[sfmode]) { spin_unlock_bh(&pmc->mca_lock); read_unlock_bh(&idev->lock); return -EINVAL; } pmc->mca_sfcount[sfmode]--; } err = 0; for (i = 0; i < sfcount; i++) { int rv = ip6_mc_del1_src(pmc, sfmode, &psfsrc[i]); changerec |= rv > 0; if (!err && rv < 0) err = rv; } if (pmc->mca_sfmode == MCAST_EXCLUDE && pmc->mca_sfcount[MCAST_EXCLUDE] == 0 && pmc->mca_sfcount[MCAST_INCLUDE]) { struct ip6_sf_list *psf; /* filter mode change */ pmc->mca_sfmode = MCAST_INCLUDE; pmc->mca_crcount = idev->mc_qrv; idev->mc_ifc_count = pmc->mca_crcount; for (psf = pmc->mca_sources; psf; psf = psf->sf_next) psf->sf_crcount = 0; mld_ifc_event(pmc->idev); } else if (sf_setstate(pmc) || changerec) mld_ifc_event(pmc->idev); spin_unlock_bh(&pmc->mca_lock); read_unlock_bh(&idev->lock); return err; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens34498.85%240.00%
Eric Dumazet20.57%120.00%
Adrian Bunk10.29%120.00%
Hideaki Yoshifuji / 吉藤英明10.29%120.00%
Total348100.00%5100.00%

/* * Add multicast single-source filter to the interface list */
static int ip6_mc_add1_src(struct ifmcaddr6 *pmc, int sfmode, const struct in6_addr *psfsrc) { struct ip6_sf_list *psf, *psf_prev; psf_prev = NULL; for (psf = pmc->mca_sources; psf; psf = psf->sf_next) { if (ipv6_addr_equal(&psf->sf_addr, psfsrc)) break; psf_prev = psf; } if (!psf) { psf = kzalloc(sizeof(*psf), GFP_ATOMIC); if (!psf) return -ENOBUFS; psf->sf_addr = *psfsrc; if (psf_prev) { psf_prev->sf_next = psf; } else pmc->mca_sources = psf; } psf->sf_count[sfmode]++; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens12996.99%120.00%
Al Viro10.75%120.00%
Hideaki Yoshifuji / 吉藤英明10.75%120.00%
Eric Dumazet10.75%120.00%
Ingo Oeser10.75%120.00%
Total133100.00%5100.00%


static void sf_markstate(struct ifmcaddr6 *pmc) { struct ip6_sf_list *psf; int mca_xcount = pmc->mca_sfcount[MCAST_EXCLUDE]; for (psf = pmc->mca_sources; psf; psf = psf->sf_next) if (pmc->mca_sfcount[MCAST_EXCLUDE]) { psf->sf_oldin = mca_xcount == psf->sf_count[MCAST_EXCLUDE] && !psf->sf_count[MCAST_INCLUDE]; } else psf->sf_oldin = psf->sf_count[MCAST_INCLUDE] != 0; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens88100.00%1100.00%
Total88100.00%1100.00%


static int sf_setstate(struct ifmcaddr6 *pmc) { struct ip6_sf_list *psf, *dpsf; int mca_xcount = pmc->mca_sfcount[MCAST_EXCLUDE]; int qrv = pmc->idev->mc_qrv; int new_in, rv; rv = 0; for (psf = pmc->mca_sources; psf; psf = psf->sf_next) { if (pmc->mca_sfcount[MCAST_EXCLUDE]) { new_in = mca_xcount == psf->sf_count[MCAST_EXCLUDE] && !psf->sf_count[MCAST_INCLUDE]; } else new_in = psf->sf_count[MCAST_INCLUDE] != 0; if (new_in) { if (!psf->sf_oldin) { struct ip6_sf_list *prev = NULL; for (dpsf = pmc->mca_tomb; dpsf; dpsf = dpsf->sf_next) { if (ipv6_addr_equal(&dpsf->sf_addr, &psf->sf_addr)) break; prev = dpsf; } if (dpsf) { if (prev) prev->sf_next = dpsf->sf_next; else pmc->mca_tomb = dpsf->sf_next; kfree(dpsf); } psf->sf_crcount = qrv; rv++; } } else if (psf->sf_oldin) { psf->sf_crcount = 0; /* * add or update "delete" records if an active filter * is now inactive */ for (dpsf = pmc->mca_tomb; dpsf; dpsf = dpsf->sf_next) if (ipv6_addr_equal(&dpsf->sf_addr, &psf->sf_addr)) break; if (!dpsf) { dpsf = kmalloc(sizeof(*dpsf), GFP_ATOMIC); if (!dpsf) continue; *dpsf = *psf; /* pmc->mca_lock held by callers */ dpsf->sf_next = pmc->mca_tomb; pmc->mca_tomb = dpsf; } dpsf->sf_crcount = qrv; rv++; } } return rv; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens31499.68%266.67%
Al Viro10.32%133.33%
Total315100.00%3100.00%

/* * Add multicast source filter list to the interface list */
static int ip6_mc_add_src(struct inet6_dev *idev, const struct in6_addr *pmca, int sfmode, int sfcount, const struct in6_addr *psfsrc, int delta) { struct ifmcaddr6 *pmc; int isexclude; int i, err; if (!idev) return -ENODEV; read_lock_bh(&idev->lock); for (pmc = idev->mc_list; pmc; pmc = pmc->next) { if (ipv6_addr_equal(pmca, &pmc->mca_addr)) break; } if (!pmc) { /* MCA not found?? bug */ read_unlock_bh(&idev->lock); return -ESRCH; } spin_lock_bh(&pmc->mca_lock); sf_markstate(pmc); isexclude = pmc->mca_sfmode == MCAST_EXCLUDE; if (!delta) pmc->mca_sfcount[sfmode]++; err = 0; for (i = 0; i < sfcount; i++) { err = ip6_mc_add1_src(pmc, sfmode, &psfsrc[i]); if (err) break; } if (err) { int j; if (!delta) pmc->mca_sfcount[sfmode]--; for (j = 0; j < i; j++) ip6_mc_del1_src(pmc, sfmode, &psfsrc[j]); } else if (isexclude != (pmc->mca_sfcount[MCAST_EXCLUDE] != 0)) { struct ip6_sf_list *psf; /* filter mode change */ if (pmc->mca_sfcount[MCAST_EXCLUDE]) pmc->mca_sfmode = MCAST_EXCLUDE; else if (pmc->mca_sfcount[MCAST_INCLUDE]) pmc->mca_sfmode = MCAST_INCLUDE; /* else no filters; keep old mode for reports */ pmc->mca_crcount = idev->mc_qrv; idev->mc_ifc_count = pmc->mca_crcount; for (psf = pmc->mca_sources; psf; psf = psf->sf_next) psf->sf_crcount = 0; mld_ifc_event(idev); } else if (sf_setstate(pmc)) mld_ifc_event(idev); spin_unlock_bh(&pmc->mca_lock); read_unlock_bh(&idev->lock); return err; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens35597.26%228.57%
Arnaldo Carvalho de Melo51.37%114.29%
Eric Dumazet20.55%114.29%
Hideaki Yoshifuji / 吉藤英明10.27%114.29%
Adrian Bunk10.27%114.29%
Li RongQing10.27%114.29%
Total365100.00%7100.00%


static void ip6_mc_clear_src(struct ifmcaddr6 *pmc) { struct ip6_sf_list *psf, *nextpsf; for (psf = pmc->mca_tomb; psf; psf = nextpsf) { nextpsf = psf->sf_next; kfree(psf); } pmc->mca_tomb = NULL; for (psf = pmc->mca_sources; psf; psf = nextpsf) { nextpsf = psf->sf_next; kfree(psf); } pmc->mca_sources = NULL; pmc->mca_sfmode = MCAST_EXCLUDE; pmc->mca_sfcount[MCAST_INCLUDE] = 0; pmc->mca_sfcount[MCAST_EXCLUDE] = 1; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens10697.25%133.33%
Al Viro21.83%133.33%
Denis Lukianov10.92%133.33%
Total109100.00%3100.00%


static void igmp6_join_group(struct ifmcaddr6 *ma) { unsigned long delay; if (ma->mca_flags & MAF_NOREPORT) return; igmp6_send(&ma->mca_addr, ma->idev->dev, ICMPV6_MGM_REPORT); delay = prandom_u32() % unsolicited_report_interval(ma->idev); spin_lock_bh(&ma->mca_lock); if (del_timer(&ma->mca_timer)) { atomic_dec(&ma->mca_refcnt); delay = ma->mca_timer.expires - jiffies; } if (!mod_timer(&ma->mca_timer, jiffies + delay)) atomic_inc(&ma->mca_refcnt); ma->mca_flags |= MAF_TIMER_RUNNING | MAF_LAST_REPORTER; spin_unlock_bh(&ma->mca_lock); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens12294.57%133.33%
Hannes Frederic Sowa64.65%133.33%
Aruna-Hewapathirane10.78%133.33%
Total129100.00%3100.00%


static int ip6_mc_leave_src(struct sock *sk, struct ipv6_mc_socklist *iml, struct inet6_dev *idev) { int err; /* callers have the socket lock and rtnl lock * so no other readers or writers of iml or its sflist */ if (!iml->sflist) { /* any-source empty exclude case */ return ip6_mc_del_src(idev, &iml->addr, iml->sfmode, 0, NULL, 0); } err = ip6_mc_del_src(idev, &iml->addr, iml->sfmode, iml->sflist->sl_count, iml->sflist->sl_addr, 0); sock_kfree_s(sk, iml->sflist, IP6_SFLSIZE(iml->sflist->sl_max)); iml->sflist = NULL; return err; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens10895.58%120.00%
Al Viro21.77%120.00%
Américo Wang10.88%120.00%
Adrian Bunk10.88%120.00%
Stephen Hemminger10.88%120.00%
Total113100.00%5100.00%


static void igmp6_leave_group(struct ifmcaddr6 *ma) { if (mld_in_v1_mode(ma->idev)) { if (ma->mca_flags & MAF_LAST_REPORTER) igmp6_send(&ma->mca_addr, ma->idev->dev, ICMPV6_MGM_REDUCTION); } else { mld_add_delrec(ma->idev, ma); mld_ifc_event(ma->idev); } }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens6498.46%150.00%
Daniel Borkmann11.54%150.00%
Total65100.00%2100.00%


static void mld_gq_timer_expire(unsigned long data) { struct inet6_dev *idev = (struct inet6_dev *)data; idev->mc_gq_running = 0; mld_send_report(idev, NULL); in6_dev_put(idev); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens3895.00%250.00%
Al Viro12.50%125.00%
Salam Noureddine12.50%125.00%
Total40100.00%4100.00%


static void mld_ifc_timer_expire(unsigned long data) { struct inet6_dev *idev = (struct inet6_dev *)data; mld_send_cr(idev); if (idev->mc_ifc_count) { idev->mc_ifc_count--; if (idev->mc_ifc_count) mld_ifc_start_timer(idev, idev->mc_maxdelay); } in6_dev_put(idev); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens5998.33%266.67%
Salam Noureddine11.67%133.33%
Total60100.00%3100.00%


static void mld_ifc_event(struct inet6_dev *idev) { if (mld_in_v1_mode(idev)) return; idev->mc_ifc_count = idev->mc_qrv; mld_ifc_start_timer(idev, 1); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens3397.06%150.00%
Daniel Borkmann12.94%150.00%
Total34100.00%2100.00%


static void igmp6_timer_handler(unsigned long data) { struct ifmcaddr6 *ma = (struct ifmcaddr6 *) data; if (mld_in_v1_mode(ma->idev)) igmp6_send(&ma->mca_addr, ma->idev->dev, ICMPV6_MGM_REPORT); else mld_send_report(ma->idev, ma); spin_lock(&ma->mca_lock); ma->mca_flags |= MAF_LAST_REPORTER; ma->mca_flags &= ~MAF_TIMER_RUNNING; spin_unlock(&ma->mca_lock); ma_put(ma); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens9098.90%150.00%
Daniel Borkmann11.10%150.00%
Total91100.00%2100.00%

/* Device changing type */
void ipv6_mc_unmap(struct inet6_dev *idev) { struct ifmcaddr6 *i; /* Install multicast list, except for all-nodes (already installed) */ read_lock_bh(&idev->lock); for (i = idev->mc_list; i; i = i->next) igmp6_group_dropped(i); read_unlock_bh(&idev->lock); }

Contributors

PersonTokensPropCommitsCommitProp
Moni Shoua53100.00%1100.00%
Total53100.00%1100.00%


void ipv6_mc_remap(struct inet6_dev *idev) { ipv6_mc_up(idev); }

Contributors

PersonTokensPropCommitsCommitProp
Moni Shoua15100.00%1100.00%
Total15100.00%1100.00%

/* Device going down */
void ipv6_mc_down(struct inet6_dev *idev) { struct ifmcaddr6 *i; /* Withdraw multicast list */ read_lock_bh(&idev->lock); for (i = idev->mc_list; i; i = i->next) igmp6_group_dropped(i); /* Should stop timer after group drop. or we will * start timer again in mld_ifc_event() */ mld_ifc_stop_timer(idev); mld_gq_stop_timer(idev); mld_dad_stop_timer(idev); read_unlock_bh(&idev->lock); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens5376.81%150.00%
Hangbin Liu1623.19%150.00%
Total69100.00%2100.00%


static void ipv6_mc_reset(struct inet6_dev *idev) { idev->mc_qrv = sysctl_mld_qrv; idev->mc_qi = MLD_QI_DEFAULT; idev->mc_qri = MLD_QRI_DEFAULT; idev->mc_v1_seen = 0; idev->mc_maxdelay = unsolicited_report_interval(idev); }

Contributors

PersonTokensPropCommitsCommitProp
Hannes Frederic Sowa44100.00%1100.00%
Total44100.00%1100.00%

/* Device going up */
void ipv6_mc_up(struct inet6_dev *idev) { struct ifmcaddr6 *i; /* Install multicast list, except for all-nodes (already installed) */ read_lock_bh(&idev->lock); ipv6_mc_reset(idev); for (i = idev->mc_list; i; i = i->next) { mld_del_delrec(idev, i); igmp6_group_added(i); } read_unlock_bh(&idev->lock); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens5379.10%133.33%
Hangbin Liu913.43%133.33%
Hannes Frederic Sowa57.46%133.33%
Total67100.00%3100.00%

/* IPv6 device initialization. */
void ipv6_mc_init_dev(struct inet6_dev *idev) { write_lock_bh(&idev->lock); spin_lock_init(&idev->mc_lock); idev->mc_gq_running = 0; setup_timer(&idev->mc_gq_timer, mld_gq_timer_expire, (unsigned long)idev); idev->mc_tomb = NULL; idev->mc_ifc_count = 0; setup_timer(&idev->mc_ifc_timer, mld_ifc_timer_expire, (unsigned long)idev); setup_timer(&idev->mc_dad_timer, mld_dad_timer_expire, (unsigned long)idev); ipv6_mc_reset(idev); write_unlock_bh(&idev->lock); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens7066.67%112.50%
Hannes Frederic Sowa2019.05%337.50%
Pavel Emelyanov109.52%112.50%
Andrew Morton32.86%112.50%
Stephen Hemminger10.95%112.50%
Al Viro10.95%112.50%
Total105100.00%8100.00%

/* * Device is about to be destroyed: clean up. */
void ipv6_mc_destroy_dev(struct inet6_dev *idev) { struct ifmcaddr6 *i; /* Deactivate timers */ ipv6_mc_down(idev); mld_clear_delrec(idev); /* Delete all-nodes address. */ /* We cannot call ipv6_dev_mc_dec() directly, our caller in * addrconf.c has NULL'd out dev->ip6_ptr so in6_dev_get() will * fail. */ __ipv6_dev_mc_dec(idev, &in6addr_linklocal_allnodes); if (idev->cnf.forwarding) __ipv6_dev_mc_dec(idev, &in6addr_linklocal_allrouters); write_lock_bh(&idev->lock); while ((i = idev->mc_list) != NULL) { idev->mc_list = i->next; write_unlock_bh(&idev->lock); ma_put(i); write_lock_bh(&idev->lock); } write_unlock_bh(&idev->lock); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens8072.07%116.67%
Hideaki Yoshifuji / 吉藤英明1715.32%233.33%
Jan Oravec65.41%116.67%
Hangbin Liu54.50%116.67%
David S. Miller32.70%116.67%
Total111100.00%6100.00%

#ifdef CONFIG_PROC_FS struct igmp6_mc_iter_state { struct seq_net_private p; struct net_device *dev; struct inet6_dev *idev; }; #define igmp6_mc_seq_private(seq) ((struct igmp6_mc_iter_state *)(seq)->private)
static inline struct ifmcaddr6 *igmp6_mc_get_first(struct seq_file *seq) { struct ifmcaddr6 *im = NULL; struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq); struct net *net = seq_file_net(seq); state->idev = NULL; for_each_netdev_rcu(net, state->dev) { struct inet6_dev *idev; idev = __in6_dev_get(state->dev); if (!idev) continue; read_lock_bh(&idev->lock); im = idev->mc_list; if (im) { state->idev = idev; break; } read_unlock_bh(&idev->lock); } return im; }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明5044.25%228.57%
David L Stevens4943.36%114.29%
Daniel Lezcano76.19%114.29%
Pavel Emelyanov43.54%114.29%
Eric Dumazet21.77%114.29%
Eric W. Biedermann10.88%114.29%
Total113100.00%7100.00%


static struct ifmcaddr6 *igmp6_mc_get_next(struct seq_file *seq, struct ifmcaddr6 *im) { struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq); im = im->next; while (!im) { if (likely(state->idev)) read_unlock_bh(&state->idev->lock); state->dev = next_net_device_rcu(state->dev); if (!state->dev) { state->idev = NULL; break; } state->idev = __in6_dev_get(state->dev); if (!state->idev) continue; read_lock_bh(&state->idev->lock); im = state->idev->mc_list; } return im; }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明9977.95%114.29%
David L Stevens129.45%114.29%
Linus Torvalds (pre-git)129.45%342.86%
Pavel Emelyanov21.57%114.29%
Eric Dumazet21.57%114.29%
Total127100.00%7100.00%


static struct ifmcaddr6 *igmp6_mc_get_idx(struct seq_file *seq, loff_t pos) { struct ifmcaddr6 *im = igmp6_mc_get_first(seq); if (im) while (pos && (im = igmp6_mc_get_next(seq, im)) != NULL) --pos; return pos ? NULL : im; }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明5494.74%133.33%
Linus Torvalds (pre-git)23.51%133.33%
David L Stevens11.75%133.33%
Total57100.00%3100.00%


static void *igmp6_mc_seq_start(struct seq_file *seq, loff_t *pos) __acquires (RCU) { rcu_read_lock(); return igmp6_mc_get_idx(seq, *pos); }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明2681.25%133.33%
Eric Dumazet618.75%266.67%
Total32100.00%3100.00%


static void *igmp6_mc_seq_next(struct seq_file *seq, void *v, loff_t *pos) { struct ifmcaddr6 *im = igmp6_mc_get_next(seq, v); ++*pos; return im; }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明3794.87%150.00%
Eric Dumazet25.13%150.00%
Total39100.00%2100.00%


static void igmp6_mc_seq_stop(struct seq_file *seq, void *v) __releases (RCU) { struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq); if (likely(state->idev)) { read_unlock_bh(&state->idev->lock); state->idev = NULL; } state->dev = NULL; rcu_read_unlock(); }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明5889.23%240.00%
Eric Dumazet69.23%240.00%
Linus Torvalds (pre-git)11.54%120.00%
Total65100.00%5100.00%


static int igmp6_mc_seq_show(struct seq_file *seq, void *v) { struct ifmcaddr6 *im = (struct ifmcaddr6 *)v; struct igmp6_mc_iter_state *state = igmp6_mc_seq_private(seq); seq_printf(seq, "%-4d %-15s %pi6 %5d %08X %ld\n", state->dev->ifindex, state->dev->name, &im->mca_addr, im->mca_users, im->mca_flags, (im->mca_flags&MAF_TIMER_RUNNING) ? jiffies_to_clock_t(im->mca_timer.expires-jiffies) : 0); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明8389.25%120.00%
David L Stevens88.60%240.00%
Harvey Harrison22.15%240.00%
Total93100.00%5100.00%

static const struct seq_operations igmp6_mc_seq_ops = { .start = igmp6_mc_seq_start, .next = igmp6_mc_seq_next, .stop = igmp6_mc_seq_stop, .show = igmp6_mc_seq_show, };
static int igmp6_mc_seq_open(struct inode *inode, struct file *file) { return seq_open_net(inode, file, &igmp6_mc_seq_ops, sizeof(struct igmp6_mc_iter_state)); }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明2266.67%125.00%
Pavel Emelyanov721.21%125.00%
Daniel Lezcano39.09%125.00%
Linus Torvalds (pre-git)13.03%125.00%
Total33100.00%4100.00%

static const struct file_operations igmp6_mc_seq_fops = { .owner = THIS_MODULE, .open = igmp6_mc_seq_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release_net, }; struct igmp6_mcf_iter_state { struct seq_net_private p; struct net_device *dev; struct inet6_dev *idev; struct ifmcaddr6 *im; }; #define igmp6_mcf_seq_private(seq) ((struct igmp6_mcf_iter_state *)(seq)->private)
static inline struct ip6_sf_list *igmp6_mcf_get_first(struct seq_file *seq) { struct ip6_sf_list *psf = NULL; struct ifmcaddr6 *im = NULL; struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq); struct net *net = seq_file_net(seq); state->idev = NULL; state->im = NULL; for_each_netdev_rcu(net, state->dev) { struct inet6_dev *idev; idev = __in6_dev_get(state->dev); if (unlikely(idev == NULL)) continue; read_lock_bh(&idev->lock); im = idev->mc_list; if (likely(im)) { spin_lock_bh(&im->mca_lock); psf = im->mca_sources; if (likely(psf)) { state->im = im; state->idev = idev; break; } spin_unlock_bh(&im->mca_lock); } read_unlock_bh(&idev->lock); } return psf; }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明8851.76%218.18%
David L Stevens3118.24%19.09%
Linus Torvalds (pre-git)2715.88%327.27%
Linus Torvalds95.29%19.09%
Daniel Lezcano74.12%19.09%
Pavel Emelyanov52.94%19.09%
Eric Dumazet21.18%19.09%
Eric W. Biedermann10.59%19.09%
Total170100.00%11100.00%


static struct ip6_sf_list *igmp6_mcf_get_next(struct seq_file *seq, struct ip6_sf_list *psf) { struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq); psf = psf->sf_next; while (!psf) { spin_unlock_bh(&state->im->mca_lock); state->im = state->im->next; while (!state->im) { if (likely(state->idev)) read_unlock_bh(&state->idev->lock); state->dev = next_net_device_rcu(state->dev); if (!state->dev) { state->idev = NULL; goto out; } state->idev = __in6_dev_get(state->dev); if (!state->idev) continue; read_lock_bh(&state->idev->lock); state->im = state->idev->mc_list; } if (!state->im) break; spin_lock_bh(&state->im->mca_lock); psf = state->im->mca_sources; } out: return psf; }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明16085.11%112.50%
David L Stevens126.38%112.50%
Linus Torvalds (pre-git)94.79%337.50%
Linus Torvalds31.60%112.50%
Eric Dumazet21.06%112.50%
Pavel Emelyanov21.06%112.50%
Total188100.00%8100.00%


static struct ip6_sf_list *igmp6_mcf_get_idx(struct seq_file *seq, loff_t pos) { struct ip6_sf_list *psf = igmp6_mcf_get_first(seq); if (psf) while (pos && (psf = igmp6_mcf_get_next(seq, psf)) != NULL) --pos; return pos ? NULL : psf; }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明5698.25%150.00%
David L Stevens11.75%150.00%
Total57100.00%2100.00%


static void *igmp6_mcf_seq_start(struct seq_file *seq, loff_t *pos) __acquires (RCU) { rcu_read_lock(); return *pos ? igmp6_mcf_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明3282.05%240.00%
Eric Dumazet615.38%240.00%
Joe Perches12.56%120.00%
Total39100.00%5100.00%


static void *igmp6_mcf_seq_next(struct seq_file *seq, void *v, loff_t *pos) { struct ip6_sf_list *psf; if (v == SEQ_START_TOKEN) psf = igmp6_mcf_get_first(seq); else psf = igmp6_mcf_get_next(seq, v); ++*pos; return psf; }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明5498.18%150.00%
Joe Perches11.82%150.00%
Total55100.00%2100.00%


static void igmp6_mcf_seq_stop(struct seq_file *seq, void *v) __releases (RCU) { struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq); if (likely(state->im)) { spin_unlock_bh(&state->im->mca_lock); state->im = NULL; } if (likely(state->idev)) { read_unlock_bh(&state->idev->lock); state->idev = NULL; } state->dev = NULL; rcu_read_unlock(); }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明8693.48%250.00%
Eric Dumazet66.52%250.00%
Total92100.00%4100.00%


static int igmp6_mcf_seq_show(struct seq_file *seq, void *v) { struct ip6_sf_list *psf = (struct ip6_sf_list *)v; struct igmp6_mcf_iter_state *state = igmp6_mcf_seq_private(seq); if (v == SEQ_START_TOKEN) { seq_puts(seq, "Idx Device Multicast Address Source Address INC EXC\n"); } else { seq_printf(seq, "%3d %6.6s %pi6 %pi6 %6lu %6lu\n", state->dev->ifindex, state->dev->name, &state->im->mca_addr, &psf->sf_addr, psf->sf_count[MCAST_INCLUDE], psf->sf_count[MCAST_EXCLUDE]); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明9188.35%111.11%
Linus Torvalds (pre-git)65.83%444.44%
Harvey Harrison32.91%222.22%
Joe Perches32.91%222.22%
Total103100.00%9100.00%

static const struct seq_operations igmp6_mcf_seq_ops = { .start = igmp6_mcf_seq_start, .next = igmp6_mcf_seq_next, .stop = igmp6_mcf_seq_stop, .show = igmp6_mcf_seq_show, };
static int igmp6_mcf_seq_open(struct inode *inode, struct file *file) { return seq_open_net(inode, file, &igmp6_mcf_seq_ops, sizeof(struct igmp6_mcf_iter_state)); }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明2060.61%120.00%
Pavel Emelyanov721.21%120.00%
Daniel Lezcano39.09%120.00%
Linus Torvalds (pre-git)39.09%240.00%
Total33100.00%5100.00%

static const struct file_operations igmp6_mcf_seq_fops = { .owner = THIS_MODULE, .open = igmp6_mcf_seq_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release_net, };
static int __net_init igmp6_proc_init(struct net *net) { int err; err = -ENOMEM; if (!proc_create("igmp6", S_IRUGO, net->proc_net, &igmp6_mc_seq_fops)) goto out; if (!proc_create("mcfilter6", S_IRUGO, net->proc_net, &igmp6_mcf_seq_fops)) goto out_proc_net_igmp6; err = 0; out: return err; out_proc_net_igmp6: remove_proc_entry("igmp6", net->proc_net); goto out; }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Lezcano6780.72%125.00%
Gao Feng1518.07%250.00%
Alexey Dobriyan11.20%125.00%
Total83100.00%4100.00%


static void __net_exit igmp6_proc_exit(struct net *net) { remove_proc_entry("mcfilter6", net->proc_net); remove_proc_entry("igmp6", net->proc_net); }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Lezcano1963.33%133.33%
Gao Feng1033.33%133.33%
Alexey Dobriyan13.33%133.33%
Total30100.00%3100.00%

#else
static inline int igmp6_proc_init(struct net *net) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Lezcano1493.33%150.00%
Alexey Dobriyan16.67%150.00%
Total15100.00%2100.00%


static inline void igmp6_proc_exit(struct net *net) { }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Lezcano981.82%150.00%
Alexey Dobriyan218.18%150.00%
Total11100.00%2100.00%

#endif
static int __net_init igmp6_net_init(struct net *net) { int err; err = inet_ctl_sock_create(&net->ipv6.igmp_sk, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6, net); if (err < 0) { pr_err("Failed to initialize the IGMP6 control socket (err %d)\n", err); goto out; } inet6_sk(net->ipv6.igmp_sk)->hop_limit = 1; err = inet_ctl_sock_create(&net->ipv6.mc_autojoin_sk, PF_INET6, SOCK_RAW, IPPROTO_ICMPV6, net); if (err < 0) { pr_err("Failed to initialize the IGMP6 autojoin socket (err %d)\n", err); goto out_sock_create; } err = igmp6_proc_init(net); if (err) goto out_sock_create_autojoin; return 0; out_sock_create_autojoin: inet_ctl_sock_destroy(net->ipv6.mc_autojoin_sk); out_sock_create: inet_ctl_sock_destroy(net->ipv6.igmp_sk); out: return err; }

Contributors

PersonTokensPropCommitsCommitProp
Madhu Challa5537.16%18.33%
Daniel Lezcano3825.68%216.67%
Linus Torvalds (pre-git)3221.62%433.33%
Denis V. Lunev128.11%18.33%
Al Viro74.73%18.33%
Joe Perches21.35%18.33%
Alexey Dobriyan10.68%18.33%
Hideaki Yoshifuji / 吉藤英明10.68%18.33%
Total148100.00%12100.00%


static void __net_exit igmp6_net_exit(struct net *net) { inet_ctl_sock_destroy(net->ipv6.igmp_sk); inet_ctl_sock_destroy(net->ipv6.mc_autojoin_sk); igmp6_proc_exit(net); }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Lezcano1337.14%225.00%
Linus Torvalds (pre-git)1028.57%225.00%
Madhu Challa925.71%112.50%
Alexey Dobriyan12.86%112.50%
Hideaki Yoshifuji / 吉藤英明12.86%112.50%
Denis V. Lunev12.86%112.50%
Total35100.00%8100.00%

static struct pernet_operations igmp6_net_ops = { .init = igmp6_net_init, .exit = igmp6_net_exit, };
int __init igmp6_init(void) { return register_pernet_subsys(&igmp6_net_ops); }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Lezcano15100.00%1100.00%
Total15100.00%1100.00%


void igmp6_cleanup(void) { unregister_pernet_subsys(&igmp6_net_ops); }

Contributors

PersonTokensPropCommitsCommitProp
Daniel Lezcano13100.00%1100.00%
Total13100.00%1100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
David L Stevens880558.85%2411.65%
Hideaki Yoshifuji / 吉藤英明170711.41%3014.56%
Linus Torvalds (pre-git)11197.48%209.71%
Daniel Borkmann7645.11%115.34%
Hannes Frederic Sowa3682.46%52.43%
Daniel Lezcano3372.25%31.46%
Américo Wang3112.08%73.40%
Eric Dumazet3012.01%83.88%
Hangbin Liu2111.41%41.94%
David S. Miller1420.95%83.88%
Yan Zheng1030.69%31.46%
Flavio Leitner940.63%10.49%
Madhu Challa890.59%20.97%
Arnaldo Carvalho de Melo700.47%83.88%
Moni Shoua690.46%10.49%
Al Viro400.27%41.94%
Pavel Emelyanov370.25%31.46%
Neil Horman360.24%20.97%
Herbert Xu340.23%10.49%
Denis V. Lunev320.21%73.40%
Linus Torvalds270.18%31.46%
Randy Dunlap260.17%10.49%
Gao Feng250.17%20.97%
Alexey Dobriyan210.14%41.94%
Shirley Ma200.13%10.49%
Eric W. Biedermann150.10%41.94%
Li Wei120.08%10.49%
Simon Horman120.08%10.49%
Stephen Hemminger110.07%20.97%
Sabrina Dubroca110.07%10.49%
Chris Wright100.07%10.49%
Adrian Bunk90.06%20.97%
Andrew Morton90.06%20.97%
Alexey Kuznetsov80.05%10.49%
Joe Perches70.05%31.46%
Ian Morris70.05%10.49%
Benjamin Poirier60.04%10.49%
Jan Oravec60.04%10.49%
Marcelo Ricardo Leitner50.03%10.49%
Harvey Harrison50.03%20.97%
Krishna Kumar50.03%10.49%
Aruna-Hewapathirane50.03%10.49%
Lai Jiangshan40.03%10.49%
Salam Noureddine30.02%10.49%
Tejun Heo30.02%10.49%
Zheng Yan20.01%10.49%
Arjan van de Ven20.01%10.49%
Jan Engelhardt20.01%10.49%
Patrick McHardy20.01%10.49%
Jean Sacren20.01%10.49%
Philippe De Muyter20.01%10.49%
Stephen Rothwell20.01%10.49%
Ingo Oeser20.01%10.49%
Li RongQing20.01%20.97%
Rusty Russell10.01%10.49%
Jiri Pirko10.01%10.49%
Brian Haley10.01%10.49%
Denis Lukianov10.01%10.49%
Total14963100.00%206100.00%
Directory: net/ipv6
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.