1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
207dcc686SSimon Horman /* IP Virtual Server
31da177e4SLinus Torvalds * data structure and functionality definitions
41da177e4SLinus Torvalds */
51da177e4SLinus Torvalds
6bc4768ebSJulius Volz #ifndef _NET_IP_VS_H
7bc4768ebSJulius Volz #define _NET_IP_VS_H
81da177e4SLinus Torvalds
9bc4768ebSJulius Volz #include <linux/ip_vs.h> /* definitions shared with userland */
101da177e4SLinus Torvalds
11bc4768ebSJulius Volz #include <asm/types.h> /* for __uXX types */
12bc4768ebSJulius Volz
131da177e4SLinus Torvalds #include <linux/list.h> /* for struct list_head */
141da177e4SLinus Torvalds #include <linux/spinlock.h> /* for struct rwlock_t */
1560063497SArun Sharma #include <linux/atomic.h> /* for struct atomic_t */
16b54ab92bSReshetova, Elena #include <linux/refcount.h> /* for struct refcount_t */
1735dfb013SAndrew Sy Kim #include <linux/workqueue.h>
18b54ab92bSReshetova, Elena
191da177e4SLinus Torvalds #include <linux/compiler.h>
2014c85021SArnaldo Carvalho de Melo #include <linux/timer.h>
21187f1882SPaul Gortmaker #include <linux/bug.h>
221da177e4SLinus Torvalds
2314c85021SArnaldo Carvalho de Melo #include <net/checksum.h>
24e7ade46aSJulius Volz #include <linux/netfilter.h> /* for union nf_inet_addr */
251668e010SKOVACS Krisztian #include <linux/ip.h>
26e7ade46aSJulius Volz #include <linux/ipv6.h> /* for struct ipv6hdr */
274e3fd7a0SAlexey Dobriyan #include <net/ipv6.h>
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 */
32f0be83d5SJulian Anastasov #include <linux/sched/isolation.h>
3361b1ab45SHans Schillstrom
344fd9beefSAlex Gartrell #define IP_VS_HDR_INVERSE 1
354fd9beefSAlex Gartrell #define IP_VS_HDR_ICMP 2
364fd9beefSAlex Gartrell
3707dcc686SSimon Horman /* Generic access of ipvs struct */
net_ipvs(struct net * net)3861b1ab45SHans Schillstrom static inline struct netns_ipvs *net_ipvs(struct net* net)
3961b1ab45SHans Schillstrom {
4061b1ab45SHans Schillstrom return net->ipvs;
4161b1ab45SHans Schillstrom }
4207dcc686SSimon Horman
436f7edb48SCatalin(ux) M. BOIE /* Connections' size value needed by ip_vs_ctl.c */
446f7edb48SCatalin(ux) M. BOIE extern int ip_vs_conn_tab_size;
456f7edb48SCatalin(ux) M. BOIE
46705dd344SJulian Anastasov extern struct mutex __ip_vs_mutex;
47705dd344SJulian Anastasov
4864aae3cbSJulius Volz struct ip_vs_iphdr {
494fd9beefSAlex Gartrell int hdr_flags; /* ipvs flags */
50b0e010c5SAlex Gartrell __u32 off; /* Where IP or IPv4 header starts */
5163dca2c0SJesper Dangaard Brouer __u32 len; /* IPv4 simply where L4 starts
5207dcc686SSimon Horman * IPv6 where L4 Transport Header starts */
5363dca2c0SJesper Dangaard Brouer __u16 fragoffs; /* IPv6 fragment offset, 0 if first frag (or not frag)*/
5463dca2c0SJesper Dangaard Brouer __s16 protocol;
5563dca2c0SJesper Dangaard Brouer __s32 flags;
5664aae3cbSJulius Volz union nf_inet_addr saddr;
5764aae3cbSJulius Volz union nf_inet_addr daddr;
5864aae3cbSJulius Volz };
5964aae3cbSJulius Volz
frag_safe_skb_hp(const struct sk_buff * skb,int offset,int len,void * buffer)602f74713dSJesper Dangaard Brouer static inline void *frag_safe_skb_hp(const struct sk_buff *skb, int offset,
616b3d9330SGao Feng int len, void *buffer)
622f74713dSJesper Dangaard Brouer {
632f74713dSJesper Dangaard Brouer return skb_header_pointer(skb, offset, len, buffer);
642f74713dSJesper Dangaard Brouer }
652f74713dSJesper Dangaard Brouer
6663dca2c0SJesper Dangaard Brouer /* This function handles filling *ip_vs_iphdr, both for IPv4 and IPv6.
6763dca2c0SJesper Dangaard Brouer * IPv6 requires some extra work, as finding proper header position,
6863dca2c0SJesper Dangaard Brouer * depend on the IPv6 extension headers.
6963dca2c0SJesper Dangaard Brouer */
70b0e010c5SAlex Gartrell static inline int
ip_vs_fill_iph_skb_off(int af,const struct sk_buff * skb,int offset,int hdr_flags,struct ip_vs_iphdr * iphdr)71b0e010c5SAlex Gartrell ip_vs_fill_iph_skb_off(int af, const struct sk_buff *skb, int offset,
724fd9beefSAlex Gartrell int hdr_flags, struct ip_vs_iphdr *iphdr)
7364aae3cbSJulius Volz {
744fd9beefSAlex Gartrell iphdr->hdr_flags = hdr_flags;
75b0e010c5SAlex Gartrell iphdr->off = offset;
764fd9beefSAlex Gartrell
7764aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6
7864aae3cbSJulius Volz if (af == AF_INET6) {
79b0e010c5SAlex Gartrell struct ipv6hdr _iph;
80b0e010c5SAlex Gartrell const struct ipv6hdr *iph = skb_header_pointer(
81b0e010c5SAlex Gartrell skb, offset, sizeof(_iph), &_iph);
82b0e010c5SAlex Gartrell if (!iph)
83b0e010c5SAlex Gartrell return 0;
84b0e010c5SAlex Gartrell
854e3fd7a0SAlexey Dobriyan iphdr->saddr.in6 = iph->saddr;
864e3fd7a0SAlexey Dobriyan iphdr->daddr.in6 = iph->daddr;
876aafeef0SJiri Pirko /* ipv6_find_hdr() updates len, flags */
88b0e010c5SAlex Gartrell iphdr->len = offset;
8963dca2c0SJesper Dangaard Brouer iphdr->flags = 0;
9063dca2c0SJesper Dangaard Brouer iphdr->protocol = ipv6_find_hdr(skb, &iphdr->len, -1,
9163dca2c0SJesper Dangaard Brouer &iphdr->fragoffs,
9263dca2c0SJesper Dangaard Brouer &iphdr->flags);
93b0e010c5SAlex Gartrell if (iphdr->protocol < 0)
94b0e010c5SAlex Gartrell return 0;
9564aae3cbSJulius Volz } else
9664aae3cbSJulius Volz #endif
9764aae3cbSJulius Volz {
98b0e010c5SAlex Gartrell struct iphdr _iph;
99b0e010c5SAlex Gartrell const struct iphdr *iph = skb_header_pointer(
100b0e010c5SAlex Gartrell skb, offset, sizeof(_iph), &_iph);
101b0e010c5SAlex Gartrell if (!iph)
102b0e010c5SAlex Gartrell return 0;
103b0e010c5SAlex Gartrell
104b0e010c5SAlex Gartrell iphdr->len = offset + iph->ihl * 4;
10563dca2c0SJesper Dangaard Brouer iphdr->fragoffs = 0;
10664aae3cbSJulius Volz iphdr->protocol = iph->protocol;
10764aae3cbSJulius Volz iphdr->saddr.ip = iph->saddr;
10864aae3cbSJulius Volz iphdr->daddr.ip = iph->daddr;
10964aae3cbSJulius Volz }
110b0e010c5SAlex Gartrell
111b0e010c5SAlex Gartrell return 1;
112b0e010c5SAlex Gartrell }
113b0e010c5SAlex Gartrell
114b0e010c5SAlex Gartrell static inline int
ip_vs_fill_iph_skb_icmp(int af,const struct sk_buff * skb,int offset,bool inverse,struct ip_vs_iphdr * iphdr)1154fd9beefSAlex Gartrell ip_vs_fill_iph_skb_icmp(int af, const struct sk_buff *skb, int offset,
1164fd9beefSAlex Gartrell bool inverse, struct ip_vs_iphdr *iphdr)
117b0e010c5SAlex Gartrell {
1184fd9beefSAlex Gartrell int hdr_flags = IP_VS_HDR_ICMP;
1194fd9beefSAlex Gartrell
1204fd9beefSAlex Gartrell if (inverse)
1214fd9beefSAlex Gartrell hdr_flags |= IP_VS_HDR_INVERSE;
1224fd9beefSAlex Gartrell
1234fd9beefSAlex Gartrell return ip_vs_fill_iph_skb_off(af, skb, offset, hdr_flags, iphdr);
1244fd9beefSAlex Gartrell }
1254fd9beefSAlex Gartrell
1264fd9beefSAlex Gartrell static inline int
ip_vs_fill_iph_skb(int af,const struct sk_buff * skb,bool inverse,struct ip_vs_iphdr * iphdr)1274fd9beefSAlex Gartrell ip_vs_fill_iph_skb(int af, const struct sk_buff *skb, bool inverse,
1284fd9beefSAlex Gartrell struct ip_vs_iphdr *iphdr)
1294fd9beefSAlex Gartrell {
1304fd9beefSAlex Gartrell int hdr_flags = 0;
1314fd9beefSAlex Gartrell
1324fd9beefSAlex Gartrell if (inverse)
1334fd9beefSAlex Gartrell hdr_flags |= IP_VS_HDR_INVERSE;
1344fd9beefSAlex Gartrell
1354fd9beefSAlex Gartrell return ip_vs_fill_iph_skb_off(af, skb, skb_network_offset(skb),
1364fd9beefSAlex Gartrell hdr_flags, iphdr);
1374fd9beefSAlex Gartrell }
1384fd9beefSAlex Gartrell
1394fd9beefSAlex Gartrell static inline bool
ip_vs_iph_inverse(const struct ip_vs_iphdr * iph)1404fd9beefSAlex Gartrell ip_vs_iph_inverse(const struct ip_vs_iphdr *iph)
1414fd9beefSAlex Gartrell {
1424fd9beefSAlex Gartrell return !!(iph->hdr_flags & IP_VS_HDR_INVERSE);
1434fd9beefSAlex Gartrell }
1444fd9beefSAlex Gartrell
1454fd9beefSAlex Gartrell static inline bool
ip_vs_iph_icmp(const struct ip_vs_iphdr * iph)1464fd9beefSAlex Gartrell ip_vs_iph_icmp(const struct ip_vs_iphdr *iph)
1474fd9beefSAlex Gartrell {
1484fd9beefSAlex Gartrell return !!(iph->hdr_flags & IP_VS_HDR_ICMP);
14964aae3cbSJulius Volz }
15064aae3cbSJulius Volz
ip_vs_addr_copy(int af,union nf_inet_addr * dst,const union nf_inet_addr * src)15164aae3cbSJulius Volz static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
15264aae3cbSJulius Volz const union nf_inet_addr *src)
15364aae3cbSJulius Volz {
15464aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6
15564aae3cbSJulius Volz if (af == AF_INET6)
1564e3fd7a0SAlexey Dobriyan dst->in6 = src->in6;
15764aae3cbSJulius Volz else
15864aae3cbSJulius Volz #endif
15964aae3cbSJulius Volz dst->ip = src->ip;
16064aae3cbSJulius Volz }
16164aae3cbSJulius Volz
ip_vs_addr_set(int af,union nf_inet_addr * dst,const union nf_inet_addr * src)1629a05475cSJulian Anastasov static inline void ip_vs_addr_set(int af, union nf_inet_addr *dst,
1639a05475cSJulian Anastasov const union nf_inet_addr *src)
1649a05475cSJulian Anastasov {
1659a05475cSJulian Anastasov #ifdef CONFIG_IP_VS_IPV6
1669a05475cSJulian Anastasov if (af == AF_INET6) {
1679a05475cSJulian Anastasov dst->in6 = src->in6;
1689a05475cSJulian Anastasov return;
1699a05475cSJulian Anastasov }
1709a05475cSJulian Anastasov #endif
1719a05475cSJulian Anastasov dst->ip = src->ip;
1729a05475cSJulian Anastasov dst->all[1] = 0;
1739a05475cSJulian Anastasov dst->all[2] = 0;
1749a05475cSJulian Anastasov dst->all[3] = 0;
1759a05475cSJulian Anastasov }
1769a05475cSJulian Anastasov
ip_vs_addr_equal(int af,const union nf_inet_addr * a,const union nf_inet_addr * b)17764aae3cbSJulius Volz static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
17864aae3cbSJulius Volz const union nf_inet_addr *b)
17964aae3cbSJulius Volz {
18064aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6
18164aae3cbSJulius Volz if (af == AF_INET6)
18264aae3cbSJulius Volz return ipv6_addr_equal(&a->in6, &b->in6);
18364aae3cbSJulius Volz #endif
18464aae3cbSJulius Volz return a->ip == b->ip;
18564aae3cbSJulius Volz }
18664aae3cbSJulius Volz
1871da177e4SLinus Torvalds #ifdef CONFIG_IP_VS_DEBUG
18814c85021SArnaldo Carvalho de Melo #include <linux/net.h>
18914c85021SArnaldo Carvalho de Melo
1905c3a0fd7SJoe Perches int ip_vs_get_debug_level(void);
191c842a3adSJulius Volz
ip_vs_dbg_addr(int af,char * buf,size_t buf_len,const union nf_inet_addr * addr,int * idx)192c842a3adSJulius Volz static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
193c842a3adSJulius Volz const union nf_inet_addr *addr,
194c842a3adSJulius Volz int *idx)
195c842a3adSJulius Volz {
196c842a3adSJulius Volz int len;
197c842a3adSJulius Volz #ifdef CONFIG_IP_VS_IPV6
198c842a3adSJulius Volz if (af == AF_INET6)
199120b9c14SJesper Dangaard Brouer len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6c]",
2000c6ce78aSHarvey Harrison &addr->in6) + 1;
201c842a3adSJulius Volz else
202c842a3adSJulius Volz #endif
2033685f25dSHarvey Harrison len = snprintf(&buf[*idx], buf_len - *idx, "%pI4",
2043685f25dSHarvey Harrison &addr->ip) + 1;
205c842a3adSJulius Volz
206c842a3adSJulius Volz *idx += len;
207c842a3adSJulius Volz BUG_ON(*idx > buf_len + 1);
208c842a3adSJulius Volz return &buf[*idx - len];
209c842a3adSJulius Volz }
210c842a3adSJulius Volz
2119aada7acSHannes Eder #define IP_VS_DBG_BUF(level, msg, ...) \
212c842a3adSJulius Volz do { \
213c842a3adSJulius Volz char ip_vs_dbg_buf[160]; \
214c842a3adSJulius Volz int ip_vs_dbg_idx = 0; \
215c842a3adSJulius Volz if (level <= ip_vs_get_debug_level()) \
2169aada7acSHannes Eder printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
217c842a3adSJulius Volz } while (0)
218c842a3adSJulius Volz #define IP_VS_ERR_BUF(msg...) \
219c842a3adSJulius Volz do { \
220c842a3adSJulius Volz char ip_vs_dbg_buf[160]; \
221c842a3adSJulius Volz int ip_vs_dbg_idx = 0; \
2229aada7acSHannes Eder pr_err(msg); \
223c842a3adSJulius Volz } while (0)
224c842a3adSJulius Volz
225c842a3adSJulius Volz /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */
226c842a3adSJulius Volz #define IP_VS_DBG_ADDR(af, addr) \
227c842a3adSJulius Volz ip_vs_dbg_addr(af, ip_vs_dbg_buf, \
228c842a3adSJulius Volz sizeof(ip_vs_dbg_buf), addr, \
229c842a3adSJulius Volz &ip_vs_dbg_idx)
230c842a3adSJulius Volz
2319aada7acSHannes Eder #define IP_VS_DBG(level, msg, ...) \
2321da177e4SLinus Torvalds do { \
2331da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \
2349aada7acSHannes Eder printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
2351da177e4SLinus Torvalds } while (0)
2369aada7acSHannes Eder #define IP_VS_DBG_RL(msg, ...) \
2371da177e4SLinus Torvalds do { \
2381da177e4SLinus Torvalds if (net_ratelimit()) \
2399aada7acSHannes Eder printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
2401da177e4SLinus Torvalds } while (0)
2410d79641aSJulian Anastasov #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) \
2421da177e4SLinus Torvalds do { \
2431da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \
2440d79641aSJulian Anastasov pp->debug_packet(af, pp, skb, ofs, msg); \
2451da177e4SLinus Torvalds } while (0)
2460d79641aSJulian Anastasov #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) \
2471da177e4SLinus Torvalds do { \
2481da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level() && \
2491da177e4SLinus Torvalds net_ratelimit()) \
2500d79641aSJulian Anastasov pp->debug_packet(af, pp, skb, ofs, msg); \
2511da177e4SLinus Torvalds } while (0)
2521da177e4SLinus Torvalds #else /* NO DEBUGGING at ALL */
253c842a3adSJulius Volz #define IP_VS_DBG_BUF(level, msg...) do {} while (0)
254c842a3adSJulius Volz #define IP_VS_ERR_BUF(msg...) do {} while (0)
2551da177e4SLinus Torvalds #define IP_VS_DBG(level, msg...) do {} while (0)
2561da177e4SLinus Torvalds #define IP_VS_DBG_RL(msg...) do {} while (0)
2570d79641aSJulian Anastasov #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
2580d79641aSJulian Anastasov #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
2591da177e4SLinus Torvalds #endif
2601da177e4SLinus Torvalds
2611da177e4SLinus Torvalds #define IP_VS_BUG() BUG()
2621e3e238eSHannes Eder #define IP_VS_ERR_RL(msg, ...) \
2631da177e4SLinus Torvalds do { \
2641da177e4SLinus Torvalds if (net_ratelimit()) \
2651e3e238eSHannes Eder pr_err(msg, ##__VA_ARGS__); \
2661da177e4SLinus Torvalds } while (0)
2671da177e4SLinus Torvalds
26807dcc686SSimon Horman /* The port number of FTP service (in network order). */
269f3a7c66bSHarvey Harrison #define FTPPORT cpu_to_be16(21)
270f3a7c66bSHarvey Harrison #define FTPDATA cpu_to_be16(20)
2711da177e4SLinus Torvalds
27207dcc686SSimon Horman /* TCP State Values */
2731da177e4SLinus Torvalds enum {
2741da177e4SLinus Torvalds IP_VS_TCP_S_NONE = 0,
2751da177e4SLinus Torvalds IP_VS_TCP_S_ESTABLISHED,
2761da177e4SLinus Torvalds IP_VS_TCP_S_SYN_SENT,
2771da177e4SLinus Torvalds IP_VS_TCP_S_SYN_RECV,
2781da177e4SLinus Torvalds IP_VS_TCP_S_FIN_WAIT,
2791da177e4SLinus Torvalds IP_VS_TCP_S_TIME_WAIT,
2801da177e4SLinus Torvalds IP_VS_TCP_S_CLOSE,
2811da177e4SLinus Torvalds IP_VS_TCP_S_CLOSE_WAIT,
2821da177e4SLinus Torvalds IP_VS_TCP_S_LAST_ACK,
2831da177e4SLinus Torvalds IP_VS_TCP_S_LISTEN,
2841da177e4SLinus Torvalds IP_VS_TCP_S_SYNACK,
2851da177e4SLinus Torvalds IP_VS_TCP_S_LAST
2861da177e4SLinus Torvalds };
2871da177e4SLinus Torvalds
28807dcc686SSimon Horman /* UDP State Values */
2891da177e4SLinus Torvalds enum {
2901da177e4SLinus Torvalds IP_VS_UDP_S_NORMAL,
2911da177e4SLinus Torvalds IP_VS_UDP_S_LAST,
2921da177e4SLinus Torvalds };
2931da177e4SLinus Torvalds
29407dcc686SSimon Horman /* ICMP State Values */
2951da177e4SLinus Torvalds enum {
2961da177e4SLinus Torvalds IP_VS_ICMP_S_NORMAL,
2971da177e4SLinus Torvalds IP_VS_ICMP_S_LAST,
2981da177e4SLinus Torvalds };
2991da177e4SLinus Torvalds
30007dcc686SSimon Horman /* SCTP State Values */
3012906f66aSVenkata Mohan Reddy enum ip_vs_sctp_states {
3022906f66aSVenkata Mohan Reddy IP_VS_SCTP_S_NONE,
30361e7c420SJulian Anastasov IP_VS_SCTP_S_INIT1,
30461e7c420SJulian Anastasov IP_VS_SCTP_S_INIT,
30561e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE_SENT,
30661e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE_REPLIED,
30761e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE_WAIT,
30861e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE,
30961e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE_ECHOED,
3102906f66aSVenkata Mohan Reddy IP_VS_SCTP_S_ESTABLISHED,
31161e7c420SJulian Anastasov IP_VS_SCTP_S_SHUTDOWN_SENT,
31261e7c420SJulian Anastasov IP_VS_SCTP_S_SHUTDOWN_RECEIVED,
31361e7c420SJulian Anastasov IP_VS_SCTP_S_SHUTDOWN_ACK_SENT,
31461e7c420SJulian Anastasov IP_VS_SCTP_S_REJECTED,
3152906f66aSVenkata Mohan Reddy IP_VS_SCTP_S_CLOSED,
3162906f66aSVenkata Mohan Reddy IP_VS_SCTP_S_LAST
3172906f66aSVenkata Mohan Reddy };
3182906f66aSVenkata Mohan Reddy
31927541143SJulian Anastasov /* Connection templates use bits from state */
32027541143SJulian Anastasov #define IP_VS_CTPL_S_NONE 0x0000
32127541143SJulian Anastasov #define IP_VS_CTPL_S_ASSURED 0x0001
32227541143SJulian Anastasov #define IP_VS_CTPL_S_LAST 0x0002
32327541143SJulian Anastasov
32407dcc686SSimon Horman /* Delta sequence info structure
3251da177e4SLinus Torvalds * Each ip_vs_conn has 2 (output AND input seq. changes).
3261da177e4SLinus Torvalds * Only used in the VS/NAT.
3271da177e4SLinus Torvalds */
3281da177e4SLinus Torvalds struct ip_vs_seq {
3291da177e4SLinus Torvalds __u32 init_seq; /* Add delta from this seq */
3301da177e4SLinus Torvalds __u32 delta; /* Delta in sequence numbers */
3311da177e4SLinus Torvalds __u32 previous_delta; /* Delta in sequence numbers
33207dcc686SSimon Horman * before last resized pkt */
3331da177e4SLinus Torvalds };
3341da177e4SLinus Torvalds
33507dcc686SSimon Horman /* counters per cpu */
336b17fc996SHans Schillstrom struct ip_vs_counters {
3371dbd8d9aSJulian Anastasov u64_stats_t conns; /* connections scheduled */
3381dbd8d9aSJulian Anastasov u64_stats_t inpkts; /* incoming packets */
3391dbd8d9aSJulian Anastasov u64_stats_t outpkts; /* outgoing packets */
3401dbd8d9aSJulian Anastasov u64_stats_t inbytes; /* incoming bytes */
3411dbd8d9aSJulian Anastasov u64_stats_t outbytes; /* outgoing bytes */
342b17fc996SHans Schillstrom };
34307dcc686SSimon Horman /* Stats per cpu */
344b17fc996SHans Schillstrom struct ip_vs_cpu_stats {
345cd67cd5eSJulian Anastasov struct ip_vs_counters cnt;
346b17fc996SHans Schillstrom struct u64_stats_sync syncp;
347b17fc996SHans Schillstrom };
3481da177e4SLinus Torvalds
349f0be83d5SJulian Anastasov /* Default nice for estimator kthreads */
350f0be83d5SJulian Anastasov #define IPVS_EST_NICE 0
351f0be83d5SJulian Anastasov
35207dcc686SSimon Horman /* IPVS statistics objects */
3533a14a313SSven Wegener struct ip_vs_estimator {
354705dd344SJulian Anastasov struct hlist_node list;
3553a14a313SSven Wegener
3563a14a313SSven Wegener u64 last_inbytes;
3573a14a313SSven Wegener u64 last_outbytes;
358cd67cd5eSJulian Anastasov u64 last_conns;
359cd67cd5eSJulian Anastasov u64 last_inpkts;
360cd67cd5eSJulian Anastasov u64 last_outpkts;
3613a14a313SSven Wegener
362cd67cd5eSJulian Anastasov u64 cps;
363cd67cd5eSJulian Anastasov u64 inpps;
364cd67cd5eSJulian Anastasov u64 outpps;
365cd67cd5eSJulian Anastasov u64 inbps;
366cd67cd5eSJulian Anastasov u64 outbps;
367705dd344SJulian Anastasov
368705dd344SJulian Anastasov s32 ktid:16, /* kthread ID, -1=temp list */
369705dd344SJulian Anastasov ktrow:8, /* row/tick ID for kthread */
370705dd344SJulian Anastasov ktcid:8; /* chain ID for kthread tick */
371cd67cd5eSJulian Anastasov };
372cd67cd5eSJulian Anastasov
373cd67cd5eSJulian Anastasov /*
374cd67cd5eSJulian Anastasov * IPVS statistics object, 64-bit kernel version of struct ip_vs_stats_user
375cd67cd5eSJulian Anastasov */
376cd67cd5eSJulian Anastasov struct ip_vs_kstats {
377cd67cd5eSJulian Anastasov u64 conns; /* connections scheduled */
378cd67cd5eSJulian Anastasov u64 inpkts; /* incoming packets */
379cd67cd5eSJulian Anastasov u64 outpkts; /* outgoing packets */
380cd67cd5eSJulian Anastasov u64 inbytes; /* incoming bytes */
381cd67cd5eSJulian Anastasov u64 outbytes; /* outgoing bytes */
382cd67cd5eSJulian Anastasov
383cd67cd5eSJulian Anastasov u64 cps; /* current connection rate */
384cd67cd5eSJulian Anastasov u64 inpps; /* current in packet rate */
385cd67cd5eSJulian Anastasov u64 outpps; /* current out packet rate */
386cd67cd5eSJulian Anastasov u64 inbps; /* current in byte rate */
387cd67cd5eSJulian Anastasov u64 outbps; /* current out byte rate */
3883a14a313SSven Wegener };
3893a14a313SSven Wegener
390fd2c3ef7SEric Dumazet struct ip_vs_stats {
391cd67cd5eSJulian Anastasov struct ip_vs_kstats kstats; /* kernel statistics */
392e9c0ce23SSven Wegener struct ip_vs_estimator est; /* estimator */
393b962abdcSJulian Anastasov struct ip_vs_cpu_stats __percpu *cpustats; /* per cpu counters */
3941da177e4SLinus Torvalds spinlock_t lock; /* spin lock */
395cd67cd5eSJulian Anastasov struct ip_vs_kstats kstats0; /* reset values */
3961da177e4SLinus Torvalds };
3971da177e4SLinus Torvalds
3985df7d714SJulian Anastasov struct ip_vs_stats_rcu {
3995df7d714SJulian Anastasov struct ip_vs_stats s;
4005df7d714SJulian Anastasov struct rcu_head rcu_head;
4015df7d714SJulian Anastasov };
4025df7d714SJulian Anastasov
403de39afb3SJulian Anastasov int ip_vs_stats_init_alloc(struct ip_vs_stats *s);
404de39afb3SJulian Anastasov struct ip_vs_stats *ip_vs_stats_alloc(void);
405de39afb3SJulian Anastasov void ip_vs_stats_release(struct ip_vs_stats *stats);
406de39afb3SJulian Anastasov void ip_vs_stats_free(struct ip_vs_stats *stats);
407de39afb3SJulian Anastasov
408705dd344SJulian Anastasov /* Process estimators in multiple timer ticks (20/50/100, see ktrow) */
409705dd344SJulian Anastasov #define IPVS_EST_NTICKS 50
410705dd344SJulian Anastasov /* Estimation uses a 2-second period containing ticks (in jiffies) */
411705dd344SJulian Anastasov #define IPVS_EST_TICK ((2 * HZ) / IPVS_EST_NTICKS)
412705dd344SJulian Anastasov
413705dd344SJulian Anastasov /* Limit of CPU load per kthread (8 for 12.5%), ratio of CPU capacity (1/C).
414705dd344SJulian Anastasov * Value of 4 and above ensures kthreads will take work without exceeding
415705dd344SJulian Anastasov * the CPU capacity under different circumstances.
416705dd344SJulian Anastasov */
417705dd344SJulian Anastasov #define IPVS_EST_LOAD_DIVISOR 8
418705dd344SJulian Anastasov
419705dd344SJulian Anastasov /* Kthreads should not have work that exceeds the CPU load above 50% */
420705dd344SJulian Anastasov #define IPVS_EST_CPU_KTHREADS (IPVS_EST_LOAD_DIVISOR / 2)
421705dd344SJulian Anastasov
422705dd344SJulian Anastasov /* Desired number of chains per timer tick (chain load factor in 100us units),
423705dd344SJulian Anastasov * 48=4.8ms of 40ms tick (12% CPU usage):
424705dd344SJulian Anastasov * 2 sec * 1000 ms in sec * 10 (100us in ms) / 8 (12.5%) / 50
425705dd344SJulian Anastasov */
426705dd344SJulian Anastasov #define IPVS_EST_CHAIN_FACTOR \
427705dd344SJulian Anastasov ALIGN_DOWN(2 * 1000 * 10 / IPVS_EST_LOAD_DIVISOR / IPVS_EST_NTICKS, 8)
428705dd344SJulian Anastasov
429705dd344SJulian Anastasov /* Compiled number of chains per tick
430705dd344SJulian Anastasov * The defines should match cond_resched_rcu
431705dd344SJulian Anastasov */
432705dd344SJulian Anastasov #if defined(CONFIG_DEBUG_ATOMIC_SLEEP) || !defined(CONFIG_PREEMPT_RCU)
433705dd344SJulian Anastasov #define IPVS_EST_TICK_CHAINS IPVS_EST_CHAIN_FACTOR
434705dd344SJulian Anastasov #else
435705dd344SJulian Anastasov #define IPVS_EST_TICK_CHAINS 1
436705dd344SJulian Anastasov #endif
437705dd344SJulian Anastasov
438705dd344SJulian Anastasov #if IPVS_EST_NTICKS > 127
439705dd344SJulian Anastasov #error Too many timer ticks for ktrow
440705dd344SJulian Anastasov #endif
441705dd344SJulian Anastasov
442705dd344SJulian Anastasov /* Multiple chains processed in same tick */
443705dd344SJulian Anastasov struct ip_vs_est_tick_data {
444e4d0fe71SJulian Anastasov struct rcu_head rcu_head;
445705dd344SJulian Anastasov struct hlist_head chains[IPVS_EST_TICK_CHAINS];
446705dd344SJulian Anastasov DECLARE_BITMAP(present, IPVS_EST_TICK_CHAINS);
447705dd344SJulian Anastasov DECLARE_BITMAP(full, IPVS_EST_TICK_CHAINS);
448705dd344SJulian Anastasov int chain_len[IPVS_EST_TICK_CHAINS];
449705dd344SJulian Anastasov };
450705dd344SJulian Anastasov
451705dd344SJulian Anastasov /* Context for estimation kthread */
452705dd344SJulian Anastasov struct ip_vs_est_kt_data {
453705dd344SJulian Anastasov struct netns_ipvs *ipvs;
454705dd344SJulian Anastasov struct task_struct *task; /* task if running */
455705dd344SJulian Anastasov struct ip_vs_est_tick_data __rcu *ticks[IPVS_EST_NTICKS];
456705dd344SJulian Anastasov DECLARE_BITMAP(avail, IPVS_EST_NTICKS); /* tick has space for ests */
457705dd344SJulian Anastasov unsigned long est_timer; /* estimation timer (jiffies) */
458705dd344SJulian Anastasov struct ip_vs_stats *calc_stats; /* Used for calculation */
459705dd344SJulian Anastasov int tick_len[IPVS_EST_NTICKS]; /* est count */
460705dd344SJulian Anastasov int id; /* ktid per netns */
461705dd344SJulian Anastasov int chain_max; /* max ests per tick chain */
462705dd344SJulian Anastasov int tick_max; /* max ests per tick */
463705dd344SJulian Anastasov int est_count; /* attached ests to kthread */
464705dd344SJulian Anastasov int est_max_count; /* max ests per kthread */
465705dd344SJulian Anastasov int add_row; /* row for new ests */
466705dd344SJulian Anastasov int est_row; /* estimated row */
467705dd344SJulian Anastasov };
468705dd344SJulian Anastasov
46914c85021SArnaldo Carvalho de Melo struct dst_entry;
47014c85021SArnaldo Carvalho de Melo struct iphdr;
4711da177e4SLinus Torvalds struct ip_vs_conn;
4721da177e4SLinus Torvalds struct ip_vs_app;
47314c85021SArnaldo Carvalho de Melo struct sk_buff;
474252c6410SHans Schillstrom struct ip_vs_proto_data;
4751da177e4SLinus Torvalds
4761da177e4SLinus Torvalds struct ip_vs_protocol {
4771da177e4SLinus Torvalds struct ip_vs_protocol *next;
4781da177e4SLinus Torvalds char *name;
4792ad17defSJulian Anastasov u16 protocol;
4802ad17defSJulian Anastasov u16 num_states;
4811da177e4SLinus Torvalds int dont_defrag;
4821da177e4SLinus Torvalds
4831da177e4SLinus Torvalds void (*init)(struct ip_vs_protocol *pp);
4841da177e4SLinus Torvalds
4851da177e4SLinus Torvalds void (*exit)(struct ip_vs_protocol *pp);
4861da177e4SLinus Torvalds
4871281a9c2SEric W. Biederman int (*init_netns)(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd);
488252c6410SHans Schillstrom
4891281a9c2SEric W. Biederman void (*exit_netns)(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd);
490252c6410SHans Schillstrom
491d8f44c33SEric W. Biederman int (*conn_schedule)(struct netns_ipvs *ipvs,
492d8f44c33SEric W. Biederman int af, struct sk_buff *skb,
4939330419dSHans Schillstrom struct ip_vs_proto_data *pd,
494d4383f04SJesper Dangaard Brouer int *verdict, struct ip_vs_conn **cpp,
495d4383f04SJesper Dangaard Brouer struct ip_vs_iphdr *iph);
4961da177e4SLinus Torvalds
4971da177e4SLinus Torvalds struct ip_vs_conn *
498ab161976SEric W. Biederman (*conn_in_get)(struct netns_ipvs *ipvs,
499ab161976SEric W. Biederman int af,
50051ef348bSJulius Volz const struct sk_buff *skb,
501802c41adSAlex Gartrell const struct ip_vs_iphdr *iph);
5021da177e4SLinus Torvalds
5031da177e4SLinus Torvalds struct ip_vs_conn *
5040cf705c8SEric W. Biederman (*conn_out_get)(struct netns_ipvs *ipvs,
5050cf705c8SEric W. Biederman int af,
50651ef348bSJulius Volz const struct sk_buff *skb,
507802c41adSAlex Gartrell const struct ip_vs_iphdr *iph);
5081da177e4SLinus Torvalds
509d4383f04SJesper Dangaard Brouer int (*snat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp,
510d4383f04SJesper Dangaard Brouer struct ip_vs_conn *cp, struct ip_vs_iphdr *iph);
5111da177e4SLinus Torvalds
512d4383f04SJesper Dangaard Brouer int (*dnat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp,
513d4383f04SJesper Dangaard Brouer struct ip_vs_conn *cp, struct ip_vs_iphdr *iph);
5141da177e4SLinus Torvalds
5151da177e4SLinus Torvalds const char *(*state_name)(int state);
5161da177e4SLinus Torvalds
5174a516f11SSimon Horman void (*state_transition)(struct ip_vs_conn *cp, int direction,
5181da177e4SLinus Torvalds const struct sk_buff *skb,
5199330419dSHans Schillstrom struct ip_vs_proto_data *pd);
5201da177e4SLinus Torvalds
52119648918SEric W. Biederman int (*register_app)(struct netns_ipvs *ipvs, struct ip_vs_app *inc);
5221da177e4SLinus Torvalds
52319648918SEric W. Biederman void (*unregister_app)(struct netns_ipvs *ipvs, struct ip_vs_app *inc);
5241da177e4SLinus Torvalds
5251da177e4SLinus Torvalds int (*app_conn_bind)(struct ip_vs_conn *cp);
5261da177e4SLinus Torvalds
5270d79641aSJulian Anastasov void (*debug_packet)(int af, struct ip_vs_protocol *pp,
5281da177e4SLinus Torvalds const struct sk_buff *skb,
5291da177e4SLinus Torvalds int offset,
5301da177e4SLinus Torvalds const char *msg);
5311da177e4SLinus Torvalds
5329330419dSHans Schillstrom void (*timeout_change)(struct ip_vs_proto_data *pd, int flags);
5331da177e4SLinus Torvalds };
5341da177e4SLinus Torvalds
53507dcc686SSimon Horman /* protocol data per netns */
536252c6410SHans Schillstrom struct ip_vs_proto_data {
537252c6410SHans Schillstrom struct ip_vs_proto_data *next;
538252c6410SHans Schillstrom struct ip_vs_protocol *pp;
539252c6410SHans Schillstrom int *timeout_table; /* protocol timeout table */
540252c6410SHans Schillstrom atomic_t appcnt; /* counter of proto app incs. */
541252c6410SHans Schillstrom struct tcp_states_t *tcp_state_table;
542252c6410SHans Schillstrom };
543252c6410SHans Schillstrom
5445c3a0fd7SJoe Perches struct ip_vs_protocol *ip_vs_proto_get(unsigned short proto);
54518d6ade6SEric W. Biederman struct ip_vs_proto_data *ip_vs_proto_data_get(struct netns_ipvs *ipvs,
546252c6410SHans Schillstrom unsigned short proto);
5471da177e4SLinus Torvalds
548f11017ecSSimon Horman struct ip_vs_conn_param {
549e64e2b46SEric W. Biederman struct netns_ipvs *ipvs;
550f11017ecSSimon Horman const union nf_inet_addr *caddr;
551f11017ecSSimon Horman const union nf_inet_addr *vaddr;
552f11017ecSSimon Horman __be16 cport;
553f11017ecSSimon Horman __be16 vport;
554f11017ecSSimon Horman __u16 protocol;
555f11017ecSSimon Horman u16 af;
55685999283SSimon Horman
55785999283SSimon Horman const struct ip_vs_pe *pe;
55885999283SSimon Horman char *pe_data;
55985999283SSimon Horman __u8 pe_data_len;
560f11017ecSSimon Horman };
561f11017ecSSimon Horman
56207dcc686SSimon Horman /* IP_VS structure allocated for each dynamically scheduled connection */
5631da177e4SLinus Torvalds struct ip_vs_conn {
564731109e7SChangli Gao struct hlist_node c_list; /* hashed list heads */
5651da177e4SLinus Torvalds /* Protocol, addresses and port numbers */
5666e67e586SHans Schillstrom __be16 cport;
5676e67e586SHans Schillstrom __be16 dport;
5681845ed0bSJulian Anastasov __be16 vport;
5691845ed0bSJulian Anastasov u16 af; /* address family */
570e7ade46aSJulius Volz union nf_inet_addr caddr; /* client address */
571e7ade46aSJulius Volz union nf_inet_addr vaddr; /* virtual address */
572e7ade46aSJulius Volz union nf_inet_addr daddr; /* destination address */
5733575792eSJulian Anastasov volatile __u32 flags; /* status flags */
5741da177e4SLinus Torvalds __u16 protocol; /* Which protocol (TCP/UDP) */
575ba38528aSAlex Gartrell __u16 daf; /* Address family of the dest */
57658dbc6f2SEric W. Biederman struct netns_ipvs *ipvs;
5771da177e4SLinus Torvalds
5781da177e4SLinus Torvalds /* counter and timer */
579b54ab92bSReshetova, Elena refcount_t refcnt; /* reference count */
5801da177e4SLinus Torvalds struct timer_list timer; /* Expiration timer */
5811da177e4SLinus Torvalds volatile unsigned long timeout; /* timeout */
5821da177e4SLinus Torvalds
5831da177e4SLinus Torvalds /* Flags and state transition */
5841da177e4SLinus Torvalds spinlock_t lock; /* lock for state transition */
5851da177e4SLinus Torvalds volatile __u16 state; /* state info */
586efac5276SRumen G. Bogdanovski volatile __u16 old_state; /* old state, to be used for
587*c7d15aaaSSimon Horman * state transition triggered
588efac5276SRumen G. Bogdanovski * synchronization
589efac5276SRumen G. Bogdanovski */
5901845ed0bSJulian Anastasov __u32 fwmark; /* Fire wall mark from skb */
591749c42b6SJulian Anastasov unsigned long sync_endtime; /* jiffies + sent_retries */
5921da177e4SLinus Torvalds
5931da177e4SLinus Torvalds /* Control members */
5941da177e4SLinus Torvalds struct ip_vs_conn *control; /* Master control connection */
5951da177e4SLinus Torvalds atomic_t n_control; /* Number of controlled ones */
5961da177e4SLinus Torvalds struct ip_vs_dest *dest; /* real server */
5971da177e4SLinus Torvalds atomic_t in_pkts; /* incoming packet counter */
5981da177e4SLinus Torvalds
59907dcc686SSimon Horman /* Packet transmitter for different forwarding methods. If it
60007dcc686SSimon Horman * mangles the packet, it must return NF_DROP or better NF_STOLEN,
60107dcc686SSimon Horman * otherwise this must be changed to a sk_buff **.
60207dcc686SSimon Horman * NF_ACCEPT can be returned when destination is local.
6031da177e4SLinus Torvalds */
6041da177e4SLinus Torvalds int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
605d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
6061da177e4SLinus Torvalds
6071da177e4SLinus Torvalds /* Note: we can group the following members into a structure,
60807dcc686SSimon Horman * in order to save more space, and the following members are
60907dcc686SSimon Horman * only used in VS/NAT anyway
61007dcc686SSimon Horman */
6111da177e4SLinus Torvalds struct ip_vs_app *app; /* bound ip_vs_app object */
6121da177e4SLinus Torvalds void *app_data; /* Application private data */
613e3478c68SSimon Horman struct_group(sync_conn_opt,
6141da177e4SLinus Torvalds struct ip_vs_seq in_seq; /* incoming seq. struct */
6151da177e4SLinus Torvalds struct ip_vs_seq out_seq; /* outgoing seq. struct */
616e3478c68SSimon Horman );
61785999283SSimon Horman
618e9e5eee8SSimon Horman const struct ip_vs_pe *pe;
61985999283SSimon Horman char *pe_data;
62085999283SSimon Horman __u8 pe_data_len;
621088339a5SJulian Anastasov
622088339a5SJulian Anastasov struct rcu_head rcu_head;
6231da177e4SLinus Torvalds };
6241da177e4SLinus Torvalds
62507dcc686SSimon Horman /* Extended internal versions of struct ip_vs_service_user and ip_vs_dest_user
62607dcc686SSimon Horman * for IPv6 support.
627c860c6b1SJulius Volz *
628c860c6b1SJulius Volz * We need these to conveniently pass around service and destination
629c860c6b1SJulius Volz * options, but unfortunately, we also need to keep the old definitions to
630c860c6b1SJulius Volz * maintain userspace backwards compatibility for the setsockopt interface.
631c860c6b1SJulius Volz */
632c860c6b1SJulius Volz struct ip_vs_service_user_kern {
633c860c6b1SJulius Volz /* virtual service addresses */
634c860c6b1SJulius Volz u16 af;
635c860c6b1SJulius Volz u16 protocol;
636c860c6b1SJulius Volz union nf_inet_addr addr; /* virtual ip address */
6370a925864SJulian Anastasov __be16 port;
638*c7d15aaaSSimon Horman u32 fwmark; /* firewall mark of service */
639c860c6b1SJulius Volz
640c860c6b1SJulius Volz /* virtual service options */
641c860c6b1SJulius Volz char *sched_name;
6420d1e71b0SSimon Horman char *pe_name;
64395c96174SEric Dumazet unsigned int flags; /* virtual service flags */
64495c96174SEric Dumazet unsigned int timeout; /* persistent timeout in sec */
6450a925864SJulian Anastasov __be32 netmask; /* persistent netmask or plen */
646c860c6b1SJulius Volz };
647c860c6b1SJulius Volz
648c860c6b1SJulius Volz
649c860c6b1SJulius Volz struct ip_vs_dest_user_kern {
650c860c6b1SJulius Volz /* destination server address */
651c860c6b1SJulius Volz union nf_inet_addr addr;
6520a925864SJulian Anastasov __be16 port;
653c860c6b1SJulius Volz
654c860c6b1SJulius Volz /* real server options */
65595c96174SEric Dumazet unsigned int conn_flags; /* connection flags */
656c860c6b1SJulius Volz int weight; /* destination weight */
657c860c6b1SJulius Volz
658c860c6b1SJulius Volz /* thresholds for active connections */
659c860c6b1SJulius Volz u32 u_threshold; /* upper threshold */
660c860c6b1SJulius Volz u32 l_threshold; /* lower threshold */
6616cff339bSAlex Gartrell
6626cff339bSAlex Gartrell /* Address family of addr */
6636cff339bSAlex Gartrell u16 af;
66484c0d5e9SJacky Hu
66584c0d5e9SJacky Hu u16 tun_type; /* tunnel type */
66684c0d5e9SJacky Hu __be16 tun_port; /* tunnel port */
66729930e31SJacky Hu u16 tun_flags; /* tunnel flags */
668c860c6b1SJulius Volz };
669c860c6b1SJulius Volz
670c860c6b1SJulius Volz
671c860c6b1SJulius Volz /*
67207dcc686SSimon Horman * The information about the virtual service offered to the net and the
67307dcc686SSimon Horman * forwarding entries.
6741da177e4SLinus Torvalds */
6751da177e4SLinus Torvalds struct ip_vs_service {
676ceec4c38SJulian Anastasov struct hlist_node s_list; /* for normal service table */
677ceec4c38SJulian Anastasov struct hlist_node f_list; /* for fwmark-based service table */
6781da177e4SLinus Torvalds atomic_t refcnt; /* reference counter */
6791da177e4SLinus Torvalds
680e7ade46aSJulius Volz u16 af; /* address family */
6811da177e4SLinus Torvalds __u16 protocol; /* which protocol (TCP/UDP) */
682e7ade46aSJulius Volz union nf_inet_addr addr; /* IP address for virtual service */
683014d730dSAl Viro __be16 port; /* port number for the service */
6841da177e4SLinus Torvalds __u32 fwmark; /* firewall mark of the service */
68595c96174SEric Dumazet unsigned int flags; /* service status flags */
68695c96174SEric Dumazet unsigned int timeout; /* persistent timeout in ticks */
6870a925864SJulian Anastasov __be32 netmask; /* grouping granularity, mask/plen */
6883109d2f2SEric W. Biederman struct netns_ipvs *ipvs;
6891da177e4SLinus Torvalds
6901da177e4SLinus Torvalds struct list_head destinations; /* real server d-linked list */
6911da177e4SLinus Torvalds __u32 num_dests; /* number of servers */
6921da177e4SLinus Torvalds struct ip_vs_stats stats; /* statistics for the service */
6931da177e4SLinus Torvalds
6941da177e4SLinus Torvalds /* for scheduling */
695ceec4c38SJulian Anastasov struct ip_vs_scheduler __rcu *scheduler; /* bound scheduler object */
696ba3a3ce1SJulian Anastasov spinlock_t sched_lock; /* lock sched_data */
6971da177e4SLinus Torvalds void *sched_data; /* scheduler application data */
69885999283SSimon Horman
69985999283SSimon Horman /* alternate persistence engine */
700ceec4c38SJulian Anastasov struct ip_vs_pe __rcu *pe;
70131875d49SJulian Anastasov int conntrack_afmask;
702ceec4c38SJulian Anastasov
703ceec4c38SJulian Anastasov struct rcu_head rcu_head;
7041da177e4SLinus Torvalds };
7051da177e4SLinus Torvalds
706026ace06SJulian Anastasov /* Information for cached dst */
707026ace06SJulian Anastasov struct ip_vs_dest_dst {
708026ace06SJulian Anastasov struct dst_entry *dst_cache; /* destination cache entry */
709026ace06SJulian Anastasov u32 dst_cookie;
710026ace06SJulian Anastasov union nf_inet_addr dst_saddr;
711026ace06SJulian Anastasov struct rcu_head rcu_head;
712026ace06SJulian Anastasov };
7131da177e4SLinus Torvalds
71407dcc686SSimon Horman /* The real server destination forwarding entry with ip address, port number,
71507dcc686SSimon Horman * and so on.
7161da177e4SLinus Torvalds */
7171da177e4SLinus Torvalds struct ip_vs_dest {
7181da177e4SLinus Torvalds struct list_head n_list; /* for the dests in the service */
719276472eaSJulian Anastasov struct hlist_node d_list; /* for table with all the dests */
7201da177e4SLinus Torvalds
721e7ade46aSJulius Volz u16 af; /* address family */
722014d730dSAl Viro __be16 port; /* port number of the server */
723f2431e6eSHans Schillstrom union nf_inet_addr addr; /* IP address of the server */
72495c96174SEric Dumazet volatile unsigned int flags; /* dest status flags */
7251da177e4SLinus Torvalds atomic_t conn_flags; /* flags to copy to conn */
7261da177e4SLinus Torvalds atomic_t weight; /* server weight */
727a2c09ac0SInju Song atomic_t last_weight; /* server latest weight */
72884c0d5e9SJacky Hu __u16 tun_type; /* tunnel type */
72984c0d5e9SJacky Hu __be16 tun_port; /* tunnel port */
73029930e31SJacky Hu __u16 tun_flags; /* tunnel flags */
7311da177e4SLinus Torvalds
732b54ab92bSReshetova, Elena refcount_t refcnt; /* reference counter */
7331da177e4SLinus Torvalds struct ip_vs_stats stats; /* statistics */
734bcbde4c0SJulian Anastasov unsigned long idle_start; /* start time, jiffies */
7351da177e4SLinus Torvalds
7361da177e4SLinus Torvalds /* connection counters and thresholds */
7371da177e4SLinus Torvalds atomic_t activeconns; /* active connections */
7381da177e4SLinus Torvalds atomic_t inactconns; /* inactive connections */
7391da177e4SLinus Torvalds atomic_t persistconns; /* persistent connections */
7401da177e4SLinus Torvalds __u32 u_threshold; /* upper threshold */
7411da177e4SLinus Torvalds __u32 l_threshold; /* lower threshold */
7421da177e4SLinus Torvalds
7431da177e4SLinus Torvalds /* for destination cache */
7441da177e4SLinus Torvalds spinlock_t dst_lock; /* lock of dst_cache */
745026ace06SJulian Anastasov struct ip_vs_dest_dst __rcu *dest_dst; /* cached dst info */
7461da177e4SLinus Torvalds
7471da177e4SLinus Torvalds /* for virtual service */
748bcbde4c0SJulian Anastasov struct ip_vs_service __rcu *svc; /* service it belongs to */
7491da177e4SLinus Torvalds __u16 protocol; /* which protocol (TCP/UDP) */
750014d730dSAl Viro __be16 vport; /* virtual port number */
751f2431e6eSHans Schillstrom union nf_inet_addr vaddr; /* virtual IP address */
7521da177e4SLinus Torvalds __u32 vfwmark; /* firewall mark of service */
753276472eaSJulian Anastasov
7545df7d714SJulian Anastasov struct rcu_head rcu_head;
755578bc3efSJulian Anastasov struct list_head t_list; /* in dest_trash */
756276472eaSJulian Anastasov unsigned int in_rs_table:1; /* we are in rs_table */
7571da177e4SLinus Torvalds };
7581da177e4SLinus Torvalds
75907dcc686SSimon Horman /* The scheduler object */
7601da177e4SLinus Torvalds struct ip_vs_scheduler {
7611da177e4SLinus Torvalds struct list_head n_list; /* d-linked list head */
7621da177e4SLinus Torvalds char *name; /* scheduler name */
7631da177e4SLinus Torvalds atomic_t refcnt; /* reference counter */
7641da177e4SLinus Torvalds struct module *module; /* THIS_MODULE/NULL */
7651da177e4SLinus Torvalds
7661da177e4SLinus Torvalds /* scheduler initializing service */
7671da177e4SLinus Torvalds int (*init_service)(struct ip_vs_service *svc);
7681da177e4SLinus Torvalds /* scheduling service finish */
769ed3ffc4eSJulian Anastasov void (*done_service)(struct ip_vs_service *svc);
7706b6df466SJulian Anastasov /* dest is linked */
7716b6df466SJulian Anastasov int (*add_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
7726b6df466SJulian Anastasov /* dest is unlinked */
7736b6df466SJulian Anastasov int (*del_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
7746b6df466SJulian Anastasov /* dest is updated */
7756b6df466SJulian Anastasov int (*upd_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
7761da177e4SLinus Torvalds
7771da177e4SLinus Torvalds /* selecting a server from the given service */
7781da177e4SLinus Torvalds struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
779bba54de5SJulian Anastasov const struct sk_buff *skb,
780bba54de5SJulian Anastasov struct ip_vs_iphdr *iph);
7811da177e4SLinus Torvalds };
7821da177e4SLinus Torvalds
78385999283SSimon Horman /* The persistence engine object */
78485999283SSimon Horman struct ip_vs_pe {
78585999283SSimon Horman struct list_head n_list; /* d-linked list head */
78685999283SSimon Horman char *name; /* scheduler name */
78785999283SSimon Horman atomic_t refcnt; /* reference counter */
78885999283SSimon Horman struct module *module; /* THIS_MODULE/NULL */
78985999283SSimon Horman
79085999283SSimon Horman /* get the connection template, if any */
79185999283SSimon Horman int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb);
79285999283SSimon Horman bool (*ct_match)(const struct ip_vs_conn_param *p,
79385999283SSimon Horman struct ip_vs_conn *ct);
79485999283SSimon Horman u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval,
79585999283SSimon Horman bool inverse);
796a3c918acSSimon Horman int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf);
79739b97223SMarco Angaroni /* create connections for real-server outgoing packets */
79839b97223SMarco Angaroni struct ip_vs_conn* (*conn_out)(struct ip_vs_service *svc,
79939b97223SMarco Angaroni struct ip_vs_dest *dest,
80039b97223SMarco Angaroni struct sk_buff *skb,
80139b97223SMarco Angaroni const struct ip_vs_iphdr *iph,
80239b97223SMarco Angaroni __be16 dport, __be16 cport);
80385999283SSimon Horman };
8041da177e4SLinus Torvalds
80507dcc686SSimon Horman /* The application module object (a.k.a. app incarnation) */
806fd2c3ef7SEric Dumazet struct ip_vs_app {
8071da177e4SLinus Torvalds struct list_head a_list; /* member in app list */
8081da177e4SLinus Torvalds int type; /* IP_VS_APP_TYPE_xxx */
8091da177e4SLinus Torvalds char *name; /* application module name */
8101da177e4SLinus Torvalds __u16 protocol;
8111da177e4SLinus Torvalds struct module *module; /* THIS_MODULE/NULL */
8121da177e4SLinus Torvalds struct list_head incs_list; /* list of incarnations */
8131da177e4SLinus Torvalds
8141da177e4SLinus Torvalds /* members for application incarnations */
8151da177e4SLinus Torvalds struct list_head p_list; /* member in proto app list */
8161da177e4SLinus Torvalds struct ip_vs_app *app; /* its real application */
817014d730dSAl Viro __be16 port; /* port number in net order */
8181da177e4SLinus Torvalds atomic_t usecnt; /* usage counter */
819363c97d7SJulian Anastasov struct rcu_head rcu_head;
8201da177e4SLinus Torvalds
82107dcc686SSimon Horman /* output hook: Process packet in inout direction, diff set for TCP.
8228b27b10fSJulian Anastasov * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
8238b27b10fSJulian Anastasov * 2=Mangled but checksum was not updated
8248b27b10fSJulian Anastasov */
8251da177e4SLinus Torvalds int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
826d12e1229SJulian Anastasov struct sk_buff *, int *diff, struct ip_vs_iphdr *ipvsh);
8271da177e4SLinus Torvalds
82807dcc686SSimon Horman /* input hook: Process packet in outin direction, diff set for TCP.
8298b27b10fSJulian Anastasov * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
8308b27b10fSJulian Anastasov * 2=Mangled but checksum was not updated
8318b27b10fSJulian Anastasov */
8321da177e4SLinus Torvalds int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
833d12e1229SJulian Anastasov struct sk_buff *, int *diff, struct ip_vs_iphdr *ipvsh);
8341da177e4SLinus Torvalds
8351da177e4SLinus Torvalds /* ip_vs_app initializer */
8361da177e4SLinus Torvalds int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
8371da177e4SLinus Torvalds
8381da177e4SLinus Torvalds /* ip_vs_app finish */
8391da177e4SLinus Torvalds int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
8401da177e4SLinus Torvalds
8411da177e4SLinus Torvalds
8421da177e4SLinus Torvalds /* not used now */
8431da177e4SLinus Torvalds int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
8441da177e4SLinus Torvalds struct ip_vs_protocol *);
8451da177e4SLinus Torvalds
8461da177e4SLinus Torvalds void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
8471da177e4SLinus Torvalds
8481da177e4SLinus Torvalds int * timeout_table;
8491da177e4SLinus Torvalds int * timeouts;
8501da177e4SLinus Torvalds int timeouts_size;
8511da177e4SLinus Torvalds
8521da177e4SLinus Torvalds int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
8531da177e4SLinus Torvalds int *verdict, struct ip_vs_conn **cpp);
8541da177e4SLinus Torvalds
8551da177e4SLinus Torvalds struct ip_vs_conn *
8561da177e4SLinus Torvalds (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
857d4383f04SJesper Dangaard Brouer const struct iphdr *iph, int inverse);
8581da177e4SLinus Torvalds
8591da177e4SLinus Torvalds struct ip_vs_conn *
8601da177e4SLinus Torvalds (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
861d4383f04SJesper Dangaard Brouer const struct iphdr *iph, int inverse);
8621da177e4SLinus Torvalds
8631da177e4SLinus Torvalds int (*state_transition)(struct ip_vs_conn *cp, int direction,
8641da177e4SLinus Torvalds const struct sk_buff *skb,
8651da177e4SLinus Torvalds struct ip_vs_app *app);
8661da177e4SLinus Torvalds
8671da177e4SLinus Torvalds void (*timeout_change)(struct ip_vs_app *app, int flags);
8681da177e4SLinus Torvalds };
8691da177e4SLinus Torvalds
870f73181c8SPablo Neira Ayuso struct ipvs_master_sync_state {
871f73181c8SPablo Neira Ayuso struct list_head sync_queue;
872f73181c8SPablo Neira Ayuso struct ip_vs_sync_buff *sync_buff;
87307995674SZhang Yanfei unsigned long sync_queue_len;
874f73181c8SPablo Neira Ayuso unsigned int sync_queue_delay;
875f73181c8SPablo Neira Ayuso struct delayed_work master_wakeup_work;
876f73181c8SPablo Neira Ayuso struct netns_ipvs *ipvs;
877f73181c8SPablo Neira Ayuso };
878f73181c8SPablo Neira Ayuso
8795db7c8b9SJulian Anastasov struct ip_vs_sync_thread_data;
8805db7c8b9SJulian Anastasov
881578bc3efSJulian Anastasov /* How much time to keep dests in trash */
882578bc3efSJulian Anastasov #define IP_VS_DEST_TRASH_PERIOD (120 * HZ)
883578bc3efSJulian Anastasov
884e4ff6751SJulian Anastasov struct ipvs_sync_daemon_cfg {
885d3328817SJulian Anastasov union nf_inet_addr mcast_group;
886e4ff6751SJulian Anastasov int syncid;
887e4ff6751SJulian Anastasov u16 sync_maxlen;
888d3328817SJulian Anastasov u16 mcast_port;
889d3328817SJulian Anastasov u8 mcast_af;
890d3328817SJulian Anastasov u8 mcast_ttl;
891e4ff6751SJulian Anastasov /* multicast interface name */
892e4ff6751SJulian Anastasov char mcast_ifn[IP_VS_IFNAME_MAXLEN];
893e4ff6751SJulian Anastasov };
894e4ff6751SJulian 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 */
89907dcc686SSimon Horman /* Hash table: for real service lookups */
9002553d064SJulian Anastasov #define IP_VS_RTAB_BITS 4
9012553d064SJulian Anastasov #define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS)
9022553d064SJulian Anastasov #define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1)
9032553d064SJulian Anastasov
904276472eaSJulian Anastasov struct hlist_head rs_table[IP_VS_RTAB_SIZE];
9052553d064SJulian Anastasov /* ip_vs_app */
9062553d064SJulian Anastasov struct list_head app_list;
9072553d064SJulian Anastasov /* ip_vs_proto */
9082553d064SJulian Anastasov #define IP_VS_PROTO_TAB_SIZE 32 /* must be power of 2 */
9092553d064SJulian Anastasov struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE];
9102553d064SJulian Anastasov /* ip_vs_proto_tcp */
9112553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_TCP
9122553d064SJulian Anastasov #define TCP_APP_TAB_BITS 4
9132553d064SJulian Anastasov #define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS)
9142553d064SJulian Anastasov #define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1)
9152553d064SJulian Anastasov struct list_head tcp_apps[TCP_APP_TAB_SIZE];
9162553d064SJulian Anastasov #endif
9172553d064SJulian Anastasov /* ip_vs_proto_udp */
9182553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_UDP
9192553d064SJulian Anastasov #define UDP_APP_TAB_BITS 4
9202553d064SJulian Anastasov #define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS)
9212553d064SJulian Anastasov #define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1)
9222553d064SJulian Anastasov struct list_head udp_apps[UDP_APP_TAB_SIZE];
9232553d064SJulian Anastasov #endif
9242553d064SJulian Anastasov /* ip_vs_proto_sctp */
9252553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_SCTP
9262553d064SJulian Anastasov #define SCTP_APP_TAB_BITS 4
9272553d064SJulian Anastasov #define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS)
9282553d064SJulian Anastasov #define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1)
9292553d064SJulian Anastasov /* Hash table for SCTP application incarnations */
9302553d064SJulian Anastasov struct list_head sctp_apps[SCTP_APP_TAB_SIZE];
9312553d064SJulian Anastasov #endif
9322553d064SJulian Anastasov /* ip_vs_conn */
9332553d064SJulian Anastasov atomic_t conn_count; /* connection counter */
9342553d064SJulian Anastasov
9352553d064SJulian Anastasov /* ip_vs_ctl */
9365df7d714SJulian Anastasov struct ip_vs_stats_rcu *tot_stats; /* Statistics & est. */
9372553d064SJulian Anastasov
9382553d064SJulian Anastasov int num_services; /* no of virtual services */
939857ca897SJulian Anastasov int num_services6; /* IPv6 virtual services */
940f2247fbdSSimon Horman
9412553d064SJulian Anastasov /* Trash for destinations */
9422553d064SJulian Anastasov struct list_head dest_trash;
943578bc3efSJulian Anastasov spinlock_t dest_trash_lock;
944578bc3efSJulian Anastasov struct timer_list dest_trash_timer; /* expiration timer */
9452553d064SJulian Anastasov /* Service counters */
9462553d064SJulian Anastasov atomic_t ftpsvc_counter;
9472553d064SJulian Anastasov atomic_t nullsvc_counter;
94839b97223SMarco Angaroni atomic_t conn_out_counter;
9492553d064SJulian Anastasov
950f2247fbdSSimon Horman #ifdef CONFIG_SYSCTL
95135dfb013SAndrew Sy Kim /* delayed work for expiring no dest connections */
95235dfb013SAndrew Sy Kim struct delayed_work expire_nodest_conn_work;
953f2247fbdSSimon Horman /* 1/rate drop and drop-entry variables */
954f2247fbdSSimon Horman struct delayed_work defense_work; /* Work handler */
955f2247fbdSSimon Horman int drop_rate;
956f2247fbdSSimon Horman int drop_counter;
957c24b75e0SEric Dumazet int old_secure_tcp;
958f2247fbdSSimon Horman atomic_t dropentry;
959f2247fbdSSimon Horman /* locks in ctl.c */
960f2247fbdSSimon Horman spinlock_t dropentry_lock; /* drop entry handling */
961f2247fbdSSimon Horman spinlock_t droppacket_lock; /* drop packet handling */
962f2247fbdSSimon Horman spinlock_t securetcp_lock; /* state and timeout tables */
963f2247fbdSSimon Horman
9642553d064SJulian Anastasov /* sys-ctl struct */
9652553d064SJulian Anastasov struct ctl_table_header *sysctl_hdr;
9662553d064SJulian Anastasov struct ctl_table *sysctl_tbl;
967f2247fbdSSimon Horman #endif
968f2247fbdSSimon Horman
9692553d064SJulian Anastasov /* sysctl variables */
9702553d064SJulian Anastasov int sysctl_amemthresh;
9712553d064SJulian Anastasov int sysctl_am_droprate;
9722553d064SJulian Anastasov int sysctl_drop_entry;
9732553d064SJulian Anastasov int sysctl_drop_packet;
9742553d064SJulian Anastasov int sysctl_secure_tcp;
9752553d064SJulian Anastasov #ifdef CONFIG_IP_VS_NFCT
9762553d064SJulian Anastasov int sysctl_conntrack;
9772553d064SJulian Anastasov #endif
9782553d064SJulian Anastasov int sysctl_snat_reroute;
9792553d064SJulian Anastasov int sysctl_sync_ver;
980f73181c8SPablo Neira Ayuso int sysctl_sync_ports;
9814d0c875dSJulian Anastasov int sysctl_sync_persist_mode;
98207995674SZhang Yanfei unsigned long sysctl_sync_qlen_max;
9831c003b15SPablo Neira Ayuso int sysctl_sync_sock_size;
9842553d064SJulian Anastasov int sysctl_cache_bypass;
9852553d064SJulian Anastasov int sysctl_expire_nodest_conn;
986c6c96c18SAlexander Frolkin int sysctl_sloppy_tcp;
987c6c96c18SAlexander Frolkin int sysctl_sloppy_sctp;
9882553d064SJulian Anastasov int sysctl_expire_quiescent_template;
9892553d064SJulian Anastasov int sysctl_sync_threshold[2];
990749c42b6SJulian Anastasov unsigned int sysctl_sync_refresh_period;
991749c42b6SJulian Anastasov int sysctl_sync_retries;
9922553d064SJulian Anastasov int sysctl_nat_icmp_send;
9933654e611SJulian Anastasov int sysctl_pmtu_disc;
9940c12582fSJulian Anastasov int sysctl_backup_only;
995d752c364SMarcelo Ricardo Leitner int sysctl_conn_reuse_mode;
99694485fedSAlex Gartrell int sysctl_schedule_icmp;
9974e478098SAlex Gartrell int sysctl_ignore_tunneled;
9982232642eSDust Li int sysctl_run_estimation;
999f0be83d5SJulian Anastasov #ifdef CONFIG_SYSCTL
1000f0be83d5SJulian Anastasov cpumask_var_t sysctl_est_cpulist; /* kthread cpumask */
1001f0be83d5SJulian Anastasov int est_cpulist_valid; /* cpulist set */
1002f0be83d5SJulian Anastasov int sysctl_est_nice; /* kthread nice */
1003f0be83d5SJulian Anastasov int est_stopped; /* stop tasks */
1004f0be83d5SJulian Anastasov #endif
10052553d064SJulian Anastasov
10062553d064SJulian Anastasov /* ip_vs_lblc */
10072553d064SJulian Anastasov int sysctl_lblc_expiration;
10082553d064SJulian Anastasov struct ctl_table_header *lblc_ctl_header;
10092553d064SJulian Anastasov struct ctl_table *lblc_ctl_table;
10102553d064SJulian Anastasov /* ip_vs_lblcr */
10112553d064SJulian Anastasov int sysctl_lblcr_expiration;
10122553d064SJulian Anastasov struct ctl_table_header *lblcr_ctl_header;
10132553d064SJulian Anastasov struct ctl_table *lblcr_ctl_table;
10142553d064SJulian Anastasov /* ip_vs_est */
1015705dd344SJulian Anastasov struct delayed_work est_reload_work;/* Reload kthread tasks */
1016705dd344SJulian Anastasov struct mutex est_mutex; /* protect kthread tasks */
1017705dd344SJulian Anastasov struct hlist_head est_temp_list; /* Ests during calc phase */
1018705dd344SJulian Anastasov struct ip_vs_est_kt_data **est_kt_arr; /* Array of kthread data ptrs */
1019705dd344SJulian Anastasov unsigned long est_max_threads;/* Hard limit of kthreads */
1020705dd344SJulian Anastasov int est_calc_phase; /* Calculation phase */
1021705dd344SJulian Anastasov int est_chain_max; /* Calculated chain_max */
1022705dd344SJulian Anastasov int est_kt_count; /* Allocated ptrs */
1023705dd344SJulian Anastasov int est_add_ktid; /* ktid where to add ests */
1024705dd344SJulian Anastasov atomic_t est_genid; /* kthreads reload genid */
1025705dd344SJulian Anastasov atomic_t est_genid_done; /* applied genid */
10262553d064SJulian Anastasov /* ip_vs_sync */
10272553d064SJulian Anastasov spinlock_t sync_lock;
1028f73181c8SPablo Neira Ayuso struct ipvs_master_sync_state *ms;
10292553d064SJulian Anastasov spinlock_t sync_buff_lock;
10305db7c8b9SJulian Anastasov struct ip_vs_sync_thread_data *master_tinfo;
10315db7c8b9SJulian Anastasov struct ip_vs_sync_thread_data *backup_tinfo;
1032f73181c8SPablo Neira Ayuso int threads_mask;
10332553d064SJulian Anastasov volatile int sync_state;
1034ae1d48b2SHans Schillstrom struct mutex sync_mutex;
1035e4ff6751SJulian Anastasov struct ipvs_sync_daemon_cfg mcfg; /* Master Configuration */
1036e4ff6751SJulian Anastasov struct ipvs_sync_daemon_cfg bcfg; /* Backup Configuration */
10372553d064SJulian Anastasov /* net name space ptr */
10382553d064SJulian Anastasov struct net *net; /* Needed by timer routines */
1039*c7d15aaaSSimon Horman /* Number of heterogeneous destinations, needed because heterogeneous
104007dcc686SSimon Horman * are not supported when synchronization is enabled.
104107dcc686SSimon Horman */
1042391f503dSAlex Gartrell unsigned int mixed_address_family_dests;
1043857ca897SJulian Anastasov unsigned int hooks_afmask; /* &1=AF_INET, &2=AF_INET6 */
10442553d064SJulian Anastasov };
10451da177e4SLinus Torvalds
104659e0350eSSimon Horman #define DEFAULT_SYNC_THRESHOLD 3
104759e0350eSSimon Horman #define DEFAULT_SYNC_PERIOD 50
10487532e8d4SSimon Horman #define DEFAULT_SYNC_VER 1
1049c6c96c18SAlexander Frolkin #define DEFAULT_SLOPPY_TCP 0
1050c6c96c18SAlexander Frolkin #define DEFAULT_SLOPPY_SCTP 0
1051749c42b6SJulian Anastasov #define DEFAULT_SYNC_REFRESH_PERIOD (0U * HZ)
1052749c42b6SJulian Anastasov #define DEFAULT_SYNC_RETRIES 0
10531c003b15SPablo Neira Ayuso #define IPVS_SYNC_WAKEUP_RATE 8
10541c003b15SPablo Neira Ayuso #define IPVS_SYNC_QLEN_MAX (IPVS_SYNC_WAKEUP_RATE * 4)
10551c003b15SPablo Neira Ayuso #define IPVS_SYNC_SEND_DELAY (HZ / 50)
10561c003b15SPablo Neira Ayuso #define IPVS_SYNC_CHECK_PERIOD HZ
1057749c42b6SJulian Anastasov #define IPVS_SYNC_FLUSH_TIME (HZ * 2)
1058f73181c8SPablo Neira Ayuso #define IPVS_SYNC_PORTS_MAX (1 << 6)
105959e0350eSSimon Horman
106059e0350eSSimon Horman #ifdef CONFIG_SYSCTL
106159e0350eSSimon Horman
sysctl_sync_threshold(struct netns_ipvs * ipvs)106259e0350eSSimon Horman static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
106359e0350eSSimon Horman {
106459e0350eSSimon Horman return ipvs->sysctl_sync_threshold[0];
106559e0350eSSimon Horman }
106659e0350eSSimon Horman
sysctl_sync_period(struct netns_ipvs * ipvs)106759e0350eSSimon Horman static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
106859e0350eSSimon Horman {
10696aa7de05SMark Rutland return READ_ONCE(ipvs->sysctl_sync_threshold[1]);
1070749c42b6SJulian Anastasov }
1071749c42b6SJulian Anastasov
sysctl_sync_refresh_period(struct netns_ipvs * ipvs)1072749c42b6SJulian Anastasov static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
1073749c42b6SJulian Anastasov {
10746aa7de05SMark Rutland return READ_ONCE(ipvs->sysctl_sync_refresh_period);
1075749c42b6SJulian Anastasov }
1076749c42b6SJulian Anastasov
sysctl_sync_retries(struct netns_ipvs * ipvs)1077749c42b6SJulian Anastasov static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
1078749c42b6SJulian Anastasov {
1079749c42b6SJulian Anastasov return ipvs->sysctl_sync_retries;
108059e0350eSSimon Horman }
108159e0350eSSimon Horman
sysctl_sync_ver(struct netns_ipvs * ipvs)10827532e8d4SSimon Horman static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
10837532e8d4SSimon Horman {
10847532e8d4SSimon Horman return ipvs->sysctl_sync_ver;
10857532e8d4SSimon Horman }
10867532e8d4SSimon Horman
sysctl_sloppy_tcp(struct netns_ipvs * ipvs)1087c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs)
1088c6c96c18SAlexander Frolkin {
1089c6c96c18SAlexander Frolkin return ipvs->sysctl_sloppy_tcp;
1090c6c96c18SAlexander Frolkin }
1091c6c96c18SAlexander Frolkin
sysctl_sloppy_sctp(struct netns_ipvs * ipvs)1092c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs)
1093c6c96c18SAlexander Frolkin {
1094c6c96c18SAlexander Frolkin return ipvs->sysctl_sloppy_sctp;
1095c6c96c18SAlexander Frolkin }
1096c6c96c18SAlexander Frolkin
sysctl_sync_ports(struct netns_ipvs * ipvs)1097f73181c8SPablo Neira Ayuso static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
1098f73181c8SPablo Neira Ayuso {
10996aa7de05SMark Rutland return READ_ONCE(ipvs->sysctl_sync_ports);
1100f73181c8SPablo Neira Ayuso }
1101f73181c8SPablo Neira Ayuso
sysctl_sync_persist_mode(struct netns_ipvs * ipvs)11024d0c875dSJulian Anastasov static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs)
11034d0c875dSJulian Anastasov {
11044d0c875dSJulian Anastasov return ipvs->sysctl_sync_persist_mode;
11054d0c875dSJulian Anastasov }
11064d0c875dSJulian Anastasov
sysctl_sync_qlen_max(struct netns_ipvs * ipvs)110707995674SZhang Yanfei static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
11081c003b15SPablo Neira Ayuso {
11091c003b15SPablo Neira Ayuso return ipvs->sysctl_sync_qlen_max;
11101c003b15SPablo Neira Ayuso }
11111c003b15SPablo Neira Ayuso
sysctl_sync_sock_size(struct netns_ipvs * ipvs)11121c003b15SPablo Neira Ayuso static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
11131c003b15SPablo Neira Ayuso {
11141c003b15SPablo Neira Ayuso return ipvs->sysctl_sync_sock_size;
11151c003b15SPablo Neira Ayuso }
11161c003b15SPablo Neira Ayuso
sysctl_pmtu_disc(struct netns_ipvs * ipvs)11173654e611SJulian Anastasov static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
11183654e611SJulian Anastasov {
11193654e611SJulian Anastasov return ipvs->sysctl_pmtu_disc;
11203654e611SJulian Anastasov }
11213654e611SJulian Anastasov
sysctl_backup_only(struct netns_ipvs * ipvs)11220c12582fSJulian Anastasov static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
11230c12582fSJulian Anastasov {
11240c12582fSJulian Anastasov return ipvs->sync_state & IP_VS_STATE_BACKUP &&
11250c12582fSJulian Anastasov ipvs->sysctl_backup_only;
11260c12582fSJulian Anastasov }
11270c12582fSJulian Anastasov
sysctl_conn_reuse_mode(struct netns_ipvs * ipvs)1128d752c364SMarcelo Ricardo Leitner static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs)
1129d752c364SMarcelo Ricardo Leitner {
1130d752c364SMarcelo Ricardo Leitner return ipvs->sysctl_conn_reuse_mode;
1131d752c364SMarcelo Ricardo Leitner }
1132d752c364SMarcelo Ricardo Leitner
sysctl_expire_nodest_conn(struct netns_ipvs * ipvs)113335dfb013SAndrew Sy Kim static inline int sysctl_expire_nodest_conn(struct netns_ipvs *ipvs)
113435dfb013SAndrew Sy Kim {
113535dfb013SAndrew Sy Kim return ipvs->sysctl_expire_nodest_conn;
113635dfb013SAndrew Sy Kim }
113735dfb013SAndrew Sy Kim
sysctl_schedule_icmp(struct netns_ipvs * ipvs)113894485fedSAlex Gartrell static inline int sysctl_schedule_icmp(struct netns_ipvs *ipvs)
113994485fedSAlex Gartrell {
114094485fedSAlex Gartrell return ipvs->sysctl_schedule_icmp;
114194485fedSAlex Gartrell }
114294485fedSAlex Gartrell
sysctl_ignore_tunneled(struct netns_ipvs * ipvs)11434e478098SAlex Gartrell static inline int sysctl_ignore_tunneled(struct netns_ipvs *ipvs)
11444e478098SAlex Gartrell {
11454e478098SAlex Gartrell return ipvs->sysctl_ignore_tunneled;
11464e478098SAlex Gartrell }
11474e478098SAlex Gartrell
sysctl_cache_bypass(struct netns_ipvs * ipvs)114857032948SEric W. Biederman static inline int sysctl_cache_bypass(struct netns_ipvs *ipvs)
114957032948SEric W. Biederman {
115057032948SEric W. Biederman return ipvs->sysctl_cache_bypass;
115157032948SEric W. Biederman }
115257032948SEric W. Biederman
sysctl_run_estimation(struct netns_ipvs * ipvs)11532232642eSDust Li static inline int sysctl_run_estimation(struct netns_ipvs *ipvs)
11542232642eSDust Li {
11552232642eSDust Li return ipvs->sysctl_run_estimation;
11562232642eSDust Li }
11572232642eSDust Li
sysctl_est_cpulist(struct netns_ipvs * ipvs)1158f0be83d5SJulian Anastasov static inline const struct cpumask *sysctl_est_cpulist(struct netns_ipvs *ipvs)
1159f0be83d5SJulian Anastasov {
1160f0be83d5SJulian Anastasov if (ipvs->est_cpulist_valid)
1161f0be83d5SJulian Anastasov return ipvs->sysctl_est_cpulist;
1162f0be83d5SJulian Anastasov else
1163f0be83d5SJulian Anastasov return housekeeping_cpumask(HK_TYPE_KTHREAD);
1164f0be83d5SJulian Anastasov }
1165f0be83d5SJulian Anastasov
sysctl_est_nice(struct netns_ipvs * ipvs)1166f0be83d5SJulian Anastasov static inline int sysctl_est_nice(struct netns_ipvs *ipvs)
1167f0be83d5SJulian Anastasov {
1168f0be83d5SJulian Anastasov return ipvs->sysctl_est_nice;
1169f0be83d5SJulian Anastasov }
1170f0be83d5SJulian Anastasov
117159e0350eSSimon Horman #else
117259e0350eSSimon Horman
sysctl_sync_threshold(struct netns_ipvs * ipvs)117359e0350eSSimon Horman static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
117459e0350eSSimon Horman {
117559e0350eSSimon Horman return DEFAULT_SYNC_THRESHOLD;
117659e0350eSSimon Horman }
117759e0350eSSimon Horman
sysctl_sync_period(struct netns_ipvs * ipvs)117859e0350eSSimon Horman static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
117959e0350eSSimon Horman {
118059e0350eSSimon Horman return DEFAULT_SYNC_PERIOD;
118159e0350eSSimon Horman }
118259e0350eSSimon Horman
sysctl_sync_refresh_period(struct netns_ipvs * ipvs)1183749c42b6SJulian Anastasov static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
1184749c42b6SJulian Anastasov {
1185749c42b6SJulian Anastasov return DEFAULT_SYNC_REFRESH_PERIOD;
1186749c42b6SJulian Anastasov }
1187749c42b6SJulian Anastasov
sysctl_sync_retries(struct netns_ipvs * ipvs)1188749c42b6SJulian Anastasov static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
1189749c42b6SJulian Anastasov {
1190749c42b6SJulian Anastasov return DEFAULT_SYNC_RETRIES & 3;
1191749c42b6SJulian Anastasov }
1192749c42b6SJulian Anastasov
sysctl_sync_ver(struct netns_ipvs * ipvs)11937532e8d4SSimon Horman static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
11947532e8d4SSimon Horman {
11957532e8d4SSimon Horman return DEFAULT_SYNC_VER;
11967532e8d4SSimon Horman }
11977532e8d4SSimon Horman
sysctl_sloppy_tcp(struct netns_ipvs * ipvs)1198c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs)
1199c6c96c18SAlexander Frolkin {
1200c6c96c18SAlexander Frolkin return DEFAULT_SLOPPY_TCP;
1201c6c96c18SAlexander Frolkin }
1202c6c96c18SAlexander Frolkin
sysctl_sloppy_sctp(struct netns_ipvs * ipvs)1203c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs)
1204c6c96c18SAlexander Frolkin {
1205c6c96c18SAlexander Frolkin return DEFAULT_SLOPPY_SCTP;
1206c6c96c18SAlexander Frolkin }
1207c6c96c18SAlexander Frolkin
sysctl_sync_ports(struct netns_ipvs * ipvs)1208f73181c8SPablo Neira Ayuso static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
1209f73181c8SPablo Neira Ayuso {
1210f73181c8SPablo Neira Ayuso return 1;
1211f73181c8SPablo Neira Ayuso }
1212f73181c8SPablo Neira Ayuso
sysctl_sync_persist_mode(struct netns_ipvs * ipvs)12134d0c875dSJulian Anastasov static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs)
12144d0c875dSJulian Anastasov {
12154d0c875dSJulian Anastasov return 0;
12164d0c875dSJulian Anastasov }
12174d0c875dSJulian Anastasov
sysctl_sync_qlen_max(struct netns_ipvs * ipvs)121807995674SZhang Yanfei static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
12191c003b15SPablo Neira Ayuso {
12201c003b15SPablo Neira Ayuso return IPVS_SYNC_QLEN_MAX;
12211c003b15SPablo Neira Ayuso }
12221c003b15SPablo Neira Ayuso
sysctl_sync_sock_size(struct netns_ipvs * ipvs)12231c003b15SPablo Neira Ayuso static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
12241c003b15SPablo Neira Ayuso {
12251c003b15SPablo Neira Ayuso return 0;
12261c003b15SPablo Neira Ayuso }
12271c003b15SPablo Neira Ayuso
sysctl_pmtu_disc(struct netns_ipvs * ipvs)12283654e611SJulian Anastasov static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
12293654e611SJulian Anastasov {
12303654e611SJulian Anastasov return 1;
12313654e611SJulian Anastasov }
12323654e611SJulian Anastasov
sysctl_backup_only(struct netns_ipvs * ipvs)12330c12582fSJulian Anastasov static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
12340c12582fSJulian Anastasov {
12350c12582fSJulian Anastasov return 0;
12360c12582fSJulian Anastasov }
12370c12582fSJulian Anastasov
sysctl_conn_reuse_mode(struct netns_ipvs * ipvs)1238d752c364SMarcelo Ricardo Leitner static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs)
1239d752c364SMarcelo Ricardo Leitner {
1240d752c364SMarcelo Ricardo Leitner return 1;
1241d752c364SMarcelo Ricardo Leitner }
1242d752c364SMarcelo Ricardo Leitner
sysctl_expire_nodest_conn(struct netns_ipvs * ipvs)124335dfb013SAndrew Sy Kim static inline int sysctl_expire_nodest_conn(struct netns_ipvs *ipvs)
124435dfb013SAndrew Sy Kim {
124535dfb013SAndrew Sy Kim return 0;
124635dfb013SAndrew Sy Kim }
124735dfb013SAndrew Sy Kim
sysctl_schedule_icmp(struct netns_ipvs * ipvs)124894485fedSAlex Gartrell static inline int sysctl_schedule_icmp(struct netns_ipvs *ipvs)
124994485fedSAlex Gartrell {
125094485fedSAlex Gartrell return 0;
125194485fedSAlex Gartrell }
125294485fedSAlex Gartrell
sysctl_ignore_tunneled(struct netns_ipvs * ipvs)12534e478098SAlex Gartrell static inline int sysctl_ignore_tunneled(struct netns_ipvs *ipvs)
12544e478098SAlex Gartrell {
12554e478098SAlex Gartrell return 0;
12564e478098SAlex Gartrell }
12574e478098SAlex Gartrell
sysctl_cache_bypass(struct netns_ipvs * ipvs)125857032948SEric W. Biederman static inline int sysctl_cache_bypass(struct netns_ipvs *ipvs)
125957032948SEric W. Biederman {
126057032948SEric W. Biederman return 0;
126157032948SEric W. Biederman }
126257032948SEric W. Biederman
sysctl_run_estimation(struct netns_ipvs * ipvs)12632232642eSDust Li static inline int sysctl_run_estimation(struct netns_ipvs *ipvs)
12642232642eSDust Li {
12652232642eSDust Li return 1;
12662232642eSDust Li }
12672232642eSDust Li
sysctl_est_cpulist(struct netns_ipvs * ipvs)1268f0be83d5SJulian Anastasov static inline const struct cpumask *sysctl_est_cpulist(struct netns_ipvs *ipvs)
1269f0be83d5SJulian Anastasov {
1270f0be83d5SJulian Anastasov return housekeeping_cpumask(HK_TYPE_KTHREAD);
1271f0be83d5SJulian Anastasov }
1272f0be83d5SJulian Anastasov
sysctl_est_nice(struct netns_ipvs * ipvs)1273f0be83d5SJulian Anastasov static inline int sysctl_est_nice(struct netns_ipvs *ipvs)
1274f0be83d5SJulian Anastasov {
1275f0be83d5SJulian Anastasov return IPVS_EST_NICE;
1276f0be83d5SJulian Anastasov }
1277f0be83d5SJulian Anastasov
127859e0350eSSimon Horman #endif
127959e0350eSSimon Horman
128007dcc686SSimon Horman /* IPVS core functions
12811da177e4SLinus Torvalds * (from ip_vs_core.c)
12821da177e4SLinus Torvalds */
12835c3a0fd7SJoe Perches const char *ip_vs_proto_name(unsigned int proto);
12845c3a0fd7SJoe Perches void ip_vs_init_hash_table(struct list_head *table, int rows);
128539b97223SMarco Angaroni struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc,
128639b97223SMarco Angaroni struct ip_vs_dest *dest,
128739b97223SMarco Angaroni struct sk_buff *skb,
128839b97223SMarco Angaroni const struct ip_vs_iphdr *iph,
128939b97223SMarco Angaroni __be16 dport,
129039b97223SMarco Angaroni __be16 cport);
1291afdd6140SSven Wegener #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
12921da177e4SLinus Torvalds
12931da177e4SLinus Torvalds #define IP_VS_APP_TYPE_FTP 1
12941da177e4SLinus Torvalds
129507dcc686SSimon Horman /* ip_vs_conn handling functions
12961da177e4SLinus Torvalds * (from ip_vs_conn.c)
12971da177e4SLinus Torvalds */
12981da177e4SLinus Torvalds enum {
12991da177e4SLinus Torvalds IP_VS_DIR_INPUT = 0,
13001da177e4SLinus Torvalds IP_VS_DIR_OUTPUT,
13011da177e4SLinus Torvalds IP_VS_DIR_INPUT_ONLY,
13021da177e4SLinus Torvalds IP_VS_DIR_LAST,
13031da177e4SLinus Torvalds };
13041da177e4SLinus Torvalds
ip_vs_conn_fill_param(struct netns_ipvs * ipvs,int af,int protocol,const union nf_inet_addr * caddr,__be16 cport,const union nf_inet_addr * vaddr,__be16 vport,struct ip_vs_conn_param * p)130519913decSEric W. Biederman static inline void ip_vs_conn_fill_param(struct netns_ipvs *ipvs, int af, int protocol,
1306f11017ecSSimon Horman const union nf_inet_addr *caddr,
1307f11017ecSSimon Horman __be16 cport,
1308f11017ecSSimon Horman const union nf_inet_addr *vaddr,
1309f11017ecSSimon Horman __be16 vport,
1310f11017ecSSimon Horman struct ip_vs_conn_param *p)
1311f11017ecSSimon Horman {
131219913decSEric W. Biederman p->ipvs = ipvs;
1313f11017ecSSimon Horman p->af = af;
1314f11017ecSSimon Horman p->protocol = protocol;
1315f11017ecSSimon Horman p->caddr = caddr;
1316f11017ecSSimon Horman p->cport = cport;
1317f11017ecSSimon Horman p->vaddr = vaddr;
1318f11017ecSSimon Horman p->vport = vport;
131985999283SSimon Horman p->pe = NULL;
132085999283SSimon Horman p->pe_data = NULL;
1321f11017ecSSimon Horman }
132228364a59SJulius Volz
1323f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p);
1324f11017ecSSimon Horman struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p);
132528364a59SJulius Volz
1326ab161976SEric W. Biederman struct ip_vs_conn * ip_vs_conn_in_get_proto(struct netns_ipvs *ipvs, int af,
1327ab161976SEric W. Biederman const struct sk_buff *skb,
1328802c41adSAlex Gartrell const struct ip_vs_iphdr *iph);
13295c0d2374SSimon Horman
1330f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p);
13311da177e4SLinus Torvalds
13320cf705c8SEric W. Biederman struct ip_vs_conn * ip_vs_conn_out_get_proto(struct netns_ipvs *ipvs, int af,
13330cf705c8SEric W. Biederman const struct sk_buff *skb,
1334802c41adSAlex Gartrell const struct ip_vs_iphdr *iph);
13355c0d2374SSimon Horman
1336088339a5SJulian Anastasov /* Get reference to gain full access to conn.
1337088339a5SJulian Anastasov * By default, RCU read-side critical sections have access only to
1338088339a5SJulian Anastasov * conn fields and its PE data, see ip_vs_conn_rcu_free() for reference.
1339088339a5SJulian Anastasov */
__ip_vs_conn_get(struct ip_vs_conn * cp)1340088339a5SJulian Anastasov static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp)
1341088339a5SJulian Anastasov {
1342b54ab92bSReshetova, Elena return refcount_inc_not_zero(&cp->refcnt);
1343088339a5SJulian Anastasov }
1344088339a5SJulian Anastasov
13451da177e4SLinus Torvalds /* put back the conn without restarting its timer */
__ip_vs_conn_put(struct ip_vs_conn * cp)13461da177e4SLinus Torvalds static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
13471da177e4SLinus Torvalds {
13484e857c58SPeter Zijlstra smp_mb__before_atomic();
1349b54ab92bSReshetova, Elena refcount_dec(&cp->refcnt);
13501da177e4SLinus Torvalds }
13515c3a0fd7SJoe Perches void ip_vs_conn_put(struct ip_vs_conn *cp);
13525c3a0fd7SJoe Perches void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
13531da177e4SLinus Torvalds
1354ba38528aSAlex Gartrell struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
1355f11017ecSSimon Horman const union nf_inet_addr *daddr,
135695c96174SEric Dumazet __be16 dport, unsigned int flags,
13570e051e68SHans Schillstrom struct ip_vs_dest *dest, __u32 fwmark);
13585c3a0fd7SJoe Perches void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
13591da177e4SLinus Torvalds
1360ec1b28caSJulian Anastasov const char *ip_vs_state_name(const struct ip_vs_conn *cp);
13611da177e4SLinus Torvalds
136269f39093SEric W. Biederman void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
13633ec10d3aSMarco Angaroni int ip_vs_check_template(struct ip_vs_conn *ct, struct ip_vs_dest *cdest);
1364423b5595SEric W. Biederman void ip_vs_random_dropentry(struct netns_ipvs *ipvs);
13655c3a0fd7SJoe Perches int ip_vs_conn_init(void);
13665c3a0fd7SJoe Perches void ip_vs_conn_cleanup(void);
13671da177e4SLinus Torvalds
ip_vs_control_del(struct ip_vs_conn * cp)13681da177e4SLinus Torvalds static inline void ip_vs_control_del(struct ip_vs_conn *cp)
13691da177e4SLinus Torvalds {
13701da177e4SLinus Torvalds struct ip_vs_conn *ctl_cp = cp->control;
13711da177e4SLinus Torvalds if (!ctl_cp) {
1372cfc78c5aSJulius Volz IP_VS_ERR_BUF("request control DEL for uncontrolled: "
1373cfc78c5aSJulius Volz "%s:%d to %s:%d\n",
1374cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1375cfc78c5aSJulius Volz ntohs(cp->cport),
1376cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
1377cfc78c5aSJulius Volz ntohs(cp->vport));
1378cfc78c5aSJulius Volz
13791da177e4SLinus Torvalds return;
13801da177e4SLinus Torvalds }
13811da177e4SLinus Torvalds
1382cfc78c5aSJulius Volz IP_VS_DBG_BUF(7, "DELeting control for: "
1383cfc78c5aSJulius Volz "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
1384cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1385cfc78c5aSJulius Volz ntohs(cp->cport),
1386cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
1387cfc78c5aSJulius Volz ntohs(ctl_cp->cport));
13881da177e4SLinus Torvalds
13891da177e4SLinus Torvalds cp->control = NULL;
13901da177e4SLinus Torvalds if (atomic_read(&ctl_cp->n_control) == 0) {
1391cfc78c5aSJulius Volz IP_VS_ERR_BUF("BUG control DEL with n=0 : "
1392cfc78c5aSJulius Volz "%s:%d to %s:%d\n",
1393cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1394cfc78c5aSJulius Volz ntohs(cp->cport),
1395cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
1396cfc78c5aSJulius Volz ntohs(cp->vport));
1397cfc78c5aSJulius Volz
13981da177e4SLinus Torvalds return;
13991da177e4SLinus Torvalds }
14001da177e4SLinus Torvalds atomic_dec(&ctl_cp->n_control);
14011da177e4SLinus Torvalds }
14021da177e4SLinus Torvalds
14031da177e4SLinus Torvalds static inline void
ip_vs_control_add(struct ip_vs_conn * cp,struct ip_vs_conn * ctl_cp)14041da177e4SLinus Torvalds ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
14051da177e4SLinus Torvalds {
14061da177e4SLinus Torvalds if (cp->control) {
1407cfc78c5aSJulius Volz IP_VS_ERR_BUF("request control ADD for already controlled: "
1408cfc78c5aSJulius Volz "%s:%d to %s:%d\n",
1409cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1410cfc78c5aSJulius Volz ntohs(cp->cport),
1411cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
1412cfc78c5aSJulius Volz ntohs(cp->vport));
1413cfc78c5aSJulius Volz
14141da177e4SLinus Torvalds ip_vs_control_del(cp);
14151da177e4SLinus Torvalds }
14161da177e4SLinus Torvalds
1417cfc78c5aSJulius Volz IP_VS_DBG_BUF(7, "ADDing control for: "
1418cfc78c5aSJulius Volz "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
1419cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1420cfc78c5aSJulius Volz ntohs(cp->cport),
1421cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
1422cfc78c5aSJulius Volz ntohs(ctl_cp->cport));
14231da177e4SLinus Torvalds
14241da177e4SLinus Torvalds cp->control = ctl_cp;
14251da177e4SLinus Torvalds atomic_inc(&ctl_cp->n_control);
14261da177e4SLinus Torvalds }
14271da177e4SLinus Torvalds
142827541143SJulian Anastasov /* Mark our template as assured */
142927541143SJulian Anastasov static inline void
ip_vs_control_assure_ct(struct ip_vs_conn * cp)143027541143SJulian Anastasov ip_vs_control_assure_ct(struct ip_vs_conn *cp)
143127541143SJulian Anastasov {
143227541143SJulian Anastasov struct ip_vs_conn *ct = cp->control;
143327541143SJulian Anastasov
143427541143SJulian Anastasov if (ct && !(ct->state & IP_VS_CTPL_S_ASSURED) &&
143527541143SJulian Anastasov (ct->flags & IP_VS_CONN_F_TEMPLATE))
143627541143SJulian Anastasov ct->state |= IP_VS_CTPL_S_ASSURED;
143727541143SJulian Anastasov }
143827541143SJulian Anastasov
143907dcc686SSimon Horman /* IPVS netns init & cleanup functions */
1440a4dd0360SEric W. Biederman int ip_vs_estimator_net_init(struct netns_ipvs *ipvs);
14413d993766SEric W. Biederman int ip_vs_control_net_init(struct netns_ipvs *ipvs);
14427d1f88ecSEric W. Biederman int ip_vs_protocol_net_init(struct netns_ipvs *ipvs);
1443b5dd212cSEric W. Biederman int ip_vs_app_net_init(struct netns_ipvs *ipvs);
14442f3edc6aSEric W. Biederman int ip_vs_conn_net_init(struct netns_ipvs *ipvs);
1445802cb437SEric W. Biederman int ip_vs_sync_net_init(struct netns_ipvs *ipvs);
14462f3edc6aSEric W. Biederman void ip_vs_conn_net_cleanup(struct netns_ipvs *ipvs);
1447b5dd212cSEric W. Biederman void ip_vs_app_net_cleanup(struct netns_ipvs *ipvs);
14487d1f88ecSEric W. Biederman void ip_vs_protocol_net_cleanup(struct netns_ipvs *ipvs);
14493d993766SEric W. Biederman void ip_vs_control_net_cleanup(struct netns_ipvs *ipvs);
1450a4dd0360SEric W. Biederman void ip_vs_estimator_net_cleanup(struct netns_ipvs *ipvs);
1451ebea1f7cSEric W. Biederman void ip_vs_sync_net_cleanup(struct netns_ipvs *ipvs);
14525d5a0815SHaishuang Yan void ip_vs_service_nets_cleanup(struct list_head *net_list);
14531da177e4SLinus Torvalds
145407dcc686SSimon Horman /* IPVS application functions
14551da177e4SLinus Torvalds * (from ip_vs_app.c)
14561da177e4SLinus Torvalds */
14571da177e4SLinus Torvalds #define IP_VS_APP_MAX_PORTS 8
14589f8128a5SEric W. Biederman struct ip_vs_app *register_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app);
14599f8128a5SEric W. Biederman void unregister_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app);
14605c3a0fd7SJoe Perches int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
14615c3a0fd7SJoe Perches void ip_vs_unbind_app(struct ip_vs_conn *cp);
14623250dc9cSEric W. Biederman int register_ip_vs_app_inc(struct netns_ipvs *ipvs, struct ip_vs_app *app, __u16 proto,
14635c3a0fd7SJoe Perches __u16 port);
14645c3a0fd7SJoe Perches int ip_vs_app_inc_get(struct ip_vs_app *inc);
14655c3a0fd7SJoe Perches void ip_vs_app_inc_put(struct ip_vs_app *inc);
14661da177e4SLinus Torvalds
1467d12e1229SJulian Anastasov int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb,
1468d12e1229SJulian Anastasov struct ip_vs_iphdr *ipvsh);
1469d12e1229SJulian Anastasov int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb,
1470d12e1229SJulian Anastasov struct ip_vs_iphdr *ipvsh);
14711da177e4SLinus Torvalds
14728be67a66SSimon Horman int register_ip_vs_pe(struct ip_vs_pe *pe);
14738be67a66SSimon Horman int unregister_ip_vs_pe(struct ip_vs_pe *pe);
1474e9e5eee8SSimon Horman struct ip_vs_pe *ip_vs_pe_getbyname(const char *name);
1475fe5e7a1eSHans Schillstrom struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name);
1476e9e5eee8SSimon Horman
147707dcc686SSimon Horman /* Use a #define to avoid all of module.h just for these trivial ops */
147869e7dae4SPaul Gortmaker #define ip_vs_pe_get(pe) \
147969e7dae4SPaul Gortmaker if (pe && pe->module) \
1480e9e5eee8SSimon Horman __module_get(pe->module);
1481e9e5eee8SSimon Horman
148269e7dae4SPaul Gortmaker #define ip_vs_pe_put(pe) \
148369e7dae4SPaul Gortmaker if (pe && pe->module) \
1484e9e5eee8SSimon Horman module_put(pe->module);
14851da177e4SLinus Torvalds
148607dcc686SSimon Horman /* IPVS protocol functions (from ip_vs_proto.c) */
14875c3a0fd7SJoe Perches int ip_vs_protocol_init(void);
14885c3a0fd7SJoe Perches void ip_vs_protocol_cleanup(void);
14895c3a0fd7SJoe Perches void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags);
14905c3a0fd7SJoe Perches int *ip_vs_create_timeout_table(int *table, int size);
14915c3a0fd7SJoe Perches void ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,
14925c3a0fd7SJoe Perches const struct sk_buff *skb, int offset,
14935c3a0fd7SJoe Perches const char *msg);
14941da177e4SLinus Torvalds
14951da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_tcp;
14961da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_udp;
14971da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_icmp;
14981da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_esp;
14991da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_ah;
15002906f66aSVenkata Mohan Reddy extern struct ip_vs_protocol ip_vs_protocol_sctp;
15011da177e4SLinus Torvalds
150207dcc686SSimon Horman /* Registering/unregistering scheduler functions
15031da177e4SLinus Torvalds * (from ip_vs_sched.c)
15041da177e4SLinus Torvalds */
15055c3a0fd7SJoe Perches int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
15065c3a0fd7SJoe Perches int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
15075c3a0fd7SJoe Perches int ip_vs_bind_scheduler(struct ip_vs_service *svc,
15081da177e4SLinus Torvalds struct ip_vs_scheduler *scheduler);
15095c3a0fd7SJoe Perches void ip_vs_unbind_scheduler(struct ip_vs_service *svc,
1510ceec4c38SJulian Anastasov struct ip_vs_scheduler *sched);
15115c3a0fd7SJoe Perches struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
15125c3a0fd7SJoe Perches void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
15135c3a0fd7SJoe Perches struct ip_vs_conn *
1514190ecd27SJulian Anastasov ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
1515d4383f04SJesper Dangaard Brouer struct ip_vs_proto_data *pd, int *ignored,
1516d4383f04SJesper Dangaard Brouer struct ip_vs_iphdr *iph);
15175c3a0fd7SJoe Perches int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
1518d4383f04SJesper Dangaard Brouer struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph);
15191da177e4SLinus Torvalds
15205c3a0fd7SJoe Perches void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg);
152141ac51eeSPatrick Schaaf
152207dcc686SSimon Horman /* IPVS control data and functions (from ip_vs_ctl.c) */
15231da177e4SLinus Torvalds extern struct ip_vs_stats ip_vs_stats;
1524b880c1f0SHans Schillstrom extern int sysctl_ip_vs_sync_ver;
15251da177e4SLinus Torvalds
15265c3a0fd7SJoe Perches struct ip_vs_service *
15270a4fd6ceSEric W. Biederman ip_vs_service_find(struct netns_ipvs *ipvs, int af, __u32 fwmark, __u16 protocol,
15283c2e0505SJulius Volz const union nf_inet_addr *vaddr, __be16 vport);
15291da177e4SLinus Torvalds
153048aed1b0SEric W. Biederman bool ip_vs_has_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol,
15317937df15SJulius Volz const union nf_inet_addr *daddr, __be16 dport);
15327937df15SJulius Volz
153339b97223SMarco Angaroni struct ip_vs_dest *
153439b97223SMarco Angaroni ip_vs_find_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol,
153539b97223SMarco Angaroni const union nf_inet_addr *daddr, __be16 dport);
15362aa3c9f4SJulian Anastasov struct ip_vs_dest *ip_vs_find_tunnel(struct netns_ipvs *ipvs, int af,
15372aa3c9f4SJulian Anastasov const union nf_inet_addr *daddr,
15382aa3c9f4SJulian Anastasov __be16 tun_port);
153939b97223SMarco Angaroni
15405c3a0fd7SJoe Perches int ip_vs_use_count_inc(void);
15415c3a0fd7SJoe Perches void ip_vs_use_count_dec(void);
15425c3a0fd7SJoe Perches int ip_vs_register_nl_ioctl(void);
15435c3a0fd7SJoe Perches void ip_vs_unregister_nl_ioctl(void);
15445c3a0fd7SJoe Perches int ip_vs_control_init(void);
15455c3a0fd7SJoe Perches void ip_vs_control_cleanup(void);
15465c3a0fd7SJoe Perches struct ip_vs_dest *
1547dc2add6fSEric W. Biederman ip_vs_find_dest(struct netns_ipvs *ipvs, int svc_af, int dest_af,
1548655eef10SAlex Gartrell const union nf_inet_addr *daddr, __be16 dport,
1549655eef10SAlex Gartrell const union nf_inet_addr *vaddr, __be16 vport,
155052793dbeSJulian Anastasov __u16 protocol, __u32 fwmark, __u32 flags);
15515c3a0fd7SJoe Perches void ip_vs_try_bind_dest(struct ip_vs_conn *cp);
15521da177e4SLinus Torvalds
ip_vs_dest_hold(struct ip_vs_dest * dest)1553fca9c20aSJulian Anastasov static inline void ip_vs_dest_hold(struct ip_vs_dest *dest)
1554fca9c20aSJulian Anastasov {
1555b54ab92bSReshetova, Elena refcount_inc(&dest->refcnt);
1556fca9c20aSJulian Anastasov }
1557fca9c20aSJulian Anastasov
ip_vs_dest_put(struct ip_vs_dest * dest)1558fca9c20aSJulian Anastasov static inline void ip_vs_dest_put(struct ip_vs_dest *dest)
1559fca9c20aSJulian Anastasov {
15604e857c58SPeter Zijlstra smp_mb__before_atomic();
1561b54ab92bSReshetova, Elena refcount_dec(&dest->refcnt);
1562fca9c20aSJulian Anastasov }
15631da177e4SLinus Torvalds
ip_vs_dest_put_and_free(struct ip_vs_dest * dest)15649e4e948aSJulian Anastasov static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)
15659e4e948aSJulian Anastasov {
1566b54ab92bSReshetova, Elena if (refcount_dec_and_test(&dest->refcnt))
15679e4e948aSJulian Anastasov kfree(dest);
15689e4e948aSJulian Anastasov }
15699e4e948aSJulian Anastasov
157007dcc686SSimon Horman /* IPVS sync daemon data and function prototypes
15711da177e4SLinus Torvalds * (from ip_vs_sync.c)
15721da177e4SLinus Torvalds */
15736ac121d7SEric W. Biederman int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *cfg,
1574e4ff6751SJulian Anastasov int state);
1575b3cf3cbfSEric W. Biederman int stop_sync_thread(struct netns_ipvs *ipvs, int state);
1576b61a8c1aSEric W. Biederman void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts);
15771da177e4SLinus Torvalds
157807dcc686SSimon Horman /* IPVS rate estimator prototypes (from ip_vs_est.c) */
1579705dd344SJulian Anastasov int ip_vs_start_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats);
15800f34d54bSEric W. Biederman void ip_vs_stop_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats);
15815c3a0fd7SJoe Perches void ip_vs_zero_estimator(struct ip_vs_stats *stats);
1582cd67cd5eSJulian Anastasov void ip_vs_read_estimator(struct ip_vs_kstats *dst, struct ip_vs_stats *stats);
1583705dd344SJulian Anastasov void ip_vs_est_reload_start(struct netns_ipvs *ipvs);
1584705dd344SJulian Anastasov int ip_vs_est_kthread_start(struct netns_ipvs *ipvs,
1585705dd344SJulian Anastasov struct ip_vs_est_kt_data *kd);
1586705dd344SJulian Anastasov void ip_vs_est_kthread_stop(struct ip_vs_est_kt_data *kd);
15871da177e4SLinus Torvalds
ip_vs_est_stopped_recalc(struct netns_ipvs * ipvs)1588f0be83d5SJulian Anastasov static inline void ip_vs_est_stopped_recalc(struct netns_ipvs *ipvs)
1589f0be83d5SJulian Anastasov {
1590f0be83d5SJulian Anastasov #ifdef CONFIG_SYSCTL
1591144361c1SJulian Anastasov /* Stop tasks while cpulist is empty or if disabled with flag */
1592144361c1SJulian Anastasov ipvs->est_stopped = !sysctl_run_estimation(ipvs) ||
1593144361c1SJulian Anastasov (ipvs->est_cpulist_valid &&
1594144361c1SJulian Anastasov cpumask_empty(sysctl_est_cpulist(ipvs)));
1595f0be83d5SJulian Anastasov #endif
1596f0be83d5SJulian Anastasov }
1597f0be83d5SJulian Anastasov
ip_vs_est_stopped(struct netns_ipvs * ipvs)1598f0be83d5SJulian Anastasov static inline bool ip_vs_est_stopped(struct netns_ipvs *ipvs)
1599f0be83d5SJulian Anastasov {
1600f0be83d5SJulian Anastasov #ifdef CONFIG_SYSCTL
1601f0be83d5SJulian Anastasov return ipvs->est_stopped;
1602f0be83d5SJulian Anastasov #else
1603f0be83d5SJulian Anastasov return false;
1604f0be83d5SJulian Anastasov #endif
1605f0be83d5SJulian Anastasov }
1606f0be83d5SJulian Anastasov
ip_vs_est_max_threads(struct netns_ipvs * ipvs)1607f0be83d5SJulian Anastasov static inline int ip_vs_est_max_threads(struct netns_ipvs *ipvs)
1608f0be83d5SJulian Anastasov {
1609f0be83d5SJulian Anastasov unsigned int limit = IPVS_EST_CPU_KTHREADS *
1610f0be83d5SJulian Anastasov cpumask_weight(sysctl_est_cpulist(ipvs));
1611f0be83d5SJulian Anastasov
1612f0be83d5SJulian Anastasov return max(1U, limit);
1613f0be83d5SJulian Anastasov }
1614f0be83d5SJulian Anastasov
161507dcc686SSimon Horman /* Various IPVS packet transmitters (from ip_vs_xmit.c) */
16165c3a0fd7SJoe Perches int ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1617d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
16185c3a0fd7SJoe Perches int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1619d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
16205c3a0fd7SJoe Perches int ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1621d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
16225c3a0fd7SJoe Perches int ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
16235c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
16245c3a0fd7SJoe Perches int ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
16255c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
16265c3a0fd7SJoe Perches int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1627d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, int offset,
1628d4383f04SJesper Dangaard Brouer unsigned int hooknum, struct ip_vs_iphdr *iph);
16295c3a0fd7SJoe Perches void ip_vs_dest_dst_rcu_free(struct rcu_head *head);
16301da177e4SLinus Torvalds
1631b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6
16325c3a0fd7SJoe Perches int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1633d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
16345c3a0fd7SJoe Perches int ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
16355c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
16365c3a0fd7SJoe Perches int ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
16375c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
16385c3a0fd7SJoe Perches int ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
16395c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
16405c3a0fd7SJoe Perches int ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1641d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, int offset,
1642d4383f04SJesper Dangaard Brouer unsigned int hooknum, struct ip_vs_iphdr *iph);
1643b3cdd2a7SJulius Volz #endif
16441da177e4SLinus Torvalds
16453a1bbf18SSimon Horman #ifdef CONFIG_SYSCTL
164607dcc686SSimon Horman /* This is a simple mechanism to ignore packets when
16471da177e4SLinus Torvalds * we are loaded. Just set ip_vs_drop_rate to 'n' and
16481da177e4SLinus Torvalds * we start to drop 1/rate of the packets
16491da177e4SLinus Torvalds */
ip_vs_todrop(struct netns_ipvs * ipvs)1650a0840e2eSHans Schillstrom static inline int ip_vs_todrop(struct netns_ipvs *ipvs)
16511da177e4SLinus Torvalds {
1652a0840e2eSHans Schillstrom if (!ipvs->drop_rate)
1653a0840e2eSHans Schillstrom return 0;
1654a0840e2eSHans Schillstrom if (--ipvs->drop_counter > 0)
1655a0840e2eSHans Schillstrom return 0;
1656a0840e2eSHans Schillstrom ipvs->drop_counter = ipvs->drop_rate;
16571da177e4SLinus Torvalds return 1;
16581da177e4SLinus Torvalds }
16593a1bbf18SSimon Horman #else
ip_vs_todrop(struct netns_ipvs * ipvs)16603a1bbf18SSimon Horman static inline int ip_vs_todrop(struct netns_ipvs *ipvs) { return 0; }
16613a1bbf18SSimon Horman #endif
16621da177e4SLinus Torvalds
166335dfb013SAndrew Sy Kim #ifdef CONFIG_SYSCTL
166435dfb013SAndrew Sy Kim /* Enqueue delayed work for expiring no dest connections
166535dfb013SAndrew Sy Kim * Only run when sysctl_expire_nodest=1
166635dfb013SAndrew Sy Kim */
ip_vs_enqueue_expire_nodest_conns(struct netns_ipvs * ipvs)166735dfb013SAndrew Sy Kim static inline void ip_vs_enqueue_expire_nodest_conns(struct netns_ipvs *ipvs)
166835dfb013SAndrew Sy Kim {
166935dfb013SAndrew Sy Kim if (sysctl_expire_nodest_conn(ipvs))
167035dfb013SAndrew Sy Kim queue_delayed_work(system_long_wq,
167135dfb013SAndrew Sy Kim &ipvs->expire_nodest_conn_work, 1);
167235dfb013SAndrew Sy Kim }
167335dfb013SAndrew Sy Kim
167435dfb013SAndrew Sy Kim void ip_vs_expire_nodest_conn_flush(struct netns_ipvs *ipvs);
167535dfb013SAndrew Sy Kim #else
ip_vs_enqueue_expire_nodest_conns(struct netns_ipvs * ipvs)167635dfb013SAndrew Sy Kim static inline void ip_vs_enqueue_expire_nodest_conns(struct netns_ipvs *ipvs) {}
167735dfb013SAndrew Sy Kim #endif
167835dfb013SAndrew Sy Kim
16791da40ab6SJulian Anastasov #define IP_VS_DFWD_METHOD(dest) (atomic_read(&(dest)->conn_flags) & \
16801da40ab6SJulian Anastasov IP_VS_CONN_F_FWD_MASK)
16811da40ab6SJulian Anastasov
168207dcc686SSimon Horman /* ip_vs_fwd_tag returns the forwarding tag of the connection */
16831da177e4SLinus Torvalds #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
16841da177e4SLinus Torvalds
ip_vs_fwd_tag(struct ip_vs_conn * cp)1685732db659SAdrian Bunk static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
16861da177e4SLinus Torvalds {
16871da177e4SLinus Torvalds char fwd;
16881da177e4SLinus Torvalds
16891da177e4SLinus Torvalds switch (IP_VS_FWD_METHOD(cp)) {
16901da177e4SLinus Torvalds case IP_VS_CONN_F_MASQ:
16911da177e4SLinus Torvalds fwd = 'M'; break;
16921da177e4SLinus Torvalds case IP_VS_CONN_F_LOCALNODE:
16931da177e4SLinus Torvalds fwd = 'L'; break;
16941da177e4SLinus Torvalds case IP_VS_CONN_F_TUNNEL:
16951da177e4SLinus Torvalds fwd = 'T'; break;
16961da177e4SLinus Torvalds case IP_VS_CONN_F_DROUTE:
16971da177e4SLinus Torvalds fwd = 'R'; break;
16981da177e4SLinus Torvalds case IP_VS_CONN_F_BYPASS:
16991da177e4SLinus Torvalds fwd = 'B'; break;
17001da177e4SLinus Torvalds default:
17011da177e4SLinus Torvalds fwd = '?'; break;
17021da177e4SLinus Torvalds }
17031da177e4SLinus Torvalds return fwd;
17041da177e4SLinus Torvalds }
17051da177e4SLinus Torvalds
17065c3a0fd7SJoe Perches void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
17071da177e4SLinus Torvalds struct ip_vs_conn *cp, int dir);
17081da177e4SLinus Torvalds
1709b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6
17105c3a0fd7SJoe Perches void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
1711b3cdd2a7SJulius Volz struct ip_vs_conn *cp, int dir);
1712b3cdd2a7SJulius Volz #endif
1713b3cdd2a7SJulius Volz
17145c3a0fd7SJoe Perches __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
17151da177e4SLinus Torvalds
ip_vs_check_diff4(__be32 old,__be32 new,__wsum oldsum)1716f9214b26SAl Viro static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
17171da177e4SLinus Torvalds {
1718f9214b26SAl Viro __be32 diff[2] = { ~old, new };
17191da177e4SLinus Torvalds
172007f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum);
1721f9214b26SAl Viro }
1722f9214b26SAl Viro
17230bbdd42bSJulius Volz #ifdef CONFIG_IP_VS_IPV6
ip_vs_check_diff16(const __be32 * old,const __be32 * new,__wsum oldsum)17240bbdd42bSJulius Volz static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new,
17250bbdd42bSJulius Volz __wsum oldsum)
17260bbdd42bSJulius Volz {
17270bbdd42bSJulius Volz __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
17280bbdd42bSJulius Volz new[3], new[2], new[1], new[0] };
17290bbdd42bSJulius Volz
173007f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum);
17310bbdd42bSJulius Volz }
17320bbdd42bSJulius Volz #endif
17330bbdd42bSJulius Volz
ip_vs_check_diff2(__be16 old,__be16 new,__wsum oldsum)1734f9214b26SAl Viro static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
1735f9214b26SAl Viro {
1736f9214b26SAl Viro __be16 diff[2] = { ~old, new };
1737f9214b26SAl Viro
173807f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum);
17391da177e4SLinus Torvalds }
17401da177e4SLinus Torvalds
174107dcc686SSimon Horman /* Forget current conntrack (unconfirmed) and attach notrack entry */
ip_vs_notrack(struct sk_buff * skb)1742cf356d69SJulian Anastasov static inline void ip_vs_notrack(struct sk_buff *skb)
1743cf356d69SJulian Anastasov {
1744cf356d69SJulian Anastasov #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1745cf356d69SJulian Anastasov enum ip_conntrack_info ctinfo;
174606b69390SJesper Juhl struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1747cf356d69SJulian Anastasov
1748ab8bc7edSFlorian Westphal if (ct) {
174997a6ad13SFlorian Westphal nf_conntrack_put(&ct->ct_general);
1750cc41c84bSFlorian Westphal nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
1751cf356d69SJulian Anastasov }
1752cf356d69SJulian Anastasov #endif
1753cf356d69SJulian Anastasov }
1754cf356d69SJulian Anastasov
1755f4bc17cdSJulian Anastasov #ifdef CONFIG_IP_VS_NFCT
175607dcc686SSimon Horman /* Netfilter connection tracking
1757f4bc17cdSJulian Anastasov * (from ip_vs_nfct.c)
1758f4bc17cdSJulian Anastasov */
ip_vs_conntrack_enabled(struct netns_ipvs * ipvs)1759a0840e2eSHans Schillstrom static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
1760f4bc17cdSJulian Anastasov {
1761a4e2f5a7SSimon Horman #ifdef CONFIG_SYSCTL
1762a0840e2eSHans Schillstrom return ipvs->sysctl_conntrack;
1763a4e2f5a7SSimon Horman #else
1764a4e2f5a7SSimon Horman return 0;
1765a4e2f5a7SSimon Horman #endif
1766f4bc17cdSJulian Anastasov }
1767f4bc17cdSJulian Anastasov
17685c3a0fd7SJoe Perches void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
17696523ce15SJulian Anastasov int outin);
17705c3a0fd7SJoe Perches int ip_vs_confirm_conntrack(struct sk_buff *skb);
17715c3a0fd7SJoe Perches void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct,
1772f4bc17cdSJulian Anastasov struct ip_vs_conn *cp, u_int8_t proto,
1773f4bc17cdSJulian Anastasov const __be16 port, int from_rs);
17745c3a0fd7SJoe Perches void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp);
1775f4bc17cdSJulian Anastasov
1776f4bc17cdSJulian Anastasov #else
1777f4bc17cdSJulian Anastasov
ip_vs_conntrack_enabled(struct netns_ipvs * ipvs)1778a0840e2eSHans Schillstrom static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
1779f4bc17cdSJulian Anastasov {
1780f4bc17cdSJulian Anastasov return 0;
1781f4bc17cdSJulian Anastasov }
1782f4bc17cdSJulian Anastasov
ip_vs_update_conntrack(struct sk_buff * skb,struct ip_vs_conn * cp,int outin)1783f4bc17cdSJulian Anastasov static inline void ip_vs_update_conntrack(struct sk_buff *skb,
1784f4bc17cdSJulian Anastasov struct ip_vs_conn *cp, int outin)
1785f4bc17cdSJulian Anastasov {
1786f4bc17cdSJulian Anastasov }
1787f4bc17cdSJulian Anastasov
ip_vs_confirm_conntrack(struct sk_buff * skb)1788e23ebf0fSKrzysztof Wilczynski static inline int ip_vs_confirm_conntrack(struct sk_buff *skb)
1789f4bc17cdSJulian Anastasov {
1790f4bc17cdSJulian Anastasov return NF_ACCEPT;
1791f4bc17cdSJulian Anastasov }
1792f4bc17cdSJulian Anastasov
ip_vs_conn_drop_conntrack(struct ip_vs_conn * cp)1793f4bc17cdSJulian Anastasov static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
1794f4bc17cdSJulian Anastasov {
1795f4bc17cdSJulian Anastasov }
179607dcc686SSimon Horman #endif /* CONFIG_IP_VS_NFCT */
17976523ce15SJulian Anastasov
1798f0a5e4d7SJulian Anastasov /* Using old conntrack that can not be redirected to another real server? */
ip_vs_conn_uses_old_conntrack(struct ip_vs_conn * cp,struct sk_buff * skb)1799f0a5e4d7SJulian Anastasov static inline bool ip_vs_conn_uses_old_conntrack(struct ip_vs_conn *cp,
1800f719e375SJulian Anastasov struct sk_buff *skb)
1801f719e375SJulian Anastasov {
1802f719e375SJulian Anastasov #ifdef CONFIG_IP_VS_NFCT
1803f719e375SJulian Anastasov enum ip_conntrack_info ctinfo;
1804f719e375SJulian Anastasov struct nf_conn *ct;
1805f719e375SJulian Anastasov
1806f719e375SJulian Anastasov ct = nf_ct_get(skb, &ctinfo);
1807f0a5e4d7SJulian Anastasov if (ct && nf_ct_is_confirmed(ct))
1808f719e375SJulian Anastasov return true;
1809f719e375SJulian Anastasov #endif
1810f719e375SJulian Anastasov return false;
1811f719e375SJulian Anastasov }
1812f719e375SJulian Anastasov
ip_vs_register_conntrack(struct ip_vs_service * svc)181331875d49SJulian Anastasov static inline int ip_vs_register_conntrack(struct ip_vs_service *svc)
181431875d49SJulian Anastasov {
181531875d49SJulian Anastasov #if IS_ENABLED(CONFIG_NF_CONNTRACK)
181631875d49SJulian Anastasov int afmask = (svc->af == AF_INET6) ? 2 : 1;
181731875d49SJulian Anastasov int ret = 0;
181831875d49SJulian Anastasov
181931875d49SJulian Anastasov if (!(svc->conntrack_afmask & afmask)) {
182031875d49SJulian Anastasov ret = nf_ct_netns_get(svc->ipvs->net, svc->af);
182131875d49SJulian Anastasov if (ret >= 0)
182231875d49SJulian Anastasov svc->conntrack_afmask |= afmask;
182331875d49SJulian Anastasov }
182431875d49SJulian Anastasov return ret;
182531875d49SJulian Anastasov #else
182631875d49SJulian Anastasov return 0;
182731875d49SJulian Anastasov #endif
182831875d49SJulian Anastasov }
182931875d49SJulian Anastasov
ip_vs_unregister_conntrack(struct ip_vs_service * svc)183031875d49SJulian Anastasov static inline void ip_vs_unregister_conntrack(struct ip_vs_service *svc)
183131875d49SJulian Anastasov {
183231875d49SJulian Anastasov #if IS_ENABLED(CONFIG_NF_CONNTRACK)
183331875d49SJulian Anastasov int afmask = (svc->af == AF_INET6) ? 2 : 1;
183431875d49SJulian Anastasov
183531875d49SJulian Anastasov if (svc->conntrack_afmask & afmask) {
183631875d49SJulian Anastasov nf_ct_netns_put(svc->ipvs->net, svc->af);
183731875d49SJulian Anastasov svc->conntrack_afmask &= ~afmask;
183831875d49SJulian Anastasov }
183931875d49SJulian Anastasov #endif
184031875d49SJulian Anastasov }
184131875d49SJulian Anastasov
1842857ca897SJulian Anastasov int ip_vs_register_hooks(struct netns_ipvs *ipvs, unsigned int af);
1843857ca897SJulian Anastasov void ip_vs_unregister_hooks(struct netns_ipvs *ipvs, unsigned int af);
1844857ca897SJulian Anastasov
1845c16526a7SSimon Kirby static inline int
ip_vs_dest_conn_overhead(struct ip_vs_dest * dest)1846b552f7e3SChangli Gao ip_vs_dest_conn_overhead(struct ip_vs_dest *dest)
1847b552f7e3SChangli Gao {
184807dcc686SSimon Horman /* We think the overhead of processing active connections is 256
1849b552f7e3SChangli Gao * times higher than that of inactive connections in average. (This
1850b552f7e3SChangli Gao * 256 times might not be accurate, we will change it later) We
1851b552f7e3SChangli Gao * use the following formula to estimate the overhead now:
1852b552f7e3SChangli Gao * dest->activeconns*256 + dest->inactconns
1853b552f7e3SChangli Gao */
1854b552f7e3SChangli Gao return (atomic_read(&dest->activeconns) << 8) +
1855b552f7e3SChangli Gao atomic_read(&dest->inactconns);
1856b552f7e3SChangli Gao }
1857b552f7e3SChangli Gao
1858edf597daSLeon Romanovsky #ifdef CONFIG_IP_VS_PROTO_TCP
1859edf597daSLeon Romanovsky INDIRECT_CALLABLE_DECLARE(int
1860edf597daSLeon Romanovsky tcp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,
1861edf597daSLeon Romanovsky struct ip_vs_conn *cp, struct ip_vs_iphdr *iph));
1862edf597daSLeon Romanovsky #endif
1863edf597daSLeon Romanovsky
1864edf597daSLeon Romanovsky #ifdef CONFIG_IP_VS_PROTO_UDP
1865edf597daSLeon Romanovsky INDIRECT_CALLABLE_DECLARE(int
1866edf597daSLeon Romanovsky udp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,
1867edf597daSLeon Romanovsky struct ip_vs_conn *cp, struct ip_vs_iphdr *iph));
1868edf597daSLeon Romanovsky #endif
1869bc4768ebSJulius Volz #endif /* _NET_IP_VS_H */
1870