~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to include/net/ip_vs.h

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
#include <linux/ip_vs.h>                /* definitions shared with userland */
10
10
 
11
 
/* old ipvsadm versions still include this file directly */
12
 
#ifdef __KERNEL__
13
 
 
14
11
#include <asm/types.h>                  /* for __uXX types */
15
12
 
16
13
#include <linux/sysctl.h>               /* for ctl_path */
28
25
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
29
26
#include <net/netfilter/nf_conntrack.h>
30
27
#endif
 
28
#include <net/net_namespace.h>          /* Netw namespace */
 
29
 
 
30
/*
 
31
 * Generic access of ipvs struct
 
32
 */
 
33
static inline struct netns_ipvs *net_ipvs(struct net* net)
 
34
{
 
35
        return net->ipvs;
 
36
}
 
37
/*
 
38
 * Get net ptr from skb in traffic cases
 
39
 * use skb_sknet when call is from userland (ioctl or netlink)
 
40
 */
 
41
static inline struct net *skb_net(const struct sk_buff *skb)
 
42
{
 
43
#ifdef CONFIG_NET_NS
 
44
#ifdef CONFIG_IP_VS_DEBUG
 
45
        /*
 
46
         * This is used for debug only.
 
47
         * Start with the most likely hit
 
48
         * End with BUG
 
49
         */
 
50
        if (likely(skb->dev && skb->dev->nd_net))
 
51
                return dev_net(skb->dev);
 
52
        if (skb_dst(skb) && skb_dst(skb)->dev)
 
53
                return dev_net(skb_dst(skb)->dev);
 
54
        WARN(skb->sk, "Maybe skb_sknet should be used in %s() at line:%d\n",
 
55
                      __func__, __LINE__);
 
56
        if (likely(skb->sk && skb->sk->sk_net))
 
57
                return sock_net(skb->sk);
 
58
        pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
 
59
                __func__, __LINE__);
 
60
        BUG();
 
61
#else
 
62
        return dev_net(skb->dev ? : skb_dst(skb)->dev);
 
63
#endif
 
64
#else
 
65
        return &init_net;
 
66
#endif
 
67
}
 
68
 
 
69
static inline struct net *skb_sknet(const struct sk_buff *skb)
 
70
{
 
71
#ifdef CONFIG_NET_NS
 
72
#ifdef CONFIG_IP_VS_DEBUG
 
73
        /* Start with the most likely hit */
 
74
        if (likely(skb->sk && skb->sk->sk_net))
 
75
                return sock_net(skb->sk);
 
76
        WARN(skb->dev, "Maybe skb_net should be used instead in %s() line:%d\n",
 
77
                       __func__, __LINE__);
 
78
        if (likely(skb->dev && skb->dev->nd_net))
 
79
                return dev_net(skb->dev);
 
80
        pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
 
81
                __func__, __LINE__);
 
82
        BUG();
 
83
#else
 
84
        return sock_net(skb->sk);
 
85
#endif
 
86
#else
 
87
        return &init_net;
 
88
#endif
 
89
}
 
90
/*
 
91
 * This one needed for single_open_net since net is stored directly in
 
92
 * private not as a struct i.e. seq_file_net can't be used.
 
93
 */
 
94
static inline struct net *seq_file_single_net(struct seq_file *seq)
 
95
{
 
96
#ifdef CONFIG_NET_NS
 
97
        return (struct net *)seq->private;
 
98
#else
 
99
        return &init_net;
 
100
#endif
 
101
}
31
102
 
32
103
/* Connections' size value needed by ip_vs_ctl.c */
33
104
extern int ip_vs_conn_tab_size;
258
329
                                                   before last resized pkt */
259
330
};
260
331
 
 
332
/*
 
333
 * counters per cpu
 
334
 */
 
335
struct ip_vs_counters {
 
336
        __u32           conns;          /* connections scheduled */
 
337
        __u32           inpkts;         /* incoming packets */
 
338
        __u32           outpkts;        /* outgoing packets */
 
339
        __u64           inbytes;        /* incoming bytes */
 
340
        __u64           outbytes;       /* outgoing bytes */
 
341
};
 
342
/*
 
343
 * Stats per cpu
 
344
 */
 
345
struct ip_vs_cpu_stats {
 
346
        struct ip_vs_counters   ustats;
 
347
        struct u64_stats_sync   syncp;
 
348
};
261
349
 
