addrconf.c (e1ec1b8ccdf0df6000faa8c2d985ca5f94157e5a) addrconf.c (439e23857a21c3a953826eed23c818697a97de1a)
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 *

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

330
331 ndev = kzalloc(sizeof(struct inet6_dev), GFP_KERNEL);
332
333 if (ndev == NULL)
334 return NULL;
335
336 rwlock_init(&ndev->lock);
337 ndev->dev = dev;
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 *

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

330
331 ndev = kzalloc(sizeof(struct inet6_dev), GFP_KERNEL);
332
333 if (ndev == NULL)
334 return NULL;
335
336 rwlock_init(&ndev->lock);
337 ndev->dev = dev;
338 memcpy(&ndev->cnf, dev_net(dev)->ipv6.devconf_dflt, sizeof(ndev->cnf));
338 memcpy(&ndev->cnf, dev->nd_net->ipv6.devconf_dflt, sizeof(ndev->cnf));
339 ndev->cnf.mtu6 = dev->mtu;
340 ndev->cnf.sysctl = NULL;
341 ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl);
342 if (ndev->nd_parms == NULL) {
343 kfree(ndev);
344 return NULL;
345 }
346 /* We refer to the device */
347 dev_hold(dev);
348
349 if (snmp6_alloc_dev(ndev) < 0) {
350 ADBG((KERN_WARNING
351 "%s(): cannot allocate memory for statistics; dev=%s.\n",
339 ndev->cnf.mtu6 = dev->mtu;
340 ndev->cnf.sysctl = NULL;
341 ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl);
342 if (ndev->nd_parms == NULL) {
343 kfree(ndev);
344 return NULL;
345 }
346 /* We refer to the device */
347 dev_hold(dev);
348
349 if (snmp6_alloc_dev(ndev) < 0) {
350 ADBG((KERN_WARNING
351 "%s(): cannot allocate memory for statistics; dev=%s.\n",
352 __func__, dev->name));
352 __FUNCTION__, dev->name));
353 neigh_parms_release(&nd_tbl, ndev->nd_parms);
354 ndev->dead = 1;
355 in6_dev_finish_destroy(ndev);
356 return NULL;
357 }
358
359 if (snmp6_register_dev(ndev) < 0) {
360 ADBG((KERN_WARNING
361 "%s(): cannot create /proc/net/dev_snmp6/%s\n",
353 neigh_parms_release(&nd_tbl, ndev->nd_parms);
354 ndev->dead = 1;
355 in6_dev_finish_destroy(ndev);
356 return NULL;
357 }
358
359 if (snmp6_register_dev(ndev) < 0) {
360 ADBG((KERN_WARNING
361 "%s(): cannot create /proc/net/dev_snmp6/%s\n",
362 __func__, dev->name));
362 __FUNCTION__, dev->name));
363 neigh_parms_release(&nd_tbl, ndev->nd_parms);
364 ndev->dead = 1;
365 in6_dev_finish_destroy(ndev);
366 return NULL;
367 }
368
369 /* One reference from device. We must do this before
370 * we invoke __ipv6_regen_rndid().

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

488 if (p == &net->ipv6.devconf_all->forwarding) {
489 __s32 newf = net->ipv6.devconf_all->forwarding;
490 net->ipv6.devconf_dflt->forwarding = newf;
491 addrconf_forward_change(net, newf);
492 } else if ((!*p) ^ (!old))
493 dev_forward_change((struct inet6_dev *)table->extra1);
494
495 if (*p)
363 neigh_parms_release(&nd_tbl, ndev->nd_parms);
364 ndev->dead = 1;
365 in6_dev_finish_destroy(ndev);
366 return NULL;
367 }
368
369 /* One reference from device. We must do this before
370 * we invoke __ipv6_regen_rndid().

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

488 if (p == &net->ipv6.devconf_all->forwarding) {
489 __s32 newf = net->ipv6.devconf_all->forwarding;
490 net->ipv6.devconf_dflt->forwarding = newf;
491 addrconf_forward_change(net, newf);
492 } else if ((!*p) ^ (!old))
493 dev_forward_change((struct inet6_dev *)table->extra1);
494
495 if (*p)
496 rt6_purge_dflt_routers(net);
496 rt6_purge_dflt_routers();
497}
498#endif
499
500/* Nobody refers to this ifaddr, destroy it */
501
502void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp)
503{
504 BUG_TRAP(ifp->if_next==NULL);

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

556 if (idev->dead) {
557 err = -ENODEV; /*XXX*/
558 goto out2;
559 }
560
561 write_lock(&addrconf_hash_lock);
562
563 /* Ignore adding duplicate addresses on an interface */
497}
498#endif
499
500/* Nobody refers to this ifaddr, destroy it */
501
502void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp)
503{
504 BUG_TRAP(ifp->if_next==NULL);

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

556 if (idev->dead) {
557 err = -ENODEV; /*XXX*/
558 goto out2;
559 }
560
561 write_lock(&addrconf_hash_lock);
562
563 /* Ignore adding duplicate addresses on an interface */
564 if (ipv6_chk_same_addr(dev_net(idev->dev), addr, idev->dev)) {
564 if (ipv6_chk_same_addr(&init_net, addr, idev->dev)) {
565 ADBG(("ipv6_add_addr: already assigned\n"));
566 err = -EEXIST;
567 goto out;
568 }
569
570 ifa = kzalloc(sizeof(struct inet6_ifaddr), GFP_ATOMIC);
571
572 if (ifa == NULL) {

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

746 * addresses on the device.
747 * Note: subsequent RA will update lifetime.
748 *
749 * --yoshfuji
750 */
751 if ((ifp->flags & IFA_F_PERMANENT) && onlink < 1) {
752 struct in6_addr prefix;
753 struct rt6_info *rt;
565 ADBG(("ipv6_add_addr: already assigned\n"));
566 err = -EEXIST;
567 goto out;
568 }
569
570 ifa = kzalloc(sizeof(struct inet6_ifaddr), GFP_ATOMIC);
571
572 if (ifa == NULL) {

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

746 * addresses on the device.
747 * Note: subsequent RA will update lifetime.
748 *
749 * --yoshfuji
750 */
751 if ((ifp->flags & IFA_F_PERMANENT) && onlink < 1) {
752 struct in6_addr prefix;
753 struct rt6_info *rt;
754 struct net *net = dev_net(ifp->idev->dev);
754
755 ipv6_addr_prefix(&prefix, &ifp->addr, ifp->prefix_len);
755 ipv6_addr_prefix(&prefix, &ifp->addr, ifp->prefix_len);
756 rt = rt6_lookup(net, &prefix, NULL, ifp->idev->dev->ifindex, 1);
756 rt = rt6_lookup(&prefix, NULL, ifp->idev->dev->ifindex, 1);
757
758 if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) {
759 if (onlink == 0) {
760 ip6_del_rt(rt);
761 rt = NULL;
762 } else if (!(rt->rt6i_flags & RTF_EXPIRES)) {
763 rt->rt6i_expires = expires;
764 rt->rt6i_flags |= RTF_EXPIRES;

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

888out:
889 return ret;
890}
891#endif
892
893/*
894 * Choose an appropriate source address (RFC3484)
895 */
757
758 if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) {
759 if (onlink == 0) {
760 ip6_del_rt(rt);
761 rt = NULL;
762 } else if (!(rt->rt6i_flags & RTF_EXPIRES)) {
763 rt->rt6i_expires = expires;
764 rt->rt6i_flags |= RTF_EXPIRES;

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

888out:
889 return ret;
890}
891#endif
892
893/*
894 * Choose an appropriate source address (RFC3484)
895 */
896enum {
897 IPV6_SADDR_RULE_INIT = 0,
898 IPV6_SADDR_RULE_LOCAL,
899 IPV6_SADDR_RULE_SCOPE,
900 IPV6_SADDR_RULE_PREFERRED,
901#ifdef CONFIG_IPV6_MIP6
902 IPV6_SADDR_RULE_HOA,
903#endif
904 IPV6_SADDR_RULE_OIF,
905 IPV6_SADDR_RULE_LABEL,
906#ifdef CONFIG_IPV6_PRIVACY
907 IPV6_SADDR_RULE_PRIVACY,
908#endif
909 IPV6_SADDR_RULE_ORCHID,
910 IPV6_SADDR_RULE_PREFIX,
911 IPV6_SADDR_RULE_MAX
912};
913
914struct ipv6_saddr_score {
896struct ipv6_saddr_score {
915 int rule;
916 int addr_type;
917 struct inet6_ifaddr *ifa;
918 DECLARE_BITMAP(scorebits, IPV6_SADDR_RULE_MAX);
919 int scopedist;
920 int matchlen;
897 int addr_type;
898 unsigned int attrs;
899 int matchlen;
900 int scope;
901 unsigned int rule;
921};
922
902};
903
923struct ipv6_saddr_dst {
924 struct in6_addr *addr;
925 int ifindex;
926 int scope;
927 int label;
928 unsigned int prefs;
929};
904#define IPV6_SADDR_SCORE_LOCAL 0x0001
905#define IPV6_SADDR_SCORE_PREFERRED 0x0004
906#define IPV6_SADDR_SCORE_HOA 0x0008
907#define IPV6_SADDR_SCORE_OIF 0x0010
908#define IPV6_SADDR_SCORE_LABEL 0x0020
909#define IPV6_SADDR_SCORE_PRIVACY 0x0040
930
931static inline int ipv6_saddr_preferred(int type)
932{
933 if (type & (IPV6_ADDR_MAPPED|IPV6_ADDR_COMPATv4|
934 IPV6_ADDR_LOOPBACK|IPV6_ADDR_RESERVED))
935 return 1;
936 return 0;
937}
938
910
911static inline int ipv6_saddr_preferred(int type)
912{
913 if (type & (IPV6_ADDR_MAPPED|IPV6_ADDR_COMPATv4|
914 IPV6_ADDR_LOOPBACK|IPV6_ADDR_RESERVED))
915 return 1;
916 return 0;
917}
918
939static int ipv6_get_saddr_eval(struct ipv6_saddr_score *score,
940 struct ipv6_saddr_dst *dst,
941 int i)
919int ipv6_dev_get_saddr(struct net_device *daddr_dev,
920 struct in6_addr *daddr, struct in6_addr *saddr)
942{
921{
943 int ret;
944
945 if (i <= score->rule) {
946 switch (i) {
947 case IPV6_SADDR_RULE_SCOPE:
948 ret = score->scopedist;
949 break;
950 case IPV6_SADDR_RULE_PREFIX:
951 ret = score->matchlen;
952 break;
953 default:
954 ret = !!test_bit(i, score->scorebits);
955 }
956 goto out;
957 }
958
959 switch (i) {
960 case IPV6_SADDR_RULE_INIT:
961 /* Rule 0: remember if hiscore is not ready yet */
962 ret = !!score->ifa;
963 break;
964 case IPV6_SADDR_RULE_LOCAL:
965 /* Rule 1: Prefer same address */
966 ret = ipv6_addr_equal(&score->ifa->addr, dst->addr);
967 break;
968 case IPV6_SADDR_RULE_SCOPE:
969 /* Rule 2: Prefer appropriate scope
970 *
971 * ret
972 * ^
973 * -1 | d 15
974 * ---+--+-+---> scope
975 * |
976 * | d is scope of the destination.
977 * B-d | \
978 * | \ <- smaller scope is better if
979 * B-15 | \ if scope is enough for destinaion.
980 * | ret = B - scope (-1 <= scope >= d <= 15).
981 * d-C-1 | /
982 * |/ <- greater is better
983 * -C / if scope is not enough for destination.
984 * /| ret = scope - C (-1 <= d < scope <= 15).
985 *
986 * d - C - 1 < B -15 (for all -1 <= d <= 15).
987 * C > d + 14 - B >= 15 + 14 - B = 29 - B.
988 * Assume B = 0 and we get C > 29.
989 */
990 ret = __ipv6_addr_src_scope(score->addr_type);
991 if (ret >= dst->scope)
992 ret = -ret;
993 else
994 ret -= 128; /* 30 is enough */
995 score->scopedist = ret;
996 break;
997 case IPV6_SADDR_RULE_PREFERRED:
998 /* Rule 3: Avoid deprecated and optimistic addresses */
999 ret = ipv6_saddr_preferred(score->addr_type) ||
1000 !(score->ifa->flags & (IFA_F_DEPRECATED|IFA_F_OPTIMISTIC));
1001 break;
1002#ifdef CONFIG_IPV6_MIP6
1003 case IPV6_SADDR_RULE_HOA:
1004 {
1005 /* Rule 4: Prefer home address */
1006 int prefhome = !(dst->prefs & IPV6_PREFER_SRC_COA);
1007 ret = !(score->ifa->flags & IFA_F_HOMEADDRESS) ^ prefhome;
1008 break;
1009 }
1010#endif
1011 case IPV6_SADDR_RULE_OIF:
1012 /* Rule 5: Prefer outgoing interface */
1013 ret = (!dst->ifindex ||
1014 dst->ifindex == score->ifa->idev->dev->ifindex);
1015 break;
1016 case IPV6_SADDR_RULE_LABEL:
1017 /* Rule 6: Prefer matching label */
1018 ret = ipv6_addr_label(&score->ifa->addr, score->addr_type,
1019 score->ifa->idev->dev->ifindex) == dst->label;
1020 break;
1021#ifdef CONFIG_IPV6_PRIVACY
1022 case IPV6_SADDR_RULE_PRIVACY:
1023 {
1024 /* Rule 7: Prefer public address
1025 * Note: prefer temprary address if use_tempaddr >= 2
1026 */
1027 int preftmp = dst->prefs & (IPV6_PREFER_SRC_PUBLIC|IPV6_PREFER_SRC_TMP) ?
1028 !!(dst->prefs & IPV6_PREFER_SRC_TMP) :
1029 score->ifa->idev->cnf.use_tempaddr >= 2;
1030 ret = (!(score->ifa->flags & IFA_F_TEMPORARY)) ^ preftmp;
1031 break;
1032 }
1033#endif
1034 case IPV6_SADDR_RULE_ORCHID:
1035 /* Rule 8-: Prefer ORCHID vs ORCHID or
1036 * non-ORCHID vs non-ORCHID
1037 */
1038 ret = !(ipv6_addr_orchid(&score->ifa->addr) ^
1039 ipv6_addr_orchid(dst->addr));
1040 break;
1041 case IPV6_SADDR_RULE_PREFIX:
1042 /* Rule 8: Use longest matching prefix */
1043 score->matchlen = ret = ipv6_addr_diff(&score->ifa->addr,
1044 dst->addr);
1045 break;
1046 default:
1047 ret = 0;
1048 }
1049
1050 if (ret)
1051 __set_bit(i, score->scorebits);
1052 score->rule = i;
1053out:
1054 return ret;
1055}
1056
1057int ipv6_dev_get_saddr(struct net_device *dst_dev,
1058 struct in6_addr *daddr, unsigned int prefs,
1059 struct in6_addr *saddr)
1060{
1061 struct ipv6_saddr_score scores[2],
1062 *score = &scores[0], *hiscore = &scores[1];
1063 struct net *net = dev_net(dst_dev);
1064 struct ipv6_saddr_dst dst;
922 struct ipv6_saddr_score hiscore;
923 struct inet6_ifaddr *ifa_result = NULL;
924 int daddr_type = __ipv6_addr_type(daddr);
925 int daddr_scope = __ipv6_addr_src_scope(daddr_type);
926 int daddr_ifindex = daddr_dev ? daddr_dev->ifindex : 0;
927 u32 daddr_label = ipv6_addr_label(daddr, daddr_type, daddr_ifindex);
1065 struct net_device *dev;
928 struct net_device *dev;
1066 int dst_type;
1067
929
1068 dst_type = __ipv6_addr_type(daddr);
1069 dst.addr = daddr;
1070 dst.ifindex = dst_dev ? dst_dev->ifindex : 0;
1071 dst.scope = __ipv6_addr_src_scope(dst_type);
1072 dst.label = ipv6_addr_label(daddr, dst_type, dst.ifindex);
1073 dst.prefs = prefs;
930 memset(&hiscore, 0, sizeof(hiscore));
1074
931
1075 hiscore->rule = -1;
1076 hiscore->ifa = NULL;
1077
1078 read_lock(&dev_base_lock);
1079 rcu_read_lock();
1080
932 read_lock(&dev_base_lock);
933 rcu_read_lock();
934
1081 for_each_netdev(net, dev) {
935 for_each_netdev(&init_net, dev) {
1082 struct inet6_dev *idev;
936 struct inet6_dev *idev;
937 struct inet6_ifaddr *ifa;
1083
938
1084 /* Candidate Source Address (section 4)
939 /* Rule 0: Candidate Source Address (section 4)
1085 * - multicast and link-local destination address,
1086 * the set of candidate source address MUST only
1087 * include addresses assigned to interfaces
1088 * belonging to the same link as the outgoing
1089 * interface.
1090 * (- For site-local destination addresses, the
1091 * set of candidate source addresses MUST only
1092 * include addresses assigned to interfaces
1093 * belonging to the same site as the outgoing
1094 * interface.)
1095 */
940 * - multicast and link-local destination address,
941 * the set of candidate source address MUST only
942 * include addresses assigned to interfaces
943 * belonging to the same link as the outgoing
944 * interface.
945 * (- For site-local destination addresses, the
946 * set of candidate source addresses MUST only
947 * include addresses assigned to interfaces
948 * belonging to the same site as the outgoing
949 * interface.)
950 */
1096 if (((dst_type & IPV6_ADDR_MULTICAST) ||
1097 dst.scope <= IPV6_ADDR_SCOPE_LINKLOCAL) &&
1098 dst.ifindex && dev->ifindex != dst.ifindex)
951 if ((daddr_type & IPV6_ADDR_MULTICAST ||
952 daddr_scope <= IPV6_ADDR_SCOPE_LINKLOCAL) &&
953 daddr_dev && dev != daddr_dev)
1099 continue;
1100
1101 idev = __in6_dev_get(dev);
1102 if (!idev)
1103 continue;
1104
1105 read_lock_bh(&idev->lock);
954 continue;
955
956 idev = __in6_dev_get(dev);
957 if (!idev)
958 continue;
959
960 read_lock_bh(&idev->lock);
1106 for (score->ifa = idev->addr_list; score->ifa; score->ifa = score->ifa->if_next) {
1107 int i;
961 for (ifa = idev->addr_list; ifa; ifa = ifa->if_next) {
962 struct ipv6_saddr_score score;
1108
963
1109 /*
964 score.addr_type = __ipv6_addr_type(&ifa->addr);
965
966 /* Rule 0:
1110 * - Tentative Address (RFC2462 section 5.4)
1111 * - A tentative address is not considered
1112 * "assigned to an interface" in the traditional
1113 * sense, unless it is also flagged as optimistic.
1114 * - Candidate Source Address (section 4)
1115 * - In any case, anycast addresses, multicast
1116 * addresses, and the unspecified address MUST
1117 * NOT be included in a candidate set.
1118 */
967 * - Tentative Address (RFC2462 section 5.4)
968 * - A tentative address is not considered
969 * "assigned to an interface" in the traditional
970 * sense, unless it is also flagged as optimistic.
971 * - Candidate Source Address (section 4)
972 * - In any case, anycast addresses, multicast
973 * addresses, and the unspecified address MUST
974 * NOT be included in a candidate set.
975 */
1119 if ((score->ifa->flags & IFA_F_TENTATIVE) &&
1120 (!(score->ifa->flags & IFA_F_OPTIMISTIC)))
976 if ((ifa->flags & IFA_F_TENTATIVE) &&
977 (!(ifa->flags & IFA_F_OPTIMISTIC)))
1121 continue;
978 continue;
1122
1123 score->addr_type = __ipv6_addr_type(&score->ifa->addr);
1124
1125 if (unlikely(score->addr_type == IPV6_ADDR_ANY ||
1126 score->addr_type & IPV6_ADDR_MULTICAST)) {
979 if (unlikely(score.addr_type == IPV6_ADDR_ANY ||
980 score.addr_type & IPV6_ADDR_MULTICAST)) {
1127 LIMIT_NETDEBUG(KERN_DEBUG
1128 "ADDRCONF: unspecified / multicast address "
1129 "assigned as unicast address on %s",
1130 dev->name);
1131 continue;
1132 }
1133
981 LIMIT_NETDEBUG(KERN_DEBUG
982 "ADDRCONF: unspecified / multicast address "
983 "assigned as unicast address on %s",
984 dev->name);
985 continue;
986 }
987
1134 score->rule = -1;
1135 bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
988 score.attrs = 0;
989 score.matchlen = 0;
990 score.scope = 0;
991 score.rule = 0;
1136
992
1137 for (i = 0; i < IPV6_SADDR_RULE_MAX; i++) {
1138 int minihiscore, miniscore;
993 if (ifa_result == NULL) {
994 /* record it if the first available entry */
995 goto record_it;
996 }
1139
997
1140 minihiscore = ipv6_get_saddr_eval(hiscore, &dst, i);
1141 miniscore = ipv6_get_saddr_eval(score, &dst, i);
998 /* Rule 1: Prefer same address */
999 if (hiscore.rule < 1) {
1000 if (ipv6_addr_equal(&ifa_result->addr, daddr))
1001 hiscore.attrs |= IPV6_SADDR_SCORE_LOCAL;
1002 hiscore.rule++;
1003 }
1004 if (ipv6_addr_equal(&ifa->addr, daddr)) {
1005 score.attrs |= IPV6_SADDR_SCORE_LOCAL;
1006 if (!(hiscore.attrs & IPV6_SADDR_SCORE_LOCAL)) {
1007 score.rule = 1;
1008 goto record_it;
1009 }
1010 } else {
1011 if (hiscore.attrs & IPV6_SADDR_SCORE_LOCAL)
1012 continue;
1013 }
1142
1014
1143 if (minihiscore > miniscore) {
1144 if (i == IPV6_SADDR_RULE_SCOPE &&
1145 score->scopedist > 0) {
1146 /*
1147 * special case:
1148 * each remaining entry
1149 * has too small (not enough)
1150 * scope, because ifa entries
1151 * are sorted by their scope
1152 * values.
1153 */
1154 goto try_nextdev;
1155 }
1156 break;
1157 } else if (minihiscore < miniscore) {
1158 struct ipv6_saddr_score *tmp;
1015 /* Rule 2: Prefer appropriate scope */
1016 if (hiscore.rule < 2) {
1017 hiscore.scope = __ipv6_addr_src_scope(hiscore.addr_type);
1018 hiscore.rule++;
1019 }
1020 score.scope = __ipv6_addr_src_scope(score.addr_type);
1021 if (hiscore.scope < score.scope) {
1022 if (hiscore.scope < daddr_scope) {
1023 score.rule = 2;
1024 goto record_it;
1025 } else
1026 continue;
1027 } else if (score.scope < hiscore.scope) {
1028 if (score.scope < daddr_scope)
1029 break; /* addresses sorted by scope */
1030 else {
1031 score.rule = 2;
1032 goto record_it;
1033 }
1034 }
1159
1035
1160 if (hiscore->ifa)
1161 in6_ifa_put(hiscore->ifa);
1036 /* Rule 3: Avoid deprecated and optimistic addresses */
1037 if (hiscore.rule < 3) {
1038 if (ipv6_saddr_preferred(hiscore.addr_type) ||
1039 (((ifa_result->flags &
1040 (IFA_F_DEPRECATED|IFA_F_OPTIMISTIC)) == 0)))
1041 hiscore.attrs |= IPV6_SADDR_SCORE_PREFERRED;
1042 hiscore.rule++;
1043 }
1044 if (ipv6_saddr_preferred(score.addr_type) ||
1045 (((ifa->flags &
1046 (IFA_F_DEPRECATED|IFA_F_OPTIMISTIC)) == 0))) {
1047 score.attrs |= IPV6_SADDR_SCORE_PREFERRED;
1048 if (!(hiscore.attrs & IPV6_SADDR_SCORE_PREFERRED)) {
1049 score.rule = 3;
1050 goto record_it;
1051 }
1052 } else {
1053 if (hiscore.attrs & IPV6_SADDR_SCORE_PREFERRED)
1054 continue;
1055 }
1162
1056
1163 in6_ifa_hold(score->ifa);
1057 /* Rule 4: Prefer home address */
1058#if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
1059 if (hiscore.rule < 4) {
1060 if (ifa_result->flags & IFA_F_HOMEADDRESS)
1061 hiscore.attrs |= IPV6_SADDR_SCORE_HOA;
1062 hiscore.rule++;
1063 }
1064 if (ifa->flags & IFA_F_HOMEADDRESS) {
1065 score.attrs |= IPV6_SADDR_SCORE_HOA;
1066 if (!(ifa_result->flags & IFA_F_HOMEADDRESS)) {
1067 score.rule = 4;
1068 goto record_it;
1069 }
1070 } else {
1071 if (hiscore.attrs & IPV6_SADDR_SCORE_HOA)
1072 continue;
1073 }
1074#else
1075 if (hiscore.rule < 4)
1076 hiscore.rule++;
1077#endif
1164
1078
1165 tmp = hiscore;
1166 hiscore = score;
1167 score = tmp;
1079 /* Rule 5: Prefer outgoing interface */
1080 if (hiscore.rule < 5) {
1081 if (daddr_dev == NULL ||
1082 daddr_dev == ifa_result->idev->dev)
1083 hiscore.attrs |= IPV6_SADDR_SCORE_OIF;
1084 hiscore.rule++;
1085 }
1086 if (daddr_dev == NULL ||
1087 daddr_dev == ifa->idev->dev) {
1088 score.attrs |= IPV6_SADDR_SCORE_OIF;
1089 if (!(hiscore.attrs & IPV6_SADDR_SCORE_OIF)) {
1090 score.rule = 5;
1091 goto record_it;
1092 }
1093 } else {
1094 if (hiscore.attrs & IPV6_SADDR_SCORE_OIF)
1095 continue;
1096 }
1168
1097
1169 /* restore our iterator */
1170 score->ifa = hiscore->ifa;
1098 /* Rule 6: Prefer matching label */
1099 if (hiscore.rule < 6) {
1100 if (ipv6_addr_label(&ifa_result->addr,
1101 hiscore.addr_type,
1102 ifa_result->idev->dev->ifindex) == daddr_label)
1103 hiscore.attrs |= IPV6_SADDR_SCORE_LABEL;
1104 hiscore.rule++;
1105 }
1106 if (ipv6_addr_label(&ifa->addr,
1107 score.addr_type,
1108 ifa->idev->dev->ifindex) == daddr_label) {
1109 score.attrs |= IPV6_SADDR_SCORE_LABEL;
1110 if (!(hiscore.attrs & IPV6_SADDR_SCORE_LABEL)) {
1111 score.rule = 6;
1112 goto record_it;
1113 }
1114 } else {
1115 if (hiscore.attrs & IPV6_SADDR_SCORE_LABEL)
1116 continue;
1117 }
1171
1118
1172 break;
1119#ifdef CONFIG_IPV6_PRIVACY
1120 /* Rule 7: Prefer public address
1121 * Note: prefer temprary address if use_tempaddr >= 2
1122 */
1123 if (hiscore.rule < 7) {
1124 if ((!(ifa_result->flags & IFA_F_TEMPORARY)) ^
1125 (ifa_result->idev->cnf.use_tempaddr >= 2))
1126 hiscore.attrs |= IPV6_SADDR_SCORE_PRIVACY;
1127 hiscore.rule++;
1128 }
1129 if ((!(ifa->flags & IFA_F_TEMPORARY)) ^
1130 (ifa->idev->cnf.use_tempaddr >= 2)) {
1131 score.attrs |= IPV6_SADDR_SCORE_PRIVACY;
1132 if (!(hiscore.attrs & IPV6_SADDR_SCORE_PRIVACY)) {
1133 score.rule = 7;
1134 goto record_it;
1173 }
1135 }
1136 } else {
1137 if (hiscore.attrs & IPV6_SADDR_SCORE_PRIVACY)
1138 continue;
1174 }
1139 }
1140#else
1141 if (hiscore.rule < 7)
1142 hiscore.rule++;
1143#endif
1144 /* Rule 8: Use longest matching prefix */
1145 if (hiscore.rule < 8) {
1146 hiscore.matchlen = ipv6_addr_diff(&ifa_result->addr, daddr);
1147 hiscore.rule++;
1148 }
1149 score.matchlen = ipv6_addr_diff(&ifa->addr, daddr);
1150 if (score.matchlen > hiscore.matchlen) {
1151 score.rule = 8;
1152 goto record_it;
1153 }
1154#if 0
1155 else if (score.matchlen < hiscore.matchlen)
1156 continue;
1157#endif
1158
1159 /* Final Rule: choose first available one */
1160 continue;
1161record_it:
1162 if (ifa_result)
1163 in6_ifa_put(ifa_result);
1164 in6_ifa_hold(ifa);
1165 ifa_result = ifa;
1166 hiscore = score;
1175 }
1167 }
1176try_nextdev:
1177 read_unlock_bh(&idev->lock);
1178 }
1179 rcu_read_unlock();
1180 read_unlock(&dev_base_lock);
1181
1168 read_unlock_bh(&idev->lock);
1169 }
1170 rcu_read_unlock();
1171 read_unlock(&dev_base_lock);
1172
1182 if (!hiscore->ifa)
1173 if (!ifa_result)
1183 return -EADDRNOTAVAIL;
1184
1174 return -EADDRNOTAVAIL;
1175
1185 ipv6_addr_copy(saddr, &hiscore->ifa->addr);
1186 in6_ifa_put(hiscore->ifa);
1176 ipv6_addr_copy(saddr, &ifa_result->addr);
1177 in6_ifa_put(ifa_result);
1187 return 0;
1188}
1189
1178 return 0;
1179}
1180
1190EXPORT_SYMBOL(ipv6_dev_get_saddr);
1191
1181
1182int ipv6_get_saddr(struct dst_entry *dst,
1183 struct in6_addr *daddr, struct in6_addr *saddr)
1184{
1185 return ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL, daddr, saddr);
1186}
1187
1188EXPORT_SYMBOL(ipv6_get_saddr);
1189
1192int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
1193 unsigned char banned_flags)
1194{
1195 struct inet6_dev *idev;
1196 int err = -EADDRNOTAVAIL;
1197
1198 rcu_read_lock();
1199 if ((idev = __in6_dev_get(dev)) != NULL) {

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

1228int ipv6_chk_addr(struct net *net, struct in6_addr *addr,
1229 struct net_device *dev, int strict)
1230{
1231 struct inet6_ifaddr * ifp;
1232 u8 hash = ipv6_addr_hash(addr);
1233
1234 read_lock_bh(&addrconf_hash_lock);
1235 for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
1190int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
1191 unsigned char banned_flags)
1192{
1193 struct inet6_dev *idev;
1194 int err = -EADDRNOTAVAIL;
1195
1196 rcu_read_lock();
1197 if ((idev = __in6_dev_get(dev)) != NULL) {

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

1226int ipv6_chk_addr(struct net *net, struct in6_addr *addr,
1227 struct net_device *dev, int strict)
1228{
1229 struct inet6_ifaddr * ifp;
1230 u8 hash = ipv6_addr_hash(addr);
1231
1232 read_lock_bh(&addrconf_hash_lock);
1233 for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
1236 if (!net_eq(dev_net(ifp->idev->dev), net))
1234 if (ifp->idev->dev->nd_net != net)
1237 continue;
1238 if (ipv6_addr_equal(&ifp->addr, addr) &&
1239 !(ifp->flags&IFA_F_TENTATIVE)) {
1240 if (dev == NULL || ifp->idev->dev == dev ||
1241 !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))
1242 break;
1243 }
1244 }

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

1250static
1251int ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr,
1252 struct net_device *dev)
1253{
1254 struct inet6_ifaddr * ifp;
1255 u8 hash = ipv6_addr_hash(addr);
1256
1257 for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
1235 continue;
1236 if (ipv6_addr_equal(&ifp->addr, addr) &&
1237 !(ifp->flags&IFA_F_TENTATIVE)) {
1238 if (dev == NULL || ifp->idev->dev == dev ||
1239 !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))
1240 break;
1241 }
1242 }

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

1248static
1249int ipv6_chk_same_addr(struct net *net, const struct in6_addr *addr,
1250 struct net_device *dev)
1251{
1252 struct inet6_ifaddr * ifp;
1253 u8 hash = ipv6_addr_hash(addr);
1254
1255 for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
1258 if (!net_eq(dev_net(ifp->idev->dev), net))
1256 if (ifp->idev->dev->nd_net != net)
1259 continue;
1260 if (ipv6_addr_equal(&ifp->addr, addr)) {
1261 if (dev == NULL || ifp->idev->dev == dev)
1262 break;
1263 }
1264 }
1265 return ifp != NULL;
1266}
1267
1268struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, struct in6_addr *addr,
1269 struct net_device *dev, int strict)
1270{
1271 struct inet6_ifaddr * ifp;
1272 u8 hash = ipv6_addr_hash(addr);
1273
1274 read_lock_bh(&addrconf_hash_lock);
1275 for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
1257 continue;
1258 if (ipv6_addr_equal(&ifp->addr, addr)) {
1259 if (dev == NULL || ifp->idev->dev == dev)
1260 break;
1261 }
1262 }
1263 return ifp != NULL;
1264}
1265
1266struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, struct in6_addr *addr,
1267 struct net_device *dev, int strict)
1268{
1269 struct inet6_ifaddr * ifp;
1270 u8 hash = ipv6_addr_hash(addr);
1271
1272 read_lock_bh(&addrconf_hash_lock);
1273 for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
1276 if (!net_eq(dev_net(ifp->idev->dev), net))
1274 if (ifp->idev->dev->nd_net != net)
1277 continue;
1278 if (ipv6_addr_equal(&ifp->addr, addr)) {
1279 if (dev == NULL || ifp->idev->dev == dev ||
1280 !(ifp->scope&(IFA_LINK|IFA_HOST) || strict)) {
1281 in6_ifa_hold(ifp);
1282 break;
1283 }
1284 }

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

1570{
1571 struct fib6_config cfg = {
1572 .fc_table = RT6_TABLE_PREFIX,
1573 .fc_metric = IP6_RT_PRIO_ADDRCONF,
1574 .fc_ifindex = dev->ifindex,
1575 .fc_expires = expires,
1576 .fc_dst_len = plen,
1577 .fc_flags = RTF_UP | flags,
1275 continue;
1276 if (ipv6_addr_equal(&ifp->addr, addr)) {
1277 if (dev == NULL || ifp->idev->dev == dev ||
1278 !(ifp->scope&(IFA_LINK|IFA_HOST) || strict)) {
1279 in6_ifa_hold(ifp);
1280 break;
1281 }
1282 }

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

1568{
1569 struct fib6_config cfg = {
1570 .fc_table = RT6_TABLE_PREFIX,
1571 .fc_metric = IP6_RT_PRIO_ADDRCONF,
1572 .fc_ifindex = dev->ifindex,
1573 .fc_expires = expires,
1574 .fc_dst_len = plen,
1575 .fc_flags = RTF_UP | flags,
1578 .fc_nlinfo.nl_net = dev_net(dev),
1576 .fc_nlinfo.nl_net = &init_net,
1579 };
1580
1581 ipv6_addr_copy(&cfg.fc_dst, pfx);
1582
1583 /* Prevent useless cloning on PtP SIT.
1584 This thing is done here expecting that the whole
1585 class of non-broadcast devices need not cloning.
1586 */

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

1597static void addrconf_add_mroute(struct net_device *dev)
1598{
1599 struct fib6_config cfg = {
1600 .fc_table = RT6_TABLE_LOCAL,
1601 .fc_metric = IP6_RT_PRIO_ADDRCONF,
1602 .fc_ifindex = dev->ifindex,
1603 .fc_dst_len = 8,
1604 .fc_flags = RTF_UP,
1577 };
1578
1579 ipv6_addr_copy(&cfg.fc_dst, pfx);
1580
1581 /* Prevent useless cloning on PtP SIT.
1582 This thing is done here expecting that the whole
1583 class of non-broadcast devices need not cloning.
1584 */

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

1595static void addrconf_add_mroute(struct net_device *dev)
1596{
1597 struct fib6_config cfg = {
1598 .fc_table = RT6_TABLE_LOCAL,
1599 .fc_metric = IP6_RT_PRIO_ADDRCONF,
1600 .fc_ifindex = dev->ifindex,
1601 .fc_dst_len = 8,
1602 .fc_flags = RTF_UP,
1605 .fc_nlinfo.nl_net = dev_net(dev),
1603 .fc_nlinfo.nl_net = &init_net,
1606 };
1607
1608 ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0);
1609
1610 ip6_route_add(&cfg);
1611}
1612
1613#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
1614static void sit_route_add(struct net_device *dev)
1615{
1616 struct fib6_config cfg = {
1617 .fc_table = RT6_TABLE_MAIN,
1618 .fc_metric = IP6_RT_PRIO_ADDRCONF,
1619 .fc_ifindex = dev->ifindex,
1620 .fc_dst_len = 96,
1621 .fc_flags = RTF_UP | RTF_NONEXTHOP,
1604 };
1605
1606 ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0);
1607
1608 ip6_route_add(&cfg);
1609}
1610
1611#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
1612static void sit_route_add(struct net_device *dev)
1613{
1614 struct fib6_config cfg = {
1615 .fc_table = RT6_TABLE_MAIN,
1616 .fc_metric = IP6_RT_PRIO_ADDRCONF,
1617 .fc_ifindex = dev->ifindex,
1618 .fc_dst_len = 96,
1619 .fc_flags = RTF_UP | RTF_NONEXTHOP,
1622 .fc_nlinfo.nl_net = dev_net(dev),
1620 .fc_nlinfo.nl_net = &init_net,
1623 };
1624
1625 /* prefix length - 96 bits "::d.d.d.d" */
1626 ip6_route_add(&cfg);
1627}
1628#endif
1629
1630static void addrconf_add_lroute(struct net_device *dev)

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

1715 * Avoid arithmetic overflow there as well.
1716 * Overflow can happen only if HZ < USER_HZ.
1717 */
1718 if (HZ < USER_HZ && rt_expires > 0x7FFFFFFF / USER_HZ)
1719 rt_expires = 0x7FFFFFFF / USER_HZ;
1720
1721 if (pinfo->onlink) {
1722 struct rt6_info *rt;
1621 };
1622
1623 /* prefix length - 96 bits "::d.d.d.d" */
1624 ip6_route_add(&cfg);
1625}
1626#endif
1627
1628static void addrconf_add_lroute(struct net_device *dev)

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

1713 * Avoid arithmetic overflow there as well.
1714 * Overflow can happen only if HZ < USER_HZ.
1715 */
1716 if (HZ < USER_HZ && rt_expires > 0x7FFFFFFF / USER_HZ)
1717 rt_expires = 0x7FFFFFFF / USER_HZ;
1718
1719 if (pinfo->onlink) {
1720 struct rt6_info *rt;
1723 rt = rt6_lookup(dev_net(dev), &pinfo->prefix, NULL,
1724 dev->ifindex, 1);
1721 rt = rt6_lookup(&pinfo->prefix, NULL, dev->ifindex, 1);
1725
1726 if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) {
1727 if (rt->rt6i_flags&RTF_EXPIRES) {
1728 if (valid_lft == 0) {
1729 ip6_del_rt(rt);
1730 rt = NULL;
1731 } else {
1732 rt->rt6i_expires = jiffies + rt_expires;

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

1759 if (net_ratelimit())
1760 printk(KERN_DEBUG "IPv6 addrconf: prefix with wrong length %d\n",
1761 pinfo->prefix_len);
1762 in6_dev_put(in6_dev);
1763 return;
1764
1765ok:
1766
1722
1723 if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) {
1724 if (rt->rt6i_flags&RTF_EXPIRES) {
1725 if (valid_lft == 0) {
1726 ip6_del_rt(rt);
1727 rt = NULL;
1728 } else {
1729 rt->rt6i_expires = jiffies + rt_expires;

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

1756 if (net_ratelimit())
1757 printk(KERN_DEBUG "IPv6 addrconf: prefix with wrong length %d\n",
1758 pinfo->prefix_len);
1759 in6_dev_put(in6_dev);
1760 return;
1761
1762ok:
1763
1767 ifp = ipv6_get_ifaddr(dev_net(dev), &addr, dev, 1);
1764 ifp = ipv6_get_ifaddr(&init_net, &addr, dev, 1);
1768
1769 if (ifp == NULL && valid_lft) {
1770 int max_addresses = in6_dev->cnf.max_addresses;
1771 u32 addr_flags = 0;
1772
1773#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
1774 if (in6_dev->cnf.optimistic_dad &&
1775 !ipv6_devconf.forwarding)

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

1885 in6_dev_put(in6_dev);
1886}
1887
1888/*
1889 * Set destination address.
1890 * Special case for SIT interfaces where we create a new "virtual"
1891 * device.
1892 */
1765
1766 if (ifp == NULL && valid_lft) {
1767 int max_addresses = in6_dev->cnf.max_addresses;
1768 u32 addr_flags = 0;
1769
1770#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
1771 if (in6_dev->cnf.optimistic_dad &&
1772 !ipv6_devconf.forwarding)

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

1882 in6_dev_put(in6_dev);
1883}
1884
1885/*
1886 * Set destination address.
1887 * Special case for SIT interfaces where we create a new "virtual"
1888 * device.
1889 */
1893int addrconf_set_dstaddr(struct net *net, void __user *arg)
1890int addrconf_set_dstaddr(void __user *arg)
1894{
1895 struct in6_ifreq ireq;
1896 struct net_device *dev;
1897 int err = -EINVAL;
1898
1899 rtnl_lock();
1900
1901 err = -EFAULT;
1902 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
1903 goto err_exit;
1904
1891{
1892 struct in6_ifreq ireq;
1893 struct net_device *dev;
1894 int err = -EINVAL;
1895
1896 rtnl_lock();
1897
1898 err = -EFAULT;
1899 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
1900 goto err_exit;
1901
1905 dev = __dev_get_by_index(net, ireq.ifr6_ifindex);
1902 dev = __dev_get_by_index(&init_net, ireq.ifr6_ifindex);
1906
1907 err = -ENODEV;
1908 if (dev == NULL)
1909 goto err_exit;
1910
1911#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
1912 if (dev->type == ARPHRD_SIT) {
1913 struct ifreq ifr;

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

1928 ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
1929
1930 oldfs = get_fs(); set_fs(KERNEL_DS);
1931 err = dev->do_ioctl(dev, &ifr, SIOCADDTUNNEL);
1932 set_fs(oldfs);
1933
1934 if (err == 0) {
1935 err = -ENOBUFS;
1903
1904 err = -ENODEV;
1905 if (dev == NULL)
1906 goto err_exit;
1907
1908#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
1909 if (dev->type == ARPHRD_SIT) {
1910 struct ifreq ifr;

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

1925 ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
1926
1927 oldfs = get_fs(); set_fs(KERNEL_DS);
1928 err = dev->do_ioctl(dev, &ifr, SIOCADDTUNNEL);
1929 set_fs(oldfs);
1930
1931 if (err == 0) {
1932 err = -ENOBUFS;
1936 dev = __dev_get_by_name(net, p.name);
1937 if (!dev)
1933 if ((dev = __dev_get_by_name(&init_net, p.name)) == NULL)
1938 goto err_exit;
1939 err = dev_open(dev);
1940 }
1941 }
1942#endif
1943
1944err_exit:
1945 rtnl_unlock();
1946 return err;
1947}
1948
1949/*
1950 * Manual configuration of address on an interface
1951 */
1934 goto err_exit;
1935 err = dev_open(dev);
1936 }
1937 }
1938#endif
1939
1940err_exit:
1941 rtnl_unlock();
1942 return err;
1943}
1944
1945/*
1946 * Manual configuration of address on an interface
1947 */
1952static int inet6_addr_add(struct net *net, int ifindex, struct in6_addr *pfx,
1953 int plen, __u8 ifa_flags, __u32 prefered_lft,
1954 __u32 valid_lft)
1948static int inet6_addr_add(int ifindex, struct in6_addr *pfx, int plen,
1949 __u8 ifa_flags, __u32 prefered_lft, __u32 valid_lft)
1955{
1956 struct inet6_ifaddr *ifp;
1957 struct inet6_dev *idev;
1958 struct net_device *dev;
1959 int scope;
1960 u32 flags = RTF_EXPIRES;
1961
1962 ASSERT_RTNL();
1963
1964 /* check the lifetime */
1965 if (!valid_lft || prefered_lft > valid_lft)
1966 return -EINVAL;
1967
1950{
1951 struct inet6_ifaddr *ifp;
1952 struct inet6_dev *idev;
1953 struct net_device *dev;
1954 int scope;
1955 u32 flags = RTF_EXPIRES;
1956
1957 ASSERT_RTNL();
1958
1959 /* check the lifetime */
1960 if (!valid_lft || prefered_lft > valid_lft)
1961 return -EINVAL;
1962
1968 dev = __dev_get_by_index(net, ifindex);
1969 if (!dev)
1963 if ((dev = __dev_get_by_index(&init_net, ifindex)) == NULL)
1970 return -ENODEV;
1971
1972 if ((idev = addrconf_add_dev(dev)) == NULL)
1973 return -ENOBUFS;
1974
1975 scope = ipv6_addr_scope(pfx);
1976
1977 if (valid_lft == INFINITY_LIFE_TIME) {

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

2006 in6_ifa_put(ifp);
2007 addrconf_verify(0);
2008 return 0;
2009 }
2010
2011 return PTR_ERR(ifp);
2012}
2013
1964 return -ENODEV;
1965
1966 if ((idev = addrconf_add_dev(dev)) == NULL)
1967 return -ENOBUFS;
1968
1969 scope = ipv6_addr_scope(pfx);
1970
1971 if (valid_lft == INFINITY_LIFE_TIME) {

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

2000 in6_ifa_put(ifp);
2001 addrconf_verify(0);
2002 return 0;
2003 }
2004
2005 return PTR_ERR(ifp);
2006}
2007
2014static int inet6_addr_del(struct net *net, int ifindex, struct in6_addr *pfx,
2015 int plen)
2008static int inet6_addr_del(int ifindex, struct in6_addr *pfx, int plen)
2016{
2017 struct inet6_ifaddr *ifp;
2018 struct inet6_dev *idev;
2019 struct net_device *dev;
2020
2009{
2010 struct inet6_ifaddr *ifp;
2011 struct inet6_dev *idev;
2012 struct net_device *dev;
2013
2021 dev = __dev_get_by_index(net, ifindex);
2022 if (!dev)
2014 if ((dev = __dev_get_by_index(&init_net, ifindex)) == NULL)
2023 return -ENODEV;
2024
2025 if ((idev = __in6_dev_get(dev)) == NULL)
2026 return -ENXIO;
2027
2028 read_lock_bh(&idev->lock);
2029 for (ifp = idev->addr_list; ifp; ifp=ifp->if_next) {
2030 if (ifp->prefix_len == plen &&

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

2042 return 0;
2043 }
2044 }
2045 read_unlock_bh(&idev->lock);
2046 return -EADDRNOTAVAIL;
2047}
2048
2049
2015 return -ENODEV;
2016
2017 if ((idev = __in6_dev_get(dev)) == NULL)
2018 return -ENXIO;
2019
2020 read_lock_bh(&idev->lock);
2021 for (ifp = idev->addr_list; ifp; ifp=ifp->if_next) {
2022 if (ifp->prefix_len == plen &&

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

2034 return 0;
2035 }
2036 }
2037 read_unlock_bh(&idev->lock);
2038 return -EADDRNOTAVAIL;
2039}
2040
2041
2050int addrconf_add_ifaddr(struct net *net, void __user *arg)
2042int addrconf_add_ifaddr(void __user *arg)
2051{
2052 struct in6_ifreq ireq;
2053 int err;
2054
2055 if (!capable(CAP_NET_ADMIN))
2056 return -EPERM;
2057
2058 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
2059 return -EFAULT;
2060
2061 rtnl_lock();
2043{
2044 struct in6_ifreq ireq;
2045 int err;
2046
2047 if (!capable(CAP_NET_ADMIN))
2048 return -EPERM;
2049
2050 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
2051 return -EFAULT;
2052
2053 rtnl_lock();
2062 err = inet6_addr_add(net, ireq.ifr6_ifindex, &ireq.ifr6_addr,
2063 ireq.ifr6_prefixlen, IFA_F_PERMANENT,
2064 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME);
2054 err = inet6_addr_add(ireq.ifr6_ifindex, &ireq.ifr6_addr, ireq.ifr6_prefixlen,
2055 IFA_F_PERMANENT, INFINITY_LIFE_TIME, INFINITY_LIFE_TIME);
2065 rtnl_unlock();
2066 return err;
2067}
2068
2056 rtnl_unlock();
2057 return err;
2058}
2059
2069int addrconf_del_ifaddr(struct net *net, void __user *arg)
2060int addrconf_del_ifaddr(void __user *arg)
2070{
2071 struct in6_ifreq ireq;
2072 int err;
2073
2074 if (!capable(CAP_NET_ADMIN))
2075 return -EPERM;
2076
2077 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
2078 return -EFAULT;
2079
2080 rtnl_lock();
2061{
2062 struct in6_ifreq ireq;
2063 int err;
2064
2065 if (!capable(CAP_NET_ADMIN))
2066 return -EPERM;
2067
2068 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
2069 return -EFAULT;
2070
2071 rtnl_lock();
2081 err = inet6_addr_del(net, ireq.ifr6_ifindex, &ireq.ifr6_addr,
2082 ireq.ifr6_prefixlen);
2072 err = inet6_addr_del(ireq.ifr6_ifindex, &ireq.ifr6_addr, ireq.ifr6_prefixlen);
2083 rtnl_unlock();
2084 return err;
2085}
2086
2087#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
2088static void sit_add_v4_addrs(struct inet6_dev *idev)
2089{
2090 struct inet6_ifaddr * ifp;
2091 struct in6_addr addr;
2092 struct net_device *dev;
2073 rtnl_unlock();
2074 return err;
2075}
2076
2077#if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
2078static void sit_add_v4_addrs(struct inet6_dev *idev)
2079{
2080 struct inet6_ifaddr * ifp;
2081 struct in6_addr addr;
2082 struct net_device *dev;
2093 struct net *net = dev_net(idev->dev);
2094 int scope;
2095
2096 ASSERT_RTNL();
2097
2098 memset(&addr, 0, sizeof(struct in6_addr));
2099 memcpy(&addr.s6_addr32[3], idev->dev->dev_addr, 4);
2100
2101 if (idev->dev->flags&IFF_POINTOPOINT) {

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

2112 ifp->flags &= ~IFA_F_TENTATIVE;
2113 spin_unlock_bh(&ifp->lock);
2114 ipv6_ifa_notify(RTM_NEWADDR, ifp);
2115 in6_ifa_put(ifp);
2116 }
2117 return;
2118 }
2119
2083 int scope;
2084
2085 ASSERT_RTNL();
2086
2087 memset(&addr, 0, sizeof(struct in6_addr));
2088 memcpy(&addr.s6_addr32[3], idev->dev->dev_addr, 4);
2089
2090 if (idev->dev->flags&IFF_POINTOPOINT) {

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

2101 ifp->flags &= ~IFA_F_TENTATIVE;
2102 spin_unlock_bh(&ifp->lock);
2103 ipv6_ifa_notify(RTM_NEWADDR, ifp);
2104 in6_ifa_put(ifp);
2105 }
2106 return;
2107 }
2108
2120 for_each_netdev(net, dev) {
2109 for_each_netdev(&init_net, dev) {
2121 struct in_device * in_dev = __in_dev_get_rtnl(dev);
2122 if (in_dev && (dev->flags & IFF_UP)) {
2123 struct in_ifaddr * ifa;
2124
2125 int flag = scope;
2126
2127 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
2128 int plen;

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

2275 return 0;
2276 }
2277 return -1;
2278}
2279
2280static void ip6_tnl_add_linklocal(struct inet6_dev *idev)
2281{
2282 struct net_device *link_dev;
2110 struct in_device * in_dev = __in_dev_get_rtnl(dev);
2111 if (in_dev && (dev->flags & IFF_UP)) {
2112 struct in_ifaddr * ifa;
2113
2114 int flag = scope;
2115
2116 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
2117 int plen;

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

2264 return 0;
2265 }
2266 return -1;
2267}
2268
2269static void ip6_tnl_add_linklocal(struct inet6_dev *idev)
2270{
2271 struct net_device *link_dev;
2283 struct net *net = dev_net(idev->dev);
2284
2285 /* first try to inherit the link-local address from the link device */
2286 if (idev->dev->iflink &&
2272
2273 /* first try to inherit the link-local address from the link device */
2274 if (idev->dev->iflink &&
2287 (link_dev = __dev_get_by_index(net, idev->dev->iflink))) {
2275 (link_dev = __dev_get_by_index(&init_net, idev->dev->iflink))) {
2288 if (!ipv6_inherit_linklocal(idev, link_dev))
2289 return;
2290 }
2291 /* then try to inherit it from any device */
2276 if (!ipv6_inherit_linklocal(idev, link_dev))
2277 return;
2278 }
2279 /* then try to inherit it from any device */
2292 for_each_netdev(net, link_dev) {
2280 for_each_netdev(&init_net, link_dev) {
2293 if (!ipv6_inherit_linklocal(idev, link_dev))
2294 return;
2295 }
2296 printk(KERN_DEBUG "init ip6-ip6: add_linklocal failed\n");
2297}
2298
2299/*
2300 * Autoconfigure tunnel with a link-local address so routing protocols,

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

2317static int addrconf_notify(struct notifier_block *this, unsigned long event,
2318 void * data)
2319{
2320 struct net_device *dev = (struct net_device *) data;
2321 struct inet6_dev *idev = __in6_dev_get(dev);
2322 int run_pending = 0;
2323 int err;
2324
2281 if (!ipv6_inherit_linklocal(idev, link_dev))
2282 return;
2283 }
2284 printk(KERN_DEBUG "init ip6-ip6: add_linklocal failed\n");
2285}
2286
2287/*
2288 * Autoconfigure tunnel with a link-local address so routing protocols,

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

2305static int addrconf_notify(struct notifier_block *this, unsigned long event,
2306 void * data)
2307{
2308 struct net_device *dev = (struct net_device *) data;
2309 struct inet6_dev *idev = __in6_dev_get(dev);
2310 int run_pending = 0;
2311 int err;
2312
2313 if (dev->nd_net != &init_net)
2314 return NOTIFY_DONE;
2315
2325 switch(event) {
2326 case NETDEV_REGISTER:
2327 if (!idev && dev->mtu >= IPV6_MIN_MTU) {
2328 idev = ipv6_add_dev(dev);
2329 if (!idev)
2330 return notifier_from_errno(-ENOMEM);
2331 }
2332 break;

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

2456 .notifier_call = addrconf_notify,
2457 .priority = 0
2458};
2459
2460static int addrconf_ifdown(struct net_device *dev, int how)
2461{
2462 struct inet6_dev *idev;
2463 struct inet6_ifaddr *ifa, **bifa;
2316 switch(event) {
2317 case NETDEV_REGISTER:
2318 if (!idev && dev->mtu >= IPV6_MIN_MTU) {
2319 idev = ipv6_add_dev(dev);
2320 if (!idev)
2321 return notifier_from_errno(-ENOMEM);
2322 }
2323 break;

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

2447 .notifier_call = addrconf_notify,
2448 .priority = 0
2449};
2450
2451static int addrconf_ifdown(struct net_device *dev, int how)
2452{
2453 struct inet6_dev *idev;
2454 struct inet6_ifaddr *ifa, **bifa;
2464 struct net *net = dev_net(dev);
2465 int i;
2466
2467 ASSERT_RTNL();
2468
2469 if (dev == init_net.loopback_dev && how == 1)
2470 how = 0;
2471
2455 int i;
2456
2457 ASSERT_RTNL();
2458
2459 if (dev == init_net.loopback_dev && how == 1)
2460 how = 0;
2461
2472 rt6_ifdown(net, dev);
2462 rt6_ifdown(dev);
2473 neigh_ifdown(&nd_tbl, dev);
2474
2475 idev = __in6_dev_get(dev);
2476 if (idev == NULL)
2477 return -ENODEV;
2478
2479 /* Step 1: remove reference to ipv6 device from parent device.
2480 Do not dev_put!
2481 */
2463 neigh_ifdown(&nd_tbl, dev);
2464
2465 idev = __in6_dev_get(dev);
2466 if (idev == NULL)
2467 return -ENODEV;
2468
2469 /* Step 1: remove reference to ipv6 device from parent device.
2470 Do not dev_put!
2471 */
2482 if (how == 1) {
2472 if (how) {
2483 idev->dead = 1;
2484
2485 /* protected by rtnl_lock */
2486 rcu_assign_pointer(dev->ip6_ptr, NULL);
2487
2488 /* Step 1.5: remove snmp6 entry */
2489 snmp6_unregister_dev(idev);
2490

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

2506 bifa = &ifa->lst_next;
2507 }
2508 write_unlock_bh(&addrconf_hash_lock);
2509 }
2510
2511 write_lock_bh(&idev->lock);
2512
2513 /* Step 3: clear flags for stateless addrconf */
2473 idev->dead = 1;
2474
2475 /* protected by rtnl_lock */
2476 rcu_assign_pointer(dev->ip6_ptr, NULL);
2477
2478 /* Step 1.5: remove snmp6 entry */
2479 snmp6_unregister_dev(idev);
2480

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

2496 bifa = &ifa->lst_next;
2497 }
2498 write_unlock_bh(&addrconf_hash_lock);
2499 }
2500
2501 write_lock_bh(&idev->lock);
2502
2503 /* Step 3: clear flags for stateless addrconf */
2514 if (how != 1)
2504 if (!how)
2515 idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY);
2516
2517 /* Step 4: clear address list */
2518#ifdef CONFIG_IPV6_PRIVACY
2505 idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY);
2506
2507 /* Step 4: clear address list */
2508#ifdef CONFIG_IPV6_PRIVACY
2519 if (how == 1 && del_timer(&idev->regen_timer))
2509 if (how && del_timer(&idev->regen_timer))
2520 in6_dev_put(idev);
2521
2522 /* clear tempaddr list */
2523 while ((ifa = idev->tempaddr_list) != NULL) {
2524 idev->tempaddr_list = ifa->tmp_next;
2525 ifa->tmp_next = NULL;
2526 ifa->dead = 1;
2527 write_unlock_bh(&idev->lock);

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

2548 in6_ifa_put(ifa);
2549
2550 write_lock_bh(&idev->lock);
2551 }
2552 write_unlock_bh(&idev->lock);
2553
2554 /* Step 5: Discard multicast list */
2555
2510 in6_dev_put(idev);
2511
2512 /* clear tempaddr list */
2513 while ((ifa = idev->tempaddr_list) != NULL) {
2514 idev->tempaddr_list = ifa->tmp_next;
2515 ifa->tmp_next = NULL;
2516 ifa->dead = 1;
2517 write_unlock_bh(&idev->lock);

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

2538 in6_ifa_put(ifa);
2539
2540 write_lock_bh(&idev->lock);
2541 }
2542 write_unlock_bh(&idev->lock);
2543
2544 /* Step 5: Discard multicast list */
2545
2556 if (how == 1)
2546 if (how)
2557 ipv6_mc_destroy_dev(idev);
2558 else
2559 ipv6_mc_down(idev);
2560
2561 idev->tstamp = jiffies;
2562
2563 /* Shot the device (if unregistered) */
2564
2547 ipv6_mc_destroy_dev(idev);
2548 else
2549 ipv6_mc_down(idev);
2550
2551 idev->tstamp = jiffies;
2552
2553 /* Shot the device (if unregistered) */
2554
2565 if (how == 1) {
2555 if (how) {
2566 addrconf_sysctl_unregister(idev);
2567 neigh_parms_release(&nd_tbl, idev->nd_parms);
2568 neigh_ifdown(&nd_tbl, dev);
2569 in6_dev_put(idev);
2570 }
2571 return 0;
2572}
2573

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

2780 struct seq_net_private p;
2781 int bucket;
2782};
2783
2784static struct inet6_ifaddr *if6_get_first(struct seq_file *seq)
2785{
2786 struct inet6_ifaddr *ifa = NULL;
2787 struct if6_iter_state *state = seq->private;
2556 addrconf_sysctl_unregister(idev);
2557 neigh_parms_release(&nd_tbl, idev->nd_parms);
2558 neigh_ifdown(&nd_tbl, dev);
2559 in6_dev_put(idev);
2560 }
2561 return 0;
2562}
2563

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

2770 struct seq_net_private p;
2771 int bucket;
2772};
2773
2774static struct inet6_ifaddr *if6_get_first(struct seq_file *seq)
2775{
2776 struct inet6_ifaddr *ifa = NULL;
2777 struct if6_iter_state *state = seq->private;
2788 struct net *net = seq_file_net(seq);
2778 struct net *net = state->p.net;
2789
2790 for (state->bucket = 0; state->bucket < IN6_ADDR_HSIZE; ++state->bucket) {
2791 ifa = inet6_addr_lst[state->bucket];
2792
2779
2780 for (state->bucket = 0; state->bucket < IN6_ADDR_HSIZE; ++state->bucket) {
2781 ifa = inet6_addr_lst[state->bucket];
2782
2793 while (ifa && !net_eq(dev_net(ifa->idev->dev), net))
2783 while (ifa && ifa->idev->dev->nd_net != net)
2794 ifa = ifa->lst_next;
2795 if (ifa)
2796 break;
2797 }
2798 return ifa;
2799}
2800
2801static struct inet6_ifaddr *if6_get_next(struct seq_file *seq, struct inet6_ifaddr *ifa)
2802{
2803 struct if6_iter_state *state = seq->private;
2784 ifa = ifa->lst_next;
2785 if (ifa)
2786 break;
2787 }
2788 return ifa;
2789}
2790
2791static struct inet6_ifaddr *if6_get_next(struct seq_file *seq, struct inet6_ifaddr *ifa)
2792{
2793 struct if6_iter_state *state = seq->private;
2804 struct net *net = seq_file_net(seq);
2794 struct net *net = state->p.net;
2805
2806 ifa = ifa->lst_next;
2807try_again:
2808 if (ifa) {
2795
2796 ifa = ifa->lst_next;
2797try_again:
2798 if (ifa) {
2809 if (!net_eq(dev_net(ifa->idev->dev), net)) {
2799 if (ifa->idev->dev->nd_net != net) {
2810 ifa = ifa->lst_next;
2811 goto try_again;
2812 }
2813 }
2814
2815 if (!ifa && ++state->bucket < IN6_ADDR_HSIZE) {
2816 ifa = inet6_addr_lst[state->bucket];
2817 goto try_again;

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

2919/* Check if address is a home address configured on any interface. */
2920int ipv6_chk_home_addr(struct net *net, struct in6_addr *addr)
2921{
2922 int ret = 0;
2923 struct inet6_ifaddr * ifp;
2924 u8 hash = ipv6_addr_hash(addr);
2925 read_lock_bh(&addrconf_hash_lock);
2926 for (ifp = inet6_addr_lst[hash]; ifp; ifp = ifp->lst_next) {
2800 ifa = ifa->lst_next;
2801 goto try_again;
2802 }
2803 }
2804
2805 if (!ifa && ++state->bucket < IN6_ADDR_HSIZE) {
2806 ifa = inet6_addr_lst[state->bucket];
2807 goto try_again;

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

2909/* Check if address is a home address configured on any interface. */
2910int ipv6_chk_home_addr(struct net *net, struct in6_addr *addr)
2911{
2912 int ret = 0;
2913 struct inet6_ifaddr * ifp;
2914 u8 hash = ipv6_addr_hash(addr);
2915 read_lock_bh(&addrconf_hash_lock);
2916 for (ifp = inet6_addr_lst[hash]; ifp; ifp = ifp->lst_next) {
2927 if (!net_eq(dev_net(ifp->idev->dev), net))
2917 if (ifp->idev->dev->nd_net != net)
2928 continue;
2929 if (ipv6_addr_cmp(&ifp->addr, addr) == 0 &&
2930 (ifp->flags & IFA_F_HOMEADDRESS)) {
2931 ret = 1;
2932 break;
2933 }
2934 }
2935 read_unlock_bh(&addrconf_hash_lock);

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

3068 [IFA_ADDRESS] = { .len = sizeof(struct in6_addr) },
3069 [IFA_LOCAL] = { .len = sizeof(struct in6_addr) },
3070 [IFA_CACHEINFO] = { .len = sizeof(struct ifa_cacheinfo) },
3071};
3072
3073static int
3074inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
3075{
2918 continue;
2919 if (ipv6_addr_cmp(&ifp->addr, addr) == 0 &&
2920 (ifp->flags & IFA_F_HOMEADDRESS)) {
2921 ret = 1;
2922 break;
2923 }
2924 }
2925 read_unlock_bh(&addrconf_hash_lock);

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

3058 [IFA_ADDRESS] = { .len = sizeof(struct in6_addr) },
3059 [IFA_LOCAL] = { .len = sizeof(struct in6_addr) },
3060 [IFA_CACHEINFO] = { .len = sizeof(struct ifa_cacheinfo) },
3061};
3062
3063static int
3064inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
3065{
3076 struct net *net = sock_net(skb->sk);
3066 struct net *net = skb->sk->sk_net;
3077 struct ifaddrmsg *ifm;
3078 struct nlattr *tb[IFA_MAX+1];
3079 struct in6_addr *pfx;
3080 int err;
3081
3067 struct ifaddrmsg *ifm;
3068 struct nlattr *tb[IFA_MAX+1];
3069 struct in6_addr *pfx;
3070 int err;
3071
3072 if (net != &init_net)
3073 return -EINVAL;
3074
3082 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
3083 if (err < 0)
3084 return err;
3085
3086 ifm = nlmsg_data(nlh);
3087 pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]);
3088 if (pfx == NULL)
3089 return -EINVAL;
3090
3075 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
3076 if (err < 0)
3077 return err;
3078
3079 ifm = nlmsg_data(nlh);
3080 pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]);
3081 if (pfx == NULL)
3082 return -EINVAL;
3083
3091 return inet6_addr_del(net, ifm->ifa_index, pfx, ifm->ifa_prefixlen);
3084 return inet6_addr_del(ifm->ifa_index, pfx, ifm->ifa_prefixlen);
3092}
3093
3094static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags,
3095 u32 prefered_lft, u32 valid_lft)
3096{
3097 u32 flags = RTF_EXPIRES;
3098
3099 if (!valid_lft || (prefered_lft > valid_lft))

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

3126 addrconf_verify(0);
3127
3128 return 0;
3129}
3130
3131static int
3132inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
3133{
3085}
3086
3087static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags,
3088 u32 prefered_lft, u32 valid_lft)
3089{
3090 u32 flags = RTF_EXPIRES;
3091
3092 if (!valid_lft || (prefered_lft > valid_lft))

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

3119 addrconf_verify(0);
3120
3121 return 0;
3122}
3123
3124static int
3125inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
3126{
3134 struct net *net = sock_net(skb->sk);
3127 struct net *net = skb->sk->sk_net;
3135 struct ifaddrmsg *ifm;
3136 struct nlattr *tb[IFA_MAX+1];
3137 struct in6_addr *pfx;
3138 struct inet6_ifaddr *ifa;
3139 struct net_device *dev;
3140 u32 valid_lft = INFINITY_LIFE_TIME, preferred_lft = INFINITY_LIFE_TIME;
3141 u8 ifa_flags;
3142 int err;
3143
3128 struct ifaddrmsg *ifm;
3129 struct nlattr *tb[IFA_MAX+1];
3130 struct in6_addr *pfx;
3131 struct inet6_ifaddr *ifa;
3132 struct net_device *dev;
3133 u32 valid_lft = INFINITY_LIFE_TIME, preferred_lft = INFINITY_LIFE_TIME;
3134 u8 ifa_flags;
3135 int err;
3136
3137 if (net != &init_net)
3138 return -EINVAL;
3139
3144 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
3145 if (err < 0)
3146 return err;
3147
3148 ifm = nlmsg_data(nlh);
3149 pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]);
3150 if (pfx == NULL)
3151 return -EINVAL;

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

