OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [include/] [net/] [ip_vs.h] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.