[Devel] [PATCH 1/12] L2 network namespace: current network namespace operations
Dmitry Mishin
dim at openvz.org
Wed Dec 6 14:24:16 PST 2006
Added functions and macros required to operate with current network namespaces.
They are required in order to switch network namespace for incoming packets and
to not extend current network interface by addtiotional network namespace argue.
Signed-off-by: Dmitry Mishin <dim at openvz.org>
---
include/linux/net_namespace.h | 41 +++++++++++++++++++++++++++++++++++++++--
kernel/nsproxy.c | 1 +
net/core/net_namespace.c | 2 ++
3 files changed, 42 insertions(+), 2 deletions(-)
--- linux-2.6.19-rc6-mm2.orig/include/linux/net_namespace.h
+++ linux-2.6.19-rc6-mm2/include/linux/net_namespace.h
@@ -7,6 +7,7 @@
struct net_namespace {
struct kref kref;
+ struct nsproxy *ns;
};
extern struct net_namespace init_net_ns;
@@ -32,7 +33,27 @@ static inline void put_net_ns(struct net
kref_put(&ns->kref, free_net_ns);
}
-#else
+#define current_net_ns (current->nsproxy->net_ns)
+
+static inline struct net_namespace *push_net_ns(struct net_namespace *to)
+{
+ struct nsproxy *orig;
+
+ orig = current->nsproxy;
+ current->nsproxy = to->ns;
+ return orig->net_ns;
+}
+
+static inline void pop_net_ns(struct net_namespace *orig)
+{
+ current->nsproxy = orig->ns;
+}
+
+#define net_ns_match(target, ns) ((target) == (ns))
+
+#define net_ns_hash(ns) ((ns)->hash)
+
+#else /* CONFIG_NET_NS */
#define INIT_NET_NS(net_ns)
@@ -57,6 +78,22 @@ static inline int copy_net_ns(int flags,
static inline void put_net_ns(struct net_namespace *ns)
{
}
-#endif
+
+#define current_net_ns NULL
+
+static inline struct net_namespace *push_net_ns(struct net_namespace *ns)
+{
+ return NULL;
+}
+
+static inline void pop_net_ns(struct net_namespace *ns)
+{
+}
+
+#define net_ns_match(target, ns) ((void)(ns), 1)
+
+#define net_ns_hash(ns) (0)
+
+#endif /* !CONFIG_NET_NS */
#endif /* _LINUX_NET_NAMESPACE_H */
--- linux-2.6.19-rc6-mm2.orig/kernel/nsproxy.c
+++ linux-2.6.19-rc6-mm2/kernel/nsproxy.c
@@ -534,6 +534,7 @@ asmlinkage long sys_unshare_ns(unsigned
}
if (new_net) {
+ new_net->ns = current->nsproxy;
net = current->nsproxy->net_ns;
current->nsproxy->net_ns = new_net;
new_net = net;
--- linux-2.6.19-rc6-mm2.orig/net/core/net_namespace.c
+++ linux-2.6.19-rc6-mm2/net/core/net_namespace.c
@@ -14,6 +14,7 @@ struct net_namespace init_net_ns = {
.kref = {
.refcount = ATOMIC_INIT(2),
},
+ .ns = &init_nsproxy,
};
#ifdef CONFIG_NET_NS
@@ -32,6 +33,7 @@ static struct net_namespace *clone_net_n
return NULL;
kref_init(&ns->kref);
+ ns->ns = old_ns->ns;
return ns;
}
_______________________________________________
Containers mailing list
Containers at lists.osdl.org
https://lists.osdl.org/mailman/listinfo/containers
More information about the Devel
mailing list