^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* IP Virtual Server
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * data structure and functionality definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #ifndef _NET_IP_VS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define _NET_IP_VS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/ip_vs.h> /* definitions shared with userland */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/types.h> /* for __uXX types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/list.h> /* for struct list_head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/spinlock.h> /* for struct rwlock_t */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/atomic.h> /* for struct atomic_t */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/refcount.h> /* for struct refcount_t */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <net/checksum.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/netfilter.h> /* for union nf_inet_addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/ipv6.h> /* for struct ipv6hdr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #if IS_ENABLED(CONFIG_NF_CONNTRACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <net/netfilter/nf_conntrack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <net/net_namespace.h> /* Netw namespace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define IP_VS_HDR_INVERSE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define IP_VS_HDR_ICMP 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /* Generic access of ipvs struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static inline struct netns_ipvs *net_ipvs(struct net* net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return net->ipvs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* Connections' size value needed by ip_vs_ctl.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) extern int ip_vs_conn_tab_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct ip_vs_iphdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int hdr_flags; /* ipvs flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) __u32 off; /* Where IP or IPv4 header starts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) __u32 len; /* IPv4 simply where L4 starts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * IPv6 where L4 Transport Header starts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) __u16 fragoffs; /* IPv6 fragment offset, 0 if first frag (or not frag)*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) __s16 protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) __s32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) union nf_inet_addr saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) union nf_inet_addr daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static inline void *frag_safe_skb_hp(const struct sk_buff *skb, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int len, void *buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return skb_header_pointer(skb, offset, len, buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* This function handles filling *ip_vs_iphdr, both for IPv4 and IPv6.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * IPv6 requires some extra work, as finding proper header position,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * depend on the IPv6 extension headers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) ip_vs_fill_iph_skb_off(int af, const struct sk_buff *skb, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int hdr_flags, struct ip_vs_iphdr *iphdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) iphdr->hdr_flags = hdr_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) iphdr->off = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #ifdef CONFIG_IP_VS_IPV6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (af == AF_INET6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct ipv6hdr _iph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) const struct ipv6hdr *iph = skb_header_pointer(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) skb, offset, sizeof(_iph), &_iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (!iph)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) iphdr->saddr.in6 = iph->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) iphdr->daddr.in6 = iph->daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /* ipv6_find_hdr() updates len, flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) iphdr->len = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) iphdr->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) iphdr->protocol = ipv6_find_hdr(skb, &iphdr->len, -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) &iphdr->fragoffs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) &iphdr->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (iphdr->protocol < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct iphdr _iph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) const struct iphdr *iph = skb_header_pointer(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) skb, offset, sizeof(_iph), &_iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (!iph)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) iphdr->len = offset + iph->ihl * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) iphdr->fragoffs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) iphdr->protocol = iph->protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) iphdr->saddr.ip = iph->saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) iphdr->daddr.ip = iph->daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) ip_vs_fill_iph_skb_icmp(int af, const struct sk_buff *skb, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) bool inverse, struct ip_vs_iphdr *iphdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) int hdr_flags = IP_VS_HDR_ICMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (inverse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) hdr_flags |= IP_VS_HDR_INVERSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return ip_vs_fill_iph_skb_off(af, skb, offset, hdr_flags, iphdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ip_vs_fill_iph_skb(int af, const struct sk_buff *skb, bool inverse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct ip_vs_iphdr *iphdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) int hdr_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (inverse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) hdr_flags |= IP_VS_HDR_INVERSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return ip_vs_fill_iph_skb_off(af, skb, skb_network_offset(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) hdr_flags, iphdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ip_vs_iph_inverse(const struct ip_vs_iphdr *iph)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return !!(iph->hdr_flags & IP_VS_HDR_INVERSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) ip_vs_iph_icmp(const struct ip_vs_iphdr *iph)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return !!(iph->hdr_flags & IP_VS_HDR_ICMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) const union nf_inet_addr *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) #ifdef CONFIG_IP_VS_IPV6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) if (af == AF_INET6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) dst->in6 = src->in6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) dst->ip = src->ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static inline void ip_vs_addr_set(int af, union nf_inet_addr *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) const union nf_inet_addr *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) #ifdef CONFIG_IP_VS_IPV6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (af == AF_INET6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) dst->in6 = src->in6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) dst->ip = src->ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) dst->all[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) dst->all[2] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) dst->all[3] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) const union nf_inet_addr *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) #ifdef CONFIG_IP_VS_IPV6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (af == AF_INET6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return ipv6_addr_equal(&a->in6, &b->in6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) return a->ip == b->ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #ifdef CONFIG_IP_VS_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int ip_vs_get_debug_level(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) const union nf_inet_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) int *idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) #ifdef CONFIG_IP_VS_IPV6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (af == AF_INET6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6c]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) &addr->in6) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) len = snprintf(&buf[*idx], buf_len - *idx, "%pI4",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) &addr->ip) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) *idx += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) BUG_ON(*idx > buf_len + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return &buf[*idx - len];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) #define IP_VS_DBG_BUF(level, msg, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) char ip_vs_dbg_buf[160]; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) int ip_vs_dbg_idx = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (level <= ip_vs_get_debug_level()) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #define IP_VS_ERR_BUF(msg...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) char ip_vs_dbg_buf[160]; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) int ip_vs_dbg_idx = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) pr_err(msg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) #define IP_VS_DBG_ADDR(af, addr) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) ip_vs_dbg_addr(af, ip_vs_dbg_buf, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) sizeof(ip_vs_dbg_buf), addr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) &ip_vs_dbg_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) #define IP_VS_DBG(level, msg, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (level <= ip_vs_get_debug_level()) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #define IP_VS_DBG_RL(msg, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (net_ratelimit()) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (level <= ip_vs_get_debug_level()) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) pp->debug_packet(af, pp, skb, ofs, msg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (level <= ip_vs_get_debug_level() && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) net_ratelimit()) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) pp->debug_packet(af, pp, skb, ofs, msg); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #else /* NO DEBUGGING at ALL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #define IP_VS_DBG_BUF(level, msg...) do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) #define IP_VS_ERR_BUF(msg...) do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) #define IP_VS_DBG(level, msg...) do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) #define IP_VS_DBG_RL(msg...) do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) #define IP_VS_BUG() BUG()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) #define IP_VS_ERR_RL(msg, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (net_ratelimit()) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) pr_err(msg, ##__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #ifdef CONFIG_IP_VS_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) #define EnterFunction(level) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (level <= ip_vs_get_debug_level()) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) printk(KERN_DEBUG \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) pr_fmt("Enter: %s, %s line %i\n"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) __func__, __FILE__, __LINE__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) #define LeaveFunction(level) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (level <= ip_vs_get_debug_level()) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) printk(KERN_DEBUG \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) pr_fmt("Leave: %s, %s line %i\n"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) __func__, __FILE__, __LINE__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) #define EnterFunction(level) do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) #define LeaveFunction(level) do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /* The port number of FTP service (in network order). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) #define FTPPORT cpu_to_be16(21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) #define FTPDATA cpu_to_be16(20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /* TCP State Values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) IP_VS_TCP_S_NONE = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) IP_VS_TCP_S_ESTABLISHED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) IP_VS_TCP_S_SYN_SENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) IP_VS_TCP_S_SYN_RECV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) IP_VS_TCP_S_FIN_WAIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) IP_VS_TCP_S_TIME_WAIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) IP_VS_TCP_S_CLOSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) IP_VS_TCP_S_CLOSE_WAIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) IP_VS_TCP_S_LAST_ACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) IP_VS_TCP_S_LISTEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) IP_VS_TCP_S_SYNACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) IP_VS_TCP_S_LAST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /* UDP State Values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) IP_VS_UDP_S_NORMAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) IP_VS_UDP_S_LAST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) /* ICMP State Values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) IP_VS_ICMP_S_NORMAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) IP_VS_ICMP_S_LAST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) /* SCTP State Values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) enum ip_vs_sctp_states {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) IP_VS_SCTP_S_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) IP_VS_SCTP_S_INIT1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) IP_VS_SCTP_S_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) IP_VS_SCTP_S_COOKIE_SENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) IP_VS_SCTP_S_COOKIE_REPLIED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) IP_VS_SCTP_S_COOKIE_WAIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) IP_VS_SCTP_S_COOKIE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) IP_VS_SCTP_S_COOKIE_ECHOED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) IP_VS_SCTP_S_ESTABLISHED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) IP_VS_SCTP_S_SHUTDOWN_SENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) IP_VS_SCTP_S_SHUTDOWN_RECEIVED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) IP_VS_SCTP_S_SHUTDOWN_ACK_SENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) IP_VS_SCTP_S_REJECTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) IP_VS_SCTP_S_CLOSED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) IP_VS_SCTP_S_LAST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /* Connection templates use bits from state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) #define IP_VS_CTPL_S_NONE 0x0000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) #define IP_VS_CTPL_S_ASSURED 0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) #define IP_VS_CTPL_S_LAST 0x0002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) /* Delta sequence info structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) * Each ip_vs_conn has 2 (output AND input seq. changes).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * Only used in the VS/NAT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) struct ip_vs_seq {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) __u32 init_seq; /* Add delta from this seq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) __u32 delta; /* Delta in sequence numbers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) __u32 previous_delta; /* Delta in sequence numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) * before last resized pkt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) /* counters per cpu */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) struct ip_vs_counters {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) __u64 conns; /* connections scheduled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) __u64 inpkts; /* incoming packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) __u64 outpkts; /* outgoing packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) __u64 inbytes; /* incoming bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) __u64 outbytes; /* outgoing bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) /* Stats per cpu */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) struct ip_vs_cpu_stats {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) struct ip_vs_counters cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) struct u64_stats_sync syncp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /* IPVS statistics objects */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) struct ip_vs_estimator {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) u64 last_inbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) u64 last_outbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) u64 last_conns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) u64 last_inpkts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) u64 last_outpkts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) u64 cps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) u64 inpps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) u64 outpps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) u64 inbps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) u64 outbps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) * IPVS statistics object, 64-bit kernel version of struct ip_vs_stats_user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) struct ip_vs_kstats {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) u64 conns; /* connections scheduled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) u64 inpkts; /* incoming packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) u64 outpkts; /* outgoing packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) u64 inbytes; /* incoming bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) u64 outbytes; /* outgoing bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) u64 cps; /* current connection rate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) u64 inpps; /* current in packet rate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) u64 outpps; /* current out packet rate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) u64 inbps; /* current in byte rate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) u64 outbps; /* current out byte rate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct ip_vs_stats {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct ip_vs_kstats kstats; /* kernel statistics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) struct ip_vs_estimator est; /* estimator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) struct ip_vs_cpu_stats __percpu *cpustats; /* per cpu counters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) spinlock_t lock; /* spin lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) struct ip_vs_kstats kstats0; /* reset values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) struct dst_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) struct iphdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) struct ip_vs_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) struct ip_vs_app;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct sk_buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) struct ip_vs_proto_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) struct ip_vs_protocol {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) struct ip_vs_protocol *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) u16 protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) u16 num_states;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) int dont_defrag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) void (*init)(struct ip_vs_protocol *pp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) void (*exit)(struct ip_vs_protocol *pp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) int (*init_netns)(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) void (*exit_netns)(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) int (*conn_schedule)(struct netns_ipvs *ipvs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) int af, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) struct ip_vs_proto_data *pd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) int *verdict, struct ip_vs_conn **cpp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) struct ip_vs_conn *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) (*conn_in_get)(struct netns_ipvs *ipvs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) int af,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) const struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct ip_vs_conn *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) (*conn_out_get)(struct netns_ipvs *ipvs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) int af,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) const struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) int (*snat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) struct ip_vs_conn *cp, struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) int (*dnat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) struct ip_vs_conn *cp, struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) const char *(*state_name)(int state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) void (*state_transition)(struct ip_vs_conn *cp, int direction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) struct ip_vs_proto_data *pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) int (*register_app)(struct netns_ipvs *ipvs, struct ip_vs_app *inc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) void (*unregister_app)(struct netns_ipvs *ipvs, struct ip_vs_app *inc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) int (*app_conn_bind)(struct ip_vs_conn *cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) void (*debug_packet)(int af, struct ip_vs_protocol *pp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) const char *msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) void (*timeout_change)(struct ip_vs_proto_data *pd, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) /* protocol data per netns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) struct ip_vs_proto_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct ip_vs_proto_data *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) struct ip_vs_protocol *pp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) int *timeout_table; /* protocol timeout table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) atomic_t appcnt; /* counter of proto app incs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) struct tcp_states_t *tcp_state_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) struct ip_vs_protocol *ip_vs_proto_get(unsigned short proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) struct ip_vs_proto_data *ip_vs_proto_data_get(struct netns_ipvs *ipvs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) unsigned short proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) struct ip_vs_conn_param {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) struct netns_ipvs *ipvs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) const union nf_inet_addr *caddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) const union nf_inet_addr *vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) __be16 cport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) __be16 vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) __u16 protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) u16 af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) const struct ip_vs_pe *pe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) char *pe_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) __u8 pe_data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) /* IP_VS structure allocated for each dynamically scheduled connection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) struct ip_vs_conn {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) struct hlist_node c_list; /* hashed list heads */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) /* Protocol, addresses and port numbers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) __be16 cport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) __be16 dport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) __be16 vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) u16 af; /* address family */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) union nf_inet_addr caddr; /* client address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) union nf_inet_addr vaddr; /* virtual address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) union nf_inet_addr daddr; /* destination address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) volatile __u32 flags; /* status flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) __u16 protocol; /* Which protocol (TCP/UDP) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) __u16 daf; /* Address family of the dest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) struct netns_ipvs *ipvs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) /* counter and timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) refcount_t refcnt; /* reference count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) struct timer_list timer; /* Expiration timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) volatile unsigned long timeout; /* timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) /* Flags and state transition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) spinlock_t lock; /* lock for state transition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) volatile __u16 state; /* state info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) volatile __u16 old_state; /* old state, to be used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) * state transition triggerd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) * synchronization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) __u32 fwmark; /* Fire wall mark from skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) unsigned long sync_endtime; /* jiffies + sent_retries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) /* Control members */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) struct ip_vs_conn *control; /* Master control connection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) atomic_t n_control; /* Number of controlled ones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) struct ip_vs_dest *dest; /* real server */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) atomic_t in_pkts; /* incoming packet counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) /* Packet transmitter for different forwarding methods. If it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) * mangles the packet, it must return NF_DROP or better NF_STOLEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) * otherwise this must be changed to a sk_buff **.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) * NF_ACCEPT can be returned when destination is local.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) /* Note: we can group the following members into a structure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * in order to save more space, and the following members are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) * only used in VS/NAT anyway
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) struct ip_vs_app *app; /* bound ip_vs_app object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) void *app_data; /* Application private data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) struct ip_vs_seq in_seq; /* incoming seq. struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) struct ip_vs_seq out_seq; /* outgoing seq. struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) const struct ip_vs_pe *pe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) char *pe_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) __u8 pe_data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) struct rcu_head rcu_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) /* Extended internal versions of struct ip_vs_service_user and ip_vs_dest_user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) * for IPv6 support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) * We need these to conveniently pass around service and destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) * options, but unfortunately, we also need to keep the old definitions to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) * maintain userspace backwards compatibility for the setsockopt interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) struct ip_vs_service_user_kern {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) /* virtual service addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) u16 af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) u16 protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) union nf_inet_addr addr; /* virtual ip address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) __be16 port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) u32 fwmark; /* firwall mark of service */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) /* virtual service options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) char *sched_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) char *pe_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) unsigned int flags; /* virtual service flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) unsigned int timeout; /* persistent timeout in sec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) __be32 netmask; /* persistent netmask or plen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) struct ip_vs_dest_user_kern {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) /* destination server address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) union nf_inet_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) __be16 port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) /* real server options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) unsigned int conn_flags; /* connection flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) int weight; /* destination weight */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) /* thresholds for active connections */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) u32 u_threshold; /* upper threshold */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) u32 l_threshold; /* lower threshold */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) /* Address family of addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) u16 af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) u16 tun_type; /* tunnel type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) __be16 tun_port; /* tunnel port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) u16 tun_flags; /* tunnel flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) * The information about the virtual service offered to the net and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) * forwarding entries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) struct ip_vs_service {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) struct hlist_node s_list; /* for normal service table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) struct hlist_node f_list; /* for fwmark-based service table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) atomic_t refcnt; /* reference counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) u16 af; /* address family */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) __u16 protocol; /* which protocol (TCP/UDP) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) union nf_inet_addr addr; /* IP address for virtual service */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) __be16 port; /* port number for the service */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) __u32 fwmark; /* firewall mark of the service */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) unsigned int flags; /* service status flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) unsigned int timeout; /* persistent timeout in ticks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) __be32 netmask; /* grouping granularity, mask/plen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) struct netns_ipvs *ipvs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) struct list_head destinations; /* real server d-linked list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) __u32 num_dests; /* number of servers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) struct ip_vs_stats stats; /* statistics for the service */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) /* for scheduling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) struct ip_vs_scheduler __rcu *scheduler; /* bound scheduler object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) spinlock_t sched_lock; /* lock sched_data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) void *sched_data; /* scheduler application data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) /* alternate persistence engine */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) struct ip_vs_pe __rcu *pe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) int conntrack_afmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) struct rcu_head rcu_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) /* Information for cached dst */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) struct ip_vs_dest_dst {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) struct dst_entry *dst_cache; /* destination cache entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) u32 dst_cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) union nf_inet_addr dst_saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) struct rcu_head rcu_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) /* The real server destination forwarding entry with ip address, port number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) * and so on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) struct ip_vs_dest {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) struct list_head n_list; /* for the dests in the service */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) struct hlist_node d_list; /* for table with all the dests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) u16 af; /* address family */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) __be16 port; /* port number of the server */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) union nf_inet_addr addr; /* IP address of the server */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) volatile unsigned int flags; /* dest status flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) atomic_t conn_flags; /* flags to copy to conn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) atomic_t weight; /* server weight */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) atomic_t last_weight; /* server latest weight */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) __u16 tun_type; /* tunnel type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) __be16 tun_port; /* tunnel port */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) __u16 tun_flags; /* tunnel flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) refcount_t refcnt; /* reference counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) struct ip_vs_stats stats; /* statistics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) unsigned long idle_start; /* start time, jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) /* connection counters and thresholds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) atomic_t activeconns; /* active connections */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) atomic_t inactconns; /* inactive connections */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) atomic_t persistconns; /* persistent connections */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) __u32 u_threshold; /* upper threshold */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) __u32 l_threshold; /* lower threshold */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) /* for destination cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) spinlock_t dst_lock; /* lock of dst_cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) struct ip_vs_dest_dst __rcu *dest_dst; /* cached dst info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) /* for virtual service */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) struct ip_vs_service __rcu *svc; /* service it belongs to */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) __u16 protocol; /* which protocol (TCP/UDP) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) __be16 vport; /* virtual port number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) union nf_inet_addr vaddr; /* virtual IP address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) __u32 vfwmark; /* firewall mark of service */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) struct list_head t_list; /* in dest_trash */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) unsigned int in_rs_table:1; /* we are in rs_table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) /* The scheduler object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) struct ip_vs_scheduler {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) struct list_head n_list; /* d-linked list head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) char *name; /* scheduler name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) atomic_t refcnt; /* reference counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) struct module *module; /* THIS_MODULE/NULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) /* scheduler initializing service */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) int (*init_service)(struct ip_vs_service *svc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) /* scheduling service finish */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) void (*done_service)(struct ip_vs_service *svc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) /* dest is linked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) int (*add_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) /* dest is unlinked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) int (*del_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) /* dest is updated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) int (*upd_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) /* selecting a server from the given service */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) /* The persistence engine object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) struct ip_vs_pe {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) struct list_head n_list; /* d-linked list head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) char *name; /* scheduler name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) atomic_t refcnt; /* reference counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) struct module *module; /* THIS_MODULE/NULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) /* get the connection template, if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) bool (*ct_match)(const struct ip_vs_conn_param *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) struct ip_vs_conn *ct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) bool inverse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) /* create connections for real-server outgoing packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) struct ip_vs_conn* (*conn_out)(struct ip_vs_service *svc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) struct ip_vs_dest *dest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) const struct ip_vs_iphdr *iph,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) __be16 dport, __be16 cport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) /* The application module object (a.k.a. app incarnation) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) struct ip_vs_app {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) struct list_head a_list; /* member in app list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) int type; /* IP_VS_APP_TYPE_xxx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) char *name; /* application module name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) __u16 protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) struct module *module; /* THIS_MODULE/NULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) struct list_head incs_list; /* list of incarnations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) /* members for application incarnations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) struct list_head p_list; /* member in proto app list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) struct ip_vs_app *app; /* its real application */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) __be16 port; /* port number in net order */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) atomic_t usecnt; /* usage counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) struct rcu_head rcu_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) /* output hook: Process packet in inout direction, diff set for TCP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) * 2=Mangled but checksum was not updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) struct sk_buff *, int *diff, struct ip_vs_iphdr *ipvsh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) /* input hook: Process packet in outin direction, diff set for TCP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) * 2=Mangled but checksum was not updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) struct sk_buff *, int *diff, struct ip_vs_iphdr *ipvsh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) /* ip_vs_app initializer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) /* ip_vs_app finish */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) /* not used now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) struct ip_vs_protocol *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) int * timeout_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) int * timeouts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) int timeouts_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) int *verdict, struct ip_vs_conn **cpp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) struct ip_vs_conn *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) const struct iphdr *iph, int inverse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) struct ip_vs_conn *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) const struct iphdr *iph, int inverse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) int (*state_transition)(struct ip_vs_conn *cp, int direction,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) struct ip_vs_app *app);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) void (*timeout_change)(struct ip_vs_app *app, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) struct ipvs_master_sync_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) struct list_head sync_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) struct ip_vs_sync_buff *sync_buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) unsigned long sync_queue_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) unsigned int sync_queue_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) struct delayed_work master_wakeup_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) struct netns_ipvs *ipvs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) struct ip_vs_sync_thread_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) /* How much time to keep dests in trash */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) #define IP_VS_DEST_TRASH_PERIOD (120 * HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) struct ipvs_sync_daemon_cfg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) union nf_inet_addr mcast_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) int syncid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) u16 sync_maxlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) u16 mcast_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) u8 mcast_af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) u8 mcast_ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) /* multicast interface name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) char mcast_ifn[IP_VS_IFNAME_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) /* IPVS in network namespace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) struct netns_ipvs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) int gen; /* Generation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) int enable; /* enable like nf_hooks do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) /* Hash table: for real service lookups */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) #define IP_VS_RTAB_BITS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) #define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) #define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) struct hlist_head rs_table[IP_VS_RTAB_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) /* ip_vs_app */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) struct list_head app_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) /* ip_vs_proto */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) #define IP_VS_PROTO_TAB_SIZE 32 /* must be power of 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) /* ip_vs_proto_tcp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) #ifdef CONFIG_IP_VS_PROTO_TCP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) #define TCP_APP_TAB_BITS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) #define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) #define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) struct list_head tcp_apps[TCP_APP_TAB_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) /* ip_vs_proto_udp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) #ifdef CONFIG_IP_VS_PROTO_UDP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) #define UDP_APP_TAB_BITS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) #define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) #define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) struct list_head udp_apps[UDP_APP_TAB_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) /* ip_vs_proto_sctp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) #ifdef CONFIG_IP_VS_PROTO_SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) #define SCTP_APP_TAB_BITS 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) #define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) #define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) /* Hash table for SCTP application incarnations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) struct list_head sctp_apps[SCTP_APP_TAB_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) /* ip_vs_conn */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) atomic_t conn_count; /* connection counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) /* ip_vs_ctl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) struct ip_vs_stats tot_stats; /* Statistics & est. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) int num_services; /* no of virtual services */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) int num_services6; /* IPv6 virtual services */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) /* Trash for destinations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) struct list_head dest_trash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) spinlock_t dest_trash_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) struct timer_list dest_trash_timer; /* expiration timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) /* Service counters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) atomic_t ftpsvc_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) atomic_t nullsvc_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) atomic_t conn_out_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) /* delayed work for expiring no dest connections */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) struct delayed_work expire_nodest_conn_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) /* 1/rate drop and drop-entry variables */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) struct delayed_work defense_work; /* Work handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) int drop_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) int drop_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) int old_secure_tcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) atomic_t dropentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) /* locks in ctl.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) spinlock_t dropentry_lock; /* drop entry handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) spinlock_t droppacket_lock; /* drop packet handling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) spinlock_t securetcp_lock; /* state and timeout tables */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) /* sys-ctl struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) struct ctl_table_header *sysctl_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) struct ctl_table *sysctl_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) /* sysctl variables */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) int sysctl_amemthresh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) int sysctl_am_droprate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) int sysctl_drop_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) int sysctl_drop_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) int sysctl_secure_tcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) #ifdef CONFIG_IP_VS_NFCT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) int sysctl_conntrack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) int sysctl_snat_reroute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) int sysctl_sync_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) int sysctl_sync_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) int sysctl_sync_persist_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) unsigned long sysctl_sync_qlen_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) int sysctl_sync_sock_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) int sysctl_cache_bypass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) int sysctl_expire_nodest_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) int sysctl_sloppy_tcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) int sysctl_sloppy_sctp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) int sysctl_expire_quiescent_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) int sysctl_sync_threshold[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) unsigned int sysctl_sync_refresh_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) int sysctl_sync_retries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) int sysctl_nat_icmp_send;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) int sysctl_pmtu_disc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) int sysctl_backup_only;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) int sysctl_conn_reuse_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) int sysctl_schedule_icmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) int sysctl_ignore_tunneled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) /* ip_vs_lblc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) int sysctl_lblc_expiration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) struct ctl_table_header *lblc_ctl_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) struct ctl_table *lblc_ctl_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) /* ip_vs_lblcr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) int sysctl_lblcr_expiration;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) struct ctl_table_header *lblcr_ctl_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) struct ctl_table *lblcr_ctl_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) /* ip_vs_est */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) struct list_head est_list; /* estimator list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) spinlock_t est_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) struct timer_list est_timer; /* Estimation timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) /* ip_vs_sync */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) spinlock_t sync_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) struct ipvs_master_sync_state *ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) spinlock_t sync_buff_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) struct ip_vs_sync_thread_data *master_tinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) struct ip_vs_sync_thread_data *backup_tinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) int threads_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) volatile int sync_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) struct mutex sync_mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) struct ipvs_sync_daemon_cfg mcfg; /* Master Configuration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) struct ipvs_sync_daemon_cfg bcfg; /* Backup Configuration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) /* net name space ptr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) struct net *net; /* Needed by timer routines */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) /* Number of heterogeneous destinations, needed becaus heterogeneous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) * are not supported when synchronization is enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) unsigned int mixed_address_family_dests;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) unsigned int hooks_afmask; /* &1=AF_INET, &2=AF_INET6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) #define DEFAULT_SYNC_THRESHOLD 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) #define DEFAULT_SYNC_PERIOD 50
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) #define DEFAULT_SYNC_VER 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) #define DEFAULT_SLOPPY_TCP 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) #define DEFAULT_SLOPPY_SCTP 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) #define DEFAULT_SYNC_REFRESH_PERIOD (0U * HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) #define DEFAULT_SYNC_RETRIES 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) #define IPVS_SYNC_WAKEUP_RATE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) #define IPVS_SYNC_QLEN_MAX (IPVS_SYNC_WAKEUP_RATE * 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) #define IPVS_SYNC_SEND_DELAY (HZ / 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) #define IPVS_SYNC_CHECK_PERIOD HZ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) #define IPVS_SYNC_FLUSH_TIME (HZ * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) #define IPVS_SYNC_PORTS_MAX (1 << 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) return ipvs->sysctl_sync_threshold[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) return READ_ONCE(ipvs->sysctl_sync_threshold[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) return READ_ONCE(ipvs->sysctl_sync_refresh_period);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) return ipvs->sysctl_sync_retries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) return ipvs->sysctl_sync_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) return ipvs->sysctl_sloppy_tcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) return ipvs->sysctl_sloppy_sctp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) return READ_ONCE(ipvs->sysctl_sync_ports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) return ipvs->sysctl_sync_persist_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) return ipvs->sysctl_sync_qlen_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) return ipvs->sysctl_sync_sock_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) return ipvs->sysctl_pmtu_disc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) return ipvs->sync_state & IP_VS_STATE_BACKUP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) ipvs->sysctl_backup_only;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) return ipvs->sysctl_conn_reuse_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) static inline int sysctl_expire_nodest_conn(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) return ipvs->sysctl_expire_nodest_conn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) static inline int sysctl_schedule_icmp(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) return ipvs->sysctl_schedule_icmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) static inline int sysctl_ignore_tunneled(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) return ipvs->sysctl_ignore_tunneled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) static inline int sysctl_cache_bypass(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) return ipvs->sysctl_cache_bypass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) return DEFAULT_SYNC_THRESHOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) return DEFAULT_SYNC_PERIOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) return DEFAULT_SYNC_REFRESH_PERIOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) return DEFAULT_SYNC_RETRIES & 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) return DEFAULT_SYNC_VER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) return DEFAULT_SLOPPY_TCP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) return DEFAULT_SLOPPY_SCTP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) return IPVS_SYNC_QLEN_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) static inline int sysctl_expire_nodest_conn(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) static inline int sysctl_schedule_icmp(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) static inline int sysctl_ignore_tunneled(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) static inline int sysctl_cache_bypass(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) /* IPVS core functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) * (from ip_vs_core.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) const char *ip_vs_proto_name(unsigned int proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) void ip_vs_init_hash_table(struct list_head *table, int rows);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) struct ip_vs_dest *dest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) const struct ip_vs_iphdr *iph,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) __be16 dport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) __be16 cport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) #define IP_VS_APP_TYPE_FTP 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) /* ip_vs_conn handling functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) * (from ip_vs_conn.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) IP_VS_DIR_INPUT = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) IP_VS_DIR_OUTPUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) IP_VS_DIR_INPUT_ONLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) IP_VS_DIR_LAST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) static inline void ip_vs_conn_fill_param(struct netns_ipvs *ipvs, int af, int protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) const union nf_inet_addr *caddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) __be16 cport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) const union nf_inet_addr *vaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) __be16 vport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) struct ip_vs_conn_param *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) p->ipvs = ipvs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) p->af = af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) p->protocol = protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) p->caddr = caddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) p->cport = cport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) p->vaddr = vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) p->vport = vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) p->pe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) p->pe_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) struct ip_vs_conn * ip_vs_conn_in_get_proto(struct netns_ipvs *ipvs, int af,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) const struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) struct ip_vs_conn * ip_vs_conn_out_get_proto(struct netns_ipvs *ipvs, int af,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) const struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) /* Get reference to gain full access to conn.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) * By default, RCU read-side critical sections have access only to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) * conn fields and its PE data, see ip_vs_conn_rcu_free() for reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) return refcount_inc_not_zero(&cp->refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) /* put back the conn without restarting its timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) smp_mb__before_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) refcount_dec(&cp->refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) void ip_vs_conn_put(struct ip_vs_conn *cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) const union nf_inet_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) __be16 dport, unsigned int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) struct ip_vs_dest *dest, __u32 fwmark);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) const char *ip_vs_state_name(const struct ip_vs_conn *cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) int ip_vs_check_template(struct ip_vs_conn *ct, struct ip_vs_dest *cdest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) void ip_vs_random_dropentry(struct netns_ipvs *ipvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) int ip_vs_conn_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) void ip_vs_conn_cleanup(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) static inline void ip_vs_control_del(struct ip_vs_conn *cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) struct ip_vs_conn *ctl_cp = cp->control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) if (!ctl_cp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) IP_VS_ERR_BUF("request control DEL for uncontrolled: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) "%s:%d to %s:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) IP_VS_DBG_ADDR(cp->af, &cp->caddr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) ntohs(cp->cport),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) ntohs(cp->vport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) IP_VS_DBG_BUF(7, "DELeting control for: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) IP_VS_DBG_ADDR(cp->af, &cp->caddr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) ntohs(cp->cport),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) ntohs(ctl_cp->cport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) cp->control = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) if (atomic_read(&ctl_cp->n_control) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) IP_VS_ERR_BUF("BUG control DEL with n=0 : "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) "%s:%d to %s:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) IP_VS_DBG_ADDR(cp->af, &cp->caddr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) ntohs(cp->cport),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) ntohs(cp->vport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) atomic_dec(&ctl_cp->n_control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) if (cp->control) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) IP_VS_ERR_BUF("request control ADD for already controlled: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) "%s:%d to %s:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) IP_VS_DBG_ADDR(cp->af, &cp->caddr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) ntohs(cp->cport),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) ntohs(cp->vport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) ip_vs_control_del(cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) IP_VS_DBG_BUF(7, "ADDing control for: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) IP_VS_DBG_ADDR(cp->af, &cp->caddr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) ntohs(cp->cport),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) ntohs(ctl_cp->cport));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) cp->control = ctl_cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) atomic_inc(&ctl_cp->n_control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) /* Mark our template as assured */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) ip_vs_control_assure_ct(struct ip_vs_conn *cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) struct ip_vs_conn *ct = cp->control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) if (ct && !(ct->state & IP_VS_CTPL_S_ASSURED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) (ct->flags & IP_VS_CONN_F_TEMPLATE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) ct->state |= IP_VS_CTPL_S_ASSURED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) /* IPVS netns init & cleanup functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) int ip_vs_estimator_net_init(struct netns_ipvs *ipvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) int ip_vs_control_net_init(struct netns_ipvs *ipvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) int ip_vs_protocol_net_init(struct netns_ipvs *ipvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) int ip_vs_app_net_init(struct netns_ipvs *ipvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) int ip_vs_conn_net_init(struct netns_ipvs *ipvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) int ip_vs_sync_net_init(struct netns_ipvs *ipvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) void ip_vs_conn_net_cleanup(struct netns_ipvs *ipvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) void ip_vs_app_net_cleanup(struct netns_ipvs *ipvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) void ip_vs_protocol_net_cleanup(struct netns_ipvs *ipvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) void ip_vs_control_net_cleanup(struct netns_ipvs *ipvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) void ip_vs_estimator_net_cleanup(struct netns_ipvs *ipvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) void ip_vs_sync_net_cleanup(struct netns_ipvs *ipvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) void ip_vs_service_nets_cleanup(struct list_head *net_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) /* IPVS application functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) * (from ip_vs_app.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) #define IP_VS_APP_MAX_PORTS 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) struct ip_vs_app *register_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) void unregister_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) void ip_vs_unbind_app(struct ip_vs_conn *cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) int register_ip_vs_app_inc(struct netns_ipvs *ipvs, struct ip_vs_app *app, __u16 proto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) __u16 port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) int ip_vs_app_inc_get(struct ip_vs_app *inc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) void ip_vs_app_inc_put(struct ip_vs_app *inc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) struct ip_vs_iphdr *ipvsh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) struct ip_vs_iphdr *ipvsh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) int register_ip_vs_pe(struct ip_vs_pe *pe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) int unregister_ip_vs_pe(struct ip_vs_pe *pe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) struct ip_vs_pe *ip_vs_pe_getbyname(const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) /* Use a #define to avoid all of module.h just for these trivial ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) #define ip_vs_pe_get(pe) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) if (pe && pe->module) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) __module_get(pe->module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) #define ip_vs_pe_put(pe) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) if (pe && pe->module) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) module_put(pe->module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) /* IPVS protocol functions (from ip_vs_proto.c) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) int ip_vs_protocol_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) void ip_vs_protocol_cleanup(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) int *ip_vs_create_timeout_table(int *table, int size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) void ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) const struct sk_buff *skb, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) const char *msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) extern struct ip_vs_protocol ip_vs_protocol_tcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) extern struct ip_vs_protocol ip_vs_protocol_udp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) extern struct ip_vs_protocol ip_vs_protocol_icmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) extern struct ip_vs_protocol ip_vs_protocol_esp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) extern struct ip_vs_protocol ip_vs_protocol_ah;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) extern struct ip_vs_protocol ip_vs_protocol_sctp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) /* Registering/unregistering scheduler functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) * (from ip_vs_sched.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) int ip_vs_bind_scheduler(struct ip_vs_service *svc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) struct ip_vs_scheduler *scheduler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) void ip_vs_unbind_scheduler(struct ip_vs_service *svc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) struct ip_vs_scheduler *sched);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) struct ip_vs_conn *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) struct ip_vs_proto_data *pd, int *ignored,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) /* IPVS control data and functions (from ip_vs_ctl.c) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) extern struct ip_vs_stats ip_vs_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) extern int sysctl_ip_vs_sync_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) struct ip_vs_service *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) ip_vs_service_find(struct netns_ipvs *ipvs, int af, __u32 fwmark, __u16 protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) const union nf_inet_addr *vaddr, __be16 vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) bool ip_vs_has_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) const union nf_inet_addr *daddr, __be16 dport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) struct ip_vs_dest *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) ip_vs_find_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) const union nf_inet_addr *daddr, __be16 dport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) struct ip_vs_dest *ip_vs_find_tunnel(struct netns_ipvs *ipvs, int af,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) const union nf_inet_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) __be16 tun_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) int ip_vs_use_count_inc(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) void ip_vs_use_count_dec(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) int ip_vs_register_nl_ioctl(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) void ip_vs_unregister_nl_ioctl(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) int ip_vs_control_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) void ip_vs_control_cleanup(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) struct ip_vs_dest *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) ip_vs_find_dest(struct netns_ipvs *ipvs, int svc_af, int dest_af,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) const union nf_inet_addr *daddr, __be16 dport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) const union nf_inet_addr *vaddr, __be16 vport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) __u16 protocol, __u32 fwmark, __u32 flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) void ip_vs_try_bind_dest(struct ip_vs_conn *cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) static inline void ip_vs_dest_hold(struct ip_vs_dest *dest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) refcount_inc(&dest->refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) static inline void ip_vs_dest_put(struct ip_vs_dest *dest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) smp_mb__before_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) refcount_dec(&dest->refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) if (refcount_dec_and_test(&dest->refcnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) kfree(dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) /* IPVS sync daemon data and function prototypes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) * (from ip_vs_sync.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) int state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) int stop_sync_thread(struct netns_ipvs *ipvs, int state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) /* IPVS rate estimator prototypes (from ip_vs_est.c) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) void ip_vs_start_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) void ip_vs_stop_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) void ip_vs_zero_estimator(struct ip_vs_stats *stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) void ip_vs_read_estimator(struct ip_vs_kstats *dst, struct ip_vs_stats *stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) /* Various IPVS packet transmitters (from ip_vs_xmit.c) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) int ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) int ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) int ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) int ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) struct ip_vs_protocol *pp, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) unsigned int hooknum, struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) void ip_vs_dest_dst_rcu_free(struct rcu_head *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) #ifdef CONFIG_IP_VS_IPV6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) int ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) int ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) int ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) int ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) struct ip_vs_protocol *pp, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) unsigned int hooknum, struct ip_vs_iphdr *iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) /* This is a simple mechanism to ignore packets when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) * we are loaded. Just set ip_vs_drop_rate to 'n' and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) * we start to drop 1/rate of the packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) static inline int ip_vs_todrop(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) if (!ipvs->drop_rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) if (--ipvs->drop_counter > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) ipvs->drop_counter = ipvs->drop_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) static inline int ip_vs_todrop(struct netns_ipvs *ipvs) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) /* Enqueue delayed work for expiring no dest connections
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) * Only run when sysctl_expire_nodest=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) static inline void ip_vs_enqueue_expire_nodest_conns(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) if (sysctl_expire_nodest_conn(ipvs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) queue_delayed_work(system_long_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) &ipvs->expire_nodest_conn_work, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) void ip_vs_expire_nodest_conn_flush(struct netns_ipvs *ipvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) static inline void ip_vs_enqueue_expire_nodest_conns(struct netns_ipvs *ipvs) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) #define IP_VS_DFWD_METHOD(dest) (atomic_read(&(dest)->conn_flags) & \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) IP_VS_CONN_F_FWD_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) /* ip_vs_fwd_tag returns the forwarding tag of the connection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) char fwd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) switch (IP_VS_FWD_METHOD(cp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) case IP_VS_CONN_F_MASQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) fwd = 'M'; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) case IP_VS_CONN_F_LOCALNODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) fwd = 'L'; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) case IP_VS_CONN_F_TUNNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) fwd = 'T'; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) case IP_VS_CONN_F_DROUTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) fwd = 'R'; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) case IP_VS_CONN_F_BYPASS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) fwd = 'B'; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) fwd = '?'; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) return fwd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) struct ip_vs_conn *cp, int dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) #ifdef CONFIG_IP_VS_IPV6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) struct ip_vs_conn *cp, int dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) __be32 diff[2] = { ~old, new };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) return csum_partial(diff, sizeof(diff), oldsum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) #ifdef CONFIG_IP_VS_IPV6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) __wsum oldsum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) new[3], new[2], new[1], new[0] };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) return csum_partial(diff, sizeof(diff), oldsum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) __be16 diff[2] = { ~old, new };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) return csum_partial(diff, sizeof(diff), oldsum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) /* Forget current conntrack (unconfirmed) and attach notrack entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) static inline void ip_vs_notrack(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) enum ip_conntrack_info ctinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) if (ct) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) nf_conntrack_put(&ct->ct_general);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) #ifdef CONFIG_IP_VS_NFCT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) /* Netfilter connection tracking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) * (from ip_vs_nfct.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) #ifdef CONFIG_SYSCTL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) return ipvs->sysctl_conntrack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) int outin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) int ip_vs_confirm_conntrack(struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) struct ip_vs_conn *cp, u_int8_t proto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) const __be16 port, int from_rs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) static inline void ip_vs_update_conntrack(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) struct ip_vs_conn *cp, int outin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) static inline int ip_vs_confirm_conntrack(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) return NF_ACCEPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) #endif /* CONFIG_IP_VS_NFCT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) /* Using old conntrack that can not be redirected to another real server? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) static inline bool ip_vs_conn_uses_old_conntrack(struct ip_vs_conn *cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) #ifdef CONFIG_IP_VS_NFCT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) enum ip_conntrack_info ctinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) struct nf_conn *ct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) ct = nf_ct_get(skb, &ctinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) if (ct && nf_ct_is_confirmed(ct))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) static inline int ip_vs_register_conntrack(struct ip_vs_service *svc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) #if IS_ENABLED(CONFIG_NF_CONNTRACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) int afmask = (svc->af == AF_INET6) ? 2 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) if (!(svc->conntrack_afmask & afmask)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) ret = nf_ct_netns_get(svc->ipvs->net, svc->af);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) if (ret >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) svc->conntrack_afmask |= afmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) static inline void ip_vs_unregister_conntrack(struct ip_vs_service *svc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) #if IS_ENABLED(CONFIG_NF_CONNTRACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) int afmask = (svc->af == AF_INET6) ? 2 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) if (svc->conntrack_afmask & afmask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) nf_ct_netns_put(svc->ipvs->net, svc->af);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) svc->conntrack_afmask &= ~afmask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) int ip_vs_register_hooks(struct netns_ipvs *ipvs, unsigned int af);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) void ip_vs_unregister_hooks(struct netns_ipvs *ipvs, unsigned int af);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) ip_vs_dest_conn_overhead(struct ip_vs_dest *dest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) /* We think the overhead of processing active connections is 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) * times higher than that of inactive connections in average. (This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) * 256 times might not be accurate, we will change it later) We
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) * use the following formula to estimate the overhead now:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) * dest->activeconns*256 + dest->inactconns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) return (atomic_read(&dest->activeconns) << 8) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) atomic_read(&dest->inactconns);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) #endif /* _NET_IP_VS_H */