Commit 09aa98ad authored by Jarno Rajahalme's avatar Jarno Rajahalme Committed by David S. Miller

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: 7f8a436e ("openvswitch: Add conntrack action")
Signed-off-by: default avatarJarno Rajahalme <jarno@ovn.org>
Acked-by: default avatarPravin B Shelar <pshelar@ovn.org>
Acked-by: default avatarJoe Stringer <joe@ovn.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6ffcea79
...@@ -73,6 +73,8 @@ struct ovs_conntrack_info { ...@@ -73,6 +73,8 @@ struct ovs_conntrack_info {
#endif #endif
}; };
static bool labels_nonzero(const struct ovs_key_ct_labels *labels);
static void __ovs_ct_free_action(struct ovs_conntrack_info *ct_info); static void __ovs_ct_free_action(struct ovs_conntrack_info *ct_info);
static u16 key_to_nfproto(const struct sw_flow_key *key) 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, ...@@ -270,18 +272,32 @@ static int ovs_ct_init_labels(struct nf_conn *ct, struct sw_flow_key *key,
const struct ovs_key_ct_labels *labels, const struct ovs_key_ct_labels *labels,
const struct ovs_key_ct_labels *mask) const struct ovs_key_ct_labels *mask)
{ {
struct nf_conn_labels *cl; struct nf_conn_labels *cl, *master_cl;
u32 *dst; bool have_mask = labels_nonzero(mask);
int i;
/* Inherit master's labels to the related connection? */
master_cl = ct->master ? nf_ct_labels_find(ct->master) : NULL;
if (!master_cl && !have_mask)
return 0; /* Nothing to do. */
cl = ovs_ct_get_conn_labels(ct); cl = ovs_ct_get_conn_labels(ct);
if (!cl) if (!cl)
return -ENOSPC; return -ENOSPC;
dst = (u32 *)cl->bits; /* Inherit the master's labels, if any. */
if (master_cl)
*cl = *master_cl;
if (have_mask) {
u32 *dst = (u32 *)cl->bits;
int i;
for (i = 0; i < OVS_CT_LABELS_LEN_32; i++) for (i = 0; i < OVS_CT_LABELS_LEN_32; i++)
dst[i] = (dst[i] & ~mask->ct_labels_32[i]) | dst[i] = (dst[i] & ~mask->ct_labels_32[i]) |
(labels->ct_labels_32[i] & mask->ct_labels_32[i]); (labels->ct_labels_32[i]
& mask->ct_labels_32[i]);
}
memcpy(&key->ct.labels, cl->bits, OVS_CT_LABELS_LEN); memcpy(&key->ct.labels, cl->bits, OVS_CT_LABELS_LEN);
...@@ -909,11 +925,12 @@ static int ovs_ct_commit(struct net *net, struct sw_flow_key *key, ...@@ -909,11 +925,12 @@ static int ovs_ct_commit(struct net *net, struct sw_flow_key *key,
if (err) if (err)
return err; return err;
} }
if (labels_nonzero(&info->labels.mask)) { if (!nf_ct_is_confirmed(ct)) {
if (!nf_ct_is_confirmed(ct))
err = ovs_ct_init_labels(ct, key, &info->labels.value, err = ovs_ct_init_labels(ct, key, &info->labels.value,
&info->labels.mask); &info->labels.mask);
else if (err)
return err;
} else if (labels_nonzero(&info->labels.mask)) {
err = ovs_ct_set_labels(ct, key, &info->labels.value, err = ovs_ct_set_labels(ct, key, &info->labels.value,
&info->labels.mask); &info->labels.mask);
if (err) if (err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment