Skip to content

Commit cb80d58

Browse files
Jarno Rajahalmedavem330
authored andcommitted
openvswitch: Unionize ovs_key_ct_label with a u32 array.
Make the array of labels in struct ovs_key_ct_label an union, adding a u32 array of the same byte size as the existing u8 array. It is faster to loop through the labels 32 bits at the time, which is also the alignment of netlink attributes. Signed-off-by: Jarno Rajahalme <[email protected]> Acked-by: Joe Stringer <[email protected]> Acked-by: Pravin B Shelar <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 193e309 commit cb80d58

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

include/uapi/linux/openvswitch.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,13 @@ struct ovs_key_nd {
446446
__u8 nd_tll[ETH_ALEN];
447447
};
448448

449-
#define OVS_CT_LABELS_LEN 16
449+
#define OVS_CT_LABELS_LEN_32 4
450+
#define OVS_CT_LABELS_LEN (OVS_CT_LABELS_LEN_32 * sizeof(__u32))
450451
struct ovs_key_ct_labels {
451-
__u8 ct_labels[OVS_CT_LABELS_LEN];
452+
union {
453+
__u8 ct_labels[OVS_CT_LABELS_LEN];
454+
__u32 ct_labels_32[OVS_CT_LABELS_LEN_32];
455+
};
452456
};
453457

454458
/* OVS_KEY_ATTR_CT_STATE flags */

net/openvswitch/conntrack.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,20 +281,21 @@ static int ovs_ct_set_labels(struct sk_buff *skb, struct sw_flow_key *key,
281281
/* Triggers a change event, which makes sense only for
282282
* confirmed connections.
283283
*/
284-
int err = nf_connlabels_replace(ct, (u32 *)labels, (u32 *)mask,
285-
OVS_CT_LABELS_LEN / sizeof(u32));
284+
int err = nf_connlabels_replace(ct, labels->ct_labels_32,
285+
mask->ct_labels_32,
286+
OVS_CT_LABELS_LEN_32);
286287
if (err)
287288
return err;
288289
} else {
289290
u32 *dst = (u32 *)cl->bits;
290-
const u32 *msk = (const u32 *)mask->ct_labels;
291-
const u32 *lbl = (const u32 *)labels->ct_labels;
291+
const u32 *msk = mask->ct_labels_32;
292+
const u32 *lbl = labels->ct_labels_32;
292293
int i;
293294

294295
/* No-one else has access to the non-confirmed entry, copy
295296
* labels over, keeping any bits we are not explicitly setting.
296297
*/
297-
for (i = 0; i < OVS_CT_LABELS_LEN / sizeof(u32); i++)
298+
for (i = 0; i < OVS_CT_LABELS_LEN_32; i++)
298299
dst[i] = (dst[i] & ~msk[i]) | (lbl[i] & msk[i]);
299300
}
300301

@@ -866,8 +867,8 @@ static bool labels_nonzero(const struct ovs_key_ct_labels *labels)
866867
{
867868
size_t i;
868869

869-
for (i = 0; i < sizeof(*labels); i++)
870-
if (labels->ct_labels[i])
870+
for (i = 0; i < OVS_CT_LABELS_LEN_32; i++)
871+
if (labels->ct_labels_32[i])
871872
return true;
872873

873874
return false;

0 commit comments

Comments
 (0)