Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.2/patches/814769/?format=api
{ "id": 814769, "url": "http://patchwork.ozlabs.org/api/1.2/patches/814769/?format=api", "web_url": "http://patchwork.ozlabs.org/project/openvswitch/patch/1505708164-10270-4-git-send-email-roid@mellanox.com/", "project": { "id": 47, "url": "http://patchwork.ozlabs.org/api/1.2/projects/47/?format=api", "name": "Open vSwitch", "link_name": "openvswitch", "list_id": "ovs-dev.openvswitch.org", "list_email": "ovs-dev@openvswitch.org", "web_url": "http://openvswitch.org/", "scm_url": "git@github.com:openvswitch/ovs.git", "webscm_url": "https://github.com/openvswitch/ovs", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<1505708164-10270-4-git-send-email-roid@mellanox.com>", "list_archive_url": null, "date": "2017-09-18T04:16:03", "name": "[ovs-dev,V2,3/4] tc: Add header rewrite using tc pedit action", "commit_ref": null, "pull_url": null, "state": "changes-requested", "archived": false, "hash": "bb69562973dd8f1c125860609112cb14a574d0ba", "submitter": { "id": 70307, "url": "http://patchwork.ozlabs.org/api/1.2/people/70307/?format=api", "name": "Roi Dayan", "email": "roid@mellanox.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/openvswitch/patch/1505708164-10270-4-git-send-email-roid@mellanox.com/mbox/", "series": [ { "id": 3557, "url": "http://patchwork.ozlabs.org/api/1.2/series/3557/?format=api", "web_url": "http://patchwork.ozlabs.org/project/openvswitch/list/?series=3557", "date": "2017-09-18T04:16:00", "name": "Add offload support for action set", "version": 2, "mbox": "http://patchwork.ozlabs.org/series/3557/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/814769/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/814769/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<ovs-dev-bounces@openvswitch.org>", "X-Original-To": [ "incoming@patchwork.ozlabs.org", "dev@openvswitch.org" ], "Delivered-To": [ "patchwork-incoming@bilbo.ozlabs.org", "ovs-dev@mail.linuxfoundation.org" ], "Authentication-Results": "ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=openvswitch.org\n\t(client-ip=140.211.169.12; helo=mail.linuxfoundation.org;\n\tenvelope-from=ovs-dev-bounces@openvswitch.org;\n\treceiver=<UNKNOWN>)", "Received": [ "from mail.linuxfoundation.org (mail.linuxfoundation.org\n\t[140.211.169.12])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xwXnB61TJz9s7G\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 18 Sep 2017 14:18:38 +1000 (AEST)", "from mail.linux-foundation.org (localhost [127.0.0.1])\n\tby mail.linuxfoundation.org (Postfix) with ESMTP id BC4089FA;\n\tMon, 18 Sep 2017 04:16:23 +0000 (UTC)", "from smtp1.linuxfoundation.org (smtp1.linux-foundation.org\n\t[172.17.192.35])\n\tby mail.linuxfoundation.org (Postfix) with ESMTPS id B2A9C98A\n\tfor <dev@openvswitch.org>; Mon, 18 Sep 2017 04:16:18 +0000 (UTC)", "from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129])\n\tby smtp1.linuxfoundation.org (Postfix) with ESMTP id 47A2BF3\n\tfor <dev@openvswitch.org>; Mon, 18 Sep 2017 04:16:17 +0000 (UTC)", "from Internal Mail-Server by MTLPINE1 (envelope-from\n\troid@mellanox.com)\n\twith ESMTPS (AES256-SHA encrypted); 18 Sep 2017 07:16:11 +0300", "from dev-r-vrt-189.mtr.labs.mlnx (dev-r-vrt-189.mtr.labs.mlnx\n\t[10.212.189.1])\n\tby labmailer.mlnx (8.13.8/8.13.8) with ESMTP id v8I4GBDT001186;\n\tMon, 18 Sep 2017 07:16:11 +0300" ], "X-Greylist": "domain auto-whitelisted by SQLgrey-1.7.6", "From": "Roi Dayan <roid@mellanox.com>", "To": "dev@openvswitch.org", "Date": "Mon, 18 Sep 2017 07:16:03 +0300", "Message-Id": "<1505708164-10270-4-git-send-email-roid@mellanox.com>", "X-Mailer": "git-send-email 2.7.5", "In-Reply-To": "<1505708164-10270-1-git-send-email-roid@mellanox.com>", "References": "<1505708164-10270-1-git-send-email-roid@mellanox.com>", "X-Spam-Status": "No, score=0.0 required=5.0 tests=RP_MATCHES_RCVD,\n\tUNPARSEABLE_RELAY autolearn=disabled version=3.3.1", "X-Spam-Checker-Version": "SpamAssassin 3.3.1 (2010-03-16) on\n\tsmtp1.linux-foundation.org", "Cc": "Simon Horman <simon.horman@netronome.com>", "Subject": "[ovs-dev] [PATCH V2 3/4] tc: Add header rewrite using tc pedit\n\taction", "X-BeenThere": "ovs-dev@openvswitch.org", "X-Mailman-Version": "2.1.12", "Precedence": "list", "List-Id": "<ovs-dev.openvswitch.org>", "List-Unsubscribe": "<https://mail.openvswitch.org/mailman/options/ovs-dev>,\n\t<mailto:ovs-dev-request@openvswitch.org?subject=unsubscribe>", "List-Archive": "<http://mail.openvswitch.org/pipermail/ovs-dev/>", "List-Post": "<mailto:ovs-dev@openvswitch.org>", "List-Help": "<mailto:ovs-dev-request@openvswitch.org?subject=help>", "List-Subscribe": "<https://mail.openvswitch.org/mailman/listinfo/ovs-dev>,\n\t<mailto:ovs-dev-request@openvswitch.org?subject=subscribe>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Sender": "ovs-dev-bounces@openvswitch.org", "Errors-To": "ovs-dev-bounces@openvswitch.org" }, "content": "From: Paul Blakey <paulb@mellanox.com>\n\nTo be later used to implement ovs action set offloading.\n\nSigned-off-by: Paul Blakey <paulb@mellanox.com>\nReviewed-by: Roi Dayan <roid@mellanox.com>\n---\n lib/tc.c | 372 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n lib/tc.h | 16 +++\n 2 files changed, 385 insertions(+), 3 deletions(-)", "diff": "diff --git a/lib/tc.c b/lib/tc.c\nindex c9cada2..743b2ee 100644\n--- a/lib/tc.c\n+++ b/lib/tc.c\n@@ -21,8 +21,10 @@\n #include <errno.h>\n #include <linux/if_ether.h>\n #include <linux/rtnetlink.h>\n+#include <linux/tc_act/tc_csum.h>\n #include <linux/tc_act/tc_gact.h>\n #include <linux/tc_act/tc_mirred.h>\n+#include <linux/tc_act/tc_pedit.h>\n #include <linux/tc_act/tc_tunnel_key.h>\n #include <linux/tc_act/tc_vlan.h>\n #include <linux/gen_stats.h>\n@@ -33,11 +35,14 @@\n #include \"netlink-socket.h\"\n #include \"netlink.h\"\n #include \"openvswitch/ofpbuf.h\"\n+#include \"openvswitch/util.h\"\n #include \"openvswitch/vlog.h\"\n #include \"packets.h\"\n #include \"timeval.h\"\n #include \"unaligned.h\"\n \n+#define MAX_PEDIT_OFFSETS 8\n+\n VLOG_DEFINE_THIS_MODULE(tc);\n \n static struct vlog_rate_limit error_rl = VLOG_RATE_LIMIT_INIT(60, 5);\n@@ -50,6 +55,82 @@ enum tc_offload_policy {\n \n static enum tc_offload_policy tc_policy = TC_POLICY_NONE;\n \n+struct tc_pedit_key_ex {\n+ enum pedit_header_type htype;\n+ enum pedit_cmd cmd;\n+};\n+\n+struct flower_key_to_pedit {\n+ enum pedit_header_type htype;\n+ int flower_offset;\n+ int offset;\n+ int size;\n+};\n+\n+static struct flower_key_to_pedit flower_pedit_map[] = {\n+ {\n+ TCA_PEDIT_KEY_EX_HDR_TYPE_IP4,\n+ 12,\n+ offsetof(struct tc_flower_key, ipv4.ipv4_src),\n+ MEMBER_SIZEOF(struct tc_flower_key, ipv4.ipv4_src)\n+ }, {\n+ TCA_PEDIT_KEY_EX_HDR_TYPE_IP4,\n+ 16,\n+ offsetof(struct tc_flower_key, ipv4.ipv4_dst),\n+ MEMBER_SIZEOF(struct tc_flower_key, ipv4.ipv4_dst)\n+ }, {\n+ TCA_PEDIT_KEY_EX_HDR_TYPE_IP4,\n+ 8,\n+ offsetof(struct tc_flower_key, ipv4.rewrite_ttl),\n+ MEMBER_SIZEOF(struct tc_flower_key, ipv4.rewrite_ttl)\n+ }, {\n+ TCA_PEDIT_KEY_EX_HDR_TYPE_IP6,\n+ 8,\n+ offsetof(struct tc_flower_key, ipv6.ipv6_src),\n+ MEMBER_SIZEOF(struct tc_flower_key, ipv6.ipv6_src)\n+ }, {\n+ TCA_PEDIT_KEY_EX_HDR_TYPE_IP6,\n+ 24,\n+ offsetof(struct tc_flower_key, ipv6.ipv6_dst),\n+ MEMBER_SIZEOF(struct tc_flower_key, ipv6.ipv6_dst)\n+ }, {\n+ TCA_PEDIT_KEY_EX_HDR_TYPE_ETH,\n+ 6,\n+ offsetof(struct tc_flower_key, src_mac),\n+ MEMBER_SIZEOF(struct tc_flower_key, src_mac)\n+ }, {\n+ TCA_PEDIT_KEY_EX_HDR_TYPE_ETH,\n+ 0,\n+ offsetof(struct tc_flower_key, dst_mac),\n+ MEMBER_SIZEOF(struct tc_flower_key, dst_mac)\n+ }, {\n+ TCA_PEDIT_KEY_EX_HDR_TYPE_ETH,\n+ 12,\n+ offsetof(struct tc_flower_key, eth_type),\n+ MEMBER_SIZEOF(struct tc_flower_key, eth_type)\n+ }, {\n+ TCA_PEDIT_KEY_EX_HDR_TYPE_TCP,\n+ 0,\n+ offsetof(struct tc_flower_key, tcp_src),\n+ MEMBER_SIZEOF(struct tc_flower_key, tcp_src)\n+ }, {\n+ TCA_PEDIT_KEY_EX_HDR_TYPE_TCP,\n+ 2,\n+ offsetof(struct tc_flower_key, tcp_dst),\n+ MEMBER_SIZEOF(struct tc_flower_key, tcp_dst)\n+ }, {\n+ TCA_PEDIT_KEY_EX_HDR_TYPE_UDP,\n+ 0,\n+ offsetof(struct tc_flower_key, udp_src),\n+ MEMBER_SIZEOF(struct tc_flower_key, udp_src)\n+ }, {\n+ TCA_PEDIT_KEY_EX_HDR_TYPE_UDP,\n+ 2,\n+ offsetof(struct tc_flower_key, udp_dst),\n+ MEMBER_SIZEOF(struct tc_flower_key, udp_dst)\n+ },\n+};\n+\n struct tcmsg *\n tc_make_request(int ifindex, int type, unsigned int flags,\n struct ofpbuf *request)\n@@ -365,6 +446,96 @@ nl_parse_flower_ip(struct nlattr **attrs, struct tc_flower *flower) {\n }\n }\n \n+static const struct nl_policy pedit_policy[] = {\n+ [TCA_PEDIT_PARMS_EX] = { .type = NL_A_UNSPEC,\n+ .min_len = sizeof(struct tc_pedit),\n+ .optional = false, },\n+ [TCA_PEDIT_KEYS_EX] = { .type = NL_A_NESTED,\n+ .optional = false, },\n+};\n+\n+static int\n+nl_parse_act_pedit(struct nlattr *options, struct tc_flower *flower)\n+{\n+ struct nlattr *pe_attrs[ARRAY_SIZE(pedit_policy)];\n+ const struct tc_pedit *pe;\n+ const struct tc_pedit_key *keys;\n+ const struct nlattr *nla, *keys_ex, *ex_type;\n+ const void *keys_attr;\n+ char *rewrite_key = (void *) &flower->rewrite.key;\n+ char *rewrite_mask = (void *) &flower->rewrite.mask;\n+ size_t keys_ex_size, left;\n+ int type, i = 0;\n+\n+ if (!nl_parse_nested(options, pedit_policy, pe_attrs,\n+ ARRAY_SIZE(pedit_policy))) {\n+ VLOG_ERR_RL(&error_rl, \"failed to parse pedit action options\");\n+ return EPROTO;\n+ }\n+\n+ pe = nl_attr_get_unspec(pe_attrs[TCA_PEDIT_PARMS_EX], sizeof *pe);\n+ keys = pe->keys;\n+ keys_attr = pe_attrs[TCA_PEDIT_KEYS_EX];\n+ keys_ex = nl_attr_get(keys_attr);\n+ keys_ex_size = nl_attr_get_size(keys_attr);\n+\n+ NL_ATTR_FOR_EACH (nla, left, keys_ex, keys_ex_size) {\n+ if (i >= pe->nkeys) {\n+ break;\n+ }\n+\n+ if (nl_attr_type(nla) == TCA_PEDIT_KEY_EX) {\n+ ex_type = nl_attr_find_nested(nla, TCA_PEDIT_KEY_EX_HTYPE);\n+ type = nl_attr_get_u16(ex_type);\n+\n+ for (int j = 0; j < ARRAY_SIZE(flower_pedit_map); j++) {\n+ struct flower_key_to_pedit *m = &flower_pedit_map[j];\n+ int flower_off = m->flower_offset;\n+ int sz = m->size;\n+ int mf = m->offset;\n+\n+ if (m->htype != type) {\n+ continue;\n+ }\n+\n+ /* check overlap between current pedit key, which is always\n+ * 4 bytes (range [off, off + 3]), and a map entry in\n+ * flower_pedit_map (range [mf, mf + sz - 1]) */\n+ if ((keys->off >= mf && keys->off < mf + sz)\n+ || (keys->off + 3 >= mf && keys->off + 3 < mf + sz)) {\n+ int diff = flower_off + (keys->off - mf);\n+ uint32_t *dst = (void *) (rewrite_key + diff);\n+ uint32_t *dst_m = (void *) (rewrite_mask + diff);\n+ uint32_t mask = ~(keys->mask);\n+ uint32_t zero_bits;\n+\n+ if (keys->off < mf) {\n+ zero_bits = 8 * (mf - keys->off);\n+ mask &= UINT32_MAX << zero_bits;\n+ } else if (keys->off + 4 > mf + m->size) {\n+ zero_bits = 8 * (keys->off + 4 - mf - m->size);\n+ mask &= UINT32_MAX >> zero_bits;\n+ }\n+\n+ *dst_m |= mask;\n+ *dst |= keys->val & mask;\n+ }\n+ }\n+ } else {\n+ VLOG_ERR_RL(&error_rl, \"unable to parse legacy pedit type: %d\",\n+ nl_attr_type(nla));\n+ return EOPNOTSUPP;\n+ }\n+\n+ keys++;\n+ i++;\n+ }\n+\n+ flower->rewrite.rewrite = true;\n+\n+ return 0;\n+}\n+\n static const struct nl_policy tunnel_key_policy[] = {\n [TCA_TUNNEL_KEY_PARMS] = { .type = NL_A_UNSPEC,\n .min_len = sizeof(struct tc_tunnel_key),\n@@ -608,6 +779,11 @@ nl_parse_single_action(struct nlattr *action, struct tc_flower *flower)\n nl_parse_act_vlan(act_options, flower);\n } else if (!strcmp(act_kind, \"tunnel_key\")) {\n nl_parse_act_tunnel_key(act_options, flower);\n+ } else if (!strcmp(act_kind, \"pedit\")) {\n+ nl_parse_act_pedit(act_options, flower);\n+ } else if (!strcmp(act_kind, \"csum\")) {\n+ /* not doing anything for now, ovs has an implicit csum recalculation\n+ * with rewriting of packet headers (translating of pedit acts). */\n } else {\n VLOG_ERR_RL(&error_rl, \"unknown tc action kind: %s\", act_kind);\n return EINVAL;\n@@ -809,6 +985,48 @@ tc_get_tc_cls_policy(enum tc_offload_policy policy)\n }\n \n static void\n+nl_msg_put_act_csum(struct ofpbuf *request, uint32_t flags)\n+{\n+ size_t offset;\n+\n+ nl_msg_put_string(request, TCA_ACT_KIND, \"csum\");\n+ offset = nl_msg_start_nested(request, TCA_ACT_OPTIONS);\n+ {\n+ struct tc_csum parm = { .action = TC_ACT_PIPE,\n+ .update_flags = flags };\n+\n+ nl_msg_put_unspec(request, TCA_CSUM_PARMS, &parm, sizeof parm);\n+ }\n+ nl_msg_end_nested(request, offset);\n+}\n+\n+static void\n+nl_msg_put_act_pedit(struct ofpbuf *request, struct tc_pedit *parm,\n+ struct tc_pedit_key_ex *ex)\n+{\n+ size_t ksize = sizeof *parm + (parm->nkeys * sizeof(struct tc_pedit_key));\n+ size_t offset, offset_keys_ex, offset_key;\n+ int i;\n+\n+ nl_msg_put_string(request, TCA_ACT_KIND, \"pedit\");\n+ offset = nl_msg_start_nested(request, TCA_ACT_OPTIONS);\n+ {\n+ parm->action = TC_ACT_PIPE;\n+\n+ nl_msg_put_unspec(request, TCA_PEDIT_PARMS_EX, parm, ksize);\n+ offset_keys_ex = nl_msg_start_nested(request, TCA_PEDIT_KEYS_EX);\n+ for (i = 0; i < parm->nkeys; i++, ex++) {\n+ offset_key = nl_msg_start_nested(request, TCA_PEDIT_KEY_EX);\n+ nl_msg_put_u16(request, TCA_PEDIT_KEY_EX_HTYPE, ex->htype);\n+ nl_msg_put_u16(request, TCA_PEDIT_KEY_EX_CMD, ex->cmd);\n+ nl_msg_end_nested(request, offset_key);\n+ }\n+ nl_msg_end_nested(request, offset_keys_ex);\n+ }\n+ nl_msg_end_nested(request, offset);\n+}\n+\n+static void\n nl_msg_put_act_push_vlan(struct ofpbuf *request, uint16_t vid, uint8_t prio)\n {\n size_t offset;\n@@ -930,7 +1148,127 @@ nl_msg_put_act_cookie(struct ofpbuf *request, struct tc_cookie *ck) {\n }\n }\n \n+/* Given flower, a key_to_pedit map entry, calculates the rest,\n+ * where:\n+ *\n+ * mask, data - pointers of where read the first word of flower->key/mask.\n+ * current_offset - which offset to use for the first pedit action.\n+ * cnt - max pedits actions to use.\n+ * first_word_mask/last_word_mask - the mask to use for the first/last read\n+ * (as we read entire words). */\n static void\n+calc_offsets(struct tc_flower *flower, struct flower_key_to_pedit *m,\n+ int *cur_offset, int *cnt, uint32_t *last_word_mask,\n+ uint32_t *first_word_mask, uint32_t **mask, uint32_t **data)\n+{\n+ int start_offset, max_offset, total_size;\n+ int diff, right_zero_bits, left_zero_bits;\n+ char *rewrite_key = (void *) &flower->rewrite.key;\n+ char *rewrite_mask = (void *) &flower->rewrite.mask;\n+\n+ max_offset = m->offset + m->size;\n+ start_offset = ROUND_DOWN(m->offset, 4);\n+ diff = m->offset - start_offset;\n+ total_size = max_offset - start_offset;\n+ right_zero_bits = 8 * (4 - (max_offset % 4));\n+ left_zero_bits = 8 * (m->offset - start_offset);\n+\n+ *cur_offset = start_offset;\n+ *cnt = (total_size / 4) + (total_size % 4 ? 1 : 0);\n+ *last_word_mask = UINT32_MAX >> right_zero_bits;\n+ *first_word_mask = UINT32_MAX << left_zero_bits;\n+ *data = (void *) (rewrite_key + m->flower_offset - diff);\n+ *mask = (void *) (rewrite_mask + m->flower_offset - diff);\n+}\n+\n+static inline void\n+csum_update_flag(struct tc_flower *flower,\n+ enum pedit_header_type htype) {\n+ if (htype == TCA_PEDIT_KEY_EX_HDR_TYPE_IP4) {\n+ flower->csum_update_flags |= TCA_CSUM_UPDATE_FLAG_IPV4HDR;\n+ }\n+ if (htype == TCA_PEDIT_KEY_EX_HDR_TYPE_IP4\n+ || htype == TCA_PEDIT_KEY_EX_HDR_TYPE_IP6\n+ || htype == TCA_PEDIT_KEY_EX_HDR_TYPE_TCP\n+ || htype == TCA_PEDIT_KEY_EX_HDR_TYPE_UDP) {\n+ if (flower->key.ip_proto == IPPROTO_TCP) {\n+ flower->mask.ip_proto = UINT8_MAX;\n+ flower->csum_update_flags |= TCA_CSUM_UPDATE_FLAG_TCP;\n+ } else if (flower->key.ip_proto == IPPROTO_UDP) {\n+ flower->mask.ip_proto = UINT8_MAX;\n+ flower->csum_update_flags |= TCA_CSUM_UPDATE_FLAG_UDP;\n+ } else if (flower->key.ip_proto == IPPROTO_ICMP\n+ || flower->key.ip_proto == IPPROTO_ICMPV6) {\n+ flower->mask.ip_proto = UINT8_MAX;\n+ flower->csum_update_flags |= TCA_CSUM_UPDATE_FLAG_ICMP;\n+ }\n+ }\n+}\n+\n+static int\n+nl_msg_put_flower_rewrite_pedits(struct ofpbuf *request,\n+ struct tc_flower *flower)\n+{\n+ struct {\n+ struct tc_pedit sel;\n+ struct tc_pedit_key keys[MAX_PEDIT_OFFSETS];\n+ struct tc_pedit_key_ex keys_ex[MAX_PEDIT_OFFSETS];\n+ } sel = {\n+ .sel = {\n+ .nkeys = 0\n+ }\n+ };\n+ int i, j;\n+\n+ for (i = 0; i < ARRAY_SIZE(flower_pedit_map); i++) {\n+ struct flower_key_to_pedit *m = &flower_pedit_map[i];\n+ struct tc_pedit_key *pedit_key = NULL;\n+ struct tc_pedit_key_ex *pedit_key_ex = NULL;\n+ uint32_t *mask, *data, first_word_mask, last_word_mask;\n+ int cnt = 0, cur_offset = 0;\n+\n+ if (!m->size) {\n+ continue;\n+ }\n+\n+ calc_offsets(flower, m, &cur_offset, &cnt, &last_word_mask,\n+ &first_word_mask, &mask, &data);\n+\n+ for (j = 0; j < cnt; j++, mask++, data++, cur_offset += 4) {\n+ uint32_t mask_word = *mask;\n+\n+ if (j == 0) {\n+ mask_word &= first_word_mask;\n+ }\n+ if (j == cnt - 1) {\n+ mask_word &= last_word_mask;\n+ }\n+ if (!mask_word) {\n+ continue;\n+ }\n+ if (sel.sel.nkeys == MAX_PEDIT_OFFSETS) {\n+ VLOG_WARN_RL(&error_rl, \"reached too many pedit offsets: %d\",\n+ MAX_PEDIT_OFFSETS);\n+ return EOPNOTSUPP;\n+ }\n+\n+ pedit_key = &sel.keys[sel.sel.nkeys];\n+ pedit_key_ex = &sel.keys_ex[sel.sel.nkeys];\n+ pedit_key_ex->cmd = TCA_PEDIT_KEY_EX_CMD_SET;\n+ pedit_key_ex->htype = m->htype;\n+ pedit_key->off = cur_offset;\n+ pedit_key->mask = ~mask_word;\n+ pedit_key->val = *data & mask_word;\n+ sel.sel.nkeys++;\n+ csum_update_flag(flower, m->htype);\n+ }\n+ }\n+ nl_msg_put_act_pedit(request, &sel.sel, sel.keys_ex);\n+\n+ return 0;\n+}\n+\n+static int\n nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower)\n {\n size_t offset;\n@@ -939,7 +1277,20 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower)\n offset = nl_msg_start_nested(request, TCA_FLOWER_ACT);\n {\n uint16_t act_index = 1;\n+ int error;\n \n+ if (flower->rewrite.rewrite) {\n+ act_offset = nl_msg_start_nested(request, act_index++);\n+ error = nl_msg_put_flower_rewrite_pedits(request, flower);\n+ if (error) {\n+ return error;\n+ }\n+ nl_msg_end_nested(request, act_offset);\n+\n+ act_offset = nl_msg_start_nested(request, act_index++);\n+ nl_msg_put_act_csum(request, flower->csum_update_flags);\n+ nl_msg_end_nested(request, act_offset);\n+ }\n if (flower->set.set) {\n act_offset = nl_msg_start_nested(request, act_index++);\n nl_msg_put_act_tunnel_key_set(request, flower->set.id,\n@@ -980,6 +1331,8 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower)\n }\n }\n nl_msg_end_nested(request, offset);\n+\n+ return 0;\n }\n \n static void\n@@ -1021,11 +1374,19 @@ nl_msg_put_flower_tunnel(struct ofpbuf *request, struct tc_flower *flower)\n nl_msg_put_masked_value(request, type, type##_MASK, &flower->key.member, \\\n &flower->mask.member, sizeof flower->key.member)\n \n-static void\n+static int\n nl_msg_put_flower_options(struct ofpbuf *request, struct tc_flower *flower)\n {\n+\n uint16_t host_eth_type = ntohs(flower->key.eth_type);\n bool is_vlan = (host_eth_type == ETH_TYPE_VLAN);\n+ int err;\n+\n+ /* need to parse acts first as some acts require changing the matching */\n+ err = nl_msg_put_flower_acts(request, flower);\n+ if (err) {\n+ return err;\n+ }\n \n if (is_vlan) {\n host_eth_type = ntohs(flower->key.encap_eth_type);\n@@ -1083,7 +1444,7 @@ nl_msg_put_flower_options(struct ofpbuf *request, struct tc_flower *flower)\n nl_msg_put_flower_tunnel(request, flower);\n }\n \n- nl_msg_put_flower_acts(request, flower);\n+ return 0;\n }\n \n int\n@@ -1106,7 +1467,12 @@ tc_replace_flower(int ifindex, uint16_t prio, uint32_t handle,\n nl_msg_put_string(&request, TCA_KIND, \"flower\");\n basic_offset = nl_msg_start_nested(&request, TCA_OPTIONS);\n {\n- nl_msg_put_flower_options(&request, flower);\n+ error = nl_msg_put_flower_options(&request, flower);\n+\n+ if (error) {\n+ ofpbuf_uninit(&request);\n+ return error;\n+ }\n }\n nl_msg_end_nested(&request, basic_offset);\n \ndiff --git a/lib/tc.h b/lib/tc.h\nindex 6c69b79..7876051 100644\n--- a/lib/tc.h\n+++ b/lib/tc.h\n@@ -96,6 +96,7 @@ struct tc_flower_key {\n struct {\n ovs_be32 ipv4_src;\n ovs_be32 ipv4_dst;\n+ uint8_t rewrite_ttl;\n } ipv4;\n struct {\n struct in6_addr ipv6_src;\n@@ -120,6 +121,14 @@ struct tc_flower {\n uint64_t lastused;\n \n struct {\n+ bool rewrite;\n+ struct tc_flower_key key;\n+ struct tc_flower_key mask;\n+ } rewrite;\n+\n+ uint32_t csum_update_flags;\n+\n+ struct {\n bool set;\n ovs_be64 id;\n ovs_be16 tp_src;\n@@ -152,6 +161,13 @@ struct tc_flower {\n struct tc_cookie act_cookie;\n };\n \n+/* assert that if we overflow with a masked write of uint32_t to the last byte\n+ * of flower.rewrite we overflow inside struct flower.\n+ * shouldn't happen unless someone moves rewrite to the end of flower */\n+BUILD_ASSERT_DECL(offsetof(struct tc_flower, rewrite)\n+ + MEMBER_SIZEOF(struct tc_flower, rewrite)\n+ + sizeof(uint32_t) - 2 < sizeof(struct tc_flower));\n+\n int tc_replace_flower(int ifindex, uint16_t prio, uint32_t handle,\n struct tc_flower *flower);\n int tc_del_filter(int ifindex, int prio, int handle);\n", "prefixes": [ "ovs-dev", "V2", "3/4" ] }