Commit 58dbc6f2 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by Simon Horman
Browse files

ipvs: Store ipvs not net in struct ip_vs_conn



In practice struct netns_ipvs is as meaningful as struct net and more
useful as it holds the ipvs specific data.  So store a pointer to
struct netns_ipvs.

Update the accesses of conn->net to access conn->ipvs->net instead.

Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
Acked-by: default avatarJulian Anastasov <ja@ssi.bg>
Signed-off-by: default avatarSimon Horman <horms@verge.net.au>
parent d484fc38
Loading
Loading
Loading
Loading
+1 −30
Original line number Original line Diff line number Diff line
@@ -572,9 +572,7 @@ struct ip_vs_conn {
	volatile __u32          flags;          /* status flags */
	volatile __u32          flags;          /* status flags */
	__u16                   protocol;       /* Which protocol (TCP/UDP) */
	__u16                   protocol;       /* Which protocol (TCP/UDP) */
	__u16			daf;		/* Address family of the dest */
	__u16			daf;		/* Address family of the dest */
#ifdef CONFIG_NET_NS
	struct netns_ipvs	*ipvs;
	struct net              *net;           /* Name space */
#endif


	/* counter and timer */
	/* counter and timer */
	atomic_t		refcnt;		/* reference count */
	atomic_t		refcnt;		/* reference count */
@@ -621,33 +619,6 @@ struct ip_vs_conn {
	struct rcu_head		rcu_head;
	struct rcu_head		rcu_head;
};
};


/* To save some memory in conn table when name space is disabled. */
static inline struct net *ip_vs_conn_net(const struct ip_vs_conn *cp)
{
#ifdef CONFIG_NET_NS
	return cp->net;
#else
	return &init_net;
#endif
}

static inline void ip_vs_conn_net_set(struct ip_vs_conn *cp, struct net *net)
{
#ifdef CONFIG_NET_NS
	cp->net = net;
#endif
}

static inline int ip_vs_conn_net_eq(const struct ip_vs_conn *cp,
				    struct net *net)
{
#ifdef CONFIG_NET_NS
	return cp->net == net;
#else
	return 1;
#endif
}

/* Extended internal versions of struct ip_vs_service_user and ip_vs_dest_user
/* Extended internal versions of struct ip_vs_service_user and ip_vs_dest_user
 * for IPv6 support.
 * for IPv6 support.
 *
 *
+15 −15
Original line number Original line Diff line number Diff line
@@ -148,7 +148,7 @@ static unsigned int ip_vs_conn_hashkey_conn(const struct ip_vs_conn *cp)
{
{
	struct ip_vs_conn_param p;
	struct ip_vs_conn_param p;


	ip_vs_conn_fill_param(ip_vs_conn_net(cp), cp->af, cp->protocol,
	ip_vs_conn_fill_param(cp->ipvs->net, cp->af, cp->protocol,
			      &cp->caddr, cp->cport, NULL, 0, &p);
			      &cp->caddr, cp->cport, NULL, 0, &p);


	if (cp->pe) {
	if (cp->pe) {
@@ -279,7 +279,7 @@ __ip_vs_conn_in_get(const struct ip_vs_conn_param *p)
		    ip_vs_addr_equal(p->af, p->vaddr, &cp->vaddr) &&
		    ip_vs_addr_equal(p->af, p->vaddr, &cp->vaddr) &&
		    ((!p->cport) ^ (!(cp->flags & IP_VS_CONN_F_NO_CPORT))) &&
		    ((!p->cport) ^ (!(cp->flags & IP_VS_CONN_F_NO_CPORT))) &&
		    p->protocol == cp->protocol &&
		    p->protocol == cp->protocol &&
		    ip_vs_conn_net_eq(cp, p->net)) {
		    net_eq(cp->ipvs->net, p->net)) {
			if (!__ip_vs_conn_get(cp))
			if (!__ip_vs_conn_get(cp))
				continue;
				continue;
			/* HIT */
			/* HIT */
