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