Also make linter happy:
sgsnemu/cmdline.c:4: WARNING:LEADING_SPACE: please, no spaces at the start of a line
Change-Id: Ie89a9f9de64cd59d21341b6f381b32f56693840f
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
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
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
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
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
While at it, move internal functions of gtp.h to a separate file too.
Make all functions that are only used inside gtp.c static.
The following APIs are unexpectedly public:
* imsi_gtp2str gets used by pdp.h
* gsna2in_addr, gtp_echo_req gets used by osmo-sgsn
Change-Id: I72c40cbdec33449ca8104fb3cad8df1a9e07dfd7
Move all includes from /usr/include/….h to
/usr/include/osmocom/gtp/….h to be more consistent with other Osmocom
projects, and to not "pollute" the top include directory if we add more
header files.
Also the new directory structure makes more obvious, which headers are
public and which ones aren't.
Adjust libgtp.pc.in so both #include <gtp.h> (legacy)
and #include <osmocom/gtp/gtp.h> can be used.
Related: OS#6373
Change-Id: If7e01c61168819bf7120667344e40c857da5490b
This reverts commit 0917ce4e22,
as it breaks building osmo-sgsn. This needs to be reworked to be
backwards compatible.
Related: OS#6373
Change-Id: I2c2b2ff0875217e041d94c8e2cef030d2a86c2d8
The device name option could be empty, using it without checking
would crash sgsnemu. Using the real device is better anyway.
Change-Id: Ic3934281bfc2e433323e4ab72cf5be2cbd1c962a
Until now, sgsnemu was able to identify pdp contexts of incoming packets
in the tun based on the assumption that the Interface-Identifier part of
public IPv6 addresses in incoming packets was equal to the announced
prefix path during Create Pdp Context Response (see changes in cb_tun_ind()).
This assumption works fine with osmo-ggsn due to implementation details but
breaks on other spec-conformant GGSNs.
In order to fix it, a new placeholder struct pdp_peer_sgsnemu_ctx is
introduced which will be assigned to each pdp_t "peer[0]" user-defined
pointer. This way, each pdp_t ctx upgrades from having only 1 iphash_t
item to 3 (hence being able to match against 3 different ip addresses).
This way, in IPv6 we can match against 2 different IP addresses set on
the tun iface:
* link-local: "fe80::IfId", where IfId is the Interface-Identifier
received during Pdp Context Resp and which can be used to communicate
with the nearest router (the GGSN).
* global: The global IPv6 addr set after SLAAC procedure, containing a
the prefix announced by CreatePdpContextResp/RouterAdvertisement and
an Interface-Identifier chosen by sgsnemu itself (currently ::ff).
This change is also a step forward towards supporting IPv4v6 APNs in sgsnemu.
Related: OS#4434
Change-Id: I0d36145250185e4cce699fdaedfe96bd969f5fa1
Disable IPv6 automatic SLAAC by linux kernel and handle it manually.
This allows us gaining control on local address acquisition and set
addresses and routing properly. It will also allow us to run in ping
mode without a tun iface.
Related: OS#4434
Change-Id: Iae59cf6ffb181357e10b3080a5c751bd454f4a1f
On older systems (like debian 8), the enum is not present in the header
file and build will fail (as saw in osmocom's OBS instance).
Furthermore, the sysctl to change the value was added at a later point
in time, which means compiling can go fine but running may fail due to
the sysctl not being available.
This is a fix-up to Change-Id I1d51f3ca91edbb3b788939982ab63264182ec2ce
Change-Id: I208970d5b16ea7148444d414b0a6f68c8d9a086c
Functions for IPv6 will be added soon afterwards. Also take the chance
to check for address length in sgsnemu and only apply the route if the
address matches.
Change-Id: Ic6c1b3c11c56f047e6e8c6f1040257fd62afea0f
It's not needed because a link-local address will be added as a result
of Create Pdp Context Response. Morevoer, it fools sgsnemu ip addr
verifications since it gets used on some scenarios by applications.
Change-Id: I1d51f3ca91edbb3b788939982ab63264182ec2ce
Let's avoid buffer-overflow writing into out-of-bounds memory in the
event the GGSN sends us 2 EUAs in Create PDP Context Respose. It should
theoretically happen since we don't yet support ipv4v6 APNs in sgsnemu,
but who knows.
Change-Id: I8becd90ce1f0e8bb6e21438c04da4a9cab845492
Modern gcc-9.2.1 actually fails like this with --enable-werror active:
In file included from sgsnemu.c:52:
In function ‘process_options’,
inlined from ‘main’ at sgsnemu.c:1557:6:
../lib/syserr.h:31:3: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
31 | logp2(sub, pri, __FILE__, __LINE__, 0, \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
32 | fmt "\n", ##args); \
| ~~~~~~~~~~~~~~~~~
sgsnemu.c:435:3: note: in expansion of macro ‘SYS_ERR’
435 | SYS_ERR(DSGSN, LOGL_ERROR, 0,
| ^~~~~~~
sgsnemu.c: In function ‘main’:
sgsnemu.c:436:42: note: format string is defined here
436 | "Listening address must be specified: %s!",
| ^~
It is correct: We are dereferencing args_info.listen_addr in a
branch which explicitly checks if that is NULL beforehand :/
Change-Id: I417f447f821d396aa92049e0a791121240f1cf44
Catched by gcc 9.1.0:
osmo-ggsn/sgsnemu/sgsnemu.c:1294:2: error: converting a packed struct ip_ping pointer (alignment 1) to a uint16_t {aka short unsigned int} pointer (alignment 2) may result in an unaligned pointer value [-Werror=address-of-packed-member]
1294 | p = (uint16_t *) & pack;
Change-Id: I783f104c31234a07f2a13f6dbc577a71b25b36a7
This way, the IP address / route handling between TUN devices and kernel
GTP can be shared, which will provide not only a unified codebase but
also a more consistent behavior.
This also paves the road for to use kernel GTP from sgsnemu in the future.
Related: OS#3214
Change-Id: Ic53a971136edd0d8871fbd6746d7b0090ce3a188
This param is parsed by gethostbyname() and it's confusing to document
it as an interface, because users will then attempt to pass "lo" to it,
which fails.
Change-Id: Id8ef0e12ddcaf8bfd199a44de0ba4280f05d4431
Older commit switched pdp_t to have an array of 2 peers instead of
only one in order to accomodate for ipv4v6 contexts, which can have 2
addresses assigned. The usage of peer field was not updated in sgsnemu
accordingly, which means the wrong memory portion was being accessed.
Fixes: 2d6a69e69a ("Add support for IPv4v6 End User Addresses")
Change-Id: I9e563522173a82b265e93b1ef9dc93ced40fefa2
in "createif" mode uplink traffic not forwarding
from tun interface into Gn, inside GTP-U.
create_pdp_conf get iphash (ipm) with pdp == 0x0
Fix - in create_pdp_conf - instead of casting using already
definned iphash in ipset function.
Change-Id: Icd58450548b3a47cb933d70a2e3166c067552b2c
No warnings when used options from "pinghost" and "createif" groups
in a same time. sgsnemu created tun0 interface and send pings inside
G-PDU, but didn't calculate replys. Added options modes to avoid
mutual exclusion options.
Change-Id: I196df7838212dcddecd64a64a6cba613b6cfced0
"sgsnemu" stopped with the message "Received create PDP context response. Cause value: 128",
but normaly at that poit it should continue working and create "user plane".
Reason: Funtion "create_pdp_conf" checking result of "in46a_from_eua" and mistakenly
returned EOF when more than 1 IP address provided by GGSN.
Now function "create_pdp_conf" stopped with error when 0 IP provided or error code comes from "in46a_from_eua".
Fixes: 2d6a69e69a ("Add support for IPv4v6 End User Addresses")
Change-Id: I7881b8e1f27c432007cb6e5ff665a2ce55f103b5
sgsnemu (the only user of this API so far) has been modified to use the
new API with in46_addr.
FreeBSD code for IPv6 has not been tested.
Change-Id: Ie36afe6eaf393855a4a708000ef4ad0192bf4767