addrconf.c (818a23e3882b1bf65d1719e407be04716e69a4d5) | addrconf.c (1be9246077f6bb1583f9347c599480621d63c66a) |
---|---|
1/* 2 * IPv6 Address [auto]configuration 3 * Linux INET6 implementation 4 * 5 * Authors: 6 * Pedro Roque <roque@di.fc.ul.pt> 7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> 8 * --- 412 unchanged lines hidden (view full) --- 421 if (snmp6_register_dev(ndev) < 0) { 422 ADBG(KERN_WARNING 423 "%s: cannot create /proc/net/dev_snmp6/%s\n", 424 __func__, dev->name); 425 goto err_release; 426 } 427 428 /* One reference from device. */ | 1/* 2 * IPv6 Address [auto]configuration 3 * Linux INET6 implementation 4 * 5 * Authors: 6 * Pedro Roque <roque@di.fc.ul.pt> 7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> 8 * --- 412 unchanged lines hidden (view full) --- 421 if (snmp6_register_dev(ndev) < 0) { 422 ADBG(KERN_WARNING 423 "%s: cannot create /proc/net/dev_snmp6/%s\n", 424 __func__, dev->name); 425 goto err_release; 426 } 427 428 /* One reference from device. */ |
429 in6_dev_hold(ndev); | 429 refcount_set(&ndev->refcnt, 1); |
430 431 if (dev->flags & (IFF_NOARP | IFF_LOOPBACK)) 432 ndev->cnf.accept_dad = -1; 433 434#if IS_ENABLED(CONFIG_IPV6_SIT) 435 if (dev->type == ARPHRD_SIT && (dev->priv_flags & IFF_ISATAP)) { 436 pr_info("%s: Disabled Multicast RS\n", dev->name); 437 ndev->cnf.rtr_solicits = 0; --- 520 unchanged lines hidden (view full) --- 958static struct inet6_ifaddr * 959ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, 960 const struct in6_addr *peer_addr, int pfxlen, 961 int scope, u32 flags, u32 valid_lft, u32 prefered_lft) 962{ 963 struct net *net = dev_net(idev->dev); 964 struct inet6_ifaddr *ifa = NULL; 965 struct rt6_info *rt; | 430 431 if (dev->flags & (IFF_NOARP | IFF_LOOPBACK)) 432 ndev->cnf.accept_dad = -1; 433 434#if IS_ENABLED(CONFIG_IPV6_SIT) 435 if (dev->type == ARPHRD_SIT && (dev->priv_flags & IFF_ISATAP)) { 436 pr_info("%s: Disabled Multicast RS\n", dev->name); 437 ndev->cnf.rtr_solicits = 0; --- 520 unchanged lines hidden (view full) --- 958static struct inet6_ifaddr * 959ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, 960 const struct in6_addr *peer_addr, int pfxlen, 961 int scope, u32 flags, u32 valid_lft, u32 prefered_lft) 962{ 963 struct net *net = dev_net(idev->dev); 964 struct inet6_ifaddr *ifa = NULL; 965 struct rt6_info *rt; |
966 struct in6_validator_info i6vi; |
|
966 unsigned int hash; 967 int err = 0; 968 int addr_type = ipv6_addr_type(addr); 969 970 if (addr_type == IPV6_ADDR_ANY || 971 addr_type & IPV6_ADDR_MULTICAST || 972 (!(idev->dev->flags & IFF_LOOPBACK) && 973 addr_type & IPV6_ADDR_LOOPBACK)) 974 return ERR_PTR(-EADDRNOTAVAIL); 975 976 rcu_read_lock_bh(); | 967 unsigned int hash; 968 int err = 0; 969 int addr_type = ipv6_addr_type(addr); 970 971 if (addr_type == IPV6_ADDR_ANY || 972 addr_type & IPV6_ADDR_MULTICAST || 973 (!(idev->dev->flags & IFF_LOOPBACK) && 974 addr_type & IPV6_ADDR_LOOPBACK)) 975 return ERR_PTR(-EADDRNOTAVAIL); 976 977 rcu_read_lock_bh(); |
978 979 in6_dev_hold(idev); 980 |
|
977 if (idev->dead) { 978 err = -ENODEV; /*XXX*/ 979 goto out2; 980 } 981 982 if (idev->cnf.disable_ipv6) { 983 err = -EACCES; 984 goto out2; 985 } 986 | 981 if (idev->dead) { 982 err = -ENODEV; /*XXX*/ 983 goto out2; 984 } 985 986 if (idev->cnf.disable_ipv6) { 987 err = -EACCES; 988 goto out2; 989 } 990 |
991 i6vi.i6vi_addr = *addr; 992 i6vi.i6vi_dev = idev; 993 rcu_read_unlock_bh(); 994 995 err = inet6addr_validator_notifier_call_chain(NETDEV_UP, &i6vi); 996 997 rcu_read_lock_bh(); 998 err = notifier_to_errno(err); 999 if (err) 1000 goto out2; 1001 |
|
987 spin_lock(&addrconf_hash_lock); 988 989 /* Ignore adding duplicate addresses on an interface */ 990 if (ipv6_chk_same_addr(dev_net(idev->dev), addr, idev->dev)) { 991 ADBG("ipv6_add_addr: already assigned\n"); 992 err = -EEXIST; 993 goto out; 994 } --- 34 unchanged lines hidden (view full) --- 1029 ifa->valid_lft = valid_lft; 1030 ifa->prefered_lft = prefered_lft; 1031 ifa->cstamp = ifa->tstamp = jiffies; 1032 ifa->tokenized = false; 1033 1034 ifa->rt = rt; 1035 1036 ifa->idev = idev; | 1002 spin_lock(&addrconf_hash_lock); 1003 1004 /* Ignore adding duplicate addresses on an interface */ 1005 if (ipv6_chk_same_addr(dev_net(idev->dev), addr, idev->dev)) { 1006 ADBG("ipv6_add_addr: already assigned\n"); 1007 err = -EEXIST; 1008 goto out; 1009 } --- 34 unchanged lines hidden (view full) --- 1044 ifa->valid_lft = valid_lft; 1045 ifa->prefered_lft = prefered_lft; 1046 ifa->cstamp = ifa->tstamp = jiffies; 1047 ifa->tokenized = false; 1048 1049 ifa->rt = rt; 1050 1051 ifa->idev = idev; |
1037 in6_dev_hold(idev); | |
1038 /* For caller */ 1039 in6_ifa_hold(ifa); 1040 1041 /* Add to big hash table */ 1042 hash = inet6_addr_hash(addr); 1043 1044 hlist_add_head_rcu(&ifa->addr_lst, &inet6_addr_lst[hash]); 1045 spin_unlock(&addrconf_hash_lock); --- 11 unchanged lines hidden (view full) --- 1057 write_unlock(&idev->lock); 1058out2: 1059 rcu_read_unlock_bh(); 1060 1061 if (likely(err == 0)) 1062 inet6addr_notifier_call_chain(NETDEV_UP, ifa); 1063 else { 1064 kfree(ifa); | 1052 /* For caller */ 1053 in6_ifa_hold(ifa); 1054 1055 /* Add to big hash table */ 1056 hash = inet6_addr_hash(addr); 1057 1058 hlist_add_head_rcu(&ifa->addr_lst, &inet6_addr_lst[hash]); 1059 spin_unlock(&addrconf_hash_lock); --- 11 unchanged lines hidden (view full) --- 1071 write_unlock(&idev->lock); 1072out2: 1073 rcu_read_unlock_bh(); 1074 1075 if (likely(err == 0)) 1076 inet6addr_notifier_call_chain(NETDEV_UP, ifa); 1077 else { 1078 kfree(ifa); |
1079 in6_dev_put(idev); |
|
1065 ifa = ERR_PTR(err); 1066 } 1067 1068 return ifa; 1069out: 1070 spin_unlock(&addrconf_hash_lock); 1071 goto out2; 1072} --- 834 unchanged lines hidden (view full) --- 1907 1908/* Gets referenced address, destroys ifaddr */ 1909 1910static void addrconf_dad_stop(struct inet6_ifaddr *ifp, int dad_failed) 1911{ 1912 if (dad_failed) 1913 ifp->flags |= IFA_F_DADFAILED; 1914 | 1080 ifa = ERR_PTR(err); 1081 } 1082 1083 return ifa; 1084out: 1085 spin_unlock(&addrconf_hash_lock); 1086 goto out2; 1087} --- 834 unchanged lines hidden (view full) --- 1922 1923/* Gets referenced address, destroys ifaddr */ 1924 1925static void addrconf_dad_stop(struct inet6_ifaddr *ifp, int dad_failed) 1926{ 1927 if (dad_failed) 1928 ifp->flags |= IFA_F_DADFAILED; 1929 |
1915 if (ifp->flags&IFA_F_PERMANENT) { 1916 spin_lock_bh(&ifp->lock); 1917 addrconf_del_dad_work(ifp); 1918 ifp->flags |= IFA_F_TENTATIVE; 1919 spin_unlock_bh(&ifp->lock); 1920 if (dad_failed) 1921 ipv6_ifa_notify(0, ifp); 1922 in6_ifa_put(ifp); 1923 } else if (ifp->flags&IFA_F_TEMPORARY) { | 1930 if (ifp->flags&IFA_F_TEMPORARY) { |
1924 struct inet6_ifaddr *ifpub; 1925 spin_lock_bh(&ifp->lock); 1926 ifpub = ifp->ifpub; 1927 if (ifpub) { 1928 in6_ifa_hold(ifpub); 1929 spin_unlock_bh(&ifp->lock); 1930 ipv6_create_tempaddr(ifpub, ifp); 1931 in6_ifa_put(ifpub); 1932 } else { 1933 spin_unlock_bh(&ifp->lock); 1934 } 1935 ipv6_del_addr(ifp); | 1931 struct inet6_ifaddr *ifpub; 1932 spin_lock_bh(&ifp->lock); 1933 ifpub = ifp->ifpub; 1934 if (ifpub) { 1935 in6_ifa_hold(ifpub); 1936 spin_unlock_bh(&ifp->lock); 1937 ipv6_create_tempaddr(ifpub, ifp); 1938 in6_ifa_put(ifpub); 1939 } else { 1940 spin_unlock_bh(&ifp->lock); 1941 } 1942 ipv6_del_addr(ifp); |
1943 } else if (ifp->flags&IFA_F_PERMANENT || !dad_failed) { 1944 spin_lock_bh(&ifp->lock); 1945 addrconf_del_dad_work(ifp); 1946 ifp->flags |= IFA_F_TENTATIVE; 1947 spin_unlock_bh(&ifp->lock); 1948 if (dad_failed) 1949 ipv6_ifa_notify(0, ifp); 1950 in6_ifa_put(ifp); |
|
1936 } else { 1937 ipv6_del_addr(ifp); 1938 } 1939} 1940 1941static int addrconf_dad_end(struct inet6_ifaddr *ifp) 1942{ 1943 int err = -ENOENT; --- 331 unchanged lines hidden (view full) --- 2275 This thing is done here expecting that the whole 2276 class of non-broadcast devices need not cloning. 2277 */ 2278#if IS_ENABLED(CONFIG_IPV6_SIT) 2279 if (dev->type == ARPHRD_SIT && (dev->flags & IFF_POINTOPOINT)) 2280 cfg.fc_flags |= RTF_NONEXTHOP; 2281#endif 2282 | 1951 } else { 1952 ipv6_del_addr(ifp); 1953 } 1954} 1955 1956static int addrconf_dad_end(struct inet6_ifaddr *ifp) 1957{ 1958 int err = -ENOENT; --- 331 unchanged lines hidden (view full) --- 2290 This thing is done here expecting that the whole 2291 class of non-broadcast devices need not cloning. 2292 */ 2293#if IS_ENABLED(CONFIG_IPV6_SIT) 2294 if (dev->type == ARPHRD_SIT && (dev->flags & IFF_POINTOPOINT)) 2295 cfg.fc_flags |= RTF_NONEXTHOP; 2296#endif 2297 |
2283 ip6_route_add(&cfg); | 2298 ip6_route_add(&cfg, NULL); |
2284} 2285 2286 2287static struct rt6_info *addrconf_get_prefix_route(const struct in6_addr *pfx, 2288 int plen, 2289 const struct net_device *dev, 2290 u32 flags, u32 noflags) 2291{ --- 38 unchanged lines hidden (view full) --- 2330 .fc_ifindex = dev->ifindex, 2331 .fc_dst_len = 8, 2332 .fc_flags = RTF_UP, 2333 .fc_nlinfo.nl_net = dev_net(dev), 2334 }; 2335 2336 ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0); 2337 | 2299} 2300 2301 2302static struct rt6_info *addrconf_get_prefix_route(const struct in6_addr *pfx, 2303 int plen, 2304 const struct net_device *dev, 2305 u32 flags, u32 noflags) 2306{ --- 38 unchanged lines hidden (view full) --- 2345 .fc_ifindex = dev->ifindex, 2346 .fc_dst_len = 8, 2347 .fc_flags = RTF_UP, 2348 .fc_nlinfo.nl_net = dev_net(dev), 2349 }; 2350 2351 ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0); 2352 |
2338 ip6_route_add(&cfg); | 2353 ip6_route_add(&cfg, NULL); |
2339} 2340 2341static struct inet6_dev *addrconf_add_dev(struct net_device *dev) 2342{ 2343 struct inet6_dev *idev; 2344 2345 ASSERT_RTNL(); 2346 --- 3210 unchanged lines hidden (view full) --- 5557 struct rt6_info *rt; 5558 5559 rt = addrconf_get_prefix_route(&ifp->peer_addr, 128, 5560 ifp->idev->dev, 0, 0); 5561 if (rt) 5562 ip6_del_rt(rt); 5563 } 5564 if (ifp->rt) { | 2354} 2355 2356static struct inet6_dev *addrconf_add_dev(struct net_device *dev) 2357{ 2358 struct inet6_dev *idev; 2359 2360 ASSERT_RTNL(); 2361 --- 3210 unchanged lines hidden (view full) --- 5572 struct rt6_info *rt; 5573 5574 rt = addrconf_get_prefix_route(&ifp->peer_addr, 128, 5575 ifp->idev->dev, 0, 0); 5576 if (rt) 5577 ip6_del_rt(rt); 5578 } 5579 if (ifp->rt) { |
5565 dst_hold(&ifp->rt->dst); 5566 ip6_del_rt(ifp->rt); | 5580 if (dst_hold_safe(&ifp->rt->dst)) 5581 ip6_del_rt(ifp->rt); |
5567 } 5568 rt_genid_bump_ipv6(net); 5569 break; 5570 } 5571 atomic_inc(&net->ipv6.dev_addr_genid); 5572} 5573 5574static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) --- 1083 unchanged lines hidden --- | 5582 } 5583 rt_genid_bump_ipv6(net); 5584 break; 5585 } 5586 atomic_inc(&net->ipv6.dev_addr_genid); 5587} 5588 5589static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) --- 1083 unchanged lines hidden --- |