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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
| 25 | #ifdef CONFIG_IP_VS_DEBUG |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 26 | #include <linux/net.h> |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | extern int ip_vs_get_debug_level(void); |
| 29 | #define IP_VS_DBG(level, msg...) \ |
| 30 | do { \ |
| 31 | if (level <= ip_vs_get_debug_level()) \ |
| 32 | printk(KERN_DEBUG "IPVS: " msg); \ |
| 33 | } while (0) |
| 34 | #define IP_VS_DBG_RL(msg...) \ |
| 35 | do { \ |
| 36 | if (net_ratelimit()) \ |
| 37 | printk(KERN_DEBUG "IPVS: " msg); \ |
| 38 | } while (0) |
| 39 | #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) \ |
| 40 | do { \ |
| 41 | if (level <= ip_vs_get_debug_level()) \ |
| 42 | pp->debug_packet(pp, skb, ofs, msg); \ |
| 43 | } while (0) |
| 44 | #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) \ |
| 45 | do { \ |
| 46 | if (level <= ip_vs_get_debug_level() && \ |
| 47 | net_ratelimit()) \ |
| 48 | pp->debug_packet(pp, skb, ofs, msg); \ |
| 49 | } while (0) |
| 50 | #else /* NO DEBUGGING at ALL */ |
| 51 | #define IP_VS_DBG(level, msg...) do {} while (0) |
| 52 | #define IP_VS_DBG_RL(msg...) do {} while (0) |
| 53 | #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) do {} while (0) |
| 54 | #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) do {} while (0) |
| 55 | #endif |
| 56 | |
| 57 | #define IP_VS_BUG() BUG() |
| 58 | #define IP_VS_ERR(msg...) printk(KERN_ERR "IPVS: " msg) |
| 59 | #define IP_VS_INFO(msg...) printk(KERN_INFO "IPVS: " msg) |
| 60 | #define IP_VS_WARNING(msg...) \ |
| 61 | printk(KERN_WARNING "IPVS: " msg) |
| 62 | #define IP_VS_ERR_RL(msg...) \ |
| 63 | do { \ |
| 64 | if (net_ratelimit()) \ |
| 65 | printk(KERN_ERR "IPVS: " msg); \ |
| 66 | } while (0) |
| 67 | |
| 68 | #ifdef CONFIG_IP_VS_DEBUG |
| 69 | #define EnterFunction(level) \ |
| 70 | do { \ |
| 71 | if (level <= ip_vs_get_debug_level()) \ |
| 72 | printk(KERN_DEBUG "Enter: %s, %s line %i\n", \ |
| 73 | __FUNCTION__, __FILE__, __LINE__); \ |
| 74 | } while (0) |
| 75 | #define LeaveFunction(level) \ |
| 76 | do { \ |
| 77 | if (level <= ip_vs_get_debug_level()) \ |
| 78 | printk(KERN_DEBUG "Leave: %s, %s line %i\n", \ |
| 79 | __FUNCTION__, __FILE__, __LINE__); \ |
| 80 | } while (0) |
| 81 | #else |
| 82 | #define EnterFunction(level) do {} while (0) |
| 83 | #define LeaveFunction(level) do {} while (0) |
| 84 | #endif |
| 85 | |
| 86 | #define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); } |
| 87 | |
| 88 | |
| 89 | /* |
| 90 | * The port number of FTP service (in network order). |
| 91 | */ |
| 92 | #define FTPPORT __constant_htons(21) |
| 93 | #define FTPDATA __constant_htons(20) |
| 94 | |
| 95 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | * TCP State Values |
| 97 | */ |
| 98 | enum { |
| 99 | IP_VS_TCP_S_NONE = 0, |
| 100 | IP_VS_TCP_S_ESTABLISHED, |
| 101 | IP_VS_TCP_S_SYN_SENT, |
| 102 | IP_VS_TCP_S_SYN_RECV, |
| 103 | IP_VS_TCP_S_FIN_WAIT, |
| 104 | IP_VS_TCP_S_TIME_WAIT, |
| 105 | IP_VS_TCP_S_CLOSE, |
| 106 | IP_VS_TCP_S_CLOSE_WAIT, |
| 107 | IP_VS_TCP_S_LAST_ACK, |
| 108 | IP_VS_TCP_S_LISTEN, |
| 109 | IP_VS_TCP_S_SYNACK, |
| 110 | IP_VS_TCP_S_LAST |
| 111 | }; |
| 112 | |
| 113 | /* |
| 114 | * UDP State Values |
| 115 | */ |
| 116 | enum { |
| 117 | IP_VS_UDP_S_NORMAL, |
| 118 | IP_VS_UDP_S_LAST, |
| 119 | }; |
| 120 | |
| 121 | /* |
| 122 | * ICMP State Values |
| 123 | */ |
| 124 | enum { |
| 125 | IP_VS_ICMP_S_NORMAL, |
| 126 | IP_VS_ICMP_S_LAST, |
| 127 | }; |
| 128 | |
| 129 | /* |
| 130 | * Delta sequence info structure |
| 131 | * Each ip_vs_conn has 2 (output AND input seq. changes). |
| 132 | * Only used in the VS/NAT. |
| 133 | */ |
| 134 | struct ip_vs_seq { |
| 135 | __u32 init_seq; /* Add delta from this seq */ |
| 136 | __u32 delta; /* Delta in sequence numbers */ |
| 137 | __u32 previous_delta; /* Delta in sequence numbers |
| 138 | before last resized pkt */ |
| 139 | }; |
| 140 | |
| 141 | |
| 142 | /* |
| 143 | * IPVS statistics object |
| 144 | */ |
| 145 | struct ip_vs_stats |
| 146 | { |
| 147 | __u32 conns; /* connections scheduled */ |
| 148 | __u32 inpkts; /* incoming packets */ |
| 149 | __u32 outpkts; /* outgoing packets */ |
| 150 | __u64 inbytes; /* incoming bytes */ |
| 151 | __u64 outbytes; /* outgoing bytes */ |
| 152 | |
| 153 | __u32 cps; /* current connection rate */ |
| 154 | __u32 inpps; /* current in packet rate */ |
| 155 | __u32 outpps; /* current out packet rate */ |
| 156 | __u32 inbps; /* current in byte rate */ |
| 157 | __u32 outbps; /* current out byte rate */ |
| 158 | |
| 159 | spinlock_t lock; /* spin lock */ |
| 160 | }; |
| 161 | |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 162 | struct dst_entry; |
| 163 | struct iphdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | struct ip_vs_conn; |
| 165 | struct ip_vs_app; |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 166 | struct sk_buff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | struct ip_vs_protocol { |
| 169 | struct ip_vs_protocol *next; |
| 170 | char *name; |
Julian Anastasov | 2ad17de | 2008-04-29 03:21:23 -0700 | [diff] [blame] | 171 | u16 protocol; |
| 172 | u16 num_states; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | int dont_defrag; |
| 174 | atomic_t appcnt; /* counter of proto app incs */ |
| 175 | int *timeout_table; /* protocol timeout table */ |
| 176 | |
| 177 | void (*init)(struct ip_vs_protocol *pp); |
| 178 | |
| 179 | void (*exit)(struct ip_vs_protocol *pp); |
| 180 | |
| 181 | int (*conn_schedule)(struct sk_buff *skb, |
| 182 | struct ip_vs_protocol *pp, |
| 183 | int *verdict, struct ip_vs_conn **cpp); |
| 184 | |
| 185 | struct ip_vs_conn * |
| 186 | (*conn_in_get)(const struct sk_buff *skb, |
| 187 | struct ip_vs_protocol *pp, |
| 188 | const struct iphdr *iph, |
| 189 | unsigned int proto_off, |
| 190 | int inverse); |
| 191 | |
| 192 | struct ip_vs_conn * |
| 193 | (*conn_out_get)(const struct sk_buff *skb, |
| 194 | struct ip_vs_protocol *pp, |
| 195 | const struct iphdr *iph, |
| 196 | unsigned int proto_off, |
| 197 | int inverse); |
| 198 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 199 | int (*snat_handler)(struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | struct ip_vs_protocol *pp, struct ip_vs_conn *cp); |
| 201 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 202 | int (*dnat_handler)(struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | struct ip_vs_protocol *pp, struct ip_vs_conn *cp); |
| 204 | |
| 205 | int (*csum_check)(struct sk_buff *skb, struct ip_vs_protocol *pp); |
| 206 | |
| 207 | const char *(*state_name)(int state); |
| 208 | |
| 209 | int (*state_transition)(struct ip_vs_conn *cp, int direction, |
| 210 | const struct sk_buff *skb, |
| 211 | struct ip_vs_protocol *pp); |
| 212 | |
| 213 | int (*register_app)(struct ip_vs_app *inc); |
| 214 | |
| 215 | void (*unregister_app)(struct ip_vs_app *inc); |
| 216 | |
| 217 | int (*app_conn_bind)(struct ip_vs_conn *cp); |
| 218 | |
| 219 | void (*debug_packet)(struct ip_vs_protocol *pp, |
| 220 | const struct sk_buff *skb, |
| 221 | int offset, |
| 222 | const char *msg); |
| 223 | |
| 224 | void (*timeout_change)(struct ip_vs_protocol *pp, int flags); |
| 225 | |
| 226 | int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to); |
| 227 | }; |
| 228 | |
| 229 | extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto); |
| 230 | |
| 231 | /* |
| 232 | * IP_VS structure allocated for each dynamically scheduled connection |
| 233 | */ |
| 234 | struct ip_vs_conn { |
| 235 | struct list_head c_list; /* hashed list heads */ |
| 236 | |
| 237 | /* Protocol, addresses and port numbers */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 238 | __be32 caddr; /* client address */ |
| 239 | __be32 vaddr; /* virtual address */ |
| 240 | __be32 daddr; /* destination address */ |
| 241 | __be16 cport; |
| 242 | __be16 vport; |
| 243 | __be16 dport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | __u16 protocol; /* Which protocol (TCP/UDP) */ |
| 245 | |
| 246 | /* counter and timer */ |
| 247 | atomic_t refcnt; /* reference count */ |
| 248 | struct timer_list timer; /* Expiration timer */ |
| 249 | volatile unsigned long timeout; /* timeout */ |
| 250 | |
| 251 | /* Flags and state transition */ |
| 252 | spinlock_t lock; /* lock for state transition */ |
| 253 | volatile __u16 flags; /* status flags */ |
| 254 | volatile __u16 state; /* state info */ |
Rumen G. Bogdanovski | efac527 | 2007-11-07 02:36:55 -0800 | [diff] [blame] | 255 | volatile __u16 old_state; /* old state, to be used for |
| 256 | * state transition triggerd |
| 257 | * synchronization |
| 258 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
| 260 | /* Control members */ |
| 261 | struct ip_vs_conn *control; /* Master control connection */ |
| 262 | atomic_t n_control; /* Number of controlled ones */ |
| 263 | struct ip_vs_dest *dest; /* real server */ |
| 264 | atomic_t in_pkts; /* incoming packet counter */ |
| 265 | |
| 266 | /* packet transmitter for different forwarding methods. If it |
| 267 | mangles the packet, it must return NF_DROP or better NF_STOLEN, |
| 268 | otherwise this must be changed to a sk_buff **. |
| 269 | */ |
| 270 | int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp, |
| 271 | struct ip_vs_protocol *pp); |
| 272 | |
| 273 | /* Note: we can group the following members into a structure, |
| 274 | in order to save more space, and the following members are |
| 275 | only used in VS/NAT anyway */ |
| 276 | struct ip_vs_app *app; /* bound ip_vs_app object */ |
| 277 | void *app_data; /* Application private data */ |
| 278 | struct ip_vs_seq in_seq; /* incoming seq. struct */ |
| 279 | struct ip_vs_seq out_seq; /* outgoing seq. struct */ |
| 280 | }; |
| 281 | |
| 282 | |
| 283 | /* |
| 284 | * The information about the virtual service offered to the net |
| 285 | * and the forwarding entries |
| 286 | */ |
| 287 | struct ip_vs_service { |
| 288 | struct list_head s_list; /* for normal service table */ |
| 289 | struct list_head f_list; /* for fwmark-based service table */ |
| 290 | atomic_t refcnt; /* reference counter */ |
| 291 | atomic_t usecnt; /* use counter */ |
| 292 | |
| 293 | __u16 protocol; /* which protocol (TCP/UDP) */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 294 | __be32 addr; /* IP address for virtual service */ |
| 295 | __be16 port; /* port number for the service */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | __u32 fwmark; /* firewall mark of the service */ |
| 297 | unsigned flags; /* service status flags */ |
| 298 | unsigned timeout; /* persistent timeout in ticks */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 299 | __be32 netmask; /* grouping granularity */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | struct list_head destinations; /* real server d-linked list */ |
| 302 | __u32 num_dests; /* number of servers */ |
| 303 | struct ip_vs_stats stats; /* statistics for the service */ |
| 304 | struct ip_vs_app *inc; /* bind conns to this app inc */ |
| 305 | |
| 306 | /* for scheduling */ |
| 307 | struct ip_vs_scheduler *scheduler; /* bound scheduler object */ |
| 308 | rwlock_t sched_lock; /* lock sched_data */ |
| 309 | void *sched_data; /* scheduler application data */ |
| 310 | }; |
| 311 | |
| 312 | |
| 313 | /* |
| 314 | * The real server destination forwarding entry |
| 315 | * with ip address, port number, and so on. |
| 316 | */ |
| 317 | struct ip_vs_dest { |
| 318 | struct list_head n_list; /* for the dests in the service */ |
| 319 | struct list_head d_list; /* for table with all the dests */ |
| 320 | |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 321 | __be32 addr; /* IP address of the server */ |
| 322 | __be16 port; /* port number of the server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | volatile unsigned flags; /* dest status flags */ |
| 324 | atomic_t conn_flags; /* flags to copy to conn */ |
| 325 | atomic_t weight; /* server weight */ |
| 326 | |
| 327 | atomic_t refcnt; /* reference counter */ |
| 328 | struct ip_vs_stats stats; /* statistics */ |
| 329 | |
| 330 | /* connection counters and thresholds */ |
| 331 | atomic_t activeconns; /* active connections */ |
| 332 | atomic_t inactconns; /* inactive connections */ |
| 333 | atomic_t persistconns; /* persistent connections */ |
| 334 | __u32 u_threshold; /* upper threshold */ |
| 335 | __u32 l_threshold; /* lower threshold */ |
| 336 | |
| 337 | /* for destination cache */ |
| 338 | spinlock_t dst_lock; /* lock of dst_cache */ |
| 339 | struct dst_entry *dst_cache; /* destination cache entry */ |
| 340 | u32 dst_rtos; /* RT_TOS(tos) for dst */ |
| 341 | |
| 342 | /* for virtual service */ |
| 343 | struct ip_vs_service *svc; /* service it belongs to */ |
| 344 | __u16 protocol; /* which protocol (TCP/UDP) */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 345 | __be32 vaddr; /* virtual IP address */ |
| 346 | __be16 vport; /* virtual port number */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | __u32 vfwmark; /* firewall mark of service */ |
| 348 | }; |
| 349 | |
| 350 | |
| 351 | /* |
| 352 | * The scheduler object |
| 353 | */ |
| 354 | struct ip_vs_scheduler { |
| 355 | struct list_head n_list; /* d-linked list head */ |
| 356 | char *name; /* scheduler name */ |
| 357 | atomic_t refcnt; /* reference counter */ |
| 358 | struct module *module; /* THIS_MODULE/NULL */ |
| 359 | |
| 360 | /* scheduler initializing service */ |
| 361 | int (*init_service)(struct ip_vs_service *svc); |
| 362 | /* scheduling service finish */ |
| 363 | int (*done_service)(struct ip_vs_service *svc); |
| 364 | /* scheduler updating service */ |
| 365 | int (*update_service)(struct ip_vs_service *svc); |
| 366 | |
| 367 | /* selecting a server from the given service */ |
| 368 | struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc, |
| 369 | const struct sk_buff *skb); |
| 370 | }; |
| 371 | |
| 372 | |
| 373 | /* |
| 374 | * The application module object (a.k.a. app incarnation) |
| 375 | */ |
| 376 | struct ip_vs_app |
| 377 | { |
| 378 | struct list_head a_list; /* member in app list */ |
| 379 | int type; /* IP_VS_APP_TYPE_xxx */ |
| 380 | char *name; /* application module name */ |
| 381 | __u16 protocol; |
| 382 | struct module *module; /* THIS_MODULE/NULL */ |
| 383 | struct list_head incs_list; /* list of incarnations */ |
| 384 | |
| 385 | /* members for application incarnations */ |
| 386 | struct list_head p_list; /* member in proto app list */ |
| 387 | struct ip_vs_app *app; /* its real application */ |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 388 | __be16 port; /* port number in net order */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | atomic_t usecnt; /* usage counter */ |
| 390 | |
| 391 | /* output hook: return false if can't linearize. diff set for TCP. */ |
| 392 | int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *, |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 393 | struct sk_buff *, int *diff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
| 395 | /* input hook: return false if can't linearize. diff set for TCP. */ |
| 396 | int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *, |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 397 | struct sk_buff *, int *diff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
| 399 | /* ip_vs_app initializer */ |
| 400 | int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *); |
| 401 | |
| 402 | /* ip_vs_app finish */ |
| 403 | int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *); |
| 404 | |
| 405 | |
| 406 | /* not used now */ |
| 407 | int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *, |
| 408 | struct ip_vs_protocol *); |
| 409 | |
| 410 | void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *); |
| 411 | |
| 412 | int * timeout_table; |
| 413 | int * timeouts; |
| 414 | int timeouts_size; |
| 415 | |
| 416 | int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app, |
| 417 | int *verdict, struct ip_vs_conn **cpp); |
| 418 | |
| 419 | struct ip_vs_conn * |
| 420 | (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app, |
| 421 | const struct iphdr *iph, unsigned int proto_off, |
| 422 | int inverse); |
| 423 | |
| 424 | struct ip_vs_conn * |
| 425 | (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app, |
| 426 | const struct iphdr *iph, unsigned int proto_off, |
| 427 | int inverse); |
| 428 | |
| 429 | int (*state_transition)(struct ip_vs_conn *cp, int direction, |
| 430 | const struct sk_buff *skb, |
| 431 | struct ip_vs_app *app); |
| 432 | |
| 433 | void (*timeout_change)(struct ip_vs_app *app, int flags); |
| 434 | }; |
| 435 | |
| 436 | |
| 437 | /* |
| 438 | * IPVS core functions |
| 439 | * (from ip_vs_core.c) |
| 440 | */ |
| 441 | extern const char *ip_vs_proto_name(unsigned proto); |
| 442 | extern void ip_vs_init_hash_table(struct list_head *table, int rows); |
| 443 | #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table(t, sizeof(t)/sizeof(t[0])) |
| 444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | #define IP_VS_APP_TYPE_FTP 1 |
| 446 | |
| 447 | /* |
| 448 | * ip_vs_conn handling functions |
| 449 | * (from ip_vs_conn.c) |
| 450 | */ |
| 451 | |
| 452 | /* |
| 453 | * IPVS connection entry hash table |
| 454 | */ |
| 455 | #ifndef CONFIG_IP_VS_TAB_BITS |
| 456 | #define CONFIG_IP_VS_TAB_BITS 12 |
| 457 | #endif |
| 458 | /* make sure that IP_VS_CONN_TAB_BITS is located in [8, 20] */ |
| 459 | #if CONFIG_IP_VS_TAB_BITS < 8 |
| 460 | #define IP_VS_CONN_TAB_BITS 8 |
| 461 | #endif |
| 462 | #if CONFIG_IP_VS_TAB_BITS > 20 |
| 463 | #define IP_VS_CONN_TAB_BITS 20 |
| 464 | #endif |
| 465 | #if 8 <= CONFIG_IP_VS_TAB_BITS && CONFIG_IP_VS_TAB_BITS <= 20 |
| 466 | #define IP_VS_CONN_TAB_BITS CONFIG_IP_VS_TAB_BITS |
| 467 | #endif |
| 468 | #define IP_VS_CONN_TAB_SIZE (1 << IP_VS_CONN_TAB_BITS) |
| 469 | #define IP_VS_CONN_TAB_MASK (IP_VS_CONN_TAB_SIZE - 1) |
| 470 | |
| 471 | enum { |
| 472 | IP_VS_DIR_INPUT = 0, |
| 473 | IP_VS_DIR_OUTPUT, |
| 474 | IP_VS_DIR_INPUT_ONLY, |
| 475 | IP_VS_DIR_LAST, |
| 476 | }; |
| 477 | |
| 478 | extern struct ip_vs_conn *ip_vs_conn_in_get |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 479 | (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] | 480 | extern struct ip_vs_conn *ip_vs_ct_in_get |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 481 | (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] | 482 | extern struct ip_vs_conn *ip_vs_conn_out_get |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 483 | (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] | 484 | |
| 485 | /* put back the conn without restarting its timer */ |
| 486 | static inline void __ip_vs_conn_put(struct ip_vs_conn *cp) |
| 487 | { |
| 488 | atomic_dec(&cp->refcnt); |
| 489 | } |
| 490 | extern void ip_vs_conn_put(struct ip_vs_conn *cp); |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 491 | 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] | 492 | |
| 493 | extern struct ip_vs_conn * |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 494 | ip_vs_conn_new(int proto, __be32 caddr, __be16 cport, __be32 vaddr, __be16 vport, |
| 495 | __be32 daddr, __be16 dport, unsigned flags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | struct ip_vs_dest *dest); |
| 497 | extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp); |
| 498 | |
| 499 | extern const char * ip_vs_state_name(__u16 proto, int state); |
| 500 | |
| 501 | extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp); |
| 502 | extern int ip_vs_check_template(struct ip_vs_conn *ct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | extern void ip_vs_random_dropentry(void); |
| 504 | extern int ip_vs_conn_init(void); |
| 505 | extern void ip_vs_conn_cleanup(void); |
| 506 | |
| 507 | static inline void ip_vs_control_del(struct ip_vs_conn *cp) |
| 508 | { |
| 509 | struct ip_vs_conn *ctl_cp = cp->control; |
| 510 | if (!ctl_cp) { |
| 511 | IP_VS_ERR("request control DEL for uncontrolled: " |
| 512 | "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n", |
| 513 | NIPQUAD(cp->caddr),ntohs(cp->cport), |
| 514 | NIPQUAD(cp->vaddr),ntohs(cp->vport)); |
| 515 | return; |
| 516 | } |
| 517 | |
| 518 | IP_VS_DBG(7, "DELeting control for: " |
| 519 | "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n", |
| 520 | NIPQUAD(cp->caddr),ntohs(cp->cport), |
| 521 | NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport)); |
| 522 | |
| 523 | cp->control = NULL; |
| 524 | if (atomic_read(&ctl_cp->n_control) == 0) { |
| 525 | IP_VS_ERR("BUG control DEL with n=0 : " |
| 526 | "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n", |
| 527 | NIPQUAD(cp->caddr),ntohs(cp->cport), |
| 528 | NIPQUAD(cp->vaddr),ntohs(cp->vport)); |
| 529 | return; |
| 530 | } |
| 531 | atomic_dec(&ctl_cp->n_control); |
| 532 | } |
| 533 | |
| 534 | static inline void |
| 535 | ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp) |
| 536 | { |
| 537 | if (cp->control) { |
| 538 | IP_VS_ERR("request control ADD for already controlled: " |
| 539 | "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n", |
| 540 | NIPQUAD(cp->caddr),ntohs(cp->cport), |
| 541 | NIPQUAD(cp->vaddr),ntohs(cp->vport)); |
| 542 | ip_vs_control_del(cp); |
| 543 | } |
| 544 | |
| 545 | IP_VS_DBG(7, "ADDing control for: " |
| 546 | "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n", |
| 547 | NIPQUAD(cp->caddr),ntohs(cp->cport), |
| 548 | NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport)); |
| 549 | |
| 550 | cp->control = ctl_cp; |
| 551 | atomic_inc(&ctl_cp->n_control); |
| 552 | } |
| 553 | |
| 554 | |
| 555 | /* |
| 556 | * IPVS application functions |
| 557 | * (from ip_vs_app.c) |
| 558 | */ |
| 559 | #define IP_VS_APP_MAX_PORTS 8 |
| 560 | extern int register_ip_vs_app(struct ip_vs_app *app); |
| 561 | extern void unregister_ip_vs_app(struct ip_vs_app *app); |
| 562 | extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 563 | extern void ip_vs_unbind_app(struct ip_vs_conn *cp); |
| 564 | extern int |
| 565 | register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port); |
| 566 | extern int ip_vs_app_inc_get(struct ip_vs_app *inc); |
| 567 | extern void ip_vs_app_inc_put(struct ip_vs_app *inc); |
| 568 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 569 | extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb); |
| 570 | 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] | 571 | 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] | 572 | char *o_buf, int o_len, char *n_buf, int n_len); |
| 573 | extern int ip_vs_app_init(void); |
| 574 | extern void ip_vs_app_cleanup(void); |
| 575 | |
| 576 | |
| 577 | /* |
| 578 | * IPVS protocol functions (from ip_vs_proto.c) |
| 579 | */ |
| 580 | extern int ip_vs_protocol_init(void); |
| 581 | extern void ip_vs_protocol_cleanup(void); |
| 582 | extern void ip_vs_protocol_timeout_change(int flags); |
| 583 | extern int *ip_vs_create_timeout_table(int *table, int size); |
| 584 | extern int |
| 585 | ip_vs_set_state_timeout(int *table, int num, char **names, char *name, int to); |
| 586 | extern void |
| 587 | ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb, |
| 588 | int offset, const char *msg); |
| 589 | |
| 590 | extern struct ip_vs_protocol ip_vs_protocol_tcp; |
| 591 | extern struct ip_vs_protocol ip_vs_protocol_udp; |
| 592 | extern struct ip_vs_protocol ip_vs_protocol_icmp; |
| 593 | extern struct ip_vs_protocol ip_vs_protocol_esp; |
| 594 | extern struct ip_vs_protocol ip_vs_protocol_ah; |
| 595 | |
| 596 | |
| 597 | /* |
| 598 | * Registering/unregistering scheduler functions |
| 599 | * (from ip_vs_sched.c) |
| 600 | */ |
| 601 | extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); |
| 602 | extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler); |
| 603 | extern int ip_vs_bind_scheduler(struct ip_vs_service *svc, |
| 604 | struct ip_vs_scheduler *scheduler); |
| 605 | extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc); |
| 606 | extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name); |
| 607 | extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler); |
| 608 | extern struct ip_vs_conn * |
| 609 | ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb); |
| 610 | extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb, |
| 611 | struct ip_vs_protocol *pp); |
| 612 | |
| 613 | |
| 614 | /* |
| 615 | * IPVS control data and functions (from ip_vs_ctl.c) |
| 616 | */ |
| 617 | extern int sysctl_ip_vs_cache_bypass; |
| 618 | extern int sysctl_ip_vs_expire_nodest_conn; |
| 619 | extern int sysctl_ip_vs_expire_quiescent_template; |
| 620 | extern int sysctl_ip_vs_sync_threshold[2]; |
| 621 | extern int sysctl_ip_vs_nat_icmp_send; |
| 622 | extern struct ip_vs_stats ip_vs_stats; |
Pavel Emelyanov | 90754f8 | 2008-01-12 02:33:50 -0800 | [diff] [blame] | 623 | extern struct ctl_path net_vs_ctl_path[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
| 625 | extern struct ip_vs_service * |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 626 | ip_vs_service_get(__u32 fwmark, __u16 protocol, __be32 vaddr, __be16 vport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
| 628 | static inline void ip_vs_service_put(struct ip_vs_service *svc) |
| 629 | { |
| 630 | atomic_dec(&svc->usecnt); |
| 631 | } |
| 632 | |
| 633 | extern struct ip_vs_dest * |
Al Viro | 014d730 | 2006-09-28 14:29:52 -0700 | [diff] [blame] | 634 | ip_vs_lookup_real_service(__u16 protocol, __be32 daddr, __be16 dport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | extern int ip_vs_use_count_inc(void); |
| 636 | extern void ip_vs_use_count_dec(void); |
| 637 | extern int ip_vs_control_init(void); |
| 638 | extern void ip_vs_control_cleanup(void); |
Rumen G. Bogdanovski | 1e356f9 | 2007-11-07 02:35:54 -0800 | [diff] [blame] | 639 | extern struct ip_vs_dest * |
| 640 | ip_vs_find_dest(__be32 daddr, __be16 dport, |
| 641 | __be32 vaddr, __be16 vport, __u16 protocol); |
| 642 | 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] | 643 | |
| 644 | |
| 645 | /* |
| 646 | * IPVS sync daemon data and function prototypes |
| 647 | * (from ip_vs_sync.c) |
| 648 | */ |
| 649 | extern volatile int ip_vs_sync_state; |
| 650 | extern volatile int ip_vs_master_syncid; |
| 651 | extern volatile int ip_vs_backup_syncid; |
| 652 | extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN]; |
| 653 | extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN]; |
| 654 | extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid); |
| 655 | extern int stop_sync_thread(int state); |
| 656 | extern void ip_vs_sync_conn(struct ip_vs_conn *cp); |
| 657 | |
| 658 | |
| 659 | /* |
| 660 | * IPVS rate estimator prototypes (from ip_vs_est.c) |
| 661 | */ |
| 662 | extern int ip_vs_new_estimator(struct ip_vs_stats *stats); |
| 663 | extern void ip_vs_kill_estimator(struct ip_vs_stats *stats); |
| 664 | extern void ip_vs_zero_estimator(struct ip_vs_stats *stats); |
| 665 | |
| 666 | /* |
| 667 | * Various IPVS packet transmitters (from ip_vs_xmit.c) |
| 668 | */ |
| 669 | extern int ip_vs_null_xmit |
| 670 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 671 | extern int ip_vs_bypass_xmit |
| 672 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 673 | extern int ip_vs_nat_xmit |
| 674 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 675 | extern int ip_vs_tunnel_xmit |
| 676 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 677 | extern int ip_vs_dr_xmit |
| 678 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp); |
| 679 | extern int ip_vs_icmp_xmit |
| 680 | (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset); |
| 681 | extern void ip_vs_dst_reset(struct ip_vs_dest *dest); |
| 682 | |
| 683 | |
| 684 | /* |
| 685 | * This is a simple mechanism to ignore packets when |
| 686 | * we are loaded. Just set ip_vs_drop_rate to 'n' and |
| 687 | * we start to drop 1/rate of the packets |
| 688 | */ |
| 689 | extern int ip_vs_drop_rate; |
| 690 | extern int ip_vs_drop_counter; |
| 691 | |
| 692 | static __inline__ int ip_vs_todrop(void) |
| 693 | { |
| 694 | if (!ip_vs_drop_rate) return 0; |
| 695 | if (--ip_vs_drop_counter > 0) return 0; |
| 696 | ip_vs_drop_counter = ip_vs_drop_rate; |
| 697 | return 1; |
| 698 | } |
| 699 | |
| 700 | /* |
| 701 | * ip_vs_fwd_tag returns the forwarding tag of the connection |
| 702 | */ |
| 703 | #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK) |
| 704 | |
Adrian Bunk | 732db65 | 2005-09-01 17:40:26 -0700 | [diff] [blame] | 705 | static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | { |
| 707 | char fwd; |
| 708 | |
| 709 | switch (IP_VS_FWD_METHOD(cp)) { |
| 710 | case IP_VS_CONN_F_MASQ: |
| 711 | fwd = 'M'; break; |
| 712 | case IP_VS_CONN_F_LOCALNODE: |
| 713 | fwd = 'L'; break; |
| 714 | case IP_VS_CONN_F_TUNNEL: |
| 715 | fwd = 'T'; break; |
| 716 | case IP_VS_CONN_F_DROUTE: |
| 717 | fwd = 'R'; break; |
| 718 | case IP_VS_CONN_F_BYPASS: |
| 719 | fwd = 'B'; break; |
| 720 | default: |
| 721 | fwd = '?'; break; |
| 722 | } |
| 723 | return fwd; |
| 724 | } |
| 725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp, |
| 727 | struct ip_vs_conn *cp, int dir); |
| 728 | |
Al Viro | b1550f2 | 2006-11-14 21:37:50 -0800 | [diff] [blame] | 729 | extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | |
Al Viro | f9214b2 | 2006-11-16 02:41:18 -0800 | [diff] [blame] | 731 | 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] | 732 | { |
Al Viro | f9214b2 | 2006-11-16 02:41:18 -0800 | [diff] [blame] | 733 | __be32 diff[2] = { ~old, new }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
Al Viro | f9214b2 | 2006-11-16 02:41:18 -0800 | [diff] [blame] | 735 | return csum_partial((char *) diff, sizeof(diff), oldsum); |
| 736 | } |
| 737 | |
| 738 | static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum) |
| 739 | { |
| 740 | __be16 diff[2] = { ~old, new }; |
| 741 | |
| 742 | return csum_partial((char *) diff, sizeof(diff), oldsum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | #endif /* __KERNEL__ */ |
| 746 | |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 747 | #endif /* _NET_IP_VS_H */ |