Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 878628fb authored by YOSHIFUJI Hideaki's avatar YOSHIFUJI Hideaki
Browse files

[NET] NETNS: Omit namespace comparision without CONFIG_NET_NS.



Introduce an inline net_eq() to compare two namespaces.
Without CONFIG_NET_NS, since no namespace other than &init_net
exists, it is always 1.

We do not need to convert 1) inline vs inline and
2) inline vs &init_net comparisons.

Signed-off-by: default avatarYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
parent 57da52c1
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -118,6 +118,12 @@ static inline void release_net(struct net *net)
{
{
	atomic_dec(&net->use_count);
	atomic_dec(&net->use_count);
}
}

static inline
int net_eq(const struct net *net1, const struct net *net2)
{
	return net1 == net2;
}
#else
#else
static inline struct net *get_net(struct net *net)
static inline struct net *get_net(struct net *net)
{
{
@@ -141,6 +147,12 @@ static inline struct net *maybe_get_net(struct net *net)
{
{
	return net;
	return net;
}
}

static inline
int net_eq(const struct net *net1, const struct net *net2)
{
	return 1;
}
#endif
#endif


#define for_each_net(VAR)				\
#define for_each_net(VAR)				\
+1 −1
Original line number Original line Diff line number Diff line
@@ -4136,7 +4136,7 @@ int dev_change_net_namespace(struct net_device *dev, struct net *net, const char


	/* Get out if there is nothing todo */
	/* Get out if there is nothing todo */
	err = 0;
	err = 0;
	if (dev_net(dev) == net)
	if (net_eq(dev_net(dev), net))
		goto out;
		goto out;


	/* Pick the destination device name, and ensure
	/* Pick the destination device name, and ensure
+9 −9
Original line number Original line Diff line number Diff line
@@ -388,7 +388,7 @@ struct neighbour *neigh_lookup_nodev(struct neigh_table *tbl, struct net *net,
	hash_val = tbl->hash(pkey, NULL);
	hash_val = tbl->hash(pkey, NULL);
	for (n = tbl->hash_buckets[hash_val & tbl->hash_mask]; n; n = n->next) {
	for (n = tbl->hash_buckets[hash_val & tbl->hash_mask]; n; n = n->next) {
		if (!memcmp(n->primary_key, pkey, key_len) &&
		if (!memcmp(n->primary_key, pkey, key_len) &&
		    dev_net(n->dev) == net) {
		    net_eq(dev_net(n->dev), net)) {
			neigh_hold(n);
			neigh_hold(n);
			NEIGH_CACHE_STAT_INC(tbl, hits);
			NEIGH_CACHE_STAT_INC(tbl, hits);
			break;
			break;
@@ -483,7 +483,7 @@ struct pneigh_entry * pneigh_lookup(struct neigh_table *tbl,


	for (n = tbl->phash_buckets[hash_val]; n; n = n->next) {
	for (n = tbl->phash_buckets[hash_val]; n; n = n->next) {
		if (!memcmp(n->key, pkey, key_len) &&
		if (!memcmp(n->key, pkey, key_len) &&
		    (pneigh_net(n) == net) &&
		    net_eq(pneigh_net(n), net) &&
		    (n->dev == dev || !n->dev)) {
		    (n->dev == dev || !n->dev)) {
			read_unlock_bh(&tbl->lock);
			read_unlock_bh(&tbl->lock);
			goto out;
			goto out;
@@ -542,7 +542,7 @@ int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *pkey,
	for (np = &tbl->phash_buckets[hash_val]; (n = *np) != NULL;
	for (np = &tbl->phash_buckets[hash_val]; (n = *np) != NULL;
	     np = &n->next) {
	     np = &n->next) {
		if (!memcmp(n->key, pkey, key_len) && n->dev == dev &&
		if (!memcmp(n->key, pkey, key_len) && n->dev == dev &&
		    (pneigh_net(n) == net)) {
		    net_eq(pneigh_net(n), net)) {
			*np = n->next;
			*np = n->next;
			write_unlock_bh(&tbl->lock);
			write_unlock_bh(&tbl->lock);
			if (tbl->pdestructor)
			if (tbl->pdestructor)
@@ -1286,7 +1286,7 @@ static inline struct neigh_parms *lookup_neigh_params(struct neigh_table *tbl,
	struct neigh_parms *p;
	struct neigh_parms *p;


	for (p = &tbl->parms; p; p = p->next) {
	for (p = &tbl->parms; p; p = p->next) {
		if ((p->dev && p->dev->ifindex == ifindex && neigh_parms_net(p) == net) ||
		if ((p->dev && p->dev->ifindex == ifindex && net_eq(neigh_parms_net(p), net)) ||
		    (!p->dev && !ifindex))
		    (!p->dev && !ifindex))
			return p;
			return p;
	}
	}
@@ -1964,7 +1964,7 @@ static int neightbl_dump_info(struct sk_buff *skb, struct netlink_callback *cb)
			break;
			break;


		for (nidx = 0, p = tbl->parms.next; p; p = p->next) {
		for (nidx = 0, p = tbl->parms.next; p; p = p->next) {
			if (net != neigh_parms_net(p))
			if (!net_eq(neigh_parms_net(p), net))
				continue;
				continue;


			if (nidx++ < neigh_skip)
			if (nidx++ < neigh_skip)
@@ -2161,7 +2161,7 @@ static struct neighbour *neigh_get_first(struct seq_file *seq)
		n = tbl->hash_buckets[bucket];
		n = tbl->hash_buckets[bucket];


		while (n) {
		while (n) {
			if (dev_net(n->dev) != net)
			if (!net_eq(dev_net(n->dev), net))
				goto next;
				goto next;
			if (state->neigh_sub_iter) {
			if (state->neigh_sub_iter) {
				loff_t fakep = 0;
				loff_t fakep = 0;
@@ -2204,7 +2204,7 @@ static struct neighbour *neigh_get_next(struct seq_file *seq,


	while (1) {
	while (1) {
		while (n) {
		while (n) {
			if (dev_net(n->dev) != net)
			if (!net_eq(dev_net(n->dev), net))
				goto next;
				goto next;
			if (state->neigh_sub_iter) {
			if (state->neigh_sub_iter) {
				void *v = state->neigh_sub_iter(state, n, pos);
				void *v = state->neigh_sub_iter(state, n, pos);
@@ -2260,7 +2260,7 @@ static struct pneigh_entry *pneigh_get_first(struct seq_file *seq)
	state->flags |= NEIGH_SEQ_IS_PNEIGH;
	state->flags |= NEIGH_SEQ_IS_PNEIGH;
	for (bucket = 0; bucket <= PNEIGH_HASHMASK; bucket++) {
	for (bucket = 0; bucket <= PNEIGH_HASHMASK; bucket++) {
		pn = tbl->phash_buckets[bucket];
		pn = tbl->phash_buckets[bucket];
		while (pn && (pneigh_net(pn) != net))
		while (pn && !net_eq(pneigh_net(pn), net))
			pn = pn->next;
			pn = pn->next;
		if (pn)
		if (pn)
			break;
			break;
@@ -2283,7 +2283,7 @@ static struct pneigh_entry *pneigh_get_next(struct seq_file *seq,
		if (++state->bucket > PNEIGH_HASHMASK)
		if (++state->bucket > PNEIGH_HASHMASK)
			break;
			break;
		pn = tbl->phash_buckets[state->bucket];
		pn = tbl->phash_buckets[state->bucket];
		while (pn && (pneigh_net(pn) != net))
		while (pn && !net_eq(pneigh_net(pn), net))
			pn = pn->next;
			pn = pn->next;
		if (pn)
		if (pn)
			break;
			break;
+2 −2
Original line number Original line Diff line number Diff line
@@ -139,7 +139,7 @@ static struct sock *inet_lookup_listener_slow(struct net *net,
	sk_for_each(sk, node, head) {
	sk_for_each(sk, node, head) {
		const struct inet_sock *inet = inet_sk(sk);
		const struct inet_sock *inet = inet_sk(sk);


		if (sock_net(sk) == net && inet->num == hnum &&
		if (net_eq(sock_net(sk), net) && inet->num == hnum &&
				!ipv6_only_sock(sk)) {
				!ipv6_only_sock(sk)) {
			const __be32 rcv_saddr = inet->rcv_saddr;
			const __be32 rcv_saddr = inet->rcv_saddr;
			int score = sk->sk_family == PF_INET ? 1 : 0;
			int score = sk->sk_family == PF_INET ? 1 : 0;
@@ -182,7 +182,7 @@ struct sock *__inet_lookup_listener(struct net *net,
		if (inet->num == hnum && !sk->sk_node.next &&
		if (inet->num == hnum && !sk->sk_node.next &&
		    (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
		    (!inet->rcv_saddr || inet->rcv_saddr == daddr) &&
		    (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
		    (sk->sk_family == PF_INET || !ipv6_only_sock(sk)) &&
		    !sk->sk_bound_dev_if && sock_net(sk) == net)
		    !sk->sk_bound_dev_if && net_eq(sock_net(sk), net))
			goto sherry_cache;
			goto sherry_cache;
		sk = inet_lookup_listener_slow(net, head, daddr, hnum, dif);
		sk = inet_lookup_listener_slow(net, head, daddr, hnum, dif);
	}
	}
+1 −1
Original line number Original line Diff line number Diff line
@@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(struct net *net, struct sock *sk,
	sk_for_each_from(sk, node) {
	sk_for_each_from(sk, node) {
		struct inet_sock *inet = inet_sk(sk);
		struct inet_sock *inet = inet_sk(sk);


		if (sock_net(sk) == net && inet->num == num 		&&
		if (net_eq(sock_net(sk), net) && inet->num == num	&&
		    !(inet->daddr && inet->daddr != raddr) 		&&
		    !(inet->daddr && inet->daddr != raddr) 		&&
		    !(inet->rcv_saddr && inet->rcv_saddr != laddr)	&&
		    !(inet->rcv_saddr && inet->rcv_saddr != laddr)	&&
		    !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
		    !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
Loading