cregit-Linux how code gets into the kernel

Release 4.11 net/ipv4/ipmr.c

Directory: net/ipv4
/*
 *      IP multicast routing support for mrouted 3.6/3.8
 *
 *              (c) 1995 Alan Cox, <alan@lxorguk.ukuu.org.uk>
 *        Linux Consultancy and Custom Driver Development
 *
 *      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.
 *
 *      Fixes:
 *      Michael Chastain        :       Incorrect size of copying.
 *      Alan Cox                :       Added the cache manager code
 *      Alan Cox                :       Fixed the clone/copy bug and device race.
 *      Mike McLagan            :       Routing by source
 *      Malcolm Beattie         :       Buffer handling fixes.
 *      Alexey Kuznetsov        :       Double buffer free and other fixes.
 *      SVR Anand               :       Fixed several multicast bugs and problems.
 *      Alexey Kuznetsov        :       Status, optimisations and more.
 *      Brad Parker             :       Better behaviour on mrouted upcall
 *                                      overflow.
 *      Carlos Picoto           :       PIMv1 Support
 *      Pavlin Ivanov Radoslavov:       PIMv2 Registers must checksum only PIM header
 *                                      Relax this requirement to work with older peers.
 *
 */

#include <linux/uaccess.h>
#include <linux/types.h>
#include <linux/capability.h>
#include <linux/errno.h>
#include <linux/timer.h>
#include <linux/mm.h>
#include <linux/kernel.h>
#include <linux/fcntl.h>
#include <linux/stat.h>
#include <linux/socket.h>
#include <linux/in.h>
#include <linux/inet.h>
#include <linux/netdevice.h>
#include <linux/inetdevice.h>
#include <linux/igmp.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/mroute.h>
#include <linux/init.h>
#include <linux/if_ether.h>
#include <linux/slab.h>
#include <net/net_namespace.h>
#include <net/ip.h>
#include <net/protocol.h>
#include <linux/skbuff.h>
#include <net/route.h>
#include <net/sock.h>
#include <net/icmp.h>
#include <net/udp.h>
#include <net/raw.h>
#include <linux/notifier.h>
#include <linux/if_arp.h>
#include <linux/netfilter_ipv4.h>
#include <linux/compat.h>
#include <linux/export.h>
#include <net/ip_tunnels.h>
#include <net/checksum.h>
#include <net/netlink.h>
#include <net/fib_rules.h>
#include <linux/netconf.h>
#include <net/nexthop.h>


struct ipmr_rule {
	
struct fib_rule		common;
};


struct ipmr_result {
	
struct mr_table		*mrt;
};

/* Big lock, protecting vif table, mrt cache and mroute socket state.
 * Note that the changes are semaphored via rtnl_lock.
 */

static DEFINE_RWLOCK(mrt_lock);

/* Multicast router control variables */

/* Special spinlock for queue of unresolved entries */
static DEFINE_SPINLOCK(mfc_unres_lock);

/* We return to original Alan's scheme. Hash table of resolved
 * entries is changed only in process context and protected
 * with weak lock mrt_lock. Queue of unresolved entries is protected
 * with strong spinlock mfc_unres_lock.
 *
 * In this case data path is free of exclusive locks at all.
 */


static struct kmem_cache *mrt_cachep __read_mostly;

static struct mr_table *ipmr_new_table(struct net *net, u32 id);
static void ipmr_free_table(struct mr_table *mrt);

static void ip_mr_forward(struct net *net, struct mr_table *mrt,
			  struct sk_buff *skb, struct mfc_cache *cache,
			  int local);
static int ipmr_cache_report(struct mr_table *mrt,
			     struct sk_buff *pkt, vifi_t vifi, int assert);
static int __ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
			      struct mfc_cache *c, struct rtmsg *rtm);
static void mroute_netlink_event(struct mr_table *mrt, struct mfc_cache *mfc,
				 int cmd);
static void mroute_clean_tables(struct mr_table *mrt, bool all);
static void ipmr_expire_process(unsigned long arg);

#ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES

#define ipmr_for_each_table(mrt, net) \
	list_for_each_entry_rcu(mrt, &net->ipv4.mr_tables, list)


