addrconf.c (c5e77f5216abdd1d98e6d14d9a3eb4e88d80011a) addrconf.c (63159f29be1df7f93563a8a0f78c5e65fc844ed6)
1/*
2 * IPv6 Address [auto]configuration
3 * Linux INET6 implementation
4 *
5 * Authors:
6 * Pedro Roque <roque@di.fc.ul.pt>
7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
8 *

--- 32 unchanged lines hidden (view full) ---

41#define pr_fmt(fmt) "IPv6: " fmt
42
43#include <linux/errno.h>
44#include <linux/types.h>
45#include <linux/kernel.h>
46#include <linux/socket.h>
47#include <linux/sockios.h>
48#include <linux/net.h>
1/*
2 * IPv6 Address [auto]configuration
3 * Linux INET6 implementation
4 *
5 * Authors:
6 * Pedro Roque <roque@di.fc.ul.pt>
7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
8 *

--- 32 unchanged lines hidden (view full) ---

41#define pr_fmt(fmt) "IPv6: " fmt
42
43#include <linux/errno.h>
44#include <linux/types.h>
45#include <linux/kernel.h>
46#include <linux/socket.h>
47#include <linux/sockios.h>
48#include <linux/net.h>
49#include <linux/inet.h>
49#include <linux/in6.h>
50#include <linux/netdevice.h>
51#include <linux/if_addr.h>
52#include <linux/if_arp.h>
53#include <linux/if_arcnet.h>
54#include <linux/if_infiniband.h>
55#include <linux/route.h>
56#include <linux/inetdevice.h>

--- 40 unchanged lines hidden (view full) ---

97#if ACONF_DEBUG >= 3
98#define ADBG(fmt, ...) printk(fmt, ##__VA_ARGS__)
99#else
100#define ADBG(fmt, ...) do { if (0) printk(fmt, ##__VA_ARGS__); } while (0)
101#endif
102
103#define INFINITY_LIFE_TIME 0xFFFFFFFF
104
50#include <linux/in6.h>
51#include <linux/netdevice.h>
52#include <linux/if_addr.h>
53#include <linux/if_arp.h>
54#include <linux/if_arcnet.h>
55#include <linux/if_infiniband.h>
56#include <linux/route.h>
57#include <linux/inetdevice.h>

--- 40 unchanged lines hidden (view full) ---

98#if ACONF_DEBUG >= 3
99#define ADBG(fmt, ...) printk(fmt, ##__VA_ARGS__)
100#else
101#define ADBG(fmt, ...) do { if (0) printk(fmt, ##__VA_ARGS__); } while (0)
102#endif
103
104#define INFINITY_LIFE_TIME 0xFFFFFFFF
105
106#define IPV6_MAX_STRLEN \
107 sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")
108
105static inline u32 cstamp_delta(unsigned long cstamp)
106{
107 return (cstamp - INITIAL_JIFFIES) * 100UL / HZ;
108}
109
110#ifdef CONFIG_SYSCTL
111static int addrconf_sysctl_register(struct inet6_dev *idev);
112static void addrconf_sysctl_unregister(struct inet6_dev *idev);

--- 9 unchanged lines hidden (view full) ---

122#endif
123
124static void __ipv6_regen_rndid(struct inet6_dev *idev);
125static void __ipv6_try_regen_rndid(struct inet6_dev *idev, struct in6_addr *tmpaddr);
126static void ipv6_regen_rndid(unsigned long data);
127
128static int ipv6_generate_eui64(u8 *eui, struct net_device *dev);
129static int ipv6_count_addresses(struct inet6_dev *idev);
109static inline u32 cstamp_delta(unsigned long cstamp)
110{
111 return (cstamp - INITIAL_JIFFIES) * 100UL / HZ;
112}
113
114#ifdef CONFIG_SYSCTL
115static int addrconf_sysctl_register(struct inet6_dev *idev);
116static void addrconf_sysctl_unregister(struct inet6_dev *idev);

--- 9 unchanged lines hidden (view full) ---

126#endif
127
128static void __ipv6_regen_rndid(struct inet6_dev *idev);
129static void __ipv6_try_regen_rndid(struct inet6_dev *idev, struct in6_addr *tmpaddr);
130static void ipv6_regen_rndid(unsigned long data);
131
132static int ipv6_generate_eui64(u8 *eui, struct net_device *dev);
133static int ipv6_count_addresses(struct inet6_dev *idev);
134static int ipv6_generate_stable_address(struct in6_addr *addr,
135 u8 dad_count,
136 const struct inet6_dev *idev);
130
131/*
132 * Configured unicast address hash table
133 */
134static struct hlist_head inet6_addr_lst[IN6_ADDR_HSIZE];
135static DEFINE_SPINLOCK(addrconf_hash_lock);
136
137static void addrconf_verify(void);

--- 59 unchanged lines hidden (view full) ---

197#endif
198#endif
199 .proxy_ndp = 0,
200 .accept_source_route = 0, /* we do not accept RH0 by default. */
201 .disable_ipv6 = 0,
202 .accept_dad = 1,
203 .suppress_frag_ndisc = 1,
204 .accept_ra_mtu = 1,
137
138/*
139 * Configured unicast address hash table
140 */
141static struct hlist_head inet6_addr_lst[IN6_ADDR_HSIZE];
142static DEFINE_SPINLOCK(addrconf_hash_lock);
143
144static void addrconf_verify(void);

--- 59 unchanged lines hidden (view full) ---

204#endif
205#endif
206 .proxy_ndp = 0,
207 .accept_source_route = 0, /* we do not accept RH0 by default. */
208 .disable_ipv6 = 0,
209 .accept_dad = 1,
210 .suppress_frag_ndisc = 1,
211 .accept_ra_mtu = 1,
212 .stable_secret = {
213 .initialized = false,
214 }
205};
206
207static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
208 .forwarding = 0,
209 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
210 .mtu6 = IPV6_MIN_MTU,
211 .accept_ra = 1,
212 .accept_redirects = 1,

--- 22 unchanged lines hidden (view full) ---

235#endif
236#endif
237 .proxy_ndp = 0,
238 .accept_source_route = 0, /* we do not accept RH0 by default. */
239 .disable_ipv6 = 0,
240 .accept_dad = 1,
241 .suppress_frag_ndisc = 1,
242 .accept_ra_mtu = 1,
215};
216
217static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
218 .forwarding = 0,
219 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
220 .mtu6 = IPV6_MIN_MTU,
221 .accept_ra = 1,
222 .accept_redirects = 1,

--- 22 unchanged lines hidden (view full) ---

245#endif
246#endif
247 .proxy_ndp = 0,
248 .accept_source_route = 0, /* we do not accept RH0 by default. */
249 .disable_ipv6 = 0,
250 .accept_dad = 1,
251 .suppress_frag_ndisc = 1,
252 .accept_ra_mtu = 1,
253 .stable_secret = {
254 .initialized = false,
255 },
243};
244
245/* Check if a valid qdisc is available */
246static inline bool addrconf_qdisc_ok(const struct net_device *dev)
247{
248 return !qdisc_tx_is_noop(dev);
249}
250

--- 65 unchanged lines hidden (view full) ---

316 int err = -ENOMEM;
317
318 ASSERT_RTNL();
319
320 if (dev->mtu < IPV6_MIN_MTU)
321 return ERR_PTR(-EINVAL);
322
323 ndev = kzalloc(sizeof(struct inet6_dev), GFP_KERNEL);
256};
257
258/* Check if a valid qdisc is available */
259static inline bool addrconf_qdisc_ok(const struct net_device *dev)
260{
261 return !qdisc_tx_is_noop(dev);
262}
263

--- 65 unchanged lines hidden (view full) ---

329 int err = -ENOMEM;
330
331 ASSERT_RTNL();
332
333 if (dev->mtu < IPV6_MIN_MTU)
334 return ERR_PTR(-EINVAL);
335
336 ndev = kzalloc(sizeof(struct inet6_dev), GFP_KERNEL);
324 if (ndev == NULL)
337 if (!ndev)
325 return ERR_PTR(err);
326
327 rwlock_init(&ndev->lock);
328 ndev->dev = dev;
329 INIT_LIST_HEAD(&ndev->addr_list);
330 setup_timer(&ndev->rs_timer, addrconf_rs_timer,
331 (unsigned long)ndev);
332 memcpy(&ndev->cnf, dev_net(dev)->ipv6.devconf_dflt, sizeof(ndev->cnf));
333 ndev->cnf.mtu6 = dev->mtu;
334 ndev->cnf.sysctl = NULL;
335 ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl);
338 return ERR_PTR(err);
339
340 rwlock_init(&ndev->lock);
341 ndev->dev = dev;
342 INIT_LIST_HEAD(&ndev->addr_list);
343 setup_timer(&ndev->rs_timer, addrconf_rs_timer,
344 (unsigned long)ndev);
345 memcpy(&ndev->cnf, dev_net(dev)->ipv6.devconf_dflt, sizeof(ndev->cnf));
346 ndev->cnf.mtu6 = dev->mtu;
347 ndev->cnf.sysctl = NULL;
348 ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl);
336 if (ndev->nd_parms == NULL) {
349 if (!ndev->nd_parms) {
337 kfree(ndev);
338 return ERR_PTR(err);
339 }
340 if (ndev->cnf.forwarding)
341 dev_disable_lro(dev);
342 /* We refer to the device */
343 dev_hold(dev);
344

--- 118 unchanged lines hidden (view full) ---

463 u32 seq, int event, unsigned int flags,
464 int type)
465{
466 struct nlmsghdr *nlh;
467 struct netconfmsg *ncm;
468
469 nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct netconfmsg),
470 flags);
350 kfree(ndev);
351 return ERR_PTR(err);
352 }
353 if (ndev->cnf.forwarding)
354 dev_disable_lro(dev);
355 /* We refer to the device */
356 dev_hold(dev);
357

--- 118 unchanged lines hidden (view full) ---

476 u32 seq, int event, unsigned int flags,
477 int type)
478{
479 struct nlmsghdr *nlh;
480 struct netconfmsg *ncm;
481
482 nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct netconfmsg),
483 flags);
471 if (nlh == NULL)
484 if (!nlh)
472 return -EMSGSIZE;
473
474 ncm = nlmsg_data(nlh);
475 ncm->ncm_family = AF_INET6;
476
477 if (nla_put_s32(skb, NETCONFA_IFINDEX, ifindex) < 0)
478 goto nla_put_failure;
479

--- 21 unchanged lines hidden (view full) ---

501
502void inet6_netconf_notify_devconf(struct net *net, int type, int ifindex,
503 struct ipv6_devconf *devconf)
504{
505 struct sk_buff *skb;
506 int err = -ENOBUFS;
507
508 skb = nlmsg_new(inet6_netconf_msgsize_devconf(type), GFP_ATOMIC);
485 return -EMSGSIZE;
486
487 ncm = nlmsg_data(nlh);
488 ncm->ncm_family = AF_INET6;
489
490 if (nla_put_s32(skb, NETCONFA_IFINDEX, ifindex) < 0)
491 goto nla_put_failure;
492

--- 21 unchanged lines hidden (view full) ---

514
515void inet6_netconf_notify_devconf(struct net *net, int type, int ifindex,
516 struct ipv6_devconf *devconf)
517{
518 struct sk_buff *skb;
519 int err = -ENOBUFS;
520
521 skb = nlmsg_new(inet6_netconf_msgsize_devconf(type), GFP_ATOMIC);
509 if (skb == NULL)
522 if (!skb)
510 goto errout;
511
512 err = inet6_netconf_fill_devconf(skb, ifindex, devconf, 0, 0,
513 RTM_NEWNETCONF, 0, type);
514 if (err < 0) {
515 /* -EMSGSIZE implies BUG in inet6_netconf_msgsize_devconf() */
516 WARN_ON(err == -EMSGSIZE);
517 kfree_skb(skb);

--- 38 unchanged lines hidden (view full) ---

556 case NETCONFA_IFINDEX_ALL:
557 devconf = net->ipv6.devconf_all;
558 break;
559 case NETCONFA_IFINDEX_DEFAULT:
560 devconf = net->ipv6.devconf_dflt;
561 break;
562 default:
563 dev = __dev_get_by_index(net, ifindex);
523 goto errout;
524
525 err = inet6_netconf_fill_devconf(skb, ifindex, devconf, 0, 0,
526 RTM_NEWNETCONF, 0, type);
527 if (err < 0) {
528 /* -EMSGSIZE implies BUG in inet6_netconf_msgsize_devconf() */
529 WARN_ON(err == -EMSGSIZE);
530 kfree_skb(skb);

--- 38 unchanged lines hidden (view full) ---

569 case NETCONFA_IFINDEX_ALL:
570 devconf = net->ipv6.devconf_all;
571 break;
572 case NETCONFA_IFINDEX_DEFAULT:
573 devconf = net->ipv6.devconf_dflt;
574 break;
575 default:
576 dev = __dev_get_by_index(net, ifindex);
564 if (dev == NULL)
577 if (!dev)
565 goto errout;
566 in6_dev = __in6_dev_get(dev);
578 goto errout;
579 in6_dev = __in6_dev_get(dev);
567 if (in6_dev == NULL)
580 if (!in6_dev)
568 goto errout;
569 devconf = &in6_dev->cnf;
570 break;
571 }
572
573 err = -ENOBUFS;
574 skb = nlmsg_new(inet6_netconf_msgsize_devconf(-1), GFP_ATOMIC);
581 goto errout;
582 devconf = &in6_dev->cnf;
583 break;
584 }
585
586 err = -ENOBUFS;
587 skb = nlmsg_new(inet6_netconf_msgsize_devconf(-1), GFP_ATOMIC);
575 if (skb == NULL)
588 if (!skb)
576 goto errout;
577
578 err = inet6_netconf_fill_devconf(skb, ifindex, devconf,
579 NETLINK_CB(in_skb).portid,
580 nlh->nlmsg_seq, RTM_NEWNETCONF, 0,
581 -1);
582 if (err < 0) {
583 /* -EMSGSIZE implies BUG in inet6_netconf_msgsize_devconf() */

--- 252 unchanged lines hidden (view full) ---

836 if (ipv6_chk_same_addr(dev_net(idev->dev), addr, idev->dev)) {
837 ADBG("ipv6_add_addr: already assigned\n");
838 err = -EEXIST;
839 goto out;
840 }
841
842 ifa = kzalloc(sizeof(struct inet6_ifaddr), GFP_ATOMIC);
843
589 goto errout;
590
591 err = inet6_netconf_fill_devconf(skb, ifindex, devconf,
592 NETLINK_CB(in_skb).portid,
593 nlh->nlmsg_seq, RTM_NEWNETCONF, 0,
594 -1);
595 if (err < 0) {
596 /* -EMSGSIZE implies BUG in inet6_netconf_msgsize_devconf() */

--- 252 unchanged lines hidden (view full) ---

849 if (ipv6_chk_same_addr(dev_net(idev->dev), addr, idev->dev)) {
850 ADBG("ipv6_add_addr: already assigned\n");
851 err = -EEXIST;
852 goto out;
853 }
854
855 ifa = kzalloc(sizeof(struct inet6_ifaddr), GFP_ATOMIC);
856
844 if (ifa == NULL) {
857 if (!ifa) {
845 ADBG("ipv6_add_addr: malloc failed\n");
846 err = -ENOBUFS;
847 goto out;
848 }
849
850 rt = addrconf_dst_alloc(idev, addr, false);
851 if (IS_ERR(rt)) {
852 err = PTR_ERR(rt);
853 goto out;
854 }
855
856 neigh_parms_data_state_setall(idev->nd_parms);
857
858 ifa->addr = *addr;
859 if (peer_addr)
860 ifa->peer_addr = *peer_addr;
861
862 spin_lock_init(&ifa->lock);
858 ADBG("ipv6_add_addr: malloc failed\n");
859 err = -ENOBUFS;
860 goto out;
861 }
862
863 rt = addrconf_dst_alloc(idev, addr, false);
864 if (IS_ERR(rt)) {
865 err = PTR_ERR(rt);
866 goto out;
867 }
868
869 neigh_parms_data_state_setall(idev->nd_parms);
870
871 ifa->addr = *addr;
872 if (peer_addr)
873 ifa->peer_addr = *peer_addr;
874
875 spin_lock_init(&ifa->lock);
863 spin_lock_init(&ifa->state_lock);
864 INIT_DELAYED_WORK(&ifa->dad_work, addrconf_dad_work);
865 INIT_HLIST_NODE(&ifa->addr_lst);
866 ifa->scope = scope;
867 ifa->prefix_len = pfxlen;
868 ifa->flags = flags | IFA_F_TENTATIVE;
869 ifa->valid_lft = valid_lft;
870 ifa->prefered_lft = prefered_lft;
871 ifa->cstamp = ifa->tstamp = jiffies;

--- 126 unchanged lines hidden (view full) ---

998static void ipv6_del_addr(struct inet6_ifaddr *ifp)
999{
1000 int state;
1001 enum cleanup_prefix_rt_t action = CLEANUP_PREFIX_RT_NOP;
1002 unsigned long expires;
1003
1004 ASSERT_RTNL();
1005
876 INIT_DELAYED_WORK(&ifa->dad_work, addrconf_dad_work);
877 INIT_HLIST_NODE(&ifa->addr_lst);
878 ifa->scope = scope;
879 ifa->prefix_len = pfxlen;
880 ifa->flags = flags | IFA_F_TENTATIVE;
881 ifa->valid_lft = valid_lft;
882 ifa->prefered_lft = prefered_lft;
883 ifa->cstamp = ifa->tstamp = jiffies;

--- 126 unchanged lines hidden (view full) ---

1010static void ipv6_del_addr(struct inet6_ifaddr *ifp)
1011{
1012 int state;
1013 enum cleanup_prefix_rt_t action = CLEANUP_PREFIX_RT_NOP;
1014 unsigned long expires;
1015
1016 ASSERT_RTNL();
1017
1006 spin_lock_bh(&ifp->state_lock);
1018 spin_lock_bh(&ifp->lock);
1007 state = ifp->state;
1008 ifp->state = INET6_IFADDR_STATE_DEAD;
1019 state = ifp->state;
1020 ifp->state = INET6_IFADDR_STATE_DEAD;
1009 spin_unlock_bh(&ifp->state_lock);
1021 spin_unlock_bh(&ifp->lock);
1010
1011 if (state == INET6_IFADDR_STATE_DEAD)
1012 goto out;
1013
1014 spin_lock_bh(&addrconf_hash_lock);
1015 hlist_del_init_rcu(&ifp->addr_lst);
1016 spin_unlock_bh(&addrconf_hash_lock);
1017

--- 523 unchanged lines hidden (view full) ---

1541 /* Decouple optimistic from tentative for evaluation here.
1542 * Ban optimistic addresses explicitly, when required.
1543 */
1544 ifp_flags = (ifp->flags&IFA_F_OPTIMISTIC)
1545 ? (ifp->flags&~IFA_F_TENTATIVE)
1546 : ifp->flags;
1547 if (ipv6_addr_equal(&ifp->addr, addr) &&
1548 !(ifp_flags&banned_flags) &&
1022
1023 if (state == INET6_IFADDR_STATE_DEAD)
1024 goto out;
1025
1026 spin_lock_bh(&addrconf_hash_lock);
1027 hlist_del_init_rcu(&ifp->addr_lst);
1028 spin_unlock_bh(&addrconf_hash_lock);
1029

--- 523 unchanged lines hidden (view full) ---

1553 /* Decouple optimistic from tentative for evaluation here.
1554 * Ban optimistic addresses explicitly, when required.
1555 */
1556 ifp_flags = (ifp->flags&IFA_F_OPTIMISTIC)
1557 ? (ifp->flags&~IFA_F_TENTATIVE)
1558 : ifp->flags;
1559 if (ipv6_addr_equal(&ifp->addr, addr) &&
1560 !(ifp_flags&banned_flags) &&
1549 (dev == NULL || ifp->idev->dev == dev ||
1561 (!dev || ifp->idev->dev == dev ||
1550 !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))) {
1551 rcu_read_unlock_bh();
1552 return 1;
1553 }
1554 }
1555
1556 rcu_read_unlock_bh();
1557 return 0;

--- 5 unchanged lines hidden (view full) ---

1563{
1564 unsigned int hash = inet6_addr_hash(addr);
1565 struct inet6_ifaddr *ifp;
1566
1567 hlist_for_each_entry(ifp, &inet6_addr_lst[hash], addr_lst) {
1568 if (!net_eq(dev_net(ifp->idev->dev), net))
1569 continue;
1570 if (ipv6_addr_equal(&ifp->addr, addr)) {
1562 !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))) {
1563 rcu_read_unlock_bh();
1564 return 1;
1565 }
1566 }
1567
1568 rcu_read_unlock_bh();
1569 return 0;

--- 5 unchanged lines hidden (view full) ---

1575{
1576 unsigned int hash = inet6_addr_hash(addr);
1577 struct inet6_ifaddr *ifp;
1578
1579 hlist_for_each_entry(ifp, &inet6_addr_lst[hash], addr_lst) {
1580 if (!net_eq(dev_net(ifp->idev->dev), net))
1581 continue;
1582 if (ipv6_addr_equal(&ifp->addr, addr)) {
1571 if (dev == NULL || ifp->idev->dev == dev)
1583 if (!dev || ifp->idev->dev == dev)
1572 return true;
1573 }
1574 }
1575 return false;
1576}
1577
1578/* Compares an address/prefix_len with addresses on device @dev.
1579 * If one is found it returns true.

--- 52 unchanged lines hidden (view full) ---

1632 struct inet6_ifaddr *ifp, *result = NULL;
1633 unsigned int hash = inet6_addr_hash(addr);
1634
1635 rcu_read_lock_bh();
1636 hlist_for_each_entry_rcu_bh(ifp, &inet6_addr_lst[hash], addr_lst) {
1637 if (!net_eq(dev_net(ifp->idev->dev), net))
1638 continue;
1639 if (ipv6_addr_equal(&ifp->addr, addr)) {
1584 return true;
1585 }
1586 }
1587 return false;
1588}
1589
1590/* Compares an address/prefix_len with addresses on device @dev.
1591 * If one is found it returns true.

--- 52 unchanged lines hidden (view full) ---

1644 struct inet6_ifaddr *ifp, *result = NULL;
1645 unsigned int hash = inet6_addr_hash(addr);
1646
1647 rcu_read_lock_bh();
1648 hlist_for_each_entry_rcu_bh(ifp, &inet6_addr_lst[hash], addr_lst) {
1649 if (!net_eq(dev_net(ifp->idev->dev), net))
1650 continue;
1651 if (ipv6_addr_equal(&ifp->addr, addr)) {
1640 if (dev == NULL || ifp->idev->dev == dev ||
1652 if (!dev || ifp->idev->dev == dev ||
1641 !(ifp->scope&(IFA_LINK|IFA_HOST) || strict)) {
1642 result = ifp;
1643 in6_ifa_hold(ifp);
1644 break;
1645 }
1646 }
1647 }
1648 rcu_read_unlock_bh();

--- 32 unchanged lines hidden (view full) ---

1681 ipv6_del_addr(ifp);
1682 }
1683}
1684
1685static int addrconf_dad_end(struct inet6_ifaddr *ifp)
1686{
1687 int err = -ENOENT;
1688
1653 !(ifp->scope&(IFA_LINK|IFA_HOST) || strict)) {
1654 result = ifp;
1655 in6_ifa_hold(ifp);
1656 break;
1657 }
1658 }
1659 }
1660 rcu_read_unlock_bh();

--- 32 unchanged lines hidden (view full) ---

1693 ipv6_del_addr(ifp);
1694 }
1695}
1696
1697static int addrconf_dad_end(struct inet6_ifaddr *ifp)
1698{
1699 int err = -ENOENT;
1700
1689 spin_lock_bh(&ifp->state_lock);
1701 spin_lock_bh(&ifp->lock);
1690 if (ifp->state == INET6_IFADDR_STATE_DAD) {
1691 ifp->state = INET6_IFADDR_STATE_POSTDAD;
1692 err = 0;
1693 }
1702 if (ifp->state == INET6_IFADDR_STATE_DAD) {
1703 ifp->state = INET6_IFADDR_STATE_POSTDAD;
1704 err = 0;
1705 }
1694 spin_unlock_bh(&ifp->state_lock);
1706 spin_unlock_bh(&ifp->lock);
1695
1696 return err;
1697}
1698
1699void addrconf_dad_failure(struct inet6_ifaddr *ifp)
1700{
1707
1708 return err;
1709}
1710
1711void addrconf_dad_failure(struct inet6_ifaddr *ifp)
1712{
1713 struct in6_addr addr;
1701 struct inet6_dev *idev = ifp->idev;
1714 struct inet6_dev *idev = ifp->idev;
1715 struct net *net = dev_net(ifp->idev->dev);
1702
1703 if (addrconf_dad_end(ifp)) {
1704 in6_ifa_put(ifp);
1705 return;
1706 }
1707
1708 net_info_ratelimited("%s: IPv6 duplicate address %pI6c detected!\n",
1709 ifp->idev->dev->name, &ifp->addr);
1710
1716
1717 if (addrconf_dad_end(ifp)) {
1718 in6_ifa_put(ifp);
1719 return;
1720 }
1721
1722 net_info_ratelimited("%s: IPv6 duplicate address %pI6c detected!\n",
1723 ifp->idev->dev->name, &ifp->addr);
1724
1711 if (idev->cnf.accept_dad > 1 && !idev->cnf.disable_ipv6) {
1712 struct in6_addr addr;
1725 spin_lock_bh(&ifp->lock);
1713
1726
1727 if (ifp->flags & IFA_F_STABLE_PRIVACY) {
1728 int scope = ifp->scope;
1729 u32 flags = ifp->flags;
1730 struct in6_addr new_addr;
1731 struct inet6_ifaddr *ifp2;
1732 u32 valid_lft, preferred_lft;
1733 int pfxlen = ifp->prefix_len;
1734 int retries = ifp->stable_privacy_retry + 1;
1735
1736 if (retries > net->ipv6.sysctl.idgen_retries) {
1737 net_info_ratelimited("%s: privacy stable address generation failed because of DAD conflicts!\n",
1738 ifp->idev->dev->name);
1739 goto errdad;
1740 }
1741
1742 new_addr = ifp->addr;
1743 if (ipv6_generate_stable_address(&new_addr, retries,
1744 idev))
1745 goto errdad;
1746
1747 valid_lft = ifp->valid_lft;
1748 preferred_lft = ifp->prefered_lft;
1749
1750 spin_unlock_bh(&ifp->lock);
1751
1752 if (idev->cnf.max_addresses &&
1753 ipv6_count_addresses(idev) >=
1754 idev->cnf.max_addresses)
1755 goto lock_errdad;
1756
1757 net_info_ratelimited("%s: generating new stable privacy address because of DAD conflict\n",
1758 ifp->idev->dev->name);
1759
1760 ifp2 = ipv6_add_addr(idev, &new_addr, NULL, pfxlen,
1761 scope, flags, valid_lft,
1762 preferred_lft);
1763 if (IS_ERR(ifp2))
1764 goto lock_errdad;
1765
1766 spin_lock_bh(&ifp2->lock);
1767 ifp2->stable_privacy_retry = retries;
1768 ifp2->state = INET6_IFADDR_STATE_PREDAD;
1769 spin_unlock_bh(&ifp2->lock);
1770
1771 addrconf_mod_dad_work(ifp2, net->ipv6.sysctl.idgen_delay);
1772 in6_ifa_put(ifp2);
1773lock_errdad:
1774 spin_lock_bh(&ifp->lock);
1775 } else if (idev->cnf.accept_dad > 1 && !idev->cnf.disable_ipv6) {
1714 addr.s6_addr32[0] = htonl(0xfe800000);
1715 addr.s6_addr32[1] = 0;
1716
1717 if (!ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) &&
1718 ipv6_addr_equal(&ifp->addr, &addr)) {
1719 /* DAD failed for link-local based on MAC address */
1720 idev->cnf.disable_ipv6 = 1;
1721
1722 pr_info("%s: IPv6 being disabled!\n",
1723 ifp->idev->dev->name);
1724 }
1725 }
1726
1776 addr.s6_addr32[0] = htonl(0xfe800000);
1777 addr.s6_addr32[1] = 0;
1778
1779 if (!ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) &&
1780 ipv6_addr_equal(&ifp->addr, &addr)) {
1781 /* DAD failed for link-local based on MAC address */
1782 idev->cnf.disable_ipv6 = 1;
1783
1784 pr_info("%s: IPv6 being disabled!\n",
1785 ifp->idev->dev->name);
1786 }
1787 }
1788
1727 spin_lock_bh(&ifp->state_lock);
1789errdad:
1728 /* transition from _POSTDAD to _ERRDAD */
1729 ifp->state = INET6_IFADDR_STATE_ERRDAD;
1790 /* transition from _POSTDAD to _ERRDAD */
1791 ifp->state = INET6_IFADDR_STATE_ERRDAD;
1730 spin_unlock_bh(&ifp->state_lock);
1792 spin_unlock_bh(&ifp->lock);
1731
1732 addrconf_mod_dad_work(ifp, 0);
1733}
1734
1735/* Join to solicited addr multicast group.
1736 * caller must hold RTNL */
1737void addrconf_join_solict(struct net_device *dev, const struct in6_addr *addr)
1738{

--- 308 unchanged lines hidden (view full) ---

2047 const struct net_device *dev,
2048 u32 flags, u32 noflags)
2049{
2050 struct fib6_node *fn;
2051 struct rt6_info *rt = NULL;
2052 struct fib6_table *table;
2053
2054 table = fib6_get_table(dev_net(dev), RT6_TABLE_PREFIX);
1793
1794 addrconf_mod_dad_work(ifp, 0);
1795}
1796
1797/* Join to solicited addr multicast group.
1798 * caller must hold RTNL */
1799void addrconf_join_solict(struct net_device *dev, const struct in6_addr *addr)
1800{

--- 308 unchanged lines hidden (view full) ---

2109 const struct net_device *dev,
2110 u32 flags, u32 noflags)
2111{
2112 struct fib6_node *fn;
2113 struct rt6_info *rt = NULL;
2114 struct fib6_table *table;
2115
2116 table = fib6_get_table(dev_net(dev), RT6_TABLE_PREFIX);
2055 if (table == NULL)
2117 if (!table)
2056 return NULL;
2057
2058 read_lock_bh(&table->tb6_lock);
2059 fn = fib6_locate(&table->tb6_root, pfx, plen, NULL, 0);
2060 if (!fn)
2061 goto out;
2062 for (rt = fn->leaf; rt; rt = rt->dst.rt6_next) {
2063 if (rt->dst.dev->ifindex != dev->ifindex)

--- 117 unchanged lines hidden (view full) ---

2181}
2182
2183void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)
2184{
2185 struct prefix_info *pinfo;
2186 __u32 valid_lft;
2187 __u32 prefered_lft;
2188 int addr_type;
2118 return NULL;
2119
2120 read_lock_bh(&table->tb6_lock);
2121 fn = fib6_locate(&table->tb6_root, pfx, plen, NULL, 0);
2122 if (!fn)
2123 goto out;
2124 for (rt = fn->leaf; rt; rt = rt->dst.rt6_next) {
2125 if (rt->dst.dev->ifindex != dev->ifindex)

--- 117 unchanged lines hidden (view full) ---

2243}
2244
2245void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)
2246{
2247 struct prefix_info *pinfo;
2248 __u32 valid_lft;
2249 __u32 prefered_lft;
2250 int addr_type;
2251 u32 addr_flags = 0;
2189 struct inet6_dev *in6_dev;
2190 struct net *net = dev_net(dev);
2191
2192 pinfo = (struct prefix_info *) opt;
2193
2194 if (len < sizeof(struct prefix_info)) {
2195 ADBG("addrconf: prefix option too short\n");
2196 return;

--- 13 unchanged lines hidden (view full) ---

2210
2211 if (prefered_lft > valid_lft) {
2212 net_warn_ratelimited("addrconf: prefix option has invalid lifetime\n");
2213 return;
2214 }
2215
2216 in6_dev = in6_dev_get(dev);
2217
2252 struct inet6_dev *in6_dev;
2253 struct net *net = dev_net(dev);
2254
2255 pinfo = (struct prefix_info *) opt;
2256
2257 if (len < sizeof(struct prefix_info)) {
2258 ADBG("addrconf: prefix option too short\n");
2259 return;

--- 13 unchanged lines hidden (view full) ---

2273
2274 if (prefered_lft > valid_lft) {
2275 net_warn_ratelimited("addrconf: prefix option has invalid lifetime\n");
2276 return;
2277 }
2278
2279 in6_dev = in6_dev_get(dev);
2280
2218 if (in6_dev == NULL) {
2281 if (!in6_dev) {
2219 net_dbg_ratelimited("addrconf: device %s not configured\n",
2220 dev->name);
2221 return;
2222 }
2223
2224 /*
2225 * Two things going on here:
2226 * 1) Add routes for on-link prefixes

--- 60 unchanged lines hidden (view full) ---

2287 memcpy(&addr, &pinfo->prefix, 8);
2288
2289 if (!ipv6_addr_any(&in6_dev->token)) {
2290 read_lock_bh(&in6_dev->lock);
2291 memcpy(addr.s6_addr + 8,
2292 in6_dev->token.s6_addr + 8, 8);
2293 read_unlock_bh(&in6_dev->lock);
2294 tokenized = true;
2282 net_dbg_ratelimited("addrconf: device %s not configured\n",
2283 dev->name);
2284 return;
2285 }
2286
2287 /*
2288 * Two things going on here:
2289 * 1) Add routes for on-link prefixes

--- 60 unchanged lines hidden (view full) ---

2350 memcpy(&addr, &pinfo->prefix, 8);
2351
2352 if (!ipv6_addr_any(&in6_dev->token)) {
2353 read_lock_bh(&in6_dev->lock);
2354 memcpy(addr.s6_addr + 8,
2355 in6_dev->token.s6_addr + 8, 8);
2356 read_unlock_bh(&in6_dev->lock);
2357 tokenized = true;
2358 } else if (in6_dev->addr_gen_mode ==
2359 IN6_ADDR_GEN_MODE_STABLE_PRIVACY &&
2360 !ipv6_generate_stable_address(&addr, 0,
2361 in6_dev)) {
2362 addr_flags |= IFA_F_STABLE_PRIVACY;
2363 goto ok;
2295 } else if (ipv6_generate_eui64(addr.s6_addr + 8, dev) &&
2296 ipv6_inherit_eui64(addr.s6_addr + 8, in6_dev)) {
2297 in6_dev_put(in6_dev);
2298 return;
2299 }
2300 goto ok;
2301 }
2302 net_dbg_ratelimited("IPv6 addrconf: prefix with wrong length %d\n",
2303 pinfo->prefix_len);
2304 in6_dev_put(in6_dev);
2305 return;
2306
2307ok:
2308
2309 ifp = ipv6_get_ifaddr(net, &addr, dev, 1);
2310
2364 } else if (ipv6_generate_eui64(addr.s6_addr + 8, dev) &&
2365 ipv6_inherit_eui64(addr.s6_addr + 8, in6_dev)) {
2366 in6_dev_put(in6_dev);
2367 return;
2368 }
2369 goto ok;
2370 }
2371 net_dbg_ratelimited("IPv6 addrconf: prefix with wrong length %d\n",
2372 pinfo->prefix_len);
2373 in6_dev_put(in6_dev);
2374 return;
2375
2376ok:
2377
2378 ifp = ipv6_get_ifaddr(net, &addr, dev, 1);
2379
2311 if (ifp == NULL && valid_lft) {
2380 if (!ifp && valid_lft) {
2312 int max_addresses = in6_dev->cnf.max_addresses;
2381 int max_addresses = in6_dev->cnf.max_addresses;
2313 u32 addr_flags = 0;
2314
2315#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
2316 if (in6_dev->cnf.optimistic_dad &&
2317 !net->ipv6.devconf_all->forwarding && sllao)
2318 addr_flags = IFA_F_OPTIMISTIC;
2319#endif
2320
2321 /* Do not allow to create too much of autoconfigured

--- 23 unchanged lines hidden (view full) ---

2345 }
2346
2347 if (ifp) {
2348 u32 flags;
2349 unsigned long now;
2350 u32 stored_lft;
2351
2352 /* update lifetime (RFC2462 5.5.3 e) */
2382
2383#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
2384 if (in6_dev->cnf.optimistic_dad &&
2385 !net->ipv6.devconf_all->forwarding && sllao)
2386 addr_flags = IFA_F_OPTIMISTIC;
2387#endif
2388
2389 /* Do not allow to create too much of autoconfigured

--- 23 unchanged lines hidden (view full) ---

2413 }
2414
2415 if (ifp) {
2416 u32 flags;
2417 unsigned long now;
2418 u32 stored_lft;
2419
2420 /* update lifetime (RFC2462 5.5.3 e) */
2353 spin_lock(&ifp->lock);
2421 spin_lock_bh(&ifp->lock);
2354 now = jiffies;
2355 if (ifp->valid_lft > (now - ifp->tstamp) / HZ)
2356 stored_lft = ifp->valid_lft - (now - ifp->tstamp) / HZ;
2357 else
2358 stored_lft = 0;
2359 if (!update_lft && !create && stored_lft) {
2360 const u32 minimum_lft = min_t(u32,
2361 stored_lft, MIN_VALID_LIFETIME);

--- 13 unchanged lines hidden (view full) ---

2375 }
2376
2377 if (update_lft) {
2378 ifp->valid_lft = valid_lft;
2379 ifp->prefered_lft = prefered_lft;
2380 ifp->tstamp = now;
2381 flags = ifp->flags;
2382 ifp->flags &= ~IFA_F_DEPRECATED;
2422 now = jiffies;
2423 if (ifp->valid_lft > (now - ifp->tstamp) / HZ)
2424 stored_lft = ifp->valid_lft - (now - ifp->tstamp) / HZ;
2425 else
2426 stored_lft = 0;
2427 if (!update_lft && !create && stored_lft) {
2428 const u32 minimum_lft = min_t(u32,
2429 stored_lft, MIN_VALID_LIFETIME);

--- 13 unchanged lines hidden (view full) ---

2443 }
2444
2445 if (update_lft) {
2446 ifp->valid_lft = valid_lft;
2447 ifp->prefered_lft = prefered_lft;
2448 ifp->tstamp = now;
2449 flags = ifp->flags;
2450 ifp->flags &= ~IFA_F_DEPRECATED;
2383 spin_unlock(&ifp->lock);
2451 spin_unlock_bh(&ifp->lock);
2384
2385 if (!(flags&IFA_F_TENTATIVE))
2386 ipv6_ifa_notify(0, ifp);
2387 } else
2452
2453 if (!(flags&IFA_F_TENTATIVE))
2454 ipv6_ifa_notify(0, ifp);
2455 } else
2388 spin_unlock(&ifp->lock);
2456 spin_unlock_bh(&ifp->lock);
2389
2390 manage_tempaddrs(in6_dev, ifp, valid_lft, prefered_lft,
2391 create, now);
2392
2393 in6_ifa_put(ifp);
2394 addrconf_verify();
2395 }
2396 }

--- 16 unchanged lines hidden (view full) ---

2413
2414 err = -EFAULT;
2415 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
2416 goto err_exit;
2417
2418 dev = __dev_get_by_index(net, ireq.ifr6_ifindex);
2419
2420 err = -ENODEV;
2457
2458 manage_tempaddrs(in6_dev, ifp, valid_lft, prefered_lft,
2459 create, now);
2460
2461 in6_ifa_put(ifp);
2462 addrconf_verify();
2463 }
2464 }

