832 Commits

Author SHA1 Message Date
Pau Espin Pedrol
88d65840aa sgsnemu: Initial support IPv4v6 PDP context type
Related: OS#4433
Change-Id: If6eb2f1a5d0fb71da80e289112a67dd2faa30b4b
2025-07-16 19:08:13 +02:00
Pau Espin Pedrol
3aa81c594d cosmetic: sgsnemu: Fix trailing whitespace
Also make linter happy:
sgsnemu/cmdline.c:4: WARNING:LEADING_SPACE: please, no spaces at the start of a line

Change-Id: Ie89a9f9de64cd59d21341b6f381b32f56693840f
2025-07-16 19:03:38 +02:00
Alexander Couzens
5a97e87eed tests: add a simple gtpie_getie() test
Change-Id: I5cd45d752592c7133d4452f4e4986783fb17e256
2025-07-05 01:31:00 +02:00
Alexander Couzens
d46d0cc368 gtp: add support for SGSN Context Req/Resp/Ack
To handle both incoming and outgoing SGSN Context via GTPv1.
Introduce a FSM which handles the state of SGSN Context to simplify
the API for the SGSN which uses libgtp as well as the external SGSN
which communicates via GTP.

Change-Id: Idb8ed0bb87200a68bb8caedd734fc070df9179c0
2025-07-05 01:20:59 +02:00
Alexander Couzens
a564344d54 gsn: fix coding style issue
Remove a space between callbacks.

Change-Id: I1d978ed32619b626e82aa70887ac94b82c4de378
2025-07-04 22:28:33 +02:00
Alexander Couzens
2d4cc5ad4c gtp: move LOGP_WITH_ADDR & GTP_LOGPKG into gtp_internal.h
Log macros will be used by multiple internal files.

Change-Id: I3b59b067fc75d2ca2cbfe5cec010615e9b788923
2025-07-04 22:28:33 +02:00
Alexander Couzens
4407fc32ae gtp: internal LOGP_WITH_ADDR macro: use pointer of peer
Using a pointer is more universal for the macro.
Further the upcoming SGSN Context Req/Response/Ack code will use
a peer pointer instead of the direct object.

Change-Id: Iab11a8b07eb177c479e1920cd7fa8be2099a4b7b
2025-07-04 22:28:33 +02:00
Alexander Couzens
1e1a66a8f7 gtp.c: no-op: use ntohs instead of htons
Even the operation is the same, the sin_port is in network order.

Change-Id: Iebb031debfa7706f0ab682c94492b37573ae918d
2025-07-04 22:28:33 +02:00
Alexander Couzens
90309f958a gtpie: make ies const for getter
Getter's don't modify the ie.
Making it const is compatible with previous versions.

Change-Id: I43195314b1cf416a1f2fd4d3ddd48c4eee462b0b
2025-07-04 22:28:33 +02:00
Oliver Smith
34cb772bb4 Generate a version.h file
Related: OS#6626
Change-Id: If3972eb4e56073f8faf58b09d014a811d4a5f401
2025-06-23 16:39:14 +02:00
Daniel Willmann
5f64814986 gtp: Send RAT type IE in update context request if present
Change-Id: Idbabd123838b88cb0a2407480ca5fab10312a547
2025-06-04 16:44:56 +00:00
Pau Espin Pedrol
6cd61eed5c Drop use of deprecated vty is_config_node() cb
This callback was drepecated and is not ever called since
libosmocore.git 70ce871532ab21955e0955d7e230eae65438f047 (release 1.3.0).

See also libosmocore.git d31de237582f6fe3315d61bb9a488d4cda92654e.

Change-Id: Ief57c4ce98055e5063aafc53cb8330d3bd95d323
2025-03-05 14:55:03 +00:00
Daniel Willmann
4bcb2f72e4 Fix Typos
Change-Id: Id39fdec016115b34453698b73aacf7be7461504b
2025-03-05 15:40:21 +01:00
Oliver Smith
ba3d8905f9 Bump version: 1.12.0.37-cf65-dirty → 1.13.0
Change-Id: I7dbdd71d62fb13ba2ffc30d7d50fb4207a06340b
1.13.0
2025-02-12 12:09:58 +01:00
Alexander Couzens
cf65292b0d gtp: split gtp_req into 2 parts: transmit and fill header
Split the preparing the data from the socket and queue handling into two functions:
gtp_req(): preparing the data
gtp_req_transmit(): selecting socket, port and adding it to the transmit queue.
In a following commit gtp_req_transmit() can be used by gtpv1 function
as well.

Change-Id: Icda0ef7b0ce3631e23da88827dd54cf019878b5d
2025-01-12 21:03:39 +01:00
Alexander Couzens
71fefdad09 gtpie: add gtp_encaps a modern encapsulation method
No idea why the previous ones started at the second IE.
Further add more length arguments to the encapsulation method.