static struct mr_table *ipmr_get_table(struct net *net, u32 id) { struct mr_table *mrt; ipmr_for_each_table(mrt, net) { if (mrt->id == id) return mrt; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy2865.12%133.33%
Wang Chen1227.91%133.33%
Benjamin Thery36.98%133.33%
Total43100.00%3100.00%


static int ipmr_fib_lookup(struct net *net, struct flowi4 *flp4, struct mr_table **mrt) { int err; struct ipmr_result res; struct fib_lookup_arg arg = { .result = &res, .flags = FIB_LOOKUP_NOREF, }; /* update flow if oif or iif point to device enslaved to l3mdev */ l3mdev_update_flow(net, flowi4_to_flowi(flp4)); err = fib_rules_lookup(net->ipv4.mr_rules_ops, flowi4_to_flowi(flp4), 0, &arg); if (err < 0) return err; *mrt = res.mrt; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy6567.01%116.67%
David Ahern1111.34%116.67%
Hannes Frederic Sowa99.28%116.67%
David S. Miller66.19%116.67%
Wang Chen44.12%116.67%
Stephen Hemminger22.06%116.67%
Total97100.00%6100.00%


static int ipmr_rule_action(struct fib_rule *rule, struct flowi *flp, int flags, struct fib_lookup_arg *arg) { struct ipmr_result *res = arg->result; struct mr_table *mrt; switch (rule->action) { case FR_ACT_TO_TBL: break; case FR_ACT_UNREACHABLE: return -ENETUNREACH; case FR_ACT_PROHIBIT: return -EACCES; case FR_ACT_BLACKHOLE: default: return -EINVAL; } arg->table = fib_rule_get_table(rule, arg); mrt = ipmr_get_table(rule->fr_net, arg->table); if (!mrt) return -EAGAIN; res->mrt = mrt; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy10188.60%133.33%
David Ahern1210.53%133.33%
Ian Morris10.88%133.33%
Total114100.00%3100.00%


static int ipmr_rule_match(struct fib_rule *rule, struct flowi *fl, int flags) { return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy22100.00%1100.00%
Total22100.00%1100.00%

static const struct nla_policy ipmr_rule_policy[FRA_MAX + 1] = { FRA_GENERIC_POLICY, };
static int ipmr_rule_configure(struct fib_rule *rule, struct sk_buff *skb, struct fib_rule_hdr *frh, struct nlattr **tb) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy30100.00%1100.00%
Total30100.00%1100.00%


static int ipmr_rule_compare(struct fib_rule *rule, struct fib_rule_hdr *frh, struct nlattr **tb) { return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy25100.00%1100.00%
Total25100.00%1100.00%


static int ipmr_rule_fill(struct fib_rule *rule, struct sk_buff *skb, struct fib_rule_hdr *frh) { frh->dst_len = 0; frh->src_len = 0; frh->tos = 0; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy42100.00%1100.00%
Total42100.00%1100.00%

static const struct fib_rules_ops __net_initconst ipmr_rules_ops_template = { .family = RTNL_FAMILY_IPMR, .rule_size = sizeof(struct ipmr_rule), .addr_size = sizeof(u32), .action = ipmr_rule_action, .match = ipmr_rule_match, .configure = ipmr_rule_configure, .compare = ipmr_rule_compare, .fill = ipmr_rule_fill, .nlgroup = RTNLGRP_IPV4_RULE, .policy = ipmr_rule_policy, .owner = THIS_MODULE, };
static int __net_init ipmr_rules_init(struct net *net) { struct fib_rules_ops *ops; struct mr_table *mrt; int err; ops = fib_rules_register(&ipmr_rules_ops_template, net); if (IS_ERR(ops)) return PTR_ERR(ops); INIT_LIST_HEAD(&net->ipv4.mr_tables); mrt = ipmr_new_table(net, RT_TABLE_DEFAULT); if (IS_ERR(mrt)) { err = PTR_ERR(mrt); goto err1; } err = fib_default_rule_add(ops, 0x7fff, RT_TABLE_DEFAULT, 0); if (err < 0) goto err2; net->ipv4.mr_rules_ops = ops; return 0; err2: ipmr_free_table(mrt); err1: fib_rules_unregister(ops); return err; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy12894.12%133.33%
Nikolay Aleksandrov75.15%133.33%
Américo Wang10.74%133.33%
Total136100.00%3100.00%


static void __net_exit ipmr_rules_exit(struct net *net) { struct mr_table *mrt, *next; rtnl_lock(); list_for_each_entry_safe(mrt, next, &net->ipv4.mr_tables, list) { list_del(&mrt->list); ipmr_free_table(mrt); } fib_rules_unregister(net->ipv4.mr_rules_ops); rtnl_unlock(); }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy4371.67%120.00%
Eric Dumazet1016.67%120.00%
Américo Wang610.00%240.00%
Francesco Ruggeri11.67%120.00%
Total60100.00%5100.00%

#else #define ipmr_for_each_table(mrt, net) \ for (mrt = net->ipv4.mrt; mrt; mrt = NULL)
static struct mr_table *ipmr_get_table(struct net *net, u32 id) { return net->ipv4.mrt; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy23100.00%1100.00%
Total23100.00%1100.00%


static int ipmr_fib_lookup(struct net *net, struct flowi4 *flp4, struct mr_table **mrt) { *mrt = net->ipv4.mrt; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy3294.12%150.00%
David S. Miller25.88%150.00%
Total34100.00%2100.00%


static int __net_init ipmr_rules_init(struct net *net) { struct mr_table *mrt; mrt = ipmr_new_table(net, RT_TABLE_DEFAULT); if (IS_ERR(mrt)) return PTR_ERR(mrt); net->ipv4.mrt = mrt; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy2958.00%150.00%
Nikolay Aleksandrov2142.00%150.00%
Total50100.00%2100.00%


static void __net_exit ipmr_rules_exit(struct net *net) { rtnl_lock(); ipmr_free_table(net->ipv4.mrt); net->ipv4.mrt = NULL; rtnl_unlock(); }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy2057.14%133.33%
Américo Wang1440.00%133.33%
Francesco Ruggeri12.86%133.33%
Total35100.00%3100.00%

#endif
static inline int ipmr_hash_cmp(struct rhashtable_compare_arg *arg, const void *ptr) { const struct mfc_cache_cmp_arg *cmparg = arg->key; struct mfc_cache *c = (struct mfc_cache *)ptr; return cmparg->mfc_mcastgrp != c->mfc_mcastgrp || cmparg->mfc_origin != c->mfc_origin; }

Contributors

PersonTokensPropCommitsCommitProp
Nikolay Aleksandrov56100.00%1100.00%
Total56100.00%1100.00%

static const struct rhashtable_params ipmr_rht_params = { .head_offset = offsetof(struct mfc_cache, mnode), .key_offset = offsetof(struct mfc_cache, cmparg), .key_len = sizeof(struct mfc_cache_cmp_arg), .nelem_hint = 3, .locks_mul = 1, .obj_cmpfn = ipmr_hash_cmp, .automatic_shrinking = true, };
static struct mr_table *ipmr_new_table(struct net *net, u32 id) { struct mr_table *mrt; /* "pimreg%u" should not exceed 16 bytes (IFNAMSIZ) */ if (id != RT_TABLE_DEFAULT && id >= 1000000000) return ERR_PTR(-EINVAL); mrt = ipmr_get_table(net, id); if (mrt) return mrt; mrt = kzalloc(sizeof(*mrt), GFP_KERNEL); if (!mrt) return ERR_PTR(-ENOMEM); write_pnet(&mrt->net, net); mrt->id = id; rhltable_init(&mrt->mfc_hash, &ipmr_rht_params); INIT_LIST_HEAD(&mrt->mfc_cache_list); INIT_LIST_HEAD(&mrt->mfc_unres_queue); setup_timer(&mrt->ipmr_expire_timer, ipmr_expire_process, (unsigned long)mrt); mrt->mroute_reg_vif_num = -1; #ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES list_add_tail_rcu(&mrt->list, &net->ipv4.mr_tables); #endif return mrt; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy13378.70%240.00%
Nikolay Aleksandrov3520.71%240.00%
Ian Morris10.59%120.00%
Total169100.00%5100.00%


static void ipmr_free_table(struct mr_table *mrt) { del_timer_sync(&mrt->ipmr_expire_timer); mroute_clean_tables(mrt, true); rhltable_destroy(&mrt->mfc_hash); kfree(mrt); }

Contributors

PersonTokensPropCommitsCommitProp
Francesco Ruggeri2974.36%133.33%
Nikolay Aleksandrov1025.64%266.67%
Total39100.00%3100.00%

/* Service routines creating virtual interfaces: DVMRP tunnels and PIMREG */
static void ipmr_del_tunnel(struct net_device *dev, struct vifctl *v) { struct net *net = dev_net(dev); dev_close(dev); dev = __dev_get_by_name(net, "tunl0"); if (dev) { const struct net_device_ops *ops = dev->netdev_ops; struct ifreq ifr; struct ip_tunnel_parm p; memset(&p, 0, sizeof(p)); p.iph.daddr = v->vifc_rmt_addr.s_addr; p.iph.saddr = v->vifc_lcl_addr.s_addr; p.iph.version = 4; p.iph.ihl = 5; p.iph.protocol = IPPROTO_IPIP; sprintf(p.name, "dvmrp%d", v->vifc_vifi); ifr.ifr_ifru.ifru_data = (__force void __user *)&p; if (ops->ndo_do_ioctl) { mm_segment_t oldfs = get_fs(); set_fs(KERNEL_DS); ops->ndo_do_ioctl(dev, &ifr, SIOCDELTUNNEL); set_fs(oldfs); } } }

Contributors

PersonTokensPropCommitsCommitProp
Wang Chen15582.01%133.33%
Stephen Hemminger2312.17%133.33%
Benjamin Thery115.82%133.33%
Total189100.00%3100.00%

/* Initialize ipmr pimreg/tunnel in_device */
static bool ipmr_init_vif_indev(const struct net_device *dev) { struct in_device *in_dev; ASSERT_RTNL(); in_dev = __in_dev_get_rtnl(dev); if (!in_dev) return false; ipv4_devconf_setall(in_dev); neigh_parms_data_state_setall(in_dev->arp_parms); IPV4_DEVCONF(in_dev->cnf, RP_FILTER) = 0; return true; }

Contributors

PersonTokensPropCommitsCommitProp
Nikolay Aleksandrov61100.00%1100.00%
Total61100.00%1100.00%


static struct net_device *ipmr_new_tunnel(struct net *net, struct vifctl *v) { struct net_device *dev; dev = __dev_get_by_name(net, "tunl0"); if (dev) { const struct net_device_ops *ops = dev->netdev_ops; int err; struct ifreq ifr; struct ip_tunnel_parm p; memset(&p, 0, sizeof(p)); p.iph.daddr = v->vifc_rmt_addr.s_addr; p.iph.saddr = v->vifc_lcl_addr.s_addr; p.iph.version = 4; p.iph.ihl = 5; p.iph.protocol = IPPROTO_IPIP; sprintf(p.name, "dvmrp%d", v->vifc_vifi); ifr.ifr_ifru.ifru_data = (__force void __user *)&p; if (ops->ndo_do_ioctl) { mm_segment_t oldfs = get_fs(); set_fs(KERNEL_DS); err = ops->ndo_do_ioctl(dev, &ifr, SIOCADDTUNNEL); set_fs(oldfs); } else { err = -EOPNOTSUPP; } dev = NULL; if (err == 0 && (dev = __dev_get_by_name(net, p.name)) != NULL) { dev->flags |= IFF_MULTICAST; if (!ipmr_init_vif_indev(dev)) goto failure; if (dev_open(dev)) goto failure; dev_hold(dev); } } return dev; failure: unregister_netdevice(dev); return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)21380.08%535.71%
Stephen Hemminger3111.65%214.29%
Benjamin Thery72.63%17.14%
Wang Chen51.88%17.14%
Nikolay Aleksandrov51.88%214.29%
Eric Dumazet20.75%17.14%
Eric W. Biedermann20.75%17.14%
Ian Morris10.38%17.14%
Total266100.00%14100.00%

#if defined(CONFIG_IP_PIMSM_V1) || defined(CONFIG_IP_PIMSM_V2)
static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev) { struct net *net = dev_net(dev); struct mr_table *mrt; struct flowi4 fl4 = { .flowi4_oif = dev->ifindex, .flowi4_iif = skb->skb_iif ? : LOOPBACK_IFINDEX, .flowi4_mark = skb->mark, }; int err; err = ipmr_fib_lookup(net, &fl4, &mrt); if (err < 0) { kfree_skb(skb); return err; } read_lock(&mrt_lock); dev->stats.tx_bytes += skb->len; dev->stats.tx_packets++; ipmr_cache_report(mrt, skb, mrt->mroute_reg_vif_num, IGMPMSG_WHOLEPKT); read_unlock(&mrt_lock); kfree_skb(skb); return NETDEV_TX_OK; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)5538.46%637.50%
Patrick McHardy5437.76%318.75%
Benjamin Thery139.09%212.50%
Ben Greear74.90%16.25%
David S. Miller64.20%16.25%
Pavel Emelyanov42.80%16.25%
Cong Wang32.10%16.25%
Stephen Hemminger10.70%16.25%
Total143100.00%16100.00%


static int reg_vif_get_iflink(const struct net_device *dev) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Nicolas Dichtel15100.00%1100.00%
Total15100.00%1100.00%

static const struct net_device_ops reg_vif_netdev_ops = { .ndo_start_xmit = reg_vif_xmit, .ndo_get_iflink = reg_vif_get_iflink, };
static void reg_vif_setup(struct net_device *dev) { dev->type = ARPHRD_PIMREG; dev->mtu = ETH_DATA_LEN - sizeof(struct iphdr) - 8; dev->flags = IFF_NOARP; dev->netdev_ops = &reg_vif_netdev_ops; dev->destructor = free_netdev; dev->features |= NETIF_F_NETNS_LOCAL; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)3053.57%436.36%
David S. Miller1119.64%19.09%
Stephen Hemminger712.50%327.27%
Thomas Goff610.71%19.09%
Himangi Saraogi11.79%19.09%
Kris Katterjohn11.79%19.09%
Total56100.00%11100.00%


static struct net_device *ipmr_reg_vif(struct net *net, struct mr_table *mrt) { struct net_device *dev; char name[IFNAMSIZ]; if (mrt->id == RT_TABLE_DEFAULT) sprintf(name, "pimreg"); else sprintf(name, "pimreg%u", mrt->id); dev = alloc_netdev(0, name, NET_NAME_UNKNOWN, reg_vif_setup); if (!dev) return NULL; dev_net_set(dev, net); if (register_netdevice(dev)) { free_netdev(dev); return NULL; } if (!ipmr_init_vif_indev(dev)) goto failure; if (dev_open(dev)) goto failure; dev_hold(dev); return dev; failure: unregister_netdevice(dev); return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)4532.14%321.43%
Patrick McHardy3927.86%17.14%
Stephen Hemminger2115.00%17.14%
Thomas Goff117.86%17.14%
Raj75.00%17.14%
Wang Chen53.57%17.14%
Nikolay Aleksandrov42.86%17.14%
Eric Dumazet32.14%17.14%
Tom Gundersen21.43%17.14%
Ian Morris10.71%17.14%
Al Viro10.71%17.14%
Pavel Emelyanov10.71%17.14%
Total140100.00%14100.00%

/* called with rcu_read_lock() */
static int __pim_rcv(struct mr_table *mrt, struct sk_buff *skb, unsigned int pimlen) { struct net_device *reg_dev = NULL; struct iphdr *encap; encap = (struct iphdr *)(skb_transport_header(skb) + pimlen); /* Check that: * a. packet is really sent to a multicast group * b. packet is not a NULL-REGISTER * c. packet is not truncated */ if (!ipv4_is_multicast(encap->daddr) || encap->tot_len == 0 || ntohs(encap->tot_len) + pimlen > skb->len) return 1; read_lock(&mrt_lock); if (mrt->mroute_reg_vif_num >= 0) reg_dev = mrt->vif_table[mrt->mroute_reg_vif_num].dev; read_unlock(&mrt_lock); if (!reg_dev) return 1; skb->mac_header = skb->network_header; skb_pull(skb, (u8 *)encap - skb->data); skb_reset_network_header(skb); skb->protocol = htons(ETH_P_IP); skb->ip_summed = CHECKSUM_NONE; skb_tunnel_rx(skb, reg_dev, dev_net(reg_dev)); netif_rx(skb); return NET_RX_SUCCESS; }

Contributors

PersonTokensPropCommitsCommitProp
Nikolay Aleksandrov185100.00%2100.00%
Total185100.00%2100.00%

#else
static struct net_device *ipmr_reg_vif(struct net *net, struct mr_table *mrt) { return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Nikolay Aleksandrov21100.00%1100.00%
Total21100.00%1100.00%

#endif /** * vif_delete - Delete a VIF entry * @notify: Set to 1, if the caller is a notifier_call */
static int vif_delete(struct mr_table *mrt, int vifi, int notify, struct list_head *head) { struct vif_device *v; struct net_device *dev; struct in_device *in_dev; if (vifi < 0 || vifi >= mrt->maxvif) return -EADDRNOTAVAIL; v = &mrt->vif_table[vifi]; write_lock_bh(&mrt_lock); dev = v->dev; v->dev = NULL; if (!dev) { write_unlock_bh(&mrt_lock); return -EADDRNOTAVAIL; } if (vifi == mrt->mroute_reg_vif_num) mrt->mroute_reg_vif_num = -1; if (vifi + 1 == mrt->maxvif) { int tmp; for (tmp = vifi - 1; tmp >= 0; tmp--) { if (VIF_EXISTS(mrt, tmp)) break; } mrt->maxvif = tmp+1; } write_unlock_bh(&mrt_lock); dev_set_allmulti(dev, -1); in_dev = __in_dev_get_rtnl(dev); if (in_dev) { IPV4_DEVCONF(in_dev->cnf, MC_FORWARDING)--; inet_netconf_notify_devconf(dev_net(dev), NETCONFA_MC_FORWARDING, dev->ifindex, &in_dev->cnf); ip_rt_multicast_event(in_dev); } if (v->flags & (VIFF_TUNNEL | VIFF_REGISTER) && !notify) unregister_netdevice_queue(dev, head); dev_put(dev); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)19074.80%533.33%
Nicolas Dichtel197.48%16.67%
Benjamin Thery124.72%320.00%
Eric Dumazet124.72%213.33%
Patrick McHardy93.54%16.67%
Herbert Xu62.36%213.33%
Wang Chen62.36%16.67%
Total254100.00%15100.00%


static void ipmr_cache_free_rcu(struct rcu_head *head) { struct mfc_cache *c = container_of(head, struct mfc_cache, rcu); kmem_cache_free(mrt_cachep, c); }

Contributors

PersonTokensPropCommitsCommitProp
Eric Dumazet33100.00%1100.00%
Total33100.00%1100.00%


static inline void ipmr_cache_free(struct mfc_cache *c) { call_rcu(&c->rcu, ipmr_cache_free_rcu); }

Contributors

PersonTokensPropCommitsCommitProp
Benjamin Thery1672.73%150.00%
Eric Dumazet627.27%150.00%
Total22100.00%2100.00%

/* Destroy an unresolved cache entry, killing queued skbs * and reporting error to netlink readers. */
static void ipmr_destroy_unres(struct mr_table *mrt, struct mfc_cache *c) { struct net *net = read_pnet(&mrt->net); struct sk_buff *skb; struct nlmsgerr *e; atomic_dec(&mrt->cache_resolve_queue_len); while ((skb = skb_dequeue(&c->mfc_un.unres.unresolved))) { if (ip_hdr(skb)->version == 0) { struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct iphdr)); nlh->nlmsg_type = NLMSG_ERROR; nlh->nlmsg_len = nlmsg_msg_size(sizeof(struct nlmsgerr)); skb_trim(skb, nlh->nlmsg_len); e = nlmsg_data(nlh); e->error = -ETIMEDOUT; memset(&e->msg, 0, sizeof(e->msg)); rtnl_unicast(skb, net, NETLINK_CB(skb).portid); } else { kfree_skb(skb); } } ipmr_cache_free(c); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)12968.98%529.41%
Patrick McHardy4524.06%423.53%
Benjamin Thery31.60%211.76%
Arnaldo Carvalho de Melo31.60%15.88%
Eric Dumazet21.07%15.88%
Hong Zhi Guo21.07%15.88%
Thomas Graf10.53%15.88%
Eric W. Biedermann10.53%15.88%
Denis V. Lunev10.53%15.88%
Total187100.00%17100.00%

/* Timer process for the unresolved queue. */
static void ipmr_expire_process(unsigned long arg) { struct mr_table *mrt = (struct mr_table *)arg; unsigned long now; unsigned long expires; struct mfc_cache *c, *next; if (!spin_trylock(&mfc_unres_lock)) { mod_timer(&mrt->ipmr_expire_timer, jiffies+HZ/10); return; } if (list_empty(&mrt->mfc_unres_queue)) goto out; now = jiffies; expires = 10*HZ; list_for_each_entry_safe(c, next, &mrt->mfc_unres_queue, list) { if (time_after(c->mfc_un.unres.expires, now)) { unsigned long interval = c->mfc_un.unres.expires - now; if (interval < expires) expires = interval; continue; } list_del(&c->list); mroute_netlink_event(mrt, c, RTM_DELROUTE); ipmr_destroy_unres(mrt, c); } if (!list_empty(&mrt->mfc_unres_queue)) mod_timer(&mrt->ipmr_expire_timer, jiffies + expires); out: spin_unlock(&mfc_unres_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)11960.71%436.36%
Patrick McHardy4824.49%436.36%
Stephen Hemminger189.18%19.09%
Nicolas Dichtel94.59%19.09%
Benjamin Thery21.02%19.09%
Total196100.00%11100.00%

/* Fill oifs list. It is called under write locked mrt_lock. */
static void ipmr_update_thresholds(struct mr_table *mrt, struct mfc_cache *cache, unsigned char *ttls) { int vifi; cache->mfc_un.res.minvif = MAXVIFS; cache->mfc_un.res.maxvif = 0; memset(cache->mfc_un.res.ttls, 255, MAXVIFS); for (vifi = 0; vifi < mrt->maxvif; vifi++) { if (VIF_EXISTS(mrt, vifi) && ttls[vifi] && ttls[vifi] < 255) { cache->mfc_un.res.ttls[vifi] = ttls[vifi]; if (cache->mfc_un.res.minvif > vifi) cache->mfc_un.res.minvif = vifi; if (cache->mfc_un.res.maxvif <= vifi) cache->mfc_un.res.maxvif = vifi + 1; } } cache->mfc_un.res.lastuse = jiffies; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)15188.30%440.00%
Nikolay Aleksandrov105.85%110.00%
Patrick McHardy74.09%220.00%
Benjamin Thery21.17%220.00%
Baruch Even10.58%110.00%
Total171100.00%10100.00%


static int vif_add(struct net *net, struct mr_table *mrt, struct vifctl *vifc, int mrtsock) { int vifi = vifc->vifc_vifi; struct vif_device *v = &mrt->vif_table[vifi]; struct net_device *dev; struct in_device *in_dev; int err; /* Is vif busy ? */ if (VIF_EXISTS(mrt, vifi)) return -EADDRINUSE; switch (vifc->vifc_flags) { case VIFF_REGISTER: if (!ipmr_pimsm_enabled()) return -EINVAL; /* Special Purpose VIF in PIM * All the packets will be sent to the daemon */ if (mrt->mroute_reg_vif_num >= 0) return -EADDRINUSE; dev = ipmr_reg_vif(net, mrt); if (!dev) return -ENOBUFS; err = dev_set_allmulti(dev, 1); if (err) { unregister_netdevice(dev); dev_put(dev); return err; } break; case VIFF_TUNNEL: dev = ipmr_new_tunnel(net, vifc); if (!dev) return -ENOBUFS; err = dev_set_allmulti(dev, 1); if (err) { ipmr_del_tunnel(dev, vifc); dev_put(dev); return err; } break; case VIFF_USE_IFINDEX: case 0: if (vifc->vifc_flags == VIFF_USE_IFINDEX) { dev = dev_get_by_index(net, vifc->vifc_lcl_ifindex); if (dev && !__in_dev_get_rtnl(dev)) { dev_put(dev); return -EADDRNOTAVAIL; } } else { dev = ip_dev_find(net, vifc->vifc_lcl_addr.s_addr); } if (!dev) return -EADDRNOTAVAIL; err = dev_set_allmulti(dev, 1); if (err) { dev_put(dev); return err; } break; default: return -EINVAL; } in_dev = __in_dev_get_rtnl(dev); if (!in_dev) { dev_put(dev); return -EADDRNOTAVAIL; } IPV4_DEVCONF(in_dev->cnf, MC_FORWARDING)++; inet_netconf_notify_devconf(net, NETCONFA_MC_FORWARDING, dev->ifindex, &in_dev->cnf); ip_rt_multicast_event(in_dev); /* Fill in the VIF structures */ v->rate_limit = vifc->vifc_rate_limit; v->local = vifc->vifc_lcl_addr.s_addr; v->remote = vifc->vifc_rmt_addr.s_addr; v->flags = vifc->vifc_flags; if (!mrtsock) v->flags |= VIFF_STATIC; v->threshold = vifc->vifc_threshold; v->bytes_in = 0; v->bytes_out = 0; v->pkt_in = 0; v->pkt_out = 0; v->link = dev->ifindex; if (v->flags & (VIFF_TUNNEL | VIFF_REGISTER)) v->link = dev_get_iflink(dev); /* And finish update writing critical data */ write_lock_bh(&mrt_lock); v->dev = dev; if (v->flags & VIFF_REGISTER) mrt->mroute_reg_vif_num = vifi; if (vifi+1 > mrt->maxvif) mrt->maxvif = vifi+1; write_unlock_bh(&mrt_lock); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)30959.08%416.67%
Wang Chen8416.06%28.33%
Ilia K428.03%14.17%
Nicolas Dichtel193.63%28.33%
Benjamin Thery163.06%312.50%
Patrick McHardy132.49%28.33%
Nikolay Aleksandrov112.10%28.33%
Eric Dumazet112.10%28.33%
Dan Carpenter71.34%14.17%
Herbert Xu61.15%28.33%
Thomas Goff30.57%14.17%
Ian Morris10.19%14.17%
Denis V. Lunev10.19%14.17%
Total523100.00%24100.00%

/* called with rcu_read_lock() */
static struct mfc_cache *ipmr_cache_find(struct mr_table *mrt, __be32 origin, __be32 mcastgrp) { struct mfc_cache_cmp_arg arg = { .mfc_mcastgrp = mcastgrp, .mfc_origin = origin }; struct rhlist_head *tmp, *list; struct mfc_cache *c; list = rhltable_lookup(&mrt->mfc_hash, &arg, ipmr_rht_params); rhl_for_each_entry_rcu(c, tmp, list, mnode) return c; return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Nikolay Aleksandrov3949.37%114.29%
Linus Torvalds (pre-git)2329.11%228.57%
Patrick McHardy1215.19%228.57%
Benjamin Thery33.80%114.29%
Al Viro22.53%114.29%
Total79100.00%7100.00%

/* Look for a (*,*,oif) entry */
static struct mfc_cache *ipmr_cache_find_any_parent(struct mr_table *mrt, int vifi) { struct mfc_cache_cmp_arg arg = { .mfc_mcastgrp = htonl(INADDR_ANY), .mfc_origin = htonl(INADDR_ANY) }; struct rhlist_head *tmp, *list; struct mfc_cache *c; list = rhltable_lookup(&mrt->mfc_hash, &arg, ipmr_rht_params); rhl_for_each_entry_rcu(c, tmp, list, mnode) if (c->mfc_un.res.ttls[vifi] < 255) return c; return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Nicolas Dichtel5758.76%266.67%
Nikolay Aleksandrov4041.24%133.33%
Total97100.00%3100.00%

/* Look for a (*,G) entry */
static struct mfc_cache *ipmr_cache_find_any(struct mr_table *mrt, __be32 mcastgrp, int vifi) { struct mfc_cache_cmp_arg arg = { .mfc_mcastgrp = mcastgrp, .mfc_origin = htonl(INADDR_ANY) }; struct rhlist_head *tmp, *list; struct mfc_cache *c, *proxy; if (mcastgrp == htonl(INADDR_ANY)) goto skip; list = rhltable_lookup(&mrt->mfc_hash, &arg, ipmr_rht_params); rhl_for_each_entry_rcu(c, tmp, list, mnode) { if (c->mfc_un.res.ttls[vifi] < 255) return c; /* It's ok if the vifi is part of the static tree */ proxy = ipmr_cache_find_any_parent(mrt, c->mfc_parent); if (proxy && proxy->mfc_un.res.ttls[vifi] < 255) return c; } skip: return ipmr_cache_find_any_parent(mrt, vifi); }

Contributors

PersonTokensPropCommitsCommitProp
Nicolas Dichtel11172.55%266.67%
Nikolay Aleksandrov4227.45%133.33%
Total153100.00%3100.00%

/* Look for a (S,G,iif) entry if parent != -1 */
static struct mfc_cache *ipmr_cache_find_parent(struct mr_table *mrt, __be32 origin, __be32 mcastgrp, int parent) { struct mfc_cache_cmp_arg arg = { .mfc_mcastgrp = mcastgrp, .mfc_origin = origin, }; struct rhlist_head *tmp, *list; struct mfc_cache *c; list = rhltable_lookup(&mrt->mfc_hash, &arg, ipmr_rht_params); rhl_for_each_entry_rcu(c, tmp, list, mnode) if (parent == -1 || parent == c->mfc_parent) return c; return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Nikolay Aleksandrov95100.00%1100.00%
Total95100.00%1100.00%

/* Allocate a multicast cache entry */
static struct mfc_cache *ipmr_cache_alloc(void) { struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_KERNEL); if (c) { c->mfc_un.res.last_assert = jiffies - MFC_ASSERT_THRESH - 1; c->mfc_un.res.minvif = MAXVIFS; } return c; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)3767.27%240.00%
Thomas Goff1629.09%120.00%
Patrick McHardy11.82%120.00%
Robert P. J. Day11.82%120.00%
Total55100.00%5100.00%


static struct mfc_cache *ipmr_cache_alloc_unres(void) { struct mfc_cache *c = kmem_cache_zalloc(mrt_cachep, GFP_ATOMIC); if (c) { skb_queue_head_init(&c->mfc_un.unres.unresolved); c->mfc_un.unres.expires = jiffies + 10*HZ; } return c; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)5392.98%240.00%
Eric Dumazet23.51%120.00%
Robert P. J. Day11.75%120.00%
Patrick McHardy11.75%120.00%
Total57100.00%5100.00%

/* A cache entry has gone into a resolved state from queued */
static void ipmr_cache_resolve(struct net *net, struct mr_table *mrt, struct mfc_cache *uc, struct mfc_cache *c) { struct sk_buff *skb; struct nlmsgerr *e; /* Play the pending entries through our router */ while ((skb = __skb_dequeue(&uc->mfc_un.unres.unresolved))) { if (ip_hdr(skb)->version == 0) { struct nlmsghdr *nlh = (struct nlmsghdr *)skb_pull(skb, sizeof(struct iphdr)); if (__ipmr_fill_mroute(mrt, skb, c, nlmsg_data(nlh)) > 0) { nlh->nlmsg_len = skb_tail_pointer(skb) - (u8 *)nlh; } else { nlh->nlmsg_type = NLMSG_ERROR; nlh->nlmsg_len = nlmsg_msg_size(sizeof(struct nlmsgerr)); skb_trim(skb, nlh->nlmsg_len); e = nlmsg_data(nlh); e->error = -EMSGSIZE; memset(&e->msg, 0, sizeof(e->msg)); } rtnl_unicast(skb, net, NETLINK_CB(skb).portid); } else { ip_mr_forward(net, mrt, skb, c, 0); } } }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)15972.94%215.38%
Patrick McHardy4420.18%430.77%
Arnaldo Carvalho de Melo62.75%215.38%
Eric Dumazet31.38%17.69%
Hong Zhi Guo31.38%17.69%
Thomas Graf10.46%17.69%
Eric W. Biedermann10.46%17.69%
Denis V. Lunev10.46%17.69%
Total218100.00%13100.00%

/* Bounce a cache query up to mrouted. We could use netlink for this but mrouted * expects the following bizarre scheme. * * Called under mrt_lock. */
static int ipmr_cache_report(struct mr_table *mrt, struct sk_buff *pkt, vifi_t vifi, int assert) { const int ihl = ip_hdrlen(pkt); struct sock *mroute_sk; struct igmphdr *igmp; struct igmpmsg *msg; struct sk_buff *skb; int ret; if (assert == IGMPMSG_WHOLEPKT) skb = skb_realloc_headroom(pkt, sizeof(struct iphdr)); else skb = alloc_skb(128, GFP_ATOMIC); if (!skb) return -ENOBUFS; if (assert == IGMPMSG_WHOLEPKT) { /* Ugly, but we have no choice with this interface. * Duplicate old header, fix ihl, length etc. * And all this only to mangle msg->im_msgtype and * to set msg->im_mbz to "mbz" :-) */ skb_push(skb, sizeof(struct iphdr)); skb_reset_network_header(skb); skb_reset_transport_header(skb); msg = (struct igmpmsg *)skb_network_header(skb); memcpy(msg, skb_network_header(pkt), sizeof(struct iphdr)); msg->im_msgtype = IGMPMSG_WHOLEPKT; msg->im_mbz = 0; msg->im_vif = mrt->mroute_reg_vif_num; ip_hdr(skb)->ihl = sizeof(struct iphdr) >> 2; ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(pkt)->tot_len) + sizeof(struct iphdr)); } else { /* Copy the IP header */ skb_set_network_header(skb, skb->len); skb_put(skb, ihl); skb_copy_to_linear_data(skb, pkt->data, ihl); /* Flag to the kernel this is a route add */ ip_hdr(skb)->protocol = 0; msg = (struct igmpmsg *)skb_network_header(skb); msg->im_vif = vifi; skb_dst_set(skb, dst_clone(skb_dst(pkt))); /* Add our header */ igmp = (struct igmphdr *)skb_put(skb, sizeof(struct igmphdr)); igmp->type = assert; msg->im_msgtype = assert; igmp->code = 0; ip_hdr(skb)->tot_len = htons(skb->len); /* Fix the length */ skb->transport_header = skb->network_header; } rcu_read_lock(); mroute_sk = rcu_dereference(mrt->mroute_sk); if (!mroute_sk) { rcu_read_unlock(); kfree_skb(skb); return -EINVAL; } /* Deliver to mrouted */ ret = sock_queue_rcv_skb(mroute_sk, skb); rcu_read_unlock(); if (ret < 0) { net_warn_ratelimited("mroute: pending queue full, dropping entries\n"); kfree_skb(skb); } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)29472.06%312.00%
Arnaldo Carvalho de Melo4511.03%936.00%
Eric Dumazet327.84%312.00%
Benjamin Thery122.94%312.00%
Nikolay Aleksandrov102.45%14.00%
Simon Horman51.23%14.00%
Patrick McHardy40.98%14.00%
Américo Wang30.74%14.00%
Joe Perches20.49%28.00%
Ian Morris10.25%14.00%
Total408100.00%25100.00%

/* Queue a packet for resolution. It gets locked cache entry! */
static int ipmr_cache_unresolved(struct mr_table *mrt, vifi_t vifi, struct sk_buff *skb) { const struct iphdr *iph = ip_hdr(skb); struct mfc_cache *c; bool found = false; int err; spin_lock_bh(&mfc_unres_lock); list_for_each_entry(c, &mrt->mfc_unres_queue, list) { if (c->mfc_mcastgrp == iph->daddr && c->mfc_origin == iph->saddr) { found = true; break; } } if (!found) { /* Create a new entry if allowable */ if (atomic_read(&mrt->cache_resolve_queue_len) >= 10 || (c = ipmr_cache_alloc_unres()) == NULL) { spin_unlock_bh(&mfc_unres_lock); kfree_skb(skb); return -ENOBUFS; } /* Fill in the new cache entry */ c->mfc_parent = -1; c->mfc_origin = iph->saddr; c->mfc_mcastgrp = iph->daddr; /* Reflect first query at mrouted. */ err = ipmr_cache_report(mrt, skb, vifi, IGMPMSG_NOCACHE); if (err < 0) { /* If the report failed throw the cache entry out - Brad Parker */ spin_unlock_bh(&mfc_unres_lock); ipmr_cache_free(c); kfree_skb(skb); return err; } atomic_inc(&mrt->cache_resolve_queue_len); list_add(&c->list, &mrt->mfc_unres_queue); mroute_netlink_event(mrt, c, RTM_NEWROUTE); if (atomic_read(&mrt->cache_resolve_queue_len) == 1) mod_timer(&mrt->ipmr_expire_timer, c->mfc_un.unres.expires); } /* See if we can append the packet */ if (c->mfc_un.unres.unresolved.qlen > 3) { kfree_skb(skb); err = -ENOBUFS; } else { skb_queue_tail(&c->mfc_un.unres.unresolved, skb); err = 0; } spin_unlock_bh(&mfc_unres_lock); return err; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)21769.77%317.65%
Patrick McHardy309.65%423.53%
Benjamin Thery144.50%317.65%
Nikolay Aleksandrov134.18%15.88%
Andreas Meissner113.54%15.88%
Arnaldo Carvalho de Melo113.54%15.88%
Nicolas Dichtel92.89%15.88%
Eric Dumazet41.29%15.88%
Hideaki Yoshifuji / 吉藤英明10.32%15.88%
David S. Miller10.32%15.88%
Total311100.00%17100.00%

/* MFC cache manipulation by user space mroute daemon */
static int ipmr_mfc_delete(struct mr_table *mrt, struct mfcctl *mfc, int parent) { struct mfc_cache *c; /* The entries are added/deleted only under RTNL */ rcu_read_lock(); c = ipmr_cache_find_parent(mrt, mfc->mfcc_origin.s_addr, mfc->mfcc_mcastgrp.s_addr, parent); rcu_read_unlock(); if (!c) return -ENOENT; rhltable_remove(&mrt->mfc_hash, &c->mnode, ipmr_rht_params); list_del_rcu(&c->list); mroute_netlink_event(mrt, c, RTM_DELROUTE); ipmr_cache_free(c); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)3938.61%110.00%
Nikolay Aleksandrov3332.67%110.00%
Nicolas Dichtel1514.85%220.00%
Patrick McHardy87.92%220.00%
Benjamin Thery43.96%220.00%
Eric Dumazet10.99%110.00%
Stephen Hemminger10.99%110.00%
Total101100.00%10100.00%


static int ipmr_mfc_add(struct net *net, struct mr_table *mrt, struct mfcctl *mfc, int mrtsock, int parent) { struct mfc_cache *uc, *c; bool found; int ret; if (mfc->mfcc_parent >= MAXVIFS) return -ENFILE; /* The entries are added/deleted only under RTNL */ rcu_read_lock(); c = ipmr_cache_find_parent(mrt, mfc->mfcc_origin.s_addr, mfc->mfcc_mcastgrp.s_addr, parent); rcu_read_unlock(); if (c) { write_lock_bh(&mrt_lock); c->mfc_parent = mfc->mfcc_parent; ipmr_update_thresholds(mrt, c, mfc->mfcc_ttls); if (!mrtsock) c->mfc_flags |= MFC_STATIC; write_unlock_bh(&mrt_lock); mroute_netlink_event(mrt, c, RTM_NEWROUTE); return 0; } if (mfc->mfcc_mcastgrp.s_addr != htonl(INADDR_ANY) && !ipv4_is_multicast(mfc->mfcc_mcastgrp.s_addr)) return -EINVAL; c = ipmr_cache_alloc(); if (!c) return -ENOMEM; c->mfc_origin = mfc->mfcc_origin.s_addr; c->mfc_mcastgrp = mfc->mfcc_mcastgrp.s_addr; c->mfc_parent = mfc->mfcc_parent; ipmr_update_thresholds(mrt, c, mfc->mfcc_ttls); if (!mrtsock) c->mfc_flags |= MFC_STATIC; ret = rhltable_insert_key(&mrt->mfc_hash, &c->cmparg, &c->mnode, ipmr_rht_params); if (ret) { pr_err("ipmr: rhtable insert error %d\n", ret); ipmr_cache_free(c); return ret; } list_add_tail_rcu(&c->list, &mrt->mfc_cache_list); /* Check to see if we resolved a queued list. If so we * need to send on the frames and tidy up. */ found = false; spin_lock_bh(&mfc_unres_lock); list_for_each_entry(uc, &mrt->mfc_unres_queue, list) { if (uc->mfc_origin == c->mfc_origin && uc->mfc_mcastgrp == c->mfc_mcastgrp) { list_del(&uc->list); atomic_dec(&mrt->cache_resolve_queue_len); found = true; break; } } if (list_empty(&mrt->mfc_unres_queue)) del_timer(&mrt->ipmr_expire_timer); spin_unlock_bh(&mfc_unres_lock); if (found) { ipmr_cache_resolve(net, mrt, uc, c); ipmr_cache_free(uc); } mroute_netlink_event(mrt, c, RTM_NEWROUTE); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)21953.68%210.00%
Nikolay Aleksandrov6916.91%210.00%
Patrick McHardy6315.44%630.00%
Nicolas Dichtel338.09%315.00%
Benjamin Thery194.66%315.00%
Baruch Even20.49%15.00%
Stephen Hemminger10.25%15.00%
Ian Morris10.25%15.00%
Joe Perches10.25%15.00%
Total408100.00%20100.00%

/* Close the multicast socket, and clear the vif tables etc */
static void mroute_clean_tables(struct mr_table *mrt, bool all) { struct mfc_cache *c, *tmp; LIST_HEAD(list); int i; /* Shut down all active vif entries */ for (i = 0; i < mrt->maxvif; i++) { if (!all && (mrt->vif_table[i].flags & VIFF_STATIC)) continue; vif_delete(mrt, i, 0, &list); } unregister_netdevice_many(&list); /* Wipe the cache */ list_for_each_entry_safe(c, tmp, &mrt->mfc_cache_list, list) { if (!all && (c->mfc_flags & MFC_STATIC)) continue; rhltable_remove(&mrt->mfc_hash, &c->mnode, ipmr_rht_params); list_del_rcu(&c->list); mroute_netlink_event(mrt, c, RTM_DELROUTE); ipmr_cache_free(c); } if (atomic_read(&mrt->cache_resolve_queue_len) != 0) { spin_lock_bh(&mfc_unres_lock); list_for_each_entry_safe(c, tmp, &mrt->mfc_unres_queue, list) { list_del(&c->list); mroute_netlink_event(mrt, c, RTM_DELROUTE); ipmr_destroy_unres(mrt, c); } spin_unlock_bh(&mfc_unres_lock); } }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)9243.60%213.33%
Nikolay Aleksandrov3818.01%213.33%
Patrick McHardy3717.54%320.00%
Nicolas Dichtel188.53%16.67%
Benjamin Thery125.69%320.00%
Eric Dumazet125.69%320.00%
Wang Chen20.95%16.67%
Total211100.00%15100.00%

/* called from ip_ra_control(), before an RCU grace period, * we dont need to call synchronize_rcu() here */
static void mrtsock_destruct(struct sock *sk) { struct net *net = sock_net(sk); struct mr_table *mrt; ASSERT_RTNL(); ipmr_for_each_table(mrt, net) { if (sk == rtnl_dereference(mrt->mroute_sk)) { IPV4_DEVCONF_ALL(net, MC_FORWARDING)--; inet_netconf_notify_devconf(net, NETCONFA_MC_FORWARDING, NETCONFA_IFINDEX_ALL, net->ipv4.devconf_all); RCU_INIT_POINTER(mrt->mroute_sk, NULL); mroute_clean_tables(mrt, false); } } }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)2932.58%214.29%
Patrick McHardy1617.98%214.29%
Nicolas Dichtel1516.85%17.14%
Benjamin Thery1516.85%214.29%
Eric Dumazet44.49%17.14%
Herbert Xu44.49%17.14%
Nikolay Aleksandrov22.25%17.14%
Américo Wang11.12%17.14%
David S. Miller11.12%17.14%
Pavel Emelyanov11.12%17.14%
Stephen Hemminger11.12%17.14%
Total89100.00%14100.00%

/* Socket options and virtual interface manipulation. The whole * virtual interface system is a complete heap, but unfortunately * that's how BSD mrouted happens to think. Maybe one day with a proper * MOSPF/PIM router set up we can clean this up. */
int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, unsigned int optlen) { struct net *net = sock_net(sk); int val, ret = 0, parent = 0; struct mr_table *mrt; struct vifctl vif; struct mfcctl mfc; u32 uval; /* There's one exception to the lock - MRT_DONE which needs to unlock */ rtnl_lock(); if (sk->sk_type != SOCK_RAW || inet_sk(sk)->inet_num != IPPROTO_IGMP) { ret = -EOPNOTSUPP; goto out_unlock; } mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT); if (!mrt) { ret = -ENOENT; goto out_unlock; } if (optname != MRT_INIT) { if (sk != rcu_access_pointer(mrt->mroute_sk) && !ns_capable(net->user_ns, CAP_NET_ADMIN)) { ret = -EACCES; goto out_unlock; } } switch (optname) { case MRT_INIT: if (optlen != sizeof(int)) { ret = -EINVAL; break; } if (rtnl_dereference(mrt->mroute_sk)) { ret = -EADDRINUSE; break; } ret = ip_ra_control(sk, 1, mrtsock_destruct); if (ret == 0) { rcu_assign_pointer(mrt->mroute_sk, sk); IPV4_DEVCONF_ALL(net, MC_FORWARDING)++; inet_netconf_notify_devconf(net, NETCONFA_MC_FORWARDING, NETCONFA_IFINDEX_ALL, net->ipv4.devconf_all); } break; case MRT_DONE: if (sk != rcu_access_pointer(mrt->mroute_sk)) { ret = -EACCES; } else { ret = ip_ra_control(sk, 0, NULL); goto out_unlock; } break; case MRT_ADD_VIF: case MRT_DEL_VIF: if (optlen != sizeof(vif)) { ret = -EINVAL; break; } if (copy_from_user(&vif, optval, sizeof(vif))) { ret = -EFAULT; break; } if (vif.vifc_vifi >= MAXVIFS) { ret = -ENFILE; break; } if (optname == MRT_ADD_VIF) { ret = vif_add(net, mrt, &vif, sk == rtnl_dereference(mrt->mroute_sk)); } else { ret = vif_delete(mrt, vif.vifc_vifi, 0, NULL); } break; /* Manipulate the forwarding caches. These live * in a sort of kernel/user symbiosis. */ case MRT_ADD_MFC: case MRT_DEL_MFC: parent = -1; case MRT_ADD_MFC_PROXY: case MRT_DEL_MFC_PROXY: if (optlen != sizeof(mfc)) { ret = -EINVAL; break; } if (copy_from_user(&mfc, optval, sizeof(mfc))) { ret = -EFAULT; break; } if (parent == 0) parent = mfc.mfcc_parent; if (optname == MRT_DEL_MFC || optname == MRT_DEL_MFC_PROXY) ret = ipmr_mfc_delete(mrt, &mfc, parent); else ret = ipmr_mfc_add(net, mrt, &mfc, sk == rtnl_dereference(mrt->mroute_sk), parent); break; /* Control PIM assert. */ case MRT_ASSERT: if (optlen != sizeof(val)) { ret = -EINVAL; break; } if (get_user(val, (int __user *)optval)) { ret = -EFAULT; break; } mrt->mroute_do_assert = val; break; case MRT_PIM: if (!ipmr_pimsm_enabled()) { ret = -ENOPROTOOPT; break; } if (optlen != sizeof(val)) { ret = -EINVAL; break; } if (get_user(val, (int __user *)optval)) { ret = -EFAULT; break; } val = !!val; if (val != mrt->mroute_do_pim) { mrt->mroute_do_pim = val; mrt->mroute_do_assert = val; } break; case MRT_TABLE: if (!IS_BUILTIN(CONFIG_IP_MROUTE_MULTIPLE_TABLES)) { ret = -ENOPROTOOPT; break; } if (optlen != sizeof(uval)) { ret = -EINVAL; break; } if (get_user(uval, (u32 __user *)optval)) { ret = -EFAULT; break; } if (sk == rtnl_dereference(mrt->mroute_sk)) { ret = -EBUSY; } else { mrt = ipmr_new_table(net, uval); if (IS_ERR(mrt)) ret = PTR_ERR(mrt); else raw_sk(sk)->ipmr_table = uval; } break; /* Spurious command, or MRT_VERSION which you cannot set. */ default: ret = -ENOPROTOOPT; } out_unlock: rtnl_unlock(); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)31540.13%310.00%
Nikolay Aleksandrov21327.13%723.33%
Patrick McHardy8811.21%26.67%
Eric Dumazet759.55%516.67%
Nicolas Dichtel506.37%26.67%
Benjamin Thery243.06%26.67%
Eric W. Biedermann50.64%13.33%
Herbert Xu40.51%13.33%
David S. Miller30.38%26.67%
Al Viro30.38%13.33%
Wang Chen20.25%13.33%
Pavel Emelyanov10.13%13.33%
Américo Wang10.13%13.33%
Ian Morris10.13%13.33%
Total785100.00%30100.00%

/* Getsock opt support for the multicast routing system. */
int ip_mroute_getsockopt(struct sock *sk, int optname, char __user *optval, int __user *optlen) { int olr; int val; struct net *net = sock_net(sk); struct mr_table *mrt; if (sk->sk_type != SOCK_RAW || inet_sk(sk)->inet_num != IPPROTO_IGMP) return -EOPNOTSUPP; mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT); if (!mrt) return -ENOENT; switch (optname) { case MRT_VERSION: val = 0x0305; break; case MRT_PIM: if (!ipmr_pimsm_enabled()) return -ENOPROTOOPT; val = mrt->mroute_do_pim; break; case MRT_ASSERT: val = mrt->mroute_do_assert; break; default: return -ENOPROTOOPT; } if (get_user(olr, optlen)) return -EFAULT; olr = min_t(unsigned int, olr, sizeof(int)); if (olr < 0) return -EINVAL; if (put_user(olr, optlen)) return -EFAULT; if (copy_to_user(optval, &val, olr)) return -EFAULT; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)8742.23%18.33%
Nikolay Aleksandrov4019.42%216.67%
Patrick McHardy3014.56%216.67%
Eric Dumazet2110.19%18.33%
Linus Torvalds157.28%325.00%
Benjamin Thery104.85%18.33%
Al Viro20.97%18.33%
Ian Morris10.49%18.33%
Total206100.00%12100.00%

/* The IP multicast ioctl support routines. */
int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg) { struct sioc_sg_req sr; struct sioc_vif_req vr; struct vif_device *vif; struct mfc_cache *c; struct net *net = sock_net(sk); struct mr_table *mrt; mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT); if (!mrt) return -ENOENT; switch (cmd) { case SIOCGETVIFCNT: if (copy_from_user(&vr, arg, sizeof(vr))) return -EFAULT; if (vr.vifi >= mrt->maxvif) return -EINVAL; read_lock(&mrt_lock); vif = &mrt->vif_table[vr.vifi]; if (VIF_EXISTS(mrt, vr.vifi)) { vr.icount = vif->pkt_in; vr.ocount = vif->pkt_out; vr.ibytes = vif->bytes_in; vr.obytes = vif->bytes_out; read_unlock(&mrt_lock); if (copy_to_user(arg, &vr, sizeof(vr))) return -EFAULT; return 0; } read_unlock(&mrt_lock); return -EADDRNOTAVAIL; case SIOCGETSGCNT: if (copy_from_user(&sr, arg, sizeof(sr))) return -EFAULT; rcu_read_lock(); c = ipmr_cache_find(mrt, sr.src.s_addr, sr.grp.s_addr); if (c) { sr.pktcnt = c->mfc_un.res.pkt; sr.bytecnt = c->mfc_un.res.bytes; sr.wrong_if = c->mfc_un.res.wrong_if; rcu_read_unlock(); if (copy_to_user(arg, &sr, sizeof(sr))) return -EFAULT; return 0; } rcu_read_unlock(); return -EADDRNOTAVAIL; default: return -ENOIOCTLCMD; } }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)28583.09%330.00%
Patrick McHardy349.91%220.00%
Benjamin Thery144.08%220.00%
Eric Dumazet61.75%110.00%
Al Viro30.87%110.00%
Ian Morris10.29%110.00%
Total343100.00%10100.00%

#ifdef CONFIG_COMPAT struct compat_sioc_sg_req { struct in_addr src; struct in_addr grp; compat_ulong_t pktcnt; compat_ulong_t bytecnt; compat_ulong_t wrong_if; }; struct compat_sioc_vif_req { vifi_t vifi; /* Which iface */ compat_ulong_t icount; compat_ulong_t ocount; compat_ulong_t ibytes; compat_ulong_t obytes; };
int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg) { struct compat_sioc_sg_req sr; struct compat_sioc_vif_req vr; struct vif_device *vif; struct mfc_cache *c; struct net *net = sock_net(sk); struct mr_table *mrt; mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT); if (!mrt) return -ENOENT; switch (cmd) { case SIOCGETVIFCNT: if (copy_from_user(&vr, arg, sizeof(vr))) return -EFAULT; if (vr.vifi >= mrt->maxvif) return -EINVAL; read_lock(&mrt_lock); vif = &mrt->vif_table[vr.vifi]; if (VIF_EXISTS(mrt, vr.vifi)) { vr.icount = vif->pkt_in; vr.ocount = vif->pkt_out; vr.ibytes = vif->bytes_in; vr.obytes = vif->bytes_out; read_unlock(&mrt_lock); if (copy_to_user(arg, &vr, sizeof(vr))) return -EFAULT; return 0; } read_unlock(&mrt_lock); return -EADDRNOTAVAIL; case SIOCGETSGCNT: if (copy_from_user(&sr, arg, sizeof(sr))) return -EFAULT; rcu_read_lock(); c = ipmr_cache_find(mrt, sr.src.s_addr, sr.grp.s_addr); if (c) { sr.pktcnt = c->mfc_un.res.pkt; sr.bytecnt = c->mfc_un.res.bytes; sr.wrong_if = c->mfc_un.res.wrong_if; rcu_read_unlock(); if (copy_to_user(arg, &sr, sizeof(sr))) return -EFAULT; return 0; } rcu_read_unlock(); return -EADDRNOTAVAIL; default: return -ENOIOCTLCMD; } }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann19656.98%125.00%
David S. Miller14742.73%250.00%
Ian Morris10.29%125.00%
Total344100.00%4100.00%