--- 16 unchanged lines hidden (view full) ---

2481
2482 err = -EFAULT;
2483 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
2484 goto err_exit;
2485
2486 dev = __dev_get_by_index(net, ireq.ifr6_ifindex);
2487
2488 err = -ENODEV;
2421 if (dev == NULL)
2489 if (!dev)
2422 goto err_exit;
2423
2424#if IS_ENABLED(CONFIG_IPV6_SIT)
2425 if (dev->type == ARPHRD_SIT) {
2426 const struct net_device_ops *ops = dev->netdev_ops;
2427 struct ifreq ifr;
2428 struct ip_tunnel_parm p;
2429

--- 29 unchanged lines hidden (view full) ---

2459 }
2460#endif
2461
2462err_exit:
2463 rtnl_unlock();
2464 return err;
2465}
2466
2490 goto err_exit;
2491
2492#if IS_ENABLED(CONFIG_IPV6_SIT)
2493 if (dev->type == ARPHRD_SIT) {
2494 const struct net_device_ops *ops = dev->netdev_ops;
2495 struct ifreq ifr;
2496 struct ip_tunnel_parm p;
2497

--- 29 unchanged lines hidden (view full) ---

2527 }
2528#endif
2529
2530err_exit:
2531 rtnl_unlock();
2532 return err;
2533}
2534
2535static int ipv6_mc_config(struct sock *sk, bool join,
2536 const struct in6_addr *addr, int ifindex)
2537{
2538 int ret;
2539
2540 ASSERT_RTNL();
2541
2542 lock_sock(sk);
2543 if (join)
2544 ret = ipv6_sock_mc_join(sk, ifindex, addr);
2545 else
2546 ret = ipv6_sock_mc_drop(sk, ifindex, addr);
2547 release_sock(sk);
2548
2549 return ret;
2550}
2551
2467/*
2468 * Manual configuration of address on an interface
2469 */
2470static int inet6_addr_add(struct net *net, int ifindex,
2471 const struct in6_addr *pfx,
2472 const struct in6_addr *peer_pfx,
2473 unsigned int plen, __u32 ifa_flags,
2474 __u32 prefered_lft, __u32 valid_lft)
2475{
2476 struct inet6_ifaddr *ifp;
2477 struct inet6_dev *idev;
2478 struct net_device *dev;
2552/*
2553 * Manual configuration of address on an interface
2554 */
2555static int inet6_addr_add(struct net *net, int ifindex,
2556 const struct in6_addr *pfx,
2557 const struct in6_addr *peer_pfx,
2558 unsigned int plen, __u32 ifa_flags,
2559 __u32 prefered_lft, __u32 valid_lft)
2560{
2561 struct inet6_ifaddr *ifp;
2562 struct inet6_dev *idev;
2563 struct net_device *dev;
2564 unsigned long timeout;
2565 clock_t expires;
2479 int scope;
2480 u32 flags;
2566 int scope;
2567 u32 flags;
2481 clock_t expires;
2482 unsigned long timeout;
2483
2484 ASSERT_RTNL();
2485
2486 if (plen > 128)
2487 return -EINVAL;
2488
2489 /* check the lifetime */
2490 if (!valid_lft || prefered_lft > valid_lft)

--- 5 unchanged lines hidden (view full) ---

2496 dev = __dev_get_by_index(net, ifindex);
2497 if (!dev)
2498 return -ENODEV;
2499
2500 idev = addrconf_add_dev(dev);
2501 if (IS_ERR(idev))
2502 return PTR_ERR(idev);
2503
2568
2569 ASSERT_RTNL();
2570
2571 if (plen > 128)
2572 return -EINVAL;
2573
2574 /* check the lifetime */
2575 if (!valid_lft || prefered_lft > valid_lft)

--- 5 unchanged lines hidden (view full) ---

2581 dev = __dev_get_by_index(net, ifindex);
2582 if (!dev)
2583 return -ENODEV;
2584
2585 idev = addrconf_add_dev(dev);
2586 if (IS_ERR(idev))
2587 return PTR_ERR(idev);
2588
2589 if (ifa_flags & IFA_F_MCAUTOJOIN) {
2590 int ret = ipv6_mc_config(net->ipv6.mc_autojoin_sk,
2591 true, pfx, ifindex);
2592
2593 if (ret < 0)
2594 return ret;
2595 }
2596
2504 scope = ipv6_addr_scope(pfx);
2505
2506 timeout = addrconf_timeout_fixup(valid_lft, HZ);
2507 if (addrconf_finite_timeout(timeout)) {
2508 expires = jiffies_to_clock_t(timeout * HZ);
2509 valid_lft = timeout;
2510 flags = RTF_EXPIRES;
2511 } else {

--- 25 unchanged lines hidden (view full) ---

2537 */
2538 addrconf_dad_start(ifp);
2539 if (ifa_flags & IFA_F_MANAGETEMPADDR)
2540 manage_tempaddrs(idev, ifp, valid_lft, prefered_lft,
2541 true, jiffies);
2542 in6_ifa_put(ifp);
2543 addrconf_verify_rtnl();
2544 return 0;
2597 scope = ipv6_addr_scope(pfx);
2598
2599 timeout = addrconf_timeout_fixup(valid_lft, HZ);
2600 if (addrconf_finite_timeout(timeout)) {
2601 expires = jiffies_to_clock_t(timeout * HZ);
2602 valid_lft = timeout;
2603 flags = RTF_EXPIRES;
2604 } else {

--- 25 unchanged lines hidden (view full) ---

2630 */
2631 addrconf_dad_start(ifp);
2632 if (ifa_flags & IFA_F_MANAGETEMPADDR)
2633 manage_tempaddrs(idev, ifp, valid_lft, prefered_lft,
2634 true, jiffies);
2635 in6_ifa_put(ifp);
2636 addrconf_verify_rtnl();
2637 return 0;
2638 } else if (ifa_flags & IFA_F_MCAUTOJOIN) {
2639 ipv6_mc_config(net->ipv6.mc_autojoin_sk,
2640 false, pfx, ifindex);
2545 }
2546
2547 return PTR_ERR(ifp);
2548}
2549
2550static int inet6_addr_del(struct net *net, int ifindex, u32 ifa_flags,
2551 const struct in6_addr *pfx, unsigned int plen)
2552{

--- 4 unchanged lines hidden (view full) ---

2557 if (plen > 128)
2558 return -EINVAL;
2559
2560 dev = __dev_get_by_index(net, ifindex);
2561 if (!dev)
2562 return -ENODEV;
2563
2564 idev = __in6_dev_get(dev);
2641 }
2642
2643 return PTR_ERR(ifp);
2644}
2645
2646static int inet6_addr_del(struct net *net, int ifindex, u32 ifa_flags,
2647 const struct in6_addr *pfx, unsigned int plen)
2648{

--- 4 unchanged lines hidden (view full) ---

2653 if (plen > 128)
2654 return -EINVAL;
2655
2656 dev = __dev_get_by_index(net, ifindex);
2657 if (!dev)
2658 return -ENODEV;
2659
2660 idev = __in6_dev_get(dev);
2565 if (idev == NULL)
2661 if (!idev)
2566 return -ENXIO;
2567
2568 read_lock_bh(&idev->lock);
2569 list_for_each_entry(ifp, &idev->addr_list, if_list) {
2570 if (ifp->prefix_len == plen &&
2571 ipv6_addr_equal(pfx, &ifp->addr)) {
2572 in6_ifa_hold(ifp);
2573 read_unlock_bh(&idev->lock);
2574
2575 if (!(ifp->flags & IFA_F_TEMPORARY) &&
2576 (ifa_flags & IFA_F_MANAGETEMPADDR))
2577 manage_tempaddrs(idev, ifp, 0, 0, false,
2578 jiffies);
2579 ipv6_del_addr(ifp);
2580 addrconf_verify_rtnl();
2662 return -ENXIO;
2663
2664 read_lock_bh(&idev->lock);
2665 list_for_each_entry(ifp, &idev->addr_list, if_list) {
2666 if (ifp->prefix_len == plen &&
2667 ipv6_addr_equal(pfx, &ifp->addr)) {
2668 in6_ifa_hold(ifp);
2669 read_unlock_bh(&idev->lock);
2670
2671 if (!(ifp->flags & IFA_F_TEMPORARY) &&
2672 (ifa_flags & IFA_F_MANAGETEMPADDR))
2673 manage_tempaddrs(idev, ifp, 0, 0, false,
2674 jiffies);
2675 ipv6_del_addr(ifp);
2676 addrconf_verify_rtnl();
2677 if (ipv6_addr_is_multicast(pfx)) {
2678 ipv6_mc_config(net->ipv6.mc_autojoin_sk,
2679 false, pfx, dev->ifindex);
2680 }
2581 return 0;
2582 }
2583 }
2584 read_unlock_bh(&idev->lock);
2585 return -EADDRNOTAVAIL;
2586}
2587
2588

--- 116 unchanged lines hidden (view full) ---

2705 struct inet6_ifaddr *sp_ifa;
2706 struct rt6_info *sp_rt;
2707
2708 /* ::1 */
2709
2710 ASSERT_RTNL();
2711
2712 idev = ipv6_find_idev(dev);
2681 return 0;
2682 }
2683 }
2684 read_unlock_bh(&idev->lock);
2685 return -EADDRNOTAVAIL;
2686}
2687
2688