Change-Id: I8bb086c568e07052c52d880df06049490346e91e
2025-01-12 21:03:27 +01:00
Daniel Willmann
4b8ebcd784 gtp: Rework gtp_resp() into gtp_resp_pdp()
gtp_resp() requires a PDP context. To support more generic messages
without a PDP context, rename gtp_resp() into gtp_resp_pdp() and
create a more generic function to transmit a GTP response.

Will be used by the SGSN Context Req/Resp/Ack code.

Change-Id: Id9ff95e0e2a10a22e65ecf42b2a2b06a0f2d1a45
2025-01-07 13:39:01 +01:00
Alexander Couzens
446dd65de1 gtp_new(): use talloc instead of calloc/free
Required for SGSN Context Req fsm which is using talloc.
Adds a new api to set the libgtp talloc context via gtp_set_talloc_ctx()

Change-Id: I7c4a29c4bb1ef3c7bf506e59e99b3a804cabe34b
2025-01-07 13:35:54 +01:00
Pau Espin Pedrol
09142e1c27 jenkins.sh: Use --disable-doxygen configure param
Change-Id: I0c73c5e5c94bb712975f8ae0c6cff4743e148210
2024-12-10 17:07:54 +01:00
Alexander Couzens
04f5ea4ffa gtp.h: add more GTP cause code from 29.060 v15.3.30
Change-Id: I1571286f01a24adf10243c9551ca81bacc12f8f9
2024-11-25 16:29:08 +01:00
Daniel Willmann
839c2b9c84 gtp: Make peer addr const in gtp_req/gtp_resp
Change-Id: I955b82ba8022754c3d23979d5c55bb61233047b1
2024-11-25 16:29:08 +01:00
Alexander Couzens
65e133b42c gtpie: fix comment
Change-Id: I5aed6a7a2ae4138567944988bc81cebdbf129276
2024-11-25 16:29:08 +01:00
Alexander Couzens
95746b9588 gtp_internal.h: add missing include to <stdint.h>
Change-Id: I4b9a9b582854368b3492cb7438b3acb1a9652f9e
2024-11-25 16:29:08 +01:00
Pau Espin Pedrol
2b161df6af doc: Update all iptables references with nftables
Change-Id: I3caf316e8ccf1d757b83f7a119271084c55e018c
2024-10-25 14:58:52 +00:00
Pau Espin Pedrol
13d23077d2 doc: Document MTU features in User Manual and example config files
Related: OS#6298
Related: SYS#7122
Change-Id: Ib6e974b38107fe48072380f768e1881f0fc95e80
2024-10-25 14:58:52 +00:00
Pau Espin Pedrol
a4cb3eb011 tun: Use OSMO_STRLCPY_ARRAY
tun->devname buffer is already IFNAMSIZ bytes long, so simplify the
code.

Change-Id: I40b370f4152748d5acf6ee576462e54c9a46a8a3
2024-10-25 16:28:43 +02:00
Pau Espin Pedrol
9f1fd42148 Refactor tun_t fields and alloc APIs
The previous state of code made allocation code more complex for no good
reason; use usual alloc() type function instead, splitting between the 2
types of tun_t implementations available to make it easier to
understand.

Move the several tun-iface specific mode fields to a substruct to make
it clear those are only really containing useful information when the
tun_t is created in tun-iface mode.

Change-Id: Ic71f91c62cd5bd48c6d35534eaac2091e4c69735
2024-10-24 15:49:39 +02:00
Pau Espin Pedrol
ad03073219 Rename tun_encaps -> tun_inject_pkt
The terminology of "encapsulating" used in tun_encaps is confusing,
since in this case we are not really encapsulating anything, but
actually delivering ("injecting") the packet to the system network
stack.
Using the "encapsulating" term is also confusing because readers may
think it may be doing the GTP-U encapsulation, which is not.

Change-Id: Ibb17c792b81668571e69d79918f3adf0e9e0f6c8
2024-10-23 18:45:16 +02:00
Pau Espin Pedrol
234cd12ea5 tun.h: Remove non-existent tun_decaps()
Change-Id: If9cc5d2d54b87e38feefa55cb9410715fa9bd11f
2024-10-23 18:44:05 +02:00
Pau Espin Pedrol
d73801ebea ggsn: Rename confusing functions
It's really confusing having a function operating on a rx path called
"encaps" since it's not really encapsulating anything.
This confuses the reader by thinking this is the function encapsulating
packets into GTP-U.

Change-Id: I7ff54f5e57ccc2c436becd1be1b0f728cbcdb12c
2024-10-23 18:42:43 +02:00
Pau Espin Pedrol
1d7e86ae48 ggsn: Avoid forwarding IPv6 solicited-node multicast addr to tun device
There's no need to forward those. Morevoer, they cannot be forwarded
when using gtpu kernel mode since it doesn't support reinjecting packets
we got from it, so avoid erroring out when trying to inject them later
on.