#endif
static int ipmr_device_event(struct notifier_block *this, unsigned long event, void *ptr) { struct net_device *dev = netdev_notifier_info_to_dev(ptr); struct net *net = dev_net(dev); struct mr_table *mrt; struct vif_device *v; int ct; if (event != NETDEV_UNREGISTER) return NOTIFY_DONE; ipmr_for_each_table(mrt, net) { v = &mrt->vif_table[0]; for (ct = 0; ct < mrt->maxvif; ct++, v++) { if (v->dev == dev) vif_delete(mrt, ct, 1, NULL); } } return NOTIFY_DONE; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)7763.64%327.27%
Patrick McHardy1613.22%218.18%
Benjamin Thery1310.74%19.09%
Eric W. Biedermann86.61%19.09%
Jiri Pirko32.48%19.09%
Wang Chen21.65%19.09%
Li RongQing10.83%19.09%
Eric Dumazet10.83%19.09%
Total121100.00%11100.00%

static struct notifier_block ip_mr_notifier = { .notifier_call = ipmr_device_event, }; /* Encapsulate a packet by attaching a valid IPIP header to it. * This avoids tunnel drivers and other mess and gives us the speed so * important for multicast video. */
static void ip_encap(struct net *net, struct sk_buff *skb, __be32 saddr, __be32 daddr) { struct iphdr *iph; const struct iphdr *old_iph = ip_hdr(skb); skb_push(skb, sizeof(struct iphdr)); skb->transport_header = skb->network_header; skb_reset_network_header(skb); iph = ip_hdr(skb); iph->version = 4; iph->tos = old_iph->tos; iph->ttl = old_iph->ttl; iph->frag_off = 0; iph->daddr = daddr; iph->saddr = saddr; iph->protocol = IPPROTO_IPIP; iph->ihl = 5; iph->tot_len = htons(skb->len); ip_select_ident(net, skb, NULL); ip_send_check(iph); memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); nf_reset(skb); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)10459.09%635.29%
Arnaldo Carvalho de Melo3419.32%423.53%
Alexey Kuznetsov2514.20%15.88%
Hannes Frederic Sowa73.98%15.88%
Al Viro21.14%15.88%
Linus Torvalds10.57%15.88%
Patrick McHardy10.57%15.88%
Ansis Atteka10.57%15.88%
Eric Dumazet10.57%15.88%
Total176100.00%17100.00%


