From patchwork Wed Jul 3 17:04:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Rose X-Patchwork-Id: 1126989 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=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="iVIMSQsN"; 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 45f6t906nwz9sBp for ; Thu, 4 Jul 2019 03:05:04 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 29EB0E62; Wed, 3 Jul 2019 17:05:02 +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 249AFE3F for ; Wed, 3 Jul 2019 17:05:01 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 69782836 for ; Wed, 3 Jul 2019 17:05:00 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id r7so1585299pfl.3 for ; Wed, 03 Jul 2019 10:05:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=gwjij1sw0YlXAc0y+XJuWRNb4H0isjeCV66VUK8BWvU=; b=iVIMSQsNkqi4I6YAOznio8ftCDWGsmvGYzlrdYgcJBP3wISx6RaSObaWe1a++DURIR tVyc6JgfiUaVOBgNrv9B0UPeLjOaNA/C6KkMqdXWK0OyLeWWamlECICp+c8xYwri5if9 1ueM8yc5gPQcGvr1ZtTTXd4+EC2w1x5Yxl3mu3YJOorJYTJoLMftYDTmcfntOG3+VGdI v87QcnbI42dwN7MXLDpKA1+qkWKcXZ9J9L02kyCvL/xUsz+SB4reVZBdXwyhs7ecB0aI HZzCTBpBXHJNNp8s7621Oe0TDOs2JaBZWT0DbNGOB55QQy6gtT9Rb9KxptpTRPiwN2O3 30HA== 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; bh=gwjij1sw0YlXAc0y+XJuWRNb4H0isjeCV66VUK8BWvU=; b=PO8Gg9F1Yxeu2sZChwPpSlzgJ0eCj7/9bw+bKu8tJIflnwLhw7tQgPACjKlgzm3VxL L6TvQSgeq9BsAeCAY+z82vrD12YBrB74OHwt1MMOrQGo2y1yHcvyrAwpVSt5aRaGXGZh b6bPURBlMflJn7g6l9gfdUG6uNopB+sma8WCiu2uaijNo3P9cCLoqxt+LhjPwPU59e5B q5QazPxGtdNS0gNDlqczrBlNef5GMM7iKCq2SbHwcJUfDRljnc4mva1dI5LFxU+Rquw6 kdcUDwpqaHCe/lXtHXe30n8DhtYW8cLfEk2j5gjzHlN3AsVTB2vV69BSk4yHILhKXEJd euLA== X-Gm-Message-State: APjAAAWUyZvPHbn0DKOP78zar02F6CecAPbUrgKbuqF+/dj5aZqlvbIJ u0oh6/oLmH6dv9ntLY1H5HDcRhBi X-Google-Smtp-Source: APXvYqy3XZmj2p38Hw0J9cst9Omyk7w0+uZvwq2zb3aXrcMXyJeoxzkGeqiPu6U4w2CKs+kdKyBmZA== X-Received: by 2002:a63:e5a:: with SMTP id 26mr9116754pgo.3.1562173499478; Wed, 03 Jul 2019 10:04:59 -0700 (PDT) Received: from gizo.domain (97-115-113-19.ptld.qwest.net. [97.115.113.19]) by smtp.gmail.com with ESMTPSA id a10sm2313061pgq.2.2019.07.03.10.04.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jul 2019 10:04:58 -0700 (PDT) From: Greg Rose To: dev@openvswitch.org Date: Wed, 3 Jul 2019 10:04:53 -0700 Message-Id: <1562173495-24586-1-git-send-email-gvrose8192@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH V2 1/3] compat: Remove duplicate metadata destination code 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 ip_gre.c and ip6_gre.c both had duplicate code for handling the tunnel metadata destinations. Move the duplicate code over into the right header file, dst_metadata.h. Signed-off-by: Greg Rose Acked-by: William Tu --- v1->v2 Remove unwanted comment left over from code reorg --- datapath/linux/compat/include/net/dst_metadata.h | 135 ++++++++++++++++++++++- datapath/linux/compat/ip6_gre.c | 99 ----------------- datapath/linux/compat/ip_gre.c | 82 +------------- 3 files changed, 133 insertions(+), 183 deletions(-) diff --git a/datapath/linux/compat/include/net/dst_metadata.h b/datapath/linux/compat/include/net/dst_metadata.h index 9a82b3c..4ffafcc 100644 --- a/datapath/linux/compat/include/net/dst_metadata.h +++ b/datapath/linux/compat/include/net/dst_metadata.h @@ -30,6 +30,137 @@ struct metadata_dst { } u; }; +#ifndef DST_METADATA +#define DST_METADATA 0x0080 +#endif + +extern struct dst_ops md_dst_ops; + +static void rpl__metadata_dst_init(struct metadata_dst *md_dst, + enum metadata_type type, u8 optslen) + +{ + struct dst_entry *dst; + + dst = &md_dst->dst; + dst_init(dst, &md_dst_ops, NULL, 1, DST_OBSOLETE_NONE, + DST_METADATA | DST_NOCOUNT); + +#if 0 + /* unused in OVS */ + dst->input = dst_md_discard; + dst->output = dst_md_discard_out; +#endif + memset(dst + 1, 0, sizeof(*md_dst) + optslen - sizeof(*dst)); + md_dst->type = type; +} + +static struct +metadata_dst *__rpl_metadata_dst_alloc(u8 optslen, + enum metadata_type type, + gfp_t flags) +{ + struct metadata_dst *md_dst; + + md_dst = kmalloc(sizeof(*md_dst) + optslen, flags); + if (!md_dst) + return NULL; + + rpl__metadata_dst_init(md_dst, type, optslen); + + return md_dst; +} +static inline struct metadata_dst *rpl_tun_rx_dst(int md_size) +{ + struct metadata_dst *tun_dst; + + tun_dst = __rpl_metadata_dst_alloc(md_size, METADATA_IP_TUNNEL, + GFP_ATOMIC); + if (!tun_dst) + return NULL; + + tun_dst->u.tun_info.options_len = 0; + tun_dst->u.tun_info.mode = 0; + return tun_dst; +} +static inline struct metadata_dst *rpl__ip_tun_set_dst(__be32 saddr, + __be32 daddr, + __u8 tos, __u8 ttl, + __be16 tp_dst, + __be16 flags, + __be64 tunnel_id, + int md_size) +{ + struct metadata_dst *tun_dst; + + tun_dst = rpl_tun_rx_dst(md_size); + if (!tun_dst) + return NULL; + + ip_tunnel_key_init(&tun_dst->u.tun_info.key, + saddr, daddr, tos, ttl, + 0, 0, tp_dst, tunnel_id, flags); + return tun_dst; +} + +static inline struct metadata_dst *rpl_ip_tun_rx_dst(struct sk_buff *skb, + __be16 flags, + __be64 tunnel_id, + int md_size) +{ + const struct iphdr *iph = ip_hdr(skb); + + return rpl__ip_tun_set_dst(iph->saddr, iph->daddr, iph->tos, iph->ttl, + 0, flags, tunnel_id, md_size); +} + +static inline +struct metadata_dst *rpl__ipv6_tun_set_dst(const struct in6_addr *saddr, + const struct in6_addr *daddr, + __u8 tos, __u8 ttl, + __be16 tp_dst, + __be32 label, + __be16 flags, + __be64 tunnel_id, + int md_size) +{ + struct metadata_dst *tun_dst; + struct ip_tunnel_info *info; + + tun_dst = rpl_tun_rx_dst(md_size); + if (!tun_dst) + return NULL; + + info = &tun_dst->u.tun_info; + info->mode = IP_TUNNEL_INFO_IPV6; + info->key.tun_flags = flags; + info->key.tun_id = tunnel_id; + info->key.tp_src = 0; + info->key.tp_dst = tp_dst; + + info->key.u.ipv6.src = *saddr; + info->key.u.ipv6.dst = *daddr; + + info->key.tos = tos; + info->key.ttl = ttl; + info->key.label = label; + + return tun_dst; +} + +static inline struct metadata_dst *rpl_ipv6_tun_rx_dst(struct sk_buff *skb, + __be16 flags, + __be64 tunnel_id, + int md_size) +{ + const struct ipv6hdr *ip6h = ipv6_hdr(skb); + + return rpl__ipv6_tun_set_dst(&ip6h->saddr, &ip6h->daddr, + ipv6_get_dsfield(ip6h), ip6h->hop_limit, + 0, ip6_flowlabel(ip6h), flags, tunnel_id, + md_size); +} + static void __metadata_dst_init(struct metadata_dst *md_dst, u8 optslen) { struct dst_entry *dst; @@ -127,10 +258,6 @@ rpl_metadata_dst_alloc(u8 optslen, enum metadata_type type, gfp_t flags) } #define metadata_dst_alloc rpl_metadata_dst_alloc -#ifndef DST_METADATA -#define DST_METADATA 0x0200 -#endif - static inline bool rpl_skb_valid_dst(const struct sk_buff *skb) { struct dst_entry *dst = skb_dst(skb); diff --git a/datapath/linux/compat/ip6_gre.c b/datapath/linux/compat/ip6_gre.c index ca4e661..850e703 100644 --- a/datapath/linux/compat/ip6_gre.c +++ b/datapath/linux/compat/ip6_gre.c @@ -520,105 +520,6 @@ static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt, #endif } -static struct dst_ops md_dst_ops = { - .family = AF_UNSPEC, -}; - -#ifndef DST_METADATA -#define DST_METADATA 0x0080 -#endif - -static void rpl__metadata_dst_init(struct metadata_dst *md_dst, - enum metadata_type type, u8 optslen) - -{ - struct dst_entry *dst; - - dst = &md_dst->dst; - dst_init(dst, &md_dst_ops, NULL, 1, DST_OBSOLETE_NONE, - DST_METADATA | DST_NOCOUNT); - -#if 0 - /* unused in OVS */ - dst->input = dst_md_discard; - dst->output = dst_md_discard_out; -#endif - memset(dst + 1, 0, sizeof(*md_dst) + optslen - sizeof(*dst)); - md_dst->type = type; -} - -static struct metadata_dst *erspan_rpl_metadata_dst_alloc(u8 optslen, enum metadata_type type, - gfp_t flags) -{ - struct metadata_dst *md_dst; - - md_dst = kmalloc(sizeof(*md_dst) + optslen, flags); - if (!md_dst) - return NULL; - - rpl__metadata_dst_init(md_dst, type, optslen); - - return md_dst; -} -static inline struct metadata_dst *rpl_tun_rx_dst(int md_size) -{ - struct metadata_dst *tun_dst; - - tun_dst = erspan_rpl_metadata_dst_alloc(md_size, METADATA_IP_TUNNEL, GFP_ATOMIC); - if (!tun_dst) - return NULL; - - tun_dst->u.tun_info.options_len = 0; - tun_dst->u.tun_info.mode = 0; - return tun_dst; -} -static inline -struct metadata_dst *rpl__ipv6_tun_set_dst(const struct in6_addr *saddr, - const struct in6_addr *daddr, - __u8 tos, __u8 ttl, - __be16 tp_dst, - __be32 label, - __be16 flags, - __be64 tunnel_id, - int md_size) -{ - struct metadata_dst *tun_dst; - struct ip_tunnel_info *info; - - tun_dst = rpl_tun_rx_dst(md_size); - if (!tun_dst) - return NULL; - - info = &tun_dst->u.tun_info; - info->mode = IP_TUNNEL_INFO_IPV6; - info->key.tun_flags = flags; - info->key.tun_id = tunnel_id; - info->key.tp_src = 0; - info->key.tp_dst = tp_dst; - - info->key.u.ipv6.src = *saddr; - info->key.u.ipv6.dst = *daddr; - - info->key.tos = tos; - info->key.ttl = ttl; - info->key.label = label; - - return tun_dst; -} - -static inline struct metadata_dst *rpl_ipv6_tun_rx_dst(struct sk_buff *skb, - __be16 flags, - __be64 tunnel_id, - int md_size) -{ - const struct ipv6hdr *ip6h = ipv6_hdr(skb); - - return rpl__ipv6_tun_set_dst(&ip6h->saddr, &ip6h->daddr, - ipv6_get_dsfield(ip6h), ip6h->hop_limit, - 0, ip6_flowlabel(ip6h), flags, tunnel_id, - md_size); -} - static int ip6gre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi) { const struct ipv6hdr *ipv6h; diff --git a/datapath/linux/compat/ip_gre.c b/datapath/linux/compat/ip_gre.c index cf8803b..77c5b47 100644 --- a/datapath/linux/compat/ip_gre.c +++ b/datapath/linux/compat/ip_gre.c @@ -95,89 +95,11 @@ static __be32 tunnel_id_to_key(__be64 x) #endif } -static struct dst_ops md_dst_ops = { +/* Normally in net/core/dst.c but move it here */ +struct dst_ops md_dst_ops = { .family = AF_UNSPEC, }; -#ifndef DST_METADATA -#define DST_METADATA 0x0080 -#endif - -static void rpl__metadata_dst_init(struct metadata_dst *md_dst, - enum metadata_type type, u8 optslen) - -{ - struct dst_entry *dst; - - dst = &md_dst->dst; - dst_init(dst, &md_dst_ops, NULL, 1, DST_OBSOLETE_NONE, - DST_METADATA | DST_NOCOUNT); - -#if 0 - /* unused in OVS */ - dst->input = dst_md_discard; - dst->output = dst_md_discard_out; -#endif - memset(dst + 1, 0, sizeof(*md_dst) + optslen - sizeof(*dst)); - md_dst->type = type; -} - -static struct metadata_dst *erspan_rpl_metadata_dst_alloc(u8 optslen, enum metadata_type type, - gfp_t flags) -{ - struct metadata_dst *md_dst; - - md_dst = kmalloc(sizeof(*md_dst) + optslen, flags); - if (!md_dst) - return NULL; - - rpl__metadata_dst_init(md_dst, type, optslen); - - return md_dst; -} -static inline struct metadata_dst *rpl_tun_rx_dst(int md_size) -{ - struct metadata_dst *tun_dst; - - tun_dst = erspan_rpl_metadata_dst_alloc(md_size, METADATA_IP_TUNNEL, GFP_ATOMIC); - if (!tun_dst) - return NULL; - - tun_dst->u.tun_info.options_len = 0; - tun_dst->u.tun_info.mode = 0; - return tun_dst; -} -static inline struct metadata_dst *rpl__ip_tun_set_dst(__be32 saddr, - __be32 daddr, - __u8 tos, __u8 ttl, - __be16 tp_dst, - __be16 flags, - __be64 tunnel_id, - int md_size) -{ - struct metadata_dst *tun_dst; - - tun_dst = rpl_tun_rx_dst(md_size); - if (!tun_dst) - return NULL; - - ip_tunnel_key_init(&tun_dst->u.tun_info.key, - saddr, daddr, tos, ttl, - 0, 0, tp_dst, tunnel_id, flags); - return tun_dst; -} - -static inline struct metadata_dst *rpl_ip_tun_rx_dst(struct sk_buff *skb, - __be16 flags, - __be64 tunnel_id, - int md_size) -{ - const struct iphdr *iph = ip_hdr(skb); - - return rpl__ip_tun_set_dst(iph->saddr, iph->daddr, iph->tos, iph->ttl, - 0, flags, tunnel_id, md_size); -} - static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi, int gre_hdr_len) {