2 * Copyright (c) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "ofp-parse.h"
24 #include <netinet/in.h>
26 #include "byte-order.h"
27 #include "dynamic-string.h"
29 #include "meta-flow.h"
30 #include "multipath.h"
33 #include "ofp-actions.h"
36 #include "openflow/openflow.h"
37 #include "ovs-thread.h"
40 #include "socket-util.h"
41 #include "openvswitch/vconn.h"
43 /* Parses 'str' as an 8-bit unsigned integer into '*valuep'.
45 * 'name' describes the value parsed in an error message, if any.
47 * Returns NULL if successful, otherwise a malloc()'d string describing the
48 * error. The caller is responsible for freeing the returned string. */
49 char * OVS_WARN_UNUSED_RESULT
50 str_to_u8(const char *str, const char *name, uint8_t *valuep)
54 if (!str_to_int(str, 0, &value) || value < 0 || value > 255) {
55 return xasprintf("invalid %s \"%s\"", name, str);
61 /* Parses 'str' as a 16-bit unsigned integer into '*valuep'.
63 * 'name' describes the value parsed in an error message, if any.
65 * Returns NULL if successful, otherwise a malloc()'d string describing the
66 * error. The caller is responsible for freeing the returned string. */
67 char * OVS_WARN_UNUSED_RESULT
68 str_to_u16(const char *str, const char *name, uint16_t *valuep)
72 if (!str_to_int(str, 0, &value) || value < 0 || value > 65535) {
73 return xasprintf("invalid %s \"%s\"", name, str);
79 /* Parses 'str' as a 32-bit unsigned integer into '*valuep'.
81 * Returns NULL if successful, otherwise a malloc()'d string describing the
82 * error. The caller is responsible for freeing the returned string. */
83 char * OVS_WARN_UNUSED_RESULT
84 str_to_u32(const char *str, uint32_t *valuep)
90 return xstrdup("missing required numeric argument");
94 value = strtoul(str, &tail, 0);
95 if (errno == EINVAL || errno == ERANGE || *tail) {
96 return xasprintf("invalid numeric format %s", str);
102 /* Parses 'str' as an 64-bit unsigned integer into '*valuep'.
104 * Returns NULL if successful, otherwise a malloc()'d string describing the
105 * error. The caller is responsible for freeing the returned string. */
106 char * OVS_WARN_UNUSED_RESULT
107 str_to_u64(const char *str, uint64_t *valuep)
113 return xstrdup("missing required numeric argument");
117 value = strtoull(str, &tail, 0);
118 if (errno == EINVAL || errno == ERANGE || *tail) {
119 return xasprintf("invalid numeric format %s", str);
125 /* Parses 'str' as an 64-bit unsigned integer in network byte order into
128 * Returns NULL if successful, otherwise a malloc()'d string describing the
129 * error. The caller is responsible for freeing the returned string. */
130 char * OVS_WARN_UNUSED_RESULT
131 str_to_be64(const char *str, ovs_be64 *valuep)
136 error = str_to_u64(str, &value);
138 *valuep = htonll(value);
143 /* Parses 'str' as an Ethernet address into 'mac'.
145 * Returns NULL if successful, otherwise a malloc()'d string describing the
146 * error. The caller is responsible for freeing the returned string. */
147 char * OVS_WARN_UNUSED_RESULT
148 str_to_mac(const char *str, struct eth_addr *mac)
150 if (!ovs_scan(str, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(*mac))) {
151 return xasprintf("invalid mac address %s", str);
156 /* Parses 'str' as an IP address into '*ip'.
158 * Returns NULL if successful, otherwise a malloc()'d string describing the
159 * error. The caller is responsible for freeing the returned string. */
160 char * OVS_WARN_UNUSED_RESULT
161 str_to_ip(const char *str, ovs_be32 *ip)
163 struct in_addr in_addr;
165 if (lookup_ip(str, &in_addr)) {
166 return xasprintf("%s: could not convert to IP address", str);
168 *ip = in_addr.s_addr;
172 /* Parses 'str' as a conntrack helper into 'alg'.
174 * Returns NULL if successful, otherwise a malloc()'d string describing the
175 * error. The caller is responsible for freeing the returned string. */
176 char * OVS_WARN_UNUSED_RESULT
177 str_to_connhelper(const char *str, uint16_t *alg)
179 if (!strcmp(str, "ftp")) {
183 return xasprintf("invalid conntrack helper \"%s\"", str);
193 parse_protocol(const char *name, const struct protocol **p_out)
195 static const struct protocol protocols[] = {
196 { "ip", ETH_TYPE_IP, 0 },
197 { "ipv4", ETH_TYPE_IP, 0 },
198 { "ip4", ETH_TYPE_IP, 0 },
199 { "arp", ETH_TYPE_ARP, 0 },
200 { "icmp", ETH_TYPE_IP, IPPROTO_ICMP },
201 { "tcp", ETH_TYPE_IP, IPPROTO_TCP },
202 { "udp", ETH_TYPE_IP, IPPROTO_UDP },
203 { "sctp", ETH_TYPE_IP, IPPROTO_SCTP },
204 { "ipv6", ETH_TYPE_IPV6, 0 },
205 { "ip6", ETH_TYPE_IPV6, 0 },
206 { "icmp6", ETH_TYPE_IPV6, IPPROTO_ICMPV6 },
207 { "tcp6", ETH_TYPE_IPV6, IPPROTO_TCP },
208 { "udp6", ETH_TYPE_IPV6, IPPROTO_UDP },
209 { "sctp6", ETH_TYPE_IPV6, IPPROTO_SCTP },
210 { "rarp", ETH_TYPE_RARP, 0},
211 { "mpls", ETH_TYPE_MPLS, 0 },
212 { "mplsm", ETH_TYPE_MPLS_MCAST, 0 },
214 const struct protocol *p;
216 for (p = protocols; p < &protocols[ARRAY_SIZE(protocols)]; p++) {
217 if (!strcmp(p->name, name)) {
226 /* Parses 's' as the (possibly masked) value of field 'mf', and updates
227 * 'match' appropriately. Restricts the set of usable protocols to ones
228 * supporting the parsed field.
230 * Returns NULL if successful, otherwise a malloc()'d string describing the
231 * error. The caller is responsible for freeing the returned string. */
232 static char * OVS_WARN_UNUSED_RESULT
233 parse_field(const struct mf_field *mf, const char *s, struct match *match,
234 enum ofputil_protocol *usable_protocols)
236 union mf_value value, mask;
240 /* If there's no string, we're just trying to match on the
241 * existence of the field, so use a no-op value. */
245 error = mf_parse(mf, s, &value, &mask);
247 *usable_protocols &= mf_set(mf, &value, &mask, match, &error);
253 extract_actions(char *s)
255 s = strstr(s, "action");
258 s = strchr(s + 1, '=');
259 return s ? s + 1 : NULL;
266 static char * OVS_WARN_UNUSED_RESULT
267 parse_ofp_str__(struct ofputil_flow_mod *fm, int command, char *string,
268 enum ofputil_protocol *usable_protocols)
273 F_IMPORTANCE = 1 << 2,
278 char *act_str = NULL;
281 *usable_protocols = OFPUTIL_P_ANY;
286 string += strspn(string, " \t\r\n"); /* Skip white space. */
287 len = strcspn(string, ", \t\r\n"); /* Get length of the first token. */
289 if (!strncmp(string, "add", len)) {
291 } else if (!strncmp(string, "delete", len)) {
292 command = OFPFC_DELETE;
293 } else if (!strncmp(string, "delete_strict", len)) {
294 command = OFPFC_DELETE_STRICT;
295 } else if (!strncmp(string, "modify", len)) {
296 command = OFPFC_MODIFY;
297 } else if (!strncmp(string, "modify_strict", len)) {
298 command = OFPFC_MODIFY_STRICT;
312 fields = F_ACTIONS | F_TIMEOUT | F_PRIORITY | F_FLAGS | F_IMPORTANCE;
319 case OFPFC_DELETE_STRICT:
320 fields = F_OUT_PORT | F_PRIORITY;
324 fields = F_ACTIONS | F_TIMEOUT | F_PRIORITY | F_FLAGS;
327 case OFPFC_MODIFY_STRICT:
328 fields = F_ACTIONS | F_TIMEOUT | F_PRIORITY | F_FLAGS;
335 *fm = (struct ofputil_flow_mod) {
336 .match = MATCH_CATCHALL_INITIALIZER,
337 .priority = OFP_DEFAULT_PRIORITY,
340 .buffer_id = UINT32_MAX,
341 .out_port = OFPP_ANY,
342 .out_group = OFPG_ANY,
343 .delete_reason = OFPRR_DELETE,
345 /* For modify, by default, don't update the cookie. */
346 if (command == OFPFC_MODIFY || command == OFPFC_MODIFY_STRICT) {
347 fm->new_cookie = OVS_BE64_MAX;
350 if (fields & F_ACTIONS) {
351 act_str = extract_actions(string);
353 return xstrdup("must specify an action");
357 while (ofputil_parse_key_value(&string, &name, &value)) {
358 const struct protocol *p;
361 if (parse_protocol(name, &p)) {
362 match_set_dl_type(&fm->match, htons(p->dl_type));
364 match_set_nw_proto(&fm->match, p->nw_proto);
366 } else if (fields & F_FLAGS && !strcmp(name, "send_flow_rem")) {
367 fm->flags |= OFPUTIL_FF_SEND_FLOW_REM;
368 } else if (fields & F_FLAGS && !strcmp(name, "check_overlap")) {
369 fm->flags |= OFPUTIL_FF_CHECK_OVERLAP;
370 } else if (fields & F_FLAGS && !strcmp(name, "reset_counts")) {
371 fm->flags |= OFPUTIL_FF_RESET_COUNTS;
372 *usable_protocols &= OFPUTIL_P_OF12_UP;
373 } else if (fields & F_FLAGS && !strcmp(name, "no_packet_counts")) {
374 fm->flags |= OFPUTIL_FF_NO_PKT_COUNTS;
375 *usable_protocols &= OFPUTIL_P_OF13_UP;
376 } else if (fields & F_FLAGS && !strcmp(name, "no_byte_counts")) {
377 fm->flags |= OFPUTIL_FF_NO_BYT_COUNTS;
378 *usable_protocols &= OFPUTIL_P_OF13_UP;
379 } else if (!strcmp(name, "no_readonly_table")
380 || !strcmp(name, "allow_hidden_fields")) {
381 /* ignore these fields. */
382 } else if (mf_from_name(name)) {
383 error = parse_field(mf_from_name(name), value, &fm->match,
387 return xasprintf("field %s missing value", name);
390 if (!strcmp(name, "table")) {
391 error = str_to_u8(value, "table", &fm->table_id);
392 if (fm->table_id != 0xff) {
393 *usable_protocols &= OFPUTIL_P_TID;
395 } else if (fields & F_OUT_PORT && !strcmp(name, "out_port")) {
396 if (!ofputil_port_from_string(value, &fm->out_port)) {
397 error = xasprintf("%s is not a valid OpenFlow port",
400 } else if (fields & F_OUT_PORT && !strcmp(name, "out_group")) {
401 *usable_protocols &= OFPUTIL_P_OF11_UP;
402 if (!ofputil_group_from_string(value, &fm->out_group)) {
403 error = xasprintf("%s is not a valid OpenFlow group",
406 } else if (fields & F_PRIORITY && !strcmp(name, "priority")) {
407 uint16_t priority = 0;
409 error = str_to_u16(value, name, &priority);
410 fm->priority = priority;
411 } else if (fields & F_TIMEOUT && !strcmp(name, "idle_timeout")) {
412 error = str_to_u16(value, name, &fm->idle_timeout);
413 } else if (fields & F_TIMEOUT && !strcmp(name, "hard_timeout")) {
414 error = str_to_u16(value, name, &fm->hard_timeout);
415 } else if (fields & F_IMPORTANCE && !strcmp(name, "importance")) {
416 error = str_to_u16(value, name, &fm->importance);
417 } else if (!strcmp(name, "cookie")) {
418 char *mask = strchr(value, '/');
421 /* A mask means we're searching for a cookie. */
422 if (command == OFPFC_ADD) {
423 return xstrdup("flow additions cannot use "
427 error = str_to_be64(value, &fm->cookie);
431 error = str_to_be64(mask + 1, &fm->cookie_mask);
433 /* Matching of the cookie is only supported through NXM or
435 if (fm->cookie_mask != htonll(0)) {
436 *usable_protocols &= OFPUTIL_P_NXM_OF11_UP;
439 /* No mask means that the cookie is being set. */
440 if (command != OFPFC_ADD && command != OFPFC_MODIFY
441 && command != OFPFC_MODIFY_STRICT) {
442 return xstrdup("cannot set cookie");
444 error = str_to_be64(value, &fm->new_cookie);
445 fm->modify_cookie = true;
447 } else if (!strcmp(name, "duration")
448 || !strcmp(name, "n_packets")
449 || !strcmp(name, "n_bytes")
450 || !strcmp(name, "idle_age")
451 || !strcmp(name, "hard_age")) {
452 /* Ignore these, so that users can feed the output of
453 * "ovs-ofctl dump-flows" back into commands that parse
456 error = xasprintf("unknown keyword %s", name);
464 /* Check for usable protocol interdependencies between match fields. */
465 if (fm->match.flow.dl_type == htons(ETH_TYPE_IPV6)) {
466 const struct flow_wildcards *wc = &fm->match.wc;
467 /* Only NXM and OXM support matching L3 and L4 fields within IPv6.
469 * (IPv6 specific fields as well as arp_sha, arp_tha, nw_frag, and
470 * nw_ttl are covered elsewhere so they don't need to be included in
473 if (wc->masks.nw_proto || wc->masks.nw_tos
474 || wc->masks.tp_src || wc->masks.tp_dst) {
475 *usable_protocols &= OFPUTIL_P_NXM_OXM_ANY;
478 if (!fm->cookie_mask && fm->new_cookie == OVS_BE64_MAX
479 && (command == OFPFC_MODIFY || command == OFPFC_MODIFY_STRICT)) {
480 /* On modifies without a mask, we are supposed to add a flow if
481 * one does not exist. If a cookie wasn't been specified, use a
482 * default of zero. */
483 fm->new_cookie = htonll(0);
485 if (fields & F_ACTIONS) {
486 enum ofputil_protocol action_usable_protocols;
487 struct ofpbuf ofpacts;
490 ofpbuf_init(&ofpacts, 32);
491 error = ofpacts_parse_instructions(act_str, &ofpacts,
492 &action_usable_protocols);
493 *usable_protocols &= action_usable_protocols;
497 err = ofpacts_check(ofpacts.data, ofpacts.size, &fm->match.flow,
498 OFPP_MAX, fm->table_id, 255, usable_protocols);
499 if (!err && !*usable_protocols) {
500 err = OFPERR_OFPBAC_MATCH_INCONSISTENT;
503 error = xasprintf("actions are invalid with specified match "
504 "(%s)", ofperr_to_string(err));
509 ofpbuf_uninit(&ofpacts);
513 fm->ofpacts_len = ofpacts.size;
514 fm->ofpacts = ofpbuf_steal_data(&ofpacts);
523 /* Convert 'str_' (as described in the Flow Syntax section of the ovs-ofctl man
524 * page) into 'fm' for sending the specified flow_mod 'command' to a switch.
525 * Returns the set of usable protocols in '*usable_protocols'.
527 * To parse syntax for an OFPT_FLOW_MOD (or NXT_FLOW_MOD), use an OFPFC_*
528 * constant for 'command'. To parse syntax for an OFPST_FLOW or
529 * OFPST_AGGREGATE (or NXST_FLOW or NXST_AGGREGATE), use -1 for 'command'.
531 * If 'command' is given as -2, 'str_' may begin with a command name ("add",
532 * "modify", "delete", "modify_strict", or "delete_strict"). A missing command
533 * name is treated as "add".
535 * Returns NULL if successful, otherwise a malloc()'d string describing the
536 * error. The caller is responsible for freeing the returned string. */
537 char * OVS_WARN_UNUSED_RESULT
538 parse_ofp_str(struct ofputil_flow_mod *fm, int command, const char *str_,
539 enum ofputil_protocol *usable_protocols)
541 char *string = xstrdup(str_);
544 error = parse_ofp_str__(fm, command, string, usable_protocols);
554 static char * OVS_WARN_UNUSED_RESULT
555 parse_ofp_meter_mod_str__(struct ofputil_meter_mod *mm, char *string,
556 struct ofpbuf *bands, int command,
557 enum ofputil_protocol *usable_protocols)
564 char *save_ptr = NULL;
565 char *band_str = NULL;
568 /* Meters require at least OF 1.3. */
569 *usable_protocols = OFPUTIL_P_OF13_UP;
577 fields = F_METER | F_FLAGS | F_BANDS;
585 fields = F_METER | F_FLAGS | F_BANDS;
592 mm->command = command;
593 mm->meter.meter_id = 0;
595 if (fields & F_BANDS) {
596 band_str = strstr(string, "band");
598 return xstrdup("must specify bands");
602 band_str = strchr(band_str + 1, '=');
604 return xstrdup("must specify bands");
609 for (name = strtok_r(string, "=, \t\r\n", &save_ptr); name;
610 name = strtok_r(NULL, "=, \t\r\n", &save_ptr)) {
612 if (fields & F_FLAGS && !strcmp(name, "kbps")) {
613 mm->meter.flags |= OFPMF13_KBPS;
614 } else if (fields & F_FLAGS && !strcmp(name, "pktps")) {
615 mm->meter.flags |= OFPMF13_PKTPS;
616 } else if (fields & F_FLAGS && !strcmp(name, "burst")) {
617 mm->meter.flags |= OFPMF13_BURST;
618 } else if (fields & F_FLAGS && !strcmp(name, "stats")) {
619 mm->meter.flags |= OFPMF13_STATS;
623 value = strtok_r(NULL, ", \t\r\n", &save_ptr);
625 return xasprintf("field %s missing value", name);
628 if (!strcmp(name, "meter")) {
629 if (!strcmp(value, "all")) {
630 mm->meter.meter_id = OFPM13_ALL;
631 } else if (!strcmp(value, "controller")) {
632 mm->meter.meter_id = OFPM13_CONTROLLER;
633 } else if (!strcmp(value, "slowpath")) {
634 mm->meter.meter_id = OFPM13_SLOWPATH;
636 char *error = str_to_u32(value, &mm->meter.meter_id);
640 if (mm->meter.meter_id > OFPM13_MAX
641 || !mm->meter.meter_id) {
642 return xasprintf("invalid value for %s", name);
646 return xasprintf("unknown keyword %s", name);
650 if (fields & F_METER && !mm->meter.meter_id) {
651 return xstrdup("must specify 'meter'");
653 if (fields & F_FLAGS && !mm->meter.flags) {
654 return xstrdup("meter must specify either 'kbps' or 'pktps'");
657 if (fields & F_BANDS) {
658 uint16_t n_bands = 0;
659 struct ofputil_meter_band *band = NULL;
662 for (name = strtok_r(band_str, "=, \t\r\n", &save_ptr); name;
663 name = strtok_r(NULL, "=, \t\r\n", &save_ptr)) {
667 value = strtok_r(NULL, ", \t\r\n", &save_ptr);
669 return xasprintf("field %s missing value", name);
672 if (!strcmp(name, "type")) {
673 /* Start a new band */
674 band = ofpbuf_put_zeros(bands, sizeof *band);
677 if (!strcmp(value, "drop")) {
678 band->type = OFPMBT13_DROP;
679 } else if (!strcmp(value, "dscp_remark")) {
680 band->type = OFPMBT13_DSCP_REMARK;
682 return xasprintf("field %s unknown value %s", name, value);
684 } else if (!band || !band->type) {
685 return xstrdup("band must start with the 'type' keyword");
686 } else if (!strcmp(name, "rate")) {
687 char *error = str_to_u32(value, &band->rate);
691 } else if (!strcmp(name, "burst_size")) {
692 char *error = str_to_u32(value, &band->burst_size);
696 } else if (!strcmp(name, "prec_level")) {
697 char *error = str_to_u8(value, name, &band->prec_level);
702 return xasprintf("unknown keyword %s", name);
707 return xstrdup("meter must have bands");
710 mm->meter.n_bands = n_bands;
711 mm->meter.bands = ofpbuf_steal_data(bands);
713 for (i = 0; i < n_bands; ++i) {
714 band = &mm->meter.bands[i];
717 return xstrdup("band must have 'type'");
719 if (band->type == OFPMBT13_DSCP_REMARK) {
720 if (!band->prec_level) {
721 return xstrdup("'dscp_remark' band must have"
725 if (band->prec_level) {
726 return xstrdup("Only 'dscp_remark' band may have"
731 return xstrdup("band must have 'rate'");
733 if (mm->meter.flags & OFPMF13_BURST) {
734 if (!band->burst_size) {
735 return xstrdup("band must have 'burst_size' "
736 "when 'burst' flag is set");
739 if (band->burst_size) {
740 return xstrdup("band may have 'burst_size' only "
741 "when 'burst' flag is set");
746 mm->meter.n_bands = 0;
747 mm->meter.bands = NULL;
753 /* Convert 'str_' (as described in the Flow Syntax section of the ovs-ofctl man
754 * page) into 'mm' for sending the specified meter_mod 'command' to a switch.
756 * Returns NULL if successful, otherwise a malloc()'d string describing the
757 * error. The caller is responsible for freeing the returned string. */
758 char * OVS_WARN_UNUSED_RESULT
759 parse_ofp_meter_mod_str(struct ofputil_meter_mod *mm, const char *str_,
760 int command, enum ofputil_protocol *usable_protocols)
766 ofpbuf_init(&bands, 64);
767 string = xstrdup(str_);
769 error = parse_ofp_meter_mod_str__(mm, string, &bands, command,
773 ofpbuf_uninit(&bands);
778 static char * OVS_WARN_UNUSED_RESULT
779 parse_flow_monitor_request__(struct ofputil_flow_monitor_request *fmr,
780 const char *str_, char *string,
781 enum ofputil_protocol *usable_protocols)
783 static atomic_count id = ATOMIC_COUNT_INIT(0);
786 fmr->id = atomic_count_inc(&id);
788 fmr->flags = (NXFMF_INITIAL | NXFMF_ADD | NXFMF_DELETE | NXFMF_MODIFY
789 | NXFMF_OWN | NXFMF_ACTIONS);
790 fmr->out_port = OFPP_NONE;
791 fmr->table_id = 0xff;
792 match_init_catchall(&fmr->match);
794 while (ofputil_parse_key_value(&string, &name, &value)) {
795 const struct protocol *p;
798 if (!strcmp(name, "!initial")) {
799 fmr->flags &= ~NXFMF_INITIAL;
800 } else if (!strcmp(name, "!add")) {
801 fmr->flags &= ~NXFMF_ADD;
802 } else if (!strcmp(name, "!delete")) {
803 fmr->flags &= ~NXFMF_DELETE;
804 } else if (!strcmp(name, "!modify")) {
805 fmr->flags &= ~NXFMF_MODIFY;
806 } else if (!strcmp(name, "!actions")) {
807 fmr->flags &= ~NXFMF_ACTIONS;
808 } else if (!strcmp(name, "!own")) {
809 fmr->flags &= ~NXFMF_OWN;
810 } else if (parse_protocol(name, &p)) {
811 match_set_dl_type(&fmr->match, htons(p->dl_type));
813 match_set_nw_proto(&fmr->match, p->nw_proto);
815 } else if (mf_from_name(name)) {
816 error = parse_field(mf_from_name(name), value, &fmr->match,
820 return xasprintf("%s: field %s missing value", str_, name);
823 if (!strcmp(name, "table")) {
824 error = str_to_u8(value, "table", &fmr->table_id);
825 } else if (!strcmp(name, "out_port")) {
826 fmr->out_port = u16_to_ofp(atoi(value));
828 return xasprintf("%s: unknown keyword %s", str_, name);
839 /* Convert 'str_' (as described in the documentation for the "monitor" command
840 * in the ovs-ofctl man page) into 'fmr'.
842 * Returns NULL if successful, otherwise a malloc()'d string describing the
843 * error. The caller is responsible for freeing the returned string. */
844 char * OVS_WARN_UNUSED_RESULT
845 parse_flow_monitor_request(struct ofputil_flow_monitor_request *fmr,
847 enum ofputil_protocol *usable_protocols)
849 char *string = xstrdup(str_);
850 char *error = parse_flow_monitor_request__(fmr, str_, string,
856 /* Parses 'string' as an OFPT_FLOW_MOD or NXT_FLOW_MOD with command 'command'
857 * (one of OFPFC_*) into 'fm'.
859 * If 'command' is given as -2, 'string' may begin with a command name ("add",
860 * "modify", "delete", "modify_strict", or "delete_strict"). A missing command
861 * name is treated as "add".
863 * Returns NULL if successful, otherwise a malloc()'d string describing the
864 * error. The caller is responsible for freeing the returned string. */
865 char * OVS_WARN_UNUSED_RESULT
866 parse_ofp_flow_mod_str(struct ofputil_flow_mod *fm, const char *string,
868 enum ofputil_protocol *usable_protocols)
870 char *error = parse_ofp_str(fm, command, string, usable_protocols);
873 /* Normalize a copy of the match. This ensures that non-normalized
874 * flows get logged but doesn't affect what gets sent to the switch, so
875 * that the switch can do whatever it likes with the flow. */
876 struct match match_copy = fm->match;
877 ofputil_normalize_match(&match_copy);
883 /* Convert 'setting' (as described for the "mod-table" command
884 * in ovs-ofctl man page) into 'tm->table_vacancy->vacancy_up' and
885 * 'tm->table_vacancy->vacancy_down' threshold values.
886 * For the two threshold values, value of vacancy_up is always greater
887 * than value of vacancy_down.
889 * Returns NULL if successful, otherwise a malloc()'d string describing the
890 * error. The caller is responsible for freeing the returned string. */
891 char * OVS_WARN_UNUSED_RESULT
892 parse_ofp_table_vacancy(struct ofputil_table_mod *tm, const char *setting)
894 char *save_ptr = NULL;
895 char *vac_up, *vac_down;
896 char *value = strdup(setting);
897 int vacancy_up, vacancy_down;
899 strtok_r(value, ":", &save_ptr);
900 vac_down = strtok_r(NULL, ",", &save_ptr);
902 return xasprintf("Vacancy down value missing");
904 if (!str_to_int(vac_down, 0, &vacancy_down) ||
905 vacancy_down < 0 || vacancy_down > 100) {
906 return xasprintf("Invalid vacancy down value \"%s\"", vac_down);
908 vac_up = strtok_r(NULL, ",", &save_ptr);
910 return xasprintf("Vacancy up value missing");
912 if (!str_to_int(vac_up, 0, &vacancy_up) ||
913 vacancy_up < 0 || vacancy_up > 100) {
914 return xasprintf("Invalid vacancy up value \"%s\"", vac_up);
916 if (vacancy_down > vacancy_up) {
917 return xasprintf("Invalid vacancy range, vacancy up should be greater"
918 " than vacancy down ""(%s)",
919 ofperr_to_string(OFPERR_OFPBPC_BAD_VALUE));
921 tm->table_vacancy.vacancy_down = vacancy_down;
922 tm->table_vacancy.vacancy_up = vacancy_up;
926 /* Convert 'table_id' and 'setting' (as described for the "mod-table" command
927 * in the ovs-ofctl man page) into 'tm' for sending a table_mod command to a
930 * Stores a bitmap of the OpenFlow versions that are usable for 'tm' into
931 * '*usable_versions'.
933 * Returns NULL if successful, otherwise a malloc()'d string describing the
934 * error. The caller is responsible for freeing the returned string. */
935 char * OVS_WARN_UNUSED_RESULT
936 parse_ofp_table_mod(struct ofputil_table_mod *tm, const char *table_id,
937 const char *setting, uint32_t *usable_versions)
939 *usable_versions = 0;
940 if (!strcasecmp(table_id, "all")) {
941 tm->table_id = OFPTT_ALL;
943 char *error = str_to_u8(table_id, "table_id", &tm->table_id);
949 tm->miss = OFPUTIL_TABLE_MISS_DEFAULT;
950 tm->eviction = OFPUTIL_TABLE_EVICTION_DEFAULT;
951 tm->eviction_flags = UINT32_MAX;
952 tm->vacancy = OFPUTIL_TABLE_VACANCY_DEFAULT;
953 tm->table_vacancy.vacancy_down = 0;
954 tm->table_vacancy.vacancy_up = 0;
955 tm->table_vacancy.vacancy = 0;
956 /* Only OpenFlow 1.1 and 1.2 can configure table-miss via table_mod.
957 * Only OpenFlow 1.4+ can configure eviction and vacancy events
960 if (!strcmp(setting, "controller")) {
961 tm->miss = OFPUTIL_TABLE_MISS_CONTROLLER;
962 *usable_versions = (1u << OFP11_VERSION) | (1u << OFP12_VERSION);
963 } else if (!strcmp(setting, "continue")) {
964 tm->miss = OFPUTIL_TABLE_MISS_CONTINUE;
965 *usable_versions = (1u << OFP11_VERSION) | (1u << OFP12_VERSION);
966 } else if (!strcmp(setting, "drop")) {
967 tm->miss = OFPUTIL_TABLE_MISS_DROP;
968 *usable_versions = (1u << OFP11_VERSION) | (1u << OFP12_VERSION);
969 } else if (!strcmp(setting, "evict")) {
970 tm->eviction = OFPUTIL_TABLE_EVICTION_ON;
971 *usable_versions = (1 << OFP14_VERSION) | (1u << OFP15_VERSION);
972 } else if (!strcmp(setting, "noevict")) {
973 tm->eviction = OFPUTIL_TABLE_EVICTION_OFF;
974 *usable_versions = (1 << OFP14_VERSION) | (1u << OFP15_VERSION);
975 } else if (!strncmp(setting, "vacancy", strcspn(setting, ":"))) {
976 tm->vacancy = OFPUTIL_TABLE_VACANCY_ON;
977 *usable_versions = (1 << OFP14_VERSION) | (1u << OFP15_VERSION);
978 char *error = parse_ofp_table_vacancy(tm, setting);
982 } else if (!strcmp(setting, "novacancy")) {
983 tm->vacancy = OFPUTIL_TABLE_VACANCY_OFF;
984 *usable_versions = (1 << OFP14_VERSION) | (1u << OFP15_VERSION);
986 return xasprintf("invalid table_mod setting %s", setting);
989 if (tm->table_id == 0xfe
990 && tm->miss == OFPUTIL_TABLE_MISS_CONTINUE) {
991 return xstrdup("last table's flow miss handling can not be continue");
998 /* Opens file 'file_name' and reads each line as a flow_mod of the specified
999 * type (one of OFPFC_*). Stores each flow_mod in '*fm', an array allocated
1000 * on the caller's behalf, and the number of flow_mods in '*n_fms'.
1002 * If 'command' is given as -2, each line may start with a command name
1003 * ("add", "modify", "delete", "modify_strict", or "delete_strict"). A missing
1004 * command name is treated as "add".
1006 * Returns NULL if successful, otherwise a malloc()'d string describing the
1007 * error. The caller is responsible for freeing the returned string. */
1008 char * OVS_WARN_UNUSED_RESULT
1009 parse_ofp_flow_mod_file(const char *file_name, int command,
1010 struct ofputil_flow_mod **fms, size_t *n_fms,
1011 enum ofputil_protocol *usable_protocols)
1013 size_t allocated_fms;
1018 *usable_protocols = OFPUTIL_P_ANY;
1023 stream = !strcmp(file_name, "-") ? stdin : fopen(file_name, "r");
1024 if (stream == NULL) {
1025 return xasprintf("%s: open failed (%s)",
1026 file_name, ovs_strerror(errno));
1029 allocated_fms = *n_fms;
1032 while (!ds_get_preprocessed_line(&s, stream, &line_number)) {
1034 enum ofputil_protocol usable;
1036 if (*n_fms >= allocated_fms) {
1037 *fms = x2nrealloc(*fms, &allocated_fms, sizeof **fms);
1039 error = parse_ofp_flow_mod_str(&(*fms)[*n_fms], ds_cstr(&s), command,
1044 for (i = 0; i < *n_fms; i++) {
1045 free(CONST_CAST(struct ofpact *, (*fms)[i].ofpacts));
1052 if (stream != stdin) {
1056 return xasprintf("%s:%d: %s", file_name, line_number, error);
1058 *usable_protocols &= usable; /* Each line can narrow the set. */
1063 if (stream != stdin) {
1069 char * OVS_WARN_UNUSED_RESULT
1070 parse_ofp_flow_stats_request_str(struct ofputil_flow_stats_request *fsr,
1071 bool aggregate, const char *string,
1072 enum ofputil_protocol *usable_protocols)
1074 struct ofputil_flow_mod fm;
1077 error = parse_ofp_str(&fm, -1, string, usable_protocols);
1082 /* Special table ID support not required for stats requests. */
1083 if (*usable_protocols & OFPUTIL_P_OF10_STD_TID) {
1084 *usable_protocols |= OFPUTIL_P_OF10_STD;
1086 if (*usable_protocols & OFPUTIL_P_OF10_NXM_TID) {
1087 *usable_protocols |= OFPUTIL_P_OF10_NXM;
1090 fsr->aggregate = aggregate;
1091 fsr->cookie = fm.cookie;
1092 fsr->cookie_mask = fm.cookie_mask;
1093 fsr->match = fm.match;
1094 fsr->out_port = fm.out_port;
1095 fsr->out_group = fm.out_group;
1096 fsr->table_id = fm.table_id;
1100 /* Parses a specification of a flow from 's' into 'flow'. 's' must take the
1101 * form FIELD=VALUE[,FIELD=VALUE]... where each FIELD is the name of a
1102 * mf_field. Fields must be specified in a natural order for satisfying
1103 * prerequisites. If 'mask' is specified, fills the mask field for each of the
1104 * field specified in flow. If the map, 'names_portno' is specfied, converts
1105 * the in_port name into port no while setting the 'flow'.
1107 * Returns NULL on success, otherwise a malloc()'d string that explains the
1110 parse_ofp_exact_flow(struct flow *flow, struct flow *mask, const char *s,
1111 const struct simap *portno_names)
1113 char *pos, *key, *value_s;
1117 memset(flow, 0, sizeof *flow);
1119 memset(mask, 0, sizeof *mask);
1122 pos = copy = xstrdup(s);
1123 while (ofputil_parse_key_value(&pos, &key, &value_s)) {
1124 const struct protocol *p;
1125 if (parse_protocol(key, &p)) {
1126 if (flow->dl_type) {
1127 error = xasprintf("%s: Ethernet type set multiple times", s);
1130 flow->dl_type = htons(p->dl_type);
1132 mask->dl_type = OVS_BE16_MAX;
1136 if (flow->nw_proto) {
1137 error = xasprintf("%s: network protocol set "
1138 "multiple times", s);
1141 flow->nw_proto = p->nw_proto;
1143 mask->nw_proto = UINT8_MAX;
1147 const struct mf_field *mf;
1148 union mf_value value;
1151 mf = mf_from_name(key);
1153 error = xasprintf("%s: unknown field %s", s, key);
1157 if (!mf_are_prereqs_ok(mf, flow)) {
1158 error = xasprintf("%s: prerequisites not met for setting %s",
1163 if (mf_is_set(mf, flow)) {
1164 error = xasprintf("%s: field %s set multiple times", s, key);
1168 if (!strcmp(key, "in_port")
1170 && simap_contains(portno_names, value_s)) {
1171 flow->in_port.ofp_port = u16_to_ofp(
1172 simap_get(portno_names, value_s));
1174 mask->in_port.ofp_port = u16_to_ofp(ntohs(OVS_BE16_MAX));
1177 field_error = mf_parse_value(mf, value_s, &value);
1179 error = xasprintf("%s: bad value for %s (%s)",
1180 s, key, field_error);
1185 mf_set_flow_value(mf, &value, flow);
1187 mf_mask_field(mf, mask);
1193 if (!flow->in_port.ofp_port) {
1194 flow->in_port.ofp_port = OFPP_NONE;
1201 memset(flow, 0, sizeof *flow);
1203 memset(mask, 0, sizeof *mask);
1209 static char * OVS_WARN_UNUSED_RESULT
1210 parse_bucket_str(struct ofputil_bucket *bucket, char *str_, uint8_t group_type,
1211 enum ofputil_protocol *usable_protocols)
1213 char *pos, *key, *value;
1214 struct ofpbuf ofpacts;
1218 bucket->weight = group_type == OFPGT11_SELECT ? 1 : 0;
1219 bucket->bucket_id = OFPG15_BUCKET_ALL;
1220 bucket->watch_port = OFPP_ANY;
1221 bucket->watch_group = OFPG_ANY;
1227 while (ofputil_parse_key_value(&pos, &key, &value)) {
1228 if (!strcasecmp(key, "weight")) {
1229 error = str_to_u16(value, "weight", &bucket->weight);
1230 } else if (!strcasecmp(key, "watch_port")) {
1231 if (!ofputil_port_from_string(value, &bucket->watch_port)
1232 || (ofp_to_u16(bucket->watch_port) >= ofp_to_u16(OFPP_MAX)
1233 && bucket->watch_port != OFPP_ANY)) {
1234 error = xasprintf("%s: invalid watch_port", value);
1236 } else if (!strcasecmp(key, "watch_group")) {
1237 error = str_to_u32(value, &bucket->watch_group);
1238 if (!error && bucket->watch_group > OFPG_MAX) {
1239 error = xasprintf("invalid watch_group id %"PRIu32,
1240 bucket->watch_group);
1242 } else if (!strcasecmp(key, "bucket_id")) {
1243 error = str_to_u32(value, &bucket->bucket_id);
1244 if (!error && bucket->bucket_id > OFPG15_BUCKET_MAX) {
1245 error = xasprintf("invalid bucket_id id %"PRIu32,
1248 *usable_protocols &= OFPUTIL_P_OF15_UP;
1249 } else if (!strcasecmp(key, "action") || !strcasecmp(key, "actions")) {
1250 ds_put_format(&actions, "%s,", value);
1252 ds_put_format(&actions, "%s(%s),", key, value);
1256 ds_destroy(&actions);
1261 if (!actions.length) {
1262 return xstrdup("bucket must specify actions");
1264 ds_chomp(&actions, ',');
1266 ofpbuf_init(&ofpacts, 0);
1267 error = ofpacts_parse_actions(ds_cstr(&actions), &ofpacts,
1269 ds_destroy(&actions);
1271 ofpbuf_uninit(&ofpacts);
1274 bucket->ofpacts = ofpacts.data;
1275 bucket->ofpacts_len = ofpacts.size;
1280 static char * OVS_WARN_UNUSED_RESULT
1281 parse_select_group_field(char *s, struct field_array *fa,
1282 enum ofputil_protocol *usable_protocols)
1284 char *name, *value_str;
1286 while (ofputil_parse_key_value(&s, &name, &value_str)) {
1287 const struct mf_field *mf = mf_from_name(name);
1291 union mf_value value;
1293 if (bitmap_is_set(fa->used.bm, mf->id)) {
1294 return xasprintf("%s: duplicate field", name);
1298 error = mf_parse_value(mf, value_str, &value);
1303 /* The mask cannot be all-zeros */
1304 if (!mf_is_tun_metadata(mf) &&
1305 is_all_zeros(&value, mf->n_bytes)) {
1306 return xasprintf("%s: values are wildcards here "
1307 "and must not be all-zeros", s);
1310 /* The values parsed are masks for fields used
1311 * by the selection method */
1312 if (!mf_is_mask_valid(mf, &value)) {
1313 return xasprintf("%s: invalid mask for field %s",
1314 value_str, mf->name);
1317 memset(&value, 0xff, mf->n_bytes);
1320 field_array_set(mf->id, &value, fa);
1322 if (is_all_ones(&value, mf->n_bytes)) {
1323 *usable_protocols &= mf->usable_protocols_exact;
1324 } else if (mf->usable_protocols_bitwise == mf->usable_protocols_cidr
1325 || ip_is_cidr(value.be32)) {
1326 *usable_protocols &= mf->usable_protocols_cidr;
1328 *usable_protocols &= mf->usable_protocols_bitwise;
1331 return xasprintf("%s: unknown field %s", s, name);
1338 static char * OVS_WARN_UNUSED_RESULT
1339 parse_ofp_group_mod_str__(struct ofputil_group_mod *gm, uint16_t command,
1341 enum ofputil_protocol *usable_protocols)
1344 F_GROUP_TYPE = 1 << 0,
1346 F_COMMAND_BUCKET_ID = 1 << 2,
1347 F_COMMAND_BUCKET_ID_ALL = 1 << 3,
1349 bool had_type = false;
1350 bool had_command_bucket_id = false;
1351 struct ofputil_bucket *bucket;
1354 *usable_protocols = OFPUTIL_P_OF11_UP;
1358 fields = F_GROUP_TYPE | F_BUCKETS;
1361 case OFPGC11_DELETE:
1365 case OFPGC11_MODIFY:
1366 fields = F_GROUP_TYPE | F_BUCKETS;
1369 case OFPGC15_INSERT_BUCKET:
1370 fields = F_BUCKETS | F_COMMAND_BUCKET_ID;
1371 *usable_protocols &= OFPUTIL_P_OF15_UP;
1374 case OFPGC15_REMOVE_BUCKET:
1375 fields = F_COMMAND_BUCKET_ID | F_COMMAND_BUCKET_ID_ALL;
1376 *usable_protocols &= OFPUTIL_P_OF15_UP;
1383 memset(gm, 0, sizeof *gm);
1384 gm->command = command;
1385 gm->group_id = OFPG_ANY;
1386 gm->command_bucket_id = OFPG15_BUCKET_ALL;
1387 list_init(&gm->buckets);
1388 if (command == OFPGC11_DELETE && string[0] == '\0') {
1389 gm->group_id = OFPG_ALL;
1393 *usable_protocols = OFPUTIL_P_OF11_UP;
1395 /* Strip the buckets off the end of 'string', if there are any, saving a
1396 * pointer for later. We want to parse the buckets last because the bucket
1397 * type influences bucket defaults. */
1398 char *bkt_str = strstr(string, "bucket=");
1400 if (!(fields & F_BUCKETS)) {
1401 error = xstrdup("bucket is not needed");
1407 /* Parse everything before the buckets. */
1410 while (ofputil_parse_key_value(&pos, &name, &value)) {
1411 if (!strcmp(name, "command_bucket_id")) {
1412 if (!(fields & F_COMMAND_BUCKET_ID)) {
1413 error = xstrdup("command bucket id is not needed");
1416 if (!strcmp(value, "all")) {
1417 gm->command_bucket_id = OFPG15_BUCKET_ALL;
1418 } else if (!strcmp(value, "first")) {
1419 gm->command_bucket_id = OFPG15_BUCKET_FIRST;
1420 } else if (!strcmp(value, "last")) {
1421 gm->command_bucket_id = OFPG15_BUCKET_LAST;
1423 error = str_to_u32(value, &gm->command_bucket_id);
1427 if (gm->command_bucket_id > OFPG15_BUCKET_MAX
1428 && (gm->command_bucket_id != OFPG15_BUCKET_FIRST
1429 && gm->command_bucket_id != OFPG15_BUCKET_LAST
1430 && gm->command_bucket_id != OFPG15_BUCKET_ALL)) {
1431 error = xasprintf("invalid command bucket id %"PRIu32,
1432 gm->command_bucket_id);
1436 if (gm->command_bucket_id == OFPG15_BUCKET_ALL
1437 && !(fields & F_COMMAND_BUCKET_ID_ALL)) {
1438 error = xstrdup("command_bucket_id=all is not permitted");
1441 had_command_bucket_id = true;
1442 } else if (!strcmp(name, "group_id")) {
1443 if(!strcmp(value, "all")) {
1444 gm->group_id = OFPG_ALL;
1446 error = str_to_u32(value, &gm->group_id);
1450 if (gm->group_id != OFPG_ALL && gm->group_id > OFPG_MAX) {
1451 error = xasprintf("invalid group id %"PRIu32,
1456 } else if (!strcmp(name, "type")){
1457 if (!(fields & F_GROUP_TYPE)) {
1458 error = xstrdup("type is not needed");
1461 if (!strcmp(value, "all")) {
1462 gm->type = OFPGT11_ALL;
1463 } else if (!strcmp(value, "select")) {
1464 gm->type = OFPGT11_SELECT;
1465 } else if (!strcmp(value, "indirect")) {
1466 gm->type = OFPGT11_INDIRECT;
1467 } else if (!strcmp(value, "ff") ||
1468 !strcmp(value, "fast_failover")) {
1469 gm->type = OFPGT11_FF;
1471 error = xasprintf("invalid group type %s", value);
1475 } else if (!strcmp(name, "selection_method")) {
1476 if (!(fields & F_GROUP_TYPE)) {
1477 error = xstrdup("selection method is not needed");
1480 if (strlen(value) >= NTR_MAX_SELECTION_METHOD_LEN) {
1481 error = xasprintf("selection method is longer than %u"
1483 NTR_MAX_SELECTION_METHOD_LEN - 1);
1486 memset(gm->props.selection_method, '\0',
1487 NTR_MAX_SELECTION_METHOD_LEN);
1488 strcpy(gm->props.selection_method, value);
1489 *usable_protocols &= OFPUTIL_P_OF15_UP;
1490 } else if (!strcmp(name, "selection_method_param")) {
1491 if (!(fields & F_GROUP_TYPE)) {
1492 error = xstrdup("selection method param is not needed");
1495 error = str_to_u64(value, &gm->props.selection_method_param);
1499 *usable_protocols &= OFPUTIL_P_OF15_UP;
1500 } else if (!strcmp(name, "fields")) {
1501 if (!(fields & F_GROUP_TYPE)) {
1502 error = xstrdup("fields are not needed");
1505 error = parse_select_group_field(value, &gm->props.fields,
1510 *usable_protocols &= OFPUTIL_P_OF15_UP;
1512 error = xasprintf("unknown keyword %s", name);
1516 if (gm->group_id == OFPG_ANY) {
1517 error = xstrdup("must specify a group_id");
1520 if (fields & F_GROUP_TYPE && !had_type) {
1521 error = xstrdup("must specify a type");
1525 if (fields & F_COMMAND_BUCKET_ID) {
1526 if (!(fields & F_COMMAND_BUCKET_ID_ALL || had_command_bucket_id)) {
1527 error = xstrdup("must specify a command bucket id");
1530 } else if (had_command_bucket_id) {
1531 error = xstrdup("command bucket id is not needed");
1535 /* Now parse the buckets, if any. */
1539 bkt_str = strchr(bkt_str + 1, '=');
1541 error = xstrdup("must specify bucket content");
1546 next_bkt_str = strstr(bkt_str, "bucket=");
1548 *next_bkt_str = '\0';
1551 bucket = xzalloc(sizeof(struct ofputil_bucket));
1552 error = parse_bucket_str(bucket, bkt_str, gm->type, usable_protocols);
1557 list_push_back(&gm->buckets, &bucket->list_node);
1559 if (gm->type != OFPGT11_SELECT && bucket->weight) {
1560 error = xstrdup("Only select groups can have bucket weights.");
1564 bkt_str = next_bkt_str;
1566 if (gm->type == OFPGT11_INDIRECT && !list_is_short(&gm->buckets)) {
1567 error = xstrdup("Indirect groups can have at most one bucket.");
1573 ofputil_bucket_list_destroy(&gm->buckets);
1577 char * OVS_WARN_UNUSED_RESULT
1578 parse_ofp_group_mod_str(struct ofputil_group_mod *gm, uint16_t command,
1580 enum ofputil_protocol *usable_protocols)
1582 char *string = xstrdup(str_);
1583 char *error = parse_ofp_group_mod_str__(gm, command, string,
1588 ofputil_bucket_list_destroy(&gm->buckets);
1593 char * OVS_WARN_UNUSED_RESULT
1594 parse_ofp_group_mod_file(const char *file_name, uint16_t command,
1595 struct ofputil_group_mod **gms, size_t *n_gms,
1596 enum ofputil_protocol *usable_protocols)
1598 size_t allocated_gms;
1606 stream = !strcmp(file_name, "-") ? stdin : fopen(file_name, "r");
1607 if (stream == NULL) {
1608 return xasprintf("%s: open failed (%s)",
1609 file_name, ovs_strerror(errno));
1612 allocated_gms = *n_gms;
1615 *usable_protocols = OFPUTIL_P_OF11_UP;
1616 while (!ds_get_preprocessed_line(&s, stream, &line_number)) {
1617 enum ofputil_protocol usable;
1620 if (*n_gms >= allocated_gms) {
1621 struct ofputil_group_mod *new_gms;
1624 new_gms = x2nrealloc(*gms, &allocated_gms, sizeof **gms);
1625 for (i = 0; i < *n_gms; i++) {
1626 list_moved(&new_gms[i].buckets, &(*gms)[i].buckets);
1630 error = parse_ofp_group_mod_str(&(*gms)[*n_gms], command, ds_cstr(&s),
1635 for (i = 0; i < *n_gms; i++) {
1636 ofputil_bucket_list_destroy(&(*gms)[i].buckets);
1643 if (stream != stdin) {
1647 return xasprintf("%s:%d: %s", file_name, line_number, error);
1649 *usable_protocols &= usable;
1654 if (stream != stdin) {
1660 char * OVS_WARN_UNUSED_RESULT
1661 parse_ofp_tlv_table_mod_str(struct ofputil_tlv_table_mod *ttm,
1662 uint16_t command, const char *s,
1663 enum ofputil_protocol *usable_protocols)
1665 *usable_protocols = OFPUTIL_P_NXM_OXM_ANY;
1667 ttm->command = command;
1668 list_init(&ttm->mappings);
1671 struct ofputil_tlv_map *map = xmalloc(sizeof *map);
1678 list_push_back(&ttm->mappings, &map->list_node);
1680 if (!ovs_scan(s, "{class=%"SCNi16",type=%"SCNi8",len=%"SCNi8"}->tun_metadata%"SCNi16"%n",
1681 &map->option_class, &map->option_type, &map->option_len,
1683 ofputil_uninit_tlv_table(&ttm->mappings);
1684 return xstrdup("invalid tlv mapping");