aboutsummaryrefslogtreecommitdiffstats
path: root/net/packet/af_packet.c
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2007-09-17 14:56:21 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-10-10 19:49:10 -0400
commit881d966b48b035ab3f3aeaae0f3d3f9b584f45b2 (patch)
treec579d59a4107cbbe9e2b85939bc0d496b815c887 /net/packet/af_packet.c
parentb4b510290b056b86611757ce1175a230f1080f53 (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 'net/packet/af_packet.c')
-rw-r--r--net/packet/af_packet.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index ad0052524e88..745e2cb87c96 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -347,7 +347,7 @@ static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,
347 */ 347 */
348 348
349 saddr->spkt_device[13] = 0; 349 saddr->spkt_device[13] = 0;
350 dev = dev_get_by_name(saddr->spkt_device); 350 dev = dev_get_by_name(&init_net, saddr->spkt_device);
351 err = -ENODEV; 351 err = -ENODEV;
352 if (dev == NULL) 352 if (dev == NULL)
353 goto out_unlock; 353 goto out_unlock;
@@ -742,7 +742,7 @@ static int packet_sendmsg(struct kiocb *iocb, struct socket *sock,
742 } 742 }
743 743
744 744
745 dev = dev_get_by_index(ifindex); 745 dev = dev_get_by_index(&init_net, ifindex);
746 err = -ENXIO; 746 err = -ENXIO;
747 if (dev == NULL) 747 if (dev == NULL)
748 goto out_unlock; 748 goto out_unlock;
@@ -937,7 +937,7 @@ static int packet_bind_spkt(struct socket *sock, struct sockaddr *uaddr, int add
937 return -EINVAL; 937 return -EINVAL;
938 strlcpy(name,uaddr->sa_data,sizeof(name)); 938 strlcpy(name,uaddr->sa_data,sizeof(name));
939 939
940 dev = dev_get_by_name(name); 940 dev = dev_get_by_name(&init_net, name);
941 if (dev) { 941 if (dev) {
942 err = packet_do_bind(sk, dev, pkt_sk(sk)->num); 942 err = packet_do_bind(sk, dev, pkt_sk(sk)->num);
943 dev_put(dev); 943 dev_put(dev);
@@ -964,7 +964,7 @@ static int packet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len
964 964
965 if (sll->sll_ifindex) { 965 if (sll->sll_ifindex) {
966 err = -ENODEV; 966 err = -ENODEV;
967 dev = dev_get_by_index(sll->sll_ifindex); 967 dev = dev_get_by_index(&init_net, sll->sll_ifindex);
968 if (dev == NULL) 968 if (dev == NULL)
969 goto out; 969 goto out;
970 } 970 }
@@ -1161,7 +1161,7 @@ static int packet_getname_spkt(struct socket *sock, struct sockaddr *uaddr,
1161 return -EOPNOTSUPP; 1161 return -EOPNOTSUPP;
1162 1162
1163 uaddr->sa_family = AF_PACKET; 1163 uaddr->sa_family = AF_PACKET;
1164 dev = dev_get_by_index(pkt_sk(sk)->ifindex); 1164 dev = dev_get_by_index(&init_net, pkt_sk(sk)->ifindex);
1165 if (dev) { 1165 if (dev) {
1166 strlcpy(uaddr->sa_data, dev->name, 15); 1166 strlcpy(uaddr->sa_data, dev->name, 15);
1167 dev_put(dev); 1167 dev_put(dev);
@@ -1186,7 +1186,7 @@ static int packet_getname(struct socket *sock, struct sockaddr *uaddr,
1186 sll->sll_family = AF_PACKET; 1186 sll->sll_family = AF_PACKET;
1187 sll->sll_ifindex = po->ifindex; 1187 sll->sll_ifindex = po->ifindex;
1188 sll->sll_protocol = po->num; 1188 sll->sll_protocol = po->num;
1189 dev = dev_get_by_index(po->ifindex); 1189 dev = dev_get_by_index(&init_net, po->ifindex);
1190 if (dev) { 1190 if (dev) {
1191 sll->sll_hatype = dev->type; 1191 sll->sll_hatype = dev->type;
1192 sll->sll_halen = dev->addr_len; 1192 sll->sll_halen = dev->addr_len;
@@ -1238,7 +1238,7 @@ static int packet_mc_add(struct sock *sk, struct packet_mreq_max *mreq)
1238 rtnl_lock(); 1238 rtnl_lock();
1239 1239
1240 err = -ENODEV; 1240 err = -ENODEV;
1241 dev = __dev_get_by_index(mreq->mr_ifindex); 1241 dev = __dev_get_by_index(&init_net, mreq->mr_ifindex);
1242 if (!dev) 1242 if (!dev)
1243 goto done; 1243 goto done;
1244 1244
@@ -1292,7 +1292,7 @@ static int packet_mc_drop(struct sock *sk, struct packet_mreq_max *mreq)
1292 if (--ml->count == 0) { 1292 if (--ml->count == 0) {
1293 struct net_device *dev; 1293 struct net_device *dev;
1294 *mlp = ml->next; 1294 *mlp = ml->next;
1295 dev = dev_get_by_index(ml->ifindex); 1295 dev = dev_get_by_index(&init_net, ml->ifindex);
1296 if (dev) { 1296 if (dev) {
1297 packet_dev_mc(dev, ml, -1); 1297 packet_dev_mc(dev, ml, -1);
1298 dev_put(dev); 1298 dev_put(dev);
@@ -1320,7 +1320,7 @@ static void packet_flush_mclist(struct sock *sk)
1320 struct net_device *dev; 1320 struct net_device *dev;
1321 1321
1322 po->mclist = ml->next; 1322 po->mclist = ml->next;
1323 if ((dev = dev_get_by_index(ml->ifindex)) != NULL) { 1323 if ((dev = dev_get_by_index(&init_net, ml->ifindex)) != NULL) {
1324 packet_dev_mc(dev, ml, -1); 1324 packet_dev_mc(dev, ml, -1);
1325 dev_put(dev); 1325 dev_put(dev);
1326 } 1326 }