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 */ 3261b1ab45SHans Schillstrom 334fd9beefSAlex Gartrell #define IP_VS_HDR_INVERSE 1 344fd9beefSAlex Gartrell #define IP_VS_HDR_ICMP 2 354fd9beefSAlex Gartrell 3607dcc686SSimon Horman /* Generic access of ipvs struct */ 3761b1ab45SHans Schillstrom static inline struct netns_ipvs *net_ipvs(struct net* net) 3861b1ab45SHans Schillstrom { 3961b1ab45SHans Schillstrom return net->ipvs; 4061b1ab45SHans Schillstrom } 4107dcc686SSimon Horman 426f7edb48SCatalin(ux) M. BOIE /* Connections' size value needed by ip_vs_ctl.c */ 436f7edb48SCatalin(ux) M. BOIE extern int ip_vs_conn_tab_size; 446f7edb48SCatalin(ux) M. BOIE 4564aae3cbSJulius Volz struct ip_vs_iphdr { 464fd9beefSAlex Gartrell int hdr_flags; /* ipvs flags */ 47b0e010c5SAlex Gartrell __u32 off; /* Where IP or IPv4 header starts */ 4863dca2c0SJesper Dangaard Brouer __u32 len; /* IPv4 simply where L4 starts 4907dcc686SSimon Horman * IPv6 where L4 Transport Header starts */ 5063dca2c0SJesper Dangaard Brouer __u16 fragoffs; /* IPv6 fragment offset, 0 if first frag (or not frag)*/ 5163dca2c0SJesper Dangaard Brouer __s16 protocol; 5263dca2c0SJesper Dangaard Brouer __s32 flags; 5364aae3cbSJulius Volz union nf_inet_addr saddr; 5464aae3cbSJulius Volz union nf_inet_addr daddr; 5564aae3cbSJulius Volz }; 5664aae3cbSJulius Volz 572f74713dSJesper Dangaard Brouer static inline void *frag_safe_skb_hp(const struct sk_buff *skb, int offset, 586b3d9330SGao Feng int len, void *buffer) 592f74713dSJesper Dangaard Brouer { 602f74713dSJesper Dangaard Brouer return skb_header_pointer(skb, offset, len, buffer); 612f74713dSJesper Dangaard Brouer } 622f74713dSJesper Dangaard Brouer 6363dca2c0SJesper Dangaard Brouer /* This function handles filling *ip_vs_iphdr, both for IPv4 and IPv6. 6463dca2c0SJesper Dangaard Brouer * IPv6 requires some extra work, as finding proper header position, 6563dca2c0SJesper Dangaard Brouer * depend on the IPv6 extension headers. 6663dca2c0SJesper Dangaard Brouer */ 67b0e010c5SAlex Gartrell static inline int 68b0e010c5SAlex Gartrell ip_vs_fill_iph_skb_off(int af, const struct sk_buff *skb, int offset, 694fd9beefSAlex Gartrell int hdr_flags, struct ip_vs_iphdr *iphdr) 7064aae3cbSJulius Volz { 714fd9beefSAlex Gartrell iphdr->hdr_flags = hdr_flags; 72b0e010c5SAlex Gartrell iphdr->off = offset; 734fd9beefSAlex Gartrell 7464aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6 7564aae3cbSJulius Volz if (af == AF_INET6) { 76b0e010c5SAlex Gartrell struct ipv6hdr _iph; 77b0e010c5SAlex Gartrell const struct ipv6hdr *iph = skb_header_pointer( 78b0e010c5SAlex Gartrell skb, offset, sizeof(_iph), &_iph); 79b0e010c5SAlex Gartrell if (!iph) 80b0e010c5SAlex Gartrell return 0; 81b0e010c5SAlex Gartrell 824e3fd7a0SAlexey Dobriyan iphdr->saddr.in6 = iph->saddr; 834e3fd7a0SAlexey Dobriyan iphdr->daddr.in6 = iph->daddr; 846aafeef0SJiri Pirko /* ipv6_find_hdr() updates len, flags */ 85b0e010c5SAlex Gartrell iphdr->len = offset; 8663dca2c0SJesper Dangaard Brouer iphdr->flags = 0; 8763dca2c0SJesper Dangaard Brouer iphdr->protocol = ipv6_find_hdr(skb, &iphdr->len, -1, 8863dca2c0SJesper Dangaard Brouer &iphdr->fragoffs, 8963dca2c0SJesper Dangaard Brouer &iphdr->flags); 90b0e010c5SAlex Gartrell if (iphdr->protocol < 0) 91b0e010c5SAlex Gartrell return 0; 9264aae3cbSJulius Volz } else 9364aae3cbSJulius Volz #endif 9464aae3cbSJulius Volz { 95b0e010c5SAlex Gartrell struct iphdr _iph; 96b0e010c5SAlex Gartrell const struct iphdr *iph = skb_header_pointer( 97b0e010c5SAlex Gartrell skb, offset, sizeof(_iph), &_iph); 98b0e010c5SAlex Gartrell if (!iph) 99b0e010c5SAlex Gartrell return 0; 100b0e010c5SAlex Gartrell 101b0e010c5SAlex Gartrell iphdr->len = offset + iph->ihl * 4; 10263dca2c0SJesper Dangaard Brouer iphdr->fragoffs = 0; 10364aae3cbSJulius Volz iphdr->protocol = iph->protocol; 10464aae3cbSJulius Volz iphdr->saddr.ip = iph->saddr; 10564aae3cbSJulius Volz iphdr->daddr.ip = iph->daddr; 10664aae3cbSJulius Volz } 107b0e010c5SAlex Gartrell 108b0e010c5SAlex Gartrell return 1; 109b0e010c5SAlex Gartrell } 110b0e010c5SAlex Gartrell 111b0e010c5SAlex Gartrell static inline int 1124fd9beefSAlex Gartrell ip_vs_fill_iph_skb_icmp(int af, const struct sk_buff *skb, int offset, 1134fd9beefSAlex Gartrell bool inverse, struct ip_vs_iphdr *iphdr) 114b0e010c5SAlex Gartrell { 1154fd9beefSAlex Gartrell int hdr_flags = IP_VS_HDR_ICMP; 1164fd9beefSAlex Gartrell 1174fd9beefSAlex Gartrell if (inverse) 1184fd9beefSAlex Gartrell hdr_flags |= IP_VS_HDR_INVERSE; 1194fd9beefSAlex Gartrell 1204fd9beefSAlex Gartrell return ip_vs_fill_iph_skb_off(af, skb, offset, hdr_flags, iphdr); 1214fd9beefSAlex Gartrell } 1224fd9beefSAlex Gartrell 1234fd9beefSAlex Gartrell static inline int 1244fd9beefSAlex Gartrell ip_vs_fill_iph_skb(int af, const struct sk_buff *skb, bool inverse, 1254fd9beefSAlex Gartrell struct ip_vs_iphdr *iphdr) 1264fd9beefSAlex Gartrell { 1274fd9beefSAlex Gartrell int hdr_flags = 0; 1284fd9beefSAlex Gartrell 1294fd9beefSAlex Gartrell if (inverse) 1304fd9beefSAlex Gartrell hdr_flags |= IP_VS_HDR_INVERSE; 1314fd9beefSAlex Gartrell 1324fd9beefSAlex Gartrell return ip_vs_fill_iph_skb_off(af, skb, skb_network_offset(skb), 1334fd9beefSAlex Gartrell hdr_flags, iphdr); 1344fd9beefSAlex Gartrell } 1354fd9beefSAlex Gartrell 1364fd9beefSAlex Gartrell static inline bool 1374fd9beefSAlex Gartrell ip_vs_iph_inverse(const struct ip_vs_iphdr *iph) 1384fd9beefSAlex Gartrell { 1394fd9beefSAlex Gartrell return !!(iph->hdr_flags & IP_VS_HDR_INVERSE); 1404fd9beefSAlex Gartrell } 1414fd9beefSAlex Gartrell 1424fd9beefSAlex Gartrell static inline bool 1434fd9beefSAlex Gartrell ip_vs_iph_icmp(const struct ip_vs_iphdr *iph) 1444fd9beefSAlex Gartrell { 1454fd9beefSAlex Gartrell return !!(iph->hdr_flags & IP_VS_HDR_ICMP); 14664aae3cbSJulius Volz } 14764aae3cbSJulius Volz 14864aae3cbSJulius Volz static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst, 14964aae3cbSJulius Volz const union nf_inet_addr *src) 15064aae3cbSJulius Volz { 15164aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6 15264aae3cbSJulius Volz if (af == AF_INET6) 1534e3fd7a0SAlexey Dobriyan dst->in6 = src->in6; 15464aae3cbSJulius Volz else 15564aae3cbSJulius Volz #endif 15664aae3cbSJulius Volz dst->ip = src->ip; 15764aae3cbSJulius Volz } 15864aae3cbSJulius Volz 1599a05475cSJulian Anastasov static inline void ip_vs_addr_set(int af, union nf_inet_addr *dst, 1609a05475cSJulian Anastasov const union nf_inet_addr *src) 1619a05475cSJulian Anastasov { 1629a05475cSJulian Anastasov #ifdef CONFIG_IP_VS_IPV6 1639a05475cSJulian Anastasov if (af == AF_INET6) { 1649a05475cSJulian Anastasov dst->in6 = src->in6; 1659a05475cSJulian Anastasov return; 1669a05475cSJulian Anastasov } 1679a05475cSJulian Anastasov #endif 1689a05475cSJulian Anastasov dst->ip = src->ip; 1699a05475cSJulian Anastasov dst->all[1] = 0; 1709a05475cSJulian Anastasov dst->all[2] = 0; 1719a05475cSJulian Anastasov dst->all[3] = 0; 1729a05475cSJulian Anastasov } 1739a05475cSJulian Anastasov 17464aae3cbSJulius Volz static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a, 17564aae3cbSJulius Volz const union nf_inet_addr *b) 17664aae3cbSJulius Volz { 17764aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6 17864aae3cbSJulius Volz if (af == AF_INET6) 17964aae3cbSJulius Volz return ipv6_addr_equal(&a->in6, &b->in6); 18064aae3cbSJulius Volz #endif 18164aae3cbSJulius Volz return a->ip == b->ip; 18264aae3cbSJulius Volz } 18364aae3cbSJulius Volz 1841da177e4SLinus Torvalds #ifdef CONFIG_IP_VS_DEBUG 18514c85021SArnaldo Carvalho de Melo #include <linux/net.h> 18614c85021SArnaldo Carvalho de Melo 1875c3a0fd7SJoe Perches int ip_vs_get_debug_level(void); 188c842a3adSJulius Volz 189c842a3adSJulius Volz static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len, 190c842a3adSJulius Volz const union nf_inet_addr *addr, 191c842a3adSJulius Volz int *idx) 192c842a3adSJulius Volz { 193c842a3adSJulius Volz int len; 194c842a3adSJulius Volz #ifdef CONFIG_IP_VS_IPV6 195c842a3adSJulius Volz if (af == AF_INET6) 196120b9c14SJesper Dangaard Brouer len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6c]", 1970c6ce78aSHarvey Harrison &addr->in6) + 1; 198c842a3adSJulius Volz else 199c842a3adSJulius Volz #endif 2003685f25dSHarvey Harrison len = snprintf(&buf[*idx], buf_len - *idx, "%pI4", 2013685f25dSHarvey Harrison &addr->ip) + 1; 202c842a3adSJulius Volz 203c842a3adSJulius Volz *idx += len; 204c842a3adSJulius Volz BUG_ON(*idx > buf_len + 1); 205c842a3adSJulius Volz return &buf[*idx - len]; 206c842a3adSJulius Volz } 207c842a3adSJulius Volz 2089aada7acSHannes Eder #define IP_VS_DBG_BUF(level, msg, ...) \ 209c842a3adSJulius Volz do { \ 210c842a3adSJulius Volz char ip_vs_dbg_buf[160]; \ 211c842a3adSJulius Volz int ip_vs_dbg_idx = 0; \ 212c842a3adSJulius Volz if (level <= ip_vs_get_debug_level()) \ 2139aada7acSHannes Eder printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ 214c842a3adSJulius Volz } while (0) 215c842a3adSJulius Volz #define IP_VS_ERR_BUF(msg...) \ 216c842a3adSJulius Volz do { \ 217c842a3adSJulius Volz char ip_vs_dbg_buf[160]; \ 218c842a3adSJulius Volz int ip_vs_dbg_idx = 0; \ 2199aada7acSHannes Eder pr_err(msg); \ 220c842a3adSJulius Volz } while (0) 221c842a3adSJulius Volz 222c842a3adSJulius Volz /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */ 223c842a3adSJulius Volz #define IP_VS_DBG_ADDR(af, addr) \ 224c842a3adSJulius Volz ip_vs_dbg_addr(af, ip_vs_dbg_buf, \ 225c842a3adSJulius Volz sizeof(ip_vs_dbg_buf), addr, \ 226c842a3adSJulius Volz &ip_vs_dbg_idx) 227c842a3adSJulius Volz 2289aada7acSHannes Eder #define IP_VS_DBG(level, msg, ...) \ 2291da177e4SLinus Torvalds do { \ 2301da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \ 2319aada7acSHannes Eder printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ 2321da177e4SLinus Torvalds } while (0) 2339aada7acSHannes Eder #define IP_VS_DBG_RL(msg, ...) \ 2341da177e4SLinus Torvalds do { \ 2351da177e4SLinus Torvalds if (net_ratelimit()) \ 2369aada7acSHannes Eder printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ 2371da177e4SLinus Torvalds } while (0) 2380d79641aSJulian Anastasov #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) \ 2391da177e4SLinus Torvalds do { \ 2401da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \ 2410d79641aSJulian Anastasov pp->debug_packet(af, pp, skb, ofs, msg); \ 2421da177e4SLinus Torvalds } while (0) 2430d79641aSJulian Anastasov #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) \ 2441da177e4SLinus Torvalds do { \ 2451da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level() && \ 2461da177e4SLinus Torvalds net_ratelimit()) \ 2470d79641aSJulian Anastasov pp->debug_packet(af, pp, skb, ofs, msg); \ 2481da177e4SLinus Torvalds } while (0) 2491da177e4SLinus Torvalds #else /* NO DEBUGGING at ALL */ 250c842a3adSJulius Volz #define IP_VS_DBG_BUF(level, msg...) do {} while (0) 251c842a3adSJulius Volz #define IP_VS_ERR_BUF(msg...) do {} while (0) 2521da177e4SLinus Torvalds #define IP_VS_DBG(level, msg...) do {} while (0) 2531da177e4SLinus Torvalds #define IP_VS_DBG_RL(msg...) do {} while (0) 2540d79641aSJulian Anastasov #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) do {} while (0) 2550d79641aSJulian Anastasov #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) do {} while (0) 2561da177e4SLinus Torvalds #endif 2571da177e4SLinus Torvalds 2581da177e4SLinus Torvalds #define IP_VS_BUG() BUG() 2591e3e238eSHannes Eder #define IP_VS_ERR_RL(msg, ...) \ 2601da177e4SLinus Torvalds do { \ 2611da177e4SLinus Torvalds if (net_ratelimit()) \ 2621e3e238eSHannes Eder pr_err(msg, ##__VA_ARGS__); \ 2631da177e4SLinus Torvalds } while (0) 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds #ifdef CONFIG_IP_VS_DEBUG 2661da177e4SLinus Torvalds #define EnterFunction(level) \ 2671da177e4SLinus Torvalds do { \ 2681da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \ 2699aada7acSHannes Eder printk(KERN_DEBUG \ 2709aada7acSHannes Eder pr_fmt("Enter: %s, %s line %i\n"), \ 271d5c003b4SHarvey Harrison __func__, __FILE__, __LINE__); \ 2721da177e4SLinus Torvalds } while (0) 2731da177e4SLinus Torvalds #define LeaveFunction(level) \ 2741da177e4SLinus Torvalds do { \ 2751da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \ 2769aada7acSHannes Eder printk(KERN_DEBUG \ 2779aada7acSHannes Eder pr_fmt("Leave: %s, %s line %i\n"), \ 278d5c003b4SHarvey Harrison __func__, __FILE__, __LINE__); \ 2791da177e4SLinus Torvalds } while (0) 2801da177e4SLinus Torvalds #else 2811da177e4SLinus Torvalds #define EnterFunction(level) do {} while (0) 2821da177e4SLinus Torvalds #define LeaveFunction(level) do {} while (0) 2831da177e4SLinus Torvalds #endif 2841da177e4SLinus Torvalds 28507dcc686SSimon Horman /* The port number of FTP service (in network order). */ 286f3a7c66bSHarvey Harrison #define FTPPORT cpu_to_be16(21) 287f3a7c66bSHarvey Harrison #define FTPDATA cpu_to_be16(20) 2881da177e4SLinus Torvalds 28907dcc686SSimon Horman /* TCP State Values */ 2901da177e4SLinus Torvalds enum { 2911da177e4SLinus Torvalds IP_VS_TCP_S_NONE = 0, 2921da177e4SLinus Torvalds IP_VS_TCP_S_ESTABLISHED, 2931da177e4SLinus Torvalds IP_VS_TCP_S_SYN_SENT, 2941da177e4SLinus Torvalds IP_VS_TCP_S_SYN_RECV, 2951da177e4SLinus Torvalds IP_VS_TCP_S_FIN_WAIT, 2961da177e4SLinus Torvalds IP_VS_TCP_S_TIME_WAIT, 2971da177e4SLinus Torvalds IP_VS_TCP_S_CLOSE, 2981da177e4SLinus Torvalds IP_VS_TCP_S_CLOSE_WAIT, 2991da177e4SLinus Torvalds IP_VS_TCP_S_LAST_ACK, 3001da177e4SLinus Torvalds IP_VS_TCP_S_LISTEN, 3011da177e4SLinus Torvalds IP_VS_TCP_S_SYNACK, 3021da177e4SLinus Torvalds IP_VS_TCP_S_LAST 3031da177e4SLinus Torvalds }; 3041da177e4SLinus Torvalds 30507dcc686SSimon Horman /* UDP State Values */ 3061da177e4SLinus Torvalds enum { 3071da177e4SLinus Torvalds IP_VS_UDP_S_NORMAL, 3081da177e4SLinus Torvalds IP_VS_UDP_S_LAST, 3091da177e4SLinus Torvalds }; 3101da177e4SLinus Torvalds 31107dcc686SSimon Horman /* ICMP State Values */ 3121da177e4SLinus Torvalds enum { 3131da177e4SLinus Torvalds IP_VS_ICMP_S_NORMAL, 3141da177e4SLinus Torvalds IP_VS_ICMP_S_LAST, 3151da177e4SLinus Torvalds }; 3161da177e4SLinus Torvalds 31707dcc686SSimon Horman /* SCTP State Values */ 3182906f66aSVenkata Mohan Reddy enum ip_vs_sctp_states { 3192906f66aSVenkata Mohan Reddy IP_VS_SCTP_S_NONE, 32061e7c420SJulian Anastasov IP_VS_SCTP_S_INIT1, 32161e7c420SJulian Anastasov IP_VS_SCTP_S_INIT, 32261e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE_SENT, 32361e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE_REPLIED, 32461e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE_WAIT, 32561e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE, 32661e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE_ECHOED, 3272906f66aSVenkata Mohan Reddy IP_VS_SCTP_S_ESTABLISHED, 32861e7c420SJulian Anastasov IP_VS_SCTP_S_SHUTDOWN_SENT, 32961e7c420SJulian Anastasov IP_VS_SCTP_S_SHUTDOWN_RECEIVED, 33061e7c420SJulian Anastasov IP_VS_SCTP_S_SHUTDOWN_ACK_SENT, 33161e7c420SJulian Anastasov IP_VS_SCTP_S_REJECTED, 3322906f66aSVenkata Mohan Reddy IP_VS_SCTP_S_CLOSED, 3332906f66aSVenkata Mohan Reddy IP_VS_SCTP_S_LAST 3342906f66aSVenkata Mohan Reddy }; 3352906f66aSVenkata Mohan Reddy 33627541143SJulian Anastasov /* Connection templates use bits from state */ 33727541143SJulian Anastasov #define IP_VS_CTPL_S_NONE 0x0000 33827541143SJulian Anastasov #define IP_VS_CTPL_S_ASSURED 0x0001 33927541143SJulian Anastasov #define IP_VS_CTPL_S_LAST 0x0002 34027541143SJulian Anastasov 34107dcc686SSimon Horman /* Delta sequence info structure 3421da177e4SLinus Torvalds * Each ip_vs_conn has 2 (output AND input seq. changes). 3431da177e4SLinus Torvalds * Only used in the VS/NAT. 3441da177e4SLinus Torvalds */ 3451da177e4SLinus Torvalds struct ip_vs_seq { 3461da177e4SLinus Torvalds __u32 init_seq; /* Add delta from this seq */ 3471da177e4SLinus Torvalds __u32 delta; /* Delta in sequence numbers */ 3481da177e4SLinus Torvalds __u32 previous_delta; /* Delta in sequence numbers 34907dcc686SSimon Horman * before last resized pkt */ 3501da177e4SLinus Torvalds }; 3511da177e4SLinus Torvalds 35207dcc686SSimon Horman /* counters per cpu */ 353b17fc996SHans Schillstrom struct ip_vs_counters { 354cd67cd5eSJulian Anastasov __u64 conns; /* connections scheduled */ 355cd67cd5eSJulian Anastasov __u64 inpkts; /* incoming packets */ 356cd67cd5eSJulian Anastasov __u64 outpkts; /* outgoing packets */ 357b17fc996SHans Schillstrom __u64 inbytes; /* incoming bytes */ 358b17fc996SHans Schillstrom __u64 outbytes; /* outgoing bytes */ 359b17fc996SHans Schillstrom }; 36007dcc686SSimon Horman /* Stats per cpu */ 361b17fc996SHans Schillstrom struct ip_vs_cpu_stats { 362cd67cd5eSJulian Anastasov struct ip_vs_counters cnt; 363b17fc996SHans Schillstrom struct u64_stats_sync syncp; 364b17fc996SHans Schillstrom }; 3651da177e4SLinus Torvalds 36607dcc686SSimon Horman /* IPVS statistics objects */ 3673a14a313SSven Wegener struct ip_vs_estimator { 3683a14a313SSven Wegener struct list_head list; 3693a14a313SSven Wegener 3703a14a313SSven Wegener u64 last_inbytes; 3713a14a313SSven Wegener u64 last_outbytes; 372cd67cd5eSJulian Anastasov u64 last_conns; 373cd67cd5eSJulian Anastasov u64 last_inpkts; 374cd67cd5eSJulian Anastasov u64 last_outpkts; 3753a14a313SSven Wegener 376cd67cd5eSJulian Anastasov u64 cps; 377cd67cd5eSJulian Anastasov u64 inpps; 378cd67cd5eSJulian Anastasov u64 outpps; 379cd67cd5eSJulian Anastasov u64 inbps; 380cd67cd5eSJulian Anastasov u64 outbps; 381cd67cd5eSJulian Anastasov }; 382cd67cd5eSJulian Anastasov 383cd67cd5eSJulian Anastasov /* 384cd67cd5eSJulian Anastasov * IPVS statistics object, 64-bit kernel version of struct ip_vs_stats_user 385cd67cd5eSJulian Anastasov */ 386cd67cd5eSJulian Anastasov struct ip_vs_kstats { 387cd67cd5eSJulian Anastasov u64 conns; /* connections scheduled */ 388cd67cd5eSJulian Anastasov u64 inpkts; /* incoming packets */ 389cd67cd5eSJulian Anastasov u64 outpkts; /* outgoing packets */ 390cd67cd5eSJulian Anastasov u64 inbytes; /* incoming bytes */ 391cd67cd5eSJulian Anastasov u64 outbytes; /* outgoing bytes */ 392cd67cd5eSJulian Anastasov 393cd67cd5eSJulian Anastasov u64 cps; /* current connection rate */ 394cd67cd5eSJulian Anastasov u64 inpps; /* current in packet rate */ 395cd67cd5eSJulian Anastasov u64 outpps; /* current out packet rate */ 396cd67cd5eSJulian Anastasov u64 inbps; /* current in byte rate */ 397cd67cd5eSJulian Anastasov u64 outbps; /* current out byte rate */ 3983a14a313SSven Wegener }; 3993a14a313SSven Wegener 400fd2c3ef7SEric Dumazet struct ip_vs_stats { 401cd67cd5eSJulian Anastasov struct ip_vs_kstats kstats; /* kernel statistics */ 402e9c0ce23SSven Wegener struct ip_vs_estimator est; /* estimator */ 403b962abdcSJulian Anastasov struct ip_vs_cpu_stats __percpu *cpustats; /* per cpu counters */ 4041da177e4SLinus Torvalds spinlock_t lock; /* spin lock */ 405cd67cd5eSJulian Anastasov struct ip_vs_kstats kstats0; /* reset values */ 4061da177e4SLinus Torvalds }; 4071da177e4SLinus Torvalds 40814c85021SArnaldo Carvalho de Melo struct dst_entry; 40914c85021SArnaldo Carvalho de Melo struct iphdr; 4101da177e4SLinus Torvalds struct ip_vs_conn; 4111da177e4SLinus Torvalds struct ip_vs_app; 41214c85021SArnaldo Carvalho de Melo struct sk_buff; 413252c6410SHans Schillstrom struct ip_vs_proto_data; 4141da177e4SLinus Torvalds 4151da177e4SLinus Torvalds struct ip_vs_protocol { 4161da177e4SLinus Torvalds struct ip_vs_protocol *next; 4171da177e4SLinus Torvalds char *name; 4182ad17defSJulian Anastasov u16 protocol; 4192ad17defSJulian Anastasov u16 num_states; 4201da177e4SLinus Torvalds int dont_defrag; 4211da177e4SLinus Torvalds 4221da177e4SLinus Torvalds void (*init)(struct ip_vs_protocol *pp); 4231da177e4SLinus Torvalds 4241da177e4SLinus Torvalds void (*exit)(struct ip_vs_protocol *pp); 4251da177e4SLinus Torvalds 4261281a9c2SEric W. Biederman int (*init_netns)(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd); 427252c6410SHans Schillstrom 4281281a9c2SEric W. Biederman void (*exit_netns)(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd); 429252c6410SHans Schillstrom 430d8f44c33SEric W. Biederman int (*conn_schedule)(struct netns_ipvs *ipvs, 431d8f44c33SEric W. Biederman int af, struct sk_buff *skb, 4329330419dSHans Schillstrom struct ip_vs_proto_data *pd, 433d4383f04SJesper Dangaard Brouer int *verdict, struct ip_vs_conn **cpp, 434d4383f04SJesper Dangaard Brouer struct ip_vs_iphdr *iph); 4351da177e4SLinus Torvalds 4361da177e4SLinus Torvalds struct ip_vs_conn * 437ab161976SEric W. Biederman (*conn_in_get)(struct netns_ipvs *ipvs, 438ab161976SEric W. Biederman int af, 43951ef348bSJulius Volz const struct sk_buff *skb, 440802c41adSAlex Gartrell const struct ip_vs_iphdr *iph); 4411da177e4SLinus Torvalds 4421da177e4SLinus Torvalds struct ip_vs_conn * 4430cf705c8SEric W. Biederman (*conn_out_get)(struct netns_ipvs *ipvs, 4440cf705c8SEric W. Biederman int af, 44551ef348bSJulius Volz const struct sk_buff *skb, 446802c41adSAlex Gartrell const struct ip_vs_iphdr *iph); 4471da177e4SLinus Torvalds 448d4383f04SJesper Dangaard Brouer int (*snat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp, 449d4383f04SJesper Dangaard Brouer struct ip_vs_conn *cp, struct ip_vs_iphdr *iph); 4501da177e4SLinus Torvalds 451d4383f04SJesper Dangaard Brouer int (*dnat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp, 452d4383f04SJesper Dangaard Brouer struct ip_vs_conn *cp, struct ip_vs_iphdr *iph); 4531da177e4SLinus Torvalds 4541da177e4SLinus Torvalds const char *(*state_name)(int state); 4551da177e4SLinus Torvalds 4564a516f11SSimon Horman void (*state_transition)(struct ip_vs_conn *cp, int direction, 4571da177e4SLinus Torvalds const struct sk_buff *skb, 4589330419dSHans Schillstrom struct ip_vs_proto_data *pd); 4591da177e4SLinus Torvalds 46019648918SEric W. Biederman int (*register_app)(struct netns_ipvs *ipvs, struct ip_vs_app *inc); 4611da177e4SLinus Torvalds 46219648918SEric W. Biederman void (*unregister_app)(struct netns_ipvs *ipvs, struct ip_vs_app *inc); 4631da177e4SLinus Torvalds 4641da177e4SLinus Torvalds int (*app_conn_bind)(struct ip_vs_conn *cp); 4651da177e4SLinus Torvalds 4660d79641aSJulian Anastasov void (*debug_packet)(int af, struct ip_vs_protocol *pp, 4671da177e4SLinus Torvalds const struct sk_buff *skb, 4681da177e4SLinus Torvalds int offset, 4691da177e4SLinus Torvalds const char *msg); 4701da177e4SLinus Torvalds 4719330419dSHans Schillstrom void (*timeout_change)(struct ip_vs_proto_data *pd, int flags); 4721da177e4SLinus Torvalds }; 4731da177e4SLinus Torvalds 47407dcc686SSimon Horman /* protocol data per netns */ 475252c6410SHans Schillstrom struct ip_vs_proto_data { 476252c6410SHans Schillstrom struct ip_vs_proto_data *next; 477252c6410SHans Schillstrom struct ip_vs_protocol *pp; 478252c6410SHans Schillstrom int *timeout_table; /* protocol timeout table */ 479252c6410SHans Schillstrom atomic_t appcnt; /* counter of proto app incs. */ 480252c6410SHans Schillstrom struct tcp_states_t *tcp_state_table; 481252c6410SHans Schillstrom }; 482252c6410SHans Schillstrom 4835c3a0fd7SJoe Perches struct ip_vs_protocol *ip_vs_proto_get(unsigned short proto); 48418d6ade6SEric W. Biederman struct ip_vs_proto_data *ip_vs_proto_data_get(struct netns_ipvs *ipvs, 485252c6410SHans Schillstrom unsigned short proto); 4861da177e4SLinus Torvalds 487f11017ecSSimon Horman struct ip_vs_conn_param { 488e64e2b46SEric W. Biederman struct netns_ipvs *ipvs; 489f11017ecSSimon Horman const union nf_inet_addr *caddr; 490f11017ecSSimon Horman const union nf_inet_addr *vaddr; 491f11017ecSSimon Horman __be16 cport; 492f11017ecSSimon Horman __be16 vport; 493f11017ecSSimon Horman __u16 protocol; 494f11017ecSSimon Horman u16 af; 49585999283SSimon Horman 49685999283SSimon Horman const struct ip_vs_pe *pe; 49785999283SSimon Horman char *pe_data; 49885999283SSimon Horman __u8 pe_data_len; 499f11017ecSSimon Horman }; 500f11017ecSSimon Horman 50107dcc686SSimon Horman /* IP_VS structure allocated for each dynamically scheduled connection */ 5021da177e4SLinus Torvalds struct ip_vs_conn { 503731109e7SChangli Gao struct hlist_node c_list; /* hashed list heads */ 5041da177e4SLinus Torvalds /* Protocol, addresses and port numbers */ 5056e67e586SHans Schillstrom __be16 cport; 5066e67e586SHans Schillstrom __be16 dport; 5071845ed0bSJulian Anastasov __be16 vport; 5081845ed0bSJulian Anastasov u16 af; /* address family */ 509e7ade46aSJulius Volz union nf_inet_addr caddr; /* client address */ 510e7ade46aSJulius Volz union nf_inet_addr vaddr; /* virtual address */ 511e7ade46aSJulius Volz union nf_inet_addr daddr; /* destination address */ 5123575792eSJulian Anastasov volatile __u32 flags; /* status flags */ 5131da177e4SLinus Torvalds __u16 protocol; /* Which protocol (TCP/UDP) */ 514ba38528aSAlex Gartrell __u16 daf; /* Address family of the dest */ 51558dbc6f2SEric W. Biederman struct netns_ipvs *ipvs; 5161da177e4SLinus Torvalds 5171da177e4SLinus Torvalds /* counter and timer */ 518b54ab92bSReshetova, Elena refcount_t refcnt; /* reference count */ 5191da177e4SLinus Torvalds struct timer_list timer; /* Expiration timer */ 5201da177e4SLinus Torvalds volatile unsigned long timeout; /* timeout */ 5211da177e4SLinus Torvalds 5221da177e4SLinus Torvalds /* Flags and state transition */ 5231da177e4SLinus Torvalds spinlock_t lock; /* lock for state transition */ 5241da177e4SLinus Torvalds volatile __u16 state; /* state info */ 525efac5276SRumen G. Bogdanovski volatile __u16 old_state; /* old state, to be used for 526efac5276SRumen G. Bogdanovski * state transition triggerd 527efac5276SRumen G. Bogdanovski * synchronization 528efac5276SRumen G. Bogdanovski */ 5291845ed0bSJulian Anastasov __u32 fwmark; /* Fire wall mark from skb */ 530749c42b6SJulian Anastasov unsigned long sync_endtime; /* jiffies + sent_retries */ 5311da177e4SLinus Torvalds 5321da177e4SLinus Torvalds /* Control members */ 5331da177e4SLinus Torvalds struct ip_vs_conn *control; /* Master control connection */ 5341da177e4SLinus Torvalds atomic_t n_control; /* Number of controlled ones */ 5351da177e4SLinus Torvalds struct ip_vs_dest *dest; /* real server */ 5361da177e4SLinus Torvalds atomic_t in_pkts; /* incoming packet counter */ 5371da177e4SLinus Torvalds 53807dcc686SSimon Horman /* Packet transmitter for different forwarding methods. If it 53907dcc686SSimon Horman * mangles the packet, it must return NF_DROP or better NF_STOLEN, 54007dcc686SSimon Horman * otherwise this must be changed to a sk_buff **. 54107dcc686SSimon Horman * NF_ACCEPT can be returned when destination is local. 5421da177e4SLinus Torvalds */ 5431da177e4SLinus Torvalds int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp, 544d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 5451da177e4SLinus Torvalds 5461da177e4SLinus Torvalds /* Note: we can group the following members into a structure, 54707dcc686SSimon Horman * in order to save more space, and the following members are 54807dcc686SSimon Horman * only used in VS/NAT anyway 54907dcc686SSimon Horman */ 5501da177e4SLinus Torvalds struct ip_vs_app *app; /* bound ip_vs_app object */ 5511da177e4SLinus Torvalds void *app_data; /* Application private data */ 5521da177e4SLinus Torvalds struct ip_vs_seq in_seq; /* incoming seq. struct */ 5531da177e4SLinus Torvalds struct ip_vs_seq out_seq; /* outgoing seq. struct */ 55485999283SSimon Horman 555e9e5eee8SSimon Horman const struct ip_vs_pe *pe; 55685999283SSimon Horman char *pe_data; 55785999283SSimon Horman __u8 pe_data_len; 558088339a5SJulian Anastasov 559088339a5SJulian Anastasov struct rcu_head rcu_head; 5601da177e4SLinus Torvalds }; 5611da177e4SLinus Torvalds 56207dcc686SSimon Horman /* Extended internal versions of struct ip_vs_service_user and ip_vs_dest_user 56307dcc686SSimon Horman * for IPv6 support. 564c860c6b1SJulius Volz * 565c860c6b1SJulius Volz * We need these to conveniently pass around service and destination 566c860c6b1SJulius Volz * options, but unfortunately, we also need to keep the old definitions to 567c860c6b1SJulius Volz * maintain userspace backwards compatibility for the setsockopt interface. 568c860c6b1SJulius Volz */ 569c860c6b1SJulius Volz struct ip_vs_service_user_kern { 570c860c6b1SJulius Volz /* virtual service addresses */ 571c860c6b1SJulius Volz u16 af; 572c860c6b1SJulius Volz u16 protocol; 573c860c6b1SJulius Volz union nf_inet_addr addr; /* virtual ip address */ 5740a925864SJulian Anastasov __be16 port; 575c860c6b1SJulius Volz u32 fwmark; /* firwall mark of service */ 576c860c6b1SJulius Volz 577c860c6b1SJulius Volz /* virtual service options */ 578c860c6b1SJulius Volz char *sched_name; 5790d1e71b0SSimon Horman char *pe_name; 58095c96174SEric Dumazet unsigned int flags; /* virtual service flags */ 58195c96174SEric Dumazet unsigned int timeout; /* persistent timeout in sec */ 5820a925864SJulian Anastasov __be32 netmask; /* persistent netmask or plen */ 583c860c6b1SJulius Volz }; 584c860c6b1SJulius Volz 585c860c6b1SJulius Volz 586c860c6b1SJulius Volz struct ip_vs_dest_user_kern { 587c860c6b1SJulius Volz /* destination server address */ 588c860c6b1SJulius Volz union nf_inet_addr addr; 5890a925864SJulian Anastasov __be16 port; 590c860c6b1SJulius Volz 591c860c6b1SJulius Volz /* real server options */ 59295c96174SEric Dumazet unsigned int conn_flags; /* connection flags */ 593c860c6b1SJulius Volz int weight; /* destination weight */ 594c860c6b1SJulius Volz 595c860c6b1SJulius Volz /* thresholds for active connections */ 596c860c6b1SJulius Volz u32 u_threshold; /* upper threshold */ 597c860c6b1SJulius Volz u32 l_threshold; /* lower threshold */ 5986cff339bSAlex Gartrell 5996cff339bSAlex Gartrell /* Address family of addr */ 6006cff339bSAlex Gartrell u16 af; 60184c0d5e9SJacky Hu 60284c0d5e9SJacky Hu u16 tun_type; /* tunnel type */ 60384c0d5e9SJacky Hu __be16 tun_port; /* tunnel port */ 60429930e31SJacky Hu u16 tun_flags; /* tunnel flags */ 605c860c6b1SJulius Volz }; 606c860c6b1SJulius Volz 607c860c6b1SJulius Volz 608c860c6b1SJulius Volz /* 60907dcc686SSimon Horman * The information about the virtual service offered to the net and the 61007dcc686SSimon Horman * forwarding entries. 6111da177e4SLinus Torvalds */ 6121da177e4SLinus Torvalds struct ip_vs_service { 613ceec4c38SJulian Anastasov struct hlist_node s_list; /* for normal service table */ 614ceec4c38SJulian Anastasov struct hlist_node f_list; /* for fwmark-based service table */ 6151da177e4SLinus Torvalds atomic_t refcnt; /* reference counter */ 6161da177e4SLinus Torvalds 617e7ade46aSJulius Volz u16 af; /* address family */ 6181da177e4SLinus Torvalds __u16 protocol; /* which protocol (TCP/UDP) */ 619e7ade46aSJulius Volz union nf_inet_addr addr; /* IP address for virtual service */ 620014d730dSAl Viro __be16 port; /* port number for the service */ 6211da177e4SLinus Torvalds __u32 fwmark; /* firewall mark of the service */ 62295c96174SEric Dumazet unsigned int flags; /* service status flags */ 62395c96174SEric Dumazet unsigned int timeout; /* persistent timeout in ticks */ 6240a925864SJulian Anastasov __be32 netmask; /* grouping granularity, mask/plen */ 6253109d2f2SEric W. Biederman struct netns_ipvs *ipvs; 6261da177e4SLinus Torvalds 6271da177e4SLinus Torvalds struct list_head destinations; /* real server d-linked list */ 6281da177e4SLinus Torvalds __u32 num_dests; /* number of servers */ 6291da177e4SLinus Torvalds struct ip_vs_stats stats; /* statistics for the service */ 6301da177e4SLinus Torvalds 6311da177e4SLinus Torvalds /* for scheduling */ 632ceec4c38SJulian Anastasov struct ip_vs_scheduler __rcu *scheduler; /* bound scheduler object */ 633ba3a3ce1SJulian Anastasov spinlock_t sched_lock; /* lock sched_data */ 6341da177e4SLinus Torvalds void *sched_data; /* scheduler application data */ 63585999283SSimon Horman 63685999283SSimon Horman /* alternate persistence engine */ 637ceec4c38SJulian Anastasov struct ip_vs_pe __rcu *pe; 63831875d49SJulian Anastasov int conntrack_afmask; 639ceec4c38SJulian Anastasov 640ceec4c38SJulian Anastasov struct rcu_head rcu_head; 6411da177e4SLinus Torvalds }; 6421da177e4SLinus Torvalds 643026ace06SJulian Anastasov /* Information for cached dst */ 644026ace06SJulian Anastasov struct ip_vs_dest_dst { 645026ace06SJulian Anastasov struct dst_entry *dst_cache; /* destination cache entry */ 646026ace06SJulian Anastasov u32 dst_cookie; 647026ace06SJulian Anastasov union nf_inet_addr dst_saddr; 648026ace06SJulian Anastasov struct rcu_head rcu_head; 649026ace06SJulian Anastasov }; 6501da177e4SLinus Torvalds 65107dcc686SSimon Horman /* The real server destination forwarding entry with ip address, port number, 65207dcc686SSimon Horman * and so on. 6531da177e4SLinus Torvalds */ 6541da177e4SLinus Torvalds struct ip_vs_dest { 6551da177e4SLinus Torvalds struct list_head n_list; /* for the dests in the service */ 656276472eaSJulian Anastasov struct hlist_node d_list; /* for table with all the dests */ 6571da177e4SLinus Torvalds 658e7ade46aSJulius Volz u16 af; /* address family */ 659014d730dSAl Viro __be16 port; /* port number of the server */ 660f2431e6eSHans Schillstrom union nf_inet_addr addr; /* IP address of the server */ 66195c96174SEric Dumazet volatile unsigned int flags; /* dest status flags */ 6621da177e4SLinus Torvalds atomic_t conn_flags; /* flags to copy to conn */ 6631da177e4SLinus Torvalds atomic_t weight; /* server weight */ 664a2c09ac0SInju Song atomic_t last_weight; /* server latest weight */ 66584c0d5e9SJacky Hu __u16 tun_type; /* tunnel type */ 66684c0d5e9SJacky Hu __be16 tun_port; /* tunnel port */ 66729930e31SJacky Hu __u16 tun_flags; /* tunnel flags */ 6681da177e4SLinus Torvalds 669b54ab92bSReshetova, Elena refcount_t refcnt; /* reference counter */ 6701da177e4SLinus Torvalds struct ip_vs_stats stats; /* statistics */ 671bcbde4c0SJulian Anastasov unsigned long idle_start; /* start time, jiffies */ 6721da177e4SLinus Torvalds 6731da177e4SLinus Torvalds /* connection counters and thresholds */ 6741da177e4SLinus Torvalds atomic_t activeconns; /* active connections */ 6751da177e4SLinus Torvalds atomic_t inactconns; /* inactive connections */ 6761da177e4SLinus Torvalds atomic_t persistconns; /* persistent connections */ 6771da177e4SLinus Torvalds __u32 u_threshold; /* upper threshold */ 6781da177e4SLinus Torvalds __u32 l_threshold; /* lower threshold */ 6791da177e4SLinus Torvalds 6801da177e4SLinus Torvalds /* for destination cache */ 6811da177e4SLinus Torvalds spinlock_t dst_lock; /* lock of dst_cache */ 682026ace06SJulian Anastasov struct ip_vs_dest_dst __rcu *dest_dst; /* cached dst info */ 6831da177e4SLinus Torvalds 6841da177e4SLinus Torvalds /* for virtual service */ 685bcbde4c0SJulian Anastasov struct ip_vs_service __rcu *svc; /* service it belongs to */ 6861da177e4SLinus Torvalds __u16 protocol; /* which protocol (TCP/UDP) */ 687014d730dSAl Viro __be16 vport; /* virtual port number */ 688f2431e6eSHans Schillstrom union nf_inet_addr vaddr; /* virtual IP address */ 6891da177e4SLinus Torvalds __u32 vfwmark; /* firewall mark of service */ 690276472eaSJulian Anastasov 691578bc3efSJulian Anastasov struct list_head t_list; /* in dest_trash */ 692276472eaSJulian Anastasov unsigned int in_rs_table:1; /* we are in rs_table */ 6931da177e4SLinus Torvalds }; 6941da177e4SLinus Torvalds 69507dcc686SSimon Horman /* The scheduler object */ 6961da177e4SLinus Torvalds struct ip_vs_scheduler { 6971da177e4SLinus Torvalds struct list_head n_list; /* d-linked list head */ 6981da177e4SLinus Torvalds char *name; /* scheduler name */ 6991da177e4SLinus Torvalds atomic_t refcnt; /* reference counter */ 7001da177e4SLinus Torvalds struct module *module; /* THIS_MODULE/NULL */ 7011da177e4SLinus Torvalds 7021da177e4SLinus Torvalds /* scheduler initializing service */ 7031da177e4SLinus Torvalds int (*init_service)(struct ip_vs_service *svc); 7041da177e4SLinus Torvalds /* scheduling service finish */ 705ed3ffc4eSJulian Anastasov void (*done_service)(struct ip_vs_service *svc); 7066b6df466SJulian Anastasov /* dest is linked */ 7076b6df466SJulian Anastasov int (*add_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest); 7086b6df466SJulian Anastasov /* dest is unlinked */ 7096b6df466SJulian Anastasov int (*del_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest); 7106b6df466SJulian Anastasov /* dest is updated */ 7116b6df466SJulian Anastasov int (*upd_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest); 7121da177e4SLinus Torvalds 7131da177e4SLinus Torvalds /* selecting a server from the given service */ 7141da177e4SLinus Torvalds struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc, 715bba54de5SJulian Anastasov const struct sk_buff *skb, 716bba54de5SJulian Anastasov struct ip_vs_iphdr *iph); 7171da177e4SLinus Torvalds }; 7181da177e4SLinus Torvalds 71985999283SSimon Horman /* The persistence engine object */ 72085999283SSimon Horman struct ip_vs_pe { 72185999283SSimon Horman struct list_head n_list; /* d-linked list head */ 72285999283SSimon Horman char *name; /* scheduler name */ 72385999283SSimon Horman atomic_t refcnt; /* reference counter */ 72485999283SSimon Horman struct module *module; /* THIS_MODULE/NULL */ 72585999283SSimon Horman 72685999283SSimon Horman /* get the connection template, if any */ 72785999283SSimon Horman int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb); 72885999283SSimon Horman bool (*ct_match)(const struct ip_vs_conn_param *p, 72985999283SSimon Horman struct ip_vs_conn *ct); 73085999283SSimon Horman u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval, 73185999283SSimon Horman bool inverse); 732a3c918acSSimon Horman int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf); 73339b97223SMarco Angaroni /* create connections for real-server outgoing packets */ 73439b97223SMarco Angaroni struct ip_vs_conn* (*conn_out)(struct ip_vs_service *svc, 73539b97223SMarco Angaroni struct ip_vs_dest *dest, 73639b97223SMarco Angaroni struct sk_buff *skb, 73739b97223SMarco Angaroni const struct ip_vs_iphdr *iph, 73839b97223SMarco Angaroni __be16 dport, __be16 cport); 73985999283SSimon Horman }; 7401da177e4SLinus Torvalds 74107dcc686SSimon Horman /* The application module object (a.k.a. app incarnation) */ 742fd2c3ef7SEric Dumazet struct ip_vs_app { 7431da177e4SLinus Torvalds struct list_head a_list; /* member in app list */ 7441da177e4SLinus Torvalds int type; /* IP_VS_APP_TYPE_xxx */ 7451da177e4SLinus Torvalds char *name; /* application module name */ 7461da177e4SLinus Torvalds __u16 protocol; 7471da177e4SLinus Torvalds struct module *module; /* THIS_MODULE/NULL */ 7481da177e4SLinus Torvalds struct list_head incs_list; /* list of incarnations */ 7491da177e4SLinus Torvalds 7501da177e4SLinus Torvalds /* members for application incarnations */ 7511da177e4SLinus Torvalds struct list_head p_list; /* member in proto app list */ 7521da177e4SLinus Torvalds struct ip_vs_app *app; /* its real application */ 753014d730dSAl Viro __be16 port; /* port number in net order */ 7541da177e4SLinus Torvalds atomic_t usecnt; /* usage counter */ 755363c97d7SJulian Anastasov struct rcu_head rcu_head; 7561da177e4SLinus Torvalds 75707dcc686SSimon Horman /* output hook: Process packet in inout direction, diff set for TCP. 7588b27b10fSJulian Anastasov * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok, 7598b27b10fSJulian Anastasov * 2=Mangled but checksum was not updated 7608b27b10fSJulian Anastasov */ 7611da177e4SLinus Torvalds int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *, 762d12e1229SJulian Anastasov struct sk_buff *, int *diff, struct ip_vs_iphdr *ipvsh); 7631da177e4SLinus Torvalds 76407dcc686SSimon Horman /* input hook: Process packet in outin direction, diff set for TCP. 7658b27b10fSJulian Anastasov * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok, 7668b27b10fSJulian Anastasov * 2=Mangled but checksum was not updated 7678b27b10fSJulian Anastasov */ 7681da177e4SLinus Torvalds int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *, 769d12e1229SJulian Anastasov struct sk_buff *, int *diff, struct ip_vs_iphdr *ipvsh); 7701da177e4SLinus Torvalds 7711da177e4SLinus Torvalds /* ip_vs_app initializer */ 7721da177e4SLinus Torvalds int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *); 7731da177e4SLinus Torvalds 7741da177e4SLinus Torvalds /* ip_vs_app finish */ 7751da177e4SLinus Torvalds int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *); 7761da177e4SLinus Torvalds 7771da177e4SLinus Torvalds 7781da177e4SLinus Torvalds /* not used now */ 7791da177e4SLinus Torvalds int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *, 7801da177e4SLinus Torvalds struct ip_vs_protocol *); 7811da177e4SLinus Torvalds 7821da177e4SLinus Torvalds void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *); 7831da177e4SLinus Torvalds 7841da177e4SLinus Torvalds int * timeout_table; 7851da177e4SLinus Torvalds int * timeouts; 7861da177e4SLinus Torvalds int timeouts_size; 7871da177e4SLinus Torvalds 7881da177e4SLinus Torvalds int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app, 7891da177e4SLinus Torvalds int *verdict, struct ip_vs_conn **cpp); 7901da177e4SLinus Torvalds 7911da177e4SLinus Torvalds struct ip_vs_conn * 7921da177e4SLinus Torvalds (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app, 793d4383f04SJesper Dangaard Brouer const struct iphdr *iph, int inverse); 7941da177e4SLinus Torvalds 7951da177e4SLinus Torvalds struct ip_vs_conn * 7961da177e4SLinus Torvalds (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app, 797d4383f04SJesper Dangaard Brouer const struct iphdr *iph, int inverse); 7981da177e4SLinus Torvalds 7991da177e4SLinus Torvalds int (*state_transition)(struct ip_vs_conn *cp, int direction, 8001da177e4SLinus Torvalds const struct sk_buff *skb, 8011da177e4SLinus Torvalds struct ip_vs_app *app); 8021da177e4SLinus Torvalds 8031da177e4SLinus Torvalds void (*timeout_change)(struct ip_vs_app *app, int flags); 8041da177e4SLinus Torvalds }; 8051da177e4SLinus Torvalds 806f73181c8SPablo Neira Ayuso struct ipvs_master_sync_state { 807f73181c8SPablo Neira Ayuso struct list_head sync_queue; 808f73181c8SPablo Neira Ayuso struct ip_vs_sync_buff *sync_buff; 80907995674SZhang Yanfei unsigned long sync_queue_len; 810f73181c8SPablo Neira Ayuso unsigned int sync_queue_delay; 811f73181c8SPablo Neira Ayuso struct delayed_work master_wakeup_work; 812f73181c8SPablo Neira Ayuso struct netns_ipvs *ipvs; 813f73181c8SPablo Neira Ayuso }; 814f73181c8SPablo Neira Ayuso 8155db7c8b9SJulian Anastasov struct ip_vs_sync_thread_data; 8165db7c8b9SJulian Anastasov 817578bc3efSJulian Anastasov /* How much time to keep dests in trash */ 818578bc3efSJulian Anastasov #define IP_VS_DEST_TRASH_PERIOD (120 * HZ) 819578bc3efSJulian Anastasov 820e4ff6751SJulian Anastasov struct ipvs_sync_daemon_cfg { 821d3328817SJulian Anastasov union nf_inet_addr mcast_group; 822e4ff6751SJulian Anastasov int syncid; 823e4ff6751SJulian Anastasov u16 sync_maxlen; 824d3328817SJulian Anastasov u16 mcast_port; 825d3328817SJulian Anastasov u8 mcast_af; 826d3328817SJulian Anastasov u8 mcast_ttl; 827e4ff6751SJulian Anastasov /* multicast interface name */ 828e4ff6751SJulian Anastasov char mcast_ifn[IP_VS_IFNAME_MAXLEN]; 829e4ff6751SJulian Anastasov }; 830e4ff6751SJulian Anastasov 8312553d064SJulian Anastasov /* IPVS in network namespace */ 8322553d064SJulian Anastasov struct netns_ipvs { 8332553d064SJulian Anastasov int gen; /* Generation */ 8347a4f0761SHans Schillstrom int enable; /* enable like nf_hooks do */ 83507dcc686SSimon Horman /* Hash table: for real service lookups */ 8362553d064SJulian Anastasov #define IP_VS_RTAB_BITS 4 8372553d064SJulian Anastasov #define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS) 8382553d064SJulian Anastasov #define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1) 8392553d064SJulian Anastasov 840276472eaSJulian Anastasov struct hlist_head rs_table[IP_VS_RTAB_SIZE]; 8412553d064SJulian Anastasov /* ip_vs_app */ 8422553d064SJulian Anastasov struct list_head app_list; 8432553d064SJulian Anastasov /* ip_vs_proto */ 8442553d064SJulian Anastasov #define IP_VS_PROTO_TAB_SIZE 32 /* must be power of 2 */ 8452553d064SJulian Anastasov struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE]; 8462553d064SJulian Anastasov /* ip_vs_proto_tcp */ 8472553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_TCP 8482553d064SJulian Anastasov #define TCP_APP_TAB_BITS 4 8492553d064SJulian Anastasov #define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS) 8502553d064SJulian Anastasov #define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1) 8512553d064SJulian Anastasov struct list_head tcp_apps[TCP_APP_TAB_SIZE]; 8522553d064SJulian Anastasov #endif 8532553d064SJulian Anastasov /* ip_vs_proto_udp */ 8542553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_UDP 8552553d064SJulian Anastasov #define UDP_APP_TAB_BITS 4 8562553d064SJulian Anastasov #define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS) 8572553d064SJulian Anastasov #define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1) 8582553d064SJulian Anastasov struct list_head udp_apps[UDP_APP_TAB_SIZE]; 8592553d064SJulian Anastasov #endif 8602553d064SJulian Anastasov /* ip_vs_proto_sctp */ 8612553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_SCTP 8622553d064SJulian Anastasov #define SCTP_APP_TAB_BITS 4 8632553d064SJulian Anastasov #define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS) 8642553d064SJulian Anastasov #define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1) 8652553d064SJulian Anastasov /* Hash table for SCTP application incarnations */ 8662553d064SJulian Anastasov struct list_head sctp_apps[SCTP_APP_TAB_SIZE]; 8672553d064SJulian Anastasov #endif 8682553d064SJulian Anastasov /* ip_vs_conn */ 8692553d064SJulian Anastasov atomic_t conn_count; /* connection counter */ 8702553d064SJulian Anastasov 8712553d064SJulian Anastasov /* ip_vs_ctl */ 8722a0751afSJulian Anastasov struct ip_vs_stats tot_stats; /* Statistics & est. */ 8732553d064SJulian Anastasov 8742553d064SJulian Anastasov int num_services; /* no of virtual services */ 875857ca897SJulian Anastasov int num_services6; /* IPv6 virtual services */ 876f2247fbdSSimon Horman 8772553d064SJulian Anastasov /* Trash for destinations */ 8782553d064SJulian Anastasov struct list_head dest_trash; 879578bc3efSJulian Anastasov spinlock_t dest_trash_lock; 880578bc3efSJulian Anastasov struct timer_list dest_trash_timer; /* expiration timer */ 8812553d064SJulian Anastasov /* Service counters */ 8822553d064SJulian Anastasov atomic_t ftpsvc_counter; 8832553d064SJulian Anastasov atomic_t nullsvc_counter; 88439b97223SMarco Angaroni atomic_t conn_out_counter; 8852553d064SJulian Anastasov 886f2247fbdSSimon Horman #ifdef CONFIG_SYSCTL 88735dfb013SAndrew Sy Kim /* delayed work for expiring no dest connections */ 88835dfb013SAndrew Sy Kim struct delayed_work expire_nodest_conn_work; 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; 893c24b75e0SEric Dumazet int old_secure_tcp; 894f2247fbdSSimon Horman atomic_t dropentry; 895f2247fbdSSimon Horman /* locks in ctl.c */ 896f2247fbdSSimon Horman spinlock_t dropentry_lock; /* drop entry handling */ 897f2247fbdSSimon Horman spinlock_t droppacket_lock; /* drop packet handling */ 898f2247fbdSSimon Horman spinlock_t securetcp_lock; /* state and timeout tables */ 899f2247fbdSSimon Horman 9002553d064SJulian Anastasov /* sys-ctl struct */ 9012553d064SJulian Anastasov struct ctl_table_header *sysctl_hdr; 9022553d064SJulian Anastasov struct ctl_table *sysctl_tbl; 903f2247fbdSSimon Horman #endif 904f2247fbdSSimon Horman 9052553d064SJulian Anastasov /* sysctl variables */ 9062553d064SJulian Anastasov int sysctl_amemthresh; 9072553d064SJulian Anastasov int sysctl_am_droprate; 9082553d064SJulian Anastasov int sysctl_drop_entry; 9092553d064SJulian Anastasov int sysctl_drop_packet; 9102553d064SJulian Anastasov int sysctl_secure_tcp; 9112553d064SJulian Anastasov #ifdef CONFIG_IP_VS_NFCT 9122553d064SJulian Anastasov int sysctl_conntrack; 9132553d064SJulian Anastasov #endif 9142553d064SJulian Anastasov int sysctl_snat_reroute; 9152553d064SJulian Anastasov int sysctl_sync_ver; 916f73181c8SPablo Neira Ayuso int sysctl_sync_ports; 9174d0c875dSJulian Anastasov int sysctl_sync_persist_mode; 91807995674SZhang Yanfei unsigned long sysctl_sync_qlen_max; 9191c003b15SPablo Neira Ayuso int sysctl_sync_sock_size; 9202553d064SJulian Anastasov int sysctl_cache_bypass; 9212553d064SJulian Anastasov int sysctl_expire_nodest_conn; 922c6c96c18SAlexander Frolkin int sysctl_sloppy_tcp; 923c6c96c18SAlexander Frolkin int sysctl_sloppy_sctp; 9242553d064SJulian Anastasov int sysctl_expire_quiescent_template; 9252553d064SJulian Anastasov int sysctl_sync_threshold[2]; 926749c42b6SJulian Anastasov unsigned int sysctl_sync_refresh_period; 927749c42b6SJulian Anastasov int sysctl_sync_retries; 9282553d064SJulian Anastasov int sysctl_nat_icmp_send; 9293654e611SJulian Anastasov int sysctl_pmtu_disc; 9300c12582fSJulian Anastasov int sysctl_backup_only; 931d752c364SMarcelo Ricardo Leitner int sysctl_conn_reuse_mode; 93294485fedSAlex Gartrell int sysctl_schedule_icmp; 9334e478098SAlex Gartrell int sysctl_ignore_tunneled; 9342553d064SJulian Anastasov 9352553d064SJulian Anastasov /* ip_vs_lblc */ 9362553d064SJulian Anastasov int sysctl_lblc_expiration; 9372553d064SJulian Anastasov struct ctl_table_header *lblc_ctl_header; 9382553d064SJulian Anastasov struct ctl_table *lblc_ctl_table; 9392553d064SJulian Anastasov /* ip_vs_lblcr */ 9402553d064SJulian Anastasov int sysctl_lblcr_expiration; 9412553d064SJulian Anastasov struct ctl_table_header *lblcr_ctl_header; 9422553d064SJulian Anastasov struct ctl_table *lblcr_ctl_table; 9432553d064SJulian Anastasov /* ip_vs_est */ 9442553d064SJulian Anastasov struct list_head est_list; /* estimator list */ 9452553d064SJulian Anastasov spinlock_t est_lock; 9462553d064SJulian Anastasov struct timer_list est_timer; /* Estimation timer */ 9472553d064SJulian Anastasov /* ip_vs_sync */ 9482553d064SJulian Anastasov spinlock_t sync_lock; 949f73181c8SPablo Neira Ayuso struct ipvs_master_sync_state *ms; 9502553d064SJulian Anastasov spinlock_t sync_buff_lock; 9515db7c8b9SJulian Anastasov struct ip_vs_sync_thread_data *master_tinfo; 9525db7c8b9SJulian Anastasov struct ip_vs_sync_thread_data *backup_tinfo; 953f73181c8SPablo Neira Ayuso int threads_mask; 9542553d064SJulian Anastasov volatile int sync_state; 955ae1d48b2SHans Schillstrom struct mutex sync_mutex; 956e4ff6751SJulian Anastasov struct ipvs_sync_daemon_cfg mcfg; /* Master Configuration */ 957e4ff6751SJulian Anastasov struct ipvs_sync_daemon_cfg bcfg; /* Backup Configuration */ 9582553d064SJulian Anastasov /* net name space ptr */ 9592553d064SJulian Anastasov struct net *net; /* Needed by timer routines */ 96007dcc686SSimon Horman /* Number of heterogeneous destinations, needed becaus heterogeneous 96107dcc686SSimon Horman * are not supported when synchronization is enabled. 96207dcc686SSimon Horman */ 963391f503dSAlex Gartrell unsigned int mixed_address_family_dests; 964857ca897SJulian Anastasov unsigned int hooks_afmask; /* &1=AF_INET, &2=AF_INET6 */ 9652553d064SJulian Anastasov }; 9661da177e4SLinus Torvalds 96759e0350eSSimon Horman #define DEFAULT_SYNC_THRESHOLD 3 96859e0350eSSimon Horman #define DEFAULT_SYNC_PERIOD 50 9697532e8d4SSimon Horman #define DEFAULT_SYNC_VER 1 970c6c96c18SAlexander Frolkin #define DEFAULT_SLOPPY_TCP 0 971c6c96c18SAlexander Frolkin #define DEFAULT_SLOPPY_SCTP 0 972749c42b6SJulian Anastasov #define DEFAULT_SYNC_REFRESH_PERIOD (0U * HZ) 973749c42b6SJulian Anastasov #define DEFAULT_SYNC_RETRIES 0 9741c003b15SPablo Neira Ayuso #define IPVS_SYNC_WAKEUP_RATE 8 9751c003b15SPablo Neira Ayuso #define IPVS_SYNC_QLEN_MAX (IPVS_SYNC_WAKEUP_RATE * 4) 9761c003b15SPablo Neira Ayuso #define IPVS_SYNC_SEND_DELAY (HZ / 50) 9771c003b15SPablo Neira Ayuso #define IPVS_SYNC_CHECK_PERIOD HZ 978749c42b6SJulian Anastasov #define IPVS_SYNC_FLUSH_TIME (HZ * 2) 979f73181c8SPablo Neira Ayuso #define IPVS_SYNC_PORTS_MAX (1 << 6) 98059e0350eSSimon Horman 98159e0350eSSimon Horman #ifdef CONFIG_SYSCTL 98259e0350eSSimon Horman 98359e0350eSSimon Horman static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs) 98459e0350eSSimon Horman { 98559e0350eSSimon Horman return ipvs->sysctl_sync_threshold[0]; 98659e0350eSSimon Horman } 98759e0350eSSimon Horman 98859e0350eSSimon Horman static inline int sysctl_sync_period(struct netns_ipvs *ipvs) 98959e0350eSSimon Horman { 9906aa7de05SMark Rutland return READ_ONCE(ipvs->sysctl_sync_threshold[1]); 991749c42b6SJulian Anastasov } 992749c42b6SJulian Anastasov 993749c42b6SJulian Anastasov static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs) 994749c42b6SJulian Anastasov { 9956aa7de05SMark Rutland return READ_ONCE(ipvs->sysctl_sync_refresh_period); 996749c42b6SJulian Anastasov } 997749c42b6SJulian Anastasov 998749c42b6SJulian Anastasov static inline int sysctl_sync_retries(struct netns_ipvs *ipvs) 999749c42b6SJulian Anastasov { 1000749c42b6SJulian Anastasov return ipvs->sysctl_sync_retries; 100159e0350eSSimon Horman } 100259e0350eSSimon Horman 10037532e8d4SSimon Horman static inline int sysctl_sync_ver(struct netns_ipvs *ipvs) 10047532e8d4SSimon Horman { 10057532e8d4SSimon Horman return ipvs->sysctl_sync_ver; 10067532e8d4SSimon Horman } 10077532e8d4SSimon Horman 1008c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs) 1009c6c96c18SAlexander Frolkin { 1010c6c96c18SAlexander Frolkin return ipvs->sysctl_sloppy_tcp; 1011c6c96c18SAlexander Frolkin } 1012c6c96c18SAlexander Frolkin 1013c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs) 1014c6c96c18SAlexander Frolkin { 1015c6c96c18SAlexander Frolkin return ipvs->sysctl_sloppy_sctp; 1016c6c96c18SAlexander Frolkin } 1017c6c96c18SAlexander Frolkin 1018f73181c8SPablo Neira Ayuso static inline int sysctl_sync_ports(struct netns_ipvs *ipvs) 1019f73181c8SPablo Neira Ayuso { 10206aa7de05SMark Rutland return READ_ONCE(ipvs->sysctl_sync_ports); 1021f73181c8SPablo Neira Ayuso } 1022f73181c8SPablo Neira Ayuso 10234d0c875dSJulian Anastasov static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs) 10244d0c875dSJulian Anastasov { 10254d0c875dSJulian Anastasov return ipvs->sysctl_sync_persist_mode; 10264d0c875dSJulian Anastasov } 10274d0c875dSJulian Anastasov 102807995674SZhang Yanfei static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs) 10291c003b15SPablo Neira Ayuso { 10301c003b15SPablo Neira Ayuso return ipvs->sysctl_sync_qlen_max; 10311c003b15SPablo Neira Ayuso } 10321c003b15SPablo Neira Ayuso 10331c003b15SPablo Neira Ayuso static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs) 10341c003b15SPablo Neira Ayuso { 10351c003b15SPablo Neira Ayuso return ipvs->sysctl_sync_sock_size; 10361c003b15SPablo Neira Ayuso } 10371c003b15SPablo Neira Ayuso 10383654e611SJulian Anastasov static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs) 10393654e611SJulian Anastasov { 10403654e611SJulian Anastasov return ipvs->sysctl_pmtu_disc; 10413654e611SJulian Anastasov } 10423654e611SJulian Anastasov 10430c12582fSJulian Anastasov static inline int sysctl_backup_only(struct netns_ipvs *ipvs) 10440c12582fSJulian Anastasov { 10450c12582fSJulian Anastasov return ipvs->sync_state & IP_VS_STATE_BACKUP && 10460c12582fSJulian Anastasov ipvs->sysctl_backup_only; 10470c12582fSJulian Anastasov } 10480c12582fSJulian Anastasov 1049d752c364SMarcelo Ricardo Leitner static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs) 1050d752c364SMarcelo Ricardo Leitner { 1051d752c364SMarcelo Ricardo Leitner return ipvs->sysctl_conn_reuse_mode; 1052d752c364SMarcelo Ricardo Leitner } 1053d752c364SMarcelo Ricardo Leitner 105435dfb013SAndrew Sy Kim static inline int sysctl_expire_nodest_conn(struct netns_ipvs *ipvs) 105535dfb013SAndrew Sy Kim { 105635dfb013SAndrew Sy Kim return ipvs->sysctl_expire_nodest_conn; 105735dfb013SAndrew Sy Kim } 105835dfb013SAndrew Sy Kim 105994485fedSAlex Gartrell static inline int sysctl_schedule_icmp(struct netns_ipvs *ipvs) 106094485fedSAlex Gartrell { 106194485fedSAlex Gartrell return ipvs->sysctl_schedule_icmp; 106294485fedSAlex Gartrell } 106394485fedSAlex Gartrell 10644e478098SAlex Gartrell static inline int sysctl_ignore_tunneled(struct netns_ipvs *ipvs) 10654e478098SAlex Gartrell { 10664e478098SAlex Gartrell return ipvs->sysctl_ignore_tunneled; 10674e478098SAlex Gartrell } 10684e478098SAlex Gartrell 106957032948SEric W. Biederman static inline int sysctl_cache_bypass(struct netns_ipvs *ipvs) 107057032948SEric W. Biederman { 107157032948SEric W. Biederman return ipvs->sysctl_cache_bypass; 107257032948SEric W. Biederman } 107357032948SEric W. Biederman 107459e0350eSSimon Horman #else 107559e0350eSSimon Horman 107659e0350eSSimon Horman static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs) 107759e0350eSSimon Horman { 107859e0350eSSimon Horman return DEFAULT_SYNC_THRESHOLD; 107959e0350eSSimon Horman } 108059e0350eSSimon Horman 108159e0350eSSimon Horman static inline int sysctl_sync_period(struct netns_ipvs *ipvs) 108259e0350eSSimon Horman { 108359e0350eSSimon Horman return DEFAULT_SYNC_PERIOD; 108459e0350eSSimon Horman } 108559e0350eSSimon Horman 1086749c42b6SJulian Anastasov static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs) 1087749c42b6SJulian Anastasov { 1088749c42b6SJulian Anastasov return DEFAULT_SYNC_REFRESH_PERIOD; 1089749c42b6SJulian Anastasov } 1090749c42b6SJulian Anastasov 1091749c42b6SJulian Anastasov static inline int sysctl_sync_retries(struct netns_ipvs *ipvs) 1092749c42b6SJulian Anastasov { 1093749c42b6SJulian Anastasov return DEFAULT_SYNC_RETRIES & 3; 1094749c42b6SJulian Anastasov } 1095749c42b6SJulian Anastasov 10967532e8d4SSimon Horman static inline int sysctl_sync_ver(struct netns_ipvs *ipvs) 10977532e8d4SSimon Horman { 10987532e8d4SSimon Horman return DEFAULT_SYNC_VER; 10997532e8d4SSimon Horman } 11007532e8d4SSimon Horman 1101c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs) 1102c6c96c18SAlexander Frolkin { 1103c6c96c18SAlexander Frolkin return DEFAULT_SLOPPY_TCP; 1104c6c96c18SAlexander Frolkin } 1105c6c96c18SAlexander Frolkin 1106c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs) 1107c6c96c18SAlexander Frolkin { 1108c6c96c18SAlexander Frolkin return DEFAULT_SLOPPY_SCTP; 1109c6c96c18SAlexander Frolkin } 1110c6c96c18SAlexander Frolkin 1111f73181c8SPablo Neira Ayuso static inline int sysctl_sync_ports(struct netns_ipvs *ipvs) 1112f73181c8SPablo Neira Ayuso { 1113f73181c8SPablo Neira Ayuso return 1; 1114f73181c8SPablo Neira Ayuso } 1115f73181c8SPablo Neira Ayuso 11164d0c875dSJulian Anastasov static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs) 11174d0c875dSJulian Anastasov { 11184d0c875dSJulian Anastasov return 0; 11194d0c875dSJulian Anastasov } 11204d0c875dSJulian Anastasov 112107995674SZhang Yanfei static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs) 11221c003b15SPablo Neira Ayuso { 11231c003b15SPablo Neira Ayuso return IPVS_SYNC_QLEN_MAX; 11241c003b15SPablo Neira Ayuso } 11251c003b15SPablo Neira Ayuso 11261c003b15SPablo Neira Ayuso static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs) 11271c003b15SPablo Neira Ayuso { 11281c003b15SPablo Neira Ayuso return 0; 11291c003b15SPablo Neira Ayuso } 11301c003b15SPablo Neira Ayuso 11313654e611SJulian Anastasov static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs) 11323654e611SJulian Anastasov { 11333654e611SJulian Anastasov return 1; 11343654e611SJulian Anastasov } 11353654e611SJulian Anastasov 11360c12582fSJulian Anastasov static inline int sysctl_backup_only(struct netns_ipvs *ipvs) 11370c12582fSJulian Anastasov { 11380c12582fSJulian Anastasov return 0; 11390c12582fSJulian Anastasov } 11400c12582fSJulian Anastasov 1141d752c364SMarcelo Ricardo Leitner static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs) 1142d752c364SMarcelo Ricardo Leitner { 1143d752c364SMarcelo Ricardo Leitner return 1; 1144d752c364SMarcelo Ricardo Leitner } 1145d752c364SMarcelo Ricardo Leitner 114635dfb013SAndrew Sy Kim static inline int sysctl_expire_nodest_conn(struct netns_ipvs *ipvs) 114735dfb013SAndrew Sy Kim { 114835dfb013SAndrew Sy Kim return 0; 114935dfb013SAndrew Sy Kim } 115035dfb013SAndrew Sy Kim 115194485fedSAlex Gartrell static inline int sysctl_schedule_icmp(struct netns_ipvs *ipvs) 115294485fedSAlex Gartrell { 115394485fedSAlex Gartrell return 0; 115494485fedSAlex Gartrell } 115594485fedSAlex Gartrell 11564e478098SAlex Gartrell static inline int sysctl_ignore_tunneled(struct netns_ipvs *ipvs) 11574e478098SAlex Gartrell { 11584e478098SAlex Gartrell return 0; 11594e478098SAlex Gartrell } 11604e478098SAlex Gartrell 116157032948SEric W. Biederman static inline int sysctl_cache_bypass(struct netns_ipvs *ipvs) 116257032948SEric W. Biederman { 116357032948SEric W. Biederman return 0; 116457032948SEric W. Biederman } 116557032948SEric W. Biederman 116659e0350eSSimon Horman #endif 116759e0350eSSimon Horman 116807dcc686SSimon Horman /* IPVS core functions 11691da177e4SLinus Torvalds * (from ip_vs_core.c) 11701da177e4SLinus Torvalds */ 11715c3a0fd7SJoe Perches const char *ip_vs_proto_name(unsigned int proto); 11725c3a0fd7SJoe Perches void ip_vs_init_hash_table(struct list_head *table, int rows); 117339b97223SMarco Angaroni struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc, 117439b97223SMarco Angaroni struct ip_vs_dest *dest, 117539b97223SMarco Angaroni struct sk_buff *skb, 117639b97223SMarco Angaroni const struct ip_vs_iphdr *iph, 117739b97223SMarco Angaroni __be16 dport, 117839b97223SMarco Angaroni __be16 cport); 1179afdd6140SSven Wegener #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t))) 11801da177e4SLinus Torvalds 11811da177e4SLinus Torvalds #define IP_VS_APP_TYPE_FTP 1 11821da177e4SLinus Torvalds 118307dcc686SSimon Horman /* ip_vs_conn handling functions 11841da177e4SLinus Torvalds * (from ip_vs_conn.c) 11851da177e4SLinus Torvalds */ 11861da177e4SLinus Torvalds enum { 11871da177e4SLinus Torvalds IP_VS_DIR_INPUT = 0, 11881da177e4SLinus Torvalds IP_VS_DIR_OUTPUT, 11891da177e4SLinus Torvalds IP_VS_DIR_INPUT_ONLY, 11901da177e4SLinus Torvalds IP_VS_DIR_LAST, 11911da177e4SLinus Torvalds }; 11921da177e4SLinus Torvalds 119319913decSEric W. Biederman static inline void ip_vs_conn_fill_param(struct netns_ipvs *ipvs, int af, int protocol, 1194f11017ecSSimon Horman const union nf_inet_addr *caddr, 1195f11017ecSSimon Horman __be16 cport, 1196f11017ecSSimon Horman const union nf_inet_addr *vaddr, 1197f11017ecSSimon Horman __be16 vport, 1198f11017ecSSimon Horman struct ip_vs_conn_param *p) 1199f11017ecSSimon Horman { 120019913decSEric W. Biederman p->ipvs = ipvs; 1201f11017ecSSimon Horman p->af = af; 1202f11017ecSSimon Horman p->protocol = protocol; 1203f11017ecSSimon Horman p->caddr = caddr; 1204f11017ecSSimon Horman p->cport = cport; 1205f11017ecSSimon Horman p->vaddr = vaddr; 1206f11017ecSSimon Horman p->vport = vport; 120785999283SSimon Horman p->pe = NULL; 120885999283SSimon Horman p->pe_data = NULL; 1209f11017ecSSimon Horman } 121028364a59SJulius Volz 1211f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p); 1212f11017ecSSimon Horman struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p); 121328364a59SJulius Volz 1214ab161976SEric W. Biederman struct ip_vs_conn * ip_vs_conn_in_get_proto(struct netns_ipvs *ipvs, int af, 1215ab161976SEric W. Biederman const struct sk_buff *skb, 1216802c41adSAlex Gartrell const struct ip_vs_iphdr *iph); 12175c0d2374SSimon Horman 1218f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p); 12191da177e4SLinus Torvalds 12200cf705c8SEric W. Biederman struct ip_vs_conn * ip_vs_conn_out_get_proto(struct netns_ipvs *ipvs, int af, 12210cf705c8SEric W. Biederman const struct sk_buff *skb, 1222802c41adSAlex Gartrell const struct ip_vs_iphdr *iph); 12235c0d2374SSimon Horman 1224088339a5SJulian Anastasov /* Get reference to gain full access to conn. 1225088339a5SJulian Anastasov * By default, RCU read-side critical sections have access only to 1226088339a5SJulian Anastasov * conn fields and its PE data, see ip_vs_conn_rcu_free() for reference. 1227088339a5SJulian Anastasov */ 1228088339a5SJulian Anastasov static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp) 1229088339a5SJulian Anastasov { 1230b54ab92bSReshetova, Elena return refcount_inc_not_zero(&cp->refcnt); 1231088339a5SJulian Anastasov } 1232088339a5SJulian Anastasov 12331da177e4SLinus Torvalds /* put back the conn without restarting its timer */ 12341da177e4SLinus Torvalds static inline void __ip_vs_conn_put(struct ip_vs_conn *cp) 12351da177e4SLinus Torvalds { 12364e857c58SPeter Zijlstra smp_mb__before_atomic(); 1237b54ab92bSReshetova, Elena refcount_dec(&cp->refcnt); 12381da177e4SLinus Torvalds } 12395c3a0fd7SJoe Perches void ip_vs_conn_put(struct ip_vs_conn *cp); 12405c3a0fd7SJoe Perches void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport); 12411da177e4SLinus Torvalds 1242ba38528aSAlex Gartrell struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af, 1243f11017ecSSimon Horman const union nf_inet_addr *daddr, 124495c96174SEric Dumazet __be16 dport, unsigned int flags, 12450e051e68SHans Schillstrom struct ip_vs_dest *dest, __u32 fwmark); 12465c3a0fd7SJoe Perches void ip_vs_conn_expire_now(struct ip_vs_conn *cp); 12471da177e4SLinus Torvalds 1248ec1b28caSJulian Anastasov const char *ip_vs_state_name(const struct ip_vs_conn *cp); 12491da177e4SLinus Torvalds 125069f39093SEric W. Biederman void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp); 12513ec10d3aSMarco Angaroni int ip_vs_check_template(struct ip_vs_conn *ct, struct ip_vs_dest *cdest); 1252423b5595SEric W. Biederman void ip_vs_random_dropentry(struct netns_ipvs *ipvs); 12535c3a0fd7SJoe Perches int ip_vs_conn_init(void); 12545c3a0fd7SJoe Perches void ip_vs_conn_cleanup(void); 12551da177e4SLinus Torvalds 12561da177e4SLinus Torvalds static inline void ip_vs_control_del(struct ip_vs_conn *cp) 12571da177e4SLinus Torvalds { 12581da177e4SLinus Torvalds struct ip_vs_conn *ctl_cp = cp->control; 12591da177e4SLinus Torvalds if (!ctl_cp) { 1260cfc78c5aSJulius Volz IP_VS_ERR_BUF("request control DEL for uncontrolled: " 1261cfc78c5aSJulius Volz "%s:%d to %s:%d\n", 1262cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1263cfc78c5aSJulius Volz ntohs(cp->cport), 1264cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr), 1265cfc78c5aSJulius Volz ntohs(cp->vport)); 1266cfc78c5aSJulius Volz 12671da177e4SLinus Torvalds return; 12681da177e4SLinus Torvalds } 12691da177e4SLinus Torvalds 1270cfc78c5aSJulius Volz IP_VS_DBG_BUF(7, "DELeting control for: " 1271cfc78c5aSJulius Volz "cp.dst=%s:%d ctl_cp.dst=%s:%d\n", 1272cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1273cfc78c5aSJulius Volz ntohs(cp->cport), 1274cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr), 1275cfc78c5aSJulius Volz ntohs(ctl_cp->cport)); 12761da177e4SLinus Torvalds 12771da177e4SLinus Torvalds cp->control = NULL; 12781da177e4SLinus Torvalds if (atomic_read(&ctl_cp->n_control) == 0) { 1279cfc78c5aSJulius Volz IP_VS_ERR_BUF("BUG control DEL with n=0 : " 1280cfc78c5aSJulius Volz "%s:%d to %s:%d\n", 1281cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1282cfc78c5aSJulius Volz ntohs(cp->cport), 1283cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr), 1284cfc78c5aSJulius Volz ntohs(cp->vport)); 1285cfc78c5aSJulius Volz 12861da177e4SLinus Torvalds return; 12871da177e4SLinus Torvalds } 12881da177e4SLinus Torvalds atomic_dec(&ctl_cp->n_control); 12891da177e4SLinus Torvalds } 12901da177e4SLinus Torvalds 12911da177e4SLinus Torvalds static inline void 12921da177e4SLinus Torvalds ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp) 12931da177e4SLinus Torvalds { 12941da177e4SLinus Torvalds if (cp->control) { 1295cfc78c5aSJulius Volz IP_VS_ERR_BUF("request control ADD for already controlled: " 1296cfc78c5aSJulius Volz "%s:%d to %s:%d\n", 1297cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1298cfc78c5aSJulius Volz ntohs(cp->cport), 1299cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr), 1300cfc78c5aSJulius Volz ntohs(cp->vport)); 1301cfc78c5aSJulius Volz 13021da177e4SLinus Torvalds ip_vs_control_del(cp); 13031da177e4SLinus Torvalds } 13041da177e4SLinus Torvalds 1305cfc78c5aSJulius Volz IP_VS_DBG_BUF(7, "ADDing control for: " 1306cfc78c5aSJulius Volz "cp.dst=%s:%d ctl_cp.dst=%s:%d\n", 1307cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1308cfc78c5aSJulius Volz ntohs(cp->cport), 1309cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr), 1310cfc78c5aSJulius Volz ntohs(ctl_cp->cport)); 13111da177e4SLinus Torvalds 13121da177e4SLinus Torvalds cp->control = ctl_cp; 13131da177e4SLinus Torvalds atomic_inc(&ctl_cp->n_control); 13141da177e4SLinus Torvalds } 13151da177e4SLinus Torvalds 131627541143SJulian Anastasov /* Mark our template as assured */ 131727541143SJulian Anastasov static inline void 131827541143SJulian Anastasov ip_vs_control_assure_ct(struct ip_vs_conn *cp) 131927541143SJulian Anastasov { 132027541143SJulian Anastasov struct ip_vs_conn *ct = cp->control; 132127541143SJulian Anastasov 132227541143SJulian Anastasov if (ct && !(ct->state & IP_VS_CTPL_S_ASSURED) && 132327541143SJulian Anastasov (ct->flags & IP_VS_CONN_F_TEMPLATE)) 132427541143SJulian Anastasov ct->state |= IP_VS_CTPL_S_ASSURED; 132527541143SJulian Anastasov } 132627541143SJulian Anastasov 132707dcc686SSimon Horman /* IPVS netns init & cleanup functions */ 1328a4dd0360SEric W. Biederman int ip_vs_estimator_net_init(struct netns_ipvs *ipvs); 13293d993766SEric W. Biederman int ip_vs_control_net_init(struct netns_ipvs *ipvs); 13307d1f88ecSEric W. Biederman int ip_vs_protocol_net_init(struct netns_ipvs *ipvs); 1331b5dd212cSEric W. Biederman int ip_vs_app_net_init(struct netns_ipvs *ipvs); 13322f3edc6aSEric W. Biederman int ip_vs_conn_net_init(struct netns_ipvs *ipvs); 1333802cb437SEric W. Biederman int ip_vs_sync_net_init(struct netns_ipvs *ipvs); 13342f3edc6aSEric W. Biederman void ip_vs_conn_net_cleanup(struct netns_ipvs *ipvs); 1335b5dd212cSEric W. Biederman void ip_vs_app_net_cleanup(struct netns_ipvs *ipvs); 13367d1f88ecSEric W. Biederman void ip_vs_protocol_net_cleanup(struct netns_ipvs *ipvs); 13373d993766SEric W. Biederman void ip_vs_control_net_cleanup(struct netns_ipvs *ipvs); 1338a4dd0360SEric W. Biederman void ip_vs_estimator_net_cleanup(struct netns_ipvs *ipvs); 1339ebea1f7cSEric W. Biederman void ip_vs_sync_net_cleanup(struct netns_ipvs *ipvs); 13405d5a0815SHaishuang Yan void ip_vs_service_nets_cleanup(struct list_head *net_list); 13411da177e4SLinus Torvalds 134207dcc686SSimon Horman /* IPVS application functions 13431da177e4SLinus Torvalds * (from ip_vs_app.c) 13441da177e4SLinus Torvalds */ 13451da177e4SLinus Torvalds #define IP_VS_APP_MAX_PORTS 8 13469f8128a5SEric W. Biederman struct ip_vs_app *register_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app); 13479f8128a5SEric W. Biederman void unregister_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app); 13485c3a0fd7SJoe Perches int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp); 13495c3a0fd7SJoe Perches void ip_vs_unbind_app(struct ip_vs_conn *cp); 13503250dc9cSEric W. Biederman int register_ip_vs_app_inc(struct netns_ipvs *ipvs, struct ip_vs_app *app, __u16 proto, 13515c3a0fd7SJoe Perches __u16 port); 13525c3a0fd7SJoe Perches int ip_vs_app_inc_get(struct ip_vs_app *inc); 13535c3a0fd7SJoe Perches void ip_vs_app_inc_put(struct ip_vs_app *inc); 13541da177e4SLinus Torvalds 1355d12e1229SJulian Anastasov int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb, 1356d12e1229SJulian Anastasov struct ip_vs_iphdr *ipvsh); 1357d12e1229SJulian Anastasov int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb, 1358d12e1229SJulian Anastasov struct ip_vs_iphdr *ipvsh); 13591da177e4SLinus Torvalds 13608be67a66SSimon Horman int register_ip_vs_pe(struct ip_vs_pe *pe); 13618be67a66SSimon Horman int unregister_ip_vs_pe(struct ip_vs_pe *pe); 1362e9e5eee8SSimon Horman struct ip_vs_pe *ip_vs_pe_getbyname(const char *name); 1363fe5e7a1eSHans Schillstrom struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name); 1364e9e5eee8SSimon Horman 136507dcc686SSimon Horman /* Use a #define to avoid all of module.h just for these trivial ops */ 136669e7dae4SPaul Gortmaker #define ip_vs_pe_get(pe) \ 136769e7dae4SPaul Gortmaker if (pe && pe->module) \ 1368e9e5eee8SSimon Horman __module_get(pe->module); 1369e9e5eee8SSimon Horman 137069e7dae4SPaul Gortmaker #define ip_vs_pe_put(pe) \ 137169e7dae4SPaul Gortmaker if (pe && pe->module) \ 1372e9e5eee8SSimon Horman module_put(pe->module); 13731da177e4SLinus Torvalds 137407dcc686SSimon Horman /* IPVS protocol functions (from ip_vs_proto.c) */ 13755c3a0fd7SJoe Perches int ip_vs_protocol_init(void); 13765c3a0fd7SJoe Perches void ip_vs_protocol_cleanup(void); 13775c3a0fd7SJoe Perches void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags); 13785c3a0fd7SJoe Perches int *ip_vs_create_timeout_table(int *table, int size); 13795c3a0fd7SJoe Perches void ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp, 13805c3a0fd7SJoe Perches const struct sk_buff *skb, int offset, 13815c3a0fd7SJoe Perches const char *msg); 13821da177e4SLinus Torvalds 13831da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_tcp; 13841da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_udp; 13851da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_icmp; 13861da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_esp; 13871da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_ah; 13882906f66aSVenkata Mohan Reddy extern struct ip_vs_protocol ip_vs_protocol_sctp; 13891da177e4SLinus Torvalds 139007dcc686SSimon Horman /* Registering/unregistering scheduler functions 13911da177e4SLinus Torvalds * (from ip_vs_sched.c) 13921da177e4SLinus Torvalds */ 13935c3a0fd7SJoe Perches int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); 13945c3a0fd7SJoe Perches int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); 13955c3a0fd7SJoe Perches int ip_vs_bind_scheduler(struct ip_vs_service *svc, 13961da177e4SLinus Torvalds struct ip_vs_scheduler *scheduler); 13975c3a0fd7SJoe Perches void ip_vs_unbind_scheduler(struct ip_vs_service *svc, 1398ceec4c38SJulian Anastasov struct ip_vs_scheduler *sched); 13995c3a0fd7SJoe Perches struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name); 14005c3a0fd7SJoe Perches void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler); 14015c3a0fd7SJoe Perches struct ip_vs_conn * 1402190ecd27SJulian Anastasov ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb, 1403d4383f04SJesper Dangaard Brouer struct ip_vs_proto_data *pd, int *ignored, 1404d4383f04SJesper Dangaard Brouer struct ip_vs_iphdr *iph); 14055c3a0fd7SJoe Perches int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb, 1406d4383f04SJesper Dangaard Brouer struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph); 14071da177e4SLinus Torvalds 14085c3a0fd7SJoe Perches void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg); 140941ac51eeSPatrick Schaaf 141007dcc686SSimon Horman /* IPVS control data and functions (from ip_vs_ctl.c) */ 14111da177e4SLinus Torvalds extern struct ip_vs_stats ip_vs_stats; 1412b880c1f0SHans Schillstrom extern int sysctl_ip_vs_sync_ver; 14131da177e4SLinus Torvalds 14145c3a0fd7SJoe Perches struct ip_vs_service * 14150a4fd6ceSEric W. Biederman ip_vs_service_find(struct netns_ipvs *ipvs, int af, __u32 fwmark, __u16 protocol, 14163c2e0505SJulius Volz const union nf_inet_addr *vaddr, __be16 vport); 14171da177e4SLinus Torvalds 141848aed1b0SEric W. Biederman bool ip_vs_has_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol, 14197937df15SJulius Volz const union nf_inet_addr *daddr, __be16 dport); 14207937df15SJulius Volz 142139b97223SMarco Angaroni struct ip_vs_dest * 142239b97223SMarco Angaroni ip_vs_find_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol, 142339b97223SMarco Angaroni const union nf_inet_addr *daddr, __be16 dport); 14242aa3c9f4SJulian Anastasov struct ip_vs_dest *ip_vs_find_tunnel(struct netns_ipvs *ipvs, int af, 14252aa3c9f4SJulian Anastasov const union nf_inet_addr *daddr, 14262aa3c9f4SJulian Anastasov __be16 tun_port); 142739b97223SMarco Angaroni 14285c3a0fd7SJoe Perches int ip_vs_use_count_inc(void); 14295c3a0fd7SJoe Perches void ip_vs_use_count_dec(void); 14305c3a0fd7SJoe Perches int ip_vs_register_nl_ioctl(void); 14315c3a0fd7SJoe Perches void ip_vs_unregister_nl_ioctl(void); 14325c3a0fd7SJoe Perches int ip_vs_control_init(void); 14335c3a0fd7SJoe Perches void ip_vs_control_cleanup(void); 14345c3a0fd7SJoe Perches struct ip_vs_dest * 1435dc2add6fSEric W. Biederman ip_vs_find_dest(struct netns_ipvs *ipvs, int svc_af, int dest_af, 1436655eef10SAlex Gartrell const union nf_inet_addr *daddr, __be16 dport, 1437655eef10SAlex Gartrell const union nf_inet_addr *vaddr, __be16 vport, 143852793dbeSJulian Anastasov __u16 protocol, __u32 fwmark, __u32 flags); 14395c3a0fd7SJoe Perches void ip_vs_try_bind_dest(struct ip_vs_conn *cp); 14401da177e4SLinus Torvalds 1441fca9c20aSJulian Anastasov static inline void ip_vs_dest_hold(struct ip_vs_dest *dest) 1442fca9c20aSJulian Anastasov { 1443b54ab92bSReshetova, Elena refcount_inc(&dest->refcnt); 1444fca9c20aSJulian Anastasov } 1445fca9c20aSJulian Anastasov 1446fca9c20aSJulian Anastasov static inline void ip_vs_dest_put(struct ip_vs_dest *dest) 1447fca9c20aSJulian Anastasov { 14484e857c58SPeter Zijlstra smp_mb__before_atomic(); 1449b54ab92bSReshetova, Elena refcount_dec(&dest->refcnt); 1450fca9c20aSJulian Anastasov } 14511da177e4SLinus Torvalds 14529e4e948aSJulian Anastasov static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest) 14539e4e948aSJulian Anastasov { 1454b54ab92bSReshetova, Elena if (refcount_dec_and_test(&dest->refcnt)) 14559e4e948aSJulian Anastasov kfree(dest); 14569e4e948aSJulian Anastasov } 14579e4e948aSJulian Anastasov 145807dcc686SSimon Horman /* IPVS sync daemon data and function prototypes 14591da177e4SLinus Torvalds * (from ip_vs_sync.c) 14601da177e4SLinus Torvalds */ 14616ac121d7SEric W. Biederman int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *cfg, 1462e4ff6751SJulian Anastasov int state); 1463b3cf3cbfSEric W. Biederman int stop_sync_thread(struct netns_ipvs *ipvs, int state); 1464b61a8c1aSEric W. Biederman void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts); 14651da177e4SLinus Torvalds 146607dcc686SSimon Horman /* IPVS rate estimator prototypes (from ip_vs_est.c) */ 14670f34d54bSEric W. Biederman void ip_vs_start_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats); 14680f34d54bSEric W. Biederman void ip_vs_stop_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats); 14695c3a0fd7SJoe Perches void ip_vs_zero_estimator(struct ip_vs_stats *stats); 1470cd67cd5eSJulian Anastasov void ip_vs_read_estimator(struct ip_vs_kstats *dst, struct ip_vs_stats *stats); 14711da177e4SLinus Torvalds 147207dcc686SSimon Horman /* Various IPVS packet transmitters (from ip_vs_xmit.c) */ 14735c3a0fd7SJoe Perches int ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1474d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14755c3a0fd7SJoe Perches int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1476d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14775c3a0fd7SJoe Perches int ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1478d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14795c3a0fd7SJoe Perches int ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 14805c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14815c3a0fd7SJoe Perches int ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 14825c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14835c3a0fd7SJoe Perches int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1484d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, int offset, 1485d4383f04SJesper Dangaard Brouer unsigned int hooknum, struct ip_vs_iphdr *iph); 14865c3a0fd7SJoe Perches void ip_vs_dest_dst_rcu_free(struct rcu_head *head); 14871da177e4SLinus Torvalds 1488b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6 14895c3a0fd7SJoe Perches int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 1490d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14915c3a0fd7SJoe Perches int ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 14925c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14935c3a0fd7SJoe Perches int ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 14945c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14955c3a0fd7SJoe Perches int ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 14965c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14975c3a0fd7SJoe Perches int ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 1498d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, int offset, 1499d4383f04SJesper Dangaard Brouer unsigned int hooknum, struct ip_vs_iphdr *iph); 1500b3cdd2a7SJulius Volz #endif 15011da177e4SLinus Torvalds 15023a1bbf18SSimon Horman #ifdef CONFIG_SYSCTL 150307dcc686SSimon Horman /* This is a simple mechanism to ignore packets when 15041da177e4SLinus Torvalds * we are loaded. Just set ip_vs_drop_rate to 'n' and 15051da177e4SLinus Torvalds * we start to drop 1/rate of the packets 15061da177e4SLinus Torvalds */ 1507a0840e2eSHans Schillstrom static inline int ip_vs_todrop(struct netns_ipvs *ipvs) 15081da177e4SLinus Torvalds { 1509a0840e2eSHans Schillstrom if (!ipvs->drop_rate) 1510a0840e2eSHans Schillstrom return 0; 1511a0840e2eSHans Schillstrom if (--ipvs->drop_counter > 0) 1512a0840e2eSHans Schillstrom return 0; 1513a0840e2eSHans Schillstrom ipvs->drop_counter = ipvs->drop_rate; 15141da177e4SLinus Torvalds return 1; 15151da177e4SLinus Torvalds } 15163a1bbf18SSimon Horman #else 15173a1bbf18SSimon Horman static inline int ip_vs_todrop(struct netns_ipvs *ipvs) { return 0; } 15183a1bbf18SSimon Horman #endif 15191da177e4SLinus Torvalds 152035dfb013SAndrew Sy Kim #ifdef CONFIG_SYSCTL 152135dfb013SAndrew Sy Kim /* Enqueue delayed work for expiring no dest connections 152235dfb013SAndrew Sy Kim * Only run when sysctl_expire_nodest=1 152335dfb013SAndrew Sy Kim */ 152435dfb013SAndrew Sy Kim static inline void ip_vs_enqueue_expire_nodest_conns(struct netns_ipvs *ipvs) 152535dfb013SAndrew Sy Kim { 152635dfb013SAndrew Sy Kim if (sysctl_expire_nodest_conn(ipvs)) 152735dfb013SAndrew Sy Kim queue_delayed_work(system_long_wq, 152835dfb013SAndrew Sy Kim &ipvs->expire_nodest_conn_work, 1); 152935dfb013SAndrew Sy Kim } 153035dfb013SAndrew Sy Kim 153135dfb013SAndrew Sy Kim void ip_vs_expire_nodest_conn_flush(struct netns_ipvs *ipvs); 153235dfb013SAndrew Sy Kim #else 153335dfb013SAndrew Sy Kim static inline void ip_vs_enqueue_expire_nodest_conns(struct netns_ipvs *ipvs) {} 153435dfb013SAndrew Sy Kim #endif 153535dfb013SAndrew Sy Kim 15361da40ab6SJulian Anastasov #define IP_VS_DFWD_METHOD(dest) (atomic_read(&(dest)->conn_flags) & \ 15371da40ab6SJulian Anastasov IP_VS_CONN_F_FWD_MASK) 15381da40ab6SJulian Anastasov 153907dcc686SSimon Horman /* ip_vs_fwd_tag returns the forwarding tag of the connection */ 15401da177e4SLinus Torvalds #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK) 15411da177e4SLinus Torvalds 1542732db659SAdrian Bunk static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp) 15431da177e4SLinus Torvalds { 15441da177e4SLinus Torvalds char fwd; 15451da177e4SLinus Torvalds 15461da177e4SLinus Torvalds switch (IP_VS_FWD_METHOD(cp)) { 15471da177e4SLinus Torvalds case IP_VS_CONN_F_MASQ: 15481da177e4SLinus Torvalds fwd = 'M'; break; 15491da177e4SLinus Torvalds case IP_VS_CONN_F_LOCALNODE: 15501da177e4SLinus Torvalds fwd = 'L'; break; 15511da177e4SLinus Torvalds case IP_VS_CONN_F_TUNNEL: 15521da177e4SLinus Torvalds fwd = 'T'; break; 15531da177e4SLinus Torvalds case IP_VS_CONN_F_DROUTE: 15541da177e4SLinus Torvalds fwd = 'R'; break; 15551da177e4SLinus Torvalds case IP_VS_CONN_F_BYPASS: 15561da177e4SLinus Torvalds fwd = 'B'; break; 15571da177e4SLinus Torvalds default: 15581da177e4SLinus Torvalds fwd = '?'; break; 15591da177e4SLinus Torvalds } 15601da177e4SLinus Torvalds return fwd; 15611da177e4SLinus Torvalds } 15621da177e4SLinus Torvalds 15635c3a0fd7SJoe Perches void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp, 15641da177e4SLinus Torvalds struct ip_vs_conn *cp, int dir); 15651da177e4SLinus Torvalds 1566b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6 15675c3a0fd7SJoe Perches void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp, 1568b3cdd2a7SJulius Volz struct ip_vs_conn *cp, int dir); 1569b3cdd2a7SJulius Volz #endif 1570b3cdd2a7SJulius Volz 15715c3a0fd7SJoe Perches __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset); 15721da177e4SLinus Torvalds 1573f9214b26SAl Viro static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum) 15741da177e4SLinus Torvalds { 1575f9214b26SAl Viro __be32 diff[2] = { ~old, new }; 15761da177e4SLinus Torvalds 157707f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum); 1578f9214b26SAl Viro } 1579f9214b26SAl Viro 15800bbdd42bSJulius Volz #ifdef CONFIG_IP_VS_IPV6 15810bbdd42bSJulius Volz static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new, 15820bbdd42bSJulius Volz __wsum oldsum) 15830bbdd42bSJulius Volz { 15840bbdd42bSJulius Volz __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0], 15850bbdd42bSJulius Volz new[3], new[2], new[1], new[0] }; 15860bbdd42bSJulius Volz 158707f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum); 15880bbdd42bSJulius Volz } 15890bbdd42bSJulius Volz #endif 15900bbdd42bSJulius Volz 1591f9214b26SAl Viro static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum) 1592f9214b26SAl Viro { 1593f9214b26SAl Viro __be16 diff[2] = { ~old, new }; 1594f9214b26SAl Viro 159507f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum); 15961da177e4SLinus Torvalds } 15971da177e4SLinus Torvalds 159807dcc686SSimon Horman /* Forget current conntrack (unconfirmed) and attach notrack entry */ 1599cf356d69SJulian Anastasov static inline void ip_vs_notrack(struct sk_buff *skb) 1600cf356d69SJulian Anastasov { 1601cf356d69SJulian Anastasov #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 1602cf356d69SJulian Anastasov enum ip_conntrack_info ctinfo; 160306b69390SJesper Juhl struct nf_conn *ct = nf_ct_get(skb, &ctinfo); 1604cf356d69SJulian Anastasov 1605ab8bc7edSFlorian Westphal if (ct) { 160697a6ad13SFlorian Westphal nf_conntrack_put(&ct->ct_general); 1607cc41c84bSFlorian Westphal nf_ct_set(skb, NULL, IP_CT_UNTRACKED); 1608cf356d69SJulian Anastasov } 1609cf356d69SJulian Anastasov #endif 1610cf356d69SJulian Anastasov } 1611cf356d69SJulian Anastasov 1612f4bc17cdSJulian Anastasov #ifdef CONFIG_IP_VS_NFCT 161307dcc686SSimon Horman /* Netfilter connection tracking 1614f4bc17cdSJulian Anastasov * (from ip_vs_nfct.c) 1615f4bc17cdSJulian Anastasov */ 1616a0840e2eSHans Schillstrom static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs) 1617f4bc17cdSJulian Anastasov { 1618a4e2f5a7SSimon Horman #ifdef CONFIG_SYSCTL 1619a0840e2eSHans Schillstrom return ipvs->sysctl_conntrack; 1620a4e2f5a7SSimon Horman #else 1621a4e2f5a7SSimon Horman return 0; 1622a4e2f5a7SSimon Horman #endif 1623f4bc17cdSJulian Anastasov } 1624f4bc17cdSJulian Anastasov 16255c3a0fd7SJoe Perches void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp, 16266523ce15SJulian Anastasov int outin); 16275c3a0fd7SJoe Perches int ip_vs_confirm_conntrack(struct sk_buff *skb); 16285c3a0fd7SJoe Perches void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct, 1629f4bc17cdSJulian Anastasov struct ip_vs_conn *cp, u_int8_t proto, 1630f4bc17cdSJulian Anastasov const __be16 port, int from_rs); 16315c3a0fd7SJoe Perches void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp); 1632f4bc17cdSJulian Anastasov 1633f4bc17cdSJulian Anastasov #else 1634f4bc17cdSJulian Anastasov 1635a0840e2eSHans Schillstrom static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs) 1636f4bc17cdSJulian Anastasov { 1637f4bc17cdSJulian Anastasov return 0; 1638f4bc17cdSJulian Anastasov } 1639f4bc17cdSJulian Anastasov 1640f4bc17cdSJulian Anastasov static inline void ip_vs_update_conntrack(struct sk_buff *skb, 1641f4bc17cdSJulian Anastasov struct ip_vs_conn *cp, int outin) 1642f4bc17cdSJulian Anastasov { 1643f4bc17cdSJulian Anastasov } 1644f4bc17cdSJulian Anastasov 1645e23ebf0fSKrzysztof Wilczynski static inline int ip_vs_confirm_conntrack(struct sk_buff *skb) 1646f4bc17cdSJulian Anastasov { 1647f4bc17cdSJulian Anastasov return NF_ACCEPT; 1648f4bc17cdSJulian Anastasov } 1649f4bc17cdSJulian Anastasov 1650f4bc17cdSJulian Anastasov static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp) 1651f4bc17cdSJulian Anastasov { 1652f4bc17cdSJulian Anastasov } 165307dcc686SSimon Horman #endif /* CONFIG_IP_VS_NFCT */ 16546523ce15SJulian Anastasov 1655f0a5e4d7SJulian Anastasov /* Using old conntrack that can not be redirected to another real server? */ 1656f0a5e4d7SJulian Anastasov static inline bool ip_vs_conn_uses_old_conntrack(struct ip_vs_conn *cp, 1657f719e375SJulian Anastasov struct sk_buff *skb) 1658f719e375SJulian Anastasov { 1659f719e375SJulian Anastasov #ifdef CONFIG_IP_VS_NFCT 1660f719e375SJulian Anastasov enum ip_conntrack_info ctinfo; 1661f719e375SJulian Anastasov struct nf_conn *ct; 1662f719e375SJulian Anastasov 1663f719e375SJulian Anastasov ct = nf_ct_get(skb, &ctinfo); 1664f0a5e4d7SJulian Anastasov if (ct && nf_ct_is_confirmed(ct)) 1665f719e375SJulian Anastasov return true; 1666f719e375SJulian Anastasov #endif 1667f719e375SJulian Anastasov return false; 1668f719e375SJulian Anastasov } 1669f719e375SJulian Anastasov 167031875d49SJulian Anastasov static inline int ip_vs_register_conntrack(struct ip_vs_service *svc) 167131875d49SJulian Anastasov { 167231875d49SJulian Anastasov #if IS_ENABLED(CONFIG_NF_CONNTRACK) 167331875d49SJulian Anastasov int afmask = (svc->af == AF_INET6) ? 2 : 1; 167431875d49SJulian Anastasov int ret = 0; 167531875d49SJulian Anastasov 167631875d49SJulian Anastasov if (!(svc->conntrack_afmask & afmask)) { 167731875d49SJulian Anastasov ret = nf_ct_netns_get(svc->ipvs->net, svc->af); 167831875d49SJulian Anastasov if (ret >= 0) 167931875d49SJulian Anastasov svc->conntrack_afmask |= afmask; 168031875d49SJulian Anastasov } 168131875d49SJulian Anastasov return ret; 168231875d49SJulian Anastasov #else 168331875d49SJulian Anastasov return 0; 168431875d49SJulian Anastasov #endif 168531875d49SJulian Anastasov } 168631875d49SJulian Anastasov 168731875d49SJulian Anastasov static inline void ip_vs_unregister_conntrack(struct ip_vs_service *svc) 168831875d49SJulian Anastasov { 168931875d49SJulian Anastasov #if IS_ENABLED(CONFIG_NF_CONNTRACK) 169031875d49SJulian Anastasov int afmask = (svc->af == AF_INET6) ? 2 : 1; 169131875d49SJulian Anastasov 169231875d49SJulian Anastasov if (svc->conntrack_afmask & afmask) { 169331875d49SJulian Anastasov nf_ct_netns_put(svc->ipvs->net, svc->af); 169431875d49SJulian Anastasov svc->conntrack_afmask &= ~afmask; 169531875d49SJulian Anastasov } 169631875d49SJulian Anastasov #endif 169731875d49SJulian Anastasov } 169831875d49SJulian Anastasov 1699857ca897SJulian Anastasov int ip_vs_register_hooks(struct netns_ipvs *ipvs, unsigned int af); 1700857ca897SJulian Anastasov void ip_vs_unregister_hooks(struct netns_ipvs *ipvs, unsigned int af); 1701857ca897SJulian Anastasov 1702c16526a7SSimon Kirby static inline int 1703b552f7e3SChangli Gao ip_vs_dest_conn_overhead(struct ip_vs_dest *dest) 1704b552f7e3SChangli Gao { 170507dcc686SSimon Horman /* We think the overhead of processing active connections is 256 1706b552f7e3SChangli Gao * times higher than that of inactive connections in average. (This 1707b552f7e3SChangli Gao * 256 times might not be accurate, we will change it later) We 1708b552f7e3SChangli Gao * use the following formula to estimate the overhead now: 1709b552f7e3SChangli Gao * dest->activeconns*256 + dest->inactconns 1710b552f7e3SChangli Gao */ 1711b552f7e3SChangli Gao return (atomic_read(&dest->activeconns) << 8) + 1712b552f7e3SChangli Gao atomic_read(&dest->inactconns); 1713b552f7e3SChangli Gao } 1714b552f7e3SChangli Gao 1715*edf597daSLeon Romanovsky #ifdef CONFIG_IP_VS_PROTO_TCP 1716*edf597daSLeon Romanovsky INDIRECT_CALLABLE_DECLARE(int 1717*edf597daSLeon Romanovsky tcp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, 1718*edf597daSLeon Romanovsky struct ip_vs_conn *cp, struct ip_vs_iphdr *iph)); 1719*edf597daSLeon Romanovsky #endif 1720*edf597daSLeon Romanovsky 1721*edf597daSLeon Romanovsky #ifdef CONFIG_IP_VS_PROTO_UDP 1722*edf597daSLeon Romanovsky INDIRECT_CALLABLE_DECLARE(int 1723*edf597daSLeon Romanovsky udp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, 1724*edf597daSLeon Romanovsky struct ip_vs_conn *cp, struct ip_vs_iphdr *iph)); 1725*edf597daSLeon Romanovsky #endif 1726bc4768ebSJulius Volz #endif /* _NET_IP_VS_H */ 1727