| 1 |
|
| 2 | |
| 3 | * data structure and functionality definitions
|
| 4 |
|
| 5 |
|
| 6 | #ifndef _NET_IP_VS_H
|
| 7 | #define _NET_IP_VS_H
|
| 8 |
|
| 9 | #include <linux/ip_vs.h>
|
| 10 |
|
| 11 | #include <asm/types.h>
|
| 12 |
|
| 13 | #include <linux/list.h>
|
| 14 | #include <linux/rculist_bl.h>
|
| 15 | #include <linux/spinlock.h>
|
| 16 | #include <linux/atomic.h>
|
| 17 | #include <linux/refcount.h>
|
| 18 | #include <linux/workqueue.h>
|
| 19 |
|
| 20 | #include <linux/compiler.h>
|
| 21 | #include <linux/timer.h>
|
| 22 | #include <linux/bug.h>
|
| 23 |
|
| 24 | #include <net/checksum.h>
|
| 25 | #include <linux/netfilter.h>
|
| 26 | #include <linux/ip.h>
|
| 27 | #include <linux/ipv6.h>
|
| 28 | #include <net/ipv6.h>
|
| 29 | #if IS_ENABLED(CONFIG_NF_CONNTRACK)
|
| 30 | #include <net/netfilter/nf_conntrack.h>
|
| 31 | #endif
|
| 32 | #include <net/net_namespace.h>
|
| 33 | #include <linux/sched/isolation.h>
|
| 34 | #include <linux/siphash.h>
|
| 35 |
|
| 36 | #define IP_VS_HDR_INVERSE 1
|
| 37 | #define IP_VS_HDR_ICMP 2
|
| 38 |
|
| 39 |
|
| 40 | #define IP_VS_DEST_F_OVERLOAD 0x0002
|
| 41 |
|
| 42 |
|
| 43 | #define IP_VS_DEST_CF_AVAILABLE 0x0001
|
| 44 |
|
| 45 |
|
| 46 | #define IP_VS_CONN_TAB_MIN_BITS 8
|
| 47 | #if BITS_PER_LONG > 32
|
| 48 | #define IP_VS_CONN_TAB_MAX_BITS 27
|
| 49 | #else
|
| 50 | #define IP_VS_CONN_TAB_MAX_BITS 20
|
| 51 | #endif
|
| 52 |
|
| 53 |
|
| 54 | #if BITS_PER_LONG > 32
|
| 55 |
|
| 56 | #define IP_VS_CONN_MAX (1 << 30)
|
| 57 | #else
|
| 58 | #define IP_VS_CONN_MAX (1 << 24)
|
| 59 | #endif
|
| 60 |
|
| 61 |
|
| 62 | #define IP_VS_SVC_TAB_MIN_BITS 4
|
| 63 | #define IP_VS_SVC_TAB_MAX_BITS 20
|
| 64 |
|
| 65 |
|
| 66 | static inline struct netns_ipvs *net_ipvs(struct net* net)
|
| 67 | {
|
| 68 | return net->ipvs;
|
| 69 | }
|
| 70 |
|
| 71 |
|
| 72 | extern int ip_vs_conn_tab_size;
|
| 73 |
|
| 74 | struct ip_vs_iphdr {
|
| 75 | int hdr_flags;
|
| 76 | __u32 off;
|
| 77 | __u32 len; |
| 78 | * IPv6 where L4 Transport Header starts
|
| 79 | __u16 fragoffs;
|
| 80 | __s16 protocol;
|
| 81 | __s32 flags;
|
| 82 | union nf_inet_addr saddr;
|
| 83 | union nf_inet_addr daddr;
|
| 84 | };
|
| 85 |
|
| 86 | static inline void *frag_safe_skb_hp(const struct sk_buff *skb, int offset,
|
| 87 | int len, void *buffer)
|
| 88 | {
|
| 89 | return skb_header_pointer(skb, offset, len, buffer);
|
| 90 | }
|
| 91 |
|
| 92 | |
| 93 | * IPv6 requires some extra work, as finding proper header position,
|
| 94 | * depend on the IPv6 extension headers.
|
| 95 |
|
| 96 | static inline int
|
| 97 | ip_vs_fill_iph_skb_off(int af, const struct sk_buff *skb, int offset,
|
| 98 | int hdr_flags, struct ip_vs_iphdr *iphdr)
|
| 99 | {
|
| 100 | iphdr->hdr_flags = hdr_flags;
|
| 101 | iphdr->off = offset;
|
| 102 |
|
| 103 | #ifdef CONFIG_IP_VS_IPV6
|
| 104 | if (af == AF_INET6) {
|
| 105 | struct ipv6hdr _iph;
|
| 106 | const struct ipv6hdr *iph = skb_header_pointer(
|
| 107 | skb, offset, sizeof(_iph), &_iph);
|
| 108 | if (!iph)
|
| 109 | return 0;
|
| 110 |
|
| 111 | iphdr->saddr.in6 = iph->saddr;
|
| 112 | iphdr->daddr.in6 = iph->daddr;
|
| 113 |
|
| 114 | iphdr->len = offset;
|
| 115 | iphdr->flags = 0;
|
| 116 | iphdr->protocol = ipv6_find_hdr(skb, &iphdr->len, -1,
|
| 117 | &iphdr->fragoffs,
|
| 118 | &iphdr->flags);
|
| 119 | if (iphdr->protocol < 0)
|
| 120 | return 0;
|
| 121 | } else
|
| 122 | #endif
|
| 123 | {
|
| 124 | struct iphdr _iph;
|
| 125 | const struct iphdr *iph = skb_header_pointer(
|
| 126 | skb, offset, sizeof(_iph), &_iph);
|
| 127 | if (!iph)
|
| 128 | return 0;
|
| 129 |
|
| 130 | iphdr->len = offset + iph->ihl * 4;
|
| 131 | iphdr->fragoffs = 0;
|
| 132 | iphdr->protocol = iph->protocol;
|
| 133 | iphdr->saddr.ip = iph->saddr;
|
| 134 | iphdr->daddr.ip = iph->daddr;
|
| 135 | }
|
| 136 |
|
| 137 | return 1;
|
| 138 | }
|
| 139 |
|
| 140 | static inline int
|
| 141 | ip_vs_fill_iph_skb_icmp(int af, const struct sk_buff *skb, int offset,
|
| 142 | bool inverse, struct ip_vs_iphdr *iphdr)
|
| 143 | {
|
| 144 | int hdr_flags = IP_VS_HDR_ICMP;
|
| 145 |
|
| 146 | if (inverse)
|
| 147 | hdr_flags |= IP_VS_HDR_INVERSE;
|
| 148 |
|
| 149 | return ip_vs_fill_iph_skb_off(af, skb, offset, hdr_flags, iphdr);
|
| 150 | }
|
| 151 |
|
| 152 | static inline int
|
| 153 | ip_vs_fill_iph_skb(int af, const struct sk_buff *skb, bool inverse,
|
| 154 | struct ip_vs_iphdr *iphdr)
|
| 155 | {
|
| 156 | int hdr_flags = 0;
|
| 157 |
|
| 158 | if (inverse)
|
| 159 | hdr_flags |= IP_VS_HDR_INVERSE;
|
| 160 |
|
| 161 | return ip_vs_fill_iph_skb_off(af, skb, skb_network_offset(skb),
|
| 162 | hdr_flags, iphdr);
|
| 163 | }
|
| 164 |
|
| 165 | static inline bool
|
| 166 | ip_vs_iph_inverse(const struct ip_vs_iphdr *iph)
|
| 167 | {
|
| 168 | return !!(iph->hdr_flags & IP_VS_HDR_INVERSE);
|
| 169 | }
|
| 170 |
|
| 171 | static inline bool
|
| 172 | ip_vs_iph_icmp(const struct ip_vs_iphdr *iph)
|
| 173 | {
|
| 174 | return !!(iph->hdr_flags & IP_VS_HDR_ICMP);
|
| 175 | }
|
| 176 |
|
| 177 | static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
|
| 178 | const union nf_inet_addr *src)
|
| 179 | {
|
| 180 | #ifdef CONFIG_IP_VS_IPV6
|
| 181 | if (af == AF_INET6)
|
| 182 | dst->in6 = src->in6;
|
| 183 | else
|
| 184 | #endif
|
| 185 | dst->ip = src->ip;
|
| 186 | }
|
| 187 |
|
| 188 | static inline void ip_vs_addr_set(int af, union nf_inet_addr *dst,
|
| 189 | const union nf_inet_addr *src)
|
| 190 | {
|
| 191 | #ifdef CONFIG_IP_VS_IPV6
|
| 192 | if (af == AF_INET6) {
|
| 193 | dst->in6 = src->in6;
|
| 194 | return;
|
| 195 | }
|
| 196 | #endif
|
| 197 | dst->ip = src->ip;
|
| 198 | dst->all[1] = 0;
|
| 199 | dst->all[2] = 0;
|
| 200 | dst->all[3] = 0;
|
| 201 | }
|
| 202 |
|
| 203 | static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
|
| 204 | const union nf_inet_addr *b)
|
| 205 | {
|
| 206 | #ifdef CONFIG_IP_VS_IPV6
|
| 207 | if (af == AF_INET6)
|
| 208 | return ipv6_addr_equal(&a->in6, &b->in6);
|
| 209 | #endif
|
| 210 | return a->ip == b->ip;
|
| 211 | }
|
| 212 |
|
| 213 | #ifdef CONFIG_IP_VS_DEBUG
|
| 214 | #include <linux/net.h>
|
| 215 |
|
| 216 | int ip_vs_get_debug_level(void);
|
| 217 |
|
| 218 | static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
|
| 219 | const union nf_inet_addr *addr,
|
| 220 | int *idx)
|
| 221 | {
|
| 222 | int len;
|
| 223 | #ifdef CONFIG_IP_VS_IPV6
|
| 224 | if (af == AF_INET6)
|
| 225 | len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6c]",
|
| 226 | &addr->in6) + 1;
|
| 227 | else
|
| 228 | #endif
|
| 229 | len = snprintf(&buf[*idx], buf_len - *idx, "%pI4",
|
| 230 | &addr->ip) + 1;
|
| 231 |
|
| 232 | *idx += len;
|
| 233 | BUG_ON(*idx > buf_len + 1);
|
| 234 | return &buf[*idx - len];
|
| 235 | }
|
| 236 |
|
| 237 | #define IP_VS_DBG_BUF(level, msg, ...) \
|
| 238 | do { \
|
| 239 | char ip_vs_dbg_buf[160]; \
|
| 240 | int ip_vs_dbg_idx = 0; \
|
| 241 | if (level <= ip_vs_get_debug_level()) \
|
| 242 | printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
|
| 243 | } while (0)
|
| 244 | #define IP_VS_ERR_BUF(msg...) \
|
| 245 | do { \
|
| 246 | char ip_vs_dbg_buf[160]; \
|
| 247 | int ip_vs_dbg_idx = 0; \
|
| 248 | pr_err(msg); \
|
| 249 | } while (0)
|
| 250 |
|
| 251 |
|
| 252 | #define IP_VS_DBG_ADDR(af, addr) \
|
| 253 | ip_vs_dbg_addr(af, ip_vs_dbg_buf, \
|
| 254 | sizeof(ip_vs_dbg_buf), addr, \
|
| 255 | &ip_vs_dbg_idx)
|
| 256 |
|
| 257 | #define IP_VS_DBG(level, msg, ...) \
|
| 258 | do { \
|
| 259 | if (level <= ip_vs_get_debug_level()) \
|
| 260 | printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
|
| 261 | } while (0)
|
| 262 | #define IP_VS_DBG_RL(msg, ...) \
|
| 263 | do { \
|
| 264 | if (net_ratelimit()) \
|
| 265 | printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
|
| 266 | } while (0)
|
| 267 | #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) \
|
| 268 | do { \
|
| 269 | if (level <= ip_vs_get_debug_level()) \
|
| 270 | pp->debug_packet(af, pp, skb, ofs, msg); \
|
| 271 | } while (0)
|
| 272 | #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) \
|
| 273 | do { \
|
| 274 | if (level <= ip_vs_get_debug_level() && \
|
| 275 | net_ratelimit()) \
|
| 276 | pp->debug_packet(af, pp, skb, ofs, msg); \
|
| 277 | } while (0)
|
| 278 | #else
|
| 279 | #define IP_VS_DBG_BUF(level, msg...) do {} while (0)
|
| 280 | #define IP_VS_ERR_BUF(msg...) do {} while (0)
|
| 281 | #define IP_VS_DBG(level, msg...) do {} while (0)
|
| 282 | #define IP_VS_DBG_RL(msg...) do {} while (0)
|
| 283 | #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
|
| 284 | #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
|
| 285 | #endif
|
| 286 |
|
| 287 | #define IP_VS_BUG() BUG()
|
| 288 | #define IP_VS_ERR_RL(msg, ...) \
|
| 289 | do { \
|
| 290 | if (net_ratelimit()) \
|
| 291 | pr_err(msg, ##__VA_ARGS__); \
|
| 292 | } while (0)
|
| 293 |
|
| 294 | struct ip_vs_aligned_lock {
|
| 295 | spinlock_t l;
|
| 296 | } ____cacheline_aligned_in_smp;
|
| 297 |
|
| 298 |
|
| 299 | enum {
|
| 300 | IP_VS_AF_INET,
|
| 301 | IP_VS_AF_INET6,
|
| 302 | IP_VS_AF_MAX
|
| 303 | };
|
| 304 |
|
| 305 | static inline int ip_vs_af_index(int af)
|
| 306 | {
|
| 307 | return af == AF_INET6 ? IP_VS_AF_INET6 : IP_VS_AF_INET;
|
| 308 | }
|
| 309 |
|
| 310 |
|
| 311 | enum {
|
| 312 | IP_VS_WORK_SVC_RESIZE,
|
| 313 | IP_VS_WORK_SVC_NORESIZE,
|
| 314 | IP_VS_WORK_CONN_RESIZE,
|
| 315 | };
|
| 316 |
|
| 317 |
|
| 318 | #define FTPPORT cpu_to_be16(21)
|
| 319 | #define FTPDATA cpu_to_be16(20)
|
| 320 |
|
| 321 |
|
| 322 | enum {
|
| 323 | IP_VS_TCP_S_NONE = 0,
|
| 324 | IP_VS_TCP_S_ESTABLISHED,
|
| 325 | IP_VS_TCP_S_SYN_SENT,
|
| 326 | IP_VS_TCP_S_SYN_RECV,
|
| 327 | IP_VS_TCP_S_FIN_WAIT,
|
| 328 | IP_VS_TCP_S_TIME_WAIT,
|
| 329 | IP_VS_TCP_S_CLOSE,
|
| 330 | IP_VS_TCP_S_CLOSE_WAIT,
|
| 331 | IP_VS_TCP_S_LAST_ACK,
|
| 332 | IP_VS_TCP_S_LISTEN,
|
| 333 | IP_VS_TCP_S_SYNACK,
|
| 334 | IP_VS_TCP_S_LAST
|
| 335 | };
|
| 336 |
|
| 337 |
|
| 338 | enum {
|
| 339 | IP_VS_UDP_S_NORMAL,
|
| 340 | IP_VS_UDP_S_LAST,
|
| 341 | };
|
| 342 |
|
| 343 |
|
| 344 | enum {
|
| 345 | IP_VS_ICMP_S_NORMAL,
|
| 346 | IP_VS_ICMP_S_LAST,
|
| 347 | };
|
| 348 |
|
| 349 |
|
| 350 | enum ip_vs_sctp_states {
|
| 351 | IP_VS_SCTP_S_NONE,
|
| 352 | IP_VS_SCTP_S_INIT1,
|
| 353 | IP_VS_SCTP_S_INIT,
|
| 354 | IP_VS_SCTP_S_COOKIE_SENT,
|
| 355 | IP_VS_SCTP_S_COOKIE_REPLIED,
|
| 356 | IP_VS_SCTP_S_COOKIE_WAIT,
|
| 357 | IP_VS_SCTP_S_COOKIE,
|
| 358 | IP_VS_SCTP_S_COOKIE_ECHOED,
|
| 359 | IP_VS_SCTP_S_ESTABLISHED,
|
| 360 | IP_VS_SCTP_S_SHUTDOWN_SENT,
|
| 361 | IP_VS_SCTP_S_SHUTDOWN_RECEIVED,
|
| 362 | IP_VS_SCTP_S_SHUTDOWN_ACK_SENT,
|
| 363 | IP_VS_SCTP_S_REJECTED,
|
| 364 | IP_VS_SCTP_S_CLOSED,
|
| 365 | IP_VS_SCTP_S_LAST
|
| 366 | };
|
| 367 |
|
| 368 |
|
| 369 | #define IP_VS_CTPL_S_NONE 0x0000
|
| 370 | #define IP_VS_CTPL_S_ASSURED 0x0001
|
| 371 | #define IP_VS_CTPL_S_LAST 0x0002
|
| 372 |
|
| 373 | |
| 374 | * Each ip_vs_conn has 2 (output AND input seq. changes).
|
| 375 | * Only used in the VS/NAT.
|
| 376 |
|
| 377 | struct ip_vs_seq {
|
| 378 | __u32 init_seq;
|
| 379 | __u32 delta;
|
| 380 | __u32 previous_delta; |
| 381 | * before last resized pkt
|
| 382 | };
|
| 383 |
|
| 384 |
|
| 385 | struct ip_vs_counters {
|
| 386 | u64_stats_t conns;
|
| 387 | u64_stats_t inpkts;
|
| 388 | u64_stats_t outpkts;
|
| 389 | u64_stats_t inbytes;
|
| 390 | u64_stats_t outbytes;
|
| 391 | };
|
| 392 |
|
| 393 | struct ip_vs_cpu_stats {
|
| 394 | struct ip_vs_counters cnt;
|
| 395 | struct u64_stats_sync syncp;
|
| 396 | };
|
| 397 |
|
| 398 |
|
| 399 | #define IPVS_EST_NICE 0
|
| 400 |
|
| 401 |
|
| 402 | struct ip_vs_estimator {
|
| 403 | struct hlist_node list;
|
| 404 |
|
| 405 | u64 last_inbytes;
|
| 406 | u64 last_outbytes;
|
| 407 | u64 last_conns;
|
| 408 | u64 last_inpkts;
|
| 409 | u64 last_outpkts;
|
| 410 |
|
| 411 | u64 cps;
|
| 412 | u64 inpps;
|
| 413 | u64 outpps;
|
| 414 | u64 inbps;
|
| 415 | u64 outbps;
|
| 416 |
|
| 417 | s32 ktid:16,
|
| 418 | ktrow:8,
|
| 419 | ktcid:8;
|
| 420 | };
|
| 421 |
|
| 422 | |
| 423 | * IPVS statistics object, 64-bit kernel version of struct ip_vs_stats_user
|
| 424 |
|
| 425 | struct ip_vs_kstats {
|
| 426 | u64 conns;
|
| 427 | u64 inpkts;
|
| 428 | u64 outpkts;
|
| 429 | u64 inbytes;
|
| 430 | u64 outbytes;
|
| 431 |
|
| 432 | u64 cps;
|
| 433 | u64 inpps;
|
| 434 | u64 outpps;
|
| 435 | u64 inbps;
|
| 436 | u64 outbps;
|
| 437 | };
|
| 438 |
|
| 439 | struct ip_vs_stats {
|
| 440 | struct ip_vs_kstats kstats;
|
| 441 | struct ip_vs_estimator est;
|
| 442 | struct ip_vs_cpu_stats __percpu *cpustats;
|
| 443 | spinlock_t lock;
|
| 444 | struct ip_vs_kstats kstats0;
|
| 445 | };
|
| 446 |
|
| 447 | struct ip_vs_stats_rcu {
|
| 448 | struct ip_vs_stats s;
|
| 449 | struct rcu_head rcu_head;
|
| 450 | };
|
| 451 |
|
| 452 | int ip_vs_stats_init_alloc(struct ip_vs_stats *s);
|
| 453 | struct ip_vs_stats *ip_vs_stats_alloc(void);
|
| 454 | void ip_vs_stats_release(struct ip_vs_stats *stats);
|
| 455 | void ip_vs_stats_free(struct ip_vs_stats *stats);
|
| 456 |
|
| 457 |
|
| 458 | #define IPVS_EST_NTICKS 50
|
| 459 |
|
| 460 | #define IPVS_EST_TICK ((2 * HZ) / IPVS_EST_NTICKS)
|
| 461 |
|
| 462 | |
| 463 | * Value of 4 and above ensures kthreads will take work without exceeding
|
| 464 | * the CPU capacity under different circumstances.
|
| 465 |
|
| 466 | #define IPVS_EST_LOAD_DIVISOR 8
|
| 467 |
|
| 468 |
|
| 469 | #define IPVS_EST_CPU_KTHREADS (IPVS_EST_LOAD_DIVISOR / 2)
|
| 470 |
|
| 471 | |
| 472 | * 48=4.8ms of 40ms tick (12% CPU usage):
|
| 473 | * 2 sec * 1000 ms in sec * 10 (100us in ms) / 8 (12.5%) / 50
|
| 474 |
|
| 475 | #define IPVS_EST_CHAIN_FACTOR \
|
| 476 | ALIGN_DOWN(2 * 1000 * 10 / IPVS_EST_LOAD_DIVISOR / IPVS_EST_NTICKS, 8)
|
| 477 |
|
| 478 | |
| 479 | * The defines should match cond_resched_rcu
|
| 480 |
|
| 481 | #if defined(CONFIG_DEBUG_ATOMIC_SLEEP) || !defined(CONFIG_PREEMPT_RCU)
|
| 482 | #define IPVS_EST_TICK_CHAINS IPVS_EST_CHAIN_FACTOR
|
| 483 | #else
|
| 484 | #define IPVS_EST_TICK_CHAINS 1
|
| 485 | #endif
|
| 486 |
|
| 487 | #if IPVS_EST_NTICKS > 127
|
| 488 | #error Too many timer ticks for ktrow
|
| 489 | #endif
|
| 490 |
|
| 491 |
|
| 492 | struct ip_vs_est_tick_data {
|
| 493 | struct rcu_head rcu_head;
|
| 494 | struct hlist_head chains[IPVS_EST_TICK_CHAINS];
|
| 495 | DECLARE_BITMAP(present, IPVS_EST_TICK_CHAINS);
|
| 496 | DECLARE_BITMAP(full, IPVS_EST_TICK_CHAINS);
|
| 497 | int chain_len[IPVS_EST_TICK_CHAINS];
|
| 498 | };
|
| 499 |
|
| 500 |
|
| 501 | struct ip_vs_est_kt_data {
|
| 502 | struct netns_ipvs *ipvs;
|
| 503 | struct task_struct *task;
|
| 504 | struct ip_vs_est_tick_data __rcu *ticks[IPVS_EST_NTICKS];
|
| 505 | DECLARE_BITMAP(avail, IPVS_EST_NTICKS);
|
| 506 | unsigned long est_timer;
|
| 507 | struct ip_vs_stats *calc_stats;
|
| 508 | int needed;
|
| 509 | int tick_len[IPVS_EST_NTICKS];
|
| 510 | int id;
|
| 511 | int chain_max;
|
| 512 | int tick_max;
|
| 513 | int est_count;
|
| 514 | int est_max_count;
|
| 515 | int add_row;
|
| 516 | int est_row;
|
| 517 | };
|
| 518 |
|
| 519 |
|
| 520 | struct ip_vs_rht {
|
| 521 | struct hlist_bl_head *buckets;
|
| 522 | struct ip_vs_rht __rcu *new_tbl;
|
| 523 | seqcount_t *seqc;
|
| 524 | struct ip_vs_aligned_lock *lock;
|
| 525 | int mask;
|
| 526 | int size;
|
| 527 | int seqc_mask;
|
| 528 | int lock_mask;
|
| 529 | u32 table_id;
|
| 530 | int u_thresh;
|
| 531 | int l_thresh;
|
| 532 | int lfactor;
|
| 533 | int bits;
|
| 534 | siphash_key_t hash_key;
|
| 535 | struct rcu_head rcu_head;
|
| 536 | };
|
| 537 |
|
| 538 | |
| 539 | * ip_vs_rht_for_each_table() - Walk the hash tables
|
| 540 | * @table: struct ip_vs_rht __rcu *table
|
| 541 | * @t: current table, used as cursor, struct ip_vs_rht *var
|
| 542 | * @p: previous table, temp struct ip_vs_rht *var
|
| 543 | *
|
| 544 | * Walk tables assuming others can not change the installed tables
|
| 545 |
|
| 546 | #define ip_vs_rht_for_each_table(table, t, p) \
|
| 547 | for (p = NULL, t = rcu_dereference_protected(table, 1); \
|
| 548 | t != p; \
|
| 549 | p = t, t = rcu_dereference_protected(t->new_tbl, 1))
|
| 550 |
|
| 551 | |
| 552 | * ip_vs_rht_for_each_table_rcu() - Walk the hash tables under RCU reader lock
|
| 553 | * @table: struct ip_vs_rht __rcu *table
|
| 554 | * @t: current table, used as cursor, struct ip_vs_rht *var
|
| 555 | * @p: previous table, temp struct ip_vs_rht *var
|
| 556 | *
|
| 557 | * We usually search in one table and also in second table on resizing
|
| 558 |
|
| 559 | #define ip_vs_rht_for_each_table_rcu(table, t, p) \
|
| 560 | for (p = NULL, t = rcu_dereference(table); \
|
| 561 | t != p; \
|
| 562 | p = t, t = rcu_dereference(t->new_tbl))
|
| 563 |
|
| 564 | |
| 565 | * ip_vs_rht_for_each_bucket() - Walk all table buckets
|
| 566 | * @t: current table, used as cursor, struct ip_vs_rht *var
|
| 567 | * @bucket: bucket index, used as cursor, u32 var
|
| 568 | * @head: bucket address, used as cursor, struct hlist_bl_head *var
|
| 569 |
|
| 570 | #define ip_vs_rht_for_each_bucket(t, bucket, head) \
|
| 571 | for (bucket = 0, head = (t)->buckets; \
|
| 572 | bucket < t->size; bucket++, head++)
|
| 573 |
|
| 574 | |
| 575 | * ip_vs_rht_for_bucket_retry() - Retry bucket if entries are moved
|
| 576 | * @t: current table, used as cursor, struct ip_vs_rht *var
|
| 577 | * @bucket: index of current bucket or hash key
|
| 578 | * @sc: temp seqcount_t *var
|
| 579 | * @seq: temp unsigned int var for sequence count
|
| 580 | * @retry: temp int var
|
| 581 |
|
| 582 | #define ip_vs_rht_for_bucket_retry(t, bucket, sc, seq, retry) \
|
| 583 | for (retry = 1, sc = &(t)->seqc[(bucket) & (t)->seqc_mask]; \
|
| 584 | retry && ({ seq = read_seqcount_begin(sc); 1; }); \
|
| 585 | retry = read_seqcount_retry(sc, seq))
|
| 586 |
|
| 587 | |
| 588 | * DECLARE_IP_VS_RHT_WALK_BUCKETS_RCU() - Declare variables
|
| 589 | *
|
| 590 | * Variables for ip_vs_rht_walk_buckets_rcu
|
| 591 |
|
| 592 | #define DECLARE_IP_VS_RHT_WALK_BUCKETS_RCU() \
|
| 593 | struct ip_vs_rht *_t, *_p; \
|
| 594 | unsigned int _seq; \
|
| 595 | seqcount_t *_sc; \
|
| 596 | u32 _bucket; \
|
| 597 | int _retry
|
| 598 | |
| 599 | * ip_vs_rht_walk_buckets_rcu() - Walk all buckets under RCU read lock
|
| 600 | * @table: struct ip_vs_rht __rcu *table
|
| 601 | * @head: bucket address, used as cursor, struct hlist_bl_head *var
|
| 602 | *
|
| 603 | * Can be used while others add/delete/move entries
|
| 604 | * Not suitable if duplicates are not desired
|
| 605 | * Possible cases for reader that uses cond_resched_rcu() in the loop:
|
| 606 | * - new table can not be installed, no need to repeat
|
| 607 | * - new table can be installed => check and repeat if new table is
|
| 608 | * installed, needed for !PREEMPT_RCU
|
| 609 |
|
| 610 | #define ip_vs_rht_walk_buckets_rcu(table, head) \
|
| 611 | ip_vs_rht_for_each_table_rcu(table, _t, _p) \
|
| 612 | ip_vs_rht_for_each_bucket(_t, _bucket, head) \
|
| 613 | ip_vs_rht_for_bucket_retry(_t, _bucket, _sc, \
|
| 614 | _seq, _retry)
|
| 615 |
|
| 616 | |
| 617 | * DECLARE_IP_VS_RHT_WALK_BUCKET_RCU() - Declare variables
|
| 618 | *
|
| 619 | * Variables for ip_vs_rht_walk_bucket_rcu
|
| 620 |
|
| 621 | #define DECLARE_IP_VS_RHT_WALK_BUCKET_RCU() \
|
| 622 | unsigned int _seq; \
|
| 623 | seqcount_t *_sc; \
|
| 624 | int _retry
|
| 625 | |
| 626 | * ip_vs_rht_walk_bucket_rcu() - Walk bucket under RCU read lock
|
| 627 | * @t: current table, struct ip_vs_rht *var
|
| 628 | * @bucket: index of current bucket or hash key
|
| 629 | * @head: bucket address, used as cursor, struct hlist_bl_head *var
|
| 630 | *
|
| 631 | * Can be used while others add/delete/move entries
|
| 632 | * Not suitable if duplicates are not desired
|
| 633 | * Possible cases for reader that uses cond_resched_rcu() in the loop:
|
| 634 | * - new table can not be installed, no need to repeat
|
| 635 | * - new table can be installed => check and repeat if new table is
|
| 636 | * installed, needed for !PREEMPT_RCU
|
| 637 |
|
| 638 | #define ip_vs_rht_walk_bucket_rcu(t, bucket, head) \
|
| 639 | if (({ head = (t)->buckets + ((bucket) & (t)->mask); 0; })) \
|
| 640 | {} \
|
| 641 | else \
|
| 642 | ip_vs_rht_for_bucket_retry(t, (bucket), _sc, _seq, _retry)
|
| 643 |
|
| 644 | |
| 645 | * DECLARE_IP_VS_RHT_WALK_BUCKETS_SAFE_RCU() - Declare variables
|
| 646 | *
|
| 647 | * Variables for ip_vs_rht_walk_buckets_safe_rcu
|
| 648 |
|
| 649 | #define DECLARE_IP_VS_RHT_WALK_BUCKETS_SAFE_RCU() \
|
| 650 | struct ip_vs_rht *_t, *_p; \
|
| 651 | u32 _bucket
|
| 652 | |
| 653 | * ip_vs_rht_walk_buckets_safe_rcu() - Walk all buckets under RCU read lock
|
| 654 | * @table: struct ip_vs_rht __rcu *table
|
| 655 | * @head: bucket address, used as cursor, struct hlist_bl_head *var
|
| 656 | *
|
| 657 | * Can be used while others add/delete entries but moving is disabled
|
| 658 | * Using cond_resched_rcu() should be safe if tables do not change
|
| 659 |
|
| 660 | #define ip_vs_rht_walk_buckets_safe_rcu(table, head) \
|
| 661 | ip_vs_rht_for_each_table_rcu(table, _t, _p) \
|
| 662 | ip_vs_rht_for_each_bucket(_t, _bucket, head)
|
| 663 |
|
| 664 | |
| 665 | * DECLARE_IP_VS_RHT_WALK_BUCKETS() - Declare variables
|
| 666 | *
|
| 667 | * Variables for ip_vs_rht_walk_buckets
|
| 668 |
|
| 669 | #define DECLARE_IP_VS_RHT_WALK_BUCKETS() \
|
| 670 | struct ip_vs_rht *_t, *_p; \
|
| 671 | u32 _bucket
|
| 672 |
|
| 673 | |
| 674 | * ip_vs_rht_walk_buckets() - Walk all buckets
|
| 675 | * @table: struct ip_vs_rht __rcu *table
|
| 676 | * @head: bucket address, used as cursor, struct hlist_bl_head *var
|
| 677 | *
|
| 678 | * Use if others can not add/delete/move entries
|
| 679 |
|
| 680 | #define ip_vs_rht_walk_buckets(table, head) \
|
| 681 | ip_vs_rht_for_each_table(table, _t, _p) \
|
| 682 | ip_vs_rht_for_each_bucket(_t, _bucket, head)
|
| 683 |
|
| 684 | |
| 685 | * created and store it as highest bit in hash keys
|
| 686 |
|
| 687 | #define IP_VS_RHT_TABLE_ID_MASK BIT(31)
|
| 688 |
|
| 689 |
|
| 690 | static inline bool ip_vs_rht_same_table(struct ip_vs_rht *t, u32 hash_key)
|
| 691 | {
|
| 692 | return !((t->table_id ^ hash_key) & IP_VS_RHT_TABLE_ID_MASK);
|
| 693 | }
|
| 694 |
|
| 695 |
|
| 696 | static inline u32 ip_vs_rht_build_hash_key(struct ip_vs_rht *t, u32 hash)
|
| 697 | {
|
| 698 | return t->table_id | (hash & ~IP_VS_RHT_TABLE_ID_MASK);
|
| 699 | }
|
| 700 |
|
| 701 | void ip_vs_rht_free(struct ip_vs_rht *t);
|
| 702 | void ip_vs_rht_rcu_free(struct rcu_head *head);
|
| 703 | struct ip_vs_rht *ip_vs_rht_alloc(int buckets, int scounts, int locks);
|
| 704 | int ip_vs_rht_desired_size(struct netns_ipvs *ipvs, struct ip_vs_rht *t, int n,
|
| 705 | int lfactor, int min_bits, int max_bits);
|
| 706 | void ip_vs_rht_set_thresholds(struct ip_vs_rht *t, int size, int lfactor,
|
| 707 | int min_bits, int max_bits);
|
| 708 | u32 ip_vs_rht_hash_linfo(struct ip_vs_rht *t, int af,
|
| 709 | const union nf_inet_addr *addr, u32 v1, u32 v2);
|
| 710 |
|
| 711 | struct dst_entry;
|
| 712 | struct iphdr;
|
| 713 | struct ip_vs_conn;
|
| 714 | struct ip_vs_app;
|
| 715 | struct sk_buff;
|
| 716 | struct ip_vs_proto_data;
|
| 717 |
|
| 718 | struct ip_vs_protocol {
|
| 719 | struct ip_vs_protocol *next;
|
| 720 | char *name;
|
| 721 | u16 protocol;
|
| 722 | u16 num_states;
|
| 723 | int dont_defrag;
|
| 724 |
|
| 725 | void (*init)(struct ip_vs_protocol *pp);
|
| 726 |
|
| 727 | void (*exit)(struct ip_vs_protocol *pp);
|
| 728 |
|
| 729 | int (*init_netns)(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd);
|
| 730 |
|
| 731 | void (*exit_netns)(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd);
|
| 732 |
|
| 733 | int (*conn_schedule)(struct netns_ipvs *ipvs,
|
| 734 | int af, struct sk_buff *skb,
|
| 735 | struct ip_vs_proto_data *pd,
|
| 736 | int *verdict, struct ip_vs_conn **cpp,
|
| 737 | struct ip_vs_iphdr *iph);
|
| 738 |
|
| 739 | struct ip_vs_conn *
|
| 740 | (*conn_in_get)(struct netns_ipvs *ipvs,
|
| 741 | int af,
|
| 742 | const struct sk_buff *skb,
|
| 743 | const struct ip_vs_iphdr *iph);
|
| 744 |
|
| 745 | struct ip_vs_conn *
|
| 746 | (*conn_out_get)(struct netns_ipvs *ipvs,
|
| 747 | int af,
|
| 748 | const struct sk_buff *skb,
|
| 749 | const struct ip_vs_iphdr *iph);
|
| 750 |
|
| 751 | int (*snat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp,
|
| 752 | struct ip_vs_conn *cp, struct ip_vs_iphdr *iph);
|
| 753 |
|
| 754 | int (*dnat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp,
|
| 755 | struct ip_vs_conn *cp, struct ip_vs_iphdr *iph);
|
| 756 |
|
| 757 | const char *(*state_name)(int state);
|
| 758 |
|
| 759 | void (*state_transition)(struct ip_vs_conn *cp, int direction,
|
| 760 | const struct sk_buff *skb,
|
| 761 | struct ip_vs_proto_data *pd,
|
| 762 | unsigned int iph_len);
|
| 763 |
|
| 764 | int (*register_app)(struct netns_ipvs *ipvs, struct ip_vs_app *inc);
|
| 765 |
|
| 766 | void (*unregister_app)(struct netns_ipvs *ipvs, struct ip_vs_app *inc);
|
| 767 |
|
| 768 | int (*app_conn_bind)(struct ip_vs_conn *cp);
|
| 769 |
|
| 770 | void (*debug_packet)(int af, struct ip_vs_protocol *pp,
|
| 771 | const struct sk_buff *skb,
|
| 772 | int offset,
|
| 773 | const char *msg);
|
| 774 |
|
| 775 | void (*timeout_change)(struct ip_vs_proto_data *pd, int flags);
|
| 776 | };
|
| 777 |
|
| 778 |
|
| 779 | struct ip_vs_proto_data {
|
| 780 | struct ip_vs_proto_data *next;
|
| 781 | struct ip_vs_protocol *pp;
|
| 782 | int *timeout_table;
|
| 783 | atomic_t appcnt;
|
| 784 | struct tcp_states_t *tcp_state_table;
|
| 785 | };
|
| 786 |
|
| 787 | struct ip_vs_protocol *ip_vs_proto_get(unsigned short proto);
|
| 788 | struct ip_vs_proto_data *ip_vs_proto_data_get(struct netns_ipvs *ipvs,
|
| 789 | unsigned short proto);
|
| 790 |
|
| 791 | struct ip_vs_conn_param {
|
| 792 | struct netns_ipvs *ipvs;
|
| 793 | const union nf_inet_addr *caddr;
|
| 794 | const union nf_inet_addr *vaddr;
|
| 795 | __be16 cport;
|
| 796 | __be16 vport;
|
| 797 | __u16 protocol;
|
| 798 | u16 af;
|
| 799 |
|
| 800 | const struct ip_vs_pe *pe;
|
| 801 | char *pe_data;
|
| 802 | __u8 pe_data_len;
|
| 803 | };
|
| 804 |
|
| 805 |
|
| 806 | struct ip_vs_conn_hnode {
|
| 807 | struct hlist_bl_node node;
|
| 808 | u32 hash_key;
|
| 809 | u8 dir;
|
| 810 | } __packed;
|
| 811 |
|
| 812 |
|
| 813 | struct ip_vs_conn {
|
| 814 |
|
| 815 |
|
| 816 | struct ip_vs_conn_hnode hn0;
|
| 817 | u8 af;
|
| 818 | __be16 cport;
|
| 819 | struct ip_vs_conn_hnode hn1;
|
| 820 | u8 daf;
|
| 821 | __be16 dport;
|
| 822 | struct ip_vs_dest *dest;
|
| 823 | atomic_t n_control;
|
| 824 | volatile __u32 flags;
|
| 825 |
|
| 826 |
|
| 827 | struct ip_vs_conn *control;
|
| 828 | const struct ip_vs_pe *pe;
|
| 829 | char *pe_data;
|
| 830 | __u8 pe_data_len;
|
| 831 | volatile __u16 state;
|
| 832 | volatile __u16 old_state; |
| 833 | * state transition triggered
|
| 834 | * synchronization
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 | union nf_inet_addr caddr;
|
| 840 | union nf_inet_addr vaddr;
|
| 841 |
|
| 842 |
|
| 843 | union nf_inet_addr daddr;
|
| 844 | __u32 fwmark;
|
| 845 | __be16 vport;
|
| 846 | __u16 protocol;
|
| 847 |
|
| 848 | |
| 849 | * in order to save more space, and the following members are
|
| 850 | * only used in VS/NAT anyway
|
| 851 |
|
| 852 | struct ip_vs_app *app;
|
| 853 | void *app_data;
|
| 854 |
|
| 855 | struct_group(sync_conn_opt,
|
| 856 | struct ip_vs_seq in_seq;
|
| 857 | struct ip_vs_seq out_seq;
|
| 858 | );
|
| 859 |
|
| 860 |
|
| 861 | struct timer_list timer;
|
| 862 | volatile unsigned long timeout;
|
| 863 | spinlock_t lock;
|
| 864 | refcount_t refcnt;
|
| 865 | atomic_t in_pkts;
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 | unsigned long sync_endtime;
|
| 870 | struct netns_ipvs *ipvs;
|
| 871 |
|
| 872 | |
| 873 | * mangles the packet, it must return NF_DROP or better NF_STOLEN,
|
| 874 | * otherwise this must be changed to a sk_buff **.
|
| 875 | * NF_ACCEPT can be returned when destination is local.
|
| 876 |
|
| 877 | int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
|
| 878 | struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
|
| 879 |
|
| 880 | struct rcu_head rcu_head;
|
| 881 | };
|
| 882 |
|
| 883 | |
| 884 | * for IPv6 support.
|
| 885 | *
|
| 886 | * We need these to conveniently pass around service and destination
|
| 887 | * options, but unfortunately, we also need to keep the old definitions to
|
| 888 | * maintain userspace backwards compatibility for the setsockopt interface.
|
| 889 |
|
| 890 | struct ip_vs_service_user_kern {
|
| 891 |
|
| 892 | u16 af;
|
| 893 | u16 protocol;
|
| 894 | union nf_inet_addr addr;
|
| 895 | __be16 port;
|
| 896 | u32 fwmark;
|
| 897 |
|
| 898 |
|
| 899 | char *sched_name;
|
| 900 | char *pe_name;
|
| 901 | unsigned int flags;
|
| 902 | unsigned int timeout;
|
| 903 | __be32 netmask;
|
| 904 | };
|
| 905 |
|
| 906 |
|
| 907 | struct ip_vs_dest_user_kern {
|
| 908 |
|
| 909 | union nf_inet_addr addr;
|
| 910 | __be16 port;
|
| 911 |
|
| 912 |
|
| 913 | unsigned int conn_flags;
|
| 914 | int weight;
|
| 915 |
|
| 916 |
|
| 917 | u32 u_threshold;
|
| 918 | u32 l_threshold;
|
| 919 |
|
| 920 |
|
| 921 | u16 af;
|
| 922 |
|
| 923 | u16 tun_type;
|
| 924 | __be16 tun_port;
|
| 925 | u16 tun_flags;
|
| 926 | };
|
| 927 |
|
| 928 |
|
| 929 | |
| 930 | * The information about the virtual service offered to the net and the
|
| 931 | * forwarding entries.
|
| 932 |
|
| 933 | struct ip_vs_service {
|
| 934 | struct hlist_bl_node s_list;
|
| 935 | u32 hash_key;
|
| 936 | u16 af;
|
| 937 | __u16 protocol;
|
| 938 |
|
| 939 | union nf_inet_addr addr;
|
| 940 | __u32 fwmark;
|
| 941 | atomic_t refcnt;
|
| 942 | __be16 port;
|
| 943 | unsigned int flags;
|
| 944 | unsigned int timeout;
|
| 945 | __be32 netmask;
|
| 946 | struct netns_ipvs *ipvs;
|
| 947 |
|
| 948 | struct list_head destinations;
|
| 949 | __u32 num_dests;
|
| 950 | struct ip_vs_stats stats;
|
| 951 |
|
| 952 |
|
| 953 | struct ip_vs_scheduler __rcu *scheduler;
|
| 954 | spinlock_t sched_lock;
|
| 955 | void *sched_data;
|
| 956 |
|
| 957 |
|
| 958 | struct ip_vs_pe __rcu *pe;
|
| 959 | int conntrack_afmask;
|
| 960 |
|
| 961 | struct rcu_head rcu_head;
|
| 962 | };
|
| 963 |
|
| 964 |
|
| 965 | struct ip_vs_dest_dst {
|
| 966 | struct dst_entry *dst_cache;
|
| 967 | u32 dst_cookie;
|
| 968 | union nf_inet_addr dst_saddr;
|
| 969 | struct rcu_head rcu_head;
|
| 970 | };
|
| 971 |
|
| 972 | |
| 973 | * and so on.
|
| 974 |
|
| 975 | struct ip_vs_dest {
|
| 976 | struct list_head n_list;
|
| 977 | struct hlist_node d_list;
|
| 978 |
|
| 979 | u16 af;
|
| 980 | __be16 port;
|
| 981 | union nf_inet_addr addr;
|
| 982 | volatile unsigned int flags;
|
| 983 | atomic_t conn_flags;
|
| 984 | atomic_t weight;
|
| 985 | unsigned long cflags;
|
| 986 | atomic_t last_weight;
|
| 987 | __u16 tun_type;
|
| 988 | __be16 tun_port;
|
| 989 | __u16 tun_flags;
|
| 990 |
|
| 991 | refcount_t refcnt;
|
| 992 | struct ip_vs_stats stats;
|
| 993 | unsigned long idle_start;
|
| 994 |
|
| 995 |
|
| 996 | atomic_t activeconns;
|
| 997 | atomic_t totalconns;
|
| 998 | atomic_t persistconns;
|
| 999 | __u32 u_threshold;
|
| 1000 | __u32 l_threshold;
|
| 1001 | __u32 l_threshold_val;
|
| 1002 |
|
| 1003 |
|
| 1004 | spinlock_t dst_lock;
|
| 1005 | struct ip_vs_dest_dst __rcu *dest_dst;
|
| 1006 |
|
| 1007 |
|
| 1008 | struct ip_vs_service __rcu *svc;
|
| 1009 | __u16 protocol;
|
| 1010 | __be16 vport;
|
| 1011 | union nf_inet_addr vaddr;
|
| 1012 | __u32 vfwmark;
|
| 1013 |
|
| 1014 | struct rcu_head rcu_head;
|
| 1015 | struct list_head t_list;
|
| 1016 | unsigned int in_rs_table:1;
|
| 1017 | };
|
| 1018 |
|
| 1019 |
|
| 1020 | struct ip_vs_scheduler {
|
| 1021 | struct list_head n_list;
|
| 1022 | char *name;
|
| 1023 | atomic_t refcnt;
|
| 1024 | struct module *module;
|
| 1025 |
|
| 1026 |
|
| 1027 | int (*init_service)(struct ip_vs_service *svc);
|
| 1028 |
|
| 1029 | void (*done_service)(struct ip_vs_service *svc);
|
| 1030 |
|
| 1031 | int (*add_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
|
| 1032 |
|
| 1033 | int (*del_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
|
| 1034 |
|
| 1035 | int (*upd_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
|
| 1036 |
|
| 1037 |
|
| 1038 | struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
|
| 1039 | const struct sk_buff *skb,
|
| 1040 | struct ip_vs_iphdr *iph);
|
| 1041 | };
|
| 1042 |
|
| 1043 |
|
| 1044 | struct ip_vs_pe {
|
| 1045 | struct list_head n_list;
|
| 1046 | char *name;
|
| 1047 | atomic_t refcnt;
|
| 1048 | struct module *module;
|
| 1049 |
|
| 1050 |
|
| 1051 | int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb);
|
| 1052 | bool (*ct_match)(const struct ip_vs_conn_param *p,
|
| 1053 | struct ip_vs_conn *ct);
|
| 1054 | u32 (*hashkey_raw)(const struct ip_vs_conn_param *p,
|
| 1055 | struct ip_vs_rht *t, bool inverse);
|
| 1056 | int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf);
|
| 1057 |
|
| 1058 | struct ip_vs_conn* (*conn_out)(struct ip_vs_service *svc,
|
| 1059 | struct ip_vs_dest *dest,
|
| 1060 | struct sk_buff *skb,
|
| 1061 | const struct ip_vs_iphdr *iph,
|
| 1062 | __be16 dport, __be16 cport);
|
| 1063 | };
|
| 1064 |
|
| 1065 |
|
| 1066 | struct ip_vs_app {
|
| 1067 | struct list_head a_list;
|
| 1068 | int type;
|
| 1069 | char *name;
|
| 1070 | __u16 protocol;
|
| 1071 | struct module *module;
|
| 1072 | struct list_head incs_list;
|
| 1073 |
|
| 1074 |
|
| 1075 | struct list_head p_list;
|
| 1076 | struct ip_vs_app *app;
|
| 1077 | __be16 port;
|
| 1078 | atomic_t usecnt;
|
| 1079 | struct rcu_head rcu_head;
|
| 1080 |
|
| 1081 | |
| 1082 | * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
|
| 1083 | * 2=Mangled but checksum was not updated
|
| 1084 |
|
| 1085 | int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
|
| 1086 | struct sk_buff *, int *diff, struct ip_vs_iphdr *ipvsh);
|
| 1087 |
|
| 1088 | |
| 1089 | * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
|
| 1090 | * 2=Mangled but checksum was not updated
|
| 1091 |
|
| 1092 | int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
|
| 1093 | struct sk_buff *, int *diff, struct ip_vs_iphdr *ipvsh);
|
| 1094 |
|
| 1095 |
|
| 1096 | int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
|
| 1097 |
|
| 1098 |
|
| 1099 | int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 | int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
|
| 1104 | struct ip_vs_protocol *);
|
| 1105 |
|
| 1106 | void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
|
| 1107 |
|
| 1108 | int * timeout_table;
|
| 1109 | int * timeouts;
|
| 1110 | int timeouts_size;
|
| 1111 |
|
| 1112 | int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
|
| 1113 | int *verdict, struct ip_vs_conn **cpp);
|
| 1114 |
|
| 1115 | struct ip_vs_conn *
|
| 1116 | (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
|
| 1117 | const struct iphdr *iph, int inverse);
|
| 1118 |
|
| 1119 | struct ip_vs_conn *
|
| 1120 | (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
|
| 1121 | const struct iphdr *iph, int inverse);
|
| 1122 |
|
| 1123 | int (*state_transition)(struct ip_vs_conn *cp, int direction,
|
| 1124 | const struct sk_buff *skb,
|
| 1125 | struct ip_vs_app *app);
|
| 1126 |
|
| 1127 | void (*timeout_change)(struct ip_vs_app *app, int flags);
|
| 1128 | };
|
| 1129 |
|
| 1130 | struct ipvs_master_sync_state {
|
| 1131 | struct list_head sync_queue;
|
| 1132 | struct ip_vs_sync_buff *sync_buff;
|
| 1133 | unsigned long sync_queue_len;
|
| 1134 | unsigned int sync_queue_delay;
|
| 1135 | struct delayed_work master_wakeup_work;
|
| 1136 | struct netns_ipvs *ipvs;
|
| 1137 | };
|
| 1138 |
|
| 1139 | struct ip_vs_sync_thread_data;
|
| 1140 |
|
| 1141 |
|
| 1142 | #define IP_VS_DEST_TRASH_PERIOD (120 * HZ)
|
| 1143 |
|
| 1144 | struct ipvs_sync_daemon_cfg {
|
| 1145 | union nf_inet_addr mcast_group;
|
| 1146 | int syncid;
|
| 1147 | u16 sync_maxlen;
|
| 1148 | u16 mcast_port;
|
| 1149 | u8 mcast_af;
|
| 1150 | u8 mcast_ttl;
|
| 1151 |
|
| 1152 | char mcast_ifn[IP_VS_IFNAME_MAXLEN];
|
| 1153 | };
|
| 1154 |
|
| 1155 |
|
| 1156 | struct netns_ipvs {
|
| 1157 | int gen;
|
| 1158 | int enable;
|
| 1159 |
|
| 1160 | #define IP_VS_RTAB_BITS 4
|
| 1161 | #define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS)
|
| 1162 | #define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1)
|
| 1163 |
|
| 1164 | struct hlist_head rs_table[IP_VS_RTAB_SIZE];
|
| 1165 |
|
| 1166 | struct list_head app_list;
|
| 1167 |
|
| 1168 | #define IP_VS_PROTO_TAB_SIZE 32
|
| 1169 | struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE];
|
| 1170 |
|
| 1171 | #ifdef CONFIG_IP_VS_PROTO_TCP
|
| 1172 | #define TCP_APP_TAB_BITS 4
|
| 1173 | #define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS)
|
| 1174 | #define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1)
|
| 1175 | struct list_head tcp_apps[TCP_APP_TAB_SIZE];
|
| 1176 | #endif
|
| 1177 |
|
| 1178 | #ifdef CONFIG_IP_VS_PROTO_UDP
|
| 1179 | #define UDP_APP_TAB_BITS 4
|
| 1180 | #define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS)
|
| 1181 | #define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1)
|
| 1182 | struct list_head udp_apps[UDP_APP_TAB_SIZE];
|
| 1183 | #endif
|
| 1184 |
|
| 1185 | #ifdef CONFIG_IP_VS_PROTO_SCTP
|
| 1186 | #define SCTP_APP_TAB_BITS 4
|
| 1187 | #define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS)
|
| 1188 | #define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1)
|
| 1189 |
|
| 1190 | struct list_head sctp_apps[SCTP_APP_TAB_SIZE];
|
| 1191 | #endif
|
| 1192 |
|
| 1193 | atomic_t conn_count;
|
| 1194 | atomic_t no_cport_conns[IP_VS_AF_MAX];
|
| 1195 | struct delayed_work conn_resize_work;
|
| 1196 |
|
| 1197 |
|
| 1198 | struct ip_vs_stats_rcu *tot_stats;
|
| 1199 |
|
| 1200 |
|
| 1201 | struct list_head dest_trash;
|
| 1202 | spinlock_t dest_trash_lock;
|
| 1203 | struct timer_list dest_trash_timer;
|
| 1204 | struct mutex service_mutex;
|
| 1205 | struct rw_semaphore svc_resize_sem;
|
| 1206 | struct rw_semaphore svc_replace_sem;
|
| 1207 | struct delayed_work svc_resize_work;
|
| 1208 | atomic_t svc_table_changes;
|
| 1209 |
|
| 1210 | atomic_t num_services[IP_VS_AF_MAX];
|
| 1211 | atomic_t fwm_services[IP_VS_AF_MAX];
|
| 1212 | atomic_t nonfwm_services[IP_VS_AF_MAX];
|
| 1213 | atomic_t ftpsvc_counter[IP_VS_AF_MAX];
|
| 1214 | atomic_t nullsvc_counter[IP_VS_AF_MAX];
|
| 1215 | atomic_t conn_out_counter[IP_VS_AF_MAX];
|
| 1216 |
|
| 1217 | #ifdef CONFIG_SYSCTL
|
| 1218 |
|
| 1219 | struct delayed_work expire_nodest_conn_work;
|
| 1220 |
|
| 1221 | struct delayed_work defense_work;
|
| 1222 | int drop_rate;
|
| 1223 | int drop_counter;
|
| 1224 | int old_secure_tcp;
|
| 1225 | atomic_t dropentry;
|
| 1226 | s8 dropentry_counters[8];
|
| 1227 |
|
| 1228 | spinlock_t dropentry_lock;
|
| 1229 | spinlock_t droppacket_lock;
|
| 1230 | spinlock_t securetcp_lock;
|
| 1231 |
|
| 1232 |
|
| 1233 | struct ctl_table_header *sysctl_hdr;
|
| 1234 | struct ctl_table *sysctl_tbl;
|
| 1235 | #endif
|
| 1236 |
|
| 1237 |
|
| 1238 | int sysctl_amemthresh;
|
| 1239 | int sysctl_am_droprate;
|
| 1240 | #ifdef CONFIG_SYSCTL
|
| 1241 | int sysctl_conn_max;
|
| 1242 | int conn_max_limit;
|
| 1243 | #endif
|
| 1244 | int sysctl_drop_entry;
|
| 1245 | int sysctl_drop_packet;
|
| 1246 | int sysctl_secure_tcp;
|
| 1247 | #ifdef CONFIG_IP_VS_NFCT
|
| 1248 | int sysctl_conntrack;
|
| 1249 | #endif
|
| 1250 | int sysctl_snat_reroute;
|
| 1251 | int sysctl_sync_ver;
|
| 1252 | int sysctl_sync_ports;
|
| 1253 | int sysctl_sync_persist_mode;
|
| 1254 | unsigned long sysctl_sync_qlen_max;
|
| 1255 | int sysctl_sync_sock_size;
|
| 1256 | int sysctl_cache_bypass;
|
| 1257 | int sysctl_expire_nodest_conn;
|
| 1258 | int sysctl_sloppy_tcp;
|
| 1259 | int sysctl_sloppy_sctp;
|
| 1260 | int sysctl_expire_quiescent_template;
|
| 1261 | int sysctl_sync_threshold[2];
|
| 1262 | unsigned int sysctl_sync_refresh_period;
|
| 1263 | int sysctl_sync_retries;
|
| 1264 | int sysctl_nat_icmp_send;
|
| 1265 | int sysctl_pmtu_disc;
|
| 1266 | int sysctl_backup_only;
|
| 1267 | int sysctl_conn_reuse_mode;
|
| 1268 | int sysctl_schedule_icmp;
|
| 1269 | int sysctl_ignore_tunneled;
|
| 1270 | int sysctl_run_estimation;
|
| 1271 | #ifdef CONFIG_SYSCTL
|
| 1272 | cpumask_var_t sysctl_est_cpulist;
|
| 1273 | int est_cpulist_valid;
|
| 1274 | int sysctl_est_nice;
|
| 1275 | int est_stopped;
|
| 1276 | #endif
|
| 1277 | int sysctl_conn_lfactor;
|
| 1278 | int sysctl_svc_lfactor;
|
| 1279 |
|
| 1280 |
|
| 1281 | int sysctl_lblc_expiration;
|
| 1282 | struct ctl_table_header *lblc_ctl_header;
|
| 1283 | struct ctl_table *lblc_ctl_table;
|
| 1284 |
|
| 1285 | int sysctl_lblcr_expiration;
|
| 1286 | struct ctl_table_header *lblcr_ctl_header;
|
| 1287 | struct ctl_table *lblcr_ctl_table;
|
| 1288 | unsigned long work_flags;
|
| 1289 |
|
| 1290 | struct delayed_work est_reload_work;
|
| 1291 | struct mutex est_mutex;
|
| 1292 | struct hlist_head est_temp_list;
|
| 1293 | struct ip_vs_est_kt_data **est_kt_arr;
|
| 1294 | unsigned long est_max_threads;
|
| 1295 | int est_calc_phase;
|
| 1296 | int est_chain_max;
|
| 1297 | int est_kt_count;
|
| 1298 | int est_add_ktid;
|
| 1299 | atomic_t est_genid;
|
| 1300 | atomic_t est_genid_done;
|
| 1301 |
|
| 1302 | spinlock_t sync_lock;
|
| 1303 | struct ipvs_master_sync_state *ms;
|
| 1304 | spinlock_t sync_buff_lock;
|
| 1305 | struct ip_vs_sync_thread_data *master_tinfo;
|
| 1306 | struct ip_vs_sync_thread_data *backup_tinfo;
|
| 1307 | int threads_mask;
|
| 1308 | volatile int sync_state;
|
| 1309 | struct mutex sync_mutex;
|
| 1310 | struct ipvs_sync_daemon_cfg mcfg;
|
| 1311 | struct ipvs_sync_daemon_cfg bcfg;
|
| 1312 |
|
| 1313 | struct net *net;
|
| 1314 | |
| 1315 | * are not supported when synchronization is enabled.
|
| 1316 |
|
| 1317 | unsigned int mixed_address_family_dests;
|
| 1318 | unsigned int hooks_afmask;
|
| 1319 |
|
| 1320 | struct ip_vs_rht __rcu *svc_table;
|
| 1321 | struct ip_vs_rht __rcu *conn_tab;
|
| 1322 | atomic_t conn_tab_changes;
|
| 1323 | };
|
| 1324 |
|
| 1325 | #define DEFAULT_SYNC_THRESHOLD 3
|
| 1326 | #define DEFAULT_SYNC_PERIOD 50
|
| 1327 | #define DEFAULT_SYNC_VER 1
|
| 1328 | #define DEFAULT_SLOPPY_TCP 0
|
| 1329 | #define DEFAULT_SLOPPY_SCTP 0
|
| 1330 | #define DEFAULT_SYNC_REFRESH_PERIOD (0U * HZ)
|
| 1331 | #define DEFAULT_SYNC_RETRIES 0
|
| 1332 | #define IPVS_SYNC_WAKEUP_RATE 8
|
| 1333 | #define IPVS_SYNC_QLEN_MAX (IPVS_SYNC_WAKEUP_RATE * 4)
|
| 1334 | #define IPVS_SYNC_SEND_DELAY (HZ / 50)
|
| 1335 | #define IPVS_SYNC_CHECK_PERIOD HZ
|
| 1336 | #define IPVS_SYNC_FLUSH_TIME (HZ * 2)
|
| 1337 | #define IPVS_SYNC_PORTS_MAX (1 << 6)
|
| 1338 |
|
| 1339 | #ifdef CONFIG_SYSCTL
|
| 1340 |
|
| 1341 | static inline int sysctl_conn_max(struct netns_ipvs *ipvs)
|
| 1342 | {
|
| 1343 | return READ_ONCE(ipvs->sysctl_conn_max);
|
| 1344 | }
|
| 1345 |
|
| 1346 | static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
|
| 1347 | {
|
| 1348 | return ipvs->sysctl_sync_threshold[0];
|
| 1349 | }
|
| 1350 |
|
| 1351 | static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
|
| 1352 | {
|
| 1353 | return READ_ONCE(ipvs->sysctl_sync_threshold[1]);
|
| 1354 | }
|
| 1355 |
|
| 1356 | static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
|
| 1357 | {
|
| 1358 | return READ_ONCE(ipvs->sysctl_sync_refresh_period);
|
| 1359 | }
|
| 1360 |
|
| 1361 | static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
|
| 1362 | {
|
| 1363 | return ipvs->sysctl_sync_retries;
|
| 1364 | }
|
| 1365 |
|
| 1366 | static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
|
| 1367 | {
|
| 1368 | return ipvs->sysctl_sync_ver;
|
| 1369 | }
|
| 1370 |
|
| 1371 | static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs)
|
| 1372 | {
|
| 1373 | return ipvs->sysctl_sloppy_tcp;
|
| 1374 | }
|
| 1375 |
|
| 1376 | static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs)
|
| 1377 | {
|
| 1378 | return ipvs->sysctl_sloppy_sctp;
|
| 1379 | }
|
| 1380 |
|
| 1381 | static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
|
| 1382 | {
|
| 1383 | return READ_ONCE(ipvs->sysctl_sync_ports);
|
| 1384 | }
|
| 1385 |
|
| 1386 | static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs)
|
| 1387 | {
|
| 1388 | return ipvs->sysctl_sync_persist_mode;
|
| 1389 | }
|
| 1390 |
|
| 1391 | static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
|
| 1392 | {
|
| 1393 | return ipvs->sysctl_sync_qlen_max;
|
| 1394 | }
|
| 1395 |
|
| 1396 | static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
|
| 1397 | {
|
| 1398 | return ipvs->sysctl_sync_sock_size;
|
| 1399 | }
|
| 1400 |
|
| 1401 | static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
|
| 1402 | {
|
| 1403 | return ipvs->sysctl_pmtu_disc;
|
| 1404 | }
|
| 1405 |
|
| 1406 | static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
|
| 1407 | {
|
| 1408 | return ipvs->sync_state & IP_VS_STATE_BACKUP &&
|
| 1409 | ipvs->sysctl_backup_only;
|
| 1410 | }
|
| 1411 |
|
| 1412 | static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs)
|
| 1413 | {
|
| 1414 | return ipvs->sysctl_conn_reuse_mode;
|
| 1415 | }
|
| 1416 |
|
| 1417 | static inline int sysctl_expire_nodest_conn(struct netns_ipvs *ipvs)
|
| 1418 | {
|
| 1419 | return ipvs->sysctl_expire_nodest_conn;
|
| 1420 | }
|
| 1421 |
|
| 1422 | static inline int sysctl_schedule_icmp(struct netns_ipvs *ipvs)
|
| 1423 | {
|
| 1424 | return ipvs->sysctl_schedule_icmp;
|
| 1425 | }
|
| 1426 |
|
| 1427 | static inline int sysctl_ignore_tunneled(struct netns_ipvs *ipvs)
|
| 1428 | {
|
| 1429 | return ipvs->sysctl_ignore_tunneled;
|
| 1430 | }
|
| 1431 |
|
| 1432 | static inline int sysctl_cache_bypass(struct netns_ipvs *ipvs)
|
| 1433 | {
|
| 1434 | return ipvs->sysctl_cache_bypass;
|
| 1435 | }
|
| 1436 |
|
| 1437 | static inline int sysctl_run_estimation(struct netns_ipvs *ipvs)
|
| 1438 | {
|
| 1439 | return ipvs->sysctl_run_estimation;
|
| 1440 | }
|
| 1441 |
|
| 1442 | static inline const struct cpumask *__sysctl_est_cpulist(struct netns_ipvs *ipvs)
|
| 1443 | {
|
| 1444 | if (ipvs->est_cpulist_valid)
|
| 1445 | return ipvs->sysctl_est_cpulist;
|
| 1446 | else
|
| 1447 | return housekeeping_cpumask(HK_TYPE_KTHREAD);
|
| 1448 | }
|
| 1449 |
|
| 1450 | static inline const struct cpumask *sysctl_est_preferred_cpulist(struct netns_ipvs *ipvs)
|
| 1451 | {
|
| 1452 | if (ipvs->est_cpulist_valid)
|
| 1453 | return ipvs->sysctl_est_cpulist;
|
| 1454 | else
|
| 1455 | return NULL;
|
| 1456 | }
|
| 1457 |
|
| 1458 | static inline int sysctl_est_nice(struct netns_ipvs *ipvs)
|
| 1459 | {
|
| 1460 | return ipvs->sysctl_est_nice;
|
| 1461 | }
|
| 1462 |
|
| 1463 | #else
|
| 1464 |
|
| 1465 | static inline int sysctl_conn_max(struct netns_ipvs *ipvs)
|
| 1466 | {
|
| 1467 | return IP_VS_CONN_MAX;
|
| 1468 | }
|
| 1469 |
|
| 1470 | static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
|
| 1471 | {
|
| 1472 | return DEFAULT_SYNC_THRESHOLD;
|
| 1473 | }
|
| 1474 |
|
| 1475 | static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
|
| 1476 | {
|
| 1477 | return DEFAULT_SYNC_PERIOD;
|
| 1478 | }
|
| 1479 |
|
| 1480 | static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
|
| 1481 | {
|
| 1482 | return DEFAULT_SYNC_REFRESH_PERIOD;
|
| 1483 | }
|
| 1484 |
|
| 1485 | static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
|
| 1486 | {
|
| 1487 | return DEFAULT_SYNC_RETRIES & 3;
|
| 1488 | }
|
| 1489 |
|
| 1490 | static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
|
| 1491 | {
|
| 1492 | return DEFAULT_SYNC_VER;
|
| 1493 | }
|
| 1494 |
|
| 1495 | static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs)
|
| 1496 | {
|
| 1497 | return DEFAULT_SLOPPY_TCP;
|
| 1498 | }
|
| 1499 |
|
| 1500 | static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs)
|
| 1501 | {
|
| 1502 | return DEFAULT_SLOPPY_SCTP;
|
| 1503 | }
|
| 1504 |
|
| 1505 | static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
|
| 1506 | {
|
| 1507 | return 1;
|
| 1508 | }
|
| 1509 |
|
| 1510 | static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs)
|
| 1511 | {
|
| 1512 | return 0;
|
| 1513 | }
|
| 1514 |
|
| 1515 | static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
|
| 1516 | {
|
| 1517 | return IPVS_SYNC_QLEN_MAX;
|
| 1518 | }
|
| 1519 |
|
| 1520 | static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
|
| 1521 | {
|
| 1522 | return 0;
|
| 1523 | }
|
| 1524 |
|
| 1525 | static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
|
| 1526 | {
|
| 1527 | return 1;
|
| 1528 | }
|
| 1529 |
|
| 1530 | static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
|
| 1531 | {
|
| 1532 | return 0;
|
| 1533 | }
|
| 1534 |
|
| 1535 | static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs)
|
| 1536 | {
|
| 1537 | return 1;
|
| 1538 | }
|
| 1539 |
|
| 1540 | static inline int sysctl_expire_nodest_conn(struct netns_ipvs *ipvs)
|
| 1541 | {
|
| 1542 | return 0;
|
| 1543 | }
|
| 1544 |
|
| 1545 | static inline int sysctl_schedule_icmp(struct netns_ipvs *ipvs)
|
| 1546 | {
|
| 1547 | return 0;
|
| 1548 | }
|
| 1549 |
|
| 1550 | static inline int sysctl_ignore_tunneled(struct netns_ipvs *ipvs)
|
| 1551 | {
|
| 1552 | return 0;
|
| 1553 | }
|
| 1554 |
|
| 1555 | static inline int sysctl_cache_bypass(struct netns_ipvs *ipvs)
|
| 1556 | {
|
| 1557 | return 0;
|
| 1558 | }
|
| 1559 |
|
| 1560 | static inline int sysctl_run_estimation(struct netns_ipvs *ipvs)
|
| 1561 | {
|
| 1562 | return 1;
|
| 1563 | }
|
| 1564 |
|
| 1565 | static inline const struct cpumask *__sysctl_est_cpulist(struct netns_ipvs *ipvs)
|
| 1566 | {
|
| 1567 | return housekeeping_cpumask(HK_TYPE_KTHREAD);
|
| 1568 | }
|
| 1569 |
|
| 1570 | static inline const struct cpumask *sysctl_est_preferred_cpulist(struct netns_ipvs *ipvs)
|
| 1571 | {
|
| 1572 | return NULL;
|
| 1573 | }
|
| 1574 |
|
| 1575 | static inline int sysctl_est_nice(struct netns_ipvs *ipvs)
|
| 1576 | {
|
| 1577 | return IPVS_EST_NICE;
|
| 1578 | }
|
| 1579 |
|
| 1580 | #endif
|
| 1581 |
|
| 1582 |
|
| 1583 | static inline int sysctl_conn_lfactor(struct netns_ipvs *ipvs)
|
| 1584 | {
|
| 1585 | return READ_ONCE(ipvs->sysctl_conn_lfactor);
|
| 1586 | }
|
| 1587 |
|
| 1588 | |
| 1589 | * Smaller value decreases u_thresh to reduce collisions but increases
|
| 1590 | * the table size
|
| 1591 | * Returns factor where:
|
| 1592 | * - <0: u_thresh = size >> -factor, eg. lfactor -2 = 25% load
|
| 1593 | * - >=0: u_thresh = size << factor, eg. lfactor 1 = 200% load
|
| 1594 |
|
| 1595 | static inline int sysctl_svc_lfactor(struct netns_ipvs *ipvs)
|
| 1596 | {
|
| 1597 | return READ_ONCE(ipvs->sysctl_svc_lfactor);
|
| 1598 | }
|
| 1599 |
|
| 1600 | static inline bool sysctl_est_cpulist_empty(struct netns_ipvs *ipvs)
|
| 1601 | {
|
| 1602 | guard(rcu)();
|
| 1603 | return cpumask_empty(__sysctl_est_cpulist(ipvs));
|
| 1604 | }
|
| 1605 |
|
| 1606 | static inline unsigned int sysctl_est_cpulist_weight(struct netns_ipvs *ipvs)
|
| 1607 | {
|
| 1608 | guard(rcu)();
|
| 1609 | return cpumask_weight(__sysctl_est_cpulist(ipvs));
|
| 1610 | }
|
| 1611 |
|
| 1612 | |
| 1613 | * (from ip_vs_core.c)
|
| 1614 |
|
| 1615 | const char *ip_vs_proto_name(unsigned int proto);
|
| 1616 | void ip_vs_init_hash_table(struct list_head *table, int rows);
|
| 1617 | struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc,
|
| 1618 | struct ip_vs_dest *dest,
|
| 1619 | struct sk_buff *skb,
|
| 1620 | const struct ip_vs_iphdr *iph,
|
| 1621 | __be16 dport,
|
| 1622 | __be16 cport);
|
| 1623 | #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
|
| 1624 |
|
| 1625 | #define IP_VS_APP_TYPE_FTP 1
|
| 1626 |
|
| 1627 | |
| 1628 | * (from ip_vs_conn.c)
|
| 1629 |
|
| 1630 | enum {
|
| 1631 | IP_VS_DIR_INPUT = 0,
|
| 1632 | IP_VS_DIR_OUTPUT,
|
| 1633 | IP_VS_DIR_INPUT_ONLY,
|
| 1634 | IP_VS_DIR_LAST,
|
| 1635 | };
|
| 1636 |
|
| 1637 | static inline void ip_vs_conn_fill_param(struct netns_ipvs *ipvs, int af, int protocol,
|
| 1638 | const union nf_inet_addr *caddr,
|
| 1639 | __be16 cport,
|
| 1640 | const union nf_inet_addr *vaddr,
|
| 1641 | __be16 vport,
|
| 1642 | struct ip_vs_conn_param *p)
|
| 1643 | {
|
| 1644 | p->ipvs = ipvs;
|
| 1645 | p->af = af;
|
| 1646 | p->protocol = protocol;
|
| 1647 | p->caddr = caddr;
|
| 1648 | p->cport = cport;
|
| 1649 | p->vaddr = vaddr;
|
| 1650 | p->vport = vport;
|
| 1651 | p->pe = NULL;
|
| 1652 | p->pe_data = NULL;
|
| 1653 | }
|
| 1654 |
|
| 1655 | struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p);
|
| 1656 | struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p);
|
| 1657 |
|
| 1658 | struct ip_vs_conn * ip_vs_conn_in_get_proto(struct netns_ipvs *ipvs, int af,
|
| 1659 | const struct sk_buff *skb,
|
| 1660 | const struct ip_vs_iphdr *iph);
|
| 1661 |
|
| 1662 | struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p);
|
| 1663 |
|
| 1664 | struct ip_vs_conn * ip_vs_conn_out_get_proto(struct netns_ipvs *ipvs, int af,
|
| 1665 | const struct sk_buff *skb,
|
| 1666 | const struct ip_vs_iphdr *iph);
|
| 1667 |
|
| 1668 | |
| 1669 | * By default, RCU read-side critical sections have access only to
|
| 1670 | * conn fields and its PE data, see ip_vs_conn_rcu_free() for reference.
|
| 1671 |
|
| 1672 | static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp)
|
| 1673 | {
|
| 1674 | return refcount_inc_not_zero(&cp->refcnt);
|
| 1675 | }
|
| 1676 |
|
| 1677 |
|
| 1678 | static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
|
| 1679 | {
|
| 1680 | smp_mb__before_atomic();
|
| 1681 | refcount_dec(&cp->refcnt);
|
| 1682 | }
|
| 1683 | void ip_vs_conn_put(struct ip_vs_conn *cp);
|
| 1684 | void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
|
| 1685 | int ip_vs_conn_desired_size(struct netns_ipvs *ipvs, struct ip_vs_rht *t,
|
| 1686 | int lfactor);
|
| 1687 | struct ip_vs_rht *ip_vs_conn_tab_alloc(struct netns_ipvs *ipvs, int buckets,
|
| 1688 | int lfactor);
|
| 1689 |
|
| 1690 | static inline struct ip_vs_conn *
|
| 1691 | ip_vs_hn0_to_conn(struct ip_vs_conn_hnode *hn)
|
| 1692 | {
|
| 1693 | return container_of(hn, struct ip_vs_conn, hn0);
|
| 1694 | }
|
| 1695 |
|
| 1696 | static inline struct ip_vs_conn *
|
| 1697 | ip_vs_hn_to_conn(struct ip_vs_conn_hnode *hn)
|
| 1698 | {
|
| 1699 | return hn->dir ? container_of(hn, struct ip_vs_conn, hn1) :
|
| 1700 | container_of(hn, struct ip_vs_conn, hn0);
|
| 1701 | }
|
| 1702 |
|
| 1703 | struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
|
| 1704 | const union nf_inet_addr *daddr,
|
| 1705 | __be16 dport, unsigned int flags,
|
| 1706 | struct ip_vs_dest *dest, __u32 fwmark);
|
| 1707 | void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
|
| 1708 |
|
| 1709 | const char *ip_vs_state_name(const struct ip_vs_conn *cp);
|
| 1710 |
|
| 1711 | void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
|
| 1712 | int ip_vs_check_template(struct ip_vs_conn *ct, struct ip_vs_dest *cdest);
|
| 1713 | void ip_vs_random_dropentry(struct netns_ipvs *ipvs);
|
| 1714 | int ip_vs_conn_init(void);
|
| 1715 | void ip_vs_conn_cleanup(void);
|
| 1716 |
|
| 1717 | static inline void ip_vs_control_del(struct ip_vs_conn *cp)
|
| 1718 | {
|
| 1719 | struct ip_vs_conn *ctl_cp = cp->control;
|
| 1720 | if (!ctl_cp) {
|
| 1721 | IP_VS_ERR_BUF("request control DEL for uncontrolled: "
|
| 1722 | "%s:%d to %s:%d\n",
|
| 1723 | IP_VS_DBG_ADDR(cp->af, &cp->caddr),
|
| 1724 | ntohs(cp->cport),
|
| 1725 | IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
|
| 1726 | ntohs(cp->vport));
|
| 1727 |
|
| 1728 | return;
|
| 1729 | }
|
| 1730 |
|
| 1731 | IP_VS_DBG_BUF(7, "DELeting control for: "
|
| 1732 | "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
|
| 1733 | IP_VS_DBG_ADDR(cp->af, &cp->caddr),
|
| 1734 | ntohs(cp->cport),
|
| 1735 | IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
|
| 1736 | ntohs(ctl_cp->cport));
|
| 1737 |
|
| 1738 | cp->control = NULL;
|
| 1739 | if (atomic_read(&ctl_cp->n_control) == 0) {
|
| 1740 | IP_VS_ERR_BUF("BUG control DEL with n=0 : "
|
| 1741 | "%s:%d to %s:%d\n",
|
| 1742 | IP_VS_DBG_ADDR(cp->af, &cp->caddr),
|
| 1743 | ntohs(cp->cport),
|
| 1744 | IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
|
| 1745 | ntohs(cp->vport));
|
| 1746 |
|
| 1747 | return;
|
| 1748 | }
|
| 1749 | atomic_dec(&ctl_cp->n_control);
|
| 1750 | }
|
| 1751 |
|
| 1752 | static inline void
|
| 1753 | ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
|
| 1754 | {
|
| 1755 | if (cp->control) {
|
| 1756 | IP_VS_ERR_BUF("request control ADD for already controlled: "
|
| 1757 | "%s:%d to %s:%d\n",
|
| 1758 | IP_VS_DBG_ADDR(cp->af, &cp->caddr),
|
| 1759 | ntohs(cp->cport),
|
| 1760 | IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
|
| 1761 | ntohs(cp->vport));
|
| 1762 |
|
| 1763 | ip_vs_control_del(cp);
|
| 1764 | }
|
| 1765 |
|
| 1766 | IP_VS_DBG_BUF(7, "ADDing control for: "
|
| 1767 | "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
|
| 1768 | IP_VS_DBG_ADDR(cp->af, &cp->caddr),
|
| 1769 | ntohs(cp->cport),
|
| 1770 | IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
|
| 1771 | ntohs(ctl_cp->cport));
|
| 1772 |
|
| 1773 | cp->control = ctl_cp;
|
| 1774 | atomic_inc(&ctl_cp->n_control);
|
| 1775 | }
|
| 1776 |
|
| 1777 |
|
| 1778 | static inline void
|
| 1779 | ip_vs_control_assure_ct(struct ip_vs_conn *cp)
|
| 1780 | {
|
| 1781 | struct ip_vs_conn *ct = cp->control;
|
| 1782 |
|
| 1783 | if (ct && !(ct->state & IP_VS_CTPL_S_ASSURED) &&
|
| 1784 | (ct->flags & IP_VS_CONN_F_TEMPLATE))
|
| 1785 | ct->state |= IP_VS_CTPL_S_ASSURED;
|
| 1786 | }
|
| 1787 |
|
| 1788 |
|
| 1789 | int ip_vs_estimator_net_init(struct netns_ipvs *ipvs);
|
| 1790 | int ip_vs_control_net_init(struct netns_ipvs *ipvs);
|
| 1791 | int ip_vs_protocol_net_init(struct netns_ipvs *ipvs);
|
| 1792 | int ip_vs_app_net_init(struct netns_ipvs *ipvs);
|
| 1793 | int ip_vs_conn_net_init(struct netns_ipvs *ipvs);
|
| 1794 | int ip_vs_sync_net_init(struct netns_ipvs *ipvs);
|
| 1795 | void ip_vs_conn_net_cleanup(struct netns_ipvs *ipvs);
|
| 1796 | void ip_vs_app_net_cleanup(struct netns_ipvs *ipvs);
|
| 1797 | void ip_vs_protocol_net_cleanup(struct netns_ipvs *ipvs);
|
| 1798 | void ip_vs_control_net_cleanup(struct netns_ipvs *ipvs);
|
| 1799 | void ip_vs_estimator_net_cleanup(struct netns_ipvs *ipvs);
|
| 1800 | void ip_vs_sync_net_cleanup(struct netns_ipvs *ipvs);
|
| 1801 | void ip_vs_service_nets_cleanup(struct list_head *net_list);
|
| 1802 |
|
| 1803 | |
| 1804 | * (from ip_vs_app.c)
|
| 1805 |
|
| 1806 | #define IP_VS_APP_MAX_PORTS 8
|
| 1807 | struct ip_vs_app *register_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app);
|
| 1808 | void unregister_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app);
|
| 1809 | int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
|
| 1810 | void ip_vs_unbind_app(struct ip_vs_conn *cp);
|
| 1811 | int register_ip_vs_app_inc(struct netns_ipvs *ipvs, struct ip_vs_app *app, __u16 proto,
|
| 1812 | __u16 port);
|
| 1813 | int ip_vs_app_inc_get(struct ip_vs_app *inc);
|
| 1814 | void ip_vs_app_inc_put(struct ip_vs_app *inc);
|
| 1815 |
|
| 1816 | int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb,
|
| 1817 | struct ip_vs_iphdr *ipvsh);
|
| 1818 | int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb,
|
| 1819 | struct ip_vs_iphdr *ipvsh);
|
| 1820 |
|
| 1821 | int register_ip_vs_pe(struct ip_vs_pe *pe);
|
| 1822 | int unregister_ip_vs_pe(struct ip_vs_pe *pe);
|
| 1823 | struct ip_vs_pe *ip_vs_pe_getbyname(const char *name);
|
| 1824 | struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name);
|
| 1825 |
|
| 1826 |
|
| 1827 | #define ip_vs_pe_get(pe) \
|
| 1828 | if (pe && pe->module) \
|
| 1829 | __module_get(pe->module);
|
| 1830 |
|
| 1831 | #define ip_vs_pe_put(pe) \
|
| 1832 | if (pe && pe->module) \
|
| 1833 | module_put(pe->module);
|
| 1834 |
|
| 1835 |
|
| 1836 | int ip_vs_protocol_init(void);
|
| 1837 | void ip_vs_protocol_cleanup(void);
|
| 1838 | void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags);
|
| 1839 | int *ip_vs_create_timeout_table(int *table, int size);
|
| 1840 | void ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,
|
| 1841 | const struct sk_buff *skb, int offset,
|
| 1842 | const char *msg);
|
| 1843 |
|
| 1844 | extern struct ip_vs_protocol ip_vs_protocol_tcp;
|
| 1845 | extern struct ip_vs_protocol ip_vs_protocol_udp;
|
| 1846 | extern struct ip_vs_protocol ip_vs_protocol_icmp;
|
| 1847 | extern struct ip_vs_protocol ip_vs_protocol_esp;
|
| 1848 | extern struct ip_vs_protocol ip_vs_protocol_ah;
|
| 1849 | extern struct ip_vs_protocol ip_vs_protocol_sctp;
|
| 1850 |
|
| 1851 | |
| 1852 | * (from ip_vs_sched.c)
|
| 1853 |
|
| 1854 | int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
|
| 1855 | int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
|
| 1856 | int ip_vs_bind_scheduler(struct ip_vs_service *svc,
|
| 1857 | struct ip_vs_scheduler *scheduler);
|
| 1858 | void ip_vs_unbind_scheduler(struct ip_vs_service *svc);
|
| 1859 | struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
|
| 1860 | void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
|
| 1861 | struct ip_vs_conn *
|
| 1862 | ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
|
| 1863 | struct ip_vs_proto_data *pd, int *ignored,
|
| 1864 | struct ip_vs_iphdr *iph);
|
| 1865 | int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
|
| 1866 | struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph);
|
| 1867 |
|
| 1868 | void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg);
|
| 1869 |
|
| 1870 |
|
| 1871 | extern struct ip_vs_stats ip_vs_stats;
|
| 1872 | extern int sysctl_ip_vs_sync_ver;
|
| 1873 |
|
| 1874 | struct ip_vs_service *
|
| 1875 | ip_vs_service_find(struct netns_ipvs *ipvs, int af, __u32 fwmark, __u16 protocol,
|
| 1876 | const union nf_inet_addr *vaddr, __be16 vport);
|
| 1877 |
|
| 1878 | bool ip_vs_has_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol,
|
| 1879 | const union nf_inet_addr *daddr, __be16 dport);
|
| 1880 |
|
| 1881 | struct ip_vs_dest *
|
| 1882 | ip_vs_find_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol,
|
| 1883 | const union nf_inet_addr *daddr, __be16 dport);
|
| 1884 | struct ip_vs_dest *ip_vs_find_tunnel(struct netns_ipvs *ipvs, int af,
|
| 1885 | const union nf_inet_addr *daddr,
|
| 1886 | __be16 tun_port);
|
| 1887 |
|
| 1888 | int ip_vs_use_count_inc(void);
|
| 1889 | void ip_vs_use_count_dec(void);
|
| 1890 | int ip_vs_register_nl_ioctl(void);
|
| 1891 | void ip_vs_unregister_nl_ioctl(void);
|
| 1892 | int ip_vs_control_init(void);
|
| 1893 | void ip_vs_control_cleanup(void);
|
| 1894 | struct ip_vs_dest *
|
| 1895 | ip_vs_find_dest(struct netns_ipvs *ipvs, int svc_af, int dest_af,
|
| 1896 | const union nf_inet_addr *daddr, __be16 dport,
|
| 1897 | const union nf_inet_addr *vaddr, __be16 vport,
|
| 1898 | __u16 protocol, __u32 fwmark, __u32 flags);
|
| 1899 | void ip_vs_try_bind_dest(struct ip_vs_conn *cp);
|
| 1900 |
|
| 1901 | static inline void ip_vs_dest_hold(struct ip_vs_dest *dest)
|
| 1902 | {
|
| 1903 | refcount_inc(&dest->refcnt);
|
| 1904 | }
|
| 1905 |
|
| 1906 | static inline void ip_vs_dest_put(struct ip_vs_dest *dest)
|
| 1907 | {
|
| 1908 | smp_mb__before_atomic();
|
| 1909 | refcount_dec(&dest->refcnt);
|
| 1910 | }
|
| 1911 |
|
| 1912 | static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)
|
| 1913 | {
|
| 1914 | if (refcount_dec_and_test(&dest->refcnt))
|
| 1915 | kfree(dest);
|
| 1916 | }
|
| 1917 |
|
| 1918 | void ip_vs_dest_update_overload(struct ip_vs_dest *dest, int mode);
|
| 1919 |
|
| 1920 | |
| 1921 | * (from ip_vs_sync.c)
|
| 1922 |
|
| 1923 | int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *cfg,
|
| 1924 | int state);
|
| 1925 | int stop_sync_thread(struct netns_ipvs *ipvs, int state);
|
| 1926 | void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts);
|
| 1927 |
|
| 1928 |
|
| 1929 | int ip_vs_start_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats);
|
| 1930 | void ip_vs_stop_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats);
|
| 1931 | void ip_vs_zero_estimator(struct ip_vs_stats *stats);
|
| 1932 | void ip_vs_read_estimator(struct ip_vs_kstats *dst, struct ip_vs_stats *stats);
|
| 1933 | void ip_vs_est_reload_start(struct netns_ipvs *ipvs, bool restart);
|
| 1934 | int ip_vs_est_kthread_start(struct netns_ipvs *ipvs,
|
| 1935 | struct ip_vs_est_kt_data *kd);
|
| 1936 | void ip_vs_est_kthread_stop(struct ip_vs_est_kt_data *kd);
|
| 1937 |
|
| 1938 | static inline void ip_vs_stop_estimator_tot_stats(struct netns_ipvs *ipvs)
|
| 1939 | {
|
| 1940 | #ifdef CONFIG_SYSCTL
|
| 1941 | ip_vs_stop_estimator(ipvs, &ipvs->tot_stats->s);
|
| 1942 | ipvs->tot_stats->s.est.ktid = -2;
|
| 1943 | #endif
|
| 1944 | }
|
| 1945 |
|
| 1946 | static inline void ip_vs_est_stopped_recalc(struct netns_ipvs *ipvs)
|
| 1947 | {
|
| 1948 | #ifdef CONFIG_SYSCTL
|
| 1949 |
|
| 1950 | ipvs->est_stopped = !sysctl_run_estimation(ipvs) ||
|
| 1951 | (ipvs->est_cpulist_valid &&
|
| 1952 | sysctl_est_cpulist_empty(ipvs));
|
| 1953 | #endif
|
| 1954 | }
|
| 1955 |
|
| 1956 | static inline bool ip_vs_est_stopped(struct netns_ipvs *ipvs)
|
| 1957 | {
|
| 1958 | #ifdef CONFIG_SYSCTL
|
| 1959 | return ipvs->est_stopped;
|
| 1960 | #else
|
| 1961 | return false;
|
| 1962 | #endif
|
| 1963 | }
|
| 1964 |
|
| 1965 | static inline int ip_vs_est_max_threads(struct netns_ipvs *ipvs)
|
| 1966 | {
|
| 1967 | unsigned int limit = IPVS_EST_CPU_KTHREADS *
|
| 1968 | sysctl_est_cpulist_weight(ipvs);
|
| 1969 |
|
| 1970 | return max(1U, limit);
|
| 1971 | }
|
| 1972 |
|
| 1973 |
|
| 1974 | int ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
|
| 1975 | struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
|
| 1976 | int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
|
| 1977 | struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
|
| 1978 | int ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
|
| 1979 | struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
|
| 1980 | int ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
|
| 1981 | struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
|
| 1982 | int ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
|
| 1983 | struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
|
| 1984 | int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
|
| 1985 | struct ip_vs_protocol *pp, unsigned int toff,
|
| 1986 | unsigned int hooknum, struct ip_vs_iphdr *ciph);
|
| 1987 | void ip_vs_dest_dst_rcu_free(struct rcu_head *head);
|
| 1988 |
|
| 1989 | #ifdef CONFIG_IP_VS_IPV6
|
| 1990 | int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
|
| 1991 | struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
|
| 1992 | int ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
|
| 1993 | struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
|
| 1994 | int ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
|
| 1995 | struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
|
| 1996 | int ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
|
| 1997 | struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
|
| 1998 | int ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
|
| 1999 | struct ip_vs_protocol *pp, unsigned int toff,
|
| 2000 | unsigned int hooknum, struct ip_vs_iphdr *ciph);
|
| 2001 | #endif
|
| 2002 |
|
| 2003 | #ifdef CONFIG_SYSCTL
|
| 2004 | |
| 2005 | * we are loaded. Just set ip_vs_drop_rate to 'n' and
|
| 2006 | * we start to drop 1/rate of the packets
|
| 2007 |
|
| 2008 | static inline int ip_vs_todrop(struct netns_ipvs *ipvs)
|
| 2009 | {
|
| 2010 | if (!ipvs->drop_rate)
|
| 2011 | return 0;
|
| 2012 | if (--ipvs->drop_counter > 0)
|
| 2013 | return 0;
|
| 2014 | ipvs->drop_counter = ipvs->drop_rate;
|
| 2015 | return 1;
|
| 2016 | }
|
| 2017 | #else
|
| 2018 | static inline int ip_vs_todrop(struct netns_ipvs *ipvs) { return 0; }
|
| 2019 | #endif
|
| 2020 |
|
| 2021 | #ifdef CONFIG_SYSCTL
|
| 2022 | |
| 2023 | * Only run when sysctl_expire_nodest=1
|
| 2024 |
|
| 2025 | static inline void ip_vs_enqueue_expire_nodest_conns(struct netns_ipvs *ipvs)
|
| 2026 | {
|
| 2027 | if (sysctl_expire_nodest_conn(ipvs))
|
| 2028 | queue_delayed_work(system_long_wq,
|
| 2029 | &ipvs->expire_nodest_conn_work, 1);
|
| 2030 | }
|
| 2031 |
|
| 2032 | void ip_vs_expire_nodest_conn_flush(struct netns_ipvs *ipvs);
|
| 2033 | #else
|
| 2034 | static inline void ip_vs_enqueue_expire_nodest_conns(struct netns_ipvs *ipvs) {}
|
| 2035 | #endif
|
| 2036 |
|
| 2037 | #define IP_VS_DFWD_METHOD(dest) (atomic_read(&(dest)->conn_flags) & \
|
| 2038 | IP_VS_CONN_F_FWD_MASK)
|
| 2039 |
|
| 2040 |
|
| 2041 | #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
|
| 2042 |
|
| 2043 | static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
|
| 2044 | {
|
| 2045 | char fwd;
|
| 2046 |
|
| 2047 | switch (IP_VS_FWD_METHOD(cp)) {
|
| 2048 | case IP_VS_CONN_F_MASQ:
|
| 2049 | fwd = 'M'; break;
|
| 2050 | case IP_VS_CONN_F_LOCALNODE:
|
| 2051 | fwd = 'L'; break;
|
| 2052 | case IP_VS_CONN_F_TUNNEL:
|
| 2053 | fwd = 'T'; break;
|
| 2054 | case IP_VS_CONN_F_DROUTE:
|
| 2055 | fwd = 'R'; break;
|
| 2056 | case IP_VS_CONN_F_BYPASS:
|
| 2057 | fwd = 'B'; break;
|
| 2058 | default:
|
| 2059 | fwd = '?'; break;
|
| 2060 | }
|
| 2061 | return fwd;
|
| 2062 | }
|
| 2063 |
|
| 2064 |
|
| 2065 | static inline bool ip_vs_conn_use_hash2(struct ip_vs_conn *cp)
|
| 2066 | {
|
| 2067 | return IP_VS_FWD_METHOD(cp) == IP_VS_CONN_F_MASQ &&
|
| 2068 | !(cp->flags & IP_VS_CONN_F_TEMPLATE);
|
| 2069 | }
|
| 2070 |
|
| 2071 | bool ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
|
| 2072 | struct ip_vs_conn *cp, int dir, unsigned int toff,
|
| 2073 | bool has_ports, struct ip_vs_iphdr *ciph);
|
| 2074 |
|
| 2075 | #ifdef CONFIG_IP_VS_IPV6
|
| 2076 | void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
|
| 2077 | struct ip_vs_conn *cp, int dir, unsigned int toff,
|
| 2078 | bool has_ports, struct ip_vs_iphdr *ciph);
|
| 2079 | #endif
|
| 2080 |
|
| 2081 | static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
|
| 2082 | {
|
| 2083 | __be32 diff[2] = { ~old, new };
|
| 2084 |
|
| 2085 | return csum_partial(diff, sizeof(diff), oldsum);
|
| 2086 | }
|
| 2087 |
|
| 2088 | #ifdef CONFIG_IP_VS_IPV6
|
| 2089 | static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new,
|
| 2090 | __wsum oldsum)
|
| 2091 | {
|
| 2092 | __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
|
| 2093 | new[3], new[2], new[1], new[0] };
|
| 2094 |
|
| 2095 | return csum_partial(diff, sizeof(diff), oldsum);
|
| 2096 | }
|
| 2097 | #endif
|
| 2098 |
|
| 2099 | static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
|
| 2100 | {
|
| 2101 | __be16 diff[2] = { ~old, new };
|
| 2102 |
|
| 2103 | return csum_partial(diff, sizeof(diff), oldsum);
|
| 2104 | }
|
| 2105 |
|
| 2106 | static inline bool ip_vs_checksum_needed(struct sk_buff *skb)
|
| 2107 | {
|
| 2108 |
|
| 2109 | if (skb_csum_unnecessary(skb))
|
| 2110 | return false;
|
| 2111 |
|
| 2112 | if (!skb->dev)
|
| 2113 | return false;
|
| 2114 | return true;
|
| 2115 | }
|
| 2116 |
|
| 2117 | static inline bool ip_vs_checksum_common_check(struct sk_buff *skb,
|
| 2118 | int offset, int proto, int af)
|
| 2119 | {
|
| 2120 | if (!ip_vs_checksum_needed(skb))
|
| 2121 | return true;
|
| 2122 |
|
| 2123 | return !nf_checksum(skb, NF_INET_LOCAL_IN, offset, proto, af);
|
| 2124 | }
|
| 2125 |
|
| 2126 |
|
| 2127 | static inline void ip_vs_notrack(struct sk_buff *skb)
|
| 2128 | {
|
| 2129 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
|
| 2130 | enum ip_conntrack_info ctinfo;
|
| 2131 | struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
|
| 2132 |
|
| 2133 | if (ct) {
|
| 2134 | nf_reset_ct(skb);
|
| 2135 | nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
|
| 2136 | }
|
| 2137 | #endif
|
| 2138 | }
|
| 2139 |
|
| 2140 | #ifdef CONFIG_IP_VS_NFCT
|
| 2141 | |
| 2142 | * (from ip_vs_nfct.c)
|
| 2143 |
|
| 2144 | static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
|
| 2145 | {
|
| 2146 | #ifdef CONFIG_SYSCTL
|
| 2147 | return ipvs->sysctl_conntrack;
|
| 2148 | #else
|
| 2149 | return 0;
|
| 2150 | #endif
|
| 2151 | }
|
| 2152 |
|
| 2153 | void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
|
| 2154 | int outin);
|
| 2155 | int ip_vs_confirm_conntrack(struct sk_buff *skb);
|
| 2156 | void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct,
|
| 2157 | struct ip_vs_conn *cp, u8 proto,
|
| 2158 | const __be16 port, int from_rs);
|
| 2159 | void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp);
|
| 2160 |
|
| 2161 | #else
|
| 2162 |
|
| 2163 | static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
|
| 2164 | {
|
| 2165 | return 0;
|
| 2166 | }
|
| 2167 |
|
| 2168 | static inline void ip_vs_update_conntrack(struct sk_buff *skb,
|
| 2169 | struct ip_vs_conn *cp, int outin)
|
| 2170 | {
|
| 2171 | }
|
| 2172 |
|
| 2173 | static inline int ip_vs_confirm_conntrack(struct sk_buff *skb)
|
| 2174 | {
|
| 2175 | return NF_ACCEPT;
|
| 2176 | }
|
| 2177 |
|
| 2178 | static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
|
| 2179 | {
|
| 2180 | }
|
| 2181 | #endif
|
| 2182 |
|
| 2183 |
|
| 2184 | static inline bool ip_vs_conn_uses_old_conntrack(struct ip_vs_conn *cp,
|
| 2185 | struct sk_buff *skb)
|
| 2186 | {
|
| 2187 | #ifdef CONFIG_IP_VS_NFCT
|
| 2188 | enum ip_conntrack_info ctinfo;
|
| 2189 | struct nf_conn *ct;
|
| 2190 |
|
| 2191 | ct = nf_ct_get(skb, &ctinfo);
|
| 2192 | if (ct && nf_ct_is_confirmed(ct))
|
| 2193 | return true;
|
| 2194 | #endif
|
| 2195 | return false;
|
| 2196 | }
|
| 2197 |
|
| 2198 | static inline int ip_vs_register_conntrack(struct ip_vs_service *svc)
|
| 2199 | {
|
| 2200 | #if IS_ENABLED(CONFIG_NF_CONNTRACK)
|
| 2201 | int afmask = (svc->af == AF_INET6) ? 2 : 1;
|
| 2202 | int ret = 0;
|
| 2203 |
|
| 2204 | if (!(svc->conntrack_afmask & afmask)) {
|
| 2205 | ret = nf_ct_netns_get(svc->ipvs->net, svc->af);
|
| 2206 | if (ret >= 0)
|
| 2207 | svc->conntrack_afmask |= afmask;
|
| 2208 | }
|
| 2209 | return ret;
|
| 2210 | #else
|
| 2211 | return 0;
|
| 2212 | #endif
|
| 2213 | }
|
| 2214 |
|
| 2215 | static inline void ip_vs_unregister_conntrack(struct ip_vs_service *svc)
|
| 2216 | {
|
| 2217 | #if IS_ENABLED(CONFIG_NF_CONNTRACK)
|
| 2218 | int afmask = (svc->af == AF_INET6) ? 2 : 1;
|
| 2219 |
|
| 2220 | if (svc->conntrack_afmask & afmask) {
|
| 2221 | nf_ct_netns_put(svc->ipvs->net, svc->af);
|
| 2222 | svc->conntrack_afmask &= ~afmask;
|
| 2223 | }
|
| 2224 | #endif
|
| 2225 | }
|
| 2226 |
|
| 2227 | int ip_vs_register_hooks(struct netns_ipvs *ipvs, unsigned int af);
|
| 2228 | void ip_vs_unregister_hooks(struct netns_ipvs *ipvs, unsigned int af);
|
| 2229 |
|
| 2230 | static inline int
|
| 2231 | ip_vs_dest_conn_overhead(struct ip_vs_dest *dest)
|
| 2232 | {
|
| 2233 | |
| 2234 | * times higher than that of inactive connections in average. (This
|
| 2235 | * 257 times might not be accurate, we will change it later) We
|
| 2236 | * use the following formula to estimate the overhead now:
|
| 2237 | * dest->activeconns*256 + dest->totalconns
|
| 2238 |
|
| 2239 | return (atomic_read(&dest->activeconns) << 8) +
|
| 2240 | atomic_read(&dest->totalconns);
|
| 2241 | }
|
| 2242 |
|
| 2243 | static inline int
|
| 2244 | ip_vs_dest_inactconns(const struct ip_vs_dest *dest)
|
| 2245 | {
|
| 2246 | return max(atomic_read(&dest->totalconns) -
|
| 2247 | atomic_read(&dest->activeconns), 0);
|
| 2248 | }
|
| 2249 |
|
| 2250 | #ifdef CONFIG_IP_VS_PROTO_TCP
|
| 2251 | INDIRECT_CALLABLE_DECLARE(int
|
| 2252 | tcp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,
|
| 2253 | struct ip_vs_conn *cp, struct ip_vs_iphdr *iph));
|
| 2254 | #endif
|
| 2255 |
|
| 2256 | #ifdef CONFIG_IP_VS_PROTO_UDP
|
| 2257 | INDIRECT_CALLABLE_DECLARE(int
|
| 2258 | udp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,
|
| 2259 | struct ip_vs_conn *cp, struct ip_vs_iphdr *iph));
|
| 2260 | #endif
|
| 2261 | #endif
|