262
350
/*
263
351
 *      IPVS statistics objects
279
367
};
280
368
 
281
369
struct ip_vs_stats {
282
 
        struct ip_vs_stats_user ustats;         /* statistics */
 
370
        struct ip_vs_stats_user ustats;         /* statistics */
283
371
        struct ip_vs_estimator  est;            /* estimator */
284
 
 
285
 
        spinlock_t              lock;           /* spin lock */
 
372
        struct ip_vs_cpu_stats  *cpustats;      /* per cpu counters */
 
373
        spinlock_t              lock;           /* spin lock */
 
374
        struct ip_vs_stats_user ustats0;        /* reset values */
286
375
};
287
376
 
288
377
struct dst_entry;
290
379
struct ip_vs_conn;
291
380
struct ip_vs_app;
292
381
struct sk_buff;
 
382
struct ip_vs_proto_data;
293
383
 
294
384
struct ip_vs_protocol {
295
385
        struct ip_vs_protocol   *next;
297
387
        u16                     protocol;
298
388
        u16                     num_states;
299
389
        int                     dont_defrag;
300
 
        atomic_t                appcnt;         /* counter of proto app incs */
301
 
        int                     *timeout_table; /* protocol timeout table */
302
390
 
303
391
        void (*init)(struct ip_vs_protocol *pp);
304
392
 
305
393
        void (*exit)(struct ip_vs_protocol *pp);
306
394
 
 
395
        void (*init_netns)(struct net *net, struct ip_vs_proto_data *pd);
 
396
 
 
397
        void (*exit_netns)(struct net *net, struct ip_vs_proto_data *pd);
 
398
 
307
399
        int (*conn_schedule)(int af, struct sk_buff *skb,
308
 
                             struct ip_vs_protocol *pp,
 
400
                             struct ip_vs_proto_data *pd,
309
401
                             int *verdict, struct ip_vs_conn **cpp);
310
402
 
311
403
        struct ip_vs_conn *
312
404
        (*conn_in_get)(int af,
313
405
                       const struct sk_buff *skb,
314
 
                       struct ip_vs_protocol *pp,
315
406
                       const struct ip_vs_iphdr *iph,
316
407
                       unsigned int proto_off,
317
408
                       int inverse);
319
410
        struct ip_vs_conn *
320
411
        (*conn_out_get)(int af,
321
412
                        const struct sk_buff *skb,
322
 
                        struct ip_vs_protocol *pp,
323
413
                        const struct ip_vs_iphdr *iph,
324
414
                        unsigned int proto_off,
325
415
                        int inverse);
337
427
 
338
428
        int (*state_transition)(struct ip_vs_conn *cp, int direction,
339
429
                                const struct sk_buff *skb,
340
 
                                struct ip_vs_protocol *pp);
341
 
 
342
 
        int (*register_app)(struct ip_vs_app *inc);
343
 
 
344
 
        void (*unregister_app)(struct ip_vs_app *inc);
 
430
                                struct ip_vs_proto_data *pd);
 
431
 
 
432
        int (*register_app)(struct net *net, struct ip_vs_app *inc);
 
433
 
 
434
        void (*unregister_app)(struct net *net, struct ip_vs_app *inc);
345
435
 
346
436
        int (*app_conn_bind)(struct ip_vs_conn *cp);
347
437
 
350
440
                             int offset,
351
441
                             const char *msg);
352
442
 
353
 
        void (*timeout_change)(struct ip_vs_protocol *pp, int flags);
354
 
 
355
 
        int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to);
356
 
};
357
 
 
358
 
extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto);
 
443
        void (*timeout_change)(struct ip_vs_proto_data *pd, int flags);
 
444
};
 
445
 
 
446
/*
 
447
 * protocol data per netns
 
448
 */
 
449
struct ip_vs_proto_data {
 
450
        struct ip_vs_proto_data *next;
 
451
        struct ip_vs_protocol   *pp;
 
452
        int                     *timeout_table; /* protocol timeout table */
 
453
        atomic_t                appcnt;         /* counter of proto app incs. */
 
454
        struct tcp_states_t     *tcp_state_table;
 
455
};
 
456
 
 
457
extern struct ip_vs_protocol   *ip_vs_proto_get(unsigned short proto);
 
458
extern struct ip_vs_proto_data *ip_vs_proto_data_get(struct net *net,
 
459
                                                     unsigned short proto);
359
460
 
