cregit-Linux how code gets into the kernel

Release 4.8 net/ipv4/devinet.c

Directory: net/ipv4
/*
 *      NET3    IP device support routines.
 *
 *              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.
 *
 *      Derived from the IP parts of dev.c 1.0.19
 *              Authors:        Ross Biro
 *                              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
 *                              Mark Evans, <evansmp@uhura.aston.ac.uk>
 *
 *      Additional Authors:
 *              Alan Cox, <gw4pts@gw4pts.ampr.org>
 *              Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
 *
 *      Changes:
 *              Alexey Kuznetsov:       pa_* fields are replaced with ifaddr
 *                                      lists.
 *              Cyrus Durgin:           updated for kmod
 *              Matthias Andree:        in devinet_ioctl, compare label and
 *                                      address (4.4BSD alias style support),
 *                                      fall back to comparing just the label
 *                                      if no match found.
 */


#include <asm/uaccess.h>
#include <linux/bitops.h>
#include <linux/capability.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/socket.h>
#include <linux/sockios.h>
#include <linux/in.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/if_addr.h>
#include <linux/if_ether.h>
#include <linux/inet.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/init.h>
#include <linux/notifier.h>
#include <linux/inetdevice.h>
#include <linux/igmp.h>
#include <linux/slab.h>
#include <linux/hash.h>
#ifdef CONFIG_SYSCTL
#include <linux/sysctl.h>
#endif
#include <linux/kmod.h>
#include <linux/netconf.h>

#include <net/arp.h>
#include <net/ip.h>
#include <net/route.h>
#include <net/ip_fib.h>
#include <net/rtnetlink.h>
#include <net/net_namespace.h>
#include <net/addrconf.h>

#include "fib_lookup.h"


