From patchwork Sat Jan 23 19:59:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 12041907 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F7F3C433DB for ; Sat, 23 Jan 2021 20:06:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6096323B1B for ; Sat, 23 Jan 2021 20:06:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726405AbhAWUGG (ORCPT ); Sat, 23 Jan 2021 15:06:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726362AbhAWUAN (ORCPT ); Sat, 23 Jan 2021 15:00:13 -0500 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9B2FC061786 for ; Sat, 23 Jan 2021 11:59:32 -0800 (PST) Received: by mail-lj1-x233.google.com with SMTP id l12so8009687ljc.3 for ; Sat, 23 Jan 2021 11:59:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lcDyZRwrAjXUTsQKlql+BRrBJvsyY+Wnx1Y6bQbkSkw=; b=k99pxyhLfVQQo/eGI4ezJjsxQrLdyvd1WrEQzZMLsIUkvUBXBLmcMpKUk3f2wn3sPZ usfXGoBxojm+nfzr6EJ5MdLKitbAMtGpxgULkSkQZj3XKuExwDKta0mCODm4eyNoHT2/ GpJ+voBjFP5IfOyw2p2HIcElroeUJ5uxlSkthqc6VZF3PeMPw8kSRkstEsCuCpfU8tfa BnwwY7ke7OmbH99mnicbv0YLv4pbXlKNNDMoJerDD3I54l1FaDTx8HxmyFmuKF3MywuW 9kYBc72T04u2QPbrzb7Z+awnUO94/LdM2rbJPHfTFA+d53jSBeS8e+bk8W2Itz85hiT/ si2A== 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:mime-version:content-transfer-encoding; bh=lcDyZRwrAjXUTsQKlql+BRrBJvsyY+Wnx1Y6bQbkSkw=; b=XXXJnU8LuYzbpZ2W5ThY7HgfTxtuuKindMYOWcOyMNv8yJTFb2qT96KY69sof4GlEU pDkp4CcW2NMv1c53zRnSLDX/GYYm/VsA46CApgjqXYkl6qEOhRfuE+H/6V2kwdwUo7tE /adEKaSsypoyIHII7VO9zZQYtM0EmooiRROFUI8trz398dgD5L4gmzvx9A4TZAf5LV0V wQSIHW54c2APwqAHUKaCZRk/5IlnIQY4PQSIf1XCqBlcDZLean2AumGWPMhJ11uIGhwu 1JPLdO30G05KTp3CzSAqNtuiWK00T35/Hiqu9QYc5bCD6GYbF4K3FuBgsqAf4AhdK0nb dtzg== X-Gm-Message-State: AOAM532pCeMhpJjWMW2wt0NjAa/56j7Y1gAk4KCla+XaivhVVxKyM2dR a59qc1BHqifE/wmMQAcNjyEY+w== X-Google-Smtp-Source: ABdhPJw9cB5yBBxM/oEtk9RRbANXwT4RszGPHzD02Iis0zoZmGlmWkdtCu/tcNiiKpnOOH/y/mraJA== X-Received: by 2002:a2e:87c4:: with SMTP id v4mr442082ljj.413.1611431971362; Sat, 23 Jan 2021 11:59:31 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id f9sm1265177lft.114.2021.01.23.11.59.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 11:59:30 -0800 (PST) From: Jonas Bonn To: laforge@gnumonks.org, netdev@vger.kernel.org, pbshelar@fb.com, kuba@kernel.org Cc: pablo@netfilter.org, Jonas Bonn Subject: [RFC PATCH 01/16] Revert "GTP: add support for flow based tunneling API" Date: Sat, 23 Jan 2021 20:59:01 +0100 Message-Id: <20210123195916.2765481-2-jonas@norrbonn.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210123195916.2765481-1-jonas@norrbonn.se> References: <20210123195916.2765481-1-jonas@norrbonn.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This reverts commit 9ab7e76aefc97a9aa664accb59d6e8dc5e52514a. This patch was committed without maintainer approval and despite a number of unaddressed concerns from review. There are several issues that impede the acceptance of this patch and that make a reversion of this particular instance of these changes the best way forward: i) the patch contains several logically separate changes that would be better served as smaller patches (for review purposes) ii) functionality like the handling of end markers has been introduced without further explanation iii) symmetry between the handling of GTPv0 and GTPv1 has been unnecessarily broken iv) there are no available userspace tools to allow for testing this functionality v) there is an unaddressed Coverity report against the patch concering memory leakage vi) most importantly, the patch contains a large amount of superfluous churn that impedes other ongoing work with this driver This patch will be reworked into a series that aligns with other ongoing work and facilitates review. Signed-off-by: Jonas Bonn Acked-by: Harald Welte --- drivers/net/gtp.c | 527 ++++++++--------------------- include/uapi/linux/gtp.h | 12 - include/uapi/linux/if_link.h | 1 - include/uapi/linux/if_tunnel.h | 1 - tools/include/uapi/linux/if_link.h | 1 - 5 files changed, 144 insertions(+), 398 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 851364314ecc..4c04e271f184 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -21,7 +21,6 @@ #include #include -#include #include #include #include @@ -74,9 +73,6 @@ struct gtp_dev { unsigned int hash_size; struct hlist_head *tid_hash; struct hlist_head *addr_hash; - /* Used by LWT tunnel. */ - bool collect_md; - struct socket *collect_md_sock; }; static unsigned int gtp_net_id __read_mostly; @@ -183,121 +179,33 @@ static bool gtp_check_ms(struct sk_buff *skb, struct pdp_ctx *pctx, return false; } -static int gtp_set_tun_dst(struct gtp_dev *gtp, struct sk_buff *skb, - unsigned int hdrlen, u8 gtp_version, - __be64 tid, u8 flags) +static int gtp_rx(struct pdp_ctx *pctx, struct sk_buff *skb, + unsigned int hdrlen, unsigned int role) { - struct metadata_dst *tun_dst; - int opts_len = 0; - - if (unlikely(flags & GTP1_F_MASK)) - opts_len = sizeof(struct gtpu_metadata); - - tun_dst = udp_tun_rx_dst(skb, gtp->sk1u->sk_family, TUNNEL_KEY, tid, opts_len); - if (!tun_dst) { - netdev_dbg(gtp->dev, "Failed to allocate tun_dst"); - goto err; + if (!gtp_check_ms(skb, pctx, hdrlen, role)) { + netdev_dbg(pctx->dev, "No PDP ctx for this MS\n"); + return 1; } - netdev_dbg(gtp->dev, "attaching metadata_dst to skb, gtp ver %d hdrlen %d\n", - gtp_version, hdrlen); - if (unlikely(opts_len)) { - struct gtpu_metadata *opts; - struct gtp1_header *gtp1; - - opts = ip_tunnel_info_opts(&tun_dst->u.tun_info); - gtp1 = (struct gtp1_header *)(skb->data + sizeof(struct udphdr)); - opts->ver = GTP_METADATA_V1; - opts->flags = gtp1->flags; - opts->type = gtp1->type; - netdev_dbg(gtp->dev, "recved control pkt: flag %x type: %d\n", - opts->flags, opts->type); - tun_dst->u.tun_info.key.tun_flags |= TUNNEL_GTPU_OPT; - tun_dst->u.tun_info.options_len = opts_len; - skb->protocol = htons(0xffff); /* Unknown */ - } /* Get rid of the GTP + UDP headers. */ if (iptunnel_pull_header(skb, hdrlen, skb->protocol, - !net_eq(sock_net(gtp->sk1u), dev_net(gtp->dev)))) { - gtp->dev->stats.rx_length_errors++; - goto err; - } - - skb_dst_set(skb, &tun_dst->dst); - return 0; -err: - return -1; -} - -static int gtp_rx(struct gtp_dev *gtp, struct sk_buff *skb, - unsigned int hdrlen, u8 gtp_version, unsigned int role, - __be64 tid, u8 flags, u8 type) -{ - if (ip_tunnel_collect_metadata() || gtp->collect_md) { - int err; - - err = gtp_set_tun_dst(gtp, skb, hdrlen, gtp_version, tid, flags); - if (err) - goto err; - } else { - struct pdp_ctx *pctx; - - if (flags & GTP1_F_MASK) - hdrlen += 4; - - if (type != GTP_TPDU) - return 1; + !net_eq(sock_net(pctx->sk), dev_net(pctx->dev)))) + return -1; - if (gtp_version == GTP_V0) - pctx = gtp0_pdp_find(gtp, be64_to_cpu(tid)); - else - pctx = gtp1_pdp_find(gtp, be64_to_cpu(tid)); - if (!pctx) { - netdev_dbg(gtp->dev, "No PDP ctx to decap skb=%p\n", skb); - return 1; - } - - if (!gtp_check_ms(skb, pctx, hdrlen, role)) { - netdev_dbg(pctx->dev, "No PDP ctx for this MS\n"); - return 1; - } - /* Get rid of the GTP + UDP headers. */ - if (iptunnel_pull_header(skb, hdrlen, skb->protocol, - !net_eq(sock_net(pctx->sk), dev_net(gtp->dev)))) { - gtp->dev->stats.rx_length_errors++; - goto err; - } - } - netdev_dbg(gtp->dev, "forwarding packet from GGSN to uplink\n"); + netdev_dbg(pctx->dev, "forwarding packet from GGSN to uplink\n"); /* Now that the UDP and the GTP header have been removed, set up the * new network header. This is required by the upper layer to * calculate the transport header. */ skb_reset_network_header(skb); - if (pskb_may_pull(skb, sizeof(struct iphdr))) { - struct iphdr *iph; - - iph = ip_hdr(skb); - if (iph->version == 4) { - netdev_dbg(gtp->dev, "inner pkt: ipv4"); - skb->protocol = htons(ETH_P_IP); - } else if (iph->version == 6) { - netdev_dbg(gtp->dev, "inner pkt: ipv6"); - skb->protocol = htons(ETH_P_IPV6); - } else { - netdev_dbg(gtp->dev, "inner pkt error: Unknown type"); - } - } - skb->dev = gtp->dev; - dev_sw_netstats_rx_add(gtp->dev, skb->len); + skb->dev = pctx->dev; + + dev_sw_netstats_rx_add(pctx->dev, skb->len); + netif_rx(skb); return 0; - -err: - gtp->dev->stats.rx_dropped++; - return -1; } /* 1 means pass up to the stack, -1 means drop and 0 means decapsulated. */ @@ -306,6 +214,7 @@ static int gtp0_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb) unsigned int hdrlen = sizeof(struct udphdr) + sizeof(struct gtp0_header); struct gtp0_header *gtp0; + struct pdp_ctx *pctx; if (!pskb_may_pull(skb, hdrlen)) return -1; @@ -315,7 +224,16 @@ static int gtp0_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb) if ((gtp0->flags >> 5) != GTP_V0) return 1; - return gtp_rx(gtp, skb, hdrlen, GTP_V0, gtp->role, gtp0->tid, gtp0->flags, gtp0->type); + if (gtp0->type != GTP_TPDU) + return 1; + + pctx = gtp0_pdp_find(gtp, be64_to_cpu(gtp0->tid)); + if (!pctx) { + netdev_dbg(gtp->dev, "No PDP ctx to decap skb=%p\n", skb); + return 1; + } + + return gtp_rx(pctx, skb, hdrlen, gtp->role); } static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb) @@ -323,30 +241,41 @@ static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb) unsigned int hdrlen = sizeof(struct udphdr) + sizeof(struct gtp1_header); struct gtp1_header *gtp1; + struct pdp_ctx *pctx; if (!pskb_may_pull(skb, hdrlen)) return -1; gtp1 = (struct gtp1_header *)(skb->data + sizeof(struct udphdr)); - netdev_dbg(gtp->dev, "GTPv1 recv: flags %x\n", gtp1->flags); if ((gtp1->flags >> 5) != GTP_V1) return 1; + if (gtp1->type != GTP_TPDU) + return 1; + /* From 29.060: "This field shall be present if and only if any one or * more of the S, PN and E flags are set.". * * If any of the bit is set, then the remaining ones also have to be * set. */ + if (gtp1->flags & GTP1_F_MASK) + hdrlen += 4; + /* Make sure the header is larger enough, including extensions. */ if (!pskb_may_pull(skb, hdrlen)) return -1; gtp1 = (struct gtp1_header *)(skb->data + sizeof(struct udphdr)); - return gtp_rx(gtp, skb, hdrlen, GTP_V1, gtp->role, - key32_to_tunnel_id(gtp1->tid), gtp1->flags, gtp1->type); + pctx = gtp1_pdp_find(gtp, ntohl(gtp1->tid)); + if (!pctx) { + netdev_dbg(gtp->dev, "No PDP ctx to decap skb=%p\n", skb); + return 1; + } + + return gtp_rx(pctx, skb, hdrlen, gtp->role); } static void __gtp_encap_destroy(struct sock *sk) @@ -386,11 +315,6 @@ static void gtp_encap_disable(struct gtp_dev *gtp) { gtp_encap_disable_sock(gtp->sk0); gtp_encap_disable_sock(gtp->sk1u); - if (gtp->collect_md_sock) { - udp_tunnel_sock_release(gtp->collect_md_sock); - gtp->collect_md_sock = NULL; - netdev_dbg(gtp->dev, "GTP socket released.\n"); - } } /* UDP encapsulation receive handler. See net/ipv4/udp.c. @@ -405,8 +329,7 @@ static int gtp_encap_recv(struct sock *sk, struct sk_buff *skb) if (!gtp) return 1; - netdev_dbg(gtp->dev, "encap_recv sk=%p type %d\n", - sk, udp_sk(sk)->encap_type); + netdev_dbg(gtp->dev, "encap_recv sk=%p\n", sk); switch (udp_sk(sk)->encap_type) { case UDP_ENCAP_GTP0: @@ -460,13 +383,12 @@ static void gtp_dev_uninit(struct net_device *dev) static struct rtable *ip4_route_output_gtp(struct flowi4 *fl4, const struct sock *sk, - __be32 daddr, - __be32 saddr) + __be32 daddr) { memset(fl4, 0, sizeof(*fl4)); fl4->flowi4_oif = sk->sk_bound_dev_if; fl4->daddr = daddr; - fl4->saddr = saddr; + fl4->saddr = inet_sk(sk)->inet_saddr; fl4->flowi4_tos = RT_CONN_FLAGS(sk); fl4->flowi4_proto = sk->sk_protocol; @@ -490,7 +412,7 @@ static inline void gtp0_push_header(struct sk_buff *skb, struct pdp_ctx *pctx) gtp0->tid = cpu_to_be64(pctx->u.v0.tid); } -static inline void gtp1_push_header(struct sk_buff *skb, __be32 tid) +static inline void gtp1_push_header(struct sk_buff *skb, struct pdp_ctx *pctx) { int payload_len = skb->len; struct gtp1_header *gtp1; @@ -506,63 +428,46 @@ static inline void gtp1_push_header(struct sk_buff *skb, __be32 tid) gtp1->flags = 0x30; /* v1, GTP-non-prime. */ gtp1->type = GTP_TPDU; gtp1->length = htons(payload_len); - gtp1->tid = tid; + gtp1->tid = htonl(pctx->u.v1.o_tei); /* TODO: Suppport for extension header, sequence number and N-PDU. * Update the length field if any of them is available. */ } -static inline int gtp1_push_control_header(struct sk_buff *skb, - __be32 tid, - struct gtpu_metadata *opts, - struct net_device *dev) -{ - struct gtp1_header *gtp1c; - int payload_len; - - if (opts->ver != GTP_METADATA_V1) - return -ENOENT; +struct gtp_pktinfo { + struct sock *sk; + struct iphdr *iph; + struct flowi4 fl4; + struct rtable *rt; + struct pdp_ctx *pctx; + struct net_device *dev; + __be16 gtph_port; +}; - if (opts->type == 0xFE) { - /* for end marker ignore skb data. */ - netdev_dbg(dev, "xmit pkt with null data"); - pskb_trim(skb, 0); +static void gtp_push_header(struct sk_buff *skb, struct gtp_pktinfo *pktinfo) +{ + switch (pktinfo->pctx->gtp_version) { + case GTP_V0: + pktinfo->gtph_port = htons(GTP0_PORT); + gtp0_push_header(skb, pktinfo->pctx); + break; + case GTP_V1: + pktinfo->gtph_port = htons(GTP1U_PORT); + gtp1_push_header(skb, pktinfo->pctx); + break; } - if (skb_cow_head(skb, sizeof(*gtp1c)) < 0) - return -ENOMEM; - - payload_len = skb->len; - - gtp1c = skb_push(skb, sizeof(*gtp1c)); - - gtp1c->flags = opts->flags; - gtp1c->type = opts->type; - gtp1c->length = htons(payload_len); - gtp1c->tid = tid; - netdev_dbg(dev, "xmit control pkt: ver %d flags %x type %x pkt len %d tid %x", - opts->ver, opts->flags, opts->type, skb->len, tid); - return 0; } -struct gtp_pktinfo { - struct sock *sk; - __u8 tos; - struct flowi4 fl4; - struct rtable *rt; - struct net_device *dev; - __be16 gtph_port; -}; - static inline void gtp_set_pktinfo_ipv4(struct gtp_pktinfo *pktinfo, - struct sock *sk, - __u8 tos, - struct rtable *rt, + struct sock *sk, struct iphdr *iph, + struct pdp_ctx *pctx, struct rtable *rt, struct flowi4 *fl4, struct net_device *dev) { pktinfo->sk = sk; - pktinfo->tos = tos; + pktinfo->iph = iph; + pktinfo->pctx = pctx; pktinfo->rt = rt; pktinfo->fl4 = *fl4; pktinfo->dev = dev; @@ -572,99 +477,40 @@ static int gtp_build_skb_ip4(struct sk_buff *skb, struct net_device *dev, struct gtp_pktinfo *pktinfo) { struct gtp_dev *gtp = netdev_priv(dev); - struct gtpu_metadata *opts = NULL; - struct sock *sk = NULL; struct pdp_ctx *pctx; struct rtable *rt; struct flowi4 fl4; - u8 gtp_version; - __be16 df = 0; - __be32 tun_id; - __be32 daddr; - __be32 saddr; - __u8 tos; + struct iphdr *iph; + __be16 df; int mtu; - if (gtp->collect_md) { - /* LWT GTP1U encap */ - struct ip_tunnel_info *info = NULL; - - info = skb_tunnel_info(skb); - if (!info) { - netdev_dbg(dev, "missing tunnel info"); - return -ENOENT; - } - if (info->key.tp_dst && ntohs(info->key.tp_dst) != GTP1U_PORT) { - netdev_dbg(dev, "unexpected GTP dst port: %d", ntohs(info->key.tp_dst)); - return -EOPNOTSUPP; - } - pctx = NULL; - gtp_version = GTP_V1; - tun_id = tunnel_id_to_key32(info->key.tun_id); - daddr = info->key.u.ipv4.dst; - saddr = info->key.u.ipv4.src; - sk = gtp->sk1u; - if (!sk) { - netdev_dbg(dev, "missing tunnel sock"); - return -EOPNOTSUPP; - } - tos = info->key.tos; - if (info->key.tun_flags & TUNNEL_DONT_FRAGMENT) - df = htons(IP_DF); - - if (info->options_len != 0) { - if (info->key.tun_flags & TUNNEL_GTPU_OPT) { - opts = ip_tunnel_info_opts(info); - } else { - netdev_dbg(dev, "missing tunnel metadata for control pkt"); - return -EOPNOTSUPP; - } - } - netdev_dbg(dev, "flow-based GTP1U encap: tunnel id %d\n", - be32_to_cpu(tun_id)); - } else { - struct iphdr *iph; - - if (ntohs(skb->protocol) != ETH_P_IP) - return -EOPNOTSUPP; - - iph = ip_hdr(skb); - - /* Read the IP destination address and resolve the PDP context. - * Prepend PDP header with TEI/TID from PDP ctx. - */ - if (gtp->role == GTP_ROLE_SGSN) - pctx = ipv4_pdp_find(gtp, iph->saddr); - else - pctx = ipv4_pdp_find(gtp, iph->daddr); + /* Read the IP destination address and resolve the PDP context. + * Prepend PDP header with TEI/TID from PDP ctx. + */ + iph = ip_hdr(skb); + if (gtp->role == GTP_ROLE_SGSN) + pctx = ipv4_pdp_find(gtp, iph->saddr); + else + pctx = ipv4_pdp_find(gtp, iph->daddr); - if (!pctx) { - netdev_dbg(dev, "no PDP ctx found for %pI4, skip\n", - &iph->daddr); - return -ENOENT; - } - sk = pctx->sk; - netdev_dbg(dev, "found PDP context %p\n", pctx); - - gtp_version = pctx->gtp_version; - tun_id = htonl(pctx->u.v1.o_tei); - daddr = pctx->peer_addr_ip4.s_addr; - saddr = inet_sk(sk)->inet_saddr; - tos = iph->tos; - df = iph->frag_off; - netdev_dbg(dev, "gtp -> IP src: %pI4 dst: %pI4\n", - &iph->saddr, &iph->daddr); + if (!pctx) { + netdev_dbg(dev, "no PDP ctx found for %pI4, skip\n", + &iph->daddr); + return -ENOENT; } + netdev_dbg(dev, "found PDP context %p\n", pctx); - rt = ip4_route_output_gtp(&fl4, sk, daddr, saddr); + rt = ip4_route_output_gtp(&fl4, pctx->sk, pctx->peer_addr_ip4.s_addr); if (IS_ERR(rt)) { - netdev_dbg(dev, "no route to SSGN %pI4\n", &daddr); + netdev_dbg(dev, "no route to SSGN %pI4\n", + &pctx->peer_addr_ip4.s_addr); dev->stats.tx_carrier_errors++; goto err; } if (rt->dst.dev == dev) { - netdev_dbg(dev, "circular route to SSGN %pI4\n", &daddr); + netdev_dbg(dev, "circular route to SSGN %pI4\n", + &pctx->peer_addr_ip4.s_addr); dev->stats.collisions++; goto err_rt; } @@ -672,10 +518,11 @@ static int gtp_build_skb_ip4(struct sk_buff *skb, struct net_device *dev, skb_dst_drop(skb); /* This is similar to tnl_update_pmtu(). */ + df = iph->frag_off; if (df) { mtu = dst_mtu(&rt->dst) - dev->hard_header_len - sizeof(struct iphdr) - sizeof(struct udphdr); - switch (gtp_version) { + switch (pctx->gtp_version) { case GTP_V0: mtu -= sizeof(struct gtp0_header); break; @@ -689,38 +536,17 @@ static int gtp_build_skb_ip4(struct sk_buff *skb, struct net_device *dev, rt->dst.ops->update_pmtu(&rt->dst, NULL, skb, mtu, false); - if (!skb_is_gso(skb) && (df & htons(IP_DF)) && mtu < skb->len) { - netdev_dbg(dev, "packet too big, fragmentation needed"); + if (!skb_is_gso(skb) && (iph->frag_off & htons(IP_DF)) && + mtu < ntohs(iph->tot_len)) { + netdev_dbg(dev, "packet too big, fragmentation needed\n"); memset(IPCB(skb), 0, sizeof(*IPCB(skb))); icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu)); goto err_rt; } - gtp_set_pktinfo_ipv4(pktinfo, sk, tos, rt, &fl4, dev); - - if (unlikely(opts)) { - int err; - - pktinfo->gtph_port = htons(GTP1U_PORT); - err = gtp1_push_control_header(skb, tun_id, opts, dev); - if (err) { - netdev_info(dev, "cntr pkt error %d", err); - goto err_rt; - } - return 0; - } - - switch (gtp_version) { - case GTP_V0: - pktinfo->gtph_port = htons(GTP0_PORT); - gtp0_push_header(skb, pctx); - break; - case GTP_V1: - pktinfo->gtph_port = htons(GTP1U_PORT); - gtp1_push_header(skb, tun_id); - break; - } + gtp_set_pktinfo_ipv4(pktinfo, pctx->sk, iph, pctx, rt, &fl4, dev); + gtp_push_header(skb, pktinfo); return 0; err_rt: @@ -731,6 +557,7 @@ static int gtp_build_skb_ip4(struct sk_buff *skb, struct net_device *dev, static netdev_tx_t gtp_dev_xmit(struct sk_buff *skb, struct net_device *dev) { + unsigned int proto = ntohs(skb->protocol); struct gtp_pktinfo pktinfo; int err; @@ -742,22 +569,32 @@ static netdev_tx_t gtp_dev_xmit(struct sk_buff *skb, struct net_device *dev) /* PDP context lookups in gtp_build_skb_*() need rcu read-side lock. */ rcu_read_lock(); - err = gtp_build_skb_ip4(skb, dev, &pktinfo); + switch (proto) { + case ETH_P_IP: + err = gtp_build_skb_ip4(skb, dev, &pktinfo); + break; + default: + err = -EOPNOTSUPP; + break; + } rcu_read_unlock(); if (err < 0) goto tx_err; - udp_tunnel_xmit_skb(pktinfo.rt, pktinfo.sk, skb, - pktinfo.fl4.saddr, - pktinfo.fl4.daddr, - pktinfo.tos, - ip4_dst_hoplimit(&pktinfo.rt->dst), - 0, - pktinfo.gtph_port, - pktinfo.gtph_port, - true, - false); + switch (proto) { + case ETH_P_IP: + netdev_dbg(pktinfo.dev, "gtp -> IP src: %pI4 dst: %pI4\n", + &pktinfo.iph->saddr, &pktinfo.iph->daddr); + udp_tunnel_xmit_skb(pktinfo.rt, pktinfo.sk, skb, + pktinfo.fl4.saddr, pktinfo.fl4.daddr, + pktinfo.iph->tos, + ip4_dst_hoplimit(&pktinfo.rt->dst), + 0, + pktinfo.gtph_port, pktinfo.gtph_port, + true, false); + break; + } return NETDEV_TX_OK; tx_err: @@ -773,19 +610,6 @@ static const struct net_device_ops gtp_netdev_ops = { .ndo_get_stats64 = dev_get_tstats64, }; -static struct gtp_dev *gtp_find_flow_based_dev(struct net *net) -{ - struct gtp_net *gn = net_generic(net, gtp_net_id); - struct gtp_dev *gtp; - - list_for_each_entry(gtp, &gn->gtp_dev_list, list) { - if (gtp->collect_md) - return gtp; - } - - return NULL; -} - static void gtp_link_setup(struct net_device *dev) { dev->netdev_ops = >p_netdev_ops; @@ -810,7 +634,7 @@ static void gtp_link_setup(struct net_device *dev) } static int gtp_hashtable_new(struct gtp_dev *gtp, int hsize); -static int gtp_encap_enable(struct gtp_dev *gtp, struct net_device *dev, struct nlattr *data[]); +static int gtp_encap_enable(struct gtp_dev *gtp, struct nlattr *data[]); static void gtp_destructor(struct net_device *dev) { @@ -828,24 +652,11 @@ static int gtp_newlink(struct net *src_net, struct net_device *dev, struct gtp_net *gn; int hashsize, err; - if (!data[IFLA_GTP_FD0] && !data[IFLA_GTP_FD1] && - !data[IFLA_GTP_COLLECT_METADATA]) + if (!data[IFLA_GTP_FD0] && !data[IFLA_GTP_FD1]) return -EINVAL; gtp = netdev_priv(dev); - if (data[IFLA_GTP_COLLECT_METADATA]) { - if (data[IFLA_GTP_FD0]) { - netdev_dbg(dev, "LWT device does not support setting v0 socket"); - return -EINVAL; - } - if (gtp_find_flow_based_dev(src_net)) { - netdev_dbg(dev, "LWT device already exist"); - return -EBUSY; - } - gtp->collect_md = true; - } - if (!data[IFLA_GTP_PDP_HASHSIZE]) { hashsize = 1024; } else { @@ -858,7 +669,7 @@ static int gtp_newlink(struct net *src_net, struct net_device *dev, if (err < 0) return err; - err = gtp_encap_enable(gtp, dev, data); + err = gtp_encap_enable(gtp, data); if (err < 0) goto out_hashtable; @@ -872,7 +683,7 @@ static int gtp_newlink(struct net *src_net, struct net_device *dev, list_add_rcu(>p->list, &gn->gtp_dev_list); dev->priv_destructor = gtp_destructor; - netdev_dbg(dev, "registered new GTP interface %s\n", dev->name); + netdev_dbg(dev, "registered new GTP interface\n"); return 0; @@ -903,7 +714,6 @@ static const struct nla_policy gtp_policy[IFLA_GTP_MAX + 1] = { [IFLA_GTP_FD1] = { .type = NLA_U32 }, [IFLA_GTP_PDP_HASHSIZE] = { .type = NLA_U32 }, [IFLA_GTP_ROLE] = { .type = NLA_U32 }, - [IFLA_GTP_COLLECT_METADATA] = { .type = NLA_FLAG }, }; static int gtp_validate(struct nlattr *tb[], struct nlattr *data[], @@ -927,9 +737,6 @@ static int gtp_fill_info(struct sk_buff *skb, const struct net_device *dev) if (nla_put_u32(skb, IFLA_GTP_PDP_HASHSIZE, gtp->hash_size)) goto nla_put_failure; - if (gtp->collect_md && nla_put_flag(skb, IFLA_GTP_COLLECT_METADATA)) - goto nla_put_failure; - return 0; nla_put_failure: @@ -975,24 +782,35 @@ static int gtp_hashtable_new(struct gtp_dev *gtp, int hsize) return -ENOMEM; } -static int __gtp_encap_enable_socket(struct socket *sock, int type, - struct gtp_dev *gtp) +static struct sock *gtp_encap_enable_socket(int fd, int type, + struct gtp_dev *gtp) { struct udp_tunnel_sock_cfg tuncfg = {NULL}; + struct socket *sock; struct sock *sk; + int err; + + pr_debug("enable gtp on %d, %d\n", fd, type); + + sock = sockfd_lookup(fd, &err); + if (!sock) { + pr_debug("gtp socket fd=%d not found\n", fd); + return NULL; + } sk = sock->sk; if (sk->sk_protocol != IPPROTO_UDP || sk->sk_type != SOCK_DGRAM || (sk->sk_family != AF_INET && sk->sk_family != AF_INET6)) { - pr_debug("socket not UDP\n"); - return -EINVAL; + pr_debug("socket fd=%d not UDP\n", fd); + sk = ERR_PTR(-EINVAL); + goto out_sock; } lock_sock(sk); if (sk->sk_user_data) { - release_sock(sock->sk); - return -EBUSY; + sk = ERR_PTR(-EBUSY); + goto out_rel_sock; } sock_hold(sk); @@ -1003,58 +821,15 @@ static int __gtp_encap_enable_socket(struct socket *sock, int type, tuncfg.encap_destroy = gtp_encap_destroy; setup_udp_tunnel_sock(sock_net(sock->sk), sock, &tuncfg); - release_sock(sock->sk); - return 0; -} -static struct sock *gtp_encap_enable_socket(int fd, int type, - struct gtp_dev *gtp) -{ - struct socket *sock; - int err; - - pr_debug("enable gtp on %d, %d\n", fd, type); - - sock = sockfd_lookup(fd, &err); - if (!sock) { - pr_debug("gtp socket fd=%d not found\n", fd); - return NULL; - } - err = __gtp_encap_enable_socket(sock, type, gtp); +out_rel_sock: + release_sock(sock->sk); +out_sock: sockfd_put(sock); - if (err) - return ERR_PTR(err); - - return sock->sk; + return sk; } -static struct socket *gtp_create_gtp_socket(struct gtp_dev *gtp, struct net_device *dev) -{ - struct udp_port_cfg udp_conf; - struct socket *sock; - int err; - - memset(&udp_conf, 0, sizeof(udp_conf)); - udp_conf.family = AF_INET; - udp_conf.local_ip.s_addr = htonl(INADDR_ANY); - udp_conf.local_udp_port = htons(GTP1U_PORT); - - err = udp_sock_create(dev_net(dev), &udp_conf, &sock); - if (err < 0) { - pr_debug("create gtp sock failed: %d\n", err); - return ERR_PTR(err); - } - err = __gtp_encap_enable_socket(sock, UDP_ENCAP_GTP1U, gtp); - if (err) { - pr_debug("enable gtp sock encap failed: %d\n", err); - udp_tunnel_sock_release(sock); - return ERR_PTR(err); - } - pr_debug("create gtp sock done\n"); - return sock; -} - -static int gtp_encap_enable(struct gtp_dev *gtp, struct net_device *dev, struct nlattr *data[]) +static int gtp_encap_enable(struct gtp_dev *gtp, struct nlattr *data[]) { struct sock *sk1u = NULL; struct sock *sk0 = NULL; @@ -1078,25 +853,11 @@ static int gtp_encap_enable(struct gtp_dev *gtp, struct net_device *dev, struct } } - if (data[IFLA_GTP_COLLECT_METADATA]) { - struct socket *sock; - - if (!sk1u) { - sock = gtp_create_gtp_socket(gtp, dev); - if (IS_ERR(sock)) - return PTR_ERR(sock); - - gtp->collect_md_sock = sock; - sk1u = sock->sk; - } else { - gtp->collect_md_sock = NULL; - } - } - if (data[IFLA_GTP_ROLE]) { role = nla_get_u32(data[IFLA_GTP_ROLE]); if (role > GTP_ROLE_SGSN) { - gtp_encap_disable(gtp); + gtp_encap_disable_sock(sk0); + gtp_encap_disable_sock(sk1u); return -EINVAL; } } @@ -1655,7 +1416,7 @@ static int __init gtp_init(void) if (err < 0) goto unreg_genl_family; - pr_info("GTP module loaded (pdp ctx size %zd bytes) with tnl-md support\n", + pr_info("GTP module loaded (pdp ctx size %zd bytes)\n", sizeof(struct pdp_ctx)); return 0; diff --git a/include/uapi/linux/gtp.h b/include/uapi/linux/gtp.h index 62aff78b7c56..79f9191bbb24 100644 --- a/include/uapi/linux/gtp.h +++ b/include/uapi/linux/gtp.h @@ -2,8 +2,6 @@ #ifndef _UAPI_LINUX_GTP_H_ #define _UAPI_LINUX_GTP_H_ -#include - #define GTP_GENL_MCGRP_NAME "gtp" enum gtp_genl_cmds { @@ -36,14 +34,4 @@ enum gtp_attrs { }; #define GTPA_MAX (__GTPA_MAX + 1) -enum { - GTP_METADATA_V1 -}; - -struct gtpu_metadata { - __u8 ver; - __u8 flags; - __u8 type; -}; - #endif /* _UAPI_LINUX_GTP_H_ */ diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index 2bd0d8bbcdb2..82708c6db432 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -809,7 +809,6 @@ enum { IFLA_GTP_FD1, IFLA_GTP_PDP_HASHSIZE, IFLA_GTP_ROLE, - IFLA_GTP_COLLECT_METADATA, __IFLA_GTP_MAX, }; #define IFLA_GTP_MAX (__IFLA_GTP_MAX - 1) diff --git a/include/uapi/linux/if_tunnel.h b/include/uapi/linux/if_tunnel.h index 802da679fab1..7d9105533c7b 100644 --- a/include/uapi/linux/if_tunnel.h +++ b/include/uapi/linux/if_tunnel.h @@ -176,7 +176,6 @@ enum { #define TUNNEL_VXLAN_OPT __cpu_to_be16(0x1000) #define TUNNEL_NOCACHE __cpu_to_be16(0x2000) #define TUNNEL_ERSPAN_OPT __cpu_to_be16(0x4000) -#define TUNNEL_GTPU_OPT __cpu_to_be16(0x8000) #define TUNNEL_OPTIONS_PRESENT \ (TUNNEL_GENEVE_OPT | TUNNEL_VXLAN_OPT | TUNNEL_ERSPAN_OPT) diff --git a/tools/include/uapi/linux/if_link.h b/tools/include/uapi/linux/if_link.h index 28d649bda686..d208b2af697f 100644 --- a/tools/include/uapi/linux/if_link.h +++ b/tools/include/uapi/linux/if_link.h @@ -617,7 +617,6 @@ enum { IFLA_GTP_FD1, IFLA_GTP_PDP_HASHSIZE, IFLA_GTP_ROLE, - IFLA_GTP_COLLECT_METADATA, __IFLA_GTP_MAX, }; #define IFLA_GTP_MAX (__IFLA_GTP_MAX - 1) From patchwork Sat Jan 23 19:59:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 12041905 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34EFEC433E0 for ; Sat, 23 Jan 2021 20:06:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0C1E223B1B for ; Sat, 23 Jan 2021 20:06:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726264AbhAWUF6 (ORCPT ); Sat, 23 Jan 2021 15:05:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726363AbhAWUAO (ORCPT ); Sat, 23 Jan 2021 15:00:14 -0500 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 939A1C061788 for ; Sat, 23 Jan 2021 11:59:33 -0800 (PST) Received: by mail-lf1-x12b.google.com with SMTP id i187so2042224lfd.4 for ; Sat, 23 Jan 2021 11:59:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Axi2g6I6F47I8bzDu1p5LN7RII40A/s6odd4OB1z8JY=; b=xo3tLdxWKGXck/ItrYfHG9ZHiEH02+cSemduNlDPZyJVbfH4pvlIHcpHxmpnXK3W7h tJFMYyGNFqBdsLevaN5bg5wYNmBbxX2zWCctYp3kZ8izy9grDUGdPFEO0oGq53rxbSu2 CI6lRfJLYs/YyX951ESC3fYOsv0/0D0aAulykJg0mAqWW1v6fj+h11Wgmr0RBQUNZO55 wAFPp2qmhJlkI10Em5TsI1H0uOVBbtf4yvW+SX9egZtwBT+s0Gw4dvByQLp9pVhLrvRJ FGgWh8DK2s8pPhDCN1SPrMj8T9+dX/5tOqfSiCXXWmuNs1sbLbwqOCMmVAnc5YqWSJce xdOw== 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:mime-version:content-transfer-encoding; bh=Axi2g6I6F47I8bzDu1p5LN7RII40A/s6odd4OB1z8JY=; b=ul+1FAAUWi4WatjbSzR7KpgRtX1k2yFll6u87kFS+Ls1oGW7tyeHYM5jU40fuPHQlQ cXRFanrFReLZs2QATPvo+thN7DWVIVvr6nlVsW/pzxAYQYtxu0cLkDnud+SNouNe8xKG GfegqVWd/AAVn1c88B5KLtN1YGVfMjBNT3DETX7LG1Mn+3A1NgT/QFAi8PjOqN12vk1A V0kWpG4hOsAnQ67jQEbbvfuAG3eTXivsUWXlPMwZEtfAz6CqBtDaJxZaL3r14VpSEzdv IRBWRWNRtDb1/Z38XCMWqktDzcJOWnABMzhoet9Z/9nLj/dqf5L5PVI6++hlRme6zBHS Ol/w== X-Gm-Message-State: AOAM5319syZdzaepetxjjhMlAOdvq6lnY0a5MngAwXzsKQzn/UcoNrlY RHNfiBuiqITRCj+oo2puewI3pQ== X-Google-Smtp-Source: ABdhPJyxAtVv0dW6QA7LJA69XQDyjNPAG1q/EYaawE7Rj8c6BgB3GKwHgT48htWKND/963/MmddcDg== X-Received: by 2002:a05:6512:a8c:: with SMTP id m12mr3513321lfu.253.1611431972171; Sat, 23 Jan 2021 11:59:32 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id f9sm1265177lft.114.2021.01.23.11.59.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 11:59:31 -0800 (PST) From: Jonas Bonn To: laforge@gnumonks.org, netdev@vger.kernel.org, pbshelar@fb.com, kuba@kernel.org Cc: pablo@netfilter.org, Jonas Bonn Subject: [RFC PATCH 02/16] gtp: set initial MTU Date: Sat, 23 Jan 2021 20:59:02 +0100 Message-Id: <20210123195916.2765481-3-jonas@norrbonn.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210123195916.2765481-1-jonas@norrbonn.se> References: <20210123195916.2765481-1-jonas@norrbonn.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The GTP link is brought up with a default MTU of zero. This can lead to some rather unexpected behaviour for users who are more accustomed to interfaces coming online with reasonable defaults. This patch sets an initial MTU for the GTP link of 1500 less worst-case tunnel overhead. Signed-off-by: Jonas Bonn Acked-by: Harald Welte --- drivers/net/gtp.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 4c04e271f184..5a048f050a9c 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -612,11 +612,16 @@ static const struct net_device_ops gtp_netdev_ops = { static void gtp_link_setup(struct net_device *dev) { + unsigned int max_gtp_header_len = sizeof(struct iphdr) + + sizeof(struct udphdr) + + sizeof(struct gtp0_header); + dev->netdev_ops = >p_netdev_ops; dev->needs_free_netdev = true; dev->hard_header_len = 0; dev->addr_len = 0; + dev->mtu = ETH_DATA_LEN - max_gtp_header_len; /* Zero header length. */ dev->type = ARPHRD_NONE; @@ -626,11 +631,7 @@ static void gtp_link_setup(struct net_device *dev) dev->features |= NETIF_F_LLTX; netif_keep_dst(dev); - /* Assume largest header, ie. GTPv0. */ - dev->needed_headroom = LL_MAX_HEADER + - sizeof(struct iphdr) + - sizeof(struct udphdr) + - sizeof(struct gtp0_header); + dev->needed_headroom = LL_MAX_HEADER + max_gtp_header_len; } static int gtp_hashtable_new(struct gtp_dev *gtp, int hsize); From patchwork Sat Jan 23 19:59:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 12041903 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA08AC433DB for ; Sat, 23 Jan 2021 20:05:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ADEB02310A for ; Sat, 23 Jan 2021 20:05:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726448AbhAWUFm (ORCPT ); Sat, 23 Jan 2021 15:05:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726294AbhAWUAP (ORCPT ); Sat, 23 Jan 2021 15:00:15 -0500 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A5BEC06178B for ; Sat, 23 Jan 2021 11:59:34 -0800 (PST) Received: by mail-lj1-x235.google.com with SMTP id u11so10500413ljo.13 for ; Sat, 23 Jan 2021 11:59:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BGpaEg0j3hIwyT8YaseDu5lYmdNhnyii6Jj6H/mUeXo=; b=MsAz3qcmzDW5QGnZnBh2j+/7H+aTnytZK9igo/MrSsweIhhTX659XM4nS5ZT56FzsP DZd557Uph6TIHJ0YsXz73rr7n9T0Wtmj8HIeH78wlf/qh9lNJo4YBpEiwV/Y88+YJpeh jrE+uwWFYiB/nuMAPAx+0nzQKApurJ3wm9dQeJBiyppqyHbiwp1b61jJNxlzxwAcPHOk 1DsvPdC55ZW/UXJ2sm/4YW/arnES5jMZjwk+6nID9GGLr2bND612jzDSht7JvSlDF/qG z3YADRXOTZQCH6z21+JrJDAOQBDSRZwp46EqT5fIrDG9bS8dY1yP2lUik9RZ2yTvfx5E lM5Q== 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:mime-version:content-transfer-encoding; bh=BGpaEg0j3hIwyT8YaseDu5lYmdNhnyii6Jj6H/mUeXo=; b=r0GDPb1bBMQ7lcKCgPN3AirSlG5Jpz4Q07Hp8ZNspegd38+EUusJbPa4XdaRe335TB kThMfUX6hIvPql2WUyJkNuifn+KsaFiYh7CoiOucQayNNzuzgvsp29/ZQsbk39Lg/ObF dAgY16s1iyIykMWhmRW0SOcF2pWMX7nqz4MJHOJBkwVNpXvF5rM9QEeUuqGHyAXxXaB4 6uTnmAkLqLf+GjobMXctDYZ82OMI8/EZPcQItwnhzOALus+YXvAYDAKcgNNYe4nRg4S6 1u6Y9rvJtqCjTis+yNn/u2h9Q3TE4M7ASPtLTUcYGokntni8caOy6rNM3xSbo5hhFKF3 bxFg== X-Gm-Message-State: AOAM5317tM6hVW2X7sKhwmo8M98+hhg+hENmLIS4zmUj/eOJgPREJrda n0rMjkjzu9jd/RW+XSFvDat2eQ== X-Google-Smtp-Source: ABdhPJz+yFQTdB91wMvNsvbGAU9JyTEggUgk9KTkWc1Aom+ShgLF0REV1Qwze3CgyzfS0vlYUUmOlQ== X-Received: by 2002:a2e:9a4f:: with SMTP id k15mr1636047ljj.157.1611431973053; Sat, 23 Jan 2021 11:59:33 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id f9sm1265177lft.114.2021.01.23.11.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 11:59:32 -0800 (PST) From: Jonas Bonn To: laforge@gnumonks.org, netdev@vger.kernel.org, pbshelar@fb.com, kuba@kernel.org Cc: pablo@netfilter.org, Jonas Bonn Subject: [RFC PATCH 03/16] gtp: include role in link info Date: Sat, 23 Jan 2021 20:59:03 +0100 Message-Id: <20210123195916.2765481-4-jonas@norrbonn.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210123195916.2765481-1-jonas@norrbonn.se> References: <20210123195916.2765481-1-jonas@norrbonn.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Querying link info for the GTP interface doesn't reveal in which "role" the device is set to operate. Include this information in the info query result. Signed-off-by: Jonas Bonn Acked-by: Harald Welte --- drivers/net/gtp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 5a048f050a9c..5682d3ba7aa5 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -728,7 +728,8 @@ static int gtp_validate(struct nlattr *tb[], struct nlattr *data[], static size_t gtp_get_size(const struct net_device *dev) { - return nla_total_size(sizeof(__u32)); /* IFLA_GTP_PDP_HASHSIZE */ + return nla_total_size(sizeof(__u32)) + /* IFLA_GTP_PDP_HASHSIZE */ + nla_total_size(sizeof(__u32)); /* IFLA_GTP_ROLE */ } static int gtp_fill_info(struct sk_buff *skb, const struct net_device *dev) @@ -737,6 +738,8 @@ static int gtp_fill_info(struct sk_buff *skb, const struct net_device *dev) if (nla_put_u32(skb, IFLA_GTP_PDP_HASHSIZE, gtp->hash_size)) goto nla_put_failure; + if (nla_put_u32(skb, IFLA_GTP_ROLE, gtp->role)) + goto nla_put_failure; return 0; From patchwork Sat Jan 23 19:59:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 12041917 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD3A6C433DB for ; Sat, 23 Jan 2021 20:08:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE49E22EBE for ; Sat, 23 Jan 2021 20:08:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726586AbhAWUHs (ORCPT ); Sat, 23 Jan 2021 15:07:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726334AbhAWUAJ (ORCPT ); Sat, 23 Jan 2021 15:00:09 -0500 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E607C0617AB for ; Sat, 23 Jan 2021 11:59:35 -0800 (PST) Received: by mail-lj1-x235.google.com with SMTP id f11so10521121ljm.8 for ; Sat, 23 Jan 2021 11:59:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2qm3Xf/zORcOQpWtLlmivgXe4uJE/D2V+lZIMUhUMIQ=; b=Err4PtLSUkFp4zv98VxIIz0YinhScNfFH/vnWUFXbBFsHDzwac782SPg5AMUbDmihi 4ctyJJYGODeR23SgWIydpiYmx6yLBq6lnmZ+LZ/UaYoBAXW/nY0zEpmutNRdgH9+BZwE GkAo6UBBsXKoGUy5Gy8wst7drHoSDF1zQv1ctUxWo4UrvJstM7+CNsH3myd2p2JdGqCY on2ZwpVgjZufUKf79WEvHX6regG/CNpS/GK43AQcvSPpH1X3vSgmUBfYY7QEDY9lO/3A f2TCYcpaXE1hpxfKJFXF0JY843W3GrZ37Cr5sPtJMGqsfMyoiymK6EJ/mnfB9TpnHIau QKew== 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:mime-version:content-transfer-encoding; bh=2qm3Xf/zORcOQpWtLlmivgXe4uJE/D2V+lZIMUhUMIQ=; b=tb9MRzP4K1XyiP6m5303SukoNDI4IcEQPVPogkn9Pmpaitg+Aax9qYBFFYWuiVBkf7 xGFXH9x4QxXEcwXuehSRaoaBUA8DyWi+sLqmmJBLNUJI65OWK7kv+7bMwju3LZ8LRKca M+0x6Sd3ObJptZsnxP6fK+jws0xv3DZ7d8IPf4T44KeryCADcbQp+xknfmjq6JryaMcY mY9uVPD3RJq8U5i+9nkAqUovpAR8kDYQ/ZAfc5/ZhzwKBKFiaU9GkVJLuz0nHvrXYQ7m Axq7APMc1jHYB8RYUCmq5bMF74hkzrqYpkbQ94N7aTrvsVFsFbUv4lWEU6m2ecM/I9lc 8EDw== X-Gm-Message-State: AOAM533o2vR7/pUnGpn74cNkQxnGfX/wA8/ZObWKSFsSi1eNmLfTN1mD 9kPDKRDZT/1p+5V74AU2dI905Q== X-Google-Smtp-Source: ABdhPJwO0/aWCoAoKbhOm269ZIxIUozevsO4mFtZ8DmcMnJFh8x12bW8pg8Oamv4w/dX7hvMQh5jVQ== X-Received: by 2002:a2e:3317:: with SMTP id d23mr1361692ljc.199.1611431973876; Sat, 23 Jan 2021 11:59:33 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id f9sm1265177lft.114.2021.01.23.11.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 11:59:33 -0800 (PST) From: Jonas Bonn To: laforge@gnumonks.org, netdev@vger.kernel.org, pbshelar@fb.com, kuba@kernel.org Cc: pablo@netfilter.org, Jonas Bonn Subject: [RFC PATCH 04/16] gtp: really check namespaces before xmit Date: Sat, 23 Jan 2021 20:59:04 +0100 Message-Id: <20210123195916.2765481-5-jonas@norrbonn.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210123195916.2765481-1-jonas@norrbonn.se> References: <20210123195916.2765481-1-jonas@norrbonn.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Blindly assuming that packet transmission crosses namespaces results in skb marks being lost in the single namespace case. Signed-off-by: Jonas Bonn Acked-by: Harald Welte --- drivers/net/gtp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 5682d3ba7aa5..e4e57c0552ee 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -592,7 +592,9 @@ static netdev_tx_t gtp_dev_xmit(struct sk_buff *skb, struct net_device *dev) ip4_dst_hoplimit(&pktinfo.rt->dst), 0, pktinfo.gtph_port, pktinfo.gtph_port, - true, false); + !net_eq(sock_net(pktinfo.pctx->sk), + dev_net(dev)), + false); break; } From patchwork Sat Jan 23 19:59:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 12041895 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43B65C433E0 for ; Sat, 23 Jan 2021 20:05:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06E4522D50 for ; Sat, 23 Jan 2021 20:05:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726459AbhAWUCE (ORCPT ); Sat, 23 Jan 2021 15:02:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726386AbhAWUAg (ORCPT ); Sat, 23 Jan 2021 15:00:36 -0500 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EA59C061351 for ; Sat, 23 Jan 2021 11:59:36 -0800 (PST) Received: by mail-lf1-x134.google.com with SMTP id f1so2489727lfu.3 for ; Sat, 23 Jan 2021 11:59:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F4sC//ZgGUmA9NlrM63F0I/xBsCDk3tlcYvven7F4F8=; b=GoAI0A7oyGNiY9AZQjHaFeUnYvLxXuknAG31fBdsQuTVvs7rBN2BNUBFMlsQMyDDMI NGfx5bVF4PPTDGWYguMmZa++/B0qIeJRwO18Ge/c4IFH+B/nuUKQ7eJA+zeFKicjG9YL ZXdZTLPJ+FxZELCue3BZiya+MibT+SQC2o0O69u5nIVfwegjNpxjCAlCnXfp1gTJsX7z t7cMy49eP/agfL1sSj5IsvIZhGC0O6xgeEuECPCXjYc5WcBOKjhwbojl4xur4AWd5DHI FFnvZkxAlazuCj580485te/GlFrbfr0X8H03CZ1RgVQdkPw/PHGsAdavJOhj73ioVMtO rxAA== 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:mime-version:content-transfer-encoding; bh=F4sC//ZgGUmA9NlrM63F0I/xBsCDk3tlcYvven7F4F8=; b=ipJWjA5aCIokvWPmNMS+BHlksFGWr70S9hAoWRMi/dJcSTfKgxjjCww638z+5aEUWj +vfuhrMo42T4zR3nxFLGRtZVgpHiKoDdVtROWiNSCvaHEG1ir7yGrEmGalACaCDYbyJ9 /wuJatt4cIBwUGEnuQ1LpRt5PnmYaFW5Z5oNKPLg3lD/nI+TlAhLe85srZav2BNRvJzo EXJLI6xhQ+SmFRLBtiZQTiYvLp/9KL/VeAfWrlfK/GCzLXcLu8rTb7pr7PHscq9zc6G1 6M+CZ8Unf2fJ+AIY0MVr0JOB8QyJjHP29vN6XxAWBEhdxcx+soAUHZYS+wM/kvxZINAX q49w== X-Gm-Message-State: AOAM533YiTkjkNA4WwWH4+UdlvzTvtyL01YCpSb6Wo3nWxhsMoQUFmYM IVI2D/ydQ3CGNnU+tlUsnRrjZQ== X-Google-Smtp-Source: ABdhPJzD2voNSbCbLvnNC5Tt1tXWHox80PeGJ4A0aAtPQlHJoeJkYUSu6uyhuaDR7l+RtMHWkVq3HA== X-Received: by 2002:a05:6512:398a:: with SMTP id j10mr897450lfu.167.1611431974692; Sat, 23 Jan 2021 11:59:34 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id f9sm1265177lft.114.2021.01.23.11.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 11:59:34 -0800 (PST) From: Jonas Bonn To: laforge@gnumonks.org, netdev@vger.kernel.org, pbshelar@fb.com, kuba@kernel.org Cc: pablo@netfilter.org, Jonas Bonn Subject: [RFC PATCH 05/16] gtp: drop unnecessary call to skb_dst_drop Date: Sat, 23 Jan 2021 20:59:05 +0100 Message-Id: <20210123195916.2765481-6-jonas@norrbonn.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210123195916.2765481-1-jonas@norrbonn.se> References: <20210123195916.2765481-1-jonas@norrbonn.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The call to skb_dst_drop() is already done as part of udp_tunnel_xmit(). Signed-off-by: Jonas Bonn Acked-by: Harald Welte --- drivers/net/gtp.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index e4e57c0552ee..04d9de385549 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -515,8 +515,6 @@ static int gtp_build_skb_ip4(struct sk_buff *skb, struct net_device *dev, goto err_rt; } - skb_dst_drop(skb); - /* This is similar to tnl_update_pmtu(). */ df = iph->frag_off; if (df) { From patchwork Sat Jan 23 19:59:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 12041915 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03A33C433E0 for ; Sat, 23 Jan 2021 20:07:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C1AB622EBE for ; Sat, 23 Jan 2021 20:07:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726131AbhAWUH3 (ORCPT ); Sat, 23 Jan 2021 15:07:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726344AbhAWUAK (ORCPT ); Sat, 23 Jan 2021 15:00:10 -0500 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D541CC061352 for ; Sat, 23 Jan 2021 11:59:36 -0800 (PST) Received: by mail-lf1-x12c.google.com with SMTP id a12so4174572lfb.1 for ; Sat, 23 Jan 2021 11:59:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uEnUir7NULfyhfcHWwSmbaRoX9scIfA0jMqc4I/U48c=; b=h3lQ6MBNS4WgT2lmfNMoja3+Qw8J006XBzugSTcBp/oVp7aT4CO4IFYnWfL/AZgwK+ JA10LGgvOsbAAWRLUHulSocCYqKxaO++lAWrpcsLvL7Kta9TtlgNaehV9Y4Hs9WmU0Fc NGnJ4Jfjomhh8fg8DLPXV1SqyYaCwbO/GcZJ+xAX/cnh8KeKyMx4G3dPPGGRTZ7dLMrg onl3DZdc92KBUztOqV69iWQEx2vp874U73mXyAonLcKGTU528jt3tcRlEseYhfojWVyX OqySyplJiV2u55xMR6g4MAqgbkPCvxHYWfC9ijdZ9eTChjSL70llNYPwcB6fnAdkYvQM UQtg== 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:mime-version:content-transfer-encoding; bh=uEnUir7NULfyhfcHWwSmbaRoX9scIfA0jMqc4I/U48c=; b=lfrWgNmXVRnat9B0bhQcs7BzFZoMUvEVuAbw2jJJ96nKWert3owfwUieDYT4aiDexD scC178u75rlRlsmq0pIPTrSzY9r/bRamCjeCXpZgAO5tAwpkFm8tnexM+nILx+Ur2EKh 79acpY9zTpfLEIEOuVYrf9NHmleY25Pva39hs/ESIDOx7mgE8Ov+ChHqDKfqaKLcvgNK FMOAPeYz+qbJS92wmYxqvUpDy73Id28b1EkOVphEnCe51+577V8ZEa1JU8WnndXu0eAI L7FfCSKNyCwkSqvUFzf5PWNikVEX9z6526sRIecx77W1tF9fbbmVyvTIUc4UYvxomx1X y+jA== X-Gm-Message-State: AOAM531a95DsKkvsRLq6kUcPx3z/xIpLmBZ5iT/0w4uDp3AeT9sf9+rL zbEonq9ezToI/yyFmoksjo5NYg== X-Google-Smtp-Source: ABdhPJxvI1aq1vDb3qCkPy4oM7pt7fHt3Smc62p4LxFBgS2IQH5xo2NWcrblHvSnabELp/jbmC+kpA== X-Received: by 2002:a19:1d8:: with SMTP id 207mr1702988lfb.54.1611431975453; Sat, 23 Jan 2021 11:59:35 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id f9sm1265177lft.114.2021.01.23.11.59.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 11:59:35 -0800 (PST) From: Jonas Bonn To: laforge@gnumonks.org, netdev@vger.kernel.org, pbshelar@fb.com, kuba@kernel.org Cc: pablo@netfilter.org, Jonas Bonn Subject: [RFC PATCH 06/16] gtp: set device type Date: Sat, 23 Jan 2021 20:59:06 +0100 Message-Id: <20210123195916.2765481-7-jonas@norrbonn.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210123195916.2765481-1-jonas@norrbonn.se> References: <20210123195916.2765481-1-jonas@norrbonn.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Set the devtype to 'gtp' when setting up the link. Signed-off-by: Jonas Bonn Acked-by: Harald Welte --- drivers/net/gtp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 04d9de385549..a1bb02818977 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -610,6 +610,10 @@ static const struct net_device_ops gtp_netdev_ops = { .ndo_get_stats64 = dev_get_tstats64, }; +static const struct device_type gtp_type = { + .name = "gtp", +}; + static void gtp_link_setup(struct net_device *dev) { unsigned int max_gtp_header_len = sizeof(struct iphdr) + @@ -618,6 +622,7 @@ static void gtp_link_setup(struct net_device *dev) dev->netdev_ops = >p_netdev_ops; dev->needs_free_netdev = true; + SET_NETDEV_DEVTYPE(dev, >p_type); dev->hard_header_len = 0; dev->addr_len = 0; From patchwork Sat Jan 23 19:59:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 12041885 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6907C433E0 for ; Sat, 23 Jan 2021 20:02:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B478722D2B for ; Sat, 23 Jan 2021 20:02:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725765AbhAWUBv (ORCPT ); Sat, 23 Jan 2021 15:01:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726388AbhAWUAg (ORCPT ); Sat, 23 Jan 2021 15:00:36 -0500 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B331AC061353 for ; Sat, 23 Jan 2021 11:59:37 -0800 (PST) Received: by mail-lf1-x133.google.com with SMTP id m22so12314807lfg.5 for ; Sat, 23 Jan 2021 11:59:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J2qbl8+PQmeLyZfcgsn0UGIJs64aBXhfNs1G+gzOFeE=; b=1Ud6hvg3A/pK14NfV5hTPTcyN2GSwBlEAsZ2QGg1daq5RIfeqVPX6HoovvWfAZ5gFa CMmxkg4wubEohvEebzny2CfwtQVFA7npfrgeyoRKfCGSrLuUYSr1hMIcFVBH0Ogm1jCY adiUSXMB36TOKSHb+PtU68UmkrS0bNnuRgMzHb7dlkfgh7wFXqay80GRn2uh/nEv9tGa zQVclUmK1boO09QjhO0M7K+sTIdz+/5ScuydbGTUH2cn7v0qj/zlXD2N23gXmAg5sDYY Vo/K+Vm5q1CetmMzIsXeesIN3/fbIi3ErDISuO8wtdAb7c7OSrUKhZSnmNzkpsUw7n4l tlog== 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:mime-version:content-transfer-encoding; bh=J2qbl8+PQmeLyZfcgsn0UGIJs64aBXhfNs1G+gzOFeE=; b=O4oG2rYjFVIMKw8/8ine2WE4pdiYB9BUW1yJATTEYNfLUZ3VRxPQ2xHbuNa5FyzqL6 jqkiYecxGT2dfwf/X0p5n8c6Vj7NRQUDjbu33WC8kTsUfk1KDGCEvVPyUBr4xQFzszaF ev7mamsa3uWulcWZHYq9l7FSbSWCvJfQRxV+NmqB0QekPca51/Fmu9EHQfKr9W5ZBVLh r//Z57NkccCea6xE/4XY7qMEg6mFpI6MAQDViPVNoPMef/FAF+XX4n8UaBUOgYwgXNiT +r8RIk5xMiTCjvGO0f4GXjBRKAES1yB3EE7OGJ4+aMnJ8VJWdqWFnTuZdH2YWJSgwvxu 7yyw== X-Gm-Message-State: AOAM530pZZecu6+q/98LLBUPLz0VYmwounBSvVCECxhNkGqRkI2pUg/3 rUBxFTIuu8DxIYqtAEW2rfPBrVlDKlqQlw== X-Google-Smtp-Source: ABdhPJycpNILlHBBeihyG/7NGXlyqGa7qcsB/cAIDimezP/CUD1BSOMObgq8edCK93FZkpQNGgA1IA== X-Received: by 2002:a05:6512:54d:: with SMTP id h13mr21383lfl.181.1611431976190; Sat, 23 Jan 2021 11:59:36 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id f9sm1265177lft.114.2021.01.23.11.59.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 11:59:35 -0800 (PST) From: Jonas Bonn To: laforge@gnumonks.org, netdev@vger.kernel.org, pbshelar@fb.com, kuba@kernel.org Cc: pablo@netfilter.org, Jonas Bonn Subject: [RFC PATCH 07/16] gtp: rework IPv4 functionality Date: Sat, 23 Jan 2021 20:59:07 +0100 Message-Id: <20210123195916.2765481-8-jonas@norrbonn.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210123195916.2765481-1-jonas@norrbonn.se> References: <20210123195916.2765481-1-jonas@norrbonn.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This patch does some cleanup work in the IPv4 functionality to lay the groundwork for adding support for IPv6. The form of these changes is largely borrowed from the bareudp and geneve drivers, so there shouldn't be anything here that looks unnecessarily unfamiliar. Signed-off-by: Jonas Bonn --- drivers/net/gtp.c | 204 +++++++++++++++++++++------------------------- 1 file changed, 92 insertions(+), 112 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index a1bb02818977..4a3a52970856 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -381,18 +382,36 @@ static void gtp_dev_uninit(struct net_device *dev) free_percpu(dev->tstats); } -static struct rtable *ip4_route_output_gtp(struct flowi4 *fl4, - const struct sock *sk, - __be32 daddr) +static struct rtable *gtp_get_v4_rt(struct sk_buff *skb, + struct net_device *dev, + struct pdp_ctx *pctx, + __be32 *saddr) { - memset(fl4, 0, sizeof(*fl4)); - fl4->flowi4_oif = sk->sk_bound_dev_if; - fl4->daddr = daddr; - fl4->saddr = inet_sk(sk)->inet_saddr; - fl4->flowi4_tos = RT_CONN_FLAGS(sk); - fl4->flowi4_proto = sk->sk_protocol; - - return ip_route_output_key(sock_net(sk), fl4); + const struct sock *sk = pctx->sk; + struct rtable *rt = NULL; + struct flowi4 fl4; + + memset(&fl4, 0, sizeof(fl4)); + fl4.flowi4_oif = sk->sk_bound_dev_if; + fl4.daddr = pctx->peer_addr_ip4.s_addr; + fl4.saddr = inet_sk(sk)->inet_saddr; + fl4.flowi4_tos = RT_CONN_FLAGS(sk); + fl4.flowi4_proto = sk->sk_protocol; + + rt = ip_route_output_key(sock_net(sk), &fl4); + if (IS_ERR(rt)) { + netdev_dbg(pctx->dev, "no route to %pI4\n", &fl4.daddr); + return ERR_PTR(-ENETUNREACH); + } + if (rt->dst.dev == dev) { + netdev_dbg(pctx->dev, "circular route to %pI4\n", &fl4.daddr); + ip_rt_put(rt); + return ERR_PTR(-ELOOP); + } + + *saddr = fl4.saddr; + + return rt; } static inline void gtp0_push_header(struct sk_buff *skb, struct pdp_ctx *pctx) @@ -435,54 +454,31 @@ static inline void gtp1_push_header(struct sk_buff *skb, struct pdp_ctx *pctx) */ } -struct gtp_pktinfo { - struct sock *sk; - struct iphdr *iph; - struct flowi4 fl4; - struct rtable *rt; - struct pdp_ctx *pctx; - struct net_device *dev; - __be16 gtph_port; -}; - -static void gtp_push_header(struct sk_buff *skb, struct gtp_pktinfo *pktinfo) +static void gtp_push_header(struct sk_buff *skb, struct pdp_ctx *pctx, + __be16 *port) { - switch (pktinfo->pctx->gtp_version) { + switch (pctx->gtp_version) { case GTP_V0: - pktinfo->gtph_port = htons(GTP0_PORT); - gtp0_push_header(skb, pktinfo->pctx); + *port = htons(GTP0_PORT); + gtp0_push_header(skb, pctx); break; case GTP_V1: - pktinfo->gtph_port = htons(GTP1U_PORT); - gtp1_push_header(skb, pktinfo->pctx); + *port = htons(GTP1U_PORT); + gtp1_push_header(skb, pctx); break; } } -static inline void gtp_set_pktinfo_ipv4(struct gtp_pktinfo *pktinfo, - struct sock *sk, struct iphdr *iph, - struct pdp_ctx *pctx, struct rtable *rt, - struct flowi4 *fl4, - struct net_device *dev) -{ - pktinfo->sk = sk; - pktinfo->iph = iph; - pktinfo->pctx = pctx; - pktinfo->rt = rt; - pktinfo->fl4 = *fl4; - pktinfo->dev = dev; -} - -static int gtp_build_skb_ip4(struct sk_buff *skb, struct net_device *dev, - struct gtp_pktinfo *pktinfo) +static int gtp_xmit_ip4(struct sk_buff *skb, struct net_device *dev) { struct gtp_dev *gtp = netdev_priv(dev); struct pdp_ctx *pctx; struct rtable *rt; - struct flowi4 fl4; + __be32 saddr; struct iphdr *iph; - __be16 df; - int mtu; + int headroom; + __be16 port; + int r; /* Read the IP destination address and resolve the PDP context. * Prepend PDP header with TEI/TID from PDP ctx. @@ -500,102 +496,86 @@ static int gtp_build_skb_ip4(struct sk_buff *skb, struct net_device *dev, } netdev_dbg(dev, "found PDP context %p\n", pctx); - rt = ip4_route_output_gtp(&fl4, pctx->sk, pctx->peer_addr_ip4.s_addr); + rt = gtp_get_v4_rt(skb, dev, pctx, &saddr); if (IS_ERR(rt)) { - netdev_dbg(dev, "no route to SSGN %pI4\n", - &pctx->peer_addr_ip4.s_addr); - dev->stats.tx_carrier_errors++; - goto err; + if (PTR_ERR(rt) == -ENETUNREACH) + dev->stats.tx_carrier_errors++; + else if (PTR_ERR(rt) == -ELOOP) + dev->stats.collisions++; + return PTR_ERR(rt); } - if (rt->dst.dev == dev) { - netdev_dbg(dev, "circular route to SSGN %pI4\n", - &pctx->peer_addr_ip4.s_addr); - dev->stats.collisions++; - goto err_rt; - } + headroom = sizeof(struct iphdr) + sizeof(struct udphdr); - /* This is similar to tnl_update_pmtu(). */ - df = iph->frag_off; - if (df) { - mtu = dst_mtu(&rt->dst) - dev->hard_header_len - - sizeof(struct iphdr) - sizeof(struct udphdr); - switch (pctx->gtp_version) { - case GTP_V0: - mtu -= sizeof(struct gtp0_header); - break; - case GTP_V1: - mtu -= sizeof(struct gtp1_header); - break; - } - } else { - mtu = dst_mtu(&rt->dst); + switch (pctx->gtp_version) { + case GTP_V0: + headroom += sizeof(struct gtp0_header); + break; + case GTP_V1: + headroom += sizeof(struct gtp1_header); + break; } - rt->dst.ops->update_pmtu(&rt->dst, NULL, skb, mtu, false); + r = skb_tunnel_check_pmtu(skb, &rt->dst, headroom, + netif_is_any_bridge_port(dev)); + if (r < 0) { + ip_rt_put(rt); + return r; + } else if (r) { + netif_rx(skb); + ip_rt_put(rt); + return -EMSGSIZE; + } - if (!skb_is_gso(skb) && (iph->frag_off & htons(IP_DF)) && - mtu < ntohs(iph->tot_len)) { - netdev_dbg(dev, "packet too big, fragmentation needed\n"); - memset(IPCB(skb), 0, sizeof(*IPCB(skb))); - icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, - htonl(mtu)); + /* Ensure there is sufficient headroom. */ + r = skb_cow_head(skb, headroom); + if (unlikely(r)) goto err_rt; - } - gtp_set_pktinfo_ipv4(pktinfo, pctx->sk, iph, pctx, rt, &fl4, dev); - gtp_push_header(skb, pktinfo); + skb_reset_inner_headers(skb); + + gtp_push_header(skb, pctx, &port); + + iph = ip_hdr(skb); + netdev_dbg(dev, "gtp -> IP src: %pI4 dst: %pI4\n", + &iph->saddr, &iph->daddr); + + udp_tunnel_xmit_skb(rt, pctx->sk, skb, + saddr, pctx->peer_addr_ip4.s_addr, + iph->tos, + ip4_dst_hoplimit(&rt->dst), + 0, + port, port, + !net_eq(sock_net(pctx->sk), + dev_net(pctx->dev)), + false); return 0; err_rt: ip_rt_put(rt); -err: return -EBADMSG; } static netdev_tx_t gtp_dev_xmit(struct sk_buff *skb, struct net_device *dev) { unsigned int proto = ntohs(skb->protocol); - struct gtp_pktinfo pktinfo; int err; - /* Ensure there is sufficient headroom. */ - if (skb_cow_head(skb, dev->needed_headroom)) + if (proto != ETH_P_IP && proto != ETH_P_IPV6) { + err = -ENOTSUPP; goto tx_err; - - skb_reset_inner_headers(skb); + } /* PDP context lookups in gtp_build_skb_*() need rcu read-side lock. */ rcu_read_lock(); - switch (proto) { - case ETH_P_IP: - err = gtp_build_skb_ip4(skb, dev, &pktinfo); - break; - default: - err = -EOPNOTSUPP; - break; - } + + err = gtp_xmit_ip4(skb, dev); + rcu_read_unlock(); if (err < 0) goto tx_err; - switch (proto) { - case ETH_P_IP: - netdev_dbg(pktinfo.dev, "gtp -> IP src: %pI4 dst: %pI4\n", - &pktinfo.iph->saddr, &pktinfo.iph->daddr); - udp_tunnel_xmit_skb(pktinfo.rt, pktinfo.sk, skb, - pktinfo.fl4.saddr, pktinfo.fl4.daddr, - pktinfo.iph->tos, - ip4_dst_hoplimit(&pktinfo.rt->dst), - 0, - pktinfo.gtph_port, pktinfo.gtph_port, - !net_eq(sock_net(pktinfo.pctx->sk), - dev_net(dev)), - false); - break; - } - return NETDEV_TX_OK; tx_err: dev->stats.tx_errors++; From patchwork Sat Jan 23 19:59:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 12041913 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 750D4C433DB for ; Sat, 23 Jan 2021 20:07:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 41B3022D50 for ; Sat, 23 Jan 2021 20:07:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726439AbhAWUHO (ORCPT ); Sat, 23 Jan 2021 15:07:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726355AbhAWUAM (ORCPT ); Sat, 23 Jan 2021 15:00:12 -0500 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A85EC061356 for ; Sat, 23 Jan 2021 11:59:38 -0800 (PST) Received: by mail-lf1-x132.google.com with SMTP id q8so12291039lfm.10 for ; Sat, 23 Jan 2021 11:59:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7DFWD5qel0j71Y8L6cBxsrwCWoQdL04CuvfzZDaeHcM=; b=yvQ4uXsDAYfBJkqlT3MyUl0ZBWVUe01nRz+N1+GR2Q9k5tOy+KLft+1CmVfGwETzk8 CnU5ppyuQkrPRCE506yn5BR+SNXxMH9AZJ3rgriBKF73227uHGz3t7hasIGg5xacFwqt NONIsukcXXFamEDgk23K8GVYMo+6ERkao3tiLcExrIA3ysTfg9zNU+kVCoR1l+EjBU39 GsNLdcCdsFOi7fMbvOd4NsX+gD6uRoKB950DfZcoHHN7FoMj8sD0plIK6EDQb2gfoGwB flKw+AwBAMeHzssduzH6yVov90Y7A8bD61n3gXvlHttpgIMlVj4IV9QeCRTDT34CiOJd Wj8Q== 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:mime-version:content-transfer-encoding; bh=7DFWD5qel0j71Y8L6cBxsrwCWoQdL04CuvfzZDaeHcM=; b=bxj/iZEAa0NbL8+yVUs0AgPa92REEvu9lQMuM4hmKz5QIPzoZU5IETh+VyodfLHywz k+pagXEkZVfsknf11SM5/Zmr0aPRpNTI6QQrvPMcvRgmEHY/S2M7BnHjCHb7KkYmzoRP y6emZZN8q8olQXFo8AHhyMT1HXDpXUNLMLL2yE+bwl6d9OhOP/IVgAsGP2utkOz1nRYz E/QFdvupRBpAXZmBn1EeLbeYX8Y5zPj/uhAnljrcOcCKeiUNFFFrxMuE+/loPZzsIhRe yOuMVlJFVWqXsj3Sy4wDNO97haNHH4Hco3PkzetI5WvfQ9UeidcLJfbDDUaYmnHp9XfP lu0Q== X-Gm-Message-State: AOAM533G0TzzOuozH2gNJDoqFbYR8KPrbHzsbX9DJOiqWJ/s5UKbujcU GJf6ZvqRW64EzXOAdKSajdatng== X-Google-Smtp-Source: ABdhPJwiJKhcP2K7kCf+vgV44yBD/7o0EmM5/7HcAQKxjsHM7IE6QOJ1m8h9RqJohY1x4I/O9cCnnQ== X-Received: by 2002:a05:6512:3157:: with SMTP id s23mr29733lfi.275.1611431976944; Sat, 23 Jan 2021 11:59:36 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id f9sm1265177lft.114.2021.01.23.11.59.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 11:59:36 -0800 (PST) From: Jonas Bonn To: laforge@gnumonks.org, netdev@vger.kernel.org, pbshelar@fb.com, kuba@kernel.org Cc: pablo@netfilter.org, Jonas Bonn Subject: [RFC PATCH 08/16] gtp: set dev features to enable GSO Date: Sat, 23 Jan 2021 20:59:08 +0100 Message-Id: <20210123195916.2765481-9-jonas@norrbonn.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210123195916.2765481-1-jonas@norrbonn.se> References: <20210123195916.2765481-1-jonas@norrbonn.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Signed-off-by: Jonas Bonn --- drivers/net/gtp.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 4a3a52970856..df2f227680eb 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -532,7 +532,11 @@ static int gtp_xmit_ip4(struct sk_buff *skb, struct net_device *dev) if (unlikely(r)) goto err_rt; - skb_reset_inner_headers(skb); + r = udp_tunnel_handle_offloads(skb, true); + if (unlikely(r)) + goto err_rt; + + skb_set_inner_protocol(skb, skb->protocol); gtp_push_header(skb, pctx, &port); @@ -614,6 +618,8 @@ static void gtp_link_setup(struct net_device *dev) dev->priv_flags |= IFF_NO_QUEUE; dev->features |= NETIF_F_LLTX; + dev->hw_features |= NETIF_F_SG | NETIF_F_GSO_SOFTWARE | NETIF_F_HW_CSUM; + dev->features |= NETIF_F_SG | NETIF_F_GSO_SOFTWARE | NETIF_F_HW_CSUM; netif_keep_dst(dev); dev->needed_headroom = LL_MAX_HEADER + max_gtp_header_len; From patchwork Sat Jan 23 19:59:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 12041889 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4251AC433DB for ; Sat, 23 Jan 2021 20:03:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0814522B40 for ; Sat, 23 Jan 2021 20:03:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726485AbhAWUCb (ORCPT ); Sat, 23 Jan 2021 15:02:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726400AbhAWUAh (ORCPT ); Sat, 23 Jan 2021 15:00:37 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 357E3C0612F2 for ; Sat, 23 Jan 2021 11:59:39 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id a12so4174675lfb.1 for ; Sat, 23 Jan 2021 11:59:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a8roDgMj60xDlpj02wthqVGznMg0XPB6yLR44gW6uag=; b=mnU5eSeuXztQNQc4us7Y8hWpWLm/mVw6c8Yg0nI1Y+mv8rIxSJMX/ux3R1lGy21Yw8 bnkXNibmhluLDIjlZa0ugmT26WdS8dqlRovC/C7LZmdiO/doJEy8l8h0emnqqXbmwF04 WC8TgcxQoKlGspNPufd0CnJcjdFOaYWr6jEROJDbjp24sZt5/atw4jlc5kxD8JEA6Rlk Y3T6oHm6Z0uW6AKKbf1ooNdMwyNA4EFA34336sGblgouIQFUJ0G9oNB38oKR9StAQYEy 3PBzIz/NPMaTmA4GVeVmfWqm4rvYDi+ZoUuUYO9A48muTAo+8gS5XcSEuTnkZyTonlk+ 2KcQ== 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:mime-version:content-transfer-encoding; bh=a8roDgMj60xDlpj02wthqVGznMg0XPB6yLR44gW6uag=; b=pDgloct/b/DVxuj5X51ARn90uKBd2BvhamgKpN3Q97QhpC57Rimtx/QKgWNQs3Py73 p2k9y7//kKedufztsvRm7TyvguaC3DaNRCIR3E2GhW49MRwsOu0W5GIve9NChSFsmV0q YR1Q0+xUbwIr6h1HWThx+Boy6zWYWfnJIo2X4gK4RHQtFNKIJVHG9246u8OdmWB5srx9 Wocx9P6qlmeeYAN6qEz+l9Xe3LvDGvVTr10/6HYfX7MZmrDM2FKMCVYNSuFozzTCcXDN 2lhEOqLA+3zOmnfVsgWRcD72MZKYTdbg43eEqoHkmYshJ9+lVfzBZvyHXCj25TUJnsxC YajA== X-Gm-Message-State: AOAM533qmdle2Was92LMpLkOSi1FHdFvj55fahHPH4qNVtte/T2Q3JbK /ySxLrmXBDX1+Pvl7vYRfwEreD45/jGu5Q== X-Google-Smtp-Source: ABdhPJz9NeIchUOQQsGVcMHEI51iAkVA3lxTRLRXbf6m8q8Q5RHzzRVYz1H3QHy6u3fXwOSXhXGa3g== X-Received: by 2002:a19:d07:: with SMTP id 7mr526160lfn.215.1611431977777; Sat, 23 Jan 2021 11:59:37 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id f9sm1265177lft.114.2021.01.23.11.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 11:59:37 -0800 (PST) From: Jonas Bonn To: laforge@gnumonks.org, netdev@vger.kernel.org, pbshelar@fb.com, kuba@kernel.org Cc: pablo@netfilter.org, Jonas Bonn Subject: [RFC PATCH 09/16] gtp: support GRO Date: Sat, 23 Jan 2021 20:59:09 +0100 Message-Id: <20210123195916.2765481-10-jonas@norrbonn.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210123195916.2765481-1-jonas@norrbonn.se> References: <20210123195916.2765481-1-jonas@norrbonn.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This patch implements GRO callbacks for UDP-tunneled GTP traffic. iperf3 numbers Without GRO for GTP tunnels: Accepted connection from 172.99.2.1, port 48783 [ 5] local 172.99.0.1 port 5201 connected to 172.99.2.1 port 46095 [ ID] Interval Transfer Bitrate [ 5] 0.00-1.00 sec 563 MBytes 576306 KBytes/sec [ 5] 1.00-2.00 sec 681 MBytes 697814 KBytes/sec [ 5] 2.00-3.00 sec 677 MBytes 693612 KBytes/sec [ 5] 3.00-4.00 sec 679 MBytes 695690 KBytes/sec [ 5] 4.00-5.00 sec 683 MBytes 699521 KBytes/sec [ 5] 5.00-6.00 sec 682 MBytes 698922 KBytes/sec [ 5] 6.00-7.00 sec 683 MBytes 699820 KBytes/sec [ 5] 7.00-8.00 sec 682 MBytes 698052 KBytes/sec [ 5] 8.00-9.00 sec 683 MBytes 699245 KBytes/sec [ 5] 9.00-10.00 sec 683 MBytes 699554 KBytes/sec [ 5] 10.00-10.00 sec 616 KBytes 687914 KBytes/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bitrate [ 5] 0.00-10.00 sec 6.54 GBytes 685853 KBytes/sec receiver With GRO for GTP tunnels: Accepted connection from 172.99.2.1, port 40847 [ 5] local 172.99.0.1 port 5201 connected to 172.99.2.1 port 55053 [ ID] Interval Transfer Bitrate [ 5] 0.00-1.00 sec 989 MBytes 1012640 KBytes/sec [ 5] 1.00-2.00 sec 1.23 GBytes 1291408 KBytes/sec [ 5] 2.00-3.00 sec 1.26 GBytes 1320197 KBytes/sec [ 5] 3.00-4.00 sec 1.29 GBytes 1350097 KBytes/sec [ 5] 4.00-5.00 sec 1.23 GBytes 1284512 KBytes/sec [ 5] 5.00-6.00 sec 1.26 GBytes 1326329 KBytes/sec [ 5] 6.00-7.00 sec 1.28 GBytes 1338620 KBytes/sec [ 5] 7.00-8.00 sec 1.28 GBytes 1346391 KBytes/sec [ 5] 8.00-9.00 sec 1.30 GBytes 1366394 KBytes/sec [ 5] 9.00-10.00 sec 1.26 GBytes 1323848 KBytes/sec [ 5] 10.00-10.00 sec 384 KBytes 1113043 KBytes/sec - - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bitrate [ 5] 0.00-10.00 sec 12.4 GBytes 1296036 KBytes/sec receiver Signed-off-by: Jonas Bonn --- drivers/net/gtp.c | 126 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index df2f227680eb..b20e17988bfa 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -361,6 +361,128 @@ static int gtp_encap_recv(struct sock *sk, struct sk_buff *skb) return ret; } +static int gtp_gro_complete(struct sock *sk, struct sk_buff * skb, int nhoff) +{ + size_t hdrlen; + char* gtphdr = skb->data + nhoff; + u8 version; + __be16 type; + struct packet_offload *ptype; + uint8_t ipver; + int err = -ENOENT; + + version = *gtphdr >> 5; + switch (version) { + case GTP_V0: + hdrlen = sizeof(struct gtp0_header); + break; + case GTP_V1: + hdrlen = sizeof(struct gtp1_header); + if (*gtphdr & GTP1_F_MASK) + hdrlen += 4; + break; + } + + skb_set_inner_network_header(skb, nhoff + hdrlen); + + ipver = inner_ip_hdr(skb)->version; + switch (ipver) { + case 4: + type = cpu_to_be16(ETH_P_IP); + break; + case 6: + type = cpu_to_be16(ETH_P_IPV6); + break; + default: + goto out; + } + + rcu_read_lock(); + ptype = gro_find_complete_by_type(type); + if (!ptype) + goto out_unlock; + + err = ptype->callbacks.gro_complete(skb, nhoff + hdrlen); + + skb_set_inner_mac_header(skb, nhoff + hdrlen); + +out_unlock: + rcu_read_unlock(); +out: + + return err; + +} + +static struct sk_buff *gtp_gro_receive(struct sock *sk, + struct list_head *head, + struct sk_buff *skb) +{ + size_t off, hdrlen; + char* gtphdr; + u8 version; + struct sk_buff *pp = NULL; + __be16 type; + struct packet_offload *ptype; + + off = skb_gro_offset(skb); + + gtphdr = skb_gro_header_fast(skb, off); + if (skb_gro_header_hard(skb, off+1)) { + gtphdr = skb_gro_header_slow(skb, off+1, off); + if (unlikely(!gtphdr)) + goto out; + } + + version = *gtphdr >> 5; + switch (version) { + case GTP_V0: + hdrlen = sizeof(struct gtp0_header); + break; + case GTP_V1: + hdrlen = sizeof(struct gtp1_header); + if (*gtphdr & GTP1_F_MASK) + hdrlen += 4; + break; + } + + gtphdr = skb_gro_header_fast(skb, off); + if (skb_gro_header_hard(skb, off+hdrlen)) { + gtphdr = skb_gro_header_slow(skb, off+hdrlen, off); + if (unlikely(!gtphdr)) + goto out; + } + + skb_set_inner_network_header(skb, off + hdrlen); + + switch(inner_ip_hdr(skb)->version) { + case 4: + type = cpu_to_be16(ETH_P_IP); + break; + case 6: + type = cpu_to_be16(ETH_P_IPV6); + break; + default: + goto out; + } + + rcu_read_lock(); + ptype = gro_find_receive_by_type(type); + if (!ptype) + goto out_unlock; + + skb_gro_pull(skb, hdrlen); + skb_gro_postpull_rcsum(skb, gtphdr, hdrlen); + + pp = call_gro_receive(ptype->callbacks.gro_receive, head, skb); + +out_unlock: + rcu_read_unlock(); +out: + + return pp; +} + static int gtp_dev_init(struct net_device *dev) { struct gtp_dev *gtp = netdev_priv(dev); @@ -618,7 +740,9 @@ static void gtp_link_setup(struct net_device *dev) dev->priv_flags |= IFF_NO_QUEUE; dev->features |= NETIF_F_LLTX; + dev->hw_features |= NETIF_F_RXCSUM; dev->hw_features |= NETIF_F_SG | NETIF_F_GSO_SOFTWARE | NETIF_F_HW_CSUM; + dev->features |= NETIF_F_RXCSUM; dev->features |= NETIF_F_SG | NETIF_F_GSO_SOFTWARE | NETIF_F_HW_CSUM; netif_keep_dst(dev); @@ -814,6 +938,8 @@ static struct sock *gtp_encap_enable_socket(int fd, int type, tuncfg.encap_type = type; tuncfg.encap_rcv = gtp_encap_recv; tuncfg.encap_destroy = gtp_encap_destroy; + tuncfg.gro_receive = gtp_gro_receive; + tuncfg.gro_complete = gtp_gro_complete; setup_udp_tunnel_sock(sock_net(sock->sk), sock, &tuncfg); From patchwork Sat Jan 23 19:59:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 12041909 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A99BFC433E0 for ; Sat, 23 Jan 2021 20:06:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8304C23B1B for ; Sat, 23 Jan 2021 20:06:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726488AbhAWUGW (ORCPT ); Sat, 23 Jan 2021 15:06:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726361AbhAWUAN (ORCPT ); Sat, 23 Jan 2021 15:00:13 -0500 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FF8DC06121C for ; Sat, 23 Jan 2021 11:59:40 -0800 (PST) Received: by mail-lj1-x229.google.com with SMTP id f2so5337287ljp.11 for ; Sat, 23 Jan 2021 11:59:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=94fMBMJGVw8OxVT9BQu2sHrnWkzVR9OiBlBF0ObRZmc=; b=qdJcfhvIQmQasEM+UGe+wIw44nubzKflPLSmZZdpFeEXEhFDtWi2roQEm4cg9X+Xvs 8QVzJx9kteVzuHH18ZgIDR9hZ8PSyyUA4KJFevKpiGV1rtLDT5faWswk5UNcG2KG8Fpl 1qmgnthlpYFVY7e4+U4Ae4Tp1XGKnq/WCU4+vAXWfEZsUojNyf1szwvsU0YQbKIlS9Wn ylPdiON2IC/YMCCinAC4i4xKc2CeRy+rTETmcu3NymrYusZMWI1dIUIZyKH9nGTSFqr8 sJKEhVeoAdMNJm30lDYJYHkisrUqM4FBbAL3BfJvXomRStEy80h3tPK0zpS9E05YLwdc rplw== 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:mime-version:content-transfer-encoding; bh=94fMBMJGVw8OxVT9BQu2sHrnWkzVR9OiBlBF0ObRZmc=; b=UVGJptAsWKha+45leNeoXfP0sgwHZxu4UkMd1Li+H2LG1Ju1pQTwdg/frkaDtK8AfQ aYB6+nGLUFesLYDg7Skz3lYG5UZhYCviXtwXEQQaR4FlfwiB9Iz1FV3dACT/XqnudUcq aLWWFAa8nou/JXnIsr4CJCKeJctW0w55XClUjcdpsmd8OxV7TUDRE+SV0cV5Kf1dxtSw ZH4JTg94qccOLYguH8USbXVis+H7A4aL/S9WYk8WCZkiI5c2Q18Dir5S0OI8zxAqyVm8 BvYdViHZMO+SIa3xwz7LmXAJH4EXd2LiUGjaFJKLzSoDveHkE7LlE2Pm7n7tlDu3Nkbz RqIw== X-Gm-Message-State: AOAM532g4nBxei+XjGCnqT+VoSSEVr31gIZ30PDn4o/8CQj8GZW6AoBM pkoffG2o4fy4BQhhCTPzmeTm9e/dWlRBMg== X-Google-Smtp-Source: ABdhPJwml1Qi8gp5Gyd7yXCihBncHe4pg8Jb0YClets5i/umJ+5UAQ1N8pIw1l4cAaXzU4hVmlV/KQ== X-Received: by 2002:a2e:bc0c:: with SMTP id b12mr88003ljf.201.1611431978646; Sat, 23 Jan 2021 11:59:38 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id f9sm1265177lft.114.2021.01.23.11.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 11:59:38 -0800 (PST) From: Jonas Bonn To: laforge@gnumonks.org, netdev@vger.kernel.org, pbshelar@fb.com, kuba@kernel.org Cc: pablo@netfilter.org, Jonas Bonn Subject: [RFC PATCH 10/16] gtp: refactor check_ms back into version specific handlers Date: Sat, 23 Jan 2021 20:59:10 +0100 Message-Id: <20210123195916.2765481-11-jonas@norrbonn.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210123195916.2765481-1-jonas@norrbonn.se> References: <20210123195916.2765481-1-jonas@norrbonn.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This is preparatory work for adding flow based tunneling work by Pravin Shelar. Signed-off-by: Jonas Bonn --- drivers/net/gtp.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index b20e17988bfa..c42092bb505f 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -181,13 +181,8 @@ static bool gtp_check_ms(struct sk_buff *skb, struct pdp_ctx *pctx, } static int gtp_rx(struct pdp_ctx *pctx, struct sk_buff *skb, - unsigned int hdrlen, unsigned int role) + unsigned int hdrlen) { - if (!gtp_check_ms(skb, pctx, hdrlen, role)) { - netdev_dbg(pctx->dev, "No PDP ctx for this MS\n"); - return 1; - } - /* Get rid of the GTP + UDP headers. */ if (iptunnel_pull_header(skb, hdrlen, skb->protocol, !net_eq(sock_net(pctx->sk), dev_net(pctx->dev)))) @@ -234,7 +229,12 @@ static int gtp0_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb) return 1; } - return gtp_rx(pctx, skb, hdrlen, gtp->role); + if (!gtp_check_ms(skb, pctx, hdrlen, gtp->role)) { + netdev_dbg(pctx->dev, "No PDP ctx for this MS\n"); + return 1; + } + + return gtp_rx(pctx, skb, hdrlen); } static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb) @@ -276,7 +276,12 @@ static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb) return 1; } - return gtp_rx(pctx, skb, hdrlen, gtp->role); + if (!gtp_check_ms(skb, pctx, hdrlen, gtp->role)) { + netdev_dbg(pctx->dev, "No PDP ctx for this MS\n"); + return 1; + } + + return gtp_rx(pctx, skb, hdrlen); } static void __gtp_encap_destroy(struct sock *sk) From patchwork Sat Jan 23 19:59:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 12041891 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 399E0C433DB for ; Sat, 23 Jan 2021 20:04:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0159422DBF for ; Sat, 23 Jan 2021 20:04:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726532AbhAWUD6 (ORCPT ); Sat, 23 Jan 2021 15:03:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726408AbhAWUAj (ORCPT ); Sat, 23 Jan 2021 15:00:39 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C216DC06121D for ; Sat, 23 Jan 2021 11:59:40 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id p21so7220468lfu.11 for ; Sat, 23 Jan 2021 11:59:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=D4axjSfGQ2KiBmAfemDsyXw/2yGOzXxndCOpqPCFG+A=; b=yEcAXsJCr2YzWoYpyveMY0W2UqZPL87xtYnBeBEO/BeTwNN6G+IvgvCQM+v0Yb5Mgc xqlGsU1j9qSD6xGWiPBx0j/RfpREIraz0euEfU8p1QMqP0r/0KCGv7IrPgjF9VLxCGP0 LI+a9RKXdKjgNc5xLQM+xl1BuanVgMHjj2cc2KLsciM3MFOcio7G9lpnlvg7qMx+nf9Z U+Qk4SUYV2z9FVdoELzfBI7emI8rEMhbbwuRqZY4bV3XsHtMhSfBmNwStJvY8xvCdWcI w3UqtWSHVw8NG/5QvOG8Fkq6luG0W41UbuLygZwoITEevI76JzCXVzlko0PdwY7bFDfT d7uw== 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:mime-version:content-transfer-encoding; bh=D4axjSfGQ2KiBmAfemDsyXw/2yGOzXxndCOpqPCFG+A=; b=Mrss8siMxY7jIzWnewghoZxr3XPjwY/piySVzKmDePQ/631+7fk6b+U6siFPyCp0xM R0GeonZ+Z//bgoDaW2AYAlFAavUD67J/i+3XXh1EnF0JVIYS5IWdJ8vhKnjSplucJqHj 8qtrXyQexZ8uMwmt3qFkb/IrrYp/HOT8QVn+c9zs71W+687H7X6i4Xj945BZhoxsaA4R PtEy+zt600dVGOuTqcF1BNPWIVEUsNGAhNWO2TuWQiHDws3EBB9iig0Ep+aS3Hk1RkOc iQxNgZlPRGKaize0CYqfXbuCbcHtT23xjcafr+ulWAZl7SjvwKCQ07BAbpiWwQTzHA1d RQvw== X-Gm-Message-State: AOAM531eXQHe2mRtQjD051vfXwOhijffc1/rxK3M/8Y1STZZM4BhqxXg zo+/8ZDzLHxyFPl0ompyuo44ww== X-Google-Smtp-Source: ABdhPJyUv+zz6zbPNQkhpBtWDpDjNvNubqnX7wSMwUlC/u3cUupYewMBfe2FkRa4bSU8GIyQwdQuSQ== X-Received: by 2002:a19:6b0e:: with SMTP id d14mr631098lfa.210.1611431979390; Sat, 23 Jan 2021 11:59:39 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id f9sm1265177lft.114.2021.01.23.11.59.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 11:59:39 -0800 (PST) From: Jonas Bonn To: laforge@gnumonks.org, netdev@vger.kernel.org, pbshelar@fb.com, kuba@kernel.org Cc: pablo@netfilter.org, Jonas Bonn Subject: [RFC PATCH 11/16] gtp: drop duplicated assignment Date: Sat, 23 Jan 2021 20:59:11 +0100 Message-Id: <20210123195916.2765481-12-jonas@norrbonn.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210123195916.2765481-1-jonas@norrbonn.se> References: <20210123195916.2765481-1-jonas@norrbonn.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This assignment is already done a few line earlier. Signed-off-by: Jonas Bonn --- drivers/net/gtp.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index c42092bb505f..023d38b1098d 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -268,8 +268,6 @@ static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb) if (!pskb_may_pull(skb, hdrlen)) return -1; - gtp1 = (struct gtp1_header *)(skb->data + sizeof(struct udphdr)); - pctx = gtp1_pdp_find(gtp, ntohl(gtp1->tid)); if (!pctx) { netdev_dbg(gtp->dev, "No PDP ctx to decap skb=%p\n", skb); From patchwork Sat Jan 23 19:59:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 12041899 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A910C433E0 for ; Sat, 23 Jan 2021 20:05:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 59BC122DBF for ; Sat, 23 Jan 2021 20:05:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726439AbhAWUFR (ORCPT ); Sat, 23 Jan 2021 15:05:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726365AbhAWUAP (ORCPT ); Sat, 23 Jan 2021 15:00:15 -0500 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83B2EC06121E for ; Sat, 23 Jan 2021 11:59:41 -0800 (PST) Received: by mail-lf1-x133.google.com with SMTP id a8so12308149lfi.8 for ; Sat, 23 Jan 2021 11:59:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xqyGdbaS6LmomEk16hB8uNnXJFM5N97xCzDYtkMA9Rg=; b=KLAmp9h9yQlypWi6TuTMPfrmMUdpsT7NHO1yzs7JL6UGQCxOFHTXU4DfMLs5tCvuQP MLES0VcY5GBu4pCUQmSQQTCdyZAksT8K5IO/suMhNBXNtZnGZMOtpMy7ITqf4/O+IzhF igJAM7FQ0gDBD3eI4Gj2XtYwX/yIU3WFBkbYeXseF5b0TogNpUVicyi3IWFnEjVJJem0 Y/2fhc1w+yaz27o+mdBoBFxCa6CMdBnlcBABXGi9dlzWCIecNFBMf4FoODLfHKAYCKF3 KWxOHv/OAqrID4zLKiridcZ8TA84G/6W0eTorSI9bGEUm1JvK07b69vylmvHy/bWl2zf DGhw== 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:mime-version:content-transfer-encoding; bh=xqyGdbaS6LmomEk16hB8uNnXJFM5N97xCzDYtkMA9Rg=; b=RLWu+ZL6EweKjkwpCtOjrp9INJLe5dvrNcbGvE4WGdRT4TccARg6+ieswKX08KPmqS x9PihaLCOUk5qJHICrZbiBCxiM147Jh2TLzexzmdhMHPsAy965w2Sk4qIhUOpQykqzgr aWHffmvjzTM3u/rlDn42mUxcLS+Rl2xSN+l2QRZmhcgLoDcrpyFkU753c2c0dCUxlNHa ToLXul+BF6qanjR5FhTeUrUNrvOatGrsiPiiS8eRi7ScQFvtp92MnncQD3ODiM68B2Of Ci/CFFlcj4Kb3j2xZjYeNbPTR/yi4qbUj7D0MuKpcy1eoJgK70g8eKFu52ViypFF0lAK zbiw== X-Gm-Message-State: AOAM531tjDpuB0HGgK+2T5K3h/mFdiKtcVcHluiGjqcpzeq8dETKTw9L 96ogPz9dlqEfv936Le28hOhy9SUhp5yUKw== X-Google-Smtp-Source: ABdhPJwYniqzOAOYAAenGS65Eqv7GMPJY+hmQfHyrmV7ojMrw4N7WzR4zJ9nLasof91xK6K+eyorQw== X-Received: by 2002:a05:6512:228a:: with SMTP id f10mr890373lfu.412.1611431980114; Sat, 23 Jan 2021 11:59:40 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id f9sm1265177lft.114.2021.01.23.11.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 11:59:39 -0800 (PST) From: Jonas Bonn To: laforge@gnumonks.org, netdev@vger.kernel.org, pbshelar@fb.com, kuba@kernel.org Cc: pablo@netfilter.org, Jonas Bonn Subject: [RFC PATCH 12/16] gtp: update rx_length_errors for abnormally short packets Date: Sat, 23 Jan 2021 20:59:12 +0100 Message-Id: <20210123195916.2765481-13-jonas@norrbonn.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210123195916.2765481-1-jonas@norrbonn.se> References: <20210123195916.2765481-1-jonas@norrbonn.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Based on work by Pravin Shelar. Update appropriate stats when packet transmission isn't possible. Signed-off-by: Jonas Bonn Acked-by: Harald Welte --- drivers/net/gtp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 023d38b1098d..7ab8540e46d2 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -185,8 +185,10 @@ static int gtp_rx(struct pdp_ctx *pctx, struct sk_buff *skb, { /* Get rid of the GTP + UDP headers. */ if (iptunnel_pull_header(skb, hdrlen, skb->protocol, - !net_eq(sock_net(pctx->sk), dev_net(pctx->dev)))) - return -1; + !net_eq(sock_net(pctx->sk), dev_net(pctx->dev)))) { + pctx->dev->stats.rx_length_errors++; + goto err; + } netdev_dbg(pctx->dev, "forwarding packet from GGSN to uplink\n"); @@ -202,6 +204,10 @@ static int gtp_rx(struct pdp_ctx *pctx, struct sk_buff *skb, netif_rx(skb); return 0; + +err: + pctx->dev->stats.rx_dropped++; + return -1; } /* 1 means pass up to the stack, -1 means drop and 0 means decapsulated. */ From patchwork Sat Jan 23 19:59:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 12041887 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A461C433E0 for ; Sat, 23 Jan 2021 20:03:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 04DF922B40 for ; Sat, 23 Jan 2021 20:03:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726493AbhAWUCx (ORCPT ); Sat, 23 Jan 2021 15:02:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726402AbhAWUAk (ORCPT ); Sat, 23 Jan 2021 15:00:40 -0500 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40C64C06121F for ; Sat, 23 Jan 2021 11:59:42 -0800 (PST) Received: by mail-lf1-x135.google.com with SMTP id a8so12308205lfi.8 for ; Sat, 23 Jan 2021 11:59:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7JEnFHod/CacccbC2px8f2RtPEF1uIxuwyGPq/6p3Jo=; b=IPdrLQAW2KuSrzRp1p0+7pjgnbPoKHTFyA5z3b1xUI3PIO1dXyWyI8XabkRJgQ6RUC LLrb90zg+7ltF8AfGyGM0ggzQ3s9ZsNDGFyC78wQn5J2mBCLQQ79q3M8pSTlrpLDb3jW A4Hhpsy1OkKc8CSp6nbWlrXIdmc1Dq3f2JzTZke9LKpmnM5Y6RY5orpssG0u6iWW/itv VsMODLCT1V8MbMxyCEUxkxWgvXN9TbIlSzwtmS8k71V9qa14cOHy/UwO5OEzN6EE2/9b RJ68MfjP9jQ6/vCp5fL3Nrz1hj52aoe5RJNCOp8woH9Wc3apIWVzi0otLcW5/ueRdofu T3AQ== 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:mime-version:content-transfer-encoding; bh=7JEnFHod/CacccbC2px8f2RtPEF1uIxuwyGPq/6p3Jo=; b=Fn49RqZA28MlVoXbhpAHlH9u02Jglf0XUz5K+Djnlwg6D0mei2jgR3N4/dfHHolWSp 7wlK8nXxF+o9DPw3lKUgS0xC3hsGNmuOpVVTxZLoRXnWMx/O5UT2KEocktBQpZn6Dr8K g9dmUwE3+IKEgR5pM5la4K4OXBOSUgTnoXmYS50PdFCe/89yp5EhlK6Rcct2h9tvHApD WVBBhpbjg2PfYwb5S2qRqoflHfW6Ip9xycGSQzS1hf1/ehgQi2mJr7Din4I7PKZA05EH 52vQeRb5gxN0l21UsAbb75lZGIsxFqHBI/XdXKG2FYMxaHe35tLQk5syXUmGushL8WHl ZNSA== X-Gm-Message-State: AOAM530jbcpX5vTcxmzgYAI0AjP5xKSv+xTmJky1NFcayJ3Eu1bhY4yA HEYwO4LrMY9yyx2a0y4vi6MX7Q== X-Google-Smtp-Source: ABdhPJwKM2V4xOYcrBFXVaY4Le6Yyt3pSg5xSnsNRq85fvBkmcfg1YWgmkoiPcMP2K/LYWlhGjCRqQ== X-Received: by 2002:a05:6512:3253:: with SMTP id c19mr831204lfr.245.1611431980850; Sat, 23 Jan 2021 11:59:40 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id f9sm1265177lft.114.2021.01.23.11.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 11:59:40 -0800 (PST) From: Jonas Bonn To: laforge@gnumonks.org, netdev@vger.kernel.org, pbshelar@fb.com, kuba@kernel.org Cc: pablo@netfilter.org, Jonas Bonn Subject: [RFC PATCH 13/16] gtp: set skb protocol after pulling headers Date: Sat, 23 Jan 2021 20:59:13 +0100 Message-Id: <20210123195916.2765481-14-jonas@norrbonn.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210123195916.2765481-1-jonas@norrbonn.se> References: <20210123195916.2765481-1-jonas@norrbonn.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Based on work by Pravin Shelar. Once the GTP headers have been the removed, the SKB protocol should be set to that of the inner packet. Signed-off-by: Jonas Bonn --- drivers/net/gtp.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 7ab8540e46d2..8aab46ec8a94 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -197,6 +197,20 @@ static int gtp_rx(struct pdp_ctx *pctx, struct sk_buff *skb, * calculate the transport header. */ skb_reset_network_header(skb); + if (pskb_may_pull(skb, sizeof(struct iphdr))) { + struct iphdr *iph; + + iph = ip_hdr(skb); + if (iph->version == 4) { + netdev_dbg(pctx->dev, "inner pkt: ipv4"); + skb->protocol = htons(ETH_P_IP); + } else if (iph->version == 6) { + netdev_dbg(pctx->dev, "inner pkt: ipv6"); + skb->protocol = htons(ETH_P_IPV6); + } else { + netdev_dbg(pctx->dev, "inner pkt error: Unknown type"); + } + } skb->dev = pctx->dev; From patchwork Sat Jan 23 19:59:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 12041893 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1977CC433E0 for ; Sat, 23 Jan 2021 20:04:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8FFB22D50 for ; Sat, 23 Jan 2021 20:04:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726131AbhAWUDn (ORCPT ); Sat, 23 Jan 2021 15:03:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726412AbhAWUAm (ORCPT ); Sat, 23 Jan 2021 15:00:42 -0500 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30A84C061220 for ; Sat, 23 Jan 2021 11:59:43 -0800 (PST) Received: by mail-lf1-x12d.google.com with SMTP id v24so12320064lfr.7 for ; Sat, 23 Jan 2021 11:59:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B+yKtN4JfFeKDZMuI5NuQ/ee2EcvA/pYHfvRmZfWYOA=; b=ZvqenGVPzOq82xfMV9LSaVjIr+IbO1FvF/ROAgD+TOIJpSyxdbzdebmjhohywz/M8s 00u1dqrbo0GiLQG/MknyWcYeQ7jVOHKnJcixoRppw+y+w3kD9+jE7wUODtCNee1KqULm U+v8dp6p7jPoj9mzPJTJ+PgNN681doAF88ZRChOlJzJla46h8GoLvljmV4FYUqLDLf43 Ral2kz9jGCg+bDBT0r8NGfxcAsCarYI0VavbgGzyTZ867Q3s0oJ9a950FmTCpaOXF5uC DLvsiVSVhdPdrfdglOTSNtsB26T6GettNZejheQXhyrFFFxhh9wsVsVv/E72Qbe2m9ni y39w== 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:mime-version:content-transfer-encoding; bh=B+yKtN4JfFeKDZMuI5NuQ/ee2EcvA/pYHfvRmZfWYOA=; b=i3JkYswF1dBugJjyanztp2lhVuI9HijmwNkWAk/NB1jrfxWFQG3YlED3LTMY8Gst0n Ds3by6Ny72sDWTPl07VIkCBbtWh8XeEanH4qMI3k2AinAFPxHhjIsc6xCyi0DBe0/McH 8512KsroWOHZzKmpqciwspD5SlqfdEdvc5Ap2xAI0TzvRbnZ/vGxtkAQvDvMtAJLsBsq sTTS59q5pVxI42xl57h+5Ga/qX0Ub6WDq707QiOqy23kXyilTWfje4rhffwSgecIIHv2 mAmCR8GoUlV5XGga4cbHwQxmiPoExbdP5LNdJV3Pbj8wZSOKViz/PFx/23OdpHexAm2y J1Qw== X-Gm-Message-State: AOAM532Fmo8VRBUV7WH2DUfTuxyJ66hvnR03gyymLToagGzXhhalSunO Pemd9E3rHkmyxTvvIwfURaOld3xs0Y4cGQ== X-Google-Smtp-Source: ABdhPJxuGRvxNtonQXWMuDCKnJ8zHHsATvMVKrHRuaCYOaDd9f6tDeji7LifpOvQbpgsGsgkq4oreg== X-Received: by 2002:a19:40d4:: with SMTP id n203mr96853lfa.350.1611431981682; Sat, 23 Jan 2021 11:59:41 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id f9sm1265177lft.114.2021.01.23.11.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 11:59:41 -0800 (PST) From: Jonas Bonn To: laforge@gnumonks.org, netdev@vger.kernel.org, pbshelar@fb.com, kuba@kernel.org Cc: pablo@netfilter.org, Jonas Bonn Subject: [RFC PATCH 14/16] gtp: add support for flow based tunneling Date: Sat, 23 Jan 2021 20:59:14 +0100 Message-Id: <20210123195916.2765481-15-jonas@norrbonn.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210123195916.2765481-1-jonas@norrbonn.se> References: <20210123195916.2765481-1-jonas@norrbonn.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Pravin B Shelar This patch adds support for flow based tunneling, allowing to send and receive GTP tunneled packets via the (lightweight) tunnel metadata mechanism. This would allow integration with OVS and eBPF using flow based tunneling APIs. The mechanism used here is to get the required GTP tunnel parameters from the tunnel metadata instead of looking up a pre-configured PDP context. The tunnel metadata contains the necessary information for creating the GTP header. Signed-off-by: Jonas Bonn --- drivers/net/gtp.c | 160 +++++++++++++++++++++++++---- include/uapi/linux/gtp.h | 12 +++ include/uapi/linux/if_tunnel.h | 1 + tools/include/uapi/linux/if_link.h | 1 + 4 files changed, 156 insertions(+), 18 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 8aab46ec8a94..668ed8a4836e 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -74,6 +75,9 @@ struct gtp_dev { unsigned int hash_size; struct hlist_head *tid_hash; struct hlist_head *addr_hash; + /* Used by LWT tunnel. */ + bool collect_md; + struct socket *collect_md_sock; }; static unsigned int gtp_net_id __read_mostly; @@ -224,6 +228,51 @@ static int gtp_rx(struct pdp_ctx *pctx, struct sk_buff *skb, return -1; } +static int gtp_set_tun_dst(struct pdp_ctx *pctx, struct sk_buff *skb, + unsigned int hdrlen) +{ + struct metadata_dst *tun_dst; + struct gtp1_header *gtp1; + int opts_len = 0; + __be64 tid; + + gtp1 = (struct gtp1_header *)(skb->data + sizeof(struct udphdr)); + + tid = key32_to_tunnel_id(gtp1->tid); + + if (unlikely(gtp1->flags & GTP1_F_MASK)) + opts_len = sizeof(struct gtpu_metadata); + + tun_dst = udp_tun_rx_dst(skb, + pctx->sk->sk_family, TUNNEL_KEY, tid, opts_len); + if (!tun_dst) { + netdev_dbg(pctx->dev, "Failed to allocate tun_dst"); + goto err; + } + + netdev_dbg(pctx->dev, "attaching metadata_dst to skb, gtp ver %d hdrlen %d\n", + pctx->gtp_version, hdrlen); + if (unlikely(opts_len)) { + struct gtpu_metadata *opts; + + opts = ip_tunnel_info_opts(&tun_dst->u.tun_info); + opts->ver = GTP_METADATA_V1; + opts->flags = gtp1->flags; + opts->type = gtp1->type; + netdev_dbg(pctx->dev, "recved control pkt: flag %x type: %d\n", + opts->flags, opts->type); + tun_dst->u.tun_info.key.tun_flags |= TUNNEL_GTPU_OPT; + tun_dst->u.tun_info.options_len = opts_len; + skb->protocol = htons(0xffff); /* Unknown */ + } + + skb_dst_set(skb, &tun_dst->dst); + return 0; +err: + return -1; +} + + /* 1 means pass up to the stack, -1 means drop and 0 means decapsulated. */ static int gtp0_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb) { @@ -262,6 +311,7 @@ static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb) unsigned int hdrlen = sizeof(struct udphdr) + sizeof(struct gtp1_header); struct gtp1_header *gtp1; + struct pdp_ctx md_pctx; struct pdp_ctx *pctx; if (!pskb_may_pull(skb, hdrlen)) @@ -272,6 +322,24 @@ static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb) if ((gtp1->flags >> 5) != GTP_V1) return 1; + if (ip_tunnel_collect_metadata() || gtp->collect_md) { + int err; + + pctx = &md_pctx; + + pctx->gtp_version = GTP_V1; + pctx->sk = gtp->sk1u; + pctx->dev = gtp->dev; + + err = gtp_set_tun_dst(pctx, skb, hdrlen); + if (err) { + gtp->dev->stats.rx_dropped++; + return -1; + } + + return gtp_rx(pctx, skb, hdrlen); + } + if (gtp1->type != GTP_TPDU) return 1; @@ -353,7 +421,8 @@ static int gtp_encap_recv(struct sock *sk, struct sk_buff *skb) if (!gtp) return 1; - netdev_dbg(gtp->dev, "encap_recv sk=%p\n", sk); + netdev_dbg(gtp->dev, "encap_recv sk=%p type %d\n", + sk, udp_sk(sk)->encap_type); switch (udp_sk(sk)->encap_type) { case UDP_ENCAP_GTP0: @@ -539,7 +608,7 @@ static struct rtable *gtp_get_v4_rt(struct sk_buff *skb, memset(&fl4, 0, sizeof(fl4)); fl4.flowi4_oif = sk->sk_bound_dev_if; fl4.daddr = pctx->peer_addr_ip4.s_addr; - fl4.saddr = inet_sk(sk)->inet_saddr; + fl4.saddr = *saddr; fl4.flowi4_tos = RT_CONN_FLAGS(sk); fl4.flowi4_proto = sk->sk_protocol; @@ -617,29 +686,84 @@ static void gtp_push_header(struct sk_buff *skb, struct pdp_ctx *pctx, static int gtp_xmit_ip4(struct sk_buff *skb, struct net_device *dev) { struct gtp_dev *gtp = netdev_priv(dev); + struct gtpu_metadata *opts = NULL; + struct pdp_ctx md_pctx; struct pdp_ctx *pctx; + __be16 port; struct rtable *rt; - __be32 saddr; struct iphdr *iph; + __be32 saddr; int headroom; - __be16 port; + __u8 tos; int r; - /* Read the IP destination address and resolve the PDP context. - * Prepend PDP header with TEI/TID from PDP ctx. - */ - iph = ip_hdr(skb); - if (gtp->role == GTP_ROLE_SGSN) - pctx = ipv4_pdp_find(gtp, iph->saddr); - else - pctx = ipv4_pdp_find(gtp, iph->daddr); + if (gtp->collect_md) { + /* LWT GTP1U encap */ + struct ip_tunnel_info *info = NULL; - if (!pctx) { - netdev_dbg(dev, "no PDP ctx found for %pI4, skip\n", - &iph->daddr); - return -ENOENT; + info = skb_tunnel_info(skb); + if (!info) { + netdev_dbg(dev, "missing tunnel info"); + return -ENOENT; + } + if (info->key.tp_dst && ntohs(info->key.tp_dst) != GTP1U_PORT) { + netdev_dbg(dev, "unexpected GTP dst port: %d", ntohs(info->key.tp_dst)); + return -EOPNOTSUPP; + } + + if (!gtp->sk1u) { + netdev_dbg(dev, "missing tunnel sock"); + return -EOPNOTSUPP; + } + + pctx = &md_pctx; + memset(pctx, 0, sizeof(*pctx)); + pctx->sk = gtp->sk1u; + pctx->gtp_version = GTP_V1; + pctx->u.v1.o_tei = ntohl(tunnel_id_to_key32(info->key.tun_id)); + pctx->peer_addr_ip4.s_addr = info->key.u.ipv4.dst; + + saddr = info->key.u.ipv4.src; + tos = info->key.tos; + + if (info->options_len != 0) { + if (info->key.tun_flags & TUNNEL_GTPU_OPT) { + opts = ip_tunnel_info_opts(info); + } else { + netdev_dbg(dev, "missing tunnel metadata for control pkt"); + return -EOPNOTSUPP; + } + } + netdev_dbg(dev, "flow-based GTP1U encap: tunnel id %d\n", + pctx->u.v1.o_tei); + } else { + struct iphdr *iph; + + if (ntohs(skb->protocol) != ETH_P_IP) + return -EOPNOTSUPP; + + iph = ip_hdr(skb); + + /* Read the IP destination address and resolve the PDP context. + * Prepend PDP header with TEI/TID from PDP ctx. + */ + if (gtp->role == GTP_ROLE_SGSN) + pctx = ipv4_pdp_find(gtp, iph->saddr); + else + pctx = ipv4_pdp_find(gtp, iph->daddr); + + if (!pctx) { + netdev_dbg(dev, "no PDP ctx found for %pI4, skip\n", + &iph->daddr); + return -ENOENT; + } + netdev_dbg(dev, "found PDP context %p\n", pctx); + + saddr = inet_sk(pctx->sk)->inet_saddr; + tos = iph->tos; + netdev_dbg(dev, "gtp -> IP src: %pI4 dst: %pI4\n", + &iph->saddr, &iph->daddr); } - netdev_dbg(dev, "found PDP context %p\n", pctx); rt = gtp_get_v4_rt(skb, dev, pctx, &saddr); if (IS_ERR(rt)) { @@ -691,7 +815,7 @@ static int gtp_xmit_ip4(struct sk_buff *skb, struct net_device *dev) udp_tunnel_xmit_skb(rt, pctx->sk, skb, saddr, pctx->peer_addr_ip4.s_addr, - iph->tos, + tos, ip4_dst_hoplimit(&rt->dst), 0, port, port, diff --git a/include/uapi/linux/gtp.h b/include/uapi/linux/gtp.h index 79f9191bbb24..62aff78b7c56 100644 --- a/include/uapi/linux/gtp.h +++ b/include/uapi/linux/gtp.h @@ -2,6 +2,8 @@ #ifndef _UAPI_LINUX_GTP_H_ #define _UAPI_LINUX_GTP_H_ +#include + #define GTP_GENL_MCGRP_NAME "gtp" enum gtp_genl_cmds { @@ -34,4 +36,14 @@ enum gtp_attrs { }; #define GTPA_MAX (__GTPA_MAX + 1) +enum { + GTP_METADATA_V1 +}; + +struct gtpu_metadata { + __u8 ver; + __u8 flags; + __u8 type; +}; + #endif /* _UAPI_LINUX_GTP_H_ */ diff --git a/include/uapi/linux/if_tunnel.h b/include/uapi/linux/if_tunnel.h index 7d9105533c7b..802da679fab1 100644 --- a/include/uapi/linux/if_tunnel.h +++ b/include/uapi/linux/if_tunnel.h @@ -176,6 +176,7 @@ enum { #define TUNNEL_VXLAN_OPT __cpu_to_be16(0x1000) #define TUNNEL_NOCACHE __cpu_to_be16(0x2000) #define TUNNEL_ERSPAN_OPT __cpu_to_be16(0x4000) +#define TUNNEL_GTPU_OPT __cpu_to_be16(0x8000) #define TUNNEL_OPTIONS_PRESENT \ (TUNNEL_GENEVE_OPT | TUNNEL_VXLAN_OPT | TUNNEL_ERSPAN_OPT) diff --git a/tools/include/uapi/linux/if_link.h b/tools/include/uapi/linux/if_link.h index d208b2af697f..28d649bda686 100644 --- a/tools/include/uapi/linux/if_link.h +++ b/tools/include/uapi/linux/if_link.h @@ -617,6 +617,7 @@ enum { IFLA_GTP_FD1, IFLA_GTP_PDP_HASHSIZE, IFLA_GTP_ROLE, + IFLA_GTP_COLLECT_METADATA, __IFLA_GTP_MAX, }; #define IFLA_GTP_MAX (__IFLA_GTP_MAX - 1) From patchwork Sat Jan 23 19:59:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 12041901 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51521C433E6 for ; Sat, 23 Jan 2021 20:05:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2AB3C22DBF for ; Sat, 23 Jan 2021 20:05:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726375AbhAWUFN (ORCPT ); Sat, 23 Jan 2021 15:05:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726437AbhAWUBJ (ORCPT ); Sat, 23 Jan 2021 15:01:09 -0500 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F6ACC061221 for ; Sat, 23 Jan 2021 11:59:44 -0800 (PST) Received: by mail-lf1-x129.google.com with SMTP id p21so7220647lfu.11 for ; Sat, 23 Jan 2021 11:59:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uKKJeqaXIO+5os8l/V0Znssmjq/yk2JjBfnzf1a4R7Q=; b=1Jy9raR49TfNioC81iTuWWXiqL9J53/BooMuFA8iZy6Duam9g1zpIZCmYj3eEOfWwQ RXbqh/mcftLp9jBOMNTG/0WoyAqvxxnjGqMgvLvviVMrmOyk8ihDcpL4xXkzj1fAayE1 HimN4WvHTHzh+WdLk0hVdfoqrtV/gReDZNyu3x6BBrG1RN/fE9hTtxmqAR2R2/1oJdTt qUsGJrtlkuhCdAO4/YIxsGgjmfq8nS/fPxPOVXI2wQI8YzGH8FaTC/FjNkcIWMaeuOCq nE13NNsEZMwHWhptlJQQo+K4Bb0vaVywa/P6Eue0V1VIOxYSoau/55biUMrHpH28QXik vtlQ== 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:mime-version:content-transfer-encoding; bh=uKKJeqaXIO+5os8l/V0Znssmjq/yk2JjBfnzf1a4R7Q=; b=gShNc2tZ6l2rjOo5eVvruE3zTS3cqd8mTILVH8mV4z6yojtQ19X9O2/FuXYMjrI2B3 QDy3mk8zqTEhdrlIBITLklDJnkLP6/Q1CTgqkrg5bhhf0FTIbKYKjtzad7xOzOMqu1ED suCia1WN9ZlCqafhsPKjJ5R2S/rH9JjbGQbqO7DDdqnYT5XRoPDdMLmjaGgjm3TEoTdM PUJvBaElsSI1tLkzIM7dr54v0q/XglODDVJYp27AIIE7nqyJh5QQiEZw/k95TyS3M5tz mTJ6vPboNNuusWN6kEOUuwYn3i9ioC5fnTScwQ+KM6EdgS776LwhltWdfiyr4N+gkID2 921Q== X-Gm-Message-State: AOAM531r1sdNu/ckLTsAe4j4mdGIeLY8dyHP5xWh24y2SNnhiEm8X1HW UGyc7IFog86eE0fgV15kfECAug== X-Google-Smtp-Source: ABdhPJyOEDegoL2JmO11AVhLcmFnAykortVOCpt/OwXZz/Er+dSWC/3k+gWOXl2eF5YAqfz0FKGZxA== X-Received: by 2002:a19:84:: with SMTP id 126mr15172lfa.120.1611431982581; Sat, 23 Jan 2021 11:59:42 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id f9sm1265177lft.114.2021.01.23.11.59.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 11:59:42 -0800 (PST) From: Jonas Bonn To: laforge@gnumonks.org, netdev@vger.kernel.org, pbshelar@fb.com, kuba@kernel.org Cc: pablo@netfilter.org, Jonas Bonn Subject: [RFC PATCH 15/16] gtp: add ability to send GTP controls headers Date: Sat, 23 Jan 2021 20:59:15 +0100 Message-Id: <20210123195916.2765481-16-jonas@norrbonn.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210123195916.2765481-1-jonas@norrbonn.se> References: <20210123195916.2765481-1-jonas@norrbonn.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Pravin B Shelar Please explain how this patch actually works... creation of the control header makes sense, but I don't understand how sending of a control header is actually triggered. Signed-off-by: Jonas Bonn --- drivers/net/gtp.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index 668ed8a4836e..bbce2671de2d 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -683,6 +683,38 @@ static void gtp_push_header(struct sk_buff *skb, struct pdp_ctx *pctx, } } +static inline int gtp1_push_control_header(struct sk_buff *skb, + struct pdp_ctx *pctx, + struct gtpu_metadata *opts, + struct net_device *dev) +{ + struct gtp1_header *gtp1c; + int payload_len; + + if (opts->ver != GTP_METADATA_V1) + return -ENOENT; + + if (opts->type == 0xFE) { + /* for end marker ignore skb data. */ + netdev_dbg(dev, "xmit pkt with null data"); + pskb_trim(skb, 0); + } + if (skb_cow_head(skb, sizeof(*gtp1c)) < 0) + return -ENOMEM; + + payload_len = skb->len; + + gtp1c = skb_push(skb, sizeof(*gtp1c)); + + gtp1c->flags = opts->flags; + gtp1c->type = opts->type; + gtp1c->length = htons(payload_len); + gtp1c->tid = htonl(pctx->u.v1.o_tei); + netdev_dbg(dev, "xmit control pkt: ver %d flags %x type %x pkt len %d tid %x", + opts->ver, opts->flags, opts->type, skb->len, pctx->u.v1.o_tei); + return 0; +} + static int gtp_xmit_ip4(struct sk_buff *skb, struct net_device *dev) { struct gtp_dev *gtp = netdev_priv(dev); @@ -807,7 +839,16 @@ static int gtp_xmit_ip4(struct sk_buff *skb, struct net_device *dev) skb_set_inner_protocol(skb, skb->protocol); - gtp_push_header(skb, pctx, &port); + if (unlikely(opts)) { + port = htons(GTP1U_PORT); + r = gtp1_push_control_header(skb, pctx, opts, dev); + if (r) { + netdev_info(dev, "cntr pkt error %d", r); + goto err_rt; + } + } else { + gtp_push_header(skb, pctx, &port); + } iph = ip_hdr(skb); netdev_dbg(dev, "gtp -> IP src: %pI4 dst: %pI4\n", From patchwork Sat Jan 23 19:59:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Bonn X-Patchwork-Id: 12041897 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F322CC433DB for ; Sat, 23 Jan 2021 20:05:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B96AB22D50 for ; Sat, 23 Jan 2021 20:05:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726434AbhAWUFO (ORCPT ); Sat, 23 Jan 2021 15:05:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726430AbhAWUAv (ORCPT ); Sat, 23 Jan 2021 15:00:51 -0500 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C46BDC061222 for ; Sat, 23 Jan 2021 11:59:44 -0800 (PST) Received: by mail-lf1-x132.google.com with SMTP id h7so12320912lfc.6 for ; Sat, 23 Jan 2021 11:59:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=norrbonn-se.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jowe04iloA30aLI+ur9iy6s0ZbFaGPL/iBAGPVncJhc=; b=U5fl1saQSJYNR2DyyFIwNFaB1y1NEmeajhV1fgsPHWZriB3Ynq7Jpq83ORcmTiFRRN X6c5J4qlAFYss/FQhZFNqSAN7xUskIo9oPRCnHWPN1PMz2+koD4+GWbiTu7dDqxI7kdY xPvsN9ASJEDFco9qLKpIhmUoXLhpcadJgYIaSAdA6gltp2U+aKDu2Wah/M9RO8HgBsjm 7vlf6KahGL0BKuoUGpJBi3GV4oHIvm9pIj9CD3v9H6l2GAeF/SdYeZv8b3s+ZR/GfZhX HQrb4soxGB5sbi4oHNRKv+dlBUhNcpI2hq9KDjg09W7KbKFS07RmesOzrGCkSYU0QAxD rIZw== 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:mime-version:content-transfer-encoding; bh=jowe04iloA30aLI+ur9iy6s0ZbFaGPL/iBAGPVncJhc=; b=dh2dpOnpM7F84CD3NvhUcrq8hBacKFXLjKz8FDyRvuOPb4UAEjs1LWHKinl7e2r3Ie IcxWUtqCg4k+CPi5heDzIroFQj+c06kVEQaOWebve85jxyn3Fzp0u0+1erw6MnXWwcMT dqxcYGnZ8FzhWsTy56bDz20qvWC36AbIXis85WpYK0Y7QoBqGBA+ibCr7N2IEH3UopZ8 E3wif35g7EX0CN/PDmscBVzThiL0JKeHLUfkWu+1D3e04CVMRrLFgUKX0zPPAMR82EGO dhd54Bro3rmrKoo/FlD3XKNOjVnQWpQ9cdVrJ7KPladFUFBhvlSbNKapTwz5/zxyORk2 dUug== X-Gm-Message-State: AOAM533vESpviAxq+K/IwJ8yI5lnsIMwrpBJ7GTtvIYrivcZjUrfugpU hK3N/6VnmV+YLUT+yXlgabfvSA== X-Google-Smtp-Source: ABdhPJyshZtjmqFaMD4wxqdkhfp38TsmybKHLzMVostpmdZY4vOIV9nbZt45Ml+2x/oDSOtUDh4J1w== X-Received: by 2002:a19:6d07:: with SMTP id i7mr145337lfc.75.1611431983345; Sat, 23 Jan 2021 11:59:43 -0800 (PST) Received: from mimer.lan (h-137-65.A159.priv.bahnhof.se. [81.170.137.65]) by smtp.gmail.com with ESMTPSA id f9sm1265177lft.114.2021.01.23.11.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Jan 2021 11:59:42 -0800 (PST) From: Jonas Bonn To: laforge@gnumonks.org, netdev@vger.kernel.org, pbshelar@fb.com, kuba@kernel.org Cc: pablo@netfilter.org, Jonas Bonn Subject: [RFC PATCH 16/16] gtp: add netlink support for setting up flow based tunnels Date: Sat, 23 Jan 2021 20:59:16 +0100 Message-Id: <20210123195916.2765481-17-jonas@norrbonn.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210123195916.2765481-1-jonas@norrbonn.se> References: <20210123195916.2765481-1-jonas@norrbonn.se> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Pravin B Shelar This adds the Netlink interface necessary to set up flow based tunnels. Signed-off-by: Jonas Bonn --- drivers/net/gtp.c | 139 +++++++++++++++++++++++++++-------- include/uapi/linux/if_link.h | 1 + 2 files changed, 111 insertions(+), 29 deletions(-) diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c index bbce2671de2d..a4fff0f1e174 100644 --- a/drivers/net/gtp.c +++ b/drivers/net/gtp.c @@ -407,6 +407,11 @@ static void gtp_encap_disable(struct gtp_dev *gtp) { gtp_encap_disable_sock(gtp->sk0); gtp_encap_disable_sock(gtp->sk1u); + if (gtp->collect_md_sock) { + udp_tunnel_sock_release(gtp->collect_md_sock); + gtp->collect_md_sock = NULL; + netdev_dbg(gtp->dev, "GTP socket released.\n"); + } } /* UDP encapsulation receive handler. See net/ipv4/udp.c. @@ -904,6 +909,19 @@ static const struct net_device_ops gtp_netdev_ops = { .ndo_get_stats64 = dev_get_tstats64, }; +static struct gtp_dev *gtp_find_flow_based_dev(struct net *net) +{ + struct gtp_net *gn = net_generic(net, gtp_net_id); + struct gtp_dev *gtp; + + list_for_each_entry(gtp, &gn->gtp_dev_list, list) { + if (gtp->collect_md) + return gtp; + } + + return NULL; +} + static const struct device_type gtp_type = { .name = "gtp", }; @@ -938,7 +956,7 @@ static void gtp_link_setup(struct net_device *dev) } static int gtp_hashtable_new(struct gtp_dev *gtp, int hsize); -static int gtp_encap_enable(struct gtp_dev *gtp, struct nlattr *data[]); +static int gtp_encap_enable(struct gtp_dev *gtp, struct net_device *dev, struct nlattr *data[]); static void gtp_destructor(struct net_device *dev) { @@ -956,11 +974,24 @@ static int gtp_newlink(struct net *src_net, struct net_device *dev, struct gtp_net *gn; int hashsize, err; - if (!data[IFLA_GTP_FD0] && !data[IFLA_GTP_FD1]) + if (!data[IFLA_GTP_FD0] && !data[IFLA_GTP_FD1] && + !data[IFLA_GTP_COLLECT_METADATA]) return -EINVAL; gtp = netdev_priv(dev); + if (data[IFLA_GTP_COLLECT_METADATA]) { + if (data[IFLA_GTP_FD0]) { + netdev_dbg(dev, "LWT device does not support setting v0 socket"); + return -EINVAL; + } + if (gtp_find_flow_based_dev(src_net)) { + netdev_dbg(dev, "LWT device already exist"); + return -EBUSY; + } + gtp->collect_md = true; + } + if (!data[IFLA_GTP_PDP_HASHSIZE]) { hashsize = 1024; } else { @@ -973,7 +1004,7 @@ static int gtp_newlink(struct net *src_net, struct net_device *dev, if (err < 0) return err; - err = gtp_encap_enable(gtp, data); + err = gtp_encap_enable(gtp, dev, data); if (err < 0) goto out_hashtable; @@ -987,7 +1018,7 @@ static int gtp_newlink(struct net *src_net, struct net_device *dev, list_add_rcu(>p->list, &gn->gtp_dev_list); dev->priv_destructor = gtp_destructor; - netdev_dbg(dev, "registered new GTP interface\n"); + netdev_dbg(dev, "registered new GTP interface %s\n", dev->name); return 0; @@ -1018,6 +1049,7 @@ static const struct nla_policy gtp_policy[IFLA_GTP_MAX + 1] = { [IFLA_GTP_FD1] = { .type = NLA_U32 }, [IFLA_GTP_PDP_HASHSIZE] = { .type = NLA_U32 }, [IFLA_GTP_ROLE] = { .type = NLA_U32 }, + [IFLA_GTP_COLLECT_METADATA] = { .type = NLA_FLAG }, }; static int gtp_validate(struct nlattr *tb[], struct nlattr *data[], @@ -1044,6 +1076,9 @@ static int gtp_fill_info(struct sk_buff *skb, const struct net_device *dev) if (nla_put_u32(skb, IFLA_GTP_ROLE, gtp->role)) goto nla_put_failure; + if (gtp->collect_md && nla_put_flag(skb, IFLA_GTP_COLLECT_METADATA)) + goto nla_put_failure; + return 0; nla_put_failure: @@ -1089,35 +1124,24 @@ static int gtp_hashtable_new(struct gtp_dev *gtp, int hsize) return -ENOMEM; } -static struct sock *gtp_encap_enable_socket(int fd, int type, - struct gtp_dev *gtp) +static int __gtp_encap_enable_socket(struct socket *sock, int type, + struct gtp_dev *gtp) { struct udp_tunnel_sock_cfg tuncfg = {NULL}; - struct socket *sock; struct sock *sk; - int err; - - pr_debug("enable gtp on %d, %d\n", fd, type); - - sock = sockfd_lookup(fd, &err); - if (!sock) { - pr_debug("gtp socket fd=%d not found\n", fd); - return NULL; - } sk = sock->sk; if (sk->sk_protocol != IPPROTO_UDP || sk->sk_type != SOCK_DGRAM || (sk->sk_family != AF_INET && sk->sk_family != AF_INET6)) { - pr_debug("socket fd=%d not UDP\n", fd); - sk = ERR_PTR(-EINVAL); - goto out_sock; + pr_debug("socket not UDP\n"); + return -EINVAL; } lock_sock(sk); if (sk->sk_user_data) { - sk = ERR_PTR(-EBUSY); - goto out_rel_sock; + release_sock(sock->sk); + return -EBUSY; } sock_hold(sk); @@ -1130,15 +1154,58 @@ static struct sock *gtp_encap_enable_socket(int fd, int type, tuncfg.gro_complete = gtp_gro_complete; setup_udp_tunnel_sock(sock_net(sock->sk), sock, &tuncfg); - -out_rel_sock: release_sock(sock->sk); -out_sock: + return 0; +} + +static struct sock *gtp_encap_enable_socket(int fd, int type, + struct gtp_dev *gtp) +{ + struct socket *sock; + int err; + + pr_debug("enable gtp on %d, %d\n", fd, type); + + sock = sockfd_lookup(fd, &err); + if (!sock) { + pr_debug("gtp socket fd=%d not found\n", fd); + return NULL; + } + err = __gtp_encap_enable_socket(sock, type, gtp); sockfd_put(sock); - return sk; + if (err) + return ERR_PTR(err); + + return sock->sk; +} + +static struct socket *gtp_create_gtp_socket(struct gtp_dev *gtp, struct net_device *dev) +{ + struct udp_port_cfg udp_conf; + struct socket *sock; + int err; + + memset(&udp_conf, 0, sizeof(udp_conf)); + udp_conf.family = AF_INET; + udp_conf.local_ip.s_addr = htonl(INADDR_ANY); + udp_conf.local_udp_port = htons(GTP1U_PORT); + + err = udp_sock_create(dev_net(dev), &udp_conf, &sock); + if (err < 0) { + pr_debug("create gtp sock failed: %d\n", err); + return ERR_PTR(err); + } + err = __gtp_encap_enable_socket(sock, UDP_ENCAP_GTP1U, gtp); + if (err) { + pr_debug("enable gtp sock encap failed: %d\n", err); + udp_tunnel_sock_release(sock); + return ERR_PTR(err); + } + pr_debug("create gtp sock done\n"); + return sock; } -static int gtp_encap_enable(struct gtp_dev *gtp, struct nlattr *data[]) +static int gtp_encap_enable(struct gtp_dev *gtp, struct net_device *dev, struct nlattr *data[]) { struct sock *sk1u = NULL; struct sock *sk0 = NULL; @@ -1162,11 +1229,25 @@ static int gtp_encap_enable(struct gtp_dev *gtp, struct nlattr *data[]) } } + if (data[IFLA_GTP_COLLECT_METADATA]) { + struct socket *sock; + + if (!sk1u) { + sock = gtp_create_gtp_socket(gtp, dev); + if (IS_ERR(sock)) + return PTR_ERR(sock); + + gtp->collect_md_sock = sock; + sk1u = sock->sk; + } else { + gtp->collect_md_sock = NULL; + } + } + if (data[IFLA_GTP_ROLE]) { role = nla_get_u32(data[IFLA_GTP_ROLE]); if (role > GTP_ROLE_SGSN) { - gtp_encap_disable_sock(sk0); - gtp_encap_disable_sock(sk1u); + gtp_encap_disable(gtp); return -EINVAL; } } @@ -1725,7 +1806,7 @@ static int __init gtp_init(void) if (err < 0) goto unreg_genl_family; - pr_info("GTP module loaded (pdp ctx size %zd bytes)\n", + pr_info("GTP module loaded (pdp ctx size %zd bytes) with tnl-md support\n", sizeof(struct pdp_ctx)); return 0; diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index 82708c6db432..2bd0d8bbcdb2 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -809,6 +809,7 @@ enum { IFLA_GTP_FD1, IFLA_GTP_PDP_HASHSIZE, IFLA_GTP_ROLE, + IFLA_GTP_COLLECT_METADATA, __IFLA_GTP_MAX, }; #define IFLA_GTP_MAX (__IFLA_GTP_MAX - 1)