mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
netfilter: conntrack: support a fixed size of 128 distinct labels
The conntrack label extension is currently variable-sized, e.g. if
only 2 labels are used by iptables rules then the labels->bits[] array
will only contain one element.
We track size of each label storage area in the 'words' member.
But in nftables and openvswitch we always have to ask for worst-case
since we don't know what bit will be used at configuration time.
As most arches are 64bit we need to allocate 24 bytes in this case:
struct nf_conn_labels {
u8 words; /* 0 1 */
/* XXX 7 bytes hole, try to pack */
long unsigned bits[2]; /* 8 24 */
Make bits a fixed size and drop the words member, it simplifies
the code and only increases memory requirements on x86 when
less than 64bit labels are required.
We still only allocate the extension if its needed.
Signed-off-by: Florian Westphal <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
This commit is contained in:
parent
6e1f760e13
commit
23014011ba
6 changed files with 18 additions and 40 deletions
|
|
@ -10,8 +10,7 @@
|
|||
#define NF_CT_LABELS_MAX_SIZE ((XT_CONNLABEL_MAXBIT + 1) / BITS_PER_BYTE)
|
||||
|
||||
struct nf_conn_labels {
|
||||
u8 words;
|
||||
unsigned long bits[];
|
||||
unsigned long bits[NF_CT_LABELS_MAX_SIZE / sizeof(long)];
|
||||
};
|
||||
|
||||
static inline struct nf_conn_labels *nf_ct_labels_find(const struct nf_conn *ct)
|
||||
|
|
@ -26,20 +25,13 @@ static inline struct nf_conn_labels *nf_ct_labels_find(const struct nf_conn *ct)
|
|||
static inline struct nf_conn_labels *nf_ct_labels_ext_add(struct nf_conn *ct)
|
||||
{
|
||||
#ifdef CONFIG_NF_CONNTRACK_LABELS
|
||||
struct nf_conn_labels *cl_ext;
|
||||
struct net *net = nf_ct_net(ct);
|
||||
u8 words;
|
||||
|
||||
words = ACCESS_ONCE(net->ct.label_words);
|
||||
if (words == 0)
|
||||
if (net->ct.labels_used == 0)
|
||||
return NULL;
|
||||
|
||||
cl_ext = nf_ct_ext_add_length(ct, NF_CT_EXT_LABELS,
|
||||
words * sizeof(long), GFP_ATOMIC);
|
||||
if (cl_ext != NULL)
|
||||
cl_ext->words = words;
|
||||
|
||||
return cl_ext;
|
||||
return nf_ct_ext_add_length(ct, NF_CT_EXT_LABELS,
|
||||
sizeof(struct nf_conn_labels), GFP_ATOMIC);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue