IPVS changes, part 3 of 4 - per-net tables
Subsystems (5)
Julian Anastasov
maintainercover IPVS changes, part 3 of 4 - per-net tables
Hello,
This patchset is part 3 of changes that accumulated in
recent time. It is for nf-next and should be applied when the patches from part 1 and 2 are already applied. It contains changes that convert the connection and service tables to be per-net and targets more netns isolation when IPVS is used in large setups.
First patch adds useful wrappers to rculist_bl.h, thehlist_bl methods IPVS will use in the following patches. The other patches are IPVS-specific.
All patches here come from the work
"ipvs: per-net tables and optimizations" last posted on 19 Oct 2025 as v6, with the following changes:
Patch 1 comes from v6/patch 1 without changes
Patch 2 comes from v6/patch 7 with added comments
Patch 3 comes from v6/patch 8 without changes
Patch 4 comes from v6/patch 9 with some changes due to the
v6/patch 11 position change
Patch 5 comes from v6/patch 12 without changes
As result, the following patches will:
* Add new wrappers into rculist_bl.h
* Add infrastructure for resizable hash tables based on hlist_bl which we will use for services and connections: hlists with per-bucket bit lock in the heads. The resizing delays RCU lookups on a bucket level with seqcounts which are protected with spin locks. The entries keep the table ID and the hash value which allows to filter the entries without touching many cache lines and to unlink the entries without lookup by keys.
* Change the 256-bucket service hash table to be resizable in the range of 4..20 bits depending on the added services and use jhash hashing to reduce the collisions.
* Change the global connection table to be per-net and resizable in the range of 256..ip_vs_conn_tab_size. As the connections are hashed by using remote addresses and ports, use siphash instead of jhash for better security.
* Make the connection hashing more secure for setups with multiple services. Hashing only by remote address and port (client info) is not enough. To reduce the possible hash collisions add the used virtual address/port (local info) into the hash and as a side effect the MASQ connections will be double hashed into the hash table to match the traffic from real servers:
OLD:
- all methods: c_list node: proto, caddr:cport
NEW:
- all methods: hn0 node (dir 0): proto, caddr:cport -> vaddr:vport
- MASQ method: hn1 node (dir 1): proto, daddr:dport -> caddr:cport
Julian Anastasov (5):
rculist_bl: add hlist_bl_for_each_entry_continue_rcu
ipvs: add resizable hash tables
ipvs: use resizable hash table for services
ipvs: switch to per-net connection table
ipvs: use more keys for connection hashing
include/linux/rculist_bl.h | 49 +- include/net/ip_vs.h | 376 +++++++++-- net/netfilter/ipvs/ip_vs_conn.c | 992 ++++++++++++++++++++++-------- net/netfilter/ipvs/ip_vs_core.c | 179 ++++++ net/netfilter/ipvs/ip_vs_ctl.c | 691 +++++++++++++++++---- net/netfilter/ipvs/ip_vs_pe_sip.c | 4 +- net/netfilter/ipvs/ip_vs_sync.c | 23 + 7 files changed, 1880 insertions(+), 434 deletions(-)
Signature · 1 line
2.53.0
Julian Anastasov
maintainerPATCH 1/5 rculist_bl: add hlist_bl_for_each_entry_continue_rcu
Change the old hlist_bl_first_rcu to hlist_bl_first_rcu_dereference to indicate that it is a RCU dereference.
Add hlist_bl_next_rcu and hlist_bl_first_rcu to use RCU pointers and use them to fix sparse warnings.
Add hlist_bl_for_each_entry_continue_rcu.
--- include/linux/rculist_bl.h | 49 +++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 9 deletions(-)
include/linux/rculist_bl.h +40 -9
@@ -8,21 +8,31 @@#include <linux/list_bl.h> #include <linux/rcupdate.h> +/* return the first ptr or next element in an RCU protected list */ +#define hlist_bl_first_rcu (head) \ + (*((struct hlist_bl_node __rcu **)(&(head)->first))) +#define hlist_bl_next_rcu (node) \ + (*((struct hlist_bl_node __rcu **)(&(node)->next))) +static inline void hlist_bl_set_first_rcu (struct hlist_bl_head *h,struct hlist_bl_node *n) {LIST_BL_BUG_ON ((unsigned long )n &LIST_BL_LOCKMASK );LIST_BL_BUG_ON (((unsigned long )h->first &LIST_BL_LOCKMASK ) !=LIST_BL_LOCKMASK ); -rcu_assign_pointer (h->first, +rcu_assign_pointer (hlist_bl_first_rcu (h), (struct hlist_bl_node *)((unsigned long )n |LIST_BL_LOCKMASK )); } -static inline struct hlist_bl_node *hlist_bl_first_rcu (struct hlist_bl_head *h) -{ -return (struct hlist_bl_node *) - ((unsigned long )rcu_dereference_check (h->first,hlist_bl_is_locked (h)) & ~LIST_BL_LOCKMASK ); -} +#define hlist_bl_first_rcu_dereference (head) \ +({ \ + struct hlist_bl_head *__head = (head); \ + \ + (struct hlist_bl_node *) \ + ((unsigned long)rcu_dereference_check(hlist_bl_first_rcu(__head), \ + hlist_bl_is_locked(__head)) & \ + ~LIST_BL_LOCKMASK); \ +})/** * hlist_bl_del_rcu - deletes entry from hash list without re-initialization
@@ -73,7 +83,7 @@ static inline void hlist_bl_add_head_rcu(struct hlist_bl_node *n, {struct hlist_bl_node *first; -/* don't need hlist_bl_first_rcu because we're under lock */ +/* don't need hlist_bl_first_rcu* because we're under lock */ first =hlist_bl_first (h); n->next = first;
@@ -93,9 +103,30 @@ static inline void hlist_bl_add_head_rcu(struct hlist_bl_node *n,* */ #define hlist_bl_for_each_entry_rcu (tpos, pos, head, member) \ - for (pos = hlist_bl_first_rcu(head); \ + for (pos = hlist_bl_first_rcu_dereference(head); \ pos && \ ({ tpos = hlist_bl_entry(pos, typeof(*tpos), member); 1; }); \ - pos = rcu_dereference_raw(pos->next)) + pos = rcu_dereference_raw(hlist_bl_next_rcu(pos))) + +/** +* hlist_bl_for_each_entry_continue_rcu - continue iteration over list of given +* type +* @tpos: the type * to use as a loop cursor. +* @pos: the &struct hlist_bl_node to use as a loop cursor. +* @member: the name of the hlist_bl_node within the struct. +* +* Continue to iterate over list of given type, continuing after +* the current position which must have been in the list when the RCU read +* lock was taken. +* This would typically require either that you obtained the node from a +* previous walk of the list in the same RCU read-side critical section, or +* that you held some sort of non-RCU reference (such as a reference count) +* to keep the node alive *and* in the list. +*/ +#define hlist_bl_for_each_entry_continue_rcu (tpos, pos, member) \ + for (pos = rcu_dereference_raw(hlist_bl_next_rcu(&(tpos)->member)); \ + pos && \ + ({ tpos = hlist_bl_entry(pos, typeof(*tpos), member); 1; }); \ + pos = rcu_dereference_raw(hlist_bl_next_rcu(pos)))#endif
Signature · 1 line
2.53.0
Julian Anastasov
maintainerPATCH 2/5 ipvs: add resizable hash tables
In reply to Julian AnastasovAdd infrastructure for resizable hash tables based on hlist_bl which we will use in followup patches.
The tables allow RCU lookups during resizing, bucket modifications are protected with per-bucket bit lock and additional custom locking, the tables are resized when load reaches thresholds determined based on load factor parameter.
--- include/net/ip_vs.h | 197 ++++++++++++++++++++++++++++++++ net/netfilter/ipvs/ip_vs_conn.c | 5 - net/netfilter/ipvs/ip_vs_core.c | 179 +++++++++++++++++++++++++++++ 3 files changed, 376 insertions(+), 5 deletions(-)
include/net/ip_vs.h +197 -0
@@ -11,6 +11,7 @@#include <asm/types.h> /* for __uXX types */ #include <linux/list.h> /* for struct list_head */ +#include <linux/rculist_bl.h> /* for struct hlist_bl_head */ #include <linux/spinlock.h> /* for struct rwlock_t */ #include <linux/atomic.h> /* for struct atomic_t */ #include <linux/refcount.h> /* for struct refcount_t */
@@ -30,6 +31,7 @@#endif #include <net/net_namespace.h> /* Netw namespace */ #include <linux/sched/isolation.h> +#include <linux/siphash.h> #define IP_VS_HDR_INVERSE 1#define IP_VS_HDR_ICMP 2
@@ -271,6 +273,10 @@ static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len, pr_err(msg, ##__VA_ARGS__); \ }while (0 ) +struct ip_vs_aligned_lock { +spinlock_t l;/* Protect buckets */ +}____cacheline_aligned_in_smp ; +/* For arrays per family */ enum {IP_VS_AF_INET ,
@@ -484,6 +490,197 @@ struct ip_vs_est_kt_data {int est_row;/* estimated row */ }; +/* IPVS resizable hash tables */ +struct ip_vs_rht { +struct hlist_bl_head *buckets; +struct ip_vs_rht __rcu *new_tbl;/* New/Same table */ +seqcount_t *seqc;/* Protects moves */ +struct ip_vs_aligned_lock *lock;/* Protect seqc */ +int mask;/* Buckets mask */ +int size;/* Buckets */ +int seqc_mask;/* seqc mask */ +int lock_mask;/* lock mask */ +u32 table_id; +int u_thresh;/* upper threshold */ +int l_thresh;/* lower threshold */ +int lfactor;/* Load Factor (shift)*/ +int bits;/* size = 1 << bits */ +siphash_key_t hash_key; +struct rcu_head rcu_head; +}; + +/** +* ip_vs_rht_for_each_table() - Walk the hash tables +* @table: struct ip_vs_rht __rcu *table +* @t: current table, used as cursor, struct ip_vs_rht *var +* @p: previous table, temp struct ip_vs_rht *var +* +* Walk tables assuming others can not change the installed tables +*/ +#define ip_vs_rht_for_each_table (table, t, p) \ + for (p = NULL, t = rcu_dereference_protected(table, 1); \ + t != p; \ + p = t, t = rcu_dereference_protected(t->new_tbl, 1)) + +/** +* ip_vs_rht_for_each_table_rcu() - Walk the hash tables under RCU reader lock +* @table: struct ip_vs_rht __rcu *table +* @t: current table, used as cursor, struct ip_vs_rht *var +* @p: previous table, temp struct ip_vs_rht *var +* +* We usually search in one table and also in second table on resizing +*/ +#define ip_vs_rht_for_each_table_rcu (table, t, p) \ + for (p = NULL, t = rcu_dereference(table); \ + t != p; \ + p = t, t = rcu_dereference(t->new_tbl)) + +/** +* ip_vs_rht_for_each_bucket() - Walk all table buckets +* @t: current table, used as cursor, struct ip_vs_rht *var +* @bucket: bucket index, used as cursor, u32 var +* @head: bucket address, used as cursor, struct hlist_bl_head *var +*/ +#define ip_vs_rht_for_each_bucket (t, bucket, head) \ + for (bucket = 0, head = (t)->buckets; \ + bucket < t->size; bucket++, head++) + +/** +* ip_vs_rht_for_bucket_retry() - Retry bucket if entries are moved +* @t: current table, used as cursor, struct ip_vs_rht *var +* @bucket: index of current bucket or hash key +* @sc: temp seqcount_t *var +* @retry: temp int var +*/ +#define ip_vs_rht_for_bucket_retry (t, bucket, sc, seq, retry) \ + for (retry = 1, sc = &(t)->seqc[(bucket) & (t)->seqc_mask]; \ + retry && ({ seq = read_seqcount_begin(sc); 1; }); \ + retry = read_seqcount_retry(sc, seq)) + +/** +* DECLARE_IP_VS_RHT_WALK_BUCKETS_RCU() - Declare variables +* +* Variables for ip_vs_rht_walk_buckets_rcu +*/ +#define DECLARE_IP_VS_RHT_WALK_BUCKETS_RCU () \ + struct ip_vs_rht *_t, *_p; \ + unsigned int _seq; \ + seqcount_t *_sc; \ + u32 _bucket; \ + int _retry +/** +* ip_vs_rht_walk_buckets_rcu() - Walk all buckets under RCU read lock +* @table: struct ip_vs_rht __rcu *table +* @head: bucket address, used as cursor, struct hlist_bl_head *var +* +* Can be used while others add/delete/move entries +* Not suitable if duplicates are not desired +* Possible cases for reader that uses cond_resched_rcu() in the loop: +* - new table can not be installed, no need to repeat +* - new table can be installed => check and repeat if new table is +* installed, needed for !PREEMPT_RCU +*/ +#define ip_vs_rht_walk_buckets_rcu (table, head) \ + ip_vs_rht_for_each_table_rcu(table, _t, _p) \ + ip_vs_rht_for_each_bucket(_t, _bucket, head) \ + ip_vs_rht_for_bucket_retry(_t, _bucket, _sc, \ + _seq, _retry) + +/** +* DECLARE_IP_VS_RHT_WALK_BUCKET_RCU() - Declare variables +* +* Variables for ip_vs_rht_walk_bucket_rcu +*/ +#define DECLARE_IP_VS_RHT_WALK_BUCKET_RCU () \ + unsigned int _seq; \ + seqcount_t *_sc; \ + int _retry +/** +* ip_vs_rht_walk_bucket_rcu() - Walk bucket under RCU read lock +* @t: current table, struct ip_vs_rht *var +* @bucket: index of current bucket or hash key +* @head: bucket address, used as cursor, struct hlist_bl_head *var +* +* Can be used while others add/delete/move entries +* Not suitable if duplicates are not desired +* Possible cases for reader that uses cond_resched_rcu() in the loop: +* - new table can not be installed, no need to repeat +* - new table can be installed => check and repeat if new table is +* installed, needed for !PREEMPT_RCU +*/ +#define ip_vs_rht_walk_bucket_rcu (t, bucket, head) \ + if (({ head = (t)->buckets + ((bucket) & (t)->mask); 0; })) \ + {} \ + else \ + ip_vs_rht_for_bucket_retry(t, (bucket), _sc, _seq, _retry) + +/** +* DECLARE_IP_VS_RHT_WALK_BUCKETS_SAFE_RCU() - Declare variables +* +* Variables for ip_vs_rht_walk_buckets_safe_rcu +*/ +#define DECLARE_IP_VS_RHT_WALK_BUCKETS_SAFE_RCU () \ + struct ip_vs_rht *_t, *_p; \ + u32 _bucket +/** +* ip_vs_rht_walk_buckets_safe_rcu() - Walk all buckets under RCU read lock +* @table: struct ip_vs_rht __rcu *table +* @head: bucket address, used as cursor, struct hlist_bl_head *var +* +* Can be used while others add/delete entries but moving is disabled +* Using cond_resched_rcu() should be safe if tables do not change +*/ +#define ip_vs_rht_walk_buckets_safe_rcu (table, head) \ + ip_vs_rht_for_each_table_rcu(table, _t, _p) \ + ip_vs_rht_for_each_bucket(_t, _bucket, head) + +/** +* DECLARE_IP_VS_RHT_WALK_BUCKETS() - Declare variables +* +* Variables for ip_vs_rht_walk_buckets +*/ +#define DECLARE_IP_VS_RHT_WALK_BUCKETS () \ + struct ip_vs_rht *_t, *_p; \ + u32 _bucket + +/** +* ip_vs_rht_walk_buckets() - Walk all buckets +* @table: struct ip_vs_rht __rcu *table +* @head: bucket address, used as cursor, struct hlist_bl_head *var +* +* Use if others can not add/delete/move entries +*/ +#define ip_vs_rht_walk_buckets (table, head) \ + ip_vs_rht_for_each_table(table, _t, _p) \ + ip_vs_rht_for_each_bucket(_t, _bucket, head) + +/* Entries can be in one of two tables, so we flip bit when new table is +* created and store it as highest bit in hash keys +*/ +#define IP_VS_RHT_TABLE_ID_MASK BIT(31) + +/* Check if hash key is from this table */ +static inline bool ip_vs_rht_same_table (struct ip_vs_rht *t,u32 hash_key) +{ +return !((t->table_id ^ hash_key) &IP_VS_RHT_TABLE_ID_MASK ); +} + +/* Build per-table hash key from hash value */ +static inline u32 ip_vs_rht_build_hash_key (struct ip_vs_rht *t,u32 hash) +{ +return t->table_id | (hash & ~IP_VS_RHT_TABLE_ID_MASK ); +} + +void ip_vs_rht_free (struct ip_vs_rht *t); +void ip_vs_rht_rcu_free (struct rcu_head *head); +struct ip_vs_rht *ip_vs_rht_alloc (int buckets,int scounts,int locks); +int ip_vs_rht_desired_size (struct netns_ipvs *ipvs,struct ip_vs_rht *t,int n, +int lfactor,int min_bits,int max_bits); +void ip_vs_rht_set_thresholds (struct ip_vs_rht *t,int size,int lfactor, +int min_bits,int max_bits); +u32 ip_vs_rht_hash_linfo (struct ip_vs_rht *t,int af, +const union nf_inet_addr *addr,u32 v1,u32 v2); +struct dst_entry ;struct iphdr ;struct ip_vs_conn ;
net/netfilter/ipvs/ip_vs_conn.c +0 -5
@@ -76,11 +76,6 @@ static unsigned int ip_vs_conn_rnd __read_mostly;#define IP_VS_ADDRSTRLEN (8+1)#endif -struct ip_vs_aligned_lock -{ -spinlock_t l; -} __attribute__((__aligned__ (SMP_CACHE_BYTES ))); -/* lock array for conn table */ static struct ip_vs_aligned_lock __ip_vs_conntbl_lock_array[CT_LOCKARRAY_SIZE] __cacheline_aligned;
net/netfilter/ipvs/ip_vs_core.c +179 -0
185 lines not on this page · raw message
Signature · 1 line
2.53.0
Florian Westphal
maintainerRe: [PATCH nf-next 2/5] ipvs: add resizable hash tables
include/net/ip_vs.h struct ip_vs_est_kt_data { · line 555
Quoted 8 lines · Julian Anastasov
include/net/ip_vs.h +8
-0+/** +* ip_vs_rht_for_bucket_retry() - Retry bucket if entries are moved +* @t: current table, used as cursor, struct ip_vs_rht *var +* @bucket: index of current bucket or hash key +* @sc: temp seqcount_t *var +* @retry: temp int var +*/ +#define ip_vs_rht_for_bucket_retry (t, bucket, sc, seq, retry) \
This triggers a small kdoc warning:
Warning: include/net/ip_vs.h:554 function parameter 'seq' not described in 'ip_vs_rht_for_bucket_retry'
Julian Anastasov
maintainerRe: [PATCH nf-next 2/5] ipvs: add resizable hash tables
Hello,
Quoted 12 lines · Florian Westphal
include/net/ip_vs.h struct ip_vs_est_kt_data { · line 555
Quoted 8 lines · Julian Anastasov
include/net/ip_vs.h +8
-0+/** +* ip_vs_rht_for_bucket_retry() - Retry bucket if entries are moved +* @t: current table, used as cursor, struct ip_vs_rht *var +* @bucket: index of current bucket or hash key +* @sc: temp seqcount_t *var +* @retry: temp int var +*/ +#define ip_vs_rht_for_bucket_retry (t, bucket, sc, seq, retry) \This triggers a small kdoc warning:
Quoted 1 line
Warning:
include/net/ip_vs.h:554function parameter 'seq' not described in 'ip_vs_rht_for_bucket_retry'
Will fix it, thanks! Just let me know if more comments
are expected before sending next version...
Regards
--
Julian Anastasov <[email protected]>
Florian Westphal
maintainerRe: [PATCH nf-next 2/5] ipvs: add resizable hash tables
Quoted 12 lines · Julian Anastasov
Quoted 12 lines
include/net/ip_vs.h struct ip_vs_est_kt_data { · line 555
Quoted 8 lines · Julian Anastasov
include/net/ip_vs.h +8
-0+/** +* ip_vs_rht_for_bucket_retry() - Retry bucket if entries are moved +* @t: current table, used as cursor, struct ip_vs_rht *var +* @bucket: index of current bucket or hash key +* @sc: temp seqcount_t *var +* @retry: temp int var +*/ +#define ip_vs_rht_for_bucket_retry (t, bucket, sc, seq, retry) \This triggers a small kdoc warning:
Quoted 4 lines
Quoted 1 line
Warning:
include/net/ip_vs.h:554function parameter 'seq' not described in 'ip_vs_rht_for_bucket_retry'Will fix it, thanks! Just let me know if more comments
are expected before sending next version...
There is some checkpatch noise in patch 1:
CHECK: Alignment should match open parenthesis
#42: FILE: include/linux/rculist_bl.h:24:
+ rcu_assign_pointer(hlist_bl_first_rcu(h),
(struct hlist_bl_node *)((unsigned long)n | LIST_BL_LOCKMASK));
CHECK: Macro argument 'member' may be better as '(member)' to avoid precedence issues #97: FILE: include/linux/rculist_bl.h:126:
+#define hlist_bl_for_each_entry_continue_rcu(tpos, pos, member) \
+ for (pos = rcu_dereference_raw(hlist_bl_next_rcu(&(tpos)->member)); \
+ pos && \
+ ({ tpos = hlist_bl_entry(pos, typeof(*tpos), member); 1; }); \
+ pos = rcu_dereference_raw(hlist_bl_next_rcu(pos)))And patch 2:
ERROR: Macros with complex values should be enclosed in parentheses #147: FILE: include/net/ip_vs.h:583:
+#define ip_vs_rht_walk_buckets_rcu(table, head) \
+ ip_vs_rht_for_each_table_rcu(table, _t, _p) \ + ip_vs_rht_for_each_bucket(_t, _bucket, head) \ + ip_vs_rht_for_bucket_retry(_t, _bucket, _sc, \
+ _seq, _retry)
BUT SEE:
do {} while (0) advice is over-stated in a few situations:
The more obvious case is macros, like MODULE_PARM_DESC, invoked at
[ there is more ]
... but I don't really care, you can handle/ignore it as you see fit.
I only have a question wrt. the hash table choice.
Why are you not re-using rhashtables and instead roll your own?
No requirement, but might make sense to mention the rationale in the commit message.
Thanks.
Julian Anastasov
maintainerRe: [PATCH nf-next 2/5] ipvs: add resizable hash tables
Hello,
Quoted 18 lines · Florian Westphal
Quoted 12 lines · Julian Anastasov
Quoted 12 lines
include/net/ip_vs.h struct ip_vs_est_kt_data { · line 555
Quoted 8 lines · Julian Anastasov
include/net/ip_vs.h +8
-0+/** +* ip_vs_rht_for_bucket_retry() - Retry bucket if entries are moved +* @t: current table, used as cursor, struct ip_vs_rht *var +* @bucket: index of current bucket or hash key +* @sc: temp seqcount_t *var +* @retry: temp int var +*/ +#define ip_vs_rht_for_bucket_retry (t, bucket, sc, seq, retry) \This triggers a small kdoc warning:
Quoted 4 lines
Quoted 1 line
Warning:
include/net/ip_vs.h:554function parameter 'seq' not described in 'ip_vs_rht_for_bucket_retry'Will fix it, thanks! Just let me know if more comments
are expected before sending next version...
Quoted 6 lines
There is some checkpatch noise in patch 1:
CHECK: Alignment should match open parenthesis
#42: FILE:include/linux/rculist_bl.h:24:
+ rcu_assign_pointer(hlist_bl_first_rcu(h),(struct hlist_bl_node *)((unsigned long)n | LIST_BL_LOCKMASK));
I don't change here any alignment and I didn't fixed it
because I'm not sure how to make it better :)
Review
Quoted 7 lines
CHECK: Macro argument 'member' may be better as '(member)' to avoid precedence issues #97: FILE:
include/linux/rculist_bl.h:126:(quoted diff) +5
-0+#define hlist_bl_for_each_entry_continue_rcu(tpos, pos, member) \ + for (pos = rcu_dereference_raw(hlist_bl_next_rcu(&(tpos)->member)); \ + pos && \ + ({ tpos = hlist_bl_entry(pos, typeof(*tpos), member); 1; }); \ + pos = rcu_dereference_raw(hlist_bl_next_rcu(pos)))
I think, this matches how all such macros use the member
field.
include/net/ip_vs.h struct ip_vs_est_kt_data { · line 587
Quoted 8 lines
And patch 2:
ERROR: Macros with complex values should be enclosed in parentheses #147: FILE:include/net/ip_vs.h:583:include/net/ip_vs.h +5
-0+#define ip_vs_rht_walk_buckets_rcu (table, head) \ + ip_vs_rht_for_each_table_rcu(table, _t, _p) \ + ip_vs_rht_for_each_bucket(_t, _bucket, head) \ + ip_vs_rht_for_bucket_retry(_t, _bucket, _sc, \ + _seq, _retry)
Yep, here we use complex macros to help the callers
use a loop with their statement/body. In the previous versions I checked the checkpatch output and due to the advanced macro usage I'm not sure what can be made better...
Quoted 9 lines
BUT SEE:
do {} while (0) advice is over-stated in a few situations:
The more obvious case is macros, like
MODULE_PARM_DESC, invoked at[ there is more ]
Quoted 8 lines
... but I don't really care, you can handle/ignore it as you see fit.
I only have a question wrt. the hash table choice.
Why are you not re-using rhashtables and instead roll your own?
No requirement, but might make sense to mention the rationale in the commit message.
I found the rhashtable_remove_fast operation slow by using
hashing+lookup. Also, IPVS needs to rehash (move) single entry when its key changes (cport in ip_vs_conn_fill_cport) and I don't see public method in rht for this. Things get complicated when we add double conn hashing, it needs careful move operation from one/two chains. Also, in part 4 of the changes we allow customizations for the load factor, in case the defaults are not suitable for the setup.
May be I can add more info in the commit message about this.
Regards
--
Julian Anastasov <[email protected]>
Florian Westphal
maintainerRe: [PATCH nf-next 2/5] ipvs: add resizable hash tables
Quoted 9 lines · Julian Anastasov
Quoted 6 lines
There is some checkpatch noise in patch 1:
CHECK: Alignment should match open parenthesis
#42: FILE:include/linux/rculist_bl.h:24:
+ rcu_assign_pointer(hlist_bl_first_rcu(h),(struct hlist_bl_node *)((unsigned long)n | LIST_BL_LOCKMASK));I don't change here any alignment and I didn't fixed it
because I'm not sure how to make it better :)
Thats fine, then just ignore it.
As I said, the checkpatch stuff isn't too imporant.
Quoted 13 lines
Quoted 4 lines
Why are you not re-using rhashtables and instead roll your own?
No requirement, but might make sense to mention the rationale in the commit message.
I found the
rhashtable_remove_fastoperation slow by using
hashing+lookup. Also, IPVS needs to rehash (move) single entry when its key changes (cport inip_vs_conn_fill_cport) and I don't see public method in rht for this. Things get complicated when we add double conn hashing, it needs careful move operation from one/two chains. Also, in part 4 of the changes we allow customizations for the load factor, in case the defaults are not suitable for the setup.
Quoted 1 line
May be I can add more info in the commit message about this.
Yes, I think your explanation makes sense, a small note/copypaste of the above into the commit message is enough.
Thanks!
Julian Anastasov
maintainerPATCH 3/5 ipvs: use resizable hash table for services
In reply to Julian AnastasovMake the hash table for services resizable in the bit range of 4-20. Table is attached only while services are present. Resizing is done by delayed work based on load (the number of hashed services). Table grows when load increases 2+ times (above 12.5% with lfactor=-3) and shrinks 8+ times when load decreases 16+ times (below 0.78%).
Switch to jhash hashing to reduce the collisions for multiple services.
Add a hash_key field into the service to store the table ID in the highest bit and the entry's hash value in the lowest bits. The lowest part of the hash value is used as bucket ID, the remaining part is used to filter the entries in the bucket before matching the keys and as result, helps the lookup operation to access only one cache line. By knowing the table ID and bucket ID for entry, we can unlink it without calculating the hash value and doing lookup by keys. We need only to validate the saved hash_key under lock.
--- include/net/ip_vs.h | 49 ++- net/netfilter/ipvs/ip_vs_ctl.c | 673 +++++++++++++++++++++++++++------ 2 files changed, 593 insertions(+), 129 deletions(-)
include/net/ip_vs.h +34 -15
@@ -35,12 +35,10 @@#define IP_VS_HDR_INVERSE 1#define IP_VS_HDR_ICMP 2 -/* -* Hash table: for virtual service lookups -*/ -#define IP_VS_SVC_TAB_BITS 8 -#define IP_VS_SVC_TAB_SIZE BIT(IP_VS_SVC_TAB_BITS) -#define IP_VS_SVC_TAB_MASK (IP_VS_SVC_TAB_SIZE - 1) + +/* svc_table limits */ +#define IP_VS_SVC_TAB_MIN_BITS 4 +#define IP_VS_SVC_TAB_MAX_BITS 20/* Generic access of ipvs struct */ static inline struct netns_ipvs *net_ipvs (struct net * net)
@@ -51,8 +49,6 @@ static inline struct netns_ipvs *net_ipvs(struct net* net)/* Connections' size value needed by ip_vs_ctl.c */ extern int ip_vs_conn_tab_size; -extern struct mutex __ip_vs_mutex; -struct ip_vs_iphdr {int hdr_flags;/* ipvs flags */ __u32 off;/* Where IP or IPv4 header starts */
@@ -289,6 +285,12 @@ static inline int ip_vs_af_index(int af)return af ==AF_INET6 ?IP_VS_AF_INET6 :IP_VS_AF_INET ; } +/* work_flags */ +enum { +IP_VS_WORK_SVC_RESIZE ,/* Schedule svc_resize_work */ +IP_VS_WORK_SVC_NORESIZE ,/* Stopping svc_resize_work */ +}; +/* The port number of FTP service (in network order). */ #define FTPPORT cpu_to_be16(21)#define FTPDATA cpu_to_be16(20)
@@ -888,14 +890,15 @@ struct ip_vs_dest_user_kern {* forwarding entries. */ struct ip_vs_service { -struct hlist_node s_list;/* node in service table */ -atomic_t refcnt;/* reference counter */ - +struct hlist_bl_node s_list;/* node in service table */ +u32 hash_key;/* Key for the hash table */ u16 af;/* address family */ __u16 protocol;/* which protocol (TCP/UDP) */ +union nf_inet_addr addr;/* IP address for virtual service */ -__be16 port;/* port number for the service */ __u32 fwmark;/* firewall mark of the service */ +atomic_t refcnt;/* reference counter */ +__be16 port;/* port number for the service */ unsigned int flags;/* service status flags */ unsigned int timeout;/* persistent timeout in ticks */ __be32 netmask;/* grouping granularity, mask/plen */
@@ -1154,6 +1157,10 @@ struct netns_ipvs {struct list_head dest_trash;spinlock_t dest_trash_lock;struct timer_list dest_trash_timer;/* expiration timer */ +struct mutex service_mutex;/* service reconfig */ +struct rw_semaphore svc_resize_sem;/* svc_table resizing */ +struct delayed_work svc_resize_work;/* resize svc_table */ +atomic_t svc_table_changes;/* ++ on new table */ /* Service counters */ atomic_t num_services[IP_VS_AF_MAX ];/* Services */ atomic_t fwm_services[IP_VS_AF_MAX ];/* Services */
@@ -1218,6 +1225,7 @@ struct netns_ipvs {int sysctl_est_nice;/* kthread nice */ int est_stopped;/* stop tasks */ #endif +int sysctl_svc_lfactor;/* ip_vs_lblc */ int sysctl_lblc_expiration;
@@ -1227,6 +1235,7 @@ struct netns_ipvs {int sysctl_lblcr_expiration;struct ctl_table_header *lblcr_ctl_header;struct ctl_table *lblcr_ctl_table; +unsigned long work_flags;/* IP_VS_WORK_* flags */ /* ip_vs_est */ struct delayed_work est_reload_work;/* Reload kthread tasks */ struct mutex est_mutex;/* protect kthread tasks */
@@ -1258,9 +1267,7 @@ struct netns_ipvs {unsigned int mixed_address_family_dests;unsigned int hooks_afmask;/* &1=AF_INET, &2=AF_INET6 */ -/* the service mutex that protect svc_table and svc_fwm_table */ -struct mutex service_mutex; -struct hlist_head svc_table[IP_VS_SVC_TAB_SIZE ];/* Services */ +struct ip_vs_rht __rcu *svc_table;/* Services */ };#define DEFAULT_SYNC_THRESHOLD 3
@@ -1510,6 +1517,18 @@ static inline int sysctl_est_nice(struct netns_ipvs *ipvs)#endif +/* Get load factor to map num_services/u_thresh to t->size +* Smaller value decreases u_thresh to reduce collisions but increases +* the table size +* Returns factor where: +* - <0: u_thresh = size >> -factor, eg. lfactor -2 = 25% load +* - >=0: u_thresh = size << factor, eg. lfactor 1 = 200% load +*/ +static inline int sysctl_svc_lfactor (struct netns_ipvs *ipvs) +{ +return READ_ONCE (ipvs->sysctl_svc_lfactor); +} +/* IPVS core functions * (from ip_vs_core.c) */
net/netfilter/ipvs/ip_vs_ctl.c +559 -114
918 lines not on this page · raw message
Signature · 1 line
2.53.0
Julian Anastasov
maintainerPATCH 4/5 ipvs: switch to per-net connection table
In reply to Julian AnastasovUse per-net resizable hash table for connections. The global table is slow to walk when using many namespaces.
The table can be resized in the range of [256 - ip_vs_conn_tab_size]. Table is attached only while services are present. Resizing is done by delayed work based on load (the number of connections).
Add a hash_key field into the connection to store the table ID in the highest bit and the entry's hash value in the lowest bits. The lowest part of the hash value is used as bucket ID, the remaining part is used to filter the entries in the bucket before matching the keys and as result, helps the lookup operation to access only one cache line. By knowing the table ID and bucket ID for entry, we can unlink it without calculating the hash value and doing lookup by keys. We need only to validate the saved hash_key under lock.
For better security switch from jhash to siphash for the default connection hashing but the persistence engines may use their own function. Keeping the hash table loaded with entries below the size (12%) allows to avoid collision for 96+% of the conns.
ip_vs_conn_fill_cport() now will rehash the connection with proper locking because unhash+hash is not safe for RCU readers.
To invalidate the templates setting just dport to 0xffff is enough, no need to rehash them. As result, ip_vs_conn_unhash() is now unused and removed.
--- include/net/ip_vs.h | 34 +- net/netfilter/ipvs/ip_vs_conn.c | 850 +++++++++++++++++++++--------- net/netfilter/ipvs/ip_vs_ctl.c | 18 + net/netfilter/ipvs/ip_vs_pe_sip.c | 4 +- net/netfilter/ipvs/ip_vs_sync.c | 23 + 5 files changed, 667 insertions(+), 262 deletions(-)
include/net/ip_vs.h +29 -5
@@ -36,6 +36,14 @@#define IP_VS_HDR_INVERSE 1#define IP_VS_HDR_ICMP 2 +/* conn_tab limits (as per Kconfig) */ +#define IP_VS_CONN_TAB_MIN_BITS 8 +#if BITS_PER_LONG >32 +#define IP_VS_CONN_TAB_MAX_BITS 27 +#else +#define IP_VS_CONN_TAB_MAX_BITS 20 +#endif +/* svc_table limits */ #define IP_VS_SVC_TAB_MIN_BITS 4#define IP_VS_SVC_TAB_MAX_BITS 20
@@ -289,6 +297,7 @@ static inline int ip_vs_af_index(int af)enum {IP_VS_WORK_SVC_RESIZE ,/* Schedule svc_resize_work */ IP_VS_WORK_SVC_NORESIZE ,/* Stopping svc_resize_work */ +IP_VS_WORK_CONN_RESIZE ,/* Schedule conn_resize_work */ };/* The port number of FTP service (in network order). */
@@ -778,18 +787,19 @@ struct ip_vs_conn_param {/* IP_VS structure allocated for each dynamically scheduled connection */ struct ip_vs_conn { -struct hlist_node c_list;/* hashed list heads */ +struct hlist_bl_node c_list;/* node in conn_tab */ +__u32 hash_key;/* Key for the hash table */ /* Protocol, addresses and port numbers */ __be16 cport;__be16 dport;__be16 vport;u16 af;/* address family */ +__u16 protocol;/* Which protocol (TCP/UDP) */ +__u16 daf;/* Address family of the dest */ union nf_inet_addr caddr;/* client address */ union nf_inet_addr vaddr;/* virtual address */ union nf_inet_addr daddr;/* destination address */ volatile __u32 flags;/* status flags */ -__u16 protocol;/* Which protocol (TCP/UDP) */ -__u16 daf;/* Address family of the dest */ struct netns_ipvs *ipvs;/* counter and timer */
@@ -1008,8 +1018,8 @@ struct ip_vs_pe {int (*fill_param)(struct ip_vs_conn_param *p,struct sk_buff *skb);bool (*ct_match)(const struct ip_vs_conn_param *p,struct ip_vs_conn *ct); -u32 (*hashkey_raw)(const struct ip_vs_conn_param *p,u32 initval, -bool inverse); +u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, +struct ip_vs_rht *t,bool inverse);int (*show_pe_data)(const struct ip_vs_conn *cp,char *buf);/* create connections for real-server outgoing packets */ struct ip_vs_conn* (*conn_out)(struct ip_vs_service *svc,
@@ -1149,6 +1159,7 @@ struct netns_ipvs {/* ip_vs_conn */ atomic_t conn_count;/* connection counter */ atomic_t no_cport_conns[IP_VS_AF_MAX ]; +struct delayed_work conn_resize_work;/* resize conn_tab */ /* ip_vs_ctl */ struct ip_vs_stats_rcu *tot_stats;/* Statistics & est. */
@@ -1225,6 +1236,7 @@ struct netns_ipvs {int sysctl_est_nice;/* kthread nice */ int est_stopped;/* stop tasks */ #endif +int sysctl_conn_lfactor;int sysctl_svc_lfactor;/* ip_vs_lblc */
@@ -1268,6 +1280,8 @@ struct netns_ipvs {unsigned int hooks_afmask;/* &1=AF_INET, &2=AF_INET6 */ struct ip_vs_rht __rcu *svc_table;/* Services */ +struct ip_vs_rht __rcu *conn_tab;/* Connections */ +atomic_t conn_tab_changes;/* ++ on new table */ };#define DEFAULT_SYNC_THRESHOLD 3
@@ -1517,6 +1531,12 @@ static inline int sysctl_est_nice(struct netns_ipvs *ipvs)#endif +/* Get load factor to map conn_count/u_thresh to t->size */ +static inline int sysctl_conn_lfactor (struct netns_ipvs *ipvs) +{ +return READ_ONCE (ipvs->sysctl_conn_lfactor); +} +/* Get load factor to map num_services/u_thresh to t->size * Smaller value decreases u_thresh to reduce collisions but increases * the table size
@@ -1602,6 +1622,10 @@ static inline void __ip_vs_conn_put(struct ip_vs_conn *cp) }void ip_vs_conn_put (struct ip_vs_conn *cp);void ip_vs_conn_fill_cport (struct ip_vs_conn *cp,__be16 cport); +int ip_vs_conn_desired_size (struct netns_ipvs *ipvs,struct ip_vs_rht *t, +int lfactor); +struct ip_vs_rht *ip_vs_conn_tab_alloc (struct netns_ipvs *ipvs,int buckets, +int lfactor); struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af, const union nf_inet_addr *daddr,
net/netfilter/ipvs/ip_vs_conn.c +595 -255
1,211 lines not on this page · raw message
net/netfilter/ipvs/ip_vs_ctl.c +18 -0
@@ -1643,6 +1643,7 @@ ip_vs_add_service(struct netns_ipvs *ipvs, struct ip_vs_service_user_kern *u, struct ip_vs_service **svc_p) {struct ip_vs_scheduler *sched =NULL ; +struct ip_vs_rht *tc_new =NULL ;struct ip_vs_rht *t, *t_new =NULL ;int af_id =ip_vs_af_index (u->af);struct ip_vs_service *svc =NULL ;
@@ -1702,6 +1703,17 @@ ip_vs_add_service(struct netns_ipvs *ipvs, struct ip_vs_service_user_kern *u, } } +if (!rcu_dereference_protected (ipvs->conn_tab,1 )) { +int lfactor =sysctl_conn_lfactor (ipvs); +int new_size =ip_vs_conn_desired_size (ipvs,NULL , lfactor); + + tc_new =ip_vs_conn_tab_alloc (ipvs, new_size, lfactor); +if (!tc_new) { + ret = -ENOMEM ; + goto out_err; + } + } +if (!atomic_read (&ipvs->num_services[af_id])) { ret =ip_vs_register_hooks (ipvs, u->af);if (ret <0 )
@@ -1752,6 +1764,10 @@ ip_vs_add_service(struct netns_ipvs *ipvs, struct ip_vs_service_user_kern *u,rcu_assign_pointer (ipvs->svc_table, t_new); t_new =NULL ; } +if (tc_new) { +rcu_assign_pointer (ipvs->conn_tab, tc_new); + tc_new =NULL ; + }/* Update the virtual service counters */ if (svc->port ==FTPPORT )
@@ -1794,6 +1810,8 @@ ip_vs_add_service(struct netns_ipvs *ipvs, struct ip_vs_service_user_kern *u, out_err: +if (tc_new) +ip_vs_rht_free (tc_new);if (t_new)ip_vs_rht_free (t_new);if (ret_hooks >=0 )
net/netfilter/ipvs/ip_vs_pe_sip.c +2 -2
@@ -132,9 +132,9 @@ static bool ip_vs_sip_ct_match(const struct ip_vs_conn_param *p, }static u32 ip_vs_sip_hashkey_raw (const struct ip_vs_conn_param *p, -u32 initval,bool inverse) +struct ip_vs_rht *t,bool inverse) { -return jhash (p->pe_data, p->pe_data_len, initval); +return jhash (p->pe_data, p->pe_data_len, (u32 )t->hash_key.key[0 ]); }static int ip_vs_sip_show_pe_data (const struct ip_vs_conn *cp,char *buf)
net/netfilter/ipvs/ip_vs_sync.c +23 -0
@@ -1755,6 +1755,28 @@ int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *c,if (!ip_vs_use_count_inc ())return -ENOPROTOOPT ; +/* Backup server can be started without services just to sync conns, +* make sure conn_tab is created even if ipvs->enable is 0. +*/ +if (state ==IP_VS_STATE_BACKUP ) { +mutex_lock (&ipvs->service_mutex); +if (!rcu_dereference_protected (ipvs->conn_tab,1 )) { +int lfactor =sysctl_conn_lfactor (ipvs); +int new_size =ip_vs_conn_desired_size (ipvs,NULL , + lfactor); +struct ip_vs_rht *tc_new; + + tc_new =ip_vs_conn_tab_alloc (ipvs, new_size, lfactor); +if (!tc_new) { +mutex_unlock (&ipvs->service_mutex); + result = -ENOMEM ; + goto out_module; + } +rcu_assign_pointer (ipvs->conn_tab, tc_new); + } +mutex_unlock (&ipvs->service_mutex); + } +/* Do not hold one mutex and then to block on another */ for (;;) {rtnl_lock ();
@@ -1923,6 +1945,7 @@ int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *c,mutex_unlock (&ipvs->sync_mutex);rtnl_unlock (); +out_module:/* decrease the module use count */ ip_vs_use_count_dec ();return result;
Signature · 1 line
2.53.0
Julian Anastasov
maintainerPATCH 5/5 ipvs: use more keys for connection hashing
In reply to Julian AnastasovSimon Kirby reported long time ago that IPVS connection hashing based only on the client address/port (caddr, cport) as hash keys is not suitable for setups that accept traffic on multiple virtual IPs and ports. It can happen for multiple VIP:VPORT services, for single or many fwmark service(s) that match multiple virtual IPs and ports or even for passive FTP with peristence in DR/TUN mode where we expect traffic on multiple ports for the virtual IP.
Fix it by adding virtual addresses and ports to the hash function. This causes the traffic from NAT real servers to clients to use second hashing for the in->out direction.
As result:
- the IN direction from client will use hash node hn0 where the source/dest addresses and ports used by client will be used as hash keys
- the OUT direction from NAT real servers will use hash node hn1 for the traffic from real server to client
- the persistence templates are hashed only with parameters based on the IN direction, so they now will also use the virtual address, port and fwmark from the service.
OLD:
- all methods: c_list node: proto, caddr:cport
- persistence templates: c_list node: proto, caddr_net:0
- persistence engine templates: c_list node: per-PE, PE-SIP uses jhash
NEW:
- all methods: hn0 node (dir 0): proto, caddr:cport -> vaddr:vport
- MASQ method: hn1 node (dir 1): proto, daddr:dport -> caddr:cport
- persistence templates: hn0 node (dir 0):
proto, caddr_net:0 -> vaddr:vport_or_0
proto, caddr_net:0 -> fwmark:0
- persistence engine templates: hn0 node (dir 0): as before
Also reorder the ip_vs_conn fields, so that hash nodes are on same read-mostly cache line while write-mostly fields are on separate cache line.
--- include/net/ip_vs.h | 104 +++++++----- net/netfilter/ipvs/ip_vs_conn.c | 271 ++++++++++++++++++++++++-------- 2 files changed, 275 insertions(+), 100 deletions(-)
include/net/ip_vs.h +69 -35
@@ -785,51 +785,48 @@ struct ip_vs_conn_param {__u8 pe_data_len; }; +/* Hash node in conn_tab */ +struct ip_vs_conn_hnode { +struct hlist_bl_node node;/* node in conn_tab */ +u32 hash_key;/* Key for the hash table */ +u8 dir;/* 0=out->in, 1=in->out */ +} __packed; +/* IP_VS structure allocated for each dynamically scheduled connection */ struct ip_vs_conn { -struct hlist_bl_node c_list;/* node in conn_tab */ -__u32 hash_key;/* Key for the hash table */ -/* Protocol, addresses and port numbers */ +/* Cacheline for hash table nodes - rarely modified */ + +struct ip_vs_conn_hnode hn0;/* Original direction */ +u8 af;/* address family */ __be16 cport; +struct ip_vs_conn_hnode hn1;/* Reply direction */ +u8 daf;/* Address family of the dest */ __be16 dport; -__be16 vport; -u16 af;/* address family */ -__u16 protocol;/* Which protocol (TCP/UDP) */ -__u16 daf;/* Address family of the dest */ -union nf_inet_addr caddr;/* client address */ -union nf_inet_addr vaddr;/* virtual address */ -union nf_inet_addr daddr;/* destination address */ +struct ip_vs_dest *dest;/* real server */ +atomic_t n_control;/* Number of controlled ones */ volatile __u32 flags;/* status flags */ -struct netns_ipvs *ipvs; - -/* counter and timer */ -refcount_t refcnt;/* reference count */ -struct timer_list timer;/* Expiration timer */ -volatile unsigned long timeout;/* timeout */ +/* 44/64 */ -/* Flags and state transition */ -spinlock_t lock;/* lock for state transition */ +struct ip_vs_conn *control;/* Master control connection */ +const struct ip_vs_pe *pe; +char *pe_data; +__u8 pe_data_len;volatile __u16 state;/* state info */ volatile __u16 old_state;/* old state, to be used for * state transition triggered * synchronization */ -__u32 fwmark;/* Fire wall mark from skb */ -unsigned long sync_endtime;/* jiffies + sent_retries */ +/* 2-byte hole */ +/* 64/96 */ -/* Control members */ -struct ip_vs_conn *control;/* Master control connection */ -atomic_t n_control;/* Number of controlled ones */ -struct ip_vs_dest *dest;/* real server */ -atomic_t in_pkts;/* incoming packet counter */ +union nf_inet_addr caddr;/* client address */ +union nf_inet_addr vaddr;/* virtual address */ +/* 96/128 */ -/* Packet transmitter for different forwarding methods. If it -* mangles the packet, it must return NF_DROP or better NF_STOLEN, -* otherwise this must be changed to a sk_buff **. -* NF_ACCEPT can be returned when destination is local. -*/ -int (*packet_xmit)(struct sk_buff *skb,struct ip_vs_conn *cp, -struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph); +union nf_inet_addr daddr;/* destination address */ +__u32 fwmark;/* Fire wall mark from skb */ +__be16 vport; +__u16 protocol;/* Which protocol (TCP/UDP) */ /* Note: we can group the following members into a structure, * in order to save more space, and the following members are
@@ -837,14 +834,31 @@ struct ip_vs_conn {*/ struct ip_vs_app *app;/* bound ip_vs_app object */ void *app_data;/* Application private data */ +/* 128/168 */ struct_group (sync_conn_opt, struct ip_vs_seq in_seq; /* incoming seq. struct */struct ip_vs_seq out_seq;/* outgoing seq. struct */ ); +/* 152/192 */ -const struct ip_vs_pe *pe; -char *pe_data; -__u8 pe_data_len; +struct timer_list timer;/* Expiration timer */ +volatile unsigned long timeout;/* timeout */ +spinlock_t lock;/* lock for state transition */ +refcount_t refcnt;/* reference count */ +atomic_t in_pkts;/* incoming packet counter */ +/* 64-bit: 4-byte gap */ + +/* 188/256 */ +unsigned long sync_endtime;/* jiffies + sent_retries */ +struct netns_ipvs *ipvs; + +/* Packet transmitter for different forwarding methods. If it +* mangles the packet, it must return NF_DROP or better NF_STOLEN, +* otherwise this must be changed to a sk_buff **. +* NF_ACCEPT can be returned when destination is local. +*/ +int (*packet_xmit)(struct sk_buff *skb,struct ip_vs_conn *cp, +struct ip_vs_protocol *pp,struct ip_vs_iphdr *iph);struct rcu_head rcu_head; };
@@ -1627,6 +1641,19 @@ int ip_vs_conn_desired_size(struct netns_ipvs *ipvs, struct ip_vs_rht *t,struct ip_vs_rht *ip_vs_conn_tab_alloc (struct netns_ipvs *ipvs,int buckets,int lfactor); +static inline struct ip_vs_conn * +ip_vs_hn0_to_conn (struct ip_vs_conn_hnode *hn) +{ + return container_of(hn, struct ip_vs_conn, hn0); +} + +static inline struct ip_vs_conn * +ip_vs_hn_to_conn (struct ip_vs_conn_hnode *hn) +{ + return hn->dir ? container_of(hn, struct ip_vs_conn, hn1) : + container_of(hn, struct ip_vs_conn, hn0); +} + struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af, const union nf_inet_addr *daddr, __be16 dport, unsigned int flags,
@@ -1979,6 +2006,13 @@ static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)return fwd; } +/* Check if connection uses double hashing */ +static inline bool ip_vs_conn_use_hash2 (struct ip_vs_conn *cp) +{ +return IP_VS_FWD_METHOD (cp) ==IP_VS_CONN_F_MASQ && + !(cp->flags &IP_VS_CONN_F_TEMPLATE ); +} +void ip_vs_nat_icmp (struct sk_buff *skb,struct ip_vs_protocol *pp,struct ip_vs_conn *cp,int dir);
net/netfilter/ipvs/ip_vs_conn.c +206 -65
592 lines not on this page · raw message
Signature · 1 line
2.53.0