static inline int ipmr_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb) { struct ip_options *opt = &(IPCB(skb)->opt); IP_INC_STATS(net, IPSTATS_MIB_OUTFORWDATAGRAMS); IP_ADD_STATS(net, IPSTATS_MIB_OUTOCTETS, skb->len); if (unlikely(opt->optlen)) ip_forward_options(skb); return dst_output(net, sk, skb); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)2936.71%18.33%
Alexey Kuznetsov1721.52%18.33%
Eric W. Biedermann1113.92%433.33%
Vincent Bernat911.39%18.33%
David S. Miller911.39%216.67%
Ani Sinha22.53%18.33%
Hideaki Yoshifuji / 吉藤英明11.27%18.33%
Pavel Emelyanov11.27%18.33%
Total79100.00%12100.00%

/* Processing handlers for ipmr_forward */
static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt, struct sk_buff *skb, struct mfc_cache *c, int vifi) { const struct iphdr *iph = ip_hdr(skb); struct vif_device *vif = &mrt->vif_table[vifi]; struct net_device *dev; struct rtable *rt; struct flowi4 fl4; int encap = 0; if (!vif->dev) goto out_free; if (vif->flags & VIFF_REGISTER) { vif->pkt_out++; vif->bytes_out += skb->len; vif->dev->stats.tx_bytes += skb->len; vif->dev->stats.tx_packets++; ipmr_cache_report(mrt, skb, vifi, IGMPMSG_WHOLEPKT); goto out_free; } if (vif->flags & VIFF_TUNNEL) { rt = ip_route_output_ports(net, &fl4, NULL, vif->remote, vif->local, 0, 0, IPPROTO_IPIP, RT_TOS(iph->tos), vif->link); if (IS_ERR(rt)) goto out_free; encap = sizeof(struct iphdr); } else { rt = ip_route_output_ports(net, &fl4, NULL, iph->daddr, 0, 0, 0, IPPROTO_IPIP, RT_TOS(iph->tos), vif->link); if (IS_ERR(rt)) goto out_free; } dev = rt->dst.dev; if (skb->len+encap > dst_mtu(&rt->dst) && (ntohs(iph->frag_off) & IP_DF)) { /* Do not fragment multicasts. Alas, IPv4 does not * allow to send ICMP, so that packets will disappear * to blackhole. */ IP_INC_STATS(net, IPSTATS_MIB_FRAGFAILS); ip_rt_put(rt); goto out_free; } encap += LL_RESERVED_SPACE(dev) + rt->dst.header_len; if (skb_cow(skb, encap)) { ip_rt_put(rt); goto out_free; } vif->pkt_out++; vif->bytes_out += skb->len; skb_dst_drop(skb); skb_dst_set(skb, &rt->dst); ip_decrease_ttl(ip_hdr(skb)); /* FIXME: forward and output firewalls used to be called here. * What do we do with netfilter? -- RR */ if (vif->flags & VIFF_TUNNEL) { ip_encap(net, skb, vif->local, vif->remote); /* FIXME: extra output firewall step used to be here. --RR */ vif->dev->stats.tx_packets++; vif->dev->stats.tx_bytes += skb->len; } IPCB(skb)->flags |= IPSKB_FORWARDED; /* RFC1584 teaches, that DVMRP/PIM router must deliver packets locally * not only before forwarding, but after forwarding on all output * interfaces. It is clear, if mrouter runs a multicasting * program, it should receive packets not depending to what interface * program is joined. * If we will not make it, the program will have to join on all * interfaces. On the other hand, multihoming host (or router, but * not mrouter) cannot join to more than one interface - it will * result in receiving multiple packets. */ NF_HOOK(NFPROTO_IPV4, NF_INET_FORWARD, net, NULL, skb, skb->dev, dev, ipmr_forward_finish); return; out_free: kfree_skb(skb); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)29563.99%923.08%
David S. Miller6814.75%615.38%
Alexey Kuznetsov398.46%25.13%
Patrick McHardy132.82%37.69%
Arnaldo Carvalho de Melo81.74%12.56%
Eric Dumazet71.52%25.13%
Pavel Emelyanov71.52%37.69%
Changli Gao61.30%12.56%
Eric W. Biedermann30.65%25.13%
Ilpo Järvinen30.65%12.56%
Denis V. Lunev20.43%12.56%
Benjamin Thery20.43%12.56%
Hannes Frederic Sowa20.43%12.56%
Ian Morris10.22%12.56%
Hideaki Yoshifuji / 吉藤英明10.22%12.56%
Herbert Xu10.22%12.56%
Ani Sinha10.22%12.56%
Jan Engelhardt10.22%12.56%
Nikolay Aleksandrov10.22%12.56%
Total461100.00%39100.00%