--- 116 unchanged lines hidden (view full) ---

2805 struct inet6_ifaddr *sp_ifa;
2806 struct rt6_info *sp_rt;
2807
2808 /* ::1 */
2809
2810 ASSERT_RTNL();
2811
2812 idev = ipv6_find_idev(dev);
2713 if (idev == NULL) {
2813 if (!idev) {
2714 pr_debug("%s: add_dev failed\n", __func__);
2715 return;
2716 }
2717
2718 add_addr(idev, &in6addr_loopback, 128, IFA_HOST);
2719
2720 /* Add routes to other interface's IPv6 addresses */
2721 for_each_netdev(dev_net(dev), sp_dev) {

--- 30 unchanged lines hidden (view full) ---

2752 sp_ifa->rt = sp_rt;
2753 ip6_ins_rt(sp_rt);
2754 }
2755 }
2756 read_unlock_bh(&idev->lock);
2757 }
2758}
2759
2814 pr_debug("%s: add_dev failed\n", __func__);
2815 return;
2816 }
2817
2818 add_addr(idev, &in6addr_loopback, 128, IFA_HOST);
2819
2820 /* Add routes to other interface's IPv6 addresses */
2821 for_each_netdev(dev_net(dev), sp_dev) {

--- 30 unchanged lines hidden (view full) ---

2852 sp_ifa->rt = sp_rt;
2853 ip6_ins_rt(sp_rt);
2854 }
2855 }
2856 read_unlock_bh(&idev->lock);
2857 }
2858}
2859
2760static void addrconf_add_linklocal(struct inet6_dev *idev, const struct in6_addr *addr)
2860static void addrconf_add_linklocal(struct inet6_dev *idev,
2861 const struct in6_addr *addr, u32 flags)
2761{
2762 struct inet6_ifaddr *ifp;
2862{
2863 struct inet6_ifaddr *ifp;
2763 u32 addr_flags = IFA_F_PERMANENT;
2864 u32 addr_flags = flags | IFA_F_PERMANENT;
2764
2765#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
2766 if (idev->cnf.optimistic_dad &&
2767 !dev_net(idev->dev)->ipv6.devconf_all->forwarding)
2768 addr_flags |= IFA_F_OPTIMISTIC;
2769#endif
2770
2865
2866#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
2867 if (idev->cnf.optimistic_dad &&
2868 !dev_net(idev->dev)->ipv6.devconf_all->forwarding)
2869 addr_flags |= IFA_F_OPTIMISTIC;
2870#endif
2871
2771
2772 ifp = ipv6_add_addr(idev, addr, NULL, 64, IFA_LINK, addr_flags,
2773 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME);
2774 if (!IS_ERR(ifp)) {
2775 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, idev->dev, 0, 0);
2776 addrconf_dad_start(ifp);
2777 in6_ifa_put(ifp);
2778 }
2779}
2780
2872 ifp = ipv6_add_addr(idev, addr, NULL, 64, IFA_LINK, addr_flags,
2873 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME);
2874 if (!IS_ERR(ifp)) {
2875 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, idev->dev, 0, 0);
2876 addrconf_dad_start(ifp);
2877 in6_ifa_put(ifp);
2878 }
2879}
2880
2881static bool ipv6_reserved_interfaceid(struct in6_addr address)
2882{
2883 if ((address.s6_addr32[2] | address.s6_addr32[3]) == 0)
2884 return true;
2885
2886 if (address.s6_addr32[2] == htonl(0x02005eff) &&
2887 ((address.s6_addr32[3] & htonl(0xfe000000)) == htonl(0xfe000000)))
2888 return true;
2889
2890 if (address.s6_addr32[2] == htonl(0xfdffffff) &&
2891 ((address.s6_addr32[3] & htonl(0xffffff80)) == htonl(0xffffff80)))
2892 return true;
2893
2894 return false;
2895}
2896
2897static int ipv6_generate_stable_address(struct in6_addr *address,
2898 u8 dad_count,
2899 const struct inet6_dev *idev)
2900{
2901 static DEFINE_SPINLOCK(lock);
2902 static __u32 digest[SHA_DIGEST_WORDS];
2903 static __u32 workspace[SHA_WORKSPACE_WORDS];
2904
2905 static union {
2906 char __data[SHA_MESSAGE_BYTES];
2907 struct {
2908 struct in6_addr secret;
2909 __be32 prefix[2];
2910 unsigned char hwaddr[MAX_ADDR_LEN];
2911 u8 dad_count;
2912 } __packed;
2913 } data;
2914
2915 struct in6_addr secret;
2916 struct in6_addr temp;
2917 struct net *net = dev_net(idev->dev);
2918
2919 BUILD_BUG_ON(sizeof(data.__data) != sizeof(data));
2920
2921 if (idev->cnf.stable_secret.initialized)
2922 secret = idev->cnf.stable_secret.secret;
2923 else if (net->ipv6.devconf_dflt->stable_secret.initialized)
2924 secret = net->ipv6.devconf_dflt->stable_secret.secret;
2925 else
2926 return -1;
2927
2928retry:
2929 spin_lock_bh(&lock);
2930
2931 sha_init(digest);
2932 memset(&data, 0, sizeof(data));
2933 memset(workspace, 0, sizeof(workspace));
2934 memcpy(data.hwaddr, idev->dev->perm_addr, idev->dev->addr_len);
2935 data.prefix[0] = address->s6_addr32[0];
2936 data.prefix[1] = address->s6_addr32[1];
2937 data.secret = secret;
2938 data.dad_count = dad_count;
2939
2940 sha_transform(digest, data.__data, workspace);
2941
2942 temp = *address;
2943 temp.s6_addr32[2] = (__force __be32)digest[0];
2944 temp.s6_addr32[3] = (__force __be32)digest[1];
2945
2946 spin_unlock_bh(&lock);
2947
2948 if (ipv6_reserved_interfaceid(temp)) {
2949 dad_count++;
2950 if (dad_count > dev_net(idev->dev)->ipv6.sysctl.idgen_retries)
2951 return -1;
2952 goto retry;
2953 }
2954
2955 *address = temp;
2956 return 0;
2957}
2958
2781static void addrconf_addr_gen(struct inet6_dev *idev, bool prefix_route)
2782{
2959static void addrconf_addr_gen(struct inet6_dev *idev, bool prefix_route)
2960{
2783 if (idev->addr_gen_mode == IN6_ADDR_GEN_MODE_EUI64) {
2784 struct in6_addr addr;
2961 struct in6_addr addr;
2785
2962
2786 ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0);
2963 ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0);
2964
2965 if (idev->addr_gen_mode == IN6_ADDR_GEN_MODE_STABLE_PRIVACY) {
2966 if (!ipv6_generate_stable_address(&addr, 0, idev))
2967 addrconf_add_linklocal(idev, &addr,
2968 IFA_F_STABLE_PRIVACY);
2969 else if (prefix_route)
2970 addrconf_prefix_route(&addr, 64, idev->dev, 0, 0);
2971 } else if (idev->addr_gen_mode == IN6_ADDR_GEN_MODE_EUI64) {
2787 /* addrconf_add_linklocal also adds a prefix_route and we
2788 * only need to care about prefix routes if ipv6_generate_eui64
2789 * couldn't generate one.
2790 */
2791 if (ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) == 0)
2972 /* addrconf_add_linklocal also adds a prefix_route and we
2973 * only need to care about prefix routes if ipv6_generate_eui64
2974 * couldn't generate one.
2975 */
2976 if (ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) == 0)
2792 addrconf_add_linklocal(idev, &addr);
2977 addrconf_add_linklocal(idev, &addr, 0);
2793 else if (prefix_route)
2794 addrconf_prefix_route(&addr, 64, idev->dev, 0, 0);
2795 }
2796}
2797
2798static void addrconf_dev_config(struct net_device *dev)
2799{
2800 struct inet6_dev *idev;

--- 28 unchanged lines hidden (view full) ---

2829
2830 /*
2831 * Configure the tunnel with one of our IPv4
2832 * addresses... we should configure all of
2833 * our v4 addrs in the tunnel
2834 */
2835
2836 idev = ipv6_find_idev(dev);
2978 else if (prefix_route)
2979 addrconf_prefix_route(&addr, 64, idev->dev, 0, 0);
2980 }
2981}
2982
2983static void addrconf_dev_config(struct net_device *dev)
2984{
2985 struct inet6_dev *idev;

--- 28 unchanged lines hidden (view full) ---

3014
3015 /*
3016 * Configure the tunnel with one of our IPv4
3017 * addresses... we should configure all of
3018 * our v4 addrs in the tunnel
3019 */
3020
3021 idev = ipv6_find_idev(dev);
2837 if (idev == NULL) {
3022 if (!idev) {
2838 pr_debug("%s: add_dev failed\n", __func__);
2839 return;
2840 }
2841
2842 if (dev->priv_flags & IFF_ISATAP) {
2843 addrconf_addr_gen(idev, false);
2844 return;
2845 }

--- 8 unchanged lines hidden (view full) ---

2854#if IS_ENABLED(CONFIG_NET_IPGRE)
2855static void addrconf_gre_config(struct net_device *dev)
2856{
2857 struct inet6_dev *idev;
2858
2859 ASSERT_RTNL();
2860
2861 idev = ipv6_find_idev(dev);
3023 pr_debug("%s: add_dev failed\n", __func__);
3024 return;
3025 }
3026
3027 if (dev->priv_flags & IFF_ISATAP) {
3028 addrconf_addr_gen(idev, false);
3029 return;
3030 }

--- 8 unchanged lines hidden (view full) ---

3039#if IS_ENABLED(CONFIG_NET_IPGRE)
3040static void addrconf_gre_config(struct net_device *dev)
3041{
3042 struct inet6_dev *idev;
3043
3044 ASSERT_RTNL();
3045
3046 idev = ipv6_find_idev(dev);
2862 if (idev == NULL) {
3047 if (!idev) {
2863 pr_debug("%s: add_dev failed\n", __func__);
2864 return;
2865 }
2866
2867 addrconf_addr_gen(idev, true);
2868}
2869#endif
2870

--- 180 unchanged lines hidden (view full) ---

3051 int state, i;
3052
3053 ASSERT_RTNL();
3054
3055 rt6_ifdown(net, dev);
3056 neigh_ifdown(&nd_tbl, dev);
3057
3058 idev = __in6_dev_get(dev);
3048 pr_debug("%s: add_dev failed\n", __func__);
3049 return;
3050 }
3051
3052 addrconf_addr_gen(idev, true);
3053}
3054#endif
3055

--- 180 unchanged lines hidden (view full) ---

3236 int state, i;
3237
3238 ASSERT_RTNL();
3239
3240 rt6_ifdown(net, dev);
3241 neigh_ifdown(&nd_tbl, dev);
3242
3243 idev = __in6_dev_get(dev);
3059 if (idev == NULL)
3244 if (!idev)
3060 return -ENODEV;
3061
3062 /*
3063 * Step 1: remove reference to ipv6 device from parent device.
3064 * Do not dev_put!
3065 */
3066 if (how) {
3067 idev->dead = 1;

--- 54 unchanged lines hidden (view full) ---

3122 ifa = list_first_entry(&idev->addr_list,
3123 struct inet6_ifaddr, if_list);
3124 addrconf_del_dad_work(ifa);
3125
3126 list_del(&ifa->if_list);
3127
3128 write_unlock_bh(&idev->lock);
3129
3245 return -ENODEV;
3246
3247 /*
3248 * Step 1: remove reference to ipv6 device from parent device.
3249 * Do not dev_put!
3250 */
3251 if (how) {
3252 idev->dead = 1;

--- 54 unchanged lines hidden (view full) ---

3307 ifa = list_first_entry(&idev->addr_list,
3308 struct inet6_ifaddr, if_list);
3309 addrconf_del_dad_work(ifa);
3310
3311 list_del(&ifa->if_list);
3312
3313 write_unlock_bh(&idev->lock);
3314
3130 spin_lock_bh(&ifa->state_lock);
3315 spin_lock_bh(&ifa->lock);
3131 state = ifa->state;
3132 ifa->state = INET6_IFADDR_STATE_DEAD;
3316 state = ifa->state;
3317 ifa->state = INET6_IFADDR_STATE_DEAD;
3133 spin_unlock_bh(&ifa->state_lock);
3318 spin_unlock_bh(&ifa->lock);
3134
3135 if (state != INET6_IFADDR_STATE_DEAD) {
3136 __ipv6_ifa_notify(RTM_DELADDR, ifa);
3137 inet6addr_notifier_call_chain(NETDEV_DOWN, ifa);
3138 }
3139 in6_ifa_put(ifa);
3140
3141 write_lock_bh(&idev->lock);

--- 141 unchanged lines hidden (view full) ---

3283 spin_unlock(&ifp->lock);
3284 read_unlock_bh(&idev->lock);
3285}
3286
3287static void addrconf_dad_start(struct inet6_ifaddr *ifp)
3288{
3289 bool begin_dad = false;
3290
3319
3320 if (state != INET6_IFADDR_STATE_DEAD) {
3321 __ipv6_ifa_notify(RTM_DELADDR, ifa);
3322 inet6addr_notifier_call_chain(NETDEV_DOWN, ifa);
3323 }
3324 in6_ifa_put(ifa);
3325
3326 write_lock_bh(&idev->lock);

--- 141 unchanged lines hidden (view full) ---

3468 spin_unlock(&ifp->lock);
3469 read_unlock_bh(&idev->lock);
3470}
3471
3472static void addrconf_dad_start(struct inet6_ifaddr *ifp)
3473{
3474 bool begin_dad = false;
3475
3291 spin_lock_bh(&ifp->state_lock);
3476 spin_lock_bh(&ifp->lock);
3292 if (ifp->state != INET6_IFADDR_STATE_DEAD) {
3293 ifp->state = INET6_IFADDR_STATE_PREDAD;
3294 begin_dad = true;
3295 }
3477 if (ifp->state != INET6_IFADDR_STATE_DEAD) {
3478 ifp->state = INET6_IFADDR_STATE_PREDAD;
3479 begin_dad = true;
3480 }
3296 spin_unlock_bh(&ifp->state_lock);
3481 spin_unlock_bh(&ifp->lock);
3297
3298 if (begin_dad)
3299 addrconf_mod_dad_work(ifp, 0);
3300}
3301
3302static void addrconf_dad_work(struct work_struct *w)
3303{
3304 struct inet6_ifaddr *ifp = container_of(to_delayed_work(w),

--- 5 unchanged lines hidden (view full) ---

3310 enum {
3311 DAD_PROCESS,
3312 DAD_BEGIN,
3313 DAD_ABORT,
3314 } action = DAD_PROCESS;
3315
3316 rtnl_lock();
3317
3482
3483 if (begin_dad)
3484 addrconf_mod_dad_work(ifp, 0);
3485}
3486
3487static void addrconf_dad_work(struct work_struct *w)
3488{
3489 struct inet6_ifaddr *ifp = container_of(to_delayed_work(w),

--- 5 unchanged lines hidden (view full) ---

3495 enum {
3496 DAD_PROCESS,
3497 DAD_BEGIN,
3498 DAD_ABORT,
3499 } action = DAD_PROCESS;
3500
3501 rtnl_lock();
3502
3318 spin_lock_bh(&ifp->state_lock);
3503 spin_lock_bh(&ifp->lock);
3319 if (ifp->state == INET6_IFADDR_STATE_PREDAD) {
3320 action = DAD_BEGIN;
3321 ifp->state = INET6_IFADDR_STATE_DAD;
3322 } else if (ifp->state == INET6_IFADDR_STATE_ERRDAD) {
3323 action = DAD_ABORT;
3324 ifp->state = INET6_IFADDR_STATE_POSTDAD;
3325 }
3504 if (ifp->state == INET6_IFADDR_STATE_PREDAD) {
3505 action = DAD_BEGIN;
3506 ifp->state = INET6_IFADDR_STATE_DAD;
3507 } else if (ifp->state == INET6_IFADDR_STATE_ERRDAD) {
3508 action = DAD_ABORT;
3509 ifp->state = INET6_IFADDR_STATE_POSTDAD;
3510 }
3326 spin_unlock_bh(&ifp->state_lock);
3511 spin_unlock_bh(&ifp->lock);
3327
3328 if (action == DAD_BEGIN) {
3329 addrconf_dad_begin(ifp);
3330 goto out;
3331 } else if (action == DAD_ABORT) {
3332 addrconf_dad_stop(ifp, 1);
3333 goto out;
3334 }

--- 471 unchanged lines hidden (view full) ---

3806 int err;
3807
3808 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
3809 if (err < 0)
3810 return err;
3811
3812 ifm = nlmsg_data(nlh);
3813 pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL], &peer_pfx);
3512
3513 if (action == DAD_BEGIN) {
3514 addrconf_dad_begin(ifp);
3515 goto out;
3516 } else if (action == DAD_ABORT) {
3517 addrconf_dad_stop(ifp, 1);
3518 goto out;
3519 }

--- 471 unchanged lines hidden (view full) ---

3991 int err;
3992
3993 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
3994 if (err < 0)
3995 return err;
3996
3997 ifm = nlmsg_data(nlh);
3998 pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL], &peer_pfx);
3814 if (pfx == NULL)
3999 if (!pfx)
3815 return -EINVAL;
3816
3817 ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) : ifm->ifa_flags;
3818
3819 /* We ignore other flags so far. */
3820 ifa_flags &= IFA_F_MANAGETEMPADDR;
3821
3822 return inet6_addr_del(net, ifm->ifa_index, ifa_flags, pfx,

--- 95 unchanged lines hidden (view full) ---

3918 int err;
3919
3920 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
3921 if (err < 0)
3922 return err;
3923
3924 ifm = nlmsg_data(nlh);
3925 pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL], &peer_pfx);
4000 return -EINVAL;
4001
4002 ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) : ifm->ifa_flags;
4003
4004 /* We ignore other flags so far. */
4005 ifa_flags &= IFA_F_MANAGETEMPADDR;
4006
4007 return inet6_addr_del(net, ifm->ifa_index, ifa_flags, pfx,

--- 95 unchanged lines hidden (view full) ---

4103 int err;
4104
4105 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
4106 if (err < 0)
4107 return err;
4108
4109 ifm = nlmsg_data(nlh);
4110 pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL], &peer_pfx);
3926 if (pfx == NULL)
4111 if (!pfx)
3927 return -EINVAL;
3928
3929 if (tb[IFA_CACHEINFO]) {
3930 struct ifa_cacheinfo *ci;
3931
3932 ci = nla_data(tb[IFA_CACHEINFO]);
3933 valid_lft = ci->ifa_valid;
3934 preferred_lft = ci->ifa_prefered;
3935 } else {
3936 preferred_lft = INFINITY_LIFE_TIME;
3937 valid_lft = INFINITY_LIFE_TIME;
3938 }
3939
3940 dev = __dev_get_by_index(net, ifm->ifa_index);
4112 return -EINVAL;
4113
4114 if (tb[IFA_CACHEINFO]) {
4115 struct ifa_cacheinfo *ci;
4116
4117 ci = nla_data(tb[IFA_CACHEINFO]);
4118 valid_lft = ci->ifa_valid;
4119 preferred_lft = ci->ifa_prefered;
4120 } else {
4121 preferred_lft = INFINITY_LIFE_TIME;
4122 valid_lft = INFINITY_LIFE_TIME;
4123 }
4124
4125 dev = __dev_get_by_index(net, ifm->ifa_index);
3941 if (dev == NULL)
4126 if (!dev)
3942 return -ENODEV;
3943
3944 ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) : ifm->ifa_flags;
3945
3946 /* We ignore other flags so far. */
3947 ifa_flags &= IFA_F_NODAD | IFA_F_HOMEADDRESS | IFA_F_MANAGETEMPADDR |
4127 return -ENODEV;
4128
4129 ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) : ifm->ifa_flags;
4130
4131 /* We ignore other flags so far. */
4132 ifa_flags &= IFA_F_NODAD | IFA_F_HOMEADDRESS | IFA_F_MANAGETEMPADDR |
3948 IFA_F_NOPREFIXROUTE;
4133 IFA_F_NOPREFIXROUTE | IFA_F_MCAUTOJOIN;
3949
3950 ifa = ipv6_get_ifaddr(net, pfx, dev, 1);
4134
4135 ifa = ipv6_get_ifaddr(net, pfx, dev, 1);
3951 if (ifa == NULL) {
4136 if (!ifa) {
3952 /*
3953 * It would be best to check for !NLM_F_CREATE here but
3954 * userspace already relies on not having to provide this.
3955 */
3956 return inet6_addr_add(net, ifm->ifa_index, pfx, peer_pfx,
3957 ifm->ifa_prefixlen, ifa_flags,
3958 preferred_lft, valid_lft);
3959 }

--- 58 unchanged lines hidden (view full) ---

4018
4019static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa,
4020 u32 portid, u32 seq, int event, unsigned int flags)
4021{
4022 struct nlmsghdr *nlh;
4023 u32 preferred, valid;
4024
4025 nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct ifaddrmsg), flags);
4137 /*
4138 * It would be best to check for !NLM_F_CREATE here but
4139 * userspace already relies on not having to provide this.
4140 */
4141 return inet6_addr_add(net, ifm->ifa_index, pfx, peer_pfx,
4142 ifm->ifa_prefixlen, ifa_flags,
4143 preferred_lft, valid_lft);
4144 }

