2 * data structure and functionality definitions
8 #include <linux/ip_vs.h> /* definitions shared with userland */
10 #include <asm/types.h> /* for __uXX types */
12 #include <linux/list.h> /* for struct list_head */
13 #include <linux/spinlock.h> /* for struct rwlock_t */
14 #include <linux/atomic.h> /* for struct atomic_t */
15 #include <linux/compiler.h>
16 #include <linux/timer.h>
17 #include <linux/bug.h>
19 #include <net/checksum.h>
20 #include <linux/netfilter.h> /* for union nf_inet_addr */
22 #include <linux/ipv6.h> /* for struct ipv6hdr */
24 #if IS_ENABLED(CONFIG_IP_VS_IPV6)
25 #include <linux/netfilter_ipv6/ip6_tables.h>
27 #if IS_ENABLED(CONFIG_NF_CONNTRACK)
28 #include <net/netfilter/nf_conntrack.h>
30 #include <net/net_namespace.h> /* Netw namespace */
32 /* Generic access of ipvs struct */
33 static inline struct netns_ipvs
*net_ipvs(struct net
* net
)
38 /* Get net ptr from skb in traffic cases
39 * use skb_sknet when call is from userland (ioctl or netlink)
41 static inline struct net
*skb_net(const struct sk_buff
*skb
)
44 #ifdef CONFIG_IP_VS_DEBUG
46 * This is used for debug only.
47 * Start with the most likely hit
50 if (likely(skb
->dev
&& dev_net(skb
->dev
)))
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",
56 if (likely(skb
->sk
&& sock_net(skb
->sk
)))
57 return sock_net(skb
->sk
);
58 pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
62 return dev_net(skb
->dev
? : skb_dst(skb
)->dev
);
69 static inline struct net
*skb_sknet(const struct sk_buff
*skb
)
72 #ifdef CONFIG_IP_VS_DEBUG
73 /* Start with the most likely hit */
74 if (likely(skb
->sk
&& sock_net(skb
->sk
)))
75 return sock_net(skb
->sk
);
76 WARN(skb
->dev
, "Maybe skb_net should be used instead in %s() line:%d\n",
78 if (likely(skb
->dev
&& dev_net(skb
->dev
)))
79 return dev_net(skb
->dev
);
80 pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
84 return sock_net(skb
->sk
);
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.
94 static inline struct net
*seq_file_single_net(struct seq_file
*seq
)
97 return (struct net
*)seq
->private;
103 /* Connections' size value needed by ip_vs_ctl.c */
104 extern int ip_vs_conn_tab_size
;
107 __u32 off
; /* Where IP or IPv4 header starts */
108 __u32 len
; /* IPv4 simply where L4 starts
109 * IPv6 where L4 Transport Header starts */
110 __u16 fragoffs
; /* IPv6 fragment offset, 0 if first frag (or not frag)*/
113 union nf_inet_addr saddr
;
114 union nf_inet_addr daddr
;
117 static inline void *frag_safe_skb_hp(const struct sk_buff
*skb
, int offset
,
118 int len
, void *buffer
,
119 const struct ip_vs_iphdr
*ipvsh
)
121 return skb_header_pointer(skb
, offset
, len
, buffer
);
124 /* This function handles filling *ip_vs_iphdr, both for IPv4 and IPv6.
125 * IPv6 requires some extra work, as finding proper header position,
126 * depend on the IPv6 extension headers.
129 ip_vs_fill_iph_skb_off(int af
, const struct sk_buff
*skb
, int offset
,
130 struct ip_vs_iphdr
*iphdr
)
133 #ifdef CONFIG_IP_VS_IPV6
134 if (af
== AF_INET6
) {
136 const struct ipv6hdr
*iph
= skb_header_pointer(
137 skb
, offset
, sizeof(_iph
), &_iph
);
141 iphdr
->saddr
.in6
= iph
->saddr
;
142 iphdr
->daddr
.in6
= iph
->daddr
;
143 /* ipv6_find_hdr() updates len, flags */
146 iphdr
->protocol
= ipv6_find_hdr(skb
, &iphdr
->len
, -1,
149 if (iphdr
->protocol
< 0)
155 const struct iphdr
*iph
= skb_header_pointer(
156 skb
, offset
, sizeof(_iph
), &_iph
);
160 iphdr
->len
= offset
+ iph
->ihl
* 4;
162 iphdr
->protocol
= iph
->protocol
;
163 iphdr
->saddr
.ip
= iph
->saddr
;
164 iphdr
->daddr
.ip
= iph
->daddr
;
171 ip_vs_fill_iph_skb(int af
, const struct sk_buff
*skb
, struct ip_vs_iphdr
*iphdr
)
173 return ip_vs_fill_iph_skb_off(af
, skb
, skb_network_offset(skb
), iphdr
);
176 static inline void ip_vs_addr_copy(int af
, union nf_inet_addr
*dst
,
177 const union nf_inet_addr
*src
)
179 #ifdef CONFIG_IP_VS_IPV6
187 static inline void ip_vs_addr_set(int af
, union nf_inet_addr
*dst
,
188 const union nf_inet_addr
*src
)
190 #ifdef CONFIG_IP_VS_IPV6
191 if (af
== AF_INET6
) {
202 static inline int ip_vs_addr_equal(int af
, const union nf_inet_addr
*a
,
203 const union nf_inet_addr
*b
)
205 #ifdef CONFIG_IP_VS_IPV6
207 return ipv6_addr_equal(&a
->in6
, &b
->in6
);
209 return a
->ip
== b
->ip
;
212 #ifdef CONFIG_IP_VS_DEBUG
213 #include <linux/net.h>
215 int ip_vs_get_debug_level(void);
217 static inline const char *ip_vs_dbg_addr(int af
, char *buf
, size_t buf_len
,
218 const union nf_inet_addr
*addr
,
222 #ifdef CONFIG_IP_VS_IPV6
224 len
= snprintf(&buf
[*idx
], buf_len
- *idx
, "[%pI6c]",
228 len
= snprintf(&buf
[*idx
], buf_len
- *idx
, "%pI4",
232 BUG_ON(*idx
> buf_len
+ 1);
233 return &buf
[*idx
- len
];
236 #define IP_VS_DBG_BUF(level, msg, ...) \
238 char ip_vs_dbg_buf[160]; \
239 int ip_vs_dbg_idx = 0; \
240 if (level <= ip_vs_get_debug_level()) \
241 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
243 #define IP_VS_ERR_BUF(msg...) \
245 char ip_vs_dbg_buf[160]; \
246 int ip_vs_dbg_idx = 0; \
250 /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */
251 #define IP_VS_DBG_ADDR(af, addr) \
252 ip_vs_dbg_addr(af, ip_vs_dbg_buf, \
253 sizeof(ip_vs_dbg_buf), addr, \
256 #define IP_VS_DBG(level, msg, ...) \
258 if (level <= ip_vs_get_debug_level()) \
259 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
261 #define IP_VS_DBG_RL(msg, ...) \
263 if (net_ratelimit()) \
264 printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
266 #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) \
268 if (level <= ip_vs_get_debug_level()) \
269 pp->debug_packet(af, pp, skb, ofs, msg); \
271 #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) \
273 if (level <= ip_vs_get_debug_level() && \
275 pp->debug_packet(af, pp, skb, ofs, msg); \
277 #else /* NO DEBUGGING at ALL */
278 #define IP_VS_DBG_BUF(level, msg...) do {} while (0)
279 #define IP_VS_ERR_BUF(msg...) do {} while (0)
280 #define IP_VS_DBG(level, msg...) do {} while (0)
281 #define IP_VS_DBG_RL(msg...) do {} while (0)
282 #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
283 #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
286 #define IP_VS_BUG() BUG()
287 #define IP_VS_ERR_RL(msg, ...) \
289 if (net_ratelimit()) \
290 pr_err(msg, ##__VA_ARGS__); \
293 #ifdef CONFIG_IP_VS_DEBUG
294 #define EnterFunction(level) \
296 if (level <= ip_vs_get_debug_level()) \
298 pr_fmt("Enter: %s, %s line %i\n"), \
299 __func__, __FILE__, __LINE__); \
301 #define LeaveFunction(level) \
303 if (level <= ip_vs_get_debug_level()) \
305 pr_fmt("Leave: %s, %s line %i\n"), \
306 __func__, __FILE__, __LINE__); \
309 #define EnterFunction(level) do {} while (0)
310 #define LeaveFunction(level) do {} while (0)
313 /* The port number of FTP service (in network order). */
314 #define FTPPORT cpu_to_be16(21)
315 #define FTPDATA cpu_to_be16(20)
317 /* TCP State Values */
319 IP_VS_TCP_S_NONE
= 0,
320 IP_VS_TCP_S_ESTABLISHED
,
321 IP_VS_TCP_S_SYN_SENT
,
322 IP_VS_TCP_S_SYN_RECV
,
323 IP_VS_TCP_S_FIN_WAIT
,
324 IP_VS_TCP_S_TIME_WAIT
,
326 IP_VS_TCP_S_CLOSE_WAIT
,
327 IP_VS_TCP_S_LAST_ACK
,
333 /* UDP State Values */
339 /* ICMP State Values */
345 /* SCTP State Values */
346 enum ip_vs_sctp_states
{
350 IP_VS_SCTP_S_COOKIE_SENT
,
351 IP_VS_SCTP_S_COOKIE_REPLIED
,
352 IP_VS_SCTP_S_COOKIE_WAIT
,
354 IP_VS_SCTP_S_COOKIE_ECHOED
,
355 IP_VS_SCTP_S_ESTABLISHED
,
356 IP_VS_SCTP_S_SHUTDOWN_SENT
,
357 IP_VS_SCTP_S_SHUTDOWN_RECEIVED
,
358 IP_VS_SCTP_S_SHUTDOWN_ACK_SENT
,
359 IP_VS_SCTP_S_REJECTED
,
364 /* Delta sequence info structure
365 * Each ip_vs_conn has 2 (output AND input seq. changes).
366 * Only used in the VS/NAT.
369 __u32 init_seq
; /* Add delta from this seq */
370 __u32 delta
; /* Delta in sequence numbers */
371 __u32 previous_delta
; /* Delta in sequence numbers
372 * before last resized pkt */
375 /* counters per cpu */
376 struct ip_vs_counters
{
377 __u64 conns
; /* connections scheduled */
378 __u64 inpkts
; /* incoming packets */
379 __u64 outpkts
; /* outgoing packets */
380 __u64 inbytes
; /* incoming bytes */
381 __u64 outbytes
; /* outgoing bytes */
384 struct ip_vs_cpu_stats
{
385 struct ip_vs_counters cnt
;
386 struct u64_stats_sync syncp
;
389 /* IPVS statistics objects */
390 struct ip_vs_estimator
{
391 struct list_head list
;
407 * IPVS statistics object, 64-bit kernel version of struct ip_vs_stats_user
409 struct ip_vs_kstats
{
410 u64 conns
; /* connections scheduled */
411 u64 inpkts
; /* incoming packets */
412 u64 outpkts
; /* outgoing packets */
413 u64 inbytes
; /* incoming bytes */
414 u64 outbytes
; /* outgoing bytes */
416 u64 cps
; /* current connection rate */
417 u64 inpps
; /* current in packet rate */
418 u64 outpps
; /* current out packet rate */
419 u64 inbps
; /* current in byte rate */
420 u64 outbps
; /* current out byte rate */
424 struct ip_vs_kstats kstats
; /* kernel statistics */
425 struct ip_vs_estimator est
; /* estimator */
426 struct ip_vs_cpu_stats __percpu
*cpustats
; /* per cpu counters */
427 spinlock_t lock
; /* spin lock */
428 struct ip_vs_kstats kstats0
; /* reset values */
436 struct ip_vs_proto_data
;
438 struct ip_vs_protocol
{
439 struct ip_vs_protocol
*next
;
445 void (*init
)(struct ip_vs_protocol
*pp
);
447 void (*exit
)(struct ip_vs_protocol
*pp
);
449 int (*init_netns
)(struct net
*net
, struct ip_vs_proto_data
*pd
);
451 void (*exit_netns
)(struct net
*net
, struct ip_vs_proto_data
*pd
);
453 int (*conn_schedule
)(int af
, struct sk_buff
*skb
,
454 struct ip_vs_proto_data
*pd
,
455 int *verdict
, struct ip_vs_conn
**cpp
,
456 struct ip_vs_iphdr
*iph
);
459 (*conn_in_get
)(int af
,
460 const struct sk_buff
*skb
,
461 const struct ip_vs_iphdr
*iph
,
465 (*conn_out_get
)(int af
,
466 const struct sk_buff
*skb
,
467 const struct ip_vs_iphdr
*iph
,
470 int (*snat_handler
)(struct sk_buff
*skb
, struct ip_vs_protocol
*pp
,
471 struct ip_vs_conn
*cp
, struct ip_vs_iphdr
*iph
);
473 int (*dnat_handler
)(struct sk_buff
*skb
, struct ip_vs_protocol
*pp
,
474 struct ip_vs_conn
*cp
, struct ip_vs_iphdr
*iph
);
476 int (*csum_check
)(int af
, struct sk_buff
*skb
,
477 struct ip_vs_protocol
*pp
);
479 const char *(*state_name
)(int state
);
481 void (*state_transition
)(struct ip_vs_conn
*cp
, int direction
,
482 const struct sk_buff
*skb
,
483 struct ip_vs_proto_data
*pd
);
485 int (*register_app
)(struct net
*net
, struct ip_vs_app
*inc
);
487 void (*unregister_app
)(struct net
*net
, struct ip_vs_app
*inc
);
489 int (*app_conn_bind
)(struct ip_vs_conn
*cp
);
491 void (*debug_packet
)(int af
, struct ip_vs_protocol
*pp
,
492 const struct sk_buff
*skb
,
496 void (*timeout_change
)(struct ip_vs_proto_data
*pd
, int flags
);
499 /* protocol data per netns */
500 struct ip_vs_proto_data
{
501 struct ip_vs_proto_data
*next
;
502 struct ip_vs_protocol
*pp
;
503 int *timeout_table
; /* protocol timeout table */
504 atomic_t appcnt
; /* counter of proto app incs. */
505 struct tcp_states_t
*tcp_state_table
;
508 struct ip_vs_protocol
*ip_vs_proto_get(unsigned short proto
);
509 struct ip_vs_proto_data
*ip_vs_proto_data_get(struct net
*net
,
510 unsigned short proto
);
512 struct ip_vs_conn_param
{
514 const union nf_inet_addr
*caddr
;
515 const union nf_inet_addr
*vaddr
;
521 const struct ip_vs_pe
*pe
;
526 /* IP_VS structure allocated for each dynamically scheduled connection */
528 struct hlist_node c_list
; /* hashed list heads */
529 /* Protocol, addresses and port numbers */
533 u16 af
; /* address family */
534 union nf_inet_addr caddr
; /* client address */
535 union nf_inet_addr vaddr
; /* virtual address */
536 union nf_inet_addr daddr
; /* destination address */
537 volatile __u32 flags
; /* status flags */
538 __u16 protocol
; /* Which protocol (TCP/UDP) */
539 __u16 daf
; /* Address family of the dest */
541 struct net
*net
; /* Name space */
544 /* counter and timer */
545 atomic_t refcnt
; /* reference count */
546 struct timer_list timer
; /* Expiration timer */
547 volatile unsigned long timeout
; /* timeout */
549 /* Flags and state transition */
550 spinlock_t lock
; /* lock for state transition */
551 volatile __u16 state
; /* state info */
552 volatile __u16 old_state
; /* old state, to be used for
553 * state transition triggerd
556 __u32 fwmark
; /* Fire wall mark from skb */
557 unsigned long sync_endtime
; /* jiffies + sent_retries */
559 /* Control members */
560 struct ip_vs_conn
*control
; /* Master control connection */
561 atomic_t n_control
; /* Number of controlled ones */
562 struct ip_vs_dest
*dest
; /* real server */
563 atomic_t in_pkts
; /* incoming packet counter */
565 /* Packet transmitter for different forwarding methods. If it
566 * mangles the packet, it must return NF_DROP or better NF_STOLEN,
567 * otherwise this must be changed to a sk_buff **.
568 * NF_ACCEPT can be returned when destination is local.
570 int (*packet_xmit
)(struct sk_buff
*skb
, struct ip_vs_conn
*cp
,
571 struct ip_vs_protocol
*pp
, struct ip_vs_iphdr
*iph
);
573 /* Note: we can group the following members into a structure,
574 * in order to save more space, and the following members are
575 * only used in VS/NAT anyway
577 struct ip_vs_app
*app
; /* bound ip_vs_app object */
578 void *app_data
; /* Application private data */
579 struct ip_vs_seq in_seq
; /* incoming seq. struct */
580 struct ip_vs_seq out_seq
; /* outgoing seq. struct */
582 const struct ip_vs_pe
*pe
;
586 struct rcu_head rcu_head
;
589 /* 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
)
599 static inline void ip_vs_conn_net_set(struct ip_vs_conn
*cp
, struct net
*net
)
606 static inline int ip_vs_conn_net_eq(const struct ip_vs_conn
*cp
,
610 return cp
->net
== net
;
616 /* Extended internal versions of struct ip_vs_service_user and ip_vs_dest_user
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 and the
660 * 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
;
700 /* The real server destination forwarding entry with ip address, port number,
704 struct list_head n_list
; /* for the dests in the service */
705 struct hlist_node d_list
; /* for table with all the dests */
707 u16 af
; /* address family */
708 __be16 port
; /* port number of the server */
709 union nf_inet_addr addr
; /* IP address of the server */
710 volatile unsigned int flags
; /* dest status flags */
711 atomic_t conn_flags
; /* flags to copy to conn */
712 atomic_t weight
; /* server weight */
714 atomic_t refcnt
; /* reference counter */
715 struct ip_vs_stats stats
; /* statistics */
716 unsigned long idle_start
; /* start time, jiffies */
718 /* connection counters and thresholds */
719 atomic_t activeconns
; /* active connections */
720 atomic_t inactconns
; /* inactive connections */
721 atomic_t persistconns
; /* persistent connections */
722 __u32 u_threshold
; /* upper threshold */
723 __u32 l_threshold
; /* lower threshold */
725 /* for destination cache */
726 spinlock_t dst_lock
; /* lock of dst_cache */
727 struct ip_vs_dest_dst __rcu
*dest_dst
; /* cached dst info */
729 /* for virtual service */
730 struct ip_vs_service __rcu
*svc
; /* service it belongs to */
731 __u16 protocol
; /* which protocol (TCP/UDP) */
732 __be16 vport
; /* virtual port number */
733 union nf_inet_addr vaddr
; /* virtual IP address */
734 __u32 vfwmark
; /* firewall mark of service */
736 struct list_head t_list
; /* in dest_trash */
737 unsigned int in_rs_table
:1; /* we are in rs_table */
740 /* The scheduler object */
741 struct ip_vs_scheduler
{
742 struct list_head n_list
; /* d-linked list head */
743 char *name
; /* scheduler name */
744 atomic_t refcnt
; /* reference counter */
745 struct module
*module
; /* THIS_MODULE/NULL */
747 /* scheduler initializing service */
748 int (*init_service
)(struct ip_vs_service
*svc
);
749 /* scheduling service finish */
750 void (*done_service
)(struct ip_vs_service
*svc
);
752 int (*add_dest
)(struct ip_vs_service
*svc
, struct ip_vs_dest
*dest
);
753 /* dest is unlinked */
754 int (*del_dest
)(struct ip_vs_service
*svc
, struct ip_vs_dest
*dest
);
755 /* dest is updated */
756 int (*upd_dest
)(struct ip_vs_service
*svc
, struct ip_vs_dest
*dest
);
758 /* selecting a server from the given service */
759 struct ip_vs_dest
* (*schedule
)(struct ip_vs_service
*svc
,
760 const struct sk_buff
*skb
,
761 struct ip_vs_iphdr
*iph
);
764 /* The persistence engine object */
766 struct list_head n_list
; /* d-linked list head */
767 char *name
; /* scheduler name */
768 atomic_t refcnt
; /* reference counter */
769 struct module
*module
; /* THIS_MODULE/NULL */
771 /* get the connection template, if any */
772 int (*fill_param
)(struct ip_vs_conn_param
*p
, struct sk_buff
*skb
);
773 bool (*ct_match
)(const struct ip_vs_conn_param
*p
,
774 struct ip_vs_conn
*ct
);
775 u32 (*hashkey_raw
)(const struct ip_vs_conn_param
*p
, u32 initval
,
777 int (*show_pe_data
)(const struct ip_vs_conn
*cp
, char *buf
);
780 /* The application module object (a.k.a. app incarnation) */
782 struct list_head a_list
; /* member in app list */
783 int type
; /* IP_VS_APP_TYPE_xxx */
784 char *name
; /* application module name */
786 struct module
*module
; /* THIS_MODULE/NULL */
787 struct list_head incs_list
; /* list of incarnations */
789 /* members for application incarnations */
790 struct list_head p_list
; /* member in proto app list */
791 struct ip_vs_app
*app
; /* its real application */
792 __be16 port
; /* port number in net order */
793 atomic_t usecnt
; /* usage counter */
794 struct rcu_head rcu_head
;
796 /* output hook: Process packet in inout direction, diff set for TCP.
797 * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
798 * 2=Mangled but checksum was not updated
800 int (*pkt_out
)(struct ip_vs_app
*, struct ip_vs_conn
*,
801 struct sk_buff
*, int *diff
);
803 /* input hook: Process packet in outin 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_in
)(struct ip_vs_app
*, struct ip_vs_conn
*,
808 struct sk_buff
*, int *diff
);
810 /* ip_vs_app initializer */
811 int (*init_conn
)(struct ip_vs_app
*, struct ip_vs_conn
*);
813 /* ip_vs_app finish */
814 int (*done_conn
)(struct ip_vs_app
*, struct ip_vs_conn
*);
818 int (*bind_conn
)(struct ip_vs_app
*, struct ip_vs_conn
*,
819 struct ip_vs_protocol
*);
821 void (*unbind_conn
)(struct ip_vs_app
*, struct ip_vs_conn
*);
827 int (*conn_schedule
)(struct sk_buff
*skb
, struct ip_vs_app
*app
,
828 int *verdict
, struct ip_vs_conn
**cpp
);
831 (*conn_in_get
)(const struct sk_buff
*skb
, struct ip_vs_app
*app
,
832 const struct iphdr
*iph
, int inverse
);
835 (*conn_out_get
)(const struct sk_buff
*skb
, struct ip_vs_app
*app
,
836 const struct iphdr
*iph
, int inverse
);
838 int (*state_transition
)(struct ip_vs_conn
*cp
, int direction
,
839 const struct sk_buff
*skb
,
840 struct ip_vs_app
*app
);
842 void (*timeout_change
)(struct ip_vs_app
*app
, int flags
);
845 struct ipvs_master_sync_state
{
846 struct list_head sync_queue
;
847 struct ip_vs_sync_buff
*sync_buff
;
848 unsigned long sync_queue_len
;
849 unsigned int sync_queue_delay
;
850 struct task_struct
*master_thread
;
851 struct delayed_work master_wakeup_work
;
852 struct netns_ipvs
*ipvs
;
855 /* How much time to keep dests in trash */
856 #define IP_VS_DEST_TRASH_PERIOD (120 * HZ)
858 struct ipvs_sync_daemon_cfg
{
859 union nf_inet_addr mcast_group
;
865 /* multicast interface name */
866 char mcast_ifn
[IP_VS_IFNAME_MAXLEN
];
869 /* IPVS in network namespace */
871 int gen
; /* Generation */
872 int enable
; /* enable like nf_hooks do */
873 /* Hash table: for real service lookups */
874 #define IP_VS_RTAB_BITS 4
875 #define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS)
876 #define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1)
878 struct hlist_head rs_table
[IP_VS_RTAB_SIZE
];
880 struct list_head app_list
;
882 #define IP_VS_PROTO_TAB_SIZE 32 /* must be power of 2 */
883 struct ip_vs_proto_data
*proto_data_table
[IP_VS_PROTO_TAB_SIZE
];
884 /* ip_vs_proto_tcp */
885 #ifdef CONFIG_IP_VS_PROTO_TCP
886 #define TCP_APP_TAB_BITS 4
887 #define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS)
888 #define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1)
889 struct list_head tcp_apps
[TCP_APP_TAB_SIZE
];
891 /* ip_vs_proto_udp */
892 #ifdef CONFIG_IP_VS_PROTO_UDP
893 #define UDP_APP_TAB_BITS 4
894 #define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS)
895 #define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1)
896 struct list_head udp_apps
[UDP_APP_TAB_SIZE
];
898 /* ip_vs_proto_sctp */
899 #ifdef CONFIG_IP_VS_PROTO_SCTP
900 #define SCTP_APP_TAB_BITS 4
901 #define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS)
902 #define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1)
903 /* Hash table for SCTP application incarnations */
904 struct list_head sctp_apps
[SCTP_APP_TAB_SIZE
];
907 atomic_t conn_count
; /* connection counter */
910 struct ip_vs_stats tot_stats
; /* Statistics & est. */
912 int num_services
; /* no of virtual services */
914 /* Trash for destinations */
915 struct list_head dest_trash
;
916 spinlock_t dest_trash_lock
;
917 struct timer_list dest_trash_timer
; /* expiration timer */
918 /* Service counters */
919 atomic_t ftpsvc_counter
;
920 atomic_t nullsvc_counter
;
923 /* 1/rate drop and drop-entry variables */
924 struct delayed_work defense_work
; /* Work handler */
929 spinlock_t dropentry_lock
; /* drop entry handling */
930 spinlock_t droppacket_lock
; /* drop packet handling */
931 spinlock_t securetcp_lock
; /* state and timeout tables */
934 struct ctl_table_header
*sysctl_hdr
;
935 struct ctl_table
*sysctl_tbl
;
938 /* sysctl variables */
939 int sysctl_amemthresh
;
940 int sysctl_am_droprate
;
941 int sysctl_drop_entry
;
942 int sysctl_drop_packet
;
943 int sysctl_secure_tcp
;
944 #ifdef CONFIG_IP_VS_NFCT
945 int sysctl_conntrack
;
947 int sysctl_snat_reroute
;
949 int sysctl_sync_ports
;
950 int sysctl_sync_persist_mode
;
951 unsigned long sysctl_sync_qlen_max
;
952 int sysctl_sync_sock_size
;
953 int sysctl_cache_bypass
;
954 int sysctl_expire_nodest_conn
;
955 int sysctl_sloppy_tcp
;
956 int sysctl_sloppy_sctp
;
957 int sysctl_expire_quiescent_template
;
958 int sysctl_sync_threshold
[2];
959 unsigned int sysctl_sync_refresh_period
;
960 int sysctl_sync_retries
;
961 int sysctl_nat_icmp_send
;
962 int sysctl_pmtu_disc
;
963 int sysctl_backup_only
;
964 int sysctl_conn_reuse_mode
;
967 int sysctl_lblc_expiration
;
968 struct ctl_table_header
*lblc_ctl_header
;
969 struct ctl_table
*lblc_ctl_table
;
971 int sysctl_lblcr_expiration
;
972 struct ctl_table_header
*lblcr_ctl_header
;
973 struct ctl_table
*lblcr_ctl_table
;
975 struct list_head est_list
; /* estimator list */
977 struct timer_list est_timer
; /* Estimation timer */
979 spinlock_t sync_lock
;
980 struct ipvs_master_sync_state
*ms
;
981 spinlock_t sync_buff_lock
;
982 struct task_struct
**backup_threads
;
984 volatile int sync_state
;
985 struct mutex sync_mutex
;
986 struct ipvs_sync_daemon_cfg mcfg
; /* Master Configuration */
987 struct ipvs_sync_daemon_cfg bcfg
; /* Backup Configuration */
988 /* net name space ptr */
989 struct net
*net
; /* Needed by timer routines */
990 /* Number of heterogeneous destinations, needed becaus heterogeneous
991 * are not supported when synchronization is enabled.
993 unsigned int mixed_address_family_dests
;
996 #define DEFAULT_SYNC_THRESHOLD 3
997 #define DEFAULT_SYNC_PERIOD 50
998 #define DEFAULT_SYNC_VER 1
999 #define DEFAULT_SLOPPY_TCP 0
1000 #define DEFAULT_SLOPPY_SCTP 0
1001 #define DEFAULT_SYNC_REFRESH_PERIOD (0U * HZ)
1002 #define DEFAULT_SYNC_RETRIES 0
1003 #define IPVS_SYNC_WAKEUP_RATE 8
1004 #define IPVS_SYNC_QLEN_MAX (IPVS_SYNC_WAKEUP_RATE * 4)
1005 #define IPVS_SYNC_SEND_DELAY (HZ / 50)
1006 #define IPVS_SYNC_CHECK_PERIOD HZ
1007 #define IPVS_SYNC_FLUSH_TIME (HZ * 2)
1008 #define IPVS_SYNC_PORTS_MAX (1 << 6)
1010 #ifdef CONFIG_SYSCTL
1012 static inline int sysctl_sync_threshold(struct netns_ipvs
*ipvs
)
1014 return ipvs
->sysctl_sync_threshold
[0];
1017 static inline int sysctl_sync_period(struct netns_ipvs
*ipvs
)
1019 return ACCESS_ONCE(ipvs
->sysctl_sync_threshold
[1]);
1022 static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs
*ipvs
)
1024 return ACCESS_ONCE(ipvs
->sysctl_sync_refresh_period
);
1027 static inline int sysctl_sync_retries(struct netns_ipvs
*ipvs
)
1029 return ipvs
->sysctl_sync_retries
;
1032 static inline int sysctl_sync_ver(struct netns_ipvs
*ipvs
)
1034 return ipvs
->sysctl_sync_ver
;
1037 static inline int sysctl_sloppy_tcp(struct netns_ipvs
*ipvs
)
1039 return ipvs
->sysctl_sloppy_tcp
;
1042 static inline int sysctl_sloppy_sctp(struct netns_ipvs
*ipvs
)
1044 return ipvs
->sysctl_sloppy_sctp
;
1047 static inline int sysctl_sync_ports(struct netns_ipvs
*ipvs
)
1049 return ACCESS_ONCE(ipvs
->sysctl_sync_ports
);
1052 static inline int sysctl_sync_persist_mode(struct netns_ipvs
*ipvs
)
1054 return ipvs
->sysctl_sync_persist_mode
;
1057 static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs
*ipvs
)
1059 return ipvs
->sysctl_sync_qlen_max
;
1062 static inline int sysctl_sync_sock_size(struct netns_ipvs
*ipvs
)
1064 return ipvs
->sysctl_sync_sock_size
;
1067 static inline int sysctl_pmtu_disc(struct netns_ipvs
*ipvs
)
1069 return ipvs
->sysctl_pmtu_disc
;
1072 static inline int sysctl_backup_only(struct netns_ipvs
*ipvs
)
1074 return ipvs
->sync_state
& IP_VS_STATE_BACKUP
&&
1075 ipvs
->sysctl_backup_only
;
1078 static inline int sysctl_conn_reuse_mode(struct netns_ipvs
*ipvs
)
1080 return ipvs
->sysctl_conn_reuse_mode
;
1085 static inline int sysctl_sync_threshold(struct netns_ipvs
*ipvs
)
1087 return DEFAULT_SYNC_THRESHOLD
;
1090 static inline int sysctl_sync_period(struct netns_ipvs
*ipvs
)
1092 return DEFAULT_SYNC_PERIOD
;
1095 static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs
*ipvs
)
1097 return DEFAULT_SYNC_REFRESH_PERIOD
;
1100 static inline int sysctl_sync_retries(struct netns_ipvs
*ipvs
)
1102 return DEFAULT_SYNC_RETRIES
& 3;
1105 static inline int sysctl_sync_ver(struct netns_ipvs
*ipvs
)
1107 return DEFAULT_SYNC_VER
;
1110 static inline int sysctl_sloppy_tcp(struct netns_ipvs
*ipvs
)
1112 return DEFAULT_SLOPPY_TCP
;
1115 static inline int sysctl_sloppy_sctp(struct netns_ipvs
*ipvs
)
1117 return DEFAULT_SLOPPY_SCTP
;
1120 static inline int sysctl_sync_ports(struct netns_ipvs
*ipvs
)
1125 static inline int sysctl_sync_persist_mode(struct netns_ipvs
*ipvs
)
1130 static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs
*ipvs
)
1132 return IPVS_SYNC_QLEN_MAX
;
1135 static inline int sysctl_sync_sock_size(struct netns_ipvs
*ipvs
)
1140 static inline int sysctl_pmtu_disc(struct netns_ipvs
*ipvs
)
1145 static inline int sysctl_backup_only(struct netns_ipvs
*ipvs
)
1150 static inline int sysctl_conn_reuse_mode(struct netns_ipvs
*ipvs
)
1157 /* IPVS core functions
1158 * (from ip_vs_core.c)
1160 const char *ip_vs_proto_name(unsigned int proto
);
1161 void ip_vs_init_hash_table(struct list_head
*table
, int rows
);
1162 #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
1164 #define IP_VS_APP_TYPE_FTP 1
1166 /* ip_vs_conn handling functions
1167 * (from ip_vs_conn.c)
1170 IP_VS_DIR_INPUT
= 0,
1172 IP_VS_DIR_INPUT_ONLY
,
1176 static inline void ip_vs_conn_fill_param(struct net
*net
, int af
, int protocol
,
1177 const union nf_inet_addr
*caddr
,
1179 const union nf_inet_addr
*vaddr
,
1181 struct ip_vs_conn_param
*p
)
1185 p
->protocol
= protocol
;
1194 struct ip_vs_conn
*ip_vs_conn_in_get(const struct ip_vs_conn_param
*p
);
1195 struct ip_vs_conn
*ip_vs_ct_in_get(const struct ip_vs_conn_param
*p
);
1197 struct ip_vs_conn
* ip_vs_conn_in_get_proto(int af
, const struct sk_buff
*skb
,
1198 const struct ip_vs_iphdr
*iph
,
1201 struct ip_vs_conn
*ip_vs_conn_out_get(const struct ip_vs_conn_param
*p
);
1203 struct ip_vs_conn
* ip_vs_conn_out_get_proto(int af
, const struct sk_buff
*skb
,
1204 const struct ip_vs_iphdr
*iph
,
1207 /* Get reference to gain full access to conn.
1208 * By default, RCU read-side critical sections have access only to
1209 * conn fields and its PE data, see ip_vs_conn_rcu_free() for reference.
1211 static inline bool __ip_vs_conn_get(struct ip_vs_conn
*cp
)
1213 return atomic_inc_not_zero(&cp
->refcnt
);
1216 /* put back the conn without restarting its timer */
1217 static inline void __ip_vs_conn_put(struct ip_vs_conn
*cp
)
1219 smp_mb__before_atomic();
1220 atomic_dec(&cp
->refcnt
);
1222 void ip_vs_conn_put(struct ip_vs_conn
*cp
);
1223 void ip_vs_conn_fill_cport(struct ip_vs_conn
*cp
, __be16 cport
);
1225 struct ip_vs_conn
*ip_vs_conn_new(const struct ip_vs_conn_param
*p
, int dest_af
,
1226 const union nf_inet_addr
*daddr
,
1227 __be16 dport
, unsigned int flags
,
1228 struct ip_vs_dest
*dest
, __u32 fwmark
);
1229 void ip_vs_conn_expire_now(struct ip_vs_conn
*cp
);
1231 const char *ip_vs_state_name(__u16 proto
, int state
);
1233 void ip_vs_tcp_conn_listen(struct net
*net
, struct ip_vs_conn
*cp
);
1234 int ip_vs_check_template(struct ip_vs_conn
*ct
);
1235 void ip_vs_random_dropentry(struct net
*net
);
1236 int ip_vs_conn_init(void);
1237 void ip_vs_conn_cleanup(void);
1239 static inline void ip_vs_control_del(struct ip_vs_conn
*cp
)
1241 struct ip_vs_conn
*ctl_cp
= cp
->control
;
1243 IP_VS_ERR_BUF("request control DEL for uncontrolled: "
1245 IP_VS_DBG_ADDR(cp
->af
, &cp
->caddr
),
1247 IP_VS_DBG_ADDR(cp
->af
, &cp
->vaddr
),
1253 IP_VS_DBG_BUF(7, "DELeting control for: "
1254 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
1255 IP_VS_DBG_ADDR(cp
->af
, &cp
->caddr
),
1257 IP_VS_DBG_ADDR(cp
->af
, &ctl_cp
->caddr
),
1258 ntohs(ctl_cp
->cport
));
1261 if (atomic_read(&ctl_cp
->n_control
) == 0) {
1262 IP_VS_ERR_BUF("BUG control DEL with n=0 : "
1264 IP_VS_DBG_ADDR(cp
->af
, &cp
->caddr
),
1266 IP_VS_DBG_ADDR(cp
->af
, &cp
->vaddr
),
1271 atomic_dec(&ctl_cp
->n_control
);
1275 ip_vs_control_add(struct ip_vs_conn
*cp
, struct ip_vs_conn
*ctl_cp
)
1278 IP_VS_ERR_BUF("request control ADD for already controlled: "
1280 IP_VS_DBG_ADDR(cp
->af
, &cp
->caddr
),
1282 IP_VS_DBG_ADDR(cp
->af
, &cp
->vaddr
),
1285 ip_vs_control_del(cp
);
1288 IP_VS_DBG_BUF(7, "ADDing control for: "
1289 "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
1290 IP_VS_DBG_ADDR(cp
->af
, &cp
->caddr
),
1292 IP_VS_DBG_ADDR(cp
->af
, &ctl_cp
->caddr
),
1293 ntohs(ctl_cp
->cport
));
1295 cp
->control
= ctl_cp
;
1296 atomic_inc(&ctl_cp
->n_control
);
1299 /* IPVS netns init & cleanup functions */
1300 int ip_vs_estimator_net_init(struct net
*net
);
1301 int ip_vs_control_net_init(struct net
*net
);
1302 int ip_vs_protocol_net_init(struct net
*net
);
1303 int ip_vs_app_net_init(struct net
*net
);
1304 int ip_vs_conn_net_init(struct net
*net
);
1305 int ip_vs_sync_net_init(struct net
*net
);
1306 void ip_vs_conn_net_cleanup(struct net
*net
);
1307 void ip_vs_app_net_cleanup(struct net
*net
);
1308 void ip_vs_protocol_net_cleanup(struct net
*net
);
1309 void ip_vs_control_net_cleanup(struct net
*net
);
1310 void ip_vs_estimator_net_cleanup(struct net
*net
);
1311 void ip_vs_sync_net_cleanup(struct net
*net
);
1312 void ip_vs_service_net_cleanup(struct net
*net
);
1314 /* IPVS application functions
1315 * (from ip_vs_app.c)
1317 #define IP_VS_APP_MAX_PORTS 8
1318 struct ip_vs_app
*register_ip_vs_app(struct net
*net
, struct ip_vs_app
*app
);
1319 void unregister_ip_vs_app(struct net
*net
, struct ip_vs_app
*app
);
1320 int ip_vs_bind_app(struct ip_vs_conn
*cp
, struct ip_vs_protocol
*pp
);
1321 void ip_vs_unbind_app(struct ip_vs_conn
*cp
);
1322 int register_ip_vs_app_inc(struct net
*net
, struct ip_vs_app
*app
, __u16 proto
,
1324 int ip_vs_app_inc_get(struct ip_vs_app
*inc
);
1325 void ip_vs_app_inc_put(struct ip_vs_app
*inc
);
1327 int ip_vs_app_pkt_out(struct ip_vs_conn
*, struct sk_buff
*skb
);
1328 int ip_vs_app_pkt_in(struct ip_vs_conn
*, struct sk_buff
*skb
);
1330 int register_ip_vs_pe(struct ip_vs_pe
*pe
);
1331 int unregister_ip_vs_pe(struct ip_vs_pe
*pe
);
1332 struct ip_vs_pe
*ip_vs_pe_getbyname(const char *name
);
1333 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 */
1336 #define ip_vs_pe_get(pe) \
1337 if (pe && pe->module) \
1338 __module_get(pe->module);
1340 #define ip_vs_pe_put(pe) \
1341 if (pe && pe->module) \
1342 module_put(pe->module);
1344 /* IPVS protocol functions (from ip_vs_proto.c) */
1345 int ip_vs_protocol_init(void);
1346 void ip_vs_protocol_cleanup(void);
1347 void ip_vs_protocol_timeout_change(struct netns_ipvs
*ipvs
, int flags
);
1348 int *ip_vs_create_timeout_table(int *table
, int size
);
1349 int ip_vs_set_state_timeout(int *table
, int num
, const char *const *names
,
1350 const char *name
, int to
);
1351 void ip_vs_tcpudp_debug_packet(int af
, struct ip_vs_protocol
*pp
,
1352 const struct sk_buff
*skb
, int offset
,
1355 extern struct ip_vs_protocol ip_vs_protocol_tcp
;
1356 extern struct ip_vs_protocol ip_vs_protocol_udp
;
1357 extern struct ip_vs_protocol ip_vs_protocol_icmp
;
1358 extern struct ip_vs_protocol ip_vs_protocol_esp
;
1359 extern struct ip_vs_protocol ip_vs_protocol_ah
;
1360 extern struct ip_vs_protocol ip_vs_protocol_sctp
;
1362 /* Registering/unregistering scheduler functions
1363 * (from ip_vs_sched.c)
1365 int register_ip_vs_scheduler(struct ip_vs_scheduler
*scheduler
);
1366 int unregister_ip_vs_scheduler(struct ip_vs_scheduler
*scheduler
);
1367 int ip_vs_bind_scheduler(struct ip_vs_service
*svc
,
1368 struct ip_vs_scheduler
*scheduler
);
1369 void ip_vs_unbind_scheduler(struct ip_vs_service
*svc
,
1370 struct ip_vs_scheduler
*sched
);
1371 struct ip_vs_scheduler
*ip_vs_scheduler_get(const char *sched_name
);
1372 void ip_vs_scheduler_put(struct ip_vs_scheduler
*scheduler
);
1374 ip_vs_schedule(struct ip_vs_service
*svc
, struct sk_buff
*skb
,
1375 struct ip_vs_proto_data
*pd
, int *ignored
,
1376 struct ip_vs_iphdr
*iph
);
1377 int ip_vs_leave(struct ip_vs_service
*svc
, struct sk_buff
*skb
,
1378 struct ip_vs_proto_data
*pd
, struct ip_vs_iphdr
*iph
);
1380 void ip_vs_scheduler_err(struct ip_vs_service
*svc
, const char *msg
);
1382 /* IPVS control data and functions (from ip_vs_ctl.c) */
1383 extern struct ip_vs_stats ip_vs_stats
;
1384 extern int sysctl_ip_vs_sync_ver
;
1386 struct ip_vs_service
*
1387 ip_vs_service_find(struct net
*net
, int af
, __u32 fwmark
, __u16 protocol
,
1388 const union nf_inet_addr
*vaddr
, __be16 vport
);
1390 bool ip_vs_has_real_service(struct net
*net
, int af
, __u16 protocol
,
1391 const union nf_inet_addr
*daddr
, __be16 dport
);
1393 int ip_vs_use_count_inc(void);
1394 void ip_vs_use_count_dec(void);
1395 int ip_vs_register_nl_ioctl(void);
1396 void ip_vs_unregister_nl_ioctl(void);
1397 int ip_vs_control_init(void);
1398 void ip_vs_control_cleanup(void);
1400 ip_vs_find_dest(struct net
*net
, int svc_af
, int dest_af
,
1401 const union nf_inet_addr
*daddr
, __be16 dport
,
1402 const union nf_inet_addr
*vaddr
, __be16 vport
,
1403 __u16 protocol
, __u32 fwmark
, __u32 flags
);
1404 void ip_vs_try_bind_dest(struct ip_vs_conn
*cp
);
1406 static inline void ip_vs_dest_hold(struct ip_vs_dest
*dest
)
1408 atomic_inc(&dest
->refcnt
);
1411 static inline void ip_vs_dest_put(struct ip_vs_dest
*dest
)
1413 smp_mb__before_atomic();
1414 atomic_dec(&dest
->refcnt
);
1417 static inline void ip_vs_dest_put_and_free(struct ip_vs_dest
*dest
)
1419 if (atomic_dec_return(&dest
->refcnt
) < 0)
1423 /* IPVS sync daemon data and function prototypes
1424 * (from ip_vs_sync.c)
1426 int start_sync_thread(struct net
*net
, struct ipvs_sync_daemon_cfg
*cfg
,
1428 int stop_sync_thread(struct net
*net
, int state
);
1429 void ip_vs_sync_conn(struct net
*net
, struct ip_vs_conn
*cp
, int pkts
);
1431 /* IPVS rate estimator prototypes (from ip_vs_est.c) */
1432 void ip_vs_start_estimator(struct net
*net
, struct ip_vs_stats
*stats
);
1433 void ip_vs_stop_estimator(struct net
*net
, struct ip_vs_stats
*stats
);
1434 void ip_vs_zero_estimator(struct ip_vs_stats
*stats
);
1435 void ip_vs_read_estimator(struct ip_vs_kstats
*dst
, struct ip_vs_stats
*stats
);
1437 /* Various IPVS packet transmitters (from ip_vs_xmit.c) */
1438 int ip_vs_null_xmit(struct sk_buff
*skb
, struct ip_vs_conn
*cp
,
1439 struct ip_vs_protocol
*pp
, struct ip_vs_iphdr
*iph
);
1440 int ip_vs_bypass_xmit(struct sk_buff
*skb
, struct ip_vs_conn
*cp
,
1441 struct ip_vs_protocol
*pp
, struct ip_vs_iphdr
*iph
);
1442 int ip_vs_nat_xmit(struct sk_buff
*skb
, struct ip_vs_conn
*cp
,
1443 struct ip_vs_protocol
*pp
, struct ip_vs_iphdr
*iph
);
1444 int ip_vs_tunnel_xmit(struct sk_buff
*skb
, struct ip_vs_conn
*cp
,
1445 struct ip_vs_protocol
*pp
, struct ip_vs_iphdr
*iph
);
1446 int ip_vs_dr_xmit(struct sk_buff
*skb
, struct ip_vs_conn
*cp
,
1447 struct ip_vs_protocol
*pp
, struct ip_vs_iphdr
*iph
);
1448 int ip_vs_icmp_xmit(struct sk_buff
*skb
, struct ip_vs_conn
*cp
,
1449 struct ip_vs_protocol
*pp
, int offset
,
1450 unsigned int hooknum
, struct ip_vs_iphdr
*iph
);
1451 void ip_vs_dest_dst_rcu_free(struct rcu_head
*head
);
1453 #ifdef CONFIG_IP_VS_IPV6
1454 int ip_vs_bypass_xmit_v6(struct sk_buff
*skb
, struct ip_vs_conn
*cp
,
1455 struct ip_vs_protocol
*pp
, struct ip_vs_iphdr
*iph
);
1456 int ip_vs_nat_xmit_v6(struct sk_buff
*skb
, struct ip_vs_conn
*cp
,
1457 struct ip_vs_protocol
*pp
, struct ip_vs_iphdr
*iph
);
1458 int ip_vs_tunnel_xmit_v6(struct sk_buff
*skb
, struct ip_vs_conn
*cp
,
1459 struct ip_vs_protocol
*pp
, struct ip_vs_iphdr
*iph
);
1460 int ip_vs_dr_xmit_v6(struct sk_buff
*skb
, struct ip_vs_conn
*cp
,
1461 struct ip_vs_protocol
*pp
, struct ip_vs_iphdr
*iph
);
1462 int ip_vs_icmp_xmit_v6(struct sk_buff
*skb
, struct ip_vs_conn
*cp
,
1463 struct ip_vs_protocol
*pp
, int offset
,
1464 unsigned int hooknum
, struct ip_vs_iphdr
*iph
);
1467 #ifdef CONFIG_SYSCTL
1468 /* This is a simple mechanism to ignore packets when
1469 * we are loaded. Just set ip_vs_drop_rate to 'n' and
1470 * we start to drop 1/rate of the packets
1472 static inline int ip_vs_todrop(struct netns_ipvs
*ipvs
)
1474 if (!ipvs
->drop_rate
)
1476 if (--ipvs
->drop_counter
> 0)
1478 ipvs
->drop_counter
= ipvs
->drop_rate
;
1482 static inline int ip_vs_todrop(struct netns_ipvs
*ipvs
) { return 0; }
1485 /* ip_vs_fwd_tag returns the forwarding tag of the connection */
1486 #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
1488 static inline char ip_vs_fwd_tag(struct ip_vs_conn
*cp
)
1492 switch (IP_VS_FWD_METHOD(cp
)) {
1493 case IP_VS_CONN_F_MASQ
:
1495 case IP_VS_CONN_F_LOCALNODE
:
1497 case IP_VS_CONN_F_TUNNEL
:
1499 case IP_VS_CONN_F_DROUTE
:
1501 case IP_VS_CONN_F_BYPASS
:
1509 void ip_vs_nat_icmp(struct sk_buff
*skb
, struct ip_vs_protocol
*pp
,
1510 struct ip_vs_conn
*cp
, int dir
);
1512 #ifdef CONFIG_IP_VS_IPV6
1513 void ip_vs_nat_icmp_v6(struct sk_buff
*skb
, struct ip_vs_protocol
*pp
,
1514 struct ip_vs_conn
*cp
, int dir
);
1517 __sum16
ip_vs_checksum_complete(struct sk_buff
*skb
, int offset
);
1519 static inline __wsum
ip_vs_check_diff4(__be32 old
, __be32
new, __wsum oldsum
)
1521 __be32 diff
[2] = { ~old
, new };
1523 return csum_partial(diff
, sizeof(diff
), oldsum
);
1526 #ifdef CONFIG_IP_VS_IPV6
1527 static inline __wsum
ip_vs_check_diff16(const __be32
*old
, const __be32
*new,
1530 __be32 diff
[8] = { ~old
[3], ~old
[2], ~old
[1], ~old
[0],
1531 new[3], new[2], new[1], new[0] };
1533 return csum_partial(diff
, sizeof(diff
), oldsum
);
1537 static inline __wsum
ip_vs_check_diff2(__be16 old
, __be16
new, __wsum oldsum
)
1539 __be16 diff
[2] = { ~old
, new };
1541 return csum_partial(diff
, sizeof(diff
), oldsum
);
1544 /* Forget current conntrack (unconfirmed) and attach notrack entry */
1545 static inline void ip_vs_notrack(struct sk_buff
*skb
)
1547 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
1548 enum ip_conntrack_info ctinfo
;
1549 struct nf_conn
*ct
= nf_ct_get(skb
, &ctinfo
);
1551 if (!ct
|| !nf_ct_is_untracked(ct
)) {
1552 nf_conntrack_put(skb
->nfct
);
1553 skb
->nfct
= &nf_ct_untracked_get()->ct_general
;
1554 skb
->nfctinfo
= IP_CT_NEW
;
1555 nf_conntrack_get(skb
->nfct
);
1560 #ifdef CONFIG_IP_VS_NFCT
1561 /* Netfilter connection tracking
1562 * (from ip_vs_nfct.c)
1564 static inline int ip_vs_conntrack_enabled(struct netns_ipvs
*ipvs
)
1566 #ifdef CONFIG_SYSCTL
1567 return ipvs
->sysctl_conntrack
;
1573 void ip_vs_update_conntrack(struct sk_buff
*skb
, struct ip_vs_conn
*cp
,
1575 int ip_vs_confirm_conntrack(struct sk_buff
*skb
);
1576 void ip_vs_nfct_expect_related(struct sk_buff
*skb
, struct nf_conn
*ct
,
1577 struct ip_vs_conn
*cp
, u_int8_t proto
,
1578 const __be16 port
, int from_rs
);
1579 void ip_vs_conn_drop_conntrack(struct ip_vs_conn
*cp
);
1583 static inline int ip_vs_conntrack_enabled(struct netns_ipvs
*ipvs
)
1588 static inline void ip_vs_update_conntrack(struct sk_buff
*skb
,
1589 struct ip_vs_conn
*cp
, int outin
)
1593 static inline int ip_vs_confirm_conntrack(struct sk_buff
*skb
)
1598 static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn
*cp
)
1601 #endif /* CONFIG_IP_VS_NFCT */
1604 ip_vs_dest_conn_overhead(struct ip_vs_dest
*dest
)
1606 /* We think the overhead of processing active connections is 256
1607 * times higher than that of inactive connections in average. (This
1608 * 256 times might not be accurate, we will change it later) We
1609 * use the following formula to estimate the overhead now:
1610 * dest->activeconns*256 + dest->inactconns
1612 return (atomic_read(&dest
->activeconns
) << 8) +
1613 atomic_read(&dest
->inactconns
);
1616 #endif /* _NET_IP_VS_H */