Skip to content

Commit b87cec3

Browse files
Jarno Rajahalmedavem330
authored andcommitted
openvswitch: Simplify labels length logic.
Since 2301401 ("netfilter: conntrack: support a fixed size of 128 distinct labels"), the size of conntrack labels extension has fixed to 128 bits, so we do not need to check for labels sizes shorter than 128 at run-time. This patch simplifies labels length logic accordingly, but allows the conntrack labels size to be increased in the future without breaking the build. In the event of conntrack labels increasing in size OVS would still be able to deal with the 128 first label bits. Suggested-by: Joe Stringer <[email protected]> Signed-off-by: Jarno Rajahalme <[email protected]> Acked-by: Pravin B Shelar <[email protected]> Acked-by: Joe Stringer <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cb80d58 commit b87cec3

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

net/openvswitch/conntrack.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,20 @@ static u32 ovs_ct_get_mark(const struct nf_conn *ct)
129129
#endif
130130
}
131131

132+
/* Guard against conntrack labels max size shrinking below 128 bits. */
133+
#if NF_CT_LABELS_MAX_SIZE < 16
134+
#error NF_CT_LABELS_MAX_SIZE must be at least 16 bytes
135+
#endif
136+
132137
static void ovs_ct_get_labels(const struct nf_conn *ct,
133138
struct ovs_key_ct_labels *labels)
134139
{
135140
struct nf_conn_labels *cl = ct ? nf_ct_labels_find(ct) : NULL;
136141

137-
if (cl) {
138-
size_t len = sizeof(cl->bits);
139-
140-
if (len > OVS_CT_LABELS_LEN)
141-
len = OVS_CT_LABELS_LEN;
142-
else if (len < OVS_CT_LABELS_LEN)
143-
memset(labels, 0, OVS_CT_LABELS_LEN);
144-
memcpy(labels, cl->bits, len);
145-
} else {
142+
if (cl)
143+
memcpy(labels, cl->bits, OVS_CT_LABELS_LEN);
144+
else
146145
memset(labels, 0, OVS_CT_LABELS_LEN);
147-
}
148146
}
149147

150148
static void __ovs_ct_update_key(struct sw_flow_key *key, u8 state,
@@ -274,7 +272,7 @@ static int ovs_ct_set_labels(struct sk_buff *skb, struct sw_flow_key *key,
274272
nf_ct_labels_ext_add(ct);
275273
cl = nf_ct_labels_find(ct);
276274
}
277-
if (!cl || sizeof(cl->bits) < OVS_CT_LABELS_LEN)
275+
if (!cl)
278276
return -ENOSPC;
279277

280278
if (nf_ct_is_confirmed(ct)) {

0 commit comments

Comments
 (0)