360
461
struct ip_vs_conn_param {
 
462
        struct net                      *net;
361
463
        const union nf_inet_addr        *caddr;
362
464
        const union nf_inet_addr        *vaddr;
363
465
        __be16                          cport;
374
476
 *      IP_VS structure allocated for each dynamically scheduled connection
375
477
 */
376
478
struct ip_vs_conn {
377
 
        struct list_head        c_list;         /* hashed list heads */
378
 
 
 
479
        struct hlist_node       c_list;         /* hashed list heads */
 
480
#ifdef CONFIG_NET_NS
 
481
        struct net              *net;           /* Name space */
 
482
#endif
379
483
        /* Protocol, addresses and port numbers */
380
 
        u16                      af;            /* address family */
381
 
        union nf_inet_addr       caddr;          /* client address */
382
 
        union nf_inet_addr       vaddr;          /* virtual address */
383
 
        union nf_inet_addr       daddr;          /* destination address */
384
 
        volatile __u32           flags;          /* status flags */
385
 
        __be16                   cport;
386
 
        __be16                   vport;
387
 
        __be16                   dport;
 
484
        u16                     af;             /* address family */
 
485
        __be16                  cport;
 
486
        __be16                  vport;
 
487
        __be16                  dport;
 
488
        __u32                   fwmark;         /* Fire wall mark from skb */
 
489
        union nf_inet_addr      caddr;          /* client address */
 
490
        union nf_inet_addr      vaddr;          /* virtual address */
 
491
        union nf_inet_addr      daddr;          /* destination address */
 
492
        volatile __u32          flags;          /* status flags */
388
493
        __u16                   protocol;       /* Which protocol (TCP/UDP) */
389
494
 
390
495
        /* counter and timer */
422
527
        struct ip_vs_seq        in_seq;         /* incoming seq. struct */
423
528
        struct ip_vs_seq        out_seq;        /* outgoing seq. struct */
424
529
 
 
530
        const struct ip_vs_pe   *pe;
425
531
        char                    *pe_data;
426
532
        __u8                    pe_data_len;
427
533
};
428
534
 
 
535
/*
 
536
 *  To save some memory in conn table when name space is disabled.
 
537
 */
 
538
static inline struct net *ip_vs_conn_net(const struct ip_vs_conn *cp)
 
539
{
 
540
#ifdef CONFIG_NET_NS
 
541
        return cp->net;
 
542
#else
 
543
        return &init_net;
 
544
#endif
 
545
}
 
546
static inline void ip_vs_conn_net_set(struct ip_vs_conn *cp, struct net *net)
 
547
{
 
548
#ifdef CONFIG_NET_NS
 
549
        cp->net = net;
 
550
#endif
 
551
}
 
552
 
 
553
static inline int ip_vs_conn_net_eq(const struct ip_vs_conn *cp,
 
554
                                    struct net *net)
 
555
{
 
556
#ifdef CONFIG_NET_NS
 
557
        return cp->net == net;
 
558
#else
 
559
        return 1;
 
560
#endif
 
561
}
429
562
 
430
563
/*
431
564
 *      Extended internal versions of struct ip_vs_service_user and
485
618
        unsigned                flags;    /* service status flags */
486
619
        unsigned                timeout;  /* persistent timeout in ticks */
487
620
        __be32                  netmask;  /* grouping granularity */
 
621
        struct net              *net;
488
622
 
489
623
        struct list_head        destinations;  /* real server d-linked list */
490
624
        __u32                   num_dests;     /* number of servers */
510
644
        struct list_head        d_list;   /* for table with all the dests */
511
645
 
512
646
        u16                     af;             /* address family */
 
647
        __be16                  port;           /* port number of the server */
513
648
        union nf_inet_addr      addr;           /* IP address of the server */
514
 
        __be16                  port;           /* port number of the server */
515
649
        volatile unsigned       flags;          /* dest status flags */
516
650
        atomic_t                conn_flags;     /* flags to copy to conn */
517
651
        atomic_t                weight;         /* server weight */
531
665
        struct dst_entry        *dst_cache;     /* destination cache entry */
532
666
        u32                     dst_rtos;       /* RT_TOS(tos) for dst */
533
667
        u32                     dst_cookie;
534
 
#ifdef CONFIG_IP_VS_IPV6
535
 
        struct in6_addr         dst_saddr;
536
 
#endif
 
668
        union nf_inet_addr      dst_saddr;
537
669
 
538
670
        /* for virtual service */
539
671
        struct ip_vs_service    *svc;           /* service it belongs to */
540
672
        __u16                   protocol;       /* which protocol (TCP/UDP) */
 
673
        __be16                  vport;          /* virtual port number */
541
674
        union nf_inet_addr      vaddr;          /* virtual IP address */
542
 
