1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 207dcc686SSimon Horman /* IP Virtual Server 31da177e4SLinus Torvalds * data structure and functionality definitions 41da177e4SLinus Torvalds */ 51da177e4SLinus Torvalds 6bc4768ebSJulius Volz #ifndef _NET_IP_VS_H 7bc4768ebSJulius Volz #define _NET_IP_VS_H 81da177e4SLinus Torvalds 9bc4768ebSJulius Volz #include <linux/ip_vs.h> /* definitions shared with userland */ 101da177e4SLinus Torvalds 11bc4768ebSJulius Volz #include <asm/types.h> /* for __uXX types */ 12bc4768ebSJulius Volz 131da177e4SLinus Torvalds #include <linux/list.h> /* for struct list_head */ 141da177e4SLinus Torvalds #include <linux/spinlock.h> /* for struct rwlock_t */ 1560063497SArun Sharma #include <linux/atomic.h> /* for struct atomic_t */ 16b54ab92bSReshetova, Elena #include <linux/refcount.h> /* for struct refcount_t */ 17b54ab92bSReshetova, Elena 181da177e4SLinus Torvalds #include <linux/compiler.h> 1914c85021SArnaldo Carvalho de Melo #include <linux/timer.h> 20187f1882SPaul Gortmaker #include <linux/bug.h> 211da177e4SLinus Torvalds 2214c85021SArnaldo Carvalho de Melo #include <net/checksum.h> 23e7ade46aSJulius Volz #include <linux/netfilter.h> /* for union nf_inet_addr */ 241668e010SKOVACS Krisztian #include <linux/ip.h> 25e7ade46aSJulius Volz #include <linux/ipv6.h> /* for struct ipv6hdr */ 264e3fd7a0SAlexey Dobriyan #include <net/ipv6.h> 2754d83efaSJesper Dangaard Brouer #if IS_ENABLED(CONFIG_IP_VS_IPV6) 2863dca2c0SJesper Dangaard Brouer #include <linux/netfilter_ipv6/ip6_tables.h> 2963dca2c0SJesper Dangaard Brouer #endif 30a638e514SJesper Dangaard Brouer #if IS_ENABLED(CONFIG_NF_CONNTRACK) 31f4bc17cdSJulian Anastasov #include <net/netfilter/nf_conntrack.h> 32f4bc17cdSJulian Anastasov #endif 3361b1ab45SHans Schillstrom #include <net/net_namespace.h> /* Netw namespace */ 3461b1ab45SHans Schillstrom 354fd9beefSAlex Gartrell #define IP_VS_HDR_INVERSE 1 364fd9beefSAlex Gartrell #define IP_VS_HDR_ICMP 2 374fd9beefSAlex Gartrell 3807dcc686SSimon Horman /* Generic access of ipvs struct */ 3961b1ab45SHans Schillstrom static inline struct netns_ipvs *net_ipvs(struct net* net) 4061b1ab45SHans Schillstrom { 4161b1ab45SHans Schillstrom return net->ipvs; 4261b1ab45SHans Schillstrom } 4307dcc686SSimon Horman 4407dcc686SSimon Horman /* This one needed for single_open_net since net is stored directly in 4525985edcSLucas De Marchi * private not as a struct i.e. seq_file_net can't be used. 46b17fc996SHans Schillstrom */ 47b17fc996SHans Schillstrom static inline struct net *seq_file_single_net(struct seq_file *seq) 48b17fc996SHans Schillstrom { 49b17fc996SHans Schillstrom #ifdef CONFIG_NET_NS 50b17fc996SHans Schillstrom return (struct net *)seq->private; 51b17fc996SHans Schillstrom #else 52b17fc996SHans Schillstrom return &init_net; 53b17fc996SHans Schillstrom #endif 54b17fc996SHans Schillstrom } 556f7edb48SCatalin(ux) M. BOIE 566f7edb48SCatalin(ux) M. BOIE /* Connections' size value needed by ip_vs_ctl.c */ 576f7edb48SCatalin(ux) M. BOIE extern int ip_vs_conn_tab_size; 586f7edb48SCatalin(ux) M. BOIE 5964aae3cbSJulius Volz struct ip_vs_iphdr { 604fd9beefSAlex Gartrell int hdr_flags; /* ipvs flags */ 61b0e010c5SAlex Gartrell __u32 off; /* Where IP or IPv4 header starts */ 6263dca2c0SJesper Dangaard Brouer __u32 len; /* IPv4 simply where L4 starts 6307dcc686SSimon Horman * IPv6 where L4 Transport Header starts */ 6463dca2c0SJesper Dangaard Brouer __u16 fragoffs; /* IPv6 fragment offset, 0 if first frag (or not frag)*/ 6563dca2c0SJesper Dangaard Brouer __s16 protocol; 6663dca2c0SJesper Dangaard Brouer __s32 flags; 6764aae3cbSJulius Volz union nf_inet_addr saddr; 6864aae3cbSJulius Volz union nf_inet_addr daddr; 6964aae3cbSJulius Volz }; 7064aae3cbSJulius Volz 712f74713dSJesper Dangaard Brouer static inline void *frag_safe_skb_hp(const struct sk_buff *skb, int offset, 726b3d9330SGao Feng int len, void *buffer) 732f74713dSJesper Dangaard Brouer { 742f74713dSJesper Dangaard Brouer return skb_header_pointer(skb, offset, len, buffer); 752f74713dSJesper Dangaard Brouer } 762f74713dSJesper Dangaard Brouer 7763dca2c0SJesper Dangaard Brouer /* This function handles filling *ip_vs_iphdr, both for IPv4 and IPv6. 7863dca2c0SJesper Dangaard Brouer * IPv6 requires some extra work, as finding proper header position, 7963dca2c0SJesper Dangaard Brouer * depend on the IPv6 extension headers. 8063dca2c0SJesper Dangaard Brouer */ 81b0e010c5SAlex Gartrell static inline int 82b0e010c5SAlex Gartrell ip_vs_fill_iph_skb_off(int af, const struct sk_buff *skb, int offset, 834fd9beefSAlex Gartrell int hdr_flags, struct ip_vs_iphdr *iphdr) 8464aae3cbSJulius Volz { 854fd9beefSAlex Gartrell iphdr->hdr_flags = hdr_flags; 86b0e010c5SAlex Gartrell iphdr->off = offset; 874fd9beefSAlex Gartrell 8864aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6 8964aae3cbSJulius Volz if (af == AF_INET6) { 90b0e010c5SAlex Gartrell struct ipv6hdr _iph; 91b0e010c5SAlex Gartrell const struct ipv6hdr *iph = skb_header_pointer( 92b0e010c5SAlex Gartrell skb, offset, sizeof(_iph), &_iph); 93b0e010c5SAlex Gartrell if (!iph) 94b0e010c5SAlex Gartrell return 0; 95b0e010c5SAlex Gartrell 964e3fd7a0SAlexey Dobriyan iphdr->saddr.in6 = iph->saddr; 974e3fd7a0SAlexey Dobriyan iphdr->daddr.in6 = iph->daddr; 986aafeef0SJiri Pirko /* ipv6_find_hdr() updates len, flags */ 99b0e010c5SAlex Gartrell iphdr->len = offset; 10063dca2c0SJesper Dangaard Brouer iphdr->flags = 0; 10163dca2c0SJesper Dangaard Brouer iphdr->protocol = ipv6_find_hdr(skb, &iphdr->len, -1, 10263dca2c0SJesper Dangaard Brouer &iphdr->fragoffs, 10363dca2c0SJesper Dangaard Brouer &iphdr->flags); 104b0e010c5SAlex Gartrell if (iphdr->protocol < 0) 105b0e010c5SAlex Gartrell return 0; 10664aae3cbSJulius Volz } else 10764aae3cbSJulius Volz #endif 10864aae3cbSJulius Volz { 109b0e010c5SAlex Gartrell struct iphdr _iph; 110b0e010c5SAlex Gartrell const struct iphdr *iph = skb_header_pointer( 111b0e010c5SAlex Gartrell skb, offset, sizeof(_iph), &_iph); 112b0e010c5SAlex Gartrell if (!iph) 113b0e010c5SAlex Gartrell return 0; 114b0e010c5SAlex Gartrell 115b0e010c5SAlex Gartrell iphdr->len = offset + iph->ihl * 4; 11663dca2c0SJesper Dangaard Brouer iphdr->fragoffs = 0; 11764aae3cbSJulius Volz iphdr->protocol = iph->protocol; 11864aae3cbSJulius Volz iphdr->saddr.ip = iph->saddr; 11964aae3cbSJulius Volz iphdr->daddr.ip = iph->daddr; 12064aae3cbSJulius Volz } 121b0e010c5SAlex Gartrell 122b0e010c5SAlex Gartrell return 1; 123b0e010c5SAlex Gartrell } 124b0e010c5SAlex Gartrell 125b0e010c5SAlex Gartrell static inline int 1264fd9beefSAlex Gartrell ip_vs_fill_iph_skb_icmp(int af, const struct sk_buff *skb, int offset, 1274fd9beefSAlex Gartrell bool inverse, struct ip_vs_iphdr *iphdr) 128b0e010c5SAlex Gartrell { 1294fd9beefSAlex Gartrell int hdr_flags = IP_VS_HDR_ICMP; 1304fd9beefSAlex Gartrell 1314fd9beefSAlex Gartrell if (inverse) 1324fd9beefSAlex Gartrell hdr_flags |= IP_VS_HDR_INVERSE; 1334fd9beefSAlex Gartrell 1344fd9beefSAlex Gartrell return ip_vs_fill_iph_skb_off(af, skb, offset, hdr_flags, iphdr); 1354fd9beefSAlex Gartrell } 1364fd9beefSAlex Gartrell 1374fd9beefSAlex Gartrell static inline int 1384fd9beefSAlex Gartrell ip_vs_fill_iph_skb(int af, const struct sk_buff *skb, bool inverse, 1394fd9beefSAlex Gartrell struct ip_vs_iphdr *iphdr) 1404fd9beefSAlex Gartrell { 1414fd9beefSAlex Gartrell int hdr_flags = 0; 1424fd9beefSAlex Gartrell 1434fd9beefSAlex Gartrell if (inverse) 1444fd9beefSAlex Gartrell hdr_flags |= IP_VS_HDR_INVERSE; 1454fd9beefSAlex Gartrell 1464fd9beefSAlex Gartrell return ip_vs_fill_iph_skb_off(af, skb, skb_network_offset(skb), 1474fd9beefSAlex Gartrell hdr_flags, iphdr); 1484fd9beefSAlex Gartrell } 1494fd9beefSAlex Gartrell 1504fd9beefSAlex Gartrell static inline bool 1514fd9beefSAlex Gartrell ip_vs_iph_inverse(const struct ip_vs_iphdr *iph) 1524fd9beefSAlex Gartrell { 1534fd9beefSAlex Gartrell return !!(iph->hdr_flags & IP_VS_HDR_INVERSE); 1544fd9beefSAlex Gartrell } 1554fd9beefSAlex Gartrell 1564fd9beefSAlex Gartrell static inline bool 1574fd9beefSAlex Gartrell ip_vs_iph_icmp(const struct ip_vs_iphdr *iph) 1584fd9beefSAlex Gartrell { 1594fd9beefSAlex Gartrell return !!(iph->hdr_flags & IP_VS_HDR_ICMP); 16064aae3cbSJulius Volz } 16164aae3cbSJulius Volz 16264aae3cbSJulius Volz static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst, 16364aae3cbSJulius Volz const union nf_inet_addr *src) 16464aae3cbSJulius Volz { 16564aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6 16664aae3cbSJulius Volz if (af == AF_INET6) 1674e3fd7a0SAlexey Dobriyan dst->in6 = src->in6; 16864aae3cbSJulius Volz else 16964aae3cbSJulius Volz #endif 17064aae3cbSJulius Volz dst->ip = src->ip; 17164aae3cbSJulius Volz } 17264aae3cbSJulius Volz 1739a05475cSJulian Anastasov static inline void ip_vs_addr_set(int af, union nf_inet_addr *dst, 1749a05475cSJulian Anastasov const union nf_inet_addr *src) 1759a05475cSJulian Anastasov { 1769a05475cSJulian Anastasov #ifdef CONFIG_IP_VS_IPV6 1779a05475cSJulian Anastasov if (af == AF_INET6) { 1789a05475cSJulian Anastasov dst->in6 = src->in6; 1799a05475cSJulian Anastasov return; 1809a05475cSJulian Anastasov } 1819a05475cSJulian Anastasov #endif 1829a05475cSJulian Anastasov dst->ip = src->ip; 1839a05475cSJulian Anastasov dst->all[1] = 0; 1849a05475cSJulian Anastasov dst->all[2] = 0; 1859a05475cSJulian Anastasov dst->all[3] = 0; 1869a05475cSJulian Anastasov } 1879a05475cSJulian Anastasov 18864aae3cbSJulius Volz static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a, 18964aae3cbSJulius Volz const union nf_inet_addr *b) 19064aae3cbSJulius Volz { 19164aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6 19264aae3cbSJulius Volz if (af == AF_INET6) 19364aae3cbSJulius Volz return ipv6_addr_equal(&a->in6, &b->in6); 19464aae3cbSJulius Volz #endif 19564aae3cbSJulius Volz return a->ip == b->ip; 19664aae3cbSJulius Volz } 19764aae3cbSJulius Volz 1981da177e4SLinus Torvalds #ifdef CONFIG_IP_VS_DEBUG 19914c85021SArnaldo Carvalho de Melo #include <linux/net.h> 20014c85021SArnaldo Carvalho de Melo 2015c3a0fd7SJoe Perches int ip_vs_get_debug_level(void); 202c842a3adSJulius Volz 203c842a3adSJulius Volz static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len, 204c842a3adSJulius Volz const union nf_inet_addr *addr, 205c842a3adSJulius Volz int *idx) 206c842a3adSJulius Volz { 207c842a3adSJulius Volz int len; 208c842a3adSJulius Volz #ifdef CONFIG_IP_VS_IPV6 209c842a3adSJulius Volz if (af == AF_INET6) 210120b9c14SJesper Dangaard Brouer len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6c]", 2110c6ce78aSHarvey Harrison &addr->in6) + 1; 212c842a3adSJulius Volz else 213c842a3adSJulius Volz #endif 2143685f25dSHarvey Harrison len = snprintf(&buf[*idx], buf_len - *idx, "%pI4", 2153685f25dSHarvey Harrison &addr->ip) + 1; 216c842a3adSJulius Volz 217c842a3adSJulius Volz *idx += len; 218c842a3adSJulius Volz BUG_ON(*idx > buf_len + 1); 219c842a3adSJulius Volz return &buf[*idx - len]; 220c842a3adSJulius Volz } 221c842a3adSJulius Volz 2229aada7acSHannes Eder #define IP_VS_DBG_BUF(level, msg, ...) \ 223c842a3adSJulius Volz do { \ 224c842a3adSJulius Volz char ip_vs_dbg_buf[160]; \ 225c842a3adSJulius Volz int ip_vs_dbg_idx = 0; \ 226c842a3adSJulius Volz if (level <= ip_vs_get_debug_level()) \ 2279aada7acSHannes Eder printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ 228c842a3adSJulius Volz } while (0) 229c842a3adSJulius Volz #define IP_VS_ERR_BUF(msg...) \ 230c842a3adSJulius Volz do { \ 231c842a3adSJulius Volz char ip_vs_dbg_buf[160]; \ 232c842a3adSJulius Volz int ip_vs_dbg_idx = 0; \ 2339aada7acSHannes Eder pr_err(msg); \ 234c842a3adSJulius Volz } while (0) 235c842a3adSJulius Volz 236c842a3adSJulius Volz /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */ 237c842a3adSJulius Volz #define IP_VS_DBG_ADDR(af, addr) \ 238c842a3adSJulius Volz ip_vs_dbg_addr(af, ip_vs_dbg_buf, \ 239c842a3adSJulius Volz sizeof(ip_vs_dbg_buf), addr, \ 240c842a3adSJulius Volz &ip_vs_dbg_idx) 241c842a3adSJulius Volz 2429aada7acSHannes Eder #define IP_VS_DBG(level, msg, ...) \ 2431da177e4SLinus Torvalds do { \ 2441da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \ 2459aada7acSHannes Eder printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ 2461da177e4SLinus Torvalds } while (0) 2479aada7acSHannes Eder #define IP_VS_DBG_RL(msg, ...) \ 2481da177e4SLinus Torvalds do { \ 2491da177e4SLinus Torvalds if (net_ratelimit()) \ 2509aada7acSHannes Eder printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ 2511da177e4SLinus Torvalds } while (0) 2520d79641aSJulian Anastasov #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) \ 2531da177e4SLinus Torvalds do { \ 2541da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \ 2550d79641aSJulian Anastasov pp->debug_packet(af, pp, skb, ofs, msg); \ 2561da177e4SLinus Torvalds } while (0) 2570d79641aSJulian Anastasov #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) \ 2581da177e4SLinus Torvalds do { \ 2591da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level() && \ 2601da177e4SLinus Torvalds net_ratelimit()) \ 2610d79641aSJulian Anastasov pp->debug_packet(af, pp, skb, ofs, msg); \ 2621da177e4SLinus Torvalds } while (0) 2631da177e4SLinus Torvalds #else /* NO DEBUGGING at ALL */ 264c842a3adSJulius Volz #define IP_VS_DBG_BUF(level, msg...) do {} while (0) 265c842a3adSJulius Volz #define IP_VS_ERR_BUF(msg...) do {} while (0) 2661da177e4SLinus Torvalds #define IP_VS_DBG(level, msg...) do {} while (0) 2671da177e4SLinus Torvalds #define IP_VS_DBG_RL(msg...) do {} while (0) 2680d79641aSJulian Anastasov #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) do {} while (0) 2690d79641aSJulian Anastasov #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) do {} while (0) 2701da177e4SLinus Torvalds #endif 2711da177e4SLinus Torvalds 2721da177e4SLinus Torvalds #define IP_VS_BUG() BUG() 2731e3e238eSHannes Eder #define IP_VS_ERR_RL(msg, ...) \ 2741da177e4SLinus Torvalds do { \ 2751da177e4SLinus Torvalds if (net_ratelimit()) \ 2761e3e238eSHannes Eder pr_err(msg, ##__VA_ARGS__); \ 2771da177e4SLinus Torvalds } while (0) 2781da177e4SLinus Torvalds 2791da177e4SLinus Torvalds #ifdef CONFIG_IP_VS_DEBUG 2801da177e4SLinus Torvalds #define EnterFunction(level) \ 2811da177e4SLinus Torvalds do { \ 2821da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \ 2839aada7acSHannes Eder printk(KERN_DEBUG \ 2849aada7acSHannes Eder pr_fmt("Enter: %s, %s line %i\n"), \ 285d5c003b4SHarvey Harrison __func__, __FILE__, __LINE__); \ 2861da177e4SLinus Torvalds } while (0) 2871da177e4SLinus Torvalds #define LeaveFunction(level) \ 2881da177e4SLinus Torvalds do { \ 2891da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \ 2909aada7acSHannes Eder printk(KERN_DEBUG \ 2919aada7acSHannes Eder pr_fmt("Leave: %s, %s line %i\n"), \ 292d5c003b4SHarvey Harrison __func__, __FILE__, __LINE__); \ 2931da177e4SLinus Torvalds } while (0) 2941da177e4SLinus Torvalds #else 2951da177e4SLinus Torvalds #define EnterFunction(level) do {} while (0) 2961da177e4SLinus Torvalds #define LeaveFunction(level) do {} while (0) 2971da177e4SLinus Torvalds #endif 2981da177e4SLinus Torvalds 29907dcc686SSimon Horman /* The port number of FTP service (in network order). */ 300f3a7c66bSHarvey Harrison #define FTPPORT cpu_to_be16(21) 301f3a7c66bSHarvey Harrison #define FTPDATA cpu_to_be16(20) 3021da177e4SLinus Torvalds 30307dcc686SSimon Horman /* TCP State Values */ 3041da177e4SLinus Torvalds enum { 3051da177e4SLinus Torvalds IP_VS_TCP_S_NONE = 0, 3061da177e4SLinus Torvalds IP_VS_TCP_S_ESTABLISHED, 3071da177e4SLinus Torvalds IP_VS_TCP_S_SYN_SENT, 3081da177e4SLinus Torvalds IP_VS_TCP_S_SYN_RECV, 3091da177e4SLinus Torvalds IP_VS_TCP_S_FIN_WAIT, 3101da177e4SLinus Torvalds IP_VS_TCP_S_TIME_WAIT, 3111da177e4SLinus Torvalds IP_VS_TCP_S_CLOSE, 3121da177e4SLinus Torvalds IP_VS_TCP_S_CLOSE_WAIT, 3131da177e4SLinus Torvalds IP_VS_TCP_S_LAST_ACK, 3141da177e4SLinus Torvalds IP_VS_TCP_S_LISTEN, 3151da177e4SLinus Torvalds IP_VS_TCP_S_SYNACK, 3161da177e4SLinus Torvalds IP_VS_TCP_S_LAST 3171da177e4SLinus Torvalds }; 3181da177e4SLinus Torvalds 31907dcc686SSimon Horman /* UDP State Values */ 3201da177e4SLinus Torvalds enum { 3211da177e4SLinus Torvalds IP_VS_UDP_S_NORMAL, 3221da177e4SLinus Torvalds IP_VS_UDP_S_LAST, 3231da177e4SLinus Torvalds }; 3241da177e4SLinus Torvalds 32507dcc686SSimon Horman /* ICMP State Values */ 3261da177e4SLinus Torvalds enum { 3271da177e4SLinus Torvalds IP_VS_ICMP_S_NORMAL, 3281da177e4SLinus Torvalds IP_VS_ICMP_S_LAST, 3291da177e4SLinus Torvalds }; 3301da177e4SLinus Torvalds 33107dcc686SSimon Horman /* SCTP State Values */ 3322906f66aSVenkata Mohan Reddy enum ip_vs_sctp_states { 3332906f66aSVenkata Mohan Reddy IP_VS_SCTP_S_NONE, 33461e7c420SJulian Anastasov IP_VS_SCTP_S_INIT1, 33561e7c420SJulian Anastasov IP_VS_SCTP_S_INIT, 33661e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE_SENT, 33761e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE_REPLIED, 33861e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE_WAIT, 33961e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE, 34061e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE_ECHOED, 3412906f66aSVenkata Mohan Reddy IP_VS_SCTP_S_ESTABLISHED, 34261e7c420SJulian Anastasov IP_VS_SCTP_S_SHUTDOWN_SENT, 34361e7c420SJulian Anastasov IP_VS_SCTP_S_SHUTDOWN_RECEIVED, 34461e7c420SJulian Anastasov IP_VS_SCTP_S_SHUTDOWN_ACK_SENT, 34561e7c420SJulian Anastasov IP_VS_SCTP_S_REJECTED, 3462906f66aSVenkata Mohan Reddy IP_VS_SCTP_S_CLOSED, 3472906f66aSVenkata Mohan Reddy IP_VS_SCTP_S_LAST 3482906f66aSVenkata Mohan Reddy }; 3492906f66aSVenkata Mohan Reddy 35007dcc686SSimon Horman /* Delta sequence info structure 3511da177e4SLinus Torvalds * Each ip_vs_conn has 2 (output AND input seq. changes). 3521da177e4SLinus Torvalds * Only used in the VS/NAT. 3531da177e4SLinus Torvalds */ 3541da177e4SLinus Torvalds struct ip_vs_seq { 3551da177e4SLinus Torvalds __u32 init_seq; /* Add delta from this seq */ 3561da177e4SLinus Torvalds __u32 delta; /* Delta in sequence numbers */ 3571da177e4SLinus Torvalds __u32 previous_delta; /* Delta in sequence numbers 35807dcc686SSimon Horman * before last resized pkt */ 3591da177e4SLinus Torvalds }; 3601da177e4SLinus Torvalds 36107dcc686SSimon Horman /* counters per cpu */ 362b17fc996SHans Schillstrom struct ip_vs_counters { 363cd67cd5eSJulian Anastasov __u64 conns; /* connections scheduled */ 364cd67cd5eSJulian Anastasov __u64 inpkts; /* incoming packets */ 365cd67cd5eSJulian Anastasov __u64 outpkts; /* outgoing packets */ 366b17fc996SHans Schillstrom __u64 inbytes; /* incoming bytes */ 367b17fc996SHans Schillstrom __u64 outbytes; /* outgoing bytes */ 368b17fc996SHans Schillstrom }; 36907dcc686SSimon Horman /* Stats per cpu */ 370b17fc996SHans Schillstrom struct ip_vs_cpu_stats { 371cd67cd5eSJulian Anastasov struct ip_vs_counters cnt; 372b17fc996SHans Schillstrom struct u64_stats_sync syncp; 373b17fc996SHans Schillstrom }; 3741da177e4SLinus Torvalds 37507dcc686SSimon Horman /* IPVS statistics objects */ 3763a14a313SSven Wegener struct ip_vs_estimator { 3773a14a313SSven Wegener struct list_head list; 3783a14a313SSven Wegener 3793a14a313SSven Wegener u64 last_inbytes; 3803a14a313SSven Wegener u64 last_outbytes; 381cd67cd5eSJulian Anastasov u64 last_conns; 382cd67cd5eSJulian Anastasov u64 last_inpkts; 383cd67cd5eSJulian Anastasov u64 last_outpkts; 3843a14a313SSven Wegener 385cd67cd5eSJulian Anastasov u64 cps; 386cd67cd5eSJulian Anastasov u64 inpps; 387cd67cd5eSJulian Anastasov u64 outpps; 388cd67cd5eSJulian Anastasov u64 inbps; 389cd67cd5eSJulian Anastasov u64 outbps; 390cd67cd5eSJulian Anastasov }; 391cd67cd5eSJulian Anastasov 392cd67cd5eSJulian Anastasov /* 393cd67cd5eSJulian Anastasov * IPVS statistics object, 64-bit kernel version of struct ip_vs_stats_user 394cd67cd5eSJulian Anastasov */ 395cd67cd5eSJulian Anastasov struct ip_vs_kstats { 396cd67cd5eSJulian Anastasov u64 conns; /* connections scheduled */ 397cd67cd5eSJulian Anastasov u64 inpkts; /* incoming packets */ 398cd67cd5eSJulian Anastasov u64 outpkts; /* outgoing packets */ 399cd67cd5eSJulian Anastasov u64 inbytes; /* incoming bytes */ 400cd67cd5eSJulian Anastasov u64 outbytes; /* outgoing bytes */ 401cd67cd5eSJulian Anastasov 402cd67cd5eSJulian Anastasov u64 cps; /* current connection rate */ 403cd67cd5eSJulian Anastasov u64 inpps; /* current in packet rate */ 404cd67cd5eSJulian Anastasov u64 outpps; /* current out packet rate */ 405cd67cd5eSJulian Anastasov u64 inbps; /* current in byte rate */ 406cd67cd5eSJulian Anastasov u64 outbps; /* current out byte rate */ 4073a14a313SSven Wegener }; 4083a14a313SSven Wegener 409fd2c3ef7SEric Dumazet struct ip_vs_stats { 410cd67cd5eSJulian Anastasov struct ip_vs_kstats kstats; /* kernel statistics */ 411e9c0ce23SSven Wegener struct ip_vs_estimator est; /* estimator */ 412b962abdcSJulian Anastasov struct ip_vs_cpu_stats __percpu *cpustats; /* per cpu counters */ 4131da177e4SLinus Torvalds spinlock_t lock; /* spin lock */ 414cd67cd5eSJulian Anastasov struct ip_vs_kstats kstats0; /* reset values */ 4151da177e4SLinus Torvalds }; 4161da177e4SLinus Torvalds 41714c85021SArnaldo Carvalho de Melo struct dst_entry; 41814c85021SArnaldo Carvalho de Melo struct iphdr; 4191da177e4SLinus Torvalds struct ip_vs_conn; 4201da177e4SLinus Torvalds struct ip_vs_app; 42114c85021SArnaldo Carvalho de Melo struct sk_buff; 422252c6410SHans Schillstrom struct ip_vs_proto_data; 4231da177e4SLinus Torvalds 4241da177e4SLinus Torvalds struct ip_vs_protocol { 4251da177e4SLinus Torvalds struct ip_vs_protocol *next; 4261da177e4SLinus Torvalds char *name; 4272ad17defSJulian Anastasov u16 protocol; 4282ad17defSJulian Anastasov u16 num_states; 4291da177e4SLinus Torvalds int dont_defrag; 4301da177e4SLinus Torvalds 4311da177e4SLinus Torvalds void (*init)(struct ip_vs_protocol *pp); 4321da177e4SLinus Torvalds 4331da177e4SLinus Torvalds void (*exit)(struct ip_vs_protocol *pp); 4341da177e4SLinus Torvalds 4351281a9c2SEric W. Biederman int (*init_netns)(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd); 436252c6410SHans Schillstrom 4371281a9c2SEric W. Biederman void (*exit_netns)(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd); 438252c6410SHans Schillstrom 439d8f44c33SEric W. Biederman int (*conn_schedule)(struct netns_ipvs *ipvs, 440d8f44c33SEric W. Biederman int af, struct sk_buff *skb, 4419330419dSHans Schillstrom struct ip_vs_proto_data *pd, 442d4383f04SJesper Dangaard Brouer int *verdict, struct ip_vs_conn **cpp, 443d4383f04SJesper Dangaard Brouer struct ip_vs_iphdr *iph); 4441da177e4SLinus Torvalds 4451da177e4SLinus Torvalds struct ip_vs_conn * 446ab161976SEric W. Biederman (*conn_in_get)(struct netns_ipvs *ipvs, 447ab161976SEric W. Biederman int af, 44851ef348bSJulius Volz const struct sk_buff *skb, 449802c41adSAlex Gartrell const struct ip_vs_iphdr *iph); 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvalds struct ip_vs_conn * 4520cf705c8SEric W. Biederman (*conn_out_get)(struct netns_ipvs *ipvs, 4530cf705c8SEric W. Biederman int af, 45451ef348bSJulius Volz const struct sk_buff *skb, 455802c41adSAlex Gartrell const struct ip_vs_iphdr *iph); 4561da177e4SLinus Torvalds 457d4383f04SJesper Dangaard Brouer int (*snat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp, 458d4383f04SJesper Dangaard Brouer struct ip_vs_conn *cp, struct ip_vs_iphdr *iph); 4591da177e4SLinus Torvalds 460d4383f04SJesper Dangaard Brouer int (*dnat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp, 461d4383f04SJesper Dangaard Brouer struct ip_vs_conn *cp, struct ip_vs_iphdr *iph); 4621da177e4SLinus Torvalds 46351ef348bSJulius Volz int (*csum_check)(int af, struct sk_buff *skb, 46451ef348bSJulius Volz struct ip_vs_protocol *pp); 4651da177e4SLinus Torvalds 4661da177e4SLinus Torvalds const char *(*state_name)(int state); 4671da177e4SLinus Torvalds 4684a516f11SSimon Horman void (*state_transition)(struct ip_vs_conn *cp, int direction, 4691da177e4SLinus Torvalds const struct sk_buff *skb, 4709330419dSHans Schillstrom struct ip_vs_proto_data *pd); 4711da177e4SLinus Torvalds 47219648918SEric W. Biederman int (*register_app)(struct netns_ipvs *ipvs, struct ip_vs_app *inc); 4731da177e4SLinus Torvalds 47419648918SEric W. Biederman void (*unregister_app)(struct netns_ipvs *ipvs, struct ip_vs_app *inc); 4751da177e4SLinus Torvalds 4761da177e4SLinus Torvalds int (*app_conn_bind)(struct ip_vs_conn *cp); 4771da177e4SLinus Torvalds 4780d79641aSJulian Anastasov void (*debug_packet)(int af, struct ip_vs_protocol *pp, 4791da177e4SLinus Torvalds const struct sk_buff *skb, 4801da177e4SLinus Torvalds int offset, 4811da177e4SLinus Torvalds const char *msg); 4821da177e4SLinus Torvalds 4839330419dSHans Schillstrom void (*timeout_change)(struct ip_vs_proto_data *pd, int flags); 4841da177e4SLinus Torvalds }; 4851da177e4SLinus Torvalds 48607dcc686SSimon Horman /* protocol data per netns */ 487252c6410SHans Schillstrom struct ip_vs_proto_data { 488252c6410SHans Schillstrom struct ip_vs_proto_data *next; 489252c6410SHans Schillstrom struct ip_vs_protocol *pp; 490252c6410SHans Schillstrom int *timeout_table; /* protocol timeout table */ 491252c6410SHans Schillstrom atomic_t appcnt; /* counter of proto app incs. */ 492252c6410SHans Schillstrom struct tcp_states_t *tcp_state_table; 493252c6410SHans Schillstrom }; 494252c6410SHans Schillstrom 4955c3a0fd7SJoe Perches struct ip_vs_protocol *ip_vs_proto_get(unsigned short proto); 49618d6ade6SEric W. Biederman struct ip_vs_proto_data *ip_vs_proto_data_get(struct netns_ipvs *ipvs, 497252c6410SHans Schillstrom unsigned short proto); 4981da177e4SLinus Torvalds 499f11017ecSSimon Horman struct ip_vs_conn_param { 500e64e2b46SEric W. Biederman struct netns_ipvs *ipvs; 501f11017ecSSimon Horman const union nf_inet_addr *caddr; 502f11017ecSSimon Horman const union nf_inet_addr *vaddr; 503f11017ecSSimon Horman __be16 cport; 504f11017ecSSimon Horman __be16 vport; 505f11017ecSSimon Horman __u16 protocol; 506f11017ecSSimon Horman u16 af; 50785999283SSimon Horman 50885999283SSimon Horman const struct ip_vs_pe *pe; 50985999283SSimon Horman char *pe_data; 51085999283SSimon Horman __u8 pe_data_len; 511f11017ecSSimon Horman }; 512f11017ecSSimon Horman 51307dcc686SSimon Horman /* IP_VS structure allocated for each dynamically scheduled connection */ 5141da177e4SLinus Torvalds struct ip_vs_conn { 515731109e7SChangli Gao struct hlist_node c_list; /* hashed list heads */ 5161da177e4SLinus Torvalds /* Protocol, addresses and port numbers */ 5176e67e586SHans Schillstrom __be16 cport; 5186e67e586SHans Schillstrom __be16 dport; 5191845ed0bSJulian Anastasov __be16 vport; 5201845ed0bSJulian Anastasov u16 af; /* address family */ 521e7ade46aSJulius Volz union nf_inet_addr caddr; /* client address */ 522e7ade46aSJulius Volz union nf_inet_addr vaddr; /* virtual address */ 523e7ade46aSJulius Volz union nf_inet_addr daddr; /* destination address */ 5243575792eSJulian Anastasov volatile __u32 flags; /* status flags */ 5251da177e4SLinus Torvalds __u16 protocol; /* Which protocol (TCP/UDP) */ 526ba38528aSAlex Gartrell __u16 daf; /* Address family of the dest */ 52758dbc6f2SEric W. Biederman struct netns_ipvs *ipvs; 5281da177e4SLinus Torvalds 5291da177e4SLinus Torvalds /* counter and timer */ 530b54ab92bSReshetova, Elena refcount_t refcnt; /* reference count */ 5311da177e4SLinus Torvalds struct timer_list timer; /* Expiration timer */ 5321da177e4SLinus Torvalds volatile unsigned long timeout; /* timeout */ 5331da177e4SLinus Torvalds 5341da177e4SLinus Torvalds /* Flags and state transition */ 5351da177e4SLinus Torvalds spinlock_t lock; /* lock for state transition */ 5361da177e4SLinus Torvalds volatile __u16 state; /* state info */ 537efac5276SRumen G. Bogdanovski volatile __u16 old_state; /* old state, to be used for 538efac5276SRumen G. Bogdanovski * state transition triggerd 539efac5276SRumen G. Bogdanovski * synchronization 540efac5276SRumen G. Bogdanovski */ 5411845ed0bSJulian Anastasov __u32 fwmark; /* Fire wall mark from skb */ 542749c42b6SJulian Anastasov unsigned long sync_endtime; /* jiffies + sent_retries */ 5431da177e4SLinus Torvalds 5441da177e4SLinus Torvalds /* Control members */ 5451da177e4SLinus Torvalds struct ip_vs_conn *control; /* Master control connection */ 5461da177e4SLinus Torvalds atomic_t n_control; /* Number of controlled ones */ 5471da177e4SLinus Torvalds struct ip_vs_dest *dest; /* real server */ 5481da177e4SLinus Torvalds atomic_t in_pkts; /* incoming packet counter */ 5491da177e4SLinus Torvalds 55007dcc686SSimon Horman /* Packet transmitter for different forwarding methods. If it 55107dcc686SSimon Horman * mangles the packet, it must return NF_DROP or better NF_STOLEN, 55207dcc686SSimon Horman * otherwise this must be changed to a sk_buff **. 55307dcc686SSimon Horman * NF_ACCEPT can be returned when destination is local. 5541da177e4SLinus Torvalds */ 5551da177e4SLinus Torvalds int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp, 556d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 5571da177e4SLinus Torvalds 5581da177e4SLinus Torvalds /* Note: we can group the following members into a structure, 55907dcc686SSimon Horman * in order to save more space, and the following members are 56007dcc686SSimon Horman * only used in VS/NAT anyway 56107dcc686SSimon Horman */ 5621da177e4SLinus Torvalds struct ip_vs_app *app; /* bound ip_vs_app object */ 5631da177e4SLinus Torvalds void *app_data; /* Application private data */ 5641da177e4SLinus Torvalds struct ip_vs_seq in_seq; /* incoming seq. struct */ 5651da177e4SLinus Torvalds struct ip_vs_seq out_seq; /* outgoing seq. struct */ 56685999283SSimon Horman 567e9e5eee8SSimon Horman const struct ip_vs_pe *pe; 56885999283SSimon Horman char *pe_data; 56985999283SSimon Horman __u8 pe_data_len; 570088339a5SJulian Anastasov 571088339a5SJulian Anastasov struct rcu_head rcu_head; 5721da177e4SLinus Torvalds }; 5731da177e4SLinus Torvalds 57407dcc686SSimon Horman /* Extended internal versions of struct ip_vs_service_user and ip_vs_dest_user 57507dcc686SSimon Horman * for IPv6 support. 576c860c6b1SJulius Volz * 577c860c6b1SJulius Volz * We need these to conveniently pass around service and destination 578c860c6b1SJulius Volz * options, but unfortunately, we also need to keep the old definitions to 579c860c6b1SJulius Volz * maintain userspace backwards compatibility for the setsockopt interface. 580c860c6b1SJulius Volz */ 581c860c6b1SJulius Volz struct ip_vs_service_user_kern { 582c860c6b1SJulius Volz /* virtual service addresses */ 583c860c6b1SJulius Volz u16 af; 584c860c6b1SJulius Volz u16 protocol; 585c860c6b1SJulius Volz union nf_inet_addr addr; /* virtual ip address */ 5860a925864SJulian Anastasov __be16 port; 587c860c6b1SJulius Volz u32 fwmark; /* firwall mark of service */ 588c860c6b1SJulius Volz 589c860c6b1SJulius Volz /* virtual service options */ 590c860c6b1SJulius Volz char *sched_name; 5910d1e71b0SSimon Horman char *pe_name; 59295c96174SEric Dumazet unsigned int flags; /* virtual service flags */ 59395c96174SEric Dumazet unsigned int timeout; /* persistent timeout in sec */ 5940a925864SJulian Anastasov __be32 netmask; /* persistent netmask or plen */ 595c860c6b1SJulius Volz }; 596c860c6b1SJulius Volz 597c860c6b1SJulius Volz 598c860c6b1SJulius Volz struct ip_vs_dest_user_kern { 599c860c6b1SJulius Volz /* destination server address */ 600c860c6b1SJulius Volz union nf_inet_addr addr; 6010a925864SJulian Anastasov __be16 port; 602c860c6b1SJulius Volz 603c860c6b1SJulius Volz /* real server options */ 60495c96174SEric Dumazet unsigned int conn_flags; /* connection flags */ 605c860c6b1SJulius Volz int weight; /* destination weight */ 606c860c6b1SJulius Volz 607c860c6b1SJulius Volz /* thresholds for active connections */ 608c860c6b1SJulius Volz u32 u_threshold; /* upper threshold */ 609c860c6b1SJulius Volz u32 l_threshold; /* lower threshold */ 6106cff339bSAlex Gartrell 6116cff339bSAlex Gartrell /* Address family of addr */ 6126cff339bSAlex Gartrell u16 af; 613c860c6b1SJulius Volz }; 614c860c6b1SJulius Volz 615c860c6b1SJulius Volz 616c860c6b1SJulius Volz /* 61707dcc686SSimon Horman * The information about the virtual service offered to the net and the 61807dcc686SSimon Horman * forwarding entries. 6191da177e4SLinus Torvalds */ 6201da177e4SLinus Torvalds struct ip_vs_service { 621ceec4c38SJulian Anastasov struct hlist_node s_list; /* for normal service table */ 622ceec4c38SJulian Anastasov struct hlist_node f_list; /* for fwmark-based service table */ 6231da177e4SLinus Torvalds atomic_t refcnt; /* reference counter */ 6241da177e4SLinus Torvalds 625e7ade46aSJulius Volz u16 af; /* address family */ 6261da177e4SLinus Torvalds __u16 protocol; /* which protocol (TCP/UDP) */ 627e7ade46aSJulius Volz union nf_inet_addr addr; /* IP address for virtual service */ 628014d730dSAl Viro __be16 port; /* port number for the service */ 6291da177e4SLinus Torvalds __u32 fwmark; /* firewall mark of the service */ 63095c96174SEric Dumazet unsigned int flags; /* service status flags */ 63195c96174SEric Dumazet unsigned int timeout; /* persistent timeout in ticks */ 6320a925864SJulian Anastasov __be32 netmask; /* grouping granularity, mask/plen */ 6333109d2f2SEric W. Biederman struct netns_ipvs *ipvs; 6341da177e4SLinus Torvalds 6351da177e4SLinus Torvalds struct list_head destinations; /* real server d-linked list */ 6361da177e4SLinus Torvalds __u32 num_dests; /* number of servers */ 6371da177e4SLinus Torvalds struct ip_vs_stats stats; /* statistics for the service */ 6381da177e4SLinus Torvalds 6391da177e4SLinus Torvalds /* for scheduling */ 640ceec4c38SJulian Anastasov struct ip_vs_scheduler __rcu *scheduler; /* bound scheduler object */ 641ba3a3ce1SJulian Anastasov spinlock_t sched_lock; /* lock sched_data */ 6421da177e4SLinus Torvalds void *sched_data; /* scheduler application data */ 64385999283SSimon Horman 64485999283SSimon Horman /* alternate persistence engine */ 645ceec4c38SJulian Anastasov struct ip_vs_pe __rcu *pe; 646*31875d49SJulian Anastasov int conntrack_afmask; 647ceec4c38SJulian Anastasov 648ceec4c38SJulian Anastasov struct rcu_head rcu_head; 6491da177e4SLinus Torvalds }; 6501da177e4SLinus Torvalds 651026ace06SJulian Anastasov /* Information for cached dst */ 652026ace06SJulian Anastasov struct ip_vs_dest_dst { 653026ace06SJulian Anastasov struct dst_entry *dst_cache; /* destination cache entry */ 654026ace06SJulian Anastasov u32 dst_cookie; 655026ace06SJulian Anastasov union nf_inet_addr dst_saddr; 656026ace06SJulian Anastasov struct rcu_head rcu_head; 657026ace06SJulian Anastasov }; 6581da177e4SLinus Torvalds 65907dcc686SSimon Horman /* The real server destination forwarding entry with ip address, port number, 66007dcc686SSimon Horman * and so on. 6611da177e4SLinus Torvalds */ 6621da177e4SLinus Torvalds struct ip_vs_dest { 6631da177e4SLinus Torvalds struct list_head n_list; /* for the dests in the service */ 664276472eaSJulian Anastasov struct hlist_node d_list; /* for table with all the dests */ 6651da177e4SLinus Torvalds 666e7ade46aSJulius Volz u16 af; /* address family */ 667014d730dSAl Viro __be16 port; /* port number of the server */ 668f2431e6eSHans Schillstrom union nf_inet_addr addr; /* IP address of the server */ 66995c96174SEric Dumazet volatile unsigned int flags; /* dest status flags */ 6701da177e4SLinus Torvalds atomic_t conn_flags; /* flags to copy to conn */ 6711da177e4SLinus Torvalds atomic_t weight; /* server weight */ 6721da177e4SLinus Torvalds 673b54ab92bSReshetova, Elena refcount_t refcnt; /* reference counter */ 6741da177e4SLinus Torvalds struct ip_vs_stats stats; /* statistics */ 675bcbde4c0SJulian Anastasov unsigned long idle_start; /* start time, jiffies */ 6761da177e4SLinus Torvalds 6771da177e4SLinus Torvalds /* connection counters and thresholds */ 6781da177e4SLinus Torvalds atomic_t activeconns; /* active connections */ 6791da177e4SLinus Torvalds atomic_t inactconns; /* inactive connections */ 6801da177e4SLinus Torvalds atomic_t persistconns; /* persistent connections */ 6811da177e4SLinus Torvalds __u32 u_threshold; /* upper threshold */ 6821da177e4SLinus Torvalds __u32 l_threshold; /* lower threshold */ 6831da177e4SLinus Torvalds 6841da177e4SLinus Torvalds /* for destination cache */ 6851da177e4SLinus Torvalds spinlock_t dst_lock; /* lock of dst_cache */ 686026ace06SJulian Anastasov struct ip_vs_dest_dst __rcu *dest_dst; /* cached dst info */ 6871da177e4SLinus Torvalds 6881da177e4SLinus Torvalds /* for virtual service */ 689bcbde4c0SJulian Anastasov struct ip_vs_service __rcu *svc; /* service it belongs to */ 6901da177e4SLinus Torvalds __u16 protocol; /* which protocol (TCP/UDP) */ 691014d730dSAl Viro __be16 vport; /* virtual port number */ 692f2431e6eSHans Schillstrom union nf_inet_addr vaddr; /* virtual IP address */ 6931da177e4SLinus Torvalds __u32 vfwmark; /* firewall mark of service */ 694276472eaSJulian Anastasov 695578bc3efSJulian Anastasov struct list_head t_list; /* in dest_trash */ 696276472eaSJulian Anastasov unsigned int in_rs_table:1; /* we are in rs_table */ 6971da177e4SLinus Torvalds }; 6981da177e4SLinus Torvalds 69907dcc686SSimon Horman /* The scheduler object */ 7001da177e4SLinus Torvalds struct ip_vs_scheduler { 7011da177e4SLinus Torvalds struct list_head n_list; /* d-linked list head */ 7021da177e4SLinus Torvalds char *name; /* scheduler name */ 7031da177e4SLinus Torvalds atomic_t refcnt; /* reference counter */ 7041da177e4SLinus Torvalds struct module *module; /* THIS_MODULE/NULL */ 7051da177e4SLinus Torvalds 7061da177e4SLinus Torvalds /* scheduler initializing service */ 7071da177e4SLinus Torvalds int (*init_service)(struct ip_vs_service *svc); 7081da177e4SLinus Torvalds /* scheduling service finish */ 709ed3ffc4eSJulian Anastasov void (*done_service)(struct ip_vs_service *svc); 7106b6df466SJulian Anastasov /* dest is linked */ 7116b6df466SJulian Anastasov int (*add_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest); 7126b6df466SJulian Anastasov /* dest is unlinked */ 7136b6df466SJulian Anastasov int (*del_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest); 7146b6df466SJulian Anastasov /* dest is updated */ 7156b6df466SJulian Anastasov int (*upd_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest); 7161da177e4SLinus Torvalds 7171da177e4SLinus Torvalds /* selecting a server from the given service */ 7181da177e4SLinus Torvalds struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc, 719bba54de5SJulian Anastasov const struct sk_buff *skb, 720bba54de5SJulian Anastasov struct ip_vs_iphdr *iph); 7211da177e4SLinus Torvalds }; 7221da177e4SLinus Torvalds 72385999283SSimon Horman /* The persistence engine object */ 72485999283SSimon Horman struct ip_vs_pe { 72585999283SSimon Horman struct list_head n_list; /* d-linked list head */ 72685999283SSimon Horman char *name; /* scheduler name */ 72785999283SSimon Horman atomic_t refcnt; /* reference counter */ 72885999283SSimon Horman struct module *module; /* THIS_MODULE/NULL */ 72985999283SSimon Horman 73085999283SSimon Horman /* get the connection template, if any */ 73185999283SSimon Horman int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb); 73285999283SSimon Horman bool (*ct_match)(const struct ip_vs_conn_param *p, 73385999283SSimon Horman struct ip_vs_conn *ct); 73485999283SSimon Horman u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval, 73585999283SSimon Horman bool inverse); 736a3c918acSSimon Horman int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf); 73739b97223SMarco Angaroni /* create connections for real-server outgoing packets */ 73839b97223SMarco Angaroni struct ip_vs_conn* (*conn_out)(struct ip_vs_service *svc, 73939b97223SMarco Angaroni struct ip_vs_dest *dest, 74039b97223SMarco Angaroni struct sk_buff *skb, 74139b97223SMarco Angaroni const struct ip_vs_iphdr *iph, 74239b97223SMarco Angaroni __be16 dport, __be16 cport); 74385999283SSimon Horman }; 7441da177e4SLinus Torvalds 74507dcc686SSimon Horman /* The application module object (a.k.a. app incarnation) */ 746fd2c3ef7SEric Dumazet struct ip_vs_app { 7471da177e4SLinus Torvalds struct list_head a_list; /* member in app list */ 7481da177e4SLinus Torvalds int type; /* IP_VS_APP_TYPE_xxx */ 7491da177e4SLinus Torvalds char *name; /* application module name */ 7501da177e4SLinus Torvalds __u16 protocol; 7511da177e4SLinus Torvalds struct module *module; /* THIS_MODULE/NULL */ 7521da177e4SLinus Torvalds struct list_head incs_list; /* list of incarnations */ 7531da177e4SLinus Torvalds 7541da177e4SLinus Torvalds /* members for application incarnations */ 7551da177e4SLinus Torvalds struct list_head p_list; /* member in proto app list */ 7561da177e4SLinus Torvalds struct ip_vs_app *app; /* its real application */ 757014d730dSAl Viro __be16 port; /* port number in net order */ 7581da177e4SLinus Torvalds atomic_t usecnt; /* usage counter */ 759363c97d7SJulian Anastasov struct rcu_head rcu_head; 7601da177e4SLinus Torvalds 76107dcc686SSimon Horman /* output hook: Process packet in inout direction, diff set for TCP. 7628b27b10fSJulian Anastasov * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok, 7638b27b10fSJulian Anastasov * 2=Mangled but checksum was not updated 7648b27b10fSJulian Anastasov */ 7651da177e4SLinus Torvalds int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *, 7663db05feaSHerbert Xu struct sk_buff *, int *diff); 7671da177e4SLinus Torvalds 76807dcc686SSimon Horman /* input hook: Process packet in outin direction, diff set for TCP. 7698b27b10fSJulian Anastasov * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok, 7708b27b10fSJulian Anastasov * 2=Mangled but checksum was not updated 7718b27b10fSJulian Anastasov */ 7721da177e4SLinus Torvalds int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *, 7733db05feaSHerbert Xu struct sk_buff *, int *diff); 7741da177e4SLinus Torvalds 7751da177e4SLinus Torvalds /* ip_vs_app initializer */ 7761da177e4SLinus Torvalds int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *); 7771da177e4SLinus Torvalds 7781da177e4SLinus Torvalds /* ip_vs_app finish */ 7791da177e4SLinus Torvalds int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *); 7801da177e4SLinus Torvalds 7811da177e4SLinus Torvalds 7821da177e4SLinus Torvalds /* not used now */ 7831da177e4SLinus Torvalds int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *, 7841da177e4SLinus Torvalds struct ip_vs_protocol *); 7851da177e4SLinus Torvalds 7861da177e4SLinus Torvalds void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *); 7871da177e4SLinus Torvalds 7881da177e4SLinus Torvalds int * timeout_table; 7891da177e4SLinus Torvalds int * timeouts; 7901da177e4SLinus Torvalds int timeouts_size; 7911da177e4SLinus Torvalds 7921da177e4SLinus Torvalds int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app, 7931da177e4SLinus Torvalds int *verdict, struct ip_vs_conn **cpp); 7941da177e4SLinus Torvalds 7951da177e4SLinus Torvalds struct ip_vs_conn * 7961da177e4SLinus Torvalds (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app, 797d4383f04SJesper Dangaard Brouer const struct iphdr *iph, int inverse); 7981da177e4SLinus Torvalds 7991da177e4SLinus Torvalds struct ip_vs_conn * 8001da177e4SLinus Torvalds (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app, 801d4383f04SJesper Dangaard Brouer const struct iphdr *iph, int inverse); 8021da177e4SLinus Torvalds 8031da177e4SLinus Torvalds int (*state_transition)(struct ip_vs_conn *cp, int direction, 8041da177e4SLinus Torvalds const struct sk_buff *skb, 8051da177e4SLinus Torvalds struct ip_vs_app *app); 8061da177e4SLinus Torvalds 8071da177e4SLinus Torvalds void (*timeout_change)(struct ip_vs_app *app, int flags); 8081da177e4SLinus Torvalds }; 8091da177e4SLinus Torvalds 810f73181c8SPablo Neira Ayuso struct ipvs_master_sync_state { 811f73181c8SPablo Neira Ayuso struct list_head sync_queue; 812f73181c8SPablo Neira Ayuso struct ip_vs_sync_buff *sync_buff; 81307995674SZhang Yanfei unsigned long sync_queue_len; 814f73181c8SPablo Neira Ayuso unsigned int sync_queue_delay; 815f73181c8SPablo Neira Ayuso struct task_struct *master_thread; 816f73181c8SPablo Neira Ayuso struct delayed_work master_wakeup_work; 817f73181c8SPablo Neira Ayuso struct netns_ipvs *ipvs; 818f73181c8SPablo Neira Ayuso }; 819f73181c8SPablo Neira Ayuso 820578bc3efSJulian Anastasov /* How much time to keep dests in trash */ 821578bc3efSJulian Anastasov #define IP_VS_DEST_TRASH_PERIOD (120 * HZ) 822578bc3efSJulian Anastasov 823e4ff6751SJulian Anastasov struct ipvs_sync_daemon_cfg { 824d3328817SJulian Anastasov union nf_inet_addr mcast_group; 825e4ff6751SJulian Anastasov int syncid; 826e4ff6751SJulian Anastasov u16 sync_maxlen; 827d3328817SJulian Anastasov u16 mcast_port; 828d3328817SJulian Anastasov u8 mcast_af; 829d3328817SJulian Anastasov u8 mcast_ttl; 830e4ff6751SJulian Anastasov /* multicast interface name */ 831e4ff6751SJulian Anastasov char mcast_ifn[IP_VS_IFNAME_MAXLEN]; 832e4ff6751SJulian Anastasov }; 833e4ff6751SJulian Anastasov 8342553d064SJulian Anastasov /* IPVS in network namespace */ 8352553d064SJulian Anastasov struct netns_ipvs { 8362553d064SJulian Anastasov int gen; /* Generation */ 8377a4f0761SHans Schillstrom int enable; /* enable like nf_hooks do */ 83807dcc686SSimon Horman /* Hash table: for real service lookups */ 8392553d064SJulian Anastasov #define IP_VS_RTAB_BITS 4 8402553d064SJulian Anastasov #define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS) 8412553d064SJulian Anastasov #define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1) 8422553d064SJulian Anastasov 843276472eaSJulian Anastasov struct hlist_head rs_table[IP_VS_RTAB_SIZE]; 8442553d064SJulian Anastasov /* ip_vs_app */ 8452553d064SJulian Anastasov struct list_head app_list; 8462553d064SJulian Anastasov /* ip_vs_proto */ 8472553d064SJulian Anastasov #define IP_VS_PROTO_TAB_SIZE 32 /* must be power of 2 */ 8482553d064SJulian Anastasov struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE]; 8492553d064SJulian Anastasov /* ip_vs_proto_tcp */ 8502553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_TCP 8512553d064SJulian Anastasov #define TCP_APP_TAB_BITS 4 8522553d064SJulian Anastasov #define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS) 8532553d064SJulian Anastasov #define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1) 8542553d064SJulian Anastasov struct list_head tcp_apps[TCP_APP_TAB_SIZE]; 8552553d064SJulian Anastasov #endif 8562553d064SJulian Anastasov /* ip_vs_proto_udp */ 8572553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_UDP 8582553d064SJulian Anastasov #define UDP_APP_TAB_BITS 4 8592553d064SJulian Anastasov #define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS) 8602553d064SJulian Anastasov #define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1) 8612553d064SJulian Anastasov struct list_head udp_apps[UDP_APP_TAB_SIZE]; 8622553d064SJulian Anastasov #endif 8632553d064SJulian Anastasov /* ip_vs_proto_sctp */ 8642553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_SCTP 8652553d064SJulian Anastasov #define SCTP_APP_TAB_BITS 4 8662553d064SJulian Anastasov #define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS) 8672553d064SJulian Anastasov #define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1) 8682553d064SJulian Anastasov /* Hash table for SCTP application incarnations */ 8692553d064SJulian Anastasov struct list_head sctp_apps[SCTP_APP_TAB_SIZE]; 8702553d064SJulian Anastasov #endif 8712553d064SJulian Anastasov /* ip_vs_conn */ 8722553d064SJulian Anastasov atomic_t conn_count; /* connection counter */ 8732553d064SJulian Anastasov 8742553d064SJulian Anastasov /* ip_vs_ctl */ 8752a0751afSJulian Anastasov struct ip_vs_stats tot_stats; /* Statistics & est. */ 8762553d064SJulian Anastasov 8772553d064SJulian Anastasov int num_services; /* no of virtual services */ 878f2247fbdSSimon Horman 8792553d064SJulian Anastasov /* Trash for destinations */ 8802553d064SJulian Anastasov struct list_head dest_trash; 881578bc3efSJulian Anastasov spinlock_t dest_trash_lock; 882578bc3efSJulian Anastasov struct timer_list dest_trash_timer; /* expiration timer */ 8832553d064SJulian Anastasov /* Service counters */ 8842553d064SJulian Anastasov atomic_t ftpsvc_counter; 8852553d064SJulian Anastasov atomic_t nullsvc_counter; 88639b97223SMarco Angaroni atomic_t conn_out_counter; 8872553d064SJulian Anastasov 888f2247fbdSSimon Horman #ifdef CONFIG_SYSCTL 889f2247fbdSSimon Horman /* 1/rate drop and drop-entry variables */ 890f2247fbdSSimon Horman struct delayed_work defense_work; /* Work handler */ 891f2247fbdSSimon Horman int drop_rate; 892f2247fbdSSimon Horman int drop_counter; 893f2247fbdSSimon Horman atomic_t dropentry; 894f2247fbdSSimon Horman /* locks in ctl.c */ 895f2247fbdSSimon Horman spinlock_t dropentry_lock; /* drop entry handling */ 896f2247fbdSSimon Horman spinlock_t droppacket_lock; /* drop packet handling */ 897f2247fbdSSimon Horman spinlock_t securetcp_lock; /* state and timeout tables */ 898f2247fbdSSimon Horman 8992553d064SJulian Anastasov /* sys-ctl struct */ 9002553d064SJulian Anastasov struct ctl_table_header *sysctl_hdr; 9012553d064SJulian Anastasov struct ctl_table *sysctl_tbl; 902f2247fbdSSimon Horman #endif 903f2247fbdSSimon Horman 9042553d064SJulian Anastasov /* sysctl variables */ 9052553d064SJulian Anastasov int sysctl_amemthresh; 9062553d064SJulian Anastasov int sysctl_am_droprate; 9072553d064SJulian Anastasov int sysctl_drop_entry; 9082553d064SJulian Anastasov int sysctl_drop_packet; 9092553d064SJulian Anastasov int sysctl_secure_tcp; 9102553d064SJulian Anastasov #ifdef CONFIG_IP_VS_NFCT 9112553d064SJulian Anastasov int sysctl_conntrack; 9122553d064SJulian Anastasov #endif 9132553d064SJulian Anastasov int sysctl_snat_reroute; 9142553d064SJulian Anastasov int sysctl_sync_ver; 915f73181c8SPablo Neira Ayuso int sysctl_sync_ports; 9164d0c875dSJulian Anastasov int sysctl_sync_persist_mode; 91707995674SZhang Yanfei unsigned long sysctl_sync_qlen_max; 9181c003b15SPablo Neira Ayuso int sysctl_sync_sock_size; 9192553d064SJulian Anastasov int sysctl_cache_bypass; 9202553d064SJulian Anastasov int sysctl_expire_nodest_conn; 921c6c96c18SAlexander Frolkin int sysctl_sloppy_tcp; 922c6c96c18SAlexander Frolkin int sysctl_sloppy_sctp; 9232553d064SJulian Anastasov int sysctl_expire_quiescent_template; 9242553d064SJulian Anastasov int sysctl_sync_threshold[2]; 925749c42b6SJulian Anastasov unsigned int sysctl_sync_refresh_period; 926749c42b6SJulian Anastasov int sysctl_sync_retries; 9272553d064SJulian Anastasov int sysctl_nat_icmp_send; 9283654e611SJulian Anastasov int sysctl_pmtu_disc; 9290c12582fSJulian Anastasov int sysctl_backup_only; 930d752c364SMarcelo Ricardo Leitner int sysctl_conn_reuse_mode; 93194485fedSAlex Gartrell int sysctl_schedule_icmp; 9324e478098SAlex Gartrell int sysctl_ignore_tunneled; 9332553d064SJulian Anastasov 9342553d064SJulian Anastasov /* ip_vs_lblc */ 9352553d064SJulian Anastasov int sysctl_lblc_expiration; 9362553d064SJulian Anastasov struct ctl_table_header *lblc_ctl_header; 9372553d064SJulian Anastasov struct ctl_table *lblc_ctl_table; 9382553d064SJulian Anastasov /* ip_vs_lblcr */ 9392553d064SJulian Anastasov int sysctl_lblcr_expiration; 9402553d064SJulian Anastasov struct ctl_table_header *lblcr_ctl_header; 9412553d064SJulian Anastasov struct ctl_table *lblcr_ctl_table; 9422553d064SJulian Anastasov /* ip_vs_est */ 9432553d064SJulian Anastasov struct list_head est_list; /* estimator list */ 9442553d064SJulian Anastasov spinlock_t est_lock; 9452553d064SJulian Anastasov struct timer_list est_timer; /* Estimation timer */ 9462553d064SJulian Anastasov /* ip_vs_sync */ 9472553d064SJulian Anastasov spinlock_t sync_lock; 948f73181c8SPablo Neira Ayuso struct ipvs_master_sync_state *ms; 9492553d064SJulian Anastasov spinlock_t sync_buff_lock; 950f73181c8SPablo Neira Ayuso struct task_struct **backup_threads; 951f73181c8SPablo Neira Ayuso int threads_mask; 9522553d064SJulian Anastasov volatile int sync_state; 953ae1d48b2SHans Schillstrom struct mutex sync_mutex; 954e4ff6751SJulian Anastasov struct ipvs_sync_daemon_cfg mcfg; /* Master Configuration */ 955e4ff6751SJulian Anastasov struct ipvs_sync_daemon_cfg bcfg; /* Backup Configuration */ 9562553d064SJulian Anastasov /* net name space ptr */ 9572553d064SJulian Anastasov struct net *net; /* Needed by timer routines */ 95807dcc686SSimon Horman /* Number of heterogeneous destinations, needed becaus heterogeneous 95907dcc686SSimon Horman * are not supported when synchronization is enabled. 96007dcc686SSimon Horman */ 961391f503dSAlex Gartrell unsigned int mixed_address_family_dests; 9622553d064SJulian Anastasov }; 9631da177e4SLinus Torvalds 96459e0350eSSimon Horman #define DEFAULT_SYNC_THRESHOLD 3 96559e0350eSSimon Horman #define DEFAULT_SYNC_PERIOD 50 9667532e8d4SSimon Horman #define DEFAULT_SYNC_VER 1 967c6c96c18SAlexander Frolkin #define DEFAULT_SLOPPY_TCP 0 968c6c96c18SAlexander Frolkin #define DEFAULT_SLOPPY_SCTP 0 969749c42b6SJulian Anastasov #define DEFAULT_SYNC_REFRESH_PERIOD (0U * HZ) 970749c42b6SJulian Anastasov #define DEFAULT_SYNC_RETRIES 0 9711c003b15SPablo Neira Ayuso #define IPVS_SYNC_WAKEUP_RATE 8 9721c003b15SPablo Neira Ayuso #define IPVS_SYNC_QLEN_MAX (IPVS_SYNC_WAKEUP_RATE * 4) 9731c003b15SPablo Neira Ayuso #define IPVS_SYNC_SEND_DELAY (HZ / 50) 9741c003b15SPablo Neira Ayuso #define IPVS_SYNC_CHECK_PERIOD HZ 975749c42b6SJulian Anastasov #define IPVS_SYNC_FLUSH_TIME (HZ * 2) 976f73181c8SPablo Neira Ayuso #define IPVS_SYNC_PORTS_MAX (1 << 6) 97759e0350eSSimon Horman 97859e0350eSSimon Horman #ifdef CONFIG_SYSCTL 97959e0350eSSimon Horman 98059e0350eSSimon Horman static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs) 98159e0350eSSimon Horman { 98259e0350eSSimon Horman return ipvs->sysctl_sync_threshold[0]; 98359e0350eSSimon Horman } 98459e0350eSSimon Horman 98559e0350eSSimon Horman static inline int sysctl_sync_period(struct netns_ipvs *ipvs) 98659e0350eSSimon Horman { 9876aa7de05SMark Rutland return READ_ONCE(ipvs->sysctl_sync_threshold[1]); 988749c42b6SJulian Anastasov } 989749c42b6SJulian Anastasov 990749c42b6SJulian Anastasov static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs) 991749c42b6SJulian Anastasov { 9926aa7de05SMark Rutland return READ_ONCE(ipvs->sysctl_sync_refresh_period); 993749c42b6SJulian Anastasov } 994749c42b6SJulian Anastasov 995749c42b6SJulian Anastasov static inline int sysctl_sync_retries(struct netns_ipvs *ipvs) 996749c42b6SJulian Anastasov { 997749c42b6SJulian Anastasov return ipvs->sysctl_sync_retries; 99859e0350eSSimon Horman } 99959e0350eSSimon Horman 10007532e8d4SSimon Horman static inline int sysctl_sync_ver(struct netns_ipvs *ipvs) 10017532e8d4SSimon Horman { 10027532e8d4SSimon Horman return ipvs->sysctl_sync_ver; 10037532e8d4SSimon Horman } 10047532e8d4SSimon Horman 1005c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs) 1006c6c96c18SAlexander Frolkin { 1007c6c96c18SAlexander Frolkin return ipvs->sysctl_sloppy_tcp; 1008c6c96c18SAlexander Frolkin } 1009c6c96c18SAlexander Frolkin 1010c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs) 1011c6c96c18SAlexander Frolkin { 1012c6c96c18SAlexander Frolkin return ipvs->sysctl_sloppy_sctp; 1013c6c96c18SAlexander Frolkin } 1014c6c96c18SAlexander Frolkin 1015f73181c8SPablo Neira Ayuso static inline int sysctl_sync_ports(struct netns_ipvs *ipvs) 1016f73181c8SPablo Neira Ayuso { 10176aa7de05SMark Rutland return READ_ONCE(ipvs->sysctl_sync_ports); 1018f73181c8SPablo Neira Ayuso } 1019f73181c8SPablo Neira Ayuso 10204d0c875dSJulian Anastasov static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs) 10214d0c875dSJulian Anastasov { 10224d0c875dSJulian Anastasov return ipvs->sysctl_sync_persist_mode; 10234d0c875dSJulian Anastasov } 10244d0c875dSJulian Anastasov 102507995674SZhang Yanfei static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs) 10261c003b15SPablo Neira Ayuso { 10271c003b15SPablo Neira Ayuso return ipvs->sysctl_sync_qlen_max; 10281c003b15SPablo Neira Ayuso } 10291c003b15SPablo Neira Ayuso 10301c003b15SPablo Neira Ayuso static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs) 10311c003b15SPablo Neira Ayuso { 10321c003b15SPablo Neira Ayuso return ipvs->sysctl_sync_sock_size; 10331c003b15SPablo Neira Ayuso } 10341c003b15SPablo Neira Ayuso 10353654e611SJulian Anastasov static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs) 10363654e611SJulian Anastasov { 10373654e611SJulian Anastasov return ipvs->sysctl_pmtu_disc; 10383654e611SJulian Anastasov } 10393654e611SJulian Anastasov 10400c12582fSJulian Anastasov static inline int sysctl_backup_only(struct netns_ipvs *ipvs) 10410c12582fSJulian Anastasov { 10420c12582fSJulian Anastasov return ipvs->sync_state & IP_VS_STATE_BACKUP && 10430c12582fSJulian Anastasov ipvs->sysctl_backup_only; 10440c12582fSJulian Anastasov } 10450c12582fSJulian Anastasov 1046d752c364SMarcelo Ricardo Leitner static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs) 1047d752c364SMarcelo Ricardo Leitner { 1048d752c364SMarcelo Ricardo Leitner return ipvs->sysctl_conn_reuse_mode; 1049d752c364SMarcelo Ricardo Leitner } 1050d752c364SMarcelo Ricardo Leitner 105194485fedSAlex Gartrell static inline int sysctl_schedule_icmp(struct netns_ipvs *ipvs) 105294485fedSAlex Gartrell { 105394485fedSAlex Gartrell return ipvs->sysctl_schedule_icmp; 105494485fedSAlex Gartrell } 105594485fedSAlex Gartrell 10564e478098SAlex Gartrell static inline int sysctl_ignore_tunneled(struct netns_ipvs *ipvs) 10574e478098SAlex Gartrell { 10584e478098SAlex Gartrell return ipvs->sysctl_ignore_tunneled; 10594e478098SAlex Gartrell } 10604e478098SAlex Gartrell 106157032948SEric W. Biederman static inline int sysctl_cache_bypass(struct netns_ipvs *ipvs) 106257032948SEric W. Biederman { 106357032948SEric W. Biederman return ipvs->sysctl_cache_bypass; 106457032948SEric W. Biederman } 106557032948SEric W. Biederman 106659e0350eSSimon Horman #else 106759e0350eSSimon Horman 106859e0350eSSimon Horman static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs) 106959e0350eSSimon Horman { 107059e0350eSSimon Horman return DEFAULT_SYNC_THRESHOLD; 107159e0350eSSimon Horman } 107259e0350eSSimon Horman 107359e0350eSSimon Horman static inline int sysctl_sync_period(struct netns_ipvs *ipvs) 107459e0350eSSimon Horman { 107559e0350eSSimon Horman return DEFAULT_SYNC_PERIOD; 107659e0350eSSimon Horman } 107759e0350eSSimon Horman 1078749c42b6SJulian Anastasov static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs) 1079749c42b6SJulian Anastasov { 1080749c42b6SJulian Anastasov return DEFAULT_SYNC_REFRESH_PERIOD; 1081749c42b6SJulian Anastasov } 1082749c42b6SJulian Anastasov 1083749c42b6SJulian Anastasov static inline int sysctl_sync_retries(struct netns_ipvs *ipvs) 1084749c42b6SJulian Anastasov { 1085749c42b6SJulian Anastasov return DEFAULT_SYNC_RETRIES & 3; 1086749c42b6SJulian Anastasov } 1087749c42b6SJulian Anastasov 10887532e8d4SSimon Horman static inline int sysctl_sync_ver(struct netns_ipvs *ipvs) 10897532e8d4SSimon Horman { 10907532e8d4SSimon Horman return DEFAULT_SYNC_VER; 10917532e8d4SSimon Horman } 10927532e8d4SSimon Horman 1093c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs) 1094c6c96c18SAlexander Frolkin { 1095c6c96c18SAlexander Frolkin return DEFAULT_SLOPPY_TCP; 1096c6c96c18SAlexander Frolkin } 1097c6c96c18SAlexander Frolkin 1098c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs) 1099c6c96c18SAlexander Frolkin { 1100c6c96c18SAlexander Frolkin return DEFAULT_SLOPPY_SCTP; 1101c6c96c18SAlexander Frolkin } 1102c6c96c18SAlexander Frolkin 1103f73181c8SPablo Neira Ayuso static inline int sysctl_sync_ports(struct netns_ipvs *ipvs) 1104f73181c8SPablo Neira Ayuso { 1105f73181c8SPablo Neira Ayuso return 1; 1106f73181c8SPablo Neira Ayuso } 1107f73181c8SPablo Neira Ayuso 11084d0c875dSJulian Anastasov static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs) 11094d0c875dSJulian Anastasov { 11104d0c875dSJulian Anastasov return 0; 11114d0c875dSJulian Anastasov } 11124d0c875dSJulian Anastasov 111307995674SZhang Yanfei static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs) 11141c003b15SPablo Neira Ayuso { 11151c003b15SPablo Neira Ayuso return IPVS_SYNC_QLEN_MAX; 11161c003b15SPablo Neira Ayuso } 11171c003b15SPablo Neira Ayuso 11181c003b15SPablo Neira Ayuso static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs) 11191c003b15SPablo Neira Ayuso { 11201c003b15SPablo Neira Ayuso return 0; 11211c003b15SPablo Neira Ayuso } 11221c003b15SPablo Neira Ayuso 11233654e611SJulian Anastasov static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs) 11243654e611SJulian Anastasov { 11253654e611SJulian Anastasov return 1; 11263654e611SJulian Anastasov } 11273654e611SJulian Anastasov 11280c12582fSJulian Anastasov static inline int sysctl_backup_only(struct netns_ipvs *ipvs) 11290c12582fSJulian Anastasov { 11300c12582fSJulian Anastasov return 0; 11310c12582fSJulian Anastasov } 11320c12582fSJulian Anastasov 1133d752c364SMarcelo Ricardo Leitner static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs) 1134d752c364SMarcelo Ricardo Leitner { 1135d752c364SMarcelo Ricardo Leitner return 1; 1136d752c364SMarcelo Ricardo Leitner } 1137d752c364SMarcelo Ricardo Leitner 113894485fedSAlex Gartrell static inline int sysctl_schedule_icmp(struct netns_ipvs *ipvs) 113994485fedSAlex Gartrell { 114094485fedSAlex Gartrell return 0; 114194485fedSAlex Gartrell } 114294485fedSAlex Gartrell 11434e478098SAlex Gartrell static inline int sysctl_ignore_tunneled(struct netns_ipvs *ipvs) 11444e478098SAlex Gartrell { 11454e478098SAlex Gartrell return 0; 11464e478098SAlex Gartrell } 11474e478098SAlex Gartrell 114857032948SEric W. Biederman static inline int sysctl_cache_bypass(struct netns_ipvs *ipvs) 114957032948SEric W. Biederman { 115057032948SEric W. Biederman return 0; 115157032948SEric W. Biederman } 115257032948SEric W. Biederman 115359e0350eSSimon Horman #endif 115459e0350eSSimon Horman 115507dcc686SSimon Horman /* IPVS core functions 11561da177e4SLinus Torvalds * (from ip_vs_core.c) 11571da177e4SLinus Torvalds */ 11585c3a0fd7SJoe Perches const char *ip_vs_proto_name(unsigned int proto); 11595c3a0fd7SJoe Perches void ip_vs_init_hash_table(struct list_head *table, int rows); 116039b97223SMarco Angaroni struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc, 116139b97223SMarco Angaroni struct ip_vs_dest *dest, 116239b97223SMarco Angaroni struct sk_buff *skb, 116339b97223SMarco Angaroni const struct ip_vs_iphdr *iph, 116439b97223SMarco Angaroni __be16 dport, 116539b97223SMarco Angaroni __be16 cport); 1166afdd6140SSven Wegener #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t))) 11671da177e4SLinus Torvalds 11681da177e4SLinus Torvalds #define IP_VS_APP_TYPE_FTP 1 11691da177e4SLinus Torvalds 117007dcc686SSimon Horman /* ip_vs_conn handling functions 11711da177e4SLinus Torvalds * (from ip_vs_conn.c) 11721da177e4SLinus Torvalds */ 11731da177e4SLinus Torvalds enum { 11741da177e4SLinus Torvalds IP_VS_DIR_INPUT = 0, 11751da177e4SLinus Torvalds IP_VS_DIR_OUTPUT, 11761da177e4SLinus Torvalds IP_VS_DIR_INPUT_ONLY, 11771da177e4SLinus Torvalds IP_VS_DIR_LAST, 11781da177e4SLinus Torvalds }; 11791da177e4SLinus Torvalds 118019913decSEric W. Biederman static inline void ip_vs_conn_fill_param(struct netns_ipvs *ipvs, int af, int protocol, 1181f11017ecSSimon Horman const union nf_inet_addr *caddr, 1182f11017ecSSimon Horman __be16 cport, 1183f11017ecSSimon Horman const union nf_inet_addr *vaddr, 1184f11017ecSSimon Horman __be16 vport, 1185f11017ecSSimon Horman struct ip_vs_conn_param *p) 1186f11017ecSSimon Horman { 118719913decSEric W. Biederman p->ipvs = ipvs; 1188f11017ecSSimon Horman p->af = af; 1189f11017ecSSimon Horman p->protocol = protocol; 1190f11017ecSSimon Horman p->caddr = caddr; 1191f11017ecSSimon Horman p->cport = cport; 1192f11017ecSSimon Horman p->vaddr = vaddr; 1193f11017ecSSimon Horman p->vport = vport; 119485999283SSimon Horman p->pe = NULL; 119585999283SSimon Horman p->pe_data = NULL; 1196f11017ecSSimon Horman } 119728364a59SJulius Volz 1198f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p); 1199f11017ecSSimon Horman struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p); 120028364a59SJulius Volz 1201ab161976SEric W. Biederman struct ip_vs_conn * ip_vs_conn_in_get_proto(struct netns_ipvs *ipvs, int af, 1202ab161976SEric W. Biederman const struct sk_buff *skb, 1203802c41adSAlex Gartrell const struct ip_vs_iphdr *iph); 12045c0d2374SSimon Horman 1205f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p); 12061da177e4SLinus Torvalds 12070cf705c8SEric W. Biederman struct ip_vs_conn * ip_vs_conn_out_get_proto(struct netns_ipvs *ipvs, int af, 12080cf705c8SEric W. Biederman const struct sk_buff *skb, 1209802c41adSAlex Gartrell const struct ip_vs_iphdr *iph); 12105c0d2374SSimon Horman 1211088339a5SJulian Anastasov /* Get reference to gain full access to conn. 1212088339a5SJulian Anastasov * By default, RCU read-side critical sections have access only to 1213088339a5SJulian Anastasov * conn fields and its PE data, see ip_vs_conn_rcu_free() for reference. 1214088339a5SJulian Anastasov */ 1215088339a5SJulian Anastasov static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp) 1216088339a5SJulian Anastasov { 1217b54ab92bSReshetova, Elena return refcount_inc_not_zero(&cp->refcnt); 1218088339a5SJulian Anastasov } 1219088339a5SJulian Anastasov 12201da177e4SLinus Torvalds /* put back the conn without restarting its timer */ 12211da177e4SLinus Torvalds static inline void __ip_vs_conn_put(struct ip_vs_conn *cp) 12221da177e4SLinus Torvalds { 12234e857c58SPeter Zijlstra smp_mb__before_atomic(); 1224b54ab92bSReshetova, Elena refcount_dec(&cp->refcnt); 12251da177e4SLinus Torvalds } 12265c3a0fd7SJoe Perches void ip_vs_conn_put(struct ip_vs_conn *cp); 12275c3a0fd7SJoe Perches void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport); 12281da177e4SLinus Torvalds 1229ba38528aSAlex Gartrell struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af, 1230f11017ecSSimon Horman const union nf_inet_addr *daddr, 123195c96174SEric Dumazet __be16 dport, unsigned int flags, 12320e051e68SHans Schillstrom struct ip_vs_dest *dest, __u32 fwmark); 12335c3a0fd7SJoe Perches void ip_vs_conn_expire_now(struct ip_vs_conn *cp); 12341da177e4SLinus Torvalds 12355c3a0fd7SJoe Perches const char *ip_vs_state_name(__u16 proto, int state); 12361da177e4SLinus Torvalds 123769f39093SEric W. Biederman void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp); 12383ec10d3aSMarco Angaroni int ip_vs_check_template(struct ip_vs_conn *ct, struct ip_vs_dest *cdest); 1239423b5595SEric W. Biederman void ip_vs_random_dropentry(struct netns_ipvs *ipvs); 12405c3a0fd7SJoe Perches int ip_vs_conn_init(void); 12415c3a0fd7SJoe Perches void ip_vs_conn_cleanup(void); 12421da177e4SLinus Torvalds 12431da177e4SLinus Torvalds static inline void ip_vs_control_del(struct ip_vs_conn *cp) 12441da177e4SLinus Torvalds { 12451da177e4SLinus Torvalds struct ip_vs_conn *ctl_cp = cp->control; 12461da177e4SLinus Torvalds if (!ctl_cp) { 1247cfc78c5aSJulius Volz IP_VS_ERR_BUF("request control DEL for uncontrolled: " 1248cfc78c5aSJulius Volz "%s:%d to %s:%d\n", 1249cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1250cfc78c5aSJulius Volz ntohs(cp->cport), 1251cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr), 1252cfc78c5aSJulius Volz ntohs(cp->vport)); 1253cfc78c5aSJulius Volz 12541da177e4SLinus Torvalds return; 12551da177e4SLinus Torvalds } 12561da177e4SLinus Torvalds 1257cfc78c5aSJulius Volz IP_VS_DBG_BUF(7, "DELeting control for: " 1258cfc78c5aSJulius Volz "cp.dst=%s:%d ctl_cp.dst=%s:%d\n", 1259cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1260cfc78c5aSJulius Volz ntohs(cp->cport), 1261cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr), 1262cfc78c5aSJulius Volz ntohs(ctl_cp->cport)); 12631da177e4SLinus Torvalds 12641da177e4SLinus Torvalds cp->control = NULL; 12651da177e4SLinus Torvalds if (atomic_read(&ctl_cp->n_control) == 0) { 1266cfc78c5aSJulius Volz IP_VS_ERR_BUF("BUG control DEL with n=0 : " 1267cfc78c5aSJulius Volz "%s:%d to %s:%d\n", 1268cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1269cfc78c5aSJulius Volz ntohs(cp->cport), 1270cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr), 1271cfc78c5aSJulius Volz ntohs(cp->vport)); 1272cfc78c5aSJulius Volz 12731da177e4SLinus Torvalds return; 12741da177e4SLinus Torvalds } 12751da177e4SLinus Torvalds atomic_dec(&ctl_cp->n_control); 12761da177e4SLinus Torvalds } 12771da177e4SLinus Torvalds 12781da177e4SLinus Torvalds static inline void 12791da177e4SLinus Torvalds ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp) 12801da177e4SLinus Torvalds { 12811da177e4SLinus Torvalds if (cp->control) { 1282cfc78c5aSJulius Volz IP_VS_ERR_BUF("request control ADD for already controlled: " 1283cfc78c5aSJulius Volz "%s:%d to %s:%d\n", 1284cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1285cfc78c5aSJulius Volz ntohs(cp->cport), 1286cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr), 1287cfc78c5aSJulius Volz ntohs(cp->vport)); 1288cfc78c5aSJulius Volz 12891da177e4SLinus Torvalds ip_vs_control_del(cp); 12901da177e4SLinus Torvalds } 12911da177e4SLinus Torvalds 1292cfc78c5aSJulius Volz IP_VS_DBG_BUF(7, "ADDing control for: " 1293cfc78c5aSJulius Volz "cp.dst=%s:%d ctl_cp.dst=%s:%d\n", 1294cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1295cfc78c5aSJulius Volz ntohs(cp->cport), 1296cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr), 1297cfc78c5aSJulius Volz ntohs(ctl_cp->cport)); 12981da177e4SLinus Torvalds 12991da177e4SLinus Torvalds cp->control = ctl_cp; 13001da177e4SLinus Torvalds atomic_inc(&ctl_cp->n_control); 13011da177e4SLinus Torvalds } 13021da177e4SLinus Torvalds 130307dcc686SSimon Horman /* IPVS netns init & cleanup functions */ 1304a4dd0360SEric W. Biederman int ip_vs_estimator_net_init(struct netns_ipvs *ipvs); 13053d993766SEric W. Biederman int ip_vs_control_net_init(struct netns_ipvs *ipvs); 13067d1f88ecSEric W. Biederman int ip_vs_protocol_net_init(struct netns_ipvs *ipvs); 1307b5dd212cSEric W. Biederman int ip_vs_app_net_init(struct netns_ipvs *ipvs); 13082f3edc6aSEric W. Biederman int ip_vs_conn_net_init(struct netns_ipvs *ipvs); 1309802cb437SEric W. Biederman int ip_vs_sync_net_init(struct netns_ipvs *ipvs); 13102f3edc6aSEric W. Biederman void ip_vs_conn_net_cleanup(struct netns_ipvs *ipvs); 1311b5dd212cSEric W. Biederman void ip_vs_app_net_cleanup(struct netns_ipvs *ipvs); 13127d1f88ecSEric W. Biederman void ip_vs_protocol_net_cleanup(struct netns_ipvs *ipvs); 13133d993766SEric W. Biederman void ip_vs_control_net_cleanup(struct netns_ipvs *ipvs); 1314a4dd0360SEric W. Biederman void ip_vs_estimator_net_cleanup(struct netns_ipvs *ipvs); 1315ebea1f7cSEric W. Biederman void ip_vs_sync_net_cleanup(struct netns_ipvs *ipvs); 131656d2169bSEric W. Biederman void ip_vs_service_net_cleanup(struct netns_ipvs *ipvs); 13171da177e4SLinus Torvalds 131807dcc686SSimon Horman /* IPVS application functions 13191da177e4SLinus Torvalds * (from ip_vs_app.c) 13201da177e4SLinus Torvalds */ 13211da177e4SLinus Torvalds #define IP_VS_APP_MAX_PORTS 8 13229f8128a5SEric W. Biederman struct ip_vs_app *register_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app); 13239f8128a5SEric W. Biederman void unregister_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app); 13245c3a0fd7SJoe Perches int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp); 13255c3a0fd7SJoe Perches void ip_vs_unbind_app(struct ip_vs_conn *cp); 13263250dc9cSEric W. Biederman int register_ip_vs_app_inc(struct netns_ipvs *ipvs, struct ip_vs_app *app, __u16 proto, 13275c3a0fd7SJoe Perches __u16 port); 13285c3a0fd7SJoe Perches int ip_vs_app_inc_get(struct ip_vs_app *inc); 13295c3a0fd7SJoe Perches void ip_vs_app_inc_put(struct ip_vs_app *inc); 13301da177e4SLinus Torvalds 13315c3a0fd7SJoe Perches int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb); 13325c3a0fd7SJoe Perches int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb); 13331da177e4SLinus Torvalds 13348be67a66SSimon Horman int register_ip_vs_pe(struct ip_vs_pe *pe); 13358be67a66SSimon Horman int unregister_ip_vs_pe(struct ip_vs_pe *pe); 1336e9e5eee8SSimon Horman struct ip_vs_pe *ip_vs_pe_getbyname(const char *name); 1337fe5e7a1eSHans Schillstrom struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name); 1338e9e5eee8SSimon Horman 133907dcc686SSimon Horman /* Use a #define to avoid all of module.h just for these trivial ops */ 134069e7dae4SPaul Gortmaker #define ip_vs_pe_get(pe) \ 134169e7dae4SPaul Gortmaker if (pe && pe->module) \ 1342e9e5eee8SSimon Horman __module_get(pe->module); 1343e9e5eee8SSimon Horman 134469e7dae4SPaul Gortmaker #define ip_vs_pe_put(pe) \ 134569e7dae4SPaul Gortmaker if (pe && pe->module) \ 1346e9e5eee8SSimon Horman module_put(pe->module); 13471da177e4SLinus Torvalds 134807dcc686SSimon Horman /* IPVS protocol functions (from ip_vs_proto.c) */ 13495c3a0fd7SJoe Perches int ip_vs_protocol_init(void); 13505c3a0fd7SJoe Perches void ip_vs_protocol_cleanup(void); 13515c3a0fd7SJoe Perches void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags); 13525c3a0fd7SJoe Perches int *ip_vs_create_timeout_table(int *table, int size); 13535c3a0fd7SJoe Perches void ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp, 13545c3a0fd7SJoe Perches const struct sk_buff *skb, int offset, 13555c3a0fd7SJoe Perches const char *msg); 13561da177e4SLinus Torvalds 13571da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_tcp; 13581da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_udp; 13591da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_icmp; 13601da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_esp; 13611da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_ah; 13622906f66aSVenkata Mohan Reddy extern struct ip_vs_protocol ip_vs_protocol_sctp; 13631da177e4SLinus Torvalds 136407dcc686SSimon Horman /* Registering/unregistering scheduler functions 13651da177e4SLinus Torvalds * (from ip_vs_sched.c) 13661da177e4SLinus Torvalds */ 13675c3a0fd7SJoe Perches int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); 13685c3a0fd7SJoe Perches int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); 13695c3a0fd7SJoe Perches int ip_vs_bind_scheduler(struct ip_vs_service *svc, 13701da177e4SLinus Torvalds struct ip_vs_scheduler *scheduler); 13715c3a0fd7SJoe Perches void ip_vs_unbind_scheduler(struct ip_vs_service *svc, 1372ceec4c38SJulian Anastasov struct ip_vs_scheduler *sched); 13735c3a0fd7SJoe Perches struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name); 13745c3a0fd7SJoe Perches void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler); 13755c3a0fd7SJoe Perches struct ip_vs_conn * 1376190ecd27SJulian Anastasov ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb, 1377d4383f04SJesper Dangaard Brouer struct ip_vs_proto_data *pd, int *ignored, 1378d4383f04SJesper Dangaard Brouer struct ip_vs_iphdr *iph); 13795c3a0fd7SJoe Perches int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb, 1380d4383f04SJesper Dangaard Brouer struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph); 13811da177e4SLinus Torvalds 13825c3a0fd7SJoe Perches void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg); 138341ac51eeSPatrick Schaaf 138407dcc686SSimon Horman /* IPVS control data and functions (from ip_vs_ctl.c) */ 13851da177e4SLinus Torvalds extern struct ip_vs_stats ip_vs_stats; 1386b880c1f0SHans Schillstrom extern int sysctl_ip_vs_sync_ver; 13871da177e4SLinus Torvalds 13885c3a0fd7SJoe Perches struct ip_vs_service * 13890a4fd6ceSEric W. Biederman ip_vs_service_find(struct netns_ipvs *ipvs, int af, __u32 fwmark, __u16 protocol, 13903c2e0505SJulius Volz const union nf_inet_addr *vaddr, __be16 vport); 13911da177e4SLinus Torvalds 139248aed1b0SEric W. Biederman bool ip_vs_has_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol, 13937937df15SJulius Volz const union nf_inet_addr *daddr, __be16 dport); 13947937df15SJulius Volz 139539b97223SMarco Angaroni struct ip_vs_dest * 139639b97223SMarco Angaroni ip_vs_find_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol, 139739b97223SMarco Angaroni const union nf_inet_addr *daddr, __be16 dport); 139839b97223SMarco Angaroni 13995c3a0fd7SJoe Perches int ip_vs_use_count_inc(void); 14005c3a0fd7SJoe Perches void ip_vs_use_count_dec(void); 14015c3a0fd7SJoe Perches int ip_vs_register_nl_ioctl(void); 14025c3a0fd7SJoe Perches void ip_vs_unregister_nl_ioctl(void); 14035c3a0fd7SJoe Perches int ip_vs_control_init(void); 14045c3a0fd7SJoe Perches void ip_vs_control_cleanup(void); 14055c3a0fd7SJoe Perches struct ip_vs_dest * 1406dc2add6fSEric W. Biederman ip_vs_find_dest(struct netns_ipvs *ipvs, int svc_af, int dest_af, 1407655eef10SAlex Gartrell const union nf_inet_addr *daddr, __be16 dport, 1408655eef10SAlex Gartrell const union nf_inet_addr *vaddr, __be16 vport, 140952793dbeSJulian Anastasov __u16 protocol, __u32 fwmark, __u32 flags); 14105c3a0fd7SJoe Perches void ip_vs_try_bind_dest(struct ip_vs_conn *cp); 14111da177e4SLinus Torvalds 1412fca9c20aSJulian Anastasov static inline void ip_vs_dest_hold(struct ip_vs_dest *dest) 1413fca9c20aSJulian Anastasov { 1414b54ab92bSReshetova, Elena refcount_inc(&dest->refcnt); 1415fca9c20aSJulian Anastasov } 1416fca9c20aSJulian Anastasov 1417fca9c20aSJulian Anastasov static inline void ip_vs_dest_put(struct ip_vs_dest *dest) 1418fca9c20aSJulian Anastasov { 14194e857c58SPeter Zijlstra smp_mb__before_atomic(); 1420b54ab92bSReshetova, Elena refcount_dec(&dest->refcnt); 1421fca9c20aSJulian Anastasov } 14221da177e4SLinus Torvalds 14239e4e948aSJulian Anastasov static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest) 14249e4e948aSJulian Anastasov { 1425b54ab92bSReshetova, Elena if (refcount_dec_and_test(&dest->refcnt)) 14269e4e948aSJulian Anastasov kfree(dest); 14279e4e948aSJulian Anastasov } 14289e4e948aSJulian Anastasov 142907dcc686SSimon Horman /* IPVS sync daemon data and function prototypes 14301da177e4SLinus Torvalds * (from ip_vs_sync.c) 14311da177e4SLinus Torvalds */ 14326ac121d7SEric W. Biederman int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *cfg, 1433e4ff6751SJulian Anastasov int state); 1434b3cf3cbfSEric W. Biederman int stop_sync_thread(struct netns_ipvs *ipvs, int state); 1435b61a8c1aSEric W. Biederman void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts); 14361da177e4SLinus Torvalds 143707dcc686SSimon Horman /* IPVS rate estimator prototypes (from ip_vs_est.c) */ 14380f34d54bSEric W. Biederman void ip_vs_start_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats); 14390f34d54bSEric W. Biederman void ip_vs_stop_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats); 14405c3a0fd7SJoe Perches void ip_vs_zero_estimator(struct ip_vs_stats *stats); 1441cd67cd5eSJulian Anastasov void ip_vs_read_estimator(struct ip_vs_kstats *dst, struct ip_vs_stats *stats); 14421da177e4SLinus Torvalds 144307dcc686SSimon Horman /* Various IPVS packet transmitters (from ip_vs_xmit.c) */ 14445c3a0fd7SJoe Perches int ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1445d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14465c3a0fd7SJoe Perches int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1447d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14485c3a0fd7SJoe Perches int ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1449d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14505c3a0fd7SJoe Perches int ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 14515c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14525c3a0fd7SJoe Perches int ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 14535c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14545c3a0fd7SJoe Perches int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1455d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, int offset, 1456d4383f04SJesper Dangaard Brouer unsigned int hooknum, struct ip_vs_iphdr *iph); 14575c3a0fd7SJoe Perches void ip_vs_dest_dst_rcu_free(struct rcu_head *head); 14581da177e4SLinus Torvalds 1459b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6 14605c3a0fd7SJoe Perches int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 1461d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14625c3a0fd7SJoe Perches int ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 14635c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14645c3a0fd7SJoe Perches int ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 14655c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14665c3a0fd7SJoe Perches int ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 14675c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14685c3a0fd7SJoe Perches int ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 1469d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, int offset, 1470d4383f04SJesper Dangaard Brouer unsigned int hooknum, struct ip_vs_iphdr *iph); 1471b3cdd2a7SJulius Volz #endif 14721da177e4SLinus Torvalds 14733a1bbf18SSimon Horman #ifdef CONFIG_SYSCTL 147407dcc686SSimon Horman /* This is a simple mechanism to ignore packets when 14751da177e4SLinus Torvalds * we are loaded. Just set ip_vs_drop_rate to 'n' and 14761da177e4SLinus Torvalds * we start to drop 1/rate of the packets 14771da177e4SLinus Torvalds */ 1478a0840e2eSHans Schillstrom static inline int ip_vs_todrop(struct netns_ipvs *ipvs) 14791da177e4SLinus Torvalds { 1480a0840e2eSHans Schillstrom if (!ipvs->drop_rate) 1481a0840e2eSHans Schillstrom return 0; 1482a0840e2eSHans Schillstrom if (--ipvs->drop_counter > 0) 1483a0840e2eSHans Schillstrom return 0; 1484a0840e2eSHans Schillstrom ipvs->drop_counter = ipvs->drop_rate; 14851da177e4SLinus Torvalds return 1; 14861da177e4SLinus Torvalds } 14873a1bbf18SSimon Horman #else 14883a1bbf18SSimon Horman static inline int ip_vs_todrop(struct netns_ipvs *ipvs) { return 0; } 14893a1bbf18SSimon Horman #endif 14901da177e4SLinus Torvalds 149107dcc686SSimon Horman /* ip_vs_fwd_tag returns the forwarding tag of the connection */ 14921da177e4SLinus Torvalds #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK) 14931da177e4SLinus Torvalds 1494732db659SAdrian Bunk static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp) 14951da177e4SLinus Torvalds { 14961da177e4SLinus Torvalds char fwd; 14971da177e4SLinus Torvalds 14981da177e4SLinus Torvalds switch (IP_VS_FWD_METHOD(cp)) { 14991da177e4SLinus Torvalds case IP_VS_CONN_F_MASQ: 15001da177e4SLinus Torvalds fwd = 'M'; break; 15011da177e4SLinus Torvalds case IP_VS_CONN_F_LOCALNODE: 15021da177e4SLinus Torvalds fwd = 'L'; break; 15031da177e4SLinus Torvalds case IP_VS_CONN_F_TUNNEL: 15041da177e4SLinus Torvalds fwd = 'T'; break; 15051da177e4SLinus Torvalds case IP_VS_CONN_F_DROUTE: 15061da177e4SLinus Torvalds fwd = 'R'; break; 15071da177e4SLinus Torvalds case IP_VS_CONN_F_BYPASS: 15081da177e4SLinus Torvalds fwd = 'B'; break; 15091da177e4SLinus Torvalds default: 15101da177e4SLinus Torvalds fwd = '?'; break; 15111da177e4SLinus Torvalds } 15121da177e4SLinus Torvalds return fwd; 15131da177e4SLinus Torvalds } 15141da177e4SLinus Torvalds 15155c3a0fd7SJoe Perches void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp, 15161da177e4SLinus Torvalds struct ip_vs_conn *cp, int dir); 15171da177e4SLinus Torvalds 1518b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6 15195c3a0fd7SJoe Perches void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp, 1520b3cdd2a7SJulius Volz struct ip_vs_conn *cp, int dir); 1521b3cdd2a7SJulius Volz #endif 1522b3cdd2a7SJulius Volz 15235c3a0fd7SJoe Perches __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset); 15241da177e4SLinus Torvalds 1525f9214b26SAl Viro static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum) 15261da177e4SLinus Torvalds { 1527f9214b26SAl Viro __be32 diff[2] = { ~old, new }; 15281da177e4SLinus Torvalds 152907f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum); 1530f9214b26SAl Viro } 1531f9214b26SAl Viro 15320bbdd42bSJulius Volz #ifdef CONFIG_IP_VS_IPV6 15330bbdd42bSJulius Volz static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new, 15340bbdd42bSJulius Volz __wsum oldsum) 15350bbdd42bSJulius Volz { 15360bbdd42bSJulius Volz __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0], 15370bbdd42bSJulius Volz new[3], new[2], new[1], new[0] }; 15380bbdd42bSJulius Volz 153907f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum); 15400bbdd42bSJulius Volz } 15410bbdd42bSJulius Volz #endif 15420bbdd42bSJulius Volz 1543f9214b26SAl Viro static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum) 1544f9214b26SAl Viro { 1545f9214b26SAl Viro __be16 diff[2] = { ~old, new }; 1546f9214b26SAl Viro 154707f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum); 15481da177e4SLinus Torvalds } 15491da177e4SLinus Torvalds 155007dcc686SSimon Horman /* Forget current conntrack (unconfirmed) and attach notrack entry */ 1551cf356d69SJulian Anastasov static inline void ip_vs_notrack(struct sk_buff *skb) 1552cf356d69SJulian Anastasov { 1553cf356d69SJulian Anastasov #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 1554cf356d69SJulian Anastasov enum ip_conntrack_info ctinfo; 155506b69390SJesper Juhl struct nf_conn *ct = nf_ct_get(skb, &ctinfo); 1556cf356d69SJulian Anastasov 1557ab8bc7edSFlorian Westphal if (ct) { 155897a6ad13SFlorian Westphal nf_conntrack_put(&ct->ct_general); 1559cc41c84bSFlorian Westphal nf_ct_set(skb, NULL, IP_CT_UNTRACKED); 1560cf356d69SJulian Anastasov } 1561cf356d69SJulian Anastasov #endif 1562cf356d69SJulian Anastasov } 1563cf356d69SJulian Anastasov 1564f4bc17cdSJulian Anastasov #ifdef CONFIG_IP_VS_NFCT 156507dcc686SSimon Horman /* Netfilter connection tracking 1566f4bc17cdSJulian Anastasov * (from ip_vs_nfct.c) 1567f4bc17cdSJulian Anastasov */ 1568a0840e2eSHans Schillstrom static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs) 1569f4bc17cdSJulian Anastasov { 1570a4e2f5a7SSimon Horman #ifdef CONFIG_SYSCTL 1571a0840e2eSHans Schillstrom return ipvs->sysctl_conntrack; 1572a4e2f5a7SSimon Horman #else 1573a4e2f5a7SSimon Horman return 0; 1574a4e2f5a7SSimon Horman #endif 1575f4bc17cdSJulian Anastasov } 1576f4bc17cdSJulian Anastasov 15775c3a0fd7SJoe Perches void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp, 15786523ce15SJulian Anastasov int outin); 15795c3a0fd7SJoe Perches int ip_vs_confirm_conntrack(struct sk_buff *skb); 15805c3a0fd7SJoe Perches void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct, 1581f4bc17cdSJulian Anastasov struct ip_vs_conn *cp, u_int8_t proto, 1582f4bc17cdSJulian Anastasov const __be16 port, int from_rs); 15835c3a0fd7SJoe Perches void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp); 1584f4bc17cdSJulian Anastasov 1585f4bc17cdSJulian Anastasov #else 1586f4bc17cdSJulian Anastasov 1587a0840e2eSHans Schillstrom static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs) 1588f4bc17cdSJulian Anastasov { 1589f4bc17cdSJulian Anastasov return 0; 1590f4bc17cdSJulian Anastasov } 1591f4bc17cdSJulian Anastasov 1592f4bc17cdSJulian Anastasov static inline void ip_vs_update_conntrack(struct sk_buff *skb, 1593f4bc17cdSJulian Anastasov struct ip_vs_conn *cp, int outin) 1594f4bc17cdSJulian Anastasov { 1595f4bc17cdSJulian Anastasov } 1596f4bc17cdSJulian Anastasov 1597e23ebf0fSKrzysztof Wilczynski static inline int ip_vs_confirm_conntrack(struct sk_buff *skb) 1598f4bc17cdSJulian Anastasov { 1599f4bc17cdSJulian Anastasov return NF_ACCEPT; 1600f4bc17cdSJulian Anastasov } 1601f4bc17cdSJulian Anastasov 1602f4bc17cdSJulian Anastasov static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp) 1603f4bc17cdSJulian Anastasov { 1604f4bc17cdSJulian Anastasov } 160507dcc686SSimon Horman #endif /* CONFIG_IP_VS_NFCT */ 16066523ce15SJulian Anastasov 1607f719e375SJulian Anastasov /* Really using conntrack? */ 1608f719e375SJulian Anastasov static inline bool ip_vs_conn_uses_conntrack(struct ip_vs_conn *cp, 1609f719e375SJulian Anastasov struct sk_buff *skb) 1610f719e375SJulian Anastasov { 1611f719e375SJulian Anastasov #ifdef CONFIG_IP_VS_NFCT 1612f719e375SJulian Anastasov enum ip_conntrack_info ctinfo; 1613f719e375SJulian Anastasov struct nf_conn *ct; 1614f719e375SJulian Anastasov 1615f719e375SJulian Anastasov if (!(cp->flags & IP_VS_CONN_F_NFCT)) 1616f719e375SJulian Anastasov return false; 1617f719e375SJulian Anastasov ct = nf_ct_get(skb, &ctinfo); 1618ab8bc7edSFlorian Westphal if (ct) 1619f719e375SJulian Anastasov return true; 1620f719e375SJulian Anastasov #endif 1621f719e375SJulian Anastasov return false; 1622f719e375SJulian Anastasov } 1623f719e375SJulian Anastasov 1624*31875d49SJulian Anastasov static inline int ip_vs_register_conntrack(struct ip_vs_service *svc) 1625*31875d49SJulian Anastasov { 1626*31875d49SJulian Anastasov #if IS_ENABLED(CONFIG_NF_CONNTRACK) 1627*31875d49SJulian Anastasov int afmask = (svc->af == AF_INET6) ? 2 : 1; 1628*31875d49SJulian Anastasov int ret = 0; 1629*31875d49SJulian Anastasov 1630*31875d49SJulian Anastasov if (!(svc->conntrack_afmask & afmask)) { 1631*31875d49SJulian Anastasov ret = nf_ct_netns_get(svc->ipvs->net, svc->af); 1632*31875d49SJulian Anastasov if (ret >= 0) 1633*31875d49SJulian Anastasov svc->conntrack_afmask |= afmask; 1634*31875d49SJulian Anastasov } 1635*31875d49SJulian Anastasov return ret; 1636*31875d49SJulian Anastasov #else 1637*31875d49SJulian Anastasov return 0; 1638*31875d49SJulian Anastasov #endif 1639*31875d49SJulian Anastasov } 1640*31875d49SJulian Anastasov 1641*31875d49SJulian Anastasov static inline void ip_vs_unregister_conntrack(struct ip_vs_service *svc) 1642*31875d49SJulian Anastasov { 1643*31875d49SJulian Anastasov #if IS_ENABLED(CONFIG_NF_CONNTRACK) 1644*31875d49SJulian Anastasov int afmask = (svc->af == AF_INET6) ? 2 : 1; 1645*31875d49SJulian Anastasov 1646*31875d49SJulian Anastasov if (svc->conntrack_afmask & afmask) { 1647*31875d49SJulian Anastasov nf_ct_netns_put(svc->ipvs->net, svc->af); 1648*31875d49SJulian Anastasov svc->conntrack_afmask &= ~afmask; 1649*31875d49SJulian Anastasov } 1650*31875d49SJulian Anastasov #endif 1651*31875d49SJulian Anastasov } 1652*31875d49SJulian Anastasov 1653c16526a7SSimon Kirby static inline int 1654b552f7e3SChangli Gao ip_vs_dest_conn_overhead(struct ip_vs_dest *dest) 1655b552f7e3SChangli Gao { 165607dcc686SSimon Horman /* We think the overhead of processing active connections is 256 1657b552f7e3SChangli Gao * times higher than that of inactive connections in average. (This 1658b552f7e3SChangli Gao * 256 times might not be accurate, we will change it later) We 1659b552f7e3SChangli Gao * use the following formula to estimate the overhead now: 1660b552f7e3SChangli Gao * dest->activeconns*256 + dest->inactconns 1661b552f7e3SChangli Gao */ 1662b552f7e3SChangli Gao return (atomic_read(&dest->activeconns) << 8) + 1663b552f7e3SChangli Gao atomic_read(&dest->inactconns); 1664b552f7e3SChangli Gao } 1665b552f7e3SChangli Gao 1666bc4768ebSJulius Volz #endif /* _NET_IP_VS_H */ 1667