static int ipmr_find_vif(struct mr_table *mrt, struct net_device *dev) { int ct; for (ct = mrt->maxvif-1; ct >= 0; ct--) { if (mrt->vif_table[ct].dev == dev) break; } return ct; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)4581.82%562.50%
Patrick McHardy712.73%112.50%
Benjamin Thery23.64%112.50%
Stephen Hemminger11.82%112.50%
Total55100.00%8100.00%

/* "local" means that we should preserve one skb (for local delivery) */
static void ip_mr_forward(struct net *net, struct mr_table *mrt, struct sk_buff *skb, struct mfc_cache *cache, int local) { int true_vifi = ipmr_find_vif(mrt, skb->dev); int psend = -1; int vif, ct; vif = cache->mfc_parent; cache->mfc_un.res.pkt++; cache->mfc_un.res.bytes += skb->len; cache->mfc_un.res.lastuse = jiffies; if (cache->mfc_origin == htonl(INADDR_ANY) && true_vifi >= 0) { struct mfc_cache *cache_proxy; /* For an (*,G) entry, we only check that the incomming * interface is part of the static tree. */ cache_proxy = ipmr_cache_find_any_parent(mrt, vif); if (cache_proxy && cache_proxy->mfc_un.res.ttls[true_vifi] < 255) goto forward; } /* Wrong interface: drop packet and (maybe) send PIM assert. */ if (mrt->vif_table[vif].dev != skb->dev) { struct net_device *mdev; mdev = l3mdev_master_dev_rcu(mrt->vif_table[vif].dev); if (mdev == skb->dev) goto forward; if (rt_is_output_route(skb_rtable(skb))) { /* It is our own packet, looped back. * Very complicated situation... * * The best workaround until routing daemons will be * fixed is not to redistribute packet, if it was * send through wrong interface. It means, that * multicast applications WILL NOT work for * (S,G), which have default multicast route pointing * to wrong oif. In any case, it is not a good * idea to use multicasting applications on router. */ goto dont_forward; } cache->mfc_un.res.wrong_if++; if (true_vifi >= 0 && mrt->mroute_do_assert && /* pimsm uses asserts, when switching from RPT to SPT, * so that we cannot check that packet arrived on an oif. * It is bad, but otherwise we would need to move pretty * large chunk of pimd to kernel. Ough... --ANK */ (mrt->mroute_do_pim || cache->mfc_un.res.ttls[true_vifi] < 255) && time_after(jiffies, cache->mfc_un.res.last_assert + MFC_ASSERT_THRESH)) { cache->mfc_un.res.last_assert = jiffies; ipmr_cache_report(mrt, skb, true_vifi, IGMPMSG_WRONGVIF); } goto dont_forward; } forward: mrt->vif_table[vif].pkt_in++; mrt->vif_table[vif].bytes_in += skb->len; /* Forward the frame */ if (cache->mfc_origin == htonl(INADDR_ANY) && cache->mfc_mcastgrp == htonl(INADDR_ANY)) { if (true_vifi >= 0 && true_vifi != cache->mfc_parent && ip_hdr(skb)->ttl > cache->mfc_un.res.ttls[cache->mfc_parent]) { /* It's an (*,*) entry and the packet is not coming from * the upstream: forward the packet to the upstream * only. */ psend = cache->mfc_parent; goto last_forward; } goto dont_forward; } for (ct = cache->mfc_un.res.maxvif - 1; ct >= cache->mfc_un.res.minvif; ct--) { /* For (*,G) entry, don't forward to the incoming interface */ if ((cache->mfc_origin != htonl(INADDR_ANY) || ct != true_vifi) && ip_hdr(skb)->ttl > cache->mfc_un.res.ttls[ct]) { if (psend != -1) { struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); if (skb2) ipmr_queue_xmit(net, mrt, skb2, cache, psend); } psend = ct; } } last_forward: if (psend != -1) { if (local) { struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); if (skb2) ipmr_queue_xmit(net, mrt, skb2, cache, psend); } else { ipmr_queue_xmit(net, mrt, skb, cache, psend); return; } } dont_forward: if (!local) kfree_skb(skb); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)25144.50%523.81%
Nicolas Dichtel15226.95%29.52%
Alexey Kuznetsov559.75%14.76%
David Ahern305.32%14.76%
Patrick McHardy284.96%29.52%
Nikolay Aleksandrov234.08%314.29%
Stephen Hemminger61.06%14.76%
Benjamin Thery61.06%14.76%
Eric Dumazet50.89%29.52%
David S. Miller30.53%14.76%
Arnaldo Carvalho de Melo30.53%14.76%
Rami Rosen20.35%14.76%
Total564100.00%21100.00%