3156 ci = nla_data(tb[IFA_CACHEINFO]);
3157 valid_lft = ci->ifa_valid;
3158 preferred_lft = ci->ifa_prefered;
3159 } else {
3160 preferred_lft = INFINITY_LIFE_TIME;
3161 valid_lft = INFINITY_LIFE_TIME;
3162 }
3163
3140 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
3141 if (err < 0)
3142 return err;
3143
3144 ifm = nlmsg_data(nlh);
3145 pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]);
3146 if (pfx == NULL)
3147 return -EINVAL;

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

3152 ci = nla_data(tb[IFA_CACHEINFO]);
3153 valid_lft = ci->ifa_valid;
3154 preferred_lft = ci->ifa_prefered;
3155 } else {
3156 preferred_lft = INFINITY_LIFE_TIME;
3157 valid_lft = INFINITY_LIFE_TIME;
3158 }
3159
3164 dev = __dev_get_by_index(net, ifm->ifa_index);
3160 dev = __dev_get_by_index(&init_net, ifm->ifa_index);
3165 if (dev == NULL)
3166 return -ENODEV;
3167
3168 /* We ignore other flags so far. */
3169 ifa_flags = ifm->ifa_flags & (IFA_F_NODAD | IFA_F_HOMEADDRESS);
3170
3171 ifa = ipv6_get_ifaddr(net, pfx, dev, 1);
3172 if (ifa == NULL) {
3173 /*
3174 * It would be best to check for !NLM_F_CREATE here but
3175 * userspace alreay relies on not having to provide this.
3176 */
3161 if (dev == NULL)
3162 return -ENODEV;
3163
3164 /* We ignore other flags so far. */
3165 ifa_flags = ifm->ifa_flags & (IFA_F_NODAD | IFA_F_HOMEADDRESS);
3166
3167 ifa = ipv6_get_ifaddr(net, pfx, dev, 1);
3168 if (ifa == NULL) {
3169 /*
3170 * It would be best to check for !NLM_F_CREATE here but
3171 * userspace alreay relies on not having to provide this.
3172 */
3177 return inet6_addr_add(net, ifm->ifa_index, pfx,
3178 ifm->ifa_prefixlen, ifa_flags,
3179 preferred_lft, valid_lft);
3173 return inet6_addr_add(ifm->ifa_index, pfx, ifm->ifa_prefixlen,
3174 ifa_flags, preferred_lft, valid_lft);
3180 }
3181
3182 if (nlh->nlmsg_flags & NLM_F_EXCL ||
3183 !(nlh->nlmsg_flags & NLM_F_REPLACE))
3184 err = -EEXIST;
3185 else
3186 err = inet6_addr_modify(ifa, ifa_flags, preferred_lft, valid_lft);
3187

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

3336 int idx, ip_idx;
3337 int s_idx, s_ip_idx;
3338 int err = 1;
3339 struct net_device *dev;
3340 struct inet6_dev *idev = NULL;
3341 struct inet6_ifaddr *ifa;
3342 struct ifmcaddr6 *ifmca;
3343 struct ifacaddr6 *ifaca;
3175 }
3176
3177 if (nlh->nlmsg_flags & NLM_F_EXCL ||
3178 !(nlh->nlmsg_flags & NLM_F_REPLACE))
3179 err = -EEXIST;
3180 else
3181 err = inet6_addr_modify(ifa, ifa_flags, preferred_lft, valid_lft);
3182

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

