- On flow entries with wildcards, match priority field when doing a "strict" delete.
[sliver-openvswitch.git] / datapath / forward.c
index 9c6b697..7ab2827 100644 (file)
@@ -21,9 +21,6 @@
 
 /* FIXME: do we need to use GFP_ATOMIC everywhere here? */
 
-static void execute_actions(struct datapath *, struct sk_buff *,
-                               const struct sw_flow_key *,
-                               const struct ofp_action *, int n_actions);
 static int make_writable(struct sk_buff **);
 
 static struct sk_buff *retrieve_skb(uint32_t id);
@@ -44,7 +41,7 @@ void fwd_port_input(struct sw_chain *chain, struct sk_buff *skb, int in_port)
                                flow->actions, flow->n_actions);
        } else {
                dp_output_control(chain->dp, skb, fwd_save_skb(skb), 
-                                 chain->dp->config.miss_send_len,
+                                 chain->dp->miss_send_len,
                                  OFPR_NO_MATCH);
        }
 }
@@ -60,7 +57,7 @@ static int do_output(struct datapath *dp, struct sk_buff *skb, size_t max_len,
                                         max_len, OFPR_ACTION));
 }
 
-static void execute_actions(struct datapath *dp, struct sk_buff *skb,
+void execute_actions(struct datapath *dp, struct sk_buff *skb,
                                const struct sw_flow_key *key,
                                const struct ofp_action *actions, int n_actions)
 {
@@ -278,7 +275,10 @@ recv_set_config(struct sw_chain *chain, const struct sender *sender,
                const void *msg)
 {
        const struct ofp_switch_config *osc = msg;
-       chain->dp->config = *osc;
+
+       chain->dp->flags = ntohs(osc->flags);
+       chain->dp->miss_send_len = ntohs(osc->miss_send_len);
+
        return 0;
 }
 
@@ -346,6 +346,7 @@ static int
 add_flow(struct sw_chain *chain, const struct ofp_flow_mod *ofm)
 {
        int error = -ENOMEM;
+       int i;
        int n_acts;
        struct sw_flow *flow;
 
@@ -357,6 +358,19 @@ add_flow(struct sw_chain *chain, const struct ofp_flow_mod *ofm)
                goto error;
        }
 
+       /* To prevent loops, make sure there's no action to send to the
+        * OFP_TABLE virtual port.
+        */
+       for (i=0; i<n_acts; i++) {
+               const struct ofp_action *a = &ofm->actions[i];
+
+               if (a->type == htons(OFPAT_OUTPUT) 
+                                       && a->arg.output.port == htons(OFPP_TABLE)) {
+                       /* xxx Send fancy new error message? */
+                       goto error;
+               }
+       }
+
        /* Allocate memory. */
        flow = flow_alloc(n_acts, GFP_ATOMIC);
        if (flow == NULL)
@@ -364,8 +378,8 @@ add_flow(struct sw_chain *chain, const struct ofp_flow_mod *ofm)
 
        /* Fill out flow. */
        flow_extract_match(&flow->key, &ofm->match);
-       flow->group_id = ntohl(ofm->group_id);
        flow->max_idle = ntohs(ofm->max_idle);
+       flow->priority = ntohs(ofm->priority);
        flow->timeout = jiffies + flow->max_idle * HZ;
        flow->n_actions = n_acts;
        flow->init_time = jiffies;
@@ -413,16 +427,30 @@ recv_flow(struct sw_chain *chain, const struct sender *sender, const void *msg)
        }  else if (command == OFPFC_DELETE) {
                struct sw_flow_key key;
                flow_extract_match(&key, &ofm->match);
-               return chain_delete(chain, &key, 0) ? 0 : -ESRCH;
+               return chain_delete(chain, &key, 0, 0) ? 0 : -ESRCH;
        } else if (command == OFPFC_DELETE_STRICT) {
                struct sw_flow_key key;
                flow_extract_match(&key, &ofm->match);
-               return chain_delete(chain, &key, 1) ? 0 : -ESRCH;
+               return chain_delete(chain, &key, ntohs(ofm->priority), 1) ? 0 : -ESRCH;
        } else {
                return -ENOTSUPP;
        }
 }
 
+static int
+recv_port_stats_request(struct sw_chain *chain, const struct sender *sender,
+                        const void *msg)
+{
+       return dp_send_port_stats(chain->dp, sender);
+}
+
+static int
+recv_table_stats_request(struct sw_chain *chain, const struct sender *sender,
+                         const void *msg)
+{
+       return dp_send_table_stats(chain->dp, sender);
+}
+
 /* 'msg', which is 'length' bytes long, was received across Netlink from
  * 'sender'.  Apply it to 'chain'. */
 int
@@ -461,13 +489,21 @@ fwd_control_input(struct sw_chain *chain, const struct sender *sender,
                        sizeof (struct ofp_port_mod),
                        recv_port_mod,
                },
+               [OFPT_PORT_STATS_REQUEST] = {
+                       sizeof (struct ofp_port_stats_request),
+                       recv_port_stats_request,
+               },
+               [OFPT_TABLE_STATS_REQUEST] = {
+                       sizeof (struct ofp_table_stats_request),
+                       recv_table_stats_request,
+               },
        };
 
        const struct openflow_packet *pkt;
        struct ofp_header *oh;
 
        oh = (struct ofp_header *) msg;
-       if (oh->version != 1 || oh->type >= ARRAY_SIZE(packets)
+       if (oh->version != OFP_VERSION || oh->type >= ARRAY_SIZE(packets)
                || ntohs(oh->length) > length)
                return -EINVAL;