Skip to content

Commit

Permalink
netns: Use net_eq() to compare net-namespaces for optimization.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
yoshfuji authored and davem330 committed Jul 20, 2008
1 parent 407d819 commit 721499e
Show file tree
Hide file tree
Showing 38 changed files with 58 additions and 58 deletions.
4 changes: 2 additions & 2 deletions net/appletalk/aarp.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ static int aarp_device_event(struct notifier_block *this, unsigned long event,
struct net_device *dev = ptr;
int ct;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

if (event == NETDEV_DOWN) {
Expand Down Expand Up @@ -716,7 +716,7 @@ static int aarp_rcv(struct sk_buff *skb, struct net_device *dev,
struct atalk_addr sa, *ma, da;
struct atalk_iface *ifa;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
goto out0;

/* We only do Ethernet SNAP AARP. */
Expand Down
6 changes: 3 additions & 3 deletions net/appletalk/ddp.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ static int ddp_device_event(struct notifier_block *this, unsigned long event,
{
struct net_device *dev = ptr;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

if (event == NETDEV_DOWN)
Expand Down Expand Up @@ -1405,7 +1405,7 @@ static int atalk_rcv(struct sk_buff *skb, struct net_device *dev,
int origlen;
__u16 len_hops;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
goto freeit;

/* Don't mangle buffer if shared */
Expand Down Expand Up @@ -1493,7 +1493,7 @@ static int atalk_rcv(struct sk_buff *skb, struct net_device *dev,
static int ltalk_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt, struct net_device *orig_dev)
{
if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
goto freeit;

/* Expand any short form frames */
Expand Down
2 changes: 1 addition & 1 deletion net/atm/clip.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ static int clip_device_event(struct notifier_block *this, unsigned long event,
{
struct net_device *dev = arg;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

if (event == NETDEV_UNREGISTER) {
Expand Down
2 changes: 1 addition & 1 deletion net/atm/mpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ static int mpoa_event_listener(struct notifier_block *mpoa_notifier, unsigned lo

dev = (struct net_device *)dev_ptr;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

if (dev->name == NULL || strncmp(dev->name, "lec", 3))
Expand Down
2 changes: 1 addition & 1 deletion net/ax25/af_ax25.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static int ax25_device_event(struct notifier_block *this, unsigned long event,
{
struct net_device *dev = (struct net_device *)ptr;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

/* Reject non AX.25 devices */
Expand Down
2 changes: 1 addition & 1 deletion net/ax25/ax25_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ int ax25_kiss_rcv(struct sk_buff *skb, struct net_device *dev,
skb->sk = NULL; /* Initially we don't know who it's for */
skb->destructor = NULL; /* Who initializes this, dammit?! */

if (dev_net(dev) != &init_net) {
if (!net_eq(dev_net(dev), &init_net)) {
kfree_skb(skb);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion net/bridge/br_notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static int br_device_event(struct notifier_block *unused, unsigned long event, v
struct net_bridge_port *p = dev->br_port;
struct net_bridge *br;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

/* not a port of a bridge */
Expand Down
2 changes: 1 addition & 1 deletion net/bridge/br_stp_bpdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
struct net_bridge *br;
const unsigned char *buf;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
goto err;

if (!p)
Expand Down
4 changes: 2 additions & 2 deletions net/can/af_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev,
struct can_frame *cf = (struct can_frame *)skb->data;
int matches;

if (dev->type != ARPHRD_CAN || dev_net(dev) != &init_net) {
if (dev->type != ARPHRD_CAN || !net_eq(dev_net(dev), &init_net)) {
kfree_skb(skb);
return 0;
}
Expand Down Expand Up @@ -728,7 +728,7 @@ static int can_notifier(struct notifier_block *nb, unsigned long msg,
struct net_device *dev = (struct net_device *)data;
struct dev_rcv_lists *d;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

if (dev->type != ARPHRD_CAN)
Expand Down
2 changes: 1 addition & 1 deletion net/can/bcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ static int bcm_notifier(struct notifier_block *nb, unsigned long msg,
struct bcm_op *op;
int notify_enodev = 0;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

if (dev->type != ARPHRD_CAN)
Expand Down
2 changes: 1 addition & 1 deletion net/can/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static int raw_notifier(struct notifier_block *nb,
struct raw_sock *ro = container_of(nb, struct raw_sock, notifier);
struct sock *sk = &ro->sk;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

if (dev->type != ARPHRD_CAN)
Expand Down
2 changes: 1 addition & 1 deletion net/core/pktgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ static int pktgen_device_event(struct notifier_block *unused,
{
struct net_device *dev = ptr;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

/* It is OK that we do not hold the group lock right now,
Expand Down
2 changes: 1 addition & 1 deletion net/decnet/af_decnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,7 @@ static int dn_device_event(struct notifier_block *this, unsigned long event,
{
struct net_device *dev = (struct net_device *)ptr;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

switch(event) {
Expand Down
2 changes: 1 addition & 1 deletion net/decnet/dn_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ int dn_route_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type
struct dn_dev *dn = (struct dn_dev *)dev->dn_ptr;
unsigned char padlen = 0;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
goto dump_it;

if (dn == NULL)
Expand Down
4 changes: 2 additions & 2 deletions net/econet/af_econet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ static int econet_rcv(struct sk_buff *skb, struct net_device *dev, struct packet
struct sock *sk;
struct ec_device *edev = dev->ec_ptr;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
goto drop;

if (skb->pkt_type == PACKET_OTHERHOST)
Expand Down Expand Up @@ -1119,7 +1119,7 @@ static int econet_notifier(struct notifier_block *this, unsigned long msg, void
struct net_device *dev = (struct net_device *)data;
struct ec_device *edev;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

switch (msg) {
Expand Down
26 changes: 13 additions & 13 deletions net/ipv4/igmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ void ip_mc_inc_group(struct in_device *in_dev, __be32 addr)

ASSERT_RTNL();

if (dev_net(in_dev->dev) != &init_net)
if (!net_eq(dev_net(in_dev->dev), &init_net))
return;

for (im=in_dev->mc_list; im; im=im->next) {
Expand Down Expand Up @@ -1278,7 +1278,7 @@ void ip_mc_dec_group(struct in_device *in_dev, __be32 addr)

ASSERT_RTNL();

if (dev_net(in_dev->dev) != &init_net)
if (!net_eq(dev_net(in_dev->dev), &init_net))
return;

for (ip=&in_dev->mc_list; (i=*ip)!=NULL; ip=&i->next) {
Expand Down Expand Up @@ -1308,7 +1308,7 @@ void ip_mc_down(struct in_device *in_dev)

ASSERT_RTNL();

if (dev_net(in_dev->dev) != &init_net)
if (!net_eq(dev_net(in_dev->dev), &init_net))
return;

for (i=in_dev->mc_list; i; i=i->next)
Expand All @@ -1331,7 +1331,7 @@ void ip_mc_init_dev(struct in_device *in_dev)
{
ASSERT_RTNL();

if (dev_net(in_dev->dev) != &init_net)
if (!net_eq(dev_net(in_dev->dev), &init_net))
return;

in_dev->mc_tomb = NULL;
Expand All @@ -1357,7 +1357,7 @@ void ip_mc_up(struct in_device *in_dev)

ASSERT_RTNL();

if (dev_net(in_dev->dev) != &init_net)
if (!net_eq(dev_net(in_dev->dev), &init_net))
return;

ip_mc_inc_group(in_dev, IGMP_ALL_HOSTS);
Expand All @@ -1376,7 +1376,7 @@ void ip_mc_destroy_dev(struct in_device *in_dev)

ASSERT_RTNL();

if (dev_net(in_dev->dev) != &init_net)
if (!net_eq(dev_net(in_dev->dev), &init_net))
return;

/* Deactivate timers */
Expand Down Expand Up @@ -1760,7 +1760,7 @@ int ip_mc_join_group(struct sock *sk , struct ip_mreqn *imr)
if (!ipv4_is_multicast(addr))
return -EINVAL;

if (sock_net(sk) != &init_net)
if (!net_eq(sock_net(sk), &init_net))
return -EPROTONOSUPPORT;

rtnl_lock();
Expand Down Expand Up @@ -1831,7 +1831,7 @@ int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr)
u32 ifindex;
int ret = -EADDRNOTAVAIL;

if (sock_net(sk) != &init_net)
if (!net_eq(sock_net(sk), &init_net))
return -EPROTONOSUPPORT;

rtnl_lock();
Expand Down Expand Up @@ -1879,7 +1879,7 @@ int ip_mc_source(int add, int omode, struct sock *sk, struct
if (!ipv4_is_multicast(addr))
return -EINVAL;

if (sock_net(sk) != &init_net)
if (!net_eq(sock_net(sk), &init_net))
return -EPROTONOSUPPORT;

rtnl_lock();
Expand Down Expand Up @@ -2015,7 +2015,7 @@ int ip_mc_msfilter(struct sock *sk, struct ip_msfilter *msf, int ifindex)
msf->imsf_fmode != MCAST_EXCLUDE)
return -EINVAL;

if (sock_net(sk) != &init_net)
if (!net_eq(sock_net(sk), &init_net))
return -EPROTONOSUPPORT;

rtnl_lock();
Expand Down Expand Up @@ -2098,7 +2098,7 @@ int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
if (!ipv4_is_multicast(addr))
return -EINVAL;

if (sock_net(sk) != &init_net)
if (!net_eq(sock_net(sk), &init_net))
return -EPROTONOSUPPORT;

rtnl_lock();
Expand Down Expand Up @@ -2163,7 +2163,7 @@ int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
if (!ipv4_is_multicast(addr))
return -EINVAL;

if (sock_net(sk) != &init_net)
if (!net_eq(sock_net(sk), &init_net))
return -EPROTONOSUPPORT;

rtnl_lock();
Expand Down Expand Up @@ -2250,7 +2250,7 @@ void ip_mc_drop_socket(struct sock *sk)
if (inet->mc_list == NULL)
return;

if (sock_net(sk) != &init_net)
if (!net_eq(sock_net(sk), &init_net))
return;

rtnl_lock();
Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/ipconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ ic_rarp_recv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt
unsigned char *sha, *tha; /* s for "source", t for "target" */
struct ic_device *d;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
goto drop;

if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
Expand Down Expand Up @@ -852,7 +852,7 @@ static int __init ic_bootp_recv(struct sk_buff *skb, struct net_device *dev, str
struct ic_device *d;
int len, ext_len;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
goto drop;

/* Perform verifications before taking the lock. */
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/ipmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ static int ipmr_device_event(struct notifier_block *this, unsigned long event, v
struct vif_device *v;
int ct;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

if (event != NETDEV_UNREGISTER)
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/netfilter/ip_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ ipq_rcv_dev_event(struct notifier_block *this,
{
struct net_device *dev = ptr;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

/* Drop any packets associated with the downed device */
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/netfilter/ipt_MASQUERADE.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ static int masq_device_event(struct notifier_block *this,
{
const struct net_device *dev = ptr;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

if (event == NETDEV_DOWN) {
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/ip6mr.c
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ static int ip6mr_device_event(struct notifier_block *this,
struct mif_device *v;
int ct;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

if (event != NETDEV_UNREGISTER)
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/netfilter/ip6_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ ipq_rcv_dev_event(struct notifier_block *this,
{
struct net_device *dev = ptr;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

/* Drop any packets associated with the downed device */
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ int snmp6_register_dev(struct inet6_dev *idev)
if (!idev || !idev->dev)
return -EINVAL;

if (dev_net(idev->dev) != &init_net)
if (!net_eq(dev_net(idev->dev), &init_net))
return 0;

if (!proc_net_devsnmp6)
Expand Down
4 changes: 2 additions & 2 deletions net/ipx/af_ipx.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ static int ipxitf_device_event(struct notifier_block *notifier,
struct net_device *dev = ptr;
struct ipx_interface *i, *tmp;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;

if (event != NETDEV_DOWN && event != NETDEV_UP)
Expand Down Expand Up @@ -1636,7 +1636,7 @@ static int ipx_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_ty
u16 ipx_pktsize;
int rc = 0;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
goto drop;

/* Not ours */
Expand Down
2 changes: 1 addition & 1 deletion net/irda/irlap_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ int irlap_driver_rcv(struct sk_buff *skb, struct net_device *dev,
int command;
__u8 control;

if (dev_net(dev) != &init_net)
if (!net_eq(dev_net(dev), &init_net))
goto out;

/* FIXME: should we get our own field? */
Expand Down
Loading

0 comments on commit 721499e

Please sign in to comment.