Commit Graph

34 Commits

Author SHA1 Message Date
Pau Espin bd2b55679e ggsn: Log tun fd write errors
Change-Id: I5f681b5edcc4cf525629d2078ae0c0ffd7ebb72d
2021-06-01 12:00:21 +02: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
Stefan Sperling b0b9c28284 properly store IPv6 addresses in struct tun_t
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-22 14:12:40 +00:00
Stefan Sperling aee905b790 check ioctl() call return value in tun_new()
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-11-21 14:14:10 +01:00
Harald Welte f2286395e9 Move kernel GTP support from ggsn/ to lib/
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-25 21:44:46 +02:00
Harald Welte 9eebe15cd1 lib/tun: Remove tun_setaddr() API, as everyone is using tun_addaddr() now
Change-Id: I02e057d30b6773c17ea6bc31094e53587971e9e7
2018-04-25 21:41:43 +02:00
Harald Welte c5efb5bccb lib/tun: split generic network device related stuff to lib/netdev
Change-Id: Ib021e392637a43d5cf1b40e0d50621fe7e854ba5
2018-04-25 21:41:41 +02:00
Harald Welte 9a6da455b9 lib/tun.c: Generalize tun_{set,add}addr*() functions
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-25 21:40:30 +02:00
Harald Welte b4c0828039 lib/tun.c: generalize tun_*route() to netdev_*route()
There's nothing specific to tun devices in adding a route to the kernel.

Change-Id: Ib077934aa5f3c9bed06e2cf16a980c965a7a046d
2018-04-25 20:46:05 +02:00
Harald Welte df3dcac439 lib/tun.c: Generalize tun_sifflags() to netdev_sifflags
There's nothing "tun" specific about that function, let's clarify that.

Change-Id: Iae7ced700245d6c1ac7e9807ab80d12fde8da116
2018-04-25 20:46:05 +02:00
Pau Espin f5e40b7011 Set tun_addaddr ipv agnostic and add support for ipv6
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-14 14:49:12 +00:00
Pau Espin 02e21af657 tun.c: tun_addaddr: Fix segfault and wrong usage of tun_nlattr
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-14 14:49:12 +00:00
Pau Espin b9ace14717 cosmetic: Reorder tun_addaddr to get rid of decl of tun_setaddr4
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-01 15:40:32 +01:00
Pau Espin d9fff0c543 tun_setaddr6: Fix log typo
Change-Id: Id7f7d33a33730d57c5ecf7ebf5612f4744cf5163
2017-12-01 15:39:28 +01:00
Harald Welte 4c7d29107f factor out netdev_ip_local_get() from tun_ip_local_get()
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-13 23:57:58 +09:00
Harald Welte 1af543f44c tun: Don't copy 16byte IPv6 address to 'struct in_addr'
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-11-06 03:32:52 +09:00
Pau Espin a037e5908a tun: Convert tun_ipv6_linklocal_get to be more generic
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-16 17:45:48 +02:00
Pau Espin fdd732b130 Remove trailing whitespace
Change-Id: I8e24f95a88bef3a59006a89c219871e6156963d7
2017-10-13 16:28:01 +02:00
Pau Espin 58c0da7833 lib/tun.c: tun_ipv6_linklocal_get(): fix memory leak with getifaddrs()
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-12 18:00:16 +02:00
Harald Welte f85fe9720b ICMPv6: Send router advertisement from own link-local address
I'm not quite sure how I ended up doing this, but for some strange
reason the code before this commit is sending the ICMPv6 Router
Advertisements from some weird non-standard source address.  This is
a violation of RFC4861 which clearly states that the source address
of router advertisements "MUST be the link-local address assigned to the
interface from which this message is sent."

Change-Id: Ib444af70fc8f0b433d371281601fd5a37b29039e
2017-09-24 20:51:47 +08:00
Harald Welte dda21ed7d4 Introduce a VTY, factually turning OpenGGSN into an Osmocom program
Change-Id: I9613ca3436e77ea132c47f0096df7c5050d7e826
2017-09-06 09:17:11 +02:00
Harald Welte 2778ae2b8f lib/tun: Mark internal helper functions 'static'
Change-Id: I53a8a89abb0080a39a153e9d3864c17b29aa193c
2017-09-05 23:13:14 +02:00
Harald Welte 1b6e8e7b5e Remove __sun__ code that is unmaintained
We haven nobody maintaining this platform, let's remove it.

In fact, only Linux and FreeBSD are part of the jenkins build tests,
so even Apple/MacOS is up for disposal.  However, as it's more
popular, let's keep the code.

Change-Id: Id6b8179259bacade52c39f96e688f828eff164ac
2017-09-05 23:13:14 +02:00
Harald Welte 9e6dfa0558 lib/tun.c: Proper cleanup during tun_new() error paths
Change-Id: I285be20df76774ac7258b6edb3d4f2d28703757d
2017-09-05 22:42:18 +02:00
Harald Welte 81bc2aea53 tun_new(): Fix array overflow in FreeBSD related code
Change-Id: I096e3b614e82e402886163274cfcf9355bd57580
2017-08-11 13:12:09 +02:00
Harald Welte ab6d189f8f replace hand-coded tun_gifindex() with standard POSIX if_nametoindex()
Change-Id: I738472765ab09f530dcf071455e1bb4e6fb3f6e5
2017-08-11 13:12:09 +02:00
Harald Welte 2e48a44952 Support setting TUN device IPv6 address + prefix
As we can now have PDP contexts with IPv6 user IP payload,
it is useful to extend the TUN related code to be able to
configure the tun device IPv6 address + prefix length

Change-Id: I899d21e52d02e0b8384af29ddd489ff19c8f2cf6
2017-08-11 13:12:04 +02:00
Michael McTernan b07d07072e openggsn: Check return codes and take error paths on failure.
Return early when socket() returns -1, and check return codes
where indicated by some TODOs. This removes 2 TODOs and fixes
a compiler warning about assignment to a variable which then
isn't used.

Signed-off-by: Michael McTernan <mike.mcternan@wavemobile.com>
2015-05-02 07:53:34 +02:00
Holger Hans Peter Freyther 9c7fd8edc4 logging: Switch to using libosmocore logging for all the code 2014-12-04 16:51:15 +01:00
Tobias Engel 3d7500e686 Remove out-of-bounds write
This removes an out-of-bounds write. The whole statement can simply be
removed since snprintf already adds the trailing 0 byte.
2012-11-05 13:31:25 +01:00
Harald Welte bed35df298 Convert all code to Linux coding style
After so many years of silence, we don't expect the original author to
return to the project.  To make things a bit simpler for us, we convert
the coding style to what we are used to (Linux style).

The conversion was made using the 'Lindent' script which is part of the
Linux kernel.
2011-11-02 13:06:18 +01:00
Emmanuel Bretelle 87490d7fa9 IFNAMSIZ includes terminating 0
http://www.delorie.com/gnu/docs/glibc/libc_308.html
thus reverting devname to IFNAMSIZ
and making sure (*tun)->devname[IFNAMSIZ-1] = 0;

Signed-off-by: Emmanuel Bretelle <chantra@debuntu.org>
2010-10-20 11:04:51 +02:00
Emmanuel Bretelle 4e56c83be2 fixed compilation warning against gcc-4.4
* Change arguments of tun_gifindex from:
int tun_gifindex(struct tun_t *this, int *index)
to
int tun_gifindex(struct tun_t *this, __u32 *index)
solves:
../lib/tun.c: In function ‘tun_addaddr’:
../lib/tun.c:265: warning: pointer targets in passing argument 2 of
‘tun_gifindex’ differ in signedness
../lib/tun.c:88: note: expected ‘int *’ but argument is of type ‘__u32
*’

* handle system return code and returns -1 if system failed
solves:
../lib/tun.c: In function ‘tun_runscript’:
../lib/tun.c:895: warning: ignoring return value of ‘system’, declared
with attribute warn_unused_result

* do not dereference a pointer cast and use it as an lvalue
see
http://www.mail-archive.com/svn-commits@lists.digium.com/msg50931.html
solves:
../lib/tun.c: In function ‘tun_route’:
../lib/tun.c:533: warning: dereferencing pointer ‘({anonymous})’ does
break strict-aliasing rules
../lib/tun.c:533: note: initialized from here
../lib/tun.c:534: warning: dereferencing pointer ‘({anonymous})’ does
break strict-aliasing rules
../lib/tun.c:534: note: initialized from here
../lib/tun.c:535: warning: dereferencing pointer ‘({anonymous})’ does
break strict-aliasing rules
../lib/tun.c:535: note: initialized from here
../lib/tun.c: In function ‘tun_setaddr’:
../lib/tun.c:435: warning: dereferencing pointer ‘({anonymous})’ does
break strict-aliasing rules
../lib/tun.c:435: note: initialized from here
../lib/tun.c:452: warning: dereferencing pointer ‘({anonymous})’ does
break strict-aliasing rules
../lib/tun.c:452: note: initialized from here
../lib/tun.c:465: warning: dereferencing pointer ‘({anonymous})’ does
break strict-aliasing rules
../lib/tun.c:465: note: initialized from here

Signed-off-by: Emmanuel Bretelle <chantra@debuntu.org>
2010-10-20 11:04:51 +02:00
Emmanuel Bretelle 2a103687b6 Move common sgsnemu/ggsn files to directory "lib"
Some files like in sgsnemu and ggsn directory where exactly the same.
They are now moved to the same directory for easier maintenance

Signed-off-by: Emmanuel Bretelle <chantra@debuntu.org>
2010-10-20 11:04:51 +02:00