Commit Graph

40 Commits

Author SHA1 Message Date
Pablo Neira Ayuso 64b5757043 gtp-genl: display gtp device in listing
Display the device that the tunnel belongs to, users need this
information to delete tunnels.

Change-Id: I888723a8318c04772f7d22a042e69fa6e9ef2239
2024-02-15 15:42:02 +01:00
Pablo Neira Ayuso 43b88cadbf gtp: add flags to gtp_tunnel object
Flags tells us what fields have been set in this object.

This is required by

	./gtp-tunnel del

otherwise, build helper function adds the MS/UE address and kernel reports
ENOENT, and tunnel identifier is ignored.

Update gtp-tunnel tool to set flowid to zero in the GTP version 0 case,
otherwise kernel reports EINVAL since now this flag is not ever set.

Change-Id: I66677ab2d4de2c459ed9987c465fce6f059d6d93
2024-02-15 15:42:02 +01:00
Pablo Neira Ayuso 67e1fef97d gtp: provide interface to set family
Kernel now supports for TID/I_TEI to be used in both IPv4 and IPv6 GTP
tunnels. This improves dualstack support for MS/UE so GTP traffic can
be identified with the same tunnel identifier.

Update gtp-tunnel to specify the family, since a tunnel is now
identified by the following tuple [ version, identifier, family ].

Change-Id: I584d3997ffb89cd430dfda9615a4ce0ce517ab2a
2024-02-15 15:42:02 +01:00
Oliver Smith a295615229 Add IPv6 support
Implement IPv6 in libgtpnl and the gtp-tunnel testing tool. Allow to
combine:

- GTPA_MS_ADDRESS and GTPA_PEER_ADDR6
- GTPA_MS_ADDR6 and GTPA_PEER_ADDRESS

to specify IPv4-in-IPv6-GTP and IPv6-in-IPv4-GTP in the tunnel
declaration from control plane.

This patch is based on multiple patches from Pablo in OS#6123. I decided
to squash them to directly implement v4-in-v6 and vice versa, instead of
implementing another variant first and then changing it again.

Co-developed-by: Pablo Neira Ayuso <pablo@netfilter.org>
Related: OS#6096
Change-Id: If864c9170f74af52a95cbc4cdb1b866e0309306b
2023-10-24 13:54:09 +02:00
Oliver Smith 717db098c7 Use struct gtp_addr for ms_addr and sgsn_addr
Prepare for IPv6 support by using a new struct for MS and SGSN
addresses, in which either an IPv4 or IPv6 can be stored.

Related: OS#6096
Change-Id: Ifc7e3b03a723fb544d1c7b789101102b2c27b60e
2023-10-19 16:09:15 +02:00
Pablo Neira Ayuso 99a5c32546 gtp-genl: allocate room for maximum IPv6 address
Otherwise, inet_ntop() might return ENOSPC because of the buffer
being too small to accomodate an IPv6 address.

Change-Id: I2283e0c3112bec8e6e7e7b5c96657facc09d0a7a
2023-10-19 11:55:50 +00:00
Pau Espin 6e7f2f2aa3 Bump version: 1.2.2.1-9fa7-dirty → 1.2.3
Change-Id: I9530d28a2deb4c31be0d1929a37e956c56f55b36
2022-06-28 16:13:45 +02:00
Neels Hofmeyr 9fa76ec4d6 fix some cases of rc == 0 on error
When genl_socket_talk() fails, return rc != 0.

While testing the new osmo-upf program, I noticed that I failed to get a
"Operation not permitted" error when forgetting to set cap_net_admin on
the osmo-upf binary. It looked like everything should work, but doesn't.

It is possible to catch these error cases without this patch, by
monitoring errno. That may well be the intention of the API? I'm still
submitting this patch because it seems better to return rc != 0.

Here is a code example that also catches all error cases without this
patch:

        errno = 0;
        rc = gtp_add_tunnel(genl_id, nl, t);
        if (errno) {
                rc = -errno;
        } else if (rc) {
                rc = -EINVAL;
        } else {
                tun->active = true;
        }
	return rc;

Related: SYS#5599
Change-Id: I22fd69709e023572c6c616a4184340a554456faf
2022-04-28 08:03:58 +02:00
Pau Espin f76e213543 Bump version: 1.1.0.5-b1ad-dirty → 1.2.0
Change-Id: I4b72bfb1c9c2413e84e9d8a1c5ebc19d476aada1
2018-05-02 16:37:14 +02:00
Pau Espin 16fa45f155 configure.ac: Depend on osmo-release.mk
The osmo-release.mk script can be found in libosmocore and it is used in
most osmocom related projects to help create new releases.

LIBVERSION is moved to src/Makefile.am since osmo-release.mk greps for
Makefile.am to find LIBVERSIOn changes. In any case, we don't need in
the global include makefile.

Change-Id: I5d163535c34369c74ece26574c8b1601bc1697b7
2018-05-02 16:36:24 +02:00
Harald Welte f86d9b40b1 Fix CTRL_ATTR_FAMILY_ID attribute size
This fixes the following kernel error message:
	netlink: 'osmo-ggsn': attribute type 1 has an invalid length.

This is due to CTRL_ATTR_FAMILY_ID being defined as a 16bit netlink
attribute, but us encoding it as u32:
	netlink/genetlink.c:    [CTRL_ATTR_FAMILY_ID]   = { .type = NLA_U16 },

let's properly encode it as 16bit and hence resolve the error message.

Change-Id: I41b2719ffc24d7a3420b5980f2a967264e606d91
Closes: OS#3216
2018-04-26 21:46:04 +02:00
Harald Welte 03cb4c2d66 gtp_build_payload(): Support absent peer and SGSN address
When deleting a PDP context via "gtp-tunnel delete", we specify only
the gtp netdevice, the gtp version and the TID/TEI.  However, the
gtp_build_payload() function unconditionally created the netlink
attributes for GTPA_PEER_ADDRESS and GTPA_MS_ADDRESS, having their
addresses set to zero.  The kernel then tried to find a PDP context with
MS and PEER address of 0.0.0.0, and always failed with ENOENT.

The same problem also occurred with OsmoGGSN and OpenGGSN: PDP contexts
could be added but never removed.

The corresponding kernel change that requires this userland change
is the following commit introduced in 4.12-rc1:

commit d9e2dd122637034a0697bf268eed9233701b9dca
Author: Andreas Schultz <aschultz@tpip.net>
Date:   Thu Mar 9 17:43:00 2017 +0100

    gtp: unify genl_find_pdp and prepare for per socket lookup

Older kernels will work with libgtpnl both before and after this commit,
as they internally will simply disregard any attributes beyond TID/TEI.

Change-Id: Ie2ceb2cd6d2fb009bba01a05b5480c1ad775d619
2017-11-12 22:48:15 +09:00
Harald Welte 4e3960c89f Add genl_socket_close() function
We've had genl_socket_open() but no corresponding genl_socket_close()
so far.  Let's fix that.
2017-11-08 16:15:59 +09:00
Jonas Bonn 6e9afbbc30 Rename netlink attribute
This aligns with a kernel patch that renames the netlink parameter
to emphasize that it refers to the remote peer which may be either
a GGSN or an SGSN.

The upstream kernel include file retains the legacy name as a define
but we don't need that in our internal library since we are no longer
using it anywhere.
2017-03-24 15:39:17 +01:00
Harald Welte 3bf55c32be Add support for SGSN role via IFLA_GTP_ROLE
This patch corresponds to a Linux kernel patch extending the kernel GTP
to also cover the SGSN role, not just the GGSN role.  In order to keep
the API/behavior compatible, gtp_dev_create() will continue to create
GGSN-side tunnels, while a new gtp_dev_create_sgsn() is introduced to
create SGSN-side tunnels.

Signed-off-by: Harald Welte <laforge@gnumonks.org>
2017-03-24 15:39:17 +01:00
Harald Welte 6d60a402b2 Add support for SGSN role via IFLA_GTP_ROLE
This patch corresponds to a Linux kernel patch extending the kernel GTP
to also cover the SGSN role, not just the GGSN role.  In order to keep
the API/behavior compatible, gtp_dev_create() will continue to create
GGSN-side tunnels, while a new gtp_dev_create_sgsn() is introduced to
create SGSN-side tunnels.

Signed-off-by: Harald Welte <laforge@gnumonks.org>
2017-03-24 15:39:17 +01:00
junpei yoshino 345d687038 Fix look-up of GTP tunnel by TEI
I can't look tei by gtp-tunnel in GTPv1.
I write patch for libgtpnl.

head version

$./tools/gtp-tunnel add hoge v1 65535 65535 10.0.3.2 192.168.0.2
$./tools/gtp-tunnel list
version 1 tei 0/0 ms_addr 10.0.3.2 sgsn_addr 192.168.0.2

fixed version

$./tools/gtp-tunnel add hoge v1 65535 65535 10.0.3.2 192.168.0.2
$./tools/gtp-tunnel list
version 1 tei 65535/65535 ms_addr 10.0.3.2 sgsn_addr 192.168.0.2
2016-08-25 13:06:53 +09:00
Harald Welte 80c3ffafd0 fix 'make distcheck': Add internal.h to noinst_HEADERS 2016-07-28 20:39:24 +02:00
Harald Welte d2bb0bc506 Re-license the library as LGPLv2-or-later
This facilitates the use from other projects such as ASL licensed
software.  We think there is no point in others having to re-implement
the GTP specific message parsing/encoding on top of libmnl, which is
LGPL anyway.

Please note that the tools are still licensed under GPL, just the
library has been changed.
2016-07-28 20:34:45 +02:00
Pablo Neira Ayuso f69f8c7362 gtp-genl: fix wrong MS address
This displays the SGSN address where we should show the MS address
instead. And use inet_pton instead.
2016-05-10 18:16:52 +02:00
Pablo Neira Ayuso b9f6ffea9c include: refresh linux header copies in the tree
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-05-10 18:03:25 +02:00
Pablo Neira Ayuso ee7bb1fb2e gtp: fix missing initialization of netns file descriptor
0 is a valid file descriptor and it is the default value after calloc(),
so set this -1 so we don't send it through netlink as used init_netns.

Fixes: 200b2f4 ("gtp-rtnl: and netns support")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-05-10 18:01:48 +02:00
Andreas Schultz 17c816ff84 gtp-rtnl: Split TID handling for GTPv0 and GTPv1
GTPv1 tunnel use separate 32bit Tunnel Endpoint Identifier's for each
direction while GTPv0 uses only one 64bit Tunnel IDentifier.

Signed-off-by: Andreas Schultz <aschultz@tpip.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-05-08 18:33:48 +02:00
Andreas Schultz af422a432c gtp-rtnl: real_ifname is not long needed, remove it
Signed-off-by: Andreas Schultz <aschultz@tpip.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-05-08 18:33:45 +02:00
Andreas Schultz e962741554 gtp-rtnl: sync GTPA_FLOW nl attribute name from kernel to userspace
Signed-off-by: Andreas Schultz <aschultz@tpip.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-05-08 18:33:42 +02:00
Andreas Schultz 4977330369 gtp-rtnl: and netns support
Signed-off-by: Andreas Schultz <aschultz@tpip.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2016-05-08 18:33:40 +02:00
Harald Welte 51b00a6c6c Add copright headers and license files, list Pablo as author
The kernel module still only listed me as author, even though Pablo
was doing most of the work on it after my initial incomplete version.
2014-04-03 09:37:38 -04:00
Pablo Neira Ayuso 717797b885 build: link this library to libmnl
With this change, application don't need to pass to the linker -lmnl
which is the right way to make it since they don't directly refer to
mnl_* functions.
2014-03-21 13:54:53 +01:00
Pablo Neira Ayuso deb54083e2 gtp-rtnl: add gtp_dev_config function
This function allows us to set the gtp0 device configuration the route
to encapsulate all traffic that is addressed to the MS from the GGSN
2014-03-20 16:47:00 +01:00
Pablo Neira Ayuso 1f683290fd gtp-rtnl: refactor common rtnetlink socket initialization code
This allow reusing this code in follow up changes.
2014-03-20 16:21:29 +01:00
Pablo Neira Ayuso b976ffa42c libgtpnl: add flow id support
Add new attribute to the gtp tunnel object, this extension is required
by GTPv0 since the same flowid needs to be used for uplink and downlink
packet.
2014-03-20 13:57:22 +01:00
Pablo Neira Ayuso 2d875f2c72 gtp-rtnl: remove debugging message that print netlink message 2014-03-20 10:33:18 +01:00
Pablo Neira Ayuso 7aa2087885 allow to specify the interface name for the GTP device
We can use this to specify 'gtp0' from openggsn, so we make sure that
it always uses the same tunnel device on creation. If it already exists,
it will return EEXIST. This is used to skip the problem of lacking
NLM_F_ECHO in the rtnetlink link interface that allows us to know the
name of the gtp device that has been dynamically allocated from the
kernel.

And, finally, I don't find any use case for having more than one tunnel
device when integrating this with openggsn.

This patch also adjusts tools/gtp-link-add.c which needs some care, since
it is not yet using any of the library functions. This tools are likely
to be useful for troubleshooting and debugging.
2014-02-24 11:41:51 +01:00
Pablo Neira Ayuso dea76a0069 gtp: create socket from userspace and pass them as configuration
openggsn already sets up the UDP sockets that we need for the control
and user planes of GTP. Since we cannot bind two UDP sockets (one from
userspace and another from the kernel) to the same port, change the
current code to pass the socket descriptors that has been allocated
by openggsn (or whatever daemon which uses the GTP kernel
infrastructure).

Two new attributes are added to set up the tunnel device: IFLA_GTP_FD0
(for GTP0) and IFLA_GTP_FD1 (for GTP1u), which specify the UDP socket
created from userspace. Thus, the GTP kernel code only takes care of
enabling the kernel UDP encapsulation routine.
2014-02-23 23:09:59 +01:00
Pablo Neira Ayuso 41ff538fb4 gtp-rtnl: add gtp_dev_destroy
This function allows you to destroy the gtpX device.
2014-02-22 23:19:58 +01:00
Pablo Neira Ayuso 10df05902b gtp-rtnl: refactor code to prepare the addition of gtp_dev_destroy
Add gtp_dev_talk() and gtp_put_nlmsg().
2014-02-22 23:09:38 +01:00
Pablo Neira Ayuso 3876ef618d gtp-rtnl: fix leak in struct mnl_socket on error in gtp_dev_create()
Release it in the error path.
2014-02-22 22:50:00 +01:00
Pablo Neira Ayuso 0829e0efeb gtp-genl: fix compilation warning
Fix these compilation warning:

gtp-genl.c:131:8: warning: 'pdp.version' may be used uninitialized in this function [-Wmaybe-uninitialized]
gtp-genl.c:132:8: warning: 'pdp.tid' may be used uninitialized in this function [-Wmaybe-uninitialized]
d  CCLD   libgtpnl.la

By initializing the pdp object.
2014-02-22 22:30:23 +01:00
Pablo Neira Ayuso 18532955e2 add struct gtp_tunnel and adapt functions to use it
This patch adds a gtp_tunnel structure to avoid having to deal with
functions with lots of parameters. This should also help to extend
the interfaces and the gtp_tunnel object without breaking the binary
interface (which will be good by when ipv6 support will be added).
2014-02-22 22:30:14 +01:00
Pablo Neira Ayuso 14506665d9 add libgtpnl
This patch adds the libgtpnl library. Harald mentioned that he wanted
that the specific code that is added is well encapsulated, so let's
start a small library to interact with the GTP kernel module via netlink
interface.

This was done a bit while in the rush, so the interfaces are not nice
at all and the tools need to be ported on top of this library.

This library will be used to integrate openggsn with the GTP kernel
module.
2014-02-20 19:41:29 +01:00