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