Skip to content

Commit cd8a6c3

Browse files
azhou-niciradavem330
authored andcommitted
openvswitch: Add meter action support
Implements OVS kernel meter action support. Signed-off-by: Andy Zhou <azhou@ovn.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 96fbc13 commit cd8a6c3

4 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎include/uapi/linux/openvswitch.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,8 @@ struct ovs_action_push_eth {
838838
* @OVS_ACTION_ATTR_CT_CLEAR: Clear conntrack state from the packet.
839839
* @OVS_ACTION_ATTR_PUSH_NSH: push NSH header to the packet.
840840
* @OVS_ACTION_ATTR_POP_NSH: pop the outermost NSH header off the packet.
841+
* @OVS_ACTION_ATTR_METER: Run packet through a meter, which may drop the
842+
* packet, or modify the packet (e.g., change the DSCP field).
841843
*
842844
* Only a single header can be set with a single %OVS_ACTION_ATTR_SET. Not all
843845
* fields within a header are modifiable, e.g. the IPv4 protocol and fragment
@@ -870,6 +872,7 @@ enum ovs_action_attr {
870872
OVS_ACTION_ATTR_CT_CLEAR, /* No argument. */
871873
OVS_ACTION_ATTR_PUSH_NSH, /* Nested OVS_NSH_KEY_ATTR_*. */
872874
OVS_ACTION_ATTR_POP_NSH, /* No argument. */
875+
OVS_ACTION_ATTR_METER, /* u32 meter ID. */
873876

874877
__OVS_ACTION_ATTR_MAX, /* Nothing past this will be accepted
875878
* from userspace. */

‎net/openvswitch/actions.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,12 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
13301330
case OVS_ACTION_ATTR_POP_NSH:
13311331
err = pop_nsh(skb, key);
13321332
break;
1333+
1334+
case OVS_ACTION_ATTR_METER:
1335+
if (ovs_meter_execute(dp, skb, key, nla_get_u32(a))) {
1336+
consume_skb(skb);
1337+
return 0;
1338+
}
13331339
}
13341340

13351341
if (unlikely(err)) {

‎net/openvswitch/datapath.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "conntrack.h"
3131
#include "flow.h"
3232
#include "flow_table.h"
33+
#include "meter.h"
3334
#include "vport-internal_dev.h"
3435

3536
#define DP_MAX_PORTS USHRT_MAX

‎net/openvswitch/flow_netlink.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ static bool actions_may_change_flow(const struct nlattr *actions)
9090
case OVS_ACTION_ATTR_SAMPLE:
9191
case OVS_ACTION_ATTR_SET:
9292
case OVS_ACTION_ATTR_SET_MASKED:
93+
case OVS_ACTION_ATTR_METER:
9394
default:
9495
return true;
9596
}
@@ -2844,6 +2845,7 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
28442845
[OVS_ACTION_ATTR_POP_ETH] = 0,
28452846
[OVS_ACTION_ATTR_PUSH_NSH] = (u32)-1,
28462847
[OVS_ACTION_ATTR_POP_NSH] = 0,
2848+
[OVS_ACTION_ATTR_METER] = sizeof(u32),
28472849
};
28482850
const struct ovs_action_push_vlan *vlan;
28492851
int type = nla_type(a);
@@ -3029,6 +3031,10 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
30293031
break;
30303032
}
30313033

3034+
case OVS_ACTION_ATTR_METER:
3035+
/* Non-existent meters are simply ignored. */
3036+
break;
3037+
30323038
default:
30333039
OVS_NLERR(log, "Unknown Action type %d", type);
30343040
return -EINVAL;

0 commit comments

Comments
 (0)