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