Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netns: Use net_eq() to compare net-namespaces for optimization.

Without CONFIG_NET_NS, namespace is always &init_net.
Compiler will be able to omit namespace comparisons with this patch.

Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

YOSHIFUJI Hideaki and committed by
David S. Miller
721499e8 407d819c

+58 -58
+2 -2
net/appletalk/aarp.c
··· 333 333 struct net_device *dev = ptr; 334 334 int ct; 335 335 336 - if (dev_net(dev) != &init_net) 336 + if (!net_eq(dev_net(dev), &init_net)) 337 337 return NOTIFY_DONE; 338 338 339 339 if (event == NETDEV_DOWN) { ··· 716 716 struct atalk_addr sa, *ma, da; 717 717 struct atalk_iface *ifa; 718 718 719 - if (dev_net(dev) != &init_net) 719 + if (!net_eq(dev_net(dev), &init_net)) 720 720 goto out0; 721 721 722 722 /* We only do Ethernet SNAP AARP. */
+3 -3
net/appletalk/ddp.c
··· 648 648 { 649 649 struct net_device *dev = ptr; 650 650 651 - if (dev_net(dev) != &init_net) 651 + if (!net_eq(dev_net(dev), &init_net)) 652 652 return NOTIFY_DONE; 653 653 654 654 if (event == NETDEV_DOWN) ··· 1405 1405 int origlen; 1406 1406 __u16 len_hops; 1407 1407 1408 - if (dev_net(dev) != &init_net) 1408 + if (!net_eq(dev_net(dev), &init_net)) 1409 1409 goto freeit; 1410 1410 1411 1411 /* Don't mangle buffer if shared */ ··· 1493 1493 static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev, 1494 1494 struct packet_type *pt, struct net_device *orig_dev) 1495 1495 { 1496 - if (dev_net(dev) != &init_net) 1496 + if (!net_eq(dev_net(dev), &init_net)) 1497 1497 goto freeit; 1498 1498 1499 1499 /* Expand any short form frames */
+1 -1
net/atm/clip.c
··· 612 612 { 613 613 struct net_device *dev = arg; 614 614 615 - if (dev_net(dev) != &init_net) 615 + if (!net_eq(dev_net(dev), &init_net)) 616 616 return NOTIFY_DONE; 617 617 618 618 if (event == NETDEV_UNREGISTER) {
+1 -1
net/atm/mpc.c
··· 964 964 965 965 dev = (struct net_device *)dev_ptr; 966 966 967 - if (dev_net(dev) != &init_net) 967 + if (!net_eq(dev_net(dev), &init_net)) 968 968 return NOTIFY_DONE; 969 969 970 970 if (dev->name == NULL || strncmp(dev->name, "lec", 3))
+1 -1
net/ax25/af_ax25.c
··· 116 116 { 117 117 struct net_device *dev = (struct net_device *)ptr; 118 118 119 - if (dev_net(dev) != &init_net) 119 + if (!net_eq(dev_net(dev), &init_net)) 120 120 return NOTIFY_DONE; 121 121 122 122 /* Reject non AX.25 devices */
+1 -1
net/ax25/ax25_in.c
··· 451 451 skb->sk = NULL; /* Initially we don't know who it's for */ 452 452 skb->destructor = NULL; /* Who initializes this, dammit?! */ 453 453 454 - if (dev_net(dev) != &init_net) { 454 + if (!net_eq(dev_net(dev), &init_net)) { 455 455 kfree_skb(skb); 456 456 return 0; 457 457 }
+1 -1
net/bridge/br_notify.c
··· 35 35 struct net_bridge_port *p = dev->br_port; 36 36 struct net_bridge *br; 37 37 38 - if (dev_net(dev) != &init_net) 38 + if (!net_eq(dev_net(dev), &init_net)) 39 39 return NOTIFY_DONE; 40 40 41 41 /* not a port of a bridge */
+1 -1
net/bridge/br_stp_bpdu.c
··· 140 140 struct net_bridge *br; 141 141 const unsigned char *buf; 142 142 143 - if (dev_net(dev) != &init_net) 143 + if (!net_eq(dev_net(dev), &init_net)) 144 144 goto err; 145 145 146 146 if (!p)
+2 -2
net/can/af_can.c
··· 615 615 struct can_frame *cf = (struct can_frame *)skb->data; 616 616 int matches; 617 617 618 - if (dev->type != ARPHRD_CAN || dev_net(dev) != &init_net) { 618 + if (dev->type != ARPHRD_CAN || !net_eq(dev_net(dev), &init_net)) { 619 619 kfree_skb(skb); 620 620 return 0; 621 621 } ··· 728 728 struct net_device *dev = (struct net_device *)data; 729 729 struct dev_rcv_lists *d; 730 730 731 - if (dev_net(dev) != &init_net) 731 + if (!net_eq(dev_net(dev), &init_net)) 732 732 return NOTIFY_DONE; 733 733 734 734 if (dev->type != ARPHRD_CAN)
+1 -1
net/can/bcm.c
··· 1303 1303 struct bcm_op *op; 1304 1304 int notify_enodev = 0; 1305 1305 1306 - if (dev_net(dev) != &init_net) 1306 + if (!net_eq(dev_net(dev), &init_net)) 1307 1307 return NOTIFY_DONE; 1308 1308 1309 1309 if (dev->type != ARPHRD_CAN)
+1 -1
net/can/raw.c
··· 210 210 struct raw_sock *ro = container_of(nb, struct raw_sock, notifier); 211 211 struct sock *sk = &ro->sk; 212 212 213 - if (dev_net(dev) != &init_net) 213 + if (!net_eq(dev_net(dev), &init_net)) 214 214 return NOTIFY_DONE; 215 215 216 216 if (dev->type != ARPHRD_CAN)
+1 -1
net/core/pktgen.c
··· 1875 1875 { 1876 1876 struct net_device *dev = ptr; 1877 1877 1878 - if (dev_net(dev) != &init_net) 1878 + if (!net_eq(dev_net(dev), &init_net)) 1879 1879 return NOTIFY_DONE; 1880 1880 1881 1881 /* It is OK that we do not hold the group lock right now,
+1 -1
net/decnet/af_decnet.c
··· 2089 2089 { 2090 2090 struct net_device *dev = (struct net_device *)ptr; 2091 2091 2092 - if (dev_net(dev) != &init_net) 2092 + if (!net_eq(dev_net(dev), &init_net)) 2093 2093 return NOTIFY_DONE; 2094 2094 2095 2095 switch(event) {
+1 -1
net/decnet/dn_route.c
··· 580 580 struct dn_dev *dn = (struct dn_dev *)dev->dn_ptr; 581 581 unsigned char padlen = 0; 582 582 583 - if (dev_net(dev) != &init_net) 583 + if (!net_eq(dev_net(dev), &init_net)) 584 584 goto dump_it; 585 585 586 586 if (dn == NULL)
+2 -2
net/econet/af_econet.c
··· 1062 1062 struct sock *sk; 1063 1063 struct ec_device *edev = dev->ec_ptr; 1064 1064 1065 - if (dev_net(dev) != &init_net) 1065 + if (!net_eq(dev_net(dev), &init_net)) 1066 1066 goto drop; 1067 1067 1068 1068 if (skb->pkt_type == PACKET_OTHERHOST) ··· 1119 1119 struct net_device *dev = (struct net_device *)data; 1120 1120 struct ec_device *edev; 1121 1121 1122 - if (dev_net(dev) != &init_net) 1122 + if (!net_eq(dev_net(dev), &init_net)) 1123 1123 return NOTIFY_DONE; 1124 1124 1125 1125 switch (msg) {
+13 -13
net/ipv4/igmp.c
··· 1196 1196 1197 1197 ASSERT_RTNL(); 1198 1198 1199 - if (dev_net(in_dev->dev) != &init_net) 1199 + if (!net_eq(dev_net(in_dev->dev), &init_net)) 1200 1200 return; 1201 1201 1202 1202 for (im=in_dev->mc_list; im; im=im->next) { ··· 1278 1278 1279 1279 ASSERT_RTNL(); 1280 1280 1281 - if (dev_net(in_dev->dev) != &init_net) 1281 + if (!net_eq(dev_net(in_dev->dev), &init_net)) 1282 1282 return; 1283 1283 1284 1284 for (ip=&in_dev->mc_list; (i=*ip)!=NULL; ip=&i->next) { ··· 1308 1308 1309 1309 ASSERT_RTNL(); 1310 1310 1311 - if (dev_net(in_dev->dev) != &init_net) 1311 + if (!net_eq(dev_net(in_dev->dev), &init_net)) 1312 1312 return; 1313 1313 1314 1314 for (i=in_dev->mc_list; i; i=i->next) ··· 1331 1331 { 1332 1332 ASSERT_RTNL(); 1333 1333 1334 - if (dev_net(in_dev->dev) != &init_net) 1334 + if (!net_eq(dev_net(in_dev->dev), &init_net)) 1335 1335 return; 1336 1336 1337 1337 in_dev->mc_tomb = NULL; ··· 1357 1357 1358 1358 ASSERT_RTNL(); 1359 1359 1360 - if (dev_net(in_dev->dev) != &init_net) 1360 + if (!net_eq(dev_net(in_dev->dev), &init_net)) 1361 1361 return; 1362 1362 1363 1363 ip_mc_inc_group(in_dev, IGMP_ALL_HOSTS); ··· 1376 1376 1377 1377 ASSERT_RTNL(); 1378 1378 1379 - if (dev_net(in_dev->dev) != &init_net) 1379 + if (!net_eq(dev_net(in_dev->dev), &init_net)) 1380 1380 return; 1381 1381 1382 1382 /* Deactivate timers */ ··· 1760 1760 if (!ipv4_is_multicast(addr)) 1761 1761 return -EINVAL; 1762 1762 1763 - if (sock_net(sk) != &init_net) 1763 + if (!net_eq(sock_net(sk), &init_net)) 1764 1764 return -EPROTONOSUPPORT; 1765 1765 1766 1766 rtnl_lock(); ··· 1831 1831 u32 ifindex; 1832 1832 int ret = -EADDRNOTAVAIL; 1833 1833 1834 - if (sock_net(sk) != &init_net) 1834 + if (!net_eq(sock_net(sk), &init_net)) 1835 1835 return -EPROTONOSUPPORT; 1836 1836 1837 1837 rtnl_lock(); ··· 1879 1879 if (!ipv4_is_multicast(addr)) 1880 1880 return -EINVAL; 1881 1881 1882 - if (sock_net(sk) != &init_net) 1882 + if (!net_eq(sock_net(sk), &init_net)) 1883 1883 return -EPROTONOSUPPORT; 1884 1884 1885 1885 rtnl_lock(); ··· 2015 2015 msf->imsf_fmode != MCAST_EXCLUDE) 2016 2016 return -EINVAL; 2017 2017 2018 - if (sock_net(sk) != &init_net) 2018 + if (!net_eq(sock_net(sk), &init_net)) 2019 2019 return -EPROTONOSUPPORT; 2020 2020 2021 2021 rtnl_lock(); ··· 2098 2098 if (!ipv4_is_multicast(addr)) 2099 2099 return -EINVAL; 2100 2100 2101 - if (sock_net(sk) != &init_net) 2101 + if (!net_eq(sock_net(sk), &init_net)) 2102 2102 return -EPROTONOSUPPORT; 2103 2103 2104 2104 rtnl_lock(); ··· 2163 2163 if (!ipv4_is_multicast(addr)) 2164 2164 return -EINVAL; 2165 2165 2166 - if (sock_net(sk) != &init_net) 2166 + if (!net_eq(sock_net(sk), &init_net)) 2167 2167 return -EPROTONOSUPPORT; 2168 2168 2169 2169 rtnl_lock(); ··· 2250 2250 if (inet->mc_list == NULL) 2251 2251 return; 2252 2252 2253 - if (sock_net(sk) != &init_net) 2253 + if (!net_eq(sock_net(sk), &init_net)) 2254 2254 return; 2255 2255 2256 2256 rtnl_lock();
+2 -2
net/ipv4/ipconfig.c
··· 432 432 unsigned char *sha, *tha; /* s for "source", t for "target" */ 433 433 struct ic_device *d; 434 434 435 - if (dev_net(dev) != &init_net) 435 + if (!net_eq(dev_net(dev), &init_net)) 436 436 goto drop; 437 437 438 438 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) ··· 852 852 struct ic_device *d; 853 853 int len, ext_len; 854 854 855 - if (dev_net(dev) != &init_net) 855 + if (!net_eq(dev_net(dev), &init_net)) 856 856 goto drop; 857 857 858 858 /* Perform verifications before taking the lock. */
+1 -1
net/ipv4/ipmr.c
··· 1124 1124 struct vif_device *v; 1125 1125 int ct; 1126 1126 1127 - if (dev_net(dev) != &init_net) 1127 + if (!net_eq(dev_net(dev), &init_net)) 1128 1128 return NOTIFY_DONE; 1129 1129 1130 1130 if (event != NETDEV_UNREGISTER)
+1 -1
net/ipv4/netfilter/ip_queue.c
··· 477 477 { 478 478 struct net_device *dev = ptr; 479 479 480 - if (dev_net(dev) != &init_net) 480 + if (!net_eq(dev_net(dev), &init_net)) 481 481 return NOTIFY_DONE; 482 482 483 483 /* Drop any packets associated with the downed device */
+1 -1
net/ipv4/netfilter/ipt_MASQUERADE.c
··· 120 120 { 121 121 const struct net_device *dev = ptr; 122 122 123 - if (dev_net(dev) != &init_net) 123 + if (!net_eq(dev_net(dev), &init_net)) 124 124 return NOTIFY_DONE; 125 125 126 126 if (event == NETDEV_DOWN) {
+1 -1
net/ipv6/ip6mr.c
··· 935 935 struct mif_device *v; 936 936 int ct; 937 937 938 - if (dev_net(dev) != &init_net) 938 + if (!net_eq(dev_net(dev), &init_net)) 939 939 return NOTIFY_DONE; 940 940 941 941 if (event != NETDEV_UNREGISTER)
+1 -1
net/ipv6/netfilter/ip6_queue.c
··· 480 480 { 481 481 struct net_device *dev = ptr; 482 482 483 - if (dev_net(dev) != &init_net) 483 + if (!net_eq(dev_net(dev), &init_net)) 484 484 return NOTIFY_DONE; 485 485 486 486 /* Drop any packets associated with the downed device */
+1 -1
net/ipv6/proc.c
··· 214 214 if (!idev || !idev->dev) 215 215 return -EINVAL; 216 216 217 - if (dev_net(idev->dev) != &init_net) 217 + if (!net_eq(dev_net(idev->dev), &init_net)) 218 218 return 0; 219 219 220 220 if (!proc_net_devsnmp6)
+2 -2
net/ipx/af_ipx.c
··· 335 335 struct net_device *dev = ptr; 336 336 struct ipx_interface *i, *tmp; 337 337 338 - if (dev_net(dev) != &init_net) 338 + if (!net_eq(dev_net(dev), &init_net)) 339 339 return NOTIFY_DONE; 340 340 341 341 if (event != NETDEV_DOWN && event != NETDEV_UP) ··· 1636 1636 u16 ipx_pktsize; 1637 1637 int rc = 0; 1638 1638 1639 - if (dev_net(dev) != &init_net) 1639 + if (!net_eq(dev_net(dev), &init_net)) 1640 1640 goto drop; 1641 1641 1642 1642 /* Not ours */
+1 -1
net/irda/irlap_frame.c
··· 1326 1326 int command; 1327 1327 __u8 control; 1328 1328 1329 - if (dev_net(dev) != &init_net) 1329 + if (!net_eq(dev_net(dev), &init_net)) 1330 1330 goto out; 1331 1331 1332 1332 /* FIXME: should we get our own field? */
+1 -1
net/llc/llc_input.c
··· 150 150 int (*rcv)(struct sk_buff *, struct net_device *, 151 151 struct packet_type *, struct net_device *); 152 152 153 - if (dev_net(dev) != &init_net) 153 + if (!net_eq(dev_net(dev), &init_net)) 154 154 goto drop; 155 155 156 156 /*
+1 -1
net/netfilter/nf_sockopt.c
··· 65 65 { 66 66 struct nf_sockopt_ops *ops; 67 67 68 - if (sock_net(sk) != &init_net) 68 + if (!net_eq(sock_net(sk), &init_net)) 69 69 return ERR_PTR(-ENOPROTOOPT); 70 70 71 71 if (mutex_lock_interruptible(&nf_sockopt_mutex) != 0)
+1 -1
net/netlabel/netlabel_unlabeled.c
··· 954 954 struct net_device *dev = ptr; 955 955 struct netlbl_unlhsh_iface *iface = NULL; 956 956 957 - if (dev_net(dev) != &init_net) 957 + if (!net_eq(dev_net(dev), &init_net)) 958 958 return NOTIFY_DONE; 959 959 960 960 /* XXX - should this be a check for NETDEV_DOWN or _UNREGISTER? */
+1 -1
net/netrom/af_netrom.c
··· 118 118 { 119 119 struct net_device *dev = (struct net_device *)ptr; 120 120 121 - if (dev_net(dev) != &init_net) 121 + if (!net_eq(dev_net(dev), &init_net)) 122 122 return NOTIFY_DONE; 123 123 124 124 if (event != NETDEV_DOWN)
+1 -1
net/packet/af_packet.c
··· 1677 1677 case SIOCGIFDSTADDR: 1678 1678 case SIOCSIFDSTADDR: 1679 1679 case SIOCSIFFLAGS: 1680 - if (sock_net(sk) != &init_net) 1680 + if (!net_eq(sock_net(sk), &init_net)) 1681 1681 return -ENOIOCTLCMD; 1682 1682 return inet_dgram_ops.ioctl(sock, cmd, arg); 1683 1683 #endif
+1 -1
net/rose/af_rose.c
··· 209 209 { 210 210 struct net_device *dev = (struct net_device *)ptr; 211 211 212 - if (dev_net(dev) != &init_net) 212 + if (!net_eq(dev_net(dev), &init_net)) 213 213 return NOTIFY_DONE; 214 214 215 215 if (event != NETDEV_DOWN)
+1 -1
net/sctp/protocol.c
··· 668 668 struct sctp_sockaddr_entry *temp; 669 669 int found = 0; 670 670 671 - if (dev_net(ifa->ifa_dev->dev) != &init_net) 671 + if (!net_eq(dev_net(ifa->ifa_dev->dev), &init_net)) 672 672 return NOTIFY_DONE; 673 673 674 674 switch (ev) {
+2 -2
net/tipc/eth_media.c
··· 101 101 struct eth_bearer *eb_ptr = (struct eth_bearer *)pt->af_packet_priv; 102 102 u32 size; 103 103 104 - if (dev_net(dev) != &init_net) { 104 + if (!net_eq(dev_net(dev), &init_net)) { 105 105 kfree_skb(buf); 106 106 return 0; 107 107 } ··· 198 198 struct eth_bearer *eb_ptr = &eth_bearers[0]; 199 199 struct eth_bearer *stop = &eth_bearers[MAX_ETH_BEARERS]; 200 200 201 - if (dev_net(dev) != &init_net) 201 + if (!net_eq(dev_net(dev), &init_net)) 202 202 return NOTIFY_DONE; 203 203 204 204 while ((eb_ptr->dev != dev)) {
+1 -1
net/wireless/wext.c
··· 1299 1299 struct sk_buff *skb; 1300 1300 int err; 1301 1301 1302 - if (dev_net(dev) != &init_net) 1302 + if (!net_eq(dev_net(dev), &init_net)) 1303 1303 return; 1304 1304 1305 1305 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
+1 -1
net/x25/af_x25.c
··· 191 191 struct net_device *dev = ptr; 192 192 struct x25_neigh *nb; 193 193 194 - if (dev_net(dev) != &init_net) 194 + if (!net_eq(dev_net(dev), &init_net)) 195 195 return NOTIFY_DONE; 196 196 197 197 if (dev->type == ARPHRD_X25
+1 -1
net/x25/x25_dev.c
··· 95 95 struct sk_buff *nskb; 96 96 struct x25_neigh *nb; 97 97 98 - if (dev_net(dev) != &init_net) 98 + if (!net_eq(dev_net(dev), &init_net)) 99 99 goto drop; 100 100 101 101 nskb = skb_copy(skb, GFP_ATOMIC);
+1 -1
net/xfrm/xfrm_policy.c
··· 2360 2360 { 2361 2361 struct net_device *dev = ptr; 2362 2362 2363 - if (dev_net(dev) != &init_net) 2363 + if (!net_eq(dev_net(dev), &init_net)) 2364 2364 return NOTIFY_DONE; 2365 2365 2366 2366 switch (event) {