sFlow: Genericize/simplify kernel sFlow implementation
[sliver-openvswitch.git] / lib / dpif-netdev.c
index d0a50f3..926464e 100644 (file)
@@ -336,7 +336,7 @@ do_add_port(struct dp_netdev *dp, const char *devname, const char *type,
     int error;
 
     /* XXX reject devices already in some dp_netdev. */
-    if (type[0] == '\0' || !strcmp(type, "system")) {
+    if (type[0] == '\0' || !strcmp(type, "system") || !strcmp(type, "dummy")) {
         internal = false;
     } else if (!strcmp(type, "internal")) {
         internal = true;
@@ -378,8 +378,8 @@ do_add_port(struct dp_netdev *dp, const char *devname, const char *type,
     port->netdev = netdev;
     port->internal = internal;
 
-    netdev_get_mtu(netdev, &mtu);
-    if (mtu != INT_MAX && mtu > max_mtu) {
+    error = netdev_get_mtu(netdev, &mtu);
+    if (!error) {
         max_mtu = mtu;
     }
 
@@ -654,6 +654,12 @@ dpif_netdev_flow_from_nlattrs(const struct nlattr *key, uint32_t key_len,
         return EINVAL;
     }
 
+    if (flow->in_port < OFPP_MAX
+        ? flow->in_port >= MAX_PORTS
+        : flow->in_port != OFPP_LOCAL && flow->in_port != OFPP_NONE) {
+        return EINVAL;
+    }
+
     return 0;
 }
 
@@ -712,7 +718,7 @@ dpif_netdev_validate_actions(const struct nlattr *actions,
         case OVS_ACTION_ATTR_USERSPACE:
             break;
 
-        case OVS_ACTION_ATTR_SET_DL_TCI:
+        case OVS_ACTION_ATTR_PUSH_VLAN:
             *mutates = true;
             if (nl_attr_get_be16(a) & htons(VLAN_CFI)) {
                 return EINVAL;
@@ -726,7 +732,7 @@ dpif_netdev_validate_actions(const struct nlattr *actions,
             }
             break;
 
-        case OVS_ACTION_ATTR_STRIP_VLAN:
+        case OVS_ACTION_ATTR_POP_VLAN:
         case OVS_ACTION_ATTR_SET_DL_SRC:
         case OVS_ACTION_ATTR_SET_DL_DST:
         case OVS_ACTION_ATTR_SET_NW_SRC:
@@ -979,9 +985,11 @@ dpif_netdev_execute(struct dpif *dpif,
     }
 
     flow_extract(&copy, 0, -1, &key);
-    dpif_netdev_flow_from_nlattrs(key_attrs, key_len, &key);
-
-    error = dp_netdev_execute_actions(dp, &copy, &key, actions, actions_len);
+    error = dpif_netdev_flow_from_nlattrs(key_attrs, key_len, &key);
+    if (!error) {
+        error = dp_netdev_execute_actions(dp, &copy, &key,
+                                          actions, actions_len);
+    }
     if (mutates) {
         ofpbuf_uninit(&copy);
     }
@@ -1134,7 +1142,7 @@ dpif_netdev_wait(struct dpif *dpif)
 }
 
 static void
-dp_netdev_strip_vlan(struct ofpbuf *packet)
+dp_netdev_pop_vlan(struct ofpbuf *packet)
 {
     struct vlan_eth_header *veh = packet->l2;
     if (packet->size >= sizeof *veh
@@ -1306,12 +1314,12 @@ dp_netdev_execute_actions(struct dp_netdev *dp,
                                      key, nl_attr_get_u64(a));
             break;
 
-        case OVS_ACTION_ATTR_SET_DL_TCI:
-            eth_set_vlan_tci(packet, nl_attr_get_be16(a));
+        case OVS_ACTION_ATTR_PUSH_VLAN:
+            eth_push_vlan(packet, nl_attr_get_be16(a));
             break;
 
-        case OVS_ACTION_ATTR_STRIP_VLAN:
-            dp_netdev_strip_vlan(packet);
+        case OVS_ACTION_ATTR_POP_VLAN:
+            dp_netdev_pop_vlan(packet);
             break;
 
         case OVS_ACTION_ATTR_SET_DL_SRC:
@@ -1371,8 +1379,6 @@ const struct dpif_class dpif_netdev_class = {
     dpif_netdev_execute,
     dpif_netdev_recv_get_mask,
     dpif_netdev_recv_set_mask,
-    NULL,                       /* get_sflow_probability */
-    NULL,                       /* set_sflow_probability */
     NULL,                       /* queue_to_priority */
     dpif_netdev_recv,
     dpif_netdev_recv_wait,