static struct mr_table *ipmr_rt_fib_lookup(struct net *net, struct sk_buff *skb) { struct rtable *rt = skb_rtable(skb); struct iphdr *iph = ip_hdr(skb); struct flowi4 fl4 = { .daddr = iph->daddr, .saddr = iph->saddr, .flowi4_tos = RT_TOS(iph->tos), .flowi4_oif = (rt_is_output_route(rt) ? skb->dev->ifindex : 0), .flowi4_iif = (rt_is_output_route(rt) ? LOOPBACK_IFINDEX : skb->dev->ifindex), .flowi4_mark = skb->mark, }; struct mr_table *mrt; int err; err = ipmr_fib_lookup(net, &fl4, &mrt); if (err) return ERR_PTR(err); return mrt; }

Contributors

PersonTokensPropCommitsCommitProp
David S. Miller12082.76%654.55%
Patrick McHardy1510.34%19.09%
Benjamin Thery42.76%19.09%
Julian Anastasov32.07%19.09%
Linus Torvalds (pre-git)21.38%19.09%
Pavel Emelyanov10.69%19.09%
Total145100.00%11100.00%

/* Multicast packets for forwarding arrive here * Called with rcu_read_lock(); */
int ip_mr_input(struct sk_buff *skb) { struct mfc_cache *cache; struct net *net = dev_net(skb->dev); int local = skb_rtable(skb)->rt_flags & RTCF_LOCAL; struct mr_table *mrt; /* Packet is looped back after forward, it should not be * forwarded second time, but still can be delivered locally. */ if (IPCB(skb)->flags & IPSKB_FORWARDED) goto dont_forward; mrt = ipmr_rt_fib_lookup(net, skb); if (IS_ERR(mrt)) { kfree_skb(skb); return PTR_ERR(mrt); } if (!local) { if (IPCB(skb)->opt.router_alert) { if (ip_call_ra_chain(skb)) return 0; } else if (ip_hdr(skb)->protocol == IPPROTO_IGMP) { /* IGMPv1 (and broken IGMPv2 implementations sort of * Cisco IOS <= 11.2(8)) do not put router alert * option to IGMP packets destined to routable * groups. It is very bad, because it means * that we can forward NO IGMP messages. */ struct sock *mroute_sk; mroute_sk = rcu_dereference(mrt->mroute_sk); if (mroute_sk) { nf_reset(skb); raw_rcv(mroute_sk, skb); return 0; } } } /* already under rcu_read_lock() */ cache = ipmr_cache_find(mrt, ip_hdr(skb)->saddr, ip_hdr(skb)->daddr); if (!cache) { int vif = ipmr_find_vif(mrt, skb->dev); if (vif >= 0) cache = ipmr_cache_find_any(mrt, ip_hdr(skb)->daddr, vif); } /* No usable cache entry */ if (!cache) { int vif; if (local) { struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); ip_local_deliver(skb); if (!skb2) return -ENOBUFS; skb = skb2; } read_lock(&mrt_lock); vif = ipmr_find_vif(mrt, skb->dev); if (vif >= 0) { int err2 = ipmr_cache_unresolved(mrt, vif, skb); read_unlock(&mrt_lock); return err2; } read_unlock(&mrt_lock); kfree_skb(skb); return -ENODEV; } read_lock(&mrt_lock); ip_mr_forward(net, mrt, skb, cache, local); read_unlock(&mrt_lock); if (local) return ip_local_deliver(skb); return 0; dont_forward: if (local) return ip_local_deliver(skb); kfree_skb(skb); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)21353.65%628.57%
David S. Miller7719.40%14.76%
Nicolas Dichtel4010.08%14.76%
Eric Dumazet276.80%314.29%
Patrick McHardy164.03%419.05%
Arnaldo Carvalho de Melo92.27%14.76%
Ben Greear71.76%14.76%
Benjamin Thery41.01%29.52%
Ian Morris30.76%14.76%
Nikolay Aleksandrov10.25%14.76%
Total397100.00%21100.00%

#ifdef CONFIG_IP_PIMSM_V1 /* Handle IGMP messages of PIMv1 */
int pim_rcv_v1(struct sk_buff *skb) { struct igmphdr *pim; struct net *net = dev_net(skb->dev); struct mr_table *mrt; if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(struct iphdr))) goto drop; pim = igmp_hdr(skb); mrt = ipmr_rt_fib_lookup(net, skb); if (IS_ERR(mrt)) goto drop; if (!mrt->mroute_do_pim || pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER) goto drop; if (__pim_rcv(mrt, skb, sizeof(*pim))) { drop: kfree_skb(skb); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Ilpo Järvinen7356.15%19.09%
Patrick McHardy1612.31%218.18%
Linus Torvalds (pre-git)1310.00%436.36%
Benjamin Thery1310.00%19.09%
David S. Miller107.69%218.18%
Stephen Hemminger53.85%19.09%
Total130100.00%11100.00%

#endif #ifdef CONFIG_IP_PIMSM_V2
static int pim_rcv(struct sk_buff *skb) { struct pimreghdr *pim; struct net *net = dev_net(skb->dev); struct mr_table *mrt; if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(struct iphdr))) goto drop; pim = (struct pimreghdr *)skb_transport_header(skb); if (pim->type != ((PIM_VERSION << 4) | (PIM_TYPE_REGISTER)) || (pim->flags & PIM_NULL_REGISTER) || (ip_compute_csum((void *)pim, sizeof(*pim)) != 0 && csum_fold(skb_checksum(skb, 0, skb->len, 0)))) goto drop; mrt = ipmr_rt_fib_lookup(net, skb); if (IS_ERR(mrt)) goto drop; if (__pim_rcv(mrt, skb, sizeof(*pim))) { drop: kfree_skb(skb); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Ilpo Järvinen6938.76%17.69%
Linus Torvalds (pre-git)4424.72%430.77%
Stephen Hemminger2413.48%17.69%
Benjamin Thery126.74%17.69%
Patrick McHardy105.62%17.69%
David S. Miller105.62%215.38%
Linus Torvalds73.93%17.69%
Arnaldo Carvalho de Melo10.56%17.69%
Nikolay Aleksandrov10.56%17.69%
Total178100.00%13100.00%

#endif
static int __ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb, struct mfc_cache *c, struct rtmsg *rtm) { struct rta_mfc_stats mfcs; struct nlattr *mp_attr; struct rtnexthop *nhp; unsigned long lastuse; int ct; /* If cache is unresolved, don't try to parse IIF and OIF */ if (c->mfc_parent >= MAXVIFS) { rtm->rtm_flags |= RTNH_F_UNRESOLVED; return -ENOENT; } if (VIF_EXISTS(mrt, c->mfc_parent) && nla_put_u32(skb, RTA_IIF, mrt->vif_table[c->mfc_parent].dev->ifindex) < 0) return -EMSGSIZE; if (!(mp_attr = nla_nest_start(skb, RTA_MULTIPATH))) return -EMSGSIZE; for (ct = c->mfc_un.res.minvif; ct < c->mfc_un.res.maxvif; ct++) { if (VIF_EXISTS(mrt, ct) && c->mfc_un.res.ttls[ct] < 255) { if (!(nhp = nla_reserve_nohdr(skb, sizeof(*nhp)))) { nla_nest_cancel(skb, mp_attr); return -EMSGSIZE; } nhp->rtnh_flags = 0; nhp->rtnh_hops = c->mfc_un.res.ttls[ct]; nhp->rtnh_ifindex = mrt->vif_table[ct].dev->ifindex; nhp->rtnh_len = sizeof(*nhp); } } nla_nest_end(skb, mp_attr); lastuse = READ_ONCE(c->mfc_un.res.lastuse); lastuse = time_after_eq(jiffies, lastuse) ? jiffies - lastuse : 0; mfcs.mfcs_packets = c->mfc_un.res.pkt; mfcs.mfcs_bytes = c->mfc_un.res.bytes; mfcs.mfcs_wrong_if = c->mfc_un.res.wrong_if; if (nla_put_64bit(skb, RTA_MFC_STATS, sizeof(mfcs), &mfcs, RTA_PAD) || nla_put_u64_64bit(skb, RTA_EXPIRES, jiffies_to_clock_t(lastuse), RTA_PAD)) return -EMSGSIZE; rtm->rtm_type = RTN_MULTICAST; return 1; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)14439.13%730.43%
Nicolas Dichtel9425.54%313.04%
Nikolay Aleksandrov6216.85%313.04%
Thomas Graf4211.41%14.35%
Patrick McHardy102.72%313.04%
Linus Torvalds71.90%14.35%
Stephen Hemminger51.36%14.35%
Arnaldo Carvalho de Melo20.54%28.70%
Dan Carpenter10.27%14.35%
Benjamin Thery10.27%14.35%
Total368100.00%23100.00%


int ipmr_get_route(struct net *net, struct sk_buff *skb, __be32 saddr, __be32 daddr, struct rtmsg *rtm, u32 portid) { struct mfc_cache *cache; struct mr_table *mrt; int err; mrt = ipmr_get_table(net, RT_TABLE_DEFAULT); if (!mrt) return -ENOENT; rcu_read_lock(); cache = ipmr_cache_find(mrt, saddr, daddr); if (!cache && skb->dev) { int vif = ipmr_find_vif(mrt, skb->dev); if (vif >= 0) cache = ipmr_cache_find_any(mrt, daddr, vif); } if (!cache) { struct sk_buff *skb2; struct iphdr *iph; struct net_device *dev; int vif = -1; dev = skb->dev; read_lock(&mrt_lock); if (dev) vif = ipmr_find_vif(mrt, dev); if (vif < 0) { read_unlock(&mrt_lock); rcu_read_unlock(); return -ENODEV; } skb2 = skb_clone(skb, GFP_ATOMIC); if (!skb2) { read_unlock(&mrt_lock); rcu_read_unlock(); return -ENOMEM; } NETLINK_CB(skb2).portid = portid; skb_push(skb2, sizeof(struct iphdr)); skb_reset_network_header(skb2); iph = ip_hdr(skb2); iph->ihl = sizeof(struct iphdr) >> 2; iph->saddr = saddr; iph->daddr = daddr; iph->version = 0; err = ipmr_cache_unresolved(mrt, vif, skb2); read_unlock(&mrt_lock); rcu_read_unlock(); return err; } read_lock(&mrt_lock); err = __ipmr_fill_mroute(mrt, skb, cache, rtm); read_unlock(&mrt_lock); rcu_read_unlock(); return err; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)16750.15%731.82%
Nicolas Dichtel4413.21%29.09%
Eric Dumazet3410.21%29.09%
Patrick McHardy247.21%418.18%
Alexey Kuznetsov195.71%14.55%
David S. Miller154.50%14.55%
Arnaldo Carvalho de Melo123.60%29.09%
Nikolay Aleksandrov113.30%14.55%
Benjamin Thery41.20%14.55%
Ian Morris30.90%14.55%
Total333100.00%22100.00%


