From patchwork Tue Jul 31 10:40:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Or Gerlitz X-Patchwork-Id: 951540 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=fail (p=none dis=none) header.from=mellanox.com 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 41ftJJ4Fkbz9ryn for ; Tue, 31 Jul 2018 20:40:47 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 7C42ACC0; Tue, 31 Jul 2018 10:40:44 +0000 (UTC) X-Original-To: ovs-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 DA4F5CB7 for ; Tue, 31 Jul 2018 10:40:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id E28C4789 for ; Tue, 31 Jul 2018 10:40:42 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from ogerlitz@mellanox.com) with ESMTPS (AES256-SHA encrypted); 31 Jul 2018 13:44:02 +0300 Received: from r-vnc05.mtr.labs.mlnx (r-vnc05.mtr.labs.mlnx [10.208.0.115]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w6VAeeV1002811; Tue, 31 Jul 2018 13:40:40 +0300 From: Or Gerlitz To: ovs-dev@openvswitch.org Date: Tue, 31 Jul 2018 13:40:36 +0300 Message-Id: <1533033639-13009-2-git-send-email-ogerlitz@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1533033639-13009-1-git-send-email-ogerlitz@mellanox.com> References: <1533033639-13009-1-git-send-email-ogerlitz@mellanox.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Simon Horman , Or Gerlitz , Or Gerlitz Subject: [ovs-dev] [PATCH V2 1/4] lib/tc: Handle ttl for ipv6 too 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 TTL can and should be used to match on IPv6's hop-limit, fix that. Fixes: ab7ecf266b0a ('netdev-tc-offloads: Add nw_ttl matching using flower') Fixes: 0b4b5203d12e ('tc: Add ip layer ttl matching') Signed-off-by: Or Gerlitz Reviewed-by: Roi Dayan --- lib/netdev-tc-offloads.c | 4 ++-- lib/tc.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c index 04548c7..2a6dd6d 100644 --- a/lib/netdev-tc-offloads.c +++ b/lib/netdev-tc-offloads.c @@ -1025,8 +1025,10 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, if (is_ip_any(key)) { flower.key.ip_proto = key->nw_proto; flower.mask.ip_proto = mask->nw_proto; + mask->nw_proto = 0; flower.key.ip_ttl = key->nw_ttl; flower.mask.ip_ttl = mask->nw_ttl; + mask->nw_ttl = 0; if (mask->nw_frag & FLOW_NW_FRAG_ANY) { flower.mask.flags |= TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT; @@ -1073,8 +1075,6 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, } mask->nw_tos = 0; - mask->nw_proto = 0; - mask->nw_ttl = 0; if (key->dl_type == htons(ETH_P_IP)) { flower.key.ipv4.ipv4_src = key->nw_src; diff --git a/lib/tc.c b/lib/tc.c index 22c76b6..791f285 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -1625,6 +1625,8 @@ nl_msg_put_flower_options(struct ofpbuf *request, struct tc_flower *flower) FLOWER_PUT_MASKED_VALUE(src_mac, TCA_FLOWER_KEY_ETH_SRC); if (host_eth_type == ETH_P_IP || host_eth_type == ETH_P_IPV6) { + FLOWER_PUT_MASKED_VALUE(ip_ttl, TCA_FLOWER_KEY_IP_TTL); + if (flower->mask.ip_proto && flower->key.ip_proto) { nl_msg_put_u8(request, TCA_FLOWER_KEY_IP_PROTO, flower->key.ip_proto); @@ -1653,7 +1655,6 @@ nl_msg_put_flower_options(struct ofpbuf *request, struct tc_flower *flower) if (host_eth_type == ETH_P_IP) { FLOWER_PUT_MASKED_VALUE(ipv4.ipv4_src, TCA_FLOWER_KEY_IPV4_SRC); FLOWER_PUT_MASKED_VALUE(ipv4.ipv4_dst, TCA_FLOWER_KEY_IPV4_DST); - FLOWER_PUT_MASKED_VALUE(ip_ttl, TCA_FLOWER_KEY_IP_TTL); } else if (host_eth_type == ETH_P_IPV6) { FLOWER_PUT_MASKED_VALUE(ipv6.ipv6_src, TCA_FLOWER_KEY_IPV6_SRC); FLOWER_PUT_MASKED_VALUE(ipv6.ipv6_dst, TCA_FLOWER_KEY_IPV6_DST); From patchwork Tue Jul 31 10:40:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Or Gerlitz X-Patchwork-Id: 951541 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=fail (p=none dis=none) header.from=mellanox.com 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 41ftJr67Vxz9ryn for ; Tue, 31 Jul 2018 20:41:16 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 45BCDCC9; Tue, 31 Jul 2018 10:40:45 +0000 (UTC) X-Original-To: ovs-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 E78CECBA for ; Tue, 31 Jul 2018 10:40:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id DDC4D784 for ; Tue, 31 Jul 2018 10:40:42 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from ogerlitz@mellanox.com) with ESMTPS (AES256-SHA encrypted); 31 Jul 2018 13:44:03 +0300 Received: from r-vnc05.mtr.labs.mlnx (r-vnc05.mtr.labs.mlnx [10.208.0.115]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w6VAeeV2002811; Tue, 31 Jul 2018 13:40:40 +0300 From: Or Gerlitz To: ovs-dev@openvswitch.org Date: Tue, 31 Jul 2018 13:40:37 +0300 Message-Id: <1533033639-13009-3-git-send-email-ogerlitz@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1533033639-13009-1-git-send-email-ogerlitz@mellanox.com> References: <1533033639-13009-1-git-send-email-ogerlitz@mellanox.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Simon Horman , Or Gerlitz , Or Gerlitz Subject: [ovs-dev] [PATCH V2 2/4] lib/tc: Support matching on ip tos 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 Add the missing code to match on ip tos when dealing with the TC data-path. Signed-off-by: Or Gerlitz Reviewed-by: Roi Dayan --- include/openvswitch/match.h | 1 + lib/match.c | 7 +++++++ lib/netdev-tc-offloads.c | 6 ++++-- lib/tc.c | 10 ++++++++++ lib/tc.h | 1 + 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/openvswitch/match.h b/include/openvswitch/match.h index b43ecb1..e8c80dd 100644 --- a/include/openvswitch/match.h +++ b/include/openvswitch/match.h @@ -194,6 +194,7 @@ void match_set_nw_dscp(struct match *, uint8_t); void match_set_nw_ecn(struct match *, uint8_t); void match_set_nw_ttl(struct match *, uint8_t nw_ttl); void match_set_nw_ttl_masked(struct match *, uint8_t nw_ttl, uint8_t mask); +void match_set_nw_tos_masked(struct match *, uint8_t nw_tos, uint8_t mask); void match_set_nw_frag(struct match *, uint8_t nw_frag); void match_set_nw_frag_masked(struct match *, uint8_t nw_frag, uint8_t mask); void match_set_icmp_type(struct match *, uint8_t); diff --git a/lib/match.c b/lib/match.c index 2281fa0..a1407a8 100644 --- a/lib/match.c +++ b/lib/match.c @@ -946,6 +946,13 @@ match_set_nw_ttl(struct match *match, uint8_t nw_ttl) } void +match_set_nw_tos_masked(struct match *match, uint8_t nw_tos, uint8_t mask) +{ + match->flow.nw_tos = nw_tos & mask; + match->wc.masks.nw_tos = mask; +} + +void match_set_nw_ttl_masked(struct match *match, uint8_t nw_ttl, uint8_t mask) { match->flow.nw_ttl = nw_ttl & mask; diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c index 2a6dd6d..c61197a 100644 --- a/lib/netdev-tc-offloads.c +++ b/lib/netdev-tc-offloads.c @@ -455,6 +455,7 @@ parse_tc_flower_to_match(struct tc_flower *flower, match_set_nw_proto(match, key->ip_proto); } + match_set_nw_tos_masked(match, key->ip_tos, mask->ip_tos); match_set_nw_ttl_masked(match, key->ip_ttl, mask->ip_ttl); if (mask->flags) { @@ -1026,6 +1027,9 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, flower.key.ip_proto = key->nw_proto; flower.mask.ip_proto = mask->nw_proto; mask->nw_proto = 0; + flower.key.ip_tos = key->nw_tos; + flower.mask.ip_tos = mask->nw_tos; + mask->nw_tos = 0; flower.key.ip_ttl = key->nw_ttl; flower.mask.ip_ttl = mask->nw_ttl; mask->nw_ttl = 0; @@ -1074,8 +1078,6 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, mask->tp_dst = 0; } - mask->nw_tos = 0; - if (key->dl_type == htons(ETH_P_IP)) { flower.key.ipv4.ipv4_src = key->nw_src; flower.mask.ipv4.ipv4_src = mask->nw_src; diff --git a/lib/tc.c b/lib/tc.c index 791f285..ec7efff 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -302,6 +302,10 @@ static const struct nl_policy tca_flower_policy[] = { .optional = true, }, [TCA_FLOWER_KEY_IP_TTL_MASK] = { .type = NL_A_U8, .optional = true, }, + [TCA_FLOWER_KEY_IP_TOS] = { .type = NL_A_U8, + .optional = true, }, + [TCA_FLOWER_KEY_IP_TOS_MASK] = { .type = NL_A_U8, + .optional = true, }, [TCA_FLOWER_KEY_TCP_FLAGS] = { .type = NL_A_U16, .optional = true, }, [TCA_FLOWER_KEY_TCP_FLAGS_MASK] = { .type = NL_A_U16, @@ -497,6 +501,11 @@ nl_parse_flower_ip(struct nlattr **attrs, struct tc_flower *flower) { key->ip_ttl = nl_attr_get_u8(attrs[TCA_FLOWER_KEY_IP_TTL]); mask->ip_ttl = nl_attr_get_u8(attrs[TCA_FLOWER_KEY_IP_TTL_MASK]); } + + if (attrs[TCA_FLOWER_KEY_IP_TOS_MASK]) { + key->ip_tos = nl_attr_get_u8(attrs[TCA_FLOWER_KEY_IP_TOS]); + mask->ip_tos = nl_attr_get_u8(attrs[TCA_FLOWER_KEY_IP_TOS_MASK]); + } } static enum tc_offloaded_state @@ -1626,6 +1635,7 @@ nl_msg_put_flower_options(struct ofpbuf *request, struct tc_flower *flower) if (host_eth_type == ETH_P_IP || host_eth_type == ETH_P_IPV6) { FLOWER_PUT_MASKED_VALUE(ip_ttl, TCA_FLOWER_KEY_IP_TTL); + FLOWER_PUT_MASKED_VALUE(ip_tos, TCA_FLOWER_KEY_IP_TOS); if (flower->mask.ip_proto && flower->key.ip_proto) { nl_msg_put_u8(request, TCA_FLOWER_KEY_IP_PROTO, diff --git a/lib/tc.h b/lib/tc.h index 447d85f..90ef32a 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -95,6 +95,7 @@ struct tc_flower_key { uint8_t flags; uint8_t ip_ttl; + uint8_t ip_tos; struct { ovs_be32 ipv4_src; From patchwork Tue Jul 31 10:40:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Or Gerlitz X-Patchwork-Id: 951546 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=fail (p=none dis=none) header.from=mellanox.com 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 41ftLG68NPz9ryl for ; Tue, 31 Jul 2018 20:42:30 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id B65EACE3; Tue, 31 Jul 2018 10:40:50 +0000 (UTC) X-Original-To: ovs-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 E6ED9CBE for ; Tue, 31 Jul 2018 10:40:48 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id C4F10786 for ; Tue, 31 Jul 2018 10:40:47 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from ogerlitz@mellanox.com) with ESMTPS (AES256-SHA encrypted); 31 Jul 2018 13:44:03 +0300 Received: from r-vnc05.mtr.labs.mlnx (r-vnc05.mtr.labs.mlnx [10.208.0.115]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w6VAeeV3002811; Tue, 31 Jul 2018 13:40:40 +0300 From: Or Gerlitz To: ovs-dev@openvswitch.org Date: Tue, 31 Jul 2018 13:40:38 +0300 Message-Id: <1533033639-13009-4-git-send-email-ogerlitz@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1533033639-13009-1-git-send-email-ogerlitz@mellanox.com> References: <1533033639-13009-1-git-send-email-ogerlitz@mellanox.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Simon Horman , Or Gerlitz , Or Gerlitz Subject: [ovs-dev] [PATCH V2 3/4] lib/tc: Support setting tos and ttl for TC IP tunnels 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 Allow to set the tos and ttl for TC tunnels. Signed-off-by: Or Gerlitz Reviewed-by: Roi Dayan --- acinclude.m4 | 6 +++--- include/linux/tc_act/tc_tunnel_key.h | 10 ++++++++-- lib/netdev-tc-offloads.c | 16 ++++++++++++++++ lib/tc.c | 19 +++++++++++++++++-- lib/tc.h | 2 ++ 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index d6e0d33..a5ff325 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -192,10 +192,10 @@ AC_DEFUN([OVS_CHECK_LINUX_TC], [ AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([#include ], [ - int x = TCA_TUNNEL_KEY_ENC_DST_PORT; + int x = TCA_TUNNEL_KEY_ENC_TTL; ])], - [AC_DEFINE([HAVE_TCA_TUNNEL_KEY_ENC_DST_PORT], [1], - [Define to 1 if TCA_TUNNEL_KEY_ENC_DST_PORT is avaiable.])]) + [AC_DEFINE([HAVE_TCA_TUNNEL_KEY_ENC_TTL], [1], + [Define to 1 if TCA_TUNNEL_KEY_ENC_TTL is available.])]) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([#include ], [ diff --git a/include/linux/tc_act/tc_tunnel_key.h b/include/linux/tc_act/tc_tunnel_key.h index 0e49834..26cbd2f 100644 --- a/include/linux/tc_act/tc_tunnel_key.h +++ b/include/linux/tc_act/tc_tunnel_key.h @@ -1,7 +1,7 @@ #ifndef __LINUX_TC_ACT_TC_TUNNEL_KEY_WRAPPER_H #define __LINUX_TC_ACT_TC_TUNNEL_KEY_WRAPPER_H 1 -#if defined(__KERNEL__) || defined(HAVE_TCA_TUNNEL_KEY_ENC_DST_PORT) +#if defined(__KERNEL__) || defined(HAVE_TCA_TUNNEL_KEY_ENC_TTL) #include_next #else @@ -36,11 +36,17 @@ enum { TCA_TUNNEL_KEY_ENC_KEY_ID, /* be64 */ TCA_TUNNEL_KEY_PAD, TCA_TUNNEL_KEY_ENC_DST_PORT, /* be16 */ + TCA_TUNNEL_KEY_NO_CSUM, /* u8 */ + TCA_TUNNEL_KEY_ENC_OPTS, /* Nested TCA_TUNNEL_KEY_ENC_OPTS_ + * attributes + */ + TCA_TUNNEL_KEY_ENC_TOS, /* u8 */ + TCA_TUNNEL_KEY_ENC_TTL, /* u8 */ __TCA_TUNNEL_KEY_MAX, }; #define TCA_TUNNEL_KEY_MAX (__TCA_TUNNEL_KEY_MAX - 1) -#endif /* __KERNEL__ || HAVE_TCA_TUNNEL_KEY_ENC_DST_PORT */ +#endif /* __KERNEL__ || HAVE_TCA_TUNNEL_KEY_ENC_TTL */ #endif /* __LINUX_TC_ACT_TC_TUNNEL_KEY_WRAPPER_H */ diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c index c61197a..7ed0844 100644 --- a/lib/netdev-tc-offloads.c +++ b/lib/netdev-tc-offloads.c @@ -563,6 +563,14 @@ parse_tc_flower_to_match(struct tc_flower *flower, nl_msg_put_in6_addr(buf, OVS_TUNNEL_KEY_ATTR_IPV6_DST, &action->encap.ipv6.ipv6_dst); } + if (action->encap.tos) { + nl_msg_put_u8(buf, OVS_TUNNEL_KEY_ATTR_TOS, + action->encap.tos); + } + if (action->encap.ttl) { + nl_msg_put_u8(buf, OVS_TUNNEL_KEY_ATTR_TTL, + action->encap.ttl); + } nl_msg_put_be16(buf, OVS_TUNNEL_KEY_ATTR_TP_DST, action->encap.tp_dst); @@ -746,6 +754,14 @@ parse_put_flow_set_action(struct tc_flower *flower, struct tc_action *action, action->encap.ipv4.ipv4_dst = nl_attr_get_be32(tun_attr); } break; + case OVS_TUNNEL_KEY_ATTR_TOS: { + action->encap.tos = nl_attr_get_u8(tun_attr); + } + break; + case OVS_TUNNEL_KEY_ATTR_TTL: { + action->encap.ttl = nl_attr_get_u8(tun_attr); + } + break; case OVS_TUNNEL_KEY_ATTR_IPV6_SRC: { action->encap.ipv6.ipv6_src = nl_attr_get_in6_addr(tun_attr); diff --git a/lib/tc.c b/lib/tc.c index ec7efff..d9c9ffa 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -641,6 +641,8 @@ static const struct nl_policy tunnel_key_policy[] = { .optional = true, }, [TCA_TUNNEL_KEY_ENC_KEY_ID] = { .type = NL_A_U32, .optional = true, }, [TCA_TUNNEL_KEY_ENC_DST_PORT] = { .type = NL_A_U16, .optional = true, }, + [TCA_TUNNEL_KEY_ENC_TOS] = { .type = NL_A_U8, .optional = true, }, + [TCA_TUNNEL_KEY_ENC_TTL] = { .type = NL_A_U8, .optional = true, }, }; static int @@ -666,6 +668,8 @@ nl_parse_act_tunnel_key(struct nlattr *options, struct tc_flower *flower) struct nlattr *ipv4_dst = tun_attrs[TCA_TUNNEL_KEY_ENC_IPV4_DST]; struct nlattr *ipv6_src = tun_attrs[TCA_TUNNEL_KEY_ENC_IPV6_SRC]; struct nlattr *ipv6_dst = tun_attrs[TCA_TUNNEL_KEY_ENC_IPV6_DST]; + struct nlattr *tos = tun_attrs[TCA_TUNNEL_KEY_ENC_TOS]; + struct nlattr *ttl = tun_attrs[TCA_TUNNEL_KEY_ENC_TTL]; action = &flower->actions[flower->action_count++]; action->type = TC_ACT_ENCAP; @@ -679,6 +683,8 @@ nl_parse_act_tunnel_key(struct nlattr *options, struct tc_flower *flower) } action->encap.id = id ? be32_to_be64(nl_attr_get_be32(id)) : 0; action->encap.tp_dst = dst_port ? nl_attr_get_be16(dst_port) : 0; + action->encap.tos = tos ? nl_attr_get_u8(tos) : 0; + action->encap.ttl = ttl ? nl_attr_get_u8(ttl) : 0; } else if (tun->t_action == TCA_TUNNEL_KEY_ACT_RELEASE) { flower->tunnel.tunnel = true; } else { @@ -1251,7 +1257,8 @@ nl_msg_put_act_tunnel_key_set(struct ofpbuf *request, ovs_be64 id, ovs_be32 ipv4_src, ovs_be32 ipv4_dst, struct in6_addr *ipv6_src, struct in6_addr *ipv6_dst, - ovs_be16 tp_dst) + ovs_be16 tp_dst, + uint8_t tos, uint8_t ttl) { size_t offset; @@ -1274,6 +1281,12 @@ nl_msg_put_act_tunnel_key_set(struct ofpbuf *request, ovs_be64 id, nl_msg_put_in6_addr(request, TCA_TUNNEL_KEY_ENC_IPV6_SRC, ipv6_src); } + if (tos) { + nl_msg_put_u8(request, TCA_TUNNEL_KEY_ENC_TOS, tos); + } + if (ttl) { + nl_msg_put_u8(request, TCA_TUNNEL_KEY_ENC_TTL, ttl); + } nl_msg_put_be16(request, TCA_TUNNEL_KEY_ENC_DST_PORT, tp_dst); } nl_msg_end_nested(request, offset); @@ -1515,7 +1528,9 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower) action->encap.ipv4.ipv4_dst, &action->encap.ipv6.ipv6_src, &action->encap.ipv6.ipv6_dst, - action->encap.tp_dst); + action->encap.tp_dst, + action->encap.tos, + action->encap.ttl); nl_msg_end_nested(request, act_offset); } break; diff --git a/lib/tc.h b/lib/tc.h index 90ef32a..9a265f4 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -130,6 +130,8 @@ struct tc_action { ovs_be64 id; ovs_be16 tp_src; ovs_be16 tp_dst; + uint8_t tos; + uint8_t ttl; struct { ovs_be32 ipv4_src; ovs_be32 ipv4_dst; From patchwork Tue Jul 31 10:40:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Or Gerlitz X-Patchwork-Id: 951542 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=fail (p=none dis=none) header.from=mellanox.com 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 41ftKQ1dVPz9ryl for ; Tue, 31 Jul 2018 20:41:46 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 23441CD1; Tue, 31 Jul 2018 10:40:46 +0000 (UTC) X-Original-To: ovs-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 0C35FCB7 for ; Tue, 31 Jul 2018 10:40:44 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id DF023787 for ; Tue, 31 Jul 2018 10:40:42 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from ogerlitz@mellanox.com) with ESMTPS (AES256-SHA encrypted); 31 Jul 2018 13:44:03 +0300 Received: from r-vnc05.mtr.labs.mlnx (r-vnc05.mtr.labs.mlnx [10.208.0.115]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w6VAeeV4002811; Tue, 31 Jul 2018 13:40:40 +0300 From: Or Gerlitz To: ovs-dev@openvswitch.org Date: Tue, 31 Jul 2018 13:40:39 +0300 Message-Id: <1533033639-13009-5-git-send-email-ogerlitz@mellanox.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1533033639-13009-1-git-send-email-ogerlitz@mellanox.com> References: <1533033639-13009-1-git-send-email-ogerlitz@mellanox.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Simon Horman , Or Gerlitz , Or Gerlitz Subject: [ovs-dev] [PATCH V2 4/4] lib/tc: Support matching on ip tunnel tos and ttl 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 Support matching on tos and ttl of ip tunnels for the TC data-path. Signed-off-by: Or Gerlitz Reviewed-by: Roi Dayan --- acinclude.m4 | 10 +++++----- include/linux/pkt_cls.h | 7 ++++++- lib/netdev-tc-offloads.c | 8 ++++++++ lib/tc.c | 26 +++++++++++++++++++++++++- lib/tc.h | 4 +++- 5 files changed, 47 insertions(+), 8 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index a5ff325..1e42599 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -178,17 +178,17 @@ dnl Configure Linux tc compat. AC_DEFUN([OVS_CHECK_LINUX_TC], [ AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([#include ], [ - int x = TCA_FLOWER_KEY_CVLAN_PRIO; + int x = TCA_FLOWER_KEY_ENC_IP_TTL_MASK; ])], - [AC_DEFINE([HAVE_TCA_FLOWER_KEY_CVLAN_PRIO], [1], - [Define to 1 if TCA_FLOWER_KEY_CVLAN_PRIO is avaiable.])]) + [AC_DEFINE([HAVE_TCA_FLOWER_KEY_ENC_IP_TTL_MASK], [1], + [Define to 1 if TCA_FLOWER_KEY_ENC_IP_TTL_MASK is available.])]) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([#include ], [ int x = TCA_VLAN_PUSH_VLAN_PRIORITY; ])], [AC_DEFINE([HAVE_TCA_VLAN_PUSH_VLAN_PRIORITY], [1], - [Define to 1 if TCA_VLAN_PUSH_VLAN_PRIORITY is avaiable.])]) + [Define to 1 if TCA_VLAN_PUSH_VLAN_PRIORITY is available.])]) AC_COMPILE_IFELSE([ AC_LANG_PROGRAM([#include ], [ @@ -202,7 +202,7 @@ AC_DEFUN([OVS_CHECK_LINUX_TC], [ int x = TCA_PEDIT_KEY_EX_HDR_TYPE_UDP; ])], [AC_DEFINE([HAVE_TCA_PEDIT_KEY_EX_HDR_TYPE_UDP], [1], - [Define to 1 if TCA_PEDIT_KEY_EX_HDR_TYPE_UDP is avaiable.])]) + [Define to 1 if TCA_PEDIT_KEY_EX_HDR_TYPE_UDP is available.])]) ]) dnl OVS_CHECK_DPDK diff --git a/include/linux/pkt_cls.h b/include/linux/pkt_cls.h index 442323d..a330041 100644 --- a/include/linux/pkt_cls.h +++ b/include/linux/pkt_cls.h @@ -1,7 +1,7 @@ #ifndef __LINUX_PKT_CLS_WRAPPER_H #define __LINUX_PKT_CLS_WRAPPER_H 1 -#if defined(__KERNEL__) || defined(HAVE_TCA_FLOWER_KEY_CVLAN_PRIO) +#if defined(__KERNEL__) || defined(HAVE_TCA_FLOWER_KEY_ENC_IP_TTL_MASK) #include_next #else @@ -200,6 +200,11 @@ enum { TCA_FLOWER_KEY_CVLAN_PRIO, /* u8 */ TCA_FLOWER_KEY_CVLAN_ETH_TYPE, /* be16 */ + TCA_FLOWER_KEY_ENC_IP_TOS, /* u8 */ + TCA_FLOWER_KEY_ENC_IP_TOS_MASK, /* u8 */ + TCA_FLOWER_KEY_ENC_IP_TTL, /* u8 */ + TCA_FLOWER_KEY_ENC_IP_TTL_MASK, /* u8 */ + __TCA_FLOWER_MAX, }; diff --git a/lib/netdev-tc-offloads.c b/lib/netdev-tc-offloads.c index 7ed0844..7bc745e 100644 --- a/lib/netdev-tc-offloads.c +++ b/lib/netdev-tc-offloads.c @@ -510,6 +510,12 @@ parse_tc_flower_to_match(struct tc_flower *flower, match_set_tun_ipv6_src(match, &flower->tunnel.ipv6.ipv6_src); match_set_tun_ipv6_dst(match, &flower->tunnel.ipv6.ipv6_dst); } + if (flower->tunnel.tos) { + match_set_tun_tos(match, flower->tunnel.tos); + } + if (flower->tunnel.ttl) { + match_set_tun_ttl(match, flower->tunnel.ttl); + } if (flower->tunnel.tp_dst) { match_set_tun_tp_dst(match, flower->tunnel.tp_dst); } @@ -963,6 +969,8 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, flower.tunnel.ipv4.ipv4_dst = tnl->ip_dst; flower.tunnel.ipv6.ipv6_src = tnl->ipv6_src; flower.tunnel.ipv6.ipv6_dst = tnl->ipv6_dst; + flower.tunnel.tos = tnl->ip_tos; + flower.tunnel.ttl = tnl->ip_ttl; flower.tunnel.tp_src = tnl->tp_src; flower.tunnel.tp_dst = tnl->tp_dst; flower.tunnel.tunnel = true; diff --git a/lib/tc.c b/lib/tc.c index d9c9ffa..bbc3823 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -313,6 +313,14 @@ static const struct nl_policy tca_flower_policy[] = { [TCA_FLOWER_KEY_CVLAN_ID] = { .type = NL_A_U16, .optional = true, }, [TCA_FLOWER_KEY_CVLAN_PRIO] = { .type = NL_A_U8, .optional = true, }, [TCA_FLOWER_KEY_CVLAN_ETH_TYPE] = { .type = NL_A_U16, .optional = true, }, + [TCA_FLOWER_KEY_ENC_IP_TOS] = { .type = NL_A_U8, + .optional = true, }, + [TCA_FLOWER_KEY_ENC_IP_TOS_MASK] = { .type = NL_A_U8, + .optional = true, }, + [TCA_FLOWER_KEY_ENC_IP_TTL] = { .type = NL_A_U8, + .optional = true, }, + [TCA_FLOWER_KEY_ENC_IP_TTL_MASK] = { .type = NL_A_U8, + .optional = true, }, }; static void @@ -407,6 +415,14 @@ nl_parse_flower_tunnel(struct nlattr **attrs, struct tc_flower *flower) flower->tunnel.tp_dst = nl_attr_get_be16(attrs[TCA_FLOWER_KEY_ENC_UDP_DST_PORT]); } + if (attrs[TCA_FLOWER_KEY_ENC_IP_TOS]) { + flower->tunnel.tos = + nl_attr_get_u8(attrs[TCA_FLOWER_KEY_ENC_IP_TOS]); + } + if (attrs[TCA_FLOWER_KEY_ENC_IP_TTL]) { + flower->tunnel.ttl = + nl_attr_get_u8(attrs[TCA_FLOWER_KEY_ENC_IP_TTL]); + } } static void @@ -1605,8 +1621,9 @@ nl_msg_put_flower_tunnel(struct ofpbuf *request, struct tc_flower *flower) struct in6_addr *ipv6_dst = &flower->tunnel.ipv6.ipv6_dst; ovs_be16 tp_dst = flower->tunnel.tp_dst; ovs_be32 id = be64_to_be32(flower->tunnel.id); + uint8_t tos = flower->tunnel.tos; + uint8_t ttl = flower->tunnel.ttl; - nl_msg_put_be32(request, TCA_FLOWER_KEY_ENC_KEY_ID, id); if (ipv4_dst) { nl_msg_put_be32(request, TCA_FLOWER_KEY_ENC_IPV4_SRC, ipv4_src); nl_msg_put_be32(request, TCA_FLOWER_KEY_ENC_IPV4_DST, ipv4_dst); @@ -1614,7 +1631,14 @@ nl_msg_put_flower_tunnel(struct ofpbuf *request, struct tc_flower *flower) nl_msg_put_in6_addr(request, TCA_FLOWER_KEY_ENC_IPV6_SRC, ipv6_src); nl_msg_put_in6_addr(request, TCA_FLOWER_KEY_ENC_IPV6_DST, ipv6_dst); } + if (tos) { + nl_msg_put_u8(request, TCA_FLOWER_KEY_ENC_IP_TOS, tos); + } + if (ttl) { + nl_msg_put_u8(request, TCA_FLOWER_KEY_ENC_IP_TTL, ttl); + } nl_msg_put_be16(request, TCA_FLOWER_KEY_ENC_UDP_DST_PORT, tp_dst); + nl_msg_put_be32(request, TCA_FLOWER_KEY_ENC_KEY_ID, id); } #define FLOWER_PUT_MASKED_VALUE(member, type) \ diff --git a/lib/tc.h b/lib/tc.h index 9a265f4..aa8805d 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -183,9 +183,11 @@ struct tc_flower { struct in6_addr ipv6_src; struct in6_addr ipv6_dst; } ipv6; - ovs_be64 id; + uint8_t tos; + uint8_t ttl; ovs_be16 tp_src; ovs_be16 tp_dst; + ovs_be64 id; } tunnel; struct tc_cookie act_cookie;