xref: /openbmc/linux/include/net/ip_vs.h (revision 4d0c875dcc4923476f364e83912d134da2df224c)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *      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 */
161da177e4SLinus Torvalds #include <linux/compiler.h>
1714c85021SArnaldo Carvalho de Melo #include <linux/timer.h>
18187f1882SPaul Gortmaker #include <linux/bug.h>
191da177e4SLinus Torvalds 
2014c85021SArnaldo Carvalho de Melo #include <net/checksum.h>
21e7ade46aSJulius Volz #include <linux/netfilter.h>		/* for union nf_inet_addr */
221668e010SKOVACS Krisztian #include <linux/ip.h>
23e7ade46aSJulius Volz #include <linux/ipv6.h>			/* for struct ipv6hdr */
244e3fd7a0SAlexey Dobriyan #include <net/ipv6.h>
2554d83efaSJesper Dangaard Brouer #if IS_ENABLED(CONFIG_IP_VS_IPV6)
2663dca2c0SJesper Dangaard Brouer #include <linux/netfilter_ipv6/ip6_tables.h>
2763dca2c0SJesper Dangaard Brouer #endif
28a638e514SJesper Dangaard Brouer #if IS_ENABLED(CONFIG_NF_CONNTRACK)
29f4bc17cdSJulian Anastasov #include <net/netfilter/nf_conntrack.h>
30f4bc17cdSJulian Anastasov #endif
3161b1ab45SHans Schillstrom #include <net/net_namespace.h>		/* Netw namespace */
3261b1ab45SHans Schillstrom 
3361b1ab45SHans Schillstrom /*
3461b1ab45SHans Schillstrom  * Generic access of ipvs struct
3561b1ab45SHans Schillstrom  */
3661b1ab45SHans Schillstrom static inline struct netns_ipvs *net_ipvs(struct net* net)
3761b1ab45SHans Schillstrom {
3861b1ab45SHans Schillstrom 	return net->ipvs;
3961b1ab45SHans Schillstrom }
40fc723250SHans Schillstrom /*
41fc723250SHans Schillstrom  * Get net ptr from skb in traffic cases
42fc723250SHans Schillstrom  * use skb_sknet when call is from userland (ioctl or netlink)
43fc723250SHans Schillstrom  */
44a0840e2eSHans Schillstrom static inline struct net *skb_net(const struct sk_buff *skb)
45fc723250SHans Schillstrom {
46fc723250SHans Schillstrom #ifdef CONFIG_NET_NS
47fc723250SHans Schillstrom #ifdef CONFIG_IP_VS_DEBUG
48fc723250SHans Schillstrom 	/*
49fc723250SHans Schillstrom 	 * This is used for debug only.
50fc723250SHans Schillstrom 	 * Start with the most likely hit
51fc723250SHans Schillstrom 	 * End with BUG
52fc723250SHans Schillstrom 	 */
53fc723250SHans Schillstrom 	if (likely(skb->dev && skb->dev->nd_net))
54fc723250SHans Schillstrom 		return dev_net(skb->dev);
55a09d1977SHans Schillstrom 	if (skb_dst(skb) && skb_dst(skb)->dev)
56fc723250SHans Schillstrom 		return dev_net(skb_dst(skb)->dev);
57fc723250SHans Schillstrom 	WARN(skb->sk, "Maybe skb_sknet should be used in %s() at line:%d\n",
58fc723250SHans Schillstrom 		      __func__, __LINE__);
59fc723250SHans Schillstrom 	if (likely(skb->sk && skb->sk->sk_net))
60fc723250SHans Schillstrom 		return sock_net(skb->sk);
61fc723250SHans Schillstrom 	pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
62fc723250SHans Schillstrom 		__func__, __LINE__);
63fc723250SHans Schillstrom 	BUG();
64fc723250SHans Schillstrom #else
65fc723250SHans Schillstrom 	return dev_net(skb->dev ? : skb_dst(skb)->dev);
66fc723250SHans Schillstrom #endif
67fc723250SHans Schillstrom #else
68fc723250SHans Schillstrom 	return &init_net;
69fc723250SHans Schillstrom #endif
70fc723250SHans Schillstrom }
71fc723250SHans Schillstrom 
72a0840e2eSHans Schillstrom static inline struct net *skb_sknet(const struct sk_buff *skb)
73fc723250SHans Schillstrom {
74fc723250SHans Schillstrom #ifdef CONFIG_NET_NS
75fc723250SHans Schillstrom #ifdef CONFIG_IP_VS_DEBUG
76fc723250SHans Schillstrom 	/* Start with the most likely hit */
77fc723250SHans Schillstrom 	if (likely(skb->sk && skb->sk->sk_net))
78fc723250SHans Schillstrom 		return sock_net(skb->sk);
79fc723250SHans Schillstrom 	WARN(skb->dev, "Maybe skb_net should be used instead in %s() line:%d\n",
80fc723250SHans Schillstrom 		       __func__, __LINE__);
81fc723250SHans Schillstrom 	if (likely(skb->dev && skb->dev->nd_net))
82fc723250SHans Schillstrom 		return dev_net(skb->dev);
83fc723250SHans Schillstrom 	pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
84fc723250SHans Schillstrom 		__func__, __LINE__);
85fc723250SHans Schillstrom 	BUG();
86fc723250SHans Schillstrom #else
87fc723250SHans Schillstrom 	return sock_net(skb->sk);
88fc723250SHans Schillstrom #endif
89fc723250SHans Schillstrom #else
90fc723250SHans Schillstrom 	return &init_net;
91fc723250SHans Schillstrom #endif
92fc723250SHans Schillstrom }
93b17fc996SHans Schillstrom /*
94b17fc996SHans Schillstrom  * This one needed for single_open_net since net is stored directly in
9525985edcSLucas De Marchi  * private not as a struct i.e. seq_file_net can't be used.
96b17fc996SHans Schillstrom  */
97b17fc996SHans Schillstrom static inline struct net *seq_file_single_net(struct seq_file *seq)
98b17fc996SHans Schillstrom {
99b17fc996SHans Schillstrom #ifdef CONFIG_NET_NS
100b17fc996SHans Schillstrom 	return (struct net *)seq->private;
101b17fc996SHans Schillstrom #else
102b17fc996SHans Schillstrom 	return &init_net;
103b17fc996SHans Schillstrom #endif
104b17fc996SHans Schillstrom }
1056f7edb48SCatalin(ux) M. BOIE 
1066f7edb48SCatalin(ux) M. BOIE /* Connections' size value needed by ip_vs_ctl.c */
1076f7edb48SCatalin(ux) M. BOIE extern int ip_vs_conn_tab_size;
1086f7edb48SCatalin(ux) M. BOIE 
10964aae3cbSJulius Volz struct ip_vs_iphdr {
11063dca2c0SJesper Dangaard Brouer 	__u32 len;	/* IPv4 simply where L4 starts
11163dca2c0SJesper Dangaard Brouer 			   IPv6 where L4 Transport Header starts */
1122f74713dSJesper Dangaard Brouer 	__u32 thoff_reasm; /* Transport Header Offset in nfct_reasm skb */
11363dca2c0SJesper Dangaard Brouer 	__u16 fragoffs; /* IPv6 fragment offset, 0 if first frag (or not frag)*/
11463dca2c0SJesper Dangaard Brouer 	__s16 protocol;
11563dca2c0SJesper Dangaard Brouer 	__s32 flags;
11664aae3cbSJulius Volz 	union nf_inet_addr saddr;
11764aae3cbSJulius Volz 	union nf_inet_addr daddr;
11864aae3cbSJulius Volz };
11964aae3cbSJulius Volz 
1202f74713dSJesper Dangaard Brouer /* Dependency to module: nf_defrag_ipv6 */
1212f74713dSJesper Dangaard Brouer #if defined(CONFIG_NF_DEFRAG_IPV6) || defined(CONFIG_NF_DEFRAG_IPV6_MODULE)
1222f74713dSJesper Dangaard Brouer static inline struct sk_buff *skb_nfct_reasm(const struct sk_buff *skb)
1232f74713dSJesper Dangaard Brouer {
1242f74713dSJesper Dangaard Brouer 	return skb->nfct_reasm;
1252f74713dSJesper Dangaard Brouer }
1262f74713dSJesper Dangaard Brouer static inline void *frag_safe_skb_hp(const struct sk_buff *skb, int offset,
1272f74713dSJesper Dangaard Brouer 				      int len, void *buffer,
1282f74713dSJesper Dangaard Brouer 				      const struct ip_vs_iphdr *ipvsh)
1292f74713dSJesper Dangaard Brouer {
1302f74713dSJesper Dangaard Brouer 	if (unlikely(ipvsh->fragoffs && skb_nfct_reasm(skb)))
1312f74713dSJesper Dangaard Brouer 		return skb_header_pointer(skb_nfct_reasm(skb),
1322f74713dSJesper Dangaard Brouer 					  ipvsh->thoff_reasm, len, buffer);
1332f74713dSJesper Dangaard Brouer 
1342f74713dSJesper Dangaard Brouer 	return skb_header_pointer(skb, offset, len, buffer);
1352f74713dSJesper Dangaard Brouer }
1362f74713dSJesper Dangaard Brouer #else
1372f74713dSJesper Dangaard Brouer static inline struct sk_buff *skb_nfct_reasm(const struct sk_buff *skb)
1382f74713dSJesper Dangaard Brouer {
1392f74713dSJesper Dangaard Brouer 	return NULL;
1402f74713dSJesper Dangaard Brouer }
1412f74713dSJesper Dangaard Brouer static inline void *frag_safe_skb_hp(const struct sk_buff *skb, int offset,
1422f74713dSJesper Dangaard Brouer 				      int len, void *buffer,
1432f74713dSJesper Dangaard Brouer 				      const struct ip_vs_iphdr *ipvsh)
1442f74713dSJesper Dangaard Brouer {
1452f74713dSJesper Dangaard Brouer 	return skb_header_pointer(skb, offset, len, buffer);
1462f74713dSJesper Dangaard Brouer }
1472f74713dSJesper Dangaard Brouer #endif
1482f74713dSJesper Dangaard Brouer 
14964aae3cbSJulius Volz static inline void
15063dca2c0SJesper Dangaard Brouer ip_vs_fill_ip4hdr(const void *nh, struct ip_vs_iphdr *iphdr)
15163dca2c0SJesper Dangaard Brouer {
15263dca2c0SJesper Dangaard Brouer 	const struct iphdr *iph = nh;
15363dca2c0SJesper Dangaard Brouer 
15463dca2c0SJesper Dangaard Brouer 	iphdr->len	= iph->ihl * 4;
15563dca2c0SJesper Dangaard Brouer 	iphdr->fragoffs	= 0;
15663dca2c0SJesper Dangaard Brouer 	iphdr->protocol	= iph->protocol;
15763dca2c0SJesper Dangaard Brouer 	iphdr->saddr.ip	= iph->saddr;
15863dca2c0SJesper Dangaard Brouer 	iphdr->daddr.ip	= iph->daddr;
15963dca2c0SJesper Dangaard Brouer }
16063dca2c0SJesper Dangaard Brouer 
16163dca2c0SJesper Dangaard Brouer /* This function handles filling *ip_vs_iphdr, both for IPv4 and IPv6.
16263dca2c0SJesper Dangaard Brouer  * IPv6 requires some extra work, as finding proper header position,
16363dca2c0SJesper Dangaard Brouer  * depend on the IPv6 extension headers.
16463dca2c0SJesper Dangaard Brouer  */
16563dca2c0SJesper Dangaard Brouer static inline void
16663dca2c0SJesper Dangaard Brouer ip_vs_fill_iph_skb(int af, const struct sk_buff *skb, struct ip_vs_iphdr *iphdr)
16764aae3cbSJulius Volz {
16864aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6
16964aae3cbSJulius Volz 	if (af == AF_INET6) {
17063dca2c0SJesper Dangaard Brouer 		const struct ipv6hdr *iph =
17163dca2c0SJesper Dangaard Brouer 			(struct ipv6hdr *)skb_network_header(skb);
1724e3fd7a0SAlexey Dobriyan 		iphdr->saddr.in6 = iph->saddr;
1734e3fd7a0SAlexey Dobriyan 		iphdr->daddr.in6 = iph->daddr;
1742f74713dSJesper Dangaard Brouer 		/* ipv6_find_hdr() updates len, flags, thoff_reasm */
1752f74713dSJesper Dangaard Brouer 		iphdr->thoff_reasm = 0;
17663dca2c0SJesper Dangaard Brouer 		iphdr->len	 = 0;
17763dca2c0SJesper Dangaard Brouer 		iphdr->flags	 = 0;
17863dca2c0SJesper Dangaard Brouer 		iphdr->protocol  = ipv6_find_hdr(skb, &iphdr->len, -1,
17963dca2c0SJesper Dangaard Brouer 						 &iphdr->fragoffs,
18063dca2c0SJesper Dangaard Brouer 						 &iphdr->flags);
1812f74713dSJesper Dangaard Brouer 		/* get proto from re-assembled packet and it's offset */
1822f74713dSJesper Dangaard Brouer 		if (skb_nfct_reasm(skb))
1832f74713dSJesper Dangaard Brouer 			iphdr->protocol = ipv6_find_hdr(skb_nfct_reasm(skb),
1842f74713dSJesper Dangaard Brouer 							&iphdr->thoff_reasm,
1852f74713dSJesper Dangaard Brouer 							-1, NULL, NULL);
1862f74713dSJesper Dangaard Brouer 
18764aae3cbSJulius Volz 	} else
18864aae3cbSJulius Volz #endif
18964aae3cbSJulius Volz 	{
19063dca2c0SJesper Dangaard Brouer 		const struct iphdr *iph =
19163dca2c0SJesper Dangaard Brouer 			(struct iphdr *)skb_network_header(skb);
19264aae3cbSJulius Volz 		iphdr->len	= iph->ihl * 4;
19363dca2c0SJesper Dangaard Brouer 		iphdr->fragoffs	= 0;
19464aae3cbSJulius Volz 		iphdr->protocol	= iph->protocol;
19564aae3cbSJulius Volz 		iphdr->saddr.ip	= iph->saddr;
19664aae3cbSJulius Volz 		iphdr->daddr.ip	= iph->daddr;
19764aae3cbSJulius Volz 	}
19864aae3cbSJulius Volz }
19964aae3cbSJulius Volz 
20064aae3cbSJulius Volz static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
20164aae3cbSJulius Volz 				   const union nf_inet_addr *src)
20264aae3cbSJulius Volz {
20364aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6
20464aae3cbSJulius Volz 	if (af == AF_INET6)
2054e3fd7a0SAlexey Dobriyan 		dst->in6 = src->in6;
20664aae3cbSJulius Volz 	else
20764aae3cbSJulius Volz #endif
20864aae3cbSJulius Volz 	dst->ip = src->ip;
20964aae3cbSJulius Volz }
21064aae3cbSJulius Volz 
2119a05475cSJulian Anastasov static inline void ip_vs_addr_set(int af, union nf_inet_addr *dst,
2129a05475cSJulian Anastasov 				  const union nf_inet_addr *src)
2139a05475cSJulian Anastasov {
2149a05475cSJulian Anastasov #ifdef CONFIG_IP_VS_IPV6
2159a05475cSJulian Anastasov 	if (af == AF_INET6) {
2169a05475cSJulian Anastasov 		dst->in6 = src->in6;
2179a05475cSJulian Anastasov 		return;
2189a05475cSJulian Anastasov 	}
2199a05475cSJulian Anastasov #endif
2209a05475cSJulian Anastasov 	dst->ip = src->ip;
2219a05475cSJulian Anastasov 	dst->all[1] = 0;
2229a05475cSJulian Anastasov 	dst->all[2] = 0;
2239a05475cSJulian Anastasov 	dst->all[3] = 0;
2249a05475cSJulian Anastasov }
2259a05475cSJulian Anastasov 
22664aae3cbSJulius Volz static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
22764aae3cbSJulius Volz 				   const union nf_inet_addr *b)
22864aae3cbSJulius Volz {
22964aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6
23064aae3cbSJulius Volz 	if (af == AF_INET6)
23164aae3cbSJulius Volz 		return ipv6_addr_equal(&a->in6, &b->in6);
23264aae3cbSJulius Volz #endif
23364aae3cbSJulius Volz 	return a->ip == b->ip;
23464aae3cbSJulius Volz }
23564aae3cbSJulius Volz 
2361da177e4SLinus Torvalds #ifdef CONFIG_IP_VS_DEBUG
23714c85021SArnaldo Carvalho de Melo #include <linux/net.h>
23814c85021SArnaldo Carvalho de Melo 
2391da177e4SLinus Torvalds extern int ip_vs_get_debug_level(void);
240c842a3adSJulius Volz 
241c842a3adSJulius Volz static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
242c842a3adSJulius Volz 					 const union nf_inet_addr *addr,
243c842a3adSJulius Volz 					 int *idx)
244c842a3adSJulius Volz {
245c842a3adSJulius Volz 	int len;
246c842a3adSJulius Volz #ifdef CONFIG_IP_VS_IPV6
247c842a3adSJulius Volz 	if (af == AF_INET6)
248120b9c14SJesper Dangaard Brouer 		len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6c]",
2490c6ce78aSHarvey Harrison 			       &addr->in6) + 1;
250c842a3adSJulius Volz 	else
251c842a3adSJulius Volz #endif
2523685f25dSHarvey Harrison 		len = snprintf(&buf[*idx], buf_len - *idx, "%pI4",
2533685f25dSHarvey Harrison 			       &addr->ip) + 1;
254c842a3adSJulius Volz 
255c842a3adSJulius Volz 	*idx += len;
256c842a3adSJulius Volz 	BUG_ON(*idx > buf_len + 1);
257c842a3adSJulius Volz 	return &buf[*idx - len];
258c842a3adSJulius Volz }
259c842a3adSJulius Volz 
2609aada7acSHannes Eder #define IP_VS_DBG_BUF(level, msg, ...)					\
261c842a3adSJulius Volz 	do {								\
262c842a3adSJulius Volz 		char ip_vs_dbg_buf[160];				\
263c842a3adSJulius Volz 		int ip_vs_dbg_idx = 0;					\
264c842a3adSJulius Volz 		if (level <= ip_vs_get_debug_level())			\
2659aada7acSHannes Eder 			printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__);	\
266c842a3adSJulius Volz 	} while (0)
267c842a3adSJulius Volz #define IP_VS_ERR_BUF(msg...)						\
268c842a3adSJulius Volz 	do {								\
269c842a3adSJulius Volz 		char ip_vs_dbg_buf[160];				\
270c842a3adSJulius Volz 		int ip_vs_dbg_idx = 0;					\
2719aada7acSHannes Eder 		pr_err(msg);						\
272c842a3adSJulius Volz 	} while (0)
273c842a3adSJulius Volz 
274c842a3adSJulius Volz /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */
275c842a3adSJulius Volz #define IP_VS_DBG_ADDR(af, addr)					\
276c842a3adSJulius Volz 	ip_vs_dbg_addr(af, ip_vs_dbg_buf,				\
277c842a3adSJulius Volz 		       sizeof(ip_vs_dbg_buf), addr,			\
278c842a3adSJulius Volz 		       &ip_vs_dbg_idx)
279c842a3adSJulius Volz 
2809aada7acSHannes Eder #define IP_VS_DBG(level, msg, ...)					\
2811da177e4SLinus Torvalds 	do {								\
2821da177e4SLinus Torvalds 		if (level <= ip_vs_get_debug_level())			\
2839aada7acSHannes Eder 			printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__);	\
2841da177e4SLinus Torvalds 	} while (0)
2859aada7acSHannes Eder #define IP_VS_DBG_RL(msg, ...)						\
2861da177e4SLinus Torvalds 	do {								\
2871da177e4SLinus Torvalds 		if (net_ratelimit())					\
2889aada7acSHannes Eder 			printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__);	\
2891da177e4SLinus Torvalds 	} while (0)
2900d79641aSJulian Anastasov #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg)			\
2911da177e4SLinus Torvalds 	do {								\
2921da177e4SLinus Torvalds 		if (level <= ip_vs_get_debug_level())			\
2930d79641aSJulian Anastasov 			pp->debug_packet(af, pp, skb, ofs, msg);	\
2941da177e4SLinus Torvalds 	} while (0)
2950d79641aSJulian Anastasov #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg)			\
2961da177e4SLinus Torvalds 	do {								\
2971da177e4SLinus Torvalds 		if (level <= ip_vs_get_debug_level() &&			\
2981da177e4SLinus Torvalds 		    net_ratelimit())					\
2990d79641aSJulian Anastasov 			pp->debug_packet(af, pp, skb, ofs, msg);	\
3001da177e4SLinus Torvalds 	} while (0)
3011da177e4SLinus Torvalds #else	/* NO DEBUGGING at ALL */
302c842a3adSJulius Volz #define IP_VS_DBG_BUF(level, msg...)  do {} while (0)
303c842a3adSJulius Volz #define IP_VS_ERR_BUF(msg...)  do {} while (0)
3041da177e4SLinus Torvalds #define IP_VS_DBG(level, msg...)  do {} while (0)
3051da177e4SLinus Torvalds #define IP_VS_DBG_RL(msg...)  do {} while (0)
3060d79641aSJulian Anastasov #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg)	do {} while (0)
3070d79641aSJulian Anastasov #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg)	do {} while (0)
3081da177e4SLinus Torvalds #endif
3091da177e4SLinus Torvalds 
3101da177e4SLinus Torvalds #define IP_VS_BUG() BUG()
3111e3e238eSHannes Eder #define IP_VS_ERR_RL(msg, ...)						\
3121da177e4SLinus Torvalds 	do {								\
3131da177e4SLinus Torvalds 		if (net_ratelimit())					\
3141e3e238eSHannes Eder 			pr_err(msg, ##__VA_ARGS__);			\
3151da177e4SLinus Torvalds 	} while (0)
3161da177e4SLinus Torvalds 
3171da177e4SLinus Torvalds #ifdef CONFIG_IP_VS_DEBUG
3181da177e4SLinus Torvalds #define EnterFunction(level)						\
3191da177e4SLinus Torvalds 	do {								\
3201da177e4SLinus Torvalds 		if (level <= ip_vs_get_debug_level())			\
3219aada7acSHannes Eder 			printk(KERN_DEBUG				\
3229aada7acSHannes Eder 			       pr_fmt("Enter: %s, %s line %i\n"),	\
323d5c003b4SHarvey Harrison 			       __func__, __FILE__, __LINE__);		\
3241da177e4SLinus Torvalds 	} while (0)
3251da177e4SLinus Torvalds #define LeaveFunction(level)						\
3261da177e4SLinus Torvalds 	do {								\
3271da177e4SLinus Torvalds 		if (level <= ip_vs_get_debug_level())			\
3289aada7acSHannes Eder 			printk(KERN_DEBUG				\
3299aada7acSHannes Eder 			       pr_fmt("Leave: %s, %s line %i\n"),	\
330d5c003b4SHarvey Harrison 			       __func__, __FILE__, __LINE__);		\
3311da177e4SLinus Torvalds 	} while (0)
3321da177e4SLinus Torvalds #else
3331da177e4SLinus Torvalds #define EnterFunction(level)   do {} while (0)
3341da177e4SLinus Torvalds #define LeaveFunction(level)   do {} while (0)
3351da177e4SLinus Torvalds #endif
3361da177e4SLinus Torvalds 
3371da177e4SLinus Torvalds 
3381da177e4SLinus Torvalds /*
3391da177e4SLinus Torvalds  *      The port number of FTP service (in network order).
3401da177e4SLinus Torvalds  */
341f3a7c66bSHarvey Harrison #define FTPPORT  cpu_to_be16(21)
342f3a7c66bSHarvey Harrison #define FTPDATA  cpu_to_be16(20)
3431da177e4SLinus Torvalds 
3441da177e4SLinus Torvalds /*
3451da177e4SLinus Torvalds  *      TCP State Values
3461da177e4SLinus Torvalds  */
3471da177e4SLinus Torvalds enum {
3481da177e4SLinus Torvalds 	IP_VS_TCP_S_NONE = 0,
3491da177e4SLinus Torvalds 	IP_VS_TCP_S_ESTABLISHED,
3501da177e4SLinus Torvalds 	IP_VS_TCP_S_SYN_SENT,
3511da177e4SLinus Torvalds 	IP_VS_TCP_S_SYN_RECV,
3521da177e4SLinus Torvalds 	IP_VS_TCP_S_FIN_WAIT,
3531da177e4SLinus Torvalds 	IP_VS_TCP_S_TIME_WAIT,
3541da177e4SLinus Torvalds 	IP_VS_TCP_S_CLOSE,
3551da177e4SLinus Torvalds 	IP_VS_TCP_S_CLOSE_WAIT,
3561da177e4SLinus Torvalds 	IP_VS_TCP_S_LAST_ACK,
3571da177e4SLinus Torvalds 	IP_VS_TCP_S_LISTEN,
3581da177e4SLinus Torvalds 	IP_VS_TCP_S_SYNACK,
3591da177e4SLinus Torvalds 	IP_VS_TCP_S_LAST
3601da177e4SLinus Torvalds };
3611da177e4SLinus Torvalds 
3621da177e4SLinus Torvalds /*
3631da177e4SLinus Torvalds  *	UDP State Values
3641da177e4SLinus Torvalds  */
3651da177e4SLinus Torvalds enum {
3661da177e4SLinus Torvalds 	IP_VS_UDP_S_NORMAL,
3671da177e4SLinus Torvalds 	IP_VS_UDP_S_LAST,
3681da177e4SLinus Torvalds };
3691da177e4SLinus Torvalds 
3701da177e4SLinus Torvalds /*
3711da177e4SLinus Torvalds  *	ICMP State Values
3721da177e4SLinus Torvalds  */
3731da177e4SLinus Torvalds enum {
3741da177e4SLinus Torvalds 	IP_VS_ICMP_S_NORMAL,
3751da177e4SLinus Torvalds 	IP_VS_ICMP_S_LAST,
3761da177e4SLinus Torvalds };
3771da177e4SLinus Torvalds 
3781da177e4SLinus Torvalds /*
3792906f66aSVenkata Mohan Reddy  *	SCTP State Values
3802906f66aSVenkata Mohan Reddy  */
3812906f66aSVenkata Mohan Reddy enum ip_vs_sctp_states {
3822906f66aSVenkata Mohan Reddy 	IP_VS_SCTP_S_NONE,
38361e7c420SJulian Anastasov 	IP_VS_SCTP_S_INIT1,
38461e7c420SJulian Anastasov 	IP_VS_SCTP_S_INIT,
38561e7c420SJulian Anastasov 	IP_VS_SCTP_S_COOKIE_SENT,
38661e7c420SJulian Anastasov 	IP_VS_SCTP_S_COOKIE_REPLIED,
38761e7c420SJulian Anastasov 	IP_VS_SCTP_S_COOKIE_WAIT,
38861e7c420SJulian Anastasov 	IP_VS_SCTP_S_COOKIE,
38961e7c420SJulian Anastasov 	IP_VS_SCTP_S_COOKIE_ECHOED,
3902906f66aSVenkata Mohan Reddy 	IP_VS_SCTP_S_ESTABLISHED,
39161e7c420SJulian Anastasov 	IP_VS_SCTP_S_SHUTDOWN_SENT,
39261e7c420SJulian Anastasov 	IP_VS_SCTP_S_SHUTDOWN_RECEIVED,
39361e7c420SJulian Anastasov 	IP_VS_SCTP_S_SHUTDOWN_ACK_SENT,
39461e7c420SJulian Anastasov 	IP_VS_SCTP_S_REJECTED,
3952906f66aSVenkata Mohan Reddy 	IP_VS_SCTP_S_CLOSED,
3962906f66aSVenkata Mohan Reddy 	IP_VS_SCTP_S_LAST
3972906f66aSVenkata Mohan Reddy };
3982906f66aSVenkata Mohan Reddy 
3992906f66aSVenkata Mohan Reddy /*
4001da177e4SLinus Torvalds  *	Delta sequence info structure
4011da177e4SLinus Torvalds  *	Each ip_vs_conn has 2 (output AND input seq. changes).
4021da177e4SLinus Torvalds  *      Only used in the VS/NAT.
4031da177e4SLinus Torvalds  */
4041da177e4SLinus Torvalds struct ip_vs_seq {
4051da177e4SLinus Torvalds 	__u32			init_seq;	/* Add delta from this seq */
4061da177e4SLinus Torvalds 	__u32			delta;		/* Delta in sequence numbers */
4071da177e4SLinus Torvalds 	__u32			previous_delta;	/* Delta in sequence numbers
4081da177e4SLinus Torvalds 						   before last resized pkt */
4091da177e4SLinus Torvalds };
4101da177e4SLinus Torvalds 
411b17fc996SHans Schillstrom /*
412b17fc996SHans Schillstrom  * counters per cpu
413b17fc996SHans Schillstrom  */
414b17fc996SHans Schillstrom struct ip_vs_counters {
415b17fc996SHans Schillstrom 	__u32		conns;		/* connections scheduled */
416b17fc996SHans Schillstrom 	__u32		inpkts;		/* incoming packets */
417b17fc996SHans Schillstrom 	__u32		outpkts;	/* outgoing packets */
418b17fc996SHans Schillstrom 	__u64		inbytes;	/* incoming bytes */
419b17fc996SHans Schillstrom 	__u64		outbytes;	/* outgoing bytes */
420b17fc996SHans Schillstrom };
421b17fc996SHans Schillstrom /*
422b17fc996SHans Schillstrom  * Stats per cpu
423b17fc996SHans Schillstrom  */
424b17fc996SHans Schillstrom struct ip_vs_cpu_stats {
425b17fc996SHans Schillstrom 	struct ip_vs_counters   ustats;
426b17fc996SHans Schillstrom 	struct u64_stats_sync   syncp;
427b17fc996SHans Schillstrom };
4281da177e4SLinus Torvalds 
4291da177e4SLinus Torvalds /*
4303a14a313SSven Wegener  *	IPVS statistics objects
4311da177e4SLinus Torvalds  */
4323a14a313SSven Wegener struct ip_vs_estimator {
4333a14a313SSven Wegener 	struct list_head	list;
4343a14a313SSven Wegener 
4353a14a313SSven Wegener 	u64			last_inbytes;
4363a14a313SSven Wegener 	u64			last_outbytes;
4373a14a313SSven Wegener 	u32			last_conns;
4383a14a313SSven Wegener 	u32			last_inpkts;
4393a14a313SSven Wegener 	u32			last_outpkts;
4403a14a313SSven Wegener 
4413a14a313SSven Wegener 	u32			cps;
4423a14a313SSven Wegener 	u32			inpps;
4433a14a313SSven Wegener 	u32			outpps;
4443a14a313SSven Wegener 	u32			inbps;
4453a14a313SSven Wegener 	u32			outbps;
4463a14a313SSven Wegener };
4473a14a313SSven Wegener 
448fd2c3ef7SEric Dumazet struct ip_vs_stats {
449e9c0ce23SSven Wegener 	struct ip_vs_stats_user	ustats;		/* statistics */
450e9c0ce23SSven Wegener 	struct ip_vs_estimator	est;		/* estimator */
451b962abdcSJulian Anastasov 	struct ip_vs_cpu_stats __percpu	*cpustats;	/* per cpu counters */
4521da177e4SLinus Torvalds 	spinlock_t		lock;		/* spin lock */
45355a3d4e1SJulian Anastasov 	struct ip_vs_stats_user	ustats0;	/* reset values */
4541da177e4SLinus Torvalds };
4551da177e4SLinus Torvalds 
45614c85021SArnaldo Carvalho de Melo struct dst_entry;
45714c85021SArnaldo Carvalho de Melo struct iphdr;
4581da177e4SLinus Torvalds struct ip_vs_conn;
4591da177e4SLinus Torvalds struct ip_vs_app;
46014c85021SArnaldo Carvalho de Melo struct sk_buff;
461252c6410SHans Schillstrom struct ip_vs_proto_data;
4621da177e4SLinus Torvalds 
4631da177e4SLinus Torvalds struct ip_vs_protocol {
4641da177e4SLinus Torvalds 	struct ip_vs_protocol	*next;
4651da177e4SLinus Torvalds 	char			*name;
4662ad17defSJulian Anastasov 	u16			protocol;
4672ad17defSJulian Anastasov 	u16			num_states;
4681da177e4SLinus Torvalds 	int			dont_defrag;
4691da177e4SLinus Torvalds 
4701da177e4SLinus Torvalds 	void (*init)(struct ip_vs_protocol *pp);
4711da177e4SLinus Torvalds 
4721da177e4SLinus Torvalds 	void (*exit)(struct ip_vs_protocol *pp);
4731da177e4SLinus Torvalds 
474582b8e3eSHans Schillstrom 	int (*init_netns)(struct net *net, struct ip_vs_proto_data *pd);
475252c6410SHans Schillstrom 
476252c6410SHans Schillstrom 	void (*exit_netns)(struct net *net, struct ip_vs_proto_data *pd);
477252c6410SHans Schillstrom 
47851ef348bSJulius Volz 	int (*conn_schedule)(int af, struct sk_buff *skb,
4799330419dSHans Schillstrom 			     struct ip_vs_proto_data *pd,
480d4383f04SJesper Dangaard Brouer 			     int *verdict, struct ip_vs_conn **cpp,
481d4383f04SJesper Dangaard Brouer 			     struct ip_vs_iphdr *iph);
4821da177e4SLinus Torvalds 
4831da177e4SLinus Torvalds 	struct ip_vs_conn *
48451ef348bSJulius Volz 	(*conn_in_get)(int af,
48551ef348bSJulius Volz 		       const struct sk_buff *skb,
48651ef348bSJulius Volz 		       const struct ip_vs_iphdr *iph,
4871da177e4SLinus Torvalds 		       int inverse);
4881da177e4SLinus Torvalds 
4891da177e4SLinus Torvalds 	struct ip_vs_conn *
49051ef348bSJulius Volz 	(*conn_out_get)(int af,
49151ef348bSJulius Volz 			const struct sk_buff *skb,
49251ef348bSJulius Volz 			const struct ip_vs_iphdr *iph,
4931da177e4SLinus Torvalds 			int inverse);
4941da177e4SLinus Torvalds 
495d4383f04SJesper Dangaard Brouer 	int (*snat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp,
496d4383f04SJesper Dangaard Brouer 			    struct ip_vs_conn *cp, struct ip_vs_iphdr *iph);
4971da177e4SLinus Torvalds 
498d4383f04SJesper Dangaard Brouer 	int (*dnat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp,
499d4383f04SJesper Dangaard Brouer 			    struct ip_vs_conn *cp, struct ip_vs_iphdr *iph);
5001da177e4SLinus Torvalds 
50151ef348bSJulius Volz 	int (*csum_check)(int af, struct sk_buff *skb,
50251ef348bSJulius Volz 			  struct ip_vs_protocol *pp);
5031da177e4SLinus Torvalds 
5041da177e4SLinus Torvalds 	const char *(*state_name)(int state);
5051da177e4SLinus Torvalds 
5064a516f11SSimon Horman 	void (*state_transition)(struct ip_vs_conn *cp, int direction,
5071da177e4SLinus Torvalds 				 const struct sk_buff *skb,
5089330419dSHans Schillstrom 				 struct ip_vs_proto_data *pd);
5091da177e4SLinus Torvalds 
510ab8a5e84SHans Schillstrom 	int (*register_app)(struct net *net, struct ip_vs_app *inc);
5111da177e4SLinus Torvalds 
512ab8a5e84SHans Schillstrom 	void (*unregister_app)(struct net *net, struct ip_vs_app *inc);
5131da177e4SLinus Torvalds 
5141da177e4SLinus Torvalds 	int (*app_conn_bind)(struct ip_vs_conn *cp);
5151da177e4SLinus Torvalds 
5160d79641aSJulian Anastasov 	void (*debug_packet)(int af, struct ip_vs_protocol *pp,
5171da177e4SLinus Torvalds 			     const struct sk_buff *skb,
5181da177e4SLinus Torvalds 			     int offset,
5191da177e4SLinus Torvalds 			     const char *msg);
5201da177e4SLinus Torvalds 
5219330419dSHans Schillstrom 	void (*timeout_change)(struct ip_vs_proto_data *pd, int flags);
5221da177e4SLinus Torvalds };
5231da177e4SLinus Torvalds 
524252c6410SHans Schillstrom /*
525252c6410SHans Schillstrom  * protocol data per netns
526252c6410SHans Schillstrom  */
527252c6410SHans Schillstrom struct ip_vs_proto_data {
528252c6410SHans Schillstrom 	struct ip_vs_proto_data	*next;
529252c6410SHans Schillstrom 	struct ip_vs_protocol	*pp;
530252c6410SHans Schillstrom 	int			*timeout_table;	/* protocol timeout table */
531252c6410SHans Schillstrom 	atomic_t		appcnt;		/* counter of proto app incs. */
532252c6410SHans Schillstrom 	struct tcp_states_t	*tcp_state_table;
533252c6410SHans Schillstrom };
534252c6410SHans Schillstrom 
5351da177e4SLinus Torvalds extern struct ip_vs_protocol   *ip_vs_proto_get(unsigned short proto);
536252c6410SHans Schillstrom extern struct ip_vs_proto_data *ip_vs_proto_data_get(struct net *net,
537252c6410SHans Schillstrom 						     unsigned short proto);
5381da177e4SLinus Torvalds 
539f11017ecSSimon Horman struct ip_vs_conn_param {
5406e67e586SHans Schillstrom 	struct net			*net;
541f11017ecSSimon Horman 	const union nf_inet_addr	*caddr;
542f11017ecSSimon Horman 	const union nf_inet_addr	*vaddr;
543f11017ecSSimon Horman 	__be16				cport;
544f11017ecSSimon Horman 	__be16				vport;
545f11017ecSSimon Horman 	__u16				protocol;
546f11017ecSSimon Horman 	u16				af;
54785999283SSimon Horman 
54885999283SSimon Horman 	const struct ip_vs_pe		*pe;
54985999283SSimon Horman 	char				*pe_data;
55085999283SSimon Horman 	__u8				pe_data_len;
551f11017ecSSimon Horman };
552f11017ecSSimon Horman 
5531da177e4SLinus Torvalds /*
5541da177e4SLinus Torvalds  *	IP_VS structure allocated for each dynamically scheduled connection
5551da177e4SLinus Torvalds  */
5561da177e4SLinus Torvalds struct ip_vs_conn {
557731109e7SChangli Gao 	struct hlist_node	c_list;         /* hashed list heads */
5581da177e4SLinus Torvalds 	/* Protocol, addresses and port numbers */
5596e67e586SHans Schillstrom 	__be16                  cport;
5606e67e586SHans Schillstrom 	__be16                  dport;
5611845ed0bSJulian Anastasov 	__be16                  vport;
5621845ed0bSJulian Anastasov 	u16			af;		/* address family */
563e7ade46aSJulius Volz 	union nf_inet_addr      caddr;          /* client address */
564e7ade46aSJulius Volz 	union nf_inet_addr      vaddr;          /* virtual address */
565e7ade46aSJulius Volz 	union nf_inet_addr      daddr;          /* destination address */
5663575792eSJulian Anastasov 	volatile __u32          flags;          /* status flags */
5671da177e4SLinus Torvalds 	__u16                   protocol;       /* Which protocol (TCP/UDP) */
5681845ed0bSJulian Anastasov #ifdef CONFIG_NET_NS
5691845ed0bSJulian Anastasov 	struct net              *net;           /* Name space */
5701845ed0bSJulian Anastasov #endif
5711da177e4SLinus Torvalds 
5721da177e4SLinus Torvalds 	/* counter and timer */
5731da177e4SLinus Torvalds 	atomic_t		refcnt;		/* reference count */
5741da177e4SLinus Torvalds 	struct timer_list	timer;		/* Expiration timer */
5751da177e4SLinus Torvalds 	volatile unsigned long	timeout;	/* timeout */
5761da177e4SLinus Torvalds 
5771da177e4SLinus Torvalds 	/* Flags and state transition */
5781da177e4SLinus Torvalds 	spinlock_t              lock;           /* lock for state transition */
5791da177e4SLinus Torvalds 	volatile __u16          state;          /* state info */
580efac5276SRumen G. Bogdanovski 	volatile __u16          old_state;      /* old state, to be used for
581efac5276SRumen G. Bogdanovski 						 * state transition triggerd
582efac5276SRumen G. Bogdanovski 						 * synchronization
583efac5276SRumen G. Bogdanovski 						 */
5841845ed0bSJulian Anastasov 	__u32			fwmark;		/* Fire wall mark from skb */
585749c42b6SJulian Anastasov 	unsigned long		sync_endtime;	/* jiffies + sent_retries */
5861da177e4SLinus Torvalds 
5871da177e4SLinus Torvalds 	/* Control members */
5881da177e4SLinus Torvalds 	struct ip_vs_conn       *control;       /* Master control connection */
5891da177e4SLinus Torvalds 	atomic_t                n_control;      /* Number of controlled ones */
5901da177e4SLinus Torvalds 	struct ip_vs_dest       *dest;          /* real server */
5911da177e4SLinus Torvalds 	atomic_t                in_pkts;        /* incoming packet counter */
5921da177e4SLinus Torvalds 
5931da177e4SLinus Torvalds 	/* packet transmitter for different forwarding methods.  If it
5941da177e4SLinus Torvalds 	   mangles the packet, it must return NF_DROP or better NF_STOLEN,
5951da177e4SLinus Torvalds 	   otherwise this must be changed to a sk_buff **.
596fc604767SJulian Anastasov 	   NF_ACCEPT can be returned when destination is local.
5971da177e4SLinus Torvalds 	 */
5981da177e4SLinus Torvalds 	int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
599d4383f04SJesper Dangaard Brouer 			   struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
6001da177e4SLinus Torvalds 
6011da177e4SLinus Torvalds 	/* Note: we can group the following members into a structure,
6021da177e4SLinus Torvalds 	   in order to save more space, and the following members are
6031da177e4SLinus Torvalds 	   only used in VS/NAT anyway */
6041da177e4SLinus Torvalds 	struct ip_vs_app        *app;           /* bound ip_vs_app object */
6051da177e4SLinus Torvalds 	void                    *app_data;      /* Application private data */
6061da177e4SLinus Torvalds 	struct ip_vs_seq        in_seq;         /* incoming seq. struct */
6071da177e4SLinus Torvalds 	struct ip_vs_seq        out_seq;        /* outgoing seq. struct */
60885999283SSimon Horman 
609e9e5eee8SSimon Horman 	const struct ip_vs_pe	*pe;
61085999283SSimon Horman 	char			*pe_data;
61185999283SSimon Horman 	__u8			pe_data_len;
612088339a5SJulian Anastasov 
613088339a5SJulian Anastasov 	struct rcu_head		rcu_head;
6141da177e4SLinus Torvalds };
6151da177e4SLinus Torvalds 
6166e67e586SHans Schillstrom /*
6176e67e586SHans Schillstrom  *  To save some memory in conn table when name space is disabled.
6186e67e586SHans Schillstrom  */
6196e67e586SHans Schillstrom static inline struct net *ip_vs_conn_net(const struct ip_vs_conn *cp)
6206e67e586SHans Schillstrom {
6216e67e586SHans Schillstrom #ifdef CONFIG_NET_NS
6226e67e586SHans Schillstrom 	return cp->net;
6236e67e586SHans Schillstrom #else
6246e67e586SHans Schillstrom 	return &init_net;
6256e67e586SHans Schillstrom #endif
6266e67e586SHans Schillstrom }
6276e67e586SHans Schillstrom static inline void ip_vs_conn_net_set(struct ip_vs_conn *cp, struct net *net)
6286e67e586SHans Schillstrom {
6296e67e586SHans Schillstrom #ifdef CONFIG_NET_NS
6306e67e586SHans Schillstrom 	cp->net = net;
6316e67e586SHans Schillstrom #endif
6326e67e586SHans Schillstrom }
6336e67e586SHans Schillstrom 
6346e67e586SHans Schillstrom static inline int ip_vs_conn_net_eq(const struct ip_vs_conn *cp,
6356e67e586SHans Schillstrom 				    struct net *net)
6366e67e586SHans Schillstrom {
6376e67e586SHans Schillstrom #ifdef CONFIG_NET_NS
6386e67e586SHans Schillstrom 	return cp->net == net;
6396e67e586SHans Schillstrom #else
6406e67e586SHans Schillstrom 	return 1;
6416e67e586SHans Schillstrom #endif
6426e67e586SHans Schillstrom }
6431da177e4SLinus Torvalds 
6441da177e4SLinus Torvalds /*
645c860c6b1SJulius Volz  *	Extended internal versions of struct ip_vs_service_user and
646c860c6b1SJulius Volz  *	ip_vs_dest_user for IPv6 support.
647c860c6b1SJulius Volz  *
648c860c6b1SJulius Volz  *	We need these to conveniently pass around service and destination
649c860c6b1SJulius Volz  *	options, but unfortunately, we also need to keep the old definitions to
650c860c6b1SJulius Volz  *	maintain userspace backwards compatibility for the setsockopt interface.
651c860c6b1SJulius Volz  */
652c860c6b1SJulius Volz struct ip_vs_service_user_kern {
653c860c6b1SJulius Volz 	/* virtual service addresses */
654c860c6b1SJulius Volz 	u16			af;
655c860c6b1SJulius Volz 	u16			protocol;
656c860c6b1SJulius Volz 	union nf_inet_addr	addr;		/* virtual ip address */
6570a925864SJulian Anastasov 	__be16			port;
658c860c6b1SJulius Volz 	u32			fwmark;		/* firwall mark of service */
659c860c6b1SJulius Volz 
660c860c6b1SJulius Volz 	/* virtual service options */
661c860c6b1SJulius Volz 	char			*sched_name;
6620d1e71b0SSimon Horman 	char			*pe_name;
66395c96174SEric Dumazet 	unsigned int		flags;		/* virtual service flags */
66495c96174SEric Dumazet 	unsigned int		timeout;	/* persistent timeout in sec */
6650a925864SJulian Anastasov 	__be32			netmask;	/* persistent netmask or plen */
666c860c6b1SJulius Volz };
667c860c6b1SJulius Volz 
668c860c6b1SJulius Volz 
669c860c6b1SJulius Volz struct ip_vs_dest_user_kern {
670c860c6b1SJulius Volz 	/* destination server address */
671c860c6b1SJulius Volz 	union nf_inet_addr	addr;
6720a925864SJulian Anastasov 	__be16			port;
673c860c6b1SJulius Volz 
674c860c6b1SJulius Volz 	/* real server options */
67595c96174SEric Dumazet 	unsigned int		conn_flags;	/* connection flags */
676c860c6b1SJulius Volz 	int			weight;		/* destination weight */
677c860c6b1SJulius Volz 
678c860c6b1SJulius Volz 	/* thresholds for active connections */
679c860c6b1SJulius Volz 	u32			u_threshold;	/* upper threshold */
680c860c6b1SJulius Volz 	u32			l_threshold;	/* lower threshold */
681c860c6b1SJulius Volz };
682c860c6b1SJulius Volz 
683c860c6b1SJulius Volz 
684c860c6b1SJulius Volz /*
6851da177e4SLinus Torvalds  *	The information about the virtual service offered to the net
6861da177e4SLinus Torvalds  *	and the forwarding entries
6871da177e4SLinus Torvalds  */
6881da177e4SLinus Torvalds struct ip_vs_service {
689ceec4c38SJulian Anastasov 	struct hlist_node	s_list;   /* for normal service table */
690ceec4c38SJulian Anastasov 	struct hlist_node	f_list;   /* for fwmark-based service table */
6911da177e4SLinus Torvalds 	atomic_t		refcnt;   /* reference counter */
6921da177e4SLinus Torvalds 
693e7ade46aSJulius Volz 	u16			af;       /* address family */
6941da177e4SLinus Torvalds 	__u16			protocol; /* which protocol (TCP/UDP) */
695e7ade46aSJulius Volz 	union nf_inet_addr	addr;	  /* IP address for virtual service */
696014d730dSAl Viro 	__be16			port;	  /* port number for the service */
6971da177e4SLinus Torvalds 	__u32                   fwmark;   /* firewall mark of the service */
69895c96174SEric Dumazet 	unsigned int		flags;	  /* service status flags */
69995c96174SEric Dumazet 	unsigned int		timeout;  /* persistent timeout in ticks */
7000a925864SJulian Anastasov 	__be32			netmask;  /* grouping granularity, mask/plen */
701fc723250SHans Schillstrom 	struct net		*net;
7021da177e4SLinus Torvalds 
7031da177e4SLinus Torvalds 	struct list_head	destinations;  /* real server d-linked list */
7041da177e4SLinus Torvalds 	__u32			num_dests;     /* number of servers */
7051da177e4SLinus Torvalds 	struct ip_vs_stats      stats;         /* statistics for the service */
7061da177e4SLinus Torvalds 
7071da177e4SLinus Torvalds 	/* for scheduling */
708ceec4c38SJulian Anastasov 	struct ip_vs_scheduler __rcu *scheduler; /* bound scheduler object */
709ba3a3ce1SJulian Anastasov 	spinlock_t		sched_lock;    /* lock sched_data */
7101da177e4SLinus Torvalds 	void			*sched_data;   /* scheduler application data */
71185999283SSimon Horman 
71285999283SSimon Horman 	/* alternate persistence engine */
713ceec4c38SJulian Anastasov 	struct ip_vs_pe __rcu	*pe;
714ceec4c38SJulian Anastasov 
715ceec4c38SJulian Anastasov 	struct rcu_head		rcu_head;
7161da177e4SLinus Torvalds };
7171da177e4SLinus Torvalds 
718026ace06SJulian Anastasov /* Information for cached dst */
719026ace06SJulian Anastasov struct ip_vs_dest_dst {
720026ace06SJulian Anastasov 	struct dst_entry	*dst_cache;	/* destination cache entry */
721026ace06SJulian Anastasov 	u32			dst_cookie;
722026ace06SJulian Anastasov 	union nf_inet_addr	dst_saddr;
723026ace06SJulian Anastasov 	struct rcu_head		rcu_head;
724026ace06SJulian Anastasov };
7251da177e4SLinus Torvalds 
726578bc3efSJulian Anastasov /* In grace period after removing */
727578bc3efSJulian Anastasov #define IP_VS_DEST_STATE_REMOVING	0x01
7281da177e4SLinus Torvalds /*
7291da177e4SLinus Torvalds  *	The real server destination forwarding entry
7301da177e4SLinus Torvalds  *	with ip address, port number, and so on.
7311da177e4SLinus Torvalds  */
7321da177e4SLinus Torvalds struct ip_vs_dest {
7331da177e4SLinus Torvalds 	struct list_head	n_list;   /* for the dests in the service */
734276472eaSJulian Anastasov 	struct hlist_node	d_list;   /* for table with all the dests */
7351da177e4SLinus Torvalds 
736e7ade46aSJulius Volz 	u16			af;		/* address family */
737014d730dSAl Viro 	__be16			port;		/* port number of the server */
738f2431e6eSHans Schillstrom 	union nf_inet_addr	addr;		/* IP address of the server */
73995c96174SEric Dumazet 	volatile unsigned int	flags;		/* dest status flags */
7401da177e4SLinus Torvalds 	atomic_t		conn_flags;	/* flags to copy to conn */
7411da177e4SLinus Torvalds 	atomic_t		weight;		/* server weight */
7421da177e4SLinus Torvalds 
7431da177e4SLinus Torvalds 	atomic_t		refcnt;		/* reference counter */
7441da177e4SLinus Torvalds 	struct ip_vs_stats      stats;          /* statistics */
745578bc3efSJulian Anastasov 	unsigned long		state;		/* state flags */
7461da177e4SLinus Torvalds 
7471da177e4SLinus Torvalds 	/* connection counters and thresholds */
7481da177e4SLinus Torvalds 	atomic_t		activeconns;	/* active connections */
7491da177e4SLinus Torvalds 	atomic_t		inactconns;	/* inactive connections */
7501da177e4SLinus Torvalds 	atomic_t		persistconns;	/* persistent connections */
7511da177e4SLinus Torvalds 	__u32			u_threshold;	/* upper threshold */
7521da177e4SLinus Torvalds 	__u32			l_threshold;	/* lower threshold */
7531da177e4SLinus Torvalds 
7541da177e4SLinus Torvalds 	/* for destination cache */
7551da177e4SLinus Torvalds 	spinlock_t		dst_lock;	/* lock of dst_cache */
756026ace06SJulian Anastasov 	struct ip_vs_dest_dst __rcu *dest_dst;	/* cached dst info */
7571da177e4SLinus Torvalds 
7581da177e4SLinus Torvalds 	/* for virtual service */
7591da177e4SLinus Torvalds 	struct ip_vs_service	*svc;		/* service it belongs to */
7601da177e4SLinus Torvalds 	__u16			protocol;	/* which protocol (TCP/UDP) */
761014d730dSAl Viro 	__be16			vport;		/* virtual port number */
762f2431e6eSHans Schillstrom 	union nf_inet_addr	vaddr;		/* virtual IP address */
7631da177e4SLinus Torvalds 	__u32			vfwmark;	/* firewall mark of service */
764276472eaSJulian Anastasov 
765578bc3efSJulian Anastasov 	struct list_head	t_list;		/* in dest_trash */
766276472eaSJulian Anastasov 	struct rcu_head		rcu_head;
767276472eaSJulian Anastasov 	unsigned int		in_rs_table:1;	/* we are in rs_table */
7681da177e4SLinus Torvalds };
7691da177e4SLinus Torvalds 
7701da177e4SLinus Torvalds 
7711da177e4SLinus Torvalds /*
7721da177e4SLinus Torvalds  *	The scheduler object
7731da177e4SLinus Torvalds  */
7741da177e4SLinus Torvalds struct ip_vs_scheduler {
7751da177e4SLinus Torvalds 	struct list_head	n_list;		/* d-linked list head */
7761da177e4SLinus Torvalds 	char			*name;		/* scheduler name */
7771da177e4SLinus Torvalds 	atomic_t		refcnt;		/* reference counter */
7781da177e4SLinus Torvalds 	struct module		*module;	/* THIS_MODULE/NULL */
7791da177e4SLinus Torvalds 
7801da177e4SLinus Torvalds 	/* scheduler initializing service */
7811da177e4SLinus Torvalds 	int (*init_service)(struct ip_vs_service *svc);
7821da177e4SLinus Torvalds 	/* scheduling service finish */
783ed3ffc4eSJulian Anastasov 	void (*done_service)(struct ip_vs_service *svc);
7846b6df466SJulian Anastasov 	/* dest is linked */
7856b6df466SJulian Anastasov 	int (*add_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
7866b6df466SJulian Anastasov 	/* dest is unlinked */
7876b6df466SJulian Anastasov 	int (*del_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
7886b6df466SJulian Anastasov 	/* dest is updated */
7896b6df466SJulian Anastasov 	int (*upd_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
7901da177e4SLinus Torvalds 
7911da177e4SLinus Torvalds 	/* selecting a server from the given service */
7921da177e4SLinus Torvalds 	struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
793bba54de5SJulian Anastasov 				       const struct sk_buff *skb,
794bba54de5SJulian Anastasov 				       struct ip_vs_iphdr *iph);
7951da177e4SLinus Torvalds };
7961da177e4SLinus Torvalds 
79785999283SSimon Horman /* The persistence engine object */
79885999283SSimon Horman struct ip_vs_pe {
79985999283SSimon Horman 	struct list_head	n_list;		/* d-linked list head */
80085999283SSimon Horman 	char			*name;		/* scheduler name */
80185999283SSimon Horman 	atomic_t		refcnt;		/* reference counter */
80285999283SSimon Horman 	struct module		*module;	/* THIS_MODULE/NULL */
80385999283SSimon Horman 
80485999283SSimon Horman 	/* get the connection template, if any */
80585999283SSimon Horman 	int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb);
80685999283SSimon Horman 	bool (*ct_match)(const struct ip_vs_conn_param *p,
80785999283SSimon Horman 			 struct ip_vs_conn *ct);
80885999283SSimon Horman 	u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval,
80985999283SSimon Horman 			   bool inverse);
810a3c918acSSimon Horman 	int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf);
81185999283SSimon Horman };
8121da177e4SLinus Torvalds 
8131da177e4SLinus Torvalds /*
8141da177e4SLinus Torvalds  *	The application module object (a.k.a. app incarnation)
8151da177e4SLinus Torvalds  */
816fd2c3ef7SEric Dumazet struct ip_vs_app {
8171da177e4SLinus Torvalds 	struct list_head	a_list;		/* member in app list */
8181da177e4SLinus Torvalds 	int			type;		/* IP_VS_APP_TYPE_xxx */
8191da177e4SLinus Torvalds 	char			*name;		/* application module name */
8201da177e4SLinus Torvalds 	__u16			protocol;
8211da177e4SLinus Torvalds 	struct module		*module;	/* THIS_MODULE/NULL */
8221da177e4SLinus Torvalds 	struct list_head	incs_list;	/* list of incarnations */
8231da177e4SLinus Torvalds 
8241da177e4SLinus Torvalds 	/* members for application incarnations */
8251da177e4SLinus Torvalds 	struct list_head	p_list;		/* member in proto app list */
8261da177e4SLinus Torvalds 	struct ip_vs_app	*app;		/* its real application */
827014d730dSAl Viro 	__be16			port;		/* port number in net order */
8281da177e4SLinus Torvalds 	atomic_t		usecnt;		/* usage counter */
829363c97d7SJulian Anastasov 	struct rcu_head		rcu_head;
8301da177e4SLinus Torvalds 
8318b27b10fSJulian Anastasov 	/*
8328b27b10fSJulian Anastasov 	 * output hook: Process packet in inout direction, diff set for TCP.
8338b27b10fSJulian Anastasov 	 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
8348b27b10fSJulian Anastasov 	 *	   2=Mangled but checksum was not updated
8358b27b10fSJulian Anastasov 	 */
8361da177e4SLinus Torvalds 	int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
8373db05feaSHerbert Xu 		       struct sk_buff *, int *diff);
8381da177e4SLinus Torvalds 
8398b27b10fSJulian Anastasov 	/*
8408b27b10fSJulian Anastasov 	 * input hook: Process packet in outin direction, diff set for TCP.
8418b27b10fSJulian Anastasov 	 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
8428b27b10fSJulian Anastasov 	 *	   2=Mangled but checksum was not updated
8438b27b10fSJulian Anastasov 	 */
8441da177e4SLinus Torvalds 	int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
8453db05feaSHerbert Xu 		      struct sk_buff *, int *diff);
8461da177e4SLinus Torvalds 
8471da177e4SLinus Torvalds 	/* ip_vs_app initializer */
8481da177e4SLinus Torvalds 	int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
8491da177e4SLinus Torvalds 
8501da177e4SLinus Torvalds 	/* ip_vs_app finish */
8511da177e4SLinus Torvalds 	int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
8521da177e4SLinus Torvalds 
8531da177e4SLinus Torvalds 
8541da177e4SLinus Torvalds 	/* not used now */
8551da177e4SLinus Torvalds 	int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
8561da177e4SLinus Torvalds 			 struct ip_vs_protocol *);
8571da177e4SLinus Torvalds 
8581da177e4SLinus Torvalds 	void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
8591da177e4SLinus Torvalds 
8601da177e4SLinus Torvalds 	int *			timeout_table;
8611da177e4SLinus Torvalds 	int *			timeouts;
8621da177e4SLinus Torvalds 	int			timeouts_size;
8631da177e4SLinus Torvalds 
8641da177e4SLinus Torvalds 	int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
8651da177e4SLinus Torvalds 			     int *verdict, struct ip_vs_conn **cpp);
8661da177e4SLinus Torvalds 
8671da177e4SLinus Torvalds 	struct ip_vs_conn *
8681da177e4SLinus Torvalds 	(*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
869d4383f04SJesper Dangaard Brouer 		       const struct iphdr *iph, int inverse);
8701da177e4SLinus Torvalds 
8711da177e4SLinus Torvalds 	struct ip_vs_conn *
8721da177e4SLinus Torvalds 	(*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
873d4383f04SJesper Dangaard Brouer 			const struct iphdr *iph, int inverse);
8741da177e4SLinus Torvalds 
8751da177e4SLinus Torvalds 	int (*state_transition)(struct ip_vs_conn *cp, int direction,
8761da177e4SLinus Torvalds 				const struct sk_buff *skb,
8771da177e4SLinus Torvalds 				struct ip_vs_app *app);
8781da177e4SLinus Torvalds 
8791da177e4SLinus Torvalds 	void (*timeout_change)(struct ip_vs_app *app, int flags);
8801da177e4SLinus Torvalds };
8811da177e4SLinus Torvalds 
882f73181c8SPablo Neira Ayuso struct ipvs_master_sync_state {
883f73181c8SPablo Neira Ayuso 	struct list_head	sync_queue;
884f73181c8SPablo Neira Ayuso 	struct ip_vs_sync_buff	*sync_buff;
88507995674SZhang Yanfei 	unsigned long		sync_queue_len;
886f73181c8SPablo Neira Ayuso 	unsigned int		sync_queue_delay;
887f73181c8SPablo Neira Ayuso 	struct task_struct	*master_thread;
888f73181c8SPablo Neira Ayuso 	struct delayed_work	master_wakeup_work;
889f73181c8SPablo Neira Ayuso 	struct netns_ipvs	*ipvs;
890f73181c8SPablo Neira Ayuso };
891f73181c8SPablo Neira Ayuso 
892578bc3efSJulian Anastasov /* How much time to keep dests in trash */
893578bc3efSJulian Anastasov #define IP_VS_DEST_TRASH_PERIOD		(120 * HZ)
894578bc3efSJulian Anastasov 
8952553d064SJulian Anastasov /* IPVS in network namespace */
8962553d064SJulian Anastasov struct netns_ipvs {
8972553d064SJulian Anastasov 	int			gen;		/* Generation */
8987a4f0761SHans Schillstrom 	int			enable;		/* enable like nf_hooks do */
8992553d064SJulian Anastasov 	/*
9002553d064SJulian Anastasov 	 *	Hash table: for real service lookups
9012553d064SJulian Anastasov 	 */
9022553d064SJulian Anastasov 	#define IP_VS_RTAB_BITS 4
9032553d064SJulian Anastasov 	#define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS)
9042553d064SJulian Anastasov 	#define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1)
9052553d064SJulian Anastasov 
906276472eaSJulian Anastasov 	struct hlist_head	rs_table[IP_VS_RTAB_SIZE];
9072553d064SJulian Anastasov 	/* ip_vs_app */
9082553d064SJulian Anastasov 	struct list_head	app_list;
9092553d064SJulian Anastasov 	/* ip_vs_proto */
9102553d064SJulian Anastasov 	#define IP_VS_PROTO_TAB_SIZE	32	/* must be power of 2 */
9112553d064SJulian Anastasov 	struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE];
9122553d064SJulian Anastasov 	/* ip_vs_proto_tcp */
9132553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_TCP
9142553d064SJulian Anastasov 	#define	TCP_APP_TAB_BITS	4
9152553d064SJulian Anastasov 	#define	TCP_APP_TAB_SIZE	(1 << TCP_APP_TAB_BITS)
9162553d064SJulian Anastasov 	#define	TCP_APP_TAB_MASK	(TCP_APP_TAB_SIZE - 1)
9172553d064SJulian Anastasov 	struct list_head	tcp_apps[TCP_APP_TAB_SIZE];
9182553d064SJulian Anastasov #endif
9192553d064SJulian Anastasov 	/* ip_vs_proto_udp */
9202553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_UDP
9212553d064SJulian Anastasov 	#define	UDP_APP_TAB_BITS	4
9222553d064SJulian Anastasov 	#define	UDP_APP_TAB_SIZE	(1 << UDP_APP_TAB_BITS)
9232553d064SJulian Anastasov 	#define	UDP_APP_TAB_MASK	(UDP_APP_TAB_SIZE - 1)
9242553d064SJulian Anastasov 	struct list_head	udp_apps[UDP_APP_TAB_SIZE];
9252553d064SJulian Anastasov #endif
9262553d064SJulian Anastasov 	/* ip_vs_proto_sctp */
9272553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_SCTP
9282553d064SJulian Anastasov 	#define SCTP_APP_TAB_BITS	4
9292553d064SJulian Anastasov 	#define SCTP_APP_TAB_SIZE	(1 << SCTP_APP_TAB_BITS)
9302553d064SJulian Anastasov 	#define SCTP_APP_TAB_MASK	(SCTP_APP_TAB_SIZE - 1)
9312553d064SJulian Anastasov 	/* Hash table for SCTP application incarnations	 */
9322553d064SJulian Anastasov 	struct list_head	sctp_apps[SCTP_APP_TAB_SIZE];
9332553d064SJulian Anastasov #endif
9342553d064SJulian Anastasov 	/* ip_vs_conn */
9352553d064SJulian Anastasov 	atomic_t		conn_count;      /*  connection counter */
9362553d064SJulian Anastasov 
9372553d064SJulian Anastasov 	/* ip_vs_ctl */
9382a0751afSJulian Anastasov 	struct ip_vs_stats		tot_stats;  /* Statistics & est. */
9392553d064SJulian Anastasov 
9402553d064SJulian Anastasov 	int			num_services;    /* no of virtual services */
941f2247fbdSSimon Horman 
9422553d064SJulian Anastasov 	/* Trash for destinations */
9432553d064SJulian Anastasov 	struct list_head	dest_trash;
944578bc3efSJulian Anastasov 	spinlock_t		dest_trash_lock;
945578bc3efSJulian Anastasov 	struct timer_list	dest_trash_timer; /* expiration timer */
9462553d064SJulian Anastasov 	/* Service counters */
9472553d064SJulian Anastasov 	atomic_t		ftpsvc_counter;
9482553d064SJulian Anastasov 	atomic_t		nullsvc_counter;
9492553d064SJulian Anastasov 
950f2247fbdSSimon Horman #ifdef CONFIG_SYSCTL
951f2247fbdSSimon Horman 	/* 1/rate drop and drop-entry variables */
952f2247fbdSSimon Horman 	struct delayed_work	defense_work;   /* Work handler */
953f2247fbdSSimon Horman 	int			drop_rate;
954f2247fbdSSimon Horman 	int			drop_counter;
955f2247fbdSSimon Horman 	atomic_t		dropentry;
956f2247fbdSSimon Horman 	/* locks in ctl.c */
957f2247fbdSSimon Horman 	spinlock_t		dropentry_lock;  /* drop entry handling */
958f2247fbdSSimon Horman 	spinlock_t		droppacket_lock; /* drop packet handling */
959f2247fbdSSimon Horman 	spinlock_t		securetcp_lock;  /* state and timeout tables */
960f2247fbdSSimon Horman 
9612553d064SJulian Anastasov 	/* sys-ctl struct */
9622553d064SJulian Anastasov 	struct ctl_table_header	*sysctl_hdr;
9632553d064SJulian Anastasov 	struct ctl_table	*sysctl_tbl;
964f2247fbdSSimon Horman #endif
965f2247fbdSSimon Horman 
9662553d064SJulian Anastasov 	/* sysctl variables */
9672553d064SJulian Anastasov 	int			sysctl_amemthresh;
9682553d064SJulian Anastasov 	int			sysctl_am_droprate;
9692553d064SJulian Anastasov 	int			sysctl_drop_entry;
9702553d064SJulian Anastasov 	int			sysctl_drop_packet;
9712553d064SJulian Anastasov 	int			sysctl_secure_tcp;
9722553d064SJulian Anastasov #ifdef CONFIG_IP_VS_NFCT
9732553d064SJulian Anastasov 	int			sysctl_conntrack;
9742553d064SJulian Anastasov #endif
9752553d064SJulian Anastasov 	int			sysctl_snat_reroute;
9762553d064SJulian Anastasov 	int			sysctl_sync_ver;
977f73181c8SPablo Neira Ayuso 	int			sysctl_sync_ports;
978*4d0c875dSJulian Anastasov 	int			sysctl_sync_persist_mode;
97907995674SZhang Yanfei 	unsigned long		sysctl_sync_qlen_max;
9801c003b15SPablo Neira Ayuso 	int			sysctl_sync_sock_size;
9812553d064SJulian Anastasov 	int			sysctl_cache_bypass;
9822553d064SJulian Anastasov 	int			sysctl_expire_nodest_conn;
983c6c96c18SAlexander Frolkin 	int			sysctl_sloppy_tcp;
984c6c96c18SAlexander Frolkin 	int			sysctl_sloppy_sctp;
9852553d064SJulian Anastasov 	int			sysctl_expire_quiescent_template;
9862553d064SJulian Anastasov 	int			sysctl_sync_threshold[2];
987749c42b6SJulian Anastasov 	unsigned int		sysctl_sync_refresh_period;
988749c42b6SJulian Anastasov 	int			sysctl_sync_retries;
9892553d064SJulian Anastasov 	int			sysctl_nat_icmp_send;
9903654e611SJulian Anastasov 	int			sysctl_pmtu_disc;
9910c12582fSJulian Anastasov 	int			sysctl_backup_only;
9922553d064SJulian Anastasov 
9932553d064SJulian Anastasov 	/* ip_vs_lblc */
9942553d064SJulian Anastasov 	int			sysctl_lblc_expiration;
9952553d064SJulian Anastasov 	struct ctl_table_header	*lblc_ctl_header;
9962553d064SJulian Anastasov 	struct ctl_table	*lblc_ctl_table;
9972553d064SJulian Anastasov 	/* ip_vs_lblcr */
9982553d064SJulian Anastasov 	int			sysctl_lblcr_expiration;
9992553d064SJulian Anastasov 	struct ctl_table_header	*lblcr_ctl_header;
10002553d064SJulian Anastasov 	struct ctl_table	*lblcr_ctl_table;
10012553d064SJulian Anastasov 	/* ip_vs_est */
10022553d064SJulian Anastasov 	struct list_head	est_list;	/* estimator list */
10032553d064SJulian Anastasov 	spinlock_t		est_lock;
10042553d064SJulian Anastasov 	struct timer_list	est_timer;	/* Estimation timer */
10052553d064SJulian Anastasov 	/* ip_vs_sync */
10062553d064SJulian Anastasov 	spinlock_t		sync_lock;
1007f73181c8SPablo Neira Ayuso 	struct ipvs_master_sync_state *ms;
10082553d064SJulian Anastasov 	spinlock_t		sync_buff_lock;
1009f73181c8SPablo Neira Ayuso 	struct task_struct	**backup_threads;
1010f73181c8SPablo Neira Ayuso 	int			threads_mask;
10112553d064SJulian Anastasov 	int			send_mesg_maxlen;
10122553d064SJulian Anastasov 	int			recv_mesg_maxlen;
10132553d064SJulian Anastasov 	volatile int		sync_state;
10142553d064SJulian Anastasov 	volatile int		master_syncid;
10152553d064SJulian Anastasov 	volatile int		backup_syncid;
1016ae1d48b2SHans Schillstrom 	struct mutex		sync_mutex;
10172553d064SJulian Anastasov 	/* multicast interface name */
10182553d064SJulian Anastasov 	char			master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
10192553d064SJulian Anastasov 	char			backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
10202553d064SJulian Anastasov 	/* net name space ptr */
10212553d064SJulian Anastasov 	struct net		*net;            /* Needed by timer routines */
10222553d064SJulian Anastasov };
10231da177e4SLinus Torvalds 
102459e0350eSSimon Horman #define DEFAULT_SYNC_THRESHOLD	3
102559e0350eSSimon Horman #define DEFAULT_SYNC_PERIOD	50
10267532e8d4SSimon Horman #define DEFAULT_SYNC_VER	1
1027c6c96c18SAlexander Frolkin #define DEFAULT_SLOPPY_TCP	0
1028c6c96c18SAlexander Frolkin #define DEFAULT_SLOPPY_SCTP	0
1029749c42b6SJulian Anastasov #define DEFAULT_SYNC_REFRESH_PERIOD	(0U * HZ)
1030749c42b6SJulian Anastasov #define DEFAULT_SYNC_RETRIES		0
10311c003b15SPablo Neira Ayuso #define IPVS_SYNC_WAKEUP_RATE	8
10321c003b15SPablo Neira Ayuso #define IPVS_SYNC_QLEN_MAX	(IPVS_SYNC_WAKEUP_RATE * 4)
10331c003b15SPablo Neira Ayuso #define IPVS_SYNC_SEND_DELAY	(HZ / 50)
10341c003b15SPablo Neira Ayuso #define IPVS_SYNC_CHECK_PERIOD	HZ
1035749c42b6SJulian Anastasov #define IPVS_SYNC_FLUSH_TIME	(HZ * 2)
1036f73181c8SPablo Neira Ayuso #define IPVS_SYNC_PORTS_MAX	(1 << 6)
103759e0350eSSimon Horman 
103859e0350eSSimon Horman #ifdef CONFIG_SYSCTL
103959e0350eSSimon Horman 
104059e0350eSSimon Horman static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
104159e0350eSSimon Horman {
104259e0350eSSimon Horman 	return ipvs->sysctl_sync_threshold[0];
104359e0350eSSimon Horman }
104459e0350eSSimon Horman 
104559e0350eSSimon Horman static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
104659e0350eSSimon Horman {
1047749c42b6SJulian Anastasov 	return ACCESS_ONCE(ipvs->sysctl_sync_threshold[1]);
1048749c42b6SJulian Anastasov }
1049749c42b6SJulian Anastasov 
1050749c42b6SJulian Anastasov static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
1051749c42b6SJulian Anastasov {
1052749c42b6SJulian Anastasov 	return ACCESS_ONCE(ipvs->sysctl_sync_refresh_period);
1053749c42b6SJulian Anastasov }
1054749c42b6SJulian Anastasov 
1055749c42b6SJulian Anastasov static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
1056749c42b6SJulian Anastasov {
1057749c42b6SJulian Anastasov 	return ipvs->sysctl_sync_retries;
105859e0350eSSimon Horman }
105959e0350eSSimon Horman 
10607532e8d4SSimon Horman static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
10617532e8d4SSimon Horman {
10627532e8d4SSimon Horman 	return ipvs->sysctl_sync_ver;
10637532e8d4SSimon Horman }
10647532e8d4SSimon Horman 
1065c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs)
1066c6c96c18SAlexander Frolkin {
1067c6c96c18SAlexander Frolkin 	return ipvs->sysctl_sloppy_tcp;
1068c6c96c18SAlexander Frolkin }
1069c6c96c18SAlexander Frolkin 
1070c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs)
1071c6c96c18SAlexander Frolkin {
1072c6c96c18SAlexander Frolkin 	return ipvs->sysctl_sloppy_sctp;
1073c6c96c18SAlexander Frolkin }
1074c6c96c18SAlexander Frolkin 
1075f73181c8SPablo Neira Ayuso static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
1076f73181c8SPablo Neira Ayuso {
1077f73181c8SPablo Neira Ayuso 	return ACCESS_ONCE(ipvs->sysctl_sync_ports);
1078f73181c8SPablo Neira Ayuso }
1079f73181c8SPablo Neira Ayuso 
1080*4d0c875dSJulian Anastasov static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs)
1081*4d0c875dSJulian Anastasov {
1082*4d0c875dSJulian Anastasov 	return ipvs->sysctl_sync_persist_mode;
1083*4d0c875dSJulian Anastasov }
1084*4d0c875dSJulian Anastasov 
108507995674SZhang Yanfei static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
10861c003b15SPablo Neira Ayuso {
10871c003b15SPablo Neira Ayuso 	return ipvs->sysctl_sync_qlen_max;
10881c003b15SPablo Neira Ayuso }
10891c003b15SPablo Neira Ayuso 
10901c003b15SPablo Neira Ayuso static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
10911c003b15SPablo Neira Ayuso {
10921c003b15SPablo Neira Ayuso 	return ipvs->sysctl_sync_sock_size;
10931c003b15SPablo Neira Ayuso }
10941c003b15SPablo Neira Ayuso 
10953654e611SJulian Anastasov static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
10963654e611SJulian Anastasov {
10973654e611SJulian Anastasov 	return ipvs->sysctl_pmtu_disc;
10983654e611SJulian Anastasov }
10993654e611SJulian Anastasov 
11000c12582fSJulian Anastasov static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
11010c12582fSJulian Anastasov {
11020c12582fSJulian Anastasov 	return ipvs->sync_state & IP_VS_STATE_BACKUP &&
11030c12582fSJulian Anastasov 	       ipvs->sysctl_backup_only;
11040c12582fSJulian Anastasov }
11050c12582fSJulian Anastasov 
110659e0350eSSimon Horman #else
110759e0350eSSimon Horman 
110859e0350eSSimon Horman static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
110959e0350eSSimon Horman {
111059e0350eSSimon Horman 	return DEFAULT_SYNC_THRESHOLD;
111159e0350eSSimon Horman }
111259e0350eSSimon Horman 
111359e0350eSSimon Horman static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
111459e0350eSSimon Horman {
111559e0350eSSimon Horman 	return DEFAULT_SYNC_PERIOD;
111659e0350eSSimon Horman }
111759e0350eSSimon Horman 
1118749c42b6SJulian Anastasov static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
1119749c42b6SJulian Anastasov {
1120749c42b6SJulian Anastasov 	return DEFAULT_SYNC_REFRESH_PERIOD;
1121749c42b6SJulian Anastasov }
1122749c42b6SJulian Anastasov 
1123749c42b6SJulian Anastasov static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
1124749c42b6SJulian Anastasov {
1125749c42b6SJulian Anastasov 	return DEFAULT_SYNC_RETRIES & 3;
1126749c42b6SJulian Anastasov }
1127749c42b6SJulian Anastasov 
11287532e8d4SSimon Horman static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
11297532e8d4SSimon Horman {
11307532e8d4SSimon Horman 	return DEFAULT_SYNC_VER;
11317532e8d4SSimon Horman }
11327532e8d4SSimon Horman 
1133c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs)
1134c6c96c18SAlexander Frolkin {
1135c6c96c18SAlexander Frolkin 	return DEFAULT_SLOPPY_TCP;
1136c6c96c18SAlexander Frolkin }
1137c6c96c18SAlexander Frolkin 
1138c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs)
1139c6c96c18SAlexander Frolkin {
1140c6c96c18SAlexander Frolkin 	return DEFAULT_SLOPPY_SCTP;
1141c6c96c18SAlexander Frolkin }
1142c6c96c18SAlexander Frolkin 
1143f73181c8SPablo Neira Ayuso static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
1144f73181c8SPablo Neira Ayuso {
1145f73181c8SPablo Neira Ayuso 	return 1;
1146f73181c8SPablo Neira Ayuso }
1147f73181c8SPablo Neira Ayuso 
1148*4d0c875dSJulian Anastasov static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs)
1149*4d0c875dSJulian Anastasov {
1150*4d0c875dSJulian Anastasov 	return 0;
1151*4d0c875dSJulian Anastasov }
1152*4d0c875dSJulian Anastasov 
115307995674SZhang Yanfei static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
11541c003b15SPablo Neira Ayuso {
11551c003b15SPablo Neira Ayuso 	return IPVS_SYNC_QLEN_MAX;
11561c003b15SPablo Neira Ayuso }
11571c003b15SPablo Neira Ayuso 
11581c003b15SPablo Neira Ayuso static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
11591c003b15SPablo Neira Ayuso {
11601c003b15SPablo Neira Ayuso 	return 0;
11611c003b15SPablo Neira Ayuso }
11621c003b15SPablo Neira Ayuso 
11633654e611SJulian Anastasov static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
11643654e611SJulian Anastasov {
11653654e611SJulian Anastasov 	return 1;
11663654e611SJulian Anastasov }
11673654e611SJulian Anastasov 
11680c12582fSJulian Anastasov static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
11690c12582fSJulian Anastasov {
11700c12582fSJulian Anastasov 	return 0;
11710c12582fSJulian Anastasov }
11720c12582fSJulian Anastasov 
117359e0350eSSimon Horman #endif
117459e0350eSSimon Horman 
11751da177e4SLinus Torvalds /*
11761da177e4SLinus Torvalds  *      IPVS core functions
11771da177e4SLinus Torvalds  *      (from ip_vs_core.c)
11781da177e4SLinus Torvalds  */
117995c96174SEric Dumazet extern const char *ip_vs_proto_name(unsigned int proto);
11801da177e4SLinus Torvalds extern void ip_vs_init_hash_table(struct list_head *table, int rows);
1181afdd6140SSven Wegener #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
11821da177e4SLinus Torvalds 
11831da177e4SLinus Torvalds #define IP_VS_APP_TYPE_FTP	1
11841da177e4SLinus Torvalds 
11851da177e4SLinus Torvalds /*
11861da177e4SLinus Torvalds  *     ip_vs_conn handling functions
11871da177e4SLinus Torvalds  *     (from ip_vs_conn.c)
11881da177e4SLinus Torvalds  */
11891da177e4SLinus Torvalds 
11901da177e4SLinus Torvalds enum {
11911da177e4SLinus Torvalds 	IP_VS_DIR_INPUT = 0,
11921da177e4SLinus Torvalds 	IP_VS_DIR_OUTPUT,
11931da177e4SLinus Torvalds 	IP_VS_DIR_INPUT_ONLY,
11941da177e4SLinus Torvalds 	IP_VS_DIR_LAST,
11951da177e4SLinus Torvalds };
11961da177e4SLinus Torvalds 
11976e67e586SHans Schillstrom static inline void ip_vs_conn_fill_param(struct net *net, int af, int protocol,
1198f11017ecSSimon Horman 					 const union nf_inet_addr *caddr,
1199f11017ecSSimon Horman 					 __be16 cport,
1200f11017ecSSimon Horman 					 const union nf_inet_addr *vaddr,
1201f11017ecSSimon Horman 					 __be16 vport,
1202f11017ecSSimon Horman 					 struct ip_vs_conn_param *p)
1203f11017ecSSimon Horman {
12046e67e586SHans Schillstrom 	p->net = net;
1205f11017ecSSimon Horman 	p->af = af;
1206f11017ecSSimon Horman 	p->protocol = protocol;
1207f11017ecSSimon Horman 	p->caddr = caddr;
1208f11017ecSSimon Horman 	p->cport = cport;
1209f11017ecSSimon Horman 	p->vaddr = vaddr;
1210f11017ecSSimon Horman 	p->vport = vport;
121185999283SSimon Horman 	p->pe = NULL;
121285999283SSimon Horman 	p->pe_data = NULL;
1213f11017ecSSimon Horman }
121428364a59SJulius Volz 
1215f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p);
1216f11017ecSSimon Horman struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p);
121728364a59SJulius Volz 
12185c0d2374SSimon Horman struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb,
12195c0d2374SSimon Horman 					    const struct ip_vs_iphdr *iph,
12205c0d2374SSimon Horman 					    int inverse);
12215c0d2374SSimon Horman 
1222f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p);
12231da177e4SLinus Torvalds 
12245c0d2374SSimon Horman struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb,
12255c0d2374SSimon Horman 					     const struct ip_vs_iphdr *iph,
12265c0d2374SSimon Horman 					     int inverse);
12275c0d2374SSimon Horman 
1228088339a5SJulian Anastasov /* Get reference to gain full access to conn.
1229088339a5SJulian Anastasov  * By default, RCU read-side critical sections have access only to
1230088339a5SJulian Anastasov  * conn fields and its PE data, see ip_vs_conn_rcu_free() for reference.
1231088339a5SJulian Anastasov  */
1232088339a5SJulian Anastasov static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp)
1233088339a5SJulian Anastasov {
1234088339a5SJulian Anastasov 	return atomic_inc_not_zero(&cp->refcnt);
1235088339a5SJulian Anastasov }
1236088339a5SJulian Anastasov 
12371da177e4SLinus Torvalds /* put back the conn without restarting its timer */
12381da177e4SLinus Torvalds static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
12391da177e4SLinus Torvalds {
1240088339a5SJulian Anastasov 	smp_mb__before_atomic_dec();
12411da177e4SLinus Torvalds 	atomic_dec(&cp->refcnt);
12421da177e4SLinus Torvalds }
12431da177e4SLinus Torvalds extern void ip_vs_conn_put(struct ip_vs_conn *cp);
1244014d730dSAl Viro extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
12451da177e4SLinus Torvalds 
1246f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p,
1247f11017ecSSimon Horman 				  const union nf_inet_addr *daddr,
124895c96174SEric Dumazet 				  __be16 dport, unsigned int flags,
12490e051e68SHans Schillstrom 				  struct ip_vs_dest *dest, __u32 fwmark);
12501da177e4SLinus Torvalds extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
12511da177e4SLinus Torvalds 
12521da177e4SLinus Torvalds extern const char * ip_vs_state_name(__u16 proto, int state);
12531da177e4SLinus Torvalds 
12544a85b96cSHans Schillstrom extern void ip_vs_tcp_conn_listen(struct net *net, struct ip_vs_conn *cp);
12551da177e4SLinus Torvalds extern int ip_vs_check_template(struct ip_vs_conn *ct);
1256f6340ee0SHans Schillstrom extern void ip_vs_random_dropentry(struct net *net);
12571da177e4SLinus Torvalds extern int ip_vs_conn_init(void);
12581da177e4SLinus Torvalds extern void ip_vs_conn_cleanup(void);
12591da177e4SLinus Torvalds 
12601da177e4SLinus Torvalds static inline void ip_vs_control_del(struct ip_vs_conn *cp)
12611da177e4SLinus Torvalds {
12621da177e4SLinus Torvalds 	struct ip_vs_conn *ctl_cp = cp->control;
12631da177e4SLinus Torvalds 	if (!ctl_cp) {
1264cfc78c5aSJulius Volz 		IP_VS_ERR_BUF("request control DEL for uncontrolled: "
1265cfc78c5aSJulius Volz 			      "%s:%d to %s:%d\n",
1266cfc78c5aSJulius Volz 			      IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1267cfc78c5aSJulius Volz 			      ntohs(cp->cport),
1268cfc78c5aSJulius Volz 			      IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
1269cfc78c5aSJulius Volz 			      ntohs(cp->vport));
1270cfc78c5aSJulius Volz 
12711da177e4SLinus Torvalds 		return;
12721da177e4SLinus Torvalds 	}
12731da177e4SLinus Torvalds 
1274cfc78c5aSJulius Volz 	IP_VS_DBG_BUF(7, "DELeting control for: "
1275cfc78c5aSJulius Volz 		      "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
1276cfc78c5aSJulius Volz 		      IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1277cfc78c5aSJulius Volz 		      ntohs(cp->cport),
1278cfc78c5aSJulius Volz 		      IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
1279cfc78c5aSJulius Volz 		      ntohs(ctl_cp->cport));
12801da177e4SLinus Torvalds 
12811da177e4SLinus Torvalds 	cp->control = NULL;
12821da177e4SLinus Torvalds 	if (atomic_read(&ctl_cp->n_control) == 0) {
1283cfc78c5aSJulius Volz 		IP_VS_ERR_BUF("BUG control DEL with n=0 : "
1284cfc78c5aSJulius Volz 			      "%s:%d to %s:%d\n",
1285cfc78c5aSJulius Volz 			      IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1286cfc78c5aSJulius Volz 			      ntohs(cp->cport),
1287cfc78c5aSJulius Volz 			      IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
1288cfc78c5aSJulius Volz 			      ntohs(cp->vport));
1289cfc78c5aSJulius Volz 
12901da177e4SLinus Torvalds 		return;
12911da177e4SLinus Torvalds 	}
12921da177e4SLinus Torvalds 	atomic_dec(&ctl_cp->n_control);
12931da177e4SLinus Torvalds }
12941da177e4SLinus Torvalds 
12951da177e4SLinus Torvalds static inline void
12961da177e4SLinus Torvalds ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
12971da177e4SLinus Torvalds {
12981da177e4SLinus Torvalds 	if (cp->control) {
1299cfc78c5aSJulius Volz 		IP_VS_ERR_BUF("request control ADD for already controlled: "
1300cfc78c5aSJulius Volz 			      "%s:%d to %s:%d\n",
1301cfc78c5aSJulius Volz 			      IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1302cfc78c5aSJulius Volz 			      ntohs(cp->cport),
1303cfc78c5aSJulius Volz 			      IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
1304cfc78c5aSJulius Volz 			      ntohs(cp->vport));
1305cfc78c5aSJulius Volz 
13061da177e4SLinus Torvalds 		ip_vs_control_del(cp);
13071da177e4SLinus Torvalds 	}
13081da177e4SLinus Torvalds 
1309cfc78c5aSJulius Volz 	IP_VS_DBG_BUF(7, "ADDing control for: "
1310cfc78c5aSJulius Volz 		      "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
1311cfc78c5aSJulius Volz 		      IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1312cfc78c5aSJulius Volz 		      ntohs(cp->cport),
1313cfc78c5aSJulius Volz 		      IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
1314cfc78c5aSJulius Volz 		      ntohs(ctl_cp->cport));
13151da177e4SLinus Torvalds 
13161da177e4SLinus Torvalds 	cp->control = ctl_cp;
13171da177e4SLinus Torvalds 	atomic_inc(&ctl_cp->n_control);
13181da177e4SLinus Torvalds }
13191da177e4SLinus Torvalds 
13207a4f0761SHans Schillstrom /*
13217a4f0761SHans Schillstrom  * IPVS netns init & cleanup functions
13227a4f0761SHans Schillstrom  */
1323503cf15aSHans Schillstrom extern int ip_vs_estimator_net_init(struct net *net);
1324503cf15aSHans Schillstrom extern int ip_vs_control_net_init(struct net *net);
1325503cf15aSHans Schillstrom extern int ip_vs_protocol_net_init(struct net *net);
1326503cf15aSHans Schillstrom extern int ip_vs_app_net_init(struct net *net);
1327503cf15aSHans Schillstrom extern int ip_vs_conn_net_init(struct net *net);
1328503cf15aSHans Schillstrom extern int ip_vs_sync_net_init(struct net *net);
1329503cf15aSHans Schillstrom extern void ip_vs_conn_net_cleanup(struct net *net);
1330503cf15aSHans Schillstrom extern void ip_vs_app_net_cleanup(struct net *net);
1331503cf15aSHans Schillstrom extern void ip_vs_protocol_net_cleanup(struct net *net);
1332503cf15aSHans Schillstrom extern void ip_vs_control_net_cleanup(struct net *net);
1333503cf15aSHans Schillstrom extern void ip_vs_estimator_net_cleanup(struct net *net);
1334503cf15aSHans Schillstrom extern void ip_vs_sync_net_cleanup(struct net *net);
1335503cf15aSHans Schillstrom extern void ip_vs_service_net_cleanup(struct net *net);
13361da177e4SLinus Torvalds 
13371da177e4SLinus Torvalds /*
13381da177e4SLinus Torvalds  *      IPVS application functions
13391da177e4SLinus Torvalds  *      (from ip_vs_app.c)
13401da177e4SLinus Torvalds  */
13411da177e4SLinus Torvalds #define IP_VS_APP_MAX_PORTS  8
1342be97fdb5SJulian Anastasov extern struct ip_vs_app *register_ip_vs_app(struct net *net,
1343be97fdb5SJulian Anastasov 					    struct ip_vs_app *app);
1344ab8a5e84SHans Schillstrom extern void unregister_ip_vs_app(struct net *net, struct ip_vs_app *app);
13451da177e4SLinus Torvalds extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
13461da177e4SLinus Torvalds extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
1347ab8a5e84SHans Schillstrom extern int register_ip_vs_app_inc(struct net *net, struct ip_vs_app *app,
1348ab8a5e84SHans Schillstrom 				  __u16 proto, __u16 port);
13491da177e4SLinus Torvalds extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
13501da177e4SLinus Torvalds extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
13511da177e4SLinus Torvalds 
13523db05feaSHerbert Xu extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
13533db05feaSHerbert Xu extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
13541da177e4SLinus Torvalds 
13558be67a66SSimon Horman int register_ip_vs_pe(struct ip_vs_pe *pe);
13568be67a66SSimon Horman int unregister_ip_vs_pe(struct ip_vs_pe *pe);
1357e9e5eee8SSimon Horman struct ip_vs_pe *ip_vs_pe_getbyname(const char *name);
1358fe5e7a1eSHans Schillstrom struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name);
1359e9e5eee8SSimon Horman 
136069e7dae4SPaul Gortmaker /*
136169e7dae4SPaul Gortmaker  * Use a #define to avoid all of module.h just for these trivial ops
136269e7dae4SPaul Gortmaker  */
136369e7dae4SPaul Gortmaker #define ip_vs_pe_get(pe)			\
136469e7dae4SPaul Gortmaker 	if (pe && pe->module)			\
1365e9e5eee8SSimon Horman 		__module_get(pe->module);
1366e9e5eee8SSimon Horman 
136769e7dae4SPaul Gortmaker #define ip_vs_pe_put(pe)			\
136869e7dae4SPaul Gortmaker 	if (pe && pe->module)			\
1369e9e5eee8SSimon Horman 		module_put(pe->module);
13701da177e4SLinus Torvalds 
13711da177e4SLinus Torvalds /*
13721da177e4SLinus Torvalds  *	IPVS protocol functions (from ip_vs_proto.c)
13731da177e4SLinus Torvalds  */
13741da177e4SLinus Torvalds extern int ip_vs_protocol_init(void);
13751da177e4SLinus Torvalds extern void ip_vs_protocol_cleanup(void);
13769330419dSHans Schillstrom extern void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags);
13771da177e4SLinus Torvalds extern int *ip_vs_create_timeout_table(int *table, int size);
13781da177e4SLinus Torvalds extern int
137936cbd3dcSJan Engelhardt ip_vs_set_state_timeout(int *table, int num, const char *const *names,
138036cbd3dcSJan Engelhardt 			const char *name, int to);
13811da177e4SLinus Torvalds extern void
13820d79641aSJulian Anastasov ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,
13830d79641aSJulian Anastasov 			  const struct sk_buff *skb,
13841da177e4SLinus Torvalds 			  int offset, const char *msg);
13851da177e4SLinus Torvalds 
13861da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_tcp;
13871da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_udp;
13881da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_icmp;
13891da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_esp;
13901da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_ah;
13912906f66aSVenkata Mohan Reddy extern struct ip_vs_protocol ip_vs_protocol_sctp;
13921da177e4SLinus Torvalds 
13931da177e4SLinus Torvalds /*
13941da177e4SLinus Torvalds  *      Registering/unregistering scheduler functions
13951da177e4SLinus Torvalds  *      (from ip_vs_sched.c)
13961da177e4SLinus Torvalds  */
13971da177e4SLinus Torvalds extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
13981da177e4SLinus Torvalds extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
13991da177e4SLinus Torvalds extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
14001da177e4SLinus Torvalds 				struct ip_vs_scheduler *scheduler);
1401ceec4c38SJulian Anastasov extern void ip_vs_unbind_scheduler(struct ip_vs_service *svc,
1402ceec4c38SJulian Anastasov 				   struct ip_vs_scheduler *sched);
14031da177e4SLinus Torvalds extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
14041da177e4SLinus Torvalds extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
14051da177e4SLinus Torvalds extern struct ip_vs_conn *
1406190ecd27SJulian Anastasov ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
1407d4383f04SJesper Dangaard Brouer 	       struct ip_vs_proto_data *pd, int *ignored,
1408d4383f04SJesper Dangaard Brouer 	       struct ip_vs_iphdr *iph);
14091da177e4SLinus Torvalds extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
1410d4383f04SJesper Dangaard Brouer 			struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph);
14111da177e4SLinus Torvalds 
141241ac51eeSPatrick Schaaf extern void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg);
141341ac51eeSPatrick Schaaf 
14141da177e4SLinus Torvalds 
14151da177e4SLinus Torvalds /*
14161da177e4SLinus Torvalds  *      IPVS control data and functions (from ip_vs_ctl.c)
14171da177e4SLinus Torvalds  */
14181da177e4SLinus Torvalds extern struct ip_vs_stats ip_vs_stats;
1419b880c1f0SHans Schillstrom extern int sysctl_ip_vs_sync_ver;
14201da177e4SLinus Torvalds 
14211da177e4SLinus Torvalds extern struct ip_vs_service *
1422ceec4c38SJulian Anastasov ip_vs_service_find(struct net *net, int af, __u32 fwmark, __u16 protocol,
14233c2e0505SJulius Volz 		  const union nf_inet_addr *vaddr, __be16 vport);
14241da177e4SLinus Torvalds 
1425276472eaSJulian Anastasov extern bool
1426276472eaSJulian Anastasov ip_vs_has_real_service(struct net *net, int af, __u16 protocol,
14277937df15SJulius Volz 		       const union nf_inet_addr *daddr, __be16 dport);
14287937df15SJulius Volz 
14291da177e4SLinus Torvalds extern int ip_vs_use_count_inc(void);
14301da177e4SLinus Torvalds extern void ip_vs_use_count_dec(void);
14318537de8aSHans Schillstrom extern int ip_vs_register_nl_ioctl(void);
14328537de8aSHans Schillstrom extern void ip_vs_unregister_nl_ioctl(void);
14331da177e4SLinus Torvalds extern int ip_vs_control_init(void);
14341da177e4SLinus Torvalds extern void ip_vs_control_cleanup(void);
14351e356f9cSRumen G. Bogdanovski extern struct ip_vs_dest *
1436fc723250SHans Schillstrom ip_vs_find_dest(struct net *net, int af, const union nf_inet_addr *daddr,
1437fc723250SHans Schillstrom 		__be16 dport, const union nf_inet_addr *vaddr, __be16 vport,
143852793dbeSJulian Anastasov 		__u16 protocol, __u32 fwmark, __u32 flags);
1439413c2d04SJulian Anastasov extern void ip_vs_try_bind_dest(struct ip_vs_conn *cp);
14401da177e4SLinus Torvalds 
1441fca9c20aSJulian Anastasov static inline void ip_vs_dest_hold(struct ip_vs_dest *dest)
1442fca9c20aSJulian Anastasov {
1443fca9c20aSJulian Anastasov 	atomic_inc(&dest->refcnt);
1444fca9c20aSJulian Anastasov }
1445fca9c20aSJulian Anastasov 
1446fca9c20aSJulian Anastasov static inline void ip_vs_dest_put(struct ip_vs_dest *dest)
1447fca9c20aSJulian Anastasov {
1448fca9c20aSJulian Anastasov 	smp_mb__before_atomic_dec();
1449fca9c20aSJulian Anastasov 	atomic_dec(&dest->refcnt);
1450fca9c20aSJulian Anastasov }
14511da177e4SLinus Torvalds 
14521da177e4SLinus Torvalds /*
14531da177e4SLinus Torvalds  *      IPVS sync daemon data and function prototypes
14541da177e4SLinus Torvalds  *      (from ip_vs_sync.c)
14551da177e4SLinus Torvalds  */
1456f131315fSHans Schillstrom extern int start_sync_thread(struct net *net, int state, char *mcast_ifn,
1457f131315fSHans Schillstrom 			     __u8 syncid);
1458f131315fSHans Schillstrom extern int stop_sync_thread(struct net *net, int state);
1459749c42b6SJulian Anastasov extern void ip_vs_sync_conn(struct net *net, struct ip_vs_conn *cp, int pkts);
14601da177e4SLinus Torvalds 
14611da177e4SLinus Torvalds 
14621da177e4SLinus Torvalds /*
14631da177e4SLinus Torvalds  *      IPVS rate estimator prototypes (from ip_vs_est.c)
14641da177e4SLinus Torvalds  */
14656ef757f9SJulian Anastasov extern void ip_vs_start_estimator(struct net *net, struct ip_vs_stats *stats);
14666ef757f9SJulian Anastasov extern void ip_vs_stop_estimator(struct net *net, struct ip_vs_stats *stats);
14671da177e4SLinus Torvalds extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
1468ea9f22ccSJulian Anastasov extern void ip_vs_read_estimator(struct ip_vs_stats_user *dst,
1469ea9f22ccSJulian Anastasov 				 struct ip_vs_stats *stats);
14701da177e4SLinus Torvalds 
14711da177e4SLinus Torvalds /*
14721da177e4SLinus Torvalds  *	Various IPVS packet transmitters (from ip_vs_xmit.c)
14731da177e4SLinus Torvalds  */
1474d4383f04SJesper Dangaard Brouer extern int ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1475d4383f04SJesper Dangaard Brouer 			   struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
1476d4383f04SJesper Dangaard Brouer extern int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1477d4383f04SJesper Dangaard Brouer 			     struct ip_vs_protocol *pp,
1478d4383f04SJesper Dangaard Brouer 			     struct ip_vs_iphdr *iph);
1479d4383f04SJesper Dangaard Brouer extern int ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1480d4383f04SJesper Dangaard Brouer 			  struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
1481d4383f04SJesper Dangaard Brouer extern int ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1482d4383f04SJesper Dangaard Brouer 			     struct ip_vs_protocol *pp,
1483d4383f04SJesper Dangaard Brouer 			     struct ip_vs_iphdr *iph);
1484d4383f04SJesper Dangaard Brouer extern int ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1485d4383f04SJesper Dangaard Brouer 			 struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
1486d4383f04SJesper Dangaard Brouer extern int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1487d4383f04SJesper Dangaard Brouer 			   struct ip_vs_protocol *pp, int offset,
1488d4383f04SJesper Dangaard Brouer 			   unsigned int hooknum, struct ip_vs_iphdr *iph);
1489026ace06SJulian Anastasov extern void ip_vs_dest_dst_rcu_free(struct rcu_head *head);
14901da177e4SLinus Torvalds 
1491b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6
1492d4383f04SJesper Dangaard Brouer extern int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1493d4383f04SJesper Dangaard Brouer 				struct ip_vs_protocol *pp,
1494d4383f04SJesper Dangaard Brouer 				struct ip_vs_iphdr *iph);
1495d4383f04SJesper Dangaard Brouer extern int ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1496d4383f04SJesper Dangaard Brouer 			     struct ip_vs_protocol *pp,
1497d4383f04SJesper Dangaard Brouer 			     struct ip_vs_iphdr *iph);
1498d4383f04SJesper Dangaard Brouer extern int ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1499d4383f04SJesper Dangaard Brouer 				struct ip_vs_protocol *pp,
1500d4383f04SJesper Dangaard Brouer 				struct ip_vs_iphdr *iph);
1501d4383f04SJesper Dangaard Brouer extern int ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1502d4383f04SJesper Dangaard Brouer 			    struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
1503d4383f04SJesper Dangaard Brouer extern int ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1504d4383f04SJesper Dangaard Brouer 			      struct ip_vs_protocol *pp, int offset,
1505d4383f04SJesper Dangaard Brouer 			      unsigned int hooknum, struct ip_vs_iphdr *iph);
1506b3cdd2a7SJulius Volz #endif
15071da177e4SLinus Torvalds 
15083a1bbf18SSimon Horman #ifdef CONFIG_SYSCTL
15091da177e4SLinus Torvalds /*
15101da177e4SLinus Torvalds  *	This is a simple mechanism to ignore packets when
15111da177e4SLinus Torvalds  *	we are loaded. Just set ip_vs_drop_rate to 'n' and
15121da177e4SLinus Torvalds  *	we start to drop 1/rate of the packets
15131da177e4SLinus Torvalds  */
15141da177e4SLinus Torvalds 
1515a0840e2eSHans Schillstrom static inline int ip_vs_todrop(struct netns_ipvs *ipvs)
15161da177e4SLinus Torvalds {
1517a0840e2eSHans Schillstrom 	if (!ipvs->drop_rate)
1518a0840e2eSHans Schillstrom 		return 0;
1519a0840e2eSHans Schillstrom 	if (--ipvs->drop_counter > 0)
1520a0840e2eSHans Schillstrom 		return 0;
1521a0840e2eSHans Schillstrom 	ipvs->drop_counter = ipvs->drop_rate;
15221da177e4SLinus Torvalds 	return 1;
15231da177e4SLinus Torvalds }
15243a1bbf18SSimon Horman #else
15253a1bbf18SSimon Horman static inline int ip_vs_todrop(struct netns_ipvs *ipvs) { return 0; }
15263a1bbf18SSimon Horman #endif
15271da177e4SLinus Torvalds 
15281da177e4SLinus Torvalds /*
15291da177e4SLinus Torvalds  *      ip_vs_fwd_tag returns the forwarding tag of the connection
15301da177e4SLinus Torvalds  */
15311da177e4SLinus Torvalds #define IP_VS_FWD_METHOD(cp)  (cp->flags & IP_VS_CONN_F_FWD_MASK)
15321da177e4SLinus Torvalds 
1533732db659SAdrian Bunk static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
15341da177e4SLinus Torvalds {
15351da177e4SLinus Torvalds 	char fwd;
15361da177e4SLinus Torvalds 
15371da177e4SLinus Torvalds 	switch (IP_VS_FWD_METHOD(cp)) {
15381da177e4SLinus Torvalds 	case IP_VS_CONN_F_MASQ:
15391da177e4SLinus Torvalds 		fwd = 'M'; break;
15401da177e4SLinus Torvalds 	case IP_VS_CONN_F_LOCALNODE:
15411da177e4SLinus Torvalds 		fwd = 'L'; break;
15421da177e4SLinus Torvalds 	case IP_VS_CONN_F_TUNNEL:
15431da177e4SLinus Torvalds 		fwd = 'T'; break;
15441da177e4SLinus Torvalds 	case IP_VS_CONN_F_DROUTE:
15451da177e4SLinus Torvalds 		fwd = 'R'; break;
15461da177e4SLinus Torvalds 	case IP_VS_CONN_F_BYPASS:
15471da177e4SLinus Torvalds 		fwd = 'B'; break;
15481da177e4SLinus Torvalds 	default:
15491da177e4SLinus Torvalds 		fwd = '?'; break;
15501da177e4SLinus Torvalds 	}
15511da177e4SLinus Torvalds 	return fwd;
15521da177e4SLinus Torvalds }
15531da177e4SLinus Torvalds 
15541da177e4SLinus Torvalds extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
15551da177e4SLinus Torvalds 			   struct ip_vs_conn *cp, int dir);
15561da177e4SLinus Torvalds 
1557b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6
1558b3cdd2a7SJulius Volz extern void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
1559b3cdd2a7SJulius Volz 			      struct ip_vs_conn *cp, int dir);
1560b3cdd2a7SJulius Volz #endif
1561b3cdd2a7SJulius Volz 
1562b1550f22SAl Viro extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
15631da177e4SLinus Torvalds 
1564f9214b26SAl Viro static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
15651da177e4SLinus Torvalds {
1566f9214b26SAl Viro 	__be32 diff[2] = { ~old, new };
15671da177e4SLinus Torvalds 
156807f0757aSJoe Perches 	return csum_partial(diff, sizeof(diff), oldsum);
1569f9214b26SAl Viro }
1570f9214b26SAl Viro 
15710bbdd42bSJulius Volz #ifdef CONFIG_IP_VS_IPV6
15720bbdd42bSJulius Volz static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new,
15730bbdd42bSJulius Volz 					__wsum oldsum)
15740bbdd42bSJulius Volz {
15750bbdd42bSJulius Volz 	__be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
15760bbdd42bSJulius Volz 			    new[3],  new[2],  new[1],  new[0] };
15770bbdd42bSJulius Volz 
157807f0757aSJoe Perches 	return csum_partial(diff, sizeof(diff), oldsum);
15790bbdd42bSJulius Volz }
15800bbdd42bSJulius Volz #endif
15810bbdd42bSJulius Volz 
1582f9214b26SAl Viro static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
1583f9214b26SAl Viro {
1584f9214b26SAl Viro 	__be16 diff[2] = { ~old, new };
1585f9214b26SAl Viro 
158607f0757aSJoe Perches 	return csum_partial(diff, sizeof(diff), oldsum);
15871da177e4SLinus Torvalds }
15881da177e4SLinus Torvalds 
1589cf356d69SJulian Anastasov /*
1590cf356d69SJulian Anastasov  * Forget current conntrack (unconfirmed) and attach notrack entry
1591cf356d69SJulian Anastasov  */
1592cf356d69SJulian Anastasov static inline void ip_vs_notrack(struct sk_buff *skb)
1593cf356d69SJulian Anastasov {
1594cf356d69SJulian Anastasov #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1595cf356d69SJulian Anastasov 	enum ip_conntrack_info ctinfo;
159606b69390SJesper Juhl 	struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1597cf356d69SJulian Anastasov 
1598cf356d69SJulian Anastasov 	if (!ct || !nf_ct_is_untracked(ct)) {
15999e33ce45SLin Ming 		nf_conntrack_put(skb->nfct);
1600cf356d69SJulian Anastasov 		skb->nfct = &nf_ct_untracked_get()->ct_general;
1601cf356d69SJulian Anastasov 		skb->nfctinfo = IP_CT_NEW;
1602cf356d69SJulian Anastasov 		nf_conntrack_get(skb->nfct);
1603cf356d69SJulian Anastasov 	}
1604cf356d69SJulian Anastasov #endif
1605cf356d69SJulian Anastasov }
1606cf356d69SJulian Anastasov 
1607f4bc17cdSJulian Anastasov #ifdef CONFIG_IP_VS_NFCT
1608f4bc17cdSJulian Anastasov /*
1609f4bc17cdSJulian Anastasov  *      Netfilter connection tracking
1610f4bc17cdSJulian Anastasov  *      (from ip_vs_nfct.c)
1611f4bc17cdSJulian Anastasov  */
1612a0840e2eSHans Schillstrom static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
1613f4bc17cdSJulian Anastasov {
1614a4e2f5a7SSimon Horman #ifdef CONFIG_SYSCTL
1615a0840e2eSHans Schillstrom 	return ipvs->sysctl_conntrack;
1616a4e2f5a7SSimon Horman #else
1617a4e2f5a7SSimon Horman 	return 0;
1618a4e2f5a7SSimon Horman #endif
1619f4bc17cdSJulian Anastasov }
1620f4bc17cdSJulian Anastasov 
16216523ce15SJulian Anastasov extern void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
16226523ce15SJulian Anastasov 				   int outin);
16233c2de2aeSSimon Horman extern int ip_vs_confirm_conntrack(struct sk_buff *skb);
1624f4bc17cdSJulian Anastasov extern void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct,
1625f4bc17cdSJulian Anastasov 				      struct ip_vs_conn *cp, u_int8_t proto,
1626f4bc17cdSJulian Anastasov 				      const __be16 port, int from_rs);
1627f4bc17cdSJulian Anastasov extern void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp);
1628f4bc17cdSJulian Anastasov 
1629f4bc17cdSJulian Anastasov #else
1630f4bc17cdSJulian Anastasov 
1631a0840e2eSHans Schillstrom static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
1632f4bc17cdSJulian Anastasov {
1633f4bc17cdSJulian Anastasov 	return 0;
1634f4bc17cdSJulian Anastasov }
1635f4bc17cdSJulian Anastasov 
1636f4bc17cdSJulian Anastasov static inline void ip_vs_update_conntrack(struct sk_buff *skb,
1637f4bc17cdSJulian Anastasov 					  struct ip_vs_conn *cp, int outin)
1638f4bc17cdSJulian Anastasov {
1639f4bc17cdSJulian Anastasov }
1640f4bc17cdSJulian Anastasov 
1641e23ebf0fSKrzysztof Wilczynski static inline int ip_vs_confirm_conntrack(struct sk_buff *skb)
1642f4bc17cdSJulian Anastasov {
1643f4bc17cdSJulian Anastasov 	return NF_ACCEPT;
1644f4bc17cdSJulian Anastasov }
1645f4bc17cdSJulian Anastasov 
1646f4bc17cdSJulian Anastasov static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
1647f4bc17cdSJulian Anastasov {
1648f4bc17cdSJulian Anastasov }
1649f4bc17cdSJulian Anastasov /* CONFIG_IP_VS_NFCT */
1650f4bc17cdSJulian Anastasov #endif
16516523ce15SJulian Anastasov 
1652b552f7e3SChangli Gao static inline unsigned int
1653b552f7e3SChangli Gao ip_vs_dest_conn_overhead(struct ip_vs_dest *dest)
1654b552f7e3SChangli Gao {
1655b552f7e3SChangli Gao 	/*
1656b552f7e3SChangli Gao 	 * We think the overhead of processing active connections is 256
1657b552f7e3SChangli Gao 	 * times higher than that of inactive connections in average. (This
1658b552f7e3SChangli Gao 	 * 256 times might not be accurate, we will change it later) We
1659b552f7e3SChangli Gao 	 * use the following formula to estimate the overhead now:
1660b552f7e3SChangli Gao 	 *		  dest->activeconns*256 + dest->inactconns
1661b552f7e3SChangli Gao 	 */
1662b552f7e3SChangli Gao 	return (atomic_read(&dest->activeconns) << 8) +
1663b552f7e3SChangli Gao 		atomic_read(&dest->inactconns);
1664b552f7e3SChangli Gao }
1665b552f7e3SChangli Gao 
1666bc4768ebSJulius Volz #endif	/* _NET_IP_VS_H */
1667