--- 58 unchanged lines hidden (view full) ---

4203
4204static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa,
4205 u32 portid, u32 seq, int event, unsigned int flags)
4206{
4207 struct nlmsghdr *nlh;
4208 u32 preferred, valid;
4209
4210 nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct ifaddrmsg), flags);
4026 if (nlh == NULL)
4211 if (!nlh)
4027 return -EMSGSIZE;
4028
4029 put_ifaddrmsg(nlh, ifa->prefix_len, ifa->flags, rt_scope(ifa->scope),
4030 ifa->idev->dev->ifindex);
4031
4032 if (!((ifa->flags&IFA_F_PERMANENT) &&
4033 (ifa->prefered_lft == INFINITY_LIFE_TIME))) {
4034 preferred = ifa->prefered_lft;

--- 44 unchanged lines hidden (view full) ---

4079 struct nlmsghdr *nlh;
4080 u8 scope = RT_SCOPE_UNIVERSE;
4081 int ifindex = ifmca->idev->dev->ifindex;
4082
4083 if (ipv6_addr_scope(&ifmca->mca_addr) & IFA_SITE)
4084 scope = RT_SCOPE_SITE;
4085
4086 nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct ifaddrmsg), flags);
4212 return -EMSGSIZE;
4213
4214 put_ifaddrmsg(nlh, ifa->prefix_len, ifa->flags, rt_scope(ifa->scope),
4215 ifa->idev->dev->ifindex);
4216
4217 if (!((ifa->flags&IFA_F_PERMANENT) &&
4218 (ifa->prefered_lft == INFINITY_LIFE_TIME))) {
4219 preferred = ifa->prefered_lft;

--- 44 unchanged lines hidden (view full) ---

4264 struct nlmsghdr *nlh;
4265 u8 scope = RT_SCOPE_UNIVERSE;
4266 int ifindex = ifmca->idev->dev->ifindex;
4267
4268 if (ipv6_addr_scope(&ifmca->mca_addr) & IFA_SITE)
4269 scope = RT_SCOPE_SITE;
4270
4271 nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct ifaddrmsg), flags);
4087 if (nlh == NULL)
4272 if (!nlh)
4088 return -EMSGSIZE;
4089
4090 put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
4091 if (nla_put(skb, IFA_MULTICAST, 16, &ifmca->mca_addr) < 0 ||
4092 put_cacheinfo(skb, ifmca->mca_cstamp, ifmca->mca_tstamp,
4093 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) {
4094 nlmsg_cancel(skb, nlh);
4095 return -EMSGSIZE;

--- 9 unchanged lines hidden (view full) ---

4105 struct nlmsghdr *nlh;
4106 u8 scope = RT_SCOPE_UNIVERSE;
4107 int ifindex = ifaca->aca_idev->dev->ifindex;
4108
4109 if (ipv6_addr_scope(&ifaca->aca_addr) & IFA_SITE)
4110 scope = RT_SCOPE_SITE;
4111
4112 nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct ifaddrmsg), flags);
4273 return -EMSGSIZE;
4274
4275 put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
4276 if (nla_put(skb, IFA_MULTICAST, 16, &ifmca->mca_addr) < 0 ||
4277 put_cacheinfo(skb, ifmca->mca_cstamp, ifmca->mca_tstamp,
4278 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) {
4279 nlmsg_cancel(skb, nlh);
4280 return -EMSGSIZE;

--- 9 unchanged lines hidden (view full) ---

4290 struct nlmsghdr *nlh;
4291 u8 scope = RT_SCOPE_UNIVERSE;
4292 int ifindex = ifaca->aca_idev->dev->ifindex;
4293
4294 if (ipv6_addr_scope(&ifaca->aca_addr) & IFA_SITE)
4295 scope = RT_SCOPE_SITE;
4296
4297 nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct ifaddrmsg), flags);
4113 if (nlh == NULL)
4298 if (!nlh)
4114 return -EMSGSIZE;
4115
4116 put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
4117 if (nla_put(skb, IFA_ANYCAST, 16, &ifaca->aca_addr) < 0 ||
4118 put_cacheinfo(skb, ifaca->aca_cstamp, ifaca->aca_tstamp,
4119 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) {
4120 nlmsg_cancel(skb, nlh);
4121 return -EMSGSIZE;

--- 156 unchanged lines hidden (view full) ---

4278 struct sk_buff *skb;
4279 int err;
4280
4281 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
4282 if (err < 0)
4283 goto errout;
4284
4285 addr = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL], &peer);
4299 return -EMSGSIZE;
4300
4301 put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
4302 if (nla_put(skb, IFA_ANYCAST, 16, &ifaca->aca_addr) < 0 ||
4303 put_cacheinfo(skb, ifaca->aca_cstamp, ifaca->aca_tstamp,
4304 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) {
4305 nlmsg_cancel(skb, nlh);
4306 return -EMSGSIZE;

--- 156 unchanged lines hidden (view full) ---

4463 struct sk_buff *skb;
4464 int err;
4465
4466 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
4467 if (err < 0)
4468 goto errout;
4469
4470 addr = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL], &peer);
4286 if (addr == NULL) {
4471 if (!addr) {
4287 err = -EINVAL;
4288 goto errout;
4289 }
4290
4291 ifm = nlmsg_data(nlh);
4292 if (ifm->ifa_index)
4293 dev = __dev_get_by_index(net, ifm->ifa_index);
4294

--- 26 unchanged lines hidden (view full) ---

4321
4322static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa)
4323{
4324 struct sk_buff *skb;
4325 struct net *net = dev_net(ifa->idev->dev);
4326 int err = -ENOBUFS;
4327
4328 skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_ATOMIC);
4472 err = -EINVAL;
4473 goto errout;
4474 }
4475
4476 ifm = nlmsg_data(nlh);
4477 if (ifm->ifa_index)
4478 dev = __dev_get_by_index(net, ifm->ifa_index);
4479

