Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  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 */
 87 
 88 /* Move it to better place one day, for now keep it unique */
 89 #define NFC_IPVS_PROPERTY       0x10000
 90 
 91 #define IP_VS_SCHEDNAME_MAXLEN  16
 92 #define IP_VS_IFNAME_MAXLEN     16
 93 
 94 
 95 /*
 96  *      The struct ip_vs_service_user and struct ip_vs_dest_user are
 97  *      used to set IPVS rules through setsockopt.
 98  */
 99 struct ip_vs_service_user {
100         /* virtual service addresses */
101         u_int16_t               protocol;
102         u_int32_t               addr;           /* virtual ip address */
103         u_int16_t               port;
104         u_int32_t               fwmark;         /* firwall mark of service */
105 
106         /* virtual service options */
107         char                    sched_name[IP_VS_SCHEDNAME_MAXLEN];
108         unsigned                flags;          /* virtual service flags */
109         unsigned                timeout;        /* persistent timeout in sec */
110         u_int32_t               netmask;        /* persistent netmask */
111 };
112 
113 
114 struct ip_vs_dest_user {
115         /* destination server address */
116         u_int32_t               addr;
117         u_int16_t               port;
118 
119         /* real server options */
120         unsigned                conn_flags;     /* connection flags */
121         int                     weight;         /* destination weight */
122 
123         /* thresholds for active connections */
124         u_int32_t               u_threshold;    /* upper threshold */
125         u_int32_t               l_threshold;    /* lower threshold */
126 };
127 
128 
129 /*
130  *      IPVS statistics object (for user space)
131  */
132 struct ip_vs_stats_user
133 {
134         __u32                   conns;          /* connections scheduled */
135         __u32                   inpkts;         /* incoming packets */
136         __u32                   outpkts;        /* outgoing packets */
137         __u64                   inbytes;        /* incoming bytes */
138         __u64                   outbytes;       /* outgoing bytes */
139 
140         __u32                   cps;            /* current connection rate */
141         __u32                   inpps;          /* current in packet rate */
142         __u32                   outpps;         /* current out packet rate */
143         __u32                   inbps;          /* current in byte rate */
144         __u32                   outbps;         /* current out byte rate */
145 };
146 
147 
148 /* The argument to IP_VS_SO_GET_INFO */
149 struct ip_vs_getinfo {
150         /* version number */
151         unsigned int            version;
152 
153         /* size of connection hash table */
154         unsigned int            size;
155 
156         /* number of virtual services */
157         unsigned int            num_services;
158 };
159 
160 
161 /* The argument to IP_VS_SO_GET_SERVICE */
162 struct ip_vs_service_entry {
163         /* which service: user fills in these */
164         u_int16_t               protocol;
165         u_int32_t               addr;           /* virtual address */
166         u_int16_t               port;
167         u_int32_t               fwmark;         /* firwall mark of service */
168 
169         /* service options */
170         char                    sched_name[IP_VS_SCHEDNAME_MAXLEN];
171         unsigned                flags;          /* virtual service flags */
172         unsigned                timeout;        /* persistent timeout */
173         u_int32_t               netmask;        /* persistent netmask */
174 
175         /* number of real servers */
176         unsigned int            num_dests;
177 
178         /* statistics */
179         struct ip_vs_stats_user stats;
180 };
181 
182 
183 struct ip_vs_dest_entry {
184         u_int32_t               addr;           /* destination address */
185         u_int16_t               port;
186         unsigned                conn_flags;     /* connection flags */
187         int                     weight;         /* destination weight */
188 
189         u_int32_t               u_threshold;    /* upper threshold */
190         u_int32_t               l_threshold;    /* lower threshold */
191 
192         u_int32_t               activeconns;    /* active connections */
193         u_int32_t               inactconns;     /* inactive connections */
194         u_int32_t               persistconns;   /* persistent connections */
195 
196         /* statistics */
197         struct ip_vs_stats_user stats;
198 };
199 
200 
201 /* The argument to IP_VS_SO_GET_DESTS */
202 struct ip_vs_get_dests {
203         /* which service: user fills in these */
204         u_int16_t               protocol;
205         u_int32_t               addr;           /* virtual address */
206         u_int16_t               port;
207         u_int32_t               fwmark;         /* firwall mark of service */
208 
209         /* number of real servers */
210         unsigned int            num_dests;
211 
212         /* the real servers */
213         struct ip_vs_dest_entry entrytable[0];
214 };
215 
216 
217 /* The argument to IP_VS_SO_GET_SERVICES */
218 struct ip_vs_get_services {
219         /* number of virtual services */
220         unsigned int            num_services;
221 
222         /* service table */
223         struct ip_vs_service_entry entrytable[0];
224 };
225 
226 
227 /* The argument to IP_VS_SO_GET_TIMEOUT */
228 struct ip_vs_timeout_user {
229         int                     tcp_timeout;
230         int                     tcp_fin_timeout;
231         int                     udp_timeout;
232 };
233 
234 
235 /* The argument to IP_VS_SO_GET_DAEMON */
236 struct ip_vs_daemon_user {
237         /* sync daemon state (master/backup) */
238         int                     state;
239 
240         /* multicast interface name */
241         char                    mcast_ifn[IP_VS_IFNAME_MAXLEN];
242 
243         /* SyncID we belong to */
244         int                     syncid;
245 };
246 
247 
248 #ifdef __KERNEL__
249 
250 #include <linux/config.h>
251 #include <linux/list.h>                 /* for struct list_head */
252 #include <linux/spinlock.h>             /* for struct rwlock_t */
253 #include <linux/skbuff.h>               /* for struct sk_buff */
254 #include <linux/ip.h>                   /* for struct iphdr */
255 #include <asm/atomic.h>                 /* for struct atomic_t */
256 #include <linux/netdevice.h>            /* for struct neighbour */
257 #include <net/dst.h>                    /* for struct dst_entry */
258 #include <net/tcp.h>
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);
743 extern struct ip_vs_conn *ip_vs_conn_out_get
744 (int protocol, __u32 s_addr, __u16 s_port, __u32 d_addr, __u16 d_port);
745 
746 /* put back the conn without restarting its timer */
747 static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
748 {
749         atomic_dec(&cp->refcnt);
750 }
751 extern void ip_vs_conn_put(struct ip_vs_conn *cp);
752 extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __u16 cport);
753 
754 extern struct ip_vs_conn *
755 ip_vs_conn_new(int proto, __u32 caddr, __u16 cport, __u32 vaddr, __u16 vport,
756                __u32 daddr, __u16 dport, unsigned flags,
757                struct ip_vs_dest *dest);
758 extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
759 
760 extern const char * ip_vs_state_name(__u16 proto, int state);
761 
762 extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
763 extern int ip_vs_check_template(struct ip_vs_conn *ct);
764 extern void ip_vs_secure_tcp_set(int on);
765 extern void ip_vs_random_dropentry(void);
766 extern int ip_vs_conn_init(void);
767 extern void ip_vs_conn_cleanup(void);
768 
769 static inline void ip_vs_control_del(struct ip_vs_conn *cp)
770 {
771         struct ip_vs_conn *ctl_cp = cp->control;
772         if (!ctl_cp) {
773                 IP_VS_ERR("request control DEL for uncontrolled: "
774                           "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
775                           NIPQUAD(cp->caddr),ntohs(cp->cport),
776                           NIPQUAD(cp->vaddr),ntohs(cp->vport));
777                 return;
778         }
779 
780         IP_VS_DBG(7, "DELeting control for: "
781                   "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
782                   NIPQUAD(cp->caddr),ntohs(cp->cport),
783                   NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
784 
785         cp->control = NULL;
786         if (atomic_read(&ctl_cp->n_control) == 0) {
787                 IP_VS_ERR("BUG control DEL with n=0 : "
788                           "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
789                           NIPQUAD(cp->caddr),ntohs(cp->cport),
790                           NIPQUAD(cp->vaddr),ntohs(cp->vport));
791                 return;
792         }
793         atomic_dec(&ctl_cp->n_control);
794 }
795 
796 static inline void
797 ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
798 {
799         if (cp->control) {
800                 IP_VS_ERR("request control ADD for already controlled: "
801                           "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
802                           NIPQUAD(cp->caddr),ntohs(cp->cport),
803                           NIPQUAD(cp->vaddr),ntohs(cp->vport));
804                 ip_vs_control_del(cp);
805         }
806 
807         IP_VS_DBG(7, "ADDing control for: "
808                   "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
809                   NIPQUAD(cp->caddr),ntohs(cp->cport),
810                   NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
811 
812         cp->control = ctl_cp;
813         atomic_inc(&ctl_cp->n_control);
814 }
815 
816 
817 /*
818  *      IPVS application functions
819  *      (from ip_vs_app.c)
820  */
821 #define IP_VS_APP_MAX_PORTS  8
822 extern int register_ip_vs_app(struct ip_vs_app *app);
823 extern void unregister_ip_vs_app(struct ip_vs_app *app);
824 extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
825 extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
826 extern int
827 register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port);
828 extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
829 extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
830 
831 extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff **pskb);
832 extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff **pskb);
833 extern int ip_vs_skb_replace(struct sk_buff *skb, int pri,
834                              char *o_buf, int o_len, char *n_buf, int n_len);
835 extern int ip_vs_app_init(void);
836 extern void ip_vs_app_cleanup(void);
837 
838 
839 /*
840  *      IPVS protocol functions (from ip_vs_proto.c)
841  */
842 extern int ip_vs_protocol_init(void);
843 extern void ip_vs_protocol_cleanup(void);
844 extern void ip_vs_protocol_timeout_change(int flags);
845 extern int *ip_vs_create_timeout_table(int *table, int size);
846 extern int
847 ip_vs_set_state_timeout(int *table, int num, char **names, char *name, int to);
848 extern void
849 ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb,
850                           int offset, const char *msg);
851 
852 extern struct ip_vs_protocol ip_vs_protocol_tcp;
853 extern struct ip_vs_protocol ip_vs_protocol_udp;
854 extern struct ip_vs_protocol ip_vs_protocol_icmp;
855 extern struct ip_vs_protocol ip_vs_protocol_esp;
856 extern struct ip_vs_protocol ip_vs_protocol_ah;
857 
858 
859 /*
860  *      Registering/unregistering scheduler functions
861  *      (from ip_vs_sched.c)
862  */
863 extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
864 extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
865 extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
866                                 struct ip_vs_scheduler *scheduler);
867 extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
868 extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
869 extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
870 extern struct ip_vs_conn *
871 ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb);
872 extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
873                         struct ip_vs_protocol *pp);
874 
875 
876 /*
877  *      IPVS control data and functions (from ip_vs_ctl.c)
878  */
879 extern int sysctl_ip_vs_cache_bypass;
880 extern int sysctl_ip_vs_expire_nodest_conn;
881 extern int sysctl_ip_vs_expire_quiescent_template;
882 extern int sysctl_ip_vs_sync_threshold[2];
883 extern int sysctl_ip_vs_nat_icmp_send;
884 extern struct ip_vs_stats ip_vs_stats;
885 
886 extern struct ip_vs_service *
887 ip_vs_service_get(__u32 fwmark, __u16 protocol, __u32 vaddr, __u16 vport);
888 
889 static inline void ip_vs_service_put(struct ip_vs_service *svc)
890 {
891         atomic_dec(&svc->usecnt);
892 }
893 
894 extern struct ip_vs_dest *
895 ip_vs_lookup_real_service(__u16 protocol, __u32 daddr, __u16 dport);
896 extern int ip_vs_use_count_inc(void);
897 extern void ip_vs_use_count_dec(void);
898 extern int ip_vs_control_init(void);
899 extern void ip_vs_control_cleanup(void);
900 
901 
902 /*
903  *      IPVS sync daemon data and function prototypes
904  *      (from ip_vs_sync.c)
905  */
906 extern volatile int ip_vs_sync_state;
907 extern volatile int ip_vs_master_syncid;
908 extern volatile int ip_vs_backup_syncid;
909 extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
910 extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
911 extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
912 extern int stop_sync_thread(int state);
913 extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
914 
915 
916 /*
917  *      IPVS rate estimator prototypes (from ip_vs_est.c)
918  */
919 extern int ip_vs_new_estimator(struct ip_vs_stats *stats);
920 extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
921 extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
922 
923 /*
924  *      Various IPVS packet transmitters (from ip_vs_xmit.c)
925  */
926 extern int ip_vs_null_xmit
927 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
928 extern int ip_vs_bypass_xmit
929 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
930 extern int ip_vs_nat_xmit
931 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
932 extern int ip_vs_tunnel_xmit
933 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
934 extern int ip_vs_dr_xmit
935 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
936 extern int ip_vs_icmp_xmit
937 (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset);
938 extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
939 
940 
941 /*
942  *      This is a simple mechanism to ignore packets when
943  *      we are loaded. Just set ip_vs_drop_rate to 'n' and
944  *      we start to drop 1/rate of the packets
945  */
946 extern int ip_vs_drop_rate;
947 extern int ip_vs_drop_counter;
948 
949 static __inline__ int ip_vs_todrop(void)
950 {
951         if (!ip_vs_drop_rate) return 0;
952         if (--ip_vs_drop_counter > 0) return 0;
953         ip_vs_drop_counter = ip_vs_drop_rate;
954         return 1;
955 }
956 
957 /*
958  *      ip_vs_fwd_tag returns the forwarding tag of the connection
959  */
960 #define IP_VS_FWD_METHOD(cp)  (cp->flags & IP_VS_CONN_F_FWD_MASK)
961 
962 extern __inline__ char ip_vs_fwd_tag(struct ip_vs_conn *cp)
963 {
964         char fwd;
965 
966         switch (IP_VS_FWD_METHOD(cp)) {
967         case IP_VS_CONN_F_MASQ:
968                 fwd = 'M'; break;
969         case IP_VS_CONN_F_LOCALNODE:
970                 fwd = 'L'; break;
971         case IP_VS_CONN_F_TUNNEL:
972                 fwd = 'T'; break;
973         case IP_VS_CONN_F_DROUTE:
974                 fwd = 'R'; break;
975         case IP_VS_CONN_F_BYPASS:
976                 fwd = 'B'; break;
977         default:
978                 fwd = '?'; break;
979         }
980         return fwd;
981 }
982 
983 extern int ip_vs_make_skb_writable(struct sk_buff **pskb, int len);
984 extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
985                 struct ip_vs_conn *cp, int dir);
986 
987 extern u16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
988 
989 static inline u16 ip_vs_check_diff(u32 old, u32 new, u16 oldsum)
990 {
991         u32 diff[2] = { old, new };
992 
993         return csum_fold(csum_partial((char *) diff, sizeof(diff),
994                                       oldsum ^ 0xFFFF));
995 }
996 
997 #endif /* __KERNEL__ */
998 
999 #endif  /* _IP_VS_H */
1000 
  This page was automatically generated by the LXR engine.