Add support for listing and deleting entries based on an output port.
[sliver-openvswitch.git] / datapath / table-hash.c
index 86e1920..21a49f9 100644 (file)
@@ -113,8 +113,8 @@ static int do_delete(struct sw_flow **bucket, struct sw_flow *flow)
  * argument, since all exact-match entries are the same (highest)
  * priority. */
 static int table_hash_delete(struct sw_table *swt,
-                                                        const struct sw_flow_key *key
-                                                        uint16_t priority, int strict)
+                                       const struct sw_flow_key *key,  uint16_t out_port
+                                       uint16_t priority, int strict)
 {
        struct sw_table_hash *th = (struct sw_table_hash *) swt;
        unsigned int count = 0;
@@ -122,7 +122,8 @@ static int table_hash_delete(struct sw_table *swt,
        if (key->wildcards == 0) {
                struct sw_flow **bucket = find_bucket(swt, key);
                struct sw_flow *flow = *bucket;
-               if (flow && flow_keys_equal(&flow->key, key))
+               if (flow && flow_keys_equal(&flow->key, key)
+                               && flow_has_out_port(flow, out_port))
                        count = do_delete(bucket, flow);
        } else {
                unsigned int i;
@@ -130,7 +131,8 @@ static int table_hash_delete(struct sw_table *swt,
                for (i = 0; i <= th->bucket_mask; i++) {
                        struct sw_flow **bucket = &th->buckets[i];
                        struct sw_flow *flow = *bucket;
-                       if (flow && flow_matches_desc(&flow->key, key, strict))
+                       if (flow && flow_matches_desc(&flow->key, key, strict)
+                                       && flow_has_out_port(flow, out_port))
                                count += do_delete(bucket, flow);
                }
        }
@@ -174,7 +176,7 @@ static void table_hash_destroy(struct sw_table *swt)
 }
 
 static int table_hash_iterate(struct sw_table *swt,
-                             const struct sw_flow_key *key,
+                             const struct sw_flow_key *key, uint16_t out_port,
                              struct sw_table_position *position,
                              int (*callback)(struct sw_flow *, void *private),
                              void *private) 
@@ -189,7 +191,7 @@ static int table_hash_iterate(struct sw_table *swt,
                int error;
 
                flow = table_hash_lookup(swt, key);
-               if (!flow)
+               if (!flow || !flow_has_out_port(flow, out_port))
                        return 0;
 
                error = callback(flow, private);
@@ -201,7 +203,8 @@ static int table_hash_iterate(struct sw_table *swt,
 
                for (i = position->private[0]; i <= th->bucket_mask; i++) {
                        struct sw_flow *flow = th->buckets[i];
-                       if (flow && flow_matches_1wild(&flow->key, key)) {
+                       if (flow && flow_matches_1wild(&flow->key, key)
+                                       && flow_has_out_port(flow, out_port)) {
                                int error = callback(flow, private);
                                if (error) {
                                        position->private[0] = i;
@@ -301,11 +304,13 @@ static int table_hash2_modify(struct sw_table *swt,
 
 static int table_hash2_delete(struct sw_table *swt,
                                                          const struct sw_flow_key *key, 
+                                                         uint16_t out_port,
                                                          uint16_t priority, int strict)
 {
        struct sw_table_hash2 *t2 = (struct sw_table_hash2 *) swt;
-       return (table_hash_delete(t2->subtable[0], key, priority, strict)
-                       + table_hash_delete(t2->subtable[1], key, priority, strict));
+       return (table_hash_delete(t2->subtable[0], key, out_port, priority, strict)
+                       + table_hash_delete(t2->subtable[1], key, out_port, 
+                               priority, strict));
 }
 
 static int table_hash2_timeout(struct datapath *dp, struct sw_table *swt)
@@ -324,7 +329,7 @@ static void table_hash2_destroy(struct sw_table *swt)
 }
 
 static int table_hash2_iterate(struct sw_table *swt,
-                              const struct sw_flow_key *key,
+                              const struct sw_flow_key *key, uint16_t out_port,
                               struct sw_table_position *position,
                               int (*callback)(struct sw_flow *, void *),
                               void *private)
@@ -333,8 +338,8 @@ static int table_hash2_iterate(struct sw_table *swt,
        int i;
 
        for (i = position->private[1]; i < 2; i++) {
-               int error = table_hash_iterate(t2->subtable[i], key, position,
-                                              callback, private);
+               int error = table_hash_iterate(t2->subtable[i], key, out_port, 
+                               position, callback, private);
                if (error) {
                        return error;
                }