[ovs-dev] [PATCH v2] dpif-netlink: convert packet_type netlink attribute
Zoltán Balogh
zoltan.balogh at ericsson.com
Fri Jul 7 14:48:20 UTC 2017
Hi Eric,
I agree, my last patch did not help at all. We have reworked it with Jan, removed the unneeded code parts, it's simpler now. This way, removal of the PACKET_TYPE netlink attribute and adding of ETHER_TYPE netlink attribute happens at the same place.
Could you have a look at it and test it, please?
--->8---
diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index 562f6134c..4ef8d9965 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -3434,31 +3434,35 @@ dpif_netlink_flow_from_ofpbuf(struct dpif_netlink_flow *flow,
/*
- * If PACKET_TYPE attribute is present in 'data', it filters PACKET_TYPE out,
- * then puts 'data' to 'buf'.
+ * If PACKET_TYPE attribute is present in 'data', converts it to ETHERNET and
+ * ETHERTYPE attributes, then puts 'data' to 'buf'.
*/
static void
put_exclude_packet_type(struct ofpbuf *buf, uint16_t type,
const struct nlattr *data, uint16_t data_len)
{
- const struct nlattr *packet_type;
-
- packet_type = nl_attr_find__(data, data_len, OVS_KEY_ATTR_PACKET_TYPE);
-
+ const struct nlattr *packet_type =
+ nl_attr_find__(data, data_len, OVS_KEY_ATTR_PACKET_TYPE);
if (packet_type) {
- /* exclude PACKET_TYPE Netlink attribute. */
ovs_assert(NLA_ALIGN(packet_type->nla_len) == NL_A_U32_SIZE);
size_t packet_type_len = NL_A_U32_SIZE;
size_t first_chunk_size = (uint8_t *)packet_type - (uint8_t *)data;
size_t second_chunk_size = data_len - first_chunk_size
- packet_type_len;
- uint8_t *first_attr = NULL;
- struct nlattr *next_attr = nl_attr_next(packet_type);
+ struct nlattr *second_chunk = nl_attr_next(packet_type);
+ const struct nlattr *ethernet = nl_attr_find__(data, data_len,
+ OVS_KEY_ATTR_ETHERNET);
+ size_t offset = buf->size;
+
+ nl_msg_put_unspec(buf, type, data, first_chunk_size);
- first_attr = nl_msg_put_unspec_uninit(buf, type,
- data_len - packet_type_len);
- memcpy(first_attr, data, first_chunk_size);
- memcpy(first_attr + first_chunk_size, next_attr, second_chunk_size);
+ if (!ethernet) {
+ ovs_be32 value = nl_attr_get_be32(packet_type);
+ nl_msg_put_be16(buf, OVS_KEY_ATTR_ETHERTYPE, pt_ns_type_be(value));
+ }
+
+ nl_msg_put(buf, second_chunk, second_chunk_size);
+ nl_msg_end_nested(buf, offset);
} else {
nl_msg_put_unspec(buf, type, data, data_len);
}
@@ -3489,12 +3493,13 @@ dpif_netlink_flow_to_ofpbuf(const struct dpif_netlink_flow *flow,
}
if (!flow->ufid_terse || !flow->ufid_present) {
if (flow->key_len) {
- put_exclude_packet_type(buf, OVS_FLOW_ATTR_KEY, flow->key,
- flow->key_len);
+ put_exclude_packet_type(buf, OVS_FLOW_ATTR_KEY,
+ flow->key, flow->key_len);
}
+
if (flow->mask_len) {
- put_exclude_packet_type(buf, OVS_FLOW_ATTR_MASK, flow->mask,
- flow->mask_len);
+ put_exclude_packet_type(buf, OVS_FLOW_ATTR_MASK,
+ flow->mask, flow->mask_len);
}
if (flow->actions || flow->actions_len) {
nl_msg_put_unspec(buf, OVS_FLOW_ATTR_ACTIONS,
More information about the dev
mailing list