Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * IP Virtual Server |
| 3 | * data structure and functionality definitions |
| 4 | */ |
| 5 | |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 6 | #ifndef _NET_IP_VS_H |
| 7 | #define _NET_IP_VS_H |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 9 | #include <linux/ip_vs.h> /* definitions shared with userland */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 11 | /* old ipvsadm versions still include this file directly */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #ifdef __KERNEL__ |
| 13 | |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 14 | #include <asm/types.h> /* for __uXX types */ |
| 15 | |
| 16 | #include <linux/sysctl.h> /* for ctl_path */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/list.h> /* for struct list_head */ |
| 18 | #include <linux/spinlock.h> /* for struct rwlock_t */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <asm/atomic.h> /* for struct atomic_t */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/compiler.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 21 | #include <linux/timer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 23 | #include <net/checksum.h> |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 24 | #include <linux/netfilter.h> /* for union nf_inet_addr */ |
KOVACS Krisztian | 1668e01 | 2008-10-01 07:33:10 -0700 | [diff] [blame] | 25 | #include <linux/ip.h> |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 26 | #include <linux/ipv6.h> /* for struct ipv6hdr */ |
| 27 | #include <net/ipv6.h> /* for ipv6_addr_copy */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Catalin(ux) M. BOIE | 6f7edb4 | 2010-01-05 05:50:24 +0100 | [diff] [blame] | 29 | |
| 30 | /* Connections' size value needed by ip_vs_ctl.c */ |
| 31 | extern int ip_vs_conn_tab_size; |
| 32 | |
| 33 | |
Julius Volz | 64aae3c | 2008-09-02 15:55:34 +0200 | [diff] [blame] | 34 | struct ip_vs_iphdr { |
| 35 | int len; |
| 36 | __u8 protocol; |
| 37 | union nf_inet_addr saddr; |
| 38 | union nf_inet_addr daddr; |
| 39 | }; |
| 40 | |
| 41 | static inline void |
| 42 | ip_vs_fill_iphdr(int af, const void *nh, struct ip_vs_iphdr *iphdr) |
| 43 | { |
| 44 | #ifdef CONFIG_IP_VS_IPV6 |
| 45 | if (af == AF_INET6) { |
| 46 | const struct ipv6hdr *iph = nh; |
| 47 | iphdr->len = sizeof(struct ipv6hdr); |
| 48 | iphdr->protocol = iph->nexthdr; |
| 49 | ipv6_addr_copy(&iphdr->saddr.in6, &iph->saddr); |
| 50 | ipv6_addr_copy(&iphdr->daddr.in6, &iph->daddr); |
| 51 | } else |
| 52 | #endif |
| 53 | { |
| 54 | const struct iphdr *iph = nh; |
| 55 | iphdr->len = iph->ihl * 4; |
| 56 | iphdr->protocol = iph->protocol; |
| 57 | iphdr->saddr.ip = iph->saddr; |
| 58 | iphdr->daddr.ip = iph->daddr; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst, |
| 63 | const union nf_inet_addr *src) |
| 64 | { |
| 65 | #ifdef CONFIG_IP_VS_IPV6 |
| 66 | if (af == AF_INET6) |
| 67 | ipv6_addr_copy(&dst->in6, &src->in6); |
| 68 | else |
| 69 | #endif |
| 70 | dst->ip = src->ip; |
| 71 | } |
| 72 | |
| 73 | static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a, |
| 74 | const union nf_inet_addr *b) |
| 75 | { |
| 76 | #ifdef CONFIG_IP_VS_IPV6 |
| 77 | if (af == AF_INET6) |
| 78 | return ipv6_addr_equal(&a->in6, &b->in6); |
| 79 | #endif |
| 80 | return a->ip == b->ip; |
| 81 | } |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | #ifdef CONFIG_IP_VS_DEBUG |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 84 | #include <linux/net.h> |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | extern int ip_vs_get_debug_level(void); |
Julius Volz | c842a3a | 2008-09-02 15:55:35 +0200 | [diff] [blame] | 87 | |
| 88 | static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len, |
| 89 | const union nf_inet_addr *addr, |
| 90 | int *idx) |
| 91 | { |
| 92 | int len; |
| 93 | #ifdef CONFIG_IP_VS_IPV6 |
| 94 | if (af == AF_INET6) |
Harvey Harrison | 5b095d989 | 2008-10-29 12:52:50 -0700 | [diff] [blame] | 95 | len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6]", |
Harvey Harrison | 0c6ce78 | 2008-10-28 16:09:23 -0700 | [diff] [blame] | 96 | &addr->in6) + 1; |
Julius Volz | c842a3a | 2008-09-02 15:55:35 +0200 | [diff] [blame] | 97 | else |
| 98 | #endif |
Harvey Harrison | 3685f25 | 2008-10-31 00:56:49 -0700 | [diff] [blame] | 99 | len = snprintf(&buf[*idx], buf_len - *idx, "%pI4", |
| 100 | &addr->ip) + 1; |
Julius Volz | c842a3a | 2008-09-02 15:55:35 +0200 | [diff] [blame] | 101 | |
| 102 | *idx += len; |
| 103 | BUG_ON(*idx > buf_len + 1); |
| 104 | return &buf[*idx - len]; |
| 105 | } |
| 106 | |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 107 | #define IP_VS_DBG_BUF(level, msg, ...) \ |
| 108 | do { \ |
| 109 | char ip_vs_dbg_buf[160]; \ |
| 110 | int ip_vs_dbg_idx = 0; \ |
| 111 | if (level <= ip_vs_get_debug_level()) \ |
| 112 | printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ |
| 113 | } while (0) |
| 114 | #define IP_VS_ERR_BUF(msg...) \ |
| 115 | do { \ |
| 116 | char ip_vs_dbg_buf[160]; \ |
| 117 | int ip_vs_dbg_idx = 0; \ |
| 118 | pr_err(msg); \ |
| 119 | } while (0) |
Julius Volz | c842a3a | 2008-09-02 15:55:35 +0200 | [diff] [blame] | 120 | |
| 121 | /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */ |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 122 | #define IP_VS_DBG_ADDR(af, addr) \ |
| 123 | ip_vs_dbg_addr(af, ip_vs_dbg_buf, \ |
| 124 | sizeof(ip_vs_dbg_buf), addr, \ |
| 125 | &ip_vs_dbg_idx) |
Julius Volz | c842a3a | 2008-09-02 15:55:35 +0200 | [diff] [blame] | 126 | |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 127 | #define IP_VS_DBG(level, msg, ...) \ |
| 128 | do { \ |
| 129 | if (level <= ip_vs_get_debug_level()) \ |
| 130 | printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ |
| 131 | } while (0) |
| 132 | #define IP_VS_DBG_RL(msg, ...) \ |
| 133 | do { \ |
| 134 | if (net_ratelimit()) \ |
| 135 | printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \ |
| 136 | } while (0) |
| 137 | #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) \ |
| 138 | do { \ |
| 139 | if (level <= ip_vs_get_debug_level()) \ |
| 140 | pp->debug_packet(pp, skb, ofs, msg); \ |
| 141 | } while (0) |
| 142 | #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) \ |
| 143 | do { \ |
| 144 | if (level <= ip_vs_get_debug_level() && \ |
| 145 | net_ratelimit()) \ |
| 146 | pp->debug_packet(pp, skb, ofs, msg); \ |
| 147 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | #else /* NO DEBUGGING at ALL */ |
Julius Volz | c842a3a | 2008-09-02 15:55:35 +0200 | [diff] [blame] | 149 | #define IP_VS_DBG_BUF(level, msg...) do {} while (0) |
| 150 | #define IP_VS_ERR_BUF(msg...) do {} while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | #define IP_VS_DBG(level, msg...) do {} while (0) |
| 152 | #define IP_VS_DBG_RL(msg...) do {} while (0) |
| 153 | #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) do {} while (0) |
| 154 | #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) do {} while (0) |
| 155 | #endif |
| 156 | |
| 157 | #define IP_VS_BUG() BUG() |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 158 | #define IP_VS_ERR_RL(msg, ...) \ |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 159 | do { \ |
| 160 | if (net_ratelimit()) \ |
Hannes Eder | 1e3e238 | 2009-08-02 11:05:41 +0000 | [diff] [blame] | 161 | pr_err(msg, ##__VA_ARGS__); \ |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 162 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
| 164 | #ifdef CONFIG_IP_VS_DEBUG |
| 165 | #define EnterFunction(level) \ |
Hannes Eder | 9aada7a | 2009-07-30 14:29:44 -0700 | [diff] [blame] | 166 | do { \ |
| 167 | if (level <= ip_vs_get_debug_level()) \ |
| 168 | printk(KERN_DEBUG \ |
| 169 | pr_fmt("Enter: %s, %s line %i\n"), \ |
| 170 | __func__, __FILE__, __LINE__); \ |
| 171 | } while (0) |
| 172 | #define LeaveFunction(level) \ |
| 173 | do { \ |
| 174 | if (level <= ip_vs_get_debug_level()) \ |
| 175 | printk(KERN_DEBUG \ |
| 176 | pr_fmt("Leave: %s, %s line %i\n"), \ |
| 177 | __func__, __FILE__, __LINE__); \ |
| 178 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | #else |
| 180 | #define EnterFunction(level) do {} while (0) |
| 181 | #define LeaveFunction(level) do {} while (0) |
| 182 | #endif |
| 183 | |
| 184 | #define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); } |
| 185 | |
| 186 | |
| 187 | /* |
| 188 | * The port number of FTP service (in network order). |
| 189 | */ |
Harvey Harrison | f3a7c66 | 2009-02-14 22:58:35 -0800 | [diff] [blame] | 190 | #define FTPPORT cpu_to_be16(21) |
| 191 | #define FTPDATA cpu_to_be16(20) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | * TCP State Values |
| 195 | */ |
| 196 | enum { |
| 197 | IP_VS_TCP_S_NONE = 0, |
| 198 | IP_VS_TCP_S_ESTABLISHED, |
| 199 | IP_VS_TCP_S_SYN_SENT, |
| 200 | IP_VS_TCP_S_SYN_RECV, |
| 201 | IP_VS_TCP_S_FIN_WAIT, |
| 202 | IP_VS_TCP_S_TIME_WAIT, |
| 203 | IP_VS_TCP_S_CLOSE, |
| 204 | IP_VS_TCP_S_CLOSE_WAIT, |
| 205 | IP_VS_TCP_S_LAST_ACK, |
| 206 | IP_VS_TCP_S_LISTEN, |
| 207 | IP_VS_TCP_S_SYNACK, |
| 208 | IP_VS_TCP_S_LAST |
| 209 | }; |
| 210 | |
| 211 | /* |
| 212 | * UDP State Values |
| 213 | */ |
| 214 | enum { |
| 215 | IP_VS_UDP_S_NORMAL, |
| 216 | IP_VS_UDP_S_LAST, |
| 217 | }; |
| 218 | |
| 219 | /* |
| 220 | * ICMP State Values |
| 221 | */ |
| 222 | enum { |
| 223 | IP_VS_ICMP_S_NORMAL, |
| 224 | IP_VS_ICMP_S_LAST, |
| 225 | }; |
| 226 | |
| 227 | /* |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 228 | * SCTP State Values |
| 229 | */ |
| 230 | enum ip_vs_sctp_states { |
| 231 | IP_VS_SCTP_S_NONE, |
| 232 | IP_VS_SCTP_S_INIT_CLI, |
| 233 | IP_VS_SCTP_S_INIT_SER, |
| 234 | IP_VS_SCTP_S_INIT_ACK_CLI, |
| 235 | IP_VS_SCTP_S_INIT_ACK_SER, |
| 236 | IP_VS_SCTP_S_ECHO_CLI, |
| 237 | IP_VS_SCTP_S_ECHO_SER, |
| 238 | IP_VS_SCTP_S_ESTABLISHED, |
| 239 | IP_VS_SCTP_S_SHUT_CLI, |
| 240 | IP_VS_SCTP_S_SHUT_SER, |
| 241 | IP_VS_SCTP_S_SHUT_ACK_CLI, |
| 242 | IP_VS_SCTP_S_SHUT_ACK_SER, |
| 243 | IP_VS_SCTP_S_CLOSED, |
| 244 | IP_VS_SCTP_S_LAST |
| 245 | }; |
| 246 | |
| 247 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | * Delta sequence info structure |
| 249 | * Each ip_vs_conn has 2 (output AND input seq. changes). |
| 250 | * Only used in the VS/NAT. |
| 251 | */ |
| 252 | struct ip_vs_seq { |
| 253 | __u32 init_seq; /* Add delta from this seq */ |
| 254 | __u32 delta; /* Delta in sequence numbers */ |
| 255 | __u32 previous_delta; /* Delta in sequence numbers |
| 256 | before last resized pkt */ |
| 257 | }; |
| 258 | |
| 259 | |
| 260 | /* |
Sven Wegener | 3a14a31 | 2008-08-10 18:24:41 +0000 | [diff] [blame] | 261 | * IPVS statistics objects |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | */ |
Sven Wegener | 3a14a31 | 2008-08-10 18:24:41 +0000 | [diff] [blame] | 263 | struct ip_vs_estimator { |
| 264 | struct list_head list; |
| 265 | |
| 266 | u64 last_inbytes; |
| 267 | u64 last_outbytes; |
| 268 | u32 last_conns; |
| 269 | u32 last_inpkts; |
| 270 | u32 last_outpkts; |
| 271 | |
| 272 | u32 cps; |
| 273 | u32 inpps; |
| 274 | u32 outpps; |
| 275 | u32 inbps; |
| 276 | u32 outbps; |
| 277 | }; |
| 278 | |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 279 | struct ip_vs_stats { |
Sven Wegener | e9c0ce2 | 2008-09-08 13:39:04 +0200 | [diff] [blame] | 280 | struct ip_vs_stats_user ustats; /* statistics */ |
| 281 | struct ip_vs_estimator est; /* estimator */ |
Sven Wegener | 3a14a31 | 2008-08-10 18:24:41 +0000 | [diff] [blame] | 282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | spinlock_t lock; /* spin lock */ |
| 284 | }; |
| 285 | |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 286 | struct dst_entry; |
| 287 | struct iphdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | struct ip_vs_conn; |
| 289 | struct ip_vs_app; |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 290 | struct sk_buff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
| 292 | struct ip_vs_protocol { |
| 293 | struct ip_vs_protocol *next; |
| 294 | char *name; |
Julian Anastasov | 2ad17de | 2008-04-29 03:21:23 -0700 | [diff] [blame] | 295 | u16 protocol; |
| 296 | u16 num_states; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | int dont_defrag; |
| 298 | atomic_t appcnt; /* counter of proto app incs */ |
| 299 | int *timeout_table; /* protocol timeout table */ |
| 300 | |
| 301 | void (*init)(struct ip_vs_protocol *pp); |
| 302 | |
| 303 | void (*exit)(struct ip_vs_protocol *pp); |
| 304 | |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 305 | int (*conn_schedule)(int af, struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | struct ip_vs_protocol *pp, |
| 307 | int *verdict, struct ip_vs_conn **cpp); |
| 308 | |
| 309 | struct ip_vs_conn * |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 310 | (*conn_in_get)(int af, |
| 311 | const struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | struct ip_vs_protocol *pp, |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 313 | const struct ip_vs_iphdr *iph, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | unsigned int proto_off, |
| 315 | int inverse); |
| 316 | |
| 317 | struct ip_vs_conn * |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 318 | (*conn_out_get)(int af, |
| 319 | const struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | struct ip_vs_protocol *pp, |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 321 | const struct ip_vs_iphdr *iph, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | unsigned int proto_off, |
| 323 | int inverse); |
| 324 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 325 | int (*snat_handler)(struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | struct ip_vs_protocol *pp, struct ip_vs_conn *cp); |
| 327 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 328 | int (*dnat_handler)(struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | struct ip_vs_protocol *pp, struct ip_vs_conn *cp); |
| 330 | |
Julius Volz | 51ef348 | 2008-09-02 15:55:40 +0200 | [diff] [blame] | 331 | int (*csum_check)(int af, struct sk_buff *skb, |
| 332 | struct ip_vs_protocol *pp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
| 334 | const char *(*state_name)(int state); |
| 335 | |
| 336 | int (*state_transition)(struct ip_vs_conn *cp, int direction, |
| 337 | const struct sk_buff *skb, |
| 338 | struct ip_vs_protocol *pp); |
| 339 | |
| 340 | int (*register_app)(struct ip_vs_app *inc); |
| 341 | |
| 342 | void (*unregister_app)(struct ip_vs_app *inc); |
| 343 | |
| 344 | int (*app_conn_bind)(struct ip_vs_conn *cp); |
| 345 | |
| 346 | void (*debug_packet)(struct ip_vs_protocol *pp, |
| 347 | const struct sk_buff *skb, |
| 348 | int offset, |
| 349 | const char *msg); |
| 350 | |
| 351 | void (*timeout_change)(struct ip_vs_protocol *pp, int flags); |
| 352 | |
| 353 | int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to); |
| 354 | }; |
| 355 | |
| 356 | extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto); |
| 357 | |
| 358 | /* |
| 359 | * IP_VS structure allocated for each dynamically scheduled connection |
| 360 | */ |
| 361 | struct ip_vs_conn { |
| 362 | struct list_head c_list; /* hashed list heads */ |
| 363 | |
| 364 | /* Protocol, addresses and port numbers */ |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 365 | u16 af; /* address family */ |
| 366 | union nf_inet_addr caddr; /* client address */ |
| 367 | union nf_inet_addr vaddr; /* virtual address */ |
| 368 | union nf_inet_addr daddr; /* destination address */ |
Julian Anastasov | 3575792 | 2010-09-17 14:18:16 +0200 | [diff] [blame^] | 369 | volatile __u32 flags; /* status flags */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 370 | __be16 cport; |
| 371 | __be16 vport; |
| 372 | __be16 dport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | __u16 protocol; /* Which protocol (TCP/UDP) */ |
| 374 | |
| 375 | /* counter and timer */ |
| 376 | atomic_t refcnt; /* reference count */ |
| 377 | struct timer_list timer; /* Expiration timer */ |
| 378 | volatile unsigned long timeout; /* timeout */ |
| 379 | |
| 380 | /* Flags and state transition */ |
| 381 | spinlock_t lock; /* lock for state transition */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | volatile __u16 state; /* state info */ |
Rumen G. Bogdanovski | efac527 | 2007-11-07 02:36:55 -0800 | [diff] [blame] | 383 | volatile __u16 old_state; /* old state, to be used for |
| 384 | * state transition triggerd |
| 385 | * synchronization |
| 386 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
| 388 | /* Control members */ |
| 389 | struct ip_vs_conn *control; /* Master control connection */ |
| 390 | atomic_t n_control; /* Number of controlled ones */ |
| 391 | struct ip_vs_dest *dest; /* real server */ |
| 392 | atomic_t in_pkts; /* incoming packet counter */ |
| 393 | |
| 394 | /* packet transmitter for different forwarding methods. If it |
| 395 | mangles the packet, it must return NF_DROP or better NF_STOLEN, |
| 396 | otherwise this must be changed to a sk_buff **. |
| 397 | */ |
| 398 | int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp, |
| 399 | struct ip_vs_protocol *pp); |
| 400 | |
| 401 | /* Note: we can group the following members into a structure, |
| 402 | in order to save more space, and the following members are |
| 403 | only used in VS/NAT anyway */ |
| 404 | struct ip_vs_app *app; /* bound ip_vs_app object */ |
| 405 | void *app_data; /* Application private data */ |
| 406 | struct ip_vs_seq in_seq; /* incoming seq. struct */ |
| 407 | struct ip_vs_seq out_seq; /* outgoing seq. struct */ |
| 408 | }; |
| 409 | |
| 410 | |
| 411 | /* |
Julius Volz | c860c6b | 2008-09-02 15:55:36 +0200 | [diff] [blame] | 412 | * Extended internal versions of struct ip_vs_service_user and |
| 413 | * ip_vs_dest_user for IPv6 support. |
| 414 | * |
| 415 | * We need these to conveniently pass around service and destination |
| 416 | * options, but unfortunately, we also need to keep the old definitions to |
| 417 | * maintain userspace backwards compatibility for the setsockopt interface. |
| 418 | */ |
| 419 | struct ip_vs_service_user_kern { |
| 420 | /* virtual service addresses */ |
| 421 | u16 af; |
| 422 | u16 protocol; |
| 423 | union nf_inet_addr addr; /* virtual ip address */ |
| 424 | u16 port; |
| 425 | u32 fwmark; /* firwall mark of service */ |
| 426 | |
| 427 | /* virtual service options */ |
| 428 | char *sched_name; |
| 429 | unsigned flags; /* virtual service flags */ |
| 430 | unsigned timeout; /* persistent timeout in sec */ |
| 431 | u32 netmask; /* persistent netmask */ |
| 432 | }; |
| 433 | |
| 434 | |
| 435 | struct ip_vs_dest_user_kern { |
| 436 | /* destination server address */ |
| 437 | union nf_inet_addr addr; |
| 438 | u16 port; |
| 439 | |
| 440 | /* real server options */ |
| 441 | unsigned conn_flags; /* connection flags */ |
| 442 | int weight; /* destination weight */ |
| 443 | |
| 444 | /* thresholds for active connections */ |
| 445 | u32 u_threshold; /* upper threshold */ |
| 446 | u32 l_threshold; /* lower threshold */ |
| 447 | }; |
| 448 | |
| 449 | |
| 450 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | * The information about the virtual service offered to the net |
| 452 | * and the forwarding entries |
| 453 | */ |
| 454 | struct ip_vs_service { |
| 455 | struct list_head s_list; /* for normal service table */ |
| 456 | struct list_head f_list; /* for fwmark-based service table */ |
| 457 | atomic_t refcnt; /* reference counter */ |
| 458 | atomic_t usecnt; /* use counter */ |
| 459 | |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 460 | u16 af; /* address family */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | __u16 protocol; /* which protocol (TCP/UDP) */ |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 462 | union nf_inet_addr addr; /* IP address for virtual service */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 463 | __be16 port; /* port number for the service */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | __u32 fwmark; /* firewall mark of the service */ |
| 465 | unsigned flags; /* service status flags */ |
| 466 | unsigned timeout; /* persistent timeout in ticks */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 467 | __be32 netmask; /* grouping granularity */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | |
| 469 | struct list_head destinations; /* real server d-linked list */ |
| 470 | __u32 num_dests; /* number of servers */ |
| 471 | struct ip_vs_stats stats; /* statistics for the service */ |
| 472 | struct ip_vs_app *inc; /* bind conns to this app inc */ |
| 473 | |
| 474 | /* for scheduling */ |
| 475 | struct ip_vs_scheduler *scheduler; /* bound scheduler object */ |
| 476 | rwlock_t sched_lock; /* lock sched_data */ |
| 477 | void *sched_data; /* scheduler application data */ |
| 478 | }; |
| 479 | |
| 480 | |
| 481 | /* |
| 482 | * The real server destination forwarding entry |
| 483 | * with ip address, port number, and so on. |
| 484 | */ |
| 485 | struct ip_vs_dest { |
| 486 | struct list_head n_list; /* for the dests in the service */ |
| 487 | struct list_head d_list; /* for table with all the dests */ |
| 488 | |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 489 | u16 af; /* address family */ |
| 490 | union nf_inet_addr addr; /* IP address of the server */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 491 | __be16 port; /* port number of the server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | volatile unsigned flags; /* dest status flags */ |
| 493 | atomic_t conn_flags; /* flags to copy to conn */ |
| 494 | atomic_t weight; /* server weight */ |
| 495 | |
| 496 | atomic_t refcnt; /* reference counter */ |
| 497 | struct ip_vs_stats stats; /* statistics */ |
| 498 | |
| 499 | /* connection counters and thresholds */ |
| 500 | atomic_t activeconns; /* active connections */ |
| 501 | atomic_t inactconns; /* inactive connections */ |
| 502 | atomic_t persistconns; /* persistent connections */ |
| 503 | __u32 u_threshold; /* upper threshold */ |
| 504 | __u32 l_threshold; /* lower threshold */ |
| 505 | |
| 506 | /* for destination cache */ |
| 507 | spinlock_t dst_lock; /* lock of dst_cache */ |
| 508 | struct dst_entry *dst_cache; /* destination cache entry */ |
| 509 | u32 dst_rtos; /* RT_TOS(tos) for dst */ |
| 510 | |
| 511 | /* for virtual service */ |
| 512 | struct ip_vs_service *svc; /* service it belongs to */ |
| 513 | __u16 protocol; /* which protocol (TCP/UDP) */ |
Julius Volz | e7ade46 | 2008-09-02 15:55:33 +0200 | [diff] [blame] | 514 | union nf_inet_addr vaddr; /* virtual IP address */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 515 | __be16 vport; /* virtual port number */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | __u32 vfwmark; /* firewall mark of service */ |
| 517 | }; |
| 518 | |
| 519 | |
| 520 | /* |
| 521 | * The scheduler object |
| 522 | */ |
| 523 | struct ip_vs_scheduler { |
| 524 | struct list_head n_list; /* d-linked list head */ |
| 525 | char *name; /* scheduler name */ |
| 526 | atomic_t refcnt; /* reference counter */ |
| 527 | struct module *module; /* THIS_MODULE/NULL */ |
| 528 | |
| 529 | /* scheduler initializing service */ |
| 530 | int (*init_service)(struct ip_vs_service *svc); |
| 531 | /* scheduling service finish */ |
| 532 | int (*done_service)(struct ip_vs_service *svc); |
| 533 | /* scheduler updating service */ |
| 534 | int (*update_service)(struct ip_vs_service *svc); |
| 535 | |
| 536 | /* selecting a server from the given service */ |
| 537 | struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc, |
| 538 | const struct sk_buff *skb); |
| 539 | }; |
| 540 | |
| 541 | |
| 542 | /* |
| 543 | * The application module object (a.k.a. app incarnation) |
| 544 | */ |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 545 | struct ip_vs_app { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | struct list_head a_list; /* member in app list */ |
| 547 | int type; /* IP_VS_APP_TYPE_xxx */ |
| 548 | char *name; /* application module name */ |
| 549 | __u16 protocol; |
| 550 | struct module *module; /* THIS_MODULE/NULL */ |
| 551 | struct list_head incs_list; /* list of incarnations */ |
| 552 | |
| 553 | /* members for application incarnations */ |
| 554 | struct list_head p_list; /* member in proto app list */ |
| 555 | struct ip_vs_app *app; /* its real application */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 556 | __be16 port; /* port number in net order */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | atomic_t usecnt; /* usage counter */ |
| 558 | |
| 559 | /* output hook: return false if can't linearize. diff set for TCP. */ |
| 560 | int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *, |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 561 | struct sk_buff *, int *diff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | |
| 563 | /* input hook: return false if can't linearize. diff set for TCP. */ |
| 564 | int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *, |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 565 | struct sk_buff *, int *diff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | |
| 567 | /* ip_vs_app initializer */ |
| 568 | int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *); |
| 569 | |
| 570 | /* ip_vs_app finish */ |
| 571 | int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *); |
| 572 | |
| 573 | |
| 574 | /* not used now */ |
| 575 | int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *, |
| 576 | struct ip_vs_protocol *); |
| 577 | |
| 578 | void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *); |
| 579 | |
| 580 | int * timeout_table; |
| 581 | int * timeouts; |
| 582 | int timeouts_size; |
| 583 | |
| 584 | int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app, |
| 585 | int *verdict, struct ip_vs_conn **cpp); |
| 586 | |
| 587 | struct ip_vs_conn * |
| 588 | (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app, |
| 589 | const struct iphdr *iph, unsigned int proto_off, |
| 590 | int inverse); |
| 591 | |
| 592 | struct ip_vs_conn * |
| 593 | (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app, |
| 594 | const struct iphdr *iph, unsigned int proto_off, |
| 595 | int inverse); |
| 596 | |
| 597 | int (*state_transition)(struct ip_vs_conn *cp, int direction, |
| 598 | const struct sk_buff *skb, |
| 599 | struct ip_vs_app *app); |
| 600 | |
| 601 | void (*timeout_change)(struct ip_vs_app *app, int flags); |
| 602 | }; |
| 603 | |
| 604 | |
| 605 | /* |
| 606 | * IPVS core functions |
| 607 | * (from ip_vs_core.c) |
| 608 | */ |
| 609 | extern const char *ip_vs_proto_name(unsigned proto); |
| 610 | extern void ip_vs_init_hash_table(struct list_head *table, int rows); |
Sven Wegener | afdd614 | 2008-08-10 09:18:01 +0000 | [diff] [blame] | 611 | #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | #define IP_VS_APP_TYPE_FTP 1 |
| 614 | |
| 615 | /* |
| 616 | * ip_vs_conn handling functions |
| 617 | * (from ip_vs_conn.c) |
| 618 | */ |
| 619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | enum { |
| 621 | IP_VS_DIR_INPUT = 0, |
| 622 | IP_VS_DIR_OUTPUT, |
| 623 | IP_VS_DIR_INPUT_ONLY, |
| 624 | IP_VS_DIR_LAST, |
| 625 | }; |
| 626 | |
| 627 | extern struct ip_vs_conn *ip_vs_conn_in_get |
Julius Volz | 28364a5 | 2008-09-02 15:55:43 +0200 | [diff] [blame] | 628 | (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port, |
| 629 | const union nf_inet_addr *d_addr, __be16 d_port); |
| 630 | |
Julian Anastasov | 87375ab | 2005-09-14 21:08:51 -0700 | [diff] [blame] | 631 | extern struct ip_vs_conn *ip_vs_ct_in_get |
Julius Volz | 28364a5 | 2008-09-02 15:55:43 +0200 | [diff] [blame] | 632 | (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port, |
| 633 | const union nf_inet_addr *d_addr, __be16 d_port); |
| 634 | |
Simon Horman | 5c0d237 | 2010-08-02 17:12:44 +0200 | [diff] [blame] | 635 | struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb, |
| 636 | struct ip_vs_protocol *pp, |
| 637 | const struct ip_vs_iphdr *iph, |
| 638 | unsigned int proto_off, |
| 639 | int inverse); |
| 640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | extern struct ip_vs_conn *ip_vs_conn_out_get |
Julius Volz | 28364a5 | 2008-09-02 15:55:43 +0200 | [diff] [blame] | 642 | (int af, int protocol, const union nf_inet_addr *s_addr, __be16 s_port, |
| 643 | const union nf_inet_addr *d_addr, __be16 d_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Simon Horman | 5c0d237 | 2010-08-02 17:12:44 +0200 | [diff] [blame] | 645 | struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb, |
| 646 | struct ip_vs_protocol *pp, |
| 647 | const struct ip_vs_iphdr *iph, |
| 648 | unsigned int proto_off, |
| 649 | int inverse); |
| 650 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | /* put back the conn without restarting its timer */ |
| 652 | static inline void __ip_vs_conn_put(struct ip_vs_conn *cp) |
| 653 | { |
| 654 | atomic_dec(&cp->refcnt); |
| 655 | } |
| 656 | extern void ip_vs_conn_put(struct ip_vs_conn *cp); |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 657 | extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | |
| 659 | extern struct ip_vs_conn * |
Julius Volz | 28364a5 | 2008-09-02 15:55:43 +0200 | [diff] [blame] | 660 | ip_vs_conn_new(int af, int proto, const union nf_inet_addr *caddr, __be16 cport, |
| 661 | const union nf_inet_addr *vaddr, __be16 vport, |
| 662 | const union nf_inet_addr *daddr, __be16 dport, unsigned flags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | struct ip_vs_dest *dest); |
| 664 | extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp); |
| 665 | |
| 666 | extern const char * ip_vs_state_name(__u16 proto, int state); |
| 667 | |
| 668 | extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp); |
| 669 | extern int ip_vs_check_template(struct ip_vs_conn *ct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | extern void ip_vs_random_dropentry(void); |
| 671 | extern int ip_vs_conn_init(void); |
| 672 | extern void ip_vs_conn_cleanup(void); |
| 673 | |
| 674 | static inline void ip_vs_control_del(struct ip_vs_conn *cp) |
| 675 | { |
| 676 | struct ip_vs_conn *ctl_cp = cp->control; |
| 677 | if (!ctl_cp) { |
Julius Volz | cfc78c5 | 2008-09-02 15:55:53 +0200 | [diff] [blame] | 678 | IP_VS_ERR_BUF("request control DEL for uncontrolled: " |
| 679 | "%s:%d to %s:%d\n", |
| 680 | IP_VS_DBG_ADDR(cp->af, &cp->caddr), |
| 681 | ntohs(cp->cport), |
| 682 | IP_VS_DBG_ADDR(cp->af, &cp->vaddr), |
| 683 | ntohs(cp->vport)); |
| 684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | return; |
| 686 | } |
| 687 | |
Julius Volz | cfc78c5 | 2008-09-02 15:55:53 +0200 | [diff] [blame] | 688 | IP_VS_DBG_BUF(7, "DELeting control for: " |
| 689 | "cp.dst=%s:%d ctl_cp.dst=%s:%d\n", |
| 690 | IP_VS_DBG_ADDR(cp->af, &cp->caddr), |
| 691 | ntohs(cp->cport), |
| 692 | IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr), |
| 693 | ntohs(ctl_cp->cport)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
| 695 | cp->control = NULL; |
| 696 | if (atomic_read(&ctl_cp->n_control) == 0) { |
Julius Volz | cfc78c5 | 2008-09-02 15:55:53 +0200 | [diff] [blame] | 697 | IP_VS_ERR_BUF("BUG control DEL with n=0 : " |
| 698 | "%s:%d to %s:%d\n", |
| 699 | IP_VS_DBG_ADDR(cp->af, &cp->caddr), |
| 700 | ntohs(cp->cport), |
| 701 | IP_VS_DBG_ADDR(cp->af, &cp->vaddr), |
| 702 | ntohs(cp->vport)); |
| 703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | return; |
| 705 | } |
| 706 | atomic_dec(&ctl_cp->n_control); |
| 707 | } |
| 708 | |
| 709 | static inline void |
| 710 | ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp) |
| 711 | { |
| 712 | if (cp->control) { |
Julius Volz | cfc78c5 | 2008-09-02 15:55:53 +0200 | [diff] [blame] | 713 | IP_VS_ERR_BUF("request control ADD for already controlled: " |
| 714 | "%s:%d to %s:%d\n", |
| 715 | IP_VS_DBG_ADDR(cp->af, &cp->caddr), |
| 716 | ntohs(cp->cport), |
| 717 | IP_VS_DBG_ADDR(cp->af, &cp->vaddr), |
| 718 | ntohs(cp->vport)); |
| 719 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | ip_vs_control_del(cp); |
| 721 | } |
| 722 | |
Julius Volz | cfc78c5 | 2008-09-02 15:55:53 +0200 | [diff] [blame] | 723 | IP_VS_DBG_BUF(7, "ADDing control for: " |
| 724 | "cp.dst=%s:%d ctl_cp.dst=%s:%d\n", |
| 725 | IP_VS_DBG_ADDR(cp->af, &cp->caddr), |
| 726 | ntohs(cp->cport), |
| 727 | IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr), |
| 728 | ntohs(ctl_cp->cport)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | |
| 730 | cp->control = ctl_cp; |
| 731 | atomic_inc(&ctl_cp->n_control); |
| 732 | } |
| 733 | |
| 734 | |
| 735 | /* |
| 736 | * IPVS application functions |
| 737 | * (from ip_vs_app.c) |
| 738 | */ |
| 739 | #define IP_VS_APP_MAX_PORTS 8 |
| 740 | extern int register_ip_vs_app(struct ip_vs_app *app); |
| 741 | extern void unregister_ip_vs_app(struct ip_vs_app *app); |
| 742 | extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 743 | extern void ip_vs_unbind_app(struct ip_vs_conn *cp); |
| 744 | extern int |
| 745 | register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port); |
| 746 | extern int ip_vs_app_inc_get(struct ip_vs_app *inc); |
| 747 | extern void ip_vs_app_inc_put(struct ip_vs_app *inc); |
| 748 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 749 | extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb); |
| 750 | extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | extern int ip_vs_app_init(void); |
| 752 | extern void ip_vs_app_cleanup(void); |
| 753 | |
| 754 | |
| 755 | /* |
| 756 | * IPVS protocol functions (from ip_vs_proto.c) |
| 757 | */ |
| 758 | extern int ip_vs_protocol_init(void); |
| 759 | extern void ip_vs_protocol_cleanup(void); |
| 760 | extern void ip_vs_protocol_timeout_change(int flags); |
| 761 | extern int *ip_vs_create_timeout_table(int *table, int size); |
| 762 | extern int |
Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 763 | ip_vs_set_state_timeout(int *table, int num, const char *const *names, |
| 764 | const char *name, int to); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | extern void |
| 766 | ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb, |
| 767 | int offset, const char *msg); |
| 768 | |
| 769 | extern struct ip_vs_protocol ip_vs_protocol_tcp; |
| 770 | extern struct ip_vs_protocol ip_vs_protocol_udp; |
| 771 | extern struct ip_vs_protocol ip_vs_protocol_icmp; |
| 772 | extern struct ip_vs_protocol ip_vs_protocol_esp; |
| 773 | extern struct ip_vs_protocol ip_vs_protocol_ah; |
Venkata Mohan Reddy | 2906f66 | 2010-02-18 12:31:05 +0100 | [diff] [blame] | 774 | extern struct ip_vs_protocol ip_vs_protocol_sctp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | |
| 776 | /* |
| 777 | * Registering/unregistering scheduler functions |
| 778 | * (from ip_vs_sched.c) |
| 779 | */ |
| 780 | extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); |
| 781 | extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); |
| 782 | extern int ip_vs_bind_scheduler(struct ip_vs_service *svc, |
| 783 | struct ip_vs_scheduler *scheduler); |
| 784 | extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc); |
| 785 | extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name); |
| 786 | extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler); |
| 787 | extern struct ip_vs_conn * |
| 788 | ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb); |
| 789 | extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb, |
| 790 | struct ip_vs_protocol *pp); |
| 791 | |
| 792 | |
| 793 | /* |
| 794 | * IPVS control data and functions (from ip_vs_ctl.c) |
| 795 | */ |
| 796 | extern int sysctl_ip_vs_cache_bypass; |
| 797 | extern int sysctl_ip_vs_expire_nodest_conn; |
| 798 | extern int sysctl_ip_vs_expire_quiescent_template; |
| 799 | extern int sysctl_ip_vs_sync_threshold[2]; |
| 800 | extern int sysctl_ip_vs_nat_icmp_send; |
| 801 | extern struct ip_vs_stats ip_vs_stats; |
Sven Wegener | 5587da5 | 2008-08-10 18:24:40 +0000 | [diff] [blame] | 802 | extern const struct ctl_path net_vs_ctl_path[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
| 804 | extern struct ip_vs_service * |
Julius Volz | 3c2e050 | 2008-09-02 15:55:38 +0200 | [diff] [blame] | 805 | ip_vs_service_get(int af, __u32 fwmark, __u16 protocol, |
| 806 | const union nf_inet_addr *vaddr, __be16 vport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
| 808 | static inline void ip_vs_service_put(struct ip_vs_service *svc) |
| 809 | { |
| 810 | atomic_dec(&svc->usecnt); |
| 811 | } |
| 812 | |
| 813 | extern struct ip_vs_dest * |
Julius Volz | 7937df1 | 2008-09-02 15:55:48 +0200 | [diff] [blame] | 814 | ip_vs_lookup_real_service(int af, __u16 protocol, |
| 815 | const union nf_inet_addr *daddr, __be16 dport); |
| 816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | extern int ip_vs_use_count_inc(void); |
| 818 | extern void ip_vs_use_count_dec(void); |
| 819 | extern int ip_vs_control_init(void); |
| 820 | extern void ip_vs_control_cleanup(void); |
Rumen G. Bogdanovski | 1e356f9 | 2007-11-07 02:35:54 -0800 | [diff] [blame] | 821 | extern struct ip_vs_dest * |
Julius Volz | 7937df1 | 2008-09-02 15:55:48 +0200 | [diff] [blame] | 822 | ip_vs_find_dest(int af, const union nf_inet_addr *daddr, __be16 dport, |
| 823 | const union nf_inet_addr *vaddr, __be16 vport, __u16 protocol); |
Rumen G. Bogdanovski | 1e356f9 | 2007-11-07 02:35:54 -0800 | [diff] [blame] | 824 | extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | |
| 826 | |
| 827 | /* |
| 828 | * IPVS sync daemon data and function prototypes |
| 829 | * (from ip_vs_sync.c) |
| 830 | */ |
| 831 | extern volatile int ip_vs_sync_state; |
| 832 | extern volatile int ip_vs_master_syncid; |
| 833 | extern volatile int ip_vs_backup_syncid; |
| 834 | extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN]; |
| 835 | extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN]; |
| 836 | extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid); |
| 837 | extern int stop_sync_thread(int state); |
| 838 | extern void ip_vs_sync_conn(struct ip_vs_conn *cp); |
| 839 | |
| 840 | |
| 841 | /* |
| 842 | * IPVS rate estimator prototypes (from ip_vs_est.c) |
| 843 | */ |
Sven Wegener | a919cf4 | 2008-08-14 00:47:16 +0200 | [diff] [blame] | 844 | extern int ip_vs_estimator_init(void); |
| 845 | extern void ip_vs_estimator_cleanup(void); |
Sven Wegener | 3a14a31 | 2008-08-10 18:24:41 +0000 | [diff] [blame] | 846 | extern void ip_vs_new_estimator(struct ip_vs_stats *stats); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | extern void ip_vs_kill_estimator(struct ip_vs_stats *stats); |
| 848 | extern void ip_vs_zero_estimator(struct ip_vs_stats *stats); |
| 849 | |
| 850 | /* |
| 851 | * Various IPVS packet transmitters (from ip_vs_xmit.c) |
| 852 | */ |
| 853 | extern int ip_vs_null_xmit |
| 854 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 855 | extern int ip_vs_bypass_xmit |
| 856 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 857 | extern int ip_vs_nat_xmit |
| 858 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 859 | extern int ip_vs_tunnel_xmit |
| 860 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 861 | extern int ip_vs_dr_xmit |
| 862 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 863 | extern int ip_vs_icmp_xmit |
| 864 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset); |
| 865 | extern void ip_vs_dst_reset(struct ip_vs_dest *dest); |
| 866 | |
Julius Volz | b3cdd2a | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 867 | #ifdef CONFIG_IP_VS_IPV6 |
| 868 | extern int ip_vs_bypass_xmit_v6 |
| 869 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 870 | extern int ip_vs_nat_xmit_v6 |
| 871 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 872 | extern int ip_vs_tunnel_xmit_v6 |
| 873 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 874 | extern int ip_vs_dr_xmit_v6 |
| 875 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 876 | extern int ip_vs_icmp_xmit_v6 |
| 877 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, |
| 878 | int offset); |
| 879 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
| 881 | /* |
| 882 | * This is a simple mechanism to ignore packets when |
| 883 | * we are loaded. Just set ip_vs_drop_rate to 'n' and |
| 884 | * we start to drop 1/rate of the packets |
| 885 | */ |
| 886 | extern int ip_vs_drop_rate; |
| 887 | extern int ip_vs_drop_counter; |
| 888 | |
| 889 | static __inline__ int ip_vs_todrop(void) |
| 890 | { |
| 891 | if (!ip_vs_drop_rate) return 0; |
| 892 | if (--ip_vs_drop_counter > 0) return 0; |
| 893 | ip_vs_drop_counter = ip_vs_drop_rate; |
| 894 | return 1; |
| 895 | } |
| 896 | |
| 897 | /* |
| 898 | * ip_vs_fwd_tag returns the forwarding tag of the connection |
| 899 | */ |
| 900 | #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK) |
| 901 | |
Adrian Bunk | 732db65 | 2005-09-01 17:40:26 -0700 | [diff] [blame] | 902 | static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | { |
| 904 | char fwd; |
| 905 | |
| 906 | switch (IP_VS_FWD_METHOD(cp)) { |
| 907 | case IP_VS_CONN_F_MASQ: |
| 908 | fwd = 'M'; break; |
| 909 | case IP_VS_CONN_F_LOCALNODE: |
| 910 | fwd = 'L'; break; |
| 911 | case IP_VS_CONN_F_TUNNEL: |
| 912 | fwd = 'T'; break; |
| 913 | case IP_VS_CONN_F_DROUTE: |
| 914 | fwd = 'R'; break; |
| 915 | case IP_VS_CONN_F_BYPASS: |
| 916 | fwd = 'B'; break; |
| 917 | default: |
| 918 | fwd = '?'; break; |
| 919 | } |
| 920 | return fwd; |
| 921 | } |
| 922 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp, |
Julius Volz | b3cdd2a | 2008-09-02 15:55:45 +0200 | [diff] [blame] | 924 | struct ip_vs_conn *cp, int dir); |
| 925 | |
| 926 | #ifdef CONFIG_IP_VS_IPV6 |
| 927 | extern void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp, |
| 928 | struct ip_vs_conn *cp, int dir); |
| 929 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
Al Viro | b1550f2 | 2006-11-14 21:37:50 -0800 | [diff] [blame] | 931 | extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | |
Al Viro | f9214b2 | 2006-11-16 02:41:18 -0800 | [diff] [blame] | 933 | static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | { |
Al Viro | f9214b2 | 2006-11-16 02:41:18 -0800 | [diff] [blame] | 935 | __be32 diff[2] = { ~old, new }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | |
Joe Perches | 07f0757 | 2008-11-19 15:44:53 -0800 | [diff] [blame] | 937 | return csum_partial(diff, sizeof(diff), oldsum); |
Al Viro | f9214b2 | 2006-11-16 02:41:18 -0800 | [diff] [blame] | 938 | } |
| 939 | |
Julius Volz | 0bbdd42 | 2008-09-02 15:55:42 +0200 | [diff] [blame] | 940 | #ifdef CONFIG_IP_VS_IPV6 |
| 941 | static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new, |
| 942 | __wsum oldsum) |
| 943 | { |
| 944 | __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0], |
| 945 | new[3], new[2], new[1], new[0] }; |
| 946 | |
Joe Perches | 07f0757 | 2008-11-19 15:44:53 -0800 | [diff] [blame] | 947 | return csum_partial(diff, sizeof(diff), oldsum); |
Julius Volz | 0bbdd42 | 2008-09-02 15:55:42 +0200 | [diff] [blame] | 948 | } |
| 949 | #endif |
| 950 | |
Al Viro | f9214b2 | 2006-11-16 02:41:18 -0800 | [diff] [blame] | 951 | static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum) |
| 952 | { |
| 953 | __be16 diff[2] = { ~old, new }; |
| 954 | |
Joe Perches | 07f0757 | 2008-11-19 15:44:53 -0800 | [diff] [blame] | 955 | return csum_partial(diff, sizeof(diff), oldsum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | } |
| 957 | |
Julian Anastasov | 6523ce1 | 2010-09-05 18:02:29 +0000 | [diff] [blame] | 958 | extern void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp, |
| 959 | int outin); |
| 960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | #endif /* __KERNEL__ */ |
| 962 | |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 963 | #endif /* _NET_IP_VS_H */ |