Skip to content

Commit

Permalink
[NET] NETNS: Omit net_device->nd_net without CONFIG_NET_NS.
Browse files Browse the repository at this point in the history
Introduce per-net_device inlines: dev_net(), dev_net_set().
Without CONFIG_NET_NS, no namespace other than &init_net exists.
Let's explicitly define them to help compiler optimizations.

Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
  • Loading branch information
yoshfuji committed Mar 25, 2008
1 parent 7cbca67 commit c346dca
Show file tree
Hide file tree
Showing 87 changed files with 251 additions and 228 deletions.
2 changes: 1 addition & 1 deletion arch/ia64/hp/sim/simeth.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ simeth_device_event(struct notifier_block *this,unsigned long event, void *ptr)
return NOTIFY_DONE;
}

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
return NOTIFY_DONE;

if ( event != NETDEV_UP && event != NETDEV_DOWN ) return NOTIFY_DONE;
Expand Down
2 changes: 1 addition & 1 deletion drivers/block/aoe/aoenet.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ aoenet_rcv(struct sk_buff *skb, struct net_device *ifp, struct packet_type *pt,
struct aoe_hdr *h;
u32 n;

if (ifp->nd_net != &init_net)
if (dev_net(ifp) != &init_net)
goto exit;

skb = skb_share_check(skb, GFP_ATOMIC);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/bonding/bond_3ad.c
Original file line number Diff line number Diff line change
Expand Up @@ -2429,7 +2429,7 @@ int bond_3ad_lacpdu_recv(struct sk_buff *skb, struct net_device *dev, struct pac
struct slave *slave = NULL;
int ret = NET_RX_DROP;

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
goto out;

if (!(dev->flags & IFF_MASTER))
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/bonding/bond_alb.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ static int rlb_arp_recv(struct sk_buff *skb, struct net_device *bond_dev, struct
struct arp_pkt *arp = (struct arp_pkt *)skb->data;
int res = NET_RX_DROP;

if (bond_dev->nd_net != &init_net)
if (dev_net(bond_dev) != &init_net)
goto out;

if (!(bond_dev->flags & IFF_MASTER))
Expand Down
6 changes: 3 additions & 3 deletions drivers/net/bonding/bond_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2629,7 +2629,7 @@ static int bond_arp_rcv(struct sk_buff *skb, struct net_device *dev, struct pack
unsigned char *arp_ptr;
__be32 sip, tip;

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
goto out;

if (!(dev->priv_flags & IFF_BONDING) || !(dev->flags & IFF_MASTER))
Expand Down Expand Up @@ -3470,7 +3470,7 @@ static int bond_netdev_event(struct notifier_block *this, unsigned long event, v
{
struct net_device *event_dev = (struct net_device *)ptr;

if (event_dev->nd_net != &init_net)
if (dev_net(event_dev) != &init_net)
return NOTIFY_DONE;

dprintk("event_dev: %s, event: %lx\n",
Expand Down Expand Up @@ -3508,7 +3508,7 @@ static int bond_inetaddr_event(struct notifier_block *this, unsigned long event,
struct bonding *bond, *bond_next;
struct vlan_entry *vlan, *vlan_next;

if (ifa->ifa_dev->dev->nd_net != &init_net)
if (dev_net(ifa->ifa_dev->dev) != &init_net)
return NOTIFY_DONE;

list_for_each_entry_safe(bond, bond_next, &bond_dev_list, bond_list) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/hamradio/bpqether.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ static int bpq_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_ty
struct ethhdr *eth;
struct bpqdev *bpq;

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
goto drop;

if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
Expand Down Expand Up @@ -553,7 +553,7 @@ static int bpq_device_event(struct notifier_block *this,unsigned long event, voi
{
struct net_device *dev = (struct net_device *)ptr;

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
return NOTIFY_DONE;

if (!dev_is_ethdev(dev))
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ static __net_init int loopback_net_init(struct net *net)
if (!dev)
goto out;

dev->nd_net = net;
dev_net_set(dev, net);
err = register_netdev(dev);
if (err)
goto out_free_netdev;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/macvlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ static int macvlan_newlink(struct net_device *dev,
if (!tb[IFLA_LINK])
return -EINVAL;

lowerdev = __dev_get_by_index(dev->nd_net, nla_get_u32(tb[IFLA_LINK]));
lowerdev = __dev_get_by_index(dev_net(dev), nla_get_u32(tb[IFLA_LINK]));
if (lowerdev == NULL)
return -ENODEV;

Expand Down
6 changes: 3 additions & 3 deletions drivers/net/pppoe.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ static int pppoe_device_event(struct notifier_block *this,
{
struct net_device *dev = (struct net_device *) ptr;

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
return NOTIFY_DONE;

/* Only look at sockets that are using this specific device. */
Expand Down Expand Up @@ -392,7 +392,7 @@ static int pppoe_rcv(struct sk_buff *skb,
if (!(skb = skb_share_check(skb, GFP_ATOMIC)))
goto out;

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
goto drop;

if (!pskb_may_pull(skb, sizeof(struct pppoe_hdr)))
Expand Down Expand Up @@ -424,7 +424,7 @@ static int pppoe_disc_rcv(struct sk_buff *skb,
struct pppoe_hdr *ph;
struct pppox_sock *po;

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
goto abort;

if (!pskb_may_pull(skb, sizeof(struct pppoe_hdr)))
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/veth.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ static int veth_newlink(struct net_device *dev,
else
snprintf(ifname, IFNAMSIZ, DRV_NAME "%%d");

peer = rtnl_create_link(dev->nd_net, ifname, &veth_link_ops, tbp);
peer = rtnl_create_link(dev_net(dev), ifname, &veth_link_ops, tbp);
if (IS_ERR(peer))
return PTR_ERR(peer);

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/via-velocity.c
Original file line number Diff line number Diff line change
Expand Up @@ -3464,7 +3464,7 @@ static int velocity_netdev_event(struct notifier_block *nb, unsigned long notifi
struct velocity_info *vptr;
unsigned long flags;

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
return NOTIFY_DONE;

spin_lock_irqsave(&velocity_dev_list_lock, flags);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wan/dlci.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ static int dlci_dev_event(struct notifier_block *unused,
{
struct net_device *dev = (struct net_device *) ptr;

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
return NOTIFY_DONE;

if (event == NETDEV_UNREGISTER) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/wan/hdlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static int hdlc_rcv(struct sk_buff *skb, struct net_device *dev,
{
struct hdlc_device *hdlc = dev_to_hdlc(dev);

if (dev->nd_net != &init_net) {
if (dev_net(dev) != &init_net) {
kfree_skb(skb);
return 0;
}
Expand Down Expand Up @@ -105,7 +105,7 @@ static int hdlc_device_event(struct notifier_block *this, unsigned long event,
unsigned long flags;
int on;

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
return NOTIFY_DONE;

if (dev->get_stats != hdlc_get_stats)
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/wan/lapbether.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static int lapbeth_rcv(struct sk_buff *skb, struct net_device *dev, struct packe
int len, err;
struct lapbethdev *lapbeth;

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
goto drop;

if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
Expand Down Expand Up @@ -393,7 +393,7 @@ static int lapbeth_device_event(struct notifier_block *this,
struct lapbethdev *lapbeth;
struct net_device *dev = ptr;

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
return NOTIFY_DONE;

if (!dev_is_ethdev(dev))
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wan/syncppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ static void sppp_print_bytes (u_char *p, u16 len)

static int sppp_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *p, struct net_device *orig_dev)
{
if (dev->nd_net != &init_net) {
if (dev_net(dev) != &init_net) {
kfree_skb(skb);
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/s390/net/qeth_l3_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3250,7 +3250,7 @@ static int qeth_l3_ip_event(struct notifier_block *this,
struct qeth_ipaddr *addr;
struct qeth_card *card;

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
return NOTIFY_DONE;

QETH_DBF_TEXT(trace, 3, "ipevent");
Expand Down
6 changes: 3 additions & 3 deletions include/linux/inetdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ static inline void ipv4_devconf_setall(struct in_device *in_dev)
ipv4_devconf_set((in_dev), NET_IPV4_CONF_ ## attr, (val))

#define IN_DEV_ANDCONF(in_dev, attr) \
(IPV4_DEVCONF_ALL(in_dev->dev->nd_net, attr) && \
(IPV4_DEVCONF_ALL(dev_net(in_dev->dev), attr) && \
IN_DEV_CONF_GET((in_dev), attr))
#define IN_DEV_ORCONF(in_dev, attr) \
(IPV4_DEVCONF_ALL(in_dev->dev->nd_net, attr) || \
(IPV4_DEVCONF_ALL(dev_net(in_dev->dev), attr) || \
IN_DEV_CONF_GET((in_dev), attr))
#define IN_DEV_MAXCONF(in_dev, attr) \
(max(IPV4_DEVCONF_ALL(in_dev->dev->nd_net, attr), \
(max(IPV4_DEVCONF_ALL(dev_net(in_dev->dev), attr), \
IN_DEV_CONF_GET((in_dev), attr)))

#define IN_DEV_FORWARD(in_dev) IN_DEV_CONF_GET((in_dev), FORWARDING)
Expand Down
25 changes: 24 additions & 1 deletion include/linux/netdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,10 @@ struct net_device
void (*poll_controller)(struct net_device *dev);
#endif

#ifdef CONFIG_NET_NS
/* Network namespace this network device is inside */
struct net *nd_net;
#endif

/* bridge stuff */
struct net_bridge_port *br_port;
Expand Down Expand Up @@ -737,6 +739,27 @@ struct net_device
#define NETDEV_ALIGN 32
#define NETDEV_ALIGN_CONST (NETDEV_ALIGN - 1)

/*
* Net namespace inlines
*/
static inline
struct net *dev_net(const struct net_device *dev)
{
#ifdef CONFIG_NET_NS
return dev->nd_net;
#else
return &init_net;
#endif
}

static inline
void dev_net_set(struct net_device *dev, const struct net *net)
{
#ifdef CONFIG_NET_NS
dev->nd_dev = net;
#endif
}

/**
* netdev_priv - access network device private data
* @dev: network device
Expand Down Expand Up @@ -813,7 +836,7 @@ static inline struct net_device *next_net_device(struct net_device *dev)
struct list_head *lh;
struct net *net;

net = dev->nd_net;
net = dev_net(dev);
lh = dev->dev_list.next;
return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
}
Expand Down
2 changes: 1 addition & 1 deletion net/8021q/vlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
int i, flgs;
struct net_device *vlandev;

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
return NOTIFY_DONE;

if (!grp)
Expand Down
2 changes: 1 addition & 1 deletion net/8021q/vlan_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
struct net_device_stats *stats;
unsigned short vlan_TCI;

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
goto err_free;

skb = skb_share_check(skb, GFP_ATOMIC);
Expand Down
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->nd_net != &init_net)
if (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->nd_net != &init_net)
if (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->nd_net != &init_net)
if (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->nd_net != &init_net)
if (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->nd_net != &init_net)
if (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->nd_net != &init_net)
if (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->nd_net != &init_net)
if (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->nd_net != &init_net)
if (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->nd_net != &init_net) {
if (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 @@ -37,7 +37,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->nd_net != &init_net)
if (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 @@ -142,7 +142,7 @@ int br_stp_rcv(struct sk_buff *skb, struct net_device *dev,
struct net_bridge *br;
const unsigned char *buf;

if (dev->nd_net != &init_net)
if (dev_net(dev) != &init_net)
goto err;

if (!p)
Expand Down
Loading

0 comments on commit c346dca

Please sign in to comment.