        __be16                  vport;          /* virtual port number */
543
675
        __u32                   vfwmark;        /* firewall mark of service */
544
676
};
545
677
 
651
783
        void (*timeout_change)(struct ip_vs_app *app, int flags);
652
784
};
653
785
 
 
786
/* IPVS in network namespace */
 
787
struct netns_ipvs {
 
788
        int                     gen;            /* Generation */
 
789
        int                     enable;         /* enable like nf_hooks do */
 
790
        /*
 
791
         *      Hash table: for real service lookups
 
792
         */
 
793
        #define IP_VS_RTAB_BITS 4
 
794
        #define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS)
 
795
        #define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1)
 
796
 
 
797
        struct list_head        rs_table[IP_VS_RTAB_SIZE];
 
798
        /* ip_vs_app */
 
799
        struct list_head        app_list;
 
800
        /* ip_vs_ftp */
 
801
        struct ip_vs_app        *ftp_app;
 
802
        /* ip_vs_proto */
 
803
        #define IP_VS_PROTO_TAB_SIZE    32      /* must be power of 2 */
 
804
        struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE];
 
805
        /* ip_vs_proto_tcp */
 
806
#ifdef CONFIG_IP_VS_PROTO_TCP
 
807
        #define TCP_APP_TAB_BITS        4
 
808
        #define TCP_APP_TAB_SIZE        (1 << TCP_APP_TAB_BITS)
 
809
        #define TCP_APP_TAB_MASK        (TCP_APP_TAB_SIZE - 1)
 
810
        struct list_head        tcp_apps[TCP_APP_TAB_SIZE];
 
811
        spinlock_t              tcp_app_lock;
 
812
#endif
 
813
        /* ip_vs_proto_udp */
 
814
#ifdef CONFIG_IP_VS_PROTO_UDP
 
815
        #define UDP_APP_TAB_BITS        4
 
816
        #define UDP_APP_TAB_SIZE        (1 << UDP_APP_TAB_BITS)
 
817
        #define UDP_APP_TAB_MASK        (UDP_APP_TAB_SIZE - 1)
 
818
        struct list_head        udp_apps[UDP_APP_TAB_SIZE];
 
819
        spinlock_t              udp_app_lock;
 
820
#endif
 
821
        /* ip_vs_proto_sctp */
 
822
#ifdef CONFIG_IP_VS_PROTO_SCTP
 
823
        #define SCTP_APP_TAB_BITS       4
 
824
        #define SCTP_APP_TAB_SIZE       (1 << SCTP_APP_TAB_BITS)
 
825
        #define SCTP_APP_TAB_MASK       (SCTP_APP_TAB_SIZE - 1)
 
826
        /* Hash table for SCTP application incarnations  */
 
827
        struct list_head        sctp_apps[SCTP_APP_TAB_SIZE];
 
828
        spinlock_t              sctp_app_lock;
 
829
#endif
 
830
        /* ip_vs_conn */
 
831
        atomic_t                conn_count;      /*  connection counter */
 
832
 
 
833
        /* ip_vs_ctl */
 
834
        struct ip_vs_stats              tot_stats;  /* Statistics & est. */
 
835
 
 
836
        int                     num_services;    /* no of virtual services */
 
837
 
 
838
        rwlock_t                rs_lock;         /* real services table */
 
839
        /* semaphore for IPVS sockopts. And, [gs]etsockopt may sleep. */
 
840
        struct lock_class_key   ctl_key;        /* ctl_mutex debuging */
 
841
        /* Trash for destinations */
 
842
        struct list_head        dest_trash;
 
843
        /* Service counters */
 
844
        atomic_t                ftpsvc_counter;
 
845
        atomic_t                nullsvc_counter;
 
846
 
 
847
#ifdef CONFIG_SYSCTL
 
848
        /* 1/rate drop and drop-entry variables */
 
849
        struct delayed_work     defense_work;   /* Work handler */
 
850
        int                     drop_rate;
 
851
        int                     drop_counter;
 
852
        atomic_t                dropentry;
 
853
        /* locks in ctl.c */
 
854
        spinlock_t              dropentry_lock;  /* drop entry handling */
 
855
        spinlock_t              droppacket_lock; /* drop packet handling */
 
856
        spinlock_t              securetcp_lock;  /* state and timeout tables */
 
