Skip to content

Commit b822696

Browse files
Eric Garverdavem330
authored andcommitted
openvswitch: add ct_clear action
This adds a ct_clear action for clearing conntrack state. ct_clear is currently implemented in OVS userspace, but is not backed by an action in the kernel datapath. This is useful for flows that may modify a packet tuple after a ct lookup has already occurred. Signed-off-by: Eric Garver <e@erig.me> Acked-by: Pravin B Shelar <pshelar@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 833e0e2 commit b822696

5 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎include/uapi/linux/openvswitch.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,7 @@ struct ovs_action_push_eth {
807807
* packet.
808808
* @OVS_ACTION_ATTR_POP_ETH: Pop the outermost Ethernet header off the
809809
* packet.
810+
* @OVS_ACTION_ATTR_CT_CLEAR: Clear conntrack state from the packet.
810811
*
811812
* Only a single header can be set with a single %OVS_ACTION_ATTR_SET. Not all
812813
* fields within a header are modifiable, e.g. the IPv4 protocol and fragment
@@ -836,6 +837,7 @@ enum ovs_action_attr {
836837
OVS_ACTION_ATTR_TRUNC, /* u32 struct ovs_action_trunc. */
837838
OVS_ACTION_ATTR_PUSH_ETH, /* struct ovs_action_push_eth. */
838839
OVS_ACTION_ATTR_POP_ETH, /* No argument. */
840+
OVS_ACTION_ATTR_CT_CLEAR, /* No argument. */
839841

840842
__OVS_ACTION_ATTR_MAX, /* Nothing past this will be accepted
841843
* from userspace. */

‎net/openvswitch/actions.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,10 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
12031203
return err == -EINPROGRESS ? 0 : err;
12041204
break;
12051205

1206+
case OVS_ACTION_ATTR_CT_CLEAR:
1207+
err = ovs_ct_clear(skb, key);
1208+
break;
1209+
12061210
case OVS_ACTION_ATTR_PUSH_ETH:
12071211
err = push_eth(skb, key, nla_data(a));
12081212
break;

‎net/openvswitch/conntrack.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,17 @@ int ovs_ct_execute(struct net *net, struct sk_buff *skb,
11291129
return err;
11301130
}
11311131

1132+
int ovs_ct_clear(struct sk_buff *skb, struct sw_flow_key *key)
1133+
{
1134+
if (skb_nfct(skb)) {
1135+
nf_conntrack_put(skb_nfct(skb));
1136+
nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
1137+
ovs_ct_fill_key(skb, key);
1138+
}
1139+
1140+
return 0;
1141+
}
1142+
11321143
static int ovs_ct_add_helper(struct ovs_conntrack_info *info, const char *name,
11331144
const struct sw_flow_key *key, bool log)
11341145
{

‎net/openvswitch/conntrack.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ int ovs_ct_action_to_attr(const struct ovs_conntrack_info *, struct sk_buff *);
3030

3131
int ovs_ct_execute(struct net *, struct sk_buff *, struct sw_flow_key *,
3232
const struct ovs_conntrack_info *);
33+
int ovs_ct_clear(struct sk_buff *skb, struct sw_flow_key *key);
3334

3435
void ovs_ct_fill_key(const struct sk_buff *skb, struct sw_flow_key *key);
3536
int ovs_ct_put_key(const struct sw_flow_key *swkey,
@@ -73,6 +74,12 @@ static inline int ovs_ct_execute(struct net *net, struct sk_buff *skb,
7374
return -ENOTSUPP;
7475
}
7576

77+
static inline int ovs_ct_clear(struct sk_buff *skb,
78+
struct sw_flow_key *key)
79+
{
80+
return -ENOTSUPP;
81+
}
82+
7683
static inline void ovs_ct_fill_key(const struct sk_buff *skb,
7784
struct sw_flow_key *key)
7885
{

‎net/openvswitch/flow_netlink.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ static bool actions_may_change_flow(const struct nlattr *actions)
7676
break;
7777

7878
case OVS_ACTION_ATTR_CT:
79+
case OVS_ACTION_ATTR_CT_CLEAR:
7980
case OVS_ACTION_ATTR_HASH:
8081
case OVS_ACTION_ATTR_POP_ETH:
8182
case OVS_ACTION_ATTR_POP_MPLS:
@@ -2528,6 +2529,7 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
25282529
[OVS_ACTION_ATTR_SAMPLE] = (u32)-1,
25292530
[OVS_ACTION_ATTR_HASH] = sizeof(struct ovs_action_hash),
25302531
[OVS_ACTION_ATTR_CT] = (u32)-1,
2532+
[OVS_ACTION_ATTR_CT_CLEAR] = 0,
25312533
[OVS_ACTION_ATTR_TRUNC] = sizeof(struct ovs_action_trunc),
25322534
[OVS_ACTION_ATTR_PUSH_ETH] = sizeof(struct ovs_action_push_eth),
25332535
[OVS_ACTION_ATTR_POP_ETH] = 0,
@@ -2669,6 +2671,9 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
26692671
skip_copy = true;
26702672
break;
26712673

2674+
case OVS_ACTION_ATTR_CT_CLEAR:
2675+
break;
2676+
26722677
case OVS_ACTION_ATTR_PUSH_ETH:
26732678
/* Disallow pushing an Ethernet header if one
26742679
* is already present */

0 commit comments

Comments
 (0)