diff options
Diffstat (limited to 'net/ipv6/addrconf.c')
| -rw-r--r-- | net/ipv6/addrconf.c | 723 |
1 files changed, 484 insertions, 239 deletions
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 4da664538f52..e03c33b2465b 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c | |||
| @@ -40,7 +40,6 @@ | |||
| 40 | * status etc. | 40 | * status etc. |
| 41 | */ | 41 | */ |
| 42 | 42 | ||
| 43 | #include <linux/config.h> | ||
| 44 | #include <linux/errno.h> | 43 | #include <linux/errno.h> |
| 45 | #include <linux/types.h> | 44 | #include <linux/types.h> |
| 46 | #include <linux/socket.h> | 45 | #include <linux/socket.h> |
| @@ -49,6 +48,7 @@ | |||
| 49 | #include <linux/net.h> | 48 | #include <linux/net.h> |
| 50 | #include <linux/in6.h> | 49 | #include <linux/in6.h> |
| 51 | #include <linux/netdevice.h> | 50 | #include <linux/netdevice.h> |
| 51 | #include <linux/if_addr.h> | ||
| 52 | #include <linux/if_arp.h> | 52 | #include <linux/if_arp.h> |
| 53 | #include <linux/if_arcnet.h> | 53 | #include <linux/if_arcnet.h> |
| 54 | #include <linux/if_infiniband.h> | 54 | #include <linux/if_infiniband.h> |
| @@ -73,6 +73,7 @@ | |||
| 73 | #include <net/addrconf.h> | 73 | #include <net/addrconf.h> |
| 74 | #include <net/tcp.h> | 74 | #include <net/tcp.h> |
| 75 | #include <net/ip.h> | 75 | #include <net/ip.h> |
| 76 | #include <net/netlink.h> | ||
| 76 | #include <linux/if_tunnel.h> | 77 | #include <linux/if_tunnel.h> |
| 77 | #include <linux/rtnetlink.h> | 78 | #include <linux/rtnetlink.h> |
| 78 | 79 | ||
| @@ -118,9 +119,6 @@ static int ipv6_count_addresses(struct inet6_dev *idev); | |||
| 118 | static struct inet6_ifaddr *inet6_addr_lst[IN6_ADDR_HSIZE]; | 119 | static struct inet6_ifaddr *inet6_addr_lst[IN6_ADDR_HSIZE]; |
| 119 | static DEFINE_RWLOCK(addrconf_hash_lock); | 120 | static DEFINE_RWLOCK(addrconf_hash_lock); |
| 120 | 121 | ||
| 121 | /* Protects inet6 devices */ | ||
| 122 | DEFINE_RWLOCK(addrconf_lock); | ||
| 123 | |||
| 124 | static void addrconf_verify(unsigned long); | 122 | static void addrconf_verify(unsigned long); |
| 125 | 123 | ||
| 126 | static DEFINE_TIMER(addr_chk_timer, addrconf_verify, 0, 0); | 124 | static DEFINE_TIMER(addr_chk_timer, addrconf_verify, 0, 0); |
| @@ -145,7 +143,7 @@ static int ipv6_chk_same_addr(const struct in6_addr *addr, struct net_device *de | |||
| 145 | 143 | ||
| 146 | static ATOMIC_NOTIFIER_HEAD(inet6addr_chain); | 144 | static ATOMIC_NOTIFIER_HEAD(inet6addr_chain); |
| 147 | 145 | ||
| 148 | struct ipv6_devconf ipv6_devconf = { | 146 | struct ipv6_devconf ipv6_devconf __read_mostly = { |
| 149 | .forwarding = 0, | 147 | .forwarding = 0, |
| 150 | .hop_limit = IPV6_DEFAULT_HOPLIMIT, | 148 | .hop_limit = IPV6_DEFAULT_HOPLIMIT, |
| 151 | .mtu6 = IPV6_MIN_MTU, | 149 | .mtu6 = IPV6_MIN_MTU, |
| @@ -174,9 +172,10 @@ struct ipv6_devconf ipv6_devconf = { | |||
| 174 | .accept_ra_rt_info_max_plen = 0, | 172 | .accept_ra_rt_info_max_plen = 0, |
| 175 | #endif | 173 | #endif |
| 176 | #endif | 174 | #endif |
| 175 | .proxy_ndp = 0, | ||
| 177 | }; | 176 | }; |
| 178 | 177 | ||
| 179 | static struct ipv6_devconf ipv6_devconf_dflt = { | 178 | static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = { |
| 180 | .forwarding = 0, | 179 | .forwarding = 0, |
| 181 | .hop_limit = IPV6_DEFAULT_HOPLIMIT, | 180 | .hop_limit = IPV6_DEFAULT_HOPLIMIT, |
| 182 | .mtu6 = IPV6_MIN_MTU, | 181 | .mtu6 = IPV6_MIN_MTU, |
| @@ -204,6 +203,7 @@ static struct ipv6_devconf ipv6_devconf_dflt = { | |||
| 204 | .accept_ra_rt_info_max_plen = 0, | 203 | .accept_ra_rt_info_max_plen = 0, |
| 205 | #endif | 204 | #endif |
| 206 | #endif | 205 | #endif |
| 206 | .proxy_ndp = 0, | ||
| 207 | }; | 207 | }; |
| 208 | 208 | ||
| 209 | /* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */ | 209 | /* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */ |
| @@ -315,6 +315,12 @@ static void addrconf_mod_timer(struct inet6_ifaddr *ifp, | |||
| 315 | 315 | ||
| 316 | /* Nobody refers to this device, we may destroy it. */ | 316 | /* Nobody refers to this device, we may destroy it. */ |
| 317 | 317 | ||
| 318 | static 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 | |||
| 318 | void in6_dev_finish_destroy(struct inet6_dev *idev) | 324 | void in6_dev_finish_destroy(struct inet6_dev *idev) |
| 319 | { | 325 | { |
| 320 | struct net_device *dev = idev->dev; | 326 | struct net_device *dev = idev->dev; |
| @@ -329,7 +335,7 @@ void in6_dev_finish_destroy(struct inet6_dev *idev) | |||
| 329 | return; | 335 | return; |
| 330 | } | 336 | } |
| 331 | snmp6_free_dev(idev); | 337 | snmp6_free_dev(idev); |
| 332 | kfree(idev); | 338 | call_rcu(&idev->rcu, in6_dev_finish_destroy_rcu); |
| 333 | } | 339 | } |
| 334 | 340 | ||
| 335 | static struct inet6_dev * ipv6_add_dev(struct net_device *dev) | 341 | static struct inet6_dev * ipv6_add_dev(struct net_device *dev) |
| @@ -405,9 +411,8 @@ static struct inet6_dev * ipv6_add_dev(struct net_device *dev) | |||
| 405 | if (netif_carrier_ok(dev)) | 411 | if (netif_carrier_ok(dev)) |
| 406 | ndev->if_flags |= IF_READY; | 412 | ndev->if_flags |= IF_READY; |
| 407 | 413 | ||
| 408 | write_lock_bh(&addrconf_lock); | 414 | /* protected by rtnl_lock */ |
| 409 | dev->ip6_ptr = ndev; | 415 | rcu_assign_pointer(dev->ip6_ptr, ndev); |
| 410 | write_unlock_bh(&addrconf_lock); | ||
| 411 | 416 | ||
| 412 | ipv6_mc_init_dev(ndev); | 417 | ipv6_mc_init_dev(ndev); |
| 413 | ndev->tstamp = jiffies; | 418 | ndev->tstamp = jiffies; |
| @@ -471,7 +476,7 @@ static void addrconf_forward_change(void) | |||
| 471 | 476 | ||
| 472 | read_lock(&dev_base_lock); | 477 | read_lock(&dev_base_lock); |
| 473 | for (dev=dev_base; dev; dev=dev->next) { | 478 | for (dev=dev_base; dev; dev=dev->next) { |
| 474 | read_lock(&addrconf_lock); | 479 | rcu_read_lock(); |
| 475 | idev = __in6_dev_get(dev); | 480 | idev = __in6_dev_get(dev); |
| 476 | if (idev) { | 481 | if (idev) { |
| 477 | int changed = (!idev->cnf.forwarding) ^ (!ipv6_devconf.forwarding); | 482 | int changed = (!idev->cnf.forwarding) ^ (!ipv6_devconf.forwarding); |
| @@ -479,7 +484,7 @@ static void addrconf_forward_change(void) | |||
| 479 | if (changed) | 484 | if (changed) |
| 480 | dev_forward_change(idev); | 485 | dev_forward_change(idev); |
| 481 | } | 486 | } |
| 482 | read_unlock(&addrconf_lock); | 487 | rcu_read_unlock(); |
| 483 | } | 488 | } |
| 484 | read_unlock(&dev_base_lock); | 489 | read_unlock(&dev_base_lock); |
| 485 | } | 490 | } |
| @@ -509,6 +514,26 @@ void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp) | |||
| 509 | kfree(ifp); | 514 | kfree(ifp); |
| 510 | } | 515 | } |
| 511 | 516 | ||
| 517 | static void | ||
| 518 | ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp) | ||
| 519 | { | ||
| 520 | struct inet6_ifaddr *ifa, **ifap; | ||
| 521 | int ifp_scope = ipv6_addr_src_scope(&ifp->addr); | ||
| 522 | |||
| 523 | /* | ||
| 524 | * Each device address list is sorted in order of scope - | ||
| 525 | * global before linklocal. | ||
| 526 | */ | ||
| 527 | for (ifap = &idev->addr_list; (ifa = *ifap) != NULL; | ||
| 528 | ifap = &ifa->if_next) { | ||
| 529 | if (ifp_scope >= ipv6_addr_src_scope(&ifa->addr)) | ||
| 530 | break; | ||
| 531 | } | ||
| 532 | |||
| 533 | ifp->if_next = *ifap; | ||
| 534 | *ifap = ifp; | ||
| 535 | } | ||
| 536 | |||
| 512 | /* On success it returns ifp with increased reference count */ | 537 | /* On success it returns ifp with increased reference count */ |
| 513 | 538 | ||
| 514 | static struct inet6_ifaddr * | 539 | static struct inet6_ifaddr * |
| @@ -520,7 +545,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen, | |||
| 520 | int hash; | 545 | int hash; |
| 521 | int err = 0; | 546 | int err = 0; |
| 522 | 547 | ||
| 523 | read_lock_bh(&addrconf_lock); | 548 | rcu_read_lock_bh(); |
| 524 | if (idev->dead) { | 549 | if (idev->dead) { |
| 525 | err = -ENODEV; /*XXX*/ | 550 | err = -ENODEV; /*XXX*/ |
| 526 | goto out2; | 551 | goto out2; |
| @@ -559,6 +584,8 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen, | |||
| 559 | ifa->flags = flags | IFA_F_TENTATIVE; | 584 | ifa->flags = flags | IFA_F_TENTATIVE; |
| 560 | ifa->cstamp = ifa->tstamp = jiffies; | 585 | ifa->cstamp = ifa->tstamp = jiffies; |
| 561 | 586 | ||
| 587 | ifa->rt = rt; | ||
| 588 | |||
| 562 | ifa->idev = idev; | 589 | ifa->idev = idev; |
| 563 | in6_dev_hold(idev); | 590 | in6_dev_hold(idev); |
| 564 | /* For caller */ | 591 | /* For caller */ |
| @@ -574,8 +601,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen, | |||
| 574 | 601 | ||
| 575 | write_lock(&idev->lock); | 602 | write_lock(&idev->lock); |
| 576 | /* Add to inet6_dev unicast addr list. */ | 603 | /* Add to inet6_dev unicast addr list. */ |
| 577 | ifa->if_next = idev->addr_list; | 604 | ipv6_link_dev_addr(idev, ifa); |
| 578 | idev->addr_list = ifa; | ||
| 579 | 605 | ||
| 580 | #ifdef CONFIG_IPV6_PRIVACY | 606 | #ifdef CONFIG_IPV6_PRIVACY |
| 581 | if (ifa->flags&IFA_F_TEMPORARY) { | 607 | if (ifa->flags&IFA_F_TEMPORARY) { |
| @@ -585,12 +611,10 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen, | |||
| 585 | } | 611 | } |
| 586 | #endif | 612 | #endif |
| 587 | 613 | ||
| 588 | ifa->rt = rt; | ||
| 589 | |||
| 590 | in6_ifa_hold(ifa); | 614 | in6_ifa_hold(ifa); |
| 591 | write_unlock(&idev->lock); | 615 | write_unlock(&idev->lock); |
| 592 | out2: | 616 | out2: |
| 593 | read_unlock_bh(&addrconf_lock); | 617 | rcu_read_unlock_bh(); |
| 594 | 618 | ||
| 595 | if (likely(err == 0)) | 619 | if (likely(err == 0)) |
| 596 | atomic_notifier_call_chain(&inet6addr_chain, NETDEV_UP, ifa); | 620 | atomic_notifier_call_chain(&inet6addr_chain, NETDEV_UP, ifa); |
| @@ -716,7 +740,7 @@ static void ipv6_del_addr(struct inet6_ifaddr *ifp) | |||
| 716 | 740 | ||
| 717 | if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) { | 741 | if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) { |
| 718 | if (onlink == 0) { | 742 | if (onlink == 0) { |
| 719 | ip6_del_rt(rt, NULL, NULL, NULL); | 743 | ip6_del_rt(rt); |
| 720 | rt = NULL; | 744 | rt = NULL; |
| 721 | } else if (!(rt->rt6i_flags & RTF_EXPIRES)) { | 745 | } else if (!(rt->rt6i_flags & RTF_EXPIRES)) { |
| 722 | rt->rt6i_expires = expires; | 746 | rt->rt6i_expires = expires; |
| @@ -893,7 +917,7 @@ int ipv6_dev_get_saddr(struct net_device *daddr_dev, | |||
| 893 | memset(&hiscore, 0, sizeof(hiscore)); | 917 | memset(&hiscore, 0, sizeof(hiscore)); |
| 894 | 918 | ||
| 895 | read_lock(&dev_base_lock); | 919 | read_lock(&dev_base_lock); |
| 896 | read_lock(&addrconf_lock); | 920 | rcu_read_lock(); |
| 897 | 921 | ||
| 898 | for (dev = dev_base; dev; dev=dev->next) { | 922 | for (dev = dev_base; dev; dev=dev->next) { |
| 899 | struct inet6_dev *idev; | 923 | struct inet6_dev *idev; |
| @@ -988,7 +1012,7 @@ int ipv6_dev_get_saddr(struct net_device *daddr_dev, | |||
| 988 | continue; | 1012 | continue; |
| 989 | } else if (score.scope < hiscore.scope) { | 1013 | } else if (score.scope < hiscore.scope) { |
| 990 | if (score.scope < daddr_scope) | 1014 | if (score.scope < daddr_scope) |
| 991 | continue; | 1015 | break; /* addresses sorted by scope */ |
| 992 | else { | 1016 | else { |
| 993 | score.rule = 2; | 1017 | score.rule = 2; |
| 994 | goto record_it; | 1018 | goto record_it; |
| @@ -1014,9 +1038,27 @@ int ipv6_dev_get_saddr(struct net_device *daddr_dev, | |||
| 1014 | continue; | 1038 | continue; |
| 1015 | } | 1039 | } |
| 1016 | 1040 | ||
| 1017 | /* 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 | ||
| 1018 | if (hiscore.rule < 4) | 1059 | if (hiscore.rule < 4) |
| 1019 | hiscore.rule++; | 1060 | hiscore.rule++; |
| 1061 | #endif | ||
| 1020 | 1062 | ||
| 1021 | /* Rule 5: Prefer outgoing interface */ | 1063 | /* Rule 5: Prefer outgoing interface */ |
| 1022 | if (hiscore.rule < 5) { | 1064 | if (hiscore.rule < 5) { |
| @@ -1105,7 +1147,7 @@ record_it: | |||
| 1105 | } | 1147 | } |
| 1106 | read_unlock_bh(&idev->lock); | 1148 | read_unlock_bh(&idev->lock); |
| 1107 | } | 1149 | } |
| 1108 | read_unlock(&addrconf_lock); | 1150 | rcu_read_unlock(); |
| 1109 | read_unlock(&dev_base_lock); | 1151 | read_unlock(&dev_base_lock); |
| 1110 | 1152 | ||
| 1111 | if (!ifa_result) | 1153 | if (!ifa_result) |
| @@ -1129,7 +1171,7 @@ int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr) | |||
| 1129 | struct inet6_dev *idev; | 1171 | struct inet6_dev *idev; |
| 1130 | int err = -EADDRNOTAVAIL; | 1172 | int err = -EADDRNOTAVAIL; |
| 1131 | 1173 | ||
| 1132 | read_lock(&addrconf_lock); | 1174 | rcu_read_lock(); |
| 1133 | if ((idev = __in6_dev_get(dev)) != NULL) { | 1175 | if ((idev = __in6_dev_get(dev)) != NULL) { |
| 1134 | struct inet6_ifaddr *ifp; | 1176 | struct inet6_ifaddr *ifp; |
| 1135 | 1177 | ||
| @@ -1143,7 +1185,7 @@ int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr) | |||
| 1143 | } | 1185 | } |
| 1144 | read_unlock_bh(&idev->lock); | 1186 | read_unlock_bh(&idev->lock); |
| 1145 | } | 1187 | } |
| 1146 | read_unlock(&addrconf_lock); | 1188 | rcu_read_unlock(); |
| 1147 | return err; | 1189 | return err; |
| 1148 | } | 1190 | } |
| 1149 | 1191 | ||
| @@ -1216,8 +1258,8 @@ int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2) | |||
| 1216 | { | 1258 | { |
| 1217 | const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr; | 1259 | const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr; |
| 1218 | const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2); | 1260 | const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2); |
| 1219 | u32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr; | 1261 | __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr; |
| 1220 | u32 sk2_rcv_saddr = inet_rcv_saddr(sk2); | 1262 | __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2); |
| 1221 | int sk_ipv6only = ipv6_only_sock(sk); | 1263 | int sk_ipv6only = ipv6_only_sock(sk); |
| 1222 | int sk2_ipv6only = inet_v6_ipv6only(sk2); | 1264 | int sk2_ipv6only = inet_v6_ipv6only(sk2); |
| 1223 | int addr_type = ipv6_addr_type(sk_rcv_saddr6); | 1265 | int addr_type = ipv6_addr_type(sk_rcv_saddr6); |
| @@ -1444,7 +1486,7 @@ static void ipv6_regen_rndid(unsigned long data) | |||
| 1444 | struct inet6_dev *idev = (struct inet6_dev *) data; | 1486 | struct inet6_dev *idev = (struct inet6_dev *) data; |
| 1445 | unsigned long expires; | 1487 | unsigned long expires; |
| 1446 | 1488 | ||
| 1447 | read_lock_bh(&addrconf_lock); | 1489 | rcu_read_lock_bh(); |
| 1448 | write_lock_bh(&idev->lock); | 1490 | write_lock_bh(&idev->lock); |
| 1449 | 1491 | ||
| 1450 | if (idev->dead) | 1492 | if (idev->dead) |
| @@ -1468,7 +1510,7 @@ static void ipv6_regen_rndid(unsigned long data) | |||
| 1468 | 1510 | ||
| 1469 | out: | 1511 | out: |
| 1470 | write_unlock_bh(&idev->lock); | 1512 | write_unlock_bh(&idev->lock); |
| 1471 | read_unlock_bh(&addrconf_lock); | 1513 | rcu_read_unlock_bh(); |
| 1472 | in6_dev_put(idev); | 1514 | in6_dev_put(idev); |
| 1473 | } | 1515 | } |
| 1474 | 1516 | ||
| @@ -1489,59 +1531,56 @@ static void | |||
| 1489 | addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev, | 1531 | addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev, |
| 1490 | unsigned long expires, u32 flags) | 1532 | unsigned long expires, u32 flags) |
| 1491 | { | 1533 | { |
| 1492 | 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 | }; | ||
| 1493 | 1542 | ||
| 1494 | memset(&rtmsg, 0, sizeof(rtmsg)); | 1543 | ipv6_addr_copy(&cfg.fc_dst, pfx); |
| 1495 | ipv6_addr_copy(&rtmsg.rtmsg_dst, pfx); | ||
| 1496 | rtmsg.rtmsg_dst_len = plen; | ||
| 1497 | rtmsg.rtmsg_metric = IP6_RT_PRIO_ADDRCONF; | ||
| 1498 | rtmsg.rtmsg_ifindex = dev->ifindex; | ||
| 1499 | rtmsg.rtmsg_info = expires; | ||
| 1500 | rtmsg.rtmsg_flags = RTF_UP|flags; | ||
| 1501 | rtmsg.rtmsg_type = RTMSG_NEWROUTE; | ||
| 1502 | 1544 | ||
| 1503 | /* Prevent useless cloning on PtP SIT. | 1545 | /* Prevent useless cloning on PtP SIT. |
| 1504 | This thing is done here expecting that the whole | 1546 | This thing is done here expecting that the whole |
| 1505 | class of non-broadcast devices need not cloning. | 1547 | class of non-broadcast devices need not cloning. |
| 1506 | */ | 1548 | */ |
| 1507 | if (dev->type == ARPHRD_SIT && (dev->flags&IFF_POINTOPOINT)) | 1549 | if (dev->type == ARPHRD_SIT && (dev->flags & IFF_POINTOPOINT)) |
| 1508 | rtmsg.rtmsg_flags |= RTF_NONEXTHOP; | 1550 | cfg.fc_flags |= RTF_NONEXTHOP; |
| 1509 | 1551 | ||
| 1510 | ip6_route_add(&rtmsg, NULL, NULL, NULL); | 1552 | ip6_route_add(&cfg); |
| 1511 | } | 1553 | } |
| 1512 | 1554 | ||
| 1513 | /* Create "default" multicast route to the interface */ | 1555 | /* Create "default" multicast route to the interface */ |
| 1514 | 1556 | ||
| 1515 | static void addrconf_add_mroute(struct net_device *dev) | 1557 | static void addrconf_add_mroute(struct net_device *dev) |
| 1516 | { | 1558 | { |
| 1517 | 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); | ||
| 1518 | 1568 | ||
| 1519 | memset(&rtmsg, 0, sizeof(rtmsg)); | 1569 | ip6_route_add(&cfg); |
| 1520 | ipv6_addr_set(&rtmsg.rtmsg_dst, | ||
| 1521 | htonl(0xFF000000), 0, 0, 0); | ||
| 1522 | rtmsg.rtmsg_dst_len = 8; | ||
| 1523 | rtmsg.rtmsg_metric = IP6_RT_PRIO_ADDRCONF; | ||
| 1524 | rtmsg.rtmsg_ifindex = dev->ifindex; | ||
| 1525 | rtmsg.rtmsg_flags = RTF_UP; | ||
| 1526 | rtmsg.rtmsg_type = RTMSG_NEWROUTE; | ||
| 1527 | ip6_route_add(&rtmsg, NULL, NULL, NULL); | ||
| 1528 | } | 1570 | } |
| 1529 | 1571 | ||
| 1530 | static void sit_route_add(struct net_device *dev) | 1572 | static void sit_route_add(struct net_device *dev) |
| 1531 | { | 1573 | { |
| 1532 | struct in6_rtmsg rtmsg; | 1574 | struct fib6_config cfg = { |
| 1533 | 1575 | .fc_table = RT6_TABLE_MAIN, | |
| 1534 | memset(&rtmsg, 0, sizeof(rtmsg)); | 1576 | .fc_metric = IP6_RT_PRIO_ADDRCONF, |
| 1535 | 1577 | .fc_ifindex = dev->ifindex, | |
| 1536 | rtmsg.rtmsg_type = RTMSG_NEWROUTE; | 1578 | .fc_dst_len = 96, |
| 1537 | rtmsg.rtmsg_metric = IP6_RT_PRIO_ADDRCONF; | 1579 | .fc_flags = RTF_UP | RTF_NONEXTHOP, |
| 1580 | }; | ||
| 1538 | 1581 | ||
| 1539 | /* prefix length - 96 bits "::d.d.d.d" */ | 1582 | /* prefix length - 96 bits "::d.d.d.d" */ |
| 1540 | rtmsg.rtmsg_dst_len = 96; | 1583 | ip6_route_add(&cfg); |
| 1541 | rtmsg.rtmsg_flags = RTF_UP|RTF_NONEXTHOP; | ||
| 1542 | rtmsg.rtmsg_ifindex = dev->ifindex; | ||
| 1543 | |||
| 1544 | ip6_route_add(&rtmsg, NULL, NULL, NULL); | ||
| 1545 | } | 1584 | } |
| 1546 | 1585 | ||
| 1547 | static void addrconf_add_lroute(struct net_device *dev) | 1586 | static void addrconf_add_lroute(struct net_device *dev) |
| @@ -1642,7 +1681,7 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len) | |||
| 1642 | if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) { | 1681 | if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) { |
| 1643 | if (rt->rt6i_flags&RTF_EXPIRES) { | 1682 | if (rt->rt6i_flags&RTF_EXPIRES) { |
| 1644 | if (valid_lft == 0) { | 1683 | if (valid_lft == 0) { |
| 1645 | ip6_del_rt(rt, NULL, NULL, NULL); | 1684 | ip6_del_rt(rt); |
| 1646 | rt = NULL; | 1685 | rt = NULL; |
| 1647 | } else { | 1686 | } else { |
| 1648 | rt->rt6i_expires = jiffies + rt_expires; | 1687 | rt->rt6i_expires = jiffies + rt_expires; |
| @@ -1851,7 +1890,8 @@ err_exit: | |||
| 1851 | /* | 1890 | /* |
| 1852 | * Manual configuration of address on an interface | 1891 | * Manual configuration of address on an interface |
| 1853 | */ | 1892 | */ |
| 1854 | static int inet6_addr_add(int ifindex, struct in6_addr *pfx, int plen) | 1893 | static int inet6_addr_add(int ifindex, struct in6_addr *pfx, int plen, |
| 1894 | __u8 ifa_flags, __u32 prefered_lft, __u32 valid_lft) | ||
| 1855 | { | 1895 | { |
| 1856 | struct inet6_ifaddr *ifp; | 1896 | struct inet6_ifaddr *ifp; |
| 1857 | struct inet6_dev *idev; | 1897 | struct inet6_dev *idev; |
| @@ -1860,21 +1900,41 @@ static int inet6_addr_add(int ifindex, struct in6_addr *pfx, int plen) | |||
| 1860 | 1900 | ||
| 1861 | ASSERT_RTNL(); | 1901 | ASSERT_RTNL(); |
| 1862 | 1902 | ||
| 1903 | /* check the lifetime */ | ||
| 1904 | if (!valid_lft || prefered_lft > valid_lft) | ||
| 1905 | return -EINVAL; | ||
| 1906 | |||
| 1863 | if ((dev = __dev_get_by_index(ifindex)) == NULL) | 1907 | if ((dev = __dev_get_by_index(ifindex)) == NULL) |
| 1864 | return -ENODEV; | 1908 | return -ENODEV; |
| 1865 | 1909 | ||
| 1866 | if (!(dev->flags&IFF_UP)) | ||
| 1867 | return -ENETDOWN; | ||
| 1868 | |||
| 1869 | if ((idev = addrconf_add_dev(dev)) == NULL) | 1910 | if ((idev = addrconf_add_dev(dev)) == NULL) |
| 1870 | return -ENOBUFS; | 1911 | return -ENOBUFS; |
| 1871 | 1912 | ||
| 1872 | scope = ipv6_addr_scope(pfx); | 1913 | scope = ipv6_addr_scope(pfx); |
| 1873 | 1914 | ||
| 1874 | ifp = ipv6_add_addr(idev, pfx, plen, scope, IFA_F_PERMANENT); | 1915 | if (valid_lft == INFINITY_LIFE_TIME) |
| 1916 | ifa_flags |= IFA_F_PERMANENT; | ||
| 1917 | else if (valid_lft >= 0x7FFFFFFF/HZ) | ||
| 1918 | valid_lft = 0x7FFFFFFF/HZ; | ||
| 1919 | |||
| 1920 | if (prefered_lft == 0) | ||
| 1921 | ifa_flags |= IFA_F_DEPRECATED; | ||
| 1922 | else if ((prefered_lft >= 0x7FFFFFFF/HZ) && | ||
| 1923 | (prefered_lft != INFINITY_LIFE_TIME)) | ||
| 1924 | prefered_lft = 0x7FFFFFFF/HZ; | ||
| 1925 | |||
| 1926 | ifp = ipv6_add_addr(idev, pfx, plen, scope, ifa_flags); | ||
| 1927 | |||
| 1875 | if (!IS_ERR(ifp)) { | 1928 | if (!IS_ERR(ifp)) { |
| 1929 | spin_lock_bh(&ifp->lock); | ||
| 1930 | ifp->valid_lft = valid_lft; | ||
| 1931 | ifp->prefered_lft = prefered_lft; | ||
| 1932 | ifp->tstamp = jiffies; | ||
| 1933 | spin_unlock_bh(&ifp->lock); | ||
| 1934 | |||
| 1876 | addrconf_dad_start(ifp, 0); | 1935 | addrconf_dad_start(ifp, 0); |
| 1877 | in6_ifa_put(ifp); | 1936 | in6_ifa_put(ifp); |
| 1937 | addrconf_verify(0); | ||
| 1878 | return 0; | 1938 | return 0; |
| 1879 | } | 1939 | } |
| 1880 | 1940 | ||
| @@ -1927,7 +1987,8 @@ int addrconf_add_ifaddr(void __user *arg) | |||
| 1927 | return -EFAULT; | 1987 | return -EFAULT; |
| 1928 | 1988 | ||
| 1929 | rtnl_lock(); | 1989 | rtnl_lock(); |
| 1930 | 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, |
| 1991 | IFA_F_PERMANENT, INFINITY_LIFE_TIME, INFINITY_LIFE_TIME); | ||
| 1931 | rtnl_unlock(); | 1992 | rtnl_unlock(); |
| 1932 | return err; | 1993 | return err; |
| 1933 | } | 1994 | } |
| @@ -2300,10 +2361,10 @@ static int addrconf_ifdown(struct net_device *dev, int how) | |||
| 2300 | Do not dev_put! | 2361 | Do not dev_put! |
| 2301 | */ | 2362 | */ |
| 2302 | if (how == 1) { | 2363 | if (how == 1) { |
| 2303 | write_lock_bh(&addrconf_lock); | ||
| 2304 | dev->ip6_ptr = NULL; | ||
| 2305 | idev->dead = 1; | 2364 | idev->dead = 1; |
| 2306 | write_unlock_bh(&addrconf_lock); | 2365 | |
| 2366 | /* protected by rtnl_lock */ | ||
| 2367 | rcu_assign_pointer(dev->ip6_ptr, NULL); | ||
| 2307 | 2368 | ||
| 2308 | /* Step 1.5: remove snmp6 entry */ | 2369 | /* Step 1.5: remove snmp6 entry */ |
| 2309 | snmp6_unregister_dev(idev); | 2370 | snmp6_unregister_dev(idev); |
| @@ -2470,7 +2531,8 @@ static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags) | |||
| 2470 | spin_lock_bh(&ifp->lock); | 2531 | spin_lock_bh(&ifp->lock); |
| 2471 | 2532 | ||
| 2472 | if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) || | 2533 | if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) || |
| 2473 | !(ifp->flags&IFA_F_TENTATIVE)) { | 2534 | !(ifp->flags&IFA_F_TENTATIVE) || |
| 2535 | ifp->flags & IFA_F_NODAD) { | ||
| 2474 | ifp->flags &= ~IFA_F_TENTATIVE; | 2536 | ifp->flags &= ~IFA_F_TENTATIVE; |
| 2475 | spin_unlock_bh(&ifp->lock); | 2537 | spin_unlock_bh(&ifp->lock); |
| 2476 | read_unlock_bh(&idev->lock); | 2538 | read_unlock_bh(&idev->lock); |
| @@ -2715,6 +2777,26 @@ void if6_proc_exit(void) | |||
| 2715 | } | 2777 | } |
| 2716 | #endif /* CONFIG_PROC_FS */ | 2778 | #endif /* CONFIG_PROC_FS */ |
| 2717 | 2779 | ||
| 2780 | #ifdef CONFIG_IPV6_MIP6 | ||
| 2781 | /* Check if address is a home address configured on any interface. */ | ||
| 2782 | int 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 | |||
| 2718 | /* | 2800 | /* |
| 2719 | * Periodic address status verification | 2801 | * Periodic address status verification |
| 2720 | */ | 2802 | */ |
| @@ -2753,12 +2835,16 @@ restart: | |||
| 2753 | ifp->idev->nd_parms->retrans_time / HZ; | 2835 | ifp->idev->nd_parms->retrans_time / HZ; |
| 2754 | #endif | 2836 | #endif |
| 2755 | 2837 | ||
| 2756 | if (age >= ifp->valid_lft) { | 2838 | if (ifp->valid_lft != INFINITY_LIFE_TIME && |
| 2839 | age >= ifp->valid_lft) { | ||
| 2757 | spin_unlock(&ifp->lock); | 2840 | spin_unlock(&ifp->lock); |
| 2758 | in6_ifa_hold(ifp); | 2841 | in6_ifa_hold(ifp); |
| 2759 | read_unlock(&addrconf_hash_lock); | 2842 | read_unlock(&addrconf_hash_lock); |
| 2760 | ipv6_del_addr(ifp); | 2843 | ipv6_del_addr(ifp); |
| 2761 | goto restart; | 2844 | goto restart; |
| 2845 | } else if (ifp->prefered_lft == INFINITY_LIFE_TIME) { | ||
| 2846 | spin_unlock(&ifp->lock); | ||
| 2847 | continue; | ||
| 2762 | } else if (age >= ifp->prefered_lft) { | 2848 | } else if (age >= ifp->prefered_lft) { |
| 2763 | /* jiffies - ifp->tsamp > age >= ifp->prefered_lft */ | 2849 | /* jiffies - ifp->tsamp > age >= ifp->prefered_lft */ |
| 2764 | int deprecate = 0; | 2850 | int deprecate = 0; |
| @@ -2821,178 +2907,267 @@ restart: | |||
| 2821 | spin_unlock_bh(&addrconf_verify_lock); | 2907 | spin_unlock_bh(&addrconf_verify_lock); |
| 2822 | } | 2908 | } |
| 2823 | 2909 | ||
| 2910 | static 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 | |||
| 2927 | static 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 | |||
| 2824 | static int | 2933 | static int |
| 2825 | inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) | 2934 | inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) |
| 2826 | { | 2935 | { |
| 2827 | struct rtattr **rta = arg; | 2936 | struct ifaddrmsg *ifm; |
| 2828 | struct ifaddrmsg *ifm = NLMSG_DATA(nlh); | 2937 | struct nlattr *tb[IFA_MAX+1]; |
| 2829 | struct in6_addr *pfx; | 2938 | struct in6_addr *pfx; |
| 2939 | int err; | ||
| 2830 | 2940 | ||
| 2831 | pfx = NULL; | 2941 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); |
| 2832 | if (rta[IFA_ADDRESS-1]) { | 2942 | if (err < 0) |
| 2833 | if (RTA_PAYLOAD(rta[IFA_ADDRESS-1]) < sizeof(*pfx)) | 2943 | return err; |
| 2834 | return -EINVAL; | 2944 | |
| 2835 | pfx = RTA_DATA(rta[IFA_ADDRESS-1]); | 2945 | ifm = nlmsg_data(nlh); |
| 2836 | } | 2946 | pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]); |
| 2837 | if (rta[IFA_LOCAL-1]) { | ||
| 2838 | if (pfx && memcmp(pfx, RTA_DATA(rta[IFA_LOCAL-1]), sizeof(*pfx))) | ||
| 2839 | return -EINVAL; | ||
| 2840 | pfx = RTA_DATA(rta[IFA_LOCAL-1]); | ||
| 2841 | } | ||
| 2842 | if (pfx == NULL) | 2947 | if (pfx == NULL) |
| 2843 | return -EINVAL; | 2948 | return -EINVAL; |
| 2844 | 2949 | ||
| 2845 | return inet6_addr_del(ifm->ifa_index, pfx, ifm->ifa_prefixlen); | 2950 | return inet6_addr_del(ifm->ifa_index, pfx, ifm->ifa_prefixlen); |
| 2846 | } | 2951 | } |
| 2847 | 2952 | ||
| 2953 | static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags, | ||
| 2954 | u32 prefered_lft, u32 valid_lft) | ||
| 2955 | { | ||
| 2956 | if (!valid_lft || (prefered_lft > valid_lft)) | ||
| 2957 | return -EINVAL; | ||
| 2958 | |||
| 2959 | if (valid_lft == INFINITY_LIFE_TIME) | ||
| 2960 | ifa_flags |= IFA_F_PERMANENT; | ||
| 2961 | else if (valid_lft >= 0x7FFFFFFF/HZ) | ||
| 2962 | valid_lft = 0x7FFFFFFF/HZ; | ||
| 2963 | |||
| 2964 | if (prefered_lft == 0) | ||
| 2965 | ifa_flags |= IFA_F_DEPRECATED; | ||
| 2966 | else if ((prefered_lft >= 0x7FFFFFFF/HZ) && | ||
| 2967 | (prefered_lft != INFINITY_LIFE_TIME)) | ||
| 2968 | prefered_lft = 0x7FFFFFFF/HZ; | ||
| 2969 | |||
| 2970 | spin_lock_bh(&ifp->lock); | ||
| 2971 | ifp->flags = (ifp->flags & ~(IFA_F_DEPRECATED | IFA_F_PERMANENT | IFA_F_NODAD | IFA_F_HOMEADDRESS)) | ifa_flags; | ||
| 2972 | ifp->tstamp = jiffies; | ||
| 2973 | ifp->valid_lft = valid_lft; | ||
| 2974 | ifp->prefered_lft = prefered_lft; | ||
| 2975 | |||
| 2976 | spin_unlock_bh(&ifp->lock); | ||
| 2977 | if (!(ifp->flags&IFA_F_TENTATIVE)) | ||
| 2978 | ipv6_ifa_notify(0, ifp); | ||
| 2979 | |||
| 2980 | addrconf_verify(0); | ||
| 2981 | |||
| 2982 | return 0; | ||
| 2983 | } | ||
| 2984 | |||
| 2848 | static int | 2985 | static int |
| 2849 | inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) | 2986 | inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) |
| 2850 | { | 2987 | { |
| 2851 | struct rtattr **rta = arg; | 2988 | struct ifaddrmsg *ifm; |
| 2852 | struct ifaddrmsg *ifm = NLMSG_DATA(nlh); | 2989 | struct nlattr *tb[IFA_MAX+1]; |
| 2853 | struct in6_addr *pfx; | 2990 | struct in6_addr *pfx; |
| 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; | ||
| 2854 | 2996 | ||
| 2855 | pfx = NULL; | 2997 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); |
| 2856 | if (rta[IFA_ADDRESS-1]) { | 2998 | if (err < 0) |
| 2857 | if (RTA_PAYLOAD(rta[IFA_ADDRESS-1]) < sizeof(*pfx)) | 2999 | return err; |
| 2858 | return -EINVAL; | 3000 | |
| 2859 | pfx = RTA_DATA(rta[IFA_ADDRESS-1]); | 3001 | ifm = nlmsg_data(nlh); |
| 2860 | } | 3002 | pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]); |
| 2861 | if (rta[IFA_LOCAL-1]) { | ||
| 2862 | if (pfx && memcmp(pfx, RTA_DATA(rta[IFA_LOCAL-1]), sizeof(*pfx))) | ||
| 2863 | return -EINVAL; | ||
| 2864 | pfx = RTA_DATA(rta[IFA_LOCAL-1]); | ||
| 2865 | } | ||
| 2866 | if (pfx == NULL) | 3003 | if (pfx == NULL) |
| 2867 | return -EINVAL; | 3004 | return -EINVAL; |
| 2868 | 3005 | ||
| 2869 | return inet6_addr_add(ifm->ifa_index, pfx, ifm->ifa_prefixlen); | 3006 | if (tb[IFA_CACHEINFO]) { |
| 3007 | struct ifa_cacheinfo *ci; | ||
| 3008 | |||
| 3009 | ci = nla_data(tb[IFA_CACHEINFO]); | ||
| 3010 | valid_lft = ci->ifa_valid; | ||
| 3011 | preferred_lft = ci->ifa_prefered; | ||
| 3012 | } else { | ||
| 3013 | preferred_lft = INFINITY_LIFE_TIME; | ||
| 3014 | valid_lft = INFINITY_LIFE_TIME; | ||
| 3015 | } | ||
| 3016 | |||
| 3017 | dev = __dev_get_by_index(ifm->ifa_index); | ||
| 3018 | if (dev == NULL) | ||
| 3019 | return -ENODEV; | ||
| 3020 | |||
| 3021 | /* We ignore other flags so far. */ | ||
| 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); | ||
| 3032 | } | ||
| 3033 | |||
| 3034 | if (nlh->nlmsg_flags & NLM_F_EXCL || | ||
| 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 | |||
| 3045 | static void put_ifaddrmsg(struct nlmsghdr *nlh, u8 prefixlen, u8 flags, | ||
| 3046 | u8 scope, int ifindex) | ||
| 3047 | { | ||
| 3048 | struct ifaddrmsg *ifm; | ||
| 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; | ||
| 3056 | } | ||
| 3057 | |||
| 3058 | static int put_cacheinfo(struct sk_buff *skb, unsigned long cstamp, | ||
| 3059 | unsigned long tstamp, u32 preferred, u32 valid) | ||
| 3060 | { | ||
| 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); | ||
| 2870 | } | 3071 | } |
| 2871 | 3072 | ||
| 2872 | /* Maximum length of ifa_cacheinfo attributes */ | 3073 | static inline int rt_scope(int ifa_scope) |
| 2873 | #define INET6_IFADDR_RTA_SPACE \ | 3074 | { |
| 2874 | RTA_SPACE(16) /* IFA_ADDRESS */ + \ | 3075 | if (ifa_scope & IFA_HOST) |
| 2875 | RTA_SPACE(sizeof(struct ifa_cacheinfo)) /* CACHEINFO */ | 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 | |||
| 3085 | static 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 | } | ||
| 2876 | 3092 | ||
| 2877 | static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa, | 3093 | static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa, |
| 2878 | u32 pid, u32 seq, int event, unsigned int flags) | 3094 | u32 pid, u32 seq, int event, unsigned int flags) |
| 2879 | { | 3095 | { |
| 2880 | struct ifaddrmsg *ifm; | ||
| 2881 | struct nlmsghdr *nlh; | 3096 | struct nlmsghdr *nlh; |
| 2882 | struct ifa_cacheinfo ci; | 3097 | u32 preferred, valid; |
| 2883 | 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); | ||
| 2884 | 3105 | ||
| 2885 | nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*ifm), flags); | ||
| 2886 | ifm = NLMSG_DATA(nlh); | ||
| 2887 | ifm->ifa_family = AF_INET6; | ||
| 2888 | ifm->ifa_prefixlen = ifa->prefix_len; | ||
| 2889 | ifm->ifa_flags = ifa->flags; | ||
| 2890 | ifm->ifa_scope = RT_SCOPE_UNIVERSE; | ||
| 2891 | if (ifa->scope&IFA_HOST) | ||
| 2892 | ifm->ifa_scope = RT_SCOPE_HOST; | ||
| 2893 | else if (ifa->scope&IFA_LINK) | ||
| 2894 | ifm->ifa_scope = RT_SCOPE_LINK; | ||
| 2895 | else if (ifa->scope&IFA_SITE) | ||
| 2896 | ifm->ifa_scope = RT_SCOPE_SITE; | ||
| 2897 | ifm->ifa_index = ifa->idev->dev->ifindex; | ||
| 2898 | RTA_PUT(skb, IFA_ADDRESS, 16, &ifa->addr); | ||
| 2899 | if (!(ifa->flags&IFA_F_PERMANENT)) { | 3106 | if (!(ifa->flags&IFA_F_PERMANENT)) { |
| 2900 | ci.ifa_prefered = ifa->prefered_lft; | 3107 | preferred = ifa->prefered_lft; |
| 2901 | ci.ifa_valid = ifa->valid_lft; | 3108 | valid = ifa->valid_lft; |
| 2902 | if (ci.ifa_prefered != INFINITY_LIFE_TIME) { | 3109 | if (preferred != INFINITY_LIFE_TIME) { |
| 2903 | long tval = (jiffies - ifa->tstamp)/HZ; | 3110 | long tval = (jiffies - ifa->tstamp)/HZ; |
| 2904 | ci.ifa_prefered -= tval; | 3111 | preferred -= tval; |
| 2905 | if (ci.ifa_valid != INFINITY_LIFE_TIME) | 3112 | if (valid != INFINITY_LIFE_TIME) |
| 2906 | ci.ifa_valid -= tval; | 3113 | valid -= tval; |
| 2907 | } | 3114 | } |
| 2908 | } else { | 3115 | } else { |
| 2909 | ci.ifa_prefered = INFINITY_LIFE_TIME; | 3116 | preferred = INFINITY_LIFE_TIME; |
| 2910 | ci.ifa_valid = INFINITY_LIFE_TIME; | 3117 | valid = INFINITY_LIFE_TIME; |
| 2911 | } | 3118 | } |
| 2912 | ci.cstamp = (__u32)(TIME_DELTA(ifa->cstamp, INITIAL_JIFFIES) / HZ * 100 | ||
| 2913 | + TIME_DELTA(ifa->cstamp, INITIAL_JIFFIES) % HZ * 100 / HZ); | ||
| 2914 | ci.tstamp = (__u32)(TIME_DELTA(ifa->tstamp, INITIAL_JIFFIES) / HZ * 100 | ||
| 2915 | + TIME_DELTA(ifa->tstamp, INITIAL_JIFFIES) % HZ * 100 / HZ); | ||
| 2916 | RTA_PUT(skb, IFA_CACHEINFO, sizeof(ci), &ci); | ||
| 2917 | nlh->nlmsg_len = skb->tail - b; | ||
| 2918 | return skb->len; | ||
| 2919 | 3119 | ||
| 2920 | nlmsg_failure: | 3120 | if (nla_put(skb, IFA_ADDRESS, 16, &ifa->addr) < 0 || |
| 2921 | rtattr_failure: | 3121 | put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0) |
| 2922 | skb_trim(skb, b - skb->data); | 3122 | return nlmsg_cancel(skb, nlh); |
| 2923 | return -1; | 3123 | |
| 3124 | return nlmsg_end(skb, nlh); | ||
| 2924 | } | 3125 | } |
| 2925 | 3126 | ||
| 2926 | static int inet6_fill_ifmcaddr(struct sk_buff *skb, struct ifmcaddr6 *ifmca, | 3127 | static int inet6_fill_ifmcaddr(struct sk_buff *skb, struct ifmcaddr6 *ifmca, |
| 2927 | u32 pid, u32 seq, int event, u16 flags) | 3128 | u32 pid, u32 seq, int event, u16 flags) |
| 2928 | { | 3129 | { |
| 2929 | struct ifaddrmsg *ifm; | ||
| 2930 | struct nlmsghdr *nlh; | 3130 | struct nlmsghdr *nlh; |
| 2931 | struct ifa_cacheinfo ci; | 3131 | u8 scope = RT_SCOPE_UNIVERSE; |
| 2932 | unsigned char *b = skb->tail; | 3132 | int ifindex = ifmca->idev->dev->ifindex; |
| 2933 | |||
| 2934 | nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*ifm), flags); | ||
| 2935 | ifm = NLMSG_DATA(nlh); | ||
| 2936 | ifm->ifa_family = AF_INET6; | ||
| 2937 | ifm->ifa_prefixlen = 128; | ||
| 2938 | ifm->ifa_flags = IFA_F_PERMANENT; | ||
| 2939 | ifm->ifa_scope = RT_SCOPE_UNIVERSE; | ||
| 2940 | if (ipv6_addr_scope(&ifmca->mca_addr)&IFA_SITE) | ||
| 2941 | ifm->ifa_scope = RT_SCOPE_SITE; | ||
| 2942 | ifm->ifa_index = ifmca->idev->dev->ifindex; | ||
| 2943 | RTA_PUT(skb, IFA_MULTICAST, 16, &ifmca->mca_addr); | ||
| 2944 | ci.cstamp = (__u32)(TIME_DELTA(ifmca->mca_cstamp, INITIAL_JIFFIES) / HZ | ||
| 2945 | * 100 + TIME_DELTA(ifmca->mca_cstamp, INITIAL_JIFFIES) % HZ | ||
| 2946 | * 100 / HZ); | ||
| 2947 | ci.tstamp = (__u32)(TIME_DELTA(ifmca->mca_tstamp, INITIAL_JIFFIES) / HZ | ||
| 2948 | * 100 + TIME_DELTA(ifmca->mca_tstamp, INITIAL_JIFFIES) % HZ | ||
| 2949 | * 100 / HZ); | ||
| 2950 | ci.ifa_prefered = INFINITY_LIFE_TIME; | ||
| 2951 | ci.ifa_valid = INFINITY_LIFE_TIME; | ||
| 2952 | RTA_PUT(skb, IFA_CACHEINFO, sizeof(ci), &ci); | ||
| 2953 | nlh->nlmsg_len = skb->tail - b; | ||
| 2954 | return skb->len; | ||
| 2955 | 3133 | ||
| 2956 | nlmsg_failure: | 3134 | if (ipv6_addr_scope(&ifmca->mca_addr) & IFA_SITE) |
| 2957 | rtattr_failure: | 3135 | scope = RT_SCOPE_SITE; |
| 2958 | skb_trim(skb, b - skb->data); | 3136 | |
| 2959 | 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); | ||
| 2960 | } | 3148 | } |
| 2961 | 3149 | ||
| 2962 | static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca, | 3150 | static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca, |
| 2963 | u32 pid, u32 seq, int event, unsigned int flags) | 3151 | u32 pid, u32 seq, int event, unsigned int flags) |
| 2964 | { | 3152 | { |
| 2965 | struct ifaddrmsg *ifm; | ||
| 2966 | struct nlmsghdr *nlh; | 3153 | struct nlmsghdr *nlh; |
| 2967 | struct ifa_cacheinfo ci; | 3154 | u8 scope = RT_SCOPE_UNIVERSE; |
| 2968 | unsigned char *b = skb->tail; | 3155 | int ifindex = ifaca->aca_idev->dev->ifindex; |
| 2969 | |||
| 2970 | nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*ifm), flags); | ||
| 2971 | ifm = NLMSG_DATA(nlh); | ||
| 2972 | ifm->ifa_family = AF_INET6; | ||
| 2973 | ifm->ifa_prefixlen = 128; | ||
| 2974 | ifm->ifa_flags = IFA_F_PERMANENT; | ||
| 2975 | ifm->ifa_scope = RT_SCOPE_UNIVERSE; | ||
| 2976 | if (ipv6_addr_scope(&ifaca->aca_addr)&IFA_SITE) | ||
| 2977 | ifm->ifa_scope = RT_SCOPE_SITE; | ||
| 2978 | ifm->ifa_index = ifaca->aca_idev->dev->ifindex; | ||
| 2979 | RTA_PUT(skb, IFA_ANYCAST, 16, &ifaca->aca_addr); | ||
| 2980 | ci.cstamp = (__u32)(TIME_DELTA(ifaca->aca_cstamp, INITIAL_JIFFIES) / HZ | ||
| 2981 | * 100 + TIME_DELTA(ifaca->aca_cstamp, INITIAL_JIFFIES) % HZ | ||
| 2982 | * 100 / HZ); | ||
| 2983 | ci.tstamp = (__u32)(TIME_DELTA(ifaca->aca_tstamp, INITIAL_JIFFIES) / HZ | ||
| 2984 | * 100 + TIME_DELTA(ifaca->aca_tstamp, INITIAL_JIFFIES) % HZ | ||
| 2985 | * 100 / HZ); | ||
| 2986 | ci.ifa_prefered = INFINITY_LIFE_TIME; | ||
| 2987 | ci.ifa_valid = INFINITY_LIFE_TIME; | ||
| 2988 | RTA_PUT(skb, IFA_CACHEINFO, sizeof(ci), &ci); | ||
| 2989 | nlh->nlmsg_len = skb->tail - b; | ||
| 2990 | return skb->len; | ||
| 2991 | 3156 | ||
| 2992 | nlmsg_failure: | 3157 | if (ipv6_addr_scope(&ifaca->aca_addr) & IFA_SITE) |
| 2993 | rtattr_failure: | 3158 | scope = RT_SCOPE_SITE; |
| 2994 | skb_trim(skb, b - skb->data); | 3159 | |
| 2995 | 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); | ||
| 2996 | } | 3171 | } |
| 2997 | 3172 | ||
| 2998 | enum addr_type_t | 3173 | enum addr_type_t |
| @@ -3103,23 +3278,74 @@ static int inet6_dump_ifacaddr(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 3103 | return inet6_dump_addr(skb, cb, type); | 3278 | return inet6_dump_addr(skb, cb, type); |
| 3104 | } | 3279 | } |
| 3105 | 3280 | ||
| 3106 | static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa) | 3281 | static int inet6_rtm_getaddr(struct sk_buff *in_skb, struct nlmsghdr* nlh, |
| 3282 | void *arg) | ||
| 3107 | { | 3283 | { |
| 3284 | struct ifaddrmsg *ifm; | ||
| 3285 | struct nlattr *tb[IFA_MAX+1]; | ||
| 3286 | struct in6_addr *addr = NULL; | ||
| 3287 | struct net_device *dev = NULL; | ||
| 3288 | struct inet6_ifaddr *ifa; | ||
| 3108 | struct sk_buff *skb; | 3289 | struct sk_buff *skb; |
| 3109 | int size = NLMSG_SPACE(sizeof(struct ifaddrmsg) + INET6_IFADDR_RTA_SPACE); | 3290 | int err; |
| 3110 | 3291 | ||
| 3111 | skb = alloc_skb(size, GFP_ATOMIC); | 3292 | err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); |
| 3112 | if (!skb) { | 3293 | if (err < 0) |
| 3113 | netlink_set_err(rtnl, 0, RTNLGRP_IPV6_IFADDR, ENOBUFS); | 3294 | goto errout; |
| 3114 | return; | 3295 | |
| 3296 | addr = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]); | ||
| 3297 | if (addr == NULL) { | ||
| 3298 | err = -EINVAL; | ||
| 3299 | goto errout; | ||
| 3300 | } | ||
| 3301 | |||
| 3302 | ifm = nlmsg_data(nlh); | ||
| 3303 | if (ifm->ifa_index) | ||
| 3304 | dev = __dev_get_by_index(ifm->ifa_index); | ||
| 3305 | |||
| 3306 | if ((ifa = ipv6_get_ifaddr(addr, dev, 1)) == NULL) { | ||
| 3307 | err = -EADDRNOTAVAIL; | ||
| 3308 | goto errout; | ||
| 3115 | } | 3309 | } |
| 3116 | if (inet6_fill_ifaddr(skb, ifa, current->pid, 0, event, 0) < 0) { | 3310 | |
| 3311 | if ((skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_KERNEL)) == NULL) { | ||
| 3312 | err = -ENOBUFS; | ||
| 3313 | goto errout_ifa; | ||
| 3314 | } | ||
| 3315 | |||
| 3316 | err = inet6_fill_ifaddr(skb, ifa, NETLINK_CB(in_skb).pid, | ||
| 3317 | nlh->nlmsg_seq, RTM_NEWADDR, 0); | ||
| 3318 | if (err < 0) { | ||
| 3117 | kfree_skb(skb); | 3319 | kfree_skb(skb); |
| 3118 | netlink_set_err(rtnl, 0, RTNLGRP_IPV6_IFADDR, EINVAL); | 3320 | goto errout_ifa; |
| 3119 | return; | 3321 | } |
| 3322 | |||
| 3323 | err = rtnl_unicast(skb, NETLINK_CB(in_skb).pid); | ||
| 3324 | errout_ifa: | ||
| 3325 | in6_ifa_put(ifa); | ||
| 3326 | errout: | ||
| 3327 | return err; | ||
| 3328 | } | ||
| 3329 | |||
| 3330 | static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa) | ||
| 3331 | { | ||
| 3332 | struct sk_buff *skb; | ||
| 3333 | int err = -ENOBUFS; | ||
| 3334 | |||
| 3335 | skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_ATOMIC); | ||
| 3336 | if (skb == NULL) | ||
| 3337 | goto errout; | ||
| 3338 | |||
| 3339 | err = inet6_fill_ifaddr(skb, ifa, 0, 0, event, 0); | ||
| 3340 | if (err < 0) { | ||
| 3341 | kfree_skb(skb); | ||
| 3342 | goto errout; | ||
| 3120 | } | 3343 | } |
| 3121 | NETLINK_CB(skb).dst_group = RTNLGRP_IPV6_IFADDR; | 3344 | |
| 3122 | netlink_broadcast(rtnl, skb, 0, RTNLGRP_IPV6_IFADDR, GFP_ATOMIC); | 3345 | err = rtnl_notify(skb, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC); |
| 3346 | errout: | ||
| 3347 | if (err < 0) | ||
| 3348 | rtnl_set_sk_err(RTNLGRP_IPV6_IFADDR, err); | ||
| 3123 | } | 3349 | } |
| 3124 | 3350 | ||
| 3125 | static void inline ipv6_store_devconf(struct ipv6_devconf *cnf, | 3351 | static void inline ipv6_store_devconf(struct ipv6_devconf *cnf, |
| @@ -3154,6 +3380,7 @@ static void inline ipv6_store_devconf(struct ipv6_devconf *cnf, | |||
| 3154 | 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; |
| 3155 | #endif | 3381 | #endif |
| 3156 | #endif | 3382 | #endif |
| 3383 | array[DEVCONF_PROXY_NDP] = cnf->proxy_ndp; | ||
| 3157 | } | 3384 | } |
| 3158 | 3385 | ||
| 3159 | /* Maximum length of ifinfomsg attributes */ | 3386 | /* Maximum length of ifinfomsg attributes */ |
| @@ -3260,20 +3487,23 @@ static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) | |||
| 3260 | void inet6_ifinfo_notify(int event, struct inet6_dev *idev) | 3487 | void inet6_ifinfo_notify(int event, struct inet6_dev *idev) |
| 3261 | { | 3488 | { |
| 3262 | struct sk_buff *skb; | 3489 | struct sk_buff *skb; |
| 3263 | 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; | ||
| 3264 | 3492 | ||
| 3265 | skb = alloc_skb(size, GFP_ATOMIC); | 3493 | skb = nlmsg_new(nlmsg_total_size(payload), GFP_ATOMIC); |
| 3266 | if (!skb) { | 3494 | if (skb == NULL) |
| 3267 | netlink_set_err(rtnl, 0, RTNLGRP_IPV6_IFINFO, ENOBUFS); | 3495 | goto errout; |
| 3268 | return; | 3496 | |
| 3269 | } | 3497 | err = inet6_fill_ifinfo(skb, idev, 0, 0, event, 0); |
| 3270 | if (inet6_fill_ifinfo(skb, idev, current->pid, 0, event, 0) < 0) { | 3498 | if (err < 0) { |
| 3271 | kfree_skb(skb); | 3499 | kfree_skb(skb); |
| 3272 | netlink_set_err(rtnl, 0, RTNLGRP_IPV6_IFINFO, EINVAL); | 3500 | goto errout; |
| 3273 | return; | ||
| 3274 | } | 3501 | } |
| 3275 | NETLINK_CB(skb).dst_group = RTNLGRP_IPV6_IFINFO; | 3502 | |
| 3276 | netlink_broadcast(rtnl, skb, 0, RTNLGRP_IPV6_IFINFO, GFP_ATOMIC); | 3503 | err = rtnl_notify(skb, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC); |
| 3504 | errout: | ||
| 3505 | if (err < 0) | ||
| 3506 | rtnl_set_sk_err(RTNLGRP_IPV6_IFADDR, err); | ||
| 3277 | } | 3507 | } |
| 3278 | 3508 | ||
| 3279 | /* Maximum length of prefix_cacheinfo attributes */ | 3509 | /* Maximum length of prefix_cacheinfo attributes */ |
| @@ -3325,33 +3555,40 @@ static void inet6_prefix_notify(int event, struct inet6_dev *idev, | |||
| 3325 | struct prefix_info *pinfo) | 3555 | struct prefix_info *pinfo) |
| 3326 | { | 3556 | { |
| 3327 | struct sk_buff *skb; | 3557 | struct sk_buff *skb; |
| 3328 | 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; | ||
| 3329 | 3560 | ||
| 3330 | skb = alloc_skb(size, GFP_ATOMIC); | 3561 | skb = nlmsg_new(nlmsg_total_size(payload), GFP_ATOMIC); |
| 3331 | if (!skb) { | 3562 | if (skb == NULL) |
| 3332 | netlink_set_err(rtnl, 0, RTNLGRP_IPV6_PREFIX, ENOBUFS); | 3563 | goto errout; |
| 3333 | return; | 3564 | |
| 3334 | } | 3565 | err = inet6_fill_prefix(skb, idev, pinfo, 0, 0, event, 0); |
| 3335 | if (inet6_fill_prefix(skb, idev, pinfo, current->pid, 0, event, 0) < 0) { | 3566 | if (err < 0) { |
| 3336 | kfree_skb(skb); | 3567 | kfree_skb(skb); |
| 3337 | netlink_set_err(rtnl, 0, RTNLGRP_IPV6_PREFIX, EINVAL); | 3568 | goto errout; |
| 3338 | return; | ||
| 3339 | } | 3569 | } |
| 3340 | NETLINK_CB(skb).dst_group = RTNLGRP_IPV6_PREFIX; | 3570 | |
| 3341 | netlink_broadcast(rtnl, skb, 0, RTNLGRP_IPV6_PREFIX, GFP_ATOMIC); | 3571 | err = rtnl_notify(skb, 0, RTNLGRP_IPV6_PREFIX, NULL, GFP_ATOMIC); |
| 3572 | errout: | ||
| 3573 | if (err < 0) | ||
| 3574 | rtnl_set_sk_err(RTNLGRP_IPV6_PREFIX, err); | ||
| 3342 | } | 3575 | } |
| 3343 | 3576 | ||
| 3344 | static struct rtnetlink_link inet6_rtnetlink_table[RTM_NR_MSGTYPES] = { | 3577 | static struct rtnetlink_link inet6_rtnetlink_table[RTM_NR_MSGTYPES] = { |
| 3345 | [RTM_GETLINK - RTM_BASE] = { .dumpit = inet6_dump_ifinfo, }, | 3578 | [RTM_GETLINK - RTM_BASE] = { .dumpit = inet6_dump_ifinfo, }, |
| 3346 | [RTM_NEWADDR - RTM_BASE] = { .doit = inet6_rtm_newaddr, }, | 3579 | [RTM_NEWADDR - RTM_BASE] = { .doit = inet6_rtm_newaddr, }, |
| 3347 | [RTM_DELADDR - RTM_BASE] = { .doit = inet6_rtm_deladdr, }, | 3580 | [RTM_DELADDR - RTM_BASE] = { .doit = inet6_rtm_deladdr, }, |
| 3348 | [RTM_GETADDR - RTM_BASE] = { .dumpit = inet6_dump_ifaddr, }, | 3581 | [RTM_GETADDR - RTM_BASE] = { .doit = inet6_rtm_getaddr, |
| 3582 | .dumpit = inet6_dump_ifaddr, }, | ||
| 3349 | [RTM_GETMULTICAST - RTM_BASE] = { .dumpit = inet6_dump_ifmcaddr, }, | 3583 | [RTM_GETMULTICAST - RTM_BASE] = { .dumpit = inet6_dump_ifmcaddr, }, |
| 3350 | [RTM_GETANYCAST - RTM_BASE] = { .dumpit = inet6_dump_ifacaddr, }, | 3584 | [RTM_GETANYCAST - RTM_BASE] = { .dumpit = inet6_dump_ifacaddr, }, |
| 3351 | [RTM_NEWROUTE - RTM_BASE] = { .doit = inet6_rtm_newroute, }, | 3585 | [RTM_NEWROUTE - RTM_BASE] = { .doit = inet6_rtm_newroute, }, |
| 3352 | [RTM_DELROUTE - RTM_BASE] = { .doit = inet6_rtm_delroute, }, | 3586 | [RTM_DELROUTE - RTM_BASE] = { .doit = inet6_rtm_delroute, }, |
| 3353 | [RTM_GETROUTE - RTM_BASE] = { .doit = inet6_rtm_getroute, | 3587 | [RTM_GETROUTE - RTM_BASE] = { .doit = inet6_rtm_getroute, |
| 3354 | .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 | ||
| 3355 | }; | 3592 | }; |
| 3356 | 3593 | ||
| 3357 | static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) | 3594 | static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) |
| @@ -3360,7 +3597,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) | |||
| 3360 | 3597 | ||
| 3361 | switch (event) { | 3598 | switch (event) { |
| 3362 | case RTM_NEWADDR: | 3599 | case RTM_NEWADDR: |
| 3363 | ip6_ins_rt(ifp->rt, NULL, NULL, NULL); | 3600 | ip6_ins_rt(ifp->rt); |
| 3364 | if (ifp->idev->cnf.forwarding) | 3601 | if (ifp->idev->cnf.forwarding) |
| 3365 | addrconf_join_anycast(ifp); | 3602 | addrconf_join_anycast(ifp); |
| 3366 | break; | 3603 | break; |
| @@ -3369,7 +3606,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) | |||
| 3369 | addrconf_leave_anycast(ifp); | 3606 | addrconf_leave_anycast(ifp); |
| 3370 | addrconf_leave_solict(ifp->idev, &ifp->addr); | 3607 | addrconf_leave_solict(ifp->idev, &ifp->addr); |
| 3371 | dst_hold(&ifp->rt->u.dst); | 3608 | dst_hold(&ifp->rt->u.dst); |
| 3372 | if (ip6_del_rt(ifp->rt, NULL, NULL, NULL)) | 3609 | if (ip6_del_rt(ifp->rt)) |
| 3373 | dst_free(&ifp->rt->u.dst); | 3610 | dst_free(&ifp->rt->u.dst); |
| 3374 | break; | 3611 | break; |
| 3375 | } | 3612 | } |
| @@ -3377,10 +3614,10 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) | |||
| 3377 | 3614 | ||
| 3378 | static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) | 3615 | static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) |
| 3379 | { | 3616 | { |
| 3380 | read_lock_bh(&addrconf_lock); | 3617 | rcu_read_lock_bh(); |
| 3381 | if (likely(ifp->idev->dead == 0)) | 3618 | if (likely(ifp->idev->dead == 0)) |
| 3382 | __ipv6_ifa_notify(event, ifp); | 3619 | __ipv6_ifa_notify(event, ifp); |
| 3383 | read_unlock_bh(&addrconf_lock); | 3620 | rcu_read_unlock_bh(); |
| 3384 | } | 3621 | } |
| 3385 | 3622 | ||
| 3386 | #ifdef CONFIG_SYSCTL | 3623 | #ifdef CONFIG_SYSCTL |
| @@ -3477,7 +3714,7 @@ static struct addrconf_sysctl_table | |||
| 3477 | ctl_table addrconf_conf_dir[2]; | 3714 | ctl_table addrconf_conf_dir[2]; |
| 3478 | ctl_table addrconf_proto_dir[2]; | 3715 | ctl_table addrconf_proto_dir[2]; |
| 3479 | ctl_table addrconf_root_dir[2]; | 3716 | ctl_table addrconf_root_dir[2]; |
| 3480 | } addrconf_sysctl = { | 3717 | } addrconf_sysctl __read_mostly = { |
| 3481 | .sysctl_header = NULL, | 3718 | .sysctl_header = NULL, |
| 3482 | .addrconf_vars = { | 3719 | .addrconf_vars = { |
| 3483 | { | 3720 | { |
| @@ -3667,6 +3904,14 @@ static struct addrconf_sysctl_table | |||
| 3667 | #endif | 3904 | #endif |
| 3668 | #endif | 3905 | #endif |
| 3669 | { | 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 | { | ||
| 3670 | .ctl_name = 0, /* sentinel */ | 3915 | .ctl_name = 0, /* sentinel */ |
| 3671 | } | 3916 | } |
| 3672 | }, | 3917 | }, |
