2011-09-12 16:19:57 -07:00
|
|
|
/*
|
2017-04-07 14:43:40 -07:00
|
|
|
* Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc.
|
2011-09-12 16:19:57 -07:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "learn.h"
|
|
|
|
|
|
|
|
#include "byte-order.h"
|
2016-03-02 15:56:20 +01:00
|
|
|
#include "colors.h"
|
2016-04-14 15:20:19 -07:00
|
|
|
#include "nx-match.h"
|
|
|
|
#include "openflow/openflow.h"
|
2016-03-03 10:20:46 -08:00
|
|
|
#include "openvswitch/dynamic-string.h"
|
2016-04-04 21:32:06 -04:00
|
|
|
#include "openvswitch/match.h"
|
2016-04-04 21:32:07 -04:00
|
|
|
#include "openvswitch/meta-flow.h"
|
2016-04-14 15:20:19 -07:00
|
|
|
#include "openvswitch/ofp-actions.h"
|
|
|
|
#include "openvswitch/ofp-errors.h"
|
2018-02-09 10:04:26 -08:00
|
|
|
#include "openvswitch/ofp-flow.h"
|
|
|
|
#include "openvswitch/ofp-parse.h"
|
|
|
|
#include "openvswitch/ofp-table.h"
|
2016-03-25 14:10:24 -07:00
|
|
|
#include "openvswitch/ofpbuf.h"
|
2017-03-13 11:28:21 -07:00
|
|
|
#include "vl-mff-map.h"
|
2011-09-12 16:19:57 -07:00
|
|
|
#include "unaligned.h"
|
|
|
|
|
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
/* Checks that 'learn' is a valid action on 'flow'. Returns 0 if it is valid,
|
|
|
|
* otherwise an OFPERR_*. */
|
|
|
|
enum ofperr
|
2017-03-08 17:18:22 -08:00
|
|
|
learn_check(const struct ofpact_learn *learn, const struct match *src_match)
|
2011-09-12 16:19:57 -07:00
|
|
|
{
|
2012-07-03 22:17:14 -07:00
|
|
|
const struct ofpact_learn_spec *spec;
|
2017-03-08 17:18:22 -08:00
|
|
|
struct match dst_match;
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2017-03-08 17:18:22 -08:00
|
|
|
match_init_catchall(&dst_match);
|
2016-09-02 13:26:50 -07:00
|
|
|
OFPACT_LEARN_SPEC_FOR_EACH (spec, learn) {
|
2012-07-03 22:17:14 -07:00
|
|
|
enum ofperr error;
|
2012-04-11 17:08:13 -07:00
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
/* Check the source. */
|
|
|
|
if (spec->src_type == NX_LEARN_SRC_FIELD) {
|
2017-03-08 17:18:22 -08:00
|
|
|
error = mf_check_src(&spec->src, src_match);
|
2012-07-03 22:17:14 -07:00
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
/* Check the destination. */
|
|
|
|
switch (spec->dst_type) {
|
2011-09-12 16:19:57 -07:00
|
|
|
case NX_LEARN_DST_MATCH:
|
2017-03-08 17:18:22 -08:00
|
|
|
error = mf_check_src(&spec->dst, &dst_match);
|
2012-07-03 22:17:14 -07:00
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
2016-09-01 13:29:57 -07:00
|
|
|
if (spec->src_type & NX_LEARN_SRC_IMMEDIATE) {
|
|
|
|
mf_write_subfield_value(&spec->dst,
|
2017-03-08 17:18:22 -08:00
|
|
|
ofpact_learn_spec_imm(spec),
|
|
|
|
&dst_match);
|
2016-09-01 13:29:57 -07:00
|
|
|
}
|
2011-09-12 16:19:57 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_LEARN_DST_LOAD:
|
2017-03-08 17:18:22 -08:00
|
|
|
error = mf_check_dst(&spec->dst, &dst_match);
|
2012-07-03 22:17:14 -07:00
|
|
|
if (error) {
|
|
|
|
return error;
|
2012-04-11 17:08:13 -07:00
|
|
|
}
|
2011-09-12 16:19:57 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_LEARN_DST_OUTPUT:
|
2012-07-03 22:17:14 -07:00
|
|
|
/* Nothing to do. */
|
2011-09-12 16:19:57 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-07-03 22:17:14 -07:00
|
|
|
return 0;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
/* Composes 'fm' so that executing it will implement 'learn' given that the
|
|
|
|
* packet being processed has 'flow' as its flow.
|
|
|
|
*
|
|
|
|
* Uses 'ofpacts' to store the flow mod's actions. The caller must initialize
|
|
|
|
* 'ofpacts' and retains ownership of it. 'fm->ofpacts' will point into the
|
|
|
|
* 'ofpacts' buffer.
|
|
|
|
*
|
2018-03-19 22:01:47 -07:00
|
|
|
* The caller must eventually destroy fm->match.
|
|
|
|
*
|
2012-07-03 22:17:14 -07:00
|
|
|
* The caller has to actually execute 'fm'. */
|
|
|
|
void
|
|
|
|
learn_execute(const struct ofpact_learn *learn, const struct flow *flow,
|
|
|
|
struct ofputil_flow_mod *fm, struct ofpbuf *ofpacts)
|
|
|
|
{
|
|
|
|
const struct ofpact_learn_spec *spec;
|
2018-03-19 22:01:47 -07:00
|
|
|
struct match match;
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2018-03-19 22:01:47 -07:00
|
|
|
match_init_catchall(&match);
|
2012-08-07 15:28:18 -07:00
|
|
|
fm->priority = learn->priority;
|
2012-07-03 22:17:14 -07:00
|
|
|
fm->cookie = htonll(0);
|
|
|
|
fm->cookie_mask = htonll(0);
|
2014-06-05 15:27:31 -07:00
|
|
|
fm->new_cookie = learn->cookie;
|
2013-06-27 15:27:15 -07:00
|
|
|
fm->modify_cookie = fm->new_cookie != OVS_BE64_MAX;
|
2012-07-03 22:17:14 -07:00
|
|
|
fm->table_id = learn->table_id;
|
|
|
|
fm->command = OFPFC_MODIFY_STRICT;
|
|
|
|
fm->idle_timeout = learn->idle_timeout;
|
|
|
|
fm->hard_timeout = learn->hard_timeout;
|
2014-11-07 18:18:48 +05:30
|
|
|
fm->importance = 0;
|
2012-07-03 22:17:14 -07:00
|
|
|
fm->buffer_id = UINT32_MAX;
|
|
|
|
fm->out_port = OFPP_NONE;
|
2017-03-13 11:28:21 -07:00
|
|
|
fm->ofpacts_tlv_bitmap = 0;
|
2014-06-05 21:53:34 -07:00
|
|
|
fm->flags = 0;
|
|
|
|
if (learn->flags & NX_LEARN_F_SEND_FLOW_REM) {
|
|
|
|
fm->flags |= OFPUTIL_FF_SEND_FLOW_REM;
|
|
|
|
}
|
2012-07-03 22:17:14 -07:00
|
|
|
fm->ofpacts = NULL;
|
|
|
|
fm->ofpacts_len = 0;
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
if (learn->fin_idle_timeout || learn->fin_hard_timeout) {
|
|
|
|
struct ofpact_fin_timeout *oft;
|
|
|
|
|
|
|
|
oft = ofpact_put_FIN_TIMEOUT(ofpacts);
|
|
|
|
oft->fin_idle_timeout = learn->fin_idle_timeout;
|
|
|
|
oft->fin_hard_timeout = learn->fin_hard_timeout;
|
|
|
|
}
|
|
|
|
|
2016-09-02 13:26:50 -07:00
|
|
|
OFPACT_LEARN_SPEC_FOR_EACH (spec, learn) {
|
2014-10-07 16:49:50 -07:00
|
|
|
struct ofpact_set_field *sf;
|
2012-07-03 22:17:14 -07:00
|
|
|
union mf_subvalue value;
|
|
|
|
|
|
|
|
if (spec->src_type == NX_LEARN_SRC_FIELD) {
|
|
|
|
mf_read_subfield(&spec->src, flow, &value);
|
|
|
|
} else {
|
2016-09-01 13:29:57 -07:00
|
|
|
mf_subvalue_from_value(&spec->dst, &value,
|
|
|
|
ofpact_learn_spec_imm(spec));
|
2012-07-03 22:17:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (spec->dst_type) {
|
|
|
|
case NX_LEARN_DST_MATCH:
|
2018-03-19 22:01:47 -07:00
|
|
|
mf_write_subfield(&spec->dst, &value, &match);
|
|
|
|
match_add_ethernet_prereq(&match, spec->dst.field);
|
2017-03-13 11:28:21 -07:00
|
|
|
mf_vl_mff_set_tlv_bitmap(
|
2018-03-19 22:01:47 -07:00
|
|
|
spec->dst.field, &match.flow.tunnel.metadata.present.map);
|
2012-07-03 22:17:14 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_LEARN_DST_LOAD:
|
2016-08-31 08:43:48 -07:00
|
|
|
sf = ofpact_put_reg_load(ofpacts, spec->dst.field, NULL, NULL);
|
2014-10-07 16:49:50 -07:00
|
|
|
bitwise_copy(&value, sizeof value, 0,
|
2016-08-31 08:43:48 -07:00
|
|
|
sf->value, spec->dst.field->n_bytes, spec->dst.ofs,
|
2014-10-07 16:49:50 -07:00
|
|
|
spec->n_bits);
|
2016-08-31 08:43:48 -07:00
|
|
|
bitwise_one(ofpact_set_field_mask(sf), spec->dst.field->n_bytes,
|
|
|
|
spec->dst.ofs, spec->n_bits);
|
2017-03-13 11:28:21 -07:00
|
|
|
mf_vl_mff_set_tlv_bitmap(spec->dst.field, &fm->ofpacts_tlv_bitmap);
|
2012-07-03 22:17:14 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_LEARN_DST_OUTPUT:
|
|
|
|
if (spec->n_bits <= 16
|
|
|
|
|| is_all_zeros(value.u8, sizeof value - 2)) {
|
2015-02-25 09:33:54 -08:00
|
|
|
ofp_port_t port = u16_to_ofp(ntohll(value.integer));
|
2012-07-03 22:17:14 -07:00
|
|
|
|
2013-06-19 16:58:44 -07:00
|
|
|
if (ofp_to_u16(port) < ofp_to_u16(OFPP_MAX)
|
2012-07-03 22:17:14 -07:00
|
|
|
|| port == OFPP_IN_PORT
|
|
|
|
|| port == OFPP_FLOOD
|
|
|
|
|| port == OFPP_LOCAL
|
|
|
|
|| port == OFPP_ALL) {
|
|
|
|
ofpact_put_OUTPUT(ofpacts)->port = port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-19 22:01:47 -07:00
|
|
|
minimatch_init(&fm->match, &match);
|
2015-03-02 17:29:44 -08:00
|
|
|
fm->ofpacts = ofpacts->data;
|
|
|
|
fm->ofpacts_len = ofpacts->size;
|
2012-07-03 22:17:14 -07:00
|
|
|
}
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2013-05-14 18:24:43 -07:00
|
|
|
/* Perform a bitwise-OR on 'wc''s fields that are relevant as sources in
|
|
|
|
* the learn action 'learn'. */
|
|
|
|
void
|
|
|
|
learn_mask(const struct ofpact_learn *learn, struct flow_wildcards *wc)
|
|
|
|
{
|
|
|
|
const struct ofpact_learn_spec *spec;
|
|
|
|
union mf_subvalue value;
|
|
|
|
|
|
|
|
memset(&value, 0xff, sizeof value);
|
2016-09-02 13:26:50 -07:00
|
|
|
OFPACT_LEARN_SPEC_FOR_EACH (spec, learn) {
|
2013-05-14 18:24:43 -07:00
|
|
|
if (spec->src_type == NX_LEARN_SRC_FIELD) {
|
|
|
|
mf_write_subfield_flow(&spec->src, &value, &wc->masks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
/* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
* error. The caller is responsible for freeing the returned string. */
|
2014-12-15 14:10:38 +01:00
|
|
|
static char * OVS_WARN_UNUSED_RESULT
|
ofp-parse: Allow match field names in actions and brackets in matches.
Allow using match field names in addition to the canonical register
names in actions (including 'load', 'move', 'push', 'pop', 'output',
'multipath', 'bundle_load', and 'learn'). Allow also leaving out the
trailing '[]' to indicate full field. These changes allow simpler
syntax similar to 'set_field' to be used also elsewhere.
Correspondingly, allow the '[start..end]' syntax to be used in matches
in addition to the more explicit 'value/mask' notation. For example,
to match on the value 2 of the bits 14..15 of NXM_NX_REG0, the match
could include:
... reg0[14..15]=2 ...
instead of
... reg0=0x8000/0xc000 ...
Note that only contiguous masks can be specified with the bracket
notation.
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-01-04 16:10:56 -08:00
|
|
|
learn_parse_load_immediate(union mf_subvalue *imm, const char *s,
|
|
|
|
const char *full_s, struct ofpact_learn_spec *spec,
|
2016-08-31 08:43:48 -07:00
|
|
|
struct ofpbuf *ofpacts)
|
2012-04-13 21:24:17 -07:00
|
|
|
{
|
|
|
|
struct mf_subfield dst;
|
2013-07-08 10:15:00 -07:00
|
|
|
char *error;
|
2012-04-13 21:24:17 -07:00
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
error = mf_parse_subfield(&dst, s);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
2012-04-13 21:24:17 -07:00
|
|
|
}
|
ofp-actions: Support experimenter OXMs in Nicira extensions.
Some of the Nicira extension actions include fixed-size 32-bit members that
designate NXM fields. These actions can't accommodate 64-bit experimenter
OXMs, so we need to figure out some kind of solution. This commit does
that, in different ways for different actions.
For some actions, I did not think it was worthwhile to worry about
experimenter OXM, so I just disabled use of them. This is what I did for
bundle, learn, and multipath actions.
Other actions could be gracefully reinterpreted to support experimenter
OXM. This is true of reg_move, which use NXM headers only at the end of
the action and such that using an experimenter OXM would make the action
longer (which unambigously signals to older OVS that the action is an
error, which is desired behavior since older OVS cannot interpret this
action). The stack push and pop actions are also in this category.
reg_load was the most frustrating case. In OpenFlow 1.5 we had already
eliminated this action in favor of OF1.5+ set_field. In other OpenFlow
versions, though, reg_load is more powerful than set_field because it
can modify partial fields. This commit therefore adds a new variant of
reg_load, called reg_load2, which is simply OF1.5+ set_field with a Nicira
extension header on it.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
2014-09-11 22:09:03 -07:00
|
|
|
if (!mf_nxm_header(dst.field->id)) {
|
|
|
|
return xasprintf("%s: experimenter OXM field '%s' not supported",
|
|
|
|
full_s, s);
|
|
|
|
}
|
2012-04-13 21:24:17 -07:00
|
|
|
|
ofp-parse: Allow match field names in actions and brackets in matches.
Allow using match field names in addition to the canonical register
names in actions (including 'load', 'move', 'push', 'pop', 'output',
'multipath', 'bundle_load', and 'learn'). Allow also leaving out the
trailing '[]' to indicate full field. These changes allow simpler
syntax similar to 'set_field' to be used also elsewhere.
Correspondingly, allow the '[start..end]' syntax to be used in matches
in addition to the more explicit 'value/mask' notation. For example,
to match on the value 2 of the bits 14..15 of NXM_NX_REG0, the match
could include:
... reg0[14..15]=2 ...
instead of
... reg0=0x8000/0xc000 ...
Note that only contiguous masks can be specified with the bracket
notation.
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-01-04 16:10:56 -08:00
|
|
|
if (!bitwise_is_all_zeros(imm, sizeof *imm, dst.n_bits,
|
|
|
|
(8 * sizeof *imm) - dst.n_bits)) {
|
2013-07-08 10:15:00 -07:00
|
|
|
return xasprintf("%s: value does not fit into %u bits",
|
|
|
|
full_s, dst.n_bits);
|
2012-04-13 21:24:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
spec->n_bits = dst.n_bits;
|
|
|
|
spec->src_type = NX_LEARN_SRC_IMMEDIATE;
|
|
|
|
spec->dst_type = NX_LEARN_DST_LOAD;
|
|
|
|
spec->dst = dst;
|
2016-08-31 08:43:48 -07:00
|
|
|
|
|
|
|
/* Push value last, as this may reallocate 'spec'! */
|
|
|
|
unsigned int n_bytes = DIV_ROUND_UP(dst.n_bits, 8);
|
|
|
|
uint8_t *src_imm = ofpbuf_put_zeros(ofpacts, OFPACT_ALIGN(n_bytes));
|
ofp-parse: Allow match field names in actions and brackets in matches.
Allow using match field names in addition to the canonical register
names in actions (including 'load', 'move', 'push', 'pop', 'output',
'multipath', 'bundle_load', and 'learn'). Allow also leaving out the
trailing '[]' to indicate full field. These changes allow simpler
syntax similar to 'set_field' to be used also elsewhere.
Correspondingly, allow the '[start..end]' syntax to be used in matches
in addition to the more explicit 'value/mask' notation. For example,
to match on the value 2 of the bits 14..15 of NXM_NX_REG0, the match
could include:
... reg0[14..15]=2 ...
instead of
... reg0=0x8000/0xc000 ...
Note that only contiguous masks can be specified with the bracket
notation.
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-01-04 16:10:56 -08:00
|
|
|
memcpy(src_imm, &imm->u8[sizeof imm->u8 - n_bytes], n_bytes);
|
2016-08-31 08:43:48 -07:00
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
return NULL;
|
2012-04-13 21:24:17 -07:00
|
|
|
}
|
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
/* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
* error. The caller is responsible for freeing the returned string. */
|
2014-12-15 14:10:38 +01:00
|
|
|
static char * OVS_WARN_UNUSED_RESULT
|
2011-09-12 16:19:57 -07:00
|
|
|
learn_parse_spec(const char *orig, char *name, char *value,
|
2017-05-31 16:06:12 -07:00
|
|
|
const struct ofputil_port_map *port_map,
|
2016-08-31 08:43:48 -07:00
|
|
|
struct ofpact_learn_spec *spec,
|
learn: Fix parsing immediate value for a field match.
The value is right-justified after the string parsing with
parse_int_string(), i.e. it is in BE byte order and aligned
to the right side of the array.
For example, the 0x10011 value in a 4-byte field will look
like 0x00 0x01 0x00 0x11.
However, value copy to the resulted ofpact is performed
from the start of the memory. So, in case the destination
size is smaller than the original field size, incorrect
part of the value will be copied.
In the 0x00 0x01 0x00 0x11 example above, if the copy is
performed to a 3-byte field, the first 3 bytes will be
copied, which are 0x00 0x01 0x00 instead of 0x01 0x00 0x11.
This leads to a problem where NXM_NX_REG3[0..16]=0x10011
turns into NXM_NX_REG3[0..16]=0x100 after the parsing.
Fix that by offsetting the starting position to the size
difference in bytes similarly to how it is done in
learn_parse_load_immediate().
While at it, changing &imm to imm.b in function calls that
expect byte arrays as an argument. The old way is technically
correct, but more error prone.
The mf_write_subfield_value() call was also incorrect.
However, the 'match' variable is actually not used for
anything since checking removal in commit:
dd43a558597b ("Do not perform validation in learn_parse();")
So, just removing the call and the 'match' variable
entirely instead of fixing it.
Fixes: 21b2fa617126 ("ofp-parse: Allow match field names in actions and brackets in matches.")
Reported-at: https://mail.openvswitch.org/pipermail/ovs-discuss/2022-November/052100.html
Reported-by: Thomas Lee <newsforthomas@engineer.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2022-11-23 22:23:37 +01:00
|
|
|
struct ofpbuf *ofpacts)
|
2011-09-12 16:19:57 -07:00
|
|
|
{
|
ofp-parse: Allow match field names in actions and brackets in matches.
Allow using match field names in addition to the canonical register
names in actions (including 'load', 'move', 'push', 'pop', 'output',
'multipath', 'bundle_load', and 'learn'). Allow also leaving out the
trailing '[]' to indicate full field. These changes allow simpler
syntax similar to 'set_field' to be used also elsewhere.
Correspondingly, allow the '[start..end]' syntax to be used in matches
in addition to the more explicit 'value/mask' notation. For example,
to match on the value 2 of the bits 14..15 of NXM_NX_REG0, the match
could include:
... reg0[14..15]=2 ...
instead of
... reg0=0x8000/0xc000 ...
Note that only contiguous masks can be specified with the bracket
notation.
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-01-04 16:10:56 -08:00
|
|
|
/* Parse destination and check prerequisites. */
|
|
|
|
struct mf_subfield dst;
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2017-04-07 14:43:40 -07:00
|
|
|
char *error = mf_parse_subfield(&dst, name);
|
|
|
|
bool parse_error = error != NULL;
|
|
|
|
free(error);
|
|
|
|
|
|
|
|
if (!parse_error) {
|
ofp-parse: Allow match field names in actions and brackets in matches.
Allow using match field names in addition to the canonical register
names in actions (including 'load', 'move', 'push', 'pop', 'output',
'multipath', 'bundle_load', and 'learn'). Allow also leaving out the
trailing '[]' to indicate full field. These changes allow simpler
syntax similar to 'set_field' to be used also elsewhere.
Correspondingly, allow the '[start..end]' syntax to be used in matches
in addition to the more explicit 'value/mask' notation. For example,
to match on the value 2 of the bits 14..15 of NXM_NX_REG0, the match
could include:
... reg0[14..15]=2 ...
instead of
... reg0=0x8000/0xc000 ...
Note that only contiguous masks can be specified with the bracket
notation.
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-01-04 16:10:56 -08:00
|
|
|
if (!mf_nxm_header(dst.field->id)) {
|
ofp-actions: Support experimenter OXMs in Nicira extensions.
Some of the Nicira extension actions include fixed-size 32-bit members that
designate NXM fields. These actions can't accommodate 64-bit experimenter
OXMs, so we need to figure out some kind of solution. This commit does
that, in different ways for different actions.
For some actions, I did not think it was worthwhile to worry about
experimenter OXM, so I just disabled use of them. This is what I did for
bundle, learn, and multipath actions.
Other actions could be gracefully reinterpreted to support experimenter
OXM. This is true of reg_move, which use NXM headers only at the end of
the action and such that using an experimenter OXM would make the action
longer (which unambigously signals to older OVS that the action is an
error, which is desired behavior since older OVS cannot interpret this
action). The stack push and pop actions are also in this category.
reg_load was the most frustrating case. In OpenFlow 1.5 we had already
eliminated this action in favor of OF1.5+ set_field. In other OpenFlow
versions, though, reg_load is more powerful than set_field because it
can modify partial fields. This commit therefore adds a new variant of
reg_load, called reg_load2, which is simply OF1.5+ set_field with a Nicira
extension header on it.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
2014-09-11 22:09:03 -07:00
|
|
|
return xasprintf("%s: experimenter OXM field '%s' not supported",
|
|
|
|
orig, name);
|
|
|
|
}
|
ofp-parse: Allow match field names in actions and brackets in matches.
Allow using match field names in addition to the canonical register
names in actions (including 'load', 'move', 'push', 'pop', 'output',
'multipath', 'bundle_load', and 'learn'). Allow also leaving out the
trailing '[]' to indicate full field. These changes allow simpler
syntax similar to 'set_field' to be used also elsewhere.
Correspondingly, allow the '[start..end]' syntax to be used in matches
in addition to the more explicit 'value/mask' notation. For example,
to match on the value 2 of the bits 14..15 of NXM_NX_REG0, the match
could include:
... reg0[14..15]=2 ...
instead of
... reg0=0x8000/0xc000 ...
Note that only contiguous masks can be specified with the bracket
notation.
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-01-04 16:10:56 -08:00
|
|
|
spec->dst = dst;
|
|
|
|
spec->n_bits = dst.n_bits;
|
|
|
|
spec->dst_type = NX_LEARN_DST_MATCH;
|
2011-09-12 16:19:57 -07:00
|
|
|
|
|
|
|
/* Parse source and check prerequisites. */
|
|
|
|
if (value[0] != '\0') {
|
ofp-parse: Allow match field names in actions and brackets in matches.
Allow using match field names in addition to the canonical register
names in actions (including 'load', 'move', 'push', 'pop', 'output',
'multipath', 'bundle_load', and 'learn'). Allow also leaving out the
trailing '[]' to indicate full field. These changes allow simpler
syntax similar to 'set_field' to be used also elsewhere.
Correspondingly, allow the '[start..end]' syntax to be used in matches
in addition to the more explicit 'value/mask' notation. For example,
to match on the value 2 of the bits 14..15 of NXM_NX_REG0, the match
could include:
... reg0[14..15]=2 ...
instead of
... reg0=0x8000/0xc000 ...
Note that only contiguous masks can be specified with the bracket
notation.
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-01-04 16:10:56 -08:00
|
|
|
struct mf_subfield src;
|
|
|
|
error = mf_parse_subfield(&src, value);
|
2013-07-08 10:15:00 -07:00
|
|
|
if (error) {
|
ofp-parse: Allow match field names in actions and brackets in matches.
Allow using match field names in addition to the canonical register
names in actions (including 'load', 'move', 'push', 'pop', 'output',
'multipath', 'bundle_load', and 'learn'). Allow also leaving out the
trailing '[]' to indicate full field. These changes allow simpler
syntax similar to 'set_field' to be used also elsewhere.
Correspondingly, allow the '[start..end]' syntax to be used in matches
in addition to the more explicit 'value/mask' notation. For example,
to match on the value 2 of the bits 14..15 of NXM_NX_REG0, the match
could include:
... reg0[14..15]=2 ...
instead of
... reg0=0x8000/0xc000 ...
Note that only contiguous masks can be specified with the bracket
notation.
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-01-04 16:10:56 -08:00
|
|
|
union mf_value imm;
|
|
|
|
char *imm_error = NULL;
|
|
|
|
|
|
|
|
/* Try an immediate value. */
|
|
|
|
if (dst.ofs == 0 && dst.n_bits == dst.field->n_bits) {
|
|
|
|
/* Full field value. */
|
2017-05-31 16:06:12 -07:00
|
|
|
imm_error = mf_parse_value(dst.field, value, port_map,
|
|
|
|
&imm);
|
ofp-parse: Allow match field names in actions and brackets in matches.
Allow using match field names in addition to the canonical register
names in actions (including 'load', 'move', 'push', 'pop', 'output',
'multipath', 'bundle_load', and 'learn'). Allow also leaving out the
trailing '[]' to indicate full field. These changes allow simpler
syntax similar to 'set_field' to be used also elsewhere.
Correspondingly, allow the '[start..end]' syntax to be used in matches
in addition to the more explicit 'value/mask' notation. For example,
to match on the value 2 of the bits 14..15 of NXM_NX_REG0, the match
could include:
... reg0[14..15]=2 ...
instead of
... reg0=0x8000/0xc000 ...
Note that only contiguous masks can be specified with the bracket
notation.
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-01-04 16:10:56 -08:00
|
|
|
} else {
|
|
|
|
char *tail;
|
|
|
|
/* Partial field value. */
|
learn: Fix parsing immediate value for a field match.
The value is right-justified after the string parsing with
parse_int_string(), i.e. it is in BE byte order and aligned
to the right side of the array.
For example, the 0x10011 value in a 4-byte field will look
like 0x00 0x01 0x00 0x11.
However, value copy to the resulted ofpact is performed
from the start of the memory. So, in case the destination
size is smaller than the original field size, incorrect
part of the value will be copied.
In the 0x00 0x01 0x00 0x11 example above, if the copy is
performed to a 3-byte field, the first 3 bytes will be
copied, which are 0x00 0x01 0x00 instead of 0x01 0x00 0x11.
This leads to a problem where NXM_NX_REG3[0..16]=0x10011
turns into NXM_NX_REG3[0..16]=0x100 after the parsing.
Fix that by offsetting the starting position to the size
difference in bytes similarly to how it is done in
learn_parse_load_immediate().
While at it, changing &imm to imm.b in function calls that
expect byte arrays as an argument. The old way is technically
correct, but more error prone.
The mf_write_subfield_value() call was also incorrect.
However, the 'match' variable is actually not used for
anything since checking removal in commit:
dd43a558597b ("Do not perform validation in learn_parse();")
So, just removing the call and the 'match' variable
entirely instead of fixing it.
Fixes: 21b2fa617126 ("ofp-parse: Allow match field names in actions and brackets in matches.")
Reported-at: https://mail.openvswitch.org/pipermail/ovs-discuss/2022-November/052100.html
Reported-by: Thomas Lee <newsforthomas@engineer.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2022-11-23 22:23:37 +01:00
|
|
|
if (parse_int_string(value, imm.b,
|
ofp-parse: Allow match field names in actions and brackets in matches.
Allow using match field names in addition to the canonical register
names in actions (including 'load', 'move', 'push', 'pop', 'output',
'multipath', 'bundle_load', and 'learn'). Allow also leaving out the
trailing '[]' to indicate full field. These changes allow simpler
syntax similar to 'set_field' to be used also elsewhere.
Correspondingly, allow the '[start..end]' syntax to be used in matches
in addition to the more explicit 'value/mask' notation. For example,
to match on the value 2 of the bits 14..15 of NXM_NX_REG0, the match
could include:
... reg0[14..15]=2 ...
instead of
... reg0=0x8000/0xc000 ...
Note that only contiguous masks can be specified with the bracket
notation.
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-01-04 16:10:56 -08:00
|
|
|
dst.field->n_bytes, &tail)
|
|
|
|
|| *tail != 0) {
|
|
|
|
imm_error = xasprintf("%s: cannot parse integer value", orig);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!imm_error &&
|
learn: Fix parsing immediate value for a field match.
The value is right-justified after the string parsing with
parse_int_string(), i.e. it is in BE byte order and aligned
to the right side of the array.
For example, the 0x10011 value in a 4-byte field will look
like 0x00 0x01 0x00 0x11.
However, value copy to the resulted ofpact is performed
from the start of the memory. So, in case the destination
size is smaller than the original field size, incorrect
part of the value will be copied.
In the 0x00 0x01 0x00 0x11 example above, if the copy is
performed to a 3-byte field, the first 3 bytes will be
copied, which are 0x00 0x01 0x00 instead of 0x01 0x00 0x11.
This leads to a problem where NXM_NX_REG3[0..16]=0x10011
turns into NXM_NX_REG3[0..16]=0x100 after the parsing.
Fix that by offsetting the starting position to the size
difference in bytes similarly to how it is done in
learn_parse_load_immediate().
While at it, changing &imm to imm.b in function calls that
expect byte arrays as an argument. The old way is technically
correct, but more error prone.
The mf_write_subfield_value() call was also incorrect.
However, the 'match' variable is actually not used for
anything since checking removal in commit:
dd43a558597b ("Do not perform validation in learn_parse();")
So, just removing the call and the 'match' variable
entirely instead of fixing it.
Fixes: 21b2fa617126 ("ofp-parse: Allow match field names in actions and brackets in matches.")
Reported-at: https://mail.openvswitch.org/pipermail/ovs-discuss/2022-November/052100.html
Reported-by: Thomas Lee <newsforthomas@engineer.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2022-11-23 22:23:37 +01:00
|
|
|
!bitwise_is_all_zeros(imm.b, dst.field->n_bytes,
|
ofp-parse: Allow match field names in actions and brackets in matches.
Allow using match field names in addition to the canonical register
names in actions (including 'load', 'move', 'push', 'pop', 'output',
'multipath', 'bundle_load', and 'learn'). Allow also leaving out the
trailing '[]' to indicate full field. These changes allow simpler
syntax similar to 'set_field' to be used also elsewhere.
Correspondingly, allow the '[start..end]' syntax to be used in matches
in addition to the more explicit 'value/mask' notation. For example,
to match on the value 2 of the bits 14..15 of NXM_NX_REG0, the match
could include:
... reg0[14..15]=2 ...
instead of
... reg0=0x8000/0xc000 ...
Note that only contiguous masks can be specified with the bracket
notation.
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-01-04 16:10:56 -08:00
|
|
|
dst.n_bits,
|
|
|
|
dst.field->n_bytes * 8 - dst.n_bits)) {
|
|
|
|
struct ds ds;
|
|
|
|
|
|
|
|
ds_init(&ds);
|
2017-05-31 16:06:12 -07:00
|
|
|
mf_format(dst.field, &imm, NULL, NULL, &ds);
|
ofp-parse: Allow match field names in actions and brackets in matches.
Allow using match field names in addition to the canonical register
names in actions (including 'load', 'move', 'push', 'pop', 'output',
'multipath', 'bundle_load', and 'learn'). Allow also leaving out the
trailing '[]' to indicate full field. These changes allow simpler
syntax similar to 'set_field' to be used also elsewhere.
Correspondingly, allow the '[start..end]' syntax to be used in matches
in addition to the more explicit 'value/mask' notation. For example,
to match on the value 2 of the bits 14..15 of NXM_NX_REG0, the match
could include:
... reg0[14..15]=2 ...
instead of
... reg0=0x8000/0xc000 ...
Note that only contiguous masks can be specified with the bracket
notation.
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-01-04 16:10:56 -08:00
|
|
|
imm_error = xasprintf("%s: value %s does not fit into %d bits",
|
|
|
|
orig, ds_cstr(&ds), dst.n_bits);
|
|
|
|
ds_destroy(&ds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (imm_error) {
|
|
|
|
char *err = xasprintf("%s: %s value %s cannot be parsed as a subfield (%s) or an immediate value (%s)",
|
|
|
|
orig, name, value, error, imm_error);
|
|
|
|
free(error);
|
|
|
|
free(imm_error);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
spec->src_type = NX_LEARN_SRC_IMMEDIATE;
|
|
|
|
|
|
|
|
/* Push value last, as this may reallocate 'spec'! */
|
|
|
|
unsigned int imm_bytes = DIV_ROUND_UP(dst.n_bits, 8);
|
|
|
|
uint8_t *src_imm = ofpbuf_put_zeros(ofpacts,
|
|
|
|
OFPACT_ALIGN(imm_bytes));
|
learn: Fix parsing immediate value for a field match.
The value is right-justified after the string parsing with
parse_int_string(), i.e. it is in BE byte order and aligned
to the right side of the array.
For example, the 0x10011 value in a 4-byte field will look
like 0x00 0x01 0x00 0x11.
However, value copy to the resulted ofpact is performed
from the start of the memory. So, in case the destination
size is smaller than the original field size, incorrect
part of the value will be copied.
In the 0x00 0x01 0x00 0x11 example above, if the copy is
performed to a 3-byte field, the first 3 bytes will be
copied, which are 0x00 0x01 0x00 instead of 0x01 0x00 0x11.
This leads to a problem where NXM_NX_REG3[0..16]=0x10011
turns into NXM_NX_REG3[0..16]=0x100 after the parsing.
Fix that by offsetting the starting position to the size
difference in bytes similarly to how it is done in
learn_parse_load_immediate().
While at it, changing &imm to imm.b in function calls that
expect byte arrays as an argument. The old way is technically
correct, but more error prone.
The mf_write_subfield_value() call was also incorrect.
However, the 'match' variable is actually not used for
anything since checking removal in commit:
dd43a558597b ("Do not perform validation in learn_parse();")
So, just removing the call and the 'match' variable
entirely instead of fixing it.
Fixes: 21b2fa617126 ("ofp-parse: Allow match field names in actions and brackets in matches.")
Reported-at: https://mail.openvswitch.org/pipermail/ovs-discuss/2022-November/052100.html
Reported-by: Thomas Lee <newsforthomas@engineer.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2022-11-23 22:23:37 +01:00
|
|
|
|
|
|
|
memcpy(src_imm, &imm.b[dst.field->n_bytes - imm_bytes],
|
|
|
|
imm_bytes);
|
ofp-parse: Allow match field names in actions and brackets in matches.
Allow using match field names in addition to the canonical register
names in actions (including 'load', 'move', 'push', 'pop', 'output',
'multipath', 'bundle_load', and 'learn'). Allow also leaving out the
trailing '[]' to indicate full field. These changes allow simpler
syntax similar to 'set_field' to be used also elsewhere.
Correspondingly, allow the '[start..end]' syntax to be used in matches
in addition to the more explicit 'value/mask' notation. For example,
to match on the value 2 of the bits 14..15 of NXM_NX_REG0, the match
could include:
... reg0[14..15]=2 ...
instead of
... reg0=0x8000/0xc000 ...
Note that only contiguous masks can be specified with the bracket
notation.
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-01-04 16:10:56 -08:00
|
|
|
|
|
|
|
free(error);
|
|
|
|
return NULL;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
ofp-parse: Allow match field names in actions and brackets in matches.
Allow using match field names in addition to the canonical register
names in actions (including 'load', 'move', 'push', 'pop', 'output',
'multipath', 'bundle_load', and 'learn'). Allow also leaving out the
trailing '[]' to indicate full field. These changes allow simpler
syntax similar to 'set_field' to be used also elsewhere.
Correspondingly, allow the '[start..end]' syntax to be used in matches
in addition to the more explicit 'value/mask' notation. For example,
to match on the value 2 of the bits 14..15 of NXM_NX_REG0, the match
could include:
... reg0[14..15]=2 ...
instead of
... reg0=0x8000/0xc000 ...
Note that only contiguous masks can be specified with the bracket
notation.
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-01-04 16:10:56 -08:00
|
|
|
spec->src = src;
|
2011-12-28 12:42:14 -08:00
|
|
|
if (spec->src.n_bits != spec->dst.n_bits) {
|
2013-07-08 10:15:00 -07:00
|
|
|
return xasprintf("%s: bit widths of %s (%u) and %s (%u) "
|
|
|
|
"differ", orig, name, spec->src.n_bits, value,
|
|
|
|
spec->dst.n_bits);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
} else {
|
2011-12-28 12:42:14 -08:00
|
|
|
spec->src = spec->dst;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
spec->src_type = NX_LEARN_SRC_FIELD;
|
|
|
|
} else if (!strcmp(name, "load")) {
|
ofp-parse: Allow match field names in actions and brackets in matches.
Allow using match field names in addition to the canonical register
names in actions (including 'load', 'move', 'push', 'pop', 'output',
'multipath', 'bundle_load', and 'learn'). Allow also leaving out the
trailing '[]' to indicate full field. These changes allow simpler
syntax similar to 'set_field' to be used also elsewhere.
Correspondingly, allow the '[start..end]' syntax to be used in matches
in addition to the more explicit 'value/mask' notation. For example,
to match on the value 2 of the bits 14..15 of NXM_NX_REG0, the match
could include:
... reg0[14..15]=2 ...
instead of
... reg0=0x8000/0xc000 ...
Note that only contiguous masks can be specified with the bracket
notation.
Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
2017-01-04 16:10:56 -08:00
|
|
|
union mf_subvalue imm;
|
|
|
|
char *tail;
|
|
|
|
char *dst_value = strstr(value, "->");
|
|
|
|
|
|
|
|
if (dst_value == value) {
|
|
|
|
return xasprintf("%s: missing source before `->' in `%s'", name,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
if (!dst_value) {
|
|
|
|
return xasprintf("%s: missing `->' in `%s'", name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parse_int_string(value, imm.u8, sizeof imm.u8, (char **) &tail)
|
|
|
|
&& tail != value) {
|
|
|
|
if (tail != dst_value) {
|
|
|
|
return xasprintf("%s: garbage before `->' in `%s'",
|
|
|
|
name, value);
|
|
|
|
}
|
|
|
|
|
2017-08-02 15:03:06 -07:00
|
|
|
error = learn_parse_load_immediate(&imm, dst_value + 2, value, spec,
|
|
|
|
ofpacts);
|
2013-07-08 10:15:00 -07:00
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
2011-09-12 16:19:57 -07:00
|
|
|
} else {
|
2012-07-03 22:17:14 -07:00
|
|
|
struct ofpact_reg_move move;
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
error = nxm_parse_reg_move(&move, value);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
spec->n_bits = move.src.n_bits;
|
2011-09-12 16:19:57 -07:00
|
|
|
spec->src_type = NX_LEARN_SRC_FIELD;
|
2012-07-03 22:17:14 -07:00
|
|
|
spec->src = move.src;
|
2011-09-12 16:19:57 -07:00
|
|
|
spec->dst_type = NX_LEARN_DST_LOAD;
|
2012-07-03 22:17:14 -07:00
|
|
|
spec->dst = move.dst;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
} else if (!strcmp(name, "output")) {
|
2017-08-02 15:03:06 -07:00
|
|
|
error = mf_parse_subfield(&spec->src, value);
|
2013-07-08 10:15:00 -07:00
|
|
|
if (error) {
|
|
|
|
return error;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
|
2011-12-28 12:42:14 -08:00
|
|
|
spec->n_bits = spec->src.n_bits;
|
2011-09-12 16:19:57 -07:00
|
|
|
spec->src_type = NX_LEARN_SRC_FIELD;
|
|
|
|
spec->dst_type = NX_LEARN_DST_OUTPUT;
|
|
|
|
} else {
|
2013-07-08 10:15:00 -07:00
|
|
|
return xasprintf("%s: unknown keyword %s", orig, name);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
2013-07-08 10:15:00 -07:00
|
|
|
|
|
|
|
return NULL;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
/* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
* error. The caller is responsible for freeing the returned string. */
|
2014-12-15 14:10:38 +01:00
|
|
|
static char * OVS_WARN_UNUSED_RESULT
|
2017-05-31 16:06:12 -07:00
|
|
|
learn_parse__(char *orig, char *arg, const struct ofputil_port_map *port_map,
|
Support accepting and displaying table names in OVS tools.
OpenFlow has little-known support for naming tables. Open vSwitch has
supported table names for ages, but it has never used or displayed them
outside of commands dedicated to table manipulation. This commit adds
support for table names in ovs-ofctl. When a table has a name, it displays
that name in flows and actions, so that, for example, the following:
table=1, arp, actions=resubmit(,2)
might become:
table=ingress_acl, arp, actions=resubmit(,mac_learning)
given appropriately named tables.
For backward compatibility, only interactive ovs-ofctl commands by default
display table names; to display them in scripts, use the new --names
option.
This feature was inspired by a talk that Kei Nohguchi presented at Open
vSwitch 2017 Fall Conference.
CC: Kei Nohguchi <kei@nohguchi.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Mark Michelson <mmichels@redhat.com>
Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
2018-01-05 16:59:13 -08:00
|
|
|
const struct ofputil_table_map *table_map,
|
2017-05-31 16:06:12 -07:00
|
|
|
struct ofpbuf *ofpacts)
|
2011-09-12 16:19:57 -07:00
|
|
|
{
|
2012-07-03 22:17:14 -07:00
|
|
|
struct ofpact_learn *learn;
|
2013-07-08 10:15:00 -07:00
|
|
|
char *name, *value;
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
learn = ofpact_put_LEARN(ofpacts);
|
|
|
|
learn->idle_timeout = OFP_FLOW_PERMANENT;
|
|
|
|
learn->hard_timeout = OFP_FLOW_PERMANENT;
|
|
|
|
learn->priority = OFP_DEFAULT_PRIORITY;
|
2011-09-12 16:19:57 -07:00
|
|
|
learn->table_id = 1;
|
|
|
|
|
|
|
|
while (ofputil_parse_key_value(&arg, &name, &value)) {
|
|
|
|
if (!strcmp(name, "table")) {
|
Support accepting and displaying table names in OVS tools.
OpenFlow has little-known support for naming tables. Open vSwitch has
supported table names for ages, but it has never used or displayed them
outside of commands dedicated to table manipulation. This commit adds
support for table names in ovs-ofctl. When a table has a name, it displays
that name in flows and actions, so that, for example, the following:
table=1, arp, actions=resubmit(,2)
might become:
table=ingress_acl, arp, actions=resubmit(,mac_learning)
given appropriately named tables.
For backward compatibility, only interactive ovs-ofctl commands by default
display table names; to display them in scripts, use the new --names
option.
This feature was inspired by a talk that Kei Nohguchi presented at Open
vSwitch 2017 Fall Conference.
CC: Kei Nohguchi <kei@nohguchi.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Mark Michelson <mmichels@redhat.com>
Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
2018-01-05 16:59:13 -08:00
|
|
|
if (!ofputil_table_from_string(value, table_map,
|
|
|
|
&learn->table_id)) {
|
|
|
|
return xasprintf("unknown table \"%s\"", value);
|
|
|
|
} else if (learn->table_id == 255) {
|
2013-07-08 10:15:00 -07:00
|
|
|
return xasprintf("%s: table id 255 not valid for `learn' "
|
|
|
|
"action", orig);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
} else if (!strcmp(name, "priority")) {
|
2012-07-03 22:17:14 -07:00
|
|
|
learn->priority = atoi(value);
|
2011-09-12 16:19:57 -07:00
|
|
|
} else if (!strcmp(name, "idle_timeout")) {
|
2012-07-03 22:17:14 -07:00
|
|
|
learn->idle_timeout = atoi(value);
|
2011-09-12 16:19:57 -07:00
|
|
|
} else if (!strcmp(name, "hard_timeout")) {
|
2012-07-03 22:17:14 -07:00
|
|
|
learn->hard_timeout = atoi(value);
|
2012-02-15 10:37:03 -08:00
|
|
|
} else if (!strcmp(name, "fin_idle_timeout")) {
|
2012-07-03 22:17:14 -07:00
|
|
|
learn->fin_idle_timeout = atoi(value);
|
2012-02-15 10:37:03 -08:00
|
|
|
} else if (!strcmp(name, "fin_hard_timeout")) {
|
2012-07-03 22:17:14 -07:00
|
|
|
learn->fin_hard_timeout = atoi(value);
|
2011-09-12 16:19:57 -07:00
|
|
|
} else if (!strcmp(name, "cookie")) {
|
2014-06-05 15:27:31 -07:00
|
|
|
learn->cookie = htonll(strtoull(value, NULL, 0));
|
2014-06-05 21:37:04 -07:00
|
|
|
} else if (!strcmp(name, "send_flow_rem")) {
|
2014-06-05 21:53:34 -07:00
|
|
|
learn->flags |= NX_LEARN_F_SEND_FLOW_REM;
|
|
|
|
} else if (!strcmp(name, "delete_learned")) {
|
|
|
|
learn->flags |= NX_LEARN_F_DELETE_LEARNED;
|
2017-03-10 15:44:40 -08:00
|
|
|
} else if (!strcmp(name, "limit")) {
|
|
|
|
learn->limit = atoi(value);
|
|
|
|
} else if (!strcmp(name, "result_dst")) {
|
|
|
|
char *error;
|
|
|
|
learn->flags |= NX_LEARN_F_WRITE_RESULT;
|
|
|
|
error = mf_parse_subfield(&learn->result_dst, value);
|
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if (!learn->result_dst.field->writable) {
|
|
|
|
return xasprintf("%s is read-only", value);
|
|
|
|
}
|
|
|
|
if (learn->result_dst.n_bits != 1) {
|
|
|
|
return xasprintf("result_dst in 'learn' action must be a "
|
|
|
|
"single bit");
|
|
|
|
}
|
2011-09-12 16:19:57 -07:00
|
|
|
} else {
|
2012-07-03 22:17:14 -07:00
|
|
|
struct ofpact_learn_spec *spec;
|
2013-07-08 10:15:00 -07:00
|
|
|
char *error;
|
2012-07-03 22:17:14 -07:00
|
|
|
|
|
|
|
spec = ofpbuf_put_zeros(ofpacts, sizeof *spec);
|
2017-05-31 16:06:12 -07:00
|
|
|
error = learn_parse_spec(orig, name, value, port_map,
|
learn: Fix parsing immediate value for a field match.
The value is right-justified after the string parsing with
parse_int_string(), i.e. it is in BE byte order and aligned
to the right side of the array.
For example, the 0x10011 value in a 4-byte field will look
like 0x00 0x01 0x00 0x11.
However, value copy to the resulted ofpact is performed
from the start of the memory. So, in case the destination
size is smaller than the original field size, incorrect
part of the value will be copied.
In the 0x00 0x01 0x00 0x11 example above, if the copy is
performed to a 3-byte field, the first 3 bytes will be
copied, which are 0x00 0x01 0x00 instead of 0x01 0x00 0x11.
This leads to a problem where NXM_NX_REG3[0..16]=0x10011
turns into NXM_NX_REG3[0..16]=0x100 after the parsing.
Fix that by offsetting the starting position to the size
difference in bytes similarly to how it is done in
learn_parse_load_immediate().
While at it, changing &imm to imm.b in function calls that
expect byte arrays as an argument. The old way is technically
correct, but more error prone.
The mf_write_subfield_value() call was also incorrect.
However, the 'match' variable is actually not used for
anything since checking removal in commit:
dd43a558597b ("Do not perform validation in learn_parse();")
So, just removing the call and the 'match' variable
entirely instead of fixing it.
Fixes: 21b2fa617126 ("ofp-parse: Allow match field names in actions and brackets in matches.")
Reported-at: https://mail.openvswitch.org/pipermail/ovs-discuss/2022-November/052100.html
Reported-by: Thomas Lee <newsforthomas@engineer.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
2022-11-23 22:23:37 +01:00
|
|
|
spec, ofpacts);
|
2013-07-08 10:15:00 -07:00
|
|
|
if (error) {
|
|
|
|
return error;
|
|
|
|
}
|
2016-08-31 08:43:48 -07:00
|
|
|
learn = ofpacts->header;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
}
|
2019-03-20 13:40:19 -07:00
|
|
|
|
|
|
|
if (ofpbuf_oversized(ofpacts)) {
|
|
|
|
return xasprintf("input too big");
|
|
|
|
}
|
|
|
|
|
2016-04-12 22:00:25 -07:00
|
|
|
ofpact_finish_LEARN(ofpacts, &learn);
|
2011-09-27 13:12:04 -07:00
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parses 'arg' as a set of arguments to the "learn" action and appends a
|
2018-11-08 21:39:55 -08:00
|
|
|
* matching OFPACT_LEARN action to 'ofpacts'. ovs-actions(7) describes the
|
2013-07-08 10:15:00 -07:00
|
|
|
* format parsed.
|
|
|
|
*
|
|
|
|
* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
* error. The caller is responsible for freeing the returned string.
|
|
|
|
*
|
|
|
|
* If 'flow' is nonnull, then it should be the flow from a struct match that is
|
|
|
|
* the matching rule for the learning action. This helps to better validate
|
|
|
|
* the action's arguments.
|
|
|
|
*
|
|
|
|
* Modifies 'arg'. */
|
2014-12-15 14:10:38 +01:00
|
|
|
char * OVS_WARN_UNUSED_RESULT
|
2017-05-31 16:06:12 -07:00
|
|
|
learn_parse(char *arg, const struct ofputil_port_map *port_map,
|
Support accepting and displaying table names in OVS tools.
OpenFlow has little-known support for naming tables. Open vSwitch has
supported table names for ages, but it has never used or displayed them
outside of commands dedicated to table manipulation. This commit adds
support for table names in ovs-ofctl. When a table has a name, it displays
that name in flows and actions, so that, for example, the following:
table=1, arp, actions=resubmit(,2)
might become:
table=ingress_acl, arp, actions=resubmit(,mac_learning)
given appropriately named tables.
For backward compatibility, only interactive ovs-ofctl commands by default
display table names; to display them in scripts, use the new --names
option.
This feature was inspired by a talk that Kei Nohguchi presented at Open
vSwitch 2017 Fall Conference.
CC: Kei Nohguchi <kei@nohguchi.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Mark Michelson <mmichels@redhat.com>
Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
2018-01-05 16:59:13 -08:00
|
|
|
const struct ofputil_table_map *table_map,
|
2017-05-31 16:06:12 -07:00
|
|
|
struct ofpbuf *ofpacts)
|
2013-07-08 10:15:00 -07:00
|
|
|
{
|
|
|
|
char *orig = xstrdup(arg);
|
Support accepting and displaying table names in OVS tools.
OpenFlow has little-known support for naming tables. Open vSwitch has
supported table names for ages, but it has never used or displayed them
outside of commands dedicated to table manipulation. This commit adds
support for table names in ovs-ofctl. When a table has a name, it displays
that name in flows and actions, so that, for example, the following:
table=1, arp, actions=resubmit(,2)
might become:
table=ingress_acl, arp, actions=resubmit(,mac_learning)
given appropriately named tables.
For backward compatibility, only interactive ovs-ofctl commands by default
display table names; to display them in scripts, use the new --names
option.
This feature was inspired by a talk that Kei Nohguchi presented at Open
vSwitch 2017 Fall Conference.
CC: Kei Nohguchi <kei@nohguchi.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Mark Michelson <mmichels@redhat.com>
Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
2018-01-05 16:59:13 -08:00
|
|
|
char *error = learn_parse__(orig, arg, port_map, table_map, ofpacts);
|
2011-09-27 13:12:04 -07:00
|
|
|
free(orig);
|
2013-07-08 10:15:00 -07:00
|
|
|
return error;
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
|
2018-11-08 21:39:55 -08:00
|
|
|
/* Appends a description of 'learn' to 's', in the format that ovs-actions(7)
|
2012-07-03 22:17:14 -07:00
|
|
|
* describes. */
|
2011-09-12 16:19:57 -07:00
|
|
|
void
|
2017-05-31 16:06:12 -07:00
|
|
|
learn_format(const struct ofpact_learn *learn,
|
Support accepting and displaying table names in OVS tools.
OpenFlow has little-known support for naming tables. Open vSwitch has
supported table names for ages, but it has never used or displayed them
outside of commands dedicated to table manipulation. This commit adds
support for table names in ovs-ofctl. When a table has a name, it displays
that name in flows and actions, so that, for example, the following:
table=1, arp, actions=resubmit(,2)
might become:
table=ingress_acl, arp, actions=resubmit(,mac_learning)
given appropriately named tables.
For backward compatibility, only interactive ovs-ofctl commands by default
display table names; to display them in scripts, use the new --names
option.
This feature was inspired by a talk that Kei Nohguchi presented at Open
vSwitch 2017 Fall Conference.
CC: Kei Nohguchi <kei@nohguchi.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Mark Michelson <mmichels@redhat.com>
Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
2018-01-05 16:59:13 -08:00
|
|
|
const struct ofputil_port_map *port_map,
|
|
|
|
const struct ofputil_table_map *table_map,
|
|
|
|
struct ds *s)
|
2011-09-12 16:19:57 -07:00
|
|
|
{
|
2012-07-03 22:17:14 -07:00
|
|
|
const struct ofpact_learn_spec *spec;
|
2012-08-07 15:28:18 -07:00
|
|
|
struct match match;
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2012-08-07 15:28:18 -07:00
|
|
|
match_init_catchall(&match);
|
2011-09-12 16:19:57 -07:00
|
|
|
|
Support accepting and displaying table names in OVS tools.
OpenFlow has little-known support for naming tables. Open vSwitch has
supported table names for ages, but it has never used or displayed them
outside of commands dedicated to table manipulation. This commit adds
support for table names in ovs-ofctl. When a table has a name, it displays
that name in flows and actions, so that, for example, the following:
table=1, arp, actions=resubmit(,2)
might become:
table=ingress_acl, arp, actions=resubmit(,mac_learning)
given appropriately named tables.
For backward compatibility, only interactive ovs-ofctl commands by default
display table names; to display them in scripts, use the new --names
option.
This feature was inspired by a talk that Kei Nohguchi presented at Open
vSwitch 2017 Fall Conference.
CC: Kei Nohguchi <kei@nohguchi.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Mark Michelson <mmichels@redhat.com>
Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
2018-01-05 16:59:13 -08:00
|
|
|
ds_put_format(s, "%slearn(%s%stable=%s",
|
|
|
|
colors.learn, colors.end, colors.special, colors.end);
|
|
|
|
ofputil_format_table(learn->table_id, table_map, s);
|
2012-07-03 22:17:14 -07:00
|
|
|
if (learn->idle_timeout != OFP_FLOW_PERMANENT) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, ",%sidle_timeout=%s%"PRIu16,
|
|
|
|
colors.param, colors.end, learn->idle_timeout);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
2012-07-03 22:17:14 -07:00
|
|
|
if (learn->hard_timeout != OFP_FLOW_PERMANENT) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, ",%shard_timeout=%s%"PRIu16,
|
|
|
|
colors.param, colors.end, learn->hard_timeout);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
2012-02-15 10:37:03 -08:00
|
|
|
if (learn->fin_idle_timeout) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, ",%sfin_idle_timeout=%s%"PRIu16,
|
|
|
|
colors.param, colors.end, learn->fin_idle_timeout);
|
2012-02-15 10:37:03 -08:00
|
|
|
}
|
|
|
|
if (learn->fin_hard_timeout) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s,fin_hard_timeout=%s%"PRIu16,
|
|
|
|
colors.param, colors.end, learn->fin_hard_timeout);
|
2012-02-15 10:37:03 -08:00
|
|
|
}
|
2012-07-03 22:17:14 -07:00
|
|
|
if (learn->priority != OFP_DEFAULT_PRIORITY) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s,priority=%s%"PRIu16,
|
|
|
|
colors.special, colors.end, learn->priority);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
2014-06-05 21:53:34 -07:00
|
|
|
if (learn->flags & NX_LEARN_F_SEND_FLOW_REM) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, ",%ssend_flow_rem%s", colors.value, colors.end);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
2014-06-05 21:53:34 -07:00
|
|
|
if (learn->flags & NX_LEARN_F_DELETE_LEARNED) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, ",%sdelete_learned%s", colors.value, colors.end);
|
2014-06-05 21:53:34 -07:00
|
|
|
}
|
2012-07-03 22:17:14 -07:00
|
|
|
if (learn->cookie != 0) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, ",%scookie=%s%#"PRIx64,
|
|
|
|
colors.param, colors.end, ntohll(learn->cookie));
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
2017-03-10 15:44:40 -08:00
|
|
|
if (learn->limit != 0) {
|
|
|
|
ds_put_format(s, ",%slimit=%s%"PRIu32,
|
|
|
|
colors.param, colors.end, learn->limit);
|
|
|
|
}
|
|
|
|
if (learn->flags & NX_LEARN_F_WRITE_RESULT) {
|
|
|
|
ds_put_format(s, ",%sresult_dst=%s", colors.param, colors.end);
|
|
|
|
mf_format_subfield(&learn->result_dst, s);
|
|
|
|
}
|
2011-09-12 16:19:57 -07:00
|
|
|
|
2016-09-02 13:26:50 -07:00
|
|
|
OFPACT_LEARN_SPEC_FOR_EACH (spec, learn) {
|
2016-09-01 13:29:57 -07:00
|
|
|
unsigned int n_bytes = DIV_ROUND_UP(spec->n_bits, 8);
|
2011-09-12 16:19:57 -07:00
|
|
|
ds_put_char(s, ',');
|
|
|
|
|
2012-07-03 22:17:14 -07:00
|
|
|
switch (spec->src_type | spec->dst_type) {
|
2016-08-31 08:43:48 -07:00
|
|
|
case NX_LEARN_SRC_IMMEDIATE | NX_LEARN_DST_MATCH: {
|
2012-07-03 22:17:14 -07:00
|
|
|
if (spec->dst.ofs == 0
|
|
|
|
&& spec->dst.n_bits == spec->dst.field->n_bits) {
|
2011-09-12 16:19:57 -07:00
|
|
|
union mf_value value;
|
2011-12-01 08:33:55 -08:00
|
|
|
|
2011-09-12 16:19:57 -07:00
|
|
|
memset(&value, 0, sizeof value);
|
2016-08-31 08:43:48 -07:00
|
|
|
memcpy(&value.b[spec->dst.field->n_bytes - n_bytes],
|
2016-09-01 13:29:57 -07:00
|
|
|
ofpact_learn_spec_imm(spec), n_bytes);
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s%s=%s", colors.param,
|
|
|
|
spec->dst.field->name, colors.end);
|
2017-05-31 16:06:12 -07:00
|
|
|
mf_format(spec->dst.field, &value, NULL, port_map, s);
|
2011-09-12 16:19:57 -07:00
|
|
|
} else {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s", colors.param);
|
2012-07-03 22:17:14 -07:00
|
|
|
mf_format_subfield(&spec->dst, s);
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "=%s", colors.end);
|
2016-09-01 13:29:57 -07:00
|
|
|
ds_put_hex(s, ofpact_learn_spec_imm(spec), n_bytes);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
break;
|
2016-08-31 08:43:48 -07:00
|
|
|
}
|
2011-09-12 16:19:57 -07:00
|
|
|
case NX_LEARN_SRC_FIELD | NX_LEARN_DST_MATCH:
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s", colors.param);
|
2012-07-03 22:17:14 -07:00
|
|
|
mf_format_subfield(&spec->dst, s);
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s", colors.end);
|
2012-07-03 22:17:14 -07:00
|
|
|
if (spec->src.field != spec->dst.field ||
|
|
|
|
spec->src.ofs != spec->dst.ofs) {
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s=%s", colors.param, colors.end);
|
2012-07-03 22:17:14 -07:00
|
|
|
mf_format_subfield(&spec->src, s);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_LEARN_SRC_IMMEDIATE | NX_LEARN_DST_LOAD:
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%sload:%s", colors.special, colors.end);
|
2016-09-01 13:29:57 -07:00
|
|
|
ds_put_hex(s, ofpact_learn_spec_imm(spec), n_bytes);
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s->%s", colors.special, colors.end);
|
2012-07-03 22:17:14 -07:00
|
|
|
mf_format_subfield(&spec->dst, s);
|
2011-09-12 16:19:57 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_LEARN_SRC_FIELD | NX_LEARN_DST_LOAD:
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%sload:%s", colors.special, colors.end);
|
2012-07-03 22:17:14 -07:00
|
|
|
mf_format_subfield(&spec->src, s);
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s->%s", colors.special, colors.end);
|
2012-07-03 22:17:14 -07:00
|
|
|
mf_format_subfield(&spec->dst, s);
|
2011-09-12 16:19:57 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NX_LEARN_SRC_FIELD | NX_LEARN_DST_OUTPUT:
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%soutput:%s", colors.special, colors.end);
|
2012-07-03 22:17:14 -07:00
|
|
|
mf_format_subfield(&spec->src, s);
|
2011-09-12 16:19:57 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-03-02 15:56:20 +01:00
|
|
|
ds_put_format(s, "%s)%s", colors.learn, colors.end);
|
2011-09-12 16:19:57 -07:00
|
|
|
}
|