857
 
 
858
        /* sys-ctl struct */
 
859
        struct ctl_table_header *sysctl_hdr;
 
860
        struct ctl_table        *sysctl_tbl;
 
861
#endif
 
862
 
 
863
        /* sysctl variables */
 
864
        int                     sysctl_amemthresh;
 
865
        int                     sysctl_am_droprate;
 
866
        int                     sysctl_drop_entry;
 
867
        int                     sysctl_drop_packet;
 
868
        int                     sysctl_secure_tcp;
 
869
#ifdef CONFIG_IP_VS_NFCT
 
870
        int                     sysctl_conntrack;
 
871
#endif
 
872
        int                     sysctl_snat_reroute;
 
873
        int                     sysctl_sync_ver;
 
874
        int                     sysctl_cache_bypass;
 
875
        int                     sysctl_expire_nodest_conn;
 
876
        int                     sysctl_expire_quiescent_template;
 
877
        int                     sysctl_sync_threshold[2];
 
878
        int                     sysctl_nat_icmp_send;
 
879
 
 
880
        /* ip_vs_lblc */
 
881
        int                     sysctl_lblc_expiration;
 
882
        struct ctl_table_header *lblc_ctl_header;
 
883
        struct ctl_table        *lblc_ctl_table;
 
884
        /* ip_vs_lblcr */
 
885
        int                     sysctl_lblcr_expiration;
 
886
        struct ctl_table_header *lblcr_ctl_header;
 
887
        struct ctl_table        *lblcr_ctl_table;
 
888
        /* ip_vs_est */
 
889
        struct list_head        est_list;       /* estimator list */
 
890
        spinlock_t              est_lock;
 
891
        struct timer_list       est_timer;      /* Estimation timer */
 
892
        /* ip_vs_sync */
 
893
        struct list_head        sync_queue;
 
894
        spinlock_t              sync_lock;
 
895
        struct ip_vs_sync_buff  *sync_buff;
 
896
        spinlock_t              sync_buff_lock;
 
897
        struct sockaddr_in      sync_mcast_addr;
 
898
        struct task_struct      *master_thread;
 
899
        struct task_struct      *backup_thread;
 
900
        int                     send_mesg_maxlen;
 
901
        int                     recv_mesg_maxlen;
 
902
        volatile int            sync_state;
 
903
        volatile int            master_syncid;
 
904
        volatile int            backup_syncid;
 
905
        /* multicast interface name */
 
906
        char                    master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
 
907
        char                    backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
 
908
        /* net name space ptr */
 
909
        struct net              *net;            /* Needed by timer routines */
 
910
};
 
911
 
 
912
#define DEFAULT_SYNC_THRESHOLD  3
 
913
#define DEFAULT_SYNC_PERIOD     50
 
914
#define DEFAULT_SYNC_VER        1
 
915
 
 
916
#ifdef CONFIG_SYSCTL
 
917
 
 
918
static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
 
919
{
 
920
        return ipvs->sysctl_sync_threshold[0];
 
921
}
 
922
 
 
923
static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
 
924
{
 
925
        return ipvs->sysctl_sync_threshold[1];
 
926
}
 
927
 
 
928
static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
 
929
{
 
930
        return ipvs->sysctl_sync_ver;
 
931
}
 
932
 
 
933
#else
 
934
 
 
935
static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
 
936
{
 
937
        return DEFAULT_SYNC_THRESHOLD;
 
938
}
 
939
 
 
940
static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
 
941
{
 
942
        return DEFAULT_SYNC_PERIOD;
 
943
}
 
944
 
 
945
static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
 
946
{
 
947
        return DEFAULT_SYNC_VER;
 
948
}
 
949
 
 
950
#endif
654
951
 
