Fix "make dist" by adding forgotten files to sources lists.
[sliver-openvswitch.git] / switch / datapath.c
index 4321f94..452d471 100644 (file)
@@ -44,7 +44,7 @@
 #include "list.h"
 #include "netdev.h"
 #include "ofpbuf.h"
-#include "openflow.h"
+#include "openflow/openflow.h"
 #include "packets.h"
 #include "poll-loop.h"
 #include "rconn.h"
@@ -116,6 +116,9 @@ struct remote {
     void *cb_aux;
 };
 
+#define DP_MAX_PORTS 255
+BUILD_ASSERT_DECL(DP_MAX_PORTS <= OFPP_MAX);
+
 struct datapath {
     /* Remote connections. */
     struct remote *controller;  /* Connection to controller. */
@@ -134,7 +137,7 @@ struct datapath {
     uint16_t miss_send_len;
 
     /* Switch ports. */
-    struct sw_port ports[OFPP_MAX];
+    struct sw_port ports[DP_MAX_PORTS];
     struct list port_list; /* List of ports, for flooding. */
 };
 
@@ -533,7 +536,7 @@ output_all(struct datapath *dp, struct ofpbuf *buffer, int in_port, int flood)
 void
 output_packet(struct datapath *dp, struct ofpbuf *buffer, int out_port) 
 {
-    if (out_port >= 0 && out_port < OFPP_MAX) { 
+    if (out_port >= 0 && out_port < DP_MAX_PORTS) { 
         struct sw_port *p = &dp->ports[out_port];
         if (p->netdev != NULL && !(p->config & OFPPC_PORT_DOWN)) {
             if (!netdev_send(p->netdev, buffer)) {
@@ -567,7 +570,7 @@ dp_output_port(struct datapath *dp, struct ofpbuf *buffer,
     } else if (out_port == OFPP_IN_PORT) {
         output_packet(dp, buffer, in_port);
     } else if (out_port == OFPP_TABLE) {
-        struct sw_port *p = in_port < OFPP_MAX ? &dp->ports[in_port] : 0;
+        struct sw_port *p = in_port < DP_MAX_PORTS ? &dp->ports[in_port] : 0;
                if (run_flow_through_tables(dp, buffer, p)) {
                        ofpbuf_delete(buffer);
         }
@@ -671,8 +674,7 @@ dp_send_features_reply(struct datapath *dp, const struct sender *sender)
     ofr->capabilities = htonl(OFP_SUPPORTED_CAPABILITIES);
     ofr->actions      = htonl(OFP_SUPPORTED_ACTIONS);
     LIST_FOR_EACH (p, struct sw_port, node, &dp->port_list) {
-        struct ofp_phy_port *opp = ofpbuf_put_uninit(buffer, sizeof *opp);
-        memset(opp, 0, sizeof *opp);
+        struct ofp_phy_port *opp = ofpbuf_put_zeros(buffer, sizeof *opp);
         fill_port_desc(dp, p, opp);
     }
     send_openflow_buffer(dp, buffer, sender);
@@ -682,7 +684,7 @@ void
 dp_update_port_flags(struct datapath *dp, const struct ofp_port_mod *opm)
 {
     int port_no = ntohs(opm->port_no);
-    if (port_no < OFPP_MAX) {
+    if (port_no < DP_MAX_PORTS) {
         struct sw_port *p = &dp->ports[port_no];
 
         /* Make sure the port id hasn't changed since this was sent */
@@ -802,10 +804,9 @@ fill_flow_stats(struct ofpbuf *buffer, struct sw_flow *flow,
 {
     struct ofp_flow_stats *ofs;
     int length = sizeof *ofs + flow->sf_acts->actions_len;
-    ofs = ofpbuf_put_uninit(buffer, length);
+    ofs = ofpbuf_put_zeros(buffer, length);
     ofs->length          = htons(length);
     ofs->table_id        = table_idx;
-    ofs->pad             = 0;
     ofs->match.wildcards = htonl(flow->key.wildcards);
     ofs->match.in_port   = flow->key.flow.in_port;
     memcpy(ofs->match.dl_src, flow->key.flow.dl_src, ETH_ADDR_LEN);
@@ -815,14 +816,12 @@ fill_flow_stats(struct ofpbuf *buffer, struct sw_flow *flow,
     ofs->match.nw_src    = flow->key.flow.nw_src;
     ofs->match.nw_dst    = flow->key.flow.nw_dst;
     ofs->match.nw_proto  = flow->key.flow.nw_proto;
-    ofs->match.pad       = 0;
     ofs->match.tp_src    = flow->key.flow.tp_src;
     ofs->match.tp_dst    = flow->key.flow.tp_dst;
     ofs->duration        = htonl(now - flow->created);
     ofs->priority        = htons(flow->priority);
     ofs->idle_timeout    = htons(flow->idle_timeout);
     ofs->hard_timeout    = htons(flow->hard_timeout);
-    memset(ofs->pad2, 0, sizeof ofs->pad2);
     ofs->packet_count    = htonll(flow->packet_count);
     ofs->byte_count      = htonll(flow->byte_count);
     memcpy(ofs->actions, flow->sf_acts->actions, flow->sf_acts->actions_len);
@@ -993,7 +992,7 @@ add_flow(struct datapath *dp, const struct sender *sender,
     if (v_code != ACT_VALIDATION_OK) {
         dp_send_error_msg(dp, sender, OFPET_BAD_ACTION, v_code,
                   ofm, ntohs(ofm->header.length));
-        goto error;
+        goto error_free_flow;
     }
 
     /* Fill out flow. */
@@ -1099,13 +1098,14 @@ recv_flow(struct datapath *dp, const struct sender *sender,
     }  else if (command == OFPFC_DELETE) {
         struct sw_flow_key key;
         flow_extract_match(&key, &ofm->match);
-        return chain_delete(dp->chain, &key, 0, 0) ? 0 : -ESRCH;
+        return chain_delete(dp->chain, &key, ofm->out_port, 0, 0) ? 0 : -ESRCH;
     } else if (command == OFPFC_DELETE_STRICT) {
         struct sw_flow_key key;
         uint16_t priority;
         flow_extract_match(&key, &ofm->match);
         priority = key.wildcards ? ntohs(ofm->priority) : -1;
-        return chain_delete(dp->chain, &key, priority, 1) ? 0 : -ESRCH;
+        return chain_delete(dp->chain, &key, ofm->out_port, 
+                priority, 1) ? 0 : -ESRCH;
     } else {
         return -ENODEV;
     }
@@ -1114,7 +1114,7 @@ recv_flow(struct datapath *dp, const struct sender *sender,
 static int desc_stats_dump(struct datapath *dp, void *state,
                               struct ofpbuf *buffer)
 {
-    struct ofp_desc_stats *ods = ofpbuf_put_uninit(buffer, sizeof *ods);
+    struct ofp_desc_stats *ods = ofpbuf_put_zeros(buffer, sizeof *ods);
 
     strncpy(ods->mfr_desc, &mfr_desc, sizeof ods->mfr_desc);
     strncpy(ods->hw_desc, &hw_desc, sizeof ods->hw_desc);
@@ -1168,8 +1168,8 @@ static int flow_stats_dump(struct datapath *dp, void *state,
     {
         struct sw_table *table = dp->chain->tables[s->table_idx];
 
-        if (table->iterate(table, &match_key, &s->position,
-                           flow_stats_dump_callback, s))
+        if (table->iterate(table, &match_key, s->rq.out_port,
+                    &s->position, flow_stats_dump_callback, s))
             break;
 
         s->table_idx++;
@@ -1217,8 +1217,7 @@ static int aggregate_stats_dump(struct datapath *dp, void *state,
     struct sw_flow_key match_key;
     int table_idx;
 
-    rpy = ofpbuf_put_uninit(buffer, sizeof *rpy);
-    memset(rpy, 0, sizeof *rpy);
+    rpy = ofpbuf_put_zeros(buffer, sizeof *rpy);
 
     flow_extract_match(&match_key, &rq->match);
     table_idx = rq->table_id == 0xff ? 0 : rq->table_id;
@@ -1229,7 +1228,7 @@ static int aggregate_stats_dump(struct datapath *dp, void *state,
         struct sw_table *table = dp->chain->tables[table_idx];
         int error;
 
-        error = table->iterate(table, &match_key, &position,
+        error = table->iterate(table, &match_key, rq->out_port, &position,
                                aggregate_stats_dump_callback, rpy);
         if (error)
             return error;
@@ -1254,13 +1253,12 @@ static int table_stats_dump(struct datapath *dp, void *state,
 {
     int i;
     for (i = 0; i < dp->chain->n_tables; i++) {
-        struct ofp_table_stats *ots = ofpbuf_put_uninit(buffer, sizeof *ots);
+        struct ofp_table_stats *ots = ofpbuf_put_zeros(buffer, sizeof *ots);
         struct sw_table_stats stats;
         dp->chain->tables[i]->stats(dp->chain->tables[i], &stats);
         strncpy(ots->name, stats.name, sizeof ots->name);
         ots->table_id = i;
         ots->wildcards = htonl(stats.wildcards);
-        memset(ots->pad, 0, sizeof ots->pad);
         ots->max_entries = htonl(stats.max_flows);
         ots->active_count = htonl(stats.n_flows);
         ots->lookup_count = htonll(stats.n_lookup);
@@ -1288,15 +1286,14 @@ static int port_stats_dump(struct datapath *dp, void *state,
     struct port_stats_state *s = state;
     int i;
 
-    for (i = s->port; i < OFPP_MAX; i++) {
+    for (i = s->port; i < DP_MAX_PORTS; i++) {
         struct sw_port *p = &dp->ports[i];
         struct ofp_port_stats *ops;
         if (!p->netdev) {
             continue;
         }
-        ops = ofpbuf_put_uninit(buffer, sizeof *ops);
+        ops = ofpbuf_put_zeros(buffer, sizeof *ops);
         ops->port_no = htons(port_no(dp, p));
-        memset(ops->pad, 0, sizeof ops->pad);
         ops->rx_packets   = htonll(p->rx_packets);
         ops->tx_packets   = htonll(p->tx_packets);
         ops->rx_bytes     = htonll(p->rx_bytes);