Related: OS#6600
Related: OS#6382
Change-Id: Iac8f14083620d86f3872aa951930fbe8f680ff24
2024-10-23 18:20:57 +02:00
Pau Espin Pedrol
56a6e025d3 tun: Fix null pointer derefence when in kernel gtp mode
When using gtp kernel module, the kernel sends GTP-U packets to
userspace (osmo-ggsn) when it is unable to find a related pdp ctx for
the packet.
This is so far processes through the code path:
ggsn_gtp_fd_cb => gtp_decaps1u => gtp_gpdu_ind => encaps_tun = > tun_encaps

In usual circumstances, if the gtp module sends a packet to userspace
because it is unable to find a pdp ctx, userspace shouldn't be able
anyway, so it should go through a different code path and answer over
GTP-U with a "Error Indication".
Other specific packets (such as ICMPv6 with link local address) are also
being forwarded to userspace. Some of them are being handled in
encaps_tun() in a special way (eg. Router Soliciation), but others, such
as Neighbor Solicitation, are not being handled there and follow the
generic path where they try to be forwarded over the tun towards the
Internet.

When using the kernel gtp mode, there's no way to re-inject into the
network stack a packet we received from the gtp mode, like done when
using the tun device mode.

Prior to 38b607ece3, a bug existed in
tun_encaps() which would still try to use tun->fd (-1) when in gtp
kernel module, which ended up in an error being printed.
After the mentioned commit was applied, when in gtp kernel module it
started accessing tun->tundev which is is NULL under that setup, hence
making the bug consequences worse.

Add a pointer guard with a log line to inform about the problem, while
still discussing the originating problem in OS#6600.

Related: OS#6600
Change-Id: I508758696a0bcbb7c780a0ed33b28ba640602488
2024-10-23 15:39:47 +02:00
Pau Espin Pedrol
c075d032b9 doc: Reorder some chapters
Move general/generic osmocom chapters (logging, vty) further to the end,
so that the osmo-ggsn specific chapters stay together and don't get lost
in tons of generic content.

Change-Id: I6441944cc365bae40ab0f3cc4f1ecd1ac790c5c5
2024-10-22 19:45:18 +02:00
Pau Espin Pedrol
d44bf6fd73 doc: Fix typo: wrong interface named
Change-Id: Ib7ef619c74bf0e6453f0d5ba509e7727bf90f838
2024-10-22 19:45:18 +02:00
Pau Espin Pedrol
77d4ae0470 doc: Remove reference to non longer existing osmo-ggsn.init
The init file was removed at some point in the past.
Nowadays only a systemd service is provided.

Change-Id: I47f889a223bfaf7bd4848898211a3cc62df5e08c
2024-10-22 19:45:18 +02:00
Pau Espin Pedrol
e6feda5185 doc: Fix typo in user manual
Change-Id: I9b0024cfdb748febcecf01a097125103bc0f39c1
2024-10-22 19:45:18 +02:00
Pau Espin Pedrol
f92d875119 ggsn: apply configured APN MTU to tun
Related: OS#6298
Related: SYS#7122
Change-Id: Ifae556169d895860812c9ea5633292d7e3fab338
2024-10-22 19:45:18 +02:00
Pau Espin Pedrol
454110a007 ggsn: Use osmo_netdev_addaddr() libosmocore API
This allows dropping a lot of duplicated code.
While at it, drop references to non-linux systems, which are not
maintained anymore.
Param "dstaddr" was not used anywhere in the old APIs, so it can also be
dropped.
Param "tun->routes" was also used in BSD code, so it can also be
dropped.

Change-Id: I1fccfd658542481cd61536fbd3c7a3a32a1c253b
2024-10-22 19:45:06 +02:00
Pau Espin Pedrol
38b607ece3 ggsn: use libosmocore tundev API to create apn tun device
This way we can start dropping old osmo-ggsn specific API, avoiding
duplication of code.
Moreover, the osmo-ggsn code is using older ioctl APIs, which are
discouraged nowadays in favour of netlink, which osmo_tundev/osmo_netdev
from libosmocore is used.
Even better, we win for free non-blocking write behavior in the tundev
when switching to the new API, since it already has its own internal
wqueue.

While doing this, BSD code is dropped since anyway it's not been
maintained for a long time.
If needed, the BSD support can be added to libosmocore
osmo_tundev/osmo_netdev API.

This is a first step (already working). Follow-up commits will replace
the APIs to set up routes and addresses, and later on osmo-ggsn will win
support to set MTU on the interface.

Furthermore, this will allow easily adding netns support to osmo-ggsn
later on if ever needed.

Depends: libosmocore.git Change-Id Ia8a7e7ec6d96c7aebc80528236a0e0d035e7f38d
Change-Id: I4d99ba147ac0f3b414d2efef0068b6b8d6cf0014
2024-10-21 18:45:32 +02:00
Pau Espin Pedrol
41bec9529f ggsn: Support announcing APN MTU over ICMPv6 RA
Related: OS#6298
Related: SYS#7122
Change-Id: I8bb67915dd5f39ad9ffb80e5aaf9af1e7d70c96c
2024-10-21 18:45:32 +02:00
Pau Espin Pedrol
6041554cef ggsn: Support announcing APN MTU over PCO
This is only useful for IPv4 (or IPv4v6) APNs.
IPv6 APNs obtain this information from SLAAC RA.

Related: OS#6298
Related: SYS#7122
Change-Id: I8532acfffadda9e83962b30e4f6b17eb8b3362ac
2024-10-21 18:45:32 +02:00
Pau Espin Pedrol
6d1d181403 vty: Fix missing newline in description of 'apn tun-device' cmd
Change-Id: I92002acdb83455eb6becc688c33192d3856b0aa6
2024-10-21 18:45:24 +02:00
Pau Espin Pedrol
7d80216717 Move g_ggsn_list declaration to ggsn.c
The llist belongs to the data domain, not the vty.

Change-Id: I0a93aacbdecc283dd4f6b32892430ebdb0b94e50
2024-10-17 18:58:10 +02:00
Pau Espin Pedrol
de385e0253 Move ggsn allocation code out of vty file
The details of creation of data structures don't belong on the vty file.
While at it, split allocation code into its own function to quickly find
out where the allocation of the object happens.

Change-Id: Iaa4cd86c44957321c238d268ea62daafa1b79c69
2024-10-17 18:56:55 +02:00
Pau Espin Pedrol
ce691d8e64 Move apn allocation code out of vty file
The details of creation of data structures don't belong on the vty file.
While at it, split allocation code into its own function to quickly find
out where the allocation of the object happens.

Change-Id: If15a4158dd6599341017efd24dbf67ca565a7c34
2024-10-17 18:51:39 +02:00
Pau Espin Pedrol
8c015bd89a ggsn: kernel gtpu: Support updating pdp ctx remote IP address and TEID
Whenever the SGSN sends the GGSN a UpdatePDPCtxReq, it may offer a new
remote IP address or/and remote TEID, eg. because it wants to establish
a Direct Tunnel and point the GTPU towards the RNC, or to point it back
to itself.
If the gtpu kernel is used, osmo-ggsn lacked updating the kernel with
the new remote data.
The gtp kernel module doesn't provide an efficient/explicit way to
update a pdp context keeping the4 same local IP+TEID and changing only
the remote remote IP+TEID, hence first destroy the pdp ctx in the gtp
kernel module and then recreate it.

This fixes test GGSN_Tests_v4_only.TC_pdp4_act_update_teid in
ttcn3-ggsn-test-kernel-net-next.

Related: OS#6523
Change-Id: I1fc48be5c0f177ccf6fbe97c003b4df44809c0fe
2024-08-19 11:57:23 +02:00
Pau Espin Pedrol
5f8960b206 ggsn: Mark internal cb function static
Change-Id: Ic9fdd50ae098058cc69e5aa6a0085819d69e3599
2024-08-01 17:45:49 +02:00
Pau Espin Pedrol
0828b2afc3 gtp: Allow setting callback to receive update_context_ind
This will be used by:
* SGSN: Get to know that RNC has gonne down according to GGSN (re-attempt
  Direct Tunnel or go back to tun SGSN<->GGSN).
* GGSN: Maybe find out that Direct Flags are used (should be handled
  internally directly in the rx path probably)

Related: OS#6512
Change-Id: Ic80a9a928c55b6ff85be96014920bb42793cb943
2024-07-31 17:23:59 +02:00
Pau Espin Pedrol
70a1d64e55 gtp: Allow UpdatePDPContext initiated by GGSN
The Update PDP Context procedure can be initiated GGSN -> SGSN, as
described in TS 29.060 7.3.3.

Related: OS#6512
Change-Id: I1c3441c71b90c5bbf6f4545484586222e6180fe1
2024-07-31 17:20:58 +02:00
Pau Espin Pedrol
ea3cf1b8ae gtp: Store rx Direct Tunnel Flags in UpdatePDPCtx{Req,Resp}
In Update PDP Ctx Response, only SGSN is expected to transmit Direct
Tunnel Flags in the message.

Related: SYS#5435
Change-Id: Ia3e360a35d30858eab1e438dc2508fd756c2e22e
2024-07-31 17:20:58 +02:00