--- 26 unchanged lines hidden (view full) ---

4506
4507static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa)
4508{
4509 struct sk_buff *skb;
4510 struct net *net = dev_net(ifa->idev->dev);
4511 int err = -ENOBUFS;
4512
4513 skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_ATOMIC);
4329 if (skb == NULL)
4514 if (!skb)
4330 goto errout;
4331
4332 err = inet6_fill_ifaddr(skb, ifa, 0, 0, event, 0);
4333 if (err < 0) {
4334 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */
4335 WARN_ON(err == -EMSGSIZE);
4336 kfree_skb(skb);
4337 goto errout;

--- 55 unchanged lines hidden (view full) ---

4393#endif
4394 array[DEVCONF_DISABLE_IPV6] = cnf->disable_ipv6;
4395 array[DEVCONF_ACCEPT_DAD] = cnf->accept_dad;
4396 array[DEVCONF_FORCE_TLLAO] = cnf->force_tllao;
4397 array[DEVCONF_NDISC_NOTIFY] = cnf->ndisc_notify;
4398 array[DEVCONF_SUPPRESS_FRAG_NDISC] = cnf->suppress_frag_ndisc;
4399 array[DEVCONF_ACCEPT_RA_FROM_LOCAL] = cnf->accept_ra_from_local;
4400 array[DEVCONF_ACCEPT_RA_MTU] = cnf->accept_ra_mtu;
4515 goto errout;
4516
4517 err = inet6_fill_ifaddr(skb, ifa, 0, 0, event, 0);
4518 if (err < 0) {
4519 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */
4520 WARN_ON(err == -EMSGSIZE);
4521 kfree_skb(skb);
4522 goto errout;

--- 55 unchanged lines hidden (view full) ---

4578#endif
4579 array[DEVCONF_DISABLE_IPV6] = cnf->disable_ipv6;
4580 array[DEVCONF_ACCEPT_DAD] = cnf->accept_dad;
4581 array[DEVCONF_FORCE_TLLAO] = cnf->force_tllao;
4582 array[DEVCONF_NDISC_NOTIFY] = cnf->ndisc_notify;
4583 array[DEVCONF_SUPPRESS_FRAG_NDISC] = cnf->suppress_frag_ndisc;
4584 array[DEVCONF_ACCEPT_RA_FROM_LOCAL] = cnf->accept_ra_from_local;
4585 array[DEVCONF_ACCEPT_RA_MTU] = cnf->accept_ra_mtu;
4586 /* we omit DEVCONF_STABLE_SECRET for now */
4401}
4402
4403static inline size_t inet6_ifla6_size(void)
4404{
4405 return nla_total_size(4) /* IFLA_INET6_FLAGS */
4406 + nla_total_size(sizeof(struct ifla_cacheinfo))
4407 + nla_total_size(DEVCONF_MAX * 4) /* IFLA_INET6_CONF */
4408 + nla_total_size(IPSTATS_MIB_MAX * 8) /* IFLA_INET6_STATS */

--- 64 unchanged lines hidden (view full) ---

4473 goto nla_put_failure;
4474 ci.max_reasm_len = IPV6_MAXPLEN;
4475 ci.tstamp = cstamp_delta(idev->tstamp);
4476 ci.reachable_time = jiffies_to_msecs(idev->nd_parms->reachable_time);
4477 ci.retrans_time = jiffies_to_msecs(NEIGH_VAR(idev->nd_parms, RETRANS_TIME));
4478 if (nla_put(skb, IFLA_INET6_CACHEINFO, sizeof(ci), &ci))
4479 goto nla_put_failure;
4480 nla = nla_reserve(skb, IFLA_INET6_CONF, DEVCONF_MAX * sizeof(s32));
4587}
4588
4589static inline size_t inet6_ifla6_size(void)
4590{
4591 return nla_total_size(4) /* IFLA_INET6_FLAGS */
4592 + nla_total_size(sizeof(struct ifla_cacheinfo))
4593 + nla_total_size(DEVCONF_MAX * 4) /* IFLA_INET6_CONF */
4594 + nla_total_size(IPSTATS_MIB_MAX * 8) /* IFLA_INET6_STATS */

--- 64 unchanged lines hidden (view full) ---

4659 goto nla_put_failure;
4660 ci.max_reasm_len = IPV6_MAXPLEN;
4661 ci.tstamp = cstamp_delta(idev->tstamp);
4662 ci.reachable_time = jiffies_to_msecs(idev->nd_parms->reachable_time);
4663 ci.retrans_time = jiffies_to_msecs(NEIGH_VAR(idev->nd_parms, RETRANS_TIME));
4664 if (nla_put(skb, IFLA_INET6_CACHEINFO, sizeof(ci), &ci))
4665 goto nla_put_failure;
4666 nla = nla_reserve(skb, IFLA_INET6_CONF, DEVCONF_MAX * sizeof(s32));
4481 if (nla == NULL)
4667 if (!nla)
4482 goto nla_put_failure;
4483 ipv6_store_devconf(&idev->cnf, nla_data(nla), nla_len(nla));
4484
4485 /* XXX - MC not implemented */
4486
4487 nla = nla_reserve(skb, IFLA_INET6_STATS, IPSTATS_MIB_MAX * sizeof(u64));
4668 goto nla_put_failure;
4669 ipv6_store_devconf(&idev->cnf, nla_data(nla), nla_len(nla));
4670
4671 /* XXX - MC not implemented */
4672
4673 nla = nla_reserve(skb, IFLA_INET6_STATS, IPSTATS_MIB_MAX * sizeof(u64));
4488 if (nla == NULL)
4674 if (!nla)
4489 goto nla_put_failure;
4490 snmp6_fill_stats(nla_data(nla), idev, IFLA_INET6_STATS, nla_len(nla));
4491
4492 nla = nla_reserve(skb, IFLA_INET6_ICMP6STATS, ICMP6_MIB_MAX * sizeof(u64));
4675 goto nla_put_failure;
4676 snmp6_fill_stats(nla_data(nla), idev, IFLA_INET6_STATS, nla_len(nla));
4677
4678 nla = nla_reserve(skb, IFLA_INET6_ICMP6STATS, ICMP6_MIB_MAX * sizeof(u64));
4493 if (nla == NULL)
4679 if (!nla)
4494 goto nla_put_failure;
4495 snmp6_fill_stats(nla_data(nla), idev, IFLA_INET6_ICMP6STATS, nla_len(nla));
4496
4497 nla = nla_reserve(skb, IFLA_INET6_TOKEN, sizeof(struct in6_addr));
4680 goto nla_put_failure;
4681 snmp6_fill_stats(nla_data(nla), idev, IFLA_INET6_ICMP6STATS, nla_len(nla));
4682
4683 nla = nla_reserve(skb, IFLA_INET6_TOKEN, sizeof(struct in6_addr));
4498 if (nla == NULL)
4684 if (!nla)
4499 goto nla_put_failure;
4500
4501 if (nla_put_u8(skb, IFLA_INET6_ADDR_GEN_MODE, idev->addr_gen_mode))
4502 goto nla_put_failure;
4503
4504 read_lock_bh(&idev->lock);
4505 memcpy(nla_data(nla), idev->token.s6_addr, nla_len(nla));
4506 read_unlock_bh(&idev->lock);

--- 29 unchanged lines hidden (view full) ---

4536{
4537 struct inet6_ifaddr *ifp;
4538 struct net_device *dev = idev->dev;
4539 bool update_rs = false;
4540 struct in6_addr ll_addr;
4541
4542 ASSERT_RTNL();
4543
4685 goto nla_put_failure;
4686
4687 if (nla_put_u8(skb, IFLA_INET6_ADDR_GEN_MODE, idev->addr_gen_mode))
4688 goto nla_put_failure;
4689
4690 read_lock_bh(&idev->lock);
4691 memcpy(nla_data(nla), idev->token.s6_addr, nla_len(nla));
4692 read_unlock_bh(&idev->lock);

--- 29 unchanged lines hidden (view full) ---

4722{
4723 struct inet6_ifaddr *ifp;
4724 struct net_device *dev = idev->dev;
4725 bool update_rs = false;
4726 struct in6_addr ll_addr;
4727
4728 ASSERT_RTNL();
4729
4544 if (token == NULL)
4730 if (!token)
4545 return -EINVAL;
4546 if (ipv6_addr_any(token))
4547 return -EINVAL;
4548 if (dev->flags & (IFF_LOOPBACK | IFF_NOARP))
4549 return -EINVAL;
4550 if (!ipv6_accept_ra(idev))
4551 return -EINVAL;
4552 if (idev->cnf.rtr_solicits <= 0)

--- 74 unchanged lines hidden (view full) ---

4627 if (err)
4628 return err;
4629 }
4630
4631 if (tb[IFLA_INET6_ADDR_GEN_MODE]) {
4632 u8 mode = nla_get_u8(tb[IFLA_INET6_ADDR_GEN_MODE]);
4633
4634 if (mode != IN6_ADDR_GEN_MODE_EUI64 &&
4731 return -EINVAL;
4732 if (ipv6_addr_any(token))
4733 return -EINVAL;
4734 if (dev->flags & (IFF_LOOPBACK | IFF_NOARP))
4735 return -EINVAL;
4736 if (!ipv6_accept_ra(idev))
4737 return -EINVAL;
4738 if (idev->cnf.rtr_solicits <= 0)

--- 74 unchanged lines hidden (view full) ---

4813 if (err)
4814 return err;
4815 }
4816
4817 if (tb[IFLA_INET6_ADDR_GEN_MODE]) {
4818 u8 mode = nla_get_u8(tb[IFLA_INET6_ADDR_GEN_MODE]);
4819
4820 if (mode != IN6_ADDR_GEN_MODE_EUI64 &&
4635 mode != IN6_ADDR_GEN_MODE_NONE)
4821 mode != IN6_ADDR_GEN_MODE_NONE &&
4822 mode != IN6_ADDR_GEN_MODE_STABLE_PRIVACY)
4636 return -EINVAL;
4823 return -EINVAL;
4824
4825 if (mode == IN6_ADDR_GEN_MODE_STABLE_PRIVACY &&
4826 !idev->cnf.stable_secret.initialized &&
4827 !dev_net(dev)->ipv6.devconf_dflt->stable_secret.initialized)
4828 return -EINVAL;
4829
4637 idev->addr_gen_mode = mode;
4638 err = 0;
4639 }
4640
4641 return err;
4642}
4643
4644static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev,
4645 u32 portid, u32 seq, int event, unsigned int flags)
4646{
4647 struct net_device *dev = idev->dev;
4648 struct ifinfomsg *hdr;
4649 struct nlmsghdr *nlh;
4650 void *protoinfo;
4651
4652 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*hdr), flags);
4830 idev->addr_gen_mode = mode;
4831 err = 0;
4832 }
4833
4834 return err;
4835}
4836
4837static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev,
4838 u32 portid, u32 seq, int event, unsigned int flags)
4839{
4840 struct net_device *dev = idev->dev;
4841 struct ifinfomsg *hdr;
4842 struct nlmsghdr *nlh;
4843 void *protoinfo;
4844
4845 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*hdr), flags);
4653 if (nlh == NULL)
4846 if (!nlh)
4654 return -EMSGSIZE;
4655
4656 hdr = nlmsg_data(nlh);
4657 hdr->ifi_family = AF_INET6;
4658 hdr->__ifi_pad = 0;
4659 hdr->ifi_type = dev->type;
4660 hdr->ifi_index = dev->ifindex;
4661 hdr->ifi_flags = dev_get_flags(dev);
4662 hdr->ifi_change = 0;
4663
4664 if (nla_put_string(skb, IFLA_IFNAME, dev->name) ||
4665 (dev->addr_len &&
4666 nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) ||
4667 nla_put_u32(skb, IFLA_MTU, dev->mtu) ||
4668 (dev->ifindex != dev->iflink &&
4669 nla_put_u32(skb, IFLA_LINK, dev->iflink)))
4670 goto nla_put_failure;
4671 protoinfo = nla_nest_start(skb, IFLA_PROTINFO);
4847 return -EMSGSIZE;
4848
4849 hdr = nlmsg_data(nlh);
4850 hdr->ifi_family = AF_INET6;
4851 hdr->__ifi_pad = 0;
4852 hdr->ifi_type = dev->type;
4853 hdr->ifi_index = dev->ifindex;
4854 hdr->ifi_flags = dev_get_flags(dev);
4855 hdr->ifi_change = 0;
4856
4857 if (nla_put_string(skb, IFLA_IFNAME, dev->name) ||
4858 (dev->addr_len &&
4859 nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) ||
4860 nla_put_u32(skb, IFLA_MTU, dev->mtu) ||
4861 (dev->ifindex != dev->iflink &&
4862 nla_put_u32(skb, IFLA_LINK, dev->iflink)))
4863 goto nla_put_failure;
4864 protoinfo = nla_nest_start(skb, IFLA_PROTINFO);
4672 if (protoinfo == NULL)
4865 if (!protoinfo)
4673 goto nla_put_failure;
4674
4675 if (inet6_fill_ifla6_attrs(skb, idev) < 0)
4676 goto nla_put_failure;
4677
4678 nla_nest_end(skb, protoinfo);
4679 nlmsg_end(skb, nlh);
4680 return 0;