655
952
/*
656
953
 *      IPVS core functions
674
971
        IP_VS_DIR_LAST,
675
972
};
676
973
 
677
 
static inline void ip_vs_conn_fill_param(int af, int protocol,
 
974
static inline void ip_vs_conn_fill_param(struct net *net, int af, int protocol,
678
975
                                         const union nf_inet_addr *caddr,
679
976
                                         __be16 cport,
680
977
                                         const union nf_inet_addr *vaddr,
681
978
                                         __be16 vport,
682
979
                                         struct ip_vs_conn_param *p)
683
980
{
 
981
        p->net = net;
684
982
        p->af = af;
685
983
        p->protocol = protocol;
686
984
        p->caddr = caddr;
695
993
struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p);
696
994
 
697
995
struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb,
698
 
                                            struct ip_vs_protocol *pp,
699
996
                                            const struct ip_vs_iphdr *iph,
700
997
                                            unsigned int proto_off,
701
998
                                            int inverse);
703
1000
struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p);
704
1001
 
705
1002
struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb,
706
 
                                             struct ip_vs_protocol *pp,
707
1003
                                             const struct ip_vs_iphdr *iph,
708
1004
                                             unsigned int proto_off,
709
1005
                                             int inverse);
719
1015
struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p,
720
1016
                                  const union nf_inet_addr *daddr,
721
1017
                                  __be16 dport, unsigned flags,
722
 
                                  struct ip_vs_dest *dest);
 
1018
                                  struct ip_vs_dest *dest, __u32 fwmark);
723
1019
extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
724
1020
 
725
1021
extern const char * ip_vs_state_name(__u16 proto, int state);
726
1022
 
727
 
extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
 
1023
extern void ip_vs_tcp_conn_listen(struct net *net, struct ip_vs_conn *cp);
728
1024
extern int ip_vs_check_template(struct ip_vs_conn *ct);
729
 
extern void ip_vs_random_dropentry(void);
 
1025
extern void ip_vs_random_dropentry(struct net *net);
730
1026
extern int ip_vs_conn_init(void);
731
1027
extern void ip_vs_conn_cleanup(void);
732
1028
 
790
1086
        atomic_inc(&ctl_cp->n_control);
791
1087
}
792
1088
 
 
1089
/*
 
1090
 * IPVS netns init & cleanup functions
 
1091
 */
 
1092
extern int __ip_vs_estimator_init(struct net *net);
 
1093
extern int __ip_vs_control_init(struct net *net);
 
1094
extern int __ip_vs_protocol_init(struct net *net);
 
1095
extern int __ip_vs_app_init(struct net *net);
 
1096
extern int __ip_vs_conn_init(struct net *net);
 
1097
extern int __ip_vs_sync_init(struct net *net);
 
1098
extern void __ip_vs_conn_cleanup(struct net *net);
 
1099
extern void __ip_vs_app_cleanup(struct net *net);
 
1100
extern void __ip_vs_protocol_cleanup(struct net *net);
 
1101
extern void __ip_vs_control_cleanup(struct net *net);
 
1102
extern void __ip_vs_estimator_cleanup(struct net *net);
 
1103
extern void __ip_vs_sync_cleanup(struct net *net);
 
1104
extern void __ip_vs_service_cleanup(struct net *net);
793
1105
 
794
1106
/*
795
1107
 *      IPVS application functions
796
1108
 *      (from ip_vs_app.c)
797
1109
 */
798
1110
#define IP_VS_APP_MAX_PORTS  8
799
 
extern int register_ip_vs_app(struct ip_vs_app *app);
800
 
extern void unregister_ip_vs_app(struct ip_vs_app *app);
 
1111
extern int register_ip_vs_app(struct net *net, struct ip_vs_app *app);
 
1112
extern void unregister_ip_vs_app(struct net *net, struct ip_vs_app *app);
801
1113
extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
802
1114
extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
803
 
extern int
804
 
register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port);
 
1115
extern int register_ip_vs_app_inc(struct net *net, struct ip_vs_app *app,
 
1116
                                  __u16 proto, __u16 port);
805
1117
extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
806
1118
extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
807
1119
 
814
1126
void ip_vs_unbind_pe(struct ip_vs_service *svc);
815
1127
int register_ip_vs_pe(struct ip_vs_pe *pe);
816
1128
int unregister_ip_vs_pe(struct ip_vs_pe *pe);
817
 
extern struct ip_vs_pe *ip_vs_pe_get(const char *name);
818
 
extern void ip_vs_pe_put(struct ip_vs_pe *pe);
 
1129
struct ip_vs_pe *ip_vs_pe_getbyname(const char *name);
 
1130
struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name);
 
1131
 
 
1132
static inline void ip_vs_pe_get(const struct ip_vs_pe *pe)
 
1133
{
 
1134
        if (pe && pe->module)
 
1135
                __module_get(pe->module);
 
1136
}
 
1137
 
 
1138
static inline void ip_vs_pe_put(const struct ip_vs_pe *pe)
 
1139
{
 
1140
        if (pe && pe->module)
 
1141
                module_put(pe->module);
 
1142
}
819
1143
 
820
1144
/*
821
1145
 *      IPVS protocol functions (from ip_vs_proto.c)
822
1146
 */
