aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/addrconf.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv6/addrconf.c')
-rw-r--r--net/ipv6/addrconf.c663
1 files changed, 366 insertions, 297 deletions
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index c7852b38e03e..c18676352397 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -48,6 +48,7 @@
48#include <linux/net.h> 48#include <linux/net.h>
49#include <linux/in6.h> 49#include <linux/in6.h>
50#include <linux/netdevice.h> 50#include <linux/netdevice.h>
51#include <linux/if_addr.h>
51#include <linux/if_arp.h> 52#include <linux/if_arp.h>
52#include <linux/if_arcnet.h> 53#include <linux/if_arcnet.h>
53#include <linux/if_infiniband.h> 54#include <linux/if_infiniband.h>
@@ -72,6 +73,7 @@
72#include <net/addrconf.h> 73#include <net/addrconf.h>
73#include <net/tcp.h> 74#include <net/tcp.h>
74#include <net/ip.h> 75#include <net/ip.h>
76#include <net/netlink.h>
75#include <linux/if_tunnel.h> 77#include <linux/if_tunnel.h>
76#include <linux/rtnetlink.h> 78#include <linux/rtnetlink.h>
77 79
@@ -117,9 +119,6 @@ static int ipv6_count_addresses(struct inet6_dev *idev);
117static struct inet6_ifaddr *inet6_addr_lst[IN6_ADDR_HSIZE]; 119static struct inet6_ifaddr *inet6_addr_lst[IN6_ADDR_HSIZE];
118static DEFINE_RWLOCK(addrconf_hash_lock); 120static DEFINE_RWLOCK(addrconf_hash_lock);
119 121
120/* Protects inet6 devices */
121DEFINE_RWLOCK(addrconf_lock);
122
123static void addrconf_verify(unsigned long); 122static void addrconf_verify(unsigned long);
124 123
125static DEFINE_TIMER(addr_chk_timer, addrconf_verify, 0, 0); 124static DEFINE_TIMER(addr_chk_timer, addrconf_verify, 0, 0);
@@ -144,7 +143,7 @@ static int ipv6_chk_same_addr(const struct in6_addr *addr, struct net_device *de
144 143
145static ATOMIC_NOTIFIER_HEAD(inet6addr_chain); 144static ATOMIC_NOTIFIER_HEAD(inet6addr_chain);
146 145
147struct ipv6_devconf ipv6_devconf = { 146struct ipv6_devconf ipv6_devconf __read_mostly = {
148 .forwarding = 0, 147 .forwarding = 0,
149 .hop_limit = IPV6_DEFAULT_HOPLIMIT, 148 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
150 .mtu6 = IPV6_MIN_MTU, 149 .mtu6 = IPV6_MIN_MTU,
@@ -173,9 +172,10 @@ struct ipv6_devconf ipv6_devconf = {
173 .accept_ra_rt_info_max_plen = 0, 172 .accept_ra_rt_info_max_plen = 0,
174#endif 173#endif
175#endif 174#endif
175 .proxy_ndp = 0,
176}; 176};
177 177
178static struct ipv6_devconf ipv6_devconf_dflt = { 178static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
179 .forwarding = 0, 179 .forwarding = 0,
180 .hop_limit = IPV6_DEFAULT_HOPLIMIT, 180 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
181 .mtu6 = IPV6_MIN_MTU, 181 .mtu6 = IPV6_MIN_MTU,
@@ -203,6 +203,7 @@ static struct ipv6_devconf ipv6_devconf_dflt = {
203 .accept_ra_rt_info_max_plen = 0, 203 .accept_ra_rt_info_max_plen = 0,
204#endif 204#endif
205#endif 205#endif
206 .proxy_ndp = 0,
206}; 207};
207 208
208/* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */ 209/* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */
@@ -314,6 +315,12 @@ static void addrconf_mod_timer(struct inet6_ifaddr *ifp,
314 315
315/* Nobody refers to this device, we may destroy it. */ 316/* Nobody refers to this device, we may destroy it. */
316 317
318static void in6_dev_finish_destroy_rcu(struct rcu_head *head)
319{
320 struct inet6_dev *idev = container_of(head, struct inet6_dev, rcu);
321 kfree(idev);
322}
323
317void in6_dev_finish_destroy(struct inet6_dev *idev) 324void in6_dev_finish_destroy(struct inet6_dev *idev)
318{ 325{
319 struct net_device *dev = idev->dev; 326 struct net_device *dev = idev->dev;
@@ -328,7 +335,7 @@ void in6_dev_finish_destroy(struct inet6_dev *idev)
328 return; 335 return;
329 } 336 }
330 snmp6_free_dev(idev); 337 snmp6_free_dev(idev);
331 kfree(idev); 338 call_rcu(&idev->rcu, in6_dev_finish_destroy_rcu);
332} 339}
333 340
334static struct inet6_dev * ipv6_add_dev(struct net_device *dev) 341static struct inet6_dev * ipv6_add_dev(struct net_device *dev)
@@ -404,9 +411,8 @@ static struct inet6_dev * ipv6_add_dev(struct net_device *dev)
404 if (netif_carrier_ok(dev)) 411 if (netif_carrier_ok(dev))
405 ndev->if_flags |= IF_READY; 412 ndev->if_flags |= IF_READY;
406 413
407 write_lock_bh(&addrconf_lock); 414 /* protected by rtnl_lock */
408 dev->ip6_ptr = ndev; 415 rcu_assign_pointer(dev->ip6_ptr, ndev);
409 write_unlock_bh(&addrconf_lock);
410 416
411 ipv6_mc_init_dev(ndev); 417 ipv6_mc_init_dev(ndev);
412 ndev->tstamp = jiffies; 418 ndev->tstamp = jiffies;
@@ -470,7 +476,7 @@ static void addrconf_forward_change(void)
470 476
471 read_lock(&dev_base_lock); 477 read_lock(&dev_base_lock);
472 for (dev=dev_base; dev; dev=dev->next) { 478 for (dev=dev_base; dev; dev=dev->next) {
473 read_lock(&addrconf_lock); 479 rcu_read_lock();
474 idev = __in6_dev_get(dev); 480 idev = __in6_dev_get(dev);
475 if (idev) { 481 if (idev) {
476 int changed = (!idev->cnf.forwarding) ^ (!ipv6_devconf.forwarding); 482 int changed = (!idev->cnf.forwarding) ^ (!ipv6_devconf.forwarding);
@@ -478,7 +484,7 @@ static void addrconf_forward_change(void)
478 if (changed) 484 if (changed)
479 dev_forward_change(idev); 485 dev_forward_change(idev);
480 } 486 }
481 read_unlock(&addrconf_lock); 487 rcu_read_unlock();
482 } 488 }
483 read_unlock(&dev_base_lock); 489 read_unlock(&dev_base_lock);
484} 490}
@@ -539,7 +545,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen,
539 int hash; 545 int hash;
540 int err = 0; 546 int err = 0;
541 547
542 read_lock_bh(&addrconf_lock); 548 rcu_read_lock_bh();
543 if (idev->dead) { 549 if (idev->dead) {
544 err = -ENODEV; /*XXX*/ 550 err = -ENODEV; /*XXX*/
545 goto out2; 551 goto out2;
@@ -608,7 +614,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen,
608 in6_ifa_hold(ifa); 614 in6_ifa_hold(ifa);
609 write_unlock(&idev->lock); 615 write_unlock(&idev->lock);
610out2: 616out2:
611 read_unlock_bh(&addrconf_lock); 617 rcu_read_unlock_bh();
612 618
613 if (likely(err == 0)) 619 if (likely(err == 0))
614 atomic_notifier_call_chain(&inet6addr_chain, NETDEV_UP, ifa); 620 atomic_notifier_call_chain(&inet6addr_chain, NETDEV_UP, ifa);
@@ -734,7 +740,7 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp)
734 740
735 if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) { 741 if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) {
736 if (onlink == 0) { 742 if (onlink == 0) {
737 ip6_del_rt(rt, NULL, NULL, NULL); 743 ip6_del_rt(rt);
738 rt = NULL; 744 rt = NULL;
739 } else if (!(rt->rt6i_flags & RTF_EXPIRES)) { 745 } else if (!(rt->rt6i_flags & RTF_EXPIRES)) {
740 rt->rt6i_expires = expires; 746 rt->rt6i_expires = expires;
@@ -911,7 +917,7 @@ int ipv6_dev_get_saddr(struct net_device *daddr_dev,
911 memset(&hiscore, 0, sizeof(hiscore)); 917 memset(&hiscore, 0, sizeof(hiscore));
912 918
913 read_lock(&dev_base_lock); 919 read_lock(&dev_base_lock);
914 read_lock(&addrconf_lock); 920 rcu_read_lock();
915 921
916 for (dev = dev_base; dev; dev=dev->next) { 922 for (dev = dev_base; dev; dev=dev->next) {
917 struct inet6_dev *idev; 923 struct inet6_dev *idev;
@@ -1032,9 +1038,27 @@ int ipv6_dev_get_saddr(struct net_device *daddr_dev,
1032 continue; 1038 continue;
1033 } 1039 }
1034 1040
1035 /* Rule 4: Prefer home address -- not implemented yet */ 1041 /* Rule 4: Prefer home address */
1042#ifdef CONFIG_IPV6_MIP6
1043 if (hiscore.rule < 4) {
1044 if (ifa_result->flags & IFA_F_HOMEADDRESS)
1045 hiscore.attrs |= IPV6_SADDR_SCORE_HOA;
1046 hiscore.rule++;
1047 }
1048 if (ifa->flags & IFA_F_HOMEADDRESS) {
1049 score.attrs |= IPV6_SADDR_SCORE_HOA;
1050 if (!(ifa_result->flags & IFA_F_HOMEADDRESS)) {
1051 score.rule = 4;
1052 goto record_it;
1053 }
1054 } else {
1055 if (hiscore.attrs & IPV6_SADDR_SCORE_HOA)
1056 continue;
1057 }
1058#else
1036 if (hiscore.rule < 4) 1059 if (hiscore.rule < 4)
1037 hiscore.rule++; 1060 hiscore.rule++;
1061#endif
1038 1062
1039 /* Rule 5: Prefer outgoing interface */ 1063 /* Rule 5: Prefer outgoing interface */
1040 if (hiscore.rule < 5) { 1064 if (hiscore.rule < 5) {
@@ -1123,7 +1147,7 @@ record_it:
1123 } 1147 }
1124 read_unlock_bh(&idev->lock); 1148 read_unlock_bh(&idev->lock);
1125 } 1149 }
1126 read_unlock(&addrconf_lock); 1150 rcu_read_unlock();
1127 read_unlock(&dev_base_lock); 1151 read_unlock(&dev_base_lock);
1128 1152
1129 if (!ifa_result) 1153 if (!ifa_result)
@@ -1147,7 +1171,7 @@ int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr)
1147 struct inet6_dev *idev; 1171 struct inet6_dev *idev;
1148 int err = -EADDRNOTAVAIL; 1172 int err = -EADDRNOTAVAIL;
1149 1173
1150 read_lock(&addrconf_lock); 1174 rcu_read_lock();
1151 if ((idev = __in6_dev_get(dev)) != NULL) { 1175 if ((idev = __in6_dev_get(dev)) != NULL) {
1152 struct inet6_ifaddr *ifp; 1176 struct inet6_ifaddr *ifp;
1153 1177
@@ -1161,7 +1185,7 @@ int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr)
1161 } 1185 }
1162 read_unlock_bh(&idev->lock); 1186 read_unlock_bh(&idev->lock);
1163 } 1187 }
1164 read_unlock(&addrconf_lock); 1188 rcu_read_unlock();
1165 return err; 1189 return err;
1166} 1190}
1167 1191
@@ -1462,7 +1486,7 @@ static void ipv6_regen_rndid(unsigned long data)
1462 struct inet6_dev *idev = (struct inet6_dev *) data; 1486 struct inet6_dev *idev = (struct inet6_dev *) data;
1463 unsigned long expires; 1487 unsigned long expires;
1464 1488
1465 read_lock_bh(&addrconf_lock); 1489 rcu_read_lock_bh();
1466 write_lock_bh(&idev->lock); 1490 write_lock_bh(&idev->lock);
1467 1491
1468 if (idev->dead) 1492 if (idev->dead)
@@ -1486,7 +1510,7 @@ static void ipv6_regen_rndid(unsigned long data)
1486 1510
1487out: 1511out:
1488 write_unlock_bh(&idev->lock); 1512 write_unlock_bh(&idev->lock);
1489 read_unlock_bh(&addrconf_lock); 1513 rcu_read_unlock_bh();
1490 in6_dev_put(idev); 1514 in6_dev_put(idev);
1491} 1515}
1492 1516
@@ -1507,59 +1531,56 @@ static void
1507addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev, 1531addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev,
1508 unsigned long expires, u32 flags) 1532 unsigned long expires, u32 flags)
1509{ 1533{
1510 struct in6_rtmsg rtmsg; 1534 struct fib6_config cfg = {
1535 .fc_table = RT6_TABLE_PREFIX,
1536 .fc_metric = IP6_RT_PRIO_ADDRCONF,
1537 .fc_ifindex = dev->ifindex,
1538 .fc_expires = expires,
1539 .fc_dst_len = plen,
1540 .fc_flags = RTF_UP | flags,
1541 };
1511 1542
1512 memset(&rtmsg, 0, sizeof(rtmsg)); 1543 ipv6_addr_copy(&cfg.fc_dst, pfx);
1513 ipv6_addr_copy(&rtmsg.rtmsg_dst, pfx);
1514 rtmsg.rtmsg_dst_len = plen;
1515 rtmsg.rtmsg_metric = IP6_RT_PRIO_ADDRCONF;
1516 rtmsg.rtmsg_ifindex = dev->ifindex;
1517 rtmsg.rtmsg_info = expires;
1518 rtmsg.rtmsg_flags = RTF_UP|flags;
1519 rtmsg.rtmsg_type = RTMSG_NEWROUTE;
1520 1544
1521 /* Prevent useless cloning on PtP SIT. 1545 /* Prevent useless cloning on PtP SIT.
1522 This thing is done here expecting that the whole 1546 This thing is done here expecting that the whole
1523 class of non-broadcast devices need not cloning. 1547 class of non-broadcast devices need not cloning.
1524 */ 1548 */
1525 if (dev->type == ARPHRD_SIT && (dev->flags&IFF_POINTOPOINT)) 1549 if (dev->type == ARPHRD_SIT && (dev->flags & IFF_POINTOPOINT))
1526 rtmsg.rtmsg_flags |= RTF_NONEXTHOP; 1550 cfg.fc_flags |= RTF_NONEXTHOP;
1527 1551
1528 ip6_route_add(&rtmsg, NULL, NULL, NULL); 1552 ip6_route_add(&cfg);
1529} 1553}
1530 1554
1531/* Create "default" multicast route to the interface */ 1555/* Create "default" multicast route to the interface */
1532 1556
1533static void addrconf_add_mroute(struct net_device *dev) 1557static void addrconf_add_mroute(struct net_device *dev)
1534{ 1558{
1535 struct in6_rtmsg rtmsg; 1559 struct fib6_config cfg = {
1560 .fc_table = RT6_TABLE_LOCAL,
1561 .fc_metric = IP6_RT_PRIO_ADDRCONF,
1562 .fc_ifindex = dev->ifindex,
1563 .fc_dst_len = 8,
1564 .fc_flags = RTF_UP,
1565 };
1566
1567 ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0);
1536 1568
1537 memset(&rtmsg, 0, sizeof(rtmsg)); 1569 ip6_route_add(&cfg);
1538 ipv6_addr_set(&rtmsg.rtmsg_dst,
1539 htonl(0xFF000000), 0, 0, 0);
1540 rtmsg.rtmsg_dst_len = 8;
1541 rtmsg.rtmsg_metric = IP6_RT_PRIO_ADDRCONF;
1542 rtmsg.rtmsg_ifindex = dev->ifindex;
1543 rtmsg.rtmsg_flags = RTF_UP;
1544 rtmsg.rtmsg_type = RTMSG_NEWROUTE;
1545 ip6_route_add(&rtmsg, NULL, NULL, NULL);
1546} 1570}
1547 1571
1548static void sit_route_add(struct net_device *dev) 1572static void sit_route_add(struct net_device *dev)
1549{ 1573{
1550 struct in6_rtmsg rtmsg; 1574 struct fib6_config cfg = {
1551 1575 .fc_table = RT6_TABLE_MAIN,
1552 memset(&rtmsg, 0, sizeof(rtmsg)); 1576 .fc_metric = IP6_RT_PRIO_ADDRCONF,
1553 1577 .fc_ifindex = dev->ifindex,
1554 rtmsg.rtmsg_type = RTMSG_NEWROUTE; 1578 .fc_dst_len = 96,
1555 rtmsg.rtmsg_metric = IP6_RT_PRIO_ADDRCONF; 1579 .fc_flags = RTF_UP | RTF_NONEXTHOP,
1580 };
1556 1581
1557 /* prefix length - 96 bits "::d.d.d.d" */ 1582 /* prefix length - 96 bits "::d.d.d.d" */
1558 rtmsg.rtmsg_dst_len = 96; 1583 ip6_route_add(&cfg);
1559 rtmsg.rtmsg_flags = RTF_UP|RTF_NONEXTHOP;
1560 rtmsg.rtmsg_ifindex = dev->ifindex;
1561
1562 ip6_route_add(&rtmsg, NULL, NULL, NULL);
1563} 1584}
1564 1585
1565static void addrconf_add_lroute(struct net_device *dev) 1586static void addrconf_add_lroute(struct net_device *dev)
@@ -1660,7 +1681,7 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len)
1660 if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) { 1681 if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) {
1661 if (rt->rt6i_flags&RTF_EXPIRES) { 1682 if (rt->rt6i_flags&RTF_EXPIRES) {
1662 if (valid_lft == 0) { 1683 if (valid_lft == 0) {
1663 ip6_del_rt(rt, NULL, NULL, NULL); 1684 ip6_del_rt(rt);
1664 rt = NULL; 1685 rt = NULL;
1665 } else { 1686 } else {
1666 rt->rt6i_expires = jiffies + rt_expires; 1687 rt->rt6i_expires = jiffies + rt_expires;
@@ -1870,12 +1891,11 @@ err_exit:
1870 * Manual configuration of address on an interface 1891 * Manual configuration of address on an interface
1871 */ 1892 */
1872static int inet6_addr_add(int ifindex, struct in6_addr *pfx, int plen, 1893static int inet6_addr_add(int ifindex, struct in6_addr *pfx, int plen,
1873 __u32 prefered_lft, __u32 valid_lft) 1894 __u8 ifa_flags, __u32 prefered_lft, __u32 valid_lft)
1874{ 1895{
1875 struct inet6_ifaddr *ifp; 1896 struct inet6_ifaddr *ifp;
1876 struct inet6_dev *idev; 1897 struct inet6_dev *idev;
1877 struct net_device *dev; 1898 struct net_device *dev;
1878 __u8 ifa_flags = 0;
1879 int scope; 1899 int scope;
1880 1900
1881 ASSERT_RTNL(); 1901 ASSERT_RTNL();
@@ -1887,9 +1907,6 @@ static int inet6_addr_add(int ifindex, struct in6_addr *pfx, int plen,
1887 if ((dev = __dev_get_by_index(ifindex)) == NULL) 1907 if ((dev = __dev_get_by_index(ifindex)) == NULL)
1888 return -ENODEV; 1908 return -ENODEV;
1889 1909
1890 if (!(dev->flags&IFF_UP))
1891 return -ENETDOWN;
1892
1893 if ((idev = addrconf_add_dev(dev)) == NULL) 1910 if ((idev = addrconf_add_dev(dev)) == NULL)
1894 return -ENOBUFS; 1911 return -ENOBUFS;
1895 1912
@@ -1971,7 +1988,7 @@ int addrconf_add_ifaddr(void __user *arg)
1971 1988
1972 rtnl_lock(); 1989 rtnl_lock();
1973 err = inet6_addr_add(ireq.ifr6_ifindex, &ireq.ifr6_addr, ireq.ifr6_prefixlen, 1990 err = inet6_addr_add(ireq.ifr6_ifindex, &ireq.ifr6_addr, ireq.ifr6_prefixlen,
1974 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME); 1991 IFA_F_PERMANENT, INFINITY_LIFE_TIME, INFINITY_LIFE_TIME);
1975 rtnl_unlock(); 1992 rtnl_unlock();
1976 return err; 1993 return err;
1977} 1994}
@@ -2344,10 +2361,10 @@ static int addrconf_ifdown(struct net_device *dev, int how)
2344 Do not dev_put! 2361 Do not dev_put!
2345 */ 2362 */
2346 if (how == 1) { 2363 if (how == 1) {
2347 write_lock_bh(&addrconf_lock);
2348 dev->ip6_ptr = NULL;
2349 idev->dead = 1; 2364 idev->dead = 1;
2350 write_unlock_bh(&addrconf_lock); 2365
2366 /* protected by rtnl_lock */
2367 rcu_assign_pointer(dev->ip6_ptr, NULL);
2351 2368
2352 /* Step 1.5: remove snmp6 entry */ 2369 /* Step 1.5: remove snmp6 entry */
2353 snmp6_unregister_dev(idev); 2370 snmp6_unregister_dev(idev);
@@ -2514,7 +2531,8 @@ static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags)
2514 spin_lock_bh(&ifp->lock); 2531 spin_lock_bh(&ifp->lock);
2515 2532
2516 if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) || 2533 if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) ||
2517 !(ifp->flags&IFA_F_TENTATIVE)) { 2534 !(ifp->flags&IFA_F_TENTATIVE) ||
2535 ifp->flags & IFA_F_NODAD) {
2518 ifp->flags &= ~IFA_F_TENTATIVE; 2536 ifp->flags &= ~IFA_F_TENTATIVE;
2519 spin_unlock_bh(&ifp->lock); 2537 spin_unlock_bh(&ifp->lock);
2520 read_unlock_bh(&idev->lock); 2538 read_unlock_bh(&idev->lock);
@@ -2759,6 +2777,26 @@ void if6_proc_exit(void)
2759} 2777}
2760#endif /* CONFIG_PROC_FS */ 2778#endif /* CONFIG_PROC_FS */
2761 2779
2780#ifdef CONFIG_IPV6_MIP6
2781/* Check if address is a home address configured on any interface. */
2782int ipv6_chk_home_addr(struct in6_addr *addr)
2783{
2784 int ret = 0;
2785 struct inet6_ifaddr * ifp;
2786 u8 hash = ipv6_addr_hash(addr);
2787 read_lock_bh(&addrconf_hash_lock);
2788 for (ifp = inet6_addr_lst[hash]; ifp; ifp = ifp->lst_next) {
2789 if (ipv6_addr_cmp(&ifp->addr, addr) == 0 &&
2790 (ifp->flags & IFA_F_HOMEADDRESS)) {
2791 ret = 1;
2792 break;
2793 }
2794 }
2795 read_unlock_bh(&addrconf_hash_lock);
2796 return ret;
2797}
2798#endif
2799
2762/* 2800/*
2763 * Periodic address status verification 2801 * Periodic address status verification
2764 */ 2802 */
@@ -2869,66 +2907,68 @@ restart:
2869 spin_unlock_bh(&addrconf_verify_lock); 2907 spin_unlock_bh(&addrconf_verify_lock);
2870} 2908}
2871 2909
2910static struct in6_addr *extract_addr(struct nlattr *addr, struct nlattr *local)
2911{
2912 struct in6_addr *pfx = NULL;
2913
2914 if (addr)
2915 pfx = nla_data(addr);
2916
2917 if (local) {
2918 if (pfx && nla_memcmp(local, pfx, sizeof(*pfx)))
2919 pfx = NULL;
2920 else
2921 pfx = nla_data(local);
2922 }
2923
2924 return pfx;
2925}
2926
2927static struct nla_policy ifa_ipv6_policy[IFA_MAX+1] __read_mostly = {
2928 [IFA_ADDRESS] = { .len = sizeof(struct in6_addr) },
2929 [IFA_LOCAL] = { .len = sizeof(struct in6_addr) },
2930 [IFA_CACHEINFO] = { .len = sizeof(struct ifa_cacheinfo) },
2931};
2932
2872static int 2933static int
2873inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 2934inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
2874{ 2935{
2875 struct rtattr **rta = arg; 2936 struct ifaddrmsg *ifm;
2876 struct ifaddrmsg *ifm = NLMSG_DATA(nlh); 2937 struct nlattr *tb[IFA_MAX+1];
2877 struct in6_addr *pfx; 2938 struct in6_addr *pfx;
2939 int err;
2878 2940
2879 pfx = NULL; 2941 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
2880 if (rta[IFA_ADDRESS-1]) { 2942 if (err < 0)
2881 if (RTA_PAYLOAD(rta[IFA_ADDRESS-1]) < sizeof(*pfx)) 2943 return err;
2882 return -EINVAL; 2944
2883 pfx = RTA_DATA(rta[IFA_ADDRESS-1]); 2945 ifm = nlmsg_data(nlh);
2884 } 2946 pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]);
2885 if (rta[IFA_LOCAL-1]) {
2886 if (RTA_PAYLOAD(rta[IFA_LOCAL-1]) < sizeof(*pfx) ||
2887 (pfx && memcmp(pfx, RTA_DATA(rta[IFA_LOCAL-1]), sizeof(*pfx))))
2888 return -EINVAL;
2889 pfx = RTA_DATA(rta[IFA_LOCAL-1]);
2890 }
2891 if (pfx == NULL) 2947 if (pfx == NULL)
2892 return -EINVAL; 2948 return -EINVAL;
2893 2949
2894 return inet6_addr_del(ifm->ifa_index, pfx, ifm->ifa_prefixlen); 2950 return inet6_addr_del(ifm->ifa_index, pfx, ifm->ifa_prefixlen);
2895} 2951}
2896 2952
2897static int 2953static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags,
2898inet6_addr_modify(int ifindex, struct in6_addr *pfx, 2954 u32 prefered_lft, u32 valid_lft)
2899 __u32 prefered_lft, __u32 valid_lft)
2900{ 2955{
2901 struct inet6_ifaddr *ifp = NULL;
2902 struct net_device *dev;
2903 int ifa_flags = 0;
2904
2905 if ((dev = __dev_get_by_index(ifindex)) == NULL)
2906 return -ENODEV;
2907
2908 if (!(dev->flags&IFF_UP))
2909 return -ENETDOWN;
2910
2911 if (!valid_lft || (prefered_lft > valid_lft)) 2956 if (!valid_lft || (prefered_lft > valid_lft))
2912 return -EINVAL; 2957 return -EINVAL;
2913 2958
2914 ifp = ipv6_get_ifaddr(pfx, dev, 1);
2915 if (ifp == NULL)
2916 return -ENOENT;
2917
2918 if (valid_lft == INFINITY_LIFE_TIME) 2959 if (valid_lft == INFINITY_LIFE_TIME)
2919 ifa_flags = IFA_F_PERMANENT; 2960 ifa_flags |= IFA_F_PERMANENT;
2920 else if (valid_lft >= 0x7FFFFFFF/HZ) 2961 else if (valid_lft >= 0x7FFFFFFF/HZ)
2921 valid_lft = 0x7FFFFFFF/HZ; 2962 valid_lft = 0x7FFFFFFF/HZ;
2922 2963
2923 if (prefered_lft == 0) 2964 if (prefered_lft == 0)
2924 ifa_flags = IFA_F_DEPRECATED; 2965 ifa_flags |= IFA_F_DEPRECATED;
2925 else if ((prefered_lft >= 0x7FFFFFFF/HZ) && 2966 else if ((prefered_lft >= 0x7FFFFFFF/HZ) &&
2926 (prefered_lft != INFINITY_LIFE_TIME)) 2967 (prefered_lft != INFINITY_LIFE_TIME))
2927 prefered_lft = 0x7FFFFFFF/HZ; 2968 prefered_lft = 0x7FFFFFFF/HZ;
2928 2969
2929 spin_lock_bh(&ifp->lock); 2970 spin_lock_bh(&ifp->lock);
2930 ifp->flags = (ifp->flags & ~(IFA_F_DEPRECATED|IFA_F_PERMANENT)) | ifa_flags; 2971 ifp->flags = (ifp->flags & ~(IFA_F_DEPRECATED | IFA_F_PERMANENT | IFA_F_NODAD | IFA_F_HOMEADDRESS)) | ifa_flags;
2931
2932 ifp->tstamp = jiffies; 2972 ifp->tstamp = jiffies;
2933 ifp->valid_lft = valid_lft; 2973 ifp->valid_lft = valid_lft;
2934 ifp->prefered_lft = prefered_lft; 2974 ifp->prefered_lft = prefered_lft;
@@ -2936,7 +2976,6 @@ inet6_addr_modify(int ifindex, struct in6_addr *pfx,
2936 spin_unlock_bh(&ifp->lock); 2976 spin_unlock_bh(&ifp->lock);
2937 if (!(ifp->flags&IFA_F_TENTATIVE)) 2977 if (!(ifp->flags&IFA_F_TENTATIVE))
2938 ipv6_ifa_notify(0, ifp); 2978 ipv6_ifa_notify(0, ifp);
2939 in6_ifa_put(ifp);
2940 2979
2941 addrconf_verify(0); 2980 addrconf_verify(0);
2942 2981
@@ -2946,172 +2985,189 @@ inet6_addr_modify(int ifindex, struct in6_addr *pfx,
2946static int 2985static int
2947inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 2986inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
2948{ 2987{
2949 struct rtattr **rta = arg; 2988 struct ifaddrmsg *ifm;
2950 struct ifaddrmsg *ifm = NLMSG_DATA(nlh); 2989 struct nlattr *tb[IFA_MAX+1];
2951 struct in6_addr *pfx; 2990 struct in6_addr *pfx;
2952 __u32 valid_lft = INFINITY_LIFE_TIME, prefered_lft = INFINITY_LIFE_TIME; 2991 struct inet6_ifaddr *ifa;
2992 struct net_device *dev;
2993 u32 valid_lft = INFINITY_LIFE_TIME, preferred_lft = INFINITY_LIFE_TIME;
2994 u8 ifa_flags;
2995 int err;
2953 2996
2954 pfx = NULL; 2997 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
2955 if (rta[IFA_ADDRESS-1]) { 2998 if (err < 0)
2956 if (RTA_PAYLOAD(rta[IFA_ADDRESS-1]) < sizeof(*pfx)) 2999 return err;
2957 return -EINVAL; 3000
2958 pfx = RTA_DATA(rta[IFA_ADDRESS-1]); 3001 ifm = nlmsg_data(nlh);
2959 } 3002 pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]);
2960 if (rta[IFA_LOCAL-1]) {
2961 if (RTA_PAYLOAD(rta[IFA_LOCAL-1]) < sizeof(*pfx) ||
2962 (pfx && memcmp(pfx, RTA_DATA(rta[IFA_LOCAL-1]), sizeof(*pfx))))
2963 return -EINVAL;
2964 pfx = RTA_DATA(rta[IFA_LOCAL-1]);
2965 }
2966 if (pfx == NULL) 3003 if (pfx == NULL)
2967 return -EINVAL; 3004 return -EINVAL;
2968 3005
2969 if (rta[IFA_CACHEINFO-1]) { 3006 if (tb[IFA_CACHEINFO]) {
2970 struct ifa_cacheinfo *ci; 3007 struct ifa_cacheinfo *ci;
2971 if (RTA_PAYLOAD(rta[IFA_CACHEINFO-1]) < sizeof(*ci)) 3008
2972 return -EINVAL; 3009 ci = nla_data(tb[IFA_CACHEINFO]);
2973 ci = RTA_DATA(rta[IFA_CACHEINFO-1]);
2974 valid_lft = ci->ifa_valid; 3010 valid_lft = ci->ifa_valid;
2975 prefered_lft = ci->ifa_prefered; 3011 preferred_lft = ci->ifa_prefered;
3012 } else {
3013 preferred_lft = INFINITY_LIFE_TIME;
3014 valid_lft = INFINITY_LIFE_TIME;
2976 } 3015 }
2977 3016
2978 if (nlh->nlmsg_flags & NLM_F_REPLACE) { 3017 dev = __dev_get_by_index(ifm->ifa_index);
2979 int ret; 3018 if (dev == NULL)
2980 ret = inet6_addr_modify(ifm->ifa_index, pfx, 3019 return -ENODEV;
2981 prefered_lft, valid_lft); 3020
2982 if (ret == 0 || !(nlh->nlmsg_flags & NLM_F_CREATE)) 3021 /* We ignore other flags so far. */
2983 return ret; 3022 ifa_flags = ifm->ifa_flags & (IFA_F_NODAD | IFA_F_HOMEADDRESS);
3023
3024 ifa = ipv6_get_ifaddr(pfx, dev, 1);
3025 if (ifa == NULL) {
3026 /*
3027 * It would be best to check for !NLM_F_CREATE here but
3028 * userspace alreay relies on not having to provide this.
3029 */
3030 return inet6_addr_add(ifm->ifa_index, pfx, ifm->ifa_prefixlen,
3031 ifa_flags, preferred_lft, valid_lft);
2984 } 3032 }
2985 3033
2986 return inet6_addr_add(ifm->ifa_index, pfx, ifm->ifa_prefixlen, 3034 if (nlh->nlmsg_flags & NLM_F_EXCL ||
2987 prefered_lft, valid_lft); 3035 !(nlh->nlmsg_flags & NLM_F_REPLACE))
3036 err = -EEXIST;
3037 else
3038 err = inet6_addr_modify(ifa, ifa_flags, preferred_lft, valid_lft);
3039
3040 in6_ifa_put(ifa);
3041
3042 return err;
3043}
3044
3045static void put_ifaddrmsg(struct nlmsghdr *nlh, u8 prefixlen, u8 flags,
3046 u8 scope, int ifindex)
3047{
3048 struct ifaddrmsg *ifm;
2988 3049
3050 ifm = nlmsg_data(nlh);
3051 ifm->ifa_family = AF_INET6;
3052 ifm->ifa_prefixlen = prefixlen;
3053 ifm->ifa_flags = flags;
3054 ifm->ifa_scope = scope;
3055 ifm->ifa_index = ifindex;
2989} 3056}
2990 3057
2991/* Maximum length of ifa_cacheinfo attributes */ 3058static int put_cacheinfo(struct sk_buff *skb, unsigned long cstamp,
2992#define INET6_IFADDR_RTA_SPACE \ 3059 unsigned long tstamp, u32 preferred, u32 valid)
2993 RTA_SPACE(16) /* IFA_ADDRESS */ + \ 3060{
2994 RTA_SPACE(sizeof(struct ifa_cacheinfo)) /* CACHEINFO */ 3061 struct ifa_cacheinfo ci;
3062
3063 ci.cstamp = (u32)(TIME_DELTA(cstamp, INITIAL_JIFFIES) / HZ * 100
3064 + TIME_DELTA(cstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
3065 ci.tstamp = (u32)(TIME_DELTA(tstamp, INITIAL_JIFFIES) / HZ * 100
3066 + TIME_DELTA(tstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
3067 ci.ifa_prefered = preferred;
3068 ci.ifa_valid = valid;
3069
3070 return nla_put(skb, IFA_CACHEINFO, sizeof(ci), &ci);
3071}
3072
3073static inline int rt_scope(int ifa_scope)
3074{
3075 if (ifa_scope & IFA_HOST)
3076 return RT_SCOPE_HOST;
3077 else if (ifa_scope & IFA_LINK)
3078 return RT_SCOPE_LINK;
3079 else if (ifa_scope & IFA_SITE)
3080 return RT_SCOPE_SITE;
3081 else
3082 return RT_SCOPE_UNIVERSE;
3083}
3084
3085static inline int inet6_ifaddr_msgsize(void)
3086{
3087 return nlmsg_total_size(sizeof(struct ifaddrmsg) +
3088 nla_total_size(16) +
3089 nla_total_size(sizeof(struct ifa_cacheinfo)) +
3090 128);
3091}
2995 3092
2996static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa, 3093static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa,
2997 u32 pid, u32 seq, int event, unsigned int flags) 3094 u32 pid, u32 seq, int event, unsigned int flags)
2998{ 3095{
2999 struct ifaddrmsg *ifm;
3000 struct nlmsghdr *nlh; 3096 struct nlmsghdr *nlh;
3001 struct ifa_cacheinfo ci; 3097 u32 preferred, valid;
3002 unsigned char *b = skb->tail; 3098
3099 nlh = nlmsg_put(skb, pid, seq, event, sizeof(struct ifaddrmsg), flags);
3100 if (nlh == NULL)
3101 return -ENOBUFS;
3102
3103 put_ifaddrmsg(nlh, ifa->prefix_len, ifa->flags, rt_scope(ifa->scope),
3104 ifa->idev->dev->ifindex);
3003 3105
3004 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*ifm), flags);
3005 ifm = NLMSG_DATA(nlh);
3006 ifm->ifa_family = AF_INET6;
3007 ifm->ifa_prefixlen = ifa->prefix_len;
3008 ifm->ifa_flags = ifa->flags;
3009 ifm->ifa_scope = RT_SCOPE_UNIVERSE;
3010 if (ifa->scope&IFA_HOST)
3011 ifm->ifa_scope = RT_SCOPE_HOST;
3012 else if (ifa->scope&IFA_LINK)
3013 ifm->ifa_scope = RT_SCOPE_LINK;
3014 else if (ifa->scope&IFA_SITE)
3015 ifm->ifa_scope = RT_SCOPE_SITE;
3016 ifm->ifa_index = ifa->idev->dev->ifindex;
3017 RTA_PUT(skb, IFA_ADDRESS, 16, &ifa->addr);
3018 if (!(ifa->flags&IFA_F_PERMANENT)) { 3106 if (!(ifa->flags&IFA_F_PERMANENT)) {
3019 ci.ifa_prefered = ifa->prefered_lft; 3107 preferred = ifa->prefered_lft;
3020 ci.ifa_valid = ifa->valid_lft; 3108 valid = ifa->valid_lft;
3021 if (ci.ifa_prefered != INFINITY_LIFE_TIME) { 3109 if (preferred != INFINITY_LIFE_TIME) {
3022 long tval = (jiffies - ifa->tstamp)/HZ; 3110 long tval = (jiffies - ifa->tstamp)/HZ;
3023 ci.ifa_prefered -= tval; 3111 preferred -= tval;
3024 if (ci.ifa_valid != INFINITY_LIFE_TIME) 3112 if (valid != INFINITY_LIFE_TIME)
3025 ci.ifa_valid -= tval; 3113 valid -= tval;
3026 } 3114 }
3027 } else { 3115 } else {
3028 ci.ifa_prefered = INFINITY_LIFE_TIME; 3116 preferred = INFINITY_LIFE_TIME;
3029 ci.ifa_valid = INFINITY_LIFE_TIME; 3117 valid = INFINITY_LIFE_TIME;
3030 } 3118 }
3031 ci.cstamp = (__u32)(TIME_DELTA(ifa->cstamp, INITIAL_JIFFIES) / HZ * 100
3032 + TIME_DELTA(ifa->cstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
3033 ci.tstamp = (__u32)(TIME_DELTA(ifa->tstamp, INITIAL_JIFFIES) / HZ * 100
3034 + TIME_DELTA(ifa->tstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
3035 RTA_PUT(skb, IFA_CACHEINFO, sizeof(ci), &ci);
3036 nlh->nlmsg_len = skb->tail - b;
3037 return skb->len;
3038 3119
3039nlmsg_failure: 3120 if (nla_put(skb, IFA_ADDRESS, 16, &ifa->addr) < 0 ||
3040rtattr_failure: 3121 put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0)
3041 skb_trim(skb, b - skb->data); 3122 return nlmsg_cancel(skb, nlh);
3042 return -1; 3123
3124 return nlmsg_end(skb, nlh);
3043} 3125}
3044 3126
3045static int inet6_fill_ifmcaddr(struct sk_buff *skb, struct ifmcaddr6 *ifmca, 3127static int inet6_fill_ifmcaddr(struct sk_buff *skb, struct ifmcaddr6 *ifmca,
3046 u32 pid, u32 seq, int event, u16 flags) 3128 u32 pid, u32 seq, int event, u16 flags)
3047{ 3129{
3048 struct ifaddrmsg *ifm;
3049 struct nlmsghdr *nlh; 3130 struct nlmsghdr *nlh;
3050 struct ifa_cacheinfo ci; 3131 u8 scope = RT_SCOPE_UNIVERSE;
3051 unsigned char *b = skb->tail; 3132 int ifindex = ifmca->idev->dev->ifindex;
3052
3053 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*ifm), flags);
3054 ifm = NLMSG_DATA(nlh);
3055 ifm->ifa_family = AF_INET6;
3056 ifm->ifa_prefixlen = 128;
3057 ifm->ifa_flags = IFA_F_PERMANENT;
3058 ifm->ifa_scope = RT_SCOPE_UNIVERSE;
3059 if (ipv6_addr_scope(&ifmca->mca_addr)&IFA_SITE)
3060 ifm->ifa_scope = RT_SCOPE_SITE;
3061 ifm->ifa_index = ifmca->idev->dev->ifindex;
3062 RTA_PUT(skb, IFA_MULTICAST, 16, &ifmca->mca_addr);
3063 ci.cstamp = (__u32)(TIME_DELTA(ifmca->mca_cstamp, INITIAL_JIFFIES) / HZ
3064 * 100 + TIME_DELTA(ifmca->mca_cstamp, INITIAL_JIFFIES) % HZ
3065 * 100 / HZ);
3066 ci.tstamp = (__u32)(TIME_DELTA(ifmca->mca_tstamp, INITIAL_JIFFIES) / HZ
3067 * 100 + TIME_DELTA(ifmca->mca_tstamp, INITIAL_JIFFIES) % HZ
3068 * 100 / HZ);
3069 ci.ifa_prefered = INFINITY_LIFE_TIME;
3070 ci.ifa_valid = INFINITY_LIFE_TIME;
3071 RTA_PUT(skb, IFA_CACHEINFO, sizeof(ci), &ci);
3072 nlh->nlmsg_len = skb->tail - b;
3073 return skb->len;
3074 3133
3075nlmsg_failure: 3134 if (ipv6_addr_scope(&ifmca->mca_addr) & IFA_SITE)
3076rtattr_failure: 3135 scope = RT_SCOPE_SITE;
3077 skb_trim(skb, b - skb->data); 3136
3078 return -1; 3137 nlh = nlmsg_put(skb, pid, seq, event, sizeof(struct ifaddrmsg), flags);
3138 if (nlh == NULL)
3139 return -ENOBUFS;
3140
3141 put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
3142 if (nla_put(skb, IFA_MULTICAST, 16, &ifmca->mca_addr) < 0 ||
3143 put_cacheinfo(skb, ifmca->mca_cstamp, ifmca->mca_tstamp,
3144 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0)
3145 return nlmsg_cancel(skb, nlh);
3146
3147 return nlmsg_end(skb, nlh);
3079} 3148}
3080 3149
3081static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca, 3150static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca,
3082 u32 pid, u32 seq, int event, unsigned int flags) 3151 u32 pid, u32 seq, int event, unsigned int flags)
3083{ 3152{
3084 struct ifaddrmsg *ifm;
3085 struct nlmsghdr *nlh; 3153 struct nlmsghdr *nlh;
3086 struct ifa_cacheinfo ci; 3154 u8 scope = RT_SCOPE_UNIVERSE;
3087 unsigned char *b = skb->tail; 3155 int ifindex = ifaca->aca_idev->dev->ifindex;
3088
3089 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*ifm), flags);
3090 ifm = NLMSG_DATA(nlh);
3091 ifm->ifa_family = AF_INET6;
3092 ifm->ifa_prefixlen = 128;
3093 ifm->ifa_flags = IFA_F_PERMANENT;
3094 ifm->ifa_scope = RT_SCOPE_UNIVERSE;
3095 if (ipv6_addr_scope(&ifaca->aca_addr)&IFA_SITE)
3096 ifm->ifa_scope = RT_SCOPE_SITE;
3097 ifm->ifa_index = ifaca->aca_idev->dev->ifindex;
3098 RTA_PUT(skb, IFA_ANYCAST, 16, &ifaca->aca_addr);
3099 ci.cstamp = (__u32)(TIME_DELTA(ifaca->aca_cstamp, INITIAL_JIFFIES) / HZ
3100 * 100 + TIME_DELTA(ifaca->aca_cstamp, INITIAL_JIFFIES) % HZ
3101 * 100 / HZ);
3102 ci.tstamp = (__u32)(TIME_DELTA(ifaca->aca_tstamp, INITIAL_JIFFIES) / HZ
3103 * 100 + TIME_DELTA(ifaca->aca_tstamp, INITIAL_JIFFIES) % HZ
3104 * 100 / HZ);
3105 ci.ifa_prefered = INFINITY_LIFE_TIME;
3106 ci.ifa_valid = INFINITY_LIFE_TIME;
3107 RTA_PUT(skb, IFA_CACHEINFO, sizeof(ci), &ci);
3108 nlh->nlmsg_len = skb->tail - b;
3109 return skb->len;
3110 3156
3111nlmsg_failure: 3157 if (ipv6_addr_scope(&ifaca->aca_addr) & IFA_SITE)
3112rtattr_failure: 3158 scope = RT_SCOPE_SITE;
3113 skb_trim(skb, b - skb->data); 3159
3114 return -1; 3160 nlh = nlmsg_put(skb, pid, seq, event, sizeof(struct ifaddrmsg), flags);
3161 if (nlh == NULL)
3162 return -ENOBUFS;
3163
3164 put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
3165 if (nla_put(skb, IFA_ANYCAST, 16, &ifaca->aca_addr) < 0 ||
3166 put_cacheinfo(skb, ifaca->aca_cstamp, ifaca->aca_tstamp,
3167 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0)
3168 return nlmsg_cancel(skb, nlh);
3169
3170 return nlmsg_end(skb, nlh);
3115} 3171}
3116 3172
3117enum addr_type_t 3173enum addr_type_t
@@ -3222,79 +3278,74 @@ static int inet6_dump_ifacaddr(struct sk_buff *skb, struct netlink_callback *cb)
3222 return inet6_dump_addr(skb, cb, type); 3278 return inet6_dump_addr(skb, cb, type);
3223} 3279}
3224 3280
3225static int inet6_rtm_getaddr(struct sk_buff *in_skb, 3281static int inet6_rtm_getaddr(struct sk_buff *in_skb, struct nlmsghdr* nlh,
3226 struct nlmsghdr* nlh, void *arg) 3282 void *arg)
3227{ 3283{
3228 struct rtattr **rta = arg; 3284 struct ifaddrmsg *ifm;
3229 struct ifaddrmsg *ifm = NLMSG_DATA(nlh); 3285 struct nlattr *tb[IFA_MAX+1];
3230 struct in6_addr *addr = NULL; 3286 struct in6_addr *addr = NULL;
3231 struct net_device *dev = NULL; 3287 struct net_device *dev = NULL;
3232 struct inet6_ifaddr *ifa; 3288 struct inet6_ifaddr *ifa;
3233 struct sk_buff *skb; 3289 struct sk_buff *skb;
3234 int size = NLMSG_SPACE(sizeof(struct ifaddrmsg) + INET6_IFADDR_RTA_SPACE);
3235 int err; 3290 int err;
3236 3291
3237 if (rta[IFA_ADDRESS-1]) { 3292 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
3238 if (RTA_PAYLOAD(rta[IFA_ADDRESS-1]) < sizeof(*addr)) 3293 if (err < 0)
3239 return -EINVAL; 3294 goto errout;
3240 addr = RTA_DATA(rta[IFA_ADDRESS-1]); 3295
3241 } 3296 addr = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]);
3242 if (rta[IFA_LOCAL-1]) { 3297 if (addr == NULL) {
3243 if (RTA_PAYLOAD(rta[IFA_LOCAL-1]) < sizeof(*addr) || 3298 err = -EINVAL;
3244 (addr && memcmp(addr, RTA_DATA(rta[IFA_LOCAL-1]), sizeof(*addr)))) 3299 goto errout;
3245 return -EINVAL;
3246 addr = RTA_DATA(rta[IFA_LOCAL-1]);
3247 } 3300 }
3248 if (addr == NULL)
3249 return -EINVAL;
3250 3301
3302 ifm = nlmsg_data(nlh);
3251 if (ifm->ifa_index) 3303 if (ifm->ifa_index)
3252 dev = __dev_get_by_index(ifm->ifa_index); 3304 dev = __dev_get_by_index(ifm->ifa_index);
3253 3305
3254 if ((ifa = ipv6_get_ifaddr(addr, dev, 1)) == NULL) 3306 if ((ifa = ipv6_get_ifaddr(addr, dev, 1)) == NULL) {
3255 return -EADDRNOTAVAIL; 3307 err = -EADDRNOTAVAIL;
3308 goto errout;
3309 }
3256 3310
3257 if ((skb = alloc_skb(size, GFP_KERNEL)) == NULL) { 3311 if ((skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_KERNEL)) == NULL) {
3258 err = -ENOBUFS; 3312 err = -ENOBUFS;
3259 goto out; 3313 goto errout_ifa;
3260 } 3314 }
3261 3315
3262 NETLINK_CB(skb).dst_pid = NETLINK_CB(in_skb).pid;
3263 err = inet6_fill_ifaddr(skb, ifa, NETLINK_CB(in_skb).pid, 3316 err = inet6_fill_ifaddr(skb, ifa, NETLINK_CB(in_skb).pid,
3264 nlh->nlmsg_seq, RTM_NEWADDR, 0); 3317 nlh->nlmsg_seq, RTM_NEWADDR, 0);
3265 if (err < 0) { 3318 if (err < 0) {
3266 err = -EMSGSIZE; 3319 kfree_skb(skb);
3267 goto out_free; 3320 goto errout_ifa;
3268 } 3321 }
3269 3322
3270 err = netlink_unicast(rtnl, skb, NETLINK_CB(in_skb).pid, MSG_DONTWAIT); 3323 err = rtnl_unicast(skb, NETLINK_CB(in_skb).pid);
3271 if (err > 0) 3324errout_ifa:
3272 err = 0;
3273out:
3274 in6_ifa_put(ifa); 3325 in6_ifa_put(ifa);
3326errout:
3275 return err; 3327 return err;
3276out_free:
3277 kfree_skb(skb);
3278 goto out;
3279} 3328}
3280 3329
3281static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa) 3330static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa)
3282{ 3331{
3283 struct sk_buff *skb; 3332 struct sk_buff *skb;
3284 int size = NLMSG_SPACE(sizeof(struct ifaddrmsg) + INET6_IFADDR_RTA_SPACE); 3333 int err = -ENOBUFS;
3285 3334
3286 skb = alloc_skb(size, GFP_ATOMIC); 3335 skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_ATOMIC);
3287 if (!skb) { 3336 if (skb == NULL)
3288 netlink_set_err(rtnl, 0, RTNLGRP_IPV6_IFADDR, ENOBUFS); 3337 goto errout;
3289 return; 3338
3290 } 3339 err = inet6_fill_ifaddr(skb, ifa, 0, 0, event, 0);
3291 if (inet6_fill_ifaddr(skb, ifa, current->pid, 0, event, 0) < 0) { 3340 if (err < 0) {
3292 kfree_skb(skb); 3341 kfree_skb(skb);
3293 netlink_set_err(rtnl, 0, RTNLGRP_IPV6_IFADDR, EINVAL); 3342 goto errout;
3294 return;
3295 } 3343 }
3296 NETLINK_CB(skb).dst_group = RTNLGRP_IPV6_IFADDR; 3344
3297 netlink_broadcast(rtnl, skb, 0, RTNLGRP_IPV6_IFADDR, GFP_ATOMIC); 3345 err = rtnl_notify(skb, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC);
3346errout:
3347 if (err < 0)
3348 rtnl_set_sk_err(RTNLGRP_IPV6_IFADDR, err);
3298} 3349}
3299 3350
3300static void inline ipv6_store_devconf(struct ipv6_devconf *cnf, 3351static void inline ipv6_store_devconf(struct ipv6_devconf *cnf,
@@ -3329,6 +3380,7 @@ static void inline ipv6_store_devconf(struct ipv6_devconf *cnf,
3329 array[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN] = cnf->accept_ra_rt_info_max_plen; 3380 array[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN] = cnf->accept_ra_rt_info_max_plen;
3330#endif 3381#endif
3331#endif 3382#endif
3383 array[DEVCONF_PROXY_NDP] = cnf->proxy_ndp;
3332} 3384}
3333 3385
3334/* Maximum length of ifinfomsg attributes */ 3386/* Maximum length of ifinfomsg attributes */
@@ -3435,20 +3487,23 @@ static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
3435void inet6_ifinfo_notify(int event, struct inet6_dev *idev) 3487void inet6_ifinfo_notify(int event, struct inet6_dev *idev)
3436{ 3488{
3437 struct sk_buff *skb; 3489 struct sk_buff *skb;
3438 int size = NLMSG_SPACE(sizeof(struct ifinfomsg) + INET6_IFINFO_RTA_SPACE); 3490 int payload = sizeof(struct ifinfomsg) + INET6_IFINFO_RTA_SPACE;
3491 int err = -ENOBUFS;
3439 3492
3440 skb = alloc_skb(size, GFP_ATOMIC); 3493 skb = nlmsg_new(nlmsg_total_size(payload), GFP_ATOMIC);
3441 if (!skb) { 3494 if (skb == NULL)
3442 netlink_set_err(rtnl, 0, RTNLGRP_IPV6_IFINFO, ENOBUFS); 3495 goto errout;
3443 return; 3496
3444 } 3497 err = inet6_fill_ifinfo(skb, idev, 0, 0, event, 0);
3445 if (inet6_fill_ifinfo(skb, idev, current->pid, 0, event, 0) < 0) { 3498 if (err < 0) {
3446 kfree_skb(skb); 3499 kfree_skb(skb);
3447 netlink_set_err(rtnl, 0, RTNLGRP_IPV6_IFINFO, EINVAL); 3500 goto errout;
3448 return;
3449 } 3501 }
3450 NETLINK_CB(skb).dst_group = RTNLGRP_IPV6_IFINFO; 3502
3451 netlink_broadcast(rtnl, skb, 0, RTNLGRP_IPV6_IFINFO, GFP_ATOMIC); 3503 err = rtnl_notify(skb, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC);
3504errout:
3505 if (err < 0)
3506 rtnl_set_sk_err(RTNLGRP_IPV6_IFADDR, err);
3452} 3507}
3453 3508
3454/* Maximum length of prefix_cacheinfo attributes */ 3509/* Maximum length of prefix_cacheinfo attributes */
@@ -3500,20 +3555,23 @@ static void inet6_prefix_notify(int event, struct inet6_dev *idev,
3500 struct prefix_info *pinfo) 3555 struct prefix_info *pinfo)
3501{ 3556{
3502 struct sk_buff *skb; 3557 struct sk_buff *skb;
3503 int size = NLMSG_SPACE(sizeof(struct prefixmsg) + INET6_PREFIX_RTA_SPACE); 3558 int payload = sizeof(struct prefixmsg) + INET6_PREFIX_RTA_SPACE;
3559 int err = -ENOBUFS;
3504 3560
3505 skb = alloc_skb(size, GFP_ATOMIC); 3561 skb = nlmsg_new(nlmsg_total_size(payload), GFP_ATOMIC);
3506 if (!skb) { 3562 if (skb == NULL)
3507 netlink_set_err(rtnl, 0, RTNLGRP_IPV6_PREFIX, ENOBUFS); 3563 goto errout;
3508 return; 3564
3509 } 3565 err = inet6_fill_prefix(skb, idev, pinfo, 0, 0, event, 0);
3510 if (inet6_fill_prefix(skb, idev, pinfo, current->pid, 0, event, 0) < 0) { 3566 if (err < 0) {
3511 kfree_skb(skb); 3567 kfree_skb(skb);
3512 netlink_set_err(rtnl, 0, RTNLGRP_IPV6_PREFIX, EINVAL); 3568 goto errout;
3513 return;
3514 } 3569 }
3515 NETLINK_CB(skb).dst_group = RTNLGRP_IPV6_PREFIX; 3570
3516 netlink_broadcast(rtnl, skb, 0, RTNLGRP_IPV6_PREFIX, GFP_ATOMIC); 3571 err = rtnl_notify(skb, 0, RTNLGRP_IPV6_PREFIX, NULL, GFP_ATOMIC);
3572errout:
3573 if (err < 0)
3574 rtnl_set_sk_err(RTNLGRP_IPV6_PREFIX, err);
3517} 3575}
3518 3576
3519static struct rtnetlink_link inet6_rtnetlink_table[RTM_NR_MSGTYPES] = { 3577static struct rtnetlink_link inet6_rtnetlink_table[RTM_NR_MSGTYPES] = {
@@ -3528,6 +3586,9 @@ static struct rtnetlink_link inet6_rtnetlink_table[RTM_NR_MSGTYPES] = {
3528 [RTM_DELROUTE - RTM_BASE] = { .doit = inet6_rtm_delroute, }, 3586 [RTM_DELROUTE - RTM_BASE] = { .doit = inet6_rtm_delroute, },
3529 [RTM_GETROUTE - RTM_BASE] = { .doit = inet6_rtm_getroute, 3587 [RTM_GETROUTE - RTM_BASE] = { .doit = inet6_rtm_getroute,
3530 .dumpit = inet6_dump_fib, }, 3588 .dumpit = inet6_dump_fib, },
3589#ifdef CONFIG_IPV6_MULTIPLE_TABLES
3590 [RTM_GETRULE - RTM_BASE] = { .dumpit = fib6_rules_dump, },
3591#endif
3531}; 3592};
3532 3593
3533static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) 3594static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
@@ -3536,7 +3597,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
3536 3597
3537 switch (event) { 3598 switch (event) {
3538 case RTM_NEWADDR: 3599 case RTM_NEWADDR:
3539 ip6_ins_rt(ifp->rt, NULL, NULL, NULL); 3600 ip6_ins_rt(ifp->rt);
3540 if (ifp->idev->cnf.forwarding) 3601 if (ifp->idev->cnf.forwarding)
3541 addrconf_join_anycast(ifp); 3602 addrconf_join_anycast(ifp);
3542 break; 3603 break;
@@ -3545,7 +3606,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
3545 addrconf_leave_anycast(ifp); 3606 addrconf_leave_anycast(ifp);
3546 addrconf_leave_solict(ifp->idev, &ifp->addr); 3607 addrconf_leave_solict(ifp->idev, &ifp->addr);
3547 dst_hold(&ifp->rt->u.dst); 3608 dst_hold(&ifp->rt->u.dst);
3548 if (ip6_del_rt(ifp->rt, NULL, NULL, NULL)) 3609 if (ip6_del_rt(ifp->rt))
3549 dst_free(&ifp->rt->u.dst); 3610 dst_free(&ifp->rt->u.dst);
3550 break; 3611 break;
3551 } 3612 }
@@ -3553,10 +3614,10 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
3553 3614
3554static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) 3615static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
3555{ 3616{
3556 read_lock_bh(&addrconf_lock); 3617 rcu_read_lock_bh();
3557 if (likely(ifp->idev->dead == 0)) 3618 if (likely(ifp->idev->dead == 0))
3558 __ipv6_ifa_notify(event, ifp); 3619 __ipv6_ifa_notify(event, ifp);
3559 read_unlock_bh(&addrconf_lock); 3620 rcu_read_unlock_bh();
3560} 3621}
3561 3622
3562#ifdef CONFIG_SYSCTL 3623#ifdef CONFIG_SYSCTL
@@ -3653,7 +3714,7 @@ static struct addrconf_sysctl_table
3653 ctl_table addrconf_conf_dir[2]; 3714 ctl_table addrconf_conf_dir[2];
3654 ctl_table addrconf_proto_dir[2]; 3715 ctl_table addrconf_proto_dir[2];
3655 ctl_table addrconf_root_dir[2]; 3716 ctl_table addrconf_root_dir[2];
3656} addrconf_sysctl = { 3717} addrconf_sysctl __read_mostly = {
3657 .sysctl_header = NULL, 3718 .sysctl_header = NULL,
3658 .addrconf_vars = { 3719 .addrconf_vars = {
3659 { 3720 {
@@ -3843,6 +3904,14 @@ static struct addrconf_sysctl_table
3843#endif 3904#endif
3844#endif 3905#endif
3845 { 3906 {
3907 .ctl_name = NET_IPV6_PROXY_NDP,
3908 .procname = "proxy_ndp",
3909 .data = &ipv6_devconf.proxy_ndp,
3910 .maxlen = sizeof(int),
3911 .mode = 0644,
3912 .proc_handler = &proc_dointvec,
3913 },
3914 {
3846 .ctl_name = 0, /* sentinel */ 3915 .ctl_name = 0, /* sentinel */
3847 } 3916 }
3848 }, 3917 },