1*07dcc686SSimon 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 32*07dcc686SSimon 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 } 37*07dcc686SSimon Horman 38*07dcc686SSimon 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 */ 50fc723250SHans Schillstrom if (likely(skb->dev && skb->dev->nd_net)) 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__); 56fc723250SHans Schillstrom if (likely(skb->sk && skb->sk->sk_net)) 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 */ 74fc723250SHans Schillstrom if (likely(skb->sk && skb->sk->sk_net)) 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__); 78fc723250SHans Schillstrom if (likely(skb->dev && skb->dev->nd_net)) 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 } 90*07dcc686SSimon Horman 91*07dcc686SSimon 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 108*07dcc686SSimon 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 304*07dcc686SSimon 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 308*07dcc686SSimon 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 324*07dcc686SSimon 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 330*07dcc686SSimon 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 336*07dcc686SSimon 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 355*07dcc686SSimon 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 363*07dcc686SSimon Horman * before last resized pkt */ 3641da177e4SLinus Torvalds }; 3651da177e4SLinus Torvalds 366*07dcc686SSimon Horman /* counters per cpu */ 367b17fc996SHans Schillstrom struct ip_vs_counters { 368b17fc996SHans Schillstrom __u32 conns; /* connections scheduled */ 369b17fc996SHans Schillstrom __u32 inpkts; /* incoming packets */ 370b17fc996SHans Schillstrom __u32 outpkts; /* outgoing packets */ 371b17fc996SHans Schillstrom __u64 inbytes; /* incoming bytes */ 372b17fc996SHans Schillstrom __u64 outbytes; /* outgoing bytes */ 373b17fc996SHans Schillstrom }; 374*07dcc686SSimon Horman /* Stats per cpu */ 375b17fc996SHans Schillstrom struct ip_vs_cpu_stats { 376b17fc996SHans Schillstrom struct ip_vs_counters ustats; 377b17fc996SHans Schillstrom struct u64_stats_sync syncp; 378b17fc996SHans Schillstrom }; 3791da177e4SLinus Torvalds 380*07dcc686SSimon 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; 3863a14a313SSven Wegener u32 last_conns; 3873a14a313SSven Wegener u32 last_inpkts; 3883a14a313SSven Wegener u32 last_outpkts; 3893a14a313SSven Wegener 3903a14a313SSven Wegener u32 cps; 3913a14a313SSven Wegener u32 inpps; 3923a14a313SSven Wegener u32 outpps; 3933a14a313SSven Wegener u32 inbps; 3943a14a313SSven Wegener u32 outbps; 3953a14a313SSven Wegener }; 3963a14a313SSven Wegener 397fd2c3ef7SEric Dumazet struct ip_vs_stats { 398e9c0ce23SSven Wegener struct ip_vs_stats_user ustats; /* statistics */ 399e9c0ce23SSven Wegener struct ip_vs_estimator est; /* estimator */ 400b962abdcSJulian Anastasov struct ip_vs_cpu_stats __percpu *cpustats; /* per cpu counters */ 4011da177e4SLinus Torvalds spinlock_t lock; /* spin lock */ 40255a3d4e1SJulian Anastasov struct ip_vs_stats_user ustats0; /* reset values */ 4031da177e4SLinus Torvalds }; 4041da177e4SLinus Torvalds 40514c85021SArnaldo Carvalho de Melo struct dst_entry; 40614c85021SArnaldo Carvalho de Melo struct iphdr; 4071da177e4SLinus Torvalds struct ip_vs_conn; 4081da177e4SLinus Torvalds struct ip_vs_app; 40914c85021SArnaldo Carvalho de Melo struct sk_buff; 410252c6410SHans Schillstrom struct ip_vs_proto_data; 4111da177e4SLinus Torvalds 4121da177e4SLinus Torvalds struct ip_vs_protocol { 4131da177e4SLinus Torvalds struct ip_vs_protocol *next; 4141da177e4SLinus Torvalds char *name; 4152ad17defSJulian Anastasov u16 protocol; 4162ad17defSJulian Anastasov u16 num_states; 4171da177e4SLinus Torvalds int dont_defrag; 4181da177e4SLinus Torvalds 4191da177e4SLinus Torvalds void (*init)(struct ip_vs_protocol *pp); 4201da177e4SLinus Torvalds 4211da177e4SLinus Torvalds void (*exit)(struct ip_vs_protocol *pp); 4221da177e4SLinus Torvalds 423582b8e3eSHans Schillstrom int (*init_netns)(struct net *net, struct ip_vs_proto_data *pd); 424252c6410SHans Schillstrom 425252c6410SHans Schillstrom void (*exit_netns)(struct net *net, struct ip_vs_proto_data *pd); 426252c6410SHans Schillstrom 42751ef348bSJulius Volz int (*conn_schedule)(int af, struct sk_buff *skb, 4289330419dSHans Schillstrom struct ip_vs_proto_data *pd, 429d4383f04SJesper Dangaard Brouer int *verdict, struct ip_vs_conn **cpp, 430d4383f04SJesper Dangaard Brouer struct ip_vs_iphdr *iph); 4311da177e4SLinus Torvalds 4321da177e4SLinus Torvalds struct ip_vs_conn * 43351ef348bSJulius Volz (*conn_in_get)(int af, 43451ef348bSJulius Volz const struct sk_buff *skb, 43551ef348bSJulius Volz const struct ip_vs_iphdr *iph, 4361da177e4SLinus Torvalds int inverse); 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvalds struct ip_vs_conn * 43951ef348bSJulius Volz (*conn_out_get)(int af, 44051ef348bSJulius Volz const struct sk_buff *skb, 44151ef348bSJulius Volz const struct ip_vs_iphdr *iph, 4421da177e4SLinus Torvalds int inverse); 4431da177e4SLinus Torvalds 444d4383f04SJesper Dangaard Brouer int (*snat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp, 445d4383f04SJesper Dangaard Brouer struct ip_vs_conn *cp, struct ip_vs_iphdr *iph); 4461da177e4SLinus Torvalds 447d4383f04SJesper Dangaard Brouer int (*dnat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp, 448d4383f04SJesper Dangaard Brouer struct ip_vs_conn *cp, struct ip_vs_iphdr *iph); 4491da177e4SLinus Torvalds 45051ef348bSJulius Volz int (*csum_check)(int af, struct sk_buff *skb, 45151ef348bSJulius Volz struct ip_vs_protocol *pp); 4521da177e4SLinus Torvalds 4531da177e4SLinus Torvalds const char *(*state_name)(int state); 4541da177e4SLinus Torvalds 4554a516f11SSimon Horman void (*state_transition)(struct ip_vs_conn *cp, int direction, 4561da177e4SLinus Torvalds const struct sk_buff *skb, 4579330419dSHans Schillstrom struct ip_vs_proto_data *pd); 4581da177e4SLinus Torvalds 459ab8a5e84SHans Schillstrom int (*register_app)(struct net *net, struct ip_vs_app *inc); 4601da177e4SLinus Torvalds 461ab8a5e84SHans Schillstrom void (*unregister_app)(struct net *net, struct ip_vs_app *inc); 4621da177e4SLinus Torvalds 4631da177e4SLinus Torvalds int (*app_conn_bind)(struct ip_vs_conn *cp); 4641da177e4SLinus Torvalds 4650d79641aSJulian Anastasov void (*debug_packet)(int af, struct ip_vs_protocol *pp, 4661da177e4SLinus Torvalds const struct sk_buff *skb, 4671da177e4SLinus Torvalds int offset, 4681da177e4SLinus Torvalds const char *msg); 4691da177e4SLinus Torvalds 4709330419dSHans Schillstrom void (*timeout_change)(struct ip_vs_proto_data *pd, int flags); 4711da177e4SLinus Torvalds }; 4721da177e4SLinus Torvalds 473*07dcc686SSimon Horman /* protocol data per netns */ 474252c6410SHans Schillstrom struct ip_vs_proto_data { 475252c6410SHans Schillstrom struct ip_vs_proto_data *next; 476252c6410SHans Schillstrom struct ip_vs_protocol *pp; 477252c6410SHans Schillstrom int *timeout_table; /* protocol timeout table */ 478252c6410SHans Schillstrom atomic_t appcnt; /* counter of proto app incs. */ 479252c6410SHans Schillstrom struct tcp_states_t *tcp_state_table; 480252c6410SHans Schillstrom }; 481252c6410SHans Schillstrom 4825c3a0fd7SJoe Perches struct ip_vs_protocol *ip_vs_proto_get(unsigned short proto); 4835c3a0fd7SJoe Perches struct ip_vs_proto_data *ip_vs_proto_data_get(struct net *net, 484252c6410SHans Schillstrom unsigned short proto); 4851da177e4SLinus Torvalds 486f11017ecSSimon Horman struct ip_vs_conn_param { 4876e67e586SHans Schillstrom struct net *net; 488f11017ecSSimon Horman const union nf_inet_addr *caddr; 489f11017ecSSimon Horman const union nf_inet_addr *vaddr; 490f11017ecSSimon Horman __be16 cport; 491f11017ecSSimon Horman __be16 vport; 492f11017ecSSimon Horman __u16 protocol; 493f11017ecSSimon Horman u16 af; 49485999283SSimon Horman 49585999283SSimon Horman const struct ip_vs_pe *pe; 49685999283SSimon Horman char *pe_data; 49785999283SSimon Horman __u8 pe_data_len; 498f11017ecSSimon Horman }; 499f11017ecSSimon Horman 500*07dcc686SSimon Horman /* IP_VS structure allocated for each dynamically scheduled connection */ 5011da177e4SLinus Torvalds struct ip_vs_conn { 502731109e7SChangli Gao struct hlist_node c_list; /* hashed list heads */ 5031da177e4SLinus Torvalds /* Protocol, addresses and port numbers */ 5046e67e586SHans Schillstrom __be16 cport; 5056e67e586SHans Schillstrom __be16 dport; 5061845ed0bSJulian Anastasov __be16 vport; 5071845ed0bSJulian Anastasov u16 af; /* address family */ 508e7ade46aSJulius Volz union nf_inet_addr caddr; /* client address */ 509e7ade46aSJulius Volz union nf_inet_addr vaddr; /* virtual address */ 510e7ade46aSJulius Volz union nf_inet_addr daddr; /* destination address */ 5113575792eSJulian Anastasov volatile __u32 flags; /* status flags */ 5121da177e4SLinus Torvalds __u16 protocol; /* Which protocol (TCP/UDP) */ 513ba38528aSAlex Gartrell __u16 daf; /* Address family of the dest */ 5141845ed0bSJulian Anastasov #ifdef CONFIG_NET_NS 5151845ed0bSJulian Anastasov struct net *net; /* Name space */ 5161845ed0bSJulian Anastasov #endif 5171da177e4SLinus Torvalds 5181da177e4SLinus Torvalds /* counter and timer */ 5191da177e4SLinus Torvalds atomic_t refcnt; /* reference count */ 5201da177e4SLinus Torvalds struct timer_list timer; /* Expiration timer */ 5211da177e4SLinus Torvalds volatile unsigned long timeout; /* timeout */ 5221da177e4SLinus Torvalds 5231da177e4SLinus Torvalds /* Flags and state transition */ 5241da177e4SLinus Torvalds spinlock_t lock; /* lock for state transition */ 5251da177e4SLinus Torvalds volatile __u16 state; /* state info */ 526efac5276SRumen G. Bogdanovski volatile __u16 old_state; /* old state, to be used for 527efac5276SRumen G. Bogdanovski * state transition triggerd 528efac5276SRumen G. Bogdanovski * synchronization 529efac5276SRumen G. Bogdanovski */ 5301845ed0bSJulian Anastasov __u32 fwmark; /* Fire wall mark from skb */ 531749c42b6SJulian Anastasov unsigned long sync_endtime; /* jiffies + sent_retries */ 5321da177e4SLinus Torvalds 5331da177e4SLinus Torvalds /* Control members */ 5341da177e4SLinus Torvalds struct ip_vs_conn *control; /* Master control connection */ 5351da177e4SLinus Torvalds atomic_t n_control; /* Number of controlled ones */ 5361da177e4SLinus Torvalds struct ip_vs_dest *dest; /* real server */ 5371da177e4SLinus Torvalds atomic_t in_pkts; /* incoming packet counter */ 5381da177e4SLinus Torvalds 539*07dcc686SSimon Horman /* Packet transmitter for different forwarding methods. If it 540*07dcc686SSimon Horman * mangles the packet, it must return NF_DROP or better NF_STOLEN, 541*07dcc686SSimon Horman * otherwise this must be changed to a sk_buff **. 542*07dcc686SSimon Horman * NF_ACCEPT can be returned when destination is local. 5431da177e4SLinus Torvalds */ 5441da177e4SLinus Torvalds int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp, 545d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 5461da177e4SLinus Torvalds 5471da177e4SLinus Torvalds /* Note: we can group the following members into a structure, 548*07dcc686SSimon Horman * in order to save more space, and the following members are 549*07dcc686SSimon Horman * only used in VS/NAT anyway 550*07dcc686SSimon Horman */ 5511da177e4SLinus Torvalds struct ip_vs_app *app; /* bound ip_vs_app object */ 5521da177e4SLinus Torvalds void *app_data; /* Application private data */ 5531da177e4SLinus Torvalds struct ip_vs_seq in_seq; /* incoming seq. struct */ 5541da177e4SLinus Torvalds struct ip_vs_seq out_seq; /* outgoing seq. struct */ 55585999283SSimon Horman 556e9e5eee8SSimon Horman const struct ip_vs_pe *pe; 55785999283SSimon Horman char *pe_data; 55885999283SSimon Horman __u8 pe_data_len; 559088339a5SJulian Anastasov 560088339a5SJulian Anastasov struct rcu_head rcu_head; 5611da177e4SLinus Torvalds }; 5621da177e4SLinus Torvalds 563*07dcc686SSimon Horman /* To save some memory in conn table when name space is disabled. */ 5646e67e586SHans Schillstrom static inline struct net *ip_vs_conn_net(const struct ip_vs_conn *cp) 5656e67e586SHans Schillstrom { 5666e67e586SHans Schillstrom #ifdef CONFIG_NET_NS 5676e67e586SHans Schillstrom return cp->net; 5686e67e586SHans Schillstrom #else 5696e67e586SHans Schillstrom return &init_net; 5706e67e586SHans Schillstrom #endif 5716e67e586SHans Schillstrom } 572*07dcc686SSimon Horman 5736e67e586SHans Schillstrom static inline void ip_vs_conn_net_set(struct ip_vs_conn *cp, struct net *net) 5746e67e586SHans Schillstrom { 5756e67e586SHans Schillstrom #ifdef CONFIG_NET_NS 5766e67e586SHans Schillstrom cp->net = net; 5776e67e586SHans Schillstrom #endif 5786e67e586SHans Schillstrom } 5796e67e586SHans Schillstrom 5806e67e586SHans Schillstrom static inline int ip_vs_conn_net_eq(const struct ip_vs_conn *cp, 5816e67e586SHans Schillstrom struct net *net) 5826e67e586SHans Schillstrom { 5836e67e586SHans Schillstrom #ifdef CONFIG_NET_NS 5846e67e586SHans Schillstrom return cp->net == net; 5856e67e586SHans Schillstrom #else 5866e67e586SHans Schillstrom return 1; 5876e67e586SHans Schillstrom #endif 5886e67e586SHans Schillstrom } 5891da177e4SLinus Torvalds 590*07dcc686SSimon Horman /* Extended internal versions of struct ip_vs_service_user and ip_vs_dest_user 591*07dcc686SSimon Horman * for IPv6 support. 592c860c6b1SJulius Volz * 593c860c6b1SJulius Volz * We need these to conveniently pass around service and destination 594c860c6b1SJulius Volz * options, but unfortunately, we also need to keep the old definitions to 595c860c6b1SJulius Volz * maintain userspace backwards compatibility for the setsockopt interface. 596c860c6b1SJulius Volz */ 597c860c6b1SJulius Volz struct ip_vs_service_user_kern { 598c860c6b1SJulius Volz /* virtual service addresses */ 599c860c6b1SJulius Volz u16 af; 600c860c6b1SJulius Volz u16 protocol; 601c860c6b1SJulius Volz union nf_inet_addr addr; /* virtual ip address */ 6020a925864SJulian Anastasov __be16 port; 603c860c6b1SJulius Volz u32 fwmark; /* firwall mark of service */ 604c860c6b1SJulius Volz 605c860c6b1SJulius Volz /* virtual service options */ 606c860c6b1SJulius Volz char *sched_name; 6070d1e71b0SSimon Horman char *pe_name; 60895c96174SEric Dumazet unsigned int flags; /* virtual service flags */ 60995c96174SEric Dumazet unsigned int timeout; /* persistent timeout in sec */ 6100a925864SJulian Anastasov __be32 netmask; /* persistent netmask or plen */ 611c860c6b1SJulius Volz }; 612c860c6b1SJulius Volz 613c860c6b1SJulius Volz 614c860c6b1SJulius Volz struct ip_vs_dest_user_kern { 615c860c6b1SJulius Volz /* destination server address */ 616c860c6b1SJulius Volz union nf_inet_addr addr; 6170a925864SJulian Anastasov __be16 port; 618c860c6b1SJulius Volz 619c860c6b1SJulius Volz /* real server options */ 62095c96174SEric Dumazet unsigned int conn_flags; /* connection flags */ 621c860c6b1SJulius Volz int weight; /* destination weight */ 622c860c6b1SJulius Volz 623c860c6b1SJulius Volz /* thresholds for active connections */ 624c860c6b1SJulius Volz u32 u_threshold; /* upper threshold */ 625c860c6b1SJulius Volz u32 l_threshold; /* lower threshold */ 6266cff339bSAlex Gartrell 6276cff339bSAlex Gartrell /* Address family of addr */ 6286cff339bSAlex Gartrell u16 af; 629c860c6b1SJulius Volz }; 630c860c6b1SJulius Volz 631c860c6b1SJulius Volz 632c860c6b1SJulius Volz /* 633*07dcc686SSimon Horman * The information about the virtual service offered to the net and the 634*07dcc686SSimon Horman * forwarding entries. 6351da177e4SLinus Torvalds */ 6361da177e4SLinus Torvalds struct ip_vs_service { 637ceec4c38SJulian Anastasov struct hlist_node s_list; /* for normal service table */ 638ceec4c38SJulian Anastasov struct hlist_node f_list; /* for fwmark-based service table */ 6391da177e4SLinus Torvalds atomic_t refcnt; /* reference counter */ 6401da177e4SLinus Torvalds 641e7ade46aSJulius Volz u16 af; /* address family */ 6421da177e4SLinus Torvalds __u16 protocol; /* which protocol (TCP/UDP) */ 643e7ade46aSJulius Volz union nf_inet_addr addr; /* IP address for virtual service */ 644014d730dSAl Viro __be16 port; /* port number for the service */ 6451da177e4SLinus Torvalds __u32 fwmark; /* firewall mark of the service */ 64695c96174SEric Dumazet unsigned int flags; /* service status flags */ 64795c96174SEric Dumazet unsigned int timeout; /* persistent timeout in ticks */ 6480a925864SJulian Anastasov __be32 netmask; /* grouping granularity, mask/plen */ 649fc723250SHans Schillstrom struct net *net; 6501da177e4SLinus Torvalds 6511da177e4SLinus Torvalds struct list_head destinations; /* real server d-linked list */ 6521da177e4SLinus Torvalds __u32 num_dests; /* number of servers */ 6531da177e4SLinus Torvalds struct ip_vs_stats stats; /* statistics for the service */ 6541da177e4SLinus Torvalds 6551da177e4SLinus Torvalds /* for scheduling */ 656ceec4c38SJulian Anastasov struct ip_vs_scheduler __rcu *scheduler; /* bound scheduler object */ 657ba3a3ce1SJulian Anastasov spinlock_t sched_lock; /* lock sched_data */ 6581da177e4SLinus Torvalds void *sched_data; /* scheduler application data */ 65985999283SSimon Horman 66085999283SSimon Horman /* alternate persistence engine */ 661ceec4c38SJulian Anastasov struct ip_vs_pe __rcu *pe; 662ceec4c38SJulian Anastasov 663ceec4c38SJulian Anastasov struct rcu_head rcu_head; 6641da177e4SLinus Torvalds }; 6651da177e4SLinus Torvalds 666026ace06SJulian Anastasov /* Information for cached dst */ 667026ace06SJulian Anastasov struct ip_vs_dest_dst { 668026ace06SJulian Anastasov struct dst_entry *dst_cache; /* destination cache entry */ 669026ace06SJulian Anastasov u32 dst_cookie; 670026ace06SJulian Anastasov union nf_inet_addr dst_saddr; 671026ace06SJulian Anastasov struct rcu_head rcu_head; 672026ace06SJulian Anastasov }; 6731da177e4SLinus Torvalds 674*07dcc686SSimon Horman /* The real server destination forwarding entry with ip address, port number, 675*07dcc686SSimon Horman * and so on. 6761da177e4SLinus Torvalds */ 6771da177e4SLinus Torvalds struct ip_vs_dest { 6781da177e4SLinus Torvalds struct list_head n_list; /* for the dests in the service */ 679276472eaSJulian Anastasov struct hlist_node d_list; /* for table with all the dests */ 6801da177e4SLinus Torvalds 681e7ade46aSJulius Volz u16 af; /* address family */ 682014d730dSAl Viro __be16 port; /* port number of the server */ 683f2431e6eSHans Schillstrom union nf_inet_addr addr; /* IP address of the server */ 68495c96174SEric Dumazet volatile unsigned int flags; /* dest status flags */ 6851da177e4SLinus Torvalds atomic_t conn_flags; /* flags to copy to conn */ 6861da177e4SLinus Torvalds atomic_t weight; /* server weight */ 6871da177e4SLinus Torvalds 6881da177e4SLinus Torvalds atomic_t refcnt; /* reference counter */ 6891da177e4SLinus Torvalds struct ip_vs_stats stats; /* statistics */ 690bcbde4c0SJulian Anastasov unsigned long idle_start; /* start time, jiffies */ 6911da177e4SLinus Torvalds 6921da177e4SLinus Torvalds /* connection counters and thresholds */ 6931da177e4SLinus Torvalds atomic_t activeconns; /* active connections */ 6941da177e4SLinus Torvalds atomic_t inactconns; /* inactive connections */ 6951da177e4SLinus Torvalds atomic_t persistconns; /* persistent connections */ 6961da177e4SLinus Torvalds __u32 u_threshold; /* upper threshold */ 6971da177e4SLinus Torvalds __u32 l_threshold; /* lower threshold */ 6981da177e4SLinus Torvalds 6991da177e4SLinus Torvalds /* for destination cache */ 7001da177e4SLinus Torvalds spinlock_t dst_lock; /* lock of dst_cache */ 701026ace06SJulian Anastasov struct ip_vs_dest_dst __rcu *dest_dst; /* cached dst info */ 7021da177e4SLinus Torvalds 7031da177e4SLinus Torvalds /* for virtual service */ 704bcbde4c0SJulian Anastasov struct ip_vs_service __rcu *svc; /* service it belongs to */ 7051da177e4SLinus Torvalds __u16 protocol; /* which protocol (TCP/UDP) */ 706014d730dSAl Viro __be16 vport; /* virtual port number */ 707f2431e6eSHans Schillstrom union nf_inet_addr vaddr; /* virtual IP address */ 7081da177e4SLinus Torvalds __u32 vfwmark; /* firewall mark of service */ 709276472eaSJulian Anastasov 710578bc3efSJulian Anastasov struct list_head t_list; /* in dest_trash */ 711276472eaSJulian Anastasov unsigned int in_rs_table:1; /* we are in rs_table */ 7121da177e4SLinus Torvalds }; 7131da177e4SLinus Torvalds 714*07dcc686SSimon Horman /* The scheduler object */ 7151da177e4SLinus Torvalds struct ip_vs_scheduler { 7161da177e4SLinus Torvalds struct list_head n_list; /* d-linked list head */ 7171da177e4SLinus Torvalds char *name; /* scheduler name */ 7181da177e4SLinus Torvalds atomic_t refcnt; /* reference counter */ 7191da177e4SLinus Torvalds struct module *module; /* THIS_MODULE/NULL */ 7201da177e4SLinus Torvalds 7211da177e4SLinus Torvalds /* scheduler initializing service */ 7221da177e4SLinus Torvalds int (*init_service)(struct ip_vs_service *svc); 7231da177e4SLinus Torvalds /* scheduling service finish */ 724ed3ffc4eSJulian Anastasov void (*done_service)(struct ip_vs_service *svc); 7256b6df466SJulian Anastasov /* dest is linked */ 7266b6df466SJulian Anastasov int (*add_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest); 7276b6df466SJulian Anastasov /* dest is unlinked */ 7286b6df466SJulian Anastasov int (*del_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest); 7296b6df466SJulian Anastasov /* dest is updated */ 7306b6df466SJulian Anastasov int (*upd_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest); 7311da177e4SLinus Torvalds 7321da177e4SLinus Torvalds /* selecting a server from the given service */ 7331da177e4SLinus Torvalds struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc, 734bba54de5SJulian Anastasov const struct sk_buff *skb, 735bba54de5SJulian Anastasov struct ip_vs_iphdr *iph); 7361da177e4SLinus Torvalds }; 7371da177e4SLinus Torvalds 73885999283SSimon Horman /* The persistence engine object */ 73985999283SSimon Horman struct ip_vs_pe { 74085999283SSimon Horman struct list_head n_list; /* d-linked list head */ 74185999283SSimon Horman char *name; /* scheduler name */ 74285999283SSimon Horman atomic_t refcnt; /* reference counter */ 74385999283SSimon Horman struct module *module; /* THIS_MODULE/NULL */ 74485999283SSimon Horman 74585999283SSimon Horman /* get the connection template, if any */ 74685999283SSimon Horman int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb); 74785999283SSimon Horman bool (*ct_match)(const struct ip_vs_conn_param *p, 74885999283SSimon Horman struct ip_vs_conn *ct); 74985999283SSimon Horman u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval, 75085999283SSimon Horman bool inverse); 751a3c918acSSimon Horman int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf); 75285999283SSimon Horman }; 7531da177e4SLinus Torvalds 754*07dcc686SSimon Horman /* The application module object (a.k.a. app incarnation) */ 755fd2c3ef7SEric Dumazet struct ip_vs_app { 7561da177e4SLinus Torvalds struct list_head a_list; /* member in app list */ 7571da177e4SLinus Torvalds int type; /* IP_VS_APP_TYPE_xxx */ 7581da177e4SLinus Torvalds char *name; /* application module name */ 7591da177e4SLinus Torvalds __u16 protocol; 7601da177e4SLinus Torvalds struct module *module; /* THIS_MODULE/NULL */ 7611da177e4SLinus Torvalds struct list_head incs_list; /* list of incarnations */ 7621da177e4SLinus Torvalds 7631da177e4SLinus Torvalds /* members for application incarnations */ 7641da177e4SLinus Torvalds struct list_head p_list; /* member in proto app list */ 7651da177e4SLinus Torvalds struct ip_vs_app *app; /* its real application */ 766014d730dSAl Viro __be16 port; /* port number in net order */ 7671da177e4SLinus Torvalds atomic_t usecnt; /* usage counter */ 768363c97d7SJulian Anastasov struct rcu_head rcu_head; 7691da177e4SLinus Torvalds 770*07dcc686SSimon Horman /* output hook: Process packet in inout direction, diff set for TCP. 7718b27b10fSJulian Anastasov * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok, 7728b27b10fSJulian Anastasov * 2=Mangled but checksum was not updated 7738b27b10fSJulian Anastasov */ 7741da177e4SLinus Torvalds int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *, 7753db05feaSHerbert Xu struct sk_buff *, int *diff); 7761da177e4SLinus Torvalds 777*07dcc686SSimon Horman /* input hook: Process packet in outin direction, diff set for TCP. 7788b27b10fSJulian Anastasov * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok, 7798b27b10fSJulian Anastasov * 2=Mangled but checksum was not updated 7808b27b10fSJulian Anastasov */ 7811da177e4SLinus Torvalds int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *, 7823db05feaSHerbert Xu struct sk_buff *, int *diff); 7831da177e4SLinus Torvalds 7841da177e4SLinus Torvalds /* ip_vs_app initializer */ 7851da177e4SLinus Torvalds int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *); 7861da177e4SLinus Torvalds 7871da177e4SLinus Torvalds /* ip_vs_app finish */ 7881da177e4SLinus Torvalds int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *); 7891da177e4SLinus Torvalds 7901da177e4SLinus Torvalds 7911da177e4SLinus Torvalds /* not used now */ 7921da177e4SLinus Torvalds int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *, 7931da177e4SLinus Torvalds struct ip_vs_protocol *); 7941da177e4SLinus Torvalds 7951da177e4SLinus Torvalds void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *); 7961da177e4SLinus Torvalds 7971da177e4SLinus Torvalds int * timeout_table; 7981da177e4SLinus Torvalds int * timeouts; 7991da177e4SLinus Torvalds int timeouts_size; 8001da177e4SLinus Torvalds 8011da177e4SLinus Torvalds int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app, 8021da177e4SLinus Torvalds int *verdict, struct ip_vs_conn **cpp); 8031da177e4SLinus Torvalds 8041da177e4SLinus Torvalds struct ip_vs_conn * 8051da177e4SLinus Torvalds (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app, 806d4383f04SJesper Dangaard Brouer const struct iphdr *iph, int inverse); 8071da177e4SLinus Torvalds 8081da177e4SLinus Torvalds struct ip_vs_conn * 8091da177e4SLinus Torvalds (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app, 810d4383f04SJesper Dangaard Brouer const struct iphdr *iph, int inverse); 8111da177e4SLinus Torvalds 8121da177e4SLinus Torvalds int (*state_transition)(struct ip_vs_conn *cp, int direction, 8131da177e4SLinus Torvalds const struct sk_buff *skb, 8141da177e4SLinus Torvalds struct ip_vs_app *app); 8151da177e4SLinus Torvalds 8161da177e4SLinus Torvalds void (*timeout_change)(struct ip_vs_app *app, int flags); 8171da177e4SLinus Torvalds }; 8181da177e4SLinus Torvalds 819f73181c8SPablo Neira Ayuso struct ipvs_master_sync_state { 820f73181c8SPablo Neira Ayuso struct list_head sync_queue; 821f73181c8SPablo Neira Ayuso struct ip_vs_sync_buff *sync_buff; 82207995674SZhang Yanfei unsigned long sync_queue_len; 823f73181c8SPablo Neira Ayuso unsigned int sync_queue_delay; 824f73181c8SPablo Neira Ayuso struct task_struct *master_thread; 825f73181c8SPablo Neira Ayuso struct delayed_work master_wakeup_work; 826f73181c8SPablo Neira Ayuso struct netns_ipvs *ipvs; 827f73181c8SPablo Neira Ayuso }; 828f73181c8SPablo Neira Ayuso 829578bc3efSJulian Anastasov /* How much time to keep dests in trash */ 830578bc3efSJulian Anastasov #define IP_VS_DEST_TRASH_PERIOD (120 * HZ) 831578bc3efSJulian Anastasov 8322553d064SJulian Anastasov /* IPVS in network namespace */ 8332553d064SJulian Anastasov struct netns_ipvs { 8342553d064SJulian Anastasov int gen; /* Generation */ 8357a4f0761SHans Schillstrom int enable; /* enable like nf_hooks do */ 836*07dcc686SSimon Horman /* Hash table: for real service lookups */ 8372553d064SJulian Anastasov #define IP_VS_RTAB_BITS 4 8382553d064SJulian Anastasov #define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS) 8392553d064SJulian Anastasov #define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1) 8402553d064SJulian Anastasov 841276472eaSJulian Anastasov struct hlist_head rs_table[IP_VS_RTAB_SIZE]; 8422553d064SJulian Anastasov /* ip_vs_app */ 8432553d064SJulian Anastasov struct list_head app_list; 8442553d064SJulian Anastasov /* ip_vs_proto */ 8452553d064SJulian Anastasov #define IP_VS_PROTO_TAB_SIZE 32 /* must be power of 2 */ 8462553d064SJulian Anastasov struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE]; 8472553d064SJulian Anastasov /* ip_vs_proto_tcp */ 8482553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_TCP 8492553d064SJulian Anastasov #define TCP_APP_TAB_BITS 4 8502553d064SJulian Anastasov #define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS) 8512553d064SJulian Anastasov #define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1) 8522553d064SJulian Anastasov struct list_head tcp_apps[TCP_APP_TAB_SIZE]; 8532553d064SJulian Anastasov #endif 8542553d064SJulian Anastasov /* ip_vs_proto_udp */ 8552553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_UDP 8562553d064SJulian Anastasov #define UDP_APP_TAB_BITS 4 8572553d064SJulian Anastasov #define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS) 8582553d064SJulian Anastasov #define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1) 8592553d064SJulian Anastasov struct list_head udp_apps[UDP_APP_TAB_SIZE]; 8602553d064SJulian Anastasov #endif 8612553d064SJulian Anastasov /* ip_vs_proto_sctp */ 8622553d064SJulian Anastasov #ifdef CONFIG_IP_VS_PROTO_SCTP 8632553d064SJulian Anastasov #define SCTP_APP_TAB_BITS 4 8642553d064SJulian Anastasov #define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS) 8652553d064SJulian Anastasov #define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1) 8662553d064SJulian Anastasov /* Hash table for SCTP application incarnations */ 8672553d064SJulian Anastasov struct list_head sctp_apps[SCTP_APP_TAB_SIZE]; 8682553d064SJulian Anastasov #endif 8692553d064SJulian Anastasov /* ip_vs_conn */ 8702553d064SJulian Anastasov atomic_t conn_count; /* connection counter */ 8712553d064SJulian Anastasov 8722553d064SJulian Anastasov /* ip_vs_ctl */ 8732a0751afSJulian Anastasov struct ip_vs_stats tot_stats; /* Statistics & est. */ 8742553d064SJulian Anastasov 8752553d064SJulian Anastasov int num_services; /* no of virtual services */ 876f2247fbdSSimon Horman 8772553d064SJulian Anastasov /* Trash for destinations */ 8782553d064SJulian Anastasov struct list_head dest_trash; 879578bc3efSJulian Anastasov spinlock_t dest_trash_lock; 880578bc3efSJulian Anastasov struct timer_list dest_trash_timer; /* expiration timer */ 8812553d064SJulian Anastasov /* Service counters */ 8822553d064SJulian Anastasov atomic_t ftpsvc_counter; 8832553d064SJulian Anastasov atomic_t nullsvc_counter; 8842553d064SJulian Anastasov 885f2247fbdSSimon Horman #ifdef CONFIG_SYSCTL 886f2247fbdSSimon Horman /* 1/rate drop and drop-entry variables */ 887f2247fbdSSimon Horman struct delayed_work defense_work; /* Work handler */ 888f2247fbdSSimon Horman int drop_rate; 889f2247fbdSSimon Horman int drop_counter; 890f2247fbdSSimon Horman atomic_t dropentry; 891f2247fbdSSimon Horman /* locks in ctl.c */ 892f2247fbdSSimon Horman spinlock_t dropentry_lock; /* drop entry handling */ 893f2247fbdSSimon Horman spinlock_t droppacket_lock; /* drop packet handling */ 894f2247fbdSSimon Horman spinlock_t securetcp_lock; /* state and timeout tables */ 895f2247fbdSSimon Horman 8962553d064SJulian Anastasov /* sys-ctl struct */ 8972553d064SJulian Anastasov struct ctl_table_header *sysctl_hdr; 8982553d064SJulian Anastasov struct ctl_table *sysctl_tbl; 899f2247fbdSSimon Horman #endif 900f2247fbdSSimon Horman 9012553d064SJulian Anastasov /* sysctl variables */ 9022553d064SJulian Anastasov int sysctl_amemthresh; 9032553d064SJulian Anastasov int sysctl_am_droprate; 9042553d064SJulian Anastasov int sysctl_drop_entry; 9052553d064SJulian Anastasov int sysctl_drop_packet; 9062553d064SJulian Anastasov int sysctl_secure_tcp; 9072553d064SJulian Anastasov #ifdef CONFIG_IP_VS_NFCT 9082553d064SJulian Anastasov int sysctl_conntrack; 9092553d064SJulian Anastasov #endif 9102553d064SJulian Anastasov int sysctl_snat_reroute; 9112553d064SJulian Anastasov int sysctl_sync_ver; 912f73181c8SPablo Neira Ayuso int sysctl_sync_ports; 9134d0c875dSJulian Anastasov int sysctl_sync_persist_mode; 91407995674SZhang Yanfei unsigned long sysctl_sync_qlen_max; 9151c003b15SPablo Neira Ayuso int sysctl_sync_sock_size; 9162553d064SJulian Anastasov int sysctl_cache_bypass; 9172553d064SJulian Anastasov int sysctl_expire_nodest_conn; 918c6c96c18SAlexander Frolkin int sysctl_sloppy_tcp; 919c6c96c18SAlexander Frolkin int sysctl_sloppy_sctp; 9202553d064SJulian Anastasov int sysctl_expire_quiescent_template; 9212553d064SJulian Anastasov int sysctl_sync_threshold[2]; 922749c42b6SJulian Anastasov unsigned int sysctl_sync_refresh_period; 923749c42b6SJulian Anastasov int sysctl_sync_retries; 9242553d064SJulian Anastasov int sysctl_nat_icmp_send; 9253654e611SJulian Anastasov int sysctl_pmtu_disc; 9260c12582fSJulian Anastasov int sysctl_backup_only; 9272553d064SJulian Anastasov 9282553d064SJulian Anastasov /* ip_vs_lblc */ 9292553d064SJulian Anastasov int sysctl_lblc_expiration; 9302553d064SJulian Anastasov struct ctl_table_header *lblc_ctl_header; 9312553d064SJulian Anastasov struct ctl_table *lblc_ctl_table; 9322553d064SJulian Anastasov /* ip_vs_lblcr */ 9332553d064SJulian Anastasov int sysctl_lblcr_expiration; 9342553d064SJulian Anastasov struct ctl_table_header *lblcr_ctl_header; 9352553d064SJulian Anastasov struct ctl_table *lblcr_ctl_table; 9362553d064SJulian Anastasov /* ip_vs_est */ 9372553d064SJulian Anastasov struct list_head est_list; /* estimator list */ 9382553d064SJulian Anastasov spinlock_t est_lock; 9392553d064SJulian Anastasov struct timer_list est_timer; /* Estimation timer */ 9402553d064SJulian Anastasov /* ip_vs_sync */ 9412553d064SJulian Anastasov spinlock_t sync_lock; 942f73181c8SPablo Neira Ayuso struct ipvs_master_sync_state *ms; 9432553d064SJulian Anastasov spinlock_t sync_buff_lock; 944f73181c8SPablo Neira Ayuso struct task_struct **backup_threads; 945f73181c8SPablo Neira Ayuso int threads_mask; 9462553d064SJulian Anastasov int send_mesg_maxlen; 9472553d064SJulian Anastasov int recv_mesg_maxlen; 9482553d064SJulian Anastasov volatile int sync_state; 9492553d064SJulian Anastasov volatile int master_syncid; 9502553d064SJulian Anastasov volatile int backup_syncid; 951ae1d48b2SHans Schillstrom struct mutex sync_mutex; 9522553d064SJulian Anastasov /* multicast interface name */ 9532553d064SJulian Anastasov char master_mcast_ifn[IP_VS_IFNAME_MAXLEN]; 9542553d064SJulian Anastasov char backup_mcast_ifn[IP_VS_IFNAME_MAXLEN]; 9552553d064SJulian Anastasov /* net name space ptr */ 9562553d064SJulian Anastasov struct net *net; /* Needed by timer routines */ 957*07dcc686SSimon Horman /* Number of heterogeneous destinations, needed becaus heterogeneous 958*07dcc686SSimon Horman * are not supported when synchronization is enabled. 959*07dcc686SSimon Horman */ 960391f503dSAlex Gartrell unsigned int mixed_address_family_dests; 9612553d064SJulian Anastasov }; 9621da177e4SLinus Torvalds 96359e0350eSSimon Horman #define DEFAULT_SYNC_THRESHOLD 3 96459e0350eSSimon Horman #define DEFAULT_SYNC_PERIOD 50 9657532e8d4SSimon Horman #define DEFAULT_SYNC_VER 1 966c6c96c18SAlexander Frolkin #define DEFAULT_SLOPPY_TCP 0 967c6c96c18SAlexander Frolkin #define DEFAULT_SLOPPY_SCTP 0 968749c42b6SJulian Anastasov #define DEFAULT_SYNC_REFRESH_PERIOD (0U * HZ) 969749c42b6SJulian Anastasov #define DEFAULT_SYNC_RETRIES 0 9701c003b15SPablo Neira Ayuso #define IPVS_SYNC_WAKEUP_RATE 8 9711c003b15SPablo Neira Ayuso #define IPVS_SYNC_QLEN_MAX (IPVS_SYNC_WAKEUP_RATE * 4) 9721c003b15SPablo Neira Ayuso #define IPVS_SYNC_SEND_DELAY (HZ / 50) 9731c003b15SPablo Neira Ayuso #define IPVS_SYNC_CHECK_PERIOD HZ 974749c42b6SJulian Anastasov #define IPVS_SYNC_FLUSH_TIME (HZ * 2) 975f73181c8SPablo Neira Ayuso #define IPVS_SYNC_PORTS_MAX (1 << 6) 97659e0350eSSimon Horman 97759e0350eSSimon Horman #ifdef CONFIG_SYSCTL 97859e0350eSSimon Horman 97959e0350eSSimon Horman static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs) 98059e0350eSSimon Horman { 98159e0350eSSimon Horman return ipvs->sysctl_sync_threshold[0]; 98259e0350eSSimon Horman } 98359e0350eSSimon Horman 98459e0350eSSimon Horman static inline int sysctl_sync_period(struct netns_ipvs *ipvs) 98559e0350eSSimon Horman { 986749c42b6SJulian Anastasov return ACCESS_ONCE(ipvs->sysctl_sync_threshold[1]); 987749c42b6SJulian Anastasov } 988749c42b6SJulian Anastasov 989749c42b6SJulian Anastasov static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs) 990749c42b6SJulian Anastasov { 991749c42b6SJulian Anastasov return ACCESS_ONCE(ipvs->sysctl_sync_refresh_period); 992749c42b6SJulian Anastasov } 993749c42b6SJulian Anastasov 994749c42b6SJulian Anastasov static inline int sysctl_sync_retries(struct netns_ipvs *ipvs) 995749c42b6SJulian Anastasov { 996749c42b6SJulian Anastasov return ipvs->sysctl_sync_retries; 99759e0350eSSimon Horman } 99859e0350eSSimon Horman 9997532e8d4SSimon Horman static inline int sysctl_sync_ver(struct netns_ipvs *ipvs) 10007532e8d4SSimon Horman { 10017532e8d4SSimon Horman return ipvs->sysctl_sync_ver; 10027532e8d4SSimon Horman } 10037532e8d4SSimon Horman 1004c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs) 1005c6c96c18SAlexander Frolkin { 1006c6c96c18SAlexander Frolkin return ipvs->sysctl_sloppy_tcp; 1007c6c96c18SAlexander Frolkin } 1008c6c96c18SAlexander Frolkin 1009c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs) 1010c6c96c18SAlexander Frolkin { 1011c6c96c18SAlexander Frolkin return ipvs->sysctl_sloppy_sctp; 1012c6c96c18SAlexander Frolkin } 1013c6c96c18SAlexander Frolkin 1014f73181c8SPablo Neira Ayuso static inline int sysctl_sync_ports(struct netns_ipvs *ipvs) 1015f73181c8SPablo Neira Ayuso { 1016f73181c8SPablo Neira Ayuso return ACCESS_ONCE(ipvs->sysctl_sync_ports); 1017f73181c8SPablo Neira Ayuso } 1018f73181c8SPablo Neira Ayuso 10194d0c875dSJulian Anastasov static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs) 10204d0c875dSJulian Anastasov { 10214d0c875dSJulian Anastasov return ipvs->sysctl_sync_persist_mode; 10224d0c875dSJulian Anastasov } 10234d0c875dSJulian Anastasov 102407995674SZhang Yanfei static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs) 10251c003b15SPablo Neira Ayuso { 10261c003b15SPablo Neira Ayuso return ipvs->sysctl_sync_qlen_max; 10271c003b15SPablo Neira Ayuso } 10281c003b15SPablo Neira Ayuso 10291c003b15SPablo Neira Ayuso static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs) 10301c003b15SPablo Neira Ayuso { 10311c003b15SPablo Neira Ayuso return ipvs->sysctl_sync_sock_size; 10321c003b15SPablo Neira Ayuso } 10331c003b15SPablo Neira Ayuso 10343654e611SJulian Anastasov static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs) 10353654e611SJulian Anastasov { 10363654e611SJulian Anastasov return ipvs->sysctl_pmtu_disc; 10373654e611SJulian Anastasov } 10383654e611SJulian Anastasov 10390c12582fSJulian Anastasov static inline int sysctl_backup_only(struct netns_ipvs *ipvs) 10400c12582fSJulian Anastasov { 10410c12582fSJulian Anastasov return ipvs->sync_state & IP_VS_STATE_BACKUP && 10420c12582fSJulian Anastasov ipvs->sysctl_backup_only; 10430c12582fSJulian Anastasov } 10440c12582fSJulian Anastasov 104559e0350eSSimon Horman #else 104659e0350eSSimon Horman 104759e0350eSSimon Horman static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs) 104859e0350eSSimon Horman { 104959e0350eSSimon Horman return DEFAULT_SYNC_THRESHOLD; 105059e0350eSSimon Horman } 105159e0350eSSimon Horman 105259e0350eSSimon Horman static inline int sysctl_sync_period(struct netns_ipvs *ipvs) 105359e0350eSSimon Horman { 105459e0350eSSimon Horman return DEFAULT_SYNC_PERIOD; 105559e0350eSSimon Horman } 105659e0350eSSimon Horman 1057749c42b6SJulian Anastasov static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs) 1058749c42b6SJulian Anastasov { 1059749c42b6SJulian Anastasov return DEFAULT_SYNC_REFRESH_PERIOD; 1060749c42b6SJulian Anastasov } 1061749c42b6SJulian Anastasov 1062749c42b6SJulian Anastasov static inline int sysctl_sync_retries(struct netns_ipvs *ipvs) 1063749c42b6SJulian Anastasov { 1064749c42b6SJulian Anastasov return DEFAULT_SYNC_RETRIES & 3; 1065749c42b6SJulian Anastasov } 1066749c42b6SJulian Anastasov 10677532e8d4SSimon Horman static inline int sysctl_sync_ver(struct netns_ipvs *ipvs) 10687532e8d4SSimon Horman { 10697532e8d4SSimon Horman return DEFAULT_SYNC_VER; 10707532e8d4SSimon Horman } 10717532e8d4SSimon Horman 1072c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs) 1073c6c96c18SAlexander Frolkin { 1074c6c96c18SAlexander Frolkin return DEFAULT_SLOPPY_TCP; 1075c6c96c18SAlexander Frolkin } 1076c6c96c18SAlexander Frolkin 1077c6c96c18SAlexander Frolkin static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs) 1078c6c96c18SAlexander Frolkin { 1079c6c96c18SAlexander Frolkin return DEFAULT_SLOPPY_SCTP; 1080c6c96c18SAlexander Frolkin } 1081c6c96c18SAlexander Frolkin 1082f73181c8SPablo Neira Ayuso static inline int sysctl_sync_ports(struct netns_ipvs *ipvs) 1083f73181c8SPablo Neira Ayuso { 1084f73181c8SPablo Neira Ayuso return 1; 1085f73181c8SPablo Neira Ayuso } 1086f73181c8SPablo Neira Ayuso 10874d0c875dSJulian Anastasov static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs) 10884d0c875dSJulian Anastasov { 10894d0c875dSJulian Anastasov return 0; 10904d0c875dSJulian Anastasov } 10914d0c875dSJulian Anastasov 109207995674SZhang Yanfei static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs) 10931c003b15SPablo Neira Ayuso { 10941c003b15SPablo Neira Ayuso return IPVS_SYNC_QLEN_MAX; 10951c003b15SPablo Neira Ayuso } 10961c003b15SPablo Neira Ayuso 10971c003b15SPablo Neira Ayuso static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs) 10981c003b15SPablo Neira Ayuso { 10991c003b15SPablo Neira Ayuso return 0; 11001c003b15SPablo Neira Ayuso } 11011c003b15SPablo Neira Ayuso 11023654e611SJulian Anastasov static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs) 11033654e611SJulian Anastasov { 11043654e611SJulian Anastasov return 1; 11053654e611SJulian Anastasov } 11063654e611SJulian Anastasov 11070c12582fSJulian Anastasov static inline int sysctl_backup_only(struct netns_ipvs *ipvs) 11080c12582fSJulian Anastasov { 11090c12582fSJulian Anastasov return 0; 11100c12582fSJulian Anastasov } 11110c12582fSJulian Anastasov 111259e0350eSSimon Horman #endif 111359e0350eSSimon Horman 1114*07dcc686SSimon Horman /* IPVS core functions 11151da177e4SLinus Torvalds * (from ip_vs_core.c) 11161da177e4SLinus Torvalds */ 11175c3a0fd7SJoe Perches const char *ip_vs_proto_name(unsigned int proto); 11185c3a0fd7SJoe Perches void ip_vs_init_hash_table(struct list_head *table, int rows); 1119afdd6140SSven Wegener #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t))) 11201da177e4SLinus Torvalds 11211da177e4SLinus Torvalds #define IP_VS_APP_TYPE_FTP 1 11221da177e4SLinus Torvalds 1123*07dcc686SSimon Horman /* ip_vs_conn handling functions 11241da177e4SLinus Torvalds * (from ip_vs_conn.c) 11251da177e4SLinus Torvalds */ 11261da177e4SLinus Torvalds enum { 11271da177e4SLinus Torvalds IP_VS_DIR_INPUT = 0, 11281da177e4SLinus Torvalds IP_VS_DIR_OUTPUT, 11291da177e4SLinus Torvalds IP_VS_DIR_INPUT_ONLY, 11301da177e4SLinus Torvalds IP_VS_DIR_LAST, 11311da177e4SLinus Torvalds }; 11321da177e4SLinus Torvalds 11336e67e586SHans Schillstrom static inline void ip_vs_conn_fill_param(struct net *net, int af, int protocol, 1134f11017ecSSimon Horman const union nf_inet_addr *caddr, 1135f11017ecSSimon Horman __be16 cport, 1136f11017ecSSimon Horman const union nf_inet_addr *vaddr, 1137f11017ecSSimon Horman __be16 vport, 1138f11017ecSSimon Horman struct ip_vs_conn_param *p) 1139f11017ecSSimon Horman { 11406e67e586SHans Schillstrom p->net = net; 1141f11017ecSSimon Horman p->af = af; 1142f11017ecSSimon Horman p->protocol = protocol; 1143f11017ecSSimon Horman p->caddr = caddr; 1144f11017ecSSimon Horman p->cport = cport; 1145f11017ecSSimon Horman p->vaddr = vaddr; 1146f11017ecSSimon Horman p->vport = vport; 114785999283SSimon Horman p->pe = NULL; 114885999283SSimon Horman p->pe_data = NULL; 1149f11017ecSSimon Horman } 115028364a59SJulius Volz 1151f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p); 1152f11017ecSSimon Horman struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p); 115328364a59SJulius Volz 11545c0d2374SSimon Horman struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb, 11555c0d2374SSimon Horman const struct ip_vs_iphdr *iph, 11565c0d2374SSimon Horman int inverse); 11575c0d2374SSimon Horman 1158f11017ecSSimon Horman struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p); 11591da177e4SLinus Torvalds 11605c0d2374SSimon Horman struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb, 11615c0d2374SSimon Horman const struct ip_vs_iphdr *iph, 11625c0d2374SSimon Horman int inverse); 11635c0d2374SSimon Horman 1164088339a5SJulian Anastasov /* Get reference to gain full access to conn. 1165088339a5SJulian Anastasov * By default, RCU read-side critical sections have access only to 1166088339a5SJulian Anastasov * conn fields and its PE data, see ip_vs_conn_rcu_free() for reference. 1167088339a5SJulian Anastasov */ 1168088339a5SJulian Anastasov static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp) 1169088339a5SJulian Anastasov { 1170088339a5SJulian Anastasov return atomic_inc_not_zero(&cp->refcnt); 1171088339a5SJulian Anastasov } 1172088339a5SJulian Anastasov 11731da177e4SLinus Torvalds /* put back the conn without restarting its timer */ 11741da177e4SLinus Torvalds static inline void __ip_vs_conn_put(struct ip_vs_conn *cp) 11751da177e4SLinus Torvalds { 11764e857c58SPeter Zijlstra smp_mb__before_atomic(); 11771da177e4SLinus Torvalds atomic_dec(&cp->refcnt); 11781da177e4SLinus Torvalds } 11795c3a0fd7SJoe Perches void ip_vs_conn_put(struct ip_vs_conn *cp); 11805c3a0fd7SJoe Perches void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport); 11811da177e4SLinus Torvalds 1182ba38528aSAlex Gartrell struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af, 1183f11017ecSSimon Horman const union nf_inet_addr *daddr, 118495c96174SEric Dumazet __be16 dport, unsigned int flags, 11850e051e68SHans Schillstrom struct ip_vs_dest *dest, __u32 fwmark); 11865c3a0fd7SJoe Perches void ip_vs_conn_expire_now(struct ip_vs_conn *cp); 11871da177e4SLinus Torvalds 11885c3a0fd7SJoe Perches const char *ip_vs_state_name(__u16 proto, int state); 11891da177e4SLinus Torvalds 11905c3a0fd7SJoe Perches void ip_vs_tcp_conn_listen(struct net *net, struct ip_vs_conn *cp); 11915c3a0fd7SJoe Perches int ip_vs_check_template(struct ip_vs_conn *ct); 11925c3a0fd7SJoe Perches void ip_vs_random_dropentry(struct net *net); 11935c3a0fd7SJoe Perches int ip_vs_conn_init(void); 11945c3a0fd7SJoe Perches void ip_vs_conn_cleanup(void); 11951da177e4SLinus Torvalds 11961da177e4SLinus Torvalds static inline void ip_vs_control_del(struct ip_vs_conn *cp) 11971da177e4SLinus Torvalds { 11981da177e4SLinus Torvalds struct ip_vs_conn *ctl_cp = cp->control; 11991da177e4SLinus Torvalds if (!ctl_cp) { 1200cfc78c5aSJulius Volz IP_VS_ERR_BUF("request control DEL for uncontrolled: " 1201cfc78c5aSJulius Volz "%s:%d to %s:%d\n", 1202cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1203cfc78c5aSJulius Volz ntohs(cp->cport), 1204cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr), 1205cfc78c5aSJulius Volz ntohs(cp->vport)); 1206cfc78c5aSJulius Volz 12071da177e4SLinus Torvalds return; 12081da177e4SLinus Torvalds } 12091da177e4SLinus Torvalds 1210cfc78c5aSJulius Volz IP_VS_DBG_BUF(7, "DELeting control for: " 1211cfc78c5aSJulius Volz "cp.dst=%s:%d ctl_cp.dst=%s:%d\n", 1212cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1213cfc78c5aSJulius Volz ntohs(cp->cport), 1214cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr), 1215cfc78c5aSJulius Volz ntohs(ctl_cp->cport)); 12161da177e4SLinus Torvalds 12171da177e4SLinus Torvalds cp->control = NULL; 12181da177e4SLinus Torvalds if (atomic_read(&ctl_cp->n_control) == 0) { 1219cfc78c5aSJulius Volz IP_VS_ERR_BUF("BUG control DEL with n=0 : " 1220cfc78c5aSJulius Volz "%s:%d to %s:%d\n", 1221cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1222cfc78c5aSJulius Volz ntohs(cp->cport), 1223cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr), 1224cfc78c5aSJulius Volz ntohs(cp->vport)); 1225cfc78c5aSJulius Volz 12261da177e4SLinus Torvalds return; 12271da177e4SLinus Torvalds } 12281da177e4SLinus Torvalds atomic_dec(&ctl_cp->n_control); 12291da177e4SLinus Torvalds } 12301da177e4SLinus Torvalds 12311da177e4SLinus Torvalds static inline void 12321da177e4SLinus Torvalds ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp) 12331da177e4SLinus Torvalds { 12341da177e4SLinus Torvalds if (cp->control) { 1235cfc78c5aSJulius Volz IP_VS_ERR_BUF("request control ADD for already controlled: " 1236cfc78c5aSJulius Volz "%s:%d to %s:%d\n", 1237cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1238cfc78c5aSJulius Volz ntohs(cp->cport), 1239cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->vaddr), 1240cfc78c5aSJulius Volz ntohs(cp->vport)); 1241cfc78c5aSJulius Volz 12421da177e4SLinus Torvalds ip_vs_control_del(cp); 12431da177e4SLinus Torvalds } 12441da177e4SLinus Torvalds 1245cfc78c5aSJulius Volz IP_VS_DBG_BUF(7, "ADDing control for: " 1246cfc78c5aSJulius Volz "cp.dst=%s:%d ctl_cp.dst=%s:%d\n", 1247cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &cp->caddr), 1248cfc78c5aSJulius Volz ntohs(cp->cport), 1249cfc78c5aSJulius Volz IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr), 1250cfc78c5aSJulius Volz ntohs(ctl_cp->cport)); 12511da177e4SLinus Torvalds 12521da177e4SLinus Torvalds cp->control = ctl_cp; 12531da177e4SLinus Torvalds atomic_inc(&ctl_cp->n_control); 12541da177e4SLinus Torvalds } 12551da177e4SLinus Torvalds 1256*07dcc686SSimon Horman /* IPVS netns init & cleanup functions */ 12575c3a0fd7SJoe Perches int ip_vs_estimator_net_init(struct net *net); 12585c3a0fd7SJoe Perches int ip_vs_control_net_init(struct net *net); 12595c3a0fd7SJoe Perches int ip_vs_protocol_net_init(struct net *net); 12605c3a0fd7SJoe Perches int ip_vs_app_net_init(struct net *net); 12615c3a0fd7SJoe Perches int ip_vs_conn_net_init(struct net *net); 12625c3a0fd7SJoe Perches int ip_vs_sync_net_init(struct net *net); 12635c3a0fd7SJoe Perches void ip_vs_conn_net_cleanup(struct net *net); 12645c3a0fd7SJoe Perches void ip_vs_app_net_cleanup(struct net *net); 12655c3a0fd7SJoe Perches void ip_vs_protocol_net_cleanup(struct net *net); 12665c3a0fd7SJoe Perches void ip_vs_control_net_cleanup(struct net *net); 12675c3a0fd7SJoe Perches void ip_vs_estimator_net_cleanup(struct net *net); 12685c3a0fd7SJoe Perches void ip_vs_sync_net_cleanup(struct net *net); 12695c3a0fd7SJoe Perches void ip_vs_service_net_cleanup(struct net *net); 12701da177e4SLinus Torvalds 1271*07dcc686SSimon Horman /* IPVS application functions 12721da177e4SLinus Torvalds * (from ip_vs_app.c) 12731da177e4SLinus Torvalds */ 12741da177e4SLinus Torvalds #define IP_VS_APP_MAX_PORTS 8 12755c3a0fd7SJoe Perches struct ip_vs_app *register_ip_vs_app(struct net *net, struct ip_vs_app *app); 12765c3a0fd7SJoe Perches void unregister_ip_vs_app(struct net *net, struct ip_vs_app *app); 12775c3a0fd7SJoe Perches int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp); 12785c3a0fd7SJoe Perches void ip_vs_unbind_app(struct ip_vs_conn *cp); 12795c3a0fd7SJoe Perches int register_ip_vs_app_inc(struct net *net, struct ip_vs_app *app, __u16 proto, 12805c3a0fd7SJoe Perches __u16 port); 12815c3a0fd7SJoe Perches int ip_vs_app_inc_get(struct ip_vs_app *inc); 12825c3a0fd7SJoe Perches void ip_vs_app_inc_put(struct ip_vs_app *inc); 12831da177e4SLinus Torvalds 12845c3a0fd7SJoe Perches int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb); 12855c3a0fd7SJoe Perches int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb); 12861da177e4SLinus Torvalds 12878be67a66SSimon Horman int register_ip_vs_pe(struct ip_vs_pe *pe); 12888be67a66SSimon Horman int unregister_ip_vs_pe(struct ip_vs_pe *pe); 1289e9e5eee8SSimon Horman struct ip_vs_pe *ip_vs_pe_getbyname(const char *name); 1290fe5e7a1eSHans Schillstrom struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name); 1291e9e5eee8SSimon Horman 1292*07dcc686SSimon Horman /* Use a #define to avoid all of module.h just for these trivial ops */ 129369e7dae4SPaul Gortmaker #define ip_vs_pe_get(pe) \ 129469e7dae4SPaul Gortmaker if (pe && pe->module) \ 1295e9e5eee8SSimon Horman __module_get(pe->module); 1296e9e5eee8SSimon Horman 129769e7dae4SPaul Gortmaker #define ip_vs_pe_put(pe) \ 129869e7dae4SPaul Gortmaker if (pe && pe->module) \ 1299e9e5eee8SSimon Horman module_put(pe->module); 13001da177e4SLinus Torvalds 1301*07dcc686SSimon Horman /* IPVS protocol functions (from ip_vs_proto.c) */ 13025c3a0fd7SJoe Perches int ip_vs_protocol_init(void); 13035c3a0fd7SJoe Perches void ip_vs_protocol_cleanup(void); 13045c3a0fd7SJoe Perches void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags); 13055c3a0fd7SJoe Perches int *ip_vs_create_timeout_table(int *table, int size); 13065c3a0fd7SJoe Perches int ip_vs_set_state_timeout(int *table, int num, const char *const *names, 130736cbd3dcSJan Engelhardt const char *name, int to); 13085c3a0fd7SJoe Perches void ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp, 13095c3a0fd7SJoe Perches const struct sk_buff *skb, int offset, 13105c3a0fd7SJoe Perches const char *msg); 13111da177e4SLinus Torvalds 13121da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_tcp; 13131da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_udp; 13141da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_icmp; 13151da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_esp; 13161da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_ah; 13172906f66aSVenkata Mohan Reddy extern struct ip_vs_protocol ip_vs_protocol_sctp; 13181da177e4SLinus Torvalds 1319*07dcc686SSimon Horman /* Registering/unregistering scheduler functions 13201da177e4SLinus Torvalds * (from ip_vs_sched.c) 13211da177e4SLinus Torvalds */ 13225c3a0fd7SJoe Perches int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); 13235c3a0fd7SJoe Perches int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); 13245c3a0fd7SJoe Perches int ip_vs_bind_scheduler(struct ip_vs_service *svc, 13251da177e4SLinus Torvalds struct ip_vs_scheduler *scheduler); 13265c3a0fd7SJoe Perches void ip_vs_unbind_scheduler(struct ip_vs_service *svc, 1327ceec4c38SJulian Anastasov struct ip_vs_scheduler *sched); 13285c3a0fd7SJoe Perches struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name); 13295c3a0fd7SJoe Perches void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler); 13305c3a0fd7SJoe Perches struct ip_vs_conn * 1331190ecd27SJulian Anastasov ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb, 1332d4383f04SJesper Dangaard Brouer struct ip_vs_proto_data *pd, int *ignored, 1333d4383f04SJesper Dangaard Brouer struct ip_vs_iphdr *iph); 13345c3a0fd7SJoe Perches int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb, 1335d4383f04SJesper Dangaard Brouer struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph); 13361da177e4SLinus Torvalds 13375c3a0fd7SJoe Perches void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg); 133841ac51eeSPatrick Schaaf 1339*07dcc686SSimon Horman /* IPVS control data and functions (from ip_vs_ctl.c) */ 13401da177e4SLinus Torvalds extern struct ip_vs_stats ip_vs_stats; 1341b880c1f0SHans Schillstrom extern int sysctl_ip_vs_sync_ver; 13421da177e4SLinus Torvalds 13435c3a0fd7SJoe Perches struct ip_vs_service * 1344ceec4c38SJulian Anastasov ip_vs_service_find(struct net *net, int af, __u32 fwmark, __u16 protocol, 13453c2e0505SJulius Volz const union nf_inet_addr *vaddr, __be16 vport); 13461da177e4SLinus Torvalds 13475c3a0fd7SJoe Perches bool ip_vs_has_real_service(struct net *net, int af, __u16 protocol, 13487937df15SJulius Volz const union nf_inet_addr *daddr, __be16 dport); 13497937df15SJulius Volz 13505c3a0fd7SJoe Perches int ip_vs_use_count_inc(void); 13515c3a0fd7SJoe Perches void ip_vs_use_count_dec(void); 13525c3a0fd7SJoe Perches int ip_vs_register_nl_ioctl(void); 13535c3a0fd7SJoe Perches void ip_vs_unregister_nl_ioctl(void); 13545c3a0fd7SJoe Perches int ip_vs_control_init(void); 13555c3a0fd7SJoe Perches void ip_vs_control_cleanup(void); 13565c3a0fd7SJoe Perches struct ip_vs_dest * 1357655eef10SAlex Gartrell ip_vs_find_dest(struct net *net, int svc_af, int dest_af, 1358655eef10SAlex Gartrell const union nf_inet_addr *daddr, __be16 dport, 1359655eef10SAlex Gartrell const union nf_inet_addr *vaddr, __be16 vport, 136052793dbeSJulian Anastasov __u16 protocol, __u32 fwmark, __u32 flags); 13615c3a0fd7SJoe Perches void ip_vs_try_bind_dest(struct ip_vs_conn *cp); 13621da177e4SLinus Torvalds 1363fca9c20aSJulian Anastasov static inline void ip_vs_dest_hold(struct ip_vs_dest *dest) 1364fca9c20aSJulian Anastasov { 1365fca9c20aSJulian Anastasov atomic_inc(&dest->refcnt); 1366fca9c20aSJulian Anastasov } 1367fca9c20aSJulian Anastasov 1368fca9c20aSJulian Anastasov static inline void ip_vs_dest_put(struct ip_vs_dest *dest) 1369fca9c20aSJulian Anastasov { 13704e857c58SPeter Zijlstra smp_mb__before_atomic(); 1371fca9c20aSJulian Anastasov atomic_dec(&dest->refcnt); 1372fca9c20aSJulian Anastasov } 13731da177e4SLinus Torvalds 13749e4e948aSJulian Anastasov static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest) 13759e4e948aSJulian Anastasov { 13769e4e948aSJulian Anastasov if (atomic_dec_return(&dest->refcnt) < 0) 13779e4e948aSJulian Anastasov kfree(dest); 13789e4e948aSJulian Anastasov } 13799e4e948aSJulian Anastasov 1380*07dcc686SSimon Horman /* IPVS sync daemon data and function prototypes 13811da177e4SLinus Torvalds * (from ip_vs_sync.c) 13821da177e4SLinus Torvalds */ 13835c3a0fd7SJoe Perches int start_sync_thread(struct net *net, int state, char *mcast_ifn, __u8 syncid); 13845c3a0fd7SJoe Perches int stop_sync_thread(struct net *net, int state); 13855c3a0fd7SJoe Perches void ip_vs_sync_conn(struct net *net, struct ip_vs_conn *cp, int pkts); 13861da177e4SLinus Torvalds 1387*07dcc686SSimon Horman /* IPVS rate estimator prototypes (from ip_vs_est.c) */ 13885c3a0fd7SJoe Perches void ip_vs_start_estimator(struct net *net, struct ip_vs_stats *stats); 13895c3a0fd7SJoe Perches void ip_vs_stop_estimator(struct net *net, struct ip_vs_stats *stats); 13905c3a0fd7SJoe Perches void ip_vs_zero_estimator(struct ip_vs_stats *stats); 13915c3a0fd7SJoe Perches void ip_vs_read_estimator(struct ip_vs_stats_user *dst, 1392ea9f22ccSJulian Anastasov struct ip_vs_stats *stats); 13931da177e4SLinus Torvalds 1394*07dcc686SSimon Horman /* Various IPVS packet transmitters (from ip_vs_xmit.c) */ 13955c3a0fd7SJoe Perches int ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1396d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 13975c3a0fd7SJoe Perches int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1398d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 13995c3a0fd7SJoe Perches int ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1400d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14015c3a0fd7SJoe Perches int ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 14025c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14035c3a0fd7SJoe Perches int ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 14045c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14055c3a0fd7SJoe Perches int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, 1406d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, int offset, 1407d4383f04SJesper Dangaard Brouer unsigned int hooknum, struct ip_vs_iphdr *iph); 14085c3a0fd7SJoe Perches void ip_vs_dest_dst_rcu_free(struct rcu_head *head); 14091da177e4SLinus Torvalds 1410b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6 14115c3a0fd7SJoe Perches int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 1412d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14135c3a0fd7SJoe Perches int ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 14145c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14155c3a0fd7SJoe Perches int ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 14165c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14175c3a0fd7SJoe Perches int ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 14185c3a0fd7SJoe Perches struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph); 14195c3a0fd7SJoe Perches int ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, 1420d4383f04SJesper Dangaard Brouer struct ip_vs_protocol *pp, int offset, 1421d4383f04SJesper Dangaard Brouer unsigned int hooknum, struct ip_vs_iphdr *iph); 1422b3cdd2a7SJulius Volz #endif 14231da177e4SLinus Torvalds 14243a1bbf18SSimon Horman #ifdef CONFIG_SYSCTL 1425*07dcc686SSimon Horman /* This is a simple mechanism to ignore packets when 14261da177e4SLinus Torvalds * we are loaded. Just set ip_vs_drop_rate to 'n' and 14271da177e4SLinus Torvalds * we start to drop 1/rate of the packets 14281da177e4SLinus Torvalds */ 1429a0840e2eSHans Schillstrom static inline int ip_vs_todrop(struct netns_ipvs *ipvs) 14301da177e4SLinus Torvalds { 1431a0840e2eSHans Schillstrom if (!ipvs->drop_rate) 1432a0840e2eSHans Schillstrom return 0; 1433a0840e2eSHans Schillstrom if (--ipvs->drop_counter > 0) 1434a0840e2eSHans Schillstrom return 0; 1435a0840e2eSHans Schillstrom ipvs->drop_counter = ipvs->drop_rate; 14361da177e4SLinus Torvalds return 1; 14371da177e4SLinus Torvalds } 14383a1bbf18SSimon Horman #else 14393a1bbf18SSimon Horman static inline int ip_vs_todrop(struct netns_ipvs *ipvs) { return 0; } 14403a1bbf18SSimon Horman #endif 14411da177e4SLinus Torvalds 1442*07dcc686SSimon Horman /* ip_vs_fwd_tag returns the forwarding tag of the connection */ 14431da177e4SLinus Torvalds #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK) 14441da177e4SLinus Torvalds 1445732db659SAdrian Bunk static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp) 14461da177e4SLinus Torvalds { 14471da177e4SLinus Torvalds char fwd; 14481da177e4SLinus Torvalds 14491da177e4SLinus Torvalds switch (IP_VS_FWD_METHOD(cp)) { 14501da177e4SLinus Torvalds case IP_VS_CONN_F_MASQ: 14511da177e4SLinus Torvalds fwd = 'M'; break; 14521da177e4SLinus Torvalds case IP_VS_CONN_F_LOCALNODE: 14531da177e4SLinus Torvalds fwd = 'L'; break; 14541da177e4SLinus Torvalds case IP_VS_CONN_F_TUNNEL: 14551da177e4SLinus Torvalds fwd = 'T'; break; 14561da177e4SLinus Torvalds case IP_VS_CONN_F_DROUTE: 14571da177e4SLinus Torvalds fwd = 'R'; break; 14581da177e4SLinus Torvalds case IP_VS_CONN_F_BYPASS: 14591da177e4SLinus Torvalds fwd = 'B'; break; 14601da177e4SLinus Torvalds default: 14611da177e4SLinus Torvalds fwd = '?'; break; 14621da177e4SLinus Torvalds } 14631da177e4SLinus Torvalds return fwd; 14641da177e4SLinus Torvalds } 14651da177e4SLinus Torvalds 14665c3a0fd7SJoe Perches void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp, 14671da177e4SLinus Torvalds struct ip_vs_conn *cp, int dir); 14681da177e4SLinus Torvalds 1469b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6 14705c3a0fd7SJoe Perches void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp, 1471b3cdd2a7SJulius Volz struct ip_vs_conn *cp, int dir); 1472b3cdd2a7SJulius Volz #endif 1473b3cdd2a7SJulius Volz 14745c3a0fd7SJoe Perches __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset); 14751da177e4SLinus Torvalds 1476f9214b26SAl Viro static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum) 14771da177e4SLinus Torvalds { 1478f9214b26SAl Viro __be32 diff[2] = { ~old, new }; 14791da177e4SLinus Torvalds 148007f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum); 1481f9214b26SAl Viro } 1482f9214b26SAl Viro 14830bbdd42bSJulius Volz #ifdef CONFIG_IP_VS_IPV6 14840bbdd42bSJulius Volz static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new, 14850bbdd42bSJulius Volz __wsum oldsum) 14860bbdd42bSJulius Volz { 14870bbdd42bSJulius Volz __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0], 14880bbdd42bSJulius Volz new[3], new[2], new[1], new[0] }; 14890bbdd42bSJulius Volz 149007f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum); 14910bbdd42bSJulius Volz } 14920bbdd42bSJulius Volz #endif 14930bbdd42bSJulius Volz 1494f9214b26SAl Viro static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum) 1495f9214b26SAl Viro { 1496f9214b26SAl Viro __be16 diff[2] = { ~old, new }; 1497f9214b26SAl Viro 149807f0757aSJoe Perches return csum_partial(diff, sizeof(diff), oldsum); 14991da177e4SLinus Torvalds } 15001da177e4SLinus Torvalds 1501*07dcc686SSimon Horman /* Forget current conntrack (unconfirmed) and attach notrack entry */ 1502cf356d69SJulian Anastasov static inline void ip_vs_notrack(struct sk_buff *skb) 1503cf356d69SJulian Anastasov { 1504cf356d69SJulian Anastasov #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 1505cf356d69SJulian Anastasov enum ip_conntrack_info ctinfo; 150606b69390SJesper Juhl struct nf_conn *ct = nf_ct_get(skb, &ctinfo); 1507cf356d69SJulian Anastasov 1508cf356d69SJulian Anastasov if (!ct || !nf_ct_is_untracked(ct)) { 15099e33ce45SLin Ming nf_conntrack_put(skb->nfct); 1510cf356d69SJulian Anastasov skb->nfct = &nf_ct_untracked_get()->ct_general; 1511cf356d69SJulian Anastasov skb->nfctinfo = IP_CT_NEW; 1512cf356d69SJulian Anastasov nf_conntrack_get(skb->nfct); 1513cf356d69SJulian Anastasov } 1514cf356d69SJulian Anastasov #endif 1515cf356d69SJulian Anastasov } 1516cf356d69SJulian Anastasov 1517f4bc17cdSJulian Anastasov #ifdef CONFIG_IP_VS_NFCT 1518*07dcc686SSimon Horman /* Netfilter connection tracking 1519f4bc17cdSJulian Anastasov * (from ip_vs_nfct.c) 1520f4bc17cdSJulian Anastasov */ 1521a0840e2eSHans Schillstrom static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs) 1522f4bc17cdSJulian Anastasov { 1523a4e2f5a7SSimon Horman #ifdef CONFIG_SYSCTL 1524a0840e2eSHans Schillstrom return ipvs->sysctl_conntrack; 1525a4e2f5a7SSimon Horman #else 1526a4e2f5a7SSimon Horman return 0; 1527a4e2f5a7SSimon Horman #endif 1528f4bc17cdSJulian Anastasov } 1529f4bc17cdSJulian Anastasov 15305c3a0fd7SJoe Perches void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp, 15316523ce15SJulian Anastasov int outin); 15325c3a0fd7SJoe Perches int ip_vs_confirm_conntrack(struct sk_buff *skb); 15335c3a0fd7SJoe Perches void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct, 1534f4bc17cdSJulian Anastasov struct ip_vs_conn *cp, u_int8_t proto, 1535f4bc17cdSJulian Anastasov const __be16 port, int from_rs); 15365c3a0fd7SJoe Perches void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp); 1537f4bc17cdSJulian Anastasov 1538f4bc17cdSJulian Anastasov #else 1539f4bc17cdSJulian Anastasov 1540a0840e2eSHans Schillstrom static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs) 1541f4bc17cdSJulian Anastasov { 1542f4bc17cdSJulian Anastasov return 0; 1543f4bc17cdSJulian Anastasov } 1544f4bc17cdSJulian Anastasov 1545f4bc17cdSJulian Anastasov static inline void ip_vs_update_conntrack(struct sk_buff *skb, 1546f4bc17cdSJulian Anastasov struct ip_vs_conn *cp, int outin) 1547f4bc17cdSJulian Anastasov { 1548f4bc17cdSJulian Anastasov } 1549f4bc17cdSJulian Anastasov 1550e23ebf0fSKrzysztof Wilczynski static inline int ip_vs_confirm_conntrack(struct sk_buff *skb) 1551f4bc17cdSJulian Anastasov { 1552f4bc17cdSJulian Anastasov return NF_ACCEPT; 1553f4bc17cdSJulian Anastasov } 1554f4bc17cdSJulian Anastasov 1555f4bc17cdSJulian Anastasov static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp) 1556f4bc17cdSJulian Anastasov { 1557f4bc17cdSJulian Anastasov } 1558*07dcc686SSimon Horman #endif /* CONFIG_IP_VS_NFCT */ 15596523ce15SJulian Anastasov 1560c16526a7SSimon Kirby static inline int 1561b552f7e3SChangli Gao ip_vs_dest_conn_overhead(struct ip_vs_dest *dest) 1562b552f7e3SChangli Gao { 1563*07dcc686SSimon Horman /* We think the overhead of processing active connections is 256 1564b552f7e3SChangli Gao * times higher than that of inactive connections in average. (This 1565b552f7e3SChangli Gao * 256 times might not be accurate, we will change it later) We 1566b552f7e3SChangli Gao * use the following formula to estimate the overhead now: 1567b552f7e3SChangli Gao * dest->activeconns*256 + dest->inactconns 1568b552f7e3SChangli Gao */ 1569b552f7e3SChangli Gao return (atomic_read(&dest->activeconns) << 8) + 1570b552f7e3SChangli Gao atomic_read(&dest->inactconns); 1571b552f7e3SChangli Gao } 1572b552f7e3SChangli Gao 1573bc4768ebSJulius Volz #endif /* _NET_IP_VS_H */ 1574