cregit-Linux how code gets into the kernel

Release 4.18 net/ipv6/anycast.c

Directory: net/ipv6
/*
 *      Anycast support for IPv6
 *      Linux INET6 implementation
 *
 *      Authors:
 *      David L Stevens (dlstevens@us.ibm.com)
 *
 *      based heavily on net/ipv6/mcast.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.
 */

#include <linux/capability.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/random.h>
#include <linux/string.h>
#include <linux/socket.h>
#include <linux/sockios.h>
#include <linux/net.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 <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/checksum.h>

static int ipv6_dev_ac_dec(struct net_device *dev, const struct in6_addr *addr);

/*
 *      socket join an anycast group
 */


int ipv6_sock_ac_join(struct sock *sk, int ifindex, const struct in6_addr *addr) { struct ipv6_pinfo *np = inet6_sk(sk); struct net_device *dev = NULL; struct inet6_dev *idev; struct ipv6_ac_socklist *pac; struct net *net = sock_net(sk); int ishost = !net->ipv6.devconf_all->forwarding; int err = 0; ASSERT_RTNL(); if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) return -EPERM; if (ipv6_addr_is_multicast(addr)) return -EINVAL; if (ifindex) dev = __dev_get_by_index(net, ifindex); if (ipv6_chk_addr_and_flags(net, addr, dev, true, 0, IFA_F_TENTATIVE)) return -EINVAL; pac = sock_kmalloc(sk, sizeof(struct ipv6_ac_socklist), GFP_KERNEL); if (!pac) return -ENOMEM; pac->acl_next = NULL; pac->acl_addr = *addr; if (ifindex == 0) { struct rt6_info *rt; rt = rt6_lookup(net, addr, NULL, 0, NULL, 0); if (rt) { dev = rt->dst.dev; ip6_rt_put(rt); } else if (ishost) { err = -EADDRNOTAVAIL; goto error; } else { /* router, no matching interface: just pick one */ dev = __dev_get_by_flags(net, IFF_UP, IFF_UP | IFF_LOOPBACK); } } if (!dev) { err = -ENODEV; goto error; } idev = __in6_dev_get(dev); if (!idev) { if (ifindex) err = -ENODEV; else err = -EADDRNOTAVAIL; goto error; } /* reset ishost, now that we have a specific device */ ishost = !idev->cnf.forwarding; pac->acl_ifindex = dev->ifindex; /* XXX * For hosts, allow link-local or matching prefix anycasts. * This obviates the need for propagating anycast routes while * still allowing some non-router anycast participation. */ if (!ipv6_chk_prefix(addr, dev)) { if (ishost) err = -EADDRNOTAVAIL; if (err) goto error; } err = __ipv6_dev_ac_inc(idev, addr); if (!err) { pac->acl_next = np->ipv6_ac_list; np->ipv6_ac_list = pac; pac = NULL; } error: if (pac) sock_kfree_s(sk, pac, sizeof(*pac)); return err; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens26364.94%14.35%
David S. Miller409.88%28.70%
Alexey Kuznetsov235.68%14.35%
David Ahern215.19%28.70%
Eric Dumazet174.20%28.70%
Daniel Lezcano153.70%313.04%
Hideaki Yoshifuji / 吉藤英明71.73%313.04%
Eric W. Biedermann61.48%28.70%
Américo Wang40.99%313.04%
Marcelo Ricardo Leitner30.74%14.35%
Alexey Dobriyan20.49%14.35%
Ville Nuorvala20.49%14.35%
Ian Morris20.49%14.35%
Total405100.00%23100.00%

/* * socket leave an anycast group */
int ipv6_sock_ac_drop(struct sock *sk, int ifindex, const struct in6_addr *addr) { struct ipv6_pinfo *np = inet6_sk(sk); struct net_device *dev; struct ipv6_ac_socklist *pac, *prev_pac; struct net *net = sock_net(sk); ASSERT_RTNL(); prev_pac = NULL; for (pac = np->ipv6_ac_list; pac; pac = pac->acl_next) { if ((ifindex == 0 || pac->acl_ifindex == ifindex) && ipv6_addr_equal(&pac->acl_addr, addr)) break; prev_pac = pac; } if (!pac) return -ENOENT; if (prev_pac) prev_pac->acl_next = pac->acl_next; else np->ipv6_ac_list = pac->acl_next; dev = __dev_get_by_index(net, pac->acl_ifindex); if (dev) ipv6_dev_ac_dec(dev, &pac->acl_addr); sock_kfree_s(sk, pac, sizeof(*pac)); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens15989.83%111.11%
Daniel Lezcano116.21%111.11%
Américo Wang21.13%222.22%
Hideaki Yoshifuji / 吉藤英明10.56%111.11%
Eric Dumazet10.56%111.11%
Eric W. Biedermann10.56%111.11%
Marcelo Ricardo Leitner10.56%111.11%
Al Viro10.56%111.11%
Total177100.00%9100.00%


void ipv6_sock_ac_close(struct sock *sk) { struct ipv6_pinfo *np = inet6_sk(sk); struct net_device *dev = NULL; struct ipv6_ac_socklist *pac; struct net *net = sock_net(sk); int prev_index; if (!np->ipv6_ac_list) return; rtnl_lock(); pac = np->ipv6_ac_list; np->ipv6_ac_list = NULL; prev_index = 0; while (pac) { struct ipv6_ac_socklist *next = pac->acl_next; if (pac->acl_ifindex != prev_index) { dev = __dev_get_by_index(net, pac->acl_ifindex); prev_index = pac->acl_ifindex; } if (dev) ipv6_dev_ac_dec(dev, &pac->acl_addr); sock_kfree_s(sk, pac, sizeof(*pac)); pac = next; } rtnl_unlock(); }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens12081.08%112.50%
Daniel Lezcano117.43%112.50%
Eric Dumazet85.41%112.50%
Américo Wang32.03%225.00%
Sabrina Dubroca32.03%112.50%
Al Viro21.35%112.50%
Eric W. Biedermann10.68%112.50%
Total148100.00%8100.00%


static void aca_get(struct ifacaddr6 *aca) { refcount_inc(&aca->aca_refcnt); }

Contributors

PersonTokensPropCommitsCommitProp
Américo Wang1894.74%150.00%
Elena Reshetova15.26%150.00%
Total19100.00%2100.00%


static void aca_put(struct ifacaddr6 *ac) { if (refcount_dec_and_test(&ac->aca_refcnt)) { fib6_info_release(ac->aca_rt); kfree(ac); } }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens3085.71%125.00%
Hideaki Yoshifuji / 吉藤英明38.57%125.00%
David Ahern12.86%125.00%
Elena Reshetova12.86%125.00%
Total35100.00%4100.00%


static struct ifacaddr6 *aca_alloc(struct fib6_info *f6i, const struct in6_addr *addr) { struct ifacaddr6 *aca; aca = kzalloc(sizeof(*aca), GFP_ATOMIC); if (!aca) return NULL; aca->aca_addr = *addr; fib6_info_hold(f6i); aca->aca_rt = f6i; aca->aca_users = 1; /* aca_tstamp should be updated upon changes */ aca->aca_cstamp = aca->aca_tstamp = jiffies; refcount_set(&aca->aca_refcnt, 1); return aca; }

Contributors

PersonTokensPropCommitsCommitProp
Américo Wang8692.47%116.67%
David Ahern55.38%350.00%
Elena Reshetova11.08%116.67%
Ian Morris11.08%116.67%
Total93100.00%6100.00%

/* * device anycast group inc (add if not found) */
int __ipv6_dev_ac_inc(struct inet6_dev *idev, const struct in6_addr *addr) { struct ifacaddr6 *aca; struct fib6_info *f6i; struct net *net; int err; ASSERT_RTNL(); write_lock_bh(&idev->lock); if (idev->dead) { err = -ENODEV; goto out; } for (aca = idev->ac_list; aca; aca = aca->aca_next) { if (ipv6_addr_equal(&aca->aca_addr, addr)) { aca->aca_users++; err = 0; goto out; } } net = dev_net(idev->dev); f6i = addrconf_f6i_alloc(net, idev, addr, true, GFP_ATOMIC); if (IS_ERR(f6i)) { err = PTR_ERR(f6i); goto out; } aca = aca_alloc(f6i, addr); if (!aca) { fib6_info_release(f6i); err = -ENOMEM; goto out; } aca->aca_next = idev->ac_list; idev->ac_list = aca; /* Hold this for addrconf_join_solict() below before we unlock, * it is already exposed via idev->ac_list. */ aca_get(aca); write_unlock_bh(&idev->lock); ip6_ins_rt(net, f6i); addrconf_join_solict(idev->dev, &aca->aca_addr); aca_put(aca); return 0; out: write_unlock_bh(&idev->lock); return err; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens12952.65%16.25%
Hideaki Yoshifuji / 吉藤英明5522.45%212.50%
Américo Wang2711.02%212.50%
David Ahern2610.61%531.25%
Sabrina Dubroca31.22%16.25%
David S. Miller10.41%16.25%
Ian Morris10.41%16.25%
Andrew Morton10.41%16.25%
Eric Dumazet10.41%16.25%
Alexey Dobriyan10.41%16.25%
Total245100.00%16100.00%

/* * device anycast group decrement */
int __ipv6_dev_ac_dec(struct inet6_dev *idev, const struct in6_addr *addr) { struct ifacaddr6 *aca, *prev_aca; ASSERT_RTNL(); write_lock_bh(&idev->lock); prev_aca = NULL; for (aca = idev->ac_list; aca; aca = aca->aca_next) { if (ipv6_addr_equal(&aca->aca_addr, addr)) break; prev_aca = aca; } if (!aca) { write_unlock_bh(&idev->lock); return -ENOENT; } if (--aca->aca_users > 0) { write_unlock_bh(&idev->lock); return 0; } if (prev_aca) prev_aca->aca_next = aca->aca_next; else idev->ac_list = aca->aca_next; write_unlock_bh(&idev->lock); addrconf_leave_solict(idev, &aca->aca_addr); ip6_del_rt(dev_net(idev->dev), aca->aca_rt); aca_put(aca); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens15085.23%111.11%
Hideaki Yoshifuji / 吉藤英明169.09%444.44%
David Ahern52.84%111.11%
Sabrina Dubroca31.70%111.11%
Al Viro10.57%111.11%
Eric Dumazet10.57%111.11%
Total176100.00%9100.00%

/* called with rtnl_lock() */
static int ipv6_dev_ac_dec(struct net_device *dev, const struct in6_addr *addr) { struct inet6_dev *idev = __in6_dev_get(dev); if (!idev) return -ENODEV; return __ipv6_dev_ac_dec(idev, addr); }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明3784.09%116.67%
Eric Dumazet36.82%233.33%
David L Stevens24.55%116.67%
Adrian Bunk12.27%116.67%
Ian Morris12.27%116.67%
Total44100.00%6100.00%


void ipv6_ac_destroy_dev(struct inet6_dev *idev) { struct ifacaddr6 *aca; write_lock_bh(&idev->lock); while ((aca = idev->ac_list) != NULL) { idev->ac_list = aca->aca_next; write_unlock_bh(&idev->lock); addrconf_leave_solict(idev, &aca->aca_addr); ip6_del_rt(dev_net(idev->dev), aca->aca_rt); aca_put(aca); write_lock_bh(&idev->lock); } write_unlock_bh(&idev->lock); }

Contributors

PersonTokensPropCommitsCommitProp
Sabrina Dubroca9394.90%150.00%
David Ahern55.10%150.00%
Total98100.00%2100.00%

/* * check if the interface has this anycast address * called with rcu_read_lock() */
static bool ipv6_chk_acast_dev(struct net_device *dev, const struct in6_addr *addr) { struct inet6_dev *idev; struct ifacaddr6 *aca; idev = __in6_dev_get(dev); if (idev) { read_lock_bh(&idev->lock); for (aca = idev->ac_list; aca; aca = aca->aca_next) if (ipv6_addr_equal(&aca->aca_addr, addr)) break; read_unlock_bh(&idev->lock); return aca != NULL; } return false; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens8793.55%116.67%
Eric Dumazet44.30%350.00%
Hideaki Yoshifuji / 吉藤英明11.08%116.67%
Stephen Hemminger11.08%116.67%
Total93100.00%6100.00%

/* * check if given interface (or any, if dev==0) has this anycast address */
bool ipv6_chk_acast_addr(struct net *net, struct net_device *dev, const struct in6_addr *addr) { bool found = false; rcu_read_lock(); if (dev) found = ipv6_chk_acast_dev(dev, addr); else for_each_netdev_rcu(net, dev) if (ipv6_chk_acast_dev(dev, addr)) { found = true; break; } rcu_read_unlock(); return found; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens3853.52%112.50%
Eric Dumazet1419.72%450.00%
Pavel Emelyanov1216.90%112.50%
Daniel Lezcano68.45%112.50%
Eric W. Biedermann11.41%112.50%
Total71100.00%8100.00%

/* check if this anycast address is link-local on given interface or * is global */
bool ipv6_chk_acast_addr_src(struct net *net, struct net_device *dev, const struct in6_addr *addr) { return ipv6_chk_acast_addr(net, (ipv6_addr_type(addr) & IPV6_ADDR_LINKLOCAL ? dev : NULL), addr); }

Contributors

PersonTokensPropCommitsCommitProp
François-Xavier Le Bail42100.00%1100.00%
Total42100.00%1100.00%

#ifdef CONFIG_PROC_FS struct ac6_iter_state { struct seq_net_private p; struct net_device *dev; struct inet6_dev *idev; }; #define ac6_seq_private(seq) ((struct ac6_iter_state *)(seq)->private)
static inline struct ifacaddr6 *ac6_get_first(struct seq_file *seq) { struct ifacaddr6 *im = NULL; struct ac6_iter_state *state = ac6_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->ac_list; if (im) { state->idev = idev; break; } read_unlock_bh(&idev->lock); } return im; }

Contributors

PersonTokensPropCommitsCommitProp
David L Stevens4842.48%116.67%
Hideaki Yoshifuji / 吉藤英明4741.59%116.67%
Daniel Lezcano119.73%116.67%
Pavel Emelyanov43.54%116.67%
Eric Dumazet21.77%116.67%
Eric W. Biedermann10.88%116.67%
Total113100.00%6100.00%


static struct ifacaddr6 *ac6_get_next(struct seq_file *seq, struct ifacaddr6 *im) { struct ac6_iter_state *state = ac6_seq_private(seq); im = im->aca_next; while (!im) { if (likely(state->idev != NULL)) 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->ac_list; } return im; }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明9573.64%125.00%
David L Stevens3023.26%125.00%
Eric Dumazet21.55%125.00%
Pavel Emelyanov21.55%125.00%
Total129100.00%4100.00%


static struct ifacaddr6 *ac6_get_idx(struct seq_file *seq, loff_t pos) { struct ifacaddr6 *im = ac6_get_first(seq); if (im) while (pos && (im = ac6_get_next(seq, im)) != NULL) --pos; return pos ? NULL : im; }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明57100.00%1100.00%
Total57100.00%1100.00%


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

Contributors

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


static void *ac6_seq_next(struct seq_file *seq, void *v, loff_t *pos) { struct ifacaddr6 *im = ac6_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 ac6_seq_stop(struct seq_file *seq, void *v) __releases(RCU) { struct ac6_iter_state *state = ac6_seq_private(seq); if (likely(state->idev != NULL)) { read_unlock_bh(&state->idev->lock); state->idev = NULL; } rcu_read_unlock(); }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明5386.89%133.33%
Eric Dumazet813.11%266.67%
Total61100.00%3100.00%


static int ac6_seq_show(struct seq_file *seq, void *v) { struct ifacaddr6 *im = (struct ifacaddr6 *)v; struct ac6_iter_state *state = ac6_seq_private(seq); seq_printf(seq, "%-4d %-15s %pi6 %5d\n", state->dev->ifindex, state->dev->name, &im->aca_addr, im->aca_users); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明6697.06%133.33%
Harvey Harrison22.94%266.67%
Total68100.00%3100.00%

static const struct seq_operations ac6_seq_ops = { .start = ac6_seq_start, .next = ac6_seq_next, .stop = ac6_seq_stop, .show = ac6_seq_show, };
int __net_init ac6_proc_init(struct net *net) { if (!proc_create_net("anycast6", 0444, net->proc_net, &ac6_seq_ops, sizeof(struct ac6_iter_state))) return -ENOMEM; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明2356.10%228.57%
Christoph Hellwig819.51%114.29%
Daniel Lezcano49.76%114.29%
Gao Feng49.76%114.29%
Joe Perches12.44%114.29%
Alexey Dobriyan12.44%114.29%
Total41100.00%7100.00%


void ac6_proc_exit(struct net *net) { remove_proc_entry("anycast6", net->proc_net); }

Contributors

PersonTokensPropCommitsCommitProp
Hideaki Yoshifuji / 吉藤英明947.37%125.00%
Gao Feng526.32%125.00%
Daniel Lezcano421.05%125.00%
David L Stevens15.26%125.00%
Total19100.00%4100.00%

#endif

Overall Contributors

PersonTokensPropCommitsCommitProp
David L Stevens113848.02%11.54%
Hideaki Yoshifuji / 吉藤英明58424.64%1116.92%
Américo Wang1415.95%57.69%
Sabrina Dubroca1024.30%23.08%
Eric Dumazet713.00%710.77%
Daniel Lezcano662.78%34.62%
David Ahern632.66%812.31%
François-Xavier Le Bail431.81%11.54%
David S. Miller411.73%34.62%
Alexey Kuznetsov230.97%11.54%
Pavel Emelyanov180.76%11.54%
Adrian Bunk160.68%11.54%
Eric W. Biedermann130.55%34.62%
Gao Feng90.38%23.08%
Christoph Hellwig80.34%11.54%
Ian Morris50.21%11.54%
Marcelo Ricardo Leitner40.17%11.54%
Al Viro40.17%11.54%
Alexey Dobriyan40.17%23.08%
Randy Dunlap30.13%11.54%
Elena Reshetova30.13%11.54%
Tejun Heo30.13%11.54%
Ville Nuorvala20.08%11.54%
Harvey Harrison20.08%23.08%
Joe Perches10.04%11.54%
Stephen Hemminger10.04%11.54%
Philippe De Muyter10.04%11.54%
Andrew Morton10.04%11.54%
Total2370100.00%65100.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.