openvswitch: Add meter action support
authorAndy Zhou <azhou@ovn.org>
Fri, 10 Nov 2017 20:09:43 +0000 (12:09 -0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 13 Nov 2017 01:37:07 +0000 (10:37 +0900)
Implements OVS kernel meter action support.

Signed-off-by: Andy Zhou <azhou@ovn.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/uapi/linux/openvswitch.h
net/openvswitch/actions.c
net/openvswitch/datapath.h
net/openvswitch/flow_netlink.c

index d60b9a4cf3d1df8ed2f5aef34d667e4ad0f397fe..4265d7f9e1f22da2a3b352cf13d2bf930f530c5d 100644 (file)
@@ -838,6 +838,8 @@ struct ovs_action_push_eth {
  * @OVS_ACTION_ATTR_CT_CLEAR: Clear conntrack state from the packet.
  * @OVS_ACTION_ATTR_PUSH_NSH: push NSH header to the packet.
  * @OVS_ACTION_ATTR_POP_NSH: pop the outermost NSH header off the packet.
+ * @OVS_ACTION_ATTR_METER: Run packet through a meter, which may drop the
+ * packet, or modify the packet (e.g., change the DSCP field).
  *
  * Only a single header can be set with a single %OVS_ACTION_ATTR_SET.  Not all
  * fields within a header are modifiable, e.g. the IPv4 protocol and fragment
@@ -870,6 +872,7 @@ enum ovs_action_attr {
        OVS_ACTION_ATTR_CT_CLEAR,     /* No argument. */
        OVS_ACTION_ATTR_PUSH_NSH,     /* Nested OVS_NSH_KEY_ATTR_*. */
        OVS_ACTION_ATTR_POP_NSH,      /* No argument. */
+       OVS_ACTION_ATTR_METER,        /* u32 meter ID. */
 
        __OVS_ACTION_ATTR_MAX,        /* Nothing past this will be accepted
                                       * from userspace. */
index 9a6a6d51e421fe1113700acd33e878f52a6a74e4..30a5df27116ec695d08bd4b57d8ee97b93822403 100644 (file)
@@ -1330,6 +1330,12 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
                case OVS_ACTION_ATTR_POP_NSH:
                        err = pop_nsh(skb, key);
                        break;
+
+               case OVS_ACTION_ATTR_METER:
+                       if (ovs_meter_execute(dp, skb, key, nla_get_u32(a))) {
+                               consume_skb(skb);
+                               return 0;
+                       }
                }
 
                if (unlikely(err)) {
index 5d2997b42460ad7b2349aacc8922693a60b3ee4d..523d65526766d31e2c815209d3498ae5449f3812 100644 (file)
@@ -30,6 +30,7 @@
 #include "conntrack.h"
 #include "flow.h"
 #include "flow_table.h"
+#include "meter.h"
 #include "vport-internal_dev.h"
 
 #define DP_MAX_PORTS           USHRT_MAX
index 4201f9293af3026755a211ab612a6c76634025bc..bb4dae198c788a4b195a1082054d10c552373b4b 100644 (file)
@@ -90,6 +90,7 @@ static bool actions_may_change_flow(const struct nlattr *actions)
                case OVS_ACTION_ATTR_SAMPLE:
                case OVS_ACTION_ATTR_SET:
                case OVS_ACTION_ATTR_SET_MASKED:
+               case OVS_ACTION_ATTR_METER:
                default:
                        return true;
                }
@@ -2844,6 +2845,7 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
                        [OVS_ACTION_ATTR_POP_ETH] = 0,
                        [OVS_ACTION_ATTR_PUSH_NSH] = (u32)-1,
                        [OVS_ACTION_ATTR_POP_NSH] = 0,
+                       [OVS_ACTION_ATTR_METER] = sizeof(u32),
                };
                const struct ovs_action_push_vlan *vlan;
                int type = nla_type(a);
@@ -3029,6 +3031,10 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
                        break;
                }
 
+               case OVS_ACTION_ATTR_METER:
+                       /* Non-existent meters are simply ignored.  */
+                       break;
+
                default:
                        OVS_NLERR(log, "Unknown Action type %d", type);
                        return -EINVAL;