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 849e4ff6751SJulian Anastasov struct ipvs_sync_daemon_cfg { 850*d3328817SJulian Anastasov union nf_inet_addr mcast_group; 851e4ff6751SJulian Anastasov int syncid; 852e4ff6751SJulian Anastasov u16 sync_maxlen; 853*d3328817SJulian Anastasov u16 mcast_port; 854*d3328817SJulian Anastasov u8 mcast_af; 855*d3328817SJulian Anastasov u8 mcast_ttl; 856e4ff6751SJulian Anastasov /* multicast interface name */ 857e4ff6751SJulian Anastasov char mcast_ifn[IP_VS_IFNAME_MAXLEN]; 858e4ff6751SJulian Anastasov }; 859e4ff6751SJulian Anastasov 8602553d064SJulian Anastasov /* IPVS in network namespace */ 8612553d064SJulian Anastasov struct netns_ipvs { 8622553d064SJulian Anastasov int gen; /* Generation */ 8637a4f0761SHans Schillstrom int enable; /* enable like nf_hooks do */ 86407dcc686SSimon Horman /* Hash table: for real service lookups */ 8652553d064SJulian Anastasov #define IP_VS_RTAB_BITS 4 8662553d064SJulian Anastasov #define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS) 8672553d064SJulian Anastasov #define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1) 8682553d064SJulian Anastasov 869276472eaSJulian Anastasov struct hlist_head rs_table[IP_VS_RTAB_SIZE]; 8702553d064SJulian Anastasov /* ip_vs_app */ 8712553d064SJulian Anastasov struct list_head app_list; 8722553d064SJulian Anastasov /* ip_vs_proto */ 8732553d064SJulian Anastasov #define IP_VS_PROTO_TAB_SIZE 32 /* must be power of 2 */ 8742553d064SJulian Anastasov struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE]; 8752553d064SJulian Anastasov /* ip_vs_proto_tcp */ 8762553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_TCP 8772553d064SJulian Anastasov #define TCP_APP_TAB_BITS 4 8782553d064SJulian Anastasov #define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS) 8792553d064SJulian Anastasov #define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1) 8802553d064SJulian Anastasov struct list_head tcp_apps[TCP_APP_TAB_SIZE]; 8812553d064SJulian Anastasov #endif 8822553d064SJulian Anastasov /* ip_vs_proto_udp */ 8832553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_UDP 8842553d064SJulian Anastasov #define UDP_APP_TAB_BITS 4 8852553d064SJulian Anastasov #define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS) 8862553d064SJulian Anastasov #define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1) 8872553d064SJulian Anastasov struct list_head udp_apps[UDP_APP_TAB_SIZE]; 8882553d064SJulian Anastasov #endif 8892553d064SJulian Anastasov /* ip_vs_proto_sctp */ 8902553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_SCTP 8912553d064SJulian Anastasov #define SCTP_APP_TAB_BITS 4 8922553d064SJulian Anastasov #define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS) 8932553d064SJulian Anastasov #define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1) 8942553d064SJulian Anastasov /* Hash table for SCTP application incarnations */ 8952553d064SJulian Anastasov struct list_head sctp_apps[SCTP_APP_TAB_SIZE]; 8962553d064SJulian Anastasov #endif 8972553d064SJulian Anastasov /* ip_vs_conn */ 8982553d064SJulian Anastasov atomic_t conn_count; /* connection counter */ 8992553d064SJulian Anastasov 9002553d064SJulian Anastasov /* ip_vs_ctl */ 9012a0751afSJulian Anastasov struct ip_vs_stats tot_stats; /* Statistics & est. */ 9022553d064SJulian Anastasov 9032553d064SJulian Anastasov int num_services; /* no of virtual services */ 904f2247fbdSSimon Horman 9052553d064SJulian Anastasov /* Trash for destinations */ 9062553d064SJulian Anastasov struct list_head dest_trash; 907578bc3efSJulian Anastasov spinlock_t dest_trash_lock; 908578bc3efSJulian Anastasov struct timer_list dest_trash_timer; /* expiration timer */ 9092553d064SJulian Anastasov /* Service counters */ 9102553d064SJulian Anastasov atomic_t ftpsvc_counter; 9112553d064SJulian Anastasov atomic_t nullsvc_counter; 9122553d064SJulian Anastasov 913f2247fbdSSimon Horman #ifdef CONFIG_SYSCTL 914f2247fbdSSimon Horman /* 1/rate drop and drop-entry variables */ 915f2247fbdSSimon Horman struct delayed_work defense_work; /* Work handler */ 916f2247fbdSSimon Horman int drop_rate; 917f2247fbdSSimon Horman int drop_counter; 918f2247fbdSSimon Horman atomic_t dropentry; 919f2247fbdSSimon Horman /* locks in ctl.c */ 920f2247fbdSSimon Horman spinlock_t dropentry_lock; /* drop entry handling */ 921f2247fbdSSimon Horman spinlock_t droppacket_lock; /* drop packet handling */ 922f2247fbdSSimon Horman spinlock_t securetcp_lock; /* state and timeout tables */ 923f2247fbdSSimon Horman 9242553d064SJulian Anastasov /* sys-ctl struct */ 9252553d064SJulian Anastasov struct ctl_table_header *sysctl_hdr; 9262553d064SJulian Anastasov struct ctl_table *sysctl_tbl; 927f2247fbdSSimon Horman #endif 928f2247fbdSSimon Horman 9292553d064SJulian Anastasov /* sysctl variables */ 9302553d064SJulian Anastasov int sysctl_amemthresh; 9312553d064SJulian Anastasov int sysctl_am_droprate; 9322553d064SJulian Anastasov int sysctl_drop_entry; 9332553d064SJulian Anastasov int sysctl_drop_packet; 9342553d064SJulian Anastasov int sysctl_secure_tcp; 9352553d064SJulian Anastasov #ifdef CONFIG_IP_VS_NFCT 9362553d064SJulian Anastasov int sysctl_conntrack; 9372553d064SJulian Anastasov #endif 9382553d064SJulian Anastasov int sysctl_snat_reroute; 9392553d064SJulian Anastasov int sysctl_sync_ver; 940f73181c8SPablo Neira Ayuso int sysctl_sync_ports; 9414d0c875dSJulian Anastasov int sysctl_sync_persist_mode; 94207995674SZhang Yanfei unsigned long sysctl_sync_qlen_max; 9431c003b15SPablo Neira Ayuso int sysctl_sync_sock_size; 9442553d064SJulian Anastasov int sysctl_cache_bypass; 9452553d064SJulian Anastasov int sysctl_expire_nodest_conn; 946c6c96c18SAlexander Frolkin int sysctl_sloppy_tcp; 947c6c96c18SAlexander Frolkin int sysctl_sloppy_sctp; 9482553d064SJulian Anastasov int sysctl_expire_quiescent_template; 9492553d064SJulian Anastasov int sysctl_sync_threshold[2]; 950749c42b6SJulian Anastasov unsigned int sysctl_sync_refresh_period; 951749c42b6SJulian Anastasov int sysctl_sync_retries; 9522553d064SJulian Anastasov int sysctl_nat_icmp_send; 9533654e611SJulian Anastasov int sysctl_pmtu_disc; 9540c12582fSJulian Anastasov int sysctl_backup_only; 955d752c364SMarcelo Ricardo Leitner int sysctl_conn_reuse_mode; 9562553d064SJulian Anastasov 9572553d064SJulian Anastasov /* ip_vs_lblc */ 9582553d064SJulian Anastasov int sysctl_lblc_expiration; 9592553d064SJulian Anastasov struct ctl_table_header *lblc_ctl_header; 9602553d064SJulian Anastasov struct ctl_table *lblc_ctl_table; 9612553d064SJulian Anastasov /* ip_vs_lblcr */ 9622553d064SJulian Anastasov int sysctl_lblcr_expiration; 9632553d064SJulian Anastasov struct ctl_table_header *lblcr_ctl_header; 9642553d064SJulian Anastasov struct ctl_table *lblcr_ctl_table; 9652553d064SJulian Anastasov /* ip_vs_est */ 9662553d064SJulian Anastasov struct list_head est_list; /* estimator list */ 9672553d064SJulian Anastasov spinlock_t est_lock; 9682553d064SJulian Anastasov struct timer_list est_timer; /* Estimation timer */ 9692553d064SJulian Anastasov /* ip_vs_sync */ 9702553d064SJulian Anastasov spinlock_t sync_lock; 971f73181c8SPablo Neira Ayuso struct ipvs_master_sync_state *ms; 9722553d064SJulian Anastasov spinlock_t sync_buff_lock; 973f73181c8SPablo Neira Ayuso struct task_struct **backup_threads; 974f73181c8SPablo Neira Ayuso int threads_mask; 9752553d064SJulian Anastasov volatile int sync_state; 976ae1d48b2SHans Schillstrom struct mutex sync_mutex; 977e4ff6751SJulian Anastasov struct ipvs_sync_daemon_cfg mcfg; /* Master Configuration */ 978e4ff6751SJulian Anastasov struct ipvs_sync_daemon_cfg bcfg; /* Backup Configuration */ 9792553d064SJulian Anastasov /* net name space ptr */ 9802553d064SJulian Anastasov struct net *net; /* Needed by timer routines */ 98107dcc686SSimon Horman /* Number of heterogeneous destinations, needed becaus heterogeneous 98207dcc686SSimon Horman * are not supported when synchronization is enabled. 98307dcc686SSimon Horman */ 984391f503dSAlex Gartrell unsigned int mixed_address_family_dests; 9852553d064SJulian Anastasov }; 9861da177e4SLinus Torvalds 98759e0350eSSimon Horman #define DEFAULT_SYNC_THRESHOLD 3 98859e0350eSSimon Horman #define DEFAULT_SYNC_PERIOD 50 9897532e8d4SSimon Horman #define DEFAULT_SYNC_VER 1 990c6c96c18SAlexander Frolkin #define DEFAULT_SLOPPY_TCP 0 991c6c96c18SAlexander Frolkin #define DEFAULT_SLOPPY_SCTP 0 992749c42b6SJulian Anastasov #define DEFAULT_SYNC_REFRESH_PERIOD (0U * HZ) 993749c42b6SJulian Anastasov #define DEFAULT_SYNC_RETRIES 0 9941c003b15SPablo Neira Ayuso #define IPVS_SYNC_WAKEUP_RATE 8 9951c003b15SPablo Neira Ayuso #define IPVS_SYNC_QLEN_MAX (IPVS_SYNC_WAKEUP_RATE * 4) 9961c003b15SPablo Neira Ayuso #define IPVS_SYNC_SEND_DELAY (HZ / 50) 9971c003b15SPablo Neira Ayuso #define IPVS_SYNC_CHECK_PERIOD HZ 998749c42b6SJulian Anastasov #define IPVS_SYNC_FLUSH_TIME (HZ * 2) 999f73181c8SPablo Neira Ayuso #define IPVS_SYNC_PORTS_MAX (1 << 6) 100059e0350eSSimon Horman 100159e0350eSSimon Horman #ifdef CONFIG_SYSCTL 100259e0350eSSimon Horman 100359e0350eSSimon Horman static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs) 100459e0350eSSimon Horman { 100559e0350eSSimon Horman return ipvs->sysctl_sync_threshold[0]; 100659e0350eSSimon Horman } 100759e0350eSSimon Horman 100859e0350eSSimon Horman static inline int sysctl_sync_period(struct netns_ipvs *ipvs) 100959e0350eSSimon Horman { 1010749c42b6SJulian Anastasov return ACCESS_ONCE(ipvs->sysctl_sync_threshold[1]); 1011749c42b6SJulian Anastasov } 1012749c42b6SJulian Anastasov 1013749c42b6SJulian Anastasov static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs) 1014749c42b6SJulian Anastasov { 1015749c42b6SJulian Anastasov return ACCESS_ONCE(ipvs->sysctl_sync_refresh_period); 1016749c42b6SJulian Anastasov } 1017749c42b6SJulian Anastasov 1018749c42b6SJulian Anastasov static inline int sysctl_sync_retries(struct netns_ipvs *ipvs) 1019749c42b6SJulian Anastasov { 1020749c42b6SJulian Anastasov return ipvs->sysctl_sync_retries; 102159e0350eSSimon Horman } 102259e0350eSSimon Horman 10237532e8d4SSimon Horman static inline int sysctl_sync_ver(struct netns_ipvs *ipvs) 10247532e8d4SSimon Horman { 10257532e8d4SSimon Horman return ipvs->sysctl_sync_ver; 10267532e8d4SSimon Horman } 10277532e8d4SSimon Horman 1028c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs) 1029c6c96c18SAlexander Frolkin { 1030c6c96c18SAlexander Frolkin return ipvs->sysctl_sloppy_tcp; 1031c6c96c18SAlexander Frolkin } 1032c6c96c18SAlexander Frolkin 1033c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs) 1034c6c96c18SAlexander Frolkin { 1035c6c96c18SAlexander Frolkin return ipvs->sysctl_sloppy_sctp; 1036c6c96c18SAlexander Frolkin } 1037c6c96c18SAlexander Frolkin 1038f73181c8SPablo Neira Ayuso static inline int sysctl_sync_ports(struct netns_ipvs *ipvs) 1039f73181c8SPablo Neira Ayuso { 1040f73181c8SPablo Neira Ayuso return ACCESS_ONCE(ipvs->sysctl_sync_ports); 1041f73181c8SPablo Neira Ayuso } 1042f73181c8SPablo Neira Ayuso 10434d0c875dSJulian Anastasov static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs) 10444d0c875dSJulian Anastasov { 10454d0c875dSJulian Anastasov return ipvs->sysctl_sync_persist_mode; 10464d0c875dSJulian Anastasov } 10474d0c875dSJulian Anastasov 104807995674SZhang Yanfei static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs) 10491c003b15SPablo Neira Ayuso { 10501c003b15SPablo Neira Ayuso return ipvs->sysctl_sync_qlen_max; 10511c003b15SPablo Neira Ayuso } 10521c003b15SPablo Neira Ayuso 10531c003b15SPablo Neira Ayuso static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs) 10541c003b15SPablo Neira Ayuso { 10551c003b15SPablo Neira Ayuso return ipvs->sysctl_sync_sock_size; 10561c003b15SPablo Neira Ayuso } 10571c003b15SPablo Neira Ayuso 10583654e611SJulian Anastasov static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs) 10593654e611SJulian Anastasov { 10603654e611SJulian Anastasov return ipvs->sysctl_pmtu_disc; 10613654e611SJulian Anastasov } 10623654e611SJulian Anastasov 10630c12582fSJulian Anastasov static inline int sysctl_backup_only(struct netns_ipvs *ipvs) 10640c12582fSJulian Anastasov { 10650c12582fSJulian Anastasov return ipvs->sync_state & IP_VS_STATE_BACKUP && 10660c12582fSJulian Anastasov ipvs->sysctl_backup_only; 10670c12582fSJulian Anastasov } 10680c12582fSJulian Anastasov 1069d752c364SMarcelo Ricardo Leitner static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs) 1070d752c364SMarcelo Ricardo Leitner { 1071d752c364SMarcelo Ricardo Leitner return ipvs->sysctl_conn_reuse_mode; 1072d752c364SMarcelo Ricardo Leitner } 1073d752c364SMarcelo Ricardo Leitner 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 114659e0350eSSimon Horman #endif 114759e0350eSSimon Horman 114807dcc686SSimon Horman /* IPVS core functions 11491da177e4SLinus Torvalds * (from ip_vs_core.c) 11501da177e4SLinus Torvalds */ 11515c3a0fd7SJoe Perches const char *ip_vs_proto_name(unsigned int proto); 11525c3a0fd7SJoe Perches void ip_vs_init_hash_table(struct list_head *table, int rows); 1153afdd6140SSven Wegener #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t))) 11541da177e4SLinus Torvalds 11551da177e4SLinus Torvalds #define IP_VS_APP_TYPE_FTP 1 11561da177e4SLinus Torvalds 115707dcc686SSimon Horman /* ip_vs_conn handling functions 11581da177e4SLinus Torvalds * (from ip_vs_conn.c) 11591da177e4SLinus Torvalds */ 11601da177e4SLinus Torvalds enum { 11611da177e4SLinus Torvalds IP_VS_DIR_INPUT = 0, 11621da177e4SLinus Torvalds IP_VS_DIR_OUTPUT, 11631da177e4SLinus Torvalds IP_VS_DIR_INPUT_ONLY, 11641da177e4SLinus Torvalds IP_VS_DIR_LAST, 11651da177e4SLinus Torvalds }; 11661da177e4SLinus Torvalds 11676e67e586SHans Schillstrom static inline void ip_vs_conn_fill_param(struct net *net, int af, int protocol, 1168f11017ecSSimon Horman const union nf_inet_addr *caddr, 1169f11017ecSSimon Horman __be16 cport, 1170f11017ecSSimon Horman const union nf_inet_addr *vaddr, 1171f11017ecSSimon Horman __be16 vport, 1172f11017ecSSimon Horman struct ip_vs_conn_param *p) 1173f11017ecSSimon Horman { 11746e67e586SHans Schillstrom p->net = net; 1175f11017ecSSimon Horman p->af = af; 1176f11017ecSSimon Horman p->protocol = protocol; 1177f11017ecSSimon Horman p->caddr = caddr; 1178f11017ecSSimon Horman p->cport = cport; 1179f11017ecSSimon Horman p->vaddr = vaddr; 1180f11017ecSSimon Horman p->vport = vport; 118185999283SSimon Horman p->pe = NULL; 118285999283SSimon Horman p->pe_data = NULL; 1183f11017ecSSimon Horman } 118428364a59SJulius Volz 1185f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p); 1186f11017ecSSimon Horman struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p); 118728364a59SJulius Volz 11885c0d2374SSimon Horman struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb, 11895c0d2374SSimon Horman const struct ip_vs_iphdr *iph, 11905c0d2374SSimon Horman int inverse); 11915c0d2374SSimon Horman 1192f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p); 11931da177e4SLinus Torvalds 11945c0d2374SSimon Horman struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb, 11955c0d2374SSimon Horman const struct ip_vs_iphdr *iph, 11965c0d2374SSimon Horman int inverse); 11975c0d2374SSimon Horman 1198088339a5SJulian Anastasov /* Get reference to gain full access to conn. 1199088339a5SJulian Anastasov * By default, RCU read-side critical sections have access only to 1200088339a5SJulian Anastasov * conn fields and its PE data, see ip_vs_conn_rcu_free() for reference. 1201088339a5SJulian Anastasov */ 1202088339a5SJulian Anastasov static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp) 1203088339a5SJulian Anastasov { 1204088339a5SJulian Anastasov return atomic_inc_not_zero(&cp->refcnt); 1205088339a5SJulian Anastasov } 1206088339a5SJulian Anastasov 12071da177e4SLinus Torvalds /* put back the conn without restarting its timer */ 12081da177e4SLinus Torvalds static inline void __ip_vs_conn_put(struct ip_vs_conn *cp) 12091da177e4SLinus Torvalds { 12104e857c58SPeter Zijlstra smp_mb__before_atomic(); 12111da177e4SLinus Torvalds atomic_dec(&cp->refcnt); 12121da177e4SLinus Torvalds } 12135c3a0fd7SJoe Perches void ip_vs_conn_put(struct ip_vs_conn *cp); 12145c3a0fd7SJoe Perches void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport); 12151da177e4SLinus Torvalds 1216ba38528aSAlex Gartrell struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af, 1217f11017ecSSimon Horman const union nf_inet_addr *daddr, 121895c96174SEric Dumazet __be16 dport, unsigned int flags, 12190e051e68SHans Schillstrom struct ip_vs_dest *dest, __u32 fwmark); 12205c3a0fd7SJoe Perches void ip_vs_conn_expire_now(struct ip_vs_conn *cp); 12211da177e4SLinus Torvalds 12225c3a0fd7SJoe Perches const char *ip_vs_state_name(__u16 proto, int state); 12231da177e4SLinus Torvalds 12245c3a0fd7SJoe Perches void ip_vs_tcp_conn_listen(struct net *net, struct ip_vs_conn *cp); 12255c3a0fd7SJoe Perches int ip_vs_check_template(struct ip_vs_conn *ct); 12265c3a0fd7SJoe Perches void ip_vs_random_dropentry(struct net *net); 12275c3a0fd7SJoe Perches int ip_vs_conn_init(void); 12285c3a0fd7SJoe Perches void ip_vs_conn_cleanup(void); 12291da177e4SLinus Torvalds 12301da177e4SLinus Torvalds static inline void ip_vs_control_del(struct ip_vs_conn *cp) 12311da177e4SLinus Torvalds { 12321da177e4SLinus Torvalds struct ip_vs_conn *ctl_cp = cp->control; 12331da177e4SLinus Torvalds if (!ctl_cp) { 1234cfc78c5aSJulius Volz IP_VS_ERR_BUF("request control DEL for uncontrolled: " 1235cfc78c5aSJulius Volz "%s:%d to %s:%d\n", 1236cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1237cfc78c5aSJulius Volz ntohs(cp->cport), 1238cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr), 1239cfc78c5aSJulius Volz ntohs(cp->vport)); 1240cfc78c5aSJulius Volz 12411da177e4SLinus Torvalds return; 12421da177e4SLinus Torvalds } 12431da177e4SLinus Torvalds 1244cfc78c5aSJulius Volz IP_VS_DBG_BUF(7, "DELeting control for: " 1245cfc78c5aSJulius Volz "cp.dst=%s:%d ctl_cp.dst=%s:%d\n", 1246cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1247cfc78c5aSJulius Volz ntohs(cp->cport), 1248cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr), 1249cfc78c5aSJulius Volz ntohs(ctl_cp->cport)); 12501da177e4SLinus Torvalds 12511da177e4SLinus Torvalds cp->control = NULL; 12521da177e4SLinus Torvalds if (atomic_read(&ctl_cp->n_control) == 0) { 1253cfc78c5aSJulius Volz IP_VS_ERR_BUF("BUG control DEL with n=0 : " 1254cfc78c5aSJulius Volz "%s:%d to %s:%d\n", 1255cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1256cfc78c5aSJulius Volz ntohs(cp->cport), 1257cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr), 1258cfc78c5aSJulius Volz ntohs(cp->vport)); 1259cfc78c5aSJulius Volz 12601da177e4SLinus Torvalds return; 12611da177e4SLinus Torvalds } 12621da177e4SLinus Torvalds atomic_dec(&ctl_cp->n_control); 12631da177e4SLinus Torvalds } 12641da177e4SLinus Torvalds 12651da177e4SLinus Torvalds static inline void 12661da177e4SLinus Torvalds ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp) 12671da177e4SLinus Torvalds { 12681da177e4SLinus Torvalds if (cp->control) { 1269cfc78c5aSJulius Volz IP_VS_ERR_BUF("request control ADD for already controlled: " 1270cfc78c5aSJulius Volz "%s:%d to %s:%d\n", 1271cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1272cfc78c5aSJulius Volz ntohs(cp->cport), 1273cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr), 1274cfc78c5aSJulius Volz ntohs(cp->vport)); 1275cfc78c5aSJulius Volz 12761da177e4SLinus Torvalds ip_vs_control_del(cp); 12771da177e4SLinus Torvalds } 12781da177e4SLinus Torvalds 1279cfc78c5aSJulius Volz IP_VS_DBG_BUF(7, "ADDing control for: " 1280cfc78c5aSJulius Volz "cp.dst=%s:%d ctl_cp.dst=%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, &ctl_cp->caddr), 1284cfc78c5aSJulius Volz ntohs(ctl_cp->cport)); 12851da177e4SLinus Torvalds 12861da177e4SLinus Torvalds cp->control = ctl_cp; 12871da177e4SLinus Torvalds atomic_inc(&ctl_cp->n_control); 12881da177e4SLinus Torvalds } 12891da177e4SLinus Torvalds 129007dcc686SSimon Horman /* IPVS netns init & cleanup functions */ 12915c3a0fd7SJoe Perches int ip_vs_estimator_net_init(struct net *net); 12925c3a0fd7SJoe Perches int ip_vs_control_net_init(struct net *net); 12935c3a0fd7SJoe Perches int ip_vs_protocol_net_init(struct net *net); 12945c3a0fd7SJoe Perches int ip_vs_app_net_init(struct net *net); 12955c3a0fd7SJoe Perches int ip_vs_conn_net_init(struct net *net); 12965c3a0fd7SJoe Perches int ip_vs_sync_net_init(struct net *net); 12975c3a0fd7SJoe Perches void ip_vs_conn_net_cleanup(struct net *net); 12985c3a0fd7SJoe Perches void ip_vs_app_net_cleanup(struct net *net); 12995c3a0fd7SJoe Perches void ip_vs_protocol_net_cleanup(struct net *net); 13005c3a0fd7SJoe Perches void ip_vs_control_net_cleanup(struct net *net); 13015c3a0fd7SJoe Perches void ip_vs_estimator_net_cleanup(struct net *net); 13025c3a0fd7SJoe Perches void ip_vs_sync_net_cleanup(struct net *net); 13035c3a0fd7SJoe Perches void ip_vs_service_net_cleanup(struct net *net); 13041da177e4SLinus Torvalds 130507dcc686SSimon Horman /* IPVS application functions 13061da177e4SLinus Torvalds * (from ip_vs_app.c) 13071da177e4SLinus Torvalds */ 13081da177e4SLinus Torvalds #define IP_VS_APP_MAX_PORTS 8 13095c3a0fd7SJoe Perches struct ip_vs_app *register_ip_vs_app(struct net *net, struct ip_vs_app *app); 13105c3a0fd7SJoe Perches void unregister_ip_vs_app(struct net *net, struct ip_vs_app *app); 13115c3a0fd7SJoe Perches int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp); 13125c3a0fd7SJoe Perches void ip_vs_unbind_app(struct ip_vs_conn *cp); 13135c3a0fd7SJoe Perches int register_ip_vs_app_inc(struct net *net, struct ip_vs_app *app, __u16 proto, 13145c3a0fd7SJoe Perches __u16 port); 13155c3a0fd7SJoe Perches int ip_vs_app_inc_get(struct ip_vs_app *inc); 13165c3a0fd7SJoe Perches void ip_vs_app_inc_put(struct ip_vs_app *inc); 13171da177e4SLinus Torvalds 13185c3a0fd7SJoe Perches int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb); 13195c3a0fd7SJoe Perches int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb); 13201da177e4SLinus Torvalds 13218be67a66SSimon Horman int register_ip_vs_pe(struct ip_vs_pe *pe); 13228be67a66SSimon Horman int unregister_ip_vs_pe(struct ip_vs_pe *pe); 1323e9e5eee8SSimon Horman struct ip_vs_pe *ip_vs_pe_getbyname(const char *name); 1324fe5e7a1eSHans Schillstrom struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name); 1325e9e5eee8SSimon Horman 132607dcc686SSimon Horman /* Use a #define to avoid all of module.h just for these trivial ops */ 132769e7dae4SPaul Gortmaker #define ip_vs_pe_get(pe) \ 132869e7dae4SPaul Gortmaker if (pe && pe->module) \ 1329e9e5eee8SSimon Horman __module_get(pe->module); 1330e9e5eee8SSimon Horman 133169e7dae4SPaul Gortmaker #define ip_vs_pe_put(pe) \ 133269e7dae4SPaul Gortmaker if (pe && pe->module) \ 1333e9e5eee8SSimon Horman module_put(pe->module); 13341da177e4SLinus Torvalds 133507dcc686SSimon Horman /* IPVS protocol functions (from ip_vs_proto.c) */ 13365c3a0fd7SJoe Perches int ip_vs_protocol_init(void); 13375c3a0fd7SJoe Perches void ip_vs_protocol_cleanup(void); 13385c3a0fd7SJoe Perches void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags); 13395c3a0fd7SJoe Perches int *ip_vs_create_timeout_table(int *table, int size); 13405c3a0fd7SJoe Perches int ip_vs_set_state_timeout(int *table, int num, const char *const *names, 134136cbd3dcSJan Engelhardt const char *name, int to); 13425c3a0fd7SJoe Perches void ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp, 13435c3a0fd7SJoe Perches const struct sk_buff *skb, int offset, 13445c3a0fd7SJoe Perches const char *msg); 13451da177e4SLinus Torvalds 13461da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_tcp; 13471da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_udp; 13481da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_icmp; 13491da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_esp; 13501da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_ah; 13512906f66aSVenkata Mohan Reddy extern struct ip_vs_protocol ip_vs_protocol_sctp; 13521da177e4SLinus Torvalds 135307dcc686SSimon Horman /* Registering/unregistering scheduler functions 13541da177e4SLinus Torvalds * (from ip_vs_sched.c) 13551da177e4SLinus Torvalds */ 13565c3a0fd7SJoe Perches int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); 13575c3a0fd7SJoe Perches int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); 13585c3a0fd7SJoe Perches int ip_vs_bind_scheduler(struct ip_vs_service *svc, 13591da177e4SLinus Torvalds struct ip_vs_scheduler *scheduler); 13605c3a0fd7SJoe Perches void ip_vs_unbind_scheduler(struct ip_vs_service *svc, 1361ceec4c38SJulian Anastasov struct ip_vs_scheduler *sched); 13625c3a0fd7SJoe Perches struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name); 13635c3a0fd7SJoe Perches void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler); 13645c3a0fd7SJoe Perches struct ip_vs_conn * 1365190ecd27SJulian Anastasov ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb, 1366d4383f04SJesper Dangaard Brouer struct ip_vs_proto_data *pd, int *ignored, 1367d4383f04SJesper Dangaard Brouer struct ip_vs_iphdr *iph); 13685c3a0fd7SJoe Perches int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb, 1369d4383f04SJesper Dangaard Brouer struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph); 13701da177e4SLinus Torvalds 13715c3a0fd7SJoe Perches void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg); 137241ac51eeSPatrick Schaaf 137307dcc686SSimon Horman /* IPVS control data and functions (from ip_vs_ctl.c) */ 13741da177e4SLinus Torvalds extern struct ip_vs_stats ip_vs_stats; 1375b880c1f0SHans Schillstrom extern int sysctl_ip_vs_sync_ver; 13761da177e4SLinus Torvalds 13775c3a0fd7SJoe Perches struct ip_vs_service * 1378ceec4c38SJulian Anastasov ip_vs_service_find(struct net *net, int af, __u32 fwmark, __u16 protocol, 13793c2e0505SJulius Volz const union nf_inet_addr *vaddr, __be16 vport); 13801da177e4SLinus Torvalds 13815c3a0fd7SJoe Perches bool ip_vs_has_real_service(struct net *net, int af, __u16 protocol, 13827937df15SJulius Volz const union nf_inet_addr *daddr, __be16 dport); 13837937df15SJulius Volz 13845c3a0fd7SJoe Perches int ip_vs_use_count_inc(void); 13855c3a0fd7SJoe Perches void ip_vs_use_count_dec(void); 13865c3a0fd7SJoe Perches int ip_vs_register_nl_ioctl(void); 13875c3a0fd7SJoe Perches void ip_vs_unregister_nl_ioctl(void); 13885c3a0fd7SJoe Perches int ip_vs_control_init(void); 13895c3a0fd7SJoe Perches void ip_vs_control_cleanup(void); 13905c3a0fd7SJoe Perches struct ip_vs_dest * 1391655eef10SAlex Gartrell ip_vs_find_dest(struct net *net, int svc_af, int dest_af, 1392655eef10SAlex Gartrell const union nf_inet_addr *daddr, __be16 dport, 1393655eef10SAlex Gartrell const union nf_inet_addr *vaddr, __be16 vport, 139452793dbeSJulian Anastasov __u16 protocol, __u32 fwmark, __u32 flags); 13955c3a0fd7SJoe Perches void ip_vs_try_bind_dest(struct ip_vs_conn *cp); 13961da177e4SLinus Torvalds 1397fca9c20aSJulian Anastasov static inline void ip_vs_dest_hold(struct ip_vs_dest *dest) 1398fca9c20aSJulian Anastasov { 1399fca9c20aSJulian Anastasov atomic_inc(&dest->refcnt); 1400fca9c20aSJulian Anastasov } 1401fca9c20aSJulian Anastasov 1402fca9c20aSJulian Anastasov static inline void ip_vs_dest_put(struct ip_vs_dest *dest) 1403fca9c20aSJulian Anastasov { 14044e857c58SPeter Zijlstra smp_mb__before_atomic(); 1405fca9c20aSJulian Anastasov atomic_dec(&dest->refcnt); 1406fca9c20aSJulian Anastasov } 14071da177e4SLinus Torvalds 14089e4e948aSJulian Anastasov static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest) 14099e4e948aSJulian Anastasov { 14109e4e948aSJulian Anastasov if (atomic_dec_return(&dest->refcnt) < 0) 14119e4e948aSJulian Anastasov kfree(dest); 14129e4e948aSJulian Anastasov } 14139e4e948aSJulian Anastasov 141407dcc686SSimon Horman /* IPVS sync daemon data and function prototypes 14151da177e4SLinus Torvalds * (from ip_vs_sync.c) 14161da177e4SLinus Torvalds */ 1417e4ff6751SJulian Anastasov int start_sync_thread(struct net *net, struct ipvs_sync_daemon_cfg *cfg, 1418e4ff6751SJulian Anastasov int state); 14195c3a0fd7SJoe Perches int stop_sync_thread(struct net *net, int state); 14205c3a0fd7SJoe Perches void ip_vs_sync_conn(struct net *net, struct ip_vs_conn *cp, int pkts); 14211da177e4SLinus Torvalds 142207dcc686SSimon Horman /* IPVS rate estimator prototypes (from ip_vs_est.c) */ 14235c3a0fd7SJoe Perches void ip_vs_start_estimator(struct net *net, struct ip_vs_stats *stats); 14245c3a0fd7SJoe Perches void ip_vs_stop_estimator(struct net *net, struct ip_vs_stats *stats); 14255c3a0fd7SJoe Perches void ip_vs_zero_estimator(struct ip_vs_stats *stats); 1426cd67cd5eSJulian Anastasov void ip_vs_read_estimator(struct ip_vs_kstats *dst, struct ip_vs_stats *stats); 14271da177e4SLinus Torvalds 142807dcc686SSimon Horman /* Various IPVS packet transmitters (from ip_vs_xmit.c) */ 14295c3a0fd7SJoe Perches int ip_vs_null_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_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1432d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14335c3a0fd7SJoe Perches int ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1434d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14355c3a0fd7SJoe Perches int ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 14365c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14375c3a0fd7SJoe Perches int ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 14385c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14395c3a0fd7SJoe Perches int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1440d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, int offset, 1441d4383f04SJesper Dangaard Brouer unsigned int hooknum, struct ip_vs_iphdr *iph); 14425c3a0fd7SJoe Perches void ip_vs_dest_dst_rcu_free(struct rcu_head *head); 14431da177e4SLinus Torvalds 1444b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6 14455c3a0fd7SJoe Perches int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 1446d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14475c3a0fd7SJoe Perches int ip_vs_nat_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_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 14505c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14515c3a0fd7SJoe Perches int ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 14525c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14535c3a0fd7SJoe Perches int ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 1454d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, int offset, 1455d4383f04SJesper Dangaard Brouer unsigned int hooknum, struct ip_vs_iphdr *iph); 1456b3cdd2a7SJulius Volz #endif 14571da177e4SLinus Torvalds 14583a1bbf18SSimon Horman #ifdef CONFIG_SYSCTL 145907dcc686SSimon Horman /* This is a simple mechanism to ignore packets when 14601da177e4SLinus Torvalds * we are loaded. Just set ip_vs_drop_rate to 'n' and 14611da177e4SLinus Torvalds * we start to drop 1/rate of the packets 14621da177e4SLinus Torvalds */ 1463a0840e2eSHans Schillstrom static inline int ip_vs_todrop(struct netns_ipvs *ipvs) 14641da177e4SLinus Torvalds { 1465a0840e2eSHans Schillstrom if (!ipvs->drop_rate) 1466a0840e2eSHans Schillstrom return 0; 1467a0840e2eSHans Schillstrom if (--ipvs->drop_counter > 0) 1468a0840e2eSHans Schillstrom return 0; 1469a0840e2eSHans Schillstrom ipvs->drop_counter = ipvs->drop_rate; 14701da177e4SLinus Torvalds return 1; 14711da177e4SLinus Torvalds } 14723a1bbf18SSimon Horman #else 14733a1bbf18SSimon Horman static inline int ip_vs_todrop(struct netns_ipvs *ipvs) { return 0; } 14743a1bbf18SSimon Horman #endif 14751da177e4SLinus Torvalds 147607dcc686SSimon Horman /* ip_vs_fwd_tag returns the forwarding tag of the connection */ 14771da177e4SLinus Torvalds #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK) 14781da177e4SLinus Torvalds 1479732db659SAdrian Bunk static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp) 14801da177e4SLinus Torvalds { 14811da177e4SLinus Torvalds char fwd; 14821da177e4SLinus Torvalds 14831da177e4SLinus Torvalds switch (IP_VS_FWD_METHOD(cp)) { 14841da177e4SLinus Torvalds case IP_VS_CONN_F_MASQ: 14851da177e4SLinus Torvalds fwd = 'M'; break; 14861da177e4SLinus Torvalds case IP_VS_CONN_F_LOCALNODE: 14871da177e4SLinus Torvalds fwd = 'L'; break; 14881da177e4SLinus Torvalds case IP_VS_CONN_F_TUNNEL: 14891da177e4SLinus Torvalds fwd = 'T'; break; 14901da177e4SLinus Torvalds case IP_VS_CONN_F_DROUTE: 14911da177e4SLinus Torvalds fwd = 'R'; break; 14921da177e4SLinus Torvalds case IP_VS_CONN_F_BYPASS: 14931da177e4SLinus Torvalds fwd = 'B'; break; 14941da177e4SLinus Torvalds default: 14951da177e4SLinus Torvalds fwd = '?'; break; 14961da177e4SLinus Torvalds } 14971da177e4SLinus Torvalds return fwd; 14981da177e4SLinus Torvalds } 14991da177e4SLinus Torvalds 15005c3a0fd7SJoe Perches void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp, 15011da177e4SLinus Torvalds struct ip_vs_conn *cp, int dir); 15021da177e4SLinus Torvalds 1503b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6 15045c3a0fd7SJoe Perches void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp, 1505b3cdd2a7SJulius Volz struct ip_vs_conn *cp, int dir); 1506b3cdd2a7SJulius Volz #endif 1507b3cdd2a7SJulius Volz 15085c3a0fd7SJoe Perches __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset); 15091da177e4SLinus Torvalds 1510f9214b26SAl Viro static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum) 15111da177e4SLinus Torvalds { 1512f9214b26SAl Viro __be32 diff[2] = { ~old, new }; 15131da177e4SLinus Torvalds 151407f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum); 1515f9214b26SAl Viro } 1516f9214b26SAl Viro 15170bbdd42bSJulius Volz #ifdef CONFIG_IP_VS_IPV6 15180bbdd42bSJulius Volz static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new, 15190bbdd42bSJulius Volz __wsum oldsum) 15200bbdd42bSJulius Volz { 15210bbdd42bSJulius Volz __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0], 15220bbdd42bSJulius Volz new[3], new[2], new[1], new[0] }; 15230bbdd42bSJulius Volz 152407f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum); 15250bbdd42bSJulius Volz } 15260bbdd42bSJulius Volz #endif 15270bbdd42bSJulius Volz 1528f9214b26SAl Viro static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum) 1529f9214b26SAl Viro { 1530f9214b26SAl Viro __be16 diff[2] = { ~old, new }; 1531f9214b26SAl Viro 153207f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum); 15331da177e4SLinus Torvalds } 15341da177e4SLinus Torvalds 153507dcc686SSimon Horman /* Forget current conntrack (unconfirmed) and attach notrack entry */ 1536cf356d69SJulian Anastasov static inline void ip_vs_notrack(struct sk_buff *skb) 1537cf356d69SJulian Anastasov { 1538cf356d69SJulian Anastasov #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 1539cf356d69SJulian Anastasov enum ip_conntrack_info ctinfo; 154006b69390SJesper Juhl struct nf_conn *ct = nf_ct_get(skb, &ctinfo); 1541cf356d69SJulian Anastasov 1542cf356d69SJulian Anastasov if (!ct || !nf_ct_is_untracked(ct)) { 15439e33ce45SLin Ming nf_conntrack_put(skb->nfct); 1544cf356d69SJulian Anastasov skb->nfct = &nf_ct_untracked_get()->ct_general; 1545cf356d69SJulian Anastasov skb->nfctinfo = IP_CT_NEW; 1546cf356d69SJulian Anastasov nf_conntrack_get(skb->nfct); 1547cf356d69SJulian Anastasov } 1548cf356d69SJulian Anastasov #endif 1549cf356d69SJulian Anastasov } 1550cf356d69SJulian Anastasov 1551f4bc17cdSJulian Anastasov #ifdef CONFIG_IP_VS_NFCT 155207dcc686SSimon Horman /* Netfilter connection tracking 1553f4bc17cdSJulian Anastasov * (from ip_vs_nfct.c) 1554f4bc17cdSJulian Anastasov */ 1555a0840e2eSHans Schillstrom static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs) 1556f4bc17cdSJulian Anastasov { 1557a4e2f5a7SSimon Horman #ifdef CONFIG_SYSCTL 1558a0840e2eSHans Schillstrom return ipvs->sysctl_conntrack; 1559a4e2f5a7SSimon Horman #else 1560a4e2f5a7SSimon Horman return 0; 1561a4e2f5a7SSimon Horman #endif 1562f4bc17cdSJulian Anastasov } 1563f4bc17cdSJulian Anastasov 15645c3a0fd7SJoe Perches void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp, 15656523ce15SJulian Anastasov int outin); 15665c3a0fd7SJoe Perches int ip_vs_confirm_conntrack(struct sk_buff *skb); 15675c3a0fd7SJoe Perches void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct, 1568f4bc17cdSJulian Anastasov struct ip_vs_conn *cp, u_int8_t proto, 1569f4bc17cdSJulian Anastasov const __be16 port, int from_rs); 15705c3a0fd7SJoe Perches void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp); 1571f4bc17cdSJulian Anastasov 1572f4bc17cdSJulian Anastasov #else 1573f4bc17cdSJulian Anastasov 1574a0840e2eSHans Schillstrom static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs) 1575f4bc17cdSJulian Anastasov { 1576f4bc17cdSJulian Anastasov return 0; 1577f4bc17cdSJulian Anastasov } 1578f4bc17cdSJulian Anastasov 1579f4bc17cdSJulian Anastasov static inline void ip_vs_update_conntrack(struct sk_buff *skb, 1580f4bc17cdSJulian Anastasov struct ip_vs_conn *cp, int outin) 1581f4bc17cdSJulian Anastasov { 1582f4bc17cdSJulian Anastasov } 1583f4bc17cdSJulian Anastasov 1584e23ebf0fSKrzysztof Wilczynski static inline int ip_vs_confirm_conntrack(struct sk_buff *skb) 1585f4bc17cdSJulian Anastasov { 1586f4bc17cdSJulian Anastasov return NF_ACCEPT; 1587f4bc17cdSJulian Anastasov } 1588f4bc17cdSJulian Anastasov 1589f4bc17cdSJulian Anastasov static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp) 1590f4bc17cdSJulian Anastasov { 1591f4bc17cdSJulian Anastasov } 159207dcc686SSimon Horman #endif /* CONFIG_IP_VS_NFCT */ 15936523ce15SJulian Anastasov 1594c16526a7SSimon Kirby static inline int 1595b552f7e3SChangli Gao ip_vs_dest_conn_overhead(struct ip_vs_dest *dest) 1596b552f7e3SChangli Gao { 159707dcc686SSimon Horman /* We think the overhead of processing active connections is 256 1598b552f7e3SChangli Gao * times higher than that of inactive connections in average. (This 1599b552f7e3SChangli Gao * 256 times might not be accurate, we will change it later) We 1600b552f7e3SChangli Gao * use the following formula to estimate the overhead now: 1601b552f7e3SChangli Gao * dest->activeconns*256 + dest->inactconns 1602b552f7e3SChangli Gao */ 1603b552f7e3SChangli Gao return (atomic_read(&dest->activeconns) << 8) + 1604b552f7e3SChangli Gao atomic_read(&dest->inactconns); 1605b552f7e3SChangli Gao } 1606b552f7e3SChangli Gao 1607bc4768ebSJulius Volz #endif /* _NET_IP_VS_H */ 1608