devinet.c (d7f6884ae0ae6e406ec3500fcde16e8f51642460) devinet.c (e5ed639913eea3e4783a550291775ab78dd84966)
1/*
2 * NET3 IP device support routines.
3 *
4 * Version: $Id: devinet.c,v 1.44 2001/10/31 21:55:54 davem Exp $
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version

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

346 rtmsg_ifa(RTM_NEWADDR, ifa);
347 notifier_call_chain(&inetaddr_chain, NETDEV_UP, ifa);
348
349 return 0;
350}
351
352static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa)
353{
1/*
2 * NET3 IP device support routines.
3 *
4 * Version: $Id: devinet.c,v 1.44 2001/10/31 21:55:54 davem Exp $
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version

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

346 rtmsg_ifa(RTM_NEWADDR, ifa);
347 notifier_call_chain(&inetaddr_chain, NETDEV_UP, ifa);
348
349 return 0;
350}
351
352static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa)
353{
354 struct in_device *in_dev = __in_dev_get(dev);
354 struct in_device *in_dev = __in_dev_get_rtnl(dev);
355
356 ASSERT_RTNL();
357
358 if (!in_dev) {
359 in_dev = inetdev_init(dev);
360 if (!in_dev) {
361 inet_free_ifa(ifa);
362 return -ENOBUFS;

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

444 if (ifm->ifa_prefixlen > 32 || !rta[IFA_LOCAL - 1])
445 goto out;
446
447 rc = -ENODEV;
448 if ((dev = __dev_get_by_index(ifm->ifa_index)) == NULL)
449 goto out;
450
451 rc = -ENOBUFS;
355
356 ASSERT_RTNL();
357
358 if (!in_dev) {
359 in_dev = inetdev_init(dev);
360 if (!in_dev) {
361 inet_free_ifa(ifa);
362 return -ENOBUFS;

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

444 if (ifm->ifa_prefixlen > 32 || !rta[IFA_LOCAL - 1])
445 goto out;
446
447 rc = -ENODEV;
448 if ((dev = __dev_get_by_index(ifm->ifa_index)) == NULL)
449 goto out;
450
451 rc = -ENOBUFS;
452 if ((in_dev = __in_dev_get(dev)) == NULL) {
452 if ((in_dev = __in_dev_get_rtnl(dev)) == NULL) {
453 in_dev = inetdev_init(dev);
454 if (!in_dev)
455 goto out;
456 }
457
458 if ((ifa = inet_alloc_ifa()) == NULL)
459 goto out;
460

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

579
580 ret = -ENODEV;
581 if ((dev = __dev_get_by_name(ifr.ifr_name)) == NULL)
582 goto done;
583
584 if (colon)
585 *colon = ':';
586
453 in_dev = inetdev_init(dev);
454 if (!in_dev)
455 goto out;
456 }
457
458 if ((ifa = inet_alloc_ifa()) == NULL)
459 goto out;
460

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

579
580 ret = -ENODEV;
581 if ((dev = __dev_get_by_name(ifr.ifr_name)) == NULL)
582 goto done;
583
584 if (colon)
585 *colon = ':';
586
587 if ((in_dev = __in_dev_get(dev)) != NULL) {
587 if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
588 if (tryaddrmatch) {
589 /* Matthias Andree */
590 /* compare label and address (4.4BSD style) */
591 /* note: we only do this for a limited set of ioctls
592 and only if the original address family was AF_INET.
593 This is checked above. */
594 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
595 ifap = &ifa->ifa_next) {

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

743rarok:
744 rtnl_unlock();
745 ret = copy_to_user(arg, &ifr, sizeof(struct ifreq)) ? -EFAULT : 0;
746 goto out;
747}
748
749static int inet_gifconf(struct net_device *dev, char __user *buf, int len)
750{
588 if (tryaddrmatch) {
589 /* Matthias Andree */
590 /* compare label and address (4.4BSD style) */
591 /* note: we only do this for a limited set of ioctls
592 and only if the original address family was AF_INET.
593 This is checked above. */
594 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
595 ifap = &ifa->ifa_next) {

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

743rarok:
744 rtnl_unlock();
745 ret = copy_to_user(arg, &ifr, sizeof(struct ifreq)) ? -EFAULT : 0;
746 goto out;
747}
748
749static int inet_gifconf(struct net_device *dev, char __user *buf, int len)
750{
751 struct in_device *in_dev = __in_dev_get(dev);
751 struct in_device *in_dev = __in_dev_get_rtnl(dev);
752 struct in_ifaddr *ifa;
753 struct ifreq ifr;
754 int done = 0;
755
756 if (!in_dev || (ifa = in_dev->ifa_list) == NULL)
757 goto out;
758
759 for (; ifa; ifa = ifa->ifa_next) {

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

786}
787
788u32 inet_select_addr(const struct net_device *dev, u32 dst, int scope)
789{
790 u32 addr = 0;
791 struct in_device *in_dev;
792
793 rcu_read_lock();
752 struct in_ifaddr *ifa;
753 struct ifreq ifr;
754 int done = 0;
755
756 if (!in_dev || (ifa = in_dev->ifa_list) == NULL)
757 goto out;
758
759 for (; ifa; ifa = ifa->ifa_next) {

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

786}
787
788u32 inet_select_addr(const struct net_device *dev, u32 dst, int scope)
789{
790 u32 addr = 0;
791 struct in_device *in_dev;
792
793 rcu_read_lock();
794 in_dev = __in_dev_get(dev);
794 in_dev = __in_dev_get_rcu(dev);
795 if (!in_dev)
796 goto no_in_dev;
797
798 for_primary_ifa(in_dev) {
799 if (ifa->ifa_scope > scope)
800 continue;
801 if (!dst || inet_ifa_match(dst, ifa)) {
802 addr = ifa->ifa_local;

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

813
814 /* Not loopback addresses on loopback should be preferred
815 in this case. It is importnat that lo is the first interface
816 in dev_base list.
817 */
818 read_lock(&dev_base_lock);
819 rcu_read_lock();
820 for (dev = dev_base; dev; dev = dev->next) {
795 if (!in_dev)
796 goto no_in_dev;
797
798 for_primary_ifa(in_dev) {
799 if (ifa->ifa_scope > scope)
800 continue;
801 if (!dst || inet_ifa_match(dst, ifa)) {
802 addr = ifa->ifa_local;

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

813
814 /* Not loopback addresses on loopback should be preferred
815 in this case. It is importnat that lo is the first interface
816 in dev_base list.
817 */
818 read_lock(&dev_base_lock);
819 rcu_read_lock();
820 for (dev = dev_base; dev; dev = dev->next) {
821 if ((in_dev = __in_dev_get(dev)) == NULL)
821 if ((in_dev = __in_dev_get_rcu(dev)) == NULL)
822 continue;
823
824 for_primary_ifa(in_dev) {
825 if (ifa->ifa_scope != RT_SCOPE_LINK &&
826 ifa->ifa_scope <= scope) {
827 addr = ifa->ifa_local;
828 goto out_unlock_both;
829 }

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

882 */
883u32 inet_confirm_addr(const struct net_device *dev, u32 dst, u32 local, int scope)
884{
885 u32 addr = 0;
886 struct in_device *in_dev;
887
888 if (dev) {
889 rcu_read_lock();
822 continue;
823
824 for_primary_ifa(in_dev) {
825 if (ifa->ifa_scope != RT_SCOPE_LINK &&
826 ifa->ifa_scope <= scope) {
827 addr = ifa->ifa_local;
828 goto out_unlock_both;
829 }

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

882 */
883u32 inet_confirm_addr(const struct net_device *dev, u32 dst, u32 local, int scope)
884{
885 u32 addr = 0;
886 struct in_device *in_dev;
887
888 if (dev) {
889 rcu_read_lock();
890 if ((in_dev = __in_dev_get(dev)))
890 if ((in_dev = __in_dev_get_rcu(dev)))
891 addr = confirm_addr_indev(in_dev, dst, local, scope);
892 rcu_read_unlock();
893
894 return addr;
895 }
896
897 read_lock(&dev_base_lock);
898 rcu_read_lock();
899 for (dev = dev_base; dev; dev = dev->next) {
891 addr = confirm_addr_indev(in_dev, dst, local, scope);
892 rcu_read_unlock();
893
894 return addr;
895 }
896
897 read_lock(&dev_base_lock);
898 rcu_read_lock();
899 for (dev = dev_base; dev; dev = dev->next) {
900 if ((in_dev = __in_dev_get(dev))) {
900 if ((in_dev = __in_dev_get_rcu(dev))) {
901 addr = confirm_addr_indev(in_dev, dst, local, scope);
902 if (addr)
903 break;
904 }
905 }
906 rcu_read_unlock();
907 read_unlock(&dev_base_lock);
908

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

952}
953
954/* Called only under RTNL semaphore */
955
956static int inetdev_event(struct notifier_block *this, unsigned long event,
957 void *ptr)
958{
959 struct net_device *dev = ptr;
901 addr = confirm_addr_indev(in_dev, dst, local, scope);
902 if (addr)
903 break;
904 }
905 }
906 rcu_read_unlock();
907 read_unlock(&dev_base_lock);
908

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

952}
953
954/* Called only under RTNL semaphore */
955
956static int inetdev_event(struct notifier_block *this, unsigned long event,
957 void *ptr)
958{
959 struct net_device *dev = ptr;
960 struct in_device *in_dev = __in_dev_get(dev);
960 struct in_device *in_dev = __in_dev_get_rtnl(dev);
961
962 ASSERT_RTNL();
963
964 if (!in_dev) {
965 if (event == NETDEV_REGISTER && dev == &loopback_dev) {
966 in_dev = inetdev_init(dev);
967 if (!in_dev)
968 panic("devinet: Failed to create loopback\n");

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

1073 s_ip_idx = ip_idx = cb->args[1];
1074 read_lock(&dev_base_lock);
1075 for (dev = dev_base, idx = 0; dev; dev = dev->next, idx++) {
1076 if (idx < s_idx)
1077 continue;
1078 if (idx > s_idx)
1079 s_ip_idx = 0;
1080 rcu_read_lock();
961
962 ASSERT_RTNL();
963
964 if (!in_dev) {
965 if (event == NETDEV_REGISTER && dev == &loopback_dev) {
966 in_dev = inetdev_init(dev);
967 if (!in_dev)
968 panic("devinet: Failed to create loopback\n");

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

1073 s_ip_idx = ip_idx = cb->args[1];
1074 read_lock(&dev_base_lock);
1075 for (dev = dev_base, idx = 0; dev; dev = dev->next, idx++) {
1076 if (idx < s_idx)
1077 continue;
1078 if (idx > s_idx)
1079 s_ip_idx = 0;
1080 rcu_read_lock();
1081 if ((in_dev = __in_dev_get(dev)) == NULL) {
1081 if ((in_dev = __in_dev_get_rcu(dev)) == NULL) {
1082 rcu_read_unlock();
1083 continue;
1084 }
1085
1086 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
1087 ifa = ifa->ifa_next, ip_idx++) {
1088 if (ip_idx < s_ip_idx)
1089 continue;

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

1144
1145 ipv4_devconf.accept_redirects = !on;
1146 ipv4_devconf_dflt.forwarding = on;
1147
1148 read_lock(&dev_base_lock);
1149 for (dev = dev_base; dev; dev = dev->next) {
1150 struct in_device *in_dev;
1151 rcu_read_lock();
1082 rcu_read_unlock();
1083 continue;
1084 }
1085
1086 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
1087 ifa = ifa->ifa_next, ip_idx++) {
1088 if (ip_idx < s_ip_idx)
1089 continue;

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

1144
1145 ipv4_devconf.accept_redirects = !on;
1146 ipv4_devconf_dflt.forwarding = on;
1147
1148 read_lock(&dev_base_lock);
1149 for (dev = dev_base; dev; dev = dev->next) {
1150 struct in_device *in_dev;
1151 rcu_read_lock();
1152 in_dev = __in_dev_get(dev);
1152 in_dev = __in_dev_get_rcu(dev);
1153 if (in_dev)
1154 in_dev->cnf.forwarding = on;
1155 rcu_read_unlock();
1156 }
1157 read_unlock(&dev_base_lock);
1158
1159 rt_cache_flush(0);
1160}

--- 371 unchanged lines hidden ---
1153 if (in_dev)
1154 in_dev->cnf.forwarding = on;
1155 rcu_read_unlock();
1156 }
1157 read_unlock(&dev_base_lock);
1158
1159 rt_cache_flush(0);
1160}

--- 371 unchanged lines hidden ---