107dcc686SSimon Horman /* IP Virtual Server 21da177e4SLinus Torvalds * data structure and functionality definitions 31da177e4SLinus Torvalds */ 41da177e4SLinus Torvalds 5bc4768ebSJulius Volz #ifndef _NET_IP_VS_H 6bc4768ebSJulius Volz #define _NET_IP_VS_H 71da177e4SLinus Torvalds 8bc4768ebSJulius Volz #include <linux/ip_vs.h> /* definitions shared with userland */ 91da177e4SLinus Torvalds 10bc4768ebSJulius Volz #include <asm/types.h> /* for __uXX types */ 11bc4768ebSJulius Volz 121da177e4SLinus Torvalds #include <linux/list.h> /* for struct list_head */ 131da177e4SLinus Torvalds #include <linux/spinlock.h> /* for struct rwlock_t */ 1460063497SArun Sharma #include <linux/atomic.h> /* for struct atomic_t */ 151da177e4SLinus Torvalds #include <linux/compiler.h> 1614c85021SArnaldo Carvalho de Melo #include <linux/timer.h> 17187f1882SPaul Gortmaker #include <linux/bug.h> 181da177e4SLinus Torvalds 1914c85021SArnaldo Carvalho de Melo #include <net/checksum.h> 20e7ade46aSJulius Volz #include <linux/netfilter.h> /* for union nf_inet_addr */ 211668e010SKOVACS Krisztian #include <linux/ip.h> 22e7ade46aSJulius Volz #include <linux/ipv6.h> /* for struct ipv6hdr */ 234e3fd7a0SAlexey Dobriyan #include <net/ipv6.h> 2454d83efaSJesper Dangaard Brouer #if IS_ENABLED(CONFIG_IP_VS_IPV6) 2563dca2c0SJesper Dangaard Brouer #include <linux/netfilter_ipv6/ip6_tables.h> 2663dca2c0SJesper Dangaard Brouer #endif 27a638e514SJesper Dangaard Brouer #if IS_ENABLED(CONFIG_NF_CONNTRACK) 28f4bc17cdSJulian Anastasov #include <net/netfilter/nf_conntrack.h> 29f4bc17cdSJulian Anastasov #endif 3061b1ab45SHans Schillstrom #include <net/net_namespace.h> /* Netw namespace */ 3161b1ab45SHans Schillstrom 3207dcc686SSimon Horman /* Generic access of ipvs struct */ 3361b1ab45SHans Schillstrom static inline struct netns_ipvs *net_ipvs(struct net* net) 3461b1ab45SHans Schillstrom { 3561b1ab45SHans Schillstrom return net->ipvs; 3661b1ab45SHans Schillstrom } 3707dcc686SSimon Horman 3807dcc686SSimon Horman /* Get net ptr from skb in traffic cases 39fc723250SHans Schillstrom * use skb_sknet when call is from userland (ioctl or netlink) 40fc723250SHans Schillstrom */ 41a0840e2eSHans Schillstrom static inline struct net *skb_net(const struct sk_buff *skb) 42fc723250SHans Schillstrom { 43fc723250SHans Schillstrom #ifdef CONFIG_NET_NS 44fc723250SHans Schillstrom #ifdef CONFIG_IP_VS_DEBUG 45fc723250SHans Schillstrom /* 46fc723250SHans Schillstrom * This is used for debug only. 47fc723250SHans Schillstrom * Start with the most likely hit 48fc723250SHans Schillstrom * End with BUG 49fc723250SHans Schillstrom */ 500c5c9fb5SEric W. Biederman if (likely(skb->dev && dev_net(skb->dev))) 51fc723250SHans Schillstrom return dev_net(skb->dev); 52a09d1977SHans Schillstrom if (skb_dst(skb) && skb_dst(skb)->dev) 53fc723250SHans Schillstrom return dev_net(skb_dst(skb)->dev); 54fc723250SHans Schillstrom WARN(skb->sk, "Maybe skb_sknet should be used in %s() at line:%d\n", 55fc723250SHans Schillstrom __func__, __LINE__); 560c5c9fb5SEric W. Biederman if (likely(skb->sk && sock_net(skb->sk))) 57fc723250SHans Schillstrom return sock_net(skb->sk); 58fc723250SHans Schillstrom pr_err("There is no net ptr to find in the skb in %s() line:%d\n", 59fc723250SHans Schillstrom __func__, __LINE__); 60fc723250SHans Schillstrom BUG(); 61fc723250SHans Schillstrom #else 62fc723250SHans Schillstrom return dev_net(skb->dev ? : skb_dst(skb)->dev); 63fc723250SHans Schillstrom #endif 64fc723250SHans Schillstrom #else 65fc723250SHans Schillstrom return &init_net; 66fc723250SHans Schillstrom #endif 67fc723250SHans Schillstrom } 68fc723250SHans Schillstrom 69a0840e2eSHans Schillstrom static inline struct net *skb_sknet(const struct sk_buff *skb) 70fc723250SHans Schillstrom { 71fc723250SHans Schillstrom #ifdef CONFIG_NET_NS 72fc723250SHans Schillstrom #ifdef CONFIG_IP_VS_DEBUG 73fc723250SHans Schillstrom /* Start with the most likely hit */ 740c5c9fb5SEric W. Biederman if (likely(skb->sk && sock_net(skb->sk))) 75fc723250SHans Schillstrom return sock_net(skb->sk); 76fc723250SHans Schillstrom WARN(skb->dev, "Maybe skb_net should be used instead in %s() line:%d\n", 77fc723250SHans Schillstrom __func__, __LINE__); 780c5c9fb5SEric W. Biederman if (likely(skb->dev && dev_net(skb->dev))) 79fc723250SHans Schillstrom return dev_net(skb->dev); 80fc723250SHans Schillstrom pr_err("There is no net ptr to find in the skb in %s() line:%d\n", 81fc723250SHans Schillstrom __func__, __LINE__); 82fc723250SHans Schillstrom BUG(); 83fc723250SHans Schillstrom #else 84fc723250SHans Schillstrom return sock_net(skb->sk); 85fc723250SHans Schillstrom #endif 86fc723250SHans Schillstrom #else 87fc723250SHans Schillstrom return &init_net; 88fc723250SHans Schillstrom #endif 89fc723250SHans Schillstrom } 9007dcc686SSimon Horman 9107dcc686SSimon Horman /* This one needed for single_open_net since net is stored directly in 9225985edcSLucas De Marchi * private not as a struct i.e. seq_file_net can't be used. 93b17fc996SHans Schillstrom */ 94b17fc996SHans Schillstrom static inline struct net *seq_file_single_net(struct seq_file *seq) 95b17fc996SHans Schillstrom { 96b17fc996SHans Schillstrom #ifdef CONFIG_NET_NS 97b17fc996SHans Schillstrom return (struct net *)seq->private; 98b17fc996SHans Schillstrom #else 99b17fc996SHans Schillstrom return &init_net; 100b17fc996SHans Schillstrom #endif 101b17fc996SHans Schillstrom } 1026f7edb48SCatalin(ux) M. BOIE 1036f7edb48SCatalin(ux) M. BOIE /* Connections' size value needed by ip_vs_ctl.c */ 1046f7edb48SCatalin(ux) M. BOIE extern int ip_vs_conn_tab_size; 1056f7edb48SCatalin(ux) M. BOIE 10664aae3cbSJulius Volz struct ip_vs_iphdr { 10763dca2c0SJesper Dangaard Brouer __u32 len; /* IPv4 simply where L4 starts 10807dcc686SSimon Horman * IPv6 where L4 Transport Header starts */ 10963dca2c0SJesper Dangaard Brouer __u16 fragoffs; /* IPv6 fragment offset, 0 if first frag (or not frag)*/ 11063dca2c0SJesper Dangaard Brouer __s16 protocol; 11163dca2c0SJesper Dangaard Brouer __s32 flags; 11264aae3cbSJulius Volz union nf_inet_addr saddr; 11364aae3cbSJulius Volz union nf_inet_addr daddr; 11464aae3cbSJulius Volz }; 11564aae3cbSJulius Volz 1162f74713dSJesper Dangaard Brouer static inline void *frag_safe_skb_hp(const struct sk_buff *skb, int offset, 1172f74713dSJesper Dangaard Brouer int len, void *buffer, 1182f74713dSJesper Dangaard Brouer const struct ip_vs_iphdr *ipvsh) 1192f74713dSJesper Dangaard Brouer { 1202f74713dSJesper Dangaard Brouer return skb_header_pointer(skb, offset, len, buffer); 1212f74713dSJesper Dangaard Brouer } 1222f74713dSJesper Dangaard Brouer 12364aae3cbSJulius Volz static inline void 12463dca2c0SJesper Dangaard Brouer ip_vs_fill_ip4hdr(const void *nh, struct ip_vs_iphdr *iphdr) 12563dca2c0SJesper Dangaard Brouer { 12663dca2c0SJesper Dangaard Brouer const struct iphdr *iph = nh; 12763dca2c0SJesper Dangaard Brouer 12863dca2c0SJesper Dangaard Brouer iphdr->len = iph->ihl * 4; 12963dca2c0SJesper Dangaard Brouer iphdr->fragoffs = 0; 13063dca2c0SJesper Dangaard Brouer iphdr->protocol = iph->protocol; 13163dca2c0SJesper Dangaard Brouer iphdr->saddr.ip = iph->saddr; 13263dca2c0SJesper Dangaard Brouer iphdr->daddr.ip = iph->daddr; 13363dca2c0SJesper Dangaard Brouer } 13463dca2c0SJesper Dangaard Brouer 13563dca2c0SJesper Dangaard Brouer /* This function handles filling *ip_vs_iphdr, both for IPv4 and IPv6. 13663dca2c0SJesper Dangaard Brouer * IPv6 requires some extra work, as finding proper header position, 13763dca2c0SJesper Dangaard Brouer * depend on the IPv6 extension headers. 13863dca2c0SJesper Dangaard Brouer */ 13963dca2c0SJesper Dangaard Brouer static inline void 14063dca2c0SJesper Dangaard Brouer ip_vs_fill_iph_skb(int af, const struct sk_buff *skb, struct ip_vs_iphdr *iphdr) 14164aae3cbSJulius Volz { 14264aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6 14364aae3cbSJulius Volz if (af == AF_INET6) { 14463dca2c0SJesper Dangaard Brouer const struct ipv6hdr *iph = 14563dca2c0SJesper Dangaard Brouer (struct ipv6hdr *)skb_network_header(skb); 1464e3fd7a0SAlexey Dobriyan iphdr->saddr.in6 = iph->saddr; 1474e3fd7a0SAlexey Dobriyan iphdr->daddr.in6 = iph->daddr; 1486aafeef0SJiri Pirko /* ipv6_find_hdr() updates len, flags */ 14963dca2c0SJesper Dangaard Brouer iphdr->len = 0; 15063dca2c0SJesper Dangaard Brouer iphdr->flags = 0; 15163dca2c0SJesper Dangaard Brouer iphdr->protocol = ipv6_find_hdr(skb, &iphdr->len, -1, 15263dca2c0SJesper Dangaard Brouer &iphdr->fragoffs, 15363dca2c0SJesper Dangaard Brouer &iphdr->flags); 15464aae3cbSJulius Volz } else 15564aae3cbSJulius Volz #endif 15664aae3cbSJulius Volz { 15763dca2c0SJesper Dangaard Brouer const struct iphdr *iph = 15863dca2c0SJesper Dangaard Brouer (struct iphdr *)skb_network_header(skb); 15964aae3cbSJulius Volz iphdr->len = iph->ihl * 4; 16063dca2c0SJesper Dangaard Brouer iphdr->fragoffs = 0; 16164aae3cbSJulius Volz iphdr->protocol = iph->protocol; 16264aae3cbSJulius Volz iphdr->saddr.ip = iph->saddr; 16364aae3cbSJulius Volz iphdr->daddr.ip = iph->daddr; 16464aae3cbSJulius Volz } 16564aae3cbSJulius Volz } 16664aae3cbSJulius Volz 16764aae3cbSJulius Volz static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst, 16864aae3cbSJulius Volz const union nf_inet_addr *src) 16964aae3cbSJulius Volz { 17064aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6 17164aae3cbSJulius Volz if (af == AF_INET6) 1724e3fd7a0SAlexey Dobriyan dst->in6 = src->in6; 17364aae3cbSJulius Volz else 17464aae3cbSJulius Volz #endif 17564aae3cbSJulius Volz dst->ip = src->ip; 17664aae3cbSJulius Volz } 17764aae3cbSJulius Volz 1789a05475cSJulian Anastasov static inline void ip_vs_addr_set(int af, union nf_inet_addr *dst, 1799a05475cSJulian Anastasov const union nf_inet_addr *src) 1809a05475cSJulian Anastasov { 1819a05475cSJulian Anastasov #ifdef CONFIG_IP_VS_IPV6 1829a05475cSJulian Anastasov if (af == AF_INET6) { 1839a05475cSJulian Anastasov dst->in6 = src->in6; 1849a05475cSJulian Anastasov return; 1859a05475cSJulian Anastasov } 1869a05475cSJulian Anastasov #endif 1879a05475cSJulian Anastasov dst->ip = src->ip; 1889a05475cSJulian Anastasov dst->all[1] = 0; 1899a05475cSJulian Anastasov dst->all[2] = 0; 1909a05475cSJulian Anastasov dst->all[3] = 0; 1919a05475cSJulian Anastasov } 1929a05475cSJulian Anastasov 19364aae3cbSJulius Volz static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a, 19464aae3cbSJulius Volz const union nf_inet_addr *b) 19564aae3cbSJulius Volz { 19664aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6 19764aae3cbSJulius Volz if (af == AF_INET6) 19864aae3cbSJulius Volz return ipv6_addr_equal(&a->in6, &b->in6); 19964aae3cbSJulius Volz #endif 20064aae3cbSJulius Volz return a->ip == b->ip; 20164aae3cbSJulius Volz } 20264aae3cbSJulius Volz 2031da177e4SLinus Torvalds #ifdef CONFIG_IP_VS_DEBUG 20414c85021SArnaldo Carvalho de Melo #include <linux/net.h> 20514c85021SArnaldo Carvalho de Melo 2065c3a0fd7SJoe Perches int ip_vs_get_debug_level(void); 207c842a3adSJulius Volz 208c842a3adSJulius Volz static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len, 209c842a3adSJulius Volz const union nf_inet_addr *addr, 210c842a3adSJulius Volz int *idx) 211c842a3adSJulius Volz { 212c842a3adSJulius Volz int len; 213c842a3adSJulius Volz #ifdef CONFIG_IP_VS_IPV6 214c842a3adSJulius Volz if (af == AF_INET6) 215120b9c14SJesper Dangaard Brouer len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6c]", 2160c6ce78aSHarvey Harrison &addr->in6) + 1; 217c842a3adSJulius Volz else 218c842a3adSJulius Volz #endif 2193685f25dSHarvey Harrison len = snprintf(&buf[*idx], buf_len - *idx, "%pI4", 2203685f25dSHarvey Harrison &addr->ip) + 1; 221c842a3adSJulius Volz 222c842a3adSJulius Volz *idx += len; 223c842a3adSJulius Volz BUG_ON(*idx > buf_len + 1); 224c842a3adSJulius Volz return &buf[*idx - len]; 225c842a3adSJulius Volz } 226c842a3adSJulius Volz 2279aada7acSHannes Eder #define IP_VS_DBG_BUF(level, msg, ...) \ 228c842a3adSJulius Volz do { \ 229c842a3adSJulius Volz char ip_vs_dbg_buf[160]; \ 230c842a3adSJulius Volz int ip_vs_dbg_idx = 0; \ 231c842a3adSJulius Volz if (level <= ip_vs_get_debug_level()) \ 2329aada7acSHannes Eder printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ 233c842a3adSJulius Volz } while (0) 234c842a3adSJulius Volz #define IP_VS_ERR_BUF(msg...) \ 235c842a3adSJulius Volz do { \ 236c842a3adSJulius Volz char ip_vs_dbg_buf[160]; \ 237c842a3adSJulius Volz int ip_vs_dbg_idx = 0; \ 2389aada7acSHannes Eder pr_err(msg); \ 239c842a3adSJulius Volz } while (0) 240c842a3adSJulius Volz 241c842a3adSJulius Volz /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */ 242c842a3adSJulius Volz #define IP_VS_DBG_ADDR(af, addr) \ 243c842a3adSJulius Volz ip_vs_dbg_addr(af, ip_vs_dbg_buf, \ 244c842a3adSJulius Volz sizeof(ip_vs_dbg_buf), addr, \ 245c842a3adSJulius Volz &ip_vs_dbg_idx) 246c842a3adSJulius Volz 2479aada7acSHannes Eder #define IP_VS_DBG(level, msg, ...) \ 2481da177e4SLinus Torvalds do { \ 2491da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \ 2509aada7acSHannes Eder printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ 2511da177e4SLinus Torvalds } while (0) 2529aada7acSHannes Eder #define IP_VS_DBG_RL(msg, ...) \ 2531da177e4SLinus Torvalds do { \ 2541da177e4SLinus Torvalds if (net_ratelimit()) \ 2559aada7acSHannes Eder printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ 2561da177e4SLinus Torvalds } while (0) 2570d79641aSJulian Anastasov #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) \ 2581da177e4SLinus Torvalds do { \ 2591da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \ 2600d79641aSJulian Anastasov pp->debug_packet(af, pp, skb, ofs, msg); \ 2611da177e4SLinus Torvalds } while (0) 2620d79641aSJulian Anastasov #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) \ 2631da177e4SLinus Torvalds do { \ 2641da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level() && \ 2651da177e4SLinus Torvalds net_ratelimit()) \ 2660d79641aSJulian Anastasov pp->debug_packet(af, pp, skb, ofs, msg); \ 2671da177e4SLinus Torvalds } while (0) 2681da177e4SLinus Torvalds #else /* NO DEBUGGING at ALL */ 269c842a3adSJulius Volz #define IP_VS_DBG_BUF(level, msg...) do {} while (0) 270c842a3adSJulius Volz #define IP_VS_ERR_BUF(msg...) do {} while (0) 2711da177e4SLinus Torvalds #define IP_VS_DBG(level, msg...) do {} while (0) 2721da177e4SLinus Torvalds #define IP_VS_DBG_RL(msg...) do {} while (0) 2730d79641aSJulian Anastasov #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) do {} while (0) 2740d79641aSJulian Anastasov #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) do {} while (0) 2751da177e4SLinus Torvalds #endif 2761da177e4SLinus Torvalds 2771da177e4SLinus Torvalds #define IP_VS_BUG() BUG() 2781e3e238eSHannes Eder #define IP_VS_ERR_RL(msg, ...) \ 2791da177e4SLinus Torvalds do { \ 2801da177e4SLinus Torvalds if (net_ratelimit()) \ 2811e3e238eSHannes Eder pr_err(msg, ##__VA_ARGS__); \ 2821da177e4SLinus Torvalds } while (0) 2831da177e4SLinus Torvalds 2841da177e4SLinus Torvalds #ifdef CONFIG_IP_VS_DEBUG 2851da177e4SLinus Torvalds #define EnterFunction(level) \ 2861da177e4SLinus Torvalds do { \ 2871da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \ 2889aada7acSHannes Eder printk(KERN_DEBUG \ 2899aada7acSHannes Eder pr_fmt("Enter: %s, %s line %i\n"), \ 290d5c003b4SHarvey Harrison __func__, __FILE__, __LINE__); \ 2911da177e4SLinus Torvalds } while (0) 2921da177e4SLinus Torvalds #define LeaveFunction(level) \ 2931da177e4SLinus Torvalds do { \ 2941da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \ 2959aada7acSHannes Eder printk(KERN_DEBUG \ 2969aada7acSHannes Eder pr_fmt("Leave: %s, %s line %i\n"), \ 297d5c003b4SHarvey Harrison __func__, __FILE__, __LINE__); \ 2981da177e4SLinus Torvalds } while (0) 2991da177e4SLinus Torvalds #else 3001da177e4SLinus Torvalds #define EnterFunction(level) do {} while (0) 3011da177e4SLinus Torvalds #define LeaveFunction(level) do {} while (0) 3021da177e4SLinus Torvalds #endif 3031da177e4SLinus Torvalds 30407dcc686SSimon Horman /* The port number of FTP service (in network order). */ 305f3a7c66bSHarvey Harrison #define FTPPORT cpu_to_be16(21) 306f3a7c66bSHarvey Harrison #define FTPDATA cpu_to_be16(20) 3071da177e4SLinus Torvalds 30807dcc686SSimon Horman /* TCP State Values */ 3091da177e4SLinus Torvalds enum { 3101da177e4SLinus Torvalds IP_VS_TCP_S_NONE = 0, 3111da177e4SLinus Torvalds IP_VS_TCP_S_ESTABLISHED, 3121da177e4SLinus Torvalds IP_VS_TCP_S_SYN_SENT, 3131da177e4SLinus Torvalds IP_VS_TCP_S_SYN_RECV, 3141da177e4SLinus Torvalds IP_VS_TCP_S_FIN_WAIT, 3151da177e4SLinus Torvalds IP_VS_TCP_S_TIME_WAIT, 3161da177e4SLinus Torvalds IP_VS_TCP_S_CLOSE, 3171da177e4SLinus Torvalds IP_VS_TCP_S_CLOSE_WAIT, 3181da177e4SLinus Torvalds IP_VS_TCP_S_LAST_ACK, 3191da177e4SLinus Torvalds IP_VS_TCP_S_LISTEN, 3201da177e4SLinus Torvalds IP_VS_TCP_S_SYNACK, 3211da177e4SLinus Torvalds IP_VS_TCP_S_LAST 3221da177e4SLinus Torvalds }; 3231da177e4SLinus Torvalds 32407dcc686SSimon Horman /* UDP State Values */ 3251da177e4SLinus Torvalds enum { 3261da177e4SLinus Torvalds IP_VS_UDP_S_NORMAL, 3271da177e4SLinus Torvalds IP_VS_UDP_S_LAST, 3281da177e4SLinus Torvalds }; 3291da177e4SLinus Torvalds 33007dcc686SSimon Horman /* ICMP State Values */ 3311da177e4SLinus Torvalds enum { 3321da177e4SLinus Torvalds IP_VS_ICMP_S_NORMAL, 3331da177e4SLinus Torvalds IP_VS_ICMP_S_LAST, 3341da177e4SLinus Torvalds }; 3351da177e4SLinus Torvalds 33607dcc686SSimon Horman /* SCTP State Values */ 3372906f66aSVenkata Mohan Reddy enum ip_vs_sctp_states { 3382906f66aSVenkata Mohan Reddy IP_VS_SCTP_S_NONE, 33961e7c420SJulian Anastasov IP_VS_SCTP_S_INIT1, 34061e7c420SJulian Anastasov IP_VS_SCTP_S_INIT, 34161e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE_SENT, 34261e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE_REPLIED, 34361e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE_WAIT, 34461e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE, 34561e7c420SJulian Anastasov IP_VS_SCTP_S_COOKIE_ECHOED, 3462906f66aSVenkata Mohan Reddy IP_VS_SCTP_S_ESTABLISHED, 34761e7c420SJulian Anastasov IP_VS_SCTP_S_SHUTDOWN_SENT, 34861e7c420SJulian Anastasov IP_VS_SCTP_S_SHUTDOWN_RECEIVED, 34961e7c420SJulian Anastasov IP_VS_SCTP_S_SHUTDOWN_ACK_SENT, 35061e7c420SJulian Anastasov IP_VS_SCTP_S_REJECTED, 3512906f66aSVenkata Mohan Reddy IP_VS_SCTP_S_CLOSED, 3522906f66aSVenkata Mohan Reddy IP_VS_SCTP_S_LAST 3532906f66aSVenkata Mohan Reddy }; 3542906f66aSVenkata Mohan Reddy 35507dcc686SSimon Horman /* Delta sequence info structure 3561da177e4SLinus Torvalds * Each ip_vs_conn has 2 (output AND input seq. changes). 3571da177e4SLinus Torvalds * Only used in the VS/NAT. 3581da177e4SLinus Torvalds */ 3591da177e4SLinus Torvalds struct ip_vs_seq { 3601da177e4SLinus Torvalds __u32 init_seq; /* Add delta from this seq */ 3611da177e4SLinus Torvalds __u32 delta; /* Delta in sequence numbers */ 3621da177e4SLinus Torvalds __u32 previous_delta; /* Delta in sequence numbers 36307dcc686SSimon Horman * before last resized pkt */ 3641da177e4SLinus Torvalds }; 3651da177e4SLinus Torvalds 36607dcc686SSimon Horman /* counters per cpu */ 367b17fc996SHans Schillstrom struct ip_vs_counters { 368cd67cd5eSJulian Anastasov __u64 conns; /* connections scheduled */ 369cd67cd5eSJulian Anastasov __u64 inpkts; /* incoming packets */ 370cd67cd5eSJulian Anastasov __u64 outpkts; /* outgoing packets */ 371b17fc996SHans Schillstrom __u64 inbytes; /* incoming bytes */ 372b17fc996SHans Schillstrom __u64 outbytes; /* outgoing bytes */ 373b17fc996SHans Schillstrom }; 37407dcc686SSimon Horman /* Stats per cpu */ 375b17fc996SHans Schillstrom struct ip_vs_cpu_stats { 376cd67cd5eSJulian Anastasov struct ip_vs_counters cnt; 377b17fc996SHans Schillstrom struct u64_stats_sync syncp; 378b17fc996SHans Schillstrom }; 3791da177e4SLinus Torvalds 38007dcc686SSimon Horman /* IPVS statistics objects */ 3813a14a313SSven Wegener struct ip_vs_estimator { 3823a14a313SSven Wegener struct list_head list; 3833a14a313SSven Wegener 3843a14a313SSven Wegener u64 last_inbytes; 3853a14a313SSven Wegener u64 last_outbytes; 386cd67cd5eSJulian Anastasov u64 last_conns; 387cd67cd5eSJulian Anastasov u64 last_inpkts; 388cd67cd5eSJulian Anastasov u64 last_outpkts; 3893a14a313SSven Wegener 390cd67cd5eSJulian Anastasov u64 cps; 391cd67cd5eSJulian Anastasov u64 inpps; 392cd67cd5eSJulian Anastasov u64 outpps; 393cd67cd5eSJulian Anastasov u64 inbps; 394cd67cd5eSJulian Anastasov u64 outbps; 395cd67cd5eSJulian Anastasov }; 396cd67cd5eSJulian Anastasov 397cd67cd5eSJulian Anastasov /* 398cd67cd5eSJulian Anastasov * IPVS statistics object, 64-bit kernel version of struct ip_vs_stats_user 399cd67cd5eSJulian Anastasov */ 400cd67cd5eSJulian Anastasov struct ip_vs_kstats { 401cd67cd5eSJulian Anastasov u64 conns; /* connections scheduled */ 402cd67cd5eSJulian Anastasov u64 inpkts; /* incoming packets */ 403cd67cd5eSJulian Anastasov u64 outpkts; /* outgoing packets */ 404cd67cd5eSJulian Anastasov u64 inbytes; /* incoming bytes */ 405cd67cd5eSJulian Anastasov u64 outbytes; /* outgoing bytes */ 406cd67cd5eSJulian Anastasov 407cd67cd5eSJulian Anastasov u64 cps; /* current connection rate */ 408cd67cd5eSJulian Anastasov u64 inpps; /* current in packet rate */ 409cd67cd5eSJulian Anastasov u64 outpps; /* current out packet rate */ 410cd67cd5eSJulian Anastasov u64 inbps; /* current in byte rate */ 411cd67cd5eSJulian Anastasov u64 outbps; /* current out byte rate */ 4123a14a313SSven Wegener }; 4133a14a313SSven Wegener 414fd2c3ef7SEric Dumazet struct ip_vs_stats { 415cd67cd5eSJulian Anastasov struct ip_vs_kstats kstats; /* kernel statistics */ 416e9c0ce23SSven Wegener struct ip_vs_estimator est; /* estimator */ 417b962abdcSJulian Anastasov struct ip_vs_cpu_stats __percpu *cpustats; /* per cpu counters */ 4181da177e4SLinus Torvalds spinlock_t lock; /* spin lock */ 419cd67cd5eSJulian Anastasov struct ip_vs_kstats kstats0; /* reset values */ 4201da177e4SLinus Torvalds }; 4211da177e4SLinus Torvalds 42214c85021SArnaldo Carvalho de Melo struct dst_entry; 42314c85021SArnaldo Carvalho de Melo struct iphdr; 4241da177e4SLinus Torvalds struct ip_vs_conn; 4251da177e4SLinus Torvalds struct ip_vs_app; 42614c85021SArnaldo Carvalho de Melo struct sk_buff; 427252c6410SHans Schillstrom struct ip_vs_proto_data; 4281da177e4SLinus Torvalds 4291da177e4SLinus Torvalds struct ip_vs_protocol { 4301da177e4SLinus Torvalds struct ip_vs_protocol *next; 4311da177e4SLinus Torvalds char *name; 4322ad17defSJulian Anastasov u16 protocol; 4332ad17defSJulian Anastasov u16 num_states; 4341da177e4SLinus Torvalds int dont_defrag; 4351da177e4SLinus Torvalds 4361da177e4SLinus Torvalds void (*init)(struct ip_vs_protocol *pp); 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvalds void (*exit)(struct ip_vs_protocol *pp); 4391da177e4SLinus Torvalds 440582b8e3eSHans Schillstrom int (*init_netns)(struct net *net, struct ip_vs_proto_data *pd); 441252c6410SHans Schillstrom 442252c6410SHans Schillstrom void (*exit_netns)(struct net *net, struct ip_vs_proto_data *pd); 443252c6410SHans Schillstrom 44451ef348bSJulius Volz int (*conn_schedule)(int af, struct sk_buff *skb, 4459330419dSHans Schillstrom struct ip_vs_proto_data *pd, 446d4383f04SJesper Dangaard Brouer int *verdict, struct ip_vs_conn **cpp, 447d4383f04SJesper Dangaard Brouer struct ip_vs_iphdr *iph); 4481da177e4SLinus Torvalds 4491da177e4SLinus Torvalds struct ip_vs_conn * 45051ef348bSJulius Volz (*conn_in_get)(int af, 45151ef348bSJulius Volz const struct sk_buff *skb, 45251ef348bSJulius Volz const struct ip_vs_iphdr *iph, 4531da177e4SLinus Torvalds int inverse); 4541da177e4SLinus Torvalds 4551da177e4SLinus Torvalds struct ip_vs_conn * 45651ef348bSJulius Volz (*conn_out_get)(int af, 45751ef348bSJulius Volz const struct sk_buff *skb, 45851ef348bSJulius Volz const struct ip_vs_iphdr *iph, 4591da177e4SLinus Torvalds int inverse); 4601da177e4SLinus Torvalds 461d4383f04SJesper Dangaard Brouer int (*snat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp, 462d4383f04SJesper Dangaard Brouer struct ip_vs_conn *cp, struct ip_vs_iphdr *iph); 4631da177e4SLinus Torvalds 464d4383f04SJesper Dangaard Brouer int (*dnat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp, 465d4383f04SJesper Dangaard Brouer struct ip_vs_conn *cp, struct ip_vs_iphdr *iph); 4661da177e4SLinus Torvalds 46751ef348bSJulius Volz int (*csum_check)(int af, struct sk_buff *skb, 46851ef348bSJulius Volz struct ip_vs_protocol *pp); 4691da177e4SLinus Torvalds 4701da177e4SLinus Torvalds const char *(*state_name)(int state); 4711da177e4SLinus Torvalds 4724a516f11SSimon Horman void (*state_transition)(struct ip_vs_conn *cp, int direction, 4731da177e4SLinus Torvalds const struct sk_buff *skb, 4749330419dSHans Schillstrom struct ip_vs_proto_data *pd); 4751da177e4SLinus Torvalds 476ab8a5e84SHans Schillstrom int (*register_app)(struct net *net, struct ip_vs_app *inc); 4771da177e4SLinus Torvalds 478ab8a5e84SHans Schillstrom void (*unregister_app)(struct net *net, struct ip_vs_app *inc); 4791da177e4SLinus Torvalds 4801da177e4SLinus Torvalds int (*app_conn_bind)(struct ip_vs_conn *cp); 4811da177e4SLinus Torvalds 4820d79641aSJulian Anastasov void (*debug_packet)(int af, struct ip_vs_protocol *pp, 4831da177e4SLinus Torvalds const struct sk_buff *skb, 4841da177e4SLinus Torvalds int offset, 4851da177e4SLinus Torvalds const char *msg); 4861da177e4SLinus Torvalds 4879330419dSHans Schillstrom void (*timeout_change)(struct ip_vs_proto_data *pd, int flags); 4881da177e4SLinus Torvalds }; 4891da177e4SLinus Torvalds 49007dcc686SSimon Horman /* protocol data per netns */ 491252c6410SHans Schillstrom struct ip_vs_proto_data { 492252c6410SHans Schillstrom struct ip_vs_proto_data *next; 493252c6410SHans Schillstrom struct ip_vs_protocol *pp; 494252c6410SHans Schillstrom int *timeout_table; /* protocol timeout table */ 495252c6410SHans Schillstrom atomic_t appcnt; /* counter of proto app incs. */ 496252c6410SHans Schillstrom struct tcp_states_t *tcp_state_table; 497252c6410SHans Schillstrom }; 498252c6410SHans Schillstrom 4995c3a0fd7SJoe Perches struct ip_vs_protocol *ip_vs_proto_get(unsigned short proto); 5005c3a0fd7SJoe Perches struct ip_vs_proto_data *ip_vs_proto_data_get(struct net *net, 501252c6410SHans Schillstrom unsigned short proto); 5021da177e4SLinus Torvalds 503f11017ecSSimon Horman struct ip_vs_conn_param { 5046e67e586SHans Schillstrom struct net *net; 505f11017ecSSimon Horman const union nf_inet_addr *caddr; 506f11017ecSSimon Horman const union nf_inet_addr *vaddr; 507f11017ecSSimon Horman __be16 cport; 508f11017ecSSimon Horman __be16 vport; 509f11017ecSSimon Horman __u16 protocol; 510f11017ecSSimon Horman u16 af; 51185999283SSimon Horman 51285999283SSimon Horman const struct ip_vs_pe *pe; 51385999283SSimon Horman char *pe_data; 51485999283SSimon Horman __u8 pe_data_len; 515f11017ecSSimon Horman }; 516f11017ecSSimon Horman 51707dcc686SSimon Horman /* IP_VS structure allocated for each dynamically scheduled connection */ 5181da177e4SLinus Torvalds struct ip_vs_conn { 519731109e7SChangli Gao struct hlist_node c_list; /* hashed list heads */ 5201da177e4SLinus Torvalds /* Protocol, addresses and port numbers */ 5216e67e586SHans Schillstrom __be16 cport; 5226e67e586SHans Schillstrom __be16 dport; 5231845ed0bSJulian Anastasov __be16 vport; 5241845ed0bSJulian Anastasov u16 af; /* address family */ 525e7ade46aSJulius Volz union nf_inet_addr caddr; /* client address */ 526e7ade46aSJulius Volz union nf_inet_addr vaddr; /* virtual address */ 527e7ade46aSJulius Volz union nf_inet_addr daddr; /* destination address */ 5283575792eSJulian Anastasov volatile __u32 flags; /* status flags */ 5291da177e4SLinus Torvalds __u16 protocol; /* Which protocol (TCP/UDP) */ 530ba38528aSAlex Gartrell __u16 daf; /* Address family of the dest */ 5311845ed0bSJulian Anastasov #ifdef CONFIG_NET_NS 5321845ed0bSJulian Anastasov struct net *net; /* Name space */ 5331845ed0bSJulian Anastasov #endif 5341da177e4SLinus Torvalds 5351da177e4SLinus Torvalds /* counter and timer */ 5361da177e4SLinus Torvalds atomic_t refcnt; /* reference count */ 5371da177e4SLinus Torvalds struct timer_list timer; /* Expiration timer */ 5381da177e4SLinus Torvalds volatile unsigned long timeout; /* timeout */ 5391da177e4SLinus Torvalds 5401da177e4SLinus Torvalds /* Flags and state transition */ 5411da177e4SLinus Torvalds spinlock_t lock; /* lock for state transition */ 5421da177e4SLinus Torvalds volatile __u16 state; /* state info */ 543efac5276SRumen G. Bogdanovski volatile __u16 old_state; /* old state, to be used for 544efac5276SRumen G. Bogdanovski * state transition triggerd 545efac5276SRumen G. Bogdanovski * synchronization 546efac5276SRumen G. Bogdanovski */ 5471845ed0bSJulian Anastasov __u32 fwmark; /* Fire wall mark from skb */ 548749c42b6SJulian Anastasov unsigned long sync_endtime; /* jiffies + sent_retries */ 5491da177e4SLinus Torvalds 5501da177e4SLinus Torvalds /* Control members */ 5511da177e4SLinus Torvalds struct ip_vs_conn *control; /* Master control connection */ 5521da177e4SLinus Torvalds atomic_t n_control; /* Number of controlled ones */ 5531da177e4SLinus Torvalds struct ip_vs_dest *dest; /* real server */ 5541da177e4SLinus Torvalds atomic_t in_pkts; /* incoming packet counter */ 5551da177e4SLinus Torvalds 55607dcc686SSimon Horman /* Packet transmitter for different forwarding methods. If it 55707dcc686SSimon Horman * mangles the packet, it must return NF_DROP or better NF_STOLEN, 55807dcc686SSimon Horman * otherwise this must be changed to a sk_buff **. 55907dcc686SSimon Horman * NF_ACCEPT can be returned when destination is local. 5601da177e4SLinus Torvalds */ 5611da177e4SLinus Torvalds int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp, 562d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 5631da177e4SLinus Torvalds 5641da177e4SLinus Torvalds /* Note: we can group the following members into a structure, 56507dcc686SSimon Horman * in order to save more space, and the following members are 56607dcc686SSimon Horman * only used in VS/NAT anyway 56707dcc686SSimon Horman */ 5681da177e4SLinus Torvalds struct ip_vs_app *app; /* bound ip_vs_app object */ 5691da177e4SLinus Torvalds void *app_data; /* Application private data */ 5701da177e4SLinus Torvalds struct ip_vs_seq in_seq; /* incoming seq. struct */ 5711da177e4SLinus Torvalds struct ip_vs_seq out_seq; /* outgoing seq. struct */ 57285999283SSimon Horman 573e9e5eee8SSimon Horman const struct ip_vs_pe *pe; 57485999283SSimon Horman char *pe_data; 57585999283SSimon Horman __u8 pe_data_len; 576088339a5SJulian Anastasov 577088339a5SJulian Anastasov struct rcu_head rcu_head; 5781da177e4SLinus Torvalds }; 5791da177e4SLinus Torvalds 58007dcc686SSimon Horman /* To save some memory in conn table when name space is disabled. */ 5816e67e586SHans Schillstrom static inline struct net *ip_vs_conn_net(const struct ip_vs_conn *cp) 5826e67e586SHans Schillstrom { 5836e67e586SHans Schillstrom #ifdef CONFIG_NET_NS 5846e67e586SHans Schillstrom return cp->net; 5856e67e586SHans Schillstrom #else 5866e67e586SHans Schillstrom return &init_net; 5876e67e586SHans Schillstrom #endif 5886e67e586SHans Schillstrom } 58907dcc686SSimon Horman 5906e67e586SHans Schillstrom static inline void ip_vs_conn_net_set(struct ip_vs_conn *cp, struct net *net) 5916e67e586SHans Schillstrom { 5926e67e586SHans Schillstrom #ifdef CONFIG_NET_NS 5936e67e586SHans Schillstrom cp->net = net; 5946e67e586SHans Schillstrom #endif 5956e67e586SHans Schillstrom } 5966e67e586SHans Schillstrom 5976e67e586SHans Schillstrom static inline int ip_vs_conn_net_eq(const struct ip_vs_conn *cp, 5986e67e586SHans Schillstrom struct net *net) 5996e67e586SHans Schillstrom { 6006e67e586SHans Schillstrom #ifdef CONFIG_NET_NS 6016e67e586SHans Schillstrom return cp->net == net; 6026e67e586SHans Schillstrom #else 6036e67e586SHans Schillstrom return 1; 6046e67e586SHans Schillstrom #endif 6056e67e586SHans Schillstrom } 6061da177e4SLinus Torvalds 60707dcc686SSimon Horman /* Extended internal versions of struct ip_vs_service_user and ip_vs_dest_user 60807dcc686SSimon Horman * for IPv6 support. 609c860c6b1SJulius Volz * 610c860c6b1SJulius Volz * We need these to conveniently pass around service and destination 611c860c6b1SJulius Volz * options, but unfortunately, we also need to keep the old definitions to 612c860c6b1SJulius Volz * maintain userspace backwards compatibility for the setsockopt interface. 613c860c6b1SJulius Volz */ 614c860c6b1SJulius Volz struct ip_vs_service_user_kern { 615c860c6b1SJulius Volz /* virtual service addresses */ 616c860c6b1SJulius Volz u16 af; 617c860c6b1SJulius Volz u16 protocol; 618c860c6b1SJulius Volz union nf_inet_addr addr; /* virtual ip address */ 6190a925864SJulian Anastasov __be16 port; 620c860c6b1SJulius Volz u32 fwmark; /* firwall mark of service */ 621c860c6b1SJulius Volz 622c860c6b1SJulius Volz /* virtual service options */ 623c860c6b1SJulius Volz char *sched_name; 6240d1e71b0SSimon Horman char *pe_name; 62595c96174SEric Dumazet unsigned int flags; /* virtual service flags */ 62695c96174SEric Dumazet unsigned int timeout; /* persistent timeout in sec */ 6270a925864SJulian Anastasov __be32 netmask; /* persistent netmask or plen */ 628c860c6b1SJulius Volz }; 629c860c6b1SJulius Volz 630c860c6b1SJulius Volz 631c860c6b1SJulius Volz struct ip_vs_dest_user_kern { 632c860c6b1SJulius Volz /* destination server address */ 633c860c6b1SJulius Volz union nf_inet_addr addr; 6340a925864SJulian Anastasov __be16 port; 635c860c6b1SJulius Volz 636c860c6b1SJulius Volz /* real server options */ 63795c96174SEric Dumazet unsigned int conn_flags; /* connection flags */ 638c860c6b1SJulius Volz int weight; /* destination weight */ 639c860c6b1SJulius Volz 640c860c6b1SJulius Volz /* thresholds for active connections */ 641c860c6b1SJulius Volz u32 u_threshold; /* upper threshold */ 642c860c6b1SJulius Volz u32 l_threshold; /* lower threshold */ 6436cff339bSAlex Gartrell 6446cff339bSAlex Gartrell /* Address family of addr */ 6456cff339bSAlex Gartrell u16 af; 646c860c6b1SJulius Volz }; 647c860c6b1SJulius Volz 648c860c6b1SJulius Volz 649c860c6b1SJulius Volz /* 65007dcc686SSimon Horman * The information about the virtual service offered to the net and the 65107dcc686SSimon Horman * forwarding entries. 6521da177e4SLinus Torvalds */ 6531da177e4SLinus Torvalds struct ip_vs_service { 654ceec4c38SJulian Anastasov struct hlist_node s_list; /* for normal service table */ 655ceec4c38SJulian Anastasov struct hlist_node f_list; /* for fwmark-based service table */ 6561da177e4SLinus Torvalds atomic_t refcnt; /* reference counter */ 6571da177e4SLinus Torvalds 658e7ade46aSJulius Volz u16 af; /* address family */ 6591da177e4SLinus Torvalds __u16 protocol; /* which protocol (TCP/UDP) */ 660e7ade46aSJulius Volz union nf_inet_addr addr; /* IP address for virtual service */ 661014d730dSAl Viro __be16 port; /* port number for the service */ 6621da177e4SLinus Torvalds __u32 fwmark; /* firewall mark of the service */ 66395c96174SEric Dumazet unsigned int flags; /* service status flags */ 66495c96174SEric Dumazet unsigned int timeout; /* persistent timeout in ticks */ 6650a925864SJulian Anastasov __be32 netmask; /* grouping granularity, mask/plen */ 666fc723250SHans Schillstrom struct net *net; 6671da177e4SLinus Torvalds 6681da177e4SLinus Torvalds struct list_head destinations; /* real server d-linked list */ 6691da177e4SLinus Torvalds __u32 num_dests; /* number of servers */ 6701da177e4SLinus Torvalds struct ip_vs_stats stats; /* statistics for the service */ 6711da177e4SLinus Torvalds 6721da177e4SLinus Torvalds /* for scheduling */ 673ceec4c38SJulian Anastasov struct ip_vs_scheduler __rcu *scheduler; /* bound scheduler object */ 674ba3a3ce1SJulian Anastasov spinlock_t sched_lock; /* lock sched_data */ 6751da177e4SLinus Torvalds void *sched_data; /* scheduler application data */ 67685999283SSimon Horman 67785999283SSimon Horman /* alternate persistence engine */ 678ceec4c38SJulian Anastasov struct ip_vs_pe __rcu *pe; 679ceec4c38SJulian Anastasov 680ceec4c38SJulian Anastasov struct rcu_head rcu_head; 6811da177e4SLinus Torvalds }; 6821da177e4SLinus Torvalds 683026ace06SJulian Anastasov /* Information for cached dst */ 684026ace06SJulian Anastasov struct ip_vs_dest_dst { 685026ace06SJulian Anastasov struct dst_entry *dst_cache; /* destination cache entry */ 686026ace06SJulian Anastasov u32 dst_cookie; 687026ace06SJulian Anastasov union nf_inet_addr dst_saddr; 688026ace06SJulian Anastasov struct rcu_head rcu_head; 689026ace06SJulian Anastasov }; 6901da177e4SLinus Torvalds 69107dcc686SSimon Horman /* The real server destination forwarding entry with ip address, port number, 69207dcc686SSimon Horman * and so on. 6931da177e4SLinus Torvalds */ 6941da177e4SLinus Torvalds struct ip_vs_dest { 6951da177e4SLinus Torvalds struct list_head n_list; /* for the dests in the service */ 696276472eaSJulian Anastasov struct hlist_node d_list; /* for table with all the dests */ 6971da177e4SLinus Torvalds 698e7ade46aSJulius Volz u16 af; /* address family */ 699014d730dSAl Viro __be16 port; /* port number of the server */ 700f2431e6eSHans Schillstrom union nf_inet_addr addr; /* IP address of the server */ 70195c96174SEric Dumazet volatile unsigned int flags; /* dest status flags */ 7021da177e4SLinus Torvalds atomic_t conn_flags; /* flags to copy to conn */ 7031da177e4SLinus Torvalds atomic_t weight; /* server weight */ 7041da177e4SLinus Torvalds 7051da177e4SLinus Torvalds atomic_t refcnt; /* reference counter */ 7061da177e4SLinus Torvalds struct ip_vs_stats stats; /* statistics */ 707bcbde4c0SJulian Anastasov unsigned long idle_start; /* start time, jiffies */ 7081da177e4SLinus Torvalds 7091da177e4SLinus Torvalds /* connection counters and thresholds */ 7101da177e4SLinus Torvalds atomic_t activeconns; /* active connections */ 7111da177e4SLinus Torvalds atomic_t inactconns; /* inactive connections */ 7121da177e4SLinus Torvalds atomic_t persistconns; /* persistent connections */ 7131da177e4SLinus Torvalds __u32 u_threshold; /* upper threshold */ 7141da177e4SLinus Torvalds __u32 l_threshold; /* lower threshold */ 7151da177e4SLinus Torvalds 7161da177e4SLinus Torvalds /* for destination cache */ 7171da177e4SLinus Torvalds spinlock_t dst_lock; /* lock of dst_cache */ 718026ace06SJulian Anastasov struct ip_vs_dest_dst __rcu *dest_dst; /* cached dst info */ 7191da177e4SLinus Torvalds 7201da177e4SLinus Torvalds /* for virtual service */ 721bcbde4c0SJulian Anastasov struct ip_vs_service __rcu *svc; /* service it belongs to */ 7221da177e4SLinus Torvalds __u16 protocol; /* which protocol (TCP/UDP) */ 723014d730dSAl Viro __be16 vport; /* virtual port number */ 724f2431e6eSHans Schillstrom union nf_inet_addr vaddr; /* virtual IP address */ 7251da177e4SLinus Torvalds __u32 vfwmark; /* firewall mark of service */ 726276472eaSJulian Anastasov 727578bc3efSJulian Anastasov struct list_head t_list; /* in dest_trash */ 728276472eaSJulian Anastasov unsigned int in_rs_table:1; /* we are in rs_table */ 7291da177e4SLinus Torvalds }; 7301da177e4SLinus Torvalds 73107dcc686SSimon Horman /* The scheduler object */ 7321da177e4SLinus Torvalds struct ip_vs_scheduler { 7331da177e4SLinus Torvalds struct list_head n_list; /* d-linked list head */ 7341da177e4SLinus Torvalds char *name; /* scheduler name */ 7351da177e4SLinus Torvalds atomic_t refcnt; /* reference counter */ 7361da177e4SLinus Torvalds struct module *module; /* THIS_MODULE/NULL */ 7371da177e4SLinus Torvalds 7381da177e4SLinus Torvalds /* scheduler initializing service */ 7391da177e4SLinus Torvalds int (*init_service)(struct ip_vs_service *svc); 7401da177e4SLinus Torvalds /* scheduling service finish */ 741ed3ffc4eSJulian Anastasov void (*done_service)(struct ip_vs_service *svc); 7426b6df466SJulian Anastasov /* dest is linked */ 7436b6df466SJulian Anastasov int (*add_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest); 7446b6df466SJulian Anastasov /* dest is unlinked */ 7456b6df466SJulian Anastasov int (*del_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest); 7466b6df466SJulian Anastasov /* dest is updated */ 7476b6df466SJulian Anastasov int (*upd_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest); 7481da177e4SLinus Torvalds 7491da177e4SLinus Torvalds /* selecting a server from the given service */ 7501da177e4SLinus Torvalds struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc, 751bba54de5SJulian Anastasov const struct sk_buff *skb, 752bba54de5SJulian Anastasov struct ip_vs_iphdr *iph); 7531da177e4SLinus Torvalds }; 7541da177e4SLinus Torvalds 75585999283SSimon Horman /* The persistence engine object */ 75685999283SSimon Horman struct ip_vs_pe { 75785999283SSimon Horman struct list_head n_list; /* d-linked list head */ 75885999283SSimon Horman char *name; /* scheduler name */ 75985999283SSimon Horman atomic_t refcnt; /* reference counter */ 76085999283SSimon Horman struct module *module; /* THIS_MODULE/NULL */ 76185999283SSimon Horman 76285999283SSimon Horman /* get the connection template, if any */ 76385999283SSimon Horman int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb); 76485999283SSimon Horman bool (*ct_match)(const struct ip_vs_conn_param *p, 76585999283SSimon Horman struct ip_vs_conn *ct); 76685999283SSimon Horman u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval, 76785999283SSimon Horman bool inverse); 768a3c918acSSimon Horman int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf); 76985999283SSimon Horman }; 7701da177e4SLinus Torvalds 77107dcc686SSimon Horman /* The application module object (a.k.a. app incarnation) */ 772fd2c3ef7SEric Dumazet struct ip_vs_app { 7731da177e4SLinus Torvalds struct list_head a_list; /* member in app list */ 7741da177e4SLinus Torvalds int type; /* IP_VS_APP_TYPE_xxx */ 7751da177e4SLinus Torvalds char *name; /* application module name */ 7761da177e4SLinus Torvalds __u16 protocol; 7771da177e4SLinus Torvalds struct module *module; /* THIS_MODULE/NULL */ 7781da177e4SLinus Torvalds struct list_head incs_list; /* list of incarnations */ 7791da177e4SLinus Torvalds 7801da177e4SLinus Torvalds /* members for application incarnations */ 7811da177e4SLinus Torvalds struct list_head p_list; /* member in proto app list */ 7821da177e4SLinus Torvalds struct ip_vs_app *app; /* its real application */ 783014d730dSAl Viro __be16 port; /* port number in net order */ 7841da177e4SLinus Torvalds atomic_t usecnt; /* usage counter */ 785363c97d7SJulian Anastasov struct rcu_head rcu_head; 7861da177e4SLinus Torvalds 78707dcc686SSimon Horman /* output hook: Process packet in inout direction, diff set for TCP. 7888b27b10fSJulian Anastasov * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok, 7898b27b10fSJulian Anastasov * 2=Mangled but checksum was not updated 7908b27b10fSJulian Anastasov */ 7911da177e4SLinus Torvalds int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *, 7923db05feaSHerbert Xu struct sk_buff *, int *diff); 7931da177e4SLinus Torvalds 79407dcc686SSimon Horman /* input hook: Process packet in outin direction, diff set for TCP. 7958b27b10fSJulian Anastasov * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok, 7968b27b10fSJulian Anastasov * 2=Mangled but checksum was not updated 7978b27b10fSJulian Anastasov */ 7981da177e4SLinus Torvalds int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *, 7993db05feaSHerbert Xu struct sk_buff *, int *diff); 8001da177e4SLinus Torvalds 8011da177e4SLinus Torvalds /* ip_vs_app initializer */ 8021da177e4SLinus Torvalds int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *); 8031da177e4SLinus Torvalds 8041da177e4SLinus Torvalds /* ip_vs_app finish */ 8051da177e4SLinus Torvalds int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *); 8061da177e4SLinus Torvalds 8071da177e4SLinus Torvalds 8081da177e4SLinus Torvalds /* not used now */ 8091da177e4SLinus Torvalds int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *, 8101da177e4SLinus Torvalds struct ip_vs_protocol *); 8111da177e4SLinus Torvalds 8121da177e4SLinus Torvalds void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *); 8131da177e4SLinus Torvalds 8141da177e4SLinus Torvalds int * timeout_table; 8151da177e4SLinus Torvalds int * timeouts; 8161da177e4SLinus Torvalds int timeouts_size; 8171da177e4SLinus Torvalds 8181da177e4SLinus Torvalds int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app, 8191da177e4SLinus Torvalds int *verdict, struct ip_vs_conn **cpp); 8201da177e4SLinus Torvalds 8211da177e4SLinus Torvalds struct ip_vs_conn * 8221da177e4SLinus Torvalds (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app, 823d4383f04SJesper Dangaard Brouer const struct iphdr *iph, int inverse); 8241da177e4SLinus Torvalds 8251da177e4SLinus Torvalds struct ip_vs_conn * 8261da177e4SLinus Torvalds (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app, 827d4383f04SJesper Dangaard Brouer const struct iphdr *iph, int inverse); 8281da177e4SLinus Torvalds 8291da177e4SLinus Torvalds int (*state_transition)(struct ip_vs_conn *cp, int direction, 8301da177e4SLinus Torvalds const struct sk_buff *skb, 8311da177e4SLinus Torvalds struct ip_vs_app *app); 8321da177e4SLinus Torvalds 8331da177e4SLinus Torvalds void (*timeout_change)(struct ip_vs_app *app, int flags); 8341da177e4SLinus Torvalds }; 8351da177e4SLinus Torvalds 836f73181c8SPablo Neira Ayuso struct ipvs_master_sync_state { 837f73181c8SPablo Neira Ayuso struct list_head sync_queue; 838f73181c8SPablo Neira Ayuso struct ip_vs_sync_buff *sync_buff; 83907995674SZhang Yanfei unsigned long sync_queue_len; 840f73181c8SPablo Neira Ayuso unsigned int sync_queue_delay; 841f73181c8SPablo Neira Ayuso struct task_struct *master_thread; 842f73181c8SPablo Neira Ayuso struct delayed_work master_wakeup_work; 843f73181c8SPablo Neira Ayuso struct netns_ipvs *ipvs; 844f73181c8SPablo Neira Ayuso }; 845f73181c8SPablo Neira Ayuso 846578bc3efSJulian Anastasov /* How much time to keep dests in trash */ 847578bc3efSJulian Anastasov #define IP_VS_DEST_TRASH_PERIOD (120 * HZ) 848578bc3efSJulian Anastasov 849*e4ff6751SJulian Anastasov struct ipvs_sync_daemon_cfg { 850*e4ff6751SJulian Anastasov int syncid; 851*e4ff6751SJulian Anastasov u16 sync_maxlen; 852*e4ff6751SJulian Anastasov /* multicast interface name */ 853*e4ff6751SJulian Anastasov char mcast_ifn[IP_VS_IFNAME_MAXLEN]; 854*e4ff6751SJulian Anastasov }; 855*e4ff6751SJulian Anastasov 8562553d064SJulian Anastasov /* IPVS in network namespace */ 8572553d064SJulian Anastasov struct netns_ipvs { 8582553d064SJulian Anastasov int gen; /* Generation */ 8597a4f0761SHans Schillstrom int enable; /* enable like nf_hooks do */ 86007dcc686SSimon Horman /* Hash table: for real service lookups */ 8612553d064SJulian Anastasov #define IP_VS_RTAB_BITS 4 8622553d064SJulian Anastasov #define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS) 8632553d064SJulian Anastasov #define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1) 8642553d064SJulian Anastasov 865276472eaSJulian Anastasov struct hlist_head rs_table[IP_VS_RTAB_SIZE]; 8662553d064SJulian Anastasov /* ip_vs_app */ 8672553d064SJulian Anastasov struct list_head app_list; 8682553d064SJulian Anastasov /* ip_vs_proto */ 8692553d064SJulian Anastasov #define IP_VS_PROTO_TAB_SIZE 32 /* must be power of 2 */ 8702553d064SJulian Anastasov struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE]; 8712553d064SJulian Anastasov /* ip_vs_proto_tcp */ 8722553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_TCP 8732553d064SJulian Anastasov #define TCP_APP_TAB_BITS 4 8742553d064SJulian Anastasov #define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS) 8752553d064SJulian Anastasov #define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1) 8762553d064SJulian Anastasov struct list_head tcp_apps[TCP_APP_TAB_SIZE]; 8772553d064SJulian Anastasov #endif 8782553d064SJulian Anastasov /* ip_vs_proto_udp */ 8792553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_UDP 8802553d064SJulian Anastasov #define UDP_APP_TAB_BITS 4 8812553d064SJulian Anastasov #define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS) 8822553d064SJulian Anastasov #define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1) 8832553d064SJulian Anastasov struct list_head udp_apps[UDP_APP_TAB_SIZE]; 8842553d064SJulian Anastasov #endif 8852553d064SJulian Anastasov /* ip_vs_proto_sctp */ 8862553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_SCTP 8872553d064SJulian Anastasov #define SCTP_APP_TAB_BITS 4 8882553d064SJulian Anastasov #define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS) 8892553d064SJulian Anastasov #define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1) 8902553d064SJulian Anastasov /* Hash table for SCTP application incarnations */ 8912553d064SJulian Anastasov struct list_head sctp_apps[SCTP_APP_TAB_SIZE]; 8922553d064SJulian Anastasov #endif 8932553d064SJulian Anastasov /* ip_vs_conn */ 8942553d064SJulian Anastasov atomic_t conn_count; /* connection counter */ 8952553d064SJulian Anastasov 8962553d064SJulian Anastasov /* ip_vs_ctl */ 8972a0751afSJulian Anastasov struct ip_vs_stats tot_stats; /* Statistics & est. */ 8982553d064SJulian Anastasov 8992553d064SJulian Anastasov int num_services; /* no of virtual services */ 900f2247fbdSSimon Horman 9012553d064SJulian Anastasov /* Trash for destinations */ 9022553d064SJulian Anastasov struct list_head dest_trash; 903578bc3efSJulian Anastasov spinlock_t dest_trash_lock; 904578bc3efSJulian Anastasov struct timer_list dest_trash_timer; /* expiration timer */ 9052553d064SJulian Anastasov /* Service counters */ 9062553d064SJulian Anastasov atomic_t ftpsvc_counter; 9072553d064SJulian Anastasov atomic_t nullsvc_counter; 9082553d064SJulian Anastasov 909f2247fbdSSimon Horman #ifdef CONFIG_SYSCTL 910f2247fbdSSimon Horman /* 1/rate drop and drop-entry variables */ 911f2247fbdSSimon Horman struct delayed_work defense_work; /* Work handler */ 912f2247fbdSSimon Horman int drop_rate; 913f2247fbdSSimon Horman int drop_counter; 914f2247fbdSSimon Horman atomic_t dropentry; 915f2247fbdSSimon Horman /* locks in ctl.c */ 916f2247fbdSSimon Horman spinlock_t dropentry_lock; /* drop entry handling */ 917f2247fbdSSimon Horman spinlock_t droppacket_lock; /* drop packet handling */ 918f2247fbdSSimon Horman spinlock_t securetcp_lock; /* state and timeout tables */ 919f2247fbdSSimon Horman 9202553d064SJulian Anastasov /* sys-ctl struct */ 9212553d064SJulian Anastasov struct ctl_table_header *sysctl_hdr; 9222553d064SJulian Anastasov struct ctl_table *sysctl_tbl; 923f2247fbdSSimon Horman #endif 924f2247fbdSSimon Horman 9252553d064SJulian Anastasov /* sysctl variables */ 9262553d064SJulian Anastasov int sysctl_amemthresh; 9272553d064SJulian Anastasov int sysctl_am_droprate; 9282553d064SJulian Anastasov int sysctl_drop_entry; 9292553d064SJulian Anastasov int sysctl_drop_packet; 9302553d064SJulian Anastasov int sysctl_secure_tcp; 9312553d064SJulian Anastasov #ifdef CONFIG_IP_VS_NFCT 9322553d064SJulian Anastasov int sysctl_conntrack; 9332553d064SJulian Anastasov #endif 9342553d064SJulian Anastasov int sysctl_snat_reroute; 9352553d064SJulian Anastasov int sysctl_sync_ver; 936f73181c8SPablo Neira Ayuso int sysctl_sync_ports; 9374d0c875dSJulian Anastasov int sysctl_sync_persist_mode; 93807995674SZhang Yanfei unsigned long sysctl_sync_qlen_max; 9391c003b15SPablo Neira Ayuso int sysctl_sync_sock_size; 9402553d064SJulian Anastasov int sysctl_cache_bypass; 9412553d064SJulian Anastasov int sysctl_expire_nodest_conn; 942c6c96c18SAlexander Frolkin int sysctl_sloppy_tcp; 943c6c96c18SAlexander Frolkin int sysctl_sloppy_sctp; 9442553d064SJulian Anastasov int sysctl_expire_quiescent_template; 9452553d064SJulian Anastasov int sysctl_sync_threshold[2]; 946749c42b6SJulian Anastasov unsigned int sysctl_sync_refresh_period; 947749c42b6SJulian Anastasov int sysctl_sync_retries; 9482553d064SJulian Anastasov int sysctl_nat_icmp_send; 9493654e611SJulian Anastasov int sysctl_pmtu_disc; 9500c12582fSJulian Anastasov int sysctl_backup_only; 951d752c364SMarcelo Ricardo Leitner int sysctl_conn_reuse_mode; 9522553d064SJulian Anastasov 9532553d064SJulian Anastasov /* ip_vs_lblc */ 9542553d064SJulian Anastasov int sysctl_lblc_expiration; 9552553d064SJulian Anastasov struct ctl_table_header *lblc_ctl_header; 9562553d064SJulian Anastasov struct ctl_table *lblc_ctl_table; 9572553d064SJulian Anastasov /* ip_vs_lblcr */ 9582553d064SJulian Anastasov int sysctl_lblcr_expiration; 9592553d064SJulian Anastasov struct ctl_table_header *lblcr_ctl_header; 9602553d064SJulian Anastasov struct ctl_table *lblcr_ctl_table; 9612553d064SJulian Anastasov /* ip_vs_est */ 9622553d064SJulian Anastasov struct list_head est_list; /* estimator list */ 9632553d064SJulian Anastasov spinlock_t est_lock; 9642553d064SJulian Anastasov struct timer_list est_timer; /* Estimation timer */ 9652553d064SJulian Anastasov /* ip_vs_sync */ 9662553d064SJulian Anastasov spinlock_t sync_lock; 967f73181c8SPablo Neira Ayuso struct ipvs_master_sync_state *ms; 9682553d064SJulian Anastasov spinlock_t sync_buff_lock; 969f73181c8SPablo Neira Ayuso struct task_struct **backup_threads; 970f73181c8SPablo Neira Ayuso int threads_mask; 9712553d064SJulian Anastasov volatile int sync_state; 972ae1d48b2SHans Schillstrom struct mutex sync_mutex; 973*e4ff6751SJulian Anastasov struct ipvs_sync_daemon_cfg mcfg; /* Master Configuration */ 974*e4ff6751SJulian Anastasov struct ipvs_sync_daemon_cfg bcfg; /* Backup Configuration */ 9752553d064SJulian Anastasov /* net name space ptr */ 9762553d064SJulian Anastasov struct net *net; /* Needed by timer routines */ 97707dcc686SSimon Horman /* Number of heterogeneous destinations, needed becaus heterogeneous 97807dcc686SSimon Horman * are not supported when synchronization is enabled. 97907dcc686SSimon Horman */ 980391f503dSAlex Gartrell unsigned int mixed_address_family_dests; 9812553d064SJulian Anastasov }; 9821da177e4SLinus Torvalds 98359e0350eSSimon Horman #define DEFAULT_SYNC_THRESHOLD 3 98459e0350eSSimon Horman #define DEFAULT_SYNC_PERIOD 50 9857532e8d4SSimon Horman #define DEFAULT_SYNC_VER 1 986c6c96c18SAlexander Frolkin #define DEFAULT_SLOPPY_TCP 0 987c6c96c18SAlexander Frolkin #define DEFAULT_SLOPPY_SCTP 0 988749c42b6SJulian Anastasov #define DEFAULT_SYNC_REFRESH_PERIOD (0U * HZ) 989749c42b6SJulian Anastasov #define DEFAULT_SYNC_RETRIES 0 9901c003b15SPablo Neira Ayuso #define IPVS_SYNC_WAKEUP_RATE 8 9911c003b15SPablo Neira Ayuso #define IPVS_SYNC_QLEN_MAX (IPVS_SYNC_WAKEUP_RATE * 4) 9921c003b15SPablo Neira Ayuso #define IPVS_SYNC_SEND_DELAY (HZ / 50) 9931c003b15SPablo Neira Ayuso #define IPVS_SYNC_CHECK_PERIOD HZ 994749c42b6SJulian Anastasov #define IPVS_SYNC_FLUSH_TIME (HZ * 2) 995f73181c8SPablo Neira Ayuso #define IPVS_SYNC_PORTS_MAX (1 << 6) 99659e0350eSSimon Horman 99759e0350eSSimon Horman #ifdef CONFIG_SYSCTL 99859e0350eSSimon Horman 99959e0350eSSimon Horman static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs) 100059e0350eSSimon Horman { 100159e0350eSSimon Horman return ipvs->sysctl_sync_threshold[0]; 100259e0350eSSimon Horman } 100359e0350eSSimon Horman 100459e0350eSSimon Horman static inline int sysctl_sync_period(struct netns_ipvs *ipvs) 100559e0350eSSimon Horman { 1006749c42b6SJulian Anastasov return ACCESS_ONCE(ipvs->sysctl_sync_threshold[1]); 1007749c42b6SJulian Anastasov } 1008749c42b6SJulian Anastasov 1009749c42b6SJulian Anastasov static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs) 1010749c42b6SJulian Anastasov { 1011749c42b6SJulian Anastasov return ACCESS_ONCE(ipvs->sysctl_sync_refresh_period); 1012749c42b6SJulian Anastasov } 1013749c42b6SJulian Anastasov 1014749c42b6SJulian Anastasov static inline int sysctl_sync_retries(struct netns_ipvs *ipvs) 1015749c42b6SJulian Anastasov { 1016749c42b6SJulian Anastasov return ipvs->sysctl_sync_retries; 101759e0350eSSimon Horman } 101859e0350eSSimon Horman 10197532e8d4SSimon Horman static inline int sysctl_sync_ver(struct netns_ipvs *ipvs) 10207532e8d4SSimon Horman { 10217532e8d4SSimon Horman return ipvs->sysctl_sync_ver; 10227532e8d4SSimon Horman } 10237532e8d4SSimon Horman 1024c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs) 1025c6c96c18SAlexander Frolkin { 1026c6c96c18SAlexander Frolkin return ipvs->sysctl_sloppy_tcp; 1027c6c96c18SAlexander Frolkin } 1028c6c96c18SAlexander Frolkin 1029c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs) 1030c6c96c18SAlexander Frolkin { 1031c6c96c18SAlexander Frolkin return ipvs->sysctl_sloppy_sctp; 1032c6c96c18SAlexander Frolkin } 1033c6c96c18SAlexander Frolkin 1034f73181c8SPablo Neira Ayuso static inline int sysctl_sync_ports(struct netns_ipvs *ipvs) 1035f73181c8SPablo Neira Ayuso { 1036f73181c8SPablo Neira Ayuso return ACCESS_ONCE(ipvs->sysctl_sync_ports); 1037f73181c8SPablo Neira Ayuso } 1038f73181c8SPablo Neira Ayuso 10394d0c875dSJulian Anastasov static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs) 10404d0c875dSJulian Anastasov { 10414d0c875dSJulian Anastasov return ipvs->sysctl_sync_persist_mode; 10424d0c875dSJulian Anastasov } 10434d0c875dSJulian Anastasov 104407995674SZhang Yanfei static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs) 10451c003b15SPablo Neira Ayuso { 10461c003b15SPablo Neira Ayuso return ipvs->sysctl_sync_qlen_max; 10471c003b15SPablo Neira Ayuso } 10481c003b15SPablo Neira Ayuso 10491c003b15SPablo Neira Ayuso static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs) 10501c003b15SPablo Neira Ayuso { 10511c003b15SPablo Neira Ayuso return ipvs->sysctl_sync_sock_size; 10521c003b15SPablo Neira Ayuso } 10531c003b15SPablo Neira Ayuso 10543654e611SJulian Anastasov static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs) 10553654e611SJulian Anastasov { 10563654e611SJulian Anastasov return ipvs->sysctl_pmtu_disc; 10573654e611SJulian Anastasov } 10583654e611SJulian Anastasov 10590c12582fSJulian Anastasov static inline int sysctl_backup_only(struct netns_ipvs *ipvs) 10600c12582fSJulian Anastasov { 10610c12582fSJulian Anastasov return ipvs->sync_state & IP_VS_STATE_BACKUP && 10620c12582fSJulian Anastasov ipvs->sysctl_backup_only; 10630c12582fSJulian Anastasov } 10640c12582fSJulian Anastasov 1065d752c364SMarcelo Ricardo Leitner static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs) 1066d752c364SMarcelo Ricardo Leitner { 1067d752c364SMarcelo Ricardo Leitner return ipvs->sysctl_conn_reuse_mode; 1068d752c364SMarcelo Ricardo Leitner } 1069d752c364SMarcelo Ricardo Leitner 107059e0350eSSimon Horman #else 107159e0350eSSimon Horman 107259e0350eSSimon Horman static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs) 107359e0350eSSimon Horman { 107459e0350eSSimon Horman return DEFAULT_SYNC_THRESHOLD; 107559e0350eSSimon Horman } 107659e0350eSSimon Horman 107759e0350eSSimon Horman static inline int sysctl_sync_period(struct netns_ipvs *ipvs) 107859e0350eSSimon Horman { 107959e0350eSSimon Horman return DEFAULT_SYNC_PERIOD; 108059e0350eSSimon Horman } 108159e0350eSSimon Horman 1082749c42b6SJulian Anastasov static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs) 1083749c42b6SJulian Anastasov { 1084749c42b6SJulian Anastasov return DEFAULT_SYNC_REFRESH_PERIOD; 1085749c42b6SJulian Anastasov } 1086749c42b6SJulian Anastasov 1087749c42b6SJulian Anastasov static inline int sysctl_sync_retries(struct netns_ipvs *ipvs) 1088749c42b6SJulian Anastasov { 1089749c42b6SJulian Anastasov return DEFAULT_SYNC_RETRIES & 3; 1090749c42b6SJulian Anastasov } 1091749c42b6SJulian Anastasov 10927532e8d4SSimon Horman static inline int sysctl_sync_ver(struct netns_ipvs *ipvs) 10937532e8d4SSimon Horman { 10947532e8d4SSimon Horman return DEFAULT_SYNC_VER; 10957532e8d4SSimon Horman } 10967532e8d4SSimon Horman 1097c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs) 1098c6c96c18SAlexander Frolkin { 1099c6c96c18SAlexander Frolkin return DEFAULT_SLOPPY_TCP; 1100c6c96c18SAlexander Frolkin } 1101c6c96c18SAlexander Frolkin 1102c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs) 1103c6c96c18SAlexander Frolkin { 1104c6c96c18SAlexander Frolkin return DEFAULT_SLOPPY_SCTP; 1105c6c96c18SAlexander Frolkin } 1106c6c96c18SAlexander Frolkin 1107f73181c8SPablo Neira Ayuso static inline int sysctl_sync_ports(struct netns_ipvs *ipvs) 1108f73181c8SPablo Neira Ayuso { 1109f73181c8SPablo Neira Ayuso return 1; 1110f73181c8SPablo Neira Ayuso } 1111f73181c8SPablo Neira Ayuso 11124d0c875dSJulian Anastasov static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs) 11134d0c875dSJulian Anastasov { 11144d0c875dSJulian Anastasov return 0; 11154d0c875dSJulian Anastasov } 11164d0c875dSJulian Anastasov 111707995674SZhang Yanfei static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs) 11181c003b15SPablo Neira Ayuso { 11191c003b15SPablo Neira Ayuso return IPVS_SYNC_QLEN_MAX; 11201c003b15SPablo Neira Ayuso } 11211c003b15SPablo Neira Ayuso 11221c003b15SPablo Neira Ayuso static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs) 11231c003b15SPablo Neira Ayuso { 11241c003b15SPablo Neira Ayuso return 0; 11251c003b15SPablo Neira Ayuso } 11261c003b15SPablo Neira Ayuso 11273654e611SJulian Anastasov static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs) 11283654e611SJulian Anastasov { 11293654e611SJulian Anastasov return 1; 11303654e611SJulian Anastasov } 11313654e611SJulian Anastasov 11320c12582fSJulian Anastasov static inline int sysctl_backup_only(struct netns_ipvs *ipvs) 11330c12582fSJulian Anastasov { 11340c12582fSJulian Anastasov return 0; 11350c12582fSJulian Anastasov } 11360c12582fSJulian Anastasov 1137d752c364SMarcelo Ricardo Leitner static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs) 1138d752c364SMarcelo Ricardo Leitner { 1139d752c364SMarcelo Ricardo Leitner return 1; 1140d752c364SMarcelo Ricardo Leitner } 1141d752c364SMarcelo Ricardo Leitner 114259e0350eSSimon Horman #endif 114359e0350eSSimon Horman 114407dcc686SSimon Horman /* IPVS core functions 11451da177e4SLinus Torvalds * (from ip_vs_core.c) 11461da177e4SLinus Torvalds */ 11475c3a0fd7SJoe Perches const char *ip_vs_proto_name(unsigned int proto); 11485c3a0fd7SJoe Perches void ip_vs_init_hash_table(struct list_head *table, int rows); 1149afdd6140SSven Wegener #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t))) 11501da177e4SLinus Torvalds 11511da177e4SLinus Torvalds #define IP_VS_APP_TYPE_FTP 1 11521da177e4SLinus Torvalds 115307dcc686SSimon Horman /* ip_vs_conn handling functions 11541da177e4SLinus Torvalds * (from ip_vs_conn.c) 11551da177e4SLinus Torvalds */ 11561da177e4SLinus Torvalds enum { 11571da177e4SLinus Torvalds IP_VS_DIR_INPUT = 0, 11581da177e4SLinus Torvalds IP_VS_DIR_OUTPUT, 11591da177e4SLinus Torvalds IP_VS_DIR_INPUT_ONLY, 11601da177e4SLinus Torvalds IP_VS_DIR_LAST, 11611da177e4SLinus Torvalds }; 11621da177e4SLinus Torvalds 11636e67e586SHans Schillstrom static inline void ip_vs_conn_fill_param(struct net *net, int af, int protocol, 1164f11017ecSSimon Horman const union nf_inet_addr *caddr, 1165f11017ecSSimon Horman __be16 cport, 1166f11017ecSSimon Horman const union nf_inet_addr *vaddr, 1167f11017ecSSimon Horman __be16 vport, 1168f11017ecSSimon Horman struct ip_vs_conn_param *p) 1169f11017ecSSimon Horman { 11706e67e586SHans Schillstrom p->net = net; 1171f11017ecSSimon Horman p->af = af; 1172f11017ecSSimon Horman p->protocol = protocol; 1173f11017ecSSimon Horman p->caddr = caddr; 1174f11017ecSSimon Horman p->cport = cport; 1175f11017ecSSimon Horman p->vaddr = vaddr; 1176f11017ecSSimon Horman p->vport = vport; 117785999283SSimon Horman p->pe = NULL; 117885999283SSimon Horman p->pe_data = NULL; 1179f11017ecSSimon Horman } 118028364a59SJulius Volz 1181f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p); 1182f11017ecSSimon Horman struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p); 118328364a59SJulius Volz 11845c0d2374SSimon Horman struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb, 11855c0d2374SSimon Horman const struct ip_vs_iphdr *iph, 11865c0d2374SSimon Horman int inverse); 11875c0d2374SSimon Horman 1188f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p); 11891da177e4SLinus Torvalds 11905c0d2374SSimon Horman struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb, 11915c0d2374SSimon Horman const struct ip_vs_iphdr *iph, 11925c0d2374SSimon Horman int inverse); 11935c0d2374SSimon Horman 1194088339a5SJulian Anastasov /* Get reference to gain full access to conn. 1195088339a5SJulian Anastasov * By default, RCU read-side critical sections have access only to 1196088339a5SJulian Anastasov * conn fields and its PE data, see ip_vs_conn_rcu_free() for reference. 1197088339a5SJulian Anastasov */ 1198088339a5SJulian Anastasov static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp) 1199088339a5SJulian Anastasov { 1200088339a5SJulian Anastasov return atomic_inc_not_zero(&cp->refcnt); 1201088339a5SJulian Anastasov } 1202088339a5SJulian Anastasov 12031da177e4SLinus Torvalds /* put back the conn without restarting its timer */ 12041da177e4SLinus Torvalds static inline void __ip_vs_conn_put(struct ip_vs_conn *cp) 12051da177e4SLinus Torvalds { 12064e857c58SPeter Zijlstra smp_mb__before_atomic(); 12071da177e4SLinus Torvalds atomic_dec(&cp->refcnt); 12081da177e4SLinus Torvalds } 12095c3a0fd7SJoe Perches void ip_vs_conn_put(struct ip_vs_conn *cp); 12105c3a0fd7SJoe Perches void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport); 12111da177e4SLinus Torvalds 1212ba38528aSAlex Gartrell struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af, 1213f11017ecSSimon Horman const union nf_inet_addr *daddr, 121495c96174SEric Dumazet __be16 dport, unsigned int flags, 12150e051e68SHans Schillstrom struct ip_vs_dest *dest, __u32 fwmark); 12165c3a0fd7SJoe Perches void ip_vs_conn_expire_now(struct ip_vs_conn *cp); 12171da177e4SLinus Torvalds 12185c3a0fd7SJoe Perches const char *ip_vs_state_name(__u16 proto, int state); 12191da177e4SLinus Torvalds 12205c3a0fd7SJoe Perches void ip_vs_tcp_conn_listen(struct net *net, struct ip_vs_conn *cp); 12215c3a0fd7SJoe Perches int ip_vs_check_template(struct ip_vs_conn *ct); 12225c3a0fd7SJoe Perches void ip_vs_random_dropentry(struct net *net); 12235c3a0fd7SJoe Perches int ip_vs_conn_init(void); 12245c3a0fd7SJoe Perches void ip_vs_conn_cleanup(void); 12251da177e4SLinus Torvalds 12261da177e4SLinus Torvalds static inline void ip_vs_control_del(struct ip_vs_conn *cp) 12271da177e4SLinus Torvalds { 12281da177e4SLinus Torvalds struct ip_vs_conn *ctl_cp = cp->control; 12291da177e4SLinus Torvalds if (!ctl_cp) { 1230cfc78c5aSJulius Volz IP_VS_ERR_BUF("request control DEL for uncontrolled: " 1231cfc78c5aSJulius Volz "%s:%d to %s:%d\n", 1232cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1233cfc78c5aSJulius Volz ntohs(cp->cport), 1234cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr), 1235cfc78c5aSJulius Volz ntohs(cp->vport)); 1236cfc78c5aSJulius Volz 12371da177e4SLinus Torvalds return; 12381da177e4SLinus Torvalds } 12391da177e4SLinus Torvalds 1240cfc78c5aSJulius Volz IP_VS_DBG_BUF(7, "DELeting control for: " 1241cfc78c5aSJulius Volz "cp.dst=%s:%d ctl_cp.dst=%s:%d\n", 1242cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1243cfc78c5aSJulius Volz ntohs(cp->cport), 1244cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr), 1245cfc78c5aSJulius Volz ntohs(ctl_cp->cport)); 12461da177e4SLinus Torvalds 12471da177e4SLinus Torvalds cp->control = NULL; 12481da177e4SLinus Torvalds if (atomic_read(&ctl_cp->n_control) == 0) { 1249cfc78c5aSJulius Volz IP_VS_ERR_BUF("BUG control DEL with n=0 : " 1250cfc78c5aSJulius Volz "%s:%d to %s:%d\n", 1251cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1252cfc78c5aSJulius Volz ntohs(cp->cport), 1253cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr), 1254cfc78c5aSJulius Volz ntohs(cp->vport)); 1255cfc78c5aSJulius Volz 12561da177e4SLinus Torvalds return; 12571da177e4SLinus Torvalds } 12581da177e4SLinus Torvalds atomic_dec(&ctl_cp->n_control); 12591da177e4SLinus Torvalds } 12601da177e4SLinus Torvalds 12611da177e4SLinus Torvalds static inline void 12621da177e4SLinus Torvalds ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp) 12631da177e4SLinus Torvalds { 12641da177e4SLinus Torvalds if (cp->control) { 1265cfc78c5aSJulius Volz IP_VS_ERR_BUF("request control ADD for already controlled: " 1266cfc78c5aSJulius Volz "%s:%d to %s:%d\n", 1267cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1268cfc78c5aSJulius Volz ntohs(cp->cport), 1269cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr), 1270cfc78c5aSJulius Volz ntohs(cp->vport)); 1271cfc78c5aSJulius Volz 12721da177e4SLinus Torvalds ip_vs_control_del(cp); 12731da177e4SLinus Torvalds } 12741da177e4SLinus Torvalds 1275cfc78c5aSJulius Volz IP_VS_DBG_BUF(7, "ADDing control for: " 1276cfc78c5aSJulius Volz "cp.dst=%s:%d ctl_cp.dst=%s:%d\n", 1277cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1278cfc78c5aSJulius Volz ntohs(cp->cport), 1279cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr), 1280cfc78c5aSJulius Volz ntohs(ctl_cp->cport)); 12811da177e4SLinus Torvalds 12821da177e4SLinus Torvalds cp->control = ctl_cp; 12831da177e4SLinus Torvalds atomic_inc(&ctl_cp->n_control); 12841da177e4SLinus Torvalds } 12851da177e4SLinus Torvalds 128607dcc686SSimon Horman /* IPVS netns init & cleanup functions */ 12875c3a0fd7SJoe Perches int ip_vs_estimator_net_init(struct net *net); 12885c3a0fd7SJoe Perches int ip_vs_control_net_init(struct net *net); 12895c3a0fd7SJoe Perches int ip_vs_protocol_net_init(struct net *net); 12905c3a0fd7SJoe Perches int ip_vs_app_net_init(struct net *net); 12915c3a0fd7SJoe Perches int ip_vs_conn_net_init(struct net *net); 12925c3a0fd7SJoe Perches int ip_vs_sync_net_init(struct net *net); 12935c3a0fd7SJoe Perches void ip_vs_conn_net_cleanup(struct net *net); 12945c3a0fd7SJoe Perches void ip_vs_app_net_cleanup(struct net *net); 12955c3a0fd7SJoe Perches void ip_vs_protocol_net_cleanup(struct net *net); 12965c3a0fd7SJoe Perches void ip_vs_control_net_cleanup(struct net *net); 12975c3a0fd7SJoe Perches void ip_vs_estimator_net_cleanup(struct net *net); 12985c3a0fd7SJoe Perches void ip_vs_sync_net_cleanup(struct net *net); 12995c3a0fd7SJoe Perches void ip_vs_service_net_cleanup(struct net *net); 13001da177e4SLinus Torvalds 130107dcc686SSimon Horman /* IPVS application functions 13021da177e4SLinus Torvalds * (from ip_vs_app.c) 13031da177e4SLinus Torvalds */ 13041da177e4SLinus Torvalds #define IP_VS_APP_MAX_PORTS 8 13055c3a0fd7SJoe Perches struct ip_vs_app *register_ip_vs_app(struct net *net, struct ip_vs_app *app); 13065c3a0fd7SJoe Perches void unregister_ip_vs_app(struct net *net, struct ip_vs_app *app); 13075c3a0fd7SJoe Perches int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp); 13085c3a0fd7SJoe Perches void ip_vs_unbind_app(struct ip_vs_conn *cp); 13095c3a0fd7SJoe Perches int register_ip_vs_app_inc(struct net *net, struct ip_vs_app *app, __u16 proto, 13105c3a0fd7SJoe Perches __u16 port); 13115c3a0fd7SJoe Perches int ip_vs_app_inc_get(struct ip_vs_app *inc); 13125c3a0fd7SJoe Perches void ip_vs_app_inc_put(struct ip_vs_app *inc); 13131da177e4SLinus Torvalds 13145c3a0fd7SJoe Perches int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb); 13155c3a0fd7SJoe Perches int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb); 13161da177e4SLinus Torvalds 13178be67a66SSimon Horman int register_ip_vs_pe(struct ip_vs_pe *pe); 13188be67a66SSimon Horman int unregister_ip_vs_pe(struct ip_vs_pe *pe); 1319e9e5eee8SSimon Horman struct ip_vs_pe *ip_vs_pe_getbyname(const char *name); 1320fe5e7a1eSHans Schillstrom struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name); 1321e9e5eee8SSimon Horman 132207dcc686SSimon Horman /* Use a #define to avoid all of module.h just for these trivial ops */ 132369e7dae4SPaul Gortmaker #define ip_vs_pe_get(pe) \ 132469e7dae4SPaul Gortmaker if (pe && pe->module) \ 1325e9e5eee8SSimon Horman __module_get(pe->module); 1326e9e5eee8SSimon Horman 132769e7dae4SPaul Gortmaker #define ip_vs_pe_put(pe) \ 132869e7dae4SPaul Gortmaker if (pe && pe->module) \ 1329e9e5eee8SSimon Horman module_put(pe->module); 13301da177e4SLinus Torvalds 133107dcc686SSimon Horman /* IPVS protocol functions (from ip_vs_proto.c) */ 13325c3a0fd7SJoe Perches int ip_vs_protocol_init(void); 13335c3a0fd7SJoe Perches void ip_vs_protocol_cleanup(void); 13345c3a0fd7SJoe Perches void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags); 13355c3a0fd7SJoe Perches int *ip_vs_create_timeout_table(int *table, int size); 13365c3a0fd7SJoe Perches int ip_vs_set_state_timeout(int *table, int num, const char *const *names, 133736cbd3dcSJan Engelhardt const char *name, int to); 13385c3a0fd7SJoe Perches void ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp, 13395c3a0fd7SJoe Perches const struct sk_buff *skb, int offset, 13405c3a0fd7SJoe Perches const char *msg); 13411da177e4SLinus Torvalds 13421da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_tcp; 13431da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_udp; 13441da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_icmp; 13451da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_esp; 13461da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_ah; 13472906f66aSVenkata Mohan Reddy extern struct ip_vs_protocol ip_vs_protocol_sctp; 13481da177e4SLinus Torvalds 134907dcc686SSimon Horman /* Registering/unregistering scheduler functions 13501da177e4SLinus Torvalds * (from ip_vs_sched.c) 13511da177e4SLinus Torvalds */ 13525c3a0fd7SJoe Perches int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); 13535c3a0fd7SJoe Perches int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); 13545c3a0fd7SJoe Perches int ip_vs_bind_scheduler(struct ip_vs_service *svc, 13551da177e4SLinus Torvalds struct ip_vs_scheduler *scheduler); 13565c3a0fd7SJoe Perches void ip_vs_unbind_scheduler(struct ip_vs_service *svc, 1357ceec4c38SJulian Anastasov struct ip_vs_scheduler *sched); 13585c3a0fd7SJoe Perches struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name); 13595c3a0fd7SJoe Perches void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler); 13605c3a0fd7SJoe Perches struct ip_vs_conn * 1361190ecd27SJulian Anastasov ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb, 1362d4383f04SJesper Dangaard Brouer struct ip_vs_proto_data *pd, int *ignored, 1363d4383f04SJesper Dangaard Brouer struct ip_vs_iphdr *iph); 13645c3a0fd7SJoe Perches int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb, 1365d4383f04SJesper Dangaard Brouer struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph); 13661da177e4SLinus Torvalds 13675c3a0fd7SJoe Perches void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg); 136841ac51eeSPatrick Schaaf 136907dcc686SSimon Horman /* IPVS control data and functions (from ip_vs_ctl.c) */ 13701da177e4SLinus Torvalds extern struct ip_vs_stats ip_vs_stats; 1371b880c1f0SHans Schillstrom extern int sysctl_ip_vs_sync_ver; 13721da177e4SLinus Torvalds 13735c3a0fd7SJoe Perches struct ip_vs_service * 1374ceec4c38SJulian Anastasov ip_vs_service_find(struct net *net, int af, __u32 fwmark, __u16 protocol, 13753c2e0505SJulius Volz const union nf_inet_addr *vaddr, __be16 vport); 13761da177e4SLinus Torvalds 13775c3a0fd7SJoe Perches bool ip_vs_has_real_service(struct net *net, int af, __u16 protocol, 13787937df15SJulius Volz const union nf_inet_addr *daddr, __be16 dport); 13797937df15SJulius Volz 13805c3a0fd7SJoe Perches int ip_vs_use_count_inc(void); 13815c3a0fd7SJoe Perches void ip_vs_use_count_dec(void); 13825c3a0fd7SJoe Perches int ip_vs_register_nl_ioctl(void); 13835c3a0fd7SJoe Perches void ip_vs_unregister_nl_ioctl(void); 13845c3a0fd7SJoe Perches int ip_vs_control_init(void); 13855c3a0fd7SJoe Perches void ip_vs_control_cleanup(void); 13865c3a0fd7SJoe Perches struct ip_vs_dest * 1387655eef10SAlex Gartrell ip_vs_find_dest(struct net *net, int svc_af, int dest_af, 1388655eef10SAlex Gartrell const union nf_inet_addr *daddr, __be16 dport, 1389655eef10SAlex Gartrell const union nf_inet_addr *vaddr, __be16 vport, 139052793dbeSJulian Anastasov __u16 protocol, __u32 fwmark, __u32 flags); 13915c3a0fd7SJoe Perches void ip_vs_try_bind_dest(struct ip_vs_conn *cp); 13921da177e4SLinus Torvalds 1393fca9c20aSJulian Anastasov static inline void ip_vs_dest_hold(struct ip_vs_dest *dest) 1394fca9c20aSJulian Anastasov { 1395fca9c20aSJulian Anastasov atomic_inc(&dest->refcnt); 1396fca9c20aSJulian Anastasov } 1397fca9c20aSJulian Anastasov 1398fca9c20aSJulian Anastasov static inline void ip_vs_dest_put(struct ip_vs_dest *dest) 1399fca9c20aSJulian Anastasov { 14004e857c58SPeter Zijlstra smp_mb__before_atomic(); 1401fca9c20aSJulian Anastasov atomic_dec(&dest->refcnt); 1402fca9c20aSJulian Anastasov } 14031da177e4SLinus Torvalds 14049e4e948aSJulian Anastasov static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest) 14059e4e948aSJulian Anastasov { 14069e4e948aSJulian Anastasov if (atomic_dec_return(&dest->refcnt) < 0) 14079e4e948aSJulian Anastasov kfree(dest); 14089e4e948aSJulian Anastasov } 14099e4e948aSJulian Anastasov 141007dcc686SSimon Horman /* IPVS sync daemon data and function prototypes 14111da177e4SLinus Torvalds * (from ip_vs_sync.c) 14121da177e4SLinus Torvalds */ 1413*e4ff6751SJulian Anastasov int start_sync_thread(struct net *net, struct ipvs_sync_daemon_cfg *cfg, 1414*e4ff6751SJulian Anastasov int state); 14155c3a0fd7SJoe Perches int stop_sync_thread(struct net *net, int state); 14165c3a0fd7SJoe Perches void ip_vs_sync_conn(struct net *net, struct ip_vs_conn *cp, int pkts); 14171da177e4SLinus Torvalds 141807dcc686SSimon Horman /* IPVS rate estimator prototypes (from ip_vs_est.c) */ 14195c3a0fd7SJoe Perches void ip_vs_start_estimator(struct net *net, struct ip_vs_stats *stats); 14205c3a0fd7SJoe Perches void ip_vs_stop_estimator(struct net *net, struct ip_vs_stats *stats); 14215c3a0fd7SJoe Perches void ip_vs_zero_estimator(struct ip_vs_stats *stats); 1422cd67cd5eSJulian Anastasov void ip_vs_read_estimator(struct ip_vs_kstats *dst, struct ip_vs_stats *stats); 14231da177e4SLinus Torvalds 142407dcc686SSimon Horman /* Various IPVS packet transmitters (from ip_vs_xmit.c) */ 14255c3a0fd7SJoe Perches int ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1426d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14275c3a0fd7SJoe Perches int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1428d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14295c3a0fd7SJoe Perches int ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1430d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14315c3a0fd7SJoe Perches int ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 14325c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14335c3a0fd7SJoe Perches int ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 14345c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14355c3a0fd7SJoe Perches int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1436d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, int offset, 1437d4383f04SJesper Dangaard Brouer unsigned int hooknum, struct ip_vs_iphdr *iph); 14385c3a0fd7SJoe Perches void ip_vs_dest_dst_rcu_free(struct rcu_head *head); 14391da177e4SLinus Torvalds 1440b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6 14415c3a0fd7SJoe Perches int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 1442d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14435c3a0fd7SJoe Perches int ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 14445c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14455c3a0fd7SJoe Perches int ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 14465c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14475c3a0fd7SJoe Perches int ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 14485c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14495c3a0fd7SJoe Perches int ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 1450d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, int offset, 1451d4383f04SJesper Dangaard Brouer unsigned int hooknum, struct ip_vs_iphdr *iph); 1452b3cdd2a7SJulius Volz #endif 14531da177e4SLinus Torvalds 14543a1bbf18SSimon Horman #ifdef CONFIG_SYSCTL 145507dcc686SSimon Horman /* This is a simple mechanism to ignore packets when 14561da177e4SLinus Torvalds * we are loaded. Just set ip_vs_drop_rate to 'n' and 14571da177e4SLinus Torvalds * we start to drop 1/rate of the packets 14581da177e4SLinus Torvalds */ 1459a0840e2eSHans Schillstrom static inline int ip_vs_todrop(struct netns_ipvs *ipvs) 14601da177e4SLinus Torvalds { 1461a0840e2eSHans Schillstrom if (!ipvs->drop_rate) 1462a0840e2eSHans Schillstrom return 0; 1463a0840e2eSHans Schillstrom if (--ipvs->drop_counter > 0) 1464a0840e2eSHans Schillstrom return 0; 1465a0840e2eSHans Schillstrom ipvs->drop_counter = ipvs->drop_rate; 14661da177e4SLinus Torvalds return 1; 14671da177e4SLinus Torvalds } 14683a1bbf18SSimon Horman #else 14693a1bbf18SSimon Horman static inline int ip_vs_todrop(struct netns_ipvs *ipvs) { return 0; } 14703a1bbf18SSimon Horman #endif 14711da177e4SLinus Torvalds 147207dcc686SSimon Horman /* ip_vs_fwd_tag returns the forwarding tag of the connection */ 14731da177e4SLinus Torvalds #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK) 14741da177e4SLinus Torvalds 1475732db659SAdrian Bunk static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp) 14761da177e4SLinus Torvalds { 14771da177e4SLinus Torvalds char fwd; 14781da177e4SLinus Torvalds 14791da177e4SLinus Torvalds switch (IP_VS_FWD_METHOD(cp)) { 14801da177e4SLinus Torvalds case IP_VS_CONN_F_MASQ: 14811da177e4SLinus Torvalds fwd = 'M'; break; 14821da177e4SLinus Torvalds case IP_VS_CONN_F_LOCALNODE: 14831da177e4SLinus Torvalds fwd = 'L'; break; 14841da177e4SLinus Torvalds case IP_VS_CONN_F_TUNNEL: 14851da177e4SLinus Torvalds fwd = 'T'; break; 14861da177e4SLinus Torvalds case IP_VS_CONN_F_DROUTE: 14871da177e4SLinus Torvalds fwd = 'R'; break; 14881da177e4SLinus Torvalds case IP_VS_CONN_F_BYPASS: 14891da177e4SLinus Torvalds fwd = 'B'; break; 14901da177e4SLinus Torvalds default: 14911da177e4SLinus Torvalds fwd = '?'; break; 14921da177e4SLinus Torvalds } 14931da177e4SLinus Torvalds return fwd; 14941da177e4SLinus Torvalds } 14951da177e4SLinus Torvalds 14965c3a0fd7SJoe Perches void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp, 14971da177e4SLinus Torvalds struct ip_vs_conn *cp, int dir); 14981da177e4SLinus Torvalds 1499b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6 15005c3a0fd7SJoe Perches void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp, 1501b3cdd2a7SJulius Volz struct ip_vs_conn *cp, int dir); 1502b3cdd2a7SJulius Volz #endif 1503b3cdd2a7SJulius Volz 15045c3a0fd7SJoe Perches __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset); 15051da177e4SLinus Torvalds 1506f9214b26SAl Viro static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum) 15071da177e4SLinus Torvalds { 1508f9214b26SAl Viro __be32 diff[2] = { ~old, new }; 15091da177e4SLinus Torvalds 151007f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum); 1511f9214b26SAl Viro } 1512f9214b26SAl Viro 15130bbdd42bSJulius Volz #ifdef CONFIG_IP_VS_IPV6 15140bbdd42bSJulius Volz static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new, 15150bbdd42bSJulius Volz __wsum oldsum) 15160bbdd42bSJulius Volz { 15170bbdd42bSJulius Volz __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0], 15180bbdd42bSJulius Volz new[3], new[2], new[1], new[0] }; 15190bbdd42bSJulius Volz 152007f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum); 15210bbdd42bSJulius Volz } 15220bbdd42bSJulius Volz #endif 15230bbdd42bSJulius Volz 1524f9214b26SAl Viro static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum) 1525f9214b26SAl Viro { 1526f9214b26SAl Viro __be16 diff[2] = { ~old, new }; 1527f9214b26SAl Viro 152807f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum); 15291da177e4SLinus Torvalds } 15301da177e4SLinus Torvalds 153107dcc686SSimon Horman /* Forget current conntrack (unconfirmed) and attach notrack entry */ 1532cf356d69SJulian Anastasov static inline void ip_vs_notrack(struct sk_buff *skb) 1533cf356d69SJulian Anastasov { 1534cf356d69SJulian Anastasov #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 1535cf356d69SJulian Anastasov enum ip_conntrack_info ctinfo; 153606b69390SJesper Juhl struct nf_conn *ct = nf_ct_get(skb, &ctinfo); 1537cf356d69SJulian Anastasov 1538cf356d69SJulian Anastasov if (!ct || !nf_ct_is_untracked(ct)) { 15399e33ce45SLin Ming nf_conntrack_put(skb->nfct); 1540cf356d69SJulian Anastasov skb->nfct = &nf_ct_untracked_get()->ct_general; 1541cf356d69SJulian Anastasov skb->nfctinfo = IP_CT_NEW; 1542cf356d69SJulian Anastasov nf_conntrack_get(skb->nfct); 1543cf356d69SJulian Anastasov } 1544cf356d69SJulian Anastasov #endif 1545cf356d69SJulian Anastasov } 1546cf356d69SJulian Anastasov 1547f4bc17cdSJulian Anastasov #ifdef CONFIG_IP_VS_NFCT 154807dcc686SSimon Horman /* Netfilter connection tracking 1549f4bc17cdSJulian Anastasov * (from ip_vs_nfct.c) 1550f4bc17cdSJulian Anastasov */ 1551a0840e2eSHans Schillstrom static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs) 1552f4bc17cdSJulian Anastasov { 1553a4e2f5a7SSimon Horman #ifdef CONFIG_SYSCTL 1554a0840e2eSHans Schillstrom return ipvs->sysctl_conntrack; 1555a4e2f5a7SSimon Horman #else 1556a4e2f5a7SSimon Horman return 0; 1557a4e2f5a7SSimon Horman #endif 1558f4bc17cdSJulian Anastasov } 1559f4bc17cdSJulian Anastasov 15605c3a0fd7SJoe Perches void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp, 15616523ce15SJulian Anastasov int outin); 15625c3a0fd7SJoe Perches int ip_vs_confirm_conntrack(struct sk_buff *skb); 15635c3a0fd7SJoe Perches void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct, 1564f4bc17cdSJulian Anastasov struct ip_vs_conn *cp, u_int8_t proto, 1565f4bc17cdSJulian Anastasov const __be16 port, int from_rs); 15665c3a0fd7SJoe Perches void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp); 1567f4bc17cdSJulian Anastasov 1568f4bc17cdSJulian Anastasov #else 1569f4bc17cdSJulian Anastasov 1570a0840e2eSHans Schillstrom static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs) 1571f4bc17cdSJulian Anastasov { 1572f4bc17cdSJulian Anastasov return 0; 1573f4bc17cdSJulian Anastasov } 1574f4bc17cdSJulian Anastasov 1575f4bc17cdSJulian Anastasov static inline void ip_vs_update_conntrack(struct sk_buff *skb, 1576f4bc17cdSJulian Anastasov struct ip_vs_conn *cp, int outin) 1577f4bc17cdSJulian Anastasov { 1578f4bc17cdSJulian Anastasov } 1579f4bc17cdSJulian Anastasov 1580e23ebf0fSKrzysztof Wilczynski static inline int ip_vs_confirm_conntrack(struct sk_buff *skb) 1581f4bc17cdSJulian Anastasov { 1582f4bc17cdSJulian Anastasov return NF_ACCEPT; 1583f4bc17cdSJulian Anastasov } 1584f4bc17cdSJulian Anastasov 1585f4bc17cdSJulian Anastasov static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp) 1586f4bc17cdSJulian Anastasov { 1587f4bc17cdSJulian Anastasov } 158807dcc686SSimon Horman #endif /* CONFIG_IP_VS_NFCT */ 15896523ce15SJulian Anastasov 1590c16526a7SSimon Kirby static inline int 1591b552f7e3SChangli Gao ip_vs_dest_conn_overhead(struct ip_vs_dest *dest) 1592b552f7e3SChangli Gao { 159307dcc686SSimon Horman /* We think the overhead of processing active connections is 256 1594b552f7e3SChangli Gao * times higher than that of inactive connections in average. (This 1595b552f7e3SChangli Gao * 256 times might not be accurate, we will change it later) We 1596b552f7e3SChangli Gao * use the following formula to estimate the overhead now: 1597b552f7e3SChangli Gao * dest->activeconns*256 + dest->inactconns 1598b552f7e3SChangli Gao */ 1599b552f7e3SChangli Gao return (atomic_read(&dest->activeconns) << 8) + 1600b552f7e3SChangli Gao atomic_read(&dest->inactconns); 1601b552f7e3SChangli Gao } 1602b552f7e3SChangli Gao 1603bc4768ebSJulius Volz #endif /* _NET_IP_VS_H */ 1604