3 * data structure and functionality definitions
9 #include <linux/ip_vs.h> /* definitions shared with userland */
11 #include <asm/types.h> /* for __uXX types */
13 #include <linux/list.h> /* for struct list_head */
14 #include <linux/spinlock.h> /* for struct rwlock_t */
15 #include <linux/atomic.h> /* for struct atomic_t */
16 #include <linux/compiler.h>
17 #include <linux/timer.h>
18 #include <linux/bug.h>
20 #include <net/checksum.h>
21 #include <linux/netfilter.h> /* for union nf_inet_addr */
23 #include <linux/ipv6.h> /* for struct ipv6hdr */
25 #if IS_ENABLED(CONFIG_IP_VS_IPV6)
26 #include <linux/netfilter_ipv6/ip6_tables.h>
28 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
29 #include <net/netfilter/nf_conntrack.h>
31 #include <net/net_namespace.h> /* Netw namespace */
34 * Generic access of ipvs struct
36 static inline struct netns_ipvs *net_ipvs(struct net* net)
41 * Get net ptr from skb in traffic cases
42 * use skb_sknet when call is from userland (ioctl or netlink)
44 static inline struct net *skb_net(const struct sk_buff *skb)
47 #ifdef CONFIG_IP_VS_DEBUG
49 * This is used for debug only.
50 * Start with the most likely hit
53 if (likely(skb->dev && skb->dev->nd_net))
54 return dev_net(skb->dev);
55 if (skb_dst(skb) && skb_dst(skb)->dev)
56 return dev_net(skb_dst(skb)->dev);
57 WARN(skb->sk, "Maybe skb_sknet should be used in %s() at line:%d\n",
59 if (likely(skb->sk && skb->sk->sk_net))
60 return sock_net(skb->sk);
61 pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
65 return dev_net(skb->dev ? : skb_dst(skb)->dev);
72 static inline struct net *skb_sknet(const struct sk_buff *skb)
75 #ifdef CONFIG_IP_VS_DEBUG
76 /* Start with the most likely hit */
77 if (likely(skb->sk && skb->sk->sk_net))
78 return sock_net(skb->sk);
79 WARN(skb->dev, "Maybe skb_net should be used instead in %s() line:%d\n",
81 if (likely(skb->dev && skb->dev->nd_net))
82 return dev_net(skb->dev);
83 pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
87 return sock_net(skb->sk);
94 * This one needed for single_open_net since net is stored directly in
95 * private not as a struct i.e. seq_file_net can't be used.
97 static inline struct net *seq_file_single_net(struct seq_file *seq)
100 return (struct net *)seq->private;
106 /* Connections' size value needed by ip_vs_ctl.c */
107 extern int ip_vs_conn_tab_size;
110 __u32 len; /* IPv4 simply where L4 starts
111 IPv6 where L4 Transport Header starts */
112 __u16 fragoffs; /* IPv6 fragment offset, 0 if first frag (or not frag)*/
115 union nf_inet_addr saddr;
116 union nf_inet_addr daddr;
119 static inline void *frag_safe_skb_hp(const struct sk_buff *skb, int offset,
120 int len, void *buffer,
121 const struct ip_vs_iphdr *ipvsh)
123 return skb_header_pointer(skb, offset, len, buffer);
127 ip_vs_fill_ip4hdr(const void *nh, struct ip_vs_iphdr *iphdr)
129 const struct iphdr *iph = nh;
131 iphdr->len = iph->ihl * 4;
133 iphdr->protocol = iph->protocol;
134 iphdr->saddr.ip = iph->saddr;
135 iphdr->daddr.ip = iph->daddr;
138 /* This function handles filling *ip_vs_iphdr, both for IPv4 and IPv6.
139 * IPv6 requires some extra work, as finding proper header position,
140 * depend on the IPv6 extension headers.
143 ip_vs_fill_iph_skb(int af, const struct sk_buff *skb, struct ip_vs_iphdr *iphdr)
145 #ifdef CONFIG_IP_VS_IPV6
146 if (af == AF_INET6) {
147 const struct ipv6hdr *iph =
148 (struct ipv6hdr *)skb_network_header(skb);
149 iphdr->saddr.in6 = iph->saddr;
150 iphdr->daddr.in6 = iph->daddr;
151 /* ipv6_find_hdr() updates len, flags */
154 iphdr->protocol = ipv6_find_hdr(skb, &iphdr->len, -1,
160 const struct iphdr *iph =
161 (struct iphdr *)skb_network_header(skb);
162 iphdr->len = iph->ihl * 4;
164 iphdr->protocol = iph->protocol;
165 iphdr->saddr.ip = iph->saddr;
166 iphdr->daddr.ip = iph->daddr;
170 static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
171 const union nf_inet_addr *src)
173 #ifdef CONFIG_IP_VS_IPV6
181 static inline void ip_vs_addr_set(int af, union nf_inet_addr *dst,
182 const union nf_inet_addr *src)
184 #ifdef CONFIG_IP_VS_IPV6
185 if (af == AF_INET6) {
196 static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
197 const union nf_inet_addr *b)
199 #ifdef CONFIG_IP_VS_IPV6
201 return ipv6_addr_equal(&a->in6, &b->in6);
203 return a->ip == b->ip;
206 #ifdef CONFIG_IP_VS_DEBUG
207 #include <linux/net.h>
209 int ip_vs_get_debug_level(void);
211 static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
212 const union nf_inet_addr *addr,
216 #ifdef CONFIG_IP_VS_IPV6
218 len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6c]",
222 len = snprintf(&buf[*idx], buf_len - *idx, "%pI4",
226 BUG_ON(*idx > buf_len + 1);
227 return &buf[*idx - len];
230 #define IP_VS_DBG_BUF(level, msg, ...) \
232 char ip_vs_dbg_buf[160]; \
233 int ip_vs_dbg_idx = 0; \
234 if (level <= ip_vs_get_debug_level()) \
235 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
237 #define IP_VS_ERR_BUF(msg...) \
239 char ip_vs_dbg_buf[160]; \
240 int ip_vs_dbg_idx = 0; \
244 /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */
245 #define IP_VS_DBG_ADDR(af, addr) \
246 ip_vs_dbg_addr(af, ip_vs_dbg_buf, \
247 sizeof(ip_vs_dbg_buf), addr, \
250 #define IP_VS_DBG(level, msg, ...) \
252 if (level <= ip_vs_get_debug_level()) \
253 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
255 #define IP_VS_DBG_RL(msg, ...) \
257 if (net_ratelimit()) \
258 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
260 #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) \
262 if (level <= ip_vs_get_debug_level()) \
263 pp->debug_packet(af, pp, skb, ofs, msg); \
265 #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) \
267 if (level <= ip_vs_get_debug_level() && \
269 pp->debug_packet(af, pp, skb, ofs, msg); \
271 #else /* NO DEBUGGING at ALL */
272 #define IP_VS_DBG_BUF(level, msg...) do {} while (0)
273 #define IP_VS_ERR_BUF(msg...) do {} while (0)
274 #define IP_VS_DBG(level, msg...) do {} while (0)
275 #define IP_VS_DBG_RL(msg...) do {} while (0)
276 #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
277 #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
280 #define IP_VS_BUG() BUG()
281 #define IP_VS_ERR_RL(msg, ...) \
283 if (net_ratelimit()) \
284 pr_err(msg, ##__VA_ARGS__); \
287 #ifdef CONFIG_IP_VS_DEBUG
288 #define EnterFunction(level) \
290 if (level <= ip_vs_get_debug_level()) \
292 pr_fmt("Enter: %s, %s line %i\n"), \
293 __func__, __FILE__, __LINE__); \
295 #define LeaveFunction(level) \
297 if (level <= ip_vs_get_debug_level()) \
299 pr_fmt("Leave: %s, %s line %i\n"), \
300 __func__, __FILE__, __LINE__); \
303 #define EnterFunction(level) do {} while (0)
304 #define LeaveFunction(level) do {} while (0)
309 * The port number of FTP service (in network order).
311 #define FTPPORT cpu_to_be16(21)
312 #define FTPDATA cpu_to_be16(20)
318 IP_VS_TCP_S_NONE = 0,
319 IP_VS_TCP_S_ESTABLISHED,
320 IP_VS_TCP_S_SYN_SENT,
321 IP_VS_TCP_S_SYN_RECV,
322 IP_VS_TCP_S_FIN_WAIT,
323 IP_VS_TCP_S_TIME_WAIT,
325 IP_VS_TCP_S_CLOSE_WAIT,
326 IP_VS_TCP_S_LAST_ACK,
351 enum ip_vs_sctp_states {
355 IP_VS_SCTP_S_COOKIE_SENT,
356 IP_VS_SCTP_S_COOKIE_REPLIED,
357 IP_VS_SCTP_S_COOKIE_WAIT,
359 IP_VS_SCTP_S_COOKIE_ECHOED,
360 IP_VS_SCTP_S_ESTABLISHED,
361 IP_VS_SCTP_S_SHUTDOWN_SENT,
362 IP_VS_SCTP_S_SHUTDOWN_RECEIVED,
363 IP_VS_SCTP_S_SHUTDOWN_ACK_SENT,
364 IP_VS_SCTP_S_REJECTED,
370 * Delta sequence info structure
371 * Each ip_vs_conn has 2 (output AND input seq. changes).
372 * Only used in the VS/NAT.
375 __u32 init_seq; /* Add delta from this seq */
376 __u32 delta; /* Delta in sequence numbers */
377 __u32 previous_delta; /* Delta in sequence numbers
378 before last resized pkt */
384 struct ip_vs_counters {
385 __u32 conns; /* connections scheduled */
386 __u32 inpkts; /* incoming packets */
387 __u32 outpkts; /* outgoing packets */
388 __u64 inbytes; /* incoming bytes */
389 __u64 outbytes; /* outgoing bytes */
394 struct ip_vs_cpu_stats {
395 struct ip_vs_counters ustats;
396 struct u64_stats_sync syncp;
400 * IPVS statistics objects
402 struct ip_vs_estimator {
403 struct list_head list;
419 struct ip_vs_stats_user ustats; /* statistics */
420 struct ip_vs_estimator est; /* estimator */
421 struct ip_vs_cpu_stats __percpu *cpustats; /* per cpu counters */
422 spinlock_t lock; /* spin lock */
423 struct ip_vs_stats_user ustats0; /* reset values */
431 struct ip_vs_proto_data;
433 struct ip_vs_protocol {
434 struct ip_vs_protocol *next;
440 void (*init)(struct ip_vs_protocol *pp);
442 void (*exit)(struct ip_vs_protocol *pp);
444 int (*init_netns)(struct net *net, struct ip_vs_proto_data *pd);
446 void (*exit_netns)(struct net *net, struct ip_vs_proto_data *pd);
448 int (*conn_schedule)(int af, struct sk_buff *skb,
449 struct ip_vs_proto_data *pd,
450 int *verdict, struct ip_vs_conn **cpp,
451 struct ip_vs_iphdr *iph);
454 (*conn_in_get)(int af,
455 const struct sk_buff *skb,
456 const struct ip_vs_iphdr *iph,
460 (*conn_out_get)(int af,
461 const struct sk_buff *skb,
462 const struct ip_vs_iphdr *iph,
465 int (*snat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp,
466 struct ip_vs_conn *cp, struct ip_vs_iphdr *iph);
468 int (*dnat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp,
469 struct ip_vs_conn *cp, struct ip_vs_iphdr *iph);
471 int (*csum_check)(int af, struct sk_buff *skb,
472 struct ip_vs_protocol *pp);
474 const char *(*state_name)(int state);
476 void (*state_transition)(struct ip_vs_conn *cp, int direction,
477 const struct sk_buff *skb,
478 struct ip_vs_proto_data *pd);
480 int (*register_app)(struct net *net, struct ip_vs_app *inc);
482 void (*unregister_app)(struct net *net, struct ip_vs_app *inc);
484 int (*app_conn_bind)(struct ip_vs_conn *cp);
486 void (*debug_packet)(int af, struct ip_vs_protocol *pp,
487 const struct sk_buff *skb,
491 void (*timeout_change)(struct ip_vs_proto_data *pd, int flags);
495 * protocol data per netns
497 struct ip_vs_proto_data {
498 struct ip_vs_proto_data *next;
499 struct ip_vs_protocol *pp;
500 int *timeout_table; /* protocol timeout table */
501 atomic_t appcnt; /* counter of proto app incs. */
502 struct tcp_states_t *tcp_state_table;
505 struct ip_vs_protocol *ip_vs_proto_get(unsigned short proto);
506 struct ip_vs_proto_data *ip_vs_proto_data_get(struct net *net,
507 unsigned short proto);
509 struct ip_vs_conn_param {
511 const union nf_inet_addr *caddr;
512 const union nf_inet_addr *vaddr;
518 const struct ip_vs_pe *pe;
524 * IP_VS structure allocated for each dynamically scheduled connection
527 struct hlist_node c_list; /* hashed list heads */
528 /* Protocol, addresses and port numbers */
532 u16 af; /* address family */
533 union nf_inet_addr caddr; /* client address */
534 union nf_inet_addr vaddr; /* virtual address */
535 union nf_inet_addr daddr; /* destination address */
536 volatile __u32 flags; /* status flags */
537 __u16 protocol; /* Which protocol (TCP/UDP) */
538 __u16 daf; /* Address family of the dest */
540 struct net *net; /* Name space */
543 /* counter and timer */
544 atomic_t refcnt; /* reference count */
545 struct timer_list timer; /* Expiration timer */
546 volatile unsigned long timeout; /* timeout */
548 /* Flags and state transition */
549 spinlock_t lock; /* lock for state transition */
550 volatile __u16 state; /* state info */
551 volatile __u16 old_state; /* old state, to be used for
552 * state transition triggerd
555 __u32 fwmark; /* Fire wall mark from skb */
556 unsigned long sync_endtime; /* jiffies + sent_retries */
558 /* Control members */
559 struct ip_vs_conn *control; /* Master control connection */
560 atomic_t n_control; /* Number of controlled ones */
561 struct ip_vs_dest *dest; /* real server */
562 atomic_t in_pkts; /* incoming packet counter */
564 /* packet transmitter for different forwarding methods. If it
565 mangles the packet, it must return NF_DROP or better NF_STOLEN,
566 otherwise this must be changed to a sk_buff **.
567 NF_ACCEPT can be returned when destination is local.
569 int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
570 struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
572 /* Note: we can group the following members into a structure,
573 in order to save more space, and the following members are
574 only used in VS/NAT anyway */
575 struct ip_vs_app *app; /* bound ip_vs_app object */
576 void *app_data; /* Application private data */
577 struct ip_vs_seq in_seq; /* incoming seq. struct */
578 struct ip_vs_seq out_seq; /* outgoing seq. struct */
580 const struct ip_vs_pe *pe;
584 struct rcu_head rcu_head;
588 * To save some memory in conn table when name space is disabled.
590 static inline struct net *ip_vs_conn_net(const struct ip_vs_conn *cp)
598 static inline void ip_vs_conn_net_set(struct ip_vs_conn *cp, struct net *net)
605 static inline int ip_vs_conn_net_eq(const struct ip_vs_conn *cp,
609 return cp->net == net;
616 * Extended internal versions of struct ip_vs_service_user and
617 * ip_vs_dest_user for IPv6 support.
619 * We need these to conveniently pass around service and destination
620 * options, but unfortunately, we also need to keep the old definitions to
621 * maintain userspace backwards compatibility for the setsockopt interface.
623 struct ip_vs_service_user_kern {
624 /* virtual service addresses */
627 union nf_inet_addr addr; /* virtual ip address */
629 u32 fwmark; /* firwall mark of service */
631 /* virtual service options */
634 unsigned int flags; /* virtual service flags */
635 unsigned int timeout; /* persistent timeout in sec */
636 __be32 netmask; /* persistent netmask or plen */
640 struct ip_vs_dest_user_kern {
641 /* destination server address */
642 union nf_inet_addr addr;
645 /* real server options */
646 unsigned int conn_flags; /* connection flags */
647 int weight; /* destination weight */
649 /* thresholds for active connections */
650 u32 u_threshold; /* upper threshold */
651 u32 l_threshold; /* lower threshold */
653 /* Address family of addr */
659 * The information about the virtual service offered to the net
660 * and the forwarding entries
662 struct ip_vs_service {
663 struct hlist_node s_list; /* for normal service table */
664 struct hlist_node f_list; /* for fwmark-based service table */
665 atomic_t refcnt; /* reference counter */
667 u16 af; /* address family */
668 __u16 protocol; /* which protocol (TCP/UDP) */
669 union nf_inet_addr addr; /* IP address for virtual service */
670 __be16 port; /* port number for the service */
671 __u32 fwmark; /* firewall mark of the service */
672 unsigned int flags; /* service status flags */
673 unsigned int timeout; /* persistent timeout in ticks */
674 __be32 netmask; /* grouping granularity, mask/plen */
677 struct list_head destinations; /* real server d-linked list */
678 __u32 num_dests; /* number of servers */
679 struct ip_vs_stats stats; /* statistics for the service */
682 struct ip_vs_scheduler __rcu *scheduler; /* bound scheduler object */
683 spinlock_t sched_lock; /* lock sched_data */
684 void *sched_data; /* scheduler application data */
686 /* alternate persistence engine */
687 struct ip_vs_pe __rcu *pe;
689 struct rcu_head rcu_head;
692 /* Information for cached dst */
693 struct ip_vs_dest_dst {
694 struct dst_entry *dst_cache; /* destination cache entry */
696 union nf_inet_addr dst_saddr;
697 struct rcu_head rcu_head;
701 * The real server destination forwarding entry
702 * with ip address, port number, and so on.
705 struct list_head n_list; /* for the dests in the service */
706 struct hlist_node d_list; /* for table with all the dests */
708 u16 af; /* address family */
709 __be16 port; /* port number of the server */
710 union nf_inet_addr addr; /* IP address of the server */
711 volatile unsigned int flags; /* dest status flags */
712 atomic_t conn_flags; /* flags to copy to conn */
713 atomic_t weight; /* server weight */
715 atomic_t refcnt; /* reference counter */
716 struct ip_vs_stats stats; /* statistics */
717 unsigned long idle_start; /* start time, jiffies */
719 /* connection counters and thresholds */
720 atomic_t activeconns; /* active connections */
721 atomic_t inactconns; /* inactive connections */
722 atomic_t persistconns; /* persistent connections */
723 __u32 u_threshold; /* upper threshold */
724 __u32 l_threshold; /* lower threshold */
726 /* for destination cache */
727 spinlock_t dst_lock; /* lock of dst_cache */
728 struct ip_vs_dest_dst __rcu *dest_dst; /* cached dst info */
730 /* for virtual service */
731 struct ip_vs_service __rcu *svc; /* service it belongs to */
732 __u16 protocol; /* which protocol (TCP/UDP) */
733 __be16 vport; /* virtual port number */
734 union nf_inet_addr vaddr; /* virtual IP address */
735 __u32 vfwmark; /* firewall mark of service */
737 struct list_head t_list; /* in dest_trash */
738 unsigned int in_rs_table:1; /* we are in rs_table */
743 * The scheduler object
745 struct ip_vs_scheduler {
746 struct list_head n_list; /* d-linked list head */
747 char *name; /* scheduler name */
748 atomic_t refcnt; /* reference counter */
749 struct module *module; /* THIS_MODULE/NULL */
751 /* scheduler initializing service */
752 int (*init_service)(struct ip_vs_service *svc);
753 /* scheduling service finish */
754 void (*done_service)(struct ip_vs_service *svc);
756 int (*add_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
757 /* dest is unlinked */
758 int (*del_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
759 /* dest is updated */
760 int (*upd_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
762 /* selecting a server from the given service */
763 struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
764 const struct sk_buff *skb,
765 struct ip_vs_iphdr *iph);
768 /* The persistence engine object */
770 struct list_head n_list; /* d-linked list head */
771 char *name; /* scheduler name */
772 atomic_t refcnt; /* reference counter */
773 struct module *module; /* THIS_MODULE/NULL */
775 /* get the connection template, if any */
776 int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb);
777 bool (*ct_match)(const struct ip_vs_conn_param *p,
778 struct ip_vs_conn *ct);
779 u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval,
781 int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf);
785 * The application module object (a.k.a. app incarnation)
788 struct list_head a_list; /* member in app list */
789 int type; /* IP_VS_APP_TYPE_xxx */
790 char *name; /* application module name */
792 struct module *module; /* THIS_MODULE/NULL */
793 struct list_head incs_list; /* list of incarnations */
795 /* members for application incarnations */
796 struct list_head p_list; /* member in proto app list */
797 struct ip_vs_app *app; /* its real application */
798 __be16 port; /* port number in net order */
799 atomic_t usecnt; /* usage counter */
800 struct rcu_head rcu_head;
803 * output hook: Process packet in inout direction, diff set for TCP.
804 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
805 * 2=Mangled but checksum was not updated
807 int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
808 struct sk_buff *, int *diff);
811 * input hook: Process packet in outin direction, diff set for TCP.
812 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
813 * 2=Mangled but checksum was not updated
815 int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
816 struct sk_buff *, int *diff);
818 /* ip_vs_app initializer */
819 int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
821 /* ip_vs_app finish */
822 int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
826 int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
827 struct ip_vs_protocol *);
829 void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
835 int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
836 int *verdict, struct ip_vs_conn **cpp);
839 (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
840 const struct iphdr *iph, int inverse);
843 (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
844 const struct iphdr *iph, int inverse);
846 int (*state_transition)(struct ip_vs_conn *cp, int direction,
847 const struct sk_buff *skb,
848 struct ip_vs_app *app);
850 void (*timeout_change)(struct ip_vs_app *app, int flags);
853 struct ipvs_master_sync_state {
854 struct list_head sync_queue;
855 struct ip_vs_sync_buff *sync_buff;
856 unsigned long sync_queue_len;
857 unsigned int sync_queue_delay;
858 struct task_struct *master_thread;
859 struct delayed_work master_wakeup_work;
860 struct netns_ipvs *ipvs;
863 /* How much time to keep dests in trash */
864 #define IP_VS_DEST_TRASH_PERIOD (120 * HZ)
866 /* IPVS in network namespace */
868 int gen; /* Generation */
869 int enable; /* enable like nf_hooks do */
871 * Hash table: for real service lookups
873 #define IP_VS_RTAB_BITS 4
874 #define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS)
875 #define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1)
877 struct hlist_head rs_table[IP_VS_RTAB_SIZE];
879 struct list_head app_list;
881 #define IP_VS_PROTO_TAB_SIZE 32 /* must be power of 2 */
882 struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE];
883 /* ip_vs_proto_tcp */
884 #ifdef CONFIG_IP_VS_PROTO_TCP
885 #define TCP_APP_TAB_BITS 4
886 #define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS)
887 #define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1)
888 struct list_head tcp_apps[TCP_APP_TAB_SIZE];
890 /* ip_vs_proto_udp */
891 #ifdef CONFIG_IP_VS_PROTO_UDP
892 #define UDP_APP_TAB_BITS 4
893 #define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS)
894 #define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1)
895 struct list_head udp_apps[UDP_APP_TAB_SIZE];
897 /* ip_vs_proto_sctp */
898 #ifdef CONFIG_IP_VS_PROTO_SCTP
899 #define SCTP_APP_TAB_BITS 4
900 #define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS)
901 #define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1)
902 /* Hash table for SCTP application incarnations */
903 struct list_head sctp_apps[SCTP_APP_TAB_SIZE];
906 atomic_t conn_count; /* connection counter */
909 struct ip_vs_stats tot_stats; /* Statistics & est. */
911 int num_services; /* no of virtual services */
913 /* Trash for destinations */
914 struct list_head dest_trash;
915 spinlock_t dest_trash_lock;
916 struct timer_list dest_trash_timer; /* expiration timer */
917 /* Service counters */
918 atomic_t ftpsvc_counter;
919 atomic_t nullsvc_counter;
922 /* 1/rate drop and drop-entry variables */
923 struct delayed_work defense_work; /* Work handler */
928 spinlock_t dropentry_lock; /* drop entry handling */
929 spinlock_t droppacket_lock; /* drop packet handling */
930 spinlock_t securetcp_lock; /* state and timeout tables */
933 struct ctl_table_header *sysctl_hdr;
934 struct ctl_table *sysctl_tbl;
937 /* sysctl variables */
938 int sysctl_amemthresh;
939 int sysctl_am_droprate;
940 int sysctl_drop_entry;
941 int sysctl_drop_packet;
942 int sysctl_secure_tcp;
943 #ifdef CONFIG_IP_VS_NFCT
944 int sysctl_conntrack;
946 int sysctl_snat_reroute;
948 int sysctl_sync_ports;
949 int sysctl_sync_persist_mode;
950 unsigned long sysctl_sync_qlen_max;
951 int sysctl_sync_sock_size;
952 int sysctl_cache_bypass;
953 int sysctl_expire_nodest_conn;
954 int sysctl_sloppy_tcp;
955 int sysctl_sloppy_sctp;
956 int sysctl_expire_quiescent_template;
957 int sysctl_sync_threshold[2];
958 unsigned int sysctl_sync_refresh_period;
959 int sysctl_sync_retries;
960 int sysctl_nat_icmp_send;
961 int sysctl_pmtu_disc;
962 int sysctl_backup_only;
965 int sysctl_lblc_expiration;
966 struct ctl_table_header *lblc_ctl_header;
967 struct ctl_table *lblc_ctl_table;
969 int sysctl_lblcr_expiration;
970 struct ctl_table_header *lblcr_ctl_header;
971 struct ctl_table *lblcr_ctl_table;
973 struct list_head est_list; /* estimator list */
975 struct timer_list est_timer; /* Estimation timer */
977 spinlock_t sync_lock;
978 struct ipvs_master_sync_state *ms;
979 spinlock_t sync_buff_lock;
980 struct task_struct **backup_threads;
982 int send_mesg_maxlen;
983 int recv_mesg_maxlen;
984 volatile int sync_state;
985 volatile int master_syncid;
986 volatile int backup_syncid;
987 struct mutex sync_mutex;
988 /* multicast interface name */
989 char master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
990 char backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
991 /* net name space ptr */
992 struct net *net; /* Needed by timer routines */
993 /* Number of heterogeneous destinations, needed because
994 * heterogeneous are not supported when synchronization is
996 unsigned int mixed_address_family_dests;
999 #define DEFAULT_SYNC_THRESHOLD 3
1000 #define DEFAULT_SYNC_PERIOD 50
1001 #define DEFAULT_SYNC_VER 1
1002 #define DEFAULT_SLOPPY_TCP 0
1003 #define DEFAULT_SLOPPY_SCTP 0
1004 #define DEFAULT_SYNC_REFRESH_PERIOD (0U * HZ)
1005 #define DEFAULT_SYNC_RETRIES 0
1006 #define IPVS_SYNC_WAKEUP_RATE 8
1007 #define IPVS_SYNC_QLEN_MAX (IPVS_SYNC_WAKEUP_RATE * 4)
1008 #define IPVS_SYNC_SEND_DELAY (HZ / 50)
1009 #define IPVS_SYNC_CHECK_PERIOD HZ
1010 #define IPVS_SYNC_FLUSH_TIME (HZ * 2)
1011 #define IPVS_SYNC_PORTS_MAX (1 << 6)
1013 #ifdef CONFIG_SYSCTL
1015 static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
1017 return ipvs->sysctl_sync_threshold[0];
1020 static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
1022 return ACCESS_ONCE(ipvs->sysctl_sync_threshold[1]);
1025 static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
1027 return ACCESS_ONCE(ipvs->sysctl_sync_refresh_period);
1030 static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
1032 return ipvs->sysctl_sync_retries;
1035 static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
1037 return ipvs->sysctl_sync_ver;
1040 static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs)
1042 return ipvs->sysctl_sloppy_tcp;
1045 static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs)
1047 return ipvs->sysctl_sloppy_sctp;
1050 static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
1052 return ACCESS_ONCE(ipvs->sysctl_sync_ports);
1055 static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs)
1057 return ipvs->sysctl_sync_persist_mode;
1060 static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
1062 return ipvs->sysctl_sync_qlen_max;
1065 static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
1067 return ipvs->sysctl_sync_sock_size;
1070 static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
1072 return ipvs->sysctl_pmtu_disc;
1075 static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
1077 return ipvs->sync_state & IP_VS_STATE_BACKUP &&
1078 ipvs->sysctl_backup_only;
1083 static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
1085 return DEFAULT_SYNC_THRESHOLD;
1088 static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
1090 return DEFAULT_SYNC_PERIOD;
1093 static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
1095 return DEFAULT_SYNC_REFRESH_PERIOD;
1098 static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
1100 return DEFAULT_SYNC_RETRIES & 3;
1103 static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
1105 return DEFAULT_SYNC_VER;
1108 static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs)
1110 return DEFAULT_SLOPPY_TCP;
1113 static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs)
1115 return DEFAULT_SLOPPY_SCTP;
1118 static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
1123 static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs)
1128 static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
1130 return IPVS_SYNC_QLEN_MAX;
1133 static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
1138 static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
1143 static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
1151 * IPVS core functions
1152 * (from ip_vs_core.c)
1154 const char *ip_vs_proto_name(unsigned int proto);
1155 void ip_vs_init_hash_table(struct list_head *table, int rows);
1156 #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
1158 #define IP_VS_APP_TYPE_FTP 1
1161 * ip_vs_conn handling functions
1162 * (from ip_vs_conn.c)
1166 IP_VS_DIR_INPUT = 0,
1168 IP_VS_DIR_INPUT_ONLY,
1172 static inline void ip_vs_conn_fill_param(struct net *net, int af, int protocol,
1173 const union nf_inet_addr *caddr,
1175 const union nf_inet_addr *vaddr,
1177 struct ip_vs_conn_param *p)
1181 p->protocol = protocol;
1190 struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p);
1191 struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p);
1193 struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb,
1194 const struct ip_vs_iphdr *iph,
1197 struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p);
1199 struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb,
1200 const struct ip_vs_iphdr *iph,
1203 /* Get reference to gain full access to conn.
1204 * By default, RCU read-side critical sections have access only to
1205 * conn fields and its PE data, see ip_vs_conn_rcu_free() for reference.
1207 static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp)
1209 return atomic_inc_not_zero(&cp->refcnt);
1212 /* put back the conn without restarting its timer */
1213 static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
1215 smp_mb__before_atomic();
1216 atomic_dec(&cp->refcnt);
1218 void ip_vs_conn_put(struct ip_vs_conn *cp);
1219 void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
1221 struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
1222 const union nf_inet_addr *daddr,
1223 __be16 dport, unsigned int flags,
1224 struct ip_vs_dest *dest, __u32 fwmark);
1225 void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
1227 const char *ip_vs_state_name(__u16 proto, int state);
1229 void ip_vs_tcp_conn_listen(struct net *net, struct ip_vs_conn *cp);
1230 int ip_vs_check_template(struct ip_vs_conn *ct);
1231 void ip_vs_random_dropentry(struct net *net);
1232 int ip_vs_conn_init(void);
1233 void ip_vs_conn_cleanup(void);
1235 static inline void ip_vs_control_del(struct ip_vs_conn *cp)
1237 struct ip_vs_conn *ctl_cp = cp->control;
1239 IP_VS_ERR_BUF("request control DEL for uncontrolled: "
1241 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1243 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
1249 IP_VS_DBG_BUF(7, "DELeting control for: "
1250 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
1251 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1253 IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
1254 ntohs(ctl_cp->cport));
1257 if (atomic_read(&ctl_cp->n_control) == 0) {
1258 IP_VS_ERR_BUF("BUG control DEL with n=0 : "
1260 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1262 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
1267 atomic_dec(&ctl_cp->n_control);
1271 ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
1274 IP_VS_ERR_BUF("request control ADD for already controlled: "
1276 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1278 IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
1281 ip_vs_control_del(cp);
1284 IP_VS_DBG_BUF(7, "ADDing control for: "
1285 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
1286 IP_VS_DBG_ADDR(cp->af, &cp->caddr),
1288 IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
1289 ntohs(ctl_cp->cport));
1291 cp->control = ctl_cp;
1292 atomic_inc(&ctl_cp->n_control);
1296 * IPVS netns init & cleanup functions
1298 int ip_vs_estimator_net_init(struct net *net);
1299 int ip_vs_control_net_init(struct net *net);
1300 int ip_vs_protocol_net_init(struct net *net);
1301 int ip_vs_app_net_init(struct net *net);
1302 int ip_vs_conn_net_init(struct net *net);
1303 int ip_vs_sync_net_init(struct net *net);
1304 void ip_vs_conn_net_cleanup(struct net *net);
1305 void ip_vs_app_net_cleanup(struct net *net);
1306 void ip_vs_protocol_net_cleanup(struct net *net);
1307 void ip_vs_control_net_cleanup(struct net *net);
1308 void ip_vs_estimator_net_cleanup(struct net *net);
1309 void ip_vs_sync_net_cleanup(struct net *net);
1310 void ip_vs_service_net_cleanup(struct net *net);
1313 * IPVS application functions
1314 * (from ip_vs_app.c)
1316 #define IP_VS_APP_MAX_PORTS 8
1317 struct ip_vs_app *register_ip_vs_app(struct net *net, struct ip_vs_app *app);
1318 void unregister_ip_vs_app(struct net *net, struct ip_vs_app *app);
1319 int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
1320 void ip_vs_unbind_app(struct ip_vs_conn *cp);
1321 int register_ip_vs_app_inc(struct net *net, struct ip_vs_app *app, __u16 proto,
1323 int ip_vs_app_inc_get(struct ip_vs_app *inc);
1324 void ip_vs_app_inc_put(struct ip_vs_app *inc);
1326 int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
1327 int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
1329 int register_ip_vs_pe(struct ip_vs_pe *pe);
1330 int unregister_ip_vs_pe(struct ip_vs_pe *pe);
1331 struct ip_vs_pe *ip_vs_pe_getbyname(const char *name);
1332 struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name);
1335 * Use a #define to avoid all of module.h just for these trivial ops
1337 #define ip_vs_pe_get(pe) \
1338 if (pe && pe->module) \
1339 __module_get(pe->module);
1341 #define ip_vs_pe_put(pe) \
1342 if (pe && pe->module) \
1343 module_put(pe->module);
1346 * IPVS protocol functions (from ip_vs_proto.c)
1348 int ip_vs_protocol_init(void);
1349 void ip_vs_protocol_cleanup(void);
1350 void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags);
1351 int *ip_vs_create_timeout_table(int *table, int size);
1352 int ip_vs_set_state_timeout(int *table, int num, const char *const *names,
1353 const char *name, int to);
1354 void ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,
1355 const struct sk_buff *skb, int offset,
1358 extern struct ip_vs_protocol ip_vs_protocol_tcp;
1359 extern struct ip_vs_protocol ip_vs_protocol_udp;
1360 extern struct ip_vs_protocol ip_vs_protocol_icmp;
1361 extern struct ip_vs_protocol ip_vs_protocol_esp;
1362 extern struct ip_vs_protocol ip_vs_protocol_ah;
1363 extern struct ip_vs_protocol ip_vs_protocol_sctp;
1366 * Registering/unregistering scheduler functions
1367 * (from ip_vs_sched.c)
1369 int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
1370 int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
1371 int ip_vs_bind_scheduler(struct ip_vs_service *svc,
1372 struct ip_vs_scheduler *scheduler);
1373 void ip_vs_unbind_scheduler(struct ip_vs_service *svc,
1374 struct ip_vs_scheduler *sched);
1375 struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
1376 void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
1378 ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
1379 struct ip_vs_proto_data *pd, int *ignored,
1380 struct ip_vs_iphdr *iph);
1381 int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
1382 struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph);
1384 void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg);
1388 * IPVS control data and functions (from ip_vs_ctl.c)
1390 extern struct ip_vs_stats ip_vs_stats;
1391 extern int sysctl_ip_vs_sync_ver;
1393 struct ip_vs_service *
1394 ip_vs_service_find(struct net *net, int af, __u32 fwmark, __u16 protocol,
1395 const union nf_inet_addr *vaddr, __be16 vport);
1397 bool ip_vs_has_real_service(struct net *net, int af, __u16 protocol,
1398 const union nf_inet_addr *daddr, __be16 dport);
1400 int ip_vs_use_count_inc(void);
1401 void ip_vs_use_count_dec(void);
1402 int ip_vs_register_nl_ioctl(void);
1403 void ip_vs_unregister_nl_ioctl(void);
1404 int ip_vs_control_init(void);
1405 void ip_vs_control_cleanup(void);
1407 ip_vs_find_dest(struct net *net, int svc_af, int dest_af,
1408 const union nf_inet_addr *daddr, __be16 dport,
1409 const union nf_inet_addr *vaddr, __be16 vport,
1410 __u16 protocol, __u32 fwmark, __u32 flags);
1411 void ip_vs_try_bind_dest(struct ip_vs_conn *cp);
1413 static inline void ip_vs_dest_hold(struct ip_vs_dest *dest)
1415 atomic_inc(&dest->refcnt);
1418 static inline void ip_vs_dest_put(struct ip_vs_dest *dest)
1420 smp_mb__before_atomic();
1421 atomic_dec(&dest->refcnt);
1424 static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)
1426 if (atomic_dec_return(&dest->refcnt) < 0)
1431 * IPVS sync daemon data and function prototypes
1432 * (from ip_vs_sync.c)
1434 int start_sync_thread(struct net *net, int state, char *mcast_ifn, __u8 syncid);
1435 int stop_sync_thread(struct net *net, int state);
1436 void ip_vs_sync_conn(struct net *net, struct ip_vs_conn *cp, int pkts);
1439 * IPVS rate estimator prototypes (from ip_vs_est.c)
1441 void ip_vs_start_estimator(struct net *net, struct ip_vs_stats *stats);
1442 void ip_vs_stop_estimator(struct net *net, struct ip_vs_stats *stats);
1443 void ip_vs_zero_estimator(struct ip_vs_stats *stats);
1444 void ip_vs_read_estimator(struct ip_vs_stats_user *dst,
1445 struct ip_vs_stats *stats);
1448 * Various IPVS packet transmitters (from ip_vs_xmit.c)
1450 int ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1451 struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
1452 int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1453 struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
1454 int ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1455 struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
1456 int ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1457 struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
1458 int ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1459 struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
1460 int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
1461 struct ip_vs_protocol *pp, int offset,
1462 unsigned int hooknum, struct ip_vs_iphdr *iph);
1463 void ip_vs_dest_dst_rcu_free(struct rcu_head *head);
1465 #ifdef CONFIG_IP_VS_IPV6
1466 int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1467 struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
1468 int ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1469 struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
1470 int ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1471 struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
1472 int ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1473 struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
1474 int ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
1475 struct ip_vs_protocol *pp, int offset,
1476 unsigned int hooknum, struct ip_vs_iphdr *iph);
1479 #ifdef CONFIG_SYSCTL
1481 * This is a simple mechanism to ignore packets when
1482 * we are loaded. Just set ip_vs_drop_rate to 'n' and
1483 * we start to drop 1/rate of the packets
1486 static inline int ip_vs_todrop(struct netns_ipvs *ipvs)
1488 if (!ipvs->drop_rate)
1490 if (--ipvs->drop_counter > 0)
1492 ipvs->drop_counter = ipvs->drop_rate;
1496 static inline int ip_vs_todrop(struct netns_ipvs *ipvs) { return 0; }
1500 * ip_vs_fwd_tag returns the forwarding tag of the connection
1502 #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
1504 static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
1508 switch (IP_VS_FWD_METHOD(cp)) {
1509 case IP_VS_CONN_F_MASQ:
1511 case IP_VS_CONN_F_LOCALNODE:
1513 case IP_VS_CONN_F_TUNNEL:
1515 case IP_VS_CONN_F_DROUTE:
1517 case IP_VS_CONN_F_BYPASS:
1525 void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
1526 struct ip_vs_conn *cp, int dir);
1528 #ifdef CONFIG_IP_VS_IPV6
1529 void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
1530 struct ip_vs_conn *cp, int dir);
1533 __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
1535 static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
1537 __be32 diff[2] = { ~old, new };
1539 return csum_partial(diff, sizeof(diff), oldsum);
1542 #ifdef CONFIG_IP_VS_IPV6
1543 static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new,
1546 __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
1547 new[3], new[2], new[1], new[0] };
1549 return csum_partial(diff, sizeof(diff), oldsum);
1553 static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
1555 __be16 diff[2] = { ~old, new };
1557 return csum_partial(diff, sizeof(diff), oldsum);
1561 * Forget current conntrack (unconfirmed) and attach notrack entry
1563 static inline void ip_vs_notrack(struct sk_buff *skb)
1565 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1566 enum ip_conntrack_info ctinfo;
1567 struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
1569 if (!ct || !nf_ct_is_untracked(ct)) {
1570 nf_conntrack_put(skb->nfct);
1571 skb->nfct = &nf_ct_untracked_get()->ct_general;
1572 skb->nfctinfo = IP_CT_NEW;
1573 nf_conntrack_get(skb->nfct);
1578 #ifdef CONFIG_IP_VS_NFCT
1580 * Netfilter connection tracking
1581 * (from ip_vs_nfct.c)
1583 static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
1585 #ifdef CONFIG_SYSCTL
1586 return ipvs->sysctl_conntrack;
1592 void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
1594 int ip_vs_confirm_conntrack(struct sk_buff *skb);
1595 void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct,
1596 struct ip_vs_conn *cp, u_int8_t proto,
1597 const __be16 port, int from_rs);
1598 void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp);
1602 static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
1607 static inline void ip_vs_update_conntrack(struct sk_buff *skb,
1608 struct ip_vs_conn *cp, int outin)
1612 static inline int ip_vs_confirm_conntrack(struct sk_buff *skb)
1617 static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
1620 /* CONFIG_IP_VS_NFCT */
1624 ip_vs_dest_conn_overhead(struct ip_vs_dest *dest)
1627 * We think the overhead of processing active connections is 256
1628 * times higher than that of inactive connections in average. (This
1629 * 256 times might not be accurate, we will change it later) We
1630 * use the following formula to estimate the overhead now:
1631 * dest->activeconns*256 + dest->inactconns
1633 return (atomic_read(&dest->activeconns) << 8) +
1634 atomic_read(&dest->inactconns);
1637 #endif /* _NET_IP_VS_H */