static int ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb, u32 portid, u32 seq, struct mfc_cache *c, int cmd, int flags) { struct nlmsghdr *nlh; struct rtmsg *rtm; int err; nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rtm), flags); if (!nlh) return -EMSGSIZE; rtm = nlmsg_data(nlh); rtm->rtm_family = RTNL_FAMILY_IPMR; rtm->rtm_dst_len = 32; rtm->rtm_src_len = 32; rtm->rtm_tos = 0; rtm->rtm_table = mrt->id; if (nla_put_u32(skb, RTA_TABLE, mrt->id)) goto nla_put_failure; rtm->rtm_type = RTN_MULTICAST; rtm->rtm_scope = RT_SCOPE_UNIVERSE; if (c->mfc_flags & MFC_STATIC) rtm->rtm_protocol = RTPROT_STATIC; else rtm->rtm_protocol = RTPROT_MROUTED; rtm->rtm_flags = 0; if (nla_put_in_addr(skb, RTA_SRC, c->mfc_origin) || nla_put_in_addr(skb, RTA_DST, c->mfc_mcastgrp)) goto nla_put_failure; err = __ipmr_fill_mroute(mrt, skb, c, rtm); /* do not break the dump if cache is unresolved */ if (err < 0 && err != -ENOENT) goto nla_put_failure; nlmsg_end(skb, nlh); return 0; nla_put_failure: nlmsg_cancel(skb, nlh); return -EMSGSIZE; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy13654.84%15.56%
Nicolas Dichtel3915.73%422.22%
Linus Torvalds (pre-git)3514.11%527.78%
David S. Miller145.65%15.56%
Alexey Kuznetsov104.03%15.56%
Benjamin Thery41.61%15.56%
Johannes Berg31.21%15.56%
Jiri Benc20.81%15.56%
Eric Dumazet20.81%15.56%
Eric W. Biedermann20.81%15.56%
Ian Morris10.40%15.56%
Total248100.00%18100.00%


static size_t mroute_msgsize(bool unresolved, int maxvif) { size_t len = NLMSG_ALIGN(sizeof(struct rtmsg)) + nla_total_size(4) /* RTA_TABLE */ + nla_total_size(4) /* RTA_SRC */ + nla_total_size(4) /* RTA_DST */ ; if (!unresolved) len = len + nla_total_size(4) /* RTA_IIF */ + nla_total_size(0) /* RTA_MULTIPATH */ + maxvif * NLA_ALIGN(sizeof(struct rtnexthop)) /* RTA_MFC_STATS */ + nla_total_size_64bit(sizeof(struct rta_mfc_stats)) ; return len; }

Contributors

PersonTokensPropCommitsCommitProp
Nicolas Dichtel87100.00%2100.00%
Total87100.00%2100.00%


static void mroute_netlink_event(struct mr_table *mrt, struct mfc_cache *mfc, int cmd) { struct net *net = read_pnet(&mrt->net); struct sk_buff *skb; int err = -ENOBUFS; skb = nlmsg_new(mroute_msgsize(mfc->mfc_parent >= MAXVIFS, mrt->maxvif), GFP_ATOMIC); if (!skb) goto errout; err = ipmr_fill_mroute(mrt, skb, 0, 0, mfc, cmd, 0); if (err < 0) goto errout; rtnl_notify(skb, net, 0, RTNLGRP_IPV4_MROUTE, NULL, GFP_ATOMIC); return; errout: kfree_skb(skb); if (err < 0) rtnl_set_sk_err(net, RTNLGRP_IPV4_MROUTE, err); }

Contributors

PersonTokensPropCommitsCommitProp
Nicolas Dichtel13699.27%266.67%
Ian Morris10.73%133.33%
Total137100.00%3100.00%


