xref: /openbmc/linux/include/net/ip_vs.h (revision 84c0d5e96f3ae20344fb3a79161eab18905dae56)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
207dcc686SSimon Horman /* IP Virtual Server
31da177e4SLinus Torvalds  * data structure and functionality definitions
41da177e4SLinus Torvalds  */
51da177e4SLinus Torvalds 
6bc4768ebSJulius Volz #ifndef _NET_IP_VS_H
7bc4768ebSJulius Volz #define _NET_IP_VS_H
81da177e4SLinus Torvalds 
9bc4768ebSJulius Volz #include <linux/ip_vs.h>                /* definitions shared with userland */
101da177e4SLinus Torvalds 
11bc4768ebSJulius Volz #include <asm/types.h>                  /* for __uXX types */
12bc4768ebSJulius Volz 
131da177e4SLinus Torvalds #include <linux/list.h>                 /* for struct list_head */
141da177e4SLinus Torvalds #include <linux/spinlock.h>             /* for struct rwlock_t */
1560063497SArun Sharma #include <linux/atomic.h>               /* for struct atomic_t */
16b54ab92bSReshetova, Elena #include <linux/refcount.h>             /* for struct refcount_t */
17b54ab92bSReshetova, Elena 
181da177e4SLinus Torvalds #include <linux/compiler.h>
1914c85021SArnaldo Carvalho de Melo #include <linux/timer.h>
20187f1882SPaul Gortmaker #include <linux/bug.h>
211da177e4SLinus Torvalds 
2214c85021SArnaldo Carvalho de Melo #include <net/checksum.h>
23e7ade46aSJulius Volz #include <linux/netfilter.h>		/* for union nf_inet_addr */
241668e010SKOVACS Krisztian #include <linux/ip.h>
25e7ade46aSJulius Volz #include <linux/ipv6.h>			/* for struct ipv6hdr */
264e3fd7a0SAlexey Dobriyan #include <net/ipv6.h>
2754d83efaSJesper Dangaard Brouer #if IS_ENABLED(CONFIG_IP_VS_IPV6)
2863dca2c0SJesper Dangaard Brouer #include <linux/netfilter_ipv6/ip6_tables.h>
2963dca2c0SJesper Dangaard Brouer #endif
30a638e514SJesper Dangaard Brouer #if IS_ENABLED(CONFIG_NF_CONNTRACK)
31f4bc17cdSJulian Anastasov #include <net/netfilter/nf_conntrack.h>
32f4bc17cdSJulian Anastasov #endif
3361b1ab45SHans Schillstrom #include <net/net_namespace.h>		/* Netw namespace */
3461b1ab45SHans Schillstrom 
354fd9beefSAlex Gartrell #define IP_VS_HDR_INVERSE	1
364fd9beefSAlex Gartrell #define IP_VS_HDR_ICMP		2
374fd9beefSAlex Gartrell 
3807dcc686SSimon Horman /* Generic access of ipvs struct */
3961b1ab45SHans Schillstrom static inline struct netns_ipvs *net_ipvs(struct net* net)
4061b1ab45SHans Schillstrom {
4161b1ab45SHans Schillstrom 	return net->ipvs;
4261b1ab45SHans Schillstrom }
4307dcc686SSimon Horman 
446f7edb48SCatalin(ux) M. BOIE /* Connections' size value needed by ip_vs_ctl.c */
456f7edb48SCatalin(ux) M. BOIE extern int ip_vs_conn_tab_size;
466f7edb48SCatalin(ux) M. BOIE 
4764aae3cbSJulius Volz struct ip_vs_iphdr {
484fd9beefSAlex Gartrell 	int hdr_flags;	/* ipvs flags */
49b0e010c5SAlex Gartrell 	__u32 off;	/* Where IP or IPv4 header starts */
5063dca2c0SJesper Dangaard Brouer 	__u32 len;	/* IPv4 simply where L4 starts
5107dcc686SSimon Horman 			 * IPv6 where L4 Transport Header starts */
5263dca2c0SJesper Dangaard Brouer 	__u16 fragoffs; /* IPv6 fragment offset, 0 if first frag (or not frag)*/
5363dca2c0SJesper Dangaard Brouer 	__s16 protocol;
5463dca2c0SJesper Dangaard Brouer 	__s32 flags;
5564aae3cbSJulius Volz 	union nf_inet_addr saddr;
5664aae3cbSJulius Volz 	union nf_inet_addr daddr;
5764aae3cbSJulius Volz };
5864aae3cbSJulius Volz 
592f74713dSJesper Dangaard Brouer static inline void *frag_safe_skb_hp(const struct sk_buff *skb, int offset,
606b3d9330SGao Feng 				      int len, void *buffer)
612f74713dSJesper Dangaard Brouer {
622f74713dSJesper Dangaard Brouer 	return skb_header_pointer(skb, offset, len, buffer);
632f74713dSJesper Dangaard Brouer }
642f74713dSJesper Dangaard Brouer 
6563dca2c0SJesper Dangaard Brouer /* This function handles filling *ip_vs_iphdr, both for IPv4 and IPv6.
6663dca2c0SJesper Dangaard Brouer  * IPv6 requires some extra work, as finding proper header position,
6763dca2c0SJesper Dangaard Brouer  * depend on the IPv6 extension headers.
6863dca2c0SJesper Dangaard Brouer  */
69b0e010c5SAlex Gartrell static inline int
70b0e010c5SAlex Gartrell ip_vs_fill_iph_skb_off(int af, const struct sk_buff *skb, int offset,
714fd9beefSAlex Gartrell 		       int hdr_flags, struct ip_vs_iphdr *iphdr)
7264aae3cbSJulius Volz {
734fd9beefSAlex Gartrell 	iphdr->hdr_flags = hdr_flags;
74b0e010c5SAlex Gartrell 	iphdr->off = offset;
754fd9beefSAlex Gartrell 
7664aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6
7764aae3cbSJulius Volz 	if (af == AF_INET6) {
78b0e010c5SAlex Gartrell 		struct ipv6hdr _iph;
79b0e010c5SAlex Gartrell 		const struct ipv6hdr *iph = skb_header_pointer(
80b0e010c5SAlex Gartrell 			skb, offset, sizeof(_iph), &_iph);
81b0e010c5SAlex Gartrell 		if (!iph)
82b0e010c5SAlex Gartrell 			return 0;
83b0e010c5SAlex Gartrell 
844e3fd7a0SAlexey Dobriyan 		iphdr->saddr.in6 = iph->saddr;
854e3fd7a0SAlexey Dobriyan 		iphdr->daddr.in6 = iph->daddr;
866aafeef0SJiri Pirko 		/* ipv6_find_hdr() updates len, flags */
87b0e010c5SAlex Gartrell 		iphdr->len	 = offset;
8863dca2c0SJesper Dangaard Brouer 		iphdr->flags	 = 0;
8963dca2c0SJesper Dangaard Brouer 		iphdr->protocol  = ipv6_find_hdr(skb, &iphdr->len, -1,
9063dca2c0SJesper Dangaard Brouer 						 &iphdr->fragoffs,
9163dca2c0SJesper Dangaard Brouer 						 &iphdr->flags);
92b0e010c5SAlex Gartrell 		if (iphdr->protocol < 0)
93b0e010c5SAlex Gartrell 			return 0;
9464aae3cbSJulius Volz 	} else
9564aae3cbSJulius Volz #endif
9664aae3cbSJulius Volz 	{
97b0e010c5SAlex Gartrell 		struct iphdr _iph;
98b0e010c5SAlex Gartrell 		const struct iphdr *iph = skb_header_pointer(
99b0e010c5SAlex Gartrell 			skb, offset, sizeof(_iph), &_iph);
100b0e010c5SAlex Gartrell 		if (!iph)
101b0e010c5SAlex Gartrell 			return 0;
102b0e010c5SAlex Gartrell 
103b0e010c5SAlex Gartrell 		iphdr->len	= offset + iph->ihl * 4;
10463dca2c0SJesper Dangaard Brouer 		iphdr->fragoffs	= 0;
10564aae3cbSJulius Volz 		iphdr->protocol	= iph->protocol;
10664aae3cbSJulius Volz 		iphdr->saddr.ip	= iph->saddr;
10764aae3cbSJulius Volz 		iphdr->daddr.ip	= iph->daddr;
10864aae3cbSJulius Volz 	}
109b0e010c5SAlex Gartrell 
110b0e010c5SAlex Gartrell 	return 1;
111b0e010c5SAlex Gartrell }
112b0e010c5SAlex Gartrell 
113b0e010c5SAlex Gartrell static inline int
1144fd9beefSAlex Gartrell ip_vs_fill_iph_skb_icmp(int af, const struct sk_buff *skb, int offset,
1154fd9beefSAlex Gartrell 			bool inverse, struct ip_vs_iphdr *iphdr)
116b0e010c5SAlex Gartrell {
1174fd9beefSAlex Gartrell 	int hdr_flags = IP_VS_HDR_ICMP;
1184fd9beefSAlex Gartrell 
1194fd9beefSAlex Gartrell 	if (inverse)
1204fd9beefSAlex Gartrell 		hdr_flags |= IP_VS_HDR_INVERSE;
1214fd9beefSAlex Gartrell 
1224fd9beefSAlex Gartrell 	return ip_vs_fill_iph_skb_off(af, skb, offset, hdr_flags, iphdr);
1234fd9beefSAlex Gartrell }
1244fd9beefSAlex Gartrell 
1254fd9beefSAlex Gartrell static inline int
1264fd9beefSAlex Gartrell ip_vs_fill_iph_skb(int af, const struct sk_buff *skb, bool inverse,
1274fd9beefSAlex Gartrell 		   struct ip_vs_iphdr *iphdr)
1284fd9beefSAlex Gartrell {
1294fd9beefSAlex Gartrell 	int hdr_flags = 0;
1304fd9beefSAlex Gartrell 
1314fd9beefSAlex Gartrell 	if (inverse)
1324fd9beefSAlex Gartrell 		hdr_flags |= IP_VS_HDR_INVERSE;
1334fd9beefSAlex Gartrell 
1344fd9beefSAlex Gartrell 	return ip_vs_fill_iph_skb_off(af, skb, skb_network_offset(skb),
1354fd9beefSAlex Gartrell 				      hdr_flags, iphdr);
1364fd9beefSAlex Gartrell }
1374fd9beefSAlex Gartrell 
1384fd9beefSAlex Gartrell static inline bool
1394fd9beefSAlex Gartrell ip_vs_iph_inverse(const struct ip_vs_iphdr *iph)
1404fd9beefSAlex Gartrell {
1414fd9beefSAlex Gartrell 	return !!(iph->hdr_flags & IP_VS_HDR_INVERSE);
1424fd9beefSAlex Gartrell }
1434fd9beefSAlex Gartrell 
1444fd9beefSAlex Gartrell static inline bool
1454fd9beefSAlex Gartrell ip_vs_iph_icmp(const struct ip_vs_iphdr *iph)
1464fd9beefSAlex Gartrell {
1474fd9beefSAlex Gartrell 	return !!(iph->hdr_flags & IP_VS_HDR_ICMP);
14864aae3cbSJulius Volz }
14964aae3cbSJulius Volz 
15064aae3cbSJulius Volz static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
15164aae3cbSJulius Volz 				   const union nf_inet_addr *src)
15264aae3cbSJulius Volz {
15364aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6
15464aae3cbSJulius Volz 	if (af == AF_INET6)
1554e3fd7a0SAlexey Dobriyan 		dst->in6 = src->in6;
15664aae3cbSJulius Volz 	else
15764aae3cbSJulius Volz #endif
15864aae3cbSJulius Volz 	dst->ip = src->ip;
15964aae3cbSJulius Volz }
16064aae3cbSJulius Volz 
1619a05475cSJulian Anastasov static inline void ip_vs_addr_set(int af, union nf_inet_addr *dst,
1629a05475cSJulian Anastasov 				  const union nf_inet_addr *src)
1639a05475cSJulian Anastasov {
1649a05475cSJulian Anastasov #ifdef CONFIG_IP_VS_IPV6
1659a05475cSJulian Anastasov 	if (af == AF_INET6) {
1669a05475cSJulian Anastasov 		dst->in6 = src->in6;
1679a05475cSJulian Anastasov 		return;
1689a05475cSJulian Anastasov 	}
1699a05475cSJulian Anastasov #endif
1709a05475cSJulian Anastasov 	dst->ip = src->ip;
1719a05475cSJulian Anastasov 	dst->all[1] = 0;
1729a05475cSJulian Anastasov 	dst->all[2] = 0;
1739a05475cSJulian Anastasov 	dst->all[3] = 0;
1749a05475cSJulian Anastasov }
1759a05475cSJulian Anastasov 
17664aae3cbSJulius Volz static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
17764aae3cbSJulius Volz 				   const union nf_inet_addr *b)
17864aae3cbSJulius Volz {
17964aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6
18064aae3cbSJulius Volz 	if (af == AF_INET6)
18164aae3cbSJulius Volz 		return ipv6_addr_equal(&a->in6, &b->in6);
18264aae3cbSJulius Volz #endif
18364aae3cbSJulius Volz 	return a->ip == b->ip;
18464aae3cbSJulius Volz }
18564aae3cbSJulius Volz 
1861da177e4SLinus Torvalds #ifdef CONFIG_IP_VS_DEBUG
18714c85021SArnaldo Carvalho de Melo #include <linux/net.h>
18814c85021SArnaldo Carvalho de Melo 
1895c3a0fd7SJoe Perches int ip_vs_get_debug_level(void);
190c842a3adSJulius Volz 
191c842a3adSJulius Volz static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
192c842a3adSJulius Volz 					 const union nf_inet_addr *addr,
193c842a3adSJulius Volz 					 int *idx)
194c842a3adSJulius Volz {
195c842a3adSJulius Volz 	int len;
196c842a3adSJulius Volz #ifdef CONFIG_IP_VS_IPV6
197c842a3adSJulius Volz 	if (af == AF_INET6)
198120b9c14SJesper Dangaard Brouer 		len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6c]",
1990c6ce78aSHarvey Harrison 			       &addr->in6) + 1;
200c842a3adSJulius Volz 	else
201c842a3adSJulius Volz #endif
2023685f25dSHarvey Harrison 		len = snprintf(&buf[*idx], buf_len - *idx, "%pI4",
2033685f25dSHarvey Harrison 			       &addr->ip) + 1;
204c842a3adSJulius Volz 
205c842a3adSJulius Volz 	*idx += len;
206c842a3adSJulius Volz 	BUG_ON(*idx > buf_len + 1);
207c842a3adSJulius Volz 	return &buf[*idx - len];
208c842a3adSJulius Volz }
209c842a3adSJulius Volz 
2109aada7acSHannes Eder #define IP_VS_DBG_BUF(level, msg, ...)					\
211c842a3adSJulius Volz 	do {								\
212c842a3adSJulius Volz 		char ip_vs_dbg_buf[160];				\
213c842a3adSJulius Volz 		int ip_vs_dbg_idx = 0;					\
214c842a3adSJulius Volz 		if (level <= ip_vs_get_debug_level())			\
2159aada7acSHannes Eder 			printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__);	\
216c842a3adSJulius Volz 	} while (0)
217c842a3adSJulius Volz #define IP_VS_ERR_BUF(msg...)						\
218c842a3adSJulius Volz 	do {								\
219c842a3adSJulius Volz 		char ip_vs_dbg_buf[160];				\
220c842a3adSJulius Volz 		int ip_vs_dbg_idx = 0;					\
2219aada7acSHannes Eder 		pr_err(msg);						\
222c842a3adSJulius Volz 	} while (0)
223c842a3adSJulius Volz 
224c842a3adSJulius Volz /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */
225c842a3adSJulius Volz #define IP_VS_DBG_ADDR(af, addr)					\
226c842a3adSJulius Volz 	ip_vs_dbg_addr(af, ip_vs_dbg_buf,				\
227c842a3adSJulius Volz 		       sizeof(ip_vs_dbg_buf), addr,			\
228c842a3adSJulius Volz 		       &ip_vs_dbg_idx)
229c842a3adSJulius Volz 
2309aada7acSHannes Eder #define IP_VS_DBG(level, msg, ...)					\
2311da177e4SLinus Torvalds 	do {								\
2321da177e4SLinus Torvalds 		if (level <= ip_vs_get_debug_level())			\
2339aada7acSHannes Eder 			printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__);	\
2341da177e4SLinus Torvalds 	} while (0)
2359aada7acSHannes Eder #define IP_VS_DBG_RL(msg, ...)						\
2361da177e4SLinus Torvalds 	do {								\
2371da177e4SLinus Torvalds 		if (net_ratelimit())					\
2389aada7acSHannes Eder 			printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__);	\
2391da177e4SLinus Torvalds 	} while (0)
2400d79641aSJulian Anastasov #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg)			\
2411da177e4SLinus Torvalds 	do {								\
2421da177e4SLinus Torvalds 		if (level <= ip_vs_get_debug_level())			\
2430d79641aSJulian Anastasov 			pp->debug_packet(af, pp, skb, ofs, msg);	\
2441da177e4SLinus Torvalds 	} while (0)
2450d79641aSJulian Anastasov #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg)			\
2461da177e4SLinus Torvalds 	do {								\
2471da177e4SLinus Torvalds 		if (level <= ip_vs_get_debug_level() &&			\
2481da177e4SLinus Torvalds 		    net_ratelimit())					\
2490d79641aSJulian Anastasov 			pp->debug_packet(af, pp, skb, ofs, msg);	\
2501da177e4SLinus Torvalds 	} while (0)
2511da177e4SLinus Torvalds #else	/* NO DEBUGGING at ALL */
252c842a3adSJulius Volz #define IP_VS_DBG_BUF(level, msg...)  do {} while (0)
253c842a3adSJulius Volz #define IP_VS_ERR_BUF(msg...)  do {} while (0)
2541da177e4SLinus Torvalds #define IP_VS_DBG(level, msg...)  do {} while (0)
2551da177e4SLinus Torvalds #define IP_VS_DBG_RL(msg...)  do {} while (0)
2560d79641aSJulian Anastasov #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg)	do {} while (0)
2570d79641aSJulian Anastasov #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg)	do {} while (0)
2581da177e4SLinus Torvalds #endif
2591da177e4SLinus Torvalds 
2601da177e4SLinus Torvalds #define IP_VS_BUG() BUG()
2611e3e238eSHannes Eder #define IP_VS_ERR_RL(msg, ...)						\
2621da177e4SLinus Torvalds 	do {								\
2631da177e4SLinus Torvalds 		if (net_ratelimit())					\
2641e3e238eSHannes Eder 			pr_err(msg, ##__VA_ARGS__);			\
2651da177e4SLinus Torvalds 	} while (0)
2661da177e4SLinus Torvalds 
2671da177e4SLinus Torvalds #ifdef CONFIG_IP_VS_DEBUG
2681da177e4SLinus Torvalds #define EnterFunction(level)						\
2691da177e4SLinus Torvalds 	do {								\
2701da177e4SLinus Torvalds 		if (level <= ip_vs_get_debug_level())			\
2719aada7acSHannes Eder 			printk(KERN_DEBUG				\
2729aada7acSHannes Eder 			       pr_fmt("Enter: %s, %s line %i\n"),	\
273d5c003b4SHarvey Harrison 			       __func__, __FILE__, __LINE__);		\
2741da177e4SLinus Torvalds 	} while (0)
2751da177e4SLinus Torvalds #define LeaveFunction(level)						\
2761da177e4SLinus Torvalds 	do {								\
2771da177e4SLinus Torvalds 		if (level <= ip_vs_get_debug_level())			\
2789aada7acSHannes Eder 			printk(KERN_DEBUG				\
2799aada7acSHannes Eder 			       pr_fmt("Leave: %s, %s line %i\n"),	\
280d5c003b4SHarvey Harrison 			       __func__, __FILE__, __LINE__);		\
2811da177e4SLinus Torvalds 	} while (0)
2821da177e4SLinus Torvalds #else
2831da177e4SLinus Torvalds #define EnterFunction(level)   do {} while (0)
2841da177e4SLinus Torvalds #define LeaveFunction(level)   do {} while (0)
2851da177e4SLinus Torvalds #endif
2861da177e4SLinus Torvalds 
28707dcc686SSimon Horman /* The port number of FTP service (in network order). */
288f3a7c66bSHarvey Harrison #define FTPPORT  cpu_to_be16(21)
289f3a7c66bSHarvey Harrison #define FTPDATA  cpu_to_be16(20)
2901da177e4SLinus Torvalds 
29107dcc686SSimon Horman /* TCP State Values */
2921da177e4SLinus Torvalds enum {
2931da177e4SLinus Torvalds 	IP_VS_TCP_S_NONE = 0,
2941da177e4SLinus Torvalds 	IP_VS_TCP_S_ESTABLISHED,
2951da177e4SLinus Torvalds 	IP_VS_TCP_S_SYN_SENT,
2961da177e4SLinus Torvalds 	IP_VS_TCP_S_SYN_RECV,
2971da177e4SLinus Torvalds 	IP_VS_TCP_S_FIN_WAIT,
2981da177e4SLinus Torvalds 	IP_VS_TCP_S_TIME_WAIT,
2991da177e4SLinus Torvalds 	IP_VS_TCP_S_CLOSE,
3001da177e4SLinus Torvalds 	IP_VS_TCP_S_CLOSE_WAIT,
3011da177e4SLinus Torvalds 	IP_VS_TCP_S_LAST_ACK,
3021da177e4SLinus Torvalds 	IP_VS_TCP_S_LISTEN,
3031da177e4SLinus Torvalds 	IP_VS_TCP_S_SYNACK,
3041da177e4SLinus Torvalds 	IP_VS_TCP_S_LAST
3051da177e4SLinus Torvalds };
3061da177e4SLinus Torvalds 
30707dcc686SSimon Horman /* UDP State Values */
3081da177e4SLinus Torvalds enum {
3091da177e4SLinus Torvalds 	IP_VS_UDP_S_NORMAL,
3101da177e4SLinus Torvalds 	IP_VS_UDP_S_LAST,
3111da177e4SLinus Torvalds };
3121da177e4SLinus Torvalds 
31307dcc686SSimon Horman /* ICMP State Values */
3141da177e4SLinus Torvalds enum {
3151da177e4SLinus Torvalds 	IP_VS_ICMP_S_NORMAL,
3161da177e4SLinus Torvalds 	IP_VS_ICMP_S_LAST,
3171da177e4SLinus Torvalds };
3181da177e4SLinus Torvalds 
31907dcc686SSimon Horman /* SCTP State Values */
3202906f66aSVenkata Mohan Reddy enum ip_vs_sctp_states {
3212906f66aSVenkata Mohan Reddy 	IP_VS_SCTP_S_NONE,
32261e7c420SJulian Anastasov 	IP_VS_SCTP_S_INIT1,
32361e7c420SJulian Anastasov 	IP_VS_SCTP_S_INIT,
32461e7c420SJulian Anastasov 	IP_VS_SCTP_S_COOKIE_SENT,
32561e7c420SJulian Anastasov 	IP_VS_SCTP_S_COOKIE_REPLIED,
32661e7c420SJulian Anastasov 	IP_VS_SCTP_S_COOKIE_WAIT,
32761e7c420SJulian Anastasov 	IP_VS_SCTP_S_COOKIE,
32861e7c420SJulian Anastasov 	IP_VS_SCTP_S_COOKIE_ECHOED,
3292906f66aSVenkata Mohan Reddy 	IP_VS_SCTP_S_ESTABLISHED,
33061e7c420SJulian Anastasov 	IP_VS_SCTP_S_SHUTDOWN_SENT,
33161e7c420SJulian Anastasov 	IP_VS_SCTP_S_SHUTDOWN_RECEIVED,
33261e7c420SJulian Anastasov 	IP_VS_SCTP_S_SHUTDOWN_ACK_SENT,
33361e7c420SJulian Anastasov 	IP_VS_SCTP_S_REJECTED,
3342906f66aSVenkata Mohan Reddy 	IP_VS_SCTP_S_CLOSED,
3352906f66aSVenkata Mohan Reddy 	IP_VS_SCTP_S_LAST
3362906f66aSVenkata Mohan Reddy };
3372906f66aSVenkata Mohan Reddy 
33827541143SJulian Anastasov /* Connection templates use bits from state */
33927541143SJulian Anastasov #define IP_VS_CTPL_S_NONE		0x0000
34027541143SJulian Anastasov #define IP_VS_CTPL_S_ASSURED		0x0001
34127541143SJulian Anastasov #define IP_VS_CTPL_S_LAST		0x0002
34227541143SJulian Anastasov 
34307dcc686SSimon Horman /* Delta sequence info structure
3441da177e4SLinus Torvalds  * Each ip_vs_conn has 2 (output AND input seq. changes).
3451da177e4SLinus Torvalds  * Only used in the VS/NAT.
3461da177e4SLinus Torvalds  */
3471da177e4SLinus Torvalds struct ip_vs_seq {
3481da177e4SLinus Torvalds 	__u32			init_seq;	/* Add delta from this seq */
3491da177e4SLinus Torvalds 	__u32			delta;		/* Delta in sequence numbers */
3501da177e4SLinus Torvalds 	__u32			previous_delta;	/* Delta in sequence numbers
35107dcc686SSimon Horman 						 * before last resized pkt */
3521da177e4SLinus Torvalds };
3531da177e4SLinus Torvalds 
35407dcc686SSimon Horman /* counters per cpu */
355b17fc996SHans Schillstrom struct ip_vs_counters {
356cd67cd5eSJulian Anastasov 	__u64		conns;		/* connections scheduled */
357cd67cd5eSJulian Anastasov 	__u64		inpkts;		/* incoming packets */
358cd67cd5eSJulian Anastasov 	__u64		outpkts;	/* outgoing packets */
359b17fc996SHans Schillstrom 	__u64		inbytes;	/* incoming bytes */
360b17fc996SHans Schillstrom 	__u64		outbytes;	/* outgoing bytes */
361b17fc996SHans Schillstrom };
36207dcc686SSimon Horman /* Stats per cpu */
363b17fc996SHans Schillstrom struct ip_vs_cpu_stats {
364cd67cd5eSJulian Anastasov 	struct ip_vs_counters   cnt;
365b17fc996SHans Schillstrom 	struct u64_stats_sync   syncp;
366b17fc996SHans Schillstrom };
3671da177e4SLinus Torvalds 
36807dcc686SSimon Horman /* IPVS statistics objects */
3693a14a313SSven Wegener struct ip_vs_estimator {
3703a14a313SSven Wegener 	struct list_head	list;
3713a14a313SSven Wegener 
3723a14a313SSven Wegener 	u64			last_inbytes;
3733a14a313SSven Wegener 	u64			last_outbytes;
374cd67cd5eSJulian Anastasov 	u64			last_conns;
375cd67cd5eSJulian Anastasov 	u64			last_inpkts;
376cd67cd5eSJulian Anastasov 	u64			last_outpkts;
3773a14a313SSven Wegener 
378cd67cd5eSJulian Anastasov 	u64			cps;
379cd67cd5eSJulian Anastasov 	u64			inpps;
380cd67cd5eSJulian Anastasov 	u64			outpps;
381cd67cd5eSJulian Anastasov 	u64			inbps;
382cd67cd5eSJulian Anastasov 	u64			outbps;
383cd67cd5eSJulian Anastasov };
384cd67cd5eSJulian Anastasov 
385cd67cd5eSJulian Anastasov /*
386cd67cd5eSJulian Anastasov  * IPVS statistics object, 64-bit kernel version of struct ip_vs_stats_user
387cd67cd5eSJulian Anastasov  */
388cd67cd5eSJulian Anastasov struct ip_vs_kstats {
389cd67cd5eSJulian Anastasov 	u64			conns;		/* connections scheduled */
390cd67cd5eSJulian Anastasov 	u64			inpkts;		/* incoming packets */
391cd67cd5eSJulian Anastasov 	u64			outpkts;	/* outgoing packets */
392cd67cd5eSJulian Anastasov 	u64			inbytes;	/* incoming bytes */
393cd67cd5eSJulian Anastasov 	u64			outbytes;	/* outgoing bytes */
394cd67cd5eSJulian Anastasov 
395cd67cd5eSJulian Anastasov 	u64			cps;		/* current connection rate */
396cd67cd5eSJulian Anastasov 	u64			inpps;		/* current in packet rate */
397cd67cd5eSJulian Anastasov 	u64			outpps;		/* current out packet rate */
398cd67cd5eSJulian Anastasov 	u64			inbps;		/* current in byte rate */
399cd67cd5eSJulian Anastasov 	u64			outbps;		/* current out byte rate */
4003a14a313SSven Wegener };
4013a14a313SSven Wegener 
402fd2c3ef7SEric Dumazet struct ip_vs_stats {
403cd67cd5eSJulian Anastasov 	struct ip_vs_kstats	kstats;		/* kernel statistics */
404e9c0ce23SSven Wegener 	struct ip_vs_estimator	est;		/* estimator */
405b962abdcSJulian Anastasov 	struct ip_vs_cpu_stats __percpu	*cpustats;	/* per cpu counters */
4061da177e4SLinus Torvalds 	spinlock_t		lock;		/* spin lock */
407cd67cd5eSJulian Anastasov 	struct ip_vs_kstats	kstats0;	/* reset values */
4081da177e4SLinus Torvalds };
4091da177e4SLinus Torvalds 
41014c85021SArnaldo Carvalho de Melo struct dst_entry;
41114c85021SArnaldo Carvalho de Melo struct iphdr;
4121da177e4SLinus Torvalds struct ip_vs_conn;
4131da177e4SLinus Torvalds struct ip_vs_app;
41414c85021SArnaldo Carvalho de Melo struct sk_buff;
415252c6410SHans Schillstrom struct ip_vs_proto_data;
4161da177e4SLinus Torvalds 
4171da177e4SLinus Torvalds struct ip_vs_protocol {
4181da177e4SLinus Torvalds 	struct ip_vs_protocol	*next;
4191da177e4SLinus Torvalds 	char			*name;
4202ad17defSJulian Anastasov 	u16			protocol;
4212ad17defSJulian Anastasov 	u16			num_states;
4221da177e4SLinus Torvalds 	int			dont_defrag;
4231da177e4SLinus Torvalds 
4241da177e4SLinus Torvalds 	void (*init)(struct ip_vs_protocol *pp);
4251da177e4SLinus Torvalds 
4261da177e4SLinus Torvalds 	void (*exit)(struct ip_vs_protocol *pp);
4271da177e4SLinus Torvalds 
4281281a9c2SEric W. Biederman 	int (*init_netns)(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd);
429252c6410SHans Schillstrom 
4301281a9c2SEric W. Biederman 	void (*exit_netns)(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd);
431252c6410SHans Schillstrom 
432d8f44c33SEric W. Biederman 	int (*conn_schedule)(struct netns_ipvs *ipvs,
433d8f44c33SEric W. Biederman 			     int af, struct sk_buff *skb,
4349330419dSHans Schillstrom 			     struct ip_vs_proto_data *pd,
435d4383f04SJesper Dangaard Brouer 			     int *verdict, struct ip_vs_conn **cpp,
436d4383f04SJesper Dangaard Brouer 			     struct ip_vs_iphdr *iph);
4371da177e4SLinus Torvalds 
4381da177e4SLinus Torvalds 	struct ip_vs_conn *
439ab161976SEric W. Biederman 	(*conn_in_get)(struct netns_ipvs *ipvs,
440ab161976SEric W. Biederman 		       int af,
44151ef348bSJulius Volz 		       const struct sk_buff *skb,
442802c41adSAlex Gartrell 		       const struct ip_vs_iphdr *iph);
4431da177e4SLinus Torvalds 
4441da177e4SLinus Torvalds 	struct ip_vs_conn *
4450cf705c8SEric W. Biederman 	(*conn_out_get)(struct netns_ipvs *ipvs,
4460cf705c8SEric W. Biederman 			int af,
44751ef348bSJulius Volz 			const struct sk_buff *skb,
448802c41adSAlex Gartrell 			const struct ip_vs_iphdr *iph);
4491da177e4SLinus Torvalds 
450d4383f04SJesper Dangaard Brouer 	int (*snat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp,
451d4383f04SJesper Dangaard Brouer 			    struct ip_vs_conn *cp, struct ip_vs_iphdr *iph);
4521da177e4SLinus Torvalds 
453d4383f04SJesper Dangaard Brouer 	int (*dnat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp,
454d4383f04SJesper Dangaard Brouer 			    struct ip_vs_conn *cp, struct ip_vs_iphdr *iph);
4551da177e4SLinus Torvalds 
4561da177e4SLinus Torvalds 	const char *(*state_name)(int state);
4571da177e4SLinus Torvalds 
4584a516f11SSimon Horman 	void (*state_transition)(struct ip_vs_conn *cp, int direction,
4591da177e4SLinus Torvalds 				 const struct sk_buff *skb,
4609330419dSHans Schillstrom 				 struct ip_vs_proto_data *pd);
4611da177e4SLinus Torvalds 
46219648918SEric W. Biederman 	int (*register_app)(struct netns_ipvs *ipvs, struct ip_vs_app *inc);
4631da177e4SLinus Torvalds 
46419648918SEric W. Biederman 	void (*unregister_app)(struct netns_ipvs *ipvs, struct ip_vs_app *inc);
4651da177e4SLinus Torvalds 
4661da177e4SLinus Torvalds 	int (*app_conn_bind)(struct ip_vs_conn *cp);
4671da177e4SLinus Torvalds 
4680d79641aSJulian Anastasov 	void (*debug_packet)(int af, struct ip_vs_protocol *pp,
4691da177e4SLinus Torvalds 			     const struct sk_buff *skb,
4701da177e4SLinus Torvalds 			     int offset,
4711da177e4SLinus Torvalds 			     const char *msg);
4721da177e4SLinus Torvalds 
4739330419dSHans Schillstrom 	void (*timeout_change)(struct ip_vs_proto_data *pd, int flags);
4741da177e4SLinus Torvalds };
4751da177e4SLinus Torvalds 
47607dcc686SSimon Horman /* protocol data per netns */
477252c6410SHans Schillstrom struct ip_vs_proto_data {
478252c6410SHans Schillstrom 	struct ip_vs_proto_data	*next;
479252c6410SHans Schillstrom 	struct ip_vs_protocol	*pp;
480252c6410SHans Schillstrom 	int			*timeout_table;	/* protocol timeout table */
481252c6410SHans Schillstrom 	atomic_t		appcnt;		/* counter of proto app incs. */
482252c6410SHans Schillstrom 	struct tcp_states_t	*tcp_state_table;
483252c6410SHans Schillstrom };
484252c6410SHans Schillstrom 
4855c3a0fd7SJoe Perches struct ip_vs_protocol   *ip_vs_proto_get(unsigned short proto);
48618d6ade6SEric W. Biederman struct ip_vs_proto_data *ip_vs_proto_data_get(struct netns_ipvs *ipvs,
487252c6410SHans Schillstrom 					      unsigned short proto);
4881da177e4SLinus Torvalds 
489f11017ecSSimon Horman struct ip_vs_conn_param {
490e64e2b46SEric W. Biederman 	struct netns_ipvs		*ipvs;
491f11017ecSSimon Horman 	const union nf_inet_addr	*caddr;
492f11017ecSSimon Horman 	const union nf_inet_addr	*vaddr;
493f11017ecSSimon Horman 	__be16				cport;
494f11017ecSSimon Horman 	__be16				vport;
495f11017ecSSimon Horman 	__u16				protocol;
496f11017ecSSimon Horman 	u16				af;
49785999283SSimon Horman 
49885999283SSimon Horman 	const struct ip_vs_pe		*pe;
49985999283SSimon Horman 	char				*pe_data;
50085999283SSimon Horman 	__u8				pe_data_len;
501f11017ecSSimon Horman };
502f11017ecSSimon Horman 
50307dcc686SSimon Horman /* IP_VS structure allocated for each dynamically scheduled connection */
5041da177e4SLinus Torvalds struct ip_vs_conn {
505731109e7SChangli Gao 	struct hlist_node	c_list;         /* hashed list heads */
5061da177e4SLinus Torvalds 	/* Protocol, addresses and port numbers */
5076e67e586SHans Schillstrom 	__be16                  cport;
5086e67e586SHans Schillstrom 	__be16                  dport;
5091845ed0bSJulian Anastasov 	__be16                  vport;
5101845ed0bSJulian Anastasov 	u16			af;		/* address family */
511e7ade46aSJulius Volz 	union nf_inet_addr      caddr;          /* client address */
512e7ade46aSJulius Volz 	union nf_inet_addr      vaddr;          /* virtual address */
513e7ade46aSJulius Volz 	union nf_inet_addr      daddr;          /* destination address */
5143575792eSJulian Anastasov 	volatile __u32          flags;          /* status flags */
5151da177e4SLinus Torvalds 	__u16                   protocol;       /* Which protocol (TCP/UDP) */
516ba38528aSAlex Gartrell 	__u16			daf;		/* Address family of the dest */
51758dbc6f2SEric W. Biederman 	struct netns_ipvs	*ipvs;
5181da177e4SLinus Torvalds 
5191da177e4SLinus Torvalds 	/* counter and timer */
520b54ab92bSReshetova, Elena 	refcount_t		refcnt;		/* reference count */
5211da177e4SLinus Torvalds 	struct timer_list	timer;		/* Expiration timer */
5221da177e4SLinus Torvalds 	volatile unsigned long	timeout;	/* timeout */
5231da177e4SLinus Torvalds 
5241da177e4SLinus Torvalds 	/* Flags and state transition */
5251da177e4SLinus Torvalds 	spinlock_t              lock;           /* lock for state transition */
5261da177e4SLinus Torvalds 	volatile __u16          state;          /* state info */
527efac5276SRumen G. Bogdanovski 	volatile __u16          old_state;      /* old state, to be used for
528efac5276SRumen G. Bogdanovski 						 * state transition triggerd
529efac5276SRumen G. Bogdanovski 						 * synchronization
530efac5276SRumen G. Bogdanovski 						 */
5311845ed0bSJulian Anastasov 	__u32			fwmark;		/* Fire wall mark from skb */
532749c42b6SJulian Anastasov 	unsigned long		sync_endtime;	/* jiffies + sent_retries */
5331da177e4SLinus Torvalds 
5341da177e4SLinus Torvalds 	/* Control members */
5351da177e4SLinus Torvalds 	struct ip_vs_conn       *control;       /* Master control connection */
5361da177e4SLinus Torvalds 	atomic_t                n_control;      /* Number of controlled ones */
5371da177e4SLinus Torvalds 	struct ip_vs_dest       *dest;          /* real server */
5381da177e4SLinus Torvalds 	atomic_t                in_pkts;        /* incoming packet counter */
5391da177e4SLinus Torvalds 
54007dcc686SSimon Horman 	/* Packet transmitter for different forwarding methods.  If it
54107dcc686SSimon Horman 	 * mangles the packet, it must return NF_DROP or better NF_STOLEN,
54207dcc686SSimon Horman 	 * otherwise this must be changed to a sk_buff **.
54307dcc686SSimon Horman 	 * NF_ACCEPT can be returned when destination is local.
5441da177e4SLinus Torvalds 	 */
5451da177e4SLinus Torvalds 	int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
546d4383f04SJesper Dangaard Brouer 			   struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
5471da177e4SLinus Torvalds 
5481da177e4SLinus Torvalds 	/* Note: we can group the following members into a structure,
54907dcc686SSimon Horman 	 * in order to save more space, and the following members are
55007dcc686SSimon Horman 	 * only used in VS/NAT anyway
55107dcc686SSimon Horman 	 */
5521da177e4SLinus Torvalds 	struct ip_vs_app        *app;           /* bound ip_vs_app object */
5531da177e4SLinus Torvalds 	void                    *app_data;      /* Application private data */
5541da177e4SLinus Torvalds 	struct ip_vs_seq        in_seq;         /* incoming seq. struct */
5551da177e4SLinus Torvalds 	struct ip_vs_seq        out_seq;        /* outgoing seq. struct */
55685999283SSimon Horman 
557e9e5eee8SSimon Horman 	const struct ip_vs_pe	*pe;
55885999283SSimon Horman 	char			*pe_data;
55985999283SSimon Horman 	__u8			pe_data_len;
560088339a5SJulian Anastasov 
561088339a5SJulian Anastasov 	struct rcu_head		rcu_head;
5621da177e4SLinus Torvalds };
5631da177e4SLinus Torvalds 
56407dcc686SSimon Horman /* Extended internal versions of struct ip_vs_service_user and ip_vs_dest_user
56507dcc686SSimon Horman  * for IPv6 support.
566c860c6b1SJulius Volz  *
567c860c6b1SJulius Volz  * We need these to conveniently pass around service and destination
568c860c6b1SJulius Volz  * options, but unfortunately, we also need to keep the old definitions to
569c860c6b1SJulius Volz  * maintain userspace backwards compatibility for the setsockopt interface.
570c860c6b1SJulius Volz  */
571c860c6b1SJulius Volz struct ip_vs_service_user_kern {
572c860c6b1SJulius Volz 	/* virtual service addresses */
573c860c6b1SJulius Volz 	u16			af;
574c860c6b1SJulius Volz 	u16			protocol;
575c860c6b1SJulius Volz 	union nf_inet_addr	addr;		/* virtual ip address */
5760a925864SJulian Anastasov 	__be16			port;
577c860c6b1SJulius Volz 	u32			fwmark;		/* firwall mark of service */
578c860c6b1SJulius Volz 
579c860c6b1SJulius Volz 	/* virtual service options */
580c860c6b1SJulius Volz 	char			*sched_name;
5810d1e71b0SSimon Horman 	char			*pe_name;
58295c96174SEric Dumazet 	unsigned int		flags;		/* virtual service flags */
58395c96174SEric Dumazet 	unsigned int		timeout;	/* persistent timeout in sec */
5840a925864SJulian Anastasov 	__be32			netmask;	/* persistent netmask or plen */
585c860c6b1SJulius Volz };
586c860c6b1SJulius Volz 
587c860c6b1SJulius Volz 
588c860c6b1SJulius Volz struct ip_vs_dest_user_kern {
589c860c6b1SJulius Volz 	/* destination server address */
590c860c6b1SJulius Volz 	union nf_inet_addr	addr;
5910a925864SJulian Anastasov 	__be16			port;
592c860c6b1SJulius Volz 
593c860c6b1SJulius Volz 	/* real server options */
59495c96174SEric Dumazet 	unsigned int		conn_flags;	/* connection flags */
595c860c6b1SJulius Volz 	int			weight;		/* destination weight */
596c860c6b1SJulius Volz 
597c860c6b1SJulius Volz 	/* thresholds for active connections */
598c860c6b1SJulius Volz 	u32			u_threshold;	/* upper threshold */
599c860c6b1SJulius Volz 	u32			l_threshold;	/* lower threshold */
6006cff339bSAlex Gartrell 
6016cff339bSAlex Gartrell 	/* Address family of addr */
6026cff339bSAlex Gartrell 	u16			af;
603*84c0d5e9SJacky Hu 
604*84c0d5e9SJacky Hu 	u16			tun_type;	/* tunnel type */
605*84c0d5e9SJacky Hu 	__be16			tun_port;	/* tunnel port */
606c860c6b1SJulius Volz };
607c860c6b1SJulius Volz 
608c860c6b1SJulius Volz 
609c860c6b1SJulius Volz /*
61007dcc686SSimon Horman  * The information about the virtual service offered to the net and the
61107dcc686SSimon Horman  * forwarding entries.
6121da177e4SLinus Torvalds  */
6131da177e4SLinus Torvalds struct ip_vs_service {
614ceec4c38SJulian Anastasov 	struct hlist_node	s_list;   /* for normal service table */
615ceec4c38SJulian Anastasov 	struct hlist_node	f_list;   /* for fwmark-based service table */
6161da177e4SLinus Torvalds 	atomic_t		refcnt;   /* reference counter */
6171da177e4SLinus Torvalds 
618e7ade46aSJulius Volz 	u16			af;       /* address family */
6191da177e4SLinus Torvalds 	__u16			protocol; /* which protocol (TCP/UDP) */
620e7ade46aSJulius Volz 	union nf_inet_addr	addr;	  /* IP address for virtual service */
621014d730dSAl Viro 	__be16			port;	  /* port number for the service */
6221da177e4SLinus Torvalds 	__u32                   fwmark;   /* firewall mark of the service */
62395c96174SEric Dumazet 	unsigned int		flags;	  /* service status flags */
62495c96174SEric Dumazet 	unsigned int		timeout;  /* persistent timeout in ticks */
6250a925864SJulian Anastasov 	__be32			netmask;  /* grouping granularity, mask/plen */
6263109d2f2SEric W. Biederman 	struct netns_ipvs	*ipvs;
6271da177e4SLinus Torvalds 
6281da177e4SLinus Torvalds 	struct list_head	destinations;  /* real server d-linked list */
6291da177e4SLinus Torvalds 	__u32			num_dests;     /* number of servers */
6301da177e4SLinus Torvalds 	struct ip_vs_stats      stats;         /* statistics for the service */
6311da177e4SLinus Torvalds 
6321da177e4SLinus Torvalds 	/* for scheduling */
633ceec4c38SJulian Anastasov 	struct ip_vs_scheduler __rcu *scheduler; /* bound scheduler object */
634ba3a3ce1SJulian Anastasov 	spinlock_t		sched_lock;    /* lock sched_data */
6351da177e4SLinus Torvalds 	void			*sched_data;   /* scheduler application data */
63685999283SSimon Horman 
63785999283SSimon Horman 	/* alternate persistence engine */
638ceec4c38SJulian Anastasov 	struct ip_vs_pe __rcu	*pe;
63931875d49SJulian Anastasov 	int			conntrack_afmask;
640ceec4c38SJulian Anastasov 
641ceec4c38SJulian Anastasov 	struct rcu_head		rcu_head;
6421da177e4SLinus Torvalds };
6431da177e4SLinus Torvalds 
644026ace06SJulian Anastasov /* Information for cached dst */
645026ace06SJulian Anastasov struct ip_vs_dest_dst {
646026ace06SJulian Anastasov 	struct dst_entry	*dst_cache;	/* destination cache entry */
647026ace06SJulian Anastasov 	u32			dst_cookie;
648026ace06SJulian Anastasov 	union nf_inet_addr	dst_saddr;
649026ace06SJulian Anastasov 	struct rcu_head		rcu_head;
650026ace06SJulian Anastasov };
6511da177e4SLinus Torvalds 
65207dcc686SSimon Horman /* The real server destination forwarding entry with ip address, port number,
65307dcc686SSimon Horman  * and so on.
6541da177e4SLinus Torvalds  */
6551da177e4SLinus Torvalds struct ip_vs_dest {
6561da177e4SLinus Torvalds 	struct list_head	n_list;   /* for the dests in the service */
657276472eaSJulian Anastasov 	struct hlist_node	d_list;   /* for table with all the dests */
6581da177e4SLinus Torvalds 
659e7ade46aSJulius Volz 	u16			af;		/* address family */
660014d730dSAl Viro 	__be16			port;		/* port number of the server */
661f2431e6eSHans Schillstrom 	union nf_inet_addr	addr;		/* IP address of the server */
66295c96174SEric Dumazet 	volatile unsigned int	flags;		/* dest status flags */
6631da177e4SLinus Torvalds 	atomic_t		conn_flags;	/* flags to copy to conn */
6641da177e4SLinus Torvalds 	atomic_t		weight;		/* server weight */
665a2c09ac0SInju Song 	atomic_t		last_weight;	/* server latest weight */
666*84c0d5e9SJacky Hu 	__u16			tun_type;	/* tunnel type */
667*84c0d5e9SJacky Hu 	__be16			tun_port;	/* tunnel port */
6681da177e4SLinus Torvalds 
669b54ab92bSReshetova, Elena 	refcount_t		refcnt;		/* reference counter */
6701da177e4SLinus Torvalds 	struct ip_vs_stats      stats;          /* statistics */
671bcbde4c0SJulian Anastasov 	unsigned long		idle_start;	/* start time, jiffies */
6721da177e4SLinus Torvalds 
6731da177e4SLinus Torvalds 	/* connection counters and thresholds */
6741da177e4SLinus Torvalds 	atomic_t		activeconns;	/* active connections */
6751da177e4SLinus Torvalds 	atomic_t		inactconns;	/* inactive connections */
6761da177e4SLinus Torvalds 	atomic_t		persistconns;	/* persistent connections */
6771da177e4SLinus Torvalds 	__u32			u_threshold;	/* upper threshold */
6781da177e4SLinus Torvalds 	__u32			l_threshold;	/* lower threshold */
6791da177e4SLinus Torvalds 
6801da177e4SLinus Torvalds 	/* for destination cache */
6811da177e4SLinus Torvalds 	spinlock_t		dst_lock;	/* lock of dst_cache */
682026ace06SJulian Anastasov 	struct ip_vs_dest_dst __rcu *dest_dst;	/* cached dst info */
6831da177e4SLinus Torvalds 
6841da177e4SLinus Torvalds 	/* for virtual service */
685bcbde4c0SJulian Anastasov 	struct ip_vs_service __rcu *svc;	/* service it belongs to */
6861da177e4SLinus Torvalds 	__u16			protocol;	/* which protocol (TCP/UDP) */
687014d730dSAl Viro 	__be16			vport;		/* virtual port number */
688f2431e6eSHans Schillstrom 	union nf_inet_addr	vaddr;		/* virtual IP address */
6891da177e4SLinus Torvalds 	__u32			vfwmark;	/* firewall mark of service */
690276472eaSJulian Anastasov 
691578bc3efSJulian Anastasov 	struct list_head	t_list;		/* in dest_trash */
692276472eaSJulian Anastasov 	unsigned int		in_rs_table:1;	/* we are in rs_table */
6931da177e4SLinus Torvalds };
6941da177e4SLinus Torvalds 
69507dcc686SSimon Horman /* The scheduler object */
6961da177e4SLinus Torvalds struct ip_vs_scheduler {
6971da177e4SLinus Torvalds 	struct list_head	n_list;		/* d-linked list head */
6981da177e4SLinus Torvalds 	char			*name;		/* scheduler name */
6991da177e4SLinus Torvalds 	atomic_t		refcnt;		/* reference counter */
7001da177e4SLinus Torvalds 	struct module		*module;	/* THIS_MODULE/NULL */
7011da177e4SLinus Torvalds 
7021da177e4SLinus Torvalds 	/* scheduler initializing service */
7031da177e4SLinus Torvalds 	int (*init_service)(struct ip_vs_service *svc);
7041da177e4SLinus Torvalds 	/* scheduling service finish */
705ed3ffc4eSJulian Anastasov 	void (*done_service)(struct ip_vs_service *svc);
7066b6df466SJulian Anastasov 	/* dest is linked */
7076b6df466SJulian Anastasov 	int (*add_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
7086b6df466SJulian Anastasov 	/* dest is unlinked */
7096b6df466SJulian Anastasov 	int (*del_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
7106b6df466SJulian Anastasov 	/* dest is updated */
7116b6df466SJulian Anastasov 	int (*upd_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
7121da177e4SLinus Torvalds 
7131da177e4SLinus Torvalds 	/* selecting a server from the given service */
7141da177e4SLinus Torvalds 	struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
715bba54de5SJulian Anastasov 				       const struct sk_buff *skb,
716bba54de5SJulian Anastasov 				       struct ip_vs_iphdr *iph);
7171da177e4SLinus Torvalds };
7181da177e4SLinus Torvalds 
71985999283SSimon Horman /* The persistence engine object */
72085999283SSimon Horman struct ip_vs_pe {
72185999283SSimon Horman 	struct list_head	n_list;		/* d-linked list head */
72285999283SSimon Horman 	char			*name;		/* scheduler name */
72385999283SSimon Horman 	atomic_t		refcnt;		/* reference counter */
72485999283SSimon Horman 	struct module		*module;	/* THIS_MODULE/NULL */
72585999283SSimon Horman 
72685999283SSimon Horman 	/* get the connection template, if any */
72785999283SSimon Horman 	int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb);
72885999283SSimon Horman 	bool (*ct_match)(const struct ip_vs_conn_param *p,
72985999283SSimon Horman 			 struct ip_vs_conn *ct);
73085999283SSimon Horman 	u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval,
73185999283SSimon Horman 			   bool inverse);
732a3c918acSSimon Horman 	int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf);
73339b97223SMarco Angaroni 	/* create connections for real-server outgoing packets */
73439b97223SMarco Angaroni 	struct ip_vs_conn* (*conn_out)(struct ip_vs_service *svc,
73539b97223SMarco Angaroni 				       struct ip_vs_dest *dest,
73639b97223SMarco Angaroni 				       struct sk_buff *skb,
73739b97223SMarco Angaroni 				       const struct ip_vs_iphdr *iph,
73839b97223SMarco Angaroni 				       __be16 dport, __be16 cport);
73985999283SSimon Horman };
7401da177e4SLinus Torvalds 
74107dcc686SSimon Horman /* The application module object (a.k.a. app incarnation) */
742fd2c3ef7SEric Dumazet struct ip_vs_app {
7431da177e4SLinus Torvalds 	struct list_head	a_list;		/* member in app list */
7441da177e4SLinus Torvalds 	int			type;		/* IP_VS_APP_TYPE_xxx */
7451da177e4SLinus Torvalds 	char			*name;		/* application module name */
7461da177e4SLinus Torvalds 	__u16			protocol;
7471da177e4SLinus Torvalds 	struct module		*module;	/* THIS_MODULE/NULL */
7481da177e4SLinus Torvalds 	struct list_head	incs_list;	/* list of incarnations */
7491da177e4SLinus Torvalds 
7501da177e4SLinus Torvalds 	/* members for application incarnations */
7511da177e4SLinus Torvalds 	struct list_head	p_list;		/* member in proto app list */
7521da177e4SLinus Torvalds 	struct ip_vs_app	*app;		/* its real application */
753014d730dSAl Viro 	__be16			port;		/* port number in net order */
7541da177e4SLinus Torvalds 	atomic_t		usecnt;		/* usage counter */
755363c97d7SJulian Anastasov 	struct rcu_head		rcu_head;
7561da177e4SLinus Torvalds 
75707dcc686SSimon Horman 	/* output hook: Process packet in inout direction, diff set for TCP.
7588b27b10fSJulian Anastasov 	 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
7598b27b10fSJulian Anastasov 	 *	   2=Mangled but checksum was not updated
7608b27b10fSJulian Anastasov 	 */
7611da177e4SLinus Torvalds 	int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
762d12e1229SJulian Anastasov 		       struct sk_buff *, int *diff, struct ip_vs_iphdr *ipvsh);
7631da177e4SLinus Torvalds 
76407dcc686SSimon Horman 	/* input hook: Process packet in outin direction, diff set for TCP.
7658b27b10fSJulian Anastasov 	 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
7668b27b10fSJulian Anastasov 	 *	   2=Mangled but checksum was not updated
7678b27b10fSJulian Anastasov 	 */
7681da177e4SLinus Torvalds 	int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
769d12e1229SJulian Anastasov 		      struct sk_buff *, int *diff, struct ip_vs_iphdr *ipvsh);
7701da177e4SLinus Torvalds 
7711da177e4SLinus Torvalds 	/* ip_vs_app initializer */
7721da177e4SLinus Torvalds 	int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
7731da177e4SLinus Torvalds 
7741da177e4SLinus Torvalds 	/* ip_vs_app finish */
7751da177e4SLinus Torvalds 	int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
7761da177e4SLinus Torvalds 
7771da177e4SLinus Torvalds 
7781da177e4SLinus Torvalds 	/* not used now */
7791da177e4SLinus Torvalds 	int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
7801da177e4SLinus Torvalds 			 struct ip_vs_protocol *);
7811da177e4SLinus Torvalds 
7821da177e4SLinus Torvalds 	void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
7831da177e4SLinus Torvalds 
7841da177e4SLinus Torvalds 	int *			timeout_table;
7851da177e4SLinus Torvalds 	int *			timeouts;
7861da177e4SLinus Torvalds 	int			timeouts_size;
7871da177e4SLinus Torvalds 
7881da177e4SLinus Torvalds 	int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
7891da177e4SLinus Torvalds 			     int *verdict, struct ip_vs_conn **cpp);
7901da177e4SLinus Torvalds 
7911da177e4SLinus Torvalds 	struct ip_vs_conn *
7921da177e4SLinus Torvalds 	(*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
793d4383f04SJesper Dangaard Brouer 		       const struct iphdr *iph, int inverse);
7941da177e4SLinus Torvalds 
7951da177e4SLinus Torvalds 	struct ip_vs_conn *
7961da177e4SLinus Torvalds 	(*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
797d4383f04SJesper Dangaard Brouer 			const struct iphdr *iph, int inverse);
7981da177e4SLinus Torvalds 
7991da177e4SLinus Torvalds 	int (*state_transition)(struct ip_vs_conn *cp, int direction,
8001da177e4SLinus Torvalds 				const struct sk_buff *skb,
8011da177e4SLinus Torvalds 				struct ip_vs_app *app);
8021da177e4SLinus Torvalds 
8031da177e4SLinus Torvalds 	void (*timeout_change)(struct ip_vs_app *app, int flags);
8041da177e4SLinus Torvalds };
8051da177e4SLinus Torvalds 
806f73181c8SPablo Neira Ayuso struct ipvs_master_sync_state {
807f73181c8SPablo Neira Ayuso 	struct list_head	sync_queue;
808f73181c8SPablo Neira Ayuso 	struct ip_vs_sync_buff	*sync_buff;
80907995674SZhang Yanfei 	unsigned long		sync_queue_len;
810f73181c8SPablo Neira Ayuso 	unsigned int		sync_queue_delay;
811f73181c8SPablo Neira Ayuso 	struct task_struct	*master_thread;
812f73181c8SPablo Neira Ayuso 	struct delayed_work	master_wakeup_work;
813f73181c8SPablo Neira Ayuso 	struct netns_ipvs	*ipvs;
814f73181c8SPablo Neira Ayuso };
815f73181c8SPablo Neira Ayuso 
816578bc3efSJulian Anastasov /* How much time to keep dests in trash */
817578bc3efSJulian Anastasov #define IP_VS_DEST_TRASH_PERIOD		(120 * HZ)
818578bc3efSJulian Anastasov 
819e4ff6751SJulian Anastasov struct ipvs_sync_daemon_cfg {
820d3328817SJulian Anastasov 	union nf_inet_addr	mcast_group;
821e4ff6751SJulian Anastasov 	int			syncid;
822e4ff6751SJulian Anastasov 	u16			sync_maxlen;
823d3328817SJulian Anastasov 	u16			mcast_port;
824d3328817SJulian Anastasov 	u8			mcast_af;
825d3328817SJulian Anastasov 	u8			mcast_ttl;
826e4ff6751SJulian Anastasov 	/* multicast interface name */
827e4ff6751SJulian Anastasov 	char			mcast_ifn[IP_VS_IFNAME_MAXLEN];
828e4ff6751SJulian Anastasov };
829e4ff6751SJulian Anastasov 
8302553d064SJulian Anastasov /* IPVS in network namespace */
8312553d064SJulian Anastasov struct netns_ipvs {
8322553d064SJulian Anastasov 	int			gen;		/* Generation */
8337a4f0761SHans Schillstrom 	int			enable;		/* enable like nf_hooks do */
83407dcc686SSimon Horman 	/* Hash table: for real service lookups */
8352553d064SJulian Anastasov 	#define IP_VS_RTAB_BITS 4
8362553d064SJulian Anastasov 	#define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS)
8372553d064SJulian Anastasov 	#define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1)
8382553d064SJulian Anastasov 
839276472eaSJulian Anastasov 	struct hlist_head	rs_table[IP_VS_RTAB_SIZE];
8402553d064SJulian Anastasov 	/* ip_vs_app */
8412553d064SJulian Anastasov 	struct list_head	app_list;
8422553d064SJulian Anastasov 	/* ip_vs_proto */
8432553d064SJulian Anastasov 	#define IP_VS_PROTO_TAB_SIZE	32	/* must be power of 2 */
8442553d064SJulian Anastasov 	struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE];
8452553d064SJulian Anastasov 	/* ip_vs_proto_tcp */
8462553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_TCP
8472553d064SJulian Anastasov 	#define	TCP_APP_TAB_BITS	4
8482553d064SJulian Anastasov 	#define	TCP_APP_TAB_SIZE	(1 << TCP_APP_TAB_BITS)
8492553d064SJulian Anastasov 	#define	TCP_APP_TAB_MASK	(TCP_APP_TAB_SIZE - 1)
8502553d064SJulian Anastasov 	struct list_head	tcp_apps[TCP_APP_TAB_SIZE];
8512553d064SJulian Anastasov #endif
8522553d064SJulian Anastasov 	/* ip_vs_proto_udp */
8532553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_UDP
8542553d064SJulian Anastasov 	#define	UDP_APP_TAB_BITS	4
8552553d064SJulian Anastasov 	#define	UDP_APP_TAB_SIZE	(1 << UDP_APP_TAB_BITS)
8562553d064SJulian Anastasov 	#define	UDP_APP_TAB_MASK	(UDP_APP_TAB_SIZE - 1)
8572553d064SJulian Anastasov 	struct list_head	udp_apps[UDP_APP_TAB_SIZE];
8582553d064SJulian Anastasov #endif
8592553d064SJulian Anastasov 	/* ip_vs_proto_sctp */
8602553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_SCTP
8612553d064SJulian Anastasov 	#define SCTP_APP_TAB_BITS	4
8622553d064SJulian Anastasov 	#define SCTP_APP_TAB_SIZE	(1 << SCTP_APP_TAB_BITS)
8632553d064SJulian Anastasov 	#define SCTP_APP_TAB_MASK	(SCTP_APP_TAB_SIZE - 1)
8642553d064SJulian Anastasov 	/* Hash table for SCTP application incarnations	 */
8652553d064SJulian Anastasov 	struct list_head	sctp_apps[SCTP_APP_TAB_SIZE];
8662553d064SJulian Anastasov #endif
8672553d064SJulian Anastasov 	/* ip_vs_conn */
8682553d064SJulian Anastasov 	atomic_t		conn_count;      /* connection counter */
8692553d064SJulian Anastasov 
8702553d064SJulian Anastasov 	/* ip_vs_ctl */
8712a0751afSJulian Anastasov 	struct ip_vs_stats		tot_stats;  /* Statistics & est. */
8722553d064SJulian Anastasov 
8732553d064SJulian Anastasov 	int			num_services;    /* no of virtual services */
874f2247fbdSSimon Horman 
8752553d064SJulian Anastasov 	/* Trash for destinations */
8762553d064SJulian Anastasov 	struct list_head	dest_trash;
877578bc3efSJulian Anastasov 	spinlock_t		dest_trash_lock;
878578bc3efSJulian Anastasov 	struct timer_list	dest_trash_timer; /* expiration timer */
8792553d064SJulian Anastasov 	/* Service counters */
8802553d064SJulian Anastasov 	atomic_t		ftpsvc_counter;
8812553d064SJulian Anastasov 	atomic_t		nullsvc_counter;
88239b97223SMarco Angaroni 	atomic_t		conn_out_counter;
8832553d064SJulian Anastasov 
884f2247fbdSSimon Horman #ifdef CONFIG_SYSCTL
885f2247fbdSSimon Horman 	/* 1/rate drop and drop-entry variables */
886f2247fbdSSimon Horman 	struct delayed_work	defense_work;   /* Work handler */
887f2247fbdSSimon Horman 	int			drop_rate;
888f2247fbdSSimon Horman 	int			drop_counter;
889f2247fbdSSimon Horman 	atomic_t		dropentry;
890f2247fbdSSimon Horman 	/* locks in ctl.c */
891f2247fbdSSimon Horman 	spinlock_t		dropentry_lock;  /* drop entry handling */
892f2247fbdSSimon Horman 	spinlock_t		droppacket_lock; /* drop packet handling */
893f2247fbdSSimon Horman 	spinlock_t		securetcp_lock;  /* state and timeout tables */
894f2247fbdSSimon Horman 
8952553d064SJulian Anastasov 	/* sys-ctl struct */
8962553d064SJulian Anastasov 	struct ctl_table_header	*sysctl_hdr;
8972553d064SJulian Anastasov 	struct ctl_table	*sysctl_tbl;
898f2247fbdSSimon Horman #endif
899f2247fbdSSimon Horman 
9002553d064SJulian Anastasov 	/* sysctl variables */
9012553d064SJulian Anastasov 	int			sysctl_amemthresh;
9022553d064SJulian Anastasov 	int			sysctl_am_droprate;
9032553d064SJulian Anastasov 	int			sysctl_drop_entry;
9042553d064SJulian Anastasov 	int			sysctl_drop_packet;
9052553d064SJulian Anastasov 	int			sysctl_secure_tcp;
9062553d064SJulian Anastasov #ifdef CONFIG_IP_VS_NFCT
9072553d064SJulian Anastasov 	int			sysctl_conntrack;
9082553d064SJulian Anastasov #endif
9092553d064SJulian Anastasov 	int			sysctl_snat_reroute;
9102553d064SJulian Anastasov 	int			sysctl_sync_ver;
911f73181c8SPablo Neira Ayuso 	int			sysctl_sync_ports;
9124d0c875dSJulian Anastasov 	int			sysctl_sync_persist_mode;
91307995674SZhang Yanfei 	unsigned long		sysctl_sync_qlen_max;
9141c003b15SPablo Neira Ayuso 	int			sysctl_sync_sock_size;
9152553d064SJulian Anastasov 	int			sysctl_cache_bypass;
9162553d064SJulian Anastasov 	int			sysctl_expire_nodest_conn;
917c6c96c18SAlexander Frolkin 	int			sysctl_sloppy_tcp;
918c6c96c18SAlexander Frolkin 	int			sysctl_sloppy_sctp;
9192553d064SJulian Anastasov 	int			sysctl_expire_quiescent_template;
9202553d064SJulian Anastasov 	int			sysctl_sync_threshold[2];
921749c42b6SJulian Anastasov 	unsigned int		sysctl_sync_refresh_period;
922749c42b6SJulian Anastasov 	int			sysctl_sync_retries;
9232553d064SJulian Anastasov 	int			sysctl_nat_icmp_send;
9243654e611SJulian Anastasov 	int			sysctl_pmtu_disc;
9250c12582fSJulian Anastasov 	int			sysctl_backup_only;
926d752c364SMarcelo Ricardo Leitner 	int			sysctl_conn_reuse_mode;
92794485fedSAlex Gartrell 	int			sysctl_schedule_icmp;
9284e478098SAlex Gartrell 	int			sysctl_ignore_tunneled;
9292553d064SJulian Anastasov 
9302553d064SJulian Anastasov 	/* ip_vs_lblc */
9312553d064SJulian Anastasov 	int			sysctl_lblc_expiration;
9322553d064SJulian Anastasov 	struct ctl_table_header	*lblc_ctl_header;
9332553d064SJulian Anastasov 	struct ctl_table	*lblc_ctl_table;
9342553d064SJulian Anastasov 	/* ip_vs_lblcr */
9352553d064SJulian Anastasov 	int			sysctl_lblcr_expiration;
9362553d064SJulian Anastasov 	struct ctl_table_header	*lblcr_ctl_header;
9372553d064SJulian Anastasov 	struct ctl_table	*lblcr_ctl_table;
9382553d064SJulian Anastasov 	/* ip_vs_est */
9392553d064SJulian Anastasov 	struct list_head	est_list;	/* estimator list */
9402553d064SJulian Anastasov 	spinlock_t		est_lock;
9412553d064SJulian Anastasov 	struct timer_list	est_timer;	/* Estimation timer */
9422553d064SJulian Anastasov 	/* ip_vs_sync */
9432553d064SJulian Anastasov 	spinlock_t		sync_lock;
944f73181c8SPablo Neira Ayuso 	struct ipvs_master_sync_state *ms;
9452553d064SJulian Anastasov 	spinlock_t		sync_buff_lock;
946f73181c8SPablo Neira Ayuso 	struct task_struct	**backup_threads;
947f73181c8SPablo Neira Ayuso 	int			threads_mask;
9482553d064SJulian Anastasov 	volatile int		sync_state;
949ae1d48b2SHans Schillstrom 	struct mutex		sync_mutex;
950e4ff6751SJulian Anastasov 	struct ipvs_sync_daemon_cfg	mcfg;	/* Master Configuration */
951e4ff6751SJulian Anastasov 	struct ipvs_sync_daemon_cfg	bcfg;	/* Backup Configuration */
9522553d064SJulian Anastasov 	/* net name space ptr */
9532553d064SJulian Anastasov 	struct net		*net;            /* Needed by timer routines */
95407dcc686SSimon Horman 	/* Number of heterogeneous destinations, needed becaus heterogeneous
95507dcc686SSimon Horman 	 * are not supported when synchronization is enabled.
95607dcc686SSimon Horman 	 */
957391f503dSAlex Gartrell 	unsigned int		mixed_address_family_dests;
9582553d064SJulian Anastasov };
9591da177e4SLinus Torvalds 
96059e0350eSSimon Horman #define DEFAULT_SYNC_THRESHOLD	3
96159e0350eSSimon Horman #define DEFAULT_SYNC_PERIOD	50
9627532e8d4SSimon Horman #define DEFAULT_SYNC_VER	1
963c6c96c18SAlexander Frolkin #define DEFAULT_SLOPPY_TCP	0
964c6c96c18SAlexander Frolkin #define DEFAULT_SLOPPY_SCTP	0
965749c42b6SJulian Anastasov #define DEFAULT_SYNC_REFRESH_PERIOD	(0U * HZ)
966749c42b6SJulian Anastasov #define DEFAULT_SYNC_RETRIES		0
9671c003b15SPablo Neira Ayuso #define IPVS_SYNC_WAKEUP_RATE	8
9681c003b15SPablo Neira Ayuso #define IPVS_SYNC_QLEN_MAX	(IPVS_SYNC_WAKEUP_RATE * 4)
9691c003b15SPablo Neira Ayuso #define IPVS_SYNC_SEND_DELAY	(HZ / 50)
9701c003b15SPablo Neira Ayuso #define IPVS_SYNC_CHECK_PERIOD	HZ
971749c42b6SJulian Anastasov #define IPVS_SYNC_FLUSH_TIME	(HZ * 2)
972f73181c8SPablo Neira Ayuso #define IPVS_SYNC_PORTS_MAX	(1 << 6)
97359e0350eSSimon Horman 
97459e0350eSSimon Horman #ifdef CONFIG_SYSCTL
97559e0350eSSimon Horman 
97659e0350eSSimon Horman static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
97759e0350eSSimon Horman {
97859e0350eSSimon Horman 	return ipvs->sysctl_sync_threshold[0];
97959e0350eSSimon Horman }
98059e0350eSSimon Horman 
98159e0350eSSimon Horman static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
98259e0350eSSimon Horman {
9836aa7de05SMark Rutland 	return READ_ONCE(ipvs->sysctl_sync_threshold[1]);
984749c42b6SJulian Anastasov }
985749c42b6SJulian Anastasov 
986749c42b6SJulian Anastasov static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
987749c42b6SJulian Anastasov {
9886aa7de05SMark Rutland 	return READ_ONCE(ipvs->sysctl_sync_refresh_period);
989749c42b6SJulian Anastasov }
990749c42b6SJulian Anastasov 
991749c42b6SJulian Anastasov static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
992749c42b6SJulian Anastasov {
993749c42b6SJulian Anastasov 	return ipvs->sysctl_sync_retries;
99459e0350eSSimon Horman }
99559e0350eSSimon Horman 
9967532e8d4SSimon Horman static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
9977532e8d4SSimon Horman {
9987532e8d4SSimon Horman 	return ipvs->sysctl_sync_ver;
9997532e8d4SSimon Horman }
10007532e8d4SSimon Horman 
1001c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs)
1002c6c96c18SAlexander Frolkin {
1003c6c96c18SAlexander Frolkin 	return ipvs->sysctl_sloppy_tcp;
1004c6c96c18SAlexander Frolkin }
1005c6c96c18SAlexander Frolkin 
1006c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs)
1007c6c96c18SAlexander Frolkin {
1008c6c96c18SAlexander Frolkin 	return ipvs->sysctl_sloppy_sctp;
1009c6c96c18SAlexander Frolkin }
1010c6c96c18SAlexander Frolkin 
1011f73181c8SPablo Neira Ayuso static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
1012f73181c8SPablo Neira Ayuso {
10136aa7de05SMark Rutland 	return READ_ONCE(ipvs->sysctl_sync_ports);
1014f73181c8SPablo Neira Ayuso }
1015f73181c8SPablo Neira Ayuso 
10164d0c875dSJulian Anastasov static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs)
10174d0c875dSJulian Anastasov {
10184d0c875dSJulian Anastasov 	return ipvs->sysctl_sync_persist_mode;
10194d0c875dSJulian Anastasov }
10204d0c875dSJulian Anastasov 
102107995674SZhang Yanfei static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
10221c003b15SPablo Neira Ayuso {
10231c003b15SPablo Neira Ayuso 	return ipvs->sysctl_sync_qlen_max;
10241c003b15SPablo Neira Ayuso }
10251c003b15SPablo Neira Ayuso 
10261c003b15SPablo Neira Ayuso static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
10271c003b15SPablo Neira Ayuso {
10281c003b15SPablo Neira Ayuso 	return ipvs->sysctl_sync_sock_size;
10291c003b15SPablo Neira Ayuso }
10301c003b15SPablo Neira Ayuso 
10313654e611SJulian Anastasov static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
10323654e611SJulian Anastasov {
10333654e611SJulian Anastasov 	return ipvs->sysctl_pmtu_disc;
10343654e611SJulian Anastasov }
10353654e611SJulian Anastasov 
10360c12582fSJulian Anastasov static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
10370c12582fSJulian Anastasov {
10380c12582fSJulian Anastasov 	return ipvs->sync_state & IP_VS_STATE_BACKUP &&
10390c12582fSJulian Anastasov 	       ipvs->sysctl_backup_only;
10400c12582fSJulian Anastasov }
10410c12582fSJulian Anastasov 
1042d752c364SMarcelo Ricardo Leitner static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs)
1043d752c364SMarcelo Ricardo Leitner {
1044d752c364SMarcelo Ricardo Leitner 	return ipvs->sysctl_conn_reuse_mode;
1045d752c364SMarcelo Ricardo Leitner }
1046d752c364SMarcelo Ricardo Leitner 
104794485fedSAlex Gartrell static inline int sysctl_schedule_icmp(struct netns_ipvs *ipvs)
104894485fedSAlex Gartrell {
104994485fedSAlex Gartrell 	return ipvs->sysctl_schedule_icmp;
105094485fedSAlex Gartrell }
105194485fedSAlex Gartrell 
10524e478098SAlex Gartrell static inline int sysctl_ignore_tunneled(struct netns_ipvs *ipvs)
10534e478098SAlex Gartrell {
10544e478098SAlex Gartrell 	return ipvs->sysctl_ignore_tunneled;
10554e478098SAlex Gartrell }
10564e478098SAlex Gartrell 
105757032948SEric W. Biederman static inline int sysctl_cache_bypass(struct netns_ipvs *ipvs)
105857032948SEric W. Biederman {
105957032948SEric W. Biederman 	return ipvs->sysctl_cache_bypass;
106057032948SEric W. Biederman }
106157032948SEric W. Biederman 
106259e0350eSSimon Horman #else
106359e0350eSSimon Horman 
106459e0350eSSimon Horman static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
106559e0350eSSimon Horman {
106659e0350eSSimon Horman 	return DEFAULT_SYNC_THRESHOLD;
106759e0350eSSimon Horman }
106859e0350eSSimon Horman 
106959e0350eSSimon Horman static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
107059e0350eSSimon Horman {
107159e0350eSSimon Horman 	return DEFAULT_SYNC_PERIOD;
107259e0350eSSimon Horman }
107359e0350eSSimon Horman 
1074749c42b6SJulian Anastasov static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
1075749c42b6SJulian Anastasov {
1076749c42b6SJulian Anastasov 	return DEFAULT_SYNC_REFRESH_PERIOD;
1077749c42b6SJulian Anastasov }
1078749c42b6SJulian Anastasov 
1079749c42b6SJulian Anastasov static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
1080749c42b6SJulian Anastasov {
1081749c42b6SJulian Anastasov 	return DEFAULT_SYNC_RETRIES & 3;
1082749c42b6SJulian Anastasov }
1083749c42b6SJulian Anastasov 
10847532e8d4SSimon Horman static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
10857532e8d4SSimon Horman {
10867532e8d4SSimon Horman 	return DEFAULT_SYNC_VER;
10877532e8d4SSimon Horman }
10887532e8d4SSimon Horman 
1089c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs)
1090c6c96c18SAlexander Frolkin {
1091c6c96c18SAlexander Frolkin 	return DEFAULT_SLOPPY_TCP;
1092c6c96c18SAlexander Frolkin }
1093c6c96c18SAlexander Frolkin 
1094c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs)
1095c6c96c18SAlexander Frolkin {
1096c6c96c18SAlexander Frolkin 	return DEFAULT_SLOPPY_SCTP;
1097c6c96c18SAlexander Frolkin }
1098c6c96c18SAlexander Frolkin 
1099f73181c8SPablo Neira Ayuso static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
1100f73181c8SPablo Neira Ayuso {
1101f73181c8SPablo Neira Ayuso 	return 1;
1102f73181c8SPablo Neira Ayuso }
1103f73181c8SPablo Neira Ayuso 
11044d0c875dSJulian Anastasov static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs)
11054d0c875dSJulian Anastasov {
11064d0c875dSJulian Anastasov 	return 0;
11074d0c875dSJulian Anastasov }
11084d0c875dSJulian Anastasov 
110907995674SZhang Yanfei static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
11101c003b15SPablo Neira Ayuso {
11111c003b15SPablo Neira Ayuso 	return IPVS_SYNC_QLEN_MAX;
11121c003b15SPablo Neira Ayuso }
11131c003b15SPablo Neira Ayuso 
11141c003b15SPablo Neira Ayuso static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
11151c003b15SPablo Neira Ayuso {
11161c003b15SPablo Neira Ayuso 	return 0;
11171c003b15SPablo Neira Ayuso }
11181c003b15SPablo Neira Ayuso 
11193654e611SJulian Anastasov static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
11203654e611SJulian Anastasov {
11213654e611SJulian Anastasov 	return 1;
11223654e611SJulian Anastasov }
11233654e611SJulian Anastasov 
11240c12582fSJulian Anastasov static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
11250c12582fSJulian Anastasov {
11260c12582fSJulian Anastasov 	return 0;
11270c12582fSJulian Anastasov }
11280c12582fSJulian Anastasov 
1129d752c364SMarcelo Ricardo Leitner static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs)
1130d752c364SMarcelo Ricardo Leitner {
1131d752c364SMarcelo Ricardo Leitner 	return 1;
1132d752c364SMarcelo Ricardo Leitner }
1133d752c364SMarcelo Ricardo Leitner 
113494485fedSAlex Gartrell static inline int sysctl_schedule_icmp(struct netns_ipvs *ipvs)
113594485fedSAlex Gartrell {
113694485fedSAlex Gartrell 	return 0;
113794485fedSAlex Gartrell }
113894485fedSAlex Gartrell 
11394e478098SAlex Gartrell static inline int sysctl_ignore_tunneled(struct netns_ipvs *ipvs)
11404e478098SAlex Gartrell {
11414e478098SAlex Gartrell 	return 0;
11424e478098SAlex Gartrell }
11434e478098SAlex Gartrell 
114457032948SEric W. Biederman static inline int sysctl_cache_bypass(struct netns_ipvs *ipvs)
114557032948SEric W. Biederman {
114657032948SEric W. Biederman 	return 0;
114757032948SEric W. Biederman }
114857032948SEric W. Biederman 
114959e0350eSSimon Horman #endif
115059e0350eSSimon Horman 
115107dcc686SSimon Horman /* IPVS core functions
11521da177e4SLinus Torvalds  * (from ip_vs_core.c)
11531da177e4SLinus Torvalds  */
11545c3a0fd7SJoe Perches const char *ip_vs_proto_name(unsigned int proto);
11555c3a0fd7SJoe Perches void ip_vs_init_hash_table(struct list_head *table, int rows);
115639b97223SMarco Angaroni struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc,
115739b97223SMarco Angaroni 				      struct ip_vs_dest *dest,
115839b97223SMarco Angaroni 				      struct sk_buff *skb,
115939b97223SMarco Angaroni 				      const struct ip_vs_iphdr *iph,
116039b97223SMarco Angaroni 				      __be16 dport,
116139b97223SMarco Angaroni 				      __be16 cport);
1162afdd6140SSven Wegener #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
11631da177e4SLinus Torvalds 
11641da177e4SLinus Torvalds #define IP_VS_APP_TYPE_FTP	1
11651da177e4SLinus Torvalds 
116607dcc686SSimon Horman /* ip_vs_conn handling functions
11671da177e4SLinus Torvalds  * (from ip_vs_conn.c)
11681da177e4SLinus Torvalds  */
11691da177e4SLinus Torvalds enum {
11701da177e4SLinus Torvalds 	IP_VS_DIR_INPUT = 0,
11711da177e4SLinus Torvalds 	IP_VS_DIR_OUTPUT,
11721da177e4SLinus Torvalds 	IP_VS_DIR_INPUT_ONLY,
11731da177e4SLinus Torvalds 	IP_VS_DIR_LAST,
11741da177e4SLinus Torvalds };
11751da177e4SLinus Torvalds 
117619913decSEric W. Biederman static inline void ip_vs_conn_fill_param(struct netns_ipvs *ipvs, int af, int protocol,
1177f11017ecSSimon Horman 					 const union nf_inet_addr *caddr,
1178f11017ecSSimon Horman 					 __be16 cport,
1179f11017ecSSimon Horman 					 const union nf_inet_addr *vaddr,
1180f11017ecSSimon Horman 					 __be16 vport,
1181f11017ecSSimon Horman 					 struct ip_vs_conn_param *p)
1182f11017ecSSimon Horman {
118319913decSEric W. Biederman 	p->ipvs = ipvs;
1184f11017ecSSimon Horman 	p->af = af;
1185f11017ecSSimon Horman 	p->protocol = protocol;
1186f11017ecSSimon Horman 	p->caddr = caddr;
1187f11017ecSSimon Horman 	p->cport = cport;
1188f11017ecSSimon Horman 	p->vaddr = vaddr;
1189f11017ecSSimon Horman 	p->vport = vport;
119085999283SSimon Horman 	p->pe = NULL;
119185999283SSimon Horman 	p->pe_data = NULL;
1192f11017ecSSimon Horman }
119328364a59SJulius Volz 
1194f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p);
1195f11017ecSSimon Horman struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p);
119628364a59SJulius Volz 
1197ab161976SEric W. Biederman struct ip_vs_conn * ip_vs_conn_in_get_proto(struct netns_ipvs *ipvs, int af,
1198ab161976SEric W. Biederman 					    const struct sk_buff *skb,
1199802c41adSAlex Gartrell 					    const struct ip_vs_iphdr *iph);
12005c0d2374SSimon Horman 
1201f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p);
12021da177e4SLinus Torvalds 
12030cf705c8SEric W. Biederman struct ip_vs_conn * ip_vs_conn_out_get_proto(struct netns_ipvs *ipvs, int af,
12040cf705c8SEric W. Biederman 					     const struct sk_buff *skb,
1205802c41adSAlex Gartrell 					     const struct ip_vs_iphdr *iph);
12065c0d2374SSimon Horman 
1207088339a5SJulian Anastasov /* Get reference to gain full access to conn.
1208088339a5SJulian Anastasov  * By default, RCU read-side critical sections have access only to
1209088339a5SJulian Anastasov  * conn fields and its PE data, see ip_vs_conn_rcu_free() for reference.
1210088339a5SJulian Anastasov  */
1211088339a5SJulian Anastasov static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp)
1212088339a5SJulian Anastasov {
1213b54ab92bSReshetova, Elena 	return refcount_inc_not_zero(&cp->refcnt);
1214088339a5SJulian Anastasov }
1215088339a5SJulian Anastasov 
12161da177e4SLinus Torvalds /* put back the conn without restarting its timer */
12171da177e4SLinus Torvalds static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
12181da177e4SLinus Torvalds {
12194e857c58SPeter Zijlstra 	smp_mb__before_atomic();
1220b54ab92bSReshetova, Elena 	refcount_dec(&cp->refcnt);
12211da177e4SLinus Torvalds }
12225c3a0fd7SJoe Perches void ip_vs_conn_put(struct ip_vs_conn *cp);
12235c3a0fd7SJoe Perches void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
12241da177e4SLinus Torvalds 
1225ba38528aSAlex Gartrell struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
1226f11017ecSSimon Horman 				  const union nf_inet_addr *daddr,
122795c96174SEric Dumazet 				  __be16 dport, unsigned int flags,
12280e051e68SHans Schillstrom 				  struct ip_vs_dest *dest, __u32 fwmark);
12295c3a0fd7SJoe Perches void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
12301da177e4SLinus Torvalds 
1231ec1b28caSJulian Anastasov const char *ip_vs_state_name(const struct ip_vs_conn *cp);
12321da177e4SLinus Torvalds 
123369f39093SEric W. Biederman void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
12343ec10d3aSMarco Angaroni int ip_vs_check_template(struct ip_vs_conn *ct, struct ip_vs_dest *cdest);
1235423b5595SEric W. Biederman void ip_vs_random_dropentry(struct netns_ipvs *ipvs);
12365c3a0fd7SJoe Perches int ip_vs_conn_init(void);
12375c3a0fd7SJoe Perches void ip_vs_conn_cleanup(void);
12381da177e4SLinus Torvalds 
12391da177e4SLinus Torvalds static inline void ip_vs_control_del(struct ip_vs_conn *cp)
12401da177e4SLinus Torvalds {
12411da177e4SLinus Torvalds 	struct ip_vs_conn *ctl_cp = cp->control;
12421da177e4SLinus Torvalds 	if (!ctl_cp) {
1243cfc78c5aSJulius Volz 		IP_VS_ERR_BUF("request control DEL for uncontrolled: "
1244cfc78c5aSJulius Volz 			      "%s:%d to %s:%d\n",
1245cfc78c5aSJulius Volz 			      IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1246cfc78c5aSJulius Volz 			      ntohs(cp->cport),
1247cfc78c5aSJulius Volz 			      IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
1248cfc78c5aSJulius Volz 			      ntohs(cp->vport));
1249cfc78c5aSJulius Volz 
12501da177e4SLinus Torvalds 		return;
12511da177e4SLinus Torvalds 	}
12521da177e4SLinus Torvalds 
1253cfc78c5aSJulius Volz 	IP_VS_DBG_BUF(7, "DELeting control for: "
1254cfc78c5aSJulius Volz 		      "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
1255cfc78c5aSJulius Volz 		      IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1256cfc78c5aSJulius Volz 		      ntohs(cp->cport),
1257cfc78c5aSJulius Volz 		      IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
1258cfc78c5aSJulius Volz 		      ntohs(ctl_cp->cport));
12591da177e4SLinus Torvalds 
12601da177e4SLinus Torvalds 	cp->control = NULL;
12611da177e4SLinus Torvalds 	if (atomic_read(&ctl_cp->n_control) == 0) {
1262cfc78c5aSJulius Volz 		IP_VS_ERR_BUF("BUG control DEL with n=0 : "
1263cfc78c5aSJulius Volz 			      "%s:%d to %s:%d\n",
1264cfc78c5aSJulius Volz 			      IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1265cfc78c5aSJulius Volz 			      ntohs(cp->cport),
1266cfc78c5aSJulius Volz 			      IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
1267cfc78c5aSJulius Volz 			      ntohs(cp->vport));
1268cfc78c5aSJulius Volz 
12691da177e4SLinus Torvalds 		return;
12701da177e4SLinus Torvalds 	}
12711da177e4SLinus Torvalds 	atomic_dec(&ctl_cp->n_control);
12721da177e4SLinus Torvalds }
12731da177e4SLinus Torvalds 
12741da177e4SLinus Torvalds static inline void
12751da177e4SLinus Torvalds ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
12761da177e4SLinus Torvalds {
12771da177e4SLinus Torvalds 	if (cp->control) {
1278cfc78c5aSJulius Volz 		IP_VS_ERR_BUF("request control ADD for already controlled: "
1279cfc78c5aSJulius Volz 			      "%s:%d to %s:%d\n",
1280cfc78c5aSJulius Volz 			      IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1281cfc78c5aSJulius Volz 			      ntohs(cp->cport),
1282cfc78c5aSJulius Volz 			      IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
1283cfc78c5aSJulius Volz 			      ntohs(cp->vport));
1284cfc78c5aSJulius Volz 
12851da177e4SLinus Torvalds 		ip_vs_control_del(cp);
12861da177e4SLinus Torvalds 	}
12871da177e4SLinus Torvalds 
1288cfc78c5aSJulius Volz 	IP_VS_DBG_BUF(7, "ADDing control for: "
1289cfc78c5aSJulius Volz 		      "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
1290cfc78c5aSJulius Volz 		      IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1291cfc78c5aSJulius Volz 		      ntohs(cp->cport),
1292cfc78c5aSJulius Volz 		      IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
1293cfc78c5aSJulius Volz 		      ntohs(ctl_cp->cport));
12941da177e4SLinus Torvalds 
12951da177e4SLinus Torvalds 	cp->control = ctl_cp;
12961da177e4SLinus Torvalds 	atomic_inc(&ctl_cp->n_control);
12971da177e4SLinus Torvalds }
12981da177e4SLinus Torvalds 
129927541143SJulian Anastasov /* Mark our template as assured */
130027541143SJulian Anastasov static inline void
130127541143SJulian Anastasov ip_vs_control_assure_ct(struct ip_vs_conn *cp)
130227541143SJulian Anastasov {
130327541143SJulian Anastasov 	struct ip_vs_conn *ct = cp->control;
130427541143SJulian Anastasov 
130527541143SJulian Anastasov 	if (ct && !(ct->state & IP_VS_CTPL_S_ASSURED) &&
130627541143SJulian Anastasov 	    (ct->flags & IP_VS_CONN_F_TEMPLATE))
130727541143SJulian Anastasov 		ct->state |= IP_VS_CTPL_S_ASSURED;
130827541143SJulian Anastasov }
130927541143SJulian Anastasov 
131007dcc686SSimon Horman /* IPVS netns init & cleanup functions */
1311a4dd0360SEric W. Biederman int ip_vs_estimator_net_init(struct netns_ipvs *ipvs);
13123d993766SEric W. Biederman int ip_vs_control_net_init(struct netns_ipvs *ipvs);
13137d1f88ecSEric W. Biederman int ip_vs_protocol_net_init(struct netns_ipvs *ipvs);
1314b5dd212cSEric W. Biederman int ip_vs_app_net_init(struct netns_ipvs *ipvs);
13152f3edc6aSEric W. Biederman int ip_vs_conn_net_init(struct netns_ipvs *ipvs);
1316802cb437SEric W. Biederman int ip_vs_sync_net_init(struct netns_ipvs *ipvs);
13172f3edc6aSEric W. Biederman void ip_vs_conn_net_cleanup(struct netns_ipvs *ipvs);
1318b5dd212cSEric W. Biederman void ip_vs_app_net_cleanup(struct netns_ipvs *ipvs);
13197d1f88ecSEric W. Biederman void ip_vs_protocol_net_cleanup(struct netns_ipvs *ipvs);
13203d993766SEric W. Biederman void ip_vs_control_net_cleanup(struct netns_ipvs *ipvs);
1321a4dd0360SEric W. Biederman void ip_vs_estimator_net_cleanup(struct netns_ipvs *ipvs);
1322ebea1f7cSEric W. Biederman void ip_vs_sync_net_cleanup(struct netns_ipvs *ipvs);
132356d2169bSEric W. Biederman void ip_vs_service_net_cleanup(struct netns_ipvs *ipvs);
13241da177e4SLinus Torvalds 
132507dcc686SSimon Horman /* IPVS application functions
13261da177e4SLinus Torvalds  * (from ip_vs_app.c)
13271da177e4SLinus Torvalds  */
13281da177e4SLinus Torvalds #define IP_VS_APP_MAX_PORTS  8
13299f8128a5SEric W. Biederman struct ip_vs_app *register_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app);
13309f8128a5SEric W. Biederman void unregister_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app);
13315c3a0fd7SJoe Perches int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
13325c3a0fd7SJoe Perches void ip_vs_unbind_app(struct ip_vs_conn *cp);
13333250dc9cSEric W. Biederman int register_ip_vs_app_inc(struct netns_ipvs *ipvs, struct ip_vs_app *app, __u16 proto,
13345c3a0fd7SJoe Perches 			   __u16 port);
13355c3a0fd7SJoe Perches int ip_vs_app_inc_get(struct ip_vs_app *inc);
13365c3a0fd7SJoe Perches void ip_vs_app_inc_put(struct ip_vs_app *inc);
13371da177e4SLinus Torvalds 
1338d12e1229SJulian Anastasov int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb,
1339d12e1229SJulian Anastasov 		      struct ip_vs_iphdr *ipvsh);
1340d12e1229SJulian Anastasov int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb,
1341d12e1229SJulian Anastasov 		     struct ip_vs_iphdr *ipvsh);
13421da177e4SLinus Torvalds 
13438be67a66SSimon Horman int register_ip_vs_pe(struct ip_vs_pe *pe);
13448be67a66SSimon Horman int unregister_ip_vs_pe(struct ip_vs_pe *pe);
1345e9e5eee8SSimon Horman struct ip_vs_pe *ip_vs_pe_getbyname(const char *name);
1346fe5e7a1eSHans Schillstrom struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name);
1347e9e5eee8SSimon Horman 
134807dcc686SSimon Horman /* Use a #define to avoid all of module.h just for these trivial ops */
134969e7dae4SPaul Gortmaker #define ip_vs_pe_get(pe)			\
135069e7dae4SPaul Gortmaker 	if (pe && pe->module)			\
1351e9e5eee8SSimon Horman 		__module_get(pe->module);
1352e9e5eee8SSimon Horman 
135369e7dae4SPaul Gortmaker #define ip_vs_pe_put(pe)			\
135469e7dae4SPaul Gortmaker 	if (pe && pe->module)			\
1355e9e5eee8SSimon Horman 		module_put(pe->module);
13561da177e4SLinus Torvalds 
135707dcc686SSimon Horman /* IPVS protocol functions (from ip_vs_proto.c) */
13585c3a0fd7SJoe Perches int ip_vs_protocol_init(void);
13595c3a0fd7SJoe Perches void ip_vs_protocol_cleanup(void);
13605c3a0fd7SJoe Perches void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags);
13615c3a0fd7SJoe Perches int *ip_vs_create_timeout_table(int *table, int size);
13625c3a0fd7SJoe Perches void ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,
13635c3a0fd7SJoe Perches 			       const struct sk_buff *skb, int offset,
13645c3a0fd7SJoe Perches 			       const char *msg);
13651da177e4SLinus Torvalds 
13661da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_tcp;
13671da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_udp;
13681da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_icmp;
13691da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_esp;
13701da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_ah;
13712906f66aSVenkata Mohan Reddy extern struct ip_vs_protocol ip_vs_protocol_sctp;
13721da177e4SLinus Torvalds 
137307dcc686SSimon Horman /* Registering/unregistering scheduler functions
13741da177e4SLinus Torvalds  * (from ip_vs_sched.c)
13751da177e4SLinus Torvalds  */
13765c3a0fd7SJoe Perches int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
13775c3a0fd7SJoe Perches int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
13785c3a0fd7SJoe Perches int ip_vs_bind_scheduler(struct ip_vs_service *svc,
13791da177e4SLinus Torvalds 			 struct ip_vs_scheduler *scheduler);
13805c3a0fd7SJoe Perches void ip_vs_unbind_scheduler(struct ip_vs_service *svc,
1381ceec4c38SJulian Anastasov 			    struct ip_vs_scheduler *sched);
13825c3a0fd7SJoe Perches struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
13835c3a0fd7SJoe Perches void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
13845c3a0fd7SJoe Perches struct ip_vs_conn *
1385190ecd27SJulian Anastasov ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
1386d4383f04SJesper Dangaard Brouer 	       struct ip_vs_proto_data *pd, int *ignored,
1387d4383f04SJesper Dangaard Brouer 	       struct ip_vs_iphdr *iph);
13885c3a0fd7SJoe Perches int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
1389d4383f04SJesper Dangaard Brouer 		struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph);
13901da177e4SLinus Torvalds 
13915c3a0fd7SJoe Perches void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg);
139241ac51eeSPatrick Schaaf 
139307dcc686SSimon Horman /* IPVS control data and functions (from ip_vs_ctl.c) */
13941da177e4SLinus Torvalds extern struct ip_vs_stats ip_vs_stats;
1395b880c1f0SHans Schillstrom extern int sysctl_ip_vs_sync_ver;
13961da177e4SLinus Torvalds 
13975c3a0fd7SJoe Perches struct ip_vs_service *
13980a4fd6ceSEric W. Biederman ip_vs_service_find(struct netns_ipvs *ipvs, int af, __u32 fwmark, __u16 protocol,
13993c2e0505SJulius Volz 		  const union nf_inet_addr *vaddr, __be16 vport);
14001da177e4SLinus Torvalds 
140148aed1b0SEric W. Biederman bool ip_vs_has_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol,
14027937df15SJulius Volz 			    const union nf_inet_addr *daddr, __be16 dport);
14037937df15SJulius Volz 
140439b97223SMarco Angaroni struct ip_vs_dest *
140539b97223SMarco Angaroni ip_vs_find_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol,
140639b97223SMarco Angaroni 			const union nf_inet_addr *daddr, __be16 dport);
140739b97223SMarco Angaroni 
14085c3a0fd7SJoe Perches int ip_vs_use_count_inc(void);
14095c3a0fd7SJoe Perches void ip_vs_use_count_dec(void);
14105c3a0fd7SJoe Perches int ip_vs_register_nl_ioctl(void);
14115c3a0fd7SJoe Perches void ip_vs_unregister_nl_ioctl(void);
14125c3a0fd7SJoe Perches int ip_vs_control_init(void);
14135c3a0fd7SJoe Perches void ip_vs_control_cleanup(void);
14145c3a0fd7SJoe Perches struct ip_vs_dest *
1415dc2add6fSEric W. Biederman ip_vs_find_dest(struct netns_ipvs *ipvs, int svc_af, int dest_af,
1416655eef10SAlex Gartrell 		const union nf_inet_addr *daddr, __be16 dport,
1417655eef10SAlex Gartrell 		const union nf_inet_addr *vaddr, __be16 vport,
141852793dbeSJulian Anastasov 		__u16 protocol, __u32 fwmark, __u32 flags);
14195c3a0fd7SJoe Perches void ip_vs_try_bind_dest(struct ip_vs_conn *cp);
14201da177e4SLinus Torvalds 
1421fca9c20aSJulian Anastasov static inline void ip_vs_dest_hold(struct ip_vs_dest *dest)
1422fca9c20aSJulian Anastasov {
1423b54ab92bSReshetova, Elena 	refcount_inc(&dest->refcnt);
1424fca9c20aSJulian Anastasov }
1425fca9c20aSJulian Anastasov 
1426fca9c20aSJulian Anastasov static inline void ip_vs_dest_put(struct ip_vs_dest *dest)
1427fca9c20aSJulian Anastasov {
14284e857c58SPeter Zijlstra 	smp_mb__before_atomic();
1429b54ab92bSReshetova, Elena 	refcount_dec(&dest->refcnt);
1430fca9c20aSJulian Anastasov }
14311da177e4SLinus Torvalds 
14329e4e948aSJulian Anastasov static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)
14339e4e948aSJulian Anastasov {
1434b54ab92bSReshetova, Elena 	if (refcount_dec_and_test(&dest->refcnt))
14359e4e948aSJulian Anastasov 		kfree(dest);
14369e4e948aSJulian Anastasov }
14379e4e948aSJulian Anastasov 
143807dcc686SSimon Horman /* IPVS sync daemon data and function prototypes
14391da177e4SLinus Torvalds  * (from ip_vs_sync.c)
14401da177e4SLinus Torvalds  */
14416ac121d7SEric W. Biederman int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *cfg,
1442e4ff6751SJulian Anastasov 		      int state);
1443b3cf3cbfSEric W. Biederman int stop_sync_thread(struct netns_ipvs *ipvs, int state);
1444b61a8c1aSEric W. Biederman void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts);
14451da177e4SLinus Torvalds 
144607dcc686SSimon Horman /* IPVS rate estimator prototypes (from ip_vs_est.c) */
14470f34d54bSEric W. Biederman void ip_vs_start_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats);
14480f34d54bSEric W. Biederman void ip_vs_stop_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats);
14495c3a0fd7SJoe Perches void ip_vs_zero_estimator(struct ip_vs_stats *stats);
1450cd67cd5eSJulian Anastasov void ip_vs_read_estimator(struct ip_vs_kstats *dst, struct ip_vs_stats *stats);
14511da177e4SLinus Torvalds 
145207dcc686SSimon Horman /* Various IPVS packet transmitters (from ip_vs_xmit.c) */
14535c3a0fd7SJoe Perches int ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1454d4383f04SJesper Dangaard Brouer 		    struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
14555c3a0fd7SJoe Perches int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1456d4383f04SJesper Dangaard Brouer 		      struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
14575c3a0fd7SJoe Perches int ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1458d4383f04SJesper Dangaard Brouer 		   struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
14595c3a0fd7SJoe Perches int ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
14605c3a0fd7SJoe Perches 		      struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
14615c3a0fd7SJoe Perches int ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
14625c3a0fd7SJoe Perches 		  struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
14635c3a0fd7SJoe Perches int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1464d4383f04SJesper Dangaard Brouer 		    struct ip_vs_protocol *pp, int offset,
1465d4383f04SJesper Dangaard Brouer 		    unsigned int hooknum, struct ip_vs_iphdr *iph);
14665c3a0fd7SJoe Perches void ip_vs_dest_dst_rcu_free(struct rcu_head *head);
14671da177e4SLinus Torvalds 
1468b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6
14695c3a0fd7SJoe Perches int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1470d4383f04SJesper Dangaard Brouer 			 struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
14715c3a0fd7SJoe Perches int ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
14725c3a0fd7SJoe Perches 		      struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
14735c3a0fd7SJoe Perches int ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
14745c3a0fd7SJoe Perches 			 struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
14755c3a0fd7SJoe Perches int ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
14765c3a0fd7SJoe Perches 		     struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
14775c3a0fd7SJoe Perches int ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1478d4383f04SJesper Dangaard Brouer 		       struct ip_vs_protocol *pp, int offset,
1479d4383f04SJesper Dangaard Brouer 		       unsigned int hooknum, struct ip_vs_iphdr *iph);
1480b3cdd2a7SJulius Volz #endif
14811da177e4SLinus Torvalds 
14823a1bbf18SSimon Horman #ifdef CONFIG_SYSCTL
148307dcc686SSimon Horman /* This is a simple mechanism to ignore packets when
14841da177e4SLinus Torvalds  * we are loaded. Just set ip_vs_drop_rate to 'n' and
14851da177e4SLinus Torvalds  * we start to drop 1/rate of the packets
14861da177e4SLinus Torvalds  */
1487a0840e2eSHans Schillstrom static inline int ip_vs_todrop(struct netns_ipvs *ipvs)
14881da177e4SLinus Torvalds {
1489a0840e2eSHans Schillstrom 	if (!ipvs->drop_rate)
1490a0840e2eSHans Schillstrom 		return 0;
1491a0840e2eSHans Schillstrom 	if (--ipvs->drop_counter > 0)
1492a0840e2eSHans Schillstrom 		return 0;
1493a0840e2eSHans Schillstrom 	ipvs->drop_counter = ipvs->drop_rate;
14941da177e4SLinus Torvalds 	return 1;
14951da177e4SLinus Torvalds }
14963a1bbf18SSimon Horman #else
14973a1bbf18SSimon Horman static inline int ip_vs_todrop(struct netns_ipvs *ipvs) { return 0; }
14983a1bbf18SSimon Horman #endif
14991da177e4SLinus Torvalds 
150007dcc686SSimon Horman /* ip_vs_fwd_tag returns the forwarding tag of the connection */
15011da177e4SLinus Torvalds #define IP_VS_FWD_METHOD(cp)  (cp->flags & IP_VS_CONN_F_FWD_MASK)
15021da177e4SLinus Torvalds 
1503732db659SAdrian Bunk static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
15041da177e4SLinus Torvalds {
15051da177e4SLinus Torvalds 	char fwd;
15061da177e4SLinus Torvalds 
15071da177e4SLinus Torvalds 	switch (IP_VS_FWD_METHOD(cp)) {
15081da177e4SLinus Torvalds 	case IP_VS_CONN_F_MASQ:
15091da177e4SLinus Torvalds 		fwd = 'M'; break;
15101da177e4SLinus Torvalds 	case IP_VS_CONN_F_LOCALNODE:
15111da177e4SLinus Torvalds 		fwd = 'L'; break;
15121da177e4SLinus Torvalds 	case IP_VS_CONN_F_TUNNEL:
15131da177e4SLinus Torvalds 		fwd = 'T'; break;
15141da177e4SLinus Torvalds 	case IP_VS_CONN_F_DROUTE:
15151da177e4SLinus Torvalds 		fwd = 'R'; break;
15161da177e4SLinus Torvalds 	case IP_VS_CONN_F_BYPASS:
15171da177e4SLinus Torvalds 		fwd = 'B'; break;
15181da177e4SLinus Torvalds 	default:
15191da177e4SLinus Torvalds 		fwd = '?'; break;
15201da177e4SLinus Torvalds 	}
15211da177e4SLinus Torvalds 	return fwd;
15221da177e4SLinus Torvalds }
15231da177e4SLinus Torvalds 
15245c3a0fd7SJoe Perches void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
15251da177e4SLinus Torvalds 		    struct ip_vs_conn *cp, int dir);
15261da177e4SLinus Torvalds 
1527b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6
15285c3a0fd7SJoe Perches void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
1529b3cdd2a7SJulius Volz 		       struct ip_vs_conn *cp, int dir);
1530b3cdd2a7SJulius Volz #endif
1531b3cdd2a7SJulius Volz 
15325c3a0fd7SJoe Perches __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
15331da177e4SLinus Torvalds 
1534f9214b26SAl Viro static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
15351da177e4SLinus Torvalds {
1536f9214b26SAl Viro 	__be32 diff[2] = { ~old, new };
15371da177e4SLinus Torvalds 
153807f0757aSJoe Perches 	return csum_partial(diff, sizeof(diff), oldsum);
1539f9214b26SAl Viro }
1540f9214b26SAl Viro 
15410bbdd42bSJulius Volz #ifdef CONFIG_IP_VS_IPV6
15420bbdd42bSJulius Volz static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new,
15430bbdd42bSJulius Volz 					__wsum oldsum)
15440bbdd42bSJulius Volz {
15450bbdd42bSJulius Volz 	__be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
15460bbdd42bSJulius Volz 			    new[3],  new[2],  new[1],  new[0] };
15470bbdd42bSJulius Volz 
154807f0757aSJoe Perches 	return csum_partial(diff, sizeof(diff), oldsum);
15490bbdd42bSJulius Volz }
15500bbdd42bSJulius Volz #endif
15510bbdd42bSJulius Volz 
1552f9214b26SAl Viro static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
1553f9214b26SAl Viro {
1554f9214b26SAl Viro 	__be16 diff[2] = { ~old, new };
1555f9214b26SAl Viro 
155607f0757aSJoe Perches 	return csum_partial(diff, sizeof(diff), oldsum);
15571da177e4SLinus Torvalds }
15581da177e4SLinus Torvalds 
155907dcc686SSimon Horman /* Forget current conntrack (unconfirmed) and attach notrack entry */
1560cf356d69SJulian Anastasov static inline void ip_vs_notrack(struct sk_buff *skb)
1561cf356d69SJulian Anastasov {
1562cf356d69SJulian Anastasov #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1563cf356d69SJulian Anastasov 	enum ip_conntrack_info ctinfo;
156406b69390SJesper Juhl 	struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1565cf356d69SJulian Anastasov 
1566ab8bc7edSFlorian Westphal 	if (ct) {
156797a6ad13SFlorian Westphal 		nf_conntrack_put(&ct->ct_general);
1568cc41c84bSFlorian Westphal 		nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
1569cf356d69SJulian Anastasov 	}
1570cf356d69SJulian Anastasov #endif
1571cf356d69SJulian Anastasov }
1572cf356d69SJulian Anastasov 
1573f4bc17cdSJulian Anastasov #ifdef CONFIG_IP_VS_NFCT
157407dcc686SSimon Horman /* Netfilter connection tracking
1575f4bc17cdSJulian Anastasov  * (from ip_vs_nfct.c)
1576f4bc17cdSJulian Anastasov  */
1577a0840e2eSHans Schillstrom static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
1578f4bc17cdSJulian Anastasov {
1579a4e2f5a7SSimon Horman #ifdef CONFIG_SYSCTL
1580a0840e2eSHans Schillstrom 	return ipvs->sysctl_conntrack;
1581a4e2f5a7SSimon Horman #else
1582a4e2f5a7SSimon Horman 	return 0;
1583a4e2f5a7SSimon Horman #endif
1584f4bc17cdSJulian Anastasov }
1585f4bc17cdSJulian Anastasov 
15865c3a0fd7SJoe Perches void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
15876523ce15SJulian Anastasov 			    int outin);
15885c3a0fd7SJoe Perches int ip_vs_confirm_conntrack(struct sk_buff *skb);
15895c3a0fd7SJoe Perches void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct,
1590f4bc17cdSJulian Anastasov 			       struct ip_vs_conn *cp, u_int8_t proto,
1591f4bc17cdSJulian Anastasov 			       const __be16 port, int from_rs);
15925c3a0fd7SJoe Perches void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp);
1593f4bc17cdSJulian Anastasov 
1594f4bc17cdSJulian Anastasov #else
1595f4bc17cdSJulian Anastasov 
1596a0840e2eSHans Schillstrom static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
1597f4bc17cdSJulian Anastasov {
1598f4bc17cdSJulian Anastasov 	return 0;
1599f4bc17cdSJulian Anastasov }
1600f4bc17cdSJulian Anastasov 
1601f4bc17cdSJulian Anastasov static inline void ip_vs_update_conntrack(struct sk_buff *skb,
1602f4bc17cdSJulian Anastasov 					  struct ip_vs_conn *cp, int outin)
1603f4bc17cdSJulian Anastasov {
1604f4bc17cdSJulian Anastasov }
1605f4bc17cdSJulian Anastasov 
1606e23ebf0fSKrzysztof Wilczynski static inline int ip_vs_confirm_conntrack(struct sk_buff *skb)
1607f4bc17cdSJulian Anastasov {
1608f4bc17cdSJulian Anastasov 	return NF_ACCEPT;
1609f4bc17cdSJulian Anastasov }
1610f4bc17cdSJulian Anastasov 
1611f4bc17cdSJulian Anastasov static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
1612f4bc17cdSJulian Anastasov {
1613f4bc17cdSJulian Anastasov }
161407dcc686SSimon Horman #endif /* CONFIG_IP_VS_NFCT */
16156523ce15SJulian Anastasov 
1616f719e375SJulian Anastasov /* Really using conntrack? */
1617f719e375SJulian Anastasov static inline bool ip_vs_conn_uses_conntrack(struct ip_vs_conn *cp,
1618f719e375SJulian Anastasov 					     struct sk_buff *skb)
1619f719e375SJulian Anastasov {
1620f719e375SJulian Anastasov #ifdef CONFIG_IP_VS_NFCT
1621f719e375SJulian Anastasov 	enum ip_conntrack_info ctinfo;
1622f719e375SJulian Anastasov 	struct nf_conn *ct;
1623f719e375SJulian Anastasov 
1624f719e375SJulian Anastasov 	if (!(cp->flags & IP_VS_CONN_F_NFCT))
1625f719e375SJulian Anastasov 		return false;
1626f719e375SJulian Anastasov 	ct = nf_ct_get(skb, &ctinfo);
1627ab8bc7edSFlorian Westphal 	if (ct)
1628f719e375SJulian Anastasov 		return true;
1629f719e375SJulian Anastasov #endif
1630f719e375SJulian Anastasov 	return false;
1631f719e375SJulian Anastasov }
1632f719e375SJulian Anastasov 
163331875d49SJulian Anastasov static inline int ip_vs_register_conntrack(struct ip_vs_service *svc)
163431875d49SJulian Anastasov {
163531875d49SJulian Anastasov #if IS_ENABLED(CONFIG_NF_CONNTRACK)
163631875d49SJulian Anastasov 	int afmask = (svc->af == AF_INET6) ? 2 : 1;
163731875d49SJulian Anastasov 	int ret = 0;
163831875d49SJulian Anastasov 
163931875d49SJulian Anastasov 	if (!(svc->conntrack_afmask & afmask)) {
164031875d49SJulian Anastasov 		ret = nf_ct_netns_get(svc->ipvs->net, svc->af);
164131875d49SJulian Anastasov 		if (ret >= 0)
164231875d49SJulian Anastasov 			svc->conntrack_afmask |= afmask;
164331875d49SJulian Anastasov 	}
164431875d49SJulian Anastasov 	return ret;
164531875d49SJulian Anastasov #else
164631875d49SJulian Anastasov 	return 0;
164731875d49SJulian Anastasov #endif
164831875d49SJulian Anastasov }
164931875d49SJulian Anastasov 
165031875d49SJulian Anastasov static inline void ip_vs_unregister_conntrack(struct ip_vs_service *svc)
165131875d49SJulian Anastasov {
165231875d49SJulian Anastasov #if IS_ENABLED(CONFIG_NF_CONNTRACK)
165331875d49SJulian Anastasov 	int afmask = (svc->af == AF_INET6) ? 2 : 1;
165431875d49SJulian Anastasov 
165531875d49SJulian Anastasov 	if (svc->conntrack_afmask & afmask) {
165631875d49SJulian Anastasov 		nf_ct_netns_put(svc->ipvs->net, svc->af);
165731875d49SJulian Anastasov 		svc->conntrack_afmask &= ~afmask;
165831875d49SJulian Anastasov 	}
165931875d49SJulian Anastasov #endif
166031875d49SJulian Anastasov }
166131875d49SJulian Anastasov 
1662c16526a7SSimon Kirby static inline int
1663b552f7e3SChangli Gao ip_vs_dest_conn_overhead(struct ip_vs_dest *dest)
1664b552f7e3SChangli Gao {
166507dcc686SSimon Horman 	/* We think the overhead of processing active connections is 256
1666b552f7e3SChangli Gao 	 * times higher than that of inactive connections in average. (This
1667b552f7e3SChangli Gao 	 * 256 times might not be accurate, we will change it later) We
1668b552f7e3SChangli Gao 	 * use the following formula to estimate the overhead now:
1669b552f7e3SChangli Gao 	 *		  dest->activeconns*256 + dest->inactconns
1670b552f7e3SChangli Gao 	 */
1671b552f7e3SChangli Gao 	return (atomic_read(&dest->activeconns) << 8) +
1672b552f7e3SChangli Gao 		atomic_read(&dest->inactconns);
1673b552f7e3SChangli Gao }
1674b552f7e3SChangli Gao 
1675bc4768ebSJulius Volz #endif	/* _NET_IP_VS_H */
1676