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

Commit 61b1ab45 authored by Hans Schillstrom's avatar Hans Schillstrom Committed by Simon Horman
Browse files

IPVS: netns, add basic init per netns.



Preparation for network name-space init, in this stage
some empty functions exists.

In most files there is a check if it is root ns i.e. init_net
if (!net_eq(net, &init_net))
        return ...
this will be removed by the last patch, when enabling name-space.

*v3
 ip_vs_conn.c merge error corrected.
 net_ipvs #ifdef removed as sugested by Jan Engelhardt

[ horms@verge.net.au: Removed whitespace-change-only hunks ]
Signed-off-by: default avatarHans Schillstrom <hans.schillstrom@ericsson.com>
Acked-by: default avatarJulian Anastasov <ja@ssi.bg>
Signed-off-by: default avatarSimon Horman <horms@verge.net.au>
parent fee1cc08
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -28,6 +28,15 @@
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
#include <net/netfilter/nf_conntrack.h>
#endif
#include <net/net_namespace.h>		/* Netw namespace */

/*
 * Generic access of ipvs struct
 */
static inline struct netns_ipvs *net_ipvs(struct net* net)
{
	return net->ipvs;
}

/* Connections' size value needed by ip_vs_ctl.c */
extern int ip_vs_conn_tab_size;
@@ -922,6 +931,8 @@ extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
extern int stop_sync_thread(int state);
extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
extern int ip_vs_sync_init(void);
extern void ip_vs_sync_cleanup(void);


/*
+2 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <net/netns/conntrack.h>
#endif
#include <net/netns/xfrm.h>
#include <net/netns/ip_vs.h>

struct proc_dir_entry;
struct net_device;
@@ -94,6 +95,7 @@ struct net {
#ifdef CONFIG_XFRM
	struct netns_xfrm	xfrm;
#endif
	struct netns_ipvs	*ipvs;
};


+25 −0
Original line number Diff line number Diff line
/*
 *  IP Virtual Server
 *  Data structure for network namspace
 *
 */

#ifndef IP_VS_H_
#define IP_VS_H_

#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/list_nulls.h>
#include <linux/ip_vs.h>
#include <asm/atomic.h>
#include <linux/in.h>

struct ip_vs_stats;
struct ip_vs_sync_buff;
struct ctl_table_header;

struct netns_ipvs {
	int			gen;		/* Generation */
};

#endif /* IP_VS_H_ */
+24 −4
Original line number Diff line number Diff line
@@ -569,15 +569,35 @@ static const struct file_operations ip_vs_app_fops = {
};
#endif

int __init ip_vs_app_init(void)
static int __net_init __ip_vs_app_init(struct net *net)
{
	/* we will replace it with proc_net_ipvs_create() soon */
	proc_net_fops_create(&init_net, "ip_vs_app", 0, &ip_vs_app_fops);
	if (!net_eq(net, &init_net))	/* netns not enabled yet */
		return -EPERM;

	proc_net_fops_create(net, "ip_vs_app", 0, &ip_vs_app_fops);
	return 0;
}

static void __net_exit __ip_vs_app_cleanup(struct net *net)
{
	proc_net_remove(net, "ip_vs_app");
}

static struct pernet_operations ip_vs_app_ops = {
	.init = __ip_vs_app_init,
	.exit = __ip_vs_app_cleanup,
};

int __init ip_vs_app_init(void)
{
	int rv;

	rv = register_pernet_subsys(&ip_vs_app_ops);
	return rv;
}


void ip_vs_app_cleanup(void)
{
	proc_net_remove(&init_net, "ip_vs_app");
	unregister_pernet_subsys(&ip_vs_app_ops);
}
+28 −6
Original line number Diff line number Diff line
@@ -1201,11 +1201,36 @@ static void ip_vs_conn_flush(void)
		goto flush_again;
	}
}
/*
 * per netns init and exit
 */
int __net_init __ip_vs_conn_init(struct net *net)
{
	if (!net_eq(net, &init_net))	/* netns not enabled yet */
		return -EPERM;

	proc_net_fops_create(net, "ip_vs_conn", 0, &ip_vs_conn_fops);
	proc_net_fops_create(net, "ip_vs_conn_sync", 0, &ip_vs_conn_sync_fops);
	return 0;
}

static void __net_exit __ip_vs_conn_cleanup(struct net *net)
{
	if (!net_eq(net, &init_net))	/* netns not enabled yet */
		return;

	proc_net_remove(net, "ip_vs_conn");
	proc_net_remove(net, "ip_vs_conn_sync");
}
static struct pernet_operations ipvs_conn_ops = {
	.init = __ip_vs_conn_init,
	.exit = __ip_vs_conn_cleanup,
};

int __init ip_vs_conn_init(void)
{
	int idx;
	int retc;

	/* Compute size and mask */
	ip_vs_conn_tab_size = 1 << ip_vs_conn_tab_bits;
@@ -1243,24 +1268,21 @@ int __init ip_vs_conn_init(void)
		rwlock_init(&__ip_vs_conntbl_lock_array[idx].l);
	}

	proc_net_fops_create(&init_net, "ip_vs_conn", 0, &ip_vs_conn_fops);
	proc_net_fops_create(&init_net, "ip_vs_conn_sync", 0, &ip_vs_conn_sync_fops);
	retc = register_pernet_subsys(&ipvs_conn_ops);

	/* calculate the random value for connection hash */
	get_random_bytes(&ip_vs_conn_rnd, sizeof(ip_vs_conn_rnd));

	return 0;
	return retc;
}


void ip_vs_conn_cleanup(void)
{
	unregister_pernet_subsys(&ipvs_conn_ops);
	/* flush all the connection entries first */
	ip_vs_conn_flush();

	/* Release the empty cache */
	kmem_cache_destroy(ip_vs_conn_cachep);
	proc_net_remove(&init_net, "ip_vs_conn");
	proc_net_remove(&init_net, "ip_vs_conn_sync");
	vfree(ip_vs_conn_tab);
}
Loading