aboutsummaryrefslogtreecommitdiffstats
path: root/lib
AgeCommit message (Collapse)AuthorFilesLines
2020-05-12debug: use LOGL_NOTICE instead of LOGL_DEBUGPhilipp Maier1-1/+1
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-04-21sgsnemu: Implement ping on IPv6 APNsPau Espin Pedrol2-1/+11
Related: OS#4434 Change-Id: If9ca7c37a1a397bbc3f8912d67bccdabc4968e0c
2020-04-21sgsnemu: Handle IPv6 SLAAC in tun iface manuallyPau Espin Pedrol4-55/+204
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-15Rename netdev_*route to end in route4Pau Espin Pedrol3-9/+9
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-15icmpv6.c: Move code generating ipv6 hdr to its own functionPau Espin Pedrol1-16/+25
It will be re-used in next commits. Change-Id: I3c108efad6461cd4e82ef435290005174bc8b30e
2020-04-15icmpv6.c: Mark internal function as staticPau Espin Pedrol1-1/+1
Change-Id: Ib38907c3a05c1651faa86ef57381ee22643e0d53
2020-04-15cosmetic: icmpv6.c: fix typo in commentPau Espin Pedrol1-1/+1
Change-Id: I2217dfb0b0a1e6e029ac817902e80c771ed219c3
2020-04-14lib/netns: Fix up error pathsHarald Welte1-20/+54
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-14netdev_addaddr6: Use prefixlen argPau Espin Pedrol1-1/+1
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-14lib/netns: OSMO_ASSERT() if user doesn't call init_netns()Harald Welte1-1/+13
It is vital that init_netns() is called first in order to initialize default_nsfd. Change-Id: Ic16646fa7d60c578056b17351c5fe2090a81dff0
2020-04-14lib/netns.c: Add comments to the code, including doxygen API docsHarald Welte1-0/+45
Change-Id: I0b20e4870bf62df0a459a621a64a4e2795340ceb
2020-04-14Move icmpv6 and checksum files from ggsn/ dir to lib/Pau Espin Pedrol5-2/+467
They will be required by sgsnemu to implement ICMPv6 Router Soliciations. Change-Id: Ie878604f0fc0169cc98a1e9eee64b14d76be2c45
2020-04-14sgsnemu: Set its default loglevel category to INFOPau Espin Pedrol1-1/+1
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-03-03lib/netns: fix open_ns(): return fd from open()Vadim Yanitskiy1-1/+1
Looks like a bug introduced by I9b9c8fd6eeaaa7d190b8e2a34ca82088904c7708. Change-Id: I38caf5541ca90638ed10714adfbb08120e5397b9 Fixes: CID#208656
2020-03-02netns: Improve error checkingPau Espin Pedrol2-56/+90
Change-Id: I9b9c8fd6eeaaa7d190b8e2a34ca82088904c7708
2020-02-26add Linux network namespace support for TUN deviceAndreas Schultz3-2/+184
Change-Id: Idd0ad8fa9c8e7ba0aeec1b52947598d4d297b620
2019-08-28gtp-kernel.c: Fix wrong use of in46a_from_eua, print IPv6 euasPau Espin Pedrol1-4/+13
in46a_from_eua() API documentation clearly states an array of 2 items should be passed as pointer, but show_one_pdp() was passing only one, which would end up in out-of-bounds writes on v4v6 EUAs. Let's better use ippool to print allocated ip addresses instead of parsing EUAs we sent some point in the past. Change-Id: I7e164f40f50de43027bcd4464aa879450d2fb10e
2019-08-28Move pdp_get_peer_ipv() to lib/util.*Pau Espin Pedrol3-2/+55
Preparation for next commit, where this function will be needed inside libmisc (lib/*). Change-Id: Ibab4f6c09d1e5f0e9cfaea28ae1e7ab5b5c219b5
2019-08-28in46_addr: Improve in46a_ntop documentationPau Espin Pedrol1-1/+5
Change-Id: I27238c330f9b805ac9e734e735d2c7ae158fe524
2019-08-28Introduce in46a_is_v{4,6}() helpersPau Espin Pedrol1-0/+8
It's clearer having size-related checks in one place for a data structure in46_addr, instead of spread around the code. Change-Id: Idc94bf0c8c01bb5a30e36d3c284b99f66b972abb
2018-11-22properly store IPv6 addresses in struct tun_tStefan Sperling2-10/+16
All addresses in struct tun_t were stored as an in_addr. But IPv6 addresses need an in6_addr, so switch tun_t addresses to the in64_addr wrapper struct. This is an ABI break, as documented in TODO-RELEASE. Fixes an out of bounds memcpy() identified by Coverity. Change-Id: Idd2431ad25d7fa182e52e2bd5231ceb04d427c34 Related: CID#174278
2018-11-22fix format string error in ippool_printaddr()Stefan Sperling1-1/+1
The variable this->listsize is an unsigned int, but the format string assumed ptrdiff_t. Found by Coverity. Change-Id: Ib2a55907adae98f8aa7b079f1c9a3b4fc5f67fc5 Related: CID#188879
2018-11-22initialize local variable addr in ippool_new()Stefan Sperling1-1/+1
Coverity points out that addr.len was potentially being used uninitialized, via calls to in46a_inc(&addr). Change-Id: Idb67394e5f4c2072380a33f46c848d92c4317245 Related: CID#174189
2018-11-22replace bogus memcpy() call in ippool_newip()Stefan Sperling1-1/+9
When copying an address to a reused static hash table member with memcpy(), this code mistakenly passed the size of a pointer as the amount of bytes to be copied, rather than the actual size of the address. This means the IP pool could contain bogus IP addresses because only addr->len (a uint8_t) and 3 further bytes of the address were actually copied on 32 bit platforms. On 64 bit platforms, a sufficient amount of bytes were copied for IPv4 to work correctly, but too few bytes were copied for IPv6. This problem was found by Coverity. Replace the bogus memcpy() call with direct assignments to the appropriate struct in64addr union members, and assert that the length recorded for the address actually corresponds to the length used by the address family (IP4, IPv6). Change-Id: Ic21560f7519e776107485a8779702fb1279d065c Related: CID#57921
2018-11-22fix allocation of ippool's hash tableStefan Sperling1-3/+2
The calloc() call in ippool_new() had two problems. The first problem is benign: The order of arguments were reversed. Pass the number of elements in the array first, then the size of each element, as calloc() expects. This problem was found by me. There are more instances of this problem in this file, which I'll address in follow-up patches. The second problem is that the requested allocation was larger than necessary: The hash table is an array of pointers to ippoolm_t, not an array of struct ippoolm_t. Fix the required size passed to calloc(). This problem was found by Coverity. Change-Id: I93fa5bc539771ca19714f6a665558c9140e2ce07 Related: CID#57920
2018-11-21check ioctl() call return value in tun_new()Stefan Sperling1-1/+4
Coverity complains about a missing ioctl() return value check. Check for failure of the TUNSETNOCSUM ioctl and log a warning if it fails. Change-Id: I88da2164d975d7a232619b8d31c5eadeef0f3a80 Related: CID#57661
2018-10-21ippool.c: Use "%td" format string for ptrdiff_tHarald Welte1-6/+6
Change-Id: Iacafa0919baebac6b5a799deb41a673c022c6743 Fixes: Coverity CID#135225
2018-04-25Move kernel GTP support from ggsn/ to lib/Harald Welte5-26/+255
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-25lib/tun: Remove tun_setaddr() API, as everyone is using tun_addaddr() nowHarald Welte2-17/+0
Change-Id: I02e057d30b6773c17ea6bc31094e53587971e9e7
2018-04-25lib/netdev.c: Cosmetic changes (coding style / cleanups)Harald Welte1-49/+10
Change-Id: I60cbca616a4f727e2374c52715f9286a0f4c5e4b
2018-04-25lib/tun: split generic network device related stuff to lib/netdevHarald Welte5-755/+842
Change-Id: Ib021e392637a43d5cf1b40e0d50621fe7e854ba5
2018-04-25lib/tun.c: Generalize tun_{set,add}addr*() functionsHarald Welte1-51/+98
There's nothing really tun-specific about the adding and removing of addresses to network devices. Let's generalize the related code. Change-Id: I139a950dd81a4b1199953be1608cd109a060f562
2018-04-25lib/tun.c: generalize tun_*route() to netdev_*route()Harald Welte2-15/+8
There's nothing specific to tun devices in adding a route to the kernel. Change-Id: Ib077934aa5f3c9bed06e2cf16a980c965a7a046d
2018-04-25lib/tun.c: Generalize tun_sifflags() to netdev_sifflagsHarald Welte1-7/+7
There's nothing "tun" specific about that function, let's clarify that. Change-Id: Iae7ced700245d6c1ac7e9807ab80d12fde8da116
2017-12-14Set tun_addaddr ipv agnostic and add support for ipv6Pau Espin Pedrol2-3/+182
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-14tun.c: tun_addaddr: Fix segfault and wrong usage of tun_nlattrPau Espin Pedrol1-2/+3
First of all, dstaddr can be NULL, avoid copying it in that case. Second, we want to copy the addr data, not the pointer. I tested it and the IP was not added (not shown in ip addr) until I copied the content instead of the address. Change-Id: I8da637b155f0e913cab6c5b0dde355c9f33375b5
2017-12-11Add support for IPv4v6 End User AddressesPau Espin Pedrol2-27/+84
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-12-01cosmetic: Reorder tun_addaddr to get rid of decl of tun_setaddr4Pau Espin Pedrol1-172/+169
In any case, if we add support for ipv6 in tun_addaddr we will need tun_setaddr (and also change the API of tun_addaddr to use in46_addr). Change-Id: Iadf51379455174a642b477040ec96f28022c24c7
2017-12-01tun_setaddr6: Fix log typoPau Espin Pedrol1-1/+1
Change-Id: Id7f7d33a33730d57c5ecf7ebf5612f4744cf5163
2017-11-13factor out netdev_ip_local_get() from tun_ip_local_get()Harald Welte2-4/+25
netdev_ip_local_get() is a generalized version of tun_ip_local_get() which supports the net device as argument, rather than a tun_t. Change-Id: I072aa1a55e7bf110706e9207021b776d9b977fb6
2017-11-06ippool: Correctly compute size of static poolHarald Welte1-1/+1
* we have to use stataddr, not addr (dynamic) * we have to multiply the length of the address by 8 to get its bit length * we can simplify the -1 +1 logic (like dynamic) Change-Id: I174102051bef95f7df34b7d7c480a00ae408be7d Fixes: Coverity CID#174189
2017-11-06tun: Don't copy 16byte IPv6 address to 'struct in_addr'Harald Welte1-1/+0
The 'struct tun' curently only has an in_addr (v4-only) member to store the address of the tun device, so let's not attempt to store an IPv6 address in it. FIXME: This entire code needs an overhaul. The assumption that there's only one address, and only either v6 or v4 is broken to begin with. Change-Id: If0b626d688841d6e0a3867834f4cb1b70084050e Fixes: Coverity CID#174278
2017-10-17ippool: Implement and use blacklist instead of blindly using IPPOOL_NOGATEWAYPau Espin Pedrol2-14/+26
Commit dda21ed7d4a897c9284c69175d0da598598eae40 modified previous calls to ippool_new() removing the pass of flags to avoid allocating certain problematic IPs from the pool to MS, such as the network, gateway and broadcast IPs. Today I did some unsucessful tests with osmo-ggsn with a pool "ip prefix dynamic 176.16.222.0/24", and thus IP 176.16.222.0 was being assigned to the MS. De-capsulated DNS packets were received in the tun interface, but the Linux system in there was unable to correctly forward the packets to the gateway interface connected to the Internet. However, adding a second MS which got 176.16.222.1 had its packets forwarded correctly. However, previous implementation relies on flag IPPOOL_NOGATEWAY flag to blindly blacklist first IP after the network ip (ie, .0 and .1 are removed), which limits the IP reserved for the tun device to be .1. If a different IP in the range is assigned, it may cause issues. As a result, a blacklist is introduced in this commit to dynamically fetch the tun IP address and exlucde it from the pool of available IPs. Change-Id: I8e91f7280d60490c858a769dd578c1c8e54e9243
2017-10-16tun: Convert tun_ipv6_linklocal_get to be more genericPau Espin Pedrol2-14/+64
Add support for IPv4 and IPv6 global IPs. Also return the prefix length of the IP address by using a in46_prefix. Change-Id: I277af191dc611b6bbcb83479f4ae338083740322
2017-10-16lib/in46a: Introduce in46a_netmasklen APIPau Espin Pedrol2-0/+59
Change-Id: I06e3e038afd8f7afaec2a3fa67b1616500c8db80
2017-10-16lib/ippool: Fix listsize calculated 1 elem too smallPau Espin Pedrol1-1/+1
Take the chance this commit is changing test output to also remove use of IPPOOL_NOGATEWAY which is going to be removed soon, and instead test IPPOOL_NOBROADCAST. Change-Id: I95c24bc690490155bec9e3933d678e4668d7745f
2017-10-13in46a_to_sas(): Return AF_INET6 in case of IPv6 addressHarald Welte1-1/+1
Change-Id: Ia2f9ac60f08823d5f7c1a76c0b7cbd65ac615e26
2017-10-13Remove trailing whitespacePau Espin Pedrol5-13/+13
Change-Id: I8e24f95a88bef3a59006a89c219871e6156963d7
2017-10-12lib/tun.c: tun_ipv6_linklocal_get(): fix memory leak with getifaddrs()Pau Espin Pedrol1-0/+2
From getifaddrs(3) man: "The data returned by getifaddrs() is dynamically allocated and should be freed using freeifaddrs() when no longer needed" Change-Id: If6300d1c8d36fcafef294a4c11bbda31a158bb9c
2017-10-01Replace EUA magic numbers for IETF, IPv4 and IPv6 with #definesHarald Welte1-6/+7
Change-Id: I33f65e404217e717bd795e5229c8d9456a7b3739