@@ -359,7 +359,7 @@ struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p)


	hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[hash], c_list) {
	hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[hash], c_list) {
		if (unlikely(p->pe_data && p->pe->ct_match)) {
		if (unlikely(p->pe_data && p->pe->ct_match)) {
			if (!ip_vs_conn_net_eq(cp, p->net))
			if (!net_eq(cp->ipvs->net, p->net))
				continue;
				continue;
			if (p->pe == cp->pe && p->pe->ct_match(p, cp)) {
			if (p->pe == cp->pe && p->pe->ct_match(p, cp)) {
				if (__ip_vs_conn_get(cp))
				if (__ip_vs_conn_get(cp))
@@ -377,7 +377,7 @@ struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p)
		    p->vport == cp->vport && p->cport == cp->cport &&
		    p->vport == cp->vport && p->cport == cp->cport &&
		    cp->flags & IP_VS_CONN_F_TEMPLATE &&
		    cp->flags & IP_VS_CONN_F_TEMPLATE &&
		    p->protocol == cp->protocol &&
		    p->protocol == cp->protocol &&
		    ip_vs_conn_net_eq(cp, p->net)) {
		    net_eq(cp->ipvs->net, p->net)) {
			if (__ip_vs_conn_get(cp))
			if (__ip_vs_conn_get(cp))
				goto out;
				goto out;
		}
		}
@@ -418,7 +418,7 @@ struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p)
		    ip_vs_addr_equal(p->af, p->vaddr, &cp->caddr) &&
		    ip_vs_addr_equal(p->af, p->vaddr, &cp->caddr) &&
		    ip_vs_addr_equal(p->af, p->caddr, &cp->daddr) &&
		    ip_vs_addr_equal(p->af, p->caddr, &cp->daddr) &&
		    p->protocol == cp->protocol &&
		    p->protocol == cp->protocol &&
		    ip_vs_conn_net_eq(cp, p->net)) {
		    net_eq(cp->ipvs->net, p->net)) {
			if (!__ip_vs_conn_get(cp))
			if (!__ip_vs_conn_get(cp))
				continue;
				continue;
			/* HIT */
			/* HIT */
@@ -638,7 +638,7 @@ void ip_vs_try_bind_dest(struct ip_vs_conn *cp)
	 * so we can make the assumption that the svc_af is the same as the
	 * so we can make the assumption that the svc_af is the same as the
	 * dest_af
	 * dest_af
	 */
	 */
	dest = ip_vs_find_dest(ip_vs_conn_net(cp), cp->af, cp->af, &cp->daddr,
	dest = ip_vs_find_dest(cp->ipvs->net, cp->af, cp->af, &cp->daddr,
			       cp->dport, &cp->vaddr, cp->vport,
			       cp->dport, &cp->vaddr, cp->vport,
			       cp->protocol, cp->fwmark, cp->flags);
			       cp->protocol, cp->fwmark, cp->flags);
	if (dest) {
	if (dest) {
@@ -668,7 +668,7 @@ void ip_vs_try_bind_dest(struct ip_vs_conn *cp)
#endif
#endif
			ip_vs_bind_xmit(cp);
			ip_vs_bind_xmit(cp);


		pd = ip_vs_proto_data_get(ip_vs_conn_net(cp), cp->protocol);
		pd = ip_vs_proto_data_get(cp->ipvs->net, cp->protocol);
		if (pd && atomic_read(&pd->appcnt))
		if (pd && atomic_read(&pd->appcnt))
			ip_vs_bind_app(cp, pd->pp);
			ip_vs_bind_app(cp, pd->pp);
	}
	}
@@ -746,7 +746,7 @@ static int expire_quiescent_template(struct netns_ipvs *ipvs,
int ip_vs_check_template(struct ip_vs_conn *ct)
int ip_vs_check_template(struct ip_vs_conn *ct)
{
{
	struct ip_vs_dest *dest = ct->dest;
	struct ip_vs_dest *dest = ct->dest;
	struct netns_ipvs *ipvs = net_ipvs(ip_vs_conn_net(ct));
	struct netns_ipvs *ipvs = ct->ipvs;


	/*
	/*
	 * Checking the dest server status.
	 * Checking the dest server status.
@@ -800,8 +800,8 @@ static void ip_vs_conn_rcu_free(struct rcu_head *head)
static void ip_vs_conn_expire(unsigned long data)
static void ip_vs_conn_expire(unsigned long data)
{
{
	struct ip_vs_conn *cp = (struct ip_vs_conn *)data;
	struct ip_vs_conn *cp = (struct ip_vs_conn *)data;
	struct net *net = ip_vs_conn_net(cp);
	struct netns_ipvs *ipvs = cp->ipvs;
	struct netns_ipvs *ipvs = net_ipvs(net);
	struct net *net = ipvs->net;


	/*
	/*
	 *	do I control anybody?
	 *	do I control anybody?
@@ -887,7 +887,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,


	INIT_HLIST_NODE(&cp->c_list);
	INIT_HLIST_NODE(&cp->c_list);
	setup_timer(&cp->timer, ip_vs_conn_expire, (unsigned long)cp);
	setup_timer(&cp->timer, ip_vs_conn_expire, (unsigned long)cp);
	ip_vs_conn_net_set(cp, p->net);
	cp->ipvs	   = ipvs;
	cp->af		   = p->af;
	cp->af		   = p->af;
	cp->daf		   = dest_af;
	cp->daf		   = dest_af;
	cp->protocol	   = p->protocol;
	cp->protocol	   = p->protocol;
@@ -1061,7 +1061,7 @@ static int ip_vs_conn_seq_show(struct seq_file *seq, void *v)
		size_t len = 0;
		size_t len = 0;
		char dbuf[IP_VS_ADDRSTRLEN];
		char dbuf[IP_VS_ADDRSTRLEN];


		if (!ip_vs_conn_net_eq(cp, net))
		if (!net_eq(cp->ipvs->net, net))
			return 0;
			return 0;
		if (cp->pe_data) {
		if (cp->pe_data) {
			pe_data[0] = ' ';
			pe_data[0] = ' ';
@@ -1146,7 +1146,7 @@ static int ip_vs_conn_sync_seq_show(struct seq_file *seq, void *v)
		const struct ip_vs_conn *cp = v;
		const struct ip_vs_conn *cp = v;
		struct net *net = seq_file_net(seq);
		struct net *net = seq_file_net(seq);


		if (!ip_vs_conn_net_eq(cp, net))
		if (!net_eq(cp->ipvs->net, net))
			return 0;
			return 0;


#ifdef CONFIG_IP_VS_IPV6
#ifdef CONFIG_IP_VS_IPV6
@@ -1256,7 +1256,7 @@ void ip_vs_random_dropentry(struct net *net)
			if (cp->flags & IP_VS_CONN_F_TEMPLATE)
			if (cp->flags & IP_VS_CONN_F_TEMPLATE)
				/* connection template */
				/* connection template */
				continue;
				continue;
			if (!ip_vs_conn_net_eq(cp, net))
			if (!net_eq(cp->ipvs->net, net))
				continue;
				continue;
			if (cp->protocol == IPPROTO_TCP) {
			if (cp->protocol == IPPROTO_TCP) {
				switch(cp->state) {
				switch(cp->state) {
@@ -1319,7 +1319,7 @@ static void ip_vs_conn_flush(struct net *net)
	for (idx = 0; idx < ip_vs_conn_tab_size; idx++) {
	for (idx = 0; idx < ip_vs_conn_tab_size; idx++) {


		hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[idx], c_list) {
		hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[idx], c_list) {
			if (!ip_vs_conn_net_eq(cp, net))
			if (cp->ipvs != ipvs)
				continue;
				continue;
			IP_VS_DBG(4, "del connection\n");
			IP_VS_DBG(4, "del connection\n");
			ip_vs_conn_expire_now(cp);
			ip_vs_conn_expire_now(cp);
+3 −3
Original line number Original line Diff line number Diff line
@@ -223,14 +223,14 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,
		 */
		 */
		{
		{
			struct ip_vs_conn_param p;
			struct ip_vs_conn_param p;
			ip_vs_conn_fill_param(ip_vs_conn_net(cp), AF_INET,
			ip_vs_conn_fill_param(cp->ipvs->net, AF_INET,
					      iph->protocol, &from, port,
					      iph->protocol, &from, port,
					      &cp->caddr, 0, &p);
					      &cp->caddr, 0, &p);
			n_cp = ip_vs_conn_out_get(&p);
			n_cp = ip_vs_conn_out_get(&p);
		}
		}
		if (!n_cp) {
		if (!n_cp) {
			struct ip_vs_conn_param p;
			struct ip_vs_conn_param p;
			ip_vs_conn_fill_param(ip_vs_conn_net(cp),
			ip_vs_conn_fill_param(cp->ipvs->net,
					      AF_INET, IPPROTO_TCP, &cp->caddr,
					      AF_INET, IPPROTO_TCP, &cp->caddr,
					      0, &cp->vaddr, port, &p);
					      0, &cp->vaddr, port, &p);
			/* As above, this is ipv4 only */
			/* As above, this is ipv4 only */
@@ -392,7 +392,7 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp,


	{
	{
		struct ip_vs_conn_param p;
		struct ip_vs_conn_param p;
		ip_vs_conn_fill_param(ip_vs_conn_net(cp), AF_INET,
		ip_vs_conn_fill_param(cp->ipvs->net, AF_INET,
				      iph->protocol, &to, port, &cp->vaddr,
				      iph->protocol, &to, port, &cp->vaddr,
				      htons(ntohs(cp->vport)-1), &p);
				      htons(ntohs(cp->vport)-1), &p);
		n_cp = ip_vs_conn_in_get(&p);
		n_cp = ip_vs_conn_in_get(&p);
+1 −2
Original line number Original line Diff line number Diff line
@@ -274,8 +274,7 @@ void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
		" for conn " FMT_CONN "\n",
		" for conn " FMT_CONN "\n",
		__func__, ARG_TUPLE(&tuple), ARG_CONN(cp));
		__func__, ARG_TUPLE(&tuple), ARG_CONN(cp));


	h = nf_conntrack_find_get(ip_vs_conn_net(cp), &nf_ct_zone_dflt,
	h = nf_conntrack_find_get(cp->ipvs->net, &nf_ct_zone_dflt, &tuple);
				  &tuple);
	if (h) {
	if (h) {
		ct = nf_ct_tuplehash_to_ctrack(h);
		ct = nf_ct_tuplehash_to_ctrack(h);
		/* Show what happens instead of calling nf_ct_kill() */
		/* Show what happens instead of calling nf_ct_kill() */
+1 −1
Original line number Original line Diff line number Diff line
@@ -521,7 +521,7 @@ static void sctp_unregister_app(struct net *net, struct ip_vs_app *inc)


static int sctp_app_conn_bind(struct ip_vs_conn *cp)
static int sctp_app_conn_bind(struct ip_vs_conn *cp)
{
{
	struct netns_ipvs *ipvs = net_ipvs(ip_vs_conn_net(cp));
	struct netns_ipvs *ipvs = cp->ipvs;
	int hash;
	int hash;
	struct ip_vs_app *inc;
	struct ip_vs_app *inc;
	int result = 0;
	int result = 0;
Loading