Skip to content

Commit 09aa98a

Browse files
Jarno Rajahalmedavem330
authored andcommitted
openvswitch: Inherit master's labels.
We avoid calling into nf_conntrack_in() for expected connections, as that would remove the expectation that we want to stick around until we are ready to commit the connection. Instead, we do a lookup in the expectation table directly. However, after a successful expectation lookup we have set the flow key label field from the master connection, whereas nf_conntrack_in() does not do this. This leads to master's labels being inherited after an expectation lookup, but those labels not being inherited after the corresponding conntrack action with a commit flag. This patch resolves the problem by changing the commit code path to also inherit the master's labels to the expected connection. Resolving this conflict in favor of inheriting the labels allows more information be passed from the master connection to related connections, which would otherwise be much harder if the 32 bits in the connmark are not enough. Labels can still be set explicitly, so this change only affects the default values of the labels in presense of a master connection. Fixes: 7f8a436 ("openvswitch: Add conntrack action") 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 6ffcea7 commit 09aa98a

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

net/openvswitch/conntrack.c

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ struct ovs_conntrack_info {
7373
#endif
7474
};
7575

76+
static bool labels_nonzero(const struct ovs_key_ct_labels *labels);
77+
7678
static void __ovs_ct_free_action(struct ovs_conntrack_info *ct_info);
7779

7880
static u16 key_to_nfproto(const struct sw_flow_key *key)
@@ -270,18 +272,32 @@ static int ovs_ct_init_labels(struct nf_conn *ct, struct sw_flow_key *key,
270272
const struct ovs_key_ct_labels *labels,
271273
const struct ovs_key_ct_labels *mask)
272274
{
273-
struct nf_conn_labels *cl;
274-
u32 *dst;
275-
int i;
275+
struct nf_conn_labels *cl, *master_cl;
276+
bool have_mask = labels_nonzero(mask);
277+
278+
/* Inherit master's labels to the related connection? */
279+
master_cl = ct->master ? nf_ct_labels_find(ct->master) : NULL;
280+
281+
if (!master_cl && !have_mask)
282+
return 0; /* Nothing to do. */
276283

277284
cl = ovs_ct_get_conn_labels(ct);
278285
if (!cl)
279286
return -ENOSPC;
280287

281-
dst = (u32 *)cl->bits;
282-
for (i = 0; i < OVS_CT_LABELS_LEN_32; i++)
283-
dst[i] = (dst[i] & ~mask->ct_labels_32[i]) |
284-
(labels->ct_labels_32[i] & mask->ct_labels_32[i]);
288+
/* Inherit the master's labels, if any. */
289+
if (master_cl)
290+
*cl = *master_cl;
291+
292+
if (have_mask) {
293+
u32 *dst = (u32 *)cl->bits;
294+
int i;
295+
296+
for (i = 0; i < OVS_CT_LABELS_LEN_32; i++)
297+
dst[i] = (dst[i] & ~mask->ct_labels_32[i]) |
298+
(labels->ct_labels_32[i]
299+
& mask->ct_labels_32[i]);
300+
}
285301

286302
memcpy(&key->ct.labels, cl->bits, OVS_CT_LABELS_LEN);
287303

@@ -909,13 +925,14 @@ static int ovs_ct_commit(struct net *net, struct sw_flow_key *key,
909925
if (err)
910926
return err;
911927
}
912-
if (labels_nonzero(&info->labels.mask)) {
913-
if (!nf_ct_is_confirmed(ct))
914-
err = ovs_ct_init_labels(ct, key, &info->labels.value,
915-
&info->labels.mask);
916-
else
917-
err = ovs_ct_set_labels(ct, key, &info->labels.value,
918-
&info->labels.mask);
928+
if (!nf_ct_is_confirmed(ct)) {
929+
err = ovs_ct_init_labels(ct, key, &info->labels.value,
930+
&info->labels.mask);
931+
if (err)
932+
return err;
933+
} else if (labels_nonzero(&info->labels.mask)) {
934+
err = ovs_ct_set_labels(ct, key, &info->labels.value,
935+
&info->labels.mask);
919936
if (err)
920937
return err;
921938
}

0 commit comments

Comments
 (0)