2 * Copyright (c) 2010, 2011, 2012, 2013, 2014, 2015 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"
25 #include "byte-order.h"
26 #include "dynamic-string.h"
28 #include "meta-flow.h"
29 #include "multipath.h"
32 #include "ofp-actions.h"
35 #include "openflow/openflow.h"
36 #include "ovs-thread.h"
39 #include "socket-util.h"
40 #include "openvswitch/vconn.h"
42 /* Parses 'str' as an 8-bit unsigned integer into '*valuep'.
44 * 'name' describes the value parsed in an error message, if any.
46 * Returns NULL if successful, otherwise a malloc()'d string describing the
47 * error. The caller is responsible for freeing the returned string. */
48 char * OVS_WARN_UNUSED_RESULT
49 str_to_u8(const char *str
, const char *name
, uint8_t *valuep
)
53 if (!str_to_int(str
, 0, &value
) || value
< 0 || value
> 255) {
54 return xasprintf("invalid %s \"%s\"", name
, str
);
60 /* Parses 'str' as a 16-bit unsigned integer into '*valuep'.
62 * 'name' describes the value parsed in an error message, if any.
64 * Returns NULL if successful, otherwise a malloc()'d string describing the
65 * error. The caller is responsible for freeing the returned string. */
66 char * OVS_WARN_UNUSED_RESULT
67 str_to_u16(const char *str
, const char *name
, uint16_t *valuep
)
71 if (!str_to_int(str
, 0, &value
) || value
< 0 || value
> 65535) {
72 return xasprintf("invalid %s \"%s\"", name
, str
);
78 /* Parses 'str' as a 32-bit unsigned integer into '*valuep'.
80 * Returns NULL if successful, otherwise a malloc()'d string describing the
81 * error. The caller is responsible for freeing the returned string. */
82 char * OVS_WARN_UNUSED_RESULT
83 str_to_u32(const char *str
, uint32_t *valuep
)
89 return xstrdup("missing required numeric argument");
93 value
= strtoul(str
, &tail
, 0);
94 if (errno
== EINVAL
|| errno
== ERANGE
|| *tail
) {
95 return xasprintf("invalid numeric format %s", str
);
101 /* Parses 'str' as an 64-bit unsigned integer into '*valuep'.
103 * Returns NULL if successful, otherwise a malloc()'d string describing the
104 * error. The caller is responsible for freeing the returned string. */
105 char * OVS_WARN_UNUSED_RESULT
106 str_to_u64(const char *str
, uint64_t *valuep
)
112 return xstrdup("missing required numeric argument");
116 value
= strtoull(str
, &tail
, 0);
117 if (errno
== EINVAL
|| errno
== ERANGE
|| *tail
) {
118 return xasprintf("invalid numeric format %s", str
);
124 /* Parses 'str' as an 64-bit unsigned integer in network byte order into
127 * Returns NULL if successful, otherwise a malloc()'d string describing the
128 * error. The caller is responsible for freeing the returned string. */
129 char * OVS_WARN_UNUSED_RESULT
130 str_to_be64(const char *str
, ovs_be64
*valuep
)
135 error
= str_to_u64(str
, &value
);
137 *valuep
= htonll(value
);
142 /* Parses 'str' as an Ethernet address into 'mac'.
144 * Returns NULL if successful, otherwise a malloc()'d string describing the
145 * error. The caller is responsible for freeing the returned string. */
146 char * OVS_WARN_UNUSED_RESULT
147 str_to_mac(const char *str
, uint8_t mac
[ETH_ADDR_LEN
])
149 if (!ovs_scan(str
, ETH_ADDR_SCAN_FMT
, ETH_ADDR_SCAN_ARGS(mac
))) {
150 return xasprintf("invalid mac address %s", str
);
155 /* Parses 'str' as an IP address into '*ip'.
157 * Returns NULL if successful, otherwise a malloc()'d string describing the
158 * error. The caller is responsible for freeing the returned string. */
159 char * OVS_WARN_UNUSED_RESULT
160 str_to_ip(const char *str
, ovs_be32
*ip
)
162 struct in_addr in_addr
;
164 if (lookup_ip(str
, &in_addr
)) {
165 return xasprintf("%s: could not convert to IP address", str
);
167 *ip
= in_addr
.s_addr
;
178 parse_protocol(const char *name
, const struct protocol
**p_out
)
180 static const struct protocol protocols
[] = {
181 { "ip", ETH_TYPE_IP
, 0 },
182 { "arp", ETH_TYPE_ARP
, 0 },
183 { "icmp", ETH_TYPE_IP
, IPPROTO_ICMP
},
184 { "tcp", ETH_TYPE_IP
, IPPROTO_TCP
},
185 { "udp", ETH_TYPE_IP
, IPPROTO_UDP
},
186 { "sctp", ETH_TYPE_IP
, IPPROTO_SCTP
},
187 { "ipv6", ETH_TYPE_IPV6
, 0 },
188 { "ip6", ETH_TYPE_IPV6
, 0 },
189 { "icmp6", ETH_TYPE_IPV6
, IPPROTO_ICMPV6
},
190 { "tcp6", ETH_TYPE_IPV6
, IPPROTO_TCP
},
191 { "udp6", ETH_TYPE_IPV6
, IPPROTO_UDP
},
192 { "sctp6", ETH_TYPE_IPV6
, IPPROTO_SCTP
},
193 { "rarp", ETH_TYPE_RARP
, 0},
194 { "mpls", ETH_TYPE_MPLS
, 0 },
195 { "mplsm", ETH_TYPE_MPLS_MCAST
, 0 },
197 const struct protocol
*p
;
199 for (p
= protocols
; p
< &protocols
[ARRAY_SIZE(protocols
)]; p
++) {
200 if (!strcmp(p
->name
, name
)) {
209 /* Parses 's' as the (possibly masked) value of field 'mf', and updates
210 * 'match' appropriately. Restricts the set of usable protocols to ones
211 * supporting the parsed field.
213 * Returns NULL if successful, otherwise a malloc()'d string describing the
214 * error. The caller is responsible for freeing the returned string. */
215 static char * OVS_WARN_UNUSED_RESULT
216 parse_field(const struct mf_field
*mf
, const char *s
, struct match
*match
,
217 enum ofputil_protocol
*usable_protocols
)
219 union mf_value value
, mask
;
222 error
= mf_parse(mf
, s
, &value
, &mask
);
224 *usable_protocols
&= mf_set(mf
, &value
, &mask
, match
);
230 extract_actions(char *s
)
232 s
= strstr(s
, "action");
235 s
= strchr(s
+ 1, '=');
236 return s
? s
+ 1 : NULL
;
243 static char * OVS_WARN_UNUSED_RESULT
244 parse_ofp_str__(struct ofputil_flow_mod
*fm
, int command
, char *string
,
245 enum ofputil_protocol
*usable_protocols
)
250 F_IMPORTANCE
= 1 << 2,
255 char *save_ptr
= NULL
;
256 char *act_str
= NULL
;
259 *usable_protocols
= OFPUTIL_P_ANY
;
264 string
+= strspn(string
, " \t\r\n"); /* Skip white space. */
265 len
= strcspn(string
, ", \t\r\n"); /* Get length of the first token. */
267 if (!strncmp(string
, "add", len
)) {
269 } else if (!strncmp(string
, "delete", len
)) {
270 command
= OFPFC_DELETE
;
271 } else if (!strncmp(string
, "delete_strict", len
)) {
272 command
= OFPFC_DELETE_STRICT
;
273 } else if (!strncmp(string
, "modify", len
)) {
274 command
= OFPFC_MODIFY
;
275 } else if (!strncmp(string
, "modify_strict", len
)) {
276 command
= OFPFC_MODIFY_STRICT
;
290 fields
= F_ACTIONS
| F_TIMEOUT
| F_PRIORITY
| F_FLAGS
| F_IMPORTANCE
;
297 case OFPFC_DELETE_STRICT
:
298 fields
= F_OUT_PORT
| F_PRIORITY
;
302 fields
= F_ACTIONS
| F_TIMEOUT
| F_PRIORITY
| F_FLAGS
;
305 case OFPFC_MODIFY_STRICT
:
306 fields
= F_ACTIONS
| F_TIMEOUT
| F_PRIORITY
| F_FLAGS
;
313 match_init_catchall(&fm
->match
);
314 fm
->priority
= OFP_DEFAULT_PRIORITY
;
315 fm
->cookie
= htonll(0);
316 fm
->cookie_mask
= htonll(0);
317 if (command
== OFPFC_MODIFY
|| command
== OFPFC_MODIFY_STRICT
) {
318 /* For modify, by default, don't update the cookie. */
319 fm
->new_cookie
= OVS_BE64_MAX
;
321 fm
->new_cookie
= htonll(0);
323 fm
->modify_cookie
= false;
325 fm
->command
= command
;
326 fm
->idle_timeout
= OFP_FLOW_PERMANENT
;
327 fm
->hard_timeout
= OFP_FLOW_PERMANENT
;
328 fm
->buffer_id
= UINT32_MAX
;
329 fm
->out_port
= OFPP_ANY
;
332 fm
->out_group
= OFPG11_ANY
;
333 fm
->delete_reason
= OFPRR_DELETE
;
334 if (fields
& F_ACTIONS
) {
335 act_str
= extract_actions(string
);
337 return xstrdup("must specify an action");
340 for (name
= strtok_r(string
, "=, \t\r\n", &save_ptr
); name
;
341 name
= strtok_r(NULL
, "=, \t\r\n", &save_ptr
)) {
342 const struct protocol
*p
;
345 if (parse_protocol(name
, &p
)) {
346 match_set_dl_type(&fm
->match
, htons(p
->dl_type
));
348 match_set_nw_proto(&fm
->match
, p
->nw_proto
);
350 } else if (fields
& F_FLAGS
&& !strcmp(name
, "send_flow_rem")) {
351 fm
->flags
|= OFPUTIL_FF_SEND_FLOW_REM
;
352 } else if (fields
& F_FLAGS
&& !strcmp(name
, "check_overlap")) {
353 fm
->flags
|= OFPUTIL_FF_CHECK_OVERLAP
;
354 } else if (fields
& F_FLAGS
&& !strcmp(name
, "reset_counts")) {
355 fm
->flags
|= OFPUTIL_FF_RESET_COUNTS
;
356 *usable_protocols
&= OFPUTIL_P_OF12_UP
;
357 } else if (fields
& F_FLAGS
&& !strcmp(name
, "no_packet_counts")) {
358 fm
->flags
|= OFPUTIL_FF_NO_PKT_COUNTS
;
359 *usable_protocols
&= OFPUTIL_P_OF13_UP
;
360 } else if (fields
& F_FLAGS
&& !strcmp(name
, "no_byte_counts")) {
361 fm
->flags
|= OFPUTIL_FF_NO_BYT_COUNTS
;
362 *usable_protocols
&= OFPUTIL_P_OF13_UP
;
363 } else if (!strcmp(name
, "no_readonly_table")
364 || !strcmp(name
, "allow_hidden_fields")) {
365 /* ignore these fields. */
369 value
= strtok_r(NULL
, ", \t\r\n", &save_ptr
);
371 return xasprintf("field %s missing value", name
);
374 if (!strcmp(name
, "table")) {
375 error
= str_to_u8(value
, "table", &fm
->table_id
);
376 if (fm
->table_id
!= 0xff) {
377 *usable_protocols
&= OFPUTIL_P_TID
;
379 } else if (fields
& F_OUT_PORT
&& !strcmp(name
, "out_port")) {
380 if (!ofputil_port_from_string(value
, &fm
->out_port
)) {
381 error
= xasprintf("%s is not a valid OpenFlow port",
384 } else if (fields
& F_PRIORITY
&& !strcmp(name
, "priority")) {
385 uint16_t priority
= 0;
387 error
= str_to_u16(value
, name
, &priority
);
388 fm
->priority
= priority
;
389 } else if (fields
& F_TIMEOUT
&& !strcmp(name
, "idle_timeout")) {
390 error
= str_to_u16(value
, name
, &fm
->idle_timeout
);
391 } else if (fields
& F_TIMEOUT
&& !strcmp(name
, "hard_timeout")) {
392 error
= str_to_u16(value
, name
, &fm
->hard_timeout
);
393 } else if (fields
& F_IMPORTANCE
&& !strcmp(name
, "importance")) {
394 error
= str_to_u16(value
, name
, &fm
->importance
);
395 } else if (!strcmp(name
, "cookie")) {
396 char *mask
= strchr(value
, '/');
399 /* A mask means we're searching for a cookie. */
400 if (command
== OFPFC_ADD
) {
401 return xstrdup("flow additions cannot use "
405 error
= str_to_be64(value
, &fm
->cookie
);
409 error
= str_to_be64(mask
+ 1, &fm
->cookie_mask
);
411 /* Matching of the cookie is only supported through NXM or
413 if (fm
->cookie_mask
!= htonll(0)) {
414 *usable_protocols
&= OFPUTIL_P_NXM_OF11_UP
;
417 /* No mask means that the cookie is being set. */
418 if (command
!= OFPFC_ADD
&& command
!= OFPFC_MODIFY
419 && command
!= OFPFC_MODIFY_STRICT
) {
420 return xstrdup("cannot set cookie");
422 error
= str_to_be64(value
, &fm
->new_cookie
);
423 fm
->modify_cookie
= true;
425 } else if (mf_from_name(name
)) {
426 error
= parse_field(mf_from_name(name
), value
, &fm
->match
,
428 } else if (!strcmp(name
, "duration")
429 || !strcmp(name
, "n_packets")
430 || !strcmp(name
, "n_bytes")
431 || !strcmp(name
, "idle_age")
432 || !strcmp(name
, "hard_age")) {
433 /* Ignore these, so that users can feed the output of
434 * "ovs-ofctl dump-flows" back into commands that parse
437 error
= xasprintf("unknown keyword %s", name
);
445 /* Check for usable protocol interdependencies between match fields. */
446 if (fm
->match
.flow
.dl_type
== htons(ETH_TYPE_IPV6
)) {
447 const struct flow_wildcards
*wc
= &fm
->match
.wc
;
448 /* Only NXM and OXM support matching L3 and L4 fields within IPv6.
450 * (IPv6 specific fields as well as arp_sha, arp_tha, nw_frag, and
451 * nw_ttl are covered elsewhere so they don't need to be included in
454 if (wc
->masks
.nw_proto
|| wc
->masks
.nw_tos
455 || wc
->masks
.tp_src
|| wc
->masks
.tp_dst
) {
456 *usable_protocols
&= OFPUTIL_P_NXM_OXM_ANY
;
459 if (!fm
->cookie_mask
&& fm
->new_cookie
== OVS_BE64_MAX
460 && (command
== OFPFC_MODIFY
|| command
== OFPFC_MODIFY_STRICT
)) {
461 /* On modifies without a mask, we are supposed to add a flow if
462 * one does not exist. If a cookie wasn't been specified, use a
463 * default of zero. */
464 fm
->new_cookie
= htonll(0);
466 if (fields
& F_ACTIONS
) {
467 enum ofputil_protocol action_usable_protocols
;
468 struct ofpbuf ofpacts
;
471 ofpbuf_init(&ofpacts
, 32);
472 error
= ofpacts_parse_instructions(act_str
, &ofpacts
,
473 &action_usable_protocols
);
474 *usable_protocols
&= action_usable_protocols
;
478 err
= ofpacts_check(ofpacts
.data
, ofpacts
.size
, &fm
->match
.flow
,
479 OFPP_MAX
, fm
->table_id
, 255, usable_protocols
);
480 if (!err
&& !usable_protocols
) {
481 err
= OFPERR_OFPBAC_MATCH_INCONSISTENT
;
484 error
= xasprintf("actions are invalid with specified match "
485 "(%s)", ofperr_to_string(err
));
490 ofpbuf_uninit(&ofpacts
);
494 fm
->ofpacts_len
= ofpacts
.size
;
495 fm
->ofpacts
= ofpbuf_steal_data(&ofpacts
);
504 /* Convert 'str_' (as described in the Flow Syntax section of the ovs-ofctl man
505 * page) into 'fm' for sending the specified flow_mod 'command' to a switch.
506 * Returns the set of usable protocols in '*usable_protocols'.
508 * To parse syntax for an OFPT_FLOW_MOD (or NXT_FLOW_MOD), use an OFPFC_*
509 * constant for 'command'. To parse syntax for an OFPST_FLOW or
510 * OFPST_AGGREGATE (or NXST_FLOW or NXST_AGGREGATE), use -1 for 'command'.
512 * If 'command' is given as -2, 'str_' may begin with a command name ("add",
513 * "modify", "delete", "modify_strict", or "delete_strict"). A missing command
514 * name is treated as "add".
516 * Returns NULL if successful, otherwise a malloc()'d string describing the
517 * error. The caller is responsible for freeing the returned string. */
518 char * OVS_WARN_UNUSED_RESULT
519 parse_ofp_str(struct ofputil_flow_mod
*fm
, int command
, const char *str_
,
520 enum ofputil_protocol
*usable_protocols
)
522 char *string
= xstrdup(str_
);
525 error
= parse_ofp_str__(fm
, command
, string
, usable_protocols
);
535 static char * OVS_WARN_UNUSED_RESULT
536 parse_ofp_meter_mod_str__(struct ofputil_meter_mod
*mm
, char *string
,
537 struct ofpbuf
*bands
, int command
,
538 enum ofputil_protocol
*usable_protocols
)
545 char *save_ptr
= NULL
;
546 char *band_str
= NULL
;
549 /* Meters require at least OF 1.3. */
550 *usable_protocols
= OFPUTIL_P_OF13_UP
;
558 fields
= F_METER
| F_FLAGS
| F_BANDS
;
566 fields
= F_METER
| F_FLAGS
| F_BANDS
;
573 mm
->command
= command
;
574 mm
->meter
.meter_id
= 0;
576 if (fields
& F_BANDS
) {
577 band_str
= strstr(string
, "band");
579 return xstrdup("must specify bands");
583 band_str
= strchr(band_str
+ 1, '=');
585 return xstrdup("must specify bands");
590 for (name
= strtok_r(string
, "=, \t\r\n", &save_ptr
); name
;
591 name
= strtok_r(NULL
, "=, \t\r\n", &save_ptr
)) {
593 if (fields
& F_FLAGS
&& !strcmp(name
, "kbps")) {
594 mm
->meter
.flags
|= OFPMF13_KBPS
;
595 } else if (fields
& F_FLAGS
&& !strcmp(name
, "pktps")) {
596 mm
->meter
.flags
|= OFPMF13_PKTPS
;
597 } else if (fields
& F_FLAGS
&& !strcmp(name
, "burst")) {
598 mm
->meter
.flags
|= OFPMF13_BURST
;
599 } else if (fields
& F_FLAGS
&& !strcmp(name
, "stats")) {
600 mm
->meter
.flags
|= OFPMF13_STATS
;
604 value
= strtok_r(NULL
, ", \t\r\n", &save_ptr
);
606 return xasprintf("field %s missing value", name
);
609 if (!strcmp(name
, "meter")) {
610 if (!strcmp(value
, "all")) {
611 mm
->meter
.meter_id
= OFPM13_ALL
;
612 } else if (!strcmp(value
, "controller")) {
613 mm
->meter
.meter_id
= OFPM13_CONTROLLER
;
614 } else if (!strcmp(value
, "slowpath")) {
615 mm
->meter
.meter_id
= OFPM13_SLOWPATH
;
617 char *error
= str_to_u32(value
, &mm
->meter
.meter_id
);
621 if (mm
->meter
.meter_id
> OFPM13_MAX
622 || !mm
->meter
.meter_id
) {
623 return xasprintf("invalid value for %s", name
);
627 return xasprintf("unknown keyword %s", name
);
631 if (fields
& F_METER
&& !mm
->meter
.meter_id
) {
632 return xstrdup("must specify 'meter'");
634 if (fields
& F_FLAGS
&& !mm
->meter
.flags
) {
635 return xstrdup("meter must specify either 'kbps' or 'pktps'");
638 if (fields
& F_BANDS
) {
639 uint16_t n_bands
= 0;
640 struct ofputil_meter_band
*band
= NULL
;
643 for (name
= strtok_r(band_str
, "=, \t\r\n", &save_ptr
); name
;
644 name
= strtok_r(NULL
, "=, \t\r\n", &save_ptr
)) {
648 value
= strtok_r(NULL
, ", \t\r\n", &save_ptr
);
650 return xasprintf("field %s missing value", name
);
653 if (!strcmp(name
, "type")) {
654 /* Start a new band */
655 band
= ofpbuf_put_zeros(bands
, sizeof *band
);
658 if (!strcmp(value
, "drop")) {
659 band
->type
= OFPMBT13_DROP
;
660 } else if (!strcmp(value
, "dscp_remark")) {
661 band
->type
= OFPMBT13_DSCP_REMARK
;
663 return xasprintf("field %s unknown value %s", name
, value
);
665 } else if (!band
|| !band
->type
) {
666 return xstrdup("band must start with the 'type' keyword");
667 } else if (!strcmp(name
, "rate")) {
668 char *error
= str_to_u32(value
, &band
->rate
);
672 } else if (!strcmp(name
, "burst_size")) {
673 char *error
= str_to_u32(value
, &band
->burst_size
);
677 } else if (!strcmp(name
, "prec_level")) {
678 char *error
= str_to_u8(value
, name
, &band
->prec_level
);
683 return xasprintf("unknown keyword %s", name
);
688 return xstrdup("meter must have bands");
691 mm
->meter
.n_bands
= n_bands
;
692 mm
->meter
.bands
= ofpbuf_steal_data(bands
);
694 for (i
= 0; i
< n_bands
; ++i
) {
695 band
= &mm
->meter
.bands
[i
];
698 return xstrdup("band must have 'type'");
700 if (band
->type
== OFPMBT13_DSCP_REMARK
) {
701 if (!band
->prec_level
) {
702 return xstrdup("'dscp_remark' band must have"
706 if (band
->prec_level
) {
707 return xstrdup("Only 'dscp_remark' band may have"
712 return xstrdup("band must have 'rate'");
714 if (mm
->meter
.flags
& OFPMF13_BURST
) {
715 if (!band
->burst_size
) {
716 return xstrdup("band must have 'burst_size' "
717 "when 'burst' flag is set");
720 if (band
->burst_size
) {
721 return xstrdup("band may have 'burst_size' only "
722 "when 'burst' flag is set");
727 mm
->meter
.n_bands
= 0;
728 mm
->meter
.bands
= NULL
;
734 /* Convert 'str_' (as described in the Flow Syntax section of the ovs-ofctl man
735 * page) into 'mm' for sending the specified meter_mod 'command' to a switch.
737 * Returns NULL if successful, otherwise a malloc()'d string describing the
738 * error. The caller is responsible for freeing the returned string. */
739 char * OVS_WARN_UNUSED_RESULT
740 parse_ofp_meter_mod_str(struct ofputil_meter_mod
*mm
, const char *str_
,
741 int command
, enum ofputil_protocol
*usable_protocols
)
747 ofpbuf_init(&bands
, 64);
748 string
= xstrdup(str_
);
750 error
= parse_ofp_meter_mod_str__(mm
, string
, &bands
, command
,
754 ofpbuf_uninit(&bands
);
759 static char * OVS_WARN_UNUSED_RESULT
760 parse_flow_monitor_request__(struct ofputil_flow_monitor_request
*fmr
,
761 const char *str_
, char *string
,
762 enum ofputil_protocol
*usable_protocols
)
764 static atomic_count id
= ATOMIC_COUNT_INIT(0);
765 char *save_ptr
= NULL
;
768 fmr
->id
= atomic_count_inc(&id
);
770 fmr
->flags
= (NXFMF_INITIAL
| NXFMF_ADD
| NXFMF_DELETE
| NXFMF_MODIFY
771 | NXFMF_OWN
| NXFMF_ACTIONS
);
772 fmr
->out_port
= OFPP_NONE
;
773 fmr
->table_id
= 0xff;
774 match_init_catchall(&fmr
->match
);
776 for (name
= strtok_r(string
, "=, \t\r\n", &save_ptr
); name
;
777 name
= strtok_r(NULL
, "=, \t\r\n", &save_ptr
)) {
778 const struct protocol
*p
;
780 if (!strcmp(name
, "!initial")) {
781 fmr
->flags
&= ~NXFMF_INITIAL
;
782 } else if (!strcmp(name
, "!add")) {
783 fmr
->flags
&= ~NXFMF_ADD
;
784 } else if (!strcmp(name
, "!delete")) {
785 fmr
->flags
&= ~NXFMF_DELETE
;
786 } else if (!strcmp(name
, "!modify")) {
787 fmr
->flags
&= ~NXFMF_MODIFY
;
788 } else if (!strcmp(name
, "!actions")) {
789 fmr
->flags
&= ~NXFMF_ACTIONS
;
790 } else if (!strcmp(name
, "!own")) {
791 fmr
->flags
&= ~NXFMF_OWN
;
792 } else if (parse_protocol(name
, &p
)) {
793 match_set_dl_type(&fmr
->match
, htons(p
->dl_type
));
795 match_set_nw_proto(&fmr
->match
, p
->nw_proto
);
800 value
= strtok_r(NULL
, ", \t\r\n", &save_ptr
);
802 return xasprintf("%s: field %s missing value", str_
, name
);
805 if (!strcmp(name
, "table")) {
806 char *error
= str_to_u8(value
, "table", &fmr
->table_id
);
810 } else if (!strcmp(name
, "out_port")) {
811 fmr
->out_port
= u16_to_ofp(atoi(value
));
812 } else if (mf_from_name(name
)) {
815 error
= parse_field(mf_from_name(name
), value
, &fmr
->match
,
821 return xasprintf("%s: unknown keyword %s", str_
, name
);
828 /* Convert 'str_' (as described in the documentation for the "monitor" command
829 * in the ovs-ofctl man page) into 'fmr'.
831 * Returns NULL if successful, otherwise a malloc()'d string describing the
832 * error. The caller is responsible for freeing the returned string. */
833 char * OVS_WARN_UNUSED_RESULT
834 parse_flow_monitor_request(struct ofputil_flow_monitor_request
*fmr
,
836 enum ofputil_protocol
*usable_protocols
)
838 char *string
= xstrdup(str_
);
839 char *error
= parse_flow_monitor_request__(fmr
, str_
, string
,
845 /* Parses 'string' as an OFPT_FLOW_MOD or NXT_FLOW_MOD with command 'command'
846 * (one of OFPFC_*) into 'fm'.
848 * If 'command' is given as -2, 'string' may begin with a command name ("add",
849 * "modify", "delete", "modify_strict", or "delete_strict"). A missing command
850 * name is treated as "add".
852 * Returns NULL if successful, otherwise a malloc()'d string describing the
853 * error. The caller is responsible for freeing the returned string. */
854 char * OVS_WARN_UNUSED_RESULT
855 parse_ofp_flow_mod_str(struct ofputil_flow_mod
*fm
, const char *string
,
857 enum ofputil_protocol
*usable_protocols
)
859 char *error
= parse_ofp_str(fm
, command
, string
, usable_protocols
);
862 /* Normalize a copy of the match. This ensures that non-normalized
863 * flows get logged but doesn't affect what gets sent to the switch, so
864 * that the switch can do whatever it likes with the flow. */
865 struct match match_copy
= fm
->match
;
866 ofputil_normalize_match(&match_copy
);
872 /* Convert 'table_id' and 'flow_miss_handling' (as described for the
873 * "mod-table" command in the ovs-ofctl man page) into 'tm' for sending the
874 * specified table_mod 'command' to a switch.
876 * Returns NULL if successful, otherwise a malloc()'d string describing the
877 * error. The caller is responsible for freeing the returned string. */
878 char * OVS_WARN_UNUSED_RESULT
879 parse_ofp_table_mod(struct ofputil_table_mod
*tm
, const char *table_id
,
880 const char *flow_miss_handling
,
881 enum ofputil_protocol
*usable_protocols
)
883 /* Table mod requires at least OF 1.1. */
884 *usable_protocols
= OFPUTIL_P_OF11_UP
;
886 if (!strcasecmp(table_id
, "all")) {
887 tm
->table_id
= OFPTT_ALL
;
889 char *error
= str_to_u8(table_id
, "table_id", &tm
->table_id
);
895 if (strcmp(flow_miss_handling
, "controller") == 0) {
896 tm
->miss_config
= OFPUTIL_TABLE_MISS_CONTROLLER
;
897 } else if (strcmp(flow_miss_handling
, "continue") == 0) {
898 tm
->miss_config
= OFPUTIL_TABLE_MISS_CONTINUE
;
899 } else if (strcmp(flow_miss_handling
, "drop") == 0) {
900 tm
->miss_config
= OFPUTIL_TABLE_MISS_DROP
;
902 return xasprintf("invalid flow_miss_handling %s", flow_miss_handling
);
905 if (tm
->table_id
== 0xfe
906 && tm
->miss_config
== OFPUTIL_TABLE_MISS_CONTINUE
) {
907 return xstrdup("last table's flow miss handling can not be continue");
914 /* Opens file 'file_name' and reads each line as a flow_mod of the specified
915 * type (one of OFPFC_*). Stores each flow_mod in '*fm', an array allocated
916 * on the caller's behalf, and the number of flow_mods in '*n_fms'.
918 * If 'command' is given as -2, each line may start with a command name
919 * ("add", "modify", "delete", "modify_strict", or "delete_strict"). A missing
920 * command name is treated as "add".
922 * Returns NULL if successful, otherwise a malloc()'d string describing the
923 * error. The caller is responsible for freeing the returned string. */
924 char * OVS_WARN_UNUSED_RESULT
925 parse_ofp_flow_mod_file(const char *file_name
, int command
,
926 struct ofputil_flow_mod
**fms
, size_t *n_fms
,
927 enum ofputil_protocol
*usable_protocols
)
929 size_t allocated_fms
;
934 *usable_protocols
= OFPUTIL_P_ANY
;
939 stream
= !strcmp(file_name
, "-") ? stdin
: fopen(file_name
, "r");
940 if (stream
== NULL
) {
941 return xasprintf("%s: open failed (%s)",
942 file_name
, ovs_strerror(errno
));
945 allocated_fms
= *n_fms
;
948 while (!ds_get_preprocessed_line(&s
, stream
, &line_number
)) {
950 enum ofputil_protocol usable
;
952 if (*n_fms
>= allocated_fms
) {
953 *fms
= x2nrealloc(*fms
, &allocated_fms
, sizeof **fms
);
955 error
= parse_ofp_flow_mod_str(&(*fms
)[*n_fms
], ds_cstr(&s
), command
,
960 for (i
= 0; i
< *n_fms
; i
++) {
961 free(CONST_CAST(struct ofpact
*, (*fms
)[i
].ofpacts
));
968 if (stream
!= stdin
) {
972 return xasprintf("%s:%d: %s", file_name
, line_number
, error
);
974 *usable_protocols
&= usable
; /* Each line can narrow the set. */
979 if (stream
!= stdin
) {
985 char * OVS_WARN_UNUSED_RESULT
986 parse_ofp_flow_stats_request_str(struct ofputil_flow_stats_request
*fsr
,
987 bool aggregate
, const char *string
,
988 enum ofputil_protocol
*usable_protocols
)
990 struct ofputil_flow_mod fm
;
993 error
= parse_ofp_str(&fm
, -1, string
, usable_protocols
);
998 /* Special table ID support not required for stats requests. */
999 if (*usable_protocols
& OFPUTIL_P_OF10_STD_TID
) {
1000 *usable_protocols
|= OFPUTIL_P_OF10_STD
;
1002 if (*usable_protocols
& OFPUTIL_P_OF10_NXM_TID
) {
1003 *usable_protocols
|= OFPUTIL_P_OF10_NXM
;
1006 fsr
->aggregate
= aggregate
;
1007 fsr
->cookie
= fm
.cookie
;
1008 fsr
->cookie_mask
= fm
.cookie_mask
;
1009 fsr
->match
= fm
.match
;
1010 fsr
->out_port
= fm
.out_port
;
1011 fsr
->out_group
= fm
.out_group
;
1012 fsr
->table_id
= fm
.table_id
;
1016 /* Parses a specification of a flow from 's' into 'flow'. 's' must take the
1017 * form FIELD=VALUE[,FIELD=VALUE]... where each FIELD is the name of a
1018 * mf_field. Fields must be specified in a natural order for satisfying
1019 * prerequisites. If 'mask' is specified, fills the mask field for each of the
1020 * field specified in flow. If the map, 'names_portno' is specfied, converts
1021 * the in_port name into port no while setting the 'flow'.
1023 * Returns NULL on success, otherwise a malloc()'d string that explains the
1026 parse_ofp_exact_flow(struct flow
*flow
, struct flow
*mask
, const char *s
,
1027 const struct simap
*portno_names
)
1029 char *pos
, *key
, *value_s
;
1033 memset(flow
, 0, sizeof *flow
);
1035 memset(mask
, 0, sizeof *mask
);
1038 pos
= copy
= xstrdup(s
);
1039 while (ofputil_parse_key_value(&pos
, &key
, &value_s
)) {
1040 const struct protocol
*p
;
1041 if (parse_protocol(key
, &p
)) {
1042 if (flow
->dl_type
) {
1043 error
= xasprintf("%s: Ethernet type set multiple times", s
);
1046 flow
->dl_type
= htons(p
->dl_type
);
1048 mask
->dl_type
= OVS_BE16_MAX
;
1052 if (flow
->nw_proto
) {
1053 error
= xasprintf("%s: network protocol set "
1054 "multiple times", s
);
1057 flow
->nw_proto
= p
->nw_proto
;
1059 mask
->nw_proto
= UINT8_MAX
;
1063 const struct mf_field
*mf
;
1064 union mf_value value
;
1067 mf
= mf_from_name(key
);
1069 error
= xasprintf("%s: unknown field %s", s
, key
);
1073 if (!mf_are_prereqs_ok(mf
, flow
)) {
1074 error
= xasprintf("%s: prerequisites not met for setting %s",
1079 if (!mf_is_zero(mf
, flow
)) {
1080 error
= xasprintf("%s: field %s set multiple times", s
, key
);
1084 if (!strcmp(key
, "in_port")
1086 && simap_contains(portno_names
, value_s
)) {
1087 flow
->in_port
.ofp_port
= u16_to_ofp(
1088 simap_get(portno_names
, value_s
));
1090 mask
->in_port
.ofp_port
= u16_to_ofp(ntohs(OVS_BE16_MAX
));
1093 field_error
= mf_parse_value(mf
, value_s
, &value
);
1095 error
= xasprintf("%s: bad value for %s (%s)",
1096 s
, key
, field_error
);
1101 mf_set_flow_value(mf
, &value
, flow
);
1103 mf_mask_field(mf
, mask
);
1109 if (!flow
->in_port
.ofp_port
) {
1110 flow
->in_port
.ofp_port
= OFPP_NONE
;
1117 memset(flow
, 0, sizeof *flow
);
1119 memset(mask
, 0, sizeof *mask
);
1125 static char * OVS_WARN_UNUSED_RESULT
1126 parse_bucket_str(struct ofputil_bucket
*bucket
, char *str_
,
1127 enum ofputil_protocol
*usable_protocols
)
1129 char *pos
, *key
, *value
;
1130 struct ofpbuf ofpacts
;
1135 bucket
->bucket_id
= OFPG15_BUCKET_ALL
;
1136 bucket
->watch_port
= OFPP_ANY
;
1137 bucket
->watch_group
= OFPG11_ANY
;
1143 while (ofputil_parse_key_value(&pos
, &key
, &value
)) {
1144 if (!strcasecmp(key
, "weight")) {
1145 error
= str_to_u16(value
, "weight", &bucket
->weight
);
1146 } else if (!strcasecmp(key
, "watch_port")) {
1147 if (!ofputil_port_from_string(value
, &bucket
->watch_port
)
1148 || (ofp_to_u16(bucket
->watch_port
) >= ofp_to_u16(OFPP_MAX
)
1149 && bucket
->watch_port
!= OFPP_ANY
)) {
1150 error
= xasprintf("%s: invalid watch_port", value
);
1152 } else if (!strcasecmp(key
, "watch_group")) {
1153 error
= str_to_u32(value
, &bucket
->watch_group
);
1154 if (!error
&& bucket
->watch_group
> OFPG_MAX
) {
1155 error
= xasprintf("invalid watch_group id %"PRIu32
,
1156 bucket
->watch_group
);
1158 } else if (!strcasecmp(key
, "bucket_id")) {
1159 error
= str_to_u32(value
, &bucket
->bucket_id
);
1160 if (!error
&& bucket
->bucket_id
> OFPG15_BUCKET_MAX
) {
1161 error
= xasprintf("invalid bucket_id id %"PRIu32
,
1164 *usable_protocols
&= OFPUTIL_P_OF15_UP
;
1165 } else if (!strcasecmp(key
, "action") || !strcasecmp(key
, "actions")) {
1166 ds_put_format(&actions
, "%s,", value
);
1168 ds_put_format(&actions
, "%s(%s),", key
, value
);
1172 ds_destroy(&actions
);
1177 if (!actions
.length
) {
1178 return xstrdup("bucket must specify actions");
1180 ds_chomp(&actions
, ',');
1182 ofpbuf_init(&ofpacts
, 0);
1183 error
= ofpacts_parse_actions(ds_cstr(&actions
), &ofpacts
,
1185 ds_destroy(&actions
);
1187 ofpbuf_uninit(&ofpacts
);
1190 bucket
->ofpacts
= ofpacts
.data
;
1191 bucket
->ofpacts_len
= ofpacts
.size
;
1196 static char * OVS_WARN_UNUSED_RESULT
1197 parse_select_group_field(char *s
, struct field_array
*fa
,
1198 enum ofputil_protocol
*usable_protocols
)
1200 char *save_ptr
= NULL
;
1203 for (name
= strtok_r(s
, "=, \t\r\n", &save_ptr
); name
;
1204 name
= strtok_r(NULL
, "=, \t\r\n", &save_ptr
)) {
1205 const struct mf_field
*mf
= mf_from_name(name
);
1209 const char *value_str
;
1210 union mf_value value
;
1212 if (bitmap_is_set(fa
->used
.bm
, mf
->id
)) {
1213 return xasprintf("%s: duplicate field", name
);
1216 value_str
= strtok_r(NULL
, ", \t\r\n", &save_ptr
);
1218 error
= mf_parse_value(mf
, value_str
, &value
);
1223 /* The mask cannot be all-zeros */
1224 if (is_all_zeros(&value
, mf
->n_bytes
)) {
1225 return xasprintf("%s: values are wildcards here "
1226 "and must not be all-zeros", s
);
1229 /* The values parsed are masks for fields used
1230 * by the selection method */
1231 if (!mf_is_mask_valid(mf
, &value
)) {
1232 return xasprintf("%s: invalid mask for field %s",
1233 value_str
, mf
->name
);
1236 memset(&value
, 0xff, mf
->n_bytes
);
1239 field_array_set(mf
->id
, &value
, fa
);
1241 if (is_all_ones(&value
, mf
->n_bytes
)) {
1242 *usable_protocols
&= mf
->usable_protocols_exact
;
1243 } else if (mf
->usable_protocols_bitwise
== mf
->usable_protocols_cidr
1244 || ip_is_cidr(value
.be32
)) {
1245 *usable_protocols
&= mf
->usable_protocols_cidr
;
1247 *usable_protocols
&= mf
->usable_protocols_bitwise
;
1250 return xasprintf("%s: unknown field %s", s
, name
);
1257 static char * OVS_WARN_UNUSED_RESULT
1258 parse_ofp_group_mod_str__(struct ofputil_group_mod
*gm
, uint16_t command
,
1260 enum ofputil_protocol
*usable_protocols
)
1263 F_GROUP_TYPE
= 1 << 0,
1265 F_COMMAND_BUCKET_ID
= 1 << 2,
1266 F_COMMAND_BUCKET_ID_ALL
= 1 << 3,
1268 char *save_ptr
= NULL
;
1269 bool had_type
= false;
1270 bool had_command_bucket_id
= false;
1272 struct ofputil_bucket
*bucket
;
1275 *usable_protocols
= OFPUTIL_P_OF11_UP
;
1279 fields
= F_GROUP_TYPE
| F_BUCKETS
;
1282 case OFPGC11_DELETE
:
1286 case OFPGC11_MODIFY
:
1287 fields
= F_GROUP_TYPE
| F_BUCKETS
;
1290 case OFPGC15_INSERT_BUCKET
:
1291 fields
= F_BUCKETS
| F_COMMAND_BUCKET_ID
;
1292 *usable_protocols
&= OFPUTIL_P_OF15_UP
;
1295 case OFPGC15_REMOVE_BUCKET
:
1296 fields
= F_COMMAND_BUCKET_ID
| F_COMMAND_BUCKET_ID_ALL
;
1297 *usable_protocols
&= OFPUTIL_P_OF15_UP
;
1304 memset(gm
, 0, sizeof *gm
);
1305 gm
->command
= command
;
1306 gm
->group_id
= OFPG_ANY
;
1307 gm
->command_bucket_id
= OFPG15_BUCKET_ALL
;
1308 list_init(&gm
->buckets
);
1309 if (command
== OFPGC11_DELETE
&& string
[0] == '\0') {
1310 gm
->group_id
= OFPG_ALL
;
1314 *usable_protocols
= OFPUTIL_P_OF11_UP
;
1316 if (fields
& F_BUCKETS
) {
1317 char *bkt_str
= strstr(string
, "bucket=");
1326 bkt_str
= strchr(bkt_str
+ 1, '=');
1328 error
= xstrdup("must specify bucket content");
1333 next_bkt_str
= strstr(bkt_str
, "bucket=");
1335 *next_bkt_str
= '\0';
1338 bucket
= xzalloc(sizeof(struct ofputil_bucket
));
1339 error
= parse_bucket_str(bucket
, bkt_str
, usable_protocols
);
1344 list_push_back(&gm
->buckets
, &bucket
->list_node
);
1346 bkt_str
= next_bkt_str
;
1350 for (name
= strtok_r(string
, "=, \t\r\n", &save_ptr
); name
;
1351 name
= strtok_r(NULL
, "=, \t\r\n", &save_ptr
)) {
1354 value
= strtok_r(NULL
, ", \t\r\n", &save_ptr
);
1356 error
= xasprintf("field %s missing value", name
);
1360 if (!strcmp(name
, "command_bucket_id")) {
1361 if (!(fields
& F_COMMAND_BUCKET_ID
)) {
1362 error
= xstrdup("command bucket id is not needed");
1365 if (!strcmp(value
, "all")) {
1366 gm
->command_bucket_id
= OFPG15_BUCKET_ALL
;
1367 } else if (!strcmp(value
, "first")) {
1368 gm
->command_bucket_id
= OFPG15_BUCKET_FIRST
;
1369 } else if (!strcmp(value
, "last")) {
1370 gm
->command_bucket_id
= OFPG15_BUCKET_LAST
;
1372 error
= str_to_u32(value
, &gm
->command_bucket_id
);
1376 if (gm
->command_bucket_id
> OFPG15_BUCKET_MAX
1377 && (gm
->command_bucket_id
!= OFPG15_BUCKET_FIRST
1378 && gm
->command_bucket_id
!= OFPG15_BUCKET_LAST
1379 && gm
->command_bucket_id
!= OFPG15_BUCKET_ALL
)) {
1380 error
= xasprintf("invalid command bucket id %"PRIu32
,
1381 gm
->command_bucket_id
);
1385 if (gm
->command_bucket_id
== OFPG15_BUCKET_ALL
1386 && !(fields
& F_COMMAND_BUCKET_ID_ALL
)) {
1387 error
= xstrdup("command_bucket_id=all is not permitted");
1390 had_command_bucket_id
= true;
1391 } else if (!strcmp(name
, "group_id")) {
1392 if(!strcmp(value
, "all")) {
1393 gm
->group_id
= OFPG_ALL
;
1395 error
= str_to_u32(value
, &gm
->group_id
);
1399 if (gm
->group_id
!= OFPG_ALL
&& gm
->group_id
> OFPG_MAX
) {
1400 error
= xasprintf("invalid group id %"PRIu32
,
1405 } else if (!strcmp(name
, "type")){
1406 if (!(fields
& F_GROUP_TYPE
)) {
1407 error
= xstrdup("type is not needed");
1410 if (!strcmp(value
, "all")) {
1411 gm
->type
= OFPGT11_ALL
;
1412 } else if (!strcmp(value
, "select")) {
1413 gm
->type
= OFPGT11_SELECT
;
1414 } else if (!strcmp(value
, "indirect")) {
1415 gm
->type
= OFPGT11_INDIRECT
;
1416 } else if (!strcmp(value
, "ff") ||
1417 !strcmp(value
, "fast_failover")) {
1418 gm
->type
= OFPGT11_FF
;
1420 error
= xasprintf("invalid group type %s", value
);
1424 } else if (!strcmp(name
, "bucket")) {
1425 error
= xstrdup("bucket is not needed");
1427 } else if (!strcmp(name
, "selection_method")) {
1428 if (!(fields
& F_GROUP_TYPE
)) {
1429 error
= xstrdup("selection method is not needed");
1432 if (strlen(value
) >= NTR_MAX_SELECTION_METHOD_LEN
) {
1433 error
= xasprintf("selection method is longer than %u"
1435 NTR_MAX_SELECTION_METHOD_LEN
- 1);
1438 memset(gm
->props
.selection_method
, '\0',
1439 NTR_MAX_SELECTION_METHOD_LEN
);
1440 strcpy(gm
->props
.selection_method
, value
);
1441 *usable_protocols
&= OFPUTIL_P_OF15_UP
;
1442 } else if (!strcmp(name
, "selection_method_param")) {
1443 if (!(fields
& F_GROUP_TYPE
)) {
1444 error
= xstrdup("selection method param is not needed");
1447 error
= str_to_u64(value
, &gm
->props
.selection_method_param
);
1451 *usable_protocols
&= OFPUTIL_P_OF15_UP
;
1452 } else if (!strcmp(name
, "fields")) {
1453 if (!(fields
& F_GROUP_TYPE
)) {
1454 error
= xstrdup("fields are not needed");
1457 error
= parse_select_group_field(value
, &gm
->props
.fields
,
1462 *usable_protocols
&= OFPUTIL_P_OF15_UP
;
1464 error
= xasprintf("unknown keyword %s", name
);
1468 if (gm
->group_id
== OFPG_ANY
) {
1469 error
= xstrdup("must specify a group_id");
1472 if (fields
& F_GROUP_TYPE
&& !had_type
) {
1473 error
= xstrdup("must specify a type");
1477 if (fields
& F_COMMAND_BUCKET_ID
) {
1478 if (!(fields
& F_COMMAND_BUCKET_ID_ALL
|| had_command_bucket_id
)) {
1479 error
= xstrdup("must specify a command bucket id");
1482 } else if (had_command_bucket_id
) {
1483 error
= xstrdup("command bucket id is not needed");
1487 /* Validate buckets. */
1488 LIST_FOR_EACH (bucket
, list_node
, &gm
->buckets
) {
1489 if (bucket
->weight
!= 1 && gm
->type
!= OFPGT11_SELECT
) {
1490 error
= xstrdup("Only select groups can have bucket weights.");
1494 if (gm
->type
== OFPGT11_INDIRECT
&& !list_is_short(&gm
->buckets
)) {
1495 error
= xstrdup("Indirect groups can have at most one bucket.");
1501 ofputil_bucket_list_destroy(&gm
->buckets
);
1505 char * OVS_WARN_UNUSED_RESULT
1506 parse_ofp_group_mod_str(struct ofputil_group_mod
*gm
, uint16_t command
,
1508 enum ofputil_protocol
*usable_protocols
)
1510 char *string
= xstrdup(str_
);
1511 char *error
= parse_ofp_group_mod_str__(gm
, command
, string
,
1516 ofputil_bucket_list_destroy(&gm
->buckets
);
1521 char * OVS_WARN_UNUSED_RESULT
1522 parse_ofp_group_mod_file(const char *file_name
, uint16_t command
,
1523 struct ofputil_group_mod
**gms
, size_t *n_gms
,
1524 enum ofputil_protocol
*usable_protocols
)
1526 size_t allocated_gms
;
1534 stream
= !strcmp(file_name
, "-") ? stdin
: fopen(file_name
, "r");
1535 if (stream
== NULL
) {
1536 return xasprintf("%s: open failed (%s)",
1537 file_name
, ovs_strerror(errno
));
1540 allocated_gms
= *n_gms
;
1543 *usable_protocols
= OFPUTIL_P_OF11_UP
;
1544 while (!ds_get_preprocessed_line(&s
, stream
, &line_number
)) {
1545 enum ofputil_protocol usable
;
1548 if (*n_gms
>= allocated_gms
) {
1549 struct ofputil_group_mod
*new_gms
;
1552 new_gms
= x2nrealloc(*gms
, &allocated_gms
, sizeof **gms
);
1553 for (i
= 0; i
< *n_gms
; i
++) {
1554 list_moved(&new_gms
[i
].buckets
, &(*gms
)[i
].buckets
);
1558 error
= parse_ofp_group_mod_str(&(*gms
)[*n_gms
], command
, ds_cstr(&s
),
1563 for (i
= 0; i
< *n_gms
; i
++) {
1564 ofputil_bucket_list_destroy(&(*gms
)[i
].buckets
);
1571 if (stream
!= stdin
) {
1575 return xasprintf("%s:%d: %s", file_name
, line_number
, error
);
1577 *usable_protocols
&= usable
;
1582 if (stream
!= stdin
) {
1588 char * OVS_WARN_UNUSED_RESULT
1589 parse_ofp_geneve_table_mod_str(struct ofputil_geneve_table_mod
*gtm
,
1590 uint16_t command
, const char *s
,
1591 enum ofputil_protocol
*usable_protocols
)
1593 *usable_protocols
= OFPUTIL_P_NXM_OXM_ANY
;
1595 gtm
->command
= command
;
1596 list_init(>m
->mappings
);
1599 struct ofputil_geneve_map
*map
= xmalloc(sizeof *map
);
1606 list_push_back(>m
->mappings
, &map
->list_node
);
1608 if (!ovs_scan(s
, "{class=%"SCNi16
",type=%"SCNi8
",len=%"SCNi8
"}->tun_metadata%"SCNi16
"%n",
1609 &map
->option_class
, &map
->option_type
, &map
->option_len
,
1611 ofputil_uninit_geneve_table(>m
->mappings
);
1612 return xstrdup("invalid geneve mapping");