3331 int idx, ip_idx;
3332 int s_idx, s_ip_idx;
3333 int err = 1;
3334 struct net_device *dev;
3335 struct inet6_dev *idev = NULL;
3336 struct inet6_ifaddr *ifa;
3337 struct ifmcaddr6 *ifmca;
3338 struct ifacaddr6 *ifaca;
3344 struct net *net = sock_net(skb->sk);
3345
3346 s_idx = cb->args[0];
3347 s_ip_idx = ip_idx = cb->args[1];
3348
3349 idx = 0;
3339
3340 s_idx = cb->args[0];
3341 s_ip_idx = ip_idx = cb->args[1];
3342
3343 idx = 0;
3350 for_each_netdev(net, dev) {
3344 for_each_netdev(&init_net, dev) {
3351 if (idx < s_idx)
3352 goto cont;
3353 if (idx > s_idx)
3354 s_ip_idx = 0;
3355 ip_idx = 0;
3356 if ((idev = in6_dev_get(dev)) == NULL)
3357 goto cont;
3358 read_lock_bh(&idev->lock);

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

3409 }
3410 cb->args[0] = idx;
3411 cb->args[1] = ip_idx;
3412 return skb->len;
3413}
3414
3415static int inet6_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
3416{
3345 if (idx < s_idx)
3346 goto cont;
3347 if (idx > s_idx)
3348 s_ip_idx = 0;
3349 ip_idx = 0;
3350 if ((idev = in6_dev_get(dev)) == NULL)
3351 goto cont;
3352 read_lock_bh(&idev->lock);

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

3403 }
3404 cb->args[0] = idx;
3405 cb->args[1] = ip_idx;
3406 return skb->len;
3407}
3408
3409static int inet6_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
3410{
3411 struct net *net = skb->sk->sk_net;
3417 enum addr_type_t type = UNICAST_ADDR;
3418
3412 enum addr_type_t type = UNICAST_ADDR;
3413
3414 if (net != &init_net)
3415 return 0;
3416
3419 return inet6_dump_addr(skb, cb, type);
3420}
3421
3422static int inet6_dump_ifmcaddr(struct sk_buff *skb, struct netlink_callback *cb)
3423{
3417 return inet6_dump_addr(skb, cb, type);
3418}
3419
3420static int inet6_dump_ifmcaddr(struct sk_buff *skb, struct netlink_callback *cb)
3421{
3422 struct net *net = skb->sk->sk_net;
3424 enum addr_type_t type = MULTICAST_ADDR;
3425
3423 enum addr_type_t type = MULTICAST_ADDR;
3424
3425 if (net != &init_net)
3426 return 0;
3427
3426 return inet6_dump_addr(skb, cb, type);
3427}
3428
3429
3430static int inet6_dump_ifacaddr(struct sk_buff *skb, struct netlink_callback *cb)
3431{
3428 return inet6_dump_addr(skb, cb, type);
3429}
3430
3431
3432static int inet6_dump_ifacaddr(struct sk_buff *skb, struct netlink_callback *cb)
3433{
3434 struct net *net = skb->sk->sk_net;
3432 enum addr_type_t type = ANYCAST_ADDR;
3433
3435 enum addr_type_t type = ANYCAST_ADDR;
3436
3437 if (net != &init_net)
3438 return 0;
3439
3434 return inet6_dump_addr(skb, cb, type);
3435}
3436
3437static int inet6_rtm_getaddr(struct sk_buff *in_skb, struct nlmsghdr* nlh,
3438 void *arg)
3439{
3440 return inet6_dump_addr(skb, cb, type);
3441}
3442
3443static int inet6_rtm_getaddr(struct sk_buff *in_skb, struct nlmsghdr* nlh,
3444 void *arg)
3445{
3440 struct net *net = sock_net(in_skb->sk);
3446 struct net *net = in_skb->sk->sk_net;
3441 struct ifaddrmsg *ifm;
3442 struct nlattr *tb[IFA_MAX+1];
3443 struct in6_addr *addr = NULL;
3444 struct net_device *dev = NULL;
3445 struct inet6_ifaddr *ifa;
3446 struct sk_buff *skb;
3447 int err;
3448
3447 struct ifaddrmsg *ifm;
3448 struct nlattr *tb[IFA_MAX+1];
3449 struct in6_addr *addr = NULL;
3450 struct net_device *dev = NULL;
3451 struct inet6_ifaddr *ifa;
3452 struct sk_buff *skb;
3453 int err;
3454
3455 if (net != &init_net)
3456 return -EINVAL;
3457
3449 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
3450 if (err < 0)
3451 goto errout;
3452
3453 addr = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]);
3454 if (addr == NULL) {
3455 err = -EINVAL;
3456 goto errout;
3457 }
3458
3459 ifm = nlmsg_data(nlh);
3460 if (ifm->ifa_index)
3458 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
3459 if (err < 0)
3460 goto errout;
3461
3462 addr = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]);
3463 if (addr == NULL) {
3464 err = -EINVAL;
3465 goto errout;
3466 }
3467
3468 ifm = nlmsg_data(nlh);
3469 if (ifm->ifa_index)
3461 dev = __dev_get_by_index(net, ifm->ifa_index);
3470 dev = __dev_get_by_index(&init_net, ifm->ifa_index);
3462
3463 if ((ifa = ipv6_get_ifaddr(net, addr, dev, 1)) == NULL) {
3464 err = -EADDRNOTAVAIL;
3465 goto errout;
3466 }
3467
3468 if ((skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_KERNEL)) == NULL) {
3469 err = -ENOBUFS;
3470 goto errout_ifa;
3471 }
3472
3473 err = inet6_fill_ifaddr(skb, ifa, NETLINK_CB(in_skb).pid,
3474 nlh->nlmsg_seq, RTM_NEWADDR, 0);
3475 if (err < 0) {
3476 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */
3477 WARN_ON(err == -EMSGSIZE);
3478 kfree_skb(skb);
3479 goto errout_ifa;
3480 }
3471
3472 if ((ifa = ipv6_get_ifaddr(net, addr, dev, 1)) == NULL) {
3473 err = -EADDRNOTAVAIL;
3474 goto errout;
3475 }
3476
3477 if ((skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_KERNEL)) == NULL) {
3478 err = -ENOBUFS;
3479 goto errout_ifa;
3480 }
3481
3482 err = inet6_fill_ifaddr(skb, ifa, NETLINK_CB(in_skb).pid,
3483 nlh->nlmsg_seq, RTM_NEWADDR, 0);
3484 if (err < 0) {
3485 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */
3486 WARN_ON(err == -EMSGSIZE);
3487 kfree_skb(skb);
3488 goto errout_ifa;
3489 }
3481 err = rtnl_unicast(skb, net, NETLINK_CB(in_skb).pid);
3490 err = rtnl_unicast(skb, &init_net, NETLINK_CB(in_skb).pid);
3482errout_ifa:
3483 in6_ifa_put(ifa);
3484errout:
3485 return err;
3486}
3487
3488static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa)
3489{
3490 struct sk_buff *skb;
3491errout_ifa:
3492 in6_ifa_put(ifa);
3493errout:
3494 return err;
3495}
3496
3497static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa)
3498{
3499 struct sk_buff *skb;
3491 struct net *net = dev_net(ifa->idev->dev);
3492 int err = -ENOBUFS;
3493
3494 skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_ATOMIC);
3495 if (skb == NULL)
3496 goto errout;
3497
3498 err = inet6_fill_ifaddr(skb, ifa, 0, 0, event, 0);
3499 if (err < 0) {
3500 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */
3501 WARN_ON(err == -EMSGSIZE);
3502 kfree_skb(skb);
3503 goto errout;
3504 }
3500 int err = -ENOBUFS;
3501
3502 skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_ATOMIC);
3503 if (skb == NULL)
3504 goto errout;
3505
3506 err = inet6_fill_ifaddr(skb, ifa, 0, 0, event, 0);
3507 if (err < 0) {
3508 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */
3509 WARN_ON(err == -EMSGSIZE);
3510 kfree_skb(skb);
3511 goto errout;
3512 }
3505 err = rtnl_notify(skb, net, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC);
3513 err = rtnl_notify(skb, &init_net, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC);
3506errout:
3507 if (err < 0)
3514errout:
3515 if (err < 0)
3508 rtnl_set_sk_err(net, RTNLGRP_IPV6_IFADDR, err);
3516 rtnl_set_sk_err(&init_net, RTNLGRP_IPV6_IFADDR, err);
3509}
3510
3511static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
3512 __s32 *array, int bytes)
3513{
3514 BUG_ON(bytes < (DEVCONF_MAX * 4));
3515
3516 memset(array, 0, bytes);

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

3659
3660nla_put_failure:
3661 nlmsg_cancel(skb, nlh);
3662 return -EMSGSIZE;
3663}
3664
3665static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
3666{
3517}
3518
3519static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
3520 __s32 *array, int bytes)
3521{
3522 BUG_ON(bytes < (DEVCONF_MAX * 4));
3523
3524 memset(array, 0, bytes);

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

3667
3668nla_put_failure:
3669 nlmsg_cancel(skb, nlh);
3670 return -EMSGSIZE;
3671}
3672
3673static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
3674{
3667 struct net *net = sock_net(skb->sk);
3675 struct net *net = skb->sk->sk_net;
3668 int idx, err;
3669 int s_idx = cb->args[0];
3670 struct net_device *dev;
3671 struct inet6_dev *idev;
3672
3676 int idx, err;
3677 int s_idx = cb->args[0];
3678 struct net_device *dev;
3679 struct inet6_dev *idev;
3680
3681 if (net != &init_net)
3682 return 0;
3683
3673 read_lock(&dev_base_lock);
3674 idx = 0;
3684 read_lock(&dev_base_lock);
3685 idx = 0;
3675 for_each_netdev(net, dev) {
3686 for_each_netdev(&init_net, dev) {
3676 if (idx < s_idx)
3677 goto cont;
3678 if ((idev = in6_dev_get(dev)) == NULL)
3679 goto cont;
3680 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
3681 cb->nlh->nlmsg_seq, RTM_NEWLINK, NLM_F_MULTI);
3682 in6_dev_put(idev);
3683 if (err <= 0)

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

3689 cb->args[0] = idx;
3690
3691 return skb->len;
3692}
3693
3694void inet6_ifinfo_notify(int event, struct inet6_dev *idev)
3695{
3696 struct sk_buff *skb;
3687 if (idx < s_idx)
3688 goto cont;
3689 if ((idev = in6_dev_get(dev)) == NULL)
3690 goto cont;
3691 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
3692 cb->nlh->nlmsg_seq, RTM_NEWLINK, NLM_F_MULTI);
3693 in6_dev_put(idev);
3694 if (err <= 0)

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

3700 cb->args[0] = idx;
3701
3702 return skb->len;
3703}
3704
3705void inet6_ifinfo_notify(int event, struct inet6_dev *idev)
3706{
3707 struct sk_buff *skb;
3697 struct net *net = dev_net(idev->dev);
3698 int err = -ENOBUFS;
3699
3700 skb = nlmsg_new(inet6_if_nlmsg_size(), GFP_ATOMIC);
3701 if (skb == NULL)
3702 goto errout;
3703
3704 err = inet6_fill_ifinfo(skb, idev, 0, 0, event, 0);
3705 if (err < 0) {
3706 /* -EMSGSIZE implies BUG in inet6_if_nlmsg_size() */
3707 WARN_ON(err == -EMSGSIZE);
3708 kfree_skb(skb);
3709 goto errout;
3710 }
3708 int err = -ENOBUFS;
3709
3710 skb = nlmsg_new(inet6_if_nlmsg_size(), GFP_ATOMIC);
3711 if (skb == NULL)
3712 goto errout;
3713
3714 err = inet6_fill_ifinfo(skb, idev, 0, 0, event, 0);
3715 if (err < 0) {
3716 /* -EMSGSIZE implies BUG in inet6_if_nlmsg_size() */
3717 WARN_ON(err == -EMSGSIZE);
3718 kfree_skb(skb);
3719 goto errout;
3720 }
3711 err = rtnl_notify(skb, net, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC);
3721 err = rtnl_notify(skb, &init_net, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC);
3712errout:
3713 if (err < 0)
3722errout:
3723 if (err < 0)
3714 rtnl_set_sk_err(net, RTNLGRP_IPV6_IFADDR, err);
3724 rtnl_set_sk_err(&init_net, RTNLGRP_IPV6_IFADDR, err);
3715}
3716
3717static inline size_t inet6_prefix_nlmsg_size(void)
3718{
3719 return NLMSG_ALIGN(sizeof(struct prefixmsg))
3720 + nla_total_size(sizeof(struct in6_addr))
3721 + nla_total_size(sizeof(struct prefix_cacheinfo));
3722}

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

