Use a list rather than an array to track monitor requests in handle_flow_monitor_request().
This is in preparation for supporting OpenFlow1.4 flow monitor requests with delete and modify commands. Signed-off-by: Simon Horman <ho...@verge.net.au> --- v2 * No change --- ofproto/connmgr.c | 2 ++ ofproto/connmgr.h | 3 +++ ofproto/ofproto.c | 27 ++++++++++----------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c index 98ffb68..05ff4ce 100644 --- a/ofproto/connmgr.c +++ b/ofproto/connmgr.c @@ -2034,6 +2034,7 @@ ofmonitor_create(const struct ofputil_flow_monitor_request *request, m->out_group = request->out_group; m->table_id = request->table_id; minimatch_init(&m->match, &request->match); + list_init(&m->list_node); *monitorp = m; return 0; @@ -2061,6 +2062,7 @@ ofmonitor_destroy(struct ofmonitor *m) if (m) { minimatch_destroy(&m->match); hmap_remove(&m->ofconn->monitors, &m->ofconn_node); + list_remove(&m->list_node); free(m); } } diff --git a/ofproto/connmgr.h b/ofproto/connmgr.h index d37ff2b..fc6afbd 100644 --- a/ofproto/connmgr.h +++ b/ofproto/connmgr.h @@ -206,6 +206,9 @@ struct ofmonitor { uint32_t out_group; uint8_t table_id; struct minimatch match; + + /* Used temporarily when handling flow monitor requests */ + struct list list_node; }; struct ofputil_flow_monitor_request; diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 69d7129..80046cc 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -4832,24 +4832,20 @@ static enum ofperr handle_flow_monitor_request(struct ofconn *ofconn, const struct ofp_header *oh) OVS_EXCLUDED(ofproto_mutex) { + struct list monitor_list = LIST_INITIALIZER(&monitor_list); struct ofproto *ofproto = ofconn_get_ofproto(ofconn); - struct ofmonitor **monitors; - size_t n_monitors, allocated_monitors; struct rule_collection rules; struct list replies; + struct ofmonitor *m, *next; enum ofperr error; struct ofpbuf b; - size_t i; error = 0; ofpbuf_use_const(&b, oh, ntohs(oh->length)); - monitors = NULL; - n_monitors = allocated_monitors = 0; ovs_mutex_lock(&ofproto_mutex); for (;;) { struct ofputil_flow_monitor_request request; - struct ofmonitor *m; int retval; retval = ofputil_decode_flow_monitor_request(&request, &b); @@ -4871,16 +4867,15 @@ handle_flow_monitor_request(struct ofconn *ofconn, const struct ofp_header *oh) goto error; } - if (n_monitors >= allocated_monitors) { - monitors = x2nrealloc(monitors, &allocated_monitors, - sizeof *monitors); - } - monitors[n_monitors++] = m; + list_insert(&monitor_list, &m->list_node); } rule_collection_init(&rules); - for (i = 0; i < n_monitors; i++) { - ofproto_collect_ofmonitor_initial_rules(monitors[i], &rules); + LIST_FOR_EACH_SAFE(m, next, list_node, &monitor_list) { + ofproto_collect_ofmonitor_initial_rules(m, &rules); + /* This is the last use of monitor_list but m will persist + * so detach m from monitor_list. */ + list_init(&m->list_node); } ofpmp_init(&replies, oh); @@ -4890,15 +4885,13 @@ handle_flow_monitor_request(struct ofconn *ofconn, const struct ofp_header *oh) rule_collection_destroy(&rules); ofconn_send_replies(ofconn, &replies); - free(monitors); return 0; error: - for (i = 0; i < n_monitors; i++) { - ofmonitor_destroy(monitors[i]); + LIST_FOR_EACH(m, list_node, &monitor_list) { + ofmonitor_destroy(m); } - free(monitors); ovs_mutex_unlock(&ofproto_mutex); return error; -- 2.0.0.rc2 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev