netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netdev@vger.kernel.org, davem@davemloft.net, laforge@osmocom.org,
	pespin@sysmocom.de, osmith@sysmocom.de, kuba@kernel.org,
	pabeni@redhat.com, edumazet@google.com, fw@strlen.de
Subject: Re: [PATCH net-next 04/12] gtp: add IPv6 support
Date: Fri, 26 Apr 2024 21:41:01 +0100	[thread overview]
Message-ID: <20240426204101.GE516117@kernel.org> (raw)
In-Reply-To: <20240425105138.1361098-5-pablo@netfilter.org>

On Thu, Apr 25, 2024 at 12:51:30PM +0200, Pablo Neira Ayuso wrote:
> Add new iflink attributes to configure in-kernel UDP listener socket
> address: IFLA_GTP_LOCAL and IFLA_GTP_LOCAL6. If none of these attributes
> are specified, default is still to IPv4 INADDR_ANY for backward
> compatibility.
> 
> Add new attributes to set up family and IPv6 address of GTP tunnels:
> GTPA_FAMILY, GTPA_PEER_ADDR6 and GTPA_MS_ADDR6. If no GTPA_FAMILY is
> specified, AF_INET is assumed for backward compatibility.
> 
> setsockopt IPV6_ADDRFORM allows to downgrade socket from IPv6 to IPv4
> after socket is bound. Assumption is that socket listener that is
> attached to the gtp device needs to be either IPv4 or IPv6. Therefore,
> GTP socket listener does not allow for IPv4-mapped-IPv6 listener.
> 
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> ---
>  drivers/net/gtp.c            | 390 ++++++++++++++++++++++++++++++++---
>  include/uapi/linux/gtp.h     |   3 +
>  include/uapi/linux/if_link.h |   2 +
>  3 files changed, 368 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c
> index 1c4429d24cfc..69d865e592df 100644
> --- a/drivers/net/gtp.c
> +++ b/drivers/net/gtp.c
> @@ -24,6 +24,7 @@
>  #include <net/net_namespace.h>
>  #include <net/protocol.h>
>  #include <net/ip.h>
> +#include <net/ipv6.h>
>  #include <net/udp.h>
>  #include <net/udp_tunnel.h>
>  #include <net/icmp.h>
> @@ -52,9 +53,11 @@ struct pdp_ctx {
>  
>  	union {
>  		struct in_addr	addr;
> +		struct in6_addr	addr6;
>  	} ms;
>  	union {
>  		struct in_addr	addr;
> +		struct in6_addr	addr6;
>  	} peer;
>  
>  	struct sock		*sk;
> @@ -131,6 +134,11 @@ static inline u32 ipv4_hashfn(__be32 ip)
>  	return jhash_1word((__force u32)ip, gtp_h_initval);
>  }
>  
> +static inline u32 ipv6_hashfn(const struct in6_addr *ip6)
> +{
> +	return jhash(ip6, sizeof(*ip6), gtp_h_initval);
> +}
> +

Hi Pablo,

I'm would naively expect that the compiler can work out if this needs to
be inline.

>  /* Resolve a PDP context structure based on the 64bit TID. */
>  static struct pdp_ctx *gtp0_pdp_find(struct gtp_dev *gtp, u64 tid)
>  {

...

> @@ -878,6 +951,20 @@ static inline void gtp_set_pktinfo_ipv4(struct gtp_pktinfo *pktinfo,
>  	pktinfo->dev	= dev;
>  }
>  
> +static inline void gtp_set_pktinfo_ipv6(struct gtp_pktinfo *pktinfo,
> +					struct sock *sk, struct ipv6hdr *ip6h,
> +					struct pdp_ctx *pctx, struct rt6_info *rt6,
> +					struct flowi6 *fl6,
> +					struct net_device *dev)
> +{
> +	pktinfo->sk	= sk;
> +	pktinfo->ip6h	= ip6h;
> +	pktinfo->pctx	= pctx;
> +	pktinfo->rt6	= rt6;
> +	pktinfo->fl6	= *fl6;
> +	pktinfo->dev	= dev;
> +}

Here too.

...

> @@ -1441,7 +1736,14 @@ static struct pdp_ctx *gtp_pdp_add(struct gtp_dev *gtp, struct sock *sk,
>  		if (!pctx)
>  			pctx = pctx_tid;
>  
> -		ipv4_pdp_fill(pctx, info);
> +		switch (pctx->af) {
> +		case AF_INET:
> +			ipv4_pdp_fill(pctx, info);
> +			break;
> +		case AF_INET6:
> +			ipv6_pdp_fill(pctx, info);
> +			break;
> +		}
>  
>  		if (pctx->gtp_version == GTP_V0)
>  			netdev_dbg(dev, "GTPv0-U: update tunnel id = %llx (pdp %p)\n",

The code just before the following hunk is:

	pctx = kmalloc(sizeof(*pctx), GFP_ATOMIC);
	if (pctx == NULL)
		return ERR_PTR(-ENOMEM);


> @@ -1461,7 +1763,24 @@ static struct pdp_ctx *gtp_pdp_add(struct gtp_dev *gtp, struct sock *sk,
>  	sock_hold(sk);
>  	pctx->sk = sk;
>  	pctx->dev = gtp->dev;
> -	ipv4_pdp_fill(pctx, info);
> +	pctx->af = family;
> +
> +	switch (pctx->af) {
> +	case AF_INET:
> +		if (!info->attrs[GTPA_MS_ADDRESS] ||
> +		    !info->attrs[GTPA_PEER_ADDRESS])
> +			return ERR_PTR(-EINVAL);

So this appears to leak pctx.

> +
> +		ipv4_pdp_fill(pctx, info);
> +		break;
> +	case AF_INET6:
> +		if (!info->attrs[GTPA_MS_ADDR6] ||
> +		    !info->attrs[GTPA_PEER_ADDR6])
> +			return ERR_PTR(-EINVAL);

Likewise here.

Flagged by Smatch.

> +
> +		ipv6_pdp_fill(pctx, info);
> +		break;
> +	}
>  	atomic_set(&pctx->tx_seq, 0);
>  
>  	switch (pctx->gtp_version) {

...

  reply	other threads:[~2024-04-26 20:41 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-25 10:51 [PATCH net-next 00/12] gtp updates for net-next (v2) Pablo Neira Ayuso
2024-04-25 10:51 ` [PATCH net-next 01/12] gtp: remove useless initialization Pablo Neira Ayuso
2024-04-25 10:51 ` [PATCH net-next 02/12] gtp: properly parse extension headers Pablo Neira Ayuso
2024-04-26 20:28   ` Simon Horman
2024-05-02 10:36     ` Pablo Neira Ayuso
2024-04-25 10:51 ` [PATCH net-next 03/12] gtp: prepare for IPv6 support Pablo Neira Ayuso
2024-04-25 10:51 ` [PATCH net-next 04/12] gtp: add " Pablo Neira Ayuso
2024-04-26 20:41   ` Simon Horman [this message]
2024-05-02 10:38     ` Pablo Neira Ayuso
2024-04-25 10:51 ` [PATCH net-next 05/12] gtp: use IPv6 address /64 prefix for UE/MS Pablo Neira Ayuso
2024-04-25 10:51 ` [PATCH net-next 06/12] gtp: pass up link local traffic to userspace socket Pablo Neira Ayuso
2024-04-25 10:51 ` [PATCH net-next 07/12] gtp: move debugging to skbuff build helper function Pablo Neira Ayuso
2024-04-25 10:51 ` [PATCH net-next 08/12] gtp: remove IPv4 and IPv6 header from context object Pablo Neira Ayuso
2024-04-25 10:51 ` [PATCH net-next 09/12] gtp: add helper function to build GTP packets from an IPv4 packet Pablo Neira Ayuso
2024-04-25 10:51 ` [PATCH net-next 10/12] gtp: add helper function to build GTP packets from an IPv6 packet Pablo Neira Ayuso
2024-04-25 10:51 ` [PATCH net-next 11/12] gtp: support for IPv4-in-IPv6-GTP and IPv6-in-IPv4-GTP Pablo Neira Ayuso
2024-04-25 10:51 ` [PATCH net-next 12/12] gtp: identify tunnel via GTP device + GTP version + TEID + family Pablo Neira Ayuso
2024-04-26  2:29 ` [PATCH net-next 00/12] gtp updates for net-next (v2) Jakub Kicinski
  -- strict thread matches above, loose matches on Subject: below --
2024-04-23 22:39 [PATCH net-next 00/12] GTP driver updates for net-next Pablo Neira Ayuso
2024-04-23 22:39 ` [PATCH net-next 04/12] gtp: add IPv6 support Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240426204101.GE516117@kernel.org \
    --to=horms@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=kuba@kernel.org \
    --cc=laforge@osmocom.org \
    --cc=netdev@vger.kernel.org \
    --cc=osmith@sysmocom.de \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    --cc=pespin@sysmocom.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).