diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2007-09-17 14:56:21 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-10-10 19:49:10 -0400 |
commit | 881d966b48b035ab3f3aeaae0f3d3f9b584f45b2 (patch) | |
tree | c579d59a4107cbbe9e2b85939bc0d496b815c887 /include/linux/netdevice.h | |
parent | b4b510290b056b86611757ce1175a230f1080f53 (diff) |
[NET]: Make the device list and device lookups per namespace.
This patch makes most of the generic device layer network
namespace safe. This patch makes dev_base_head a
network namespace variable, and then it picks up
a few associated variables. The functions:
dev_getbyhwaddr
dev_getfirsthwbytype
dev_get_by_flags
dev_get_by_name
__dev_get_by_name
dev_get_by_index
__dev_get_by_index
dev_ioctl
dev_ethtool
dev_load
wireless_process_ioctl
were modified to take a network namespace argument, and
deal with it.
vlan_ioctl_set and brioctl_set were modified so their
hooks will receive a network namespace argument.
So basically anthing in the core of the network stack that was
affected to by the change of dev_base was modified to handle
multiple network namespaces. The rest of the network stack was
simply modified to explicitly use &init_net the initial network
namespace. This can be fixed when those components of the network
stack are modified to handle multiple network namespaces.
For now the ifindex generator is left global.
Fundametally ifindex numbers are per namespace, or else
we will have corner case problems with migration when
we get that far.
At the same time there are assumptions in the network stack
that the ifindex of a network device won't change. Making
the ifindex number global seems a good compromise until
the network stack can cope with ifindex changes when
you change namespaces, and the like.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/netdevice.h')
-rw-r--r-- | include/linux/netdevice.h | 66 |
1 files changed, 35 insertions, 31 deletions
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index dc3c15b726b..7353b3e1f4f 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h | |||
@@ -741,44 +741,48 @@ struct packet_type { | |||
741 | #include <linux/notifier.h> | 741 | #include <linux/notifier.h> |
742 | 742 | ||
743 | extern struct net_device loopback_dev; /* The loopback */ | 743 | extern struct net_device loopback_dev; /* The loopback */ |
744 | extern struct list_head dev_base_head; /* All devices */ | ||
745 | extern rwlock_t dev_base_lock; /* Device list lock */ | 744 | extern rwlock_t dev_base_lock; /* Device list lock */ |
746 | 745 | ||
747 | #define for_each_netdev(d) \ | ||
748 | list_for_each_entry(d, &dev_base_head, dev_list) | ||
749 | #define for_each_netdev_safe(d, n) \ | ||
750 | list_for_each_entry_safe(d, n, &dev_base_head, dev_list) | ||
751 | #define for_each_netdev_continue(d) \ | ||
752 | list_for_each_entry_continue(d, &dev_base_head, dev_list) | ||
753 | #define net_device_entry(lh) list_entry(lh, struct net_device, dev_list) | ||
754 | |||
755 | static inline struct net_device *next_net_device(struct net_device *dev) | ||
756 | { | ||
757 | struct list_head *lh; | ||
758 | 746 | ||
759 | lh = dev->dev_list.next; | 747 | #define for_each_netdev(net, d) \ |
760 | return lh == &dev_base_head ? NULL : net_device_entry(lh); | 748 | list_for_each_entry(d, &(net)->dev_base_head, dev_list) |
761 | } | 749 | #define for_each_netdev_safe(net, d, n) \ |
750 | list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list) | ||
751 | #define for_each_netdev_continue(net, d) \ | ||
752 | list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list) | ||
753 | #define net_device_entry(lh) list_entry(lh, struct net_device, dev_list) | ||
762 | 754 | ||
763 | static inline struct net_device *first_net_device(void) | 755 | #define next_net_device(d) \ |
764 | { | 756 | ({ \ |
765 | return list_empty(&dev_base_head) ? NULL : | 757 | struct net_device *dev = d; \ |
766 | net_device_entry(dev_base_head.next); | 758 | struct list_head *lh; \ |
767 | } | 759 | struct net *net; \ |
760 | \ | ||
761 | net = dev->nd_net; \ | ||
762 | lh = dev->dev_list.next; \ | ||
763 | lh == &net->dev_base_head ? NULL : net_device_entry(lh); \ | ||
764 | }) | ||
765 | |||
766 | #define first_net_device(N) \ | ||
767 | ({ \ | ||
768 | struct net *NET = (N); \ | ||
769 | list_empty(&NET->dev_base_head) ? NULL : \ | ||
770 | net_device_entry(NET->dev_base_head.next); \ | ||
771 | }) | ||
768 | 772 | ||
769 | extern int netdev_boot_setup_check(struct net_device *dev); | 773 | extern int netdev_boot_setup_check(struct net_device *dev); |
770 | extern unsigned long netdev_boot_base(const char *prefix, int unit); | 774 | extern unsigned long netdev_boot_base(const char *prefix, int unit); |
771 | extern struct net_device *dev_getbyhwaddr(unsigned short type, char *hwaddr); | 775 | extern struct net_device *dev_getbyhwaddr(struct net *net, unsigned short type, char *hwaddr); |
772 | extern struct net_device *dev_getfirstbyhwtype(unsigned short type); | 776 | extern struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type); |
773 | extern struct net_device *__dev_getfirstbyhwtype(unsigned short type); | 777 | extern struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type); |
774 | extern void dev_add_pack(struct packet_type *pt); | 778 | extern void dev_add_pack(struct packet_type *pt); |
775 | extern void dev_remove_pack(struct packet_type *pt); | 779 | extern void dev_remove_pack(struct packet_type *pt); |
776 | extern void __dev_remove_pack(struct packet_type *pt); | 780 | extern void __dev_remove_pack(struct packet_type *pt); |
777 | 781 | ||
778 | extern struct net_device *dev_get_by_flags(unsigned short flags, | 782 | extern struct net_device *dev_get_by_flags(struct net *net, unsigned short flags, |
779 | unsigned short mask); | 783 | unsigned short mask); |
780 | extern struct net_device *dev_get_by_name(const char *name); | 784 | extern struct net_device *dev_get_by_name(struct net *net, const char *name); |
781 | extern struct net_device *__dev_get_by_name(const char *name); | 785 | extern struct net_device *__dev_get_by_name(struct net *net, const char *name); |
782 | extern int dev_alloc_name(struct net_device *dev, const char *name); | 786 | extern int dev_alloc_name(struct net_device *dev, const char *name); |
783 | extern int dev_open(struct net_device *dev); | 787 | extern int dev_open(struct net_device *dev); |
784 | extern int dev_close(struct net_device *dev); | 788 | extern int dev_close(struct net_device *dev); |
@@ -790,8 +794,8 @@ extern void synchronize_net(void); | |||
790 | extern int register_netdevice_notifier(struct notifier_block *nb); | 794 | extern int register_netdevice_notifier(struct notifier_block *nb); |
791 | extern int unregister_netdevice_notifier(struct notifier_block *nb); | 795 | extern int unregister_netdevice_notifier(struct notifier_block *nb); |
792 | extern int call_netdevice_notifiers(unsigned long val, void *v); | 796 | extern int call_netdevice_notifiers(unsigned long val, void *v); |
793 | extern struct net_device *dev_get_by_index(int ifindex); | 797 | extern struct net_device *dev_get_by_index(struct net *net, int ifindex); |
794 | extern struct net_device *__dev_get_by_index(int ifindex); | 798 | extern struct net_device *__dev_get_by_index(struct net *net, int ifindex); |
795 | extern int dev_restart(struct net_device *dev); | 799 | extern int dev_restart(struct net_device *dev); |
796 | #ifdef CONFIG_NETPOLL_TRAP | 800 | #ifdef CONFIG_NETPOLL_TRAP |
797 | extern int netpoll_trap(void); | 801 | extern int netpoll_trap(void); |
@@ -1007,8 +1011,8 @@ extern int netif_rx_ni(struct sk_buff *skb); | |||
1007 | #define HAVE_NETIF_RECEIVE_SKB 1 | 1011 | #define HAVE_NETIF_RECEIVE_SKB 1 |
1008 | extern int netif_receive_skb(struct sk_buff *skb); | 1012 | extern int netif_receive_skb(struct sk_buff *skb); |
1009 | extern int dev_valid_name(const char *name); | 1013 | extern int dev_valid_name(const char *name); |
1010 | extern int dev_ioctl(unsigned int cmd, void __user *); | 1014 | extern int dev_ioctl(struct net *net, unsigned int cmd, void __user *); |
1011 | extern int dev_ethtool(struct ifreq *); | 1015 | extern int dev_ethtool(struct net *net, struct ifreq *); |
1012 | extern unsigned dev_get_flags(const struct net_device *); | 1016 | extern unsigned dev_get_flags(const struct net_device *); |
1013 | extern int dev_change_flags(struct net_device *, unsigned); | 1017 | extern int dev_change_flags(struct net_device *, unsigned); |
1014 | extern int dev_change_name(struct net_device *, char *); | 1018 | extern int dev_change_name(struct net_device *, char *); |
@@ -1327,7 +1331,7 @@ extern void dev_set_allmulti(struct net_device *dev, int inc); | |||
1327 | extern void netdev_state_change(struct net_device *dev); | 1331 | extern void netdev_state_change(struct net_device *dev); |
1328 | extern void netdev_features_change(struct net_device *dev); | 1332 | extern void netdev_features_change(struct net_device *dev); |
1329 | /* Load a device via the kmod */ | 1333 | /* Load a device via the kmod */ |
1330 | extern void dev_load(const char *name); | 1334 | extern void dev_load(struct net *net, const char *name); |
1331 | extern void dev_mcast_init(void); | 1335 | extern void dev_mcast_init(void); |
1332 | extern int netdev_max_backlog; | 1336 | extern int netdev_max_backlog; |
1333 | extern int weight_p; | 1337 | extern int weight_p; |