}
if (!(ofpfw & OFPFW10_DL_SRC)) {
- memset(wc->masks.dl_src, 0xff, ETH_ADDR_LEN);
+ WC_MASK_FIELD(wc, dl_src);
}
if (!(ofpfw & OFPFW10_DL_DST)) {
- memset(wc->masks.dl_dst, 0xff, ETH_ADDR_LEN);
+ WC_MASK_FIELD(wc, dl_dst);
}
if (!(ofpfw & OFPFW10_DL_TYPE)) {
wc->masks.dl_type = OVS_BE16_MAX;
match->flow.dl_type = ofputil_dl_type_from_openflow(ofmatch->dl_type);
match->flow.tp_src = ofmatch->tp_src;
match->flow.tp_dst = ofmatch->tp_dst;
- memcpy(match->flow.dl_src, ofmatch->dl_src, ETH_ADDR_LEN);
- memcpy(match->flow.dl_dst, ofmatch->dl_dst, ETH_ADDR_LEN);
+ match->flow.dl_src = ofmatch->dl_src;
+ match->flow.dl_dst = ofmatch->dl_dst;
match->flow.nw_tos = ofmatch->nw_tos & IP_DSCP_MASK;
match->flow.nw_proto = ofmatch->nw_proto;
} else if (match->wc.masks.vlan_tci & htons(VLAN_CFI)
&& !(match->flow.vlan_tci & htons(VLAN_CFI))) {
ofmatch->dl_vlan = htons(OFP10_VLAN_NONE);
- ofpfw |= OFPFW10_DL_VLAN_PCP;
} else {
if (!(match->wc.masks.vlan_tci & htons(VLAN_VID_MASK))) {
ofpfw |= OFPFW10_DL_VLAN;
/* Compose most of the match structure. */
ofmatch->wildcards = htonl(ofpfw);
ofmatch->in_port = htons(ofp_to_u16(match->flow.in_port.ofp_port));
- memcpy(ofmatch->dl_src, match->flow.dl_src, ETH_ADDR_LEN);
- memcpy(ofmatch->dl_dst, match->flow.dl_dst, ETH_ADDR_LEN);
+ ofmatch->dl_src = match->flow.dl_src;
+ ofmatch->dl_dst = match->flow.dl_dst;
ofmatch->dl_type = ofputil_dl_type_to_openflow(match->flow.dl_type);
ofmatch->nw_src = match->flow.nw_src;
ofmatch->nw_dst = match->flow.nw_dst;
struct match *match)
{
uint16_t wc = ntohl(ofmatch->wildcards);
- uint8_t dl_src_mask[ETH_ADDR_LEN];
- uint8_t dl_dst_mask[ETH_ADDR_LEN];
bool ipv4, arp, rarp;
- int i;
match_init_catchall(match);
match_set_in_port(match, ofp_port);
}
- for (i = 0; i < ETH_ADDR_LEN; i++) {
- dl_src_mask[i] = ~ofmatch->dl_src_mask[i];
- }
- match_set_dl_src_masked(match, ofmatch->dl_src, dl_src_mask);
-
- for (i = 0; i < ETH_ADDR_LEN; i++) {
- dl_dst_mask[i] = ~ofmatch->dl_dst_mask[i];
- }
- match_set_dl_dst_masked(match, ofmatch->dl_dst, dl_dst_mask);
+ match_set_dl_src_masked(match, ofmatch->dl_src,
+ eth_addr_invert(ofmatch->dl_src_mask));
+ match_set_dl_dst_masked(match, ofmatch->dl_dst,
+ eth_addr_invert(ofmatch->dl_dst_mask));
if (!(wc & OFPFW11_DL_VLAN)) {
if (ofmatch->dl_vlan == htons(OFPVID11_NONE)) {
struct ofp11_match *ofmatch)
{
uint32_t wc = 0;
- int i;
memset(ofmatch, 0, sizeof *ofmatch);
ofmatch->omh.type = htons(OFPMT_STANDARD);
ofmatch->in_port = ofputil_port_to_ofp11(match->flow.in_port.ofp_port);
}
- memcpy(ofmatch->dl_src, match->flow.dl_src, ETH_ADDR_LEN);
- for (i = 0; i < ETH_ADDR_LEN; i++) {
- ofmatch->dl_src_mask[i] = ~match->wc.masks.dl_src[i];
- }
-
- memcpy(ofmatch->dl_dst, match->flow.dl_dst, ETH_ADDR_LEN);
- for (i = 0; i < ETH_ADDR_LEN; i++) {
- ofmatch->dl_dst_mask[i] = ~match->wc.masks.dl_dst[i];
- }
+ ofmatch->dl_src = match->flow.dl_src;
+ ofmatch->dl_src_mask = eth_addr_invert(match->wc.masks.dl_src);
+ ofmatch->dl_dst = match->flow.dl_dst;
+ ofmatch->dl_dst_mask = eth_addr_invert(match->wc.masks.dl_dst);
if (match->wc.masks.vlan_tci == htons(0)) {
wc |= OFPFW11_DL_VLAN | OFPFW11_DL_VLAN_PCP;
const struct ofp10_phy_port *opp)
{
pp->port_no = u16_to_ofp(ntohs(opp->port_no));
- memcpy(pp->hw_addr, opp->hw_addr, OFP_ETH_ALEN);
+ pp->hw_addr = opp->hw_addr;
ovs_strlcpy(pp->name, opp->name, OFP_MAX_PORT_NAME_LEN);
pp->config = ntohl(opp->config) & OFPPC10_ALL;
if (error) {
return error;
}
- memcpy(pp->hw_addr, op->hw_addr, OFP_ETH_ALEN);
+ pp->hw_addr = op->hw_addr;
ovs_strlcpy(pp->name, op->name, OFP_MAX_PORT_NAME_LEN);
pp->config = ntohl(op->config) & OFPPC11_ALL;
if (error) {
return error;
}
- memcpy(pp->hw_addr, op->hw_addr, OFP_ETH_ALEN);
+ pp->hw_addr = op->hw_addr;
ovs_strlcpy(pp->name, op->name, OFP_MAX_PORT_NAME_LEN);
pp->config = ntohl(op->config) & OFPPC11_ALL;
memset(opp, 0, sizeof *opp);
opp->port_no = htons(ofp_to_u16(pp->port_no));
- memcpy(opp->hw_addr, pp->hw_addr, ETH_ADDR_LEN);
+ opp->hw_addr = pp->hw_addr;
ovs_strlcpy(opp->name, pp->name, OFP_MAX_PORT_NAME_LEN);
opp->config = htonl(pp->config & OFPPC10_ALL);
memset(op, 0, sizeof *op);
op->port_no = ofputil_port_to_ofp11(pp->port_no);
- memcpy(op->hw_addr, pp->hw_addr, ETH_ADDR_LEN);
+ op->hw_addr = pp->hw_addr;
ovs_strlcpy(op->name, pp->name, OFP_MAX_PORT_NAME_LEN);
op->config = htonl(pp->config & OFPPC11_ALL);
op = ofpbuf_put_zeros(b, sizeof *op);
op->port_no = ofputil_port_to_ofp11(pp->port_no);
op->length = htons(sizeof *op + sizeof *eth);
- memcpy(op->hw_addr, pp->hw_addr, ETH_ADDR_LEN);
+ op->hw_addr = pp->hw_addr;
ovs_strlcpy(op->name, pp->name, sizeof op->name);
op->config = htonl(pp->config & OFPPC11_ALL);
op->state = htonl(pp->state & OFPPS11_ALL);
ofp_port_t port)
{
struct ofpbuf *request;
- ovs_be32 ofp11_port;
switch (ofp_version) {
case OFP10_VERSION:
request = ofpraw_alloc(OFPRAW_OFPST10_PORT_DESC_REQUEST,
ofp_version, 0);
break;
-
- case OFP15_VERSION:
+ case OFP15_VERSION:{
+ struct ofp15_port_desc_request *req;
request = ofpraw_alloc(OFPRAW_OFPST15_PORT_DESC_REQUEST,
ofp_version, 0);
- ofp11_port = ofputil_port_to_ofp11(port);
- ofpbuf_put(request, &ofp11_port, sizeof ofp11_port);
+ req = ofpbuf_put_zeros(request, sizeof *req);
+ req->port_no = ofputil_port_to_ofp11(port);
break;
-
+ }
default:
OVS_NOT_REACHED();
}
const struct ofp10_port_mod *opm = b.data;
pm->port_no = u16_to_ofp(ntohs(opm->port_no));
- memcpy(pm->hw_addr, opm->hw_addr, ETH_ADDR_LEN);
+ pm->hw_addr = opm->hw_addr;
pm->config = ntohl(opm->config) & OFPPC10_ALL;
pm->mask = ntohl(opm->mask) & OFPPC10_ALL;
pm->advertise = netdev_port_features_from_ofp10(opm->advertise);
return error;
}
- memcpy(pm->hw_addr, opm->hw_addr, ETH_ADDR_LEN);
+ pm->hw_addr = opm->hw_addr;
pm->config = ntohl(opm->config) & OFPPC11_ALL;
pm->mask = ntohl(opm->mask) & OFPPC11_ALL;
pm->advertise = netdev_port_features_from_ofp11(opm->advertise);
return error;
}
- memcpy(pm->hw_addr, opm->hw_addr, ETH_ADDR_LEN);
+ pm->hw_addr = opm->hw_addr;
pm->config = ntohl(opm->config) & OFPPC11_ALL;
pm->mask = ntohl(opm->mask) & OFPPC11_ALL;
b = ofpraw_alloc(OFPRAW_OFPT10_PORT_MOD, ofp_version, 0);
opm = ofpbuf_put_zeros(b, sizeof *opm);
opm->port_no = htons(ofp_to_u16(pm->port_no));
- memcpy(opm->hw_addr, pm->hw_addr, ETH_ADDR_LEN);
+ opm->hw_addr = pm->hw_addr;
opm->config = htonl(pm->config & OFPPC10_ALL);
opm->mask = htonl(pm->mask & OFPPC10_ALL);
opm->advertise = netdev_port_features_to_ofp10(pm->advertise);
b = ofpraw_alloc(OFPRAW_OFPT11_PORT_MOD, ofp_version, 0);
opm = ofpbuf_put_zeros(b, sizeof *opm);
opm->port_no = ofputil_port_to_ofp11(pm->port_no);
- memcpy(opm->hw_addr, pm->hw_addr, ETH_ADDR_LEN);
+ opm->hw_addr = pm->hw_addr;
opm->config = htonl(pm->config & OFPPC11_ALL);
opm->mask = htonl(pm->mask & OFPPC11_ALL);
opm->advertise = netdev_port_features_to_ofp11(pm->advertise);
b = ofpraw_alloc(OFPRAW_OFPT14_PORT_MOD, ofp_version, sizeof *eth);
opm = ofpbuf_put_zeros(b, sizeof *opm);
opm->port_no = ofputil_port_to_ofp11(pm->port_no);
- memcpy(opm->hw_addr, pm->hw_addr, ETH_ADDR_LEN);
+ opm->hw_addr = pm->hw_addr;
opm->config = htonl(pm->config & OFPPC11_ALL);
opm->mask = htonl(pm->mask & OFPPC11_ALL);
wc.masks.nw_ttl = 0;
}
if (!(may_match & MAY_ARP_SHA)) {
- memset(wc.masks.arp_sha, 0, ETH_ADDR_LEN);
+ WC_UNMASK_FIELD(&wc, arp_sha);
}
if (!(may_match & MAY_ARP_THA)) {
- memset(wc.masks.arp_tha, 0, ETH_ADDR_LEN);
+ WC_UNMASK_FIELD(&wc, arp_tha);
}
if (!(may_match & MAY_IPV6)) {
wc.masks.ipv6_src = wc.masks.ipv6_dst = in6addr_any;
uint32_t group_id)
{
struct ofpbuf *request;
- ovs_be32 gid;
switch (ofp_version) {
case OFP10_VERSION:
request = ofpraw_alloc(OFPRAW_OFPST11_GROUP_DESC_REQUEST,
ofp_version, 0);
break;
- case OFP15_VERSION:
+ case OFP15_VERSION:{
+ struct ofp15_group_desc_request *req;
request = ofpraw_alloc(OFPRAW_OFPST15_GROUP_DESC_REQUEST,
ofp_version, 0);
- gid = htonl(group_id);
- ofpbuf_put(request, &gid, sizeof gid);
+ req = ofpbuf_put_zeros(request, sizeof *req);
+ req->group_id = htonl(group_id);
break;
+ }
default:
OVS_NOT_REACHED();
}
static enum ofperr
ofputil_pull_ofp15_buckets(struct ofpbuf *msg, size_t buckets_length,
- enum ofp_version version, struct ovs_list *buckets)
+ enum ofp_version version, uint8_t group_type,
+ struct ovs_list *buckets)
{
struct ofp15_bucket *ob;
size_t ob_len, actions_len, properties_len;
ovs_be32 watch_port = ofputil_port_to_ofp11(OFPP_ANY);
ovs_be32 watch_group = htonl(OFPG_ANY);
- ovs_be16 weight = htons(1);
+ ovs_be16 weight = htons(group_type == OFPGT11_SELECT ? 1 : 0);
ofpbuf_init(&ofpacts, 0);
"bucket list length %u", bucket_list_len);
return OFPERR_OFPBRC_BAD_LEN;
}
- error = ofputil_pull_ofp15_buckets(msg, bucket_list_len, version,
+ error = ofputil_pull_ofp15_buckets(msg, bucket_list_len, version, gd->type,
&gd->buckets);
if (error) {
return error;
bucket_list_len = ntohs(ogm->bucket_array_len);
error = ofputil_pull_ofp15_buckets(msg, bucket_list_len, ofp_version,
- &gm->buckets);
+ gm->type, &gm->buckets);
if (error) {
return error;
}
switch (gm->type) {
case OFPGT11_INDIRECT:
if (!list_is_singleton(&gm->buckets)) {
- return OFPERR_OFPGMFC_OUT_OF_BUCKETS;
+ return OFPERR_OFPGMFC_INVALID_GROUP;
}
break;
case OFPGT11_ALL:
}
LIST_FOR_EACH (bucket, list_node, &gm->buckets) {
+ if (bucket->weight && gm->type != OFPGT11_SELECT) {
+ return OFPERR_OFPGMFC_INVALID_GROUP;
+ }
+
switch (gm->type) {
case OFPGT11_ALL:
case OFPGT11_INDIRECT:
}
static enum ofperr
-decode_geneve_table_mappings(struct ofpbuf *msg, struct ovs_list *mappings)
+decode_geneve_table_mappings(struct ofpbuf *msg, unsigned int max_fields,
+ struct ovs_list *mappings)
{
list_init(mappings);
}
map->index = ntohs(nx_map->index);
- if (map->index >= TUN_METADATA_NUM_OPTS) {
+ if (map->index >= max_fields) {
VLOG_WARN_RL(&bad_ofmsg_rl,
"geneve table field index (%u) is too large (max %u)",
- map->index, TUN_METADATA_NUM_OPTS - 1);
+ map->index, max_fields - 1);
ofputil_uninit_geneve_table(mappings);
return OFPERR_NXGTMFC_BAD_FIELD_IDX;
}
return OFPERR_NXGTMFC_BAD_COMMAND;
}
- return decode_geneve_table_mappings(&msg, >m->mappings);
+ return decode_geneve_table_mappings(&msg, TUN_METADATA_NUM_OPTS,
+ >m->mappings);
}
struct ofpbuf *
return b;
}
+/* Decodes the NXT_GENEVE_TABLE_REPLY message in 'oh' into '*gtr'. Returns 0
+ * if successful, otherwise an ofperr.
+ *
+ * The decoder verifies that the indexes in 'gtr->mappings' are less than
+ * 'gtr->max_fields', but the caller must ensure, if necessary, that they are
+ * less than TUN_METADATA_NUM_OPTS. */
enum ofperr
ofputil_decode_geneve_table_reply(const struct ofp_header *oh,
struct ofputil_geneve_table_reply *gtr)
gtr->max_option_space = ntohl(nx_gtr->max_option_space);
gtr->max_fields = ntohs(nx_gtr->max_fields);
- return decode_geneve_table_mappings(&msg, >r->mappings);
+ return decode_geneve_table_mappings(&msg, gtr->max_fields, >r->mappings);
}
void
free(map);
}
}
+
+/* Decodes the OpenFlow "set async config" request and "get async config
+ * reply" message in '*oh' into an abstract form in 'master' and 'slave'.
+ *
+ * If 'loose' is true, this function ignores properties and values that it does
+ * not understand, as a controller would want to do when interpreting
+ * capabilities provided by a switch. If 'loose' is false, this function
+ * treats unknown properties and values as an error, as a switch would want to
+ * do when interpreting a configuration request made by a controller.
+ *
+ * Returns 0 if successful, otherwise an OFPERR_* value. */
+enum ofperr
+ofputil_decode_set_async_config(const struct ofp_header *oh,
+ uint32_t master[OAM_N_TYPES],
+ uint32_t slave[OAM_N_TYPES],
+ bool loose)
+{
+ enum ofpraw raw;
+ struct ofpbuf b;
+
+ ofpbuf_use_const(&b, oh, ntohs(oh->length));
+ raw = ofpraw_pull_assert(&b);
+
+ if (raw == OFPRAW_OFPT13_SET_ASYNC ||
+ raw == OFPRAW_NXT_SET_ASYNC_CONFIG ||
+ raw == OFPRAW_OFPT13_GET_ASYNC_REPLY) {
+ const struct nx_async_config *msg = ofpmsg_body(oh);
+
+ master[OAM_PACKET_IN] = ntohl(msg->packet_in_mask[0]);
+ master[OAM_PORT_STATUS] = ntohl(msg->port_status_mask[0]);
+ master[OAM_FLOW_REMOVED] = ntohl(msg->flow_removed_mask[0]);
+
+ slave[OAM_PACKET_IN] = ntohl(msg->packet_in_mask[1]);
+ slave[OAM_PORT_STATUS] = ntohl(msg->port_status_mask[1]);
+ slave[OAM_FLOW_REMOVED] = ntohl(msg->flow_removed_mask[1]);
+
+ } else if (raw == OFPRAW_OFPT14_SET_ASYNC ||
+ raw == OFPRAW_OFPT14_GET_ASYNC_REPLY) {
+
+ while (b.size > 0) {
+ struct ofp14_async_config_prop_reasons *msg;
+ struct ofpbuf property;
+ enum ofperr error;
+ uint16_t type;
+
+ error = ofputil_pull_property(&b, &property, &type);
+ if (error) {
+ return error;
+ }
+
+ msg = property.data;
+
+ if (property.size != sizeof *msg) {
+ return OFPERR_OFPBRC_BAD_LEN;
+ }
+
+ switch (type) {
+ case OFPACPT_PACKET_IN_SLAVE:
+ slave[OAM_PACKET_IN] = ntohl(msg->mask);
+ break;
+
+ case OFPACPT_PACKET_IN_MASTER:
+ master[OAM_PACKET_IN] = ntohl(msg->mask);
+ break;
+
+ case OFPACPT_PORT_STATUS_SLAVE:
+ slave[OAM_PORT_STATUS] = ntohl(msg->mask);
+ break;
+
+ case OFPACPT_PORT_STATUS_MASTER:
+ master[OAM_PORT_STATUS] = ntohl(msg->mask);
+ break;
+
+ case OFPACPT_FLOW_REMOVED_SLAVE:
+ slave[OAM_FLOW_REMOVED] = ntohl(msg->mask);
+ break;
+
+ case OFPACPT_FLOW_REMOVED_MASTER:
+ master[OAM_FLOW_REMOVED] = ntohl(msg->mask);
+ break;
+
+ case OFPACPT_ROLE_STATUS_SLAVE:
+ slave[OAM_ROLE_STATUS] = ntohl(msg->mask);
+ break;
+
+ case OFPACPT_ROLE_STATUS_MASTER:
+ master[OAM_ROLE_STATUS] = ntohl(msg->mask);
+ break;
+
+ case OFPACPT_TABLE_STATUS_SLAVE:
+ slave[OAM_TABLE_STATUS] = ntohl(msg->mask);
+ break;
+
+ case OFPACPT_TABLE_STATUS_MASTER:
+ master[OAM_TABLE_STATUS] = ntohl(msg->mask);
+ break;
+
+ case OFPACPT_REQUESTFORWARD_SLAVE:
+ slave[OAM_REQUESTFORWARD] = ntohl(msg->mask);
+ break;
+
+ case OFPACPT_REQUESTFORWARD_MASTER:
+ master[OAM_REQUESTFORWARD] = ntohl(msg->mask);
+ break;
+
+ default:
+ error = loose ? 0 : OFPERR_OFPBPC_BAD_TYPE;
+ break;
+ }
+ if (error) {
+ return error;
+ }
+ }
+ } else {
+ return OFPERR_OFPBRC_BAD_VERSION;
+ }
+ return 0;
+}
+
+/* Append all asynchronous configuration properties in GET_ASYNC_REPLY
+ * message, describing if various set of asynchronous messages are enabled
+ * or not. */
+static enum ofperr
+ofputil_get_async_reply(struct ofpbuf *buf, const uint32_t master_mask,
+ const uint32_t slave_mask, const uint32_t type)
+{
+ int role;
+
+ for (role = 0; role < 2; role++) {
+ struct ofp14_async_config_prop_reasons *msg;
+
+ msg = ofpbuf_put_zeros(buf, sizeof *msg);
+
+ switch (type) {
+ case OAM_PACKET_IN:
+ msg->type = (role ? htons(OFPACPT_PACKET_IN_SLAVE)
+ : htons(OFPACPT_PACKET_IN_MASTER));
+ break;
+
+ case OAM_PORT_STATUS:
+ msg->type = (role ? htons(OFPACPT_PORT_STATUS_SLAVE)
+ : htons(OFPACPT_PORT_STATUS_MASTER));
+ break;
+
+ case OAM_FLOW_REMOVED:
+ msg->type = (role ? htons(OFPACPT_FLOW_REMOVED_SLAVE)
+ : htons(OFPACPT_FLOW_REMOVED_MASTER));
+ break;
+
+ case OAM_ROLE_STATUS:
+ msg->type = (role ? htons(OFPACPT_ROLE_STATUS_SLAVE)
+ : htons(OFPACPT_ROLE_STATUS_MASTER));
+ break;
+
+ case OAM_TABLE_STATUS:
+ msg->type = (role ? htons(OFPACPT_TABLE_STATUS_SLAVE)
+ : htons(OFPACPT_TABLE_STATUS_MASTER));
+ break;
+
+ case OAM_REQUESTFORWARD:
+ msg->type = (role ? htons(OFPACPT_REQUESTFORWARD_SLAVE)
+ : htons(OFPACPT_REQUESTFORWARD_MASTER));
+ break;
+
+ default:
+ return OFPERR_OFPBRC_BAD_TYPE;
+ }
+ msg->length = htons(sizeof *msg);
+ msg->mask = (role ? htonl(slave_mask) : htonl(master_mask));
+ }
+
+ return 0;
+}
+
+/* Returns a OpenFlow message that encodes 'asynchronous configuration' properly
+ * as a reply to get async config request. */
+struct ofpbuf *
+ofputil_encode_get_async_config(const struct ofp_header *oh,
+ uint32_t master[OAM_N_TYPES],
+ uint32_t slave[OAM_N_TYPES])
+{
+ struct ofpbuf *buf;
+ uint32_t type;
+
+ buf = ofpraw_alloc_reply((oh->version < OFP14_VERSION
+ ? OFPRAW_OFPT13_GET_ASYNC_REPLY
+ : OFPRAW_OFPT14_GET_ASYNC_REPLY), oh, 0);
+
+ if (oh->version < OFP14_VERSION) {
+ struct nx_async_config *msg;
+ msg = ofpbuf_put_zeros(buf, sizeof *msg);
+
+ msg->packet_in_mask[0] = htonl(master[OAM_PACKET_IN]);
+ msg->port_status_mask[0] = htonl(master[OAM_PORT_STATUS]);
+ msg->flow_removed_mask[0] = htonl(master[OAM_FLOW_REMOVED]);
+
+ msg->packet_in_mask[1] = htonl(slave[OAM_PACKET_IN]);
+ msg->port_status_mask[1] = htonl(slave[OAM_PORT_STATUS]);
+ msg->flow_removed_mask[1] = htonl(slave[OAM_FLOW_REMOVED]);
+ } else if (oh->version == OFP14_VERSION) {
+ for (type = 0; type < OAM_N_TYPES; type++) {
+ ofputil_get_async_reply(buf, master[type], slave[type], type);
+ }
+ }
+
+ return buf;
+}