X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=ofproto%2Fofproto.c;h=764202f70f3ca545ca2914c429ddfc50e374678a;hb=296e07ace0f;hp=36de8e3a5281cf56d990fdc550405fbafbb02999;hpb=81a76618be9ea195a1e4a881ba9591728891d10b;p=sliver-openvswitch.git diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 36de8e3a5..764202f70 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -1901,6 +1901,7 @@ static void ofproto_rule_destroy__(struct rule *rule) { if (rule) { + cls_rule_destroy(&rule->cr); free(rule->ofpacts); rule->ofproto->ofproto_class->rule_dealloc(rule); } @@ -1969,7 +1970,7 @@ rule_execute(struct rule *rule, uint16_t in_port, struct ofpbuf *packet) assert(ofpbuf_headroom(packet) >= sizeof(struct ofp_packet_in)); - flow_extract(packet, 0, 0, in_port, &flow); + flow_extract(packet, 0, NULL, in_port, &flow); return rule->ofproto->ofproto_class->rule_execute(rule, &flow, packet); } @@ -2129,10 +2130,11 @@ handle_packet_out(struct ofconn *ofconn, const struct ofp_header *oh) goto exit_free_ofpacts; } if (po.in_port >= p->max_ports && po.in_port < OFPP_MAX) { - error = OFPERR_NXBRC_BAD_IN_PORT; + error = OFPERR_OFPBRC_BAD_PORT; goto exit_free_ofpacts; } + /* Get payload. */ if (po.buffer_id != UINT32_MAX) { error = ofconn_pktbuf_retrieve(ofconn, po.buffer_id, &payload, NULL); @@ -2145,7 +2147,7 @@ handle_packet_out(struct ofconn *ofconn, const struct ofp_header *oh) } /* Verify actions against packet, then send packet if successful. */ - flow_extract(payload, 0, 0, po.in_port, &flow); + flow_extract(payload, 0, NULL, po.in_port, &flow); error = ofpacts_check(po.ofpacts, po.ofpacts_len, &flow, p->max_ports); if (!error) { error = p->ofproto_class->packet_out(p, payload, &flow, @@ -2240,16 +2242,30 @@ handle_table_stats_request(struct ofconn *ofconn, const struct ofp_header *request) { struct ofproto *p = ofconn_get_ofproto(ofconn); - struct ofp10_table_stats *ots; + struct ofp12_table_stats *ots; struct ofpbuf *msg; size_t i; - msg = ofpraw_alloc_stats_reply(request, sizeof *ots * p->n_tables); - ots = ofpbuf_put_zeros(msg, sizeof *ots * p->n_tables); + /* Set up default values. + * + * ofp12_table_stats is used as a generic structure as + * it is able to hold all the fields for ofp10_table_stats + * and ofp11_table_stats (and of course itself). + */ + ots = xcalloc(p->n_tables, sizeof *ots); for (i = 0; i < p->n_tables; i++) { ots[i].table_id = i; sprintf(ots[i].name, "table%zu", i); - ots[i].wildcards = htonl(OFPFW10_ALL); + ots[i].match = htonll(OFPXMT12_MASK); + ots[i].wildcards = htonll(OFPXMT12_MASK); + ots[i].write_actions = htonl(OFPAT11_OUTPUT); + ots[i].apply_actions = htonl(OFPAT11_OUTPUT); + ots[i].write_setfields = htonll(OFPXMT12_MASK); + ots[i].apply_setfields = htonll(OFPXMT12_MASK); + ots[i].metadata_match = htonll(UINT64_MAX); + ots[i].metadata_write = htonll(UINT64_MAX); + ots[i].instructions = htonl(OFPIT11_ALL); + ots[i].config = htonl(OFPTC11_TABLE_MISS_MASK); ots[i].max_entries = htonl(1000000); /* An arbitrary big number. */ ots[i].active_count = htonl(classifier_count(&p->tables[i].cls)); } @@ -2268,7 +2284,11 @@ handle_table_stats_request(struct ofconn *ofconn, } } + msg = ofputil_encode_table_stats_reply(ots, p->n_tables, request); ofconn_send_reply(ofconn, msg); + + free(ots); + return 0; } @@ -2361,7 +2381,7 @@ check_table_id(const struct ofproto *ofproto, uint8_t table_id) { return (table_id == 0xff || table_id < ofproto->n_tables ? 0 - : OFPERR_NXBRC_BAD_TABLE_ID); + : OFPERR_OFPBRC_BAD_TABLE_ID); } @@ -2457,7 +2477,8 @@ collect_rules_loose(struct ofproto *ofproto, uint8_t table_id, cls_cursor_init(&cursor, &table->cls, &cr); CLS_CURSOR_FOR_EACH (rule, cr, &cursor) { if (rule->pending) { - return OFPROTO_POSTPONE; + error = OFPROTO_POSTPONE; + goto exit; } if (!ofproto_rule_is_hidden(rule) && ofproto_rule_has_out_port(rule, out_port) @@ -2466,7 +2487,10 @@ collect_rules_loose(struct ofproto *ofproto, uint8_t table_id, } } } - return 0; + +exit: + cls_rule_destroy(&cr); + return error; } /* Searches 'ofproto' for rules in table 'table_id' (or in all tables, if @@ -2504,7 +2528,8 @@ collect_rules_strict(struct ofproto *ofproto, uint8_t table_id, &cr)); if (rule) { if (rule->pending) { - return OFPROTO_POSTPONE; + error = OFPROTO_POSTPONE; + goto exit; } if (!ofproto_rule_is_hidden(rule) && ofproto_rule_has_out_port(rule, out_port) @@ -2513,6 +2538,9 @@ collect_rules_strict(struct ofproto *ofproto, uint8_t table_id, } } } + +exit: + cls_rule_destroy(&cr); return 0; } @@ -2554,7 +2582,7 @@ handle_flow_stats_request(struct ofconn *ofconn, long long int now = time_msec(); struct ofputil_flow_stats fs; - fs.match = rule->cr.match; + minimatch_expand(&rule->cr.match, &fs.match); fs.priority = rule->cr.priority; fs.cookie = rule->flow_cookie; fs.table_id = rule->table_id; @@ -2904,7 +2932,7 @@ add_flow(struct ofproto *ofproto, struct ofconn *ofconn, } else if (fm->table_id < ofproto->n_tables) { table = &ofproto->tables[fm->table_id]; } else { - return OFPERR_NXFMFC_BAD_TABLE_ID; + return OFPERR_OFPBRC_BAD_TABLE_ID; } if (table->flags & OFTABLE_READONLY) { @@ -2922,6 +2950,7 @@ add_flow(struct ofproto *ofproto, struct ofconn *ofconn, /* Serialize against pending deletion. */ if (is_flow_deletion_pending(ofproto, &cr, table - ofproto->tables)) { + cls_rule_destroy(&rule->cr); ofproto->ofproto_class->rule_dealloc(rule); return OFPROTO_POSTPONE; } @@ -2929,6 +2958,7 @@ add_flow(struct ofproto *ofproto, struct ofconn *ofconn, /* Check for overlap, if requested. */ if (fm->flags & OFPFF_CHECK_OVERLAP && classifier_rule_overlaps(&table->cls, &rule->cr)) { + cls_rule_destroy(&rule->cr); ofproto->ofproto_class->rule_dealloc(rule); return OFPERR_OFPFMFC_OVERLAP; } @@ -3191,10 +3221,11 @@ ofproto_rule_send_removed(struct rule *rule, uint8_t reason) return; } - fr.match = rule->cr.match; + minimatch_expand(&rule->cr.match, &fr.match); fr.priority = rule->cr.priority; fr.cookie = rule->flow_cookie; fr.reason = reason; + fr.table_id = rule->table_id; calc_flow_duration__(rule->created, time_msec(), &fr.duration_sec, &fr.duration_nsec); fr.idle_timeout = rule->idle_timeout; @@ -3268,11 +3299,10 @@ handle_flow_mod(struct ofconn *ofconn, const struct ofp_header *oh) } if (fm.flags & OFPFF10_EMERG) { - /* We do not support the OpenFlow 1.0 emergency flow cache, which is not - * required in OpenFlow 1.0.1 and removed from OpenFlow 1.1. */ - /* We do not support the emergency flow cache. It will hopefully get - * dropped from OpenFlow in the near future. There is no good error - * code, so just state that the flow table is full. */ + /* We do not support the OpenFlow 1.0 emergency flow cache, which + * is not required in OpenFlow 1.0.1 and removed from OpenFlow 1.1. + * There is no good error code, so just state that the flow table + * is full. */ error = OFPERR_OFPFMFC_ALL_TABLES_FULL; } if (!error) { @@ -3503,6 +3533,7 @@ ofproto_compose_flow_refresh_update(const struct rule *rule, { struct ofoperation *op = rule->pending; struct ofputil_flow_update fu; + struct match match; if (op && op->type == OFOPERATION_ADD && !op->victim) { /* We'll report the final flow when the operation completes. Reporting @@ -3517,7 +3548,9 @@ ofproto_compose_flow_refresh_update(const struct rule *rule, fu.hard_timeout = rule->hard_timeout; fu.table_id = rule->table_id; fu.cookie = rule->flow_cookie; - fu.match = CONST_CAST(struct match *, &rule->cr.match); + minimatch_expand(&rule->cr.match, &match); + fu.match = &match; + fu.priority = rule->cr.priority; if (!(flags & NXFMF_ACTIONS)) { fu.ofpacts = NULL; fu.ofpacts_len = 0; @@ -3622,7 +3655,7 @@ ofproto_collect_ofmonitor_refresh_rules(const struct ofmonitor *m, const struct oftable *table; struct cls_rule target; - cls_rule_init(&target, &m->match, 0); + cls_rule_init_from_minimatch(&target, &m->match, 0); FOR_EACH_MATCHING_TABLE (table, m->table_id, ofproto) { struct cls_cursor cursor; struct rule *rule; @@ -3644,6 +3677,7 @@ ofproto_collect_ofmonitor_refresh_rules(const struct ofmonitor *m, ofproto_collect_ofmonitor_refresh_rule(m, rule, seqno, rules); } } + cls_rule_destroy(&target); } static void @@ -4007,13 +4041,13 @@ ofopgroup_complete(struct ofopgroup *group) switch (op->type) { case OFOPERATION_ADD: if (!op->error) { + uint16_t vid_mask; + ofproto_rule_destroy__(op->victim); - if ((rule->cr.match.wc.masks.vlan_tci & htons(VLAN_VID_MASK)) - == htons(VLAN_VID_MASK)) { + vid_mask = minimask_get_vid_mask(&rule->cr.match.mask); + if (vid_mask == VLAN_VID_MASK) { if (ofproto->vlan_bitmap) { - uint16_t vid; - - vid = vlan_tci_to_vid(rule->cr.match.flow.vlan_tci); + uint16_t vid = miniflow_get_vid(&rule->cr.match.flow); if (!bitmap_is_set(ofproto->vlan_bitmap, vid)) { bitmap_set1(ofproto->vlan_bitmap, vid); ofproto->vlans_changed = true; @@ -4347,17 +4381,19 @@ eviction_group_hash_rule(struct rule *rule) { struct oftable *table = &rule->ofproto->tables[rule->table_id]; const struct mf_subfield *sf; + struct flow flow; uint32_t hash; hash = table->eviction_group_id_basis; + miniflow_expand(&rule->cr.match.flow, &flow); for (sf = table->eviction_fields; sf < &table->eviction_fields[table->n_eviction_fields]; sf++) { - if (mf_are_prereqs_ok(sf->field, &rule->cr.match.flow)) { + if (mf_are_prereqs_ok(sf->field, &flow)) { union mf_value value; - mf_get_value(sf->field, &rule->cr.match.flow, &value); + mf_get_value(sf->field, &flow, &value); if (sf->ofs) { bitwise_zero(&value, sf->field->n_bytes, 0, sf->ofs); } @@ -4663,12 +4699,11 @@ ofproto_get_vlan_usage(struct ofproto *ofproto, unsigned long int *vlan_bitmap) const struct cls_table *table; HMAP_FOR_EACH (table, hmap_node, &oftable->cls.tables) { - if ((table->wc.masks.vlan_tci & htons(VLAN_VID_MASK)) - == htons(VLAN_VID_MASK)) { + if (minimask_get_vid_mask(&table->mask) == VLAN_VID_MASK) { const struct cls_rule *rule; HMAP_FOR_EACH (rule, hmap_node, &table->rules) { - uint16_t vid = vlan_tci_to_vid(rule->match.flow.vlan_tci); + uint16_t vid = miniflow_get_vid(&rule->match.flow); bitmap_set1(vlan_bitmap, vid); bitmap_set1(ofproto->vlan_bitmap, vid); }