static struct ipv4_devconf ipv4_devconf = {
	.data = {
		[IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
		[IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
		[IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
		[IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
		[IPV4_DEVCONF_IGMPV2_UNSOLICITED_REPORT_INTERVAL - 1] = 10000 /*ms*/,
		[IPV4_DEVCONF_IGMPV3_UNSOLICITED_REPORT_INTERVAL - 1] =  1000 /*ms*/,
        },
};


static struct ipv4_devconf ipv4_devconf_dflt = {
	.data = {
		[IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
		[IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
		[IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
		[IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
		[IPV4_DEVCONF_ACCEPT_SOURCE_ROUTE - 1] = 1,
		[IPV4_DEVCONF_IGMPV2_UNSOLICITED_REPORT_INTERVAL - 1] = 10000 /*ms*/,
		[IPV4_DEVCONF_IGMPV3_UNSOLICITED_REPORT_INTERVAL - 1] =  1000 /*ms*/,
        },
};


#define IPV4_DEVCONF_DFLT(net, attr) \
	IPV4_DEVCONF((*net->ipv4.devconf_dflt), attr)


static const struct nla_policy ifa_ipv4_policy[IFA_MAX+1] = {
	[IFA_LOCAL]     	= { .type = NLA_U32 },
	[IFA_ADDRESS]   	= { .type = NLA_U32 },
	[IFA_BROADCAST] 	= { .type = NLA_U32 },
	[IFA_LABEL]     	= { .type = NLA_STRING, .len = IFNAMSIZ - 1 },
	[IFA_CACHEINFO]		= { .len = sizeof(struct ifa_cacheinfo) },
	[IFA_FLAGS]		= { .type = NLA_U32 },
};


#define IN4_ADDR_HSIZE_SHIFT	8

#define IN4_ADDR_HSIZE		(1U << IN4_ADDR_HSIZE_SHIFT)


static struct hlist_head inet_addr_lst[IN4_ADDR_HSIZE];


static u32 inet_addr_hash(const struct net *net, __be32 addr) { u32 val = (__force u32) addr ^ net_hash_mix(net); return hash_32(val, IN4_ADDR_HSIZE_SHIFT); }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller2978.38%133.33%
eric dumazeteric dumazet821.62%266.67%
Total37100.00%3100.00%


static void inet_hash_insert(struct net *net, struct in_ifaddr *ifa) { u32 hash = inet_addr_hash(net, ifa->ifa_local); ASSERT_RTNL(); hlist_add_head_rcu(&ifa->hash, &inet_addr_lst[hash]); }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller4293.33%250.00%
americo wangamerico wang24.44%125.00%
eric dumazeteric dumazet12.22%125.00%
Total45100.00%4100.00%


static void inet_hash_remove(struct in_ifaddr *ifa) { ASSERT_RTNL(); hlist_del_init_rcu(&ifa->hash); }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller2090.91%150.00%
americo wangamerico wang29.09%150.00%
Total22100.00%2100.00%

/** * __ip_dev_find - find the first device with a given source address. * @net: the net namespace * @addr: the source address * @devref: if true, take a reference on the found device * * If a caller uses devref=false, it should be protected by RCU, or RTNL */
struct net_device *__ip_dev_find(struct net *net, __be32 addr, bool devref) { u32 hash = inet_addr_hash(net, addr); struct net_device *result = NULL; struct in_ifaddr *ifa; rcu_read_lock(); hlist_for_each_entry_rcu(ifa, &inet_addr_lst[hash], hash) { if (ifa->ifa_local == addr) { struct net_device *dev = ifa->ifa_dev->dev; if (!net_eq(dev_net(dev), net)) continue; result = dev; break; } } if (!result) { struct flowi4 fl4 = { .daddr = addr }; struct fib_result res = { 0 }; struct fib_table *local; /* Fallback to FIB local table so that communication * over loopback subnets work. */ local = fib_get_table(net, RT_TABLE_LOCAL); if (local && !fib_table_lookup(local, &fl4, &res, FIB_LOOKUP_NOREF) && res.type == RTN_LOCAL) result = FIB_RES_DEV(res); } if (result && devref) dev_hold(result); rcu_read_unlock(); return result; }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller17294.51%266.67%
eric dumazeteric dumazet105.49%133.33%
Total182100.00%3100.00%

EXPORT_SYMBOL(__ip_dev_find); static void rtmsg_ifa(int event, struct in_ifaddr *, struct nlmsghdr *, u32); static BLOCKING_NOTIFIER_HEAD(inetaddr_chain); static void inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap, int destroy); #ifdef CONFIG_SYSCTL static int devinet_sysctl_register(struct in_device *idev); static void devinet_sysctl_unregister(struct in_device *idev); #else
static int devinet_sysctl_register(struct in_device *idev) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pavel emelianovpavel emelianov857.14%150.00%
americo wangamerico wang642.86%150.00%
Total14100.00%2100.00%


static void devinet_sysctl_unregister(struct in_device *idev) { }

Contributors

PersonTokensPropCommitsCommitProp
pavel emelianovpavel emelianov10100.00%1100.00%
Total10100.00%1100.00%

#endif /* Locks all the inet devices. */
static struct in_ifaddr *inet_alloc_ifa(void) { return kzalloc(sizeof(struct in_ifaddr), GFP_KERNEL); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git1881.82%360.00%
alexey dobriyanalexey dobriyan313.64%120.00%
panagiotis issaris*panagiotis issaris*14.55%120.00%
Total22100.00%5100.00%


static void inet_rcu_free_ifa(struct rcu_head *head) { struct in_ifaddr *ifa = container_of(head, struct in_ifaddr, rcu_head); if (ifa->ifa_dev) in_dev_put(ifa->ifa_dev); kfree(ifa); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git2454.55%466.67%
herbert xuherbert xu1840.91%116.67%
david s. millerdavid s. miller24.55%116.67%
Total44100.00%6100.00%


static void inet_free_ifa(struct in_ifaddr *ifa) { call_rcu(&ifa->rcu_head, inet_rcu_free_ifa); }

Contributors

PersonTokensPropCommitsCommitProp
david s. millerdavid s. miller1047.62%125.00%
herbert xuherbert xu942.86%125.00%
pre-gitpre-git29.52%250.00%
Total21100.00%4100.00%


void in_dev_finish_destroy(struct in_device *idev) { struct net_device *dev = idev->dev; WARN_ON(idev->ifa_list); WARN_ON(idev->mc_list); kfree(rcu_dereference_protected(idev->mc_hash, 1)); #ifdef NET_REFCNT_DEBUG pr_debug("%s: %p=%s\n", __func__, idev, dev ? dev->name : "NIL"); #endif dev_put(dev); if (!idev->dead) pr_err("Freeing alive in_device %p\n", idev); else kfree(idev); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git7278.26%228.57%
eric dumazeteric dumazet1314.13%228.57%
joe perchesjoe perches44.35%114.29%
ilpo jarvinenilpo jarvinen22.17%114.29%
arnaldo carvalho de meloarnaldo carvalho de melo11.09%114.29%
Total92100.00%7100.00%

EXPORT_SYMBOL(in_dev_finish_destroy);
static struct in_device *inetdev_init(struct net_device *dev) { struct in_device *in_dev; int err = -ENOMEM; ASSERT_RTNL(); in_dev = kzalloc(sizeof(*in_dev), GFP_KERNEL); if (!in_dev) goto out; memcpy(&in_dev->cnf, dev_net(dev)->ipv4.devconf_dflt, sizeof(in_dev->cnf)); in_dev->cnf.sysctl = NULL; in_dev->dev = dev; in_dev->arp_parms = neigh_parms_alloc(dev, &arp_tbl); if (!in_dev->arp_parms) goto out_kfree; if (IPV4_DEVCONF(in_dev->cnf, FORWARDING)) dev_disable_lro(dev); /* Reference in_dev->dev */ dev_hold(dev); /* Account for reference dev->ip_ptr (below) */ in_dev_hold(in_dev); err = devinet_sysctl_register(in_dev); if (err) { in_dev->dead = 1; in_dev_put(in_dev); in_dev = NULL; goto out; } ip_mc_init_dev(in_dev); if (dev->flags & IFF_UP) ip_mc_up(in_dev); /* we can receive as soon as ip_ptr is set -- do this last */ rcu_assign_pointer(dev->ip_ptr, in_dev); out: return in_dev ?: ERR_PTR(err); out_kfree: kfree(in_dev); in_dev = NULL; goto out; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git10949.55%735.00%
americo wangamerico wang3817.27%15.00%
arnaldo carvalho de meloarnaldo carvalho de melo209.09%15.00%
ben hutchingsben hutchings167.27%15.00%
david l stevensdavid l stevens156.82%210.00%
eric dumazeteric dumazet83.64%210.00%
pavel emelianovpavel emelianov52.27%15.00%
hideaki yoshifujihideaki yoshifuji31.36%15.00%
david s. millerdavid s. miller20.91%15.00%
jarek poplawskijarek poplawski20.91%15.00%
panagiotis issaris*panagiotis issaris*10.45%15.00%
herbert xuherbert xu10.45%15.00%
Total220100.00%20100.00%


static void in_dev_rcu_put(struct rcu_head *head) { struct in_device *idev = container_of(head, struct in_device, rcu_head); in_dev_put(idev); }

Contributors

PersonTokensPropCommitsCommitProp
herbert xuherbert xu31100.00%1100.00%
Total31100.00%1100.00%


static void inetdev_destroy(struct in_device *in_dev) { struct in_ifaddr *ifa; struct net_device *dev; ASSERT_RTNL(); dev = in_dev->dev; in_dev->dead = 1; ip_mc_destroy_dev(in_dev); while ((ifa = in_dev->ifa_list) != NULL) { inet_del_ifa(in_dev, &in_dev->ifa_list, 0); inet_free_ifa(ifa); } RCU_INIT_POINTER(dev->ip_ptr, NULL); devinet_sysctl_unregister(in_dev); neigh_parms_release(&arp_tbl, in_dev->arp_parms); arp_ifdown(dev); call_rcu(&in_dev->rcu_head, in_dev_rcu_put); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git7870.27%433.33%
herbert xuherbert xu2421.62%433.33%
hideaki yoshifujihideaki yoshifuji43.60%18.33%
eric dumazeteric dumazet32.70%18.33%
pavel emelianovpavel emelianov10.90%18.33%
stephen hemmingerstephen hemminger10.90%18.33%
Total111100.00%12100.00%


int inet_addr_onlink(struct in_device *in_dev, __be32 a, __be32 b) { rcu_read_lock(); for_primary_ifa(in_dev) { if (inet_ifa_match(a, ifa)) { if (!b || inet_ifa_match(b, ifa)) { rcu_read_unlock(); return 1; } } } endfor_ifa(in_dev); rcu_read_unlock(); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git5988.06%571.43%
david s. millerdavid s. miller68.96%114.29%
al viroal viro22.99%114.29%
Total67100.00%7100.00%


static void __inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap, int destroy, struct nlmsghdr *nlh, u32 portid) { struct in_ifaddr *promote = NULL; struct in_ifaddr *ifa, *ifa1 = *ifap; struct in_ifaddr *last_prim = in_dev->ifa_list; struct in_ifaddr *prev_prom = NULL; int do_promote = IN_DEV_PROMOTE_SECONDARIES(in_dev); ASSERT_RTNL(); if (in_dev->dead) goto no_promotions; /* 1. Deleting primary ifaddr forces deletion all secondaries * unless alias promotion is set **/ if (!(ifa1->ifa_flags & IFA_F_SECONDARY)) { struct in_ifaddr **ifap1 = &ifa1->ifa_next; while ((ifa = *ifap1) != NULL) { if (!(ifa->ifa_flags & IFA_F_SECONDARY) && ifa1->ifa_scope <= ifa->ifa_scope) last_prim = ifa; if (!(ifa->ifa_flags & IFA_F_SECONDARY) || ifa1->ifa_mask != ifa->ifa_mask || !inet_ifa_match(ifa1->ifa_address, ifa)) { ifap1 = &ifa->ifa_next; prev_prom = ifa; continue; } if (!do_promote) { inet_hash_remove(ifa); *ifap1 = ifa->ifa_next; rtmsg_ifa(RTM_DELADDR, ifa, nlh, portid); blocking_notifier_call_chain(&inetaddr_chain, NETDEV_DOWN, ifa); inet_free_ifa(ifa); } else { promote = ifa; break; } } } /* On promotion all secondaries from subnet are changing * the primary IP, we must remove all their routes silently * and later to add them back with new prefsrc. Do this * while all addresses are on the device list. */ for (ifa = promote; ifa; ifa = ifa->ifa_next) { if (ifa1->ifa_mask == ifa->ifa_mask && inet_ifa_match(ifa1->ifa_address, ifa)) fib_del_ifaddr(ifa, ifa1); } no_promotions: /* 2. Unlink it */ *ifap = ifa1->ifa_next; inet_hash_remove(ifa1); /* 3. Announce address deletion */ /* Send message first, then call notifier. At first sight, FIB update triggered by notifier will refer to already deleted ifaddr, that could confuse netlink listeners. It is not true: look, gated sees that route deleted and if it still thinks that ifaddr is valid, it will try to restore deleted routes... Grr. So that, this order is correct. */ rtmsg_ifa(RTM_DELADDR, ifa1, nlh, portid); blocking_notifier_call_chain(&inetaddr_chain, NETDEV_DOWN, ifa1); if (promote) { struct in_ifaddr *next_sec = promote->ifa_next; if (prev_prom) { prev_prom->ifa_next = promote->ifa_next; promote->ifa_next = last_prim->ifa_next; last_prim->ifa_next = promote; } promote->ifa_flags &= ~IFA_F_SECONDARY; rtmsg_ifa(RTM_NEWADDR, promote, nlh, portid); blocking_notifier_call_chain(&inetaddr_chain, NETDEV_UP, promote); for (ifa = next_sec; ifa; ifa = ifa->ifa_next) { if (ifa1->ifa_mask != ifa->ifa_mask || !inet_ifa_match(ifa1->ifa_address, ifa)) continue; fib_add_ifaddr(ifa); } } if (destroy) inet_free_ifa(ifa1); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git16737.78%738.89%
jamal hadi salimjamal hadi salim13029.41%15.56%
julian anastasovjulian anastasov5311.99%211.11%
harald welteharald welte4510.18%15.56%
david s. millerdavid s. miller214.75%211.11%
thomas grafthomas graf173.85%15.56%
eric w. biedermaneric w. biederman40.90%15.56%
alan sternalan stern30.68%15.56%
hideaki yoshifujihideaki yoshifuji10.23%15.56%
herbert xuherbert xu10.23%15.56%
Total442100.00%18100.00%


static void inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap, int destroy) { __inet_del_ifa(in_dev, ifap, destroy, NULL, 0); }

Contributors

PersonTokensPropCommitsCommitProp
thomas grafthomas graf3193.94%150.00%
pre-gitpre-git26.06%150.00%
Total33100.00%2100.00%

static void check_lifetime(struct work_struct *work); static DECLARE_DELAYED_WORK(check_lifetime_work, check_lifetime);
static int __inet_insert_ifa(struct in_ifaddr *ifa, struct nlmsghdr *nlh, u32 portid) { struct in_device *in_dev = ifa->ifa_dev; struct in_ifaddr *ifa1, **ifap, **last_primary; ASSERT_RTNL(); if (!ifa->ifa_local) { inet_free_ifa(ifa); return 0; } ifa->ifa_flags &= ~IFA_F_SECONDARY; last_primary = &in_dev->ifa_list; for (ifap = &in_dev->ifa_list; (ifa1 = *ifap) != NULL; ifap = &ifa1->ifa_next) { if (!(ifa1->ifa_flags & IFA_F_SECONDARY) && ifa->ifa_scope <= ifa1->ifa_scope) last_primary = &ifa1->ifa_next; if (ifa1->ifa_mask == ifa->ifa_mask && inet_ifa_match(ifa1->ifa_address, ifa)) { if (ifa1->ifa_local == ifa->ifa_local) { inet_free_ifa(ifa); return -EEXIST; } if (ifa1->ifa_scope != ifa->ifa_scope) { inet_free_ifa(ifa); return -EINVAL; } ifa->ifa_flags |= IFA_F_SECONDARY; } } if (!(ifa->ifa_flags & IFA_F_SECONDARY)) { prandom_seed((__force u32) ifa->ifa_local); ifap = last_primary; } ifa->ifa_next = *ifap; *ifap = ifa; inet_hash_insert(dev_net(in_dev->dev), ifa); cancel_delayed_work(&check_lifetime_work); queue_delayed_work(system_power_efficient_wq, &check_lifetime_work, 0); /* Send message first, then call notifier. Notifier will trigger FIB update, so that listeners of netlink will know about new ifaddr */ rtmsg_ifa(RTM_NEWADDR, ifa, nlh, portid); blocking_notifier_call_chain(&inetaddr_chain, NETDEV_UP, ifa); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git23781.72%535.71%
jiri pirkojiri pirko134.48%17.14%
thomas grafthomas graf134.48%17.14%
david s. millerdavid s. miller124.14%17.14%
aruna-hewapathiranearuna-hewapathirane51.72%17.14%
herbert xuherbert xu31.03%17.14%
viresh kumarviresh kumar31.03%17.14%
eric w. biedermaneric w. biederman20.69%17.14%
arnaldo carvalho de meloarnaldo carvalho de melo10.34%17.14%
alan sternalan stern10.34%17.14%
Total290100.00%14100.00%


static int inet_insert_ifa(struct in_ifaddr *ifa) { return __inet_insert_ifa(ifa, NULL, 0); }

Contributors

PersonTokensPropCommitsCommitProp
thomas grafthomas graf21100.00%1100.00%
Total21100.00%1100.00%


static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa) { struct in_device *in_dev = __in_dev_get_rtnl(dev); ASSERT_RTNL(); if (!in_dev) { inet_free_ifa(ifa); return -ENOBUFS; } ipv4_devconf_setall(in_dev); neigh_parms_data_state_setall(in_dev->arp_parms); if (ifa->ifa_dev != in_dev) { WARN_ON(ifa->ifa_dev); in_dev_hold(in_dev); ifa->ifa_dev = in_dev; } if (ipv4_is_loopback(ifa->ifa_local)) ifa->ifa_scope = RT_SCOPE_HOST; return inet_insert_ifa(ifa); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git8983.96%541.67%
jiri pirkojiri pirko76.60%18.33%
herbert xuherbert xu76.60%325.00%
ilpo jarvinenilpo jarvinen10.94%18.33%
joe perchesjoe perches10.94%18.33%
arnaldo carvalho de meloarnaldo carvalho de melo10.94%18.33%
Total106100.00%12100.00%

/* Caller must hold RCU or RTNL : * We dont take a reference on found in_device */
struct in_device *inetdev_by_index(struct net *net, int ifindex) { struct net_device *dev; struct in_device *in_dev = NULL; rcu_read_lock(); dev = dev_get_by_index_rcu(net, ifindex); if (dev) in_dev = rcu_dereference_rtnl(dev->ip_ptr); rcu_read_unlock(); return in_dev; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git4374.14%555.56%
eric dumazeteric dumazet813.79%222.22%
denis v. lunevdenis v. lunev610.34%111.11%
eric w. biedermaneric w. biederman11.72%111.11%
Total58100.00%9100.00%

EXPORT_SYMBOL(inetdev_by_index); /* Called only from RTNL semaphored context. No locks. */
struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix, __be32 mask) { ASSERT_RTNL(); for_primary_ifa(in_dev) { if (ifa->ifa_mask == mask && inet_ifa_match(prefix, ifa)) return ifa; } endfor_ifa(in_dev); return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git5196.23%583.33%
al viroal viro23.77%116.67%
Total53100.00%6100.00%


static int ip_mc_config(struct sock *sk, bool join, const struct in_ifaddr *ifa) { struct ip_mreqn mreq = { .imr_multiaddr.s_addr = ifa->ifa_address, .imr_ifindex = ifa->ifa_dev->dev->ifindex, }; int ret; ASSERT_RTNL(); lock_sock(sk); if (join) ret = ip_mc_join_group(sk, &mreq); else ret = ip_mc_leave_group(sk, &mreq); release_sock(sk); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
madhu challamadhu challa8897.78%150.00%
marcelo ricardo leitnermarcelo ricardo leitner22.22%150.00%
Total90100.00%2100.00%


static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh) { struct net *net = sock_net(skb->sk); struct nlattr *tb[IFA_MAX+1]; struct in_device *in_dev; struct ifaddrmsg *ifm; struct in_ifaddr *ifa, **ifap; int err = -EINVAL; ASSERT_RTNL(); err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv4_policy); if (err < 0) goto errout; ifm = nlmsg_data(nlh); in_dev = inetdev_by_index(net, ifm->ifa_index); if (!in_dev) { err = -ENODEV; goto errout; } for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL; ifap = &ifa->ifa_next) { if (tb[IFA_LOCAL] && ifa->ifa_local != nla_get_in_addr(tb[IFA_LOCAL])) continue; if (tb[IFA_LABEL] && nla_strcmp(tb[IFA_LABEL], ifa->ifa_label)) continue; if (tb[IFA_ADDRESS] && (ifm->ifa_prefixlen != ifa->ifa_prefixlen || !inet_ifa_match(nla_get_in_addr(tb[IFA_ADDRESS]), ifa))) continue; if (ipv4_is_multicast(ifa->ifa_address)) ip_mc_config(net->ipv4.mc_autojoin_sk, false, ifa); __inet_del_ifa(in_dev, ifap, 1, nlh, NETLINK_CB(skb).portid); return 0; } err = -EADDRNOTAVAIL; errout: return err; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git13949.82%633.33%
thomas grafthomas graf9634.41%316.67%
madhu challamadhu challa227.89%15.56%
denis v. lunevdenis v. lunev113.94%211.11%
arnaldo carvalho de meloarnaldo carvalho de melo31.08%15.56%
hideaki yoshifujihideaki yoshifuji31.08%15.56%
jiri bencjiri benc20.72%15.56%
ian morrisian morris10.36%15.56%
eric w. biedermaneric w. biederman10.36%15.56%
adrian bunkadrian bunk10.36%15.56%
Total279100.00%18100.00%

#define INFINITY_LIFE_TIME 0xFFFFFFFF
static void check_lifetime(struct work_struct *work) { unsigned long now, next, next_sec, next_sched; struct in_ifaddr *ifa; struct hlist_node *n; int i; now = jiffies; next = round_jiffies_up(now + ADDR_CHECK_FREQUENCY); for (i = 0; i < IN4_ADDR_HSIZE; i++) { bool change_needed = false; rcu_read_lock(); hlist_for_each_entry_rcu(ifa, &inet_addr_lst[i], hash) { unsigned long age; if (ifa->ifa_flags & IFA_F_PERMANENT) continue; /* We try to batch several events at once. */ age = (now - ifa->ifa_tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ; if (ifa->ifa_valid_lft != INFINITY_LIFE_TIME && age >= ifa->ifa_valid_lft) { change_needed = true; } else if (ifa->ifa_preferred_lft == INFINITY_LIFE_TIME) { continue; } else if (age >= ifa->ifa_preferred_lft) { if (time_before(ifa->ifa_tstamp + ifa->ifa_valid_lft * HZ, next)) next = ifa->ifa_tstamp + ifa->ifa_valid_lft * HZ; if (!(ifa->ifa_flags & IFA_F_DEPRECATED)) change_needed = true; } else if (time_before(ifa->ifa_tstamp + ifa->ifa_preferred_lft * HZ, next)) { next = ifa->ifa_tstamp + ifa->ifa_preferred_lft * HZ