From patchwork Fri Jan 11 11:51:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter Jansen van Vuuren X-Patchwork-Id: 1023555 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=netronome.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=netronome-com.20150623.gappssmtp.com header.i=@netronome-com.20150623.gappssmtp.com header.b="cCo/waQZ"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43bhFs4RM7z9s4s for ; Fri, 11 Jan 2019 22:58:09 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 8CED31899; Fri, 11 Jan 2019 11:57:13 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id E5298165A for ; Fri, 11 Jan 2019 11:52:05 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id EE1A77C for ; Fri, 11 Jan 2019 11:52:04 +0000 (UTC) Received: by mail-wm1-f48.google.com with SMTP id g67so2099218wmd.2 for ; Fri, 11 Jan 2019 03:52:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netronome-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tImXUjXojrtfr13lwo7MEROWpbZkX/VQiOakB0i3kj4=; b=cCo/waQZ8eTxZbYEf7bAlYFf8R8gvm0JP6JdchZo1pBzJlBj2qFkfAuqqn5qU6Ovsa /T7EvOrAXZwfs1xKJ38Yyar1WjPDDM3xznhwRhlxRgOr9iKzAzy4C/0RCMpj8Xcqou91 YEMIxzQEjq5TvWDaXzRS3hah7kYY0CUlkdxlg6dHpL+MX+1gMiKecaNAzOFPfZ1y9Y4a nwsBukjVhTlU3TsZSD+1UuDKpOcBJhnheYKa1TXqKsNrFE2hk2uZHH43De/OUDt1DjKf mnFG6C5yFcRp97L6ZAmMDo58NOl1Hz8sjHc5IK/h8qzBe/TgyWSYfEjVSMDt/LeFpJqD /CXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tImXUjXojrtfr13lwo7MEROWpbZkX/VQiOakB0i3kj4=; b=anKDYLMgWxRLJQJtgaBXiGjSbxLyV6GNgqtXTaz5PSERm0EpiNdAVSAssgh6HwD1AB zlExe5CJHwqzsEZ+lUT0FdJEecdochdKseXnUSMkQNKGycaJZ41ewOFslcHPJc07qfQx /At1sLhv+i6L46HegDuiPtVWZSZoUGx541Floy8XzerBYy7qRwNKiRBpk2x6tXB5jyWn PAn6nhGozjteSW5BIWA0xhkkyf7Qx5M2++rMsy51atfuNnKkMe5iAF2ZOMMxWuRJcSSY 4WDuUh4CxOYFTztdfk6SgH1EHGKv0isiLVsrYID4DIh9c9BqxFFtz9OhBzcGIxrQz0XU MH6Q== X-Gm-Message-State: AJcUukf6aD5K6r2IReWsZVXfMNV+0MSWbiATI3J4fr2d578Fgm0l5mm2 0qIeYLlxaPEIQbqGM9zBEwROKeXsJuM= X-Google-Smtp-Source: ALg8bN4FEzKlx6DsijtpY326aYWV0ZXaK48ThEiPtMHp4dV1wSrCFMU3rxf3uo4bQjGYAbA1hp9Jkg== X-Received: by 2002:a1c:9c0a:: with SMTP id f10mr2040320wme.73.1547207523181; Fri, 11 Jan 2019 03:52:03 -0800 (PST) Received: from pieter-Netronome.netronome.com (host81-150-168-85.in-addr.btopenworld.com. [81.150.168.85]) by smtp.gmail.com with ESMTPSA id p12sm24056801wmi.5.2019.01.11.03.52.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Jan 2019 03:52:02 -0800 (PST) From: Pieter Jansen van Vuuren To: dev@openvswitch.org Date: Fri, 11 Jan 2019 11:51:53 +0000 Message-Id: <1547207513-22802-3-git-send-email-pieter.jansenvanvuuren@netronome.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1547207513-22802-1-git-send-email-pieter.jansenvanvuuren@netronome.com> References: <1547207513-22802-1-git-send-email-pieter.jansenvanvuuren@netronome.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Pieter Jansen van Vuuren , Louis Peens Subject: [ovs-dev] [RFC 2/2] lib/tc: add set ipv6 traffic class action offload via pedit X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Extend ovs-tc translation by allowing non-byte-aligned fields for set actions. Use new boundary shifts and add set ipv6 traffic class action offload via pedit. Signed-off-by: Pieter Jansen van Vuuren Signed-off-by: Louis Peens Reviewed-by: Simon Horman --- lib/byte-order.h | 18 ++++++++++++ lib/netdev-tc-offloads.c | 4 +++ lib/tc.c | 63 ++++++++++++++++++++++++++++------------ lib/tc.h | 1 + 4 files changed, 68 insertions(+), 18 deletions(-) diff --git a/lib/byte-order.h b/lib/byte-order.h index 66d29a2b3..7bbadb24e 100644 --- a/lib/byte-order.h +++ b/lib/byte-order.h @@ -116,6 +116,24 @@ bytes_to_be32(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3) return (OVS_FORCE ovs_be32) x; } +/* These functions specifically help shifting words in network + * byte order, given that they are specified in host order. */ +static inline uint32_t +shift_ovs_be32_left(uint32_t word, int shift) +{ + uint32_t word_shifted = (OVS_FORCE uint32_t)htonl(word) << shift; + + return ntohl((OVS_FORCE ovs_be32)word_shifted); +} + +static inline uint32_t +shift_ovs_be32_right(uint32_t word, int shift) +{ + uint32_t word_shifted = (OVS_FORCE uint32_t)htonl(word) >> shift; + + return ntohl((OVS_FORCE ovs_be32)word_shifted); +} + /* These functions zero-extend big-endian values to longer ones, * or truncate long big-endian value to shorter ones. */ #ifndef __CHECKER__ diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c index 90bd3c585..1c5bd22e4 100644 --- a/lib/netdev-tc-offloads.c +++ b/lib/netdev-tc-offloads.c @@ -84,6 +84,10 @@ static struct netlink_field set_flower_map[][4] = { offsetof(struct tc_flower_key, ipv6.rewrite_hlimit), MEMBER_SIZEOF(struct tc_flower_key, ipv6.rewrite_hlimit) }, + { offsetof(struct ovs_key_ipv6, ipv6_tclass), + offsetof(struct tc_flower_key, ipv6.rewrite_tclass), + MEMBER_SIZEOF(struct tc_flower_key, ipv6.rewrite_tclass) + }, }, [OVS_KEY_ATTR_ETHERNET] = { { offsetof(struct ovs_key_ethernet, eth_src), diff --git a/lib/tc.c b/lib/tc.c index 1696c9836..f93814fa3 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -73,6 +73,7 @@ struct flower_key_to_pedit { int offset; int flower_offset; int size; + int boundary_shift; }; static struct flower_key_to_pedit flower_pedit_map[] = { @@ -80,72 +81,92 @@ static struct flower_key_to_pedit flower_pedit_map[] = { TCA_PEDIT_KEY_EX_HDR_TYPE_IP4, 12, offsetof(struct tc_flower_key, ipv4.ipv4_src), - MEMBER_SIZEOF(struct tc_flower_key, ipv4.ipv4_src) + MEMBER_SIZEOF(struct tc_flower_key, ipv4.ipv4_src), + 0 }, { TCA_PEDIT_KEY_EX_HDR_TYPE_IP4, 16, offsetof(struct tc_flower_key, ipv4.ipv4_dst), - MEMBER_SIZEOF(struct tc_flower_key, ipv4.ipv4_dst) + MEMBER_SIZEOF(struct tc_flower_key, ipv4.ipv4_dst), + 0 }, { TCA_PEDIT_KEY_EX_HDR_TYPE_IP4, 8, offsetof(struct tc_flower_key, ipv4.rewrite_ttl), - MEMBER_SIZEOF(struct tc_flower_key, ipv4.rewrite_ttl) + MEMBER_SIZEOF(struct tc_flower_key, ipv4.rewrite_ttl), + 0 }, { TCA_PEDIT_KEY_EX_HDR_TYPE_IP4, 1, offsetof(struct tc_flower_key, ipv4.rewrite_tos), - MEMBER_SIZEOF(struct tc_flower_key, ipv4.rewrite_tos) + MEMBER_SIZEOF(struct tc_flower_key, ipv4.rewrite_tos), + 0 }, { TCA_PEDIT_KEY_EX_HDR_TYPE_IP6, 7, offsetof(struct tc_flower_key, ipv6.rewrite_hlimit), - MEMBER_SIZEOF(struct tc_flower_key, ipv6.rewrite_hlimit) + MEMBER_SIZEOF(struct tc_flower_key, ipv6.rewrite_hlimit), + 0 }, { TCA_PEDIT_KEY_EX_HDR_TYPE_IP6, 8, offsetof(struct tc_flower_key, ipv6.ipv6_src), - MEMBER_SIZEOF(struct tc_flower_key, ipv6.ipv6_src) + MEMBER_SIZEOF(struct tc_flower_key, ipv6.ipv6_src), + 0 }, { TCA_PEDIT_KEY_EX_HDR_TYPE_IP6, 24, offsetof(struct tc_flower_key, ipv6.ipv6_dst), - MEMBER_SIZEOF(struct tc_flower_key, ipv6.ipv6_dst) + MEMBER_SIZEOF(struct tc_flower_key, ipv6.ipv6_dst), + 0 + }, { + TCA_PEDIT_KEY_EX_HDR_TYPE_IP6, + 0, + offsetof(struct tc_flower_key, ipv6.rewrite_tclass), + MEMBER_SIZEOF(struct tc_flower_key, ipv6.rewrite_tclass), + 4 }, { TCA_PEDIT_KEY_EX_HDR_TYPE_ETH, 6, offsetof(struct tc_flower_key, src_mac), - MEMBER_SIZEOF(struct tc_flower_key, src_mac) + MEMBER_SIZEOF(struct tc_flower_key, src_mac), + 0 }, { TCA_PEDIT_KEY_EX_HDR_TYPE_ETH, 0, offsetof(struct tc_flower_key, dst_mac), - MEMBER_SIZEOF(struct tc_flower_key, dst_mac) + MEMBER_SIZEOF(struct tc_flower_key, dst_mac), + 0 }, { TCA_PEDIT_KEY_EX_HDR_TYPE_ETH, 12, offsetof(struct tc_flower_key, eth_type), - MEMBER_SIZEOF(struct tc_flower_key, eth_type) + MEMBER_SIZEOF(struct tc_flower_key, eth_type), + 0 }, { TCA_PEDIT_KEY_EX_HDR_TYPE_TCP, 0, offsetof(struct tc_flower_key, tcp_src), - MEMBER_SIZEOF(struct tc_flower_key, tcp_src) + MEMBER_SIZEOF(struct tc_flower_key, tcp_src), + 0 }, { TCA_PEDIT_KEY_EX_HDR_TYPE_TCP, 2, offsetof(struct tc_flower_key, tcp_dst), - MEMBER_SIZEOF(struct tc_flower_key, tcp_dst) + MEMBER_SIZEOF(struct tc_flower_key, tcp_dst), + 0 }, { TCA_PEDIT_KEY_EX_HDR_TYPE_UDP, 0, offsetof(struct tc_flower_key, udp_src), - MEMBER_SIZEOF(struct tc_flower_key, udp_src) + MEMBER_SIZEOF(struct tc_flower_key, udp_src), + 0 }, { TCA_PEDIT_KEY_EX_HDR_TYPE_UDP, 2, offsetof(struct tc_flower_key, udp_dst), - MEMBER_SIZEOF(struct tc_flower_key, udp_dst) + MEMBER_SIZEOF(struct tc_flower_key, udp_dst), + 0 }, }; @@ -832,8 +853,11 @@ nl_parse_act_pedit(struct nlattr *options, struct tc_flower *flower) int diff = flower_off + (keys->off - mf); uint32_t *dst = (void *) (rewrite_key + diff); uint32_t *dst_m = (void *) (rewrite_mask + diff); - uint32_t mask = ~(keys->mask); - uint32_t zero_bits; + uint32_t mask_word, data_word, mask, zero_bits; + + mask_word = shift_ovs_be32_left(keys->mask, m->boundary_shift); + data_word = shift_ovs_be32_left(keys->val, m->boundary_shift); + mask = ~(mask_word); if (keys->off < mf) { zero_bits = 8 * (mf - keys->off); @@ -844,7 +868,7 @@ nl_parse_act_pedit(struct nlattr *options, struct tc_flower *flower) } *dst_m |= mask; - *dst |= keys->val & mask; + *dst |= data_word & mask; } } @@ -1832,6 +1856,7 @@ nl_msg_put_flower_rewrite_pedits(struct ofpbuf *request, for (j = 0; j < cnt; j++, mask++, data++, cur_offset += 4) { uint32_t mask_word = *mask; + uint32_t data_word = *data; if (j == 0) { mask_word &= first_word_mask; @@ -1853,8 +1878,10 @@ nl_msg_put_flower_rewrite_pedits(struct ofpbuf *request, pedit_key_ex->cmd = TCA_PEDIT_KEY_EX_CMD_SET; pedit_key_ex->htype = m->htype; pedit_key->off = cur_offset; + mask_word = shift_ovs_be32_right(mask_word, m->boundary_shift); + data_word = shift_ovs_be32_right(data_word, m->boundary_shift); pedit_key->mask = ~mask_word; - pedit_key->val = *data & mask_word; + pedit_key->val = data_word & mask_word; sel.sel.nkeys++; err = csum_update_flag(flower, m->htype); diff --git a/lib/tc.h b/lib/tc.h index 04b08e298..6c909df21 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -109,6 +109,7 @@ struct tc_flower_key { struct in6_addr ipv6_src; struct in6_addr ipv6_dst; uint8_t rewrite_hlimit; + uint8_t rewrite_tclass; } ipv6; struct {