--- 44 unchanged lines hidden (view full) ---

4725
4726void inet6_ifinfo_notify(int event, struct inet6_dev *idev)
4727{
4728 struct sk_buff *skb;
4729 struct net *net = dev_net(idev->dev);
4730 int err = -ENOBUFS;
4731
4732 skb = nlmsg_new(inet6_if_nlmsg_size(), GFP_ATOMIC);
4866 goto nla_put_failure;
4867
4868 if (inet6_fill_ifla6_attrs(skb, idev) < 0)
4869 goto nla_put_failure;
4870
4871 nla_nest_end(skb, protoinfo);
4872 nlmsg_end(skb, nlh);
4873 return 0;

--- 44 unchanged lines hidden (view full) ---

4918
4919void inet6_ifinfo_notify(int event, struct inet6_dev *idev)
4920{
4921 struct sk_buff *skb;
4922 struct net *net = dev_net(idev->dev);
4923 int err = -ENOBUFS;
4924
4925 skb = nlmsg_new(inet6_if_nlmsg_size(), GFP_ATOMIC);
4733 if (skb == NULL)
4926 if (!skb)
4734 goto errout;
4735
4736 err = inet6_fill_ifinfo(skb, idev, 0, 0, event, 0);
4737 if (err < 0) {
4738 /* -EMSGSIZE implies BUG in inet6_if_nlmsg_size() */
4739 WARN_ON(err == -EMSGSIZE);
4740 kfree_skb(skb);
4741 goto errout;

--- 16 unchanged lines hidden (view full) ---

4758 struct prefix_info *pinfo, u32 portid, u32 seq,
4759 int event, unsigned int flags)
4760{
4761 struct prefixmsg *pmsg;
4762 struct nlmsghdr *nlh;
4763 struct prefix_cacheinfo ci;
4764
4765 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*pmsg), flags);
4927 goto errout;
4928
4929 err = inet6_fill_ifinfo(skb, idev, 0, 0, event, 0);
4930 if (err < 0) {
4931 /* -EMSGSIZE implies BUG in inet6_if_nlmsg_size() */
4932 WARN_ON(err == -EMSGSIZE);
4933 kfree_skb(skb);
4934 goto errout;

--- 16 unchanged lines hidden (view full) ---

4951 struct prefix_info *pinfo, u32 portid, u32 seq,
4952 int event, unsigned int flags)
4953{
4954 struct prefixmsg *pmsg;
4955 struct nlmsghdr *nlh;
4956 struct prefix_cacheinfo ci;
4957
4958 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*pmsg), flags);
4766 if (nlh == NULL)
4959 if (!nlh)
4767 return -EMSGSIZE;
4768
4769 pmsg = nlmsg_data(nlh);
4770 pmsg->prefix_family = AF_INET6;
4771 pmsg->prefix_pad1 = 0;
4772 pmsg->prefix_pad2 = 0;
4773 pmsg->prefix_ifindex = idev->dev->ifindex;
4774 pmsg->prefix_len = pinfo->prefix_len;

