@@ -104,8 +104,13 @@ static inline struct net *copy_net_ns(unsigned long flags, struct net *net_ns)
extern struct list_head net_namespace_list;
+
+#define for_each_net(VAR) \
+ list_for_each_entry(VAR, &net_namespace_list, list)
+
#ifdef CONFIG_NET_NS
extern void __put_net(struct net *net);
+extern struct net *get_net_ns_by_id(int id);
static inline int net_alive(struct net *net)
{
@@ -141,6 +146,19 @@ int net_eq(const struct net *net1, const struct net *net2)
{
return net1 == net2;
}
+
+static inline struct net *__get_net_ns_by_id(int id)
+{
+ struct net *net;
+
+ for_each_net(net)
+ if (net->id == id)
+ return maybe_get_net(net);
+
+ return NULL;
+}
+extern struct net *get_net_ns_by_id(int id);
+
#else
static inline int net_alive(struct net *net)
@@ -167,6 +185,19 @@ int net_eq(const struct net *net1, const struct net *net2)
{
return 1;
}
+
+static inline struct net *__get_net_ns_by_id(int id)
+{
+ if (id == 0)
+ return &init_net;
+ return NULL;
+}
+
+static inline struct net *get_net_ns_by_id(int id)
+{
+ return __get_net_ns_by_id(id);
+}
+
#endif
@@ -195,9 +226,6 @@ static inline void release_net(struct net *net)
#endif
-#define for_each_net(VAR) \
- list_for_each_entry(VAR, &net_namespace_list, list)
-
#ifdef CONFIG_NET_NS
#define __net_init
#define __net_exit
@@ -203,6 +203,18 @@ void __put_net(struct net *net)
}
EXPORT_SYMBOL_GPL(__put_net);
+struct net *get_net_ns_by_id(int id)
+{
+ struct net *net;
+
+ rtnl_lock();
+ net = __get_net_ns_by_id(id);
+ rtnl_unlock();
+
+ return net;
+}
+EXPORT_SYMBOL_GPL(get_net_ns_by_id);
+
#else
struct net *copy_net_ns(unsigned long flags, struct net *old_net)
{