823
1147
extern int ip_vs_protocol_init(void);
824
1148
extern void ip_vs_protocol_cleanup(void);
825
 
extern void ip_vs_protocol_timeout_change(int flags);
 
1149
extern void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags);
826
1150
extern int *ip_vs_create_timeout_table(int *table, int size);
827
1151
extern int
828
1152
ip_vs_set_state_timeout(int *table, int num, const char *const *names,
852
1176
extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
853
1177
extern struct ip_vs_conn *
854
1178
ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
855
 
               struct ip_vs_protocol *pp, int *ignored);
 
1179
               struct ip_vs_proto_data *pd, int *ignored);
856
1180
extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
857
 
                        struct ip_vs_protocol *pp);
 
1181
                        struct ip_vs_proto_data *pd);
 
1182
 
 
1183
extern void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg);
858
1184
 
859
1185
 
860
1186
/*
861
1187
 *      IPVS control data and functions (from ip_vs_ctl.c)
862
1188
 */
863
 
extern int sysctl_ip_vs_cache_bypass;
864
 
extern int sysctl_ip_vs_expire_nodest_conn;
865
 
extern int sysctl_ip_vs_expire_quiescent_template;
866
 
extern int sysctl_ip_vs_sync_threshold[2];
867
 
extern int sysctl_ip_vs_nat_icmp_send;
868
 
extern int sysctl_ip_vs_conntrack;
869
 
extern int sysctl_ip_vs_snat_reroute;
870
1189
extern struct ip_vs_stats ip_vs_stats;
871
1190
extern const struct ctl_path net_vs_ctl_path[];
 
1191
extern int sysctl_ip_vs_sync_ver;
872
1192
 
 
1193
extern void ip_vs_sync_switch_mode(struct net *net, int mode);
873
1194
extern struct ip_vs_service *
874
 
ip_vs_service_get(int af, __u32 fwmark, __u16 protocol,
 
1195
ip_vs_service_get(struct net *net, int af, __u32 fwmark, __u16 protocol,
875
1196
                  const union nf_inet_addr *vaddr, __be16 vport);
876
1197
 
877
1198
static inline void ip_vs_service_put(struct ip_vs_service *svc)
880
1201
}
881
1202
 
882
1203
extern struct ip_vs_dest *
883
 
ip_vs_lookup_real_service(int af, __u16 protocol,
 
1204
ip_vs_lookup_real_service(struct net *net, int af, __u16 protocol,
884
1205
                          const union nf_inet_addr *daddr, __be16 dport);
885
1206
 
886
1207
extern int ip_vs_use_count_inc(void);
888
1209
extern int ip_vs_control_init(void);
889
1210
extern void ip_vs_control_cleanup(void);
890
1211
extern struct ip_vs_dest *
891
 
ip_vs_find_dest(int af, const union nf_inet_addr *daddr, __be16 dport,
892
 
                const union nf_inet_addr *vaddr, __be16 vport, __u16 protocol);
 
1212
ip_vs_find_dest(struct net *net, int af, const union nf_inet_addr *daddr,
 
1213
                __be16 dport, const union nf_inet_addr *vaddr, __be16 vport,
 
1214
                __u16 protocol, __u32 fwmark);
893
1215
extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp);
894
1216
 
895
1217
 
897
1219
 *      IPVS sync daemon data and function prototypes
898
1220
 *      (from ip_vs_sync.c)
899
1221
 */
900
 
extern volatile int ip_vs_sync_state;
901
 
extern volatile int ip_vs_master_syncid;
902
 
extern volatile int ip_vs_backup_syncid;
903
 
extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
904
 
extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
905
 
extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
906
 
extern int stop_sync_thread(int state);
907
 
extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
 
1222
extern int start_sync_thread(struct net *net, int state, char *mcast_ifn,
 
1223
                             __u8 syncid);
 
1224
extern int stop_sync_thread(struct net *net, int state);
 
1225
extern void ip_vs_sync_conn(struct net *net, struct ip_vs_conn *cp);
 
1226
extern int ip_vs_sync_init(void);
 
1227
extern void ip_vs_sync_cleanup(void);
908
1228
 
909
1229
 
910
1230
/*
912
1232
 */
913
1233
extern int ip_vs_estimator_init(void);
914
1234
extern void ip_vs_estimator_cleanup(void);
915
 
extern void ip_vs_new_estimator(struct ip_vs_stats *stats);
916
 
extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
 
1235
extern void ip_vs_start_estimator(struct net *net, struct ip_vs_stats *stats);
 
1236
extern void ip_vs_stop_estimator(struct net *net, struct ip_vs_stats *stats);
917
1237
extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
 
1238
extern void ip_vs_read_estimator(struct ip_vs_stats_user *dst,
 
1239
                                 struct ip_vs_stats *stats);
918
1240
 
919
1241
/*
920
1242
 *      Various IPVS packet transmitters (from ip_vs_xmit.c)
930
1252
extern int ip_vs_dr_xmit
931
1253
(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
932
1254
extern int ip_vs_icmp_xmit
933
 
(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset);
 
1255
(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp,
 
1256
 int offset, unsigned int hooknum);
934
1257
extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
935
1258
 
936
1259
#ifdef CONFIG_IP_VS_IPV6
944
1267
(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
945
1268
extern int ip_vs_icmp_xmit_v6
946
1269
(struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp,
947
 
 int offset);
 
1270
 int offset, unsigned int hooknum);
948
1271
#endif
949
1272
 
 
1273
#ifdef CONFIG_SYSCTL
950
1274
/*
951
1275
 *      This is a simple mechanism to ignore packets when
952
1276
 *      we are loaded. Just set ip_vs_drop_rate to 'n' and
953
1277
 *      we start to drop 1/rate of the packets
954
1278
 */
955
 
extern int ip_vs_drop_rate;
956
 
extern int ip_vs_drop_counter;
957
1279
 
958
 
static __inline__ int ip_vs_todrop(void)
 
1280
static inline int ip_vs_todrop(struct netns_ipvs *ipvs)
959
1281
{
960
 
        if (!ip_vs_drop_rate) return 0;
961
 
        if (--ip_vs_drop_counter > 0) return 0;
962
 
        ip_vs_drop_counter = ip_vs_drop_rate;
 
1282
        if (!ipvs->drop_rate)
 
1283
                return 0;
 
1284
        if (--ipvs->drop_counter > 0)
 
1285
                return 0;
 
1286
        ipvs->drop_counter = ipvs->drop_rate;
963
1287
        return 1;
964
1288
}
 
1289
#else
 
1290
static inline int ip_vs_todrop(struct netns_ipvs *ipvs) { return 0; }
 
1291
#endif
965
1292
 
966
1293
/*
967
1294
 *      ip_vs_fwd_tag returns the forwarding tag of the connection
1031
1358
{
1032
1359
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1033
1360
        enum ip_conntrack_info ctinfo;
1034
 
        struct nf_conn *ct = ct = nf_ct_get(skb, &ctinfo);
 
1361
        struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1035
1362
 
1036
1363
        if (!ct || !nf_ct_is_untracked(ct)) {
1037
1364
                nf_reset(skb);
1047
1374
 *      Netfilter connection tracking
1048
1375
 *      (from ip_vs_nfct.c)
1049
1376
 */
1050
 
static inline int ip_vs_conntrack_enabled(void)
 
1377
static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
1051
1378
{
1052
 
        return sysctl_ip_vs_conntrack;
 
1379
#ifdef CONFIG_SYSCTL
 
1380
        return ipvs->sysctl_conntrack;
 
1381
#else
 
1382
        return 0;
 
1383
#endif
1053
1384
}
1054
1385
 
1055
1386
extern void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
1062
1393
 
1063
1394
#else
1064
1395
 
1065
 
static inline int ip_vs_conntrack_enabled(void)
 
1396
static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
1066
1397
{
1067
1398
        return 0;
1068
1399
}
1084
1415
/* CONFIG_IP_VS_NFCT */
1085
1416
#endif
1086
1417
 
1087
 
#endif /* __KERNEL__ */
 
1418
static inline unsigned int
 
1419
ip_vs_dest_conn_overhead(struct ip_vs_dest *dest)
 
1420
{
 
1421
        /*
 
1422
         * We think the overhead of processing active connections is 256
 
1423
         * times higher than that of inactive connections in average. (This
 
1424
         * 256 times might not be accurate, we will change it later) We
 
1425
         * use the following formula to estimate the overhead now:
 
1426
         *                dest->activeconns*256 + dest->inactconns
 
1427
         */
 
1428
        return (atomic_read(&dest->activeconns) << 8) +
 
1429
                atomic_read(&dest->inactconns);
 
1430
}
1088
1431
 
1089
1432
#endif  /* _NET_IP_VS_H */