static int ipmr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb) { struct net *net = sock_net(skb->sk); struct mr_table *mrt; struct mfc_cache *mfc; unsigned int t = 0, s_t; unsigned int e = 0, s_e; s_t = cb->args[0]; s_e = cb->args[1]; rcu_read_lock(); ipmr_for_each_table(mrt, net) { if (t < s_t) goto next_table; list_for_each_entry_rcu(mfc, &mrt->mfc_cache_list, list) { if (e < s_e) goto next_entry; if (ipmr_fill_mroute(mrt, skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, mfc, RTM_NEWROUTE, NLM_F_MULTI) < 0) goto done; next_entry: e++; } e = 0; s_e = 0; spin_lock_bh(&mfc_unres_lock); list_for_each_entry(mfc, &mrt->mfc_unres_queue, list) { if (e < s_e) goto next_entry2; if (ipmr_fill_mroute(mrt, skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, mfc, RTM_NEWROUTE, NLM_F_MULTI) < 0) { spin_unlock_bh(&mfc_unres_lock); goto done; } next_entry2: e++; } spin_unlock_bh(&mfc_unres_lock); e = 0; s_e = 0; next_table: t++; } done: rcu_read_unlock(); cb->args[1] = e; cb->args[0] = t; return skb->len; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy15455.20%17.14%
Nicolas Dichtel8731.18%321.43%
Linus Torvalds (pre-git)227.89%428.57%
Nikolay Aleksandrov62.15%17.14%
Eric Dumazet51.79%17.14%
Arnaldo Carvalho de Melo31.08%214.29%
Eric W. Biedermann10.36%17.14%
Benjamin Thery10.36%17.14%
Total279100.00%14100.00%

static const struct nla_policy rtm_ipmr_policy[RTA_MAX + 1] = { [RTA_SRC] = { .type = NLA_U32 }, [RTA_DST] = { .type = NLA_U32 }, [RTA_IIF] = { .type = NLA_U32 }, [RTA_TABLE] = { .type = NLA_U32 }, [RTA_MULTIPATH] = { .len = sizeof(struct rtnexthop) }, };
static bool ipmr_rtm_validate_proto(unsigned char rtm_protocol) { switch (rtm_protocol) { case RTPROT_STATIC: case RTPROT_MROUTED: return true; } return false; }

Contributors

PersonTokensPropCommitsCommitProp
Nikolay Aleksandrov2796.43%150.00%
Stephen Hemminger13.57%150.00%
Total28100.00%2100.00%


static int ipmr_nla_get_ttls(const struct nlattr *nla, struct mfcctl *mfcc) { struct rtnexthop *rtnh = nla_data(nla); int remaining = nla_len(nla), vifi = 0; while (rtnh_ok(rtnh, remaining)) { mfcc->mfcc_ttls[vifi] = rtnh->rtnh_hops; if (++vifi == MAXVIFS) break; rtnh = rtnh_next(rtnh, &remaining); } return remaining > 0 ? -EINVAL : vifi; }

Contributors

PersonTokensPropCommitsCommitProp
Nikolay Aleksandrov6168.54%110.00%
Linus Torvalds (pre-git)1415.73%550.00%
Stephen Hemminger66.74%110.00%
Benjamin Thery44.49%220.00%
Patrick McHardy44.49%110.00%
Total89100.00%10100.00%

/* returns < 0 on error, 0 for ADD_MFC and 1 for ADD_MFC_PROXY */
static int rtm_to_ipmr_mfcc(struct net *net, struct nlmsghdr *nlh, struct mfcctl *mfcc, int *mrtsock, struct mr_table **mrtret) { struct net_device *dev = NULL; u32 tblid = RT_TABLE_DEFAULT; struct mr_table *mrt; struct nlattr *attr; struct rtmsg *rtm; int ret, rem; ret = nlmsg_validate(nlh, sizeof(*rtm), RTA_MAX, rtm_ipmr_policy); if (ret < 0) goto out; rtm = nlmsg_data(nlh); ret = -EINVAL; if (rtm->rtm_family != RTNL_FAMILY_IPMR || rtm->rtm_dst_len != 32 || rtm->rtm_type != RTN_MULTICAST || rtm->rtm_scope != RT_SCOPE_UNIVERSE || !ipmr_rtm_validate_proto(rtm->rtm_protocol)) goto out; memset(mfcc, 0, sizeof(*mfcc)); mfcc->mfcc_parent = -1; ret = 0; nlmsg_for_each_attr(attr, nlh, sizeof(struct rtmsg), rem) { switch (nla_type(attr)) { case RTA_SRC: mfcc->mfcc_origin.s_addr = nla_get_be32(attr); break; case RTA_DST: mfcc->mfcc_mcastgrp.s_addr = nla_get_be32(attr); break; case RTA_IIF: dev = __dev_get_by_index(net, nla_get_u32(attr)); if (!dev) { ret = -ENODEV; goto out; } break; case RTA_MULTIPATH: if (ipmr_nla_get_ttls(attr, mfcc) < 0) { ret = -EINVAL; goto out; } break; case RTA_PREFSRC: ret = 1; break; case RTA_TABLE: tblid = nla_get_u32(attr); break; } } mrt = ipmr_get_table(net, tblid); if (!mrt) { ret = -ENOENT; goto out; } *mrtret = mrt; *mrtsock = rtm->rtm_protocol == RTPROT_MROUTED ? 1 : 0; if (dev) mfcc->mfcc_parent = ipmr_find_vif(mrt, dev); out: return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Nikolay Aleksandrov34297.71%125.00%
Stephen Hemminger61.71%125.00%
Patrick McHardy10.29%125.00%
Benjamin Thery10.29%125.00%
Total350100.00%4100.00%

/* takes care of both newroute and delroute */
static int ipmr_rtm_route(struct sk_buff *skb, struct nlmsghdr *nlh) { struct net *net = sock_net(skb->sk); int ret, mrtsock, parent; struct mr_table *tbl; struct mfcctl mfcc; mrtsock = 0; tbl = NULL; ret = rtm_to_ipmr_mfcc(net, nlh, &mfcc, &mrtsock, &tbl); if (ret < 0) return ret; parent = ret ? mfcc.mfcc_parent : -1; if (nlh->nlmsg_type == RTM_NEWROUTE) return ipmr_mfc_add(net, tbl, &mfcc, mrtsock, parent); else return ipmr_mfc_delete(tbl, &mfcc, parent); }

Contributors

PersonTokensPropCommitsCommitProp
Nikolay Aleksandrov125100.00%1100.00%
Total125100.00%1100.00%

#ifdef CONFIG_PROC_FS /* The /proc interfaces to multicast routing : * /proc/net/ip_mr_cache & /proc/net/ip_mr_vif */ struct ipmr_vif_iter { struct seq_net_private p; struct mr_table *mrt; int ct; };
static struct vif_device *ipmr_vif_seq_idx(struct net *net, struct ipmr_vif_iter *iter, loff_t pos) { struct mr_table *mrt = iter->mrt; for (iter->ct = 0; iter->ct < mrt->maxvif; ++iter->ct) { if (!VIF_EXISTS(mrt, iter->ct)) continue; if (pos-- == 0) return &mrt->vif_table[iter->ct]; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Nikolay Aleksandrov87100.00%1100.00%
Total87100.00%1100.00%


static void *ipmr_vif_seq_start(struct seq_file *seq, loff_t *pos) __acquires (mrt_lock) { struct ipmr_vif_iter *iter = seq->private; struct net *net = seq_file_net(seq); struct mr_table *mrt; mrt = ipmr_get_table(net, RT_TABLE_DEFAULT); if (!mrt) return ERR_PTR(-ENOENT); iter->mrt = mrt; read_lock(&mrt_lock); return *pos ? ipmr_vif_seq_idx(net, seq->private, *pos - 1) : SEQ_START_TOKEN; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy3435.05%112.50%
Nikolay Aleksandrov2626.80%112.50%
Stephen Hemminger1616.49%112.50%
Benjamin Thery1111.34%112.50%
Linus Torvalds (pre-git)99.28%337.50%
Ian Morris11.03%112.50%
Total97100.00%8100.00%


static void *ipmr_vif_seq_next(struct seq_file *seq, void *v, loff_t *pos) { struct ipmr_vif_iter *iter = seq->private; struct net *net = seq_file_net(seq); struct mr_table *mrt = iter->mrt; ++*pos; if (v == SEQ_START_TOKEN) return ipmr_vif_seq_idx(net, iter, 0); while (++iter->ct < mrt->maxvif) { if (!VIF_EXISTS(mrt, iter->ct)) continue; return &mrt->vif_table[iter->ct]; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Stephen Hemminger6862.96%112.50%
Benjamin Thery1513.89%225.00%
Linus Torvalds (pre-git)1312.04%337.50%
Patrick McHardy1211.11%225.00%
Total108100.00%8100.00%


static void ipmr_vif_seq_stop(struct seq_file *seq, void *v) __releases (mrt_lock) { read_unlock(&mrt_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Stephen Hemminger25100.00%2100.00%
Total25100.00%2100.00%


static int ipmr_vif_seq_show(struct seq_file *seq, void *v) { struct ipmr_vif_iter *iter = seq->private; struct mr_table *mrt = iter->mrt; if (v == SEQ_START_TOKEN) { seq_puts(seq, "Interface BytesIn PktsIn BytesOut PktsOut Flags Local Remote\n"); } else { const struct vif_device *vif = v; const char *name = vif->dev ? vif->dev->name : "none"; seq_printf(seq, "%2zd %-10s %8ld %7ld %8ld %7ld %05X %08X %08X\n", vif - mrt->vif_table, name, vif->bytes_in, vif->pkt_in, vif->bytes_out, vif->pkt_out, vif->flags, vif->local, vif->remote); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Stephen Hemminger10081.97%116.67%
Patrick McHardy1310.66%233.33%
Benjamin Thery75.74%116.67%
Linus Torvalds (pre-git)10.82%116.67%
Alexey Dobriyan10.82%116.67%
Total122100.00%6100.00%

static const struct seq_operations ipmr_vif_seq_ops = { .start = ipmr_vif_seq_start, .next = ipmr_vif_seq_next, .stop = ipmr_vif_seq_stop, .show = ipmr_vif_seq_show, };
static int ipmr_vif_open(struct inode *inode, struct file *file) { return seq_open_net(inode, file, &ipmr_vif_seq_ops, sizeof(struct ipmr_vif_iter)); }

Contributors

PersonTokensPropCommitsCommitProp
Stephen Hemminger2266.67%125.00%
Pavel Emelyanov721.21%125.00%
Benjamin Thery39.09%125.00%
Linus Torvalds (pre-git)13.03%125.00%
Total33100.00%4100.00%

static const struct file_operations ipmr_vif_fops = { .owner = THIS_MODULE, .open = ipmr_vif_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release_net, }; struct ipmr_mfc_iter { struct seq_net_private p; struct mr_table *mrt; struct list_head *cache; };
static struct mfc_cache *ipmr_mfc_seq_idx(struct net *net, struct ipmr_mfc_iter *it, loff_t pos) { struct mr_table *mrt = it->mrt; struct mfc_cache *mfc; rcu_read_lock(); it->cache = &mrt->mfc_cache_list; list_for_each_entry_rcu(mfc, &mrt->mfc_cache_list, list) if (pos-- == 0) return mfc; rcu_read_unlock(); spin_lock_bh(&mfc_unres_lock); it->cache = &mrt->mfc_unres_queue; list_for_each_entry(mfc, it->cache, list) if (pos-- == 0) return mfc; spin_unlock_bh(&mfc_unres_lock); it->cache = NULL; return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Stephen Hemminger7362.93%114.29%
Patrick McHardy2723.28%342.86%
Benjamin Thery97.76%114.29%
Eric Dumazet54.31%114.29%
Nikolay Aleksandrov21.72%114.29%
Total116100.00%7100.00%


static void *ipmr_mfc_seq_start(struct seq_file *seq, loff_t *pos) { struct ipmr_mfc_iter *it = seq->private; struct net *net = seq_file_net(seq); struct mr_table *mrt; mrt = ipmr_get_table(net, RT_TABLE_DEFAULT); if (!mrt) return ERR_PTR(-ENOENT); it->mrt = mrt; it->cache = NULL; return *pos ? ipmr_mfc_seq_idx(net, seq->private, *pos - 1) : SEQ_START_TOKEN; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick McHardy3133.33%116.67%
Stephen Hemminger3133.33%116.67%
Hirofumi Ogawa1516.13%116.67%
Benjamin Thery1212.90%116.67%
Linus Torvalds (pre-git)33.23%116.67%
Ian Morris11.08%116.67%
Total93100.00%6100.00%


static void *ipmr_mfc_seq_next(struct seq_file *seq, void *v, loff_t *pos) { struct ipmr_mfc_iter *it = seq->private; struct net *net = seq_file_net(seq); struct mr_table *mrt = it->mrt; struct mfc_cache *mfc = v; ++*pos; if (v == SEQ_START_TOKEN) return ipmr_mfc_seq_idx(net, seq->private, 0); if (mfc->list.next != it->cache) return list_entry(mfc->list.next, struct mfc_cache, list); if (it->cache == &mrt->mfc_unres_queue) goto end_of_list; /* exhausted cache_array, show unresolved */ rcu_read_unlock(); it->cache = &mrt->mfc_unres_queue; spin_lock_bh(&mfc_unres_lock); if (!list_empty(it->cache)) return list_first_entry(it->cache, struct mfc_cache, list); end_of_list: spin_unlock_bh(&mfc_unres_lock); it->cache = NULL; return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Stephen Hemminger10358.19%19.09%
Patrick McHardy4424.86%436.36%
Benjamin Thery169.04%19.09%
Nikolay Aleksandrov73.95%19.09%
Linus Torvalds (pre-git)52.82%327.27%
Eric Dumazet21.13%19.09%
Total177100.00%11100.00%


static void ipmr_mfc_seq_stop(struct seq_file *seq, void *v) { struct ipmr_mfc_iter *it = seq->private; struct mr_table *mrt = it->mrt; if (it->cache == &mrt->mfc_unres_queue) spin_unlock_bh(&mfc_unres_lock); else if (it->cache == &mrt->mfc_cache_list) rcu_read_unlock(); }

Contributors

PersonTokensPropCommitsCommitProp
Stephen Hemminger4873.85%112.50%
Patrick McHardy913.85%450.00%
Benjamin Thery57.69%112.50%
Eric Dumazet23.08%112.50%
Nikolay Aleksandrov11.54%112.50%
Total65100.00%8100.00%


static int ipmr_mfc_seq_show(struct seq_file *seq, void *v) { int n; if (v == SEQ_START_TOKEN) { seq_puts(seq, "Group Origin Iif Pkts Bytes Wrong Oifs\n"); } else { const struct mfc_cache *mfc = v; const struct ipmr_mfc_iter *it = seq->private; const struct mr_table *mrt = it->mrt; seq_printf(seq, "%08X %08X %-3hd", (__force u32) mfc->mfc_mcastgrp, (__force u32) mfc->mfc_origin, mfc->mfc_parent); if (it->cache != &mrt->mfc_unres_queue) { seq_printf(seq, " %8lu %8lu %8lu", mfc->mfc_un.res.pkt, mfc->mfc_un.res.bytes, mfc->mfc_un.res.wrong_if); for (n = mfc->mfc_un.res.minvif; n < mfc->mfc_un.res.maxvif; n++) { if (VIF_EXISTS(mrt, n) && mfc->mfc_un.res.ttls[n] < 255) seq_printf(seq, " %2d:%-3d", n, mfc->mfc_un.res.ttls[n]); } } else { /* unresolved mfc_caches don't contain * pkt, bytes and wrong_if values */ seq_printf(seq, " %8lu %8lu %8lu", 0ul, 0ul, 0ul); } seq_putc(seq, '\n'); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)11951.52%436.36%
Stephen Hemminger5925.54%19.09%
Benjamin Thery3515.15%218.18%
Patrick McHardy135.63%327.27%
Eric Dumazet52.16%19.09%
Total231100.00%11100.00%

static const struct seq_operations ipmr_mfc_seq_ops = { .start = ipmr_mfc_seq_start, .next = ipmr_mfc_seq_next, .stop = ipmr_mfc_seq_stop, .show = ipmr_mfc_seq_show, };
static int ipmr_mfc_open(struct inode *inode, struct file *file) { return seq_open_net(inode, file, &ipmr_mfc_seq_ops, sizeof(struct ipmr_mfc_iter)); }

Contributors

PersonTokensPropCommitsCommitProp
Stephen Hemminger2266.67%125.00%
Pavel Emelyanov721.21%125.00%
Benjamin Thery39.09%125.00%
Linus Torvalds (pre-git)13.03%125.00%
Total33100.00%4100.00%

static const struct file_operations ipmr_mfc_fops = { .owner = THIS_MODULE, .open = ipmr_mfc_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release_net, }; #endif #ifdef CONFIG_IP_PIMSM_V2 static const struct net_protocol pim_protocol = { .handler = pim_rcv, .netns_ok = 1, }; #endif /* Setup for IP multicast routing */
static int __net_init ipmr_net_init(struct net *net) { int err; err = ipmr_rules_init(net); if (err < 0) goto fail; #ifdef CONFIG_PROC_FS err = -ENOMEM; if (!proc_create("ip_mr_vif", 0, net->proc_net, &ipmr_vif_fops)) goto proc_vif_fail; if (!proc_create("ip_mr_cache", 0, net->proc_net, &ipmr_mfc_fops)) goto proc_cache_fail; #endif return 0; #ifdef CONFIG_PROC_FS proc_cache_fail: remove_proc_entry("ip_mr_vif", net->proc_net); proc_vif_fail: ipmr_rules_exit(net); #endif fail: return err; }

Contributors

PersonTokensPropCommitsCommitProp
Benjamin Thery9181.25%350.00%
Gao Feng1513.39%233.33%
Patrick McHardy65.36%116.67%
Total112100.00%6100.00%


static void __net_exit ipmr_net_exit(struct net *net) { #ifdef CONFIG_PROC_FS remove_proc_entry("ip_mr_cache", net->proc_net); remove_proc_entry("ip_mr_vif", net->proc_net); #endif ipmr_rules_exit(net); }

Contributors

PersonTokensPropCommitsCommitProp
Benjamin Thery2972.50%360.00%
Gao Feng1025.00%120.00%
Patrick McHardy12.50%120.00%
Total40100.00%5100.00%

static struct pernet_operations ipmr_net_ops = { .init = ipmr_net_init, .exit = ipmr_net_exit, };
int __init ip_mr_init(void) { int err; mrt_cachep = kmem_cache_create("ip_mrt_cache", sizeof(struct mfc_cache), 0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL); err = register_pernet_subsys(&ipmr_net_ops); if (err) goto reg_pernet_fail; err = register_netdevice_notifier(&ip_mr_notifier); if (err) goto reg_notif_fail; #ifdef CONFIG_IP_PIMSM_V2 if (inet_add_protocol(&pim_protocol, IPPROTO_PIM) < 0) { pr_err("%s: can't add PIM protocol\n", __func__); err = -EAGAIN; goto add_proto_fail; } #endif rtnl_register(RTNL_FAMILY_IPMR, RTM_GETROUTE, NULL, ipmr_rtm_dumproute, NULL); rtnl_register(RTNL_FAMILY_IPMR, RTM_NEWROUTE, ipmr_rtm_route, NULL, NULL); rtnl_register(RTNL_FAMILY_IPMR, RTM_DELROUTE, ipmr_rtm_route, NULL, NULL); return 0; #ifdef CONFIG_IP_PIMSM_V2 add_proto_fail: unregister_netdevice_notifier(&ip_mr_notifier); #endif reg_notif_fail: unregister_pernet_subsys(&ipmr_net_ops); reg_pernet_fail: kmem_cache_destroy(mrt_cachep); return err; }

Contributors

PersonTokensPropCommitsCommitProp
Thomas Goff4325.44%17.14%
Linus Torvalds (pre-git)3319.53%535.71%
Benjamin Thery2715.98%214.29%
Nikolay Aleksandrov2615.38%17.14%
Wang Chen2112.43%17.14%
Patrick McHardy116.51%17.14%
Joe Perches42.37%17.14%
Greg Rose21.18%17.14%
Alexey Dobriyan21.18%17.14%
Total169100.00%14100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)491334.75%2510.20%
Patrick McHardy213515.10%166.53%
Nikolay Aleksandrov205814.55%187.35%
Nicolas Dichtel10777.62%124.90%
Stephen Hemminger8716.16%93.67%
Benjamin Thery5724.05%104.08%
David S. Miller5293.74%228.98%
Eric Dumazet3412.41%145.71%
Wang Chen3012.13%31.22%
Eric W. Biedermann2631.86%124.90%
Alexey Kuznetsov1651.17%41.63%
Ilpo Järvinen1501.06%20.82%
Arnaldo Carvalho de Melo1441.02%176.94%
Thomas Goff840.59%20.82%
David Ahern530.37%10.41%
Francesco Ruggeri510.36%10.41%
Thomas Graf440.31%20.82%
Ilia K420.30%10.41%
Linus Torvalds310.22%41.63%
Pavel Emelyanov300.21%62.45%
Américo Wang260.18%52.04%
Gao Feng250.18%20.82%
Ian Morris220.16%10.41%
Herbert Xu210.15%31.22%
Hannes Frederic Sowa180.13%20.82%
Hirofumi Ogawa150.11%10.41%
Ben Greear140.10%10.41%
Al Viro130.09%41.63%
Andreas Meissner110.08%10.41%
Vincent Bernat90.06%10.41%
Dan Carpenter80.06%20.82%
Thomas Gleixner80.06%10.41%
Joe Perches70.05%31.22%
Raj70.05%10.41%
Changli Gao60.04%10.41%
Hong Zhi Guo50.04%10.41%
Denis V. Lunev50.04%31.22%
Simon Horman50.04%10.41%
Alexey Dobriyan40.03%31.22%
Kris Katterjohn40.03%10.41%
Randy Dunlap30.02%10.41%
Cong Wang30.02%10.41%
Ani Sinha30.02%10.41%
Jiri Pirko30.02%10.41%
Julian Anastasov30.02%10.41%
Baruch Even30.02%10.41%
Rami Rosen30.02%10.41%
Tejun Heo30.02%10.41%
Johannes Berg30.02%10.41%
Hideaki Yoshifuji / 吉藤英明30.02%20.82%
Paul Gortmaker30.02%10.41%
Tom Gundersen20.01%10.41%
Christoph Lameter20.01%10.41%
Arjan van de Ven20.01%10.41%
Jiri Benc20.01%10.41%
Robert P. J. Day20.01%10.41%
Greg Rose20.01%10.41%
Ben Hutchings10.01%10.41%
Pravin B Shelar10.01%10.41%
Li RongQing10.01%10.41%
Himangi Saraogi10.01%10.41%
Gilles Espinasse10.01%10.41%
Andi Kleen10.01%10.41%
Ansis Atteka10.01%10.41%
Jan Engelhardt10.01%10.41%
Total14140100.00%245100.00%
Directory: net/ipv4
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.