--- 22 unchanged lines hidden (view full) ---

4797static void inet6_prefix_notify(int event, struct inet6_dev *idev,
4798 struct prefix_info *pinfo)
4799{
4800 struct sk_buff *skb;
4801 struct net *net = dev_net(idev->dev);
4802 int err = -ENOBUFS;
4803
4804 skb = nlmsg_new(inet6_prefix_nlmsg_size(), GFP_ATOMIC);
4960 return -EMSGSIZE;
4961
4962 pmsg = nlmsg_data(nlh);
4963 pmsg->prefix_family = AF_INET6;
4964 pmsg->prefix_pad1 = 0;
4965 pmsg->prefix_pad2 = 0;
4966 pmsg->prefix_ifindex = idev->dev->ifindex;
4967 pmsg->prefix_len = pinfo->prefix_len;

--- 22 unchanged lines hidden (view full) ---

4990static void inet6_prefix_notify(int event, struct inet6_dev *idev,
4991 struct prefix_info *pinfo)
4992{
4993 struct sk_buff *skb;
4994 struct net *net = dev_net(idev->dev);
4995 int err = -ENOBUFS;
4996
4997 skb = nlmsg_new(inet6_prefix_nlmsg_size(), GFP_ATOMIC);
4805 if (skb == NULL)
4998 if (!skb)
4806 goto errout;
4807
4808 err = inet6_fill_prefix(skb, idev, pinfo, 0, 0, event, 0);
4809 if (err < 0) {
4810 /* -EMSGSIZE implies BUG in inet6_prefix_nlmsg_size() */
4811 WARN_ON(err == -EMSGSIZE);
4812 kfree_skb(skb);
4813 goto errout;

--- 223 unchanged lines hidden (view full) ---

5037 &idev->cnf);
5038 }
5039 rtnl_unlock();
5040 }
5041
5042 return ret;
5043}
5044
4999 goto errout;
5000
5001 err = inet6_fill_prefix(skb, idev, pinfo, 0, 0, event, 0);
5002 if (err < 0) {
5003 /* -EMSGSIZE implies BUG in inet6_prefix_nlmsg_size() */
5004 WARN_ON(err == -EMSGSIZE);
5005 kfree_skb(skb);
5006 goto errout;

--- 223 unchanged lines hidden (view full) ---

5230 &idev->cnf);
5231 }
5232 rtnl_unlock();
5233 }
5234
5235 return ret;
5236}
5237
5238static int addrconf_sysctl_stable_secret(struct ctl_table *ctl, int write,
5239 void __user *buffer, size_t *lenp,
5240 loff_t *ppos)
5241{
5242 int err;
5243 struct in6_addr addr;
5244 char str[IPV6_MAX_STRLEN];
5245 struct ctl_table lctl = *ctl;
5246 struct net *net = ctl->extra2;
5247 struct ipv6_stable_secret *secret = ctl->data;
5045
5248
5249 if (&net->ipv6.devconf_all->stable_secret == ctl->data)
5250 return -EIO;
5251
5252 lctl.maxlen = IPV6_MAX_STRLEN;
5253 lctl.data = str;
5254
5255 if (!rtnl_trylock())
5256 return restart_syscall();
5257
5258 if (!write && !secret->initialized) {
5259 err = -EIO;
5260 goto out;
5261 }
5262
5263 if (!write) {
5264 err = snprintf(str, sizeof(str), "%pI6",
5265 &secret->secret);
5266 if (err >= sizeof(str)) {
5267 err = -EIO;
5268 goto out;
5269 }
5270 }
5271
5272 err = proc_dostring(&lctl, write, buffer, lenp, ppos);
5273 if (err || !write)
5274 goto out;
5275
5276 if (in6_pton(str, -1, addr.in6_u.u6_addr8, -1, NULL) != 1) {
5277 err = -EIO;
5278 goto out;
5279 }
5280
5281 secret->initialized = true;
5282 secret->secret = addr;
5283
5284 if (&net->ipv6.devconf_dflt->stable_secret == ctl->data) {
5285 struct net_device *dev;
5286
5287 for_each_netdev(net, dev) {
5288 struct inet6_dev *idev = __in6_dev_get(dev);
5289
5290 if (idev) {
5291 idev->addr_gen_mode =
5292 IN6_ADDR_GEN_MODE_STABLE_PRIVACY;
5293 }
5294 }
5295 } else {
5296 struct inet6_dev *idev = ctl->extra1;
5297
5298 idev->addr_gen_mode = IN6_ADDR_GEN_MODE_STABLE_PRIVACY;
5299 }
5300
5301out:
5302 rtnl_unlock();
5303
5304 return err;
5305}
5306
5046static struct addrconf_sysctl_table
5047{
5048 struct ctl_table_header *sysctl_header;
5049 struct ctl_table addrconf_vars[DEVCONF_MAX+1];
5050} addrconf_sysctl __read_mostly = {
5051 .sysctl_header = NULL,
5052 .addrconf_vars = {
5053 {

--- 256 unchanged lines hidden (view full) ---

5310 {
5311 .procname = "accept_ra_mtu",
5312 .data = &ipv6_devconf.accept_ra_mtu,
5313 .maxlen = sizeof(int),
5314 .mode = 0644,
5315 .proc_handler = proc_dointvec,
5316 },
5317 {
5307static struct addrconf_sysctl_table
5308{
5309 struct ctl_table_header *sysctl_header;
5310 struct ctl_table addrconf_vars[DEVCONF_MAX+1];
5311} addrconf_sysctl __read_mostly = {
5312 .sysctl_header = NULL,
5313 .addrconf_vars = {
5314 {

--- 256 unchanged lines hidden (view full) ---

5571 {
5572 .procname = "accept_ra_mtu",
5573 .data = &ipv6_devconf.accept_ra_mtu,
5574 .maxlen = sizeof(int),
5575 .mode = 0644,
5576 .proc_handler = proc_dointvec,
5577 },
5578 {
5579 .procname = "stable_secret",
5580 .data = &ipv6_devconf.stable_secret,
5581 .maxlen = IPV6_MAX_STRLEN,
5582 .mode = 0600,
5583 .proc_handler = addrconf_sysctl_stable_secret,
5584 },
5585 {
5318 /* sentinel */
5319 }
5320 },
5321};
5322
5323static int __addrconf_sysctl_register(struct net *net, char *dev_name,
5324 struct inet6_dev *idev, struct ipv6_devconf *p)
5325{
5326 int i;
5327 struct addrconf_sysctl_table *t;
5328 char path[sizeof("net/ipv6/conf/") + IFNAMSIZ];
5329
5330 t = kmemdup(&addrconf_sysctl, sizeof(*t), GFP_KERNEL);
5586 /* sentinel */
5587 }
5588 },
5589};
5590
5591static int __addrconf_sysctl_register(struct net *net, char *dev_name,
5592 struct inet6_dev *idev, struct ipv6_devconf *p)
5593{
5594 int i;
5595 struct addrconf_sysctl_table *t;
5596 char path[sizeof("net/ipv6/conf/") + IFNAMSIZ];
5597
5598 t = kmemdup(&addrconf_sysctl, sizeof(*t), GFP_KERNEL);
5331 if (t == NULL)
5599 if (!t)
5332 goto out;
5333
5334 for (i = 0; t->addrconf_vars[i].data; i++) {
5335 t->addrconf_vars[i].data += (char *)p - (char *)&ipv6_devconf;
5336 t->addrconf_vars[i].extra1 = idev; /* embedded; no ref */
5337 t->addrconf_vars[i].extra2 = net;
5338 }
5339
5340 snprintf(path, sizeof(path), "net/ipv6/conf/%s", dev_name);
5341
5342 t->sysctl_header = register_net_sysctl(net, path, t->addrconf_vars);
5600 goto out;
5601
5602 for (i = 0; t->addrconf_vars[i].data; i++) {
5603 t->addrconf_vars[i].data += (char *)p - (char *)&ipv6_devconf;
5604 t->addrconf_vars[i].extra1 = idev; /* embedded; no ref */
5605 t->addrconf_vars[i].extra2 = net;
5606 }
5607
5608 snprintf(path, sizeof(path), "net/ipv6/conf/%s", dev_name);
5609
5610 t->sysctl_header = register_net_sysctl(net, path, t->addrconf_vars);
5343 if (t->sysctl_header == NULL)
5611 if (!t->sysctl_header)
5344 goto free;
5345
5346 p->sysctl = t;
5347 return 0;
5348
5349free:
5350 kfree(t);
5351out:
5352 return -ENOBUFS;
5353}
5354
5355static void __addrconf_sysctl_unregister(struct ipv6_devconf *p)
5356{
5357 struct addrconf_sysctl_table *t;
5358
5612 goto free;
5613
5614 p->sysctl = t;
5615 return 0;
5616
5617free:
5618 kfree(t);
5619out:
5620 return -ENOBUFS;
5621}
5622
5623static void __addrconf_sysctl_unregister(struct ipv6_devconf *p)
5624{
5625 struct addrconf_sysctl_table *t;
5626
5359 if (p->sysctl == NULL)
5627 if (!p->sysctl)
5360 return;
5361
5362 t = p->sysctl;
5363 p->sysctl = NULL;
5364 unregister_net_sysctl_table(t->sysctl_header);
5365 kfree(t);
5366}
5367

--- 26 unchanged lines hidden (view full) ---

5394#endif
5395
5396static int __net_init addrconf_init_net(struct net *net)
5397{
5398 int err = -ENOMEM;
5399 struct ipv6_devconf *all, *dflt;
5400
5401 all = kmemdup(&ipv6_devconf, sizeof(ipv6_devconf), GFP_KERNEL);
5628 return;
5629
5630 t = p->sysctl;
5631 p->sysctl = NULL;
5632 unregister_net_sysctl_table(t->sysctl_header);
5633 kfree(t);
5634}
5635

--- 26 unchanged lines hidden (view full) ---

5662#endif
5663
5664static int __net_init addrconf_init_net(struct net *net)
5665{
5666 int err = -ENOMEM;
5667 struct ipv6_devconf *all, *dflt;
5668
5669 all = kmemdup(&ipv6_devconf, sizeof(ipv6_devconf), GFP_KERNEL);
5402 if (all == NULL)
5670 if (!all)
5403 goto err_alloc_all;
5404
5405 dflt = kmemdup(&ipv6_devconf_dflt, sizeof(ipv6_devconf_dflt), GFP_KERNEL);
5671 goto err_alloc_all;
5672
5673 dflt = kmemdup(&ipv6_devconf_dflt, sizeof(ipv6_devconf_dflt), GFP_KERNEL);
5406 if (dflt == NULL)
5674 if (!dflt)
5407 goto err_alloc_dflt;
5408
5409 /* these will be inherited by all namespaces */
5410 dflt->autoconf = ipv6_defaults.autoconf;
5411 dflt->disable_ipv6 = ipv6_defaults.disable_ipv6;
5412
5675 goto err_alloc_dflt;
5676
5677 /* these will be inherited by all namespaces */
5678 dflt->autoconf = ipv6_defaults.autoconf;
5679 dflt->disable_ipv6 = ipv6_defaults.disable_ipv6;
5680
5681 dflt->stable_secret.initialized = false;
5682 all->stable_secret.initialized = false;
5683
5413 net->ipv6.devconf_all = all;
5414 net->ipv6.devconf_dflt = dflt;
5415
5416#ifdef CONFIG_SYSCTL
5417 err = __addrconf_sysctl_register(net, "all", NULL, all);
5418 if (err < 0)
5419 goto err_reg_all;
5420

--- 168 unchanged lines hidden ---
5684 net->ipv6.devconf_all = all;
5685 net->ipv6.devconf_dflt = dflt;
5686
5687#ifdef CONFIG_SYSCTL
5688 err = __addrconf_sysctl_register(net, "all", NULL, all);
5689 if (err < 0)
5690 goto err_reg_all;
5691

--- 168 unchanged lines hidden ---