netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: dlezcano@fr.ibm.com
To: containers@lists.osdl.org
Cc: netdev@vger.kernel.org
Subject: [patch 09/12] net namespace : make loopback address always visible
Date: Fri, 19 Jan 2007 16:47:23 +0100	[thread overview]
Message-ID: <20070119155400.782293261@localhost.localdomain> (raw)
In-Reply-To: 20070119154714.439706567@localhost.localdomain

[-- Attachment #1: net-namespace-l3-ipv4-devinet-loopback.patch --]
[-- Type: text/plain, Size: 3625 bytes --]

From: Daniel Lezcano <dlezcano@fr.ibm.com>

Add a specific condition when doing inet interface listing 
in order to see always the loopback address.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>

---
 include/linux/net_namespace.h |    9 +++++++++
 net/core/net_namespace.c      |   22 ++++++++++++++++++++++
 net/ipv4/devinet.c            |   12 +++++-------
 3 files changed, 36 insertions(+), 7 deletions(-)

Index: 2.6.20-rc4-mm1/net/ipv4/devinet.c
===================================================================
--- 2.6.20-rc4-mm1.orig/net/ipv4/devinet.c
+++ 2.6.20-rc4-mm1/net/ipv4/devinet.c
@@ -695,8 +695,7 @@
 			for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
 			     ifap = &ifa->ifa_next) {
 				if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
-				    net_ns_match(ifa->ifa_net_ns,
-						 current_net_ns) &&
+				    net_ns_ifa_is_visible(ifa) &&
 				    sin_orig.sin_addr.s_addr ==
 							ifa->ifa_address) {
 					break; /* found */
@@ -710,13 +709,12 @@
 			for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
 			     ifap = &ifa->ifa_next)
 				if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
-                                    net_ns_match(ifa->ifa_net_ns,
-                                                 current_net_ns))
+                                    net_ns_ifa_is_visible(ifa))
 					break;
 		}
 	}
 
-	if (ifa && !net_ns_match(ifa->ifa_net_ns, current_net_ns))
+	if (ifa && !net_ns_ifa_is_visible(ifa))
 		goto done;
 
 	ret = -EADDRNOTAVAIL;
@@ -868,7 +866,7 @@
 		goto out;
 
 	for (; ifa; ifa = ifa->ifa_next) {
-		if (!net_ns_match(ifa->ifa_net_ns, current_net_ns))
+		if (!net_ns_ifa_is_visible(ifa))
 			continue;
 		if (!buf) {
 			done += sizeof(ifr);
@@ -1216,7 +1214,7 @@
 
 		for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
 		     ifa = ifa->ifa_next, ip_idx++) {
-			if (!net_ns_match(ifa->ifa_net_ns, current_net_ns))
+			if (!net_ns_ifa_is_visible(ifa))
 				continue;
 			if (ip_idx < s_ip_idx)
 				continue;
Index: 2.6.20-rc4-mm1/include/linux/net_namespace.h
===================================================================
--- 2.6.20-rc4-mm1.orig/include/linux/net_namespace.h
+++ 2.6.20-rc4-mm1/include/linux/net_namespace.h
@@ -7,6 +7,8 @@
 #include <linux/errno.h>
 #include <linux/types.h>
 
+struct in_ifaddr;
+
 struct net_namespace {
 	struct kref		kref;
 	struct net_device	*dev_base_p, **dev_tail_p;
@@ -101,6 +103,8 @@
 
 extern struct net_namespace *net_ns_find_from_dest_addr(u32 daddr);
 
+extern int net_ns_ifa_is_visible(const struct in_ifaddr *ifa);
+
 #define SELECT_SRC_ADDR net_ns_select_source_address
 
 #else /* CONFIG_NET_NS */
@@ -174,6 +178,11 @@
 	return NULL;
 }
 
+static inline int net_ns_ifa_is_visible(const struct in_ifaddr *ifa)
+{
+	return 1;
+}
+
 #define SELECT_SRC_ADDR inet_select_addr
 
 #endif /* !CONFIG_NET_NS */
Index: 2.6.20-rc4-mm1/net/core/net_namespace.c
===================================================================
--- 2.6.20-rc4-mm1.orig/net/core/net_namespace.c
+++ 2.6.20-rc4-mm1/net/core/net_namespace.c
@@ -420,4 +420,26 @@
 
 	return net_ns;
 }
+
+/*
+ * This function checks if the ifaddr is visible from the
+ * current network namespace. This is true if the ifaddr is
+ * the loopback address or if the ifaddr is owned by the network
+ * namespace.
+ * @ifa : the ifaddr
+ * Returns : 1 if visible, 0 otherwise
+ */
+int net_ns_ifa_is_visible(const struct in_ifaddr *ifa)
+{
+ 	struct net_namespace *net_ns = current_net_ns;
+
+ 	if (LOOPBACK(ifa->ifa_local))
+ 		return 1;
+
+ 	if (net_ns_match(ifa->ifa_net_ns, net_ns))
+ 		return 1;
+
+ 	return 0;
+}
+
 #endif /* CONFIG_NET_NS */

-- 

  parent reply	other threads:[~2007-01-19 16:40 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-19 15:47 [patch 00/12] net namespace : L3 namespace - introduction dlezcano
2007-01-19 15:47 ` [patch 01/12] net namespace : initialize init process to level 2 dlezcano
2007-01-19 15:47 ` [patch 02/12] net namespace : store L2 parent namespace dlezcano
2007-01-19 15:47 ` [patch 03/12] net namespace : share network ressources L2 with L3 dlezcano
2007-01-19 15:47 ` [patch 04/12] net namespace : isolate the inet device dlezcano
2007-01-19 15:47 ` [patch 05/12] net namespace : ioctl to push ifa to net namespace l3 dlezcano
2007-01-20  4:52   ` Herbert Poetzl
2007-01-20 11:48     ` Daniel Lezcano
2007-01-19 15:47 ` [patch 06/12] net namespace : check bind address dlezcano
2007-01-19 15:47 ` [patch 07/12] net namespace: set source addresse dlezcano
2007-01-19 15:47 ` [patch 08/12] net namespace : find namespace by addr dlezcano
2007-01-20  4:56   ` Herbert Poetzl
2007-01-19 15:47 ` dlezcano [this message]
2007-01-19 15:47 ` [patch 10/12] net namespace : add the loopback isolation dlezcano
2007-01-19 15:47 ` [patch 11/12] net namespace : debugfs - add net_ns debugfs dlezcano
2007-01-19 15:47 ` [patch 12/12] net namespace : Add broadcasting dlezcano
2007-01-20  4:58   ` Herbert Poetzl
2007-01-20 11:54     ` Daniel Lezcano
2007-01-20  4:48 ` [patch 00/12] net namespace : L3 namespace - introduction Herbert Poetzl
2007-01-20 11:42   ` Daniel Lezcano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070119155400.782293261@localhost.localdomain \
    --to=dlezcano@fr.ibm.com \
    --cc=containers@lists.osdl.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).