Commit Graph

709 Commits

Author SHA1 Message Date
Pau Espin d08a15b343 gtp: queue_test: Fix printf gcc warn under ARM
queue_test.c:39:3: warning: format '%ld' expects argument of type
'long int', but argument 9 has type 'unsigned int' [-Wformat=]

Change-Id: Ie9530cdd191386ca3f6c336684f81c4582c4d962
2020-07-07 16:03:37 +02:00
Harald Welte 4e37fb356a example config: use RFC1918 addresses for GGSN pools
It's 172.16, not 176.16.

Change-Id: I2d83ee747e8987f10c4960d42f3c3f2a723e3f4c
2020-05-23 11:07:34 +02:00
Oliver Smith 6a8a389c47 Makefile.am: EXTRA_DIST: debian, contrib/*.spec.in
Change-Id: Ie9cc3da87dea413408c82b721875e89735a47fcf
2020-05-22 13:39:41 +02:00
Oliver Smith 569e46cbf9 contrib: integrate RPM spec
Remove OpenSUSE bug report link, set version to @VERSION@, make it build
with CentOS 8 etc.

Related: OS#4550
Change-Id: Iba04d5c7b9beee80baca83063f9cb2cd533a0003
2020-05-19 15:25:36 +02:00
Oliver Smith 91d9410157 contrib: import RPM spec
Copy the RPM spec file from:
https://build.opensuse.org/project/show/home:mnhauke:osmocom:nightly

Related: OS#4550
Change-Id: I50a93d2cde429974b059bafd38befa9a189c0e8a
2020-05-15 13:52:17 +02:00
Oliver Smith 065ddb6416 osmo-ggsn.spec.in: remove
Remove old osmo-ggsn.spec.in file from 2017 in favor of the one imported
from mnhauke, which is currently used in openSUSE nightly builds (will
be added in a follow-up commit).

Related: OS#4550
Change-Id: I24794564f0d4d85d3955ab08f4e4c3c05f53a0cd
2020-05-15 13:52:02 +02:00
Philipp Maier 53244a2132 debug: use LOGL_NOTICE instead of LOGL_DEBUG
In debug.c the log category DICMP6 uses LOGL_DEBUG as default. This is
way to verbose, lets use LOGL_NOTICE instead.

Change-Id: I4c6a9165114d1240e7e2cfa98d30d571a3f4e9d2
Related: OS#2577
2020-05-12 11:32:06 +00:00
Dmitri Kalashnik db98f309a9 sgsnemu: use real tun device name after the device is up.
The device name option could be empty, using it without checking
would crash sgsnemu. Using the real device is better anyway.

Change-Id: Ic3934281bfc2e433323e4ab72cf5be2cbd1c962a
2020-04-28 13:14:52 +04:00
Pau Espin 04715d284f sgsnemu: Fix assumption ipv6 Interface-Identifier of public addr == announced Prefix
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
2020-04-21 16:40:39 +02:00
Pau Espin 962146085c sgsnemu: Implement ping on IPv6 APNs
Related: OS#4434
Change-Id: If9ca7c37a1a397bbc3f8912d67bccdabc4968e0c
2020-04-21 16:40:39 +02:00
Pau Espin e2b0961f18 sgsnemu: Handle IPv6 SLAAC in tun iface manually
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
2020-04-21 14:39:42 +00:00
Pau Espin ff2ebee03b sgsnemu: Fix build/run against linux < 4.11 (no sysctl addr_gen_mode support)
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
2020-04-19 08:29:35 +00:00
Pau Espin 2a1cedd2dc Rename netdev_*route to end in route4
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
2020-04-15 16:40:10 +02:00
Pau Espin c43e887e9e icmpv6.c: Move code generating ipv6 hdr to its own function
It will be re-used in next commits.

Change-Id: I3c108efad6461cd4e82ef435290005174bc8b30e
2020-04-15 16:40:10 +02:00
Pau Espin e5d71639e5 sgsnemu: tun_addaddr: Don't set local addr as dstaddr
That should be used for point-to-point destination address.

Change-Id: Iead7e9c7570ba6a9de3089a164997b1db81dc59a
2020-04-15 16:40:10 +02:00
Pau Espin a1b3deefda sgsnemu: Get rid of duplicated options.net
It's not really set by any cmdline arg, and it always contains same
content as options.netaddr.

Change-Id: Id3cdca0975bdd2893b4b83944c5ebf29b2994622
2020-04-15 16:40:10 +02:00
Pau Espin 964f08a919 sgsnemu: Get rid of duplicated options.destaddr
It's not really set by any cmdline arg, and it always contains same
content as options.netaddr.

Change-Id: I5a4e3c4b5ae43a89a7d0af62fb396311dcb6ebae
2020-04-15 16:40:10 +02:00
Pau Espin ee1529e5ac icmpv6.c: Mark internal function as static
Change-Id: Ib38907c3a05c1651faa86ef57381ee22643e0d53
2020-04-15 16:40:10 +02:00
Pau Espin 29e7bd0510 cosmetic: icmpv6.c: fix typo in comment
Change-Id: I2217dfb0b0a1e6e029ac817902e80c771ed219c3
2020-04-15 16:39:51 +02:00
Pau Espin cdcaeda81c sgsnemu: Fix ping transmitted statistics output
Change-Id: I6e23e024ee30d6049c6b8b614c50d062d80a5260
2020-04-15 16:39:28 +02:00
Pau Espin 98f8126b98 sgsnemu: Avoid adding extra autogenerated local link ipv6 addr to tun iface
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
2020-04-15 15:10:42 +02:00
Philipp Maier a1503b902c doc: use 127.0.0.2 instead of 127.0.0.6 as bind ip.
The example config for osmo-sgsn suggests to use 127.0.0.6 as bind ip.
(the ip-address where the SGSN tries to connect) Lets use 127.0.0.2
instead to match the default config of osmo-sgsn.

Change-Id: I513ab64896dee47fd92dbc5ef495fe1c6e734ec3
2020-04-14 17:16:58 +00:00
Harald Welte 8398bccb0b lib/netns: Fix up error paths
The error handling in the code was doing exactly what one would not
expect.  If we switch to a netns and then encounter an error, we
obviously have to switch back to the original netns before returning.

Likewise, if we temporarily change the signal mask, we need to switch
back to the original one before returning.

Change-Id: I9ff5ae7bffc5bd7629dae0af1b72cfea548f9039
2020-04-14 17:15:52 +00:00
Pau Espin 5552872733 netdev_addaddr6: Use prefixlen arg
The parameter was simply unused until this change was made. An Ipv6 can
have a prefix length between 48 and 64 bits.

Change-Id: I4b1512d5a4d7bbc2516221ea6808565eac0eb18f
2020-04-14 17:15:35 +00:00
Harald Welte 61b010c25a lib/netns: OSMO_ASSERT() if user doesn't call init_netns()
It is vital that init_netns() is called first in order to initialize
default_nsfd.

Change-Id: Ic16646fa7d60c578056b17351c5fe2090a81dff0
2020-04-14 13:19:35 +00:00
Harald Welte 20d9d154c5 lib/netns.c: Add comments to the code, including doxygen API docs
Change-Id: I0b20e4870bf62df0a459a621a64a4e2795340ceb
2020-04-14 13:19:04 +00:00
Pau Espin 1c8ae66654 Move icmpv6 and checksum files from ggsn/ dir to lib/
They will be required by sgsnemu to implement ICMPv6 Router
Soliciations.

Change-Id: Ie878604f0fc0169cc98a1e9eee64b14d76be2c45
2020-04-14 13:18:21 +00:00
Pau Espin fcdaf31aa8 sgsnemu: Set its default loglevel category to INFO
sgsnemu is a testing program and doesn't have a VTY iface to configure
its log levels, so let's simply enable INFO as a default.

Change-Id: I2a577f547b57fb0ab7b83de5c12da088697f3904
2020-04-14 13:18:21 +00:00
Pau Espin 9366f4c034 sgsnemu: Rename sgsnemu's libgtp cb_conf
It makes it easier to understand where the function is called.

Change-Id: Ibf32b416c3247d1415aa9c1a88755076dcd606f4
2020-04-14 13:18:21 +00:00
Pau Espin 28c6a32677 sgsnemu: Pass array of in64_addr to in46a_from_eua()
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
2020-04-14 13:18:21 +00:00
Eric Wild 107c813eee configure.ac: fix libtool issue with clang and sanitizer
As pointed out at https://github.com/libexpat/libexpat/issues/312
libtool does not play nice with clang sanitizer builds at all.
For those builds LD shoud be set to clang too (and LDFLAGS needs the
sanitizer flags as well), because the clang compiler driver knows how
linking to the sanitizer libs works, but then at a later stage libtool
fails to actually produce the shared libraries and the build fails. This
is fixed by this patch.

Addtionally LD_LIBRARY_PATH has no effect on conftest runs during
configure time, so the rpath needs to be set to the asan library path to
ensure the configure run does not fail due to a missing asan library,
i.e.:

SANS='-fsanitize=memory -fsanitize-recover=all -shared-libsan'
export CC=clang-10
ASANPATH=$(dirname `$CC -print-file-name=libclang_rt.asan-x86_64.so`)
export LDFLAGS="-Wl,-rpath,$ASANPATH $SANS $LDFLAGS"

Change-Id: Icc09c9d09bfa01264ddf867356d068e50d97c5a0
2020-04-14 13:07:47 +00:00
Pau Espin 90d1732be1 sgsnemu: cmdline: Drop unused function cmdline_parser_params_create()
Change-Id: I7d5d69f104d24aafd4aa0b7289bb8b3fa1d77ed4
2020-04-08 19:00:19 +02:00
Philipp Maier 1c3505b885 doc: do not use random ip address for dns in default conf
The default configuration has a random ip-address as first DNS server.
This might cause unnedessary trouble for people who try osmo-ggsn the
first time. Lets have some public DNS here, just to be sure.

Change-Id: I5876a806185bb3aea356fb6996d1925b8d0d1758
2020-03-25 13:01:45 +01:00
Vadim Yanitskiy 20539f0271 lib/netns: fix open_ns(): return fd from open()
Looks like a bug introduced by I9b9c8fd6eeaaa7d190b8e2a34ca82088904c7708.

Change-Id: I38caf5541ca90638ed10714adfbb08120e5397b9
Fixes: CID#208656
2020-03-03 15:40:26 +07:00
Pau Espin ad6eaa2881 netns: Improve error checking
Change-Id: I9b9c8fd6eeaaa7d190b8e2a34ca82088904c7708
2020-03-02 09:41:43 +01:00
Andreas Schultz b629240a35 add Linux network namespace support for TUN device
Change-Id: Idd0ad8fa9c8e7ba0aeec1b52947598d4d297b620
2020-02-26 11:16:06 +01:00
Pau Espin b283c32027 cosmetic: Fix comment typo
Change-Id: I8240b388ffb8c1806bf0d34a9e59146b403a13be
2020-02-25 14:13:09 +01:00
Pau Espin e71e0f2af8 Bump version: 1.4.0.32-bd8f-dirty → 1.5.0
Change-Id: I84bbe9eff37e14985b812b49e53eb6d62fff14a5
2020-01-02 20:39:39 +01:00
Vadim Yanitskiy bd8f028bff contrib/systemd: add systemd-networkd examples from manuals
Change-Id: I265637f39dd16dd43992f33149e512e34ed83252
2019-12-06 00:47:26 +07:00
Vadim Yanitskiy a55454d58e manuals/configuration.adoc: fix IPv4 address mismatch in <<ggsn_no_root>>
Change-Id: Ide9465a01857dbe5ec7f5bc1d09468153865156f
2019-12-06 00:21:13 +07:00
Vadim Yanitskiy f1be1df0d3 manuals/configuration.adoc: fix Network Address without prefix length
"An address '192.168.7.1' is specified without prefix length. The behavior
of parsing addresses without prefix length will be changed in the future
release. Please specify prefix length explicitly."

Change-Id: I51777c6344191182fb87bae6f0048ce422802541
2019-12-06 00:20:21 +07:00
Harald Welte c22205bec8 manual: Fix copy+paste error
Change-Id: Ib6a97d8c93203e1f896ab1bd3d200d2223f9fc48
2019-12-01 14:24:19 +01:00
Harald Welte fdf3358959 sgsnemu: Fix null-pointer format string argument
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
2019-12-01 09:26:49 +01:00
Pau Espin 1bf41e4f36 ggsn, sgsnemu: Drop use of no-op deprecated gtp_retrans* APIs
Related: OS#4178
Change-Id: I295b89ee493d230c2550d461fca9602c589d38b5
2019-09-05 09:59:52 +00:00
Pau Espin c94837c6a4 gtp: Manage queue timers internally
Currently each user (application) of libgtp needs to manage its own
timers in order to call gtp_retrans_timeout() and gtp_retrans() and
maintain retransmit and duplicate queues working correctly. This adds
unnecesary complexity to applications since nowadays, as a libosmocore
user, libgtp can handle this internally in an easy way.
Furthermore, keeping the timers internal to the library allows for
easier extension of features as well as re-implementation of related
code in the future.
Last but not least, it was detected that existing known applications
(osmo-sgsn, osmo-ggsn, sgsnemu) are not using correctly the API, since
they should be updating their timers through gtp_retrans_timeout()
everytime a message is enqueued/transmitted, otherwise they may fire
gtp_retrans() for retransmition too late in some cases.

Related: OS#4178
Change-Id: Ife7cfd66d6356f413263fe5bda9e43091f5c9e98
2019-09-05 09:59:52 +00:00
Vadim Yanitskiy 68c5a74557 gtp/gtp.c: cosmetic: use get_tid() where we need TID
Change-Id: I39e92f25ed51665c8a615826ed52f35024bdd54b
2019-09-02 09:03:43 +00:00
Vadim Yanitskiy bdf2cf9038 gtp_error_ind_conf(): fix: guard against an unknown GTP version
This change fixes the following compiler warnings (found by Clang):

  gtp.c:2747:13: warning: variable 'pdp' is used uninitialized
			  whenever 'if' condition is false
			  [-Wsometimes-uninitialized]
		 } else if (version == 1) {

  gtp.c:2781:14: note: uninitialized use occurs here
  		 OSMO_ASSERT(pdp);
			     ^^^

Shall not happen in general, but let's make Clang happy.

Change-Id: Id471b22afd4c45435589a4edda0a804e66be3a7a
2019-09-02 09:03:43 +00:00
Vadim Yanitskiy 00a6171b8d gtp_update_pdp_ind(): fix NULL-pointer dereference
As stated in the comment above, we need to use the tunnel identifier
to find a GTP context, and derive both IMSI and NSAPI from that TID,
when speaking GTP version 0.

This change fixes the following warnings (found with Clang):

  gtp.c:2115:22: warning: variable 'pdp' is uninitialized
			  when used here [-Wuninitialized]
		 pdp_set_imsi_nsapi(pdp, tid);
				    ^^^

  gtp.c:2118:34: warning: variable 'imsi' is uninitialized
			  when used here [-Wuninitialized]
		 if (gtp_pdp_getimsi(gsn, &pdp, imsi, nsapi))
						^^^^

  gtp.c:2118:40: warning: variable 'nsapi' is uninitialized
			  when used here [-Wuninitialized]
		 if (gtp_pdp_getimsi(gsn, &pdp, imsi, nsapi))
						      ^^^^^

Change-Id: I8f1c8d0ba2e8189d97fe1bb5c872680e5ad1cd7a
2019-09-02 09:03:43 +00:00
Pau Espin 26e300fda0 ggsn: rx DeletePdpReq confirmation: Improve documentation and use gtp_freepdp()
Update documentation since nowadays there are more paths calling
ggsn_close_one_pdp() (because we now close pdp contexts during sgsn
timeouts).

Switch pdp_freepdp() to gtp_freepdp() since in the event we ended up
there in the future we want to go through normal delete_ctx_cb  to free
related application data structures.

Change-Id: I7d9ae9a27390498ba387797aac6651e32fa44f29
2019-08-29 14:07:04 +02:00
Pau Espin 4e605b32d4 cosmetic: gtp: Improve documentation of gtp_delete_context_req2()
Change-Id: I1f85c7cc7684e146fca4f17914927d45410dbb84
2019-08-29 14:07:04 +02:00