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