3759 nlmsg_cancel(skb, nlh);
3760 return -EMSGSIZE;
3761}
3762
3763static void inet6_prefix_notify(int event, struct inet6_dev *idev,
3764 struct prefix_info *pinfo)
3765{
3766 struct sk_buff *skb;
3725}
3726
3727static inline size_t inet6_prefix_nlmsg_size(void)
3728{
3729 return NLMSG_ALIGN(sizeof(struct prefixmsg))
3730 + nla_total_size(sizeof(struct in6_addr))
3731 + nla_total_size(sizeof(struct prefix_cacheinfo));
3732}

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

3769 nlmsg_cancel(skb, nlh);
3770 return -EMSGSIZE;
3771}
3772
3773static void inet6_prefix_notify(int event, struct inet6_dev *idev,
3774 struct prefix_info *pinfo)
3775{
3776 struct sk_buff *skb;
3767 struct net *net = dev_net(idev->dev);
3768 int err = -ENOBUFS;
3769
3770 skb = nlmsg_new(inet6_prefix_nlmsg_size(), GFP_ATOMIC);
3771 if (skb == NULL)
3772 goto errout;
3773
3774 err = inet6_fill_prefix(skb, idev, pinfo, 0, 0, event, 0);
3775 if (err < 0) {
3776 /* -EMSGSIZE implies BUG in inet6_prefix_nlmsg_size() */
3777 WARN_ON(err == -EMSGSIZE);
3778 kfree_skb(skb);
3779 goto errout;
3780 }
3777 int err = -ENOBUFS;
3778
3779 skb = nlmsg_new(inet6_prefix_nlmsg_size(), GFP_ATOMIC);
3780 if (skb == NULL)
3781 goto errout;
3782
3783 err = inet6_fill_prefix(skb, idev, pinfo, 0, 0, event, 0);
3784 if (err < 0) {
3785 /* -EMSGSIZE implies BUG in inet6_prefix_nlmsg_size() */
3786 WARN_ON(err == -EMSGSIZE);
3787 kfree_skb(skb);
3788 goto errout;
3789 }
3781 err = rtnl_notify(skb, net, 0, RTNLGRP_IPV6_PREFIX, NULL, GFP_ATOMIC);
3790 err = rtnl_notify(skb, &init_net, 0, RTNLGRP_IPV6_PREFIX, NULL, GFP_ATOMIC);
3782errout:
3783 if (err < 0)
3791errout:
3792 if (err < 0)
3784 rtnl_set_sk_err(net, RTNLGRP_IPV6_PREFIX, err);
3793 rtnl_set_sk_err(&init_net, RTNLGRP_IPV6_PREFIX, err);
3785}
3786
3787static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
3788{
3789 inet6_ifa_notify(event ? : RTM_NEWADDR, ifp);
3790
3791 switch (event) {
3792 case RTM_NEWADDR:

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

4171}
4172
4173static void addrconf_sysctl_register(struct inet6_dev *idev)
4174{
4175 neigh_sysctl_register(idev->dev, idev->nd_parms, NET_IPV6,
4176 NET_IPV6_NEIGH, "ipv6",
4177 &ndisc_ifinfo_sysctl_change,
4178 NULL);
3794}
3795
3796static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
3797{
3798 inet6_ifa_notify(event ? : RTM_NEWADDR, ifp);
3799
3800 switch (event) {
3801 case RTM_NEWADDR:

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

4180}
4181
4182static void addrconf_sysctl_register(struct inet6_dev *idev)
4183{
4184 neigh_sysctl_register(idev->dev, idev->nd_parms, NET_IPV6,
4185 NET_IPV6_NEIGH, "ipv6",
4186 &ndisc_ifinfo_sysctl_change,
4187 NULL);
4179 __addrconf_sysctl_register(dev_net(idev->dev), idev->dev->name,
4188 __addrconf_sysctl_register(idev->dev->nd_net, idev->dev->name,
4180 idev->dev->ifindex, idev, &idev->cnf);
4181}
4182
4183static void addrconf_sysctl_unregister(struct inet6_dev *idev)
4184{
4185 __addrconf_sysctl_unregister(&idev->cnf);
4186 neigh_sysctl_unregister(idev->nd_parms);
4187}

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

4266
4267int unregister_inet6addr_notifier(struct notifier_block *nb)
4268{
4269 return atomic_notifier_chain_unregister(&inet6addr_chain,nb);
4270}
4271
4272EXPORT_SYMBOL(unregister_inet6addr_notifier);
4273
4189 idev->dev->ifindex, idev, &idev->cnf);
4190}
4191
4192static void addrconf_sysctl_unregister(struct inet6_dev *idev)
4193{
4194 __addrconf_sysctl_unregister(&idev->cnf);
4195 neigh_sysctl_unregister(idev->nd_parms);
4196}

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

4275
4276int unregister_inet6addr_notifier(struct notifier_block *nb)
4277{
4278 return atomic_notifier_chain_unregister(&inet6addr_chain,nb);
4279}
4280
4281EXPORT_SYMBOL(unregister_inet6addr_notifier);
4282
4274
4275static int addrconf_net_init(struct net *net)
4276{
4277 return 0;
4278}
4279
4280static void addrconf_net_exit(struct net *net)
4281{
4282 struct net_device *dev;
4283
4284 rtnl_lock();
4285 /* clean dev list */
4286 for_each_netdev(net, dev) {
4287 if (__in6_dev_get(dev) == NULL)
4288 continue;
4289 addrconf_ifdown(dev, 1);
4290 }
4291 addrconf_ifdown(net->loopback_dev, 2);
4292 rtnl_unlock();
4293}
4294
4295static struct pernet_operations addrconf_net_ops = {
4296 .init = addrconf_net_init,
4297 .exit = addrconf_net_exit,
4298};
4299
4300/*
4301 * Init / cleanup code
4302 */
4303
4304int __init addrconf_init(void)
4305{
4306 int err;
4307

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

4333 */
4334 rtnl_lock();
4335 if (!ipv6_add_dev(init_net.loopback_dev))
4336 err = -ENOMEM;
4337 rtnl_unlock();
4338 if (err)
4339 goto errlo;
4340
4283/*
4284 * Init / cleanup code
4285 */
4286
4287int __init addrconf_init(void)
4288{
4289 int err;
4290

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

4316 */
4317 rtnl_lock();
4318 if (!ipv6_add_dev(init_net.loopback_dev))
4319 err = -ENOMEM;
4320 rtnl_unlock();
4321 if (err)
4322 goto errlo;
4323
4341 err = register_pernet_device(&addrconf_net_ops);
4342 if (err)
4343 return err;
4324 ip6_null_entry.u.dst.dev = init_net.loopback_dev;
4325 ip6_null_entry.rt6i_idev = in6_dev_get(init_net.loopback_dev);
4326#ifdef CONFIG_IPV6_MULTIPLE_TABLES
4327 ip6_prohibit_entry.u.dst.dev = init_net.loopback_dev;
4328 ip6_prohibit_entry.rt6i_idev = in6_dev_get(init_net.loopback_dev);
4329 ip6_blk_hole_entry.u.dst.dev = init_net.loopback_dev;
4330 ip6_blk_hole_entry.rt6i_idev = in6_dev_get(init_net.loopback_dev);
4331#endif
4344
4345 register_netdevice_notifier(&ipv6_dev_notf);
4346
4347 addrconf_verify(0);
4348
4349 err = __rtnl_register(PF_INET6, RTM_GETLINK, NULL, inet6_dump_ifinfo);
4350 if (err < 0)
4351 goto errout;

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

4365errlo:
4366 unregister_pernet_subsys(&addrconf_ops);
4367
4368 return err;
4369}
4370
4371void addrconf_cleanup(void)
4372{
4332
4333 register_netdevice_notifier(&ipv6_dev_notf);
4334
4335 addrconf_verify(0);
4336
4337 err = __rtnl_register(PF_INET6, RTM_GETLINK, NULL, inet6_dump_ifinfo);
4338 if (err < 0)
4339 goto errout;

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

4353errlo:
4354 unregister_pernet_subsys(&addrconf_ops);
4355
4356 return err;
4357}
4358
4359void addrconf_cleanup(void)
4360{
4361 struct net_device *dev;
4373 struct inet6_ifaddr *ifa;
4374 int i;
4375
4376 unregister_netdevice_notifier(&ipv6_dev_notf);
4362 struct inet6_ifaddr *ifa;
4363 int i;
4364
4365 unregister_netdevice_notifier(&ipv6_dev_notf);
4377 unregister_pernet_device(&addrconf_net_ops);
4378
4379 unregister_pernet_subsys(&addrconf_ops);
4380
4381 rtnl_lock();
4382
4383 /*
4366
4367 unregister_pernet_subsys(&addrconf_ops);
4368
4369 rtnl_lock();
4370
4371 /*
4372 * clean dev list.
4373 */
4374
4375 for_each_netdev(&init_net, dev) {
4376 if (__in6_dev_get(dev) == NULL)
4377 continue;
4378 addrconf_ifdown(dev, 1);
4379 }
4380 addrconf_ifdown(init_net.loopback_dev, 2);
4381
4382 /*
4384 * Check hash table.
4385 */
4383 * Check hash table.
4384 */
4385
4386 write_lock_bh(&addrconf_hash_lock);
4387 for (i=0; i < IN6_ADDR_HSIZE; i++) {
4388 for (ifa=inet6_addr_lst[i]; ifa; ) {
4389 struct inet6_ifaddr *bifa;
4390
4391 bifa = ifa;
4392 ifa = ifa->lst_next;
4393 printk(KERN_DEBUG "bug: IPv6 address leakage detected: ifa=%p\n", bifa);
4394 /* Do not free it; something is wrong.
4395 Now we can investigate it with debugger.
4396 */
4397 }
4398 }
4399 write_unlock_bh(&addrconf_hash_lock);
4400
4401 del_timer(&addr_chk_timer);
4386 write_lock_bh(&addrconf_hash_lock);
4387 for (i=0; i < IN6_ADDR_HSIZE; i++) {
4388 for (ifa=inet6_addr_lst[i]; ifa; ) {
4389 struct inet6_ifaddr *bifa;
4390
4391 bifa = ifa;
4392 ifa = ifa->lst_next;
4393 printk(KERN_DEBUG "bug: IPv6 address leakage detected: ifa=%p\n", bifa);
4394 /* Do not free it; something is wrong.
4395 Now we can investigate it with debugger.
4396 */
4397 }
4398 }
4399 write_unlock_bh(&addrconf_hash_lock);
4400
4401 del_timer(&addr_chk_timer);
4402 rtnl_unlock();
4403
4402
4404 unregister_pernet_subsys(&addrconf_net_ops);
4403 rtnl_unlock();
4405}
4404}