aboutsummaryrefslogtreecommitdiffstats
path: root/sgsnemu/sgsnemu.c
AgeCommit message (Collapse)AuthorFilesLines
2020-10-12GTP: Replace recently introduced imsi_str2gtp()Keith1-1/+1
Replace with the version from osmo-sgsn, renamed so as not to collide with that version. Change-Id: I910d5339a823332277ce7b5854d5c943ed69ea81
2020-10-12sgsnemu: relax check on length of IMSI cmdline arg.Keith1-1/+1
Change-Id: I0374ff8773ae528c916fbee5f3f1efd89a5d2a08
2020-10-12Use imsi_str2gtp() in sgsnemuKeith1-16/+1
Change-Id: I94168c84dd613cfe51715e247b0d8b57308017d0
2020-04-28sgsnemu: use real tun device name after the device is up.Dmitri Kalashnik1-4/+4
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-21sgsnemu: Fix assumption ipv6 Interface-Identifier of public addr == ↵Pau Espin Pedrol1-41/+53
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-21sgsnemu: Implement ping on IPv6 APNsPau Espin Pedrol1-50/+223
Related: OS#4434 Change-Id: If9ca7c37a1a397bbc3f8912d67bccdabc4968e0c
2020-04-21sgsnemu: Handle IPv6 SLAAC in tun iface manuallyPau Espin Pedrol1-58/+103
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-19sgsnemu: Fix build/run against linux < 4.11 (no sysctl addr_gen_mode support)Pau Espin Pedrol1-5/+11
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-15Rename netdev_*route to end in route4Pau Espin Pedrol1-6/+10
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-15sgsnemu: tun_addaddr: Don't set local addr as dstaddrPau Espin Pedrol1-1/+1
That should be used for point-to-point destination address. Change-Id: Iead7e9c7570ba6a9de3089a164997b1db81dc59a
2020-04-15sgsnemu: Get rid of duplicated options.netPau Espin Pedrol1-7/+4
It's not really set by any cmdline arg, and it always contains same content as options.netaddr. Change-Id: Id3cdca0975bdd2893b4b83944c5ebf29b2994622
2020-04-15sgsnemu: Get rid of duplicated options.destaddrPau Espin Pedrol1-6/+3
It's not really set by any cmdline arg, and it always contains same content as options.netaddr. Change-Id: I5a4e3c4b5ae43a89a7d0af62fb396311dcb6ebae
2020-04-15sgsnemu: Fix ping transmitted statistics outputPau Espin Pedrol1-1/+1
Change-Id: I6e23e024ee30d6049c6b8b614c50d062d80a5260
2020-04-15sgsnemu: Avoid adding extra autogenerated local link ipv6 addr to tun ifacePau Espin Pedrol1-0/+47
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-14sgsnemu: Rename sgsnemu's libgtp cb_confPau Espin Pedrol1-2/+2
It makes it easier to understand where the function is called. Change-Id: Ibf32b416c3247d1415aa9c1a88755076dcd606f4
2020-04-14sgsnemu: Pass array of in64_addr to in46a_from_eua()Pau Espin Pedrol1-30/+34
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-03-02netns: Improve error checkingPau Espin Pedrol1-9/+42
Change-Id: I9b9c8fd6eeaaa7d190b8e2a34ca82088904c7708
2020-02-26add Linux network namespace support for TUN deviceAndreas Schultz1-1/+59
Change-Id: Idd0ad8fa9c8e7ba0aeec1b52947598d4d297b620
2019-12-01sgsnemu: Fix null-pointer format string argumentHarald Welte1-2/+1
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-09-05ggsn, sgsnemu: Drop use of no-op deprecated gtp_retrans* APIsPau Espin Pedrol1-4/+2
Related: OS#4178 Change-Id: I295b89ee493d230c2550d461fca9602c589d38b5
2019-07-29sgsnemu: Fix unaligned pointer access during ip/icmp checksumPau Espin Pedrol1-8/+12
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
2019-07-21sgsnemu: Fix format string argument countHarald Welte1-4/+8
Change-Id: I6bb8c3df53a585913d5e0351ecad2e6ae9f0b886 Closes: CID#178643
2019-06-04sgsnemu: Replace use of deprecated libgtp API pdp_newpdp with new onePau Espin Pedrol1-1/+1
Related: OS#2873 Change-Id: I9742b82c382ae2e63f8aff4c5c32e2450059082b
2019-05-31ggsn: Use gtp_delete_context_req2() everywhereOliver Smith1-4/+3
Replace calls to gtp_delete_context_req() with gtp_delete_context_req2(). Related: OS#2741 Change-Id: Iecc8c5ac45207e7e20129559c4ac7f3c67dfb36a
2018-10-21sgsnemu: Fix printing of tun device nameHarald Welte1-1/+1
Change-Id: I6cd89b7b59a6c1d506cfbe9d3088cb844d133313 Fixes: Coverity CID#178638
2018-04-25Move kernel GTP support from ggsn/ to lib/Harald Welte1-1/+1
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
2018-04-25sgsnemu: Convert from tun_setaddr() to tun_addaddr()Harald Welte1-2/+1
This converts the last caller of tun_setaddr() outside of lib/tun.c to use tun_addaddr(). Change-Id: Ia301d6a4ee3d02c1af1c85f2fe1041d3013268b0
2018-04-25lib/tun.c: generalize tun_*route() to netdev_*route()Harald Welte1-2/+2
There's nothing specific to tun devices in adding a route to the kernel. Change-Id: Ib077934aa5f3c9bed06e2cf16a980c965a7a046d
2018-04-17use osmo_init_logging2Pau Espin Pedrol1-1/+5
Change-Id: Ic38fff17cc985238b91999c8acdd92d22fd28c72
2018-02-12sgsnemu: Fix bad ptr during context deallocationPau Espin Pedrol1-2/+2
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: 2d6a69e69a4b4cb2b8cc63c4810dae44e5a4d8f6 ("Add support for IPv4v6 End User Addresses") Change-Id: I9e563522173a82b265e93b1ef9dc93ced40fefa2
2018-02-12sgsnemu: fix: no outgoing GTP-U in "createif" modeViktor Tsymbalyuk1-1/+1
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
2018-01-26sgsnemu: sgsnemu stopped after recieving "Request accepted" from ggsnViktor Tsymbalyuk1-1/+1
"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: 2d6a69e69a4b4cb2b8cc63c4810dae44e5a4d8f6 ("Add support for IPv4v6 End User Addresses") Change-Id: I7881b8e1f27c432007cb6e5ff665a2ce55f103b5
2017-12-14Set tun_addaddr ipv agnostic and add support for ipv6Pau Espin Pedrol1-15/+11
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
2017-12-14cosmetic: sgsnemu.c: Fix trailing whitespacePau Espin Pedrol1-6/+6
Change-Id: Ic392ed35946e076a39aa5f7bf80a8c2ffe73562c
2017-12-11Add support for IPv4v6 End User AddressesPau Espin Pedrol1-1/+1
Before this commit, when an MS requested an ipv4v6 context osmo-ggsn returned an error stating the type was unknown, and this text was printed in the log: Processing create PDP context request for APN 'ims' Cannot decode EUA from MS/SGSN: f1 8d This patch has been tested with an MS running the 3 types of addresses: - IPv4 and IPv6: no regressions observed, the context is activated and packets are sent to the ggsn. - IPv4v6: Wireshark correctly parses request and reponse, and then ICMPv6 traffic from both sides. Finally I see the MS using the IPv4 and IPv6 DNS addresses advertised and TCP traffic over IPv4 (because probably my IPv6 network setup is not correct). I also checked I can disable/enable data (pdp ctx delete and activate) several times without any issue. Change-Id: Ic820759167fd3bdf329cb11d4b942e903fe50af5
2017-11-06sgsnemu: Free strings in error pathHarald Welte1-2/+2
In create_pdp_conf(), we have to free() any strings both in the success and in the error case. Change-Id: If59cc8d6d151c123f46c1d029091209fd82b3c8e Fixes: Coverity CID#187636, CID#187633
2017-11-06sgsnemu: Make sure buffer has space for terminating-NULHarald Welte1-1/+1
In proc_ipv6_conf_read() we allocatea buffer on the stack but forgot the terminating NUL byte. Change-Id: I54126d8bc08c137859f2de4b47ef23fc0714fdd7 Fixes: Coverity CID#178641
2017-11-06sgsnemu: Fix format string in printing tun-device nameHarald Welte1-1/+1
Change-Id: Ie05050a78a135a1a76473337a341fd723bbe4976 Fixes: Coverity CID#178654
2017-11-06sgsnemu: Don't leak FILE handle in proc_read()Harald Welte1-1/+0
Change-Id: Ie22e6a9bc172427e867e7a4001b6c710477a232b Fixes: Coverity CID#178660
2017-10-14sgsnemu: Use getprotobynumber() in print_ipprot()Harald Welte1-9/+5
There's no point in sgsnemu doing a poor mans reimplementation of what the C library provides already by means of getprotobynumber() Change-Id: I8cdc460e4fa5d86d80addf6e5f341d2d80093a35
2017-10-14sgsnemu: Remove dead code: encaps_printf()Harald Welte1-13/+0
This function is never used/called, remove it. Change-Id: I37a447e4d5387e3fc5f4433ab20ceba7c446684b
2017-10-14sgsnemu: Mark local functions 'static'Harald Welte1-23/+23
We don't need to export those to the global name space as they're not called from code in other files. Change-Id: I454249335ba46abdb3afbc669c4a06a06f39ae72
2017-10-14sgsnemu: Print warnings on broken IPv6 configuration (acept_ra)Harald Welte1-0/+57
When sgsnemu is used for an IPv6 pdp context, we rely on the router discovery procedure and SLAAC to set the correct IPv6 address/prefix on the tun device. This requires the system to be configure to accept router-advertisements on the tun device. Let's print a warning if accept_ra for the specific tun device is set to a wrong value. We're leaving it up to the user to either set a system-wide /proc/sys/net/ipv6/conf/default/accept_ra or to configure this in an ip-up script used together with sgsnemu. Change-Id: I563092ca35bc74f035a5023e11256779aac46e11
2017-10-14sgsnemu: Add '--tun-device' option to specify TUN device nameHarald Welte1-1/+7
This way, multiple sgsnemu instances can be runnig in parallel, each of them creating a different tun device for their respective PDP context Change-Id: Id12fbadf924a60db255b6d51b9f647aa51dd2e16
2017-10-10sgsnemu: Add IPv6 support via tun device and "-t v6 --createif"Harald Welte1-12/+61
The idea is to only implement the GTP-C plane and configure the right link-local source address on the tun-device and let the regular (Linux) kernel take care of sending router solicitations and accepting/processing the related router advertisement. This avoids a lot of complexity in sgsnemu. For this to work, you must have /proc/sys/net/ipv6/conf/$tun/accept_ra set to either 1 (works only if no IPv6 forwarding/routing configured on your sgsnemu-running system) or 2 (works even if forwarding/routing is configured). Change-Id: I57e4c53ee648e1efecfba3eea592d1129849557c Closes: OS#2518
2017-10-01sgsnemu: Allow specification of PDP (EUA) Type IPv4 or IPv6Harald Welte1-1/+11
This just adds the capability to sgsnemu to request a certain PDP EUA type. It doesn't mean it actually handles anything beyond the existing IPv4 yet. Change-Id: I157f9157a7ff2ea56c37a4a902d4706de4c7d35d
2017-09-24sgsnemu: Add --no-tx-gpdu-seq option to suppress transmission of G-PDU ↵Harald Welte1-0/+10
sequence numbers Related: OS#2519 Change-Id: Idc650d896f0f72329090b56a37d9c16359294860
2017-09-24sgsnemu: Re-generate cmdline.[ch] using gengetoptHarald Welte1-3/+3
This will replace the manual additions to cmdline.[ch] with auto-generated code from gengetopt. We need to fix-up the RAT Type in sgsnemu.c as the manually-added code diverged from what gengetopt generates. Change-Id: Ia687e13d5cec1655a57078a767d2123aa022842c
2017-09-06Rename OpenGGSN to OsmoGGSNHarald Welte1-1/+1
Osmocom has maintained this program since about 7 years now, while the original author / copyright holder has completely disappeared. With the introduction of Osmocom-style CTRL and VTY interfaces, the way how the program is used and configured has substantially changed. In order to avoid confusion in terms of configuration file format etc, let's rename it to OsmoGGSN. Change-Id: I2da30f7d4828e185bfac1a4e2d8414b01cbe4f9d
2017-09-06Introduce a VTY, factually turning OpenGGSN into an Osmocom programHarald Welte1-1/+1
Change-Id: I9613ca3436e77ea132c47f0096df7c5050d7e826