11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * IP Virtual Server 31da177e4SLinus Torvalds * data structure and functionality definitions 41da177e4SLinus Torvalds */ 51da177e4SLinus Torvalds 6bc4768ebSJulius Volz #ifndef _NET_IP_VS_H 7bc4768ebSJulius Volz #define _NET_IP_VS_H 81da177e4SLinus Torvalds 9bc4768ebSJulius Volz #include <linux/ip_vs.h> /* definitions shared with userland */ 101da177e4SLinus Torvalds 11bc4768ebSJulius Volz /* old ipvsadm versions still include this file directly */ 121da177e4SLinus Torvalds #ifdef __KERNEL__ 131da177e4SLinus Torvalds 14bc4768ebSJulius Volz #include <asm/types.h> /* for __uXX types */ 15bc4768ebSJulius Volz 16bc4768ebSJulius Volz #include <linux/sysctl.h> /* for ctl_path */ 171da177e4SLinus Torvalds #include <linux/list.h> /* for struct list_head */ 181da177e4SLinus Torvalds #include <linux/spinlock.h> /* for struct rwlock_t */ 191da177e4SLinus Torvalds #include <asm/atomic.h> /* for struct atomic_t */ 201da177e4SLinus Torvalds #include <linux/compiler.h> 2114c85021SArnaldo Carvalho de Melo #include <linux/timer.h> 221da177e4SLinus Torvalds 2314c85021SArnaldo Carvalho de Melo #include <net/checksum.h> 24e7ade46aSJulius Volz #include <linux/netfilter.h> /* for union nf_inet_addr */ 25e7ade46aSJulius Volz #include <linux/ipv6.h> /* for struct ipv6hdr */ 26e7ade46aSJulius Volz #include <net/ipv6.h> /* for ipv6_addr_copy */ 271da177e4SLinus Torvalds 2864aae3cbSJulius Volz struct ip_vs_iphdr { 2964aae3cbSJulius Volz int len; 3064aae3cbSJulius Volz __u8 protocol; 3164aae3cbSJulius Volz union nf_inet_addr saddr; 3264aae3cbSJulius Volz union nf_inet_addr daddr; 3364aae3cbSJulius Volz }; 3464aae3cbSJulius Volz 3564aae3cbSJulius Volz static inline void 3664aae3cbSJulius Volz ip_vs_fill_iphdr(int af, const void *nh, struct ip_vs_iphdr *iphdr) 3764aae3cbSJulius Volz { 3864aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6 3964aae3cbSJulius Volz if (af == AF_INET6) { 4064aae3cbSJulius Volz const struct ipv6hdr *iph = nh; 4164aae3cbSJulius Volz iphdr->len = sizeof(struct ipv6hdr); 4264aae3cbSJulius Volz iphdr->protocol = iph->nexthdr; 4364aae3cbSJulius Volz ipv6_addr_copy(&iphdr->saddr.in6, &iph->saddr); 4464aae3cbSJulius Volz ipv6_addr_copy(&iphdr->daddr.in6, &iph->daddr); 4564aae3cbSJulius Volz } else 4664aae3cbSJulius Volz #endif 4764aae3cbSJulius Volz { 4864aae3cbSJulius Volz const struct iphdr *iph = nh; 4964aae3cbSJulius Volz iphdr->len = iph->ihl * 4; 5064aae3cbSJulius Volz iphdr->protocol = iph->protocol; 5164aae3cbSJulius Volz iphdr->saddr.ip = iph->saddr; 5264aae3cbSJulius Volz iphdr->daddr.ip = iph->daddr; 5364aae3cbSJulius Volz } 5464aae3cbSJulius Volz } 5564aae3cbSJulius Volz 5664aae3cbSJulius Volz static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst, 5764aae3cbSJulius Volz const union nf_inet_addr *src) 5864aae3cbSJulius Volz { 5964aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6 6064aae3cbSJulius Volz if (af == AF_INET6) 6164aae3cbSJulius Volz ipv6_addr_copy(&dst->in6, &src->in6); 6264aae3cbSJulius Volz else 6364aae3cbSJulius Volz #endif 6464aae3cbSJulius Volz dst->ip = src->ip; 6564aae3cbSJulius Volz } 6664aae3cbSJulius Volz 6764aae3cbSJulius Volz static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a, 6864aae3cbSJulius Volz const union nf_inet_addr *b) 6964aae3cbSJulius Volz { 7064aae3cbSJulius Volz #ifdef CONFIG_IP_VS_IPV6 7164aae3cbSJulius Volz if (af == AF_INET6) 7264aae3cbSJulius Volz return ipv6_addr_equal(&a->in6, &b->in6); 7364aae3cbSJulius Volz #endif 7464aae3cbSJulius Volz return a->ip == b->ip; 7564aae3cbSJulius Volz } 7664aae3cbSJulius Volz 771da177e4SLinus Torvalds #ifdef CONFIG_IP_VS_DEBUG 7814c85021SArnaldo Carvalho de Melo #include <linux/net.h> 7914c85021SArnaldo Carvalho de Melo 801da177e4SLinus Torvalds extern int ip_vs_get_debug_level(void); 81c842a3adSJulius Volz 82c842a3adSJulius Volz static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len, 83c842a3adSJulius Volz const union nf_inet_addr *addr, 84c842a3adSJulius Volz int *idx) 85c842a3adSJulius Volz { 86c842a3adSJulius Volz int len; 87c842a3adSJulius Volz #ifdef CONFIG_IP_VS_IPV6 88c842a3adSJulius Volz if (af == AF_INET6) 89c842a3adSJulius Volz len = snprintf(&buf[*idx], buf_len - *idx, "[" NIP6_FMT "]", 90c842a3adSJulius Volz NIP6(addr->in6)) + 1; 91c842a3adSJulius Volz else 92c842a3adSJulius Volz #endif 93c842a3adSJulius Volz len = snprintf(&buf[*idx], buf_len - *idx, NIPQUAD_FMT, 94c842a3adSJulius Volz NIPQUAD(addr->ip)) + 1; 95c842a3adSJulius Volz 96c842a3adSJulius Volz *idx += len; 97c842a3adSJulius Volz BUG_ON(*idx > buf_len + 1); 98c842a3adSJulius Volz return &buf[*idx - len]; 99c842a3adSJulius Volz } 100c842a3adSJulius Volz 101c842a3adSJulius Volz #define IP_VS_DBG_BUF(level, msg...) \ 102c842a3adSJulius Volz do { \ 103c842a3adSJulius Volz char ip_vs_dbg_buf[160]; \ 104c842a3adSJulius Volz int ip_vs_dbg_idx = 0; \ 105c842a3adSJulius Volz if (level <= ip_vs_get_debug_level()) \ 106c842a3adSJulius Volz printk(KERN_DEBUG "IPVS: " msg); \ 107c842a3adSJulius Volz } while (0) 108c842a3adSJulius Volz #define IP_VS_ERR_BUF(msg...) \ 109c842a3adSJulius Volz do { \ 110c842a3adSJulius Volz char ip_vs_dbg_buf[160]; \ 111c842a3adSJulius Volz int ip_vs_dbg_idx = 0; \ 112c842a3adSJulius Volz printk(KERN_ERR "IPVS: " msg); \ 113c842a3adSJulius Volz } while (0) 114c842a3adSJulius Volz 115c842a3adSJulius Volz /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */ 116c842a3adSJulius Volz #define IP_VS_DBG_ADDR(af, addr) \ 117c842a3adSJulius Volz ip_vs_dbg_addr(af, ip_vs_dbg_buf, \ 118c842a3adSJulius Volz sizeof(ip_vs_dbg_buf), addr, \ 119c842a3adSJulius Volz &ip_vs_dbg_idx) 120c842a3adSJulius Volz 1211da177e4SLinus Torvalds #define IP_VS_DBG(level, msg...) \ 1221da177e4SLinus Torvalds do { \ 1231da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \ 1241da177e4SLinus Torvalds printk(KERN_DEBUG "IPVS: " msg); \ 1251da177e4SLinus Torvalds } while (0) 1261da177e4SLinus Torvalds #define IP_VS_DBG_RL(msg...) \ 1271da177e4SLinus Torvalds do { \ 1281da177e4SLinus Torvalds if (net_ratelimit()) \ 1291da177e4SLinus Torvalds printk(KERN_DEBUG "IPVS: " msg); \ 1301da177e4SLinus Torvalds } while (0) 1311da177e4SLinus Torvalds #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) \ 1321da177e4SLinus Torvalds do { \ 1331da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \ 1341da177e4SLinus Torvalds pp->debug_packet(pp, skb, ofs, msg); \ 1351da177e4SLinus Torvalds } while (0) 1361da177e4SLinus Torvalds #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) \ 1371da177e4SLinus Torvalds do { \ 1381da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level() && \ 1391da177e4SLinus Torvalds net_ratelimit()) \ 1401da177e4SLinus Torvalds pp->debug_packet(pp, skb, ofs, msg); \ 1411da177e4SLinus Torvalds } while (0) 1421da177e4SLinus Torvalds #else /* NO DEBUGGING at ALL */ 143c842a3adSJulius Volz #define IP_VS_DBG_BUF(level, msg...) do {} while (0) 144c842a3adSJulius Volz #define IP_VS_ERR_BUF(msg...) do {} while (0) 1451da177e4SLinus Torvalds #define IP_VS_DBG(level, msg...) do {} while (0) 1461da177e4SLinus Torvalds #define IP_VS_DBG_RL(msg...) do {} while (0) 1471da177e4SLinus Torvalds #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) do {} while (0) 1481da177e4SLinus Torvalds #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) do {} while (0) 1491da177e4SLinus Torvalds #endif 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds #define IP_VS_BUG() BUG() 1521da177e4SLinus Torvalds #define IP_VS_ERR(msg...) printk(KERN_ERR "IPVS: " msg) 1531da177e4SLinus Torvalds #define IP_VS_INFO(msg...) printk(KERN_INFO "IPVS: " msg) 1541da177e4SLinus Torvalds #define IP_VS_WARNING(msg...) \ 1551da177e4SLinus Torvalds printk(KERN_WARNING "IPVS: " msg) 1561da177e4SLinus Torvalds #define IP_VS_ERR_RL(msg...) \ 1571da177e4SLinus Torvalds do { \ 1581da177e4SLinus Torvalds if (net_ratelimit()) \ 1591da177e4SLinus Torvalds printk(KERN_ERR "IPVS: " msg); \ 1601da177e4SLinus Torvalds } while (0) 1611da177e4SLinus Torvalds 1621da177e4SLinus Torvalds #ifdef CONFIG_IP_VS_DEBUG 1631da177e4SLinus Torvalds #define EnterFunction(level) \ 1641da177e4SLinus Torvalds do { \ 1651da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \ 1661da177e4SLinus Torvalds printk(KERN_DEBUG "Enter: %s, %s line %i\n", \ 1671da177e4SLinus Torvalds __FUNCTION__, __FILE__, __LINE__); \ 1681da177e4SLinus Torvalds } while (0) 1691da177e4SLinus Torvalds #define LeaveFunction(level) \ 1701da177e4SLinus Torvalds do { \ 1711da177e4SLinus Torvalds if (level <= ip_vs_get_debug_level()) \ 1721da177e4SLinus Torvalds printk(KERN_DEBUG "Leave: %s, %s line %i\n", \ 1731da177e4SLinus Torvalds __FUNCTION__, __FILE__, __LINE__); \ 1741da177e4SLinus Torvalds } while (0) 1751da177e4SLinus Torvalds #else 1761da177e4SLinus Torvalds #define EnterFunction(level) do {} while (0) 1771da177e4SLinus Torvalds #define LeaveFunction(level) do {} while (0) 1781da177e4SLinus Torvalds #endif 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds #define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); } 1811da177e4SLinus Torvalds 1821da177e4SLinus Torvalds 1831da177e4SLinus Torvalds /* 1841da177e4SLinus Torvalds * The port number of FTP service (in network order). 1851da177e4SLinus Torvalds */ 1861da177e4SLinus Torvalds #define FTPPORT __constant_htons(21) 1871da177e4SLinus Torvalds #define FTPDATA __constant_htons(20) 1881da177e4SLinus Torvalds 1891da177e4SLinus Torvalds /* 1901da177e4SLinus Torvalds * TCP State Values 1911da177e4SLinus Torvalds */ 1921da177e4SLinus Torvalds enum { 1931da177e4SLinus Torvalds IP_VS_TCP_S_NONE = 0, 1941da177e4SLinus Torvalds IP_VS_TCP_S_ESTABLISHED, 1951da177e4SLinus Torvalds IP_VS_TCP_S_SYN_SENT, 1961da177e4SLinus Torvalds IP_VS_TCP_S_SYN_RECV, 1971da177e4SLinus Torvalds IP_VS_TCP_S_FIN_WAIT, 1981da177e4SLinus Torvalds IP_VS_TCP_S_TIME_WAIT, 1991da177e4SLinus Torvalds IP_VS_TCP_S_CLOSE, 2001da177e4SLinus Torvalds IP_VS_TCP_S_CLOSE_WAIT, 2011da177e4SLinus Torvalds IP_VS_TCP_S_LAST_ACK, 2021da177e4SLinus Torvalds IP_VS_TCP_S_LISTEN, 2031da177e4SLinus Torvalds IP_VS_TCP_S_SYNACK, 2041da177e4SLinus Torvalds IP_VS_TCP_S_LAST 2051da177e4SLinus Torvalds }; 2061da177e4SLinus Torvalds 2071da177e4SLinus Torvalds /* 2081da177e4SLinus Torvalds * UDP State Values 2091da177e4SLinus Torvalds */ 2101da177e4SLinus Torvalds enum { 2111da177e4SLinus Torvalds IP_VS_UDP_S_NORMAL, 2121da177e4SLinus Torvalds IP_VS_UDP_S_LAST, 2131da177e4SLinus Torvalds }; 2141da177e4SLinus Torvalds 2151da177e4SLinus Torvalds /* 2161da177e4SLinus Torvalds * ICMP State Values 2171da177e4SLinus Torvalds */ 2181da177e4SLinus Torvalds enum { 2191da177e4SLinus Torvalds IP_VS_ICMP_S_NORMAL, 2201da177e4SLinus Torvalds IP_VS_ICMP_S_LAST, 2211da177e4SLinus Torvalds }; 2221da177e4SLinus Torvalds 2231da177e4SLinus Torvalds /* 2241da177e4SLinus Torvalds * Delta sequence info structure 2251da177e4SLinus Torvalds * Each ip_vs_conn has 2 (output AND input seq. changes). 2261da177e4SLinus Torvalds * Only used in the VS/NAT. 2271da177e4SLinus Torvalds */ 2281da177e4SLinus Torvalds struct ip_vs_seq { 2291da177e4SLinus Torvalds __u32 init_seq; /* Add delta from this seq */ 2301da177e4SLinus Torvalds __u32 delta; /* Delta in sequence numbers */ 2311da177e4SLinus Torvalds __u32 previous_delta; /* Delta in sequence numbers 2321da177e4SLinus Torvalds before last resized pkt */ 2331da177e4SLinus Torvalds }; 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds /* 2373a14a313SSven Wegener * IPVS statistics objects 2381da177e4SLinus Torvalds */ 2393a14a313SSven Wegener struct ip_vs_estimator { 2403a14a313SSven Wegener struct list_head list; 2413a14a313SSven Wegener 2423a14a313SSven Wegener u64 last_inbytes; 2433a14a313SSven Wegener u64 last_outbytes; 2443a14a313SSven Wegener u32 last_conns; 2453a14a313SSven Wegener u32 last_inpkts; 2463a14a313SSven Wegener u32 last_outpkts; 2473a14a313SSven Wegener 2483a14a313SSven Wegener u32 cps; 2493a14a313SSven Wegener u32 inpps; 2503a14a313SSven Wegener u32 outpps; 2513a14a313SSven Wegener u32 inbps; 2523a14a313SSven Wegener u32 outbps; 2533a14a313SSven Wegener }; 2543a14a313SSven Wegener 2551da177e4SLinus Torvalds struct ip_vs_stats 2561da177e4SLinus Torvalds { 2571da177e4SLinus Torvalds __u32 conns; /* connections scheduled */ 2581da177e4SLinus Torvalds __u32 inpkts; /* incoming packets */ 2591da177e4SLinus Torvalds __u32 outpkts; /* outgoing packets */ 2601da177e4SLinus Torvalds __u64 inbytes; /* incoming bytes */ 2611da177e4SLinus Torvalds __u64 outbytes; /* outgoing bytes */ 2621da177e4SLinus Torvalds 2631da177e4SLinus Torvalds __u32 cps; /* current connection rate */ 2641da177e4SLinus Torvalds __u32 inpps; /* current in packet rate */ 2651da177e4SLinus Torvalds __u32 outpps; /* current out packet rate */ 2661da177e4SLinus Torvalds __u32 inbps; /* current in byte rate */ 2671da177e4SLinus Torvalds __u32 outbps; /* current out byte rate */ 2681da177e4SLinus Torvalds 2693a14a313SSven Wegener /* 2703a14a313SSven Wegener * Don't add anything before the lock, because we use memcpy() to copy 2713a14a313SSven Wegener * the members before the lock to struct ip_vs_stats_user in 2723a14a313SSven Wegener * ip_vs_ctl.c. 2733a14a313SSven Wegener */ 2743a14a313SSven Wegener 2751da177e4SLinus Torvalds spinlock_t lock; /* spin lock */ 2763a14a313SSven Wegener 2773a14a313SSven Wegener struct ip_vs_estimator est; /* estimator */ 2781da177e4SLinus Torvalds }; 2791da177e4SLinus Torvalds 28014c85021SArnaldo Carvalho de Melo struct dst_entry; 28114c85021SArnaldo Carvalho de Melo struct iphdr; 2821da177e4SLinus Torvalds struct ip_vs_conn; 2831da177e4SLinus Torvalds struct ip_vs_app; 28414c85021SArnaldo Carvalho de Melo struct sk_buff; 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds struct ip_vs_protocol { 2871da177e4SLinus Torvalds struct ip_vs_protocol *next; 2881da177e4SLinus Torvalds char *name; 2892ad17defSJulian Anastasov u16 protocol; 2902ad17defSJulian Anastasov u16 num_states; 2911da177e4SLinus Torvalds int dont_defrag; 2921da177e4SLinus Torvalds atomic_t appcnt; /* counter of proto app incs */ 2931da177e4SLinus Torvalds int *timeout_table; /* protocol timeout table */ 2941da177e4SLinus Torvalds 2951da177e4SLinus Torvalds void (*init)(struct ip_vs_protocol *pp); 2961da177e4SLinus Torvalds 2971da177e4SLinus Torvalds void (*exit)(struct ip_vs_protocol *pp); 2981da177e4SLinus Torvalds 29951ef348bSJulius Volz int (*conn_schedule)(int af, struct sk_buff *skb, 3001da177e4SLinus Torvalds struct ip_vs_protocol *pp, 3011da177e4SLinus Torvalds int *verdict, struct ip_vs_conn **cpp); 3021da177e4SLinus Torvalds 3031da177e4SLinus Torvalds struct ip_vs_conn * 30451ef348bSJulius Volz (*conn_in_get)(int af, 30551ef348bSJulius Volz const struct sk_buff *skb, 3061da177e4SLinus Torvalds struct ip_vs_protocol *pp, 30751ef348bSJulius Volz const struct ip_vs_iphdr *iph, 3081da177e4SLinus Torvalds unsigned int proto_off, 3091da177e4SLinus Torvalds int inverse); 3101da177e4SLinus Torvalds 3111da177e4SLinus Torvalds struct ip_vs_conn * 31251ef348bSJulius Volz (*conn_out_get)(int af, 31351ef348bSJulius Volz const struct sk_buff *skb, 3141da177e4SLinus Torvalds struct ip_vs_protocol *pp, 31551ef348bSJulius Volz const struct ip_vs_iphdr *iph, 3161da177e4SLinus Torvalds unsigned int proto_off, 3171da177e4SLinus Torvalds int inverse); 3181da177e4SLinus Torvalds 3193db05feaSHerbert Xu int (*snat_handler)(struct sk_buff *skb, 3201da177e4SLinus Torvalds struct ip_vs_protocol *pp, struct ip_vs_conn *cp); 3211da177e4SLinus Torvalds 3223db05feaSHerbert Xu int (*dnat_handler)(struct sk_buff *skb, 3231da177e4SLinus Torvalds struct ip_vs_protocol *pp, struct ip_vs_conn *cp); 3241da177e4SLinus Torvalds 32551ef348bSJulius Volz int (*csum_check)(int af, struct sk_buff *skb, 32651ef348bSJulius Volz struct ip_vs_protocol *pp); 3271da177e4SLinus Torvalds 3281da177e4SLinus Torvalds const char *(*state_name)(int state); 3291da177e4SLinus Torvalds 3301da177e4SLinus Torvalds int (*state_transition)(struct ip_vs_conn *cp, int direction, 3311da177e4SLinus Torvalds const struct sk_buff *skb, 3321da177e4SLinus Torvalds struct ip_vs_protocol *pp); 3331da177e4SLinus Torvalds 3341da177e4SLinus Torvalds int (*register_app)(struct ip_vs_app *inc); 3351da177e4SLinus Torvalds 3361da177e4SLinus Torvalds void (*unregister_app)(struct ip_vs_app *inc); 3371da177e4SLinus Torvalds 3381da177e4SLinus Torvalds int (*app_conn_bind)(struct ip_vs_conn *cp); 3391da177e4SLinus Torvalds 3401da177e4SLinus Torvalds void (*debug_packet)(struct ip_vs_protocol *pp, 3411da177e4SLinus Torvalds const struct sk_buff *skb, 3421da177e4SLinus Torvalds int offset, 3431da177e4SLinus Torvalds const char *msg); 3441da177e4SLinus Torvalds 3451da177e4SLinus Torvalds void (*timeout_change)(struct ip_vs_protocol *pp, int flags); 3461da177e4SLinus Torvalds 3471da177e4SLinus Torvalds int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to); 3481da177e4SLinus Torvalds }; 3491da177e4SLinus Torvalds 3501da177e4SLinus Torvalds extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto); 3511da177e4SLinus Torvalds 3521da177e4SLinus Torvalds /* 3531da177e4SLinus Torvalds * IP_VS structure allocated for each dynamically scheduled connection 3541da177e4SLinus Torvalds */ 3551da177e4SLinus Torvalds struct ip_vs_conn { 3561da177e4SLinus Torvalds struct list_head c_list; /* hashed list heads */ 3571da177e4SLinus Torvalds 3581da177e4SLinus Torvalds /* Protocol, addresses and port numbers */ 359e7ade46aSJulius Volz u16 af; /* address family */ 360e7ade46aSJulius Volz union nf_inet_addr caddr; /* client address */ 361e7ade46aSJulius Volz union nf_inet_addr vaddr; /* virtual address */ 362e7ade46aSJulius Volz union nf_inet_addr daddr; /* destination address */ 363014d730dSAl Viro __be16 cport; 364014d730dSAl Viro __be16 vport; 365014d730dSAl Viro __be16 dport; 3661da177e4SLinus Torvalds __u16 protocol; /* Which protocol (TCP/UDP) */ 3671da177e4SLinus Torvalds 3681da177e4SLinus Torvalds /* counter and timer */ 3691da177e4SLinus Torvalds atomic_t refcnt; /* reference count */ 3701da177e4SLinus Torvalds struct timer_list timer; /* Expiration timer */ 3711da177e4SLinus Torvalds volatile unsigned long timeout; /* timeout */ 3721da177e4SLinus Torvalds 3731da177e4SLinus Torvalds /* Flags and state transition */ 3741da177e4SLinus Torvalds spinlock_t lock; /* lock for state transition */ 3751da177e4SLinus Torvalds volatile __u16 flags; /* status flags */ 3761da177e4SLinus Torvalds volatile __u16 state; /* state info */ 377efac5276SRumen G. Bogdanovski volatile __u16 old_state; /* old state, to be used for 378efac5276SRumen G. Bogdanovski * state transition triggerd 379efac5276SRumen G. Bogdanovski * synchronization 380efac5276SRumen G. Bogdanovski */ 3811da177e4SLinus Torvalds 3821da177e4SLinus Torvalds /* Control members */ 3831da177e4SLinus Torvalds struct ip_vs_conn *control; /* Master control connection */ 3841da177e4SLinus Torvalds atomic_t n_control; /* Number of controlled ones */ 3851da177e4SLinus Torvalds struct ip_vs_dest *dest; /* real server */ 3861da177e4SLinus Torvalds atomic_t in_pkts; /* incoming packet counter */ 3871da177e4SLinus Torvalds 3881da177e4SLinus Torvalds /* packet transmitter for different forwarding methods. If it 3891da177e4SLinus Torvalds mangles the packet, it must return NF_DROP or better NF_STOLEN, 3901da177e4SLinus Torvalds otherwise this must be changed to a sk_buff **. 3911da177e4SLinus Torvalds */ 3921da177e4SLinus Torvalds int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp, 3931da177e4SLinus Torvalds struct ip_vs_protocol *pp); 3941da177e4SLinus Torvalds 3951da177e4SLinus Torvalds /* Note: we can group the following members into a structure, 3961da177e4SLinus Torvalds in order to save more space, and the following members are 3971da177e4SLinus Torvalds only used in VS/NAT anyway */ 3981da177e4SLinus Torvalds struct ip_vs_app *app; /* bound ip_vs_app object */ 3991da177e4SLinus Torvalds void *app_data; /* Application private data */ 4001da177e4SLinus Torvalds struct ip_vs_seq in_seq; /* incoming seq. struct */ 4011da177e4SLinus Torvalds struct ip_vs_seq out_seq; /* outgoing seq. struct */ 4021da177e4SLinus Torvalds }; 4031da177e4SLinus Torvalds 4041da177e4SLinus Torvalds 4051da177e4SLinus Torvalds /* 406c860c6b1SJulius Volz * Extended internal versions of struct ip_vs_service_user and 407c860c6b1SJulius Volz * ip_vs_dest_user for IPv6 support. 408c860c6b1SJulius Volz * 409c860c6b1SJulius Volz * We need these to conveniently pass around service and destination 410c860c6b1SJulius Volz * options, but unfortunately, we also need to keep the old definitions to 411c860c6b1SJulius Volz * maintain userspace backwards compatibility for the setsockopt interface. 412c860c6b1SJulius Volz */ 413c860c6b1SJulius Volz struct ip_vs_service_user_kern { 414c860c6b1SJulius Volz /* virtual service addresses */ 415c860c6b1SJulius Volz u16 af; 416c860c6b1SJulius Volz u16 protocol; 417c860c6b1SJulius Volz union nf_inet_addr addr; /* virtual ip address */ 418c860c6b1SJulius Volz u16 port; 419c860c6b1SJulius Volz u32 fwmark; /* firwall mark of service */ 420c860c6b1SJulius Volz 421c860c6b1SJulius Volz /* virtual service options */ 422c860c6b1SJulius Volz char *sched_name; 423c860c6b1SJulius Volz unsigned flags; /* virtual service flags */ 424c860c6b1SJulius Volz unsigned timeout; /* persistent timeout in sec */ 425c860c6b1SJulius Volz u32 netmask; /* persistent netmask */ 426c860c6b1SJulius Volz }; 427c860c6b1SJulius Volz 428c860c6b1SJulius Volz 429c860c6b1SJulius Volz struct ip_vs_dest_user_kern { 430c860c6b1SJulius Volz /* destination server address */ 431c860c6b1SJulius Volz union nf_inet_addr addr; 432c860c6b1SJulius Volz u16 port; 433c860c6b1SJulius Volz 434c860c6b1SJulius Volz /* real server options */ 435c860c6b1SJulius Volz unsigned conn_flags; /* connection flags */ 436c860c6b1SJulius Volz int weight; /* destination weight */ 437c860c6b1SJulius Volz 438c860c6b1SJulius Volz /* thresholds for active connections */ 439c860c6b1SJulius Volz u32 u_threshold; /* upper threshold */ 440c860c6b1SJulius Volz u32 l_threshold; /* lower threshold */ 441c860c6b1SJulius Volz }; 442c860c6b1SJulius Volz 443c860c6b1SJulius Volz 444c860c6b1SJulius Volz /* 4451da177e4SLinus Torvalds * The information about the virtual service offered to the net 4461da177e4SLinus Torvalds * and the forwarding entries 4471da177e4SLinus Torvalds */ 4481da177e4SLinus Torvalds struct ip_vs_service { 4491da177e4SLinus Torvalds struct list_head s_list; /* for normal service table */ 4501da177e4SLinus Torvalds struct list_head f_list; /* for fwmark-based service table */ 4511da177e4SLinus Torvalds atomic_t refcnt; /* reference counter */ 4521da177e4SLinus Torvalds atomic_t usecnt; /* use counter */ 4531da177e4SLinus Torvalds 454e7ade46aSJulius Volz u16 af; /* address family */ 4551da177e4SLinus Torvalds __u16 protocol; /* which protocol (TCP/UDP) */ 456e7ade46aSJulius Volz union nf_inet_addr addr; /* IP address for virtual service */ 457014d730dSAl Viro __be16 port; /* port number for the service */ 4581da177e4SLinus Torvalds __u32 fwmark; /* firewall mark of the service */ 4591da177e4SLinus Torvalds unsigned flags; /* service status flags */ 4601da177e4SLinus Torvalds unsigned timeout; /* persistent timeout in ticks */ 461014d730dSAl Viro __be32 netmask; /* grouping granularity */ 4621da177e4SLinus Torvalds 4631da177e4SLinus Torvalds struct list_head destinations; /* real server d-linked list */ 4641da177e4SLinus Torvalds __u32 num_dests; /* number of servers */ 4651da177e4SLinus Torvalds struct ip_vs_stats stats; /* statistics for the service */ 4661da177e4SLinus Torvalds struct ip_vs_app *inc; /* bind conns to this app inc */ 4671da177e4SLinus Torvalds 4681da177e4SLinus Torvalds /* for scheduling */ 4691da177e4SLinus Torvalds struct ip_vs_scheduler *scheduler; /* bound scheduler object */ 4701da177e4SLinus Torvalds rwlock_t sched_lock; /* lock sched_data */ 4711da177e4SLinus Torvalds void *sched_data; /* scheduler application data */ 4721da177e4SLinus Torvalds }; 4731da177e4SLinus Torvalds 4741da177e4SLinus Torvalds 4751da177e4SLinus Torvalds /* 4761da177e4SLinus Torvalds * The real server destination forwarding entry 4771da177e4SLinus Torvalds * with ip address, port number, and so on. 4781da177e4SLinus Torvalds */ 4791da177e4SLinus Torvalds struct ip_vs_dest { 4801da177e4SLinus Torvalds struct list_head n_list; /* for the dests in the service */ 4811da177e4SLinus Torvalds struct list_head d_list; /* for table with all the dests */ 4821da177e4SLinus Torvalds 483e7ade46aSJulius Volz u16 af; /* address family */ 484e7ade46aSJulius Volz union nf_inet_addr addr; /* IP address of the server */ 485014d730dSAl Viro __be16 port; /* port number of the server */ 4861da177e4SLinus Torvalds volatile unsigned flags; /* dest status flags */ 4871da177e4SLinus Torvalds atomic_t conn_flags; /* flags to copy to conn */ 4881da177e4SLinus Torvalds atomic_t weight; /* server weight */ 4891da177e4SLinus Torvalds 4901da177e4SLinus Torvalds atomic_t refcnt; /* reference counter */ 4911da177e4SLinus Torvalds struct ip_vs_stats stats; /* statistics */ 4921da177e4SLinus Torvalds 4931da177e4SLinus Torvalds /* connection counters and thresholds */ 4941da177e4SLinus Torvalds atomic_t activeconns; /* active connections */ 4951da177e4SLinus Torvalds atomic_t inactconns; /* inactive connections */ 4961da177e4SLinus Torvalds atomic_t persistconns; /* persistent connections */ 4971da177e4SLinus Torvalds __u32 u_threshold; /* upper threshold */ 4981da177e4SLinus Torvalds __u32 l_threshold; /* lower threshold */ 4991da177e4SLinus Torvalds 5001da177e4SLinus Torvalds /* for destination cache */ 5011da177e4SLinus Torvalds spinlock_t dst_lock; /* lock of dst_cache */ 5021da177e4SLinus Torvalds struct dst_entry *dst_cache; /* destination cache entry */ 5031da177e4SLinus Torvalds u32 dst_rtos; /* RT_TOS(tos) for dst */ 5041da177e4SLinus Torvalds 5051da177e4SLinus Torvalds /* for virtual service */ 5061da177e4SLinus Torvalds struct ip_vs_service *svc; /* service it belongs to */ 5071da177e4SLinus Torvalds __u16 protocol; /* which protocol (TCP/UDP) */ 508e7ade46aSJulius Volz union nf_inet_addr vaddr; /* virtual IP address */ 509014d730dSAl Viro __be16 vport; /* virtual port number */ 5101da177e4SLinus Torvalds __u32 vfwmark; /* firewall mark of service */ 5111da177e4SLinus Torvalds }; 5121da177e4SLinus Torvalds 5131da177e4SLinus Torvalds 5141da177e4SLinus Torvalds /* 5151da177e4SLinus Torvalds * The scheduler object 5161da177e4SLinus Torvalds */ 5171da177e4SLinus Torvalds struct ip_vs_scheduler { 5181da177e4SLinus Torvalds struct list_head n_list; /* d-linked list head */ 5191da177e4SLinus Torvalds char *name; /* scheduler name */ 5201da177e4SLinus Torvalds atomic_t refcnt; /* reference counter */ 5211da177e4SLinus Torvalds struct module *module; /* THIS_MODULE/NULL */ 522b14198f6SJulius Volz #ifdef CONFIG_IP_VS_IPV6 523b14198f6SJulius Volz int supports_ipv6; /* scheduler has IPv6 support */ 524b14198f6SJulius Volz #endif 5251da177e4SLinus Torvalds 5261da177e4SLinus Torvalds /* scheduler initializing service */ 5271da177e4SLinus Torvalds int (*init_service)(struct ip_vs_service *svc); 5281da177e4SLinus Torvalds /* scheduling service finish */ 5291da177e4SLinus Torvalds int (*done_service)(struct ip_vs_service *svc); 5301da177e4SLinus Torvalds /* scheduler updating service */ 5311da177e4SLinus Torvalds int (*update_service)(struct ip_vs_service *svc); 5321da177e4SLinus Torvalds 5331da177e4SLinus Torvalds /* selecting a server from the given service */ 5341da177e4SLinus Torvalds struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc, 5351da177e4SLinus Torvalds const struct sk_buff *skb); 5361da177e4SLinus Torvalds }; 5371da177e4SLinus Torvalds 5381da177e4SLinus Torvalds 5391da177e4SLinus Torvalds /* 5401da177e4SLinus Torvalds * The application module object (a.k.a. app incarnation) 5411da177e4SLinus Torvalds */ 5421da177e4SLinus Torvalds struct ip_vs_app 5431da177e4SLinus Torvalds { 5441da177e4SLinus Torvalds struct list_head a_list; /* member in app list */ 5451da177e4SLinus Torvalds int type; /* IP_VS_APP_TYPE_xxx */ 5461da177e4SLinus Torvalds char *name; /* application module name */ 5471da177e4SLinus Torvalds __u16 protocol; 5481da177e4SLinus Torvalds struct module *module; /* THIS_MODULE/NULL */ 5491da177e4SLinus Torvalds struct list_head incs_list; /* list of incarnations */ 5501da177e4SLinus Torvalds 5511da177e4SLinus Torvalds /* members for application incarnations */ 5521da177e4SLinus Torvalds struct list_head p_list; /* member in proto app list */ 5531da177e4SLinus Torvalds struct ip_vs_app *app; /* its real application */ 554014d730dSAl Viro __be16 port; /* port number in net order */ 5551da177e4SLinus Torvalds atomic_t usecnt; /* usage counter */ 5561da177e4SLinus Torvalds 5571da177e4SLinus Torvalds /* output hook: return false if can't linearize. diff set for TCP. */ 5581da177e4SLinus Torvalds int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *, 5593db05feaSHerbert Xu struct sk_buff *, int *diff); 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds /* input hook: return false if can't linearize. diff set for TCP. */ 5621da177e4SLinus Torvalds int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *, 5633db05feaSHerbert Xu struct sk_buff *, int *diff); 5641da177e4SLinus Torvalds 5651da177e4SLinus Torvalds /* ip_vs_app initializer */ 5661da177e4SLinus Torvalds int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *); 5671da177e4SLinus Torvalds 5681da177e4SLinus Torvalds /* ip_vs_app finish */ 5691da177e4SLinus Torvalds int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *); 5701da177e4SLinus Torvalds 5711da177e4SLinus Torvalds 5721da177e4SLinus Torvalds /* not used now */ 5731da177e4SLinus Torvalds int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *, 5741da177e4SLinus Torvalds struct ip_vs_protocol *); 5751da177e4SLinus Torvalds 5761da177e4SLinus Torvalds void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *); 5771da177e4SLinus Torvalds 5781da177e4SLinus Torvalds int * timeout_table; 5791da177e4SLinus Torvalds int * timeouts; 5801da177e4SLinus Torvalds int timeouts_size; 5811da177e4SLinus Torvalds 5821da177e4SLinus Torvalds int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app, 5831da177e4SLinus Torvalds int *verdict, struct ip_vs_conn **cpp); 5841da177e4SLinus Torvalds 5851da177e4SLinus Torvalds struct ip_vs_conn * 5861da177e4SLinus Torvalds (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app, 5871da177e4SLinus Torvalds const struct iphdr *iph, unsigned int proto_off, 5881da177e4SLinus Torvalds int inverse); 5891da177e4SLinus Torvalds 5901da177e4SLinus Torvalds struct ip_vs_conn * 5911da177e4SLinus Torvalds (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app, 5921da177e4SLinus Torvalds const struct iphdr *iph, unsigned int proto_off, 5931da177e4SLinus Torvalds int inverse); 5941da177e4SLinus Torvalds 5951da177e4SLinus Torvalds int (*state_transition)(struct ip_vs_conn *cp, int direction, 5961da177e4SLinus Torvalds const struct sk_buff *skb, 5971da177e4SLinus Torvalds struct ip_vs_app *app); 5981da177e4SLinus Torvalds 5991da177e4SLinus Torvalds void (*timeout_change)(struct ip_vs_app *app, int flags); 6001da177e4SLinus Torvalds }; 6011da177e4SLinus Torvalds 6021da177e4SLinus Torvalds 6031da177e4SLinus Torvalds /* 6041da177e4SLinus Torvalds * IPVS core functions 6051da177e4SLinus Torvalds * (from ip_vs_core.c) 6061da177e4SLinus Torvalds */ 6071da177e4SLinus Torvalds extern const char *ip_vs_proto_name(unsigned proto); 6081da177e4SLinus Torvalds extern void ip_vs_init_hash_table(struct list_head *table, int rows); 609afdd6140SSven Wegener #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t))) 6101da177e4SLinus Torvalds 6111da177e4SLinus Torvalds #define IP_VS_APP_TYPE_FTP 1 6121da177e4SLinus Torvalds 6131da177e4SLinus Torvalds /* 6141da177e4SLinus Torvalds * ip_vs_conn handling functions 6151da177e4SLinus Torvalds * (from ip_vs_conn.c) 6161da177e4SLinus Torvalds */ 6171da177e4SLinus Torvalds 6181da177e4SLinus Torvalds /* 6191da177e4SLinus Torvalds * IPVS connection entry hash table 6201da177e4SLinus Torvalds */ 6211da177e4SLinus Torvalds #ifndef CONFIG_IP_VS_TAB_BITS 6221da177e4SLinus Torvalds #define CONFIG_IP_VS_TAB_BITS 12 6231da177e4SLinus Torvalds #endif 6241da177e4SLinus Torvalds /* make sure that IP_VS_CONN_TAB_BITS is located in [8, 20] */ 6251da177e4SLinus Torvalds #if CONFIG_IP_VS_TAB_BITS < 8 6261da177e4SLinus Torvalds #define IP_VS_CONN_TAB_BITS 8 6271da177e4SLinus Torvalds #endif 6281da177e4SLinus Torvalds #if CONFIG_IP_VS_TAB_BITS > 20 6291da177e4SLinus Torvalds #define IP_VS_CONN_TAB_BITS 20 6301da177e4SLinus Torvalds #endif 6311da177e4SLinus Torvalds #if 8 <= CONFIG_IP_VS_TAB_BITS && CONFIG_IP_VS_TAB_BITS <= 20 6321da177e4SLinus Torvalds #define IP_VS_CONN_TAB_BITS CONFIG_IP_VS_TAB_BITS 6331da177e4SLinus Torvalds #endif 6341da177e4SLinus Torvalds #define IP_VS_CONN_TAB_SIZE (1 << IP_VS_CONN_TAB_BITS) 6351da177e4SLinus Torvalds #define IP_VS_CONN_TAB_MASK (IP_VS_CONN_TAB_SIZE - 1) 6361da177e4SLinus Torvalds 6371da177e4SLinus Torvalds enum { 6381da177e4SLinus Torvalds IP_VS_DIR_INPUT = 0, 6391da177e4SLinus Torvalds IP_VS_DIR_OUTPUT, 6401da177e4SLinus Torvalds IP_VS_DIR_INPUT_ONLY, 6411da177e4SLinus Torvalds IP_VS_DIR_LAST, 6421da177e4SLinus Torvalds }; 6431da177e4SLinus Torvalds 6441da177e4SLinus Torvalds extern struct ip_vs_conn *ip_vs_conn_in_get 64528364a59SJulius Volz (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port, 64628364a59SJulius Volz const union nf_inet_addr *d_addr, __be16 d_port); 64728364a59SJulius Volz 64887375ab4SJulian Anastasov extern struct ip_vs_conn *ip_vs_ct_in_get 64928364a59SJulius Volz (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port, 65028364a59SJulius Volz const union nf_inet_addr *d_addr, __be16 d_port); 65128364a59SJulius Volz 6521da177e4SLinus Torvalds extern struct ip_vs_conn *ip_vs_conn_out_get 65328364a59SJulius Volz (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port, 65428364a59SJulius Volz const union nf_inet_addr *d_addr, __be16 d_port); 6551da177e4SLinus Torvalds 6561da177e4SLinus Torvalds /* put back the conn without restarting its timer */ 6571da177e4SLinus Torvalds static inline void __ip_vs_conn_put(struct ip_vs_conn *cp) 6581da177e4SLinus Torvalds { 6591da177e4SLinus Torvalds atomic_dec(&cp->refcnt); 6601da177e4SLinus Torvalds } 6611da177e4SLinus Torvalds extern void ip_vs_conn_put(struct ip_vs_conn *cp); 662014d730dSAl Viro extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport); 6631da177e4SLinus Torvalds 6641da177e4SLinus Torvalds extern struct ip_vs_conn * 66528364a59SJulius Volz ip_vs_conn_new(int af, int proto, const union nf_inet_addr *caddr, __be16 cport, 66628364a59SJulius Volz const union nf_inet_addr *vaddr, __be16 vport, 66728364a59SJulius Volz const union nf_inet_addr *daddr, __be16 dport, unsigned flags, 6681da177e4SLinus Torvalds struct ip_vs_dest *dest); 6691da177e4SLinus Torvalds extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp); 6701da177e4SLinus Torvalds 6711da177e4SLinus Torvalds extern const char * ip_vs_state_name(__u16 proto, int state); 6721da177e4SLinus Torvalds 6731da177e4SLinus Torvalds extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp); 6741da177e4SLinus Torvalds extern int ip_vs_check_template(struct ip_vs_conn *ct); 6751da177e4SLinus Torvalds extern void ip_vs_random_dropentry(void); 6761da177e4SLinus Torvalds extern int ip_vs_conn_init(void); 6771da177e4SLinus Torvalds extern void ip_vs_conn_cleanup(void); 6781da177e4SLinus Torvalds 6791da177e4SLinus Torvalds static inline void ip_vs_control_del(struct ip_vs_conn *cp) 6801da177e4SLinus Torvalds { 6811da177e4SLinus Torvalds struct ip_vs_conn *ctl_cp = cp->control; 6821da177e4SLinus Torvalds if (!ctl_cp) { 6831da177e4SLinus Torvalds IP_VS_ERR("request control DEL for uncontrolled: " 6841da177e4SLinus Torvalds "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n", 6851da177e4SLinus Torvalds NIPQUAD(cp->caddr),ntohs(cp->cport), 6861da177e4SLinus Torvalds NIPQUAD(cp->vaddr),ntohs(cp->vport)); 6871da177e4SLinus Torvalds return; 6881da177e4SLinus Torvalds } 6891da177e4SLinus Torvalds 6901da177e4SLinus Torvalds IP_VS_DBG(7, "DELeting control for: " 6911da177e4SLinus Torvalds "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n", 6921da177e4SLinus Torvalds NIPQUAD(cp->caddr),ntohs(cp->cport), 6931da177e4SLinus Torvalds NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport)); 6941da177e4SLinus Torvalds 6951da177e4SLinus Torvalds cp->control = NULL; 6961da177e4SLinus Torvalds if (atomic_read(&ctl_cp->n_control) == 0) { 6971da177e4SLinus Torvalds IP_VS_ERR("BUG control DEL with n=0 : " 6981da177e4SLinus Torvalds "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n", 6991da177e4SLinus Torvalds NIPQUAD(cp->caddr),ntohs(cp->cport), 7001da177e4SLinus Torvalds NIPQUAD(cp->vaddr),ntohs(cp->vport)); 7011da177e4SLinus Torvalds return; 7021da177e4SLinus Torvalds } 7031da177e4SLinus Torvalds atomic_dec(&ctl_cp->n_control); 7041da177e4SLinus Torvalds } 7051da177e4SLinus Torvalds 7061da177e4SLinus Torvalds static inline void 7071da177e4SLinus Torvalds ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp) 7081da177e4SLinus Torvalds { 7091da177e4SLinus Torvalds if (cp->control) { 7101da177e4SLinus Torvalds IP_VS_ERR("request control ADD for already controlled: " 7111da177e4SLinus Torvalds "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n", 7121da177e4SLinus Torvalds NIPQUAD(cp->caddr),ntohs(cp->cport), 7131da177e4SLinus Torvalds NIPQUAD(cp->vaddr),ntohs(cp->vport)); 7141da177e4SLinus Torvalds ip_vs_control_del(cp); 7151da177e4SLinus Torvalds } 7161da177e4SLinus Torvalds 7171da177e4SLinus Torvalds IP_VS_DBG(7, "ADDing control for: " 7181da177e4SLinus Torvalds "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n", 7191da177e4SLinus Torvalds NIPQUAD(cp->caddr),ntohs(cp->cport), 7201da177e4SLinus Torvalds NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport)); 7211da177e4SLinus Torvalds 7221da177e4SLinus Torvalds cp->control = ctl_cp; 7231da177e4SLinus Torvalds atomic_inc(&ctl_cp->n_control); 7241da177e4SLinus Torvalds } 7251da177e4SLinus Torvalds 7261da177e4SLinus Torvalds 7271da177e4SLinus Torvalds /* 7281da177e4SLinus Torvalds * IPVS application functions 7291da177e4SLinus Torvalds * (from ip_vs_app.c) 7301da177e4SLinus Torvalds */ 7311da177e4SLinus Torvalds #define IP_VS_APP_MAX_PORTS 8 7321da177e4SLinus Torvalds extern int register_ip_vs_app(struct ip_vs_app *app); 7331da177e4SLinus Torvalds extern void unregister_ip_vs_app(struct ip_vs_app *app); 7341da177e4SLinus Torvalds extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp); 7351da177e4SLinus Torvalds extern void ip_vs_unbind_app(struct ip_vs_conn *cp); 7361da177e4SLinus Torvalds extern int 7371da177e4SLinus Torvalds register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port); 7381da177e4SLinus Torvalds extern int ip_vs_app_inc_get(struct ip_vs_app *inc); 7391da177e4SLinus Torvalds extern void ip_vs_app_inc_put(struct ip_vs_app *inc); 7401da177e4SLinus Torvalds 7413db05feaSHerbert Xu extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb); 7423db05feaSHerbert Xu extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb); 743dd0fc66fSAl Viro extern int ip_vs_skb_replace(struct sk_buff *skb, gfp_t pri, 7441da177e4SLinus Torvalds char *o_buf, int o_len, char *n_buf, int n_len); 7451da177e4SLinus Torvalds extern int ip_vs_app_init(void); 7461da177e4SLinus Torvalds extern void ip_vs_app_cleanup(void); 7471da177e4SLinus Torvalds 7481da177e4SLinus Torvalds 7491da177e4SLinus Torvalds /* 7501da177e4SLinus Torvalds * IPVS protocol functions (from ip_vs_proto.c) 7511da177e4SLinus Torvalds */ 7521da177e4SLinus Torvalds extern int ip_vs_protocol_init(void); 7531da177e4SLinus Torvalds extern void ip_vs_protocol_cleanup(void); 7541da177e4SLinus Torvalds extern void ip_vs_protocol_timeout_change(int flags); 7551da177e4SLinus Torvalds extern int *ip_vs_create_timeout_table(int *table, int size); 7561da177e4SLinus Torvalds extern int 7571da177e4SLinus Torvalds ip_vs_set_state_timeout(int *table, int num, char **names, char *name, int to); 7581da177e4SLinus Torvalds extern void 7591da177e4SLinus Torvalds ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb, 7601da177e4SLinus Torvalds int offset, const char *msg); 7611da177e4SLinus Torvalds 7621da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_tcp; 7631da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_udp; 7641da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_icmp; 7651da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_esp; 7661da177e4SLinus Torvalds extern struct ip_vs_protocol ip_vs_protocol_ah; 7671da177e4SLinus Torvalds 7681da177e4SLinus Torvalds 7691da177e4SLinus Torvalds /* 7701da177e4SLinus Torvalds * Registering/unregistering scheduler functions 7711da177e4SLinus Torvalds * (from ip_vs_sched.c) 7721da177e4SLinus Torvalds */ 7731da177e4SLinus Torvalds extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); 7741da177e4SLinus Torvalds extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); 7751da177e4SLinus Torvalds extern int ip_vs_bind_scheduler(struct ip_vs_service *svc, 7761da177e4SLinus Torvalds struct ip_vs_scheduler *scheduler); 7771da177e4SLinus Torvalds extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc); 7781da177e4SLinus Torvalds extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name); 7791da177e4SLinus Torvalds extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler); 7801da177e4SLinus Torvalds extern struct ip_vs_conn * 7811da177e4SLinus Torvalds ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb); 7821da177e4SLinus Torvalds extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb, 7831da177e4SLinus Torvalds struct ip_vs_protocol *pp); 7841da177e4SLinus Torvalds 7851da177e4SLinus Torvalds 7861da177e4SLinus Torvalds /* 7871da177e4SLinus Torvalds * IPVS control data and functions (from ip_vs_ctl.c) 7881da177e4SLinus Torvalds */ 7891da177e4SLinus Torvalds extern int sysctl_ip_vs_cache_bypass; 7901da177e4SLinus Torvalds extern int sysctl_ip_vs_expire_nodest_conn; 7911da177e4SLinus Torvalds extern int sysctl_ip_vs_expire_quiescent_template; 7921da177e4SLinus Torvalds extern int sysctl_ip_vs_sync_threshold[2]; 7931da177e4SLinus Torvalds extern int sysctl_ip_vs_nat_icmp_send; 7941da177e4SLinus Torvalds extern struct ip_vs_stats ip_vs_stats; 7955587da55SSven Wegener extern const struct ctl_path net_vs_ctl_path[]; 7961da177e4SLinus Torvalds 7971da177e4SLinus Torvalds extern struct ip_vs_service * 7983c2e0505SJulius Volz ip_vs_service_get(int af, __u32 fwmark, __u16 protocol, 7993c2e0505SJulius Volz const union nf_inet_addr *vaddr, __be16 vport); 8001da177e4SLinus Torvalds 8011da177e4SLinus Torvalds static inline void ip_vs_service_put(struct ip_vs_service *svc) 8021da177e4SLinus Torvalds { 8031da177e4SLinus Torvalds atomic_dec(&svc->usecnt); 8041da177e4SLinus Torvalds } 8051da177e4SLinus Torvalds 8061da177e4SLinus Torvalds extern struct ip_vs_dest * 807*7937df15SJulius Volz ip_vs_lookup_real_service(int af, __u16 protocol, 808*7937df15SJulius Volz const union nf_inet_addr *daddr, __be16 dport); 809*7937df15SJulius Volz 8101da177e4SLinus Torvalds extern int ip_vs_use_count_inc(void); 8111da177e4SLinus Torvalds extern void ip_vs_use_count_dec(void); 8121da177e4SLinus Torvalds extern int ip_vs_control_init(void); 8131da177e4SLinus Torvalds extern void ip_vs_control_cleanup(void); 8141e356f9cSRumen G. Bogdanovski extern struct ip_vs_dest * 815*7937df15SJulius Volz ip_vs_find_dest(int af, const union nf_inet_addr *daddr, __be16 dport, 816*7937df15SJulius Volz const union nf_inet_addr *vaddr, __be16 vport, __u16 protocol); 8171e356f9cSRumen G. Bogdanovski extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp); 8181da177e4SLinus Torvalds 8191da177e4SLinus Torvalds 8201da177e4SLinus Torvalds /* 8211da177e4SLinus Torvalds * IPVS sync daemon data and function prototypes 8221da177e4SLinus Torvalds * (from ip_vs_sync.c) 8231da177e4SLinus Torvalds */ 8241da177e4SLinus Torvalds extern volatile int ip_vs_sync_state; 8251da177e4SLinus Torvalds extern volatile int ip_vs_master_syncid; 8261da177e4SLinus Torvalds extern volatile int ip_vs_backup_syncid; 8271da177e4SLinus Torvalds extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN]; 8281da177e4SLinus Torvalds extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN]; 8291da177e4SLinus Torvalds extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid); 8301da177e4SLinus Torvalds extern int stop_sync_thread(int state); 8311da177e4SLinus Torvalds extern void ip_vs_sync_conn(struct ip_vs_conn *cp); 8321da177e4SLinus Torvalds 8331da177e4SLinus Torvalds 8341da177e4SLinus Torvalds /* 8351da177e4SLinus Torvalds * IPVS rate estimator prototypes (from ip_vs_est.c) 8361da177e4SLinus Torvalds */ 837a919cf4bSSven Wegener extern int ip_vs_estimator_init(void); 838a919cf4bSSven Wegener extern void ip_vs_estimator_cleanup(void); 8393a14a313SSven Wegener extern void ip_vs_new_estimator(struct ip_vs_stats *stats); 8401da177e4SLinus Torvalds extern void ip_vs_kill_estimator(struct ip_vs_stats *stats); 8411da177e4SLinus Torvalds extern void ip_vs_zero_estimator(struct ip_vs_stats *stats); 8421da177e4SLinus Torvalds 8431da177e4SLinus Torvalds /* 8441da177e4SLinus Torvalds * Various IPVS packet transmitters (from ip_vs_xmit.c) 8451da177e4SLinus Torvalds */ 8461da177e4SLinus Torvalds extern int ip_vs_null_xmit 8471da177e4SLinus Torvalds (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); 8481da177e4SLinus Torvalds extern int ip_vs_bypass_xmit 8491da177e4SLinus Torvalds (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); 8501da177e4SLinus Torvalds extern int ip_vs_nat_xmit 8511da177e4SLinus Torvalds (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); 8521da177e4SLinus Torvalds extern int ip_vs_tunnel_xmit 8531da177e4SLinus Torvalds (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); 8541da177e4SLinus Torvalds extern int ip_vs_dr_xmit 8551da177e4SLinus Torvalds (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); 8561da177e4SLinus Torvalds extern int ip_vs_icmp_xmit 8571da177e4SLinus Torvalds (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset); 8581da177e4SLinus Torvalds extern void ip_vs_dst_reset(struct ip_vs_dest *dest); 8591da177e4SLinus Torvalds 860b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6 861b3cdd2a7SJulius Volz extern int ip_vs_bypass_xmit_v6 862b3cdd2a7SJulius Volz (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); 863b3cdd2a7SJulius Volz extern int ip_vs_nat_xmit_v6 864b3cdd2a7SJulius Volz (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); 865b3cdd2a7SJulius Volz extern int ip_vs_tunnel_xmit_v6 866b3cdd2a7SJulius Volz (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); 867b3cdd2a7SJulius Volz extern int ip_vs_dr_xmit_v6 868b3cdd2a7SJulius Volz (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); 869b3cdd2a7SJulius Volz extern int ip_vs_icmp_xmit_v6 870b3cdd2a7SJulius Volz (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, 871b3cdd2a7SJulius Volz int offset); 872b3cdd2a7SJulius Volz #endif 8731da177e4SLinus Torvalds 8741da177e4SLinus Torvalds /* 8751da177e4SLinus Torvalds * This is a simple mechanism to ignore packets when 8761da177e4SLinus Torvalds * we are loaded. Just set ip_vs_drop_rate to 'n' and 8771da177e4SLinus Torvalds * we start to drop 1/rate of the packets 8781da177e4SLinus Torvalds */ 8791da177e4SLinus Torvalds extern int ip_vs_drop_rate; 8801da177e4SLinus Torvalds extern int ip_vs_drop_counter; 8811da177e4SLinus Torvalds 8821da177e4SLinus Torvalds static __inline__ int ip_vs_todrop(void) 8831da177e4SLinus Torvalds { 8841da177e4SLinus Torvalds if (!ip_vs_drop_rate) return 0; 8851da177e4SLinus Torvalds if (--ip_vs_drop_counter > 0) return 0; 8861da177e4SLinus Torvalds ip_vs_drop_counter = ip_vs_drop_rate; 8871da177e4SLinus Torvalds return 1; 8881da177e4SLinus Torvalds } 8891da177e4SLinus Torvalds 8901da177e4SLinus Torvalds /* 8911da177e4SLinus Torvalds * ip_vs_fwd_tag returns the forwarding tag of the connection 8921da177e4SLinus Torvalds */ 8931da177e4SLinus Torvalds #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK) 8941da177e4SLinus Torvalds 895732db659SAdrian Bunk static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp) 8961da177e4SLinus Torvalds { 8971da177e4SLinus Torvalds char fwd; 8981da177e4SLinus Torvalds 8991da177e4SLinus Torvalds switch (IP_VS_FWD_METHOD(cp)) { 9001da177e4SLinus Torvalds case IP_VS_CONN_F_MASQ: 9011da177e4SLinus Torvalds fwd = 'M'; break; 9021da177e4SLinus Torvalds case IP_VS_CONN_F_LOCALNODE: 9031da177e4SLinus Torvalds fwd = 'L'; break; 9041da177e4SLinus Torvalds case IP_VS_CONN_F_TUNNEL: 9051da177e4SLinus Torvalds fwd = 'T'; break; 9061da177e4SLinus Torvalds case IP_VS_CONN_F_DROUTE: 9071da177e4SLinus Torvalds fwd = 'R'; break; 9081da177e4SLinus Torvalds case IP_VS_CONN_F_BYPASS: 9091da177e4SLinus Torvalds fwd = 'B'; break; 9101da177e4SLinus Torvalds default: 9111da177e4SLinus Torvalds fwd = '?'; break; 9121da177e4SLinus Torvalds } 9131da177e4SLinus Torvalds return fwd; 9141da177e4SLinus Torvalds } 9151da177e4SLinus Torvalds 9161da177e4SLinus Torvalds extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp, 9171da177e4SLinus Torvalds struct ip_vs_conn *cp, int dir); 9181da177e4SLinus Torvalds 919b3cdd2a7SJulius Volz #ifdef CONFIG_IP_VS_IPV6 920b3cdd2a7SJulius Volz extern void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp, 921b3cdd2a7SJulius Volz struct ip_vs_conn *cp, int dir); 922b3cdd2a7SJulius Volz #endif 923b3cdd2a7SJulius Volz 924b1550f22SAl Viro extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset); 9251da177e4SLinus Torvalds 926f9214b26SAl Viro static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum) 9271da177e4SLinus Torvalds { 928f9214b26SAl Viro __be32 diff[2] = { ~old, new }; 9291da177e4SLinus Torvalds 930f9214b26SAl Viro return csum_partial((char *) diff, sizeof(diff), oldsum); 931f9214b26SAl Viro } 932f9214b26SAl Viro 9330bbdd42bSJulius Volz #ifdef CONFIG_IP_VS_IPV6 9340bbdd42bSJulius Volz static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new, 9350bbdd42bSJulius Volz __wsum oldsum) 9360bbdd42bSJulius Volz { 9370bbdd42bSJulius Volz __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0], 9380bbdd42bSJulius Volz new[3], new[2], new[1], new[0] }; 9390bbdd42bSJulius Volz 9400bbdd42bSJulius Volz return csum_partial((char *) diff, sizeof(diff), oldsum); 9410bbdd42bSJulius Volz } 9420bbdd42bSJulius Volz #endif 9430bbdd42bSJulius Volz 944f9214b26SAl Viro static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum) 945f9214b26SAl Viro { 946f9214b26SAl Viro __be16 diff[2] = { ~old, new }; 947f9214b26SAl Viro 948f9214b26SAl Viro return csum_partial((char *) diff, sizeof(diff), oldsum); 9491da177e4SLinus Torvalds } 9501da177e4SLinus Torvalds 9511da177e4SLinus Torvalds #endif /* __KERNEL__ */ 9521da177e4SLinus Torvalds 953bc4768ebSJulius Volz #endif /* _NET_IP_VS_H */ 954