Commit Graph

199 Commits

Author SHA1 Message Date
Stefan Sperling d70ab97fa4 fix unaligned access in build_ipcp_pco()
IPCP data can begin at any byte location in the pco_req->v array.
Casting to a 'struct ipcp_hdr' pointer could lead to unaligned access.
Parse IPCP data with u_int8_t pointers instead to avoid this problem.

Add some length checks while here.
pco_contains_proto() and ipcp_contains_option() now receive the minimum
size of the data the caller is looking for, and only return pointers
to items of sufficient size.

Also fix an inifinite loop in ipcp_contains_option() by refusing
IPCP options with length small than 2. Previously, a zero length
option would trigger an infinite loop in the parser.

Change-Id: Ia1410abb216831864042f95679330f4508e1af3d
Related: OS#3194
2018-07-19 19:37:41 +02:00
Pau Espin 3e0baa6146 ggsn: ctrl iface: listen on IP configured by VTY
Previosuly, the CTRL iface of osmo-ggsn was always bound to 127.0.0.1

Fixes: OS#3287
Change-Id: I9b2c1b310c7dc94ef09642f7f256ae259b41619d
2018-06-19 11:52:00 +02:00
Philipp Maier 6a2856bab5 ggsn: make sure ipcp_option_hdr and and ipcp_hdr are packed
struct ipcp_option_hdr and struct ipcp_hdr are not declared as
packed explicitly, but they are used to parse memory blobs by
casting pointers.  Add __attribute__((packed)) to ensure that
those structs are stored packed.

Change-Id: I14e10bb3ce482347b3f0c4d3a75168a55df15f20
Related: OS#3288
2018-05-28 17:50:09 +02:00
Philipp Maier 0d95ca59f9 ggsn: fix misinterpreted length field in ipcp_contains_option()
The abort condition of the while loop in ipcp_contains_option()
is accessing ipcp->len directly. Unfortunately this field is an
uint16_t which as to be interpreted as little endian value. If
it is used without prior conversion the value may appear larger
than actually intended and the loop will then not stop at the
end of end of the buffer.

This can cause unpredictable results when the value given with
the parameter enum ipcp_options opt is not found.

The loop will then eventually cause a segmentation fauld or
is likely to hang as soon as cur_opt->len points to a zero
byte in memory.

- Make sure that ipcp->len interpreted correctly by accessing
  it through ntohs()

Change-Id: Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5
Related: OS#3288
2018-05-28 17:48:19 +02:00
Vadim Yanitskiy 906c2099da ggsn_vty.c: fix: use CONFIG_NODE as parent by default
There are some configuration nodes, which are handled by extenral
libraries, such as libosmoctrl. So, when switching back to the
parent node, this should be kept in mind.

Change-Id: I65be7910dc46166caa34a0984a6763e1477dec99
2018-05-09 23:13:09 +07:00
Harald Welte 546884d9a1 ggsn: don't use gtp_kernel_tunnel_{add,del}() for userspace tun
Change-Id: I00cc8eb8c4d44532f975f78783ff4e12814b3416
2018-04-25 21:44:50 +02: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 db0366c9e4 ggsn: Don't explicitly use tun_setaddr() API anymore
tun_addaddr() internally contains a fallback to tun_setaddr() for the
first address, so we can unify the API usage a bit and use tun_addaddr()
from all call sites

Change-Id: I34de003a1a040254bd38b29e48caea34cb0c88d2
2018-04-25 21:41:43 +02:00
Harald Welte 0757504a86 fix segfault in case of kernel gtp-u
There's a problem during the initial start-up of osmo-ggsn in case
of kernel gtp-u: apn->ggsn->gsn is not yet set while parsing the
'apn' nodes from the config file.  This member is only set after
the last 'apn' node has been parsed at the end of the 'ggsn' node.

Closes: OS#3217
Change-Id: I022a5e5ebc1f155e8f94938856d310462f79bbe8
2018-04-25 20:46:05 +02:00
Pau Espin 042a445cf3 use osmo_init_logging2
Change-Id: Ic38fff17cc985238b91999c8acdd92d22fd28c72
2018-04-17 14:31:42 +02:00
Harald Welte 3e443ca502 Add talloc context introspection via VTY
This requires libosmocore with Change-Id
I43fc42880b22294d83c565ae600ac65e4f38b30d or later.

Change-Id: I460efff3a3dfa2c7d955871aca78b37552a29aff
2018-02-14 00:54:32 +00:00
Pau Espin dddbbaaee1 ggsn.c: cb_tun_ind: Don't drop packets targeting pdp ctx ll addr
Change-Id: I72602a78baa2a7e3412d8b69c1bf1b3ac0efa434
2018-01-30 22:50:14 +01:00
Pau Espin 134855c45e ggsn.c: cb_tun_ind: log dst addr of packet without pdp ctx
Change-Id: Ib3a87ec2b2d0014376295028a648750fa3124485
2018-01-30 22:50:13 +01:00
Pau Espin a4942e6566 ggsn.c: cb_tun_ind: Convert ifelse to switch statement
Change-Id: I4fc97f367ae615cdf0a9501f89419990c2fd4599
2018-01-30 22:49:26 +01:00
Pau Espin 4e43ef5ab0 ggsn: Print all addresses on successful pdp ctx creation
Change-Id: I0c57df17d91bade127027e03633494adb6f818c5
2018-01-26 18:20:22 +00:00
Pau Espin 4ae8d8232d ggsn: Parse PCO_IPCP for IPv4v6 pdp ctx
pdp_has_v4 only take into account IPv4 EUAs.

Change-Id: I1cf8d6548951e5732075beeea1412d12fb6bdec3
2018-01-26 18:20:22 +00:00
Pau Espin 0bdd8bf5bc ggsn: Parse PCO_IPCP
Improvements include:
- Use Identifier received from request instead of using hardcoded id=0.
- Don't add DNS to response if they were not included in request.

Change-Id: Ic8aa5d634e526683b2ad8ed5d14088e171c41c98
2018-01-26 18:20:22 +00:00
Pau Espin 5b1ef9589c ggsn: Validate packet src addr from MS
Closes: OS#2422

Change-Id: Ie658a7f161103bb6f631ab0508e45e55fb42a442
2018-01-26 18:20:22 +00:00
Pau Espin 7d54ed48e7 ggsn: encaps_tun: Avoid forwarding packet if EUA is unassigned, fix crash
Check (before forwarding received GTP packets into the tun) if the pdp ctx
associated with the packet requested was assigned an EUA of the given IP version.
This way we avoid for instance forwarding an IPv6 packet (or sending
back a response to a Router Solicitation packet) in case the APN was
configured without IPv6 support or if the MS/SGSN didn't ask for an IPv6
while requesting an EUA.

As a side effect, this commit fixes an OSMO_ASSERT hit introduced in handle_router_mcast
in 2d6a69e69a due to a deffective MS
sending an icmpv6 Router Solicitation over IPv6 after having been
requesting and assigned an IPv4 EUA (so no IPv6 packets expected).
Before that commit, there was no crash but the message was being wrongly
answered and used an uninitialized .v6 addr field from the peer struct.

Fixes: OS#2843

Change-Id: Ib6d18a64c2b71f3bcf6cb7e3a978d2d3f9c7a79b
2018-01-26 18:20:22 +00:00
Max 6f539aa259 Fix stow-enabled jenkins build failure
The error is:
CC       gtp-kernel.o
gtp-kernel.c:19:26: fatal error: libgtpnl/gtp.h: No such file or directory
 #include <libgtpnl/gtp.h>
                          ^
compilation terminated.

Fix it by using proper CFLAGS/LIBS for libgtpnl.

Change-Id: I5a24076778ea3ce263ac27211a6f45f935155b33
2018-01-16 16:52:04 +01:00
Pau Espin e5a082d64a ggsn_vty.c: Print ipv6 link-local cmd when writing config to file
Previous commit added the ipv6 link-local vty cmd but forgot to add code
to print its value in config_write_apn.

Fixes: 37c45e3998

Change-Id: I08aeaa98d6dc318b7e9740d837ba4ac48cd7051c
2017-12-15 15:55:32 +01:00
Pau Espin 37c45e3998 ggsn: Add 'ipv6 link-local' vty cmd
This vty cmd let's you set up a new link-local IP for a specific APN to
be used during ICMPv6 Router Advertisement procedure.

osmo-ggsn hence requires a link-local IPv6 address to be added to the
tun interface, otherwise the apn will not be configured correctly and it
won't be able to allocate addresses from the ipv6 pool later on.

This feature is useful in case your OS doesn't support autoconfiguring
link-local IPs when the interface is brought up (some linux versions are
known to fail at this) or in case you configured your OS specifically to
avoid automatic set up (sysctl net.ipv6.conf.*.autoconf).

If "no ipv6 link-local" is provided (default), osmo-ggsn will rely on the
OS or the ipup-script setting up the link-local IP for the tun
interface at creation time, then fetching it after ipup-script time and
using the first link-local ip found. On the other hand, if the "ipv6
link-local" cmd is provided, osmo-ggsn will add the link-local IP to the
interface manually and use that one for later Router Advertisement
procedures.

Change-Id: I09ef27f54940d4c47150e5f9016d1cd4298c16b5
2017-12-14 16:01:35 +00:00
Pau Espin bffc3f9012 ggsn.c: Improve logging info on link-local ipv6 addr not found
Change-Id: I18fb952514712ff30d18c7626f84309055d3efa1
2017-12-14 14:49:11 +00:00
Pau Espin 2d6a69e69a Add support for IPv4v6 End User Addresses
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-11 11:39:18 +01:00
Harald Welte 4f0343233b ggsn: Ignore PCO with length 0, don't abort processing
The existing code would abort iterating over the list of PCO TLVs
if a TLV of length zero was encountered.  However, there's nothing
in the spec that would make a zero-length PCO invalid, so we should
continue to iterate over any PCO TLVs after the zero-length one.

This issue was discovered while writing test cases in
osmo-ttcn3-hacks.git

Change-Id: I36660566a8ee2ca80ae6ee99c86e167e7c208df2
2017-12-05 17:29:24 +00:00
Harald Welte bcab7fb4af ggsn.c: Fix byte order of IPCP IPv4 DNS servers
... this probably didn't show up as 8.8.8.8 is dual-endian. doh!

The address was already in network byte order, but msgb_put_u32 "of
course" expects host byte order, ending up the wrong way in the actual
packets :/

Change-Id: Ia4bcac5fcebfc24760432eb66be258a01d78f65f
Closes: OS#2685
2017-12-05 17:29:24 +00:00
Max 427699e6eb Log APN and tun names for packets
Change-Id: I6f7ce33f6585b2b78e2b8a5c0f7111f0316d6ddd
2017-12-05 17:42:09 +01:00
Pau Espin 55d639f0fb ggsn.c: Print version of unhandled ip packet
Change-Id: I7e226a12b074c96c572f90e3aaf62716d0cd47c5
2017-12-04 13:25:02 +01:00
Pau Espin 840ce8a0a8 ggsn_vty: Stop using deprecated API vty_install_default
Changes made as requested by the deprecation text.

Fixes warning below:
 warning: ‘vty_install_default’ is deprecated: Now happens implicitly with install_node() [-Wdeprecat
ed-declarations]
  vty_install_default(GGSN_NODE);
  ^~~~~~~~~~~~~~~~~~~

Change-Id: I5c6197129e0c251a4e8dd174027b011c8f6476c6
2017-11-16 17:01:51 +01:00
Harald Welte fd30bd1032 gtp-kernel: Add device nime in pdp_debug() log statements
Change-Id: Iad0e7a9fa48fcddc31b8d555244581efdbd61b4e
2017-11-14 00:08:51 +09:00
Harald Welte 227034c88e gtp-kernel: Add function name to pdp_debug() function calls
This allows us to distinguish "add" from "del" operatons in the log

Change-Id: Ibe2e76a6eecc7b5fa5f44ab2c1578597138e30b9
2017-11-14 00:08:51 +09:00
Harald Welte 3dad951171 gtp-kernel: Get rid of SYS_ERR where not applicable
SYS_ERR is for logging an error from the (operating) system including
the errno value.  For general logging, we have DEBUGP/LOGP.  Let's
convert the gtp-kernel logging over.  This also fixes the related line
ending mess-up as SYS_ERR adds a LF while LOGP/DEBUGP don't.

Change-Id: Idb4069a28227b770e20d62bf306cd294f47146ae
2017-11-14 00:08:51 +09:00
Harald Welte 318795635e gtp-kernel: proper cleanup in error path
When genl_socket_open() succeeds but genl_lookup_family() fails,
we have to clean up the socket that we just opened.

This requires a new version of libgtpnl :/

Change-Id: I31df046530347f88cb7b16c37a899b456ed1b080
2017-11-14 00:08:51 +09:00
Harald Welte 22e1573831 gtp-kernel: Make sure repeated calls to gtp_kernel_init() are safe
We have to factor out the "run once" code and make sure to really
only run that once, while the per-device code remains in the
gtp_kernel_init() function.

Change-Id: Iba5bd71e4b725eef59fe4f233fbb965e396a06c3
2017-11-14 00:08:51 +09:00
Harald Welte c85e89961a gtp-kernel: Avoid global state variable
Whether or not GTP kernel support is enabled is the property of a
given APN, and not a global state variable.

Change-Id: Iff3bd8a52bd6c20f9811ee41ff700486d08591f3
2017-11-14 00:08:51 +09:00
Harald Welte 2fc2bc6bc4 gtp-kernel: Align logging for APN start in kernel-gtp case with that of TUN
Change-Id: Ie53d37f151e8b6448636a8cde5777b3841989d05
2017-11-14 00:08:51 +09:00
Harald Welte 0d0e242685 gtp-kernel: shut down kernel GTP device in apn_down()
When we take the APN down, we should also take the GTP device down.

Change-Id: Idd250dd454a1603834d388884a24a63e044fdd7b
2017-11-14 00:08:51 +09:00
Harald Welte 698a2339eb gtp-kernel: Get rid of hard-coded kernel GTP device name
The existing kernel GTP support code inherited from OpenGGSN was overly
simplistic and didn't support multiple GTP devices or user-defined GTP
device names.  Let's remove that restriction in this patch

Change-Id: I51df223788fd5b7cf8099463b8aa0ca4a4fd1c96
2017-11-14 00:08:48 +09:00
Harald Welte 490782d18e gtp-kernel: Re-add support for kernel GTP-U acceleration
When we branched off osmo-ggsn from the old openggsn code base, the
support for kernel-gtp got temporarily removed.  This patch
re-introduces support for handling the GTP-U plane in the Linux kernel
by means of libgtpnl + the kernel GTP-U driver.

This only works for IPv4 at the moment, until the kernel GTP-U code
gains IPv6 support.

Kernel GTP currently also is restricted to a single APN per GSN.

Change-Id: Ieb1bc1bd0d51d41947f0abd6ebbc2e5d102592d6
2017-11-13 23:59:40 +09:00
Harald Welte e3c5918aee gtp_kernel: Change gtp_kernel_init() function signature
Rather than taking an explicit in_addr, prefix_length and a
string-formatted prefix, let's pass in an in46_prefix and derive
the other representations from it.

Also, don't refer to a no-longer-existing global 'ipup' variable but
add it as a function argument.

Change-Id: Ife87142c86589b4fa4062d62afe3670467548589
2017-11-13 23:57:58 +09:00
Harald Welte e2a1de5ca5 Properly NULL-out blacklist in alloc_ippool_blacklist()
This ensures that in case of error, any caller can still safely
call talloc_free() on the blacklist pointerm as free on NULL
is well-defined.  With the code prior to this patch we fear
a double-free.

Change-Id: Idc511cb3f0dfb922920aba8f88ea77df1722ecdc
2017-11-13 23:57:58 +09:00
Harald Welte f55a039048 remove unused argument to alloc_ippool_blacklist()
Change-Id: I4d3ea077ba46446e537ec9a6de6f4080fcaa428c
2017-11-13 23:57:58 +09:00
Harald Welte 51127ea962 sgsnemu: Don't leak FILE handle in proc_read()
Change-Id: Ie22e6a9bc172427e867e7a4001b6c710477a232b
Fixes: Coverity CID#178660
2017-11-06 02:42:59 +09:00
Pau Espin 859f9b0752 ippool: Implement and use blacklist instead of blindly using IPPOOL_NOGATEWAY
Commit dda21ed7d4 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-17 19:10:24 +02: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
Harald Welte 9d9d91b8e8 ggsn: Avoid crash on wrong EUA type
If the EUA in the Create PDP Context Request was not supported by
the given APN (e.g. IPv6 request for a v4-only APN), we crashed.

Avoid this and add proper handling of this error case.

Change-Id: I8d1f7ec727c5d2d4427232015f81ed57d3440dff
2017-10-14 16:39:07 +02:00
Pau Espin fdd732b130 Remove trailing whitespace
Change-Id: I8e24f95a88bef3a59006a89c219871e6156963d7
2017-10-13 16:28:01 +02:00
Pau Espin 958256f5cf create_context_ind(): Fix crash on apn not found
Program terminated with signal SIGSEGV, Segmentation fault.
0  create_context_ind (pdp=0xb6b391b0 <pdpa>)
    at /usr/src/debug/osmo-ggsn/1.0.0+gitrAUTOINC+ab5e160937-r0/git/ggsn/ggsn.c:453

453             if (!apn->started)

(gdb) bt
0  create_context_ind (pdp=0xb6b391b0 <pdpa>)
    at /usr/src/debug/osmo-ggsn/1.0.0+gitrAUTOINC+ab5e160937-r0/git/ggsn/ggsn.c:453
1  0xb6b225e0 in gtp_create_pdp_ind (gsn=gsn@entry=0x74f28, version=version@entry=1, peer=0x0,
    peer@entry=0xbee6ead4, fd=-1092167056, fd@entry=8, pack=pack@entry=0xbee6eae4, len=len@entry=179)
    at /usr/src/debug/osmo-ggsn/1.0.0+gitrAUTOINC+ab5e160937-r0/git/gtp/gtp.c:1591
2  0xb6b245e4 in gtp_decaps1c (gsn=0x74f28)
    at /usr/src/debug/osmo-ggsn/1.0.0+gitrAUTOINC+ab5e160937-r0/git/gtp/gtp.c:2986
3  0x41d770c0 in osmo_select_main () from /usr/lib/libosmocore.so.8
4  0x000121b8 in main (argc=4, argv=0xbee70e54)
    at /usr/src/debug/osmo-ggsn/1.0.0+gitrAUTOINC+ab5e160937-r0/git/ggsn/ggsn.c:897

Fixes: dd266066c7, b16c46b4c3

Change-Id: Ie4ec74e87aaf1d067dd1717d986673be56c4d6ed
2017-10-11 20:37:24 +02:00
Harald Welte b16c46b4c3 create_context_ind(): ignore a non-started default APN
If the default APN has not been started, it is not eligible to be
used in starting of new PDP contexts.

Change-Id: I93b5c205c033f275824ee8bc8cdcf1428fb086df
2017-10-01 18:29:41 +08:00
Harald Welte ed1ba2c902 apn_start(): Extend error message when setting IPv6 address fails
Tell the user about possible causes of failure to set the IPv6
address of the tun device, such as general lack of IPv6 support in
the kernel/OS, or the use of /proc/sys/net/ipv6/conf/default/disable_ipv6

Change-Id: I5ff812425ee12b8386bb66521e05c93e825a4506
2017-10-01 18:19:07 +08:00
Harald Welte ed08eb1c5a apn_stop(): Print tun device name when closing tun device
Change-Id: If981cc0696122cb69c01ceac6f54ae01bcbf4a2d
2017-10-01 18:19:07 +08:00
Harald Welte 2e84d2c29a create_context_ind(): ignore any non-started APNs
If we receive a GTP-C CREATE PDP CONTEXT for an APN that we were
unable (or not configured) to start, ignore that APN.

Change-Id: I8011a9ccc1d5effd3779f184c9055af46838ccaf
2017-10-01 18:19:07 +08:00
Harald Welte dd266066c7 apn_start(): fix clean-up after errors bringing up APN
When there's an interim error (e.g. in resolving the link-local address
or setting up the tun device), apn_start() simply calls apn_stop()
on the not-yet-fully-started apn_ctx.

This only works if apn_stop() doesn't bail out early in case of
a not-started apn_ctx, so let's remove the related check at the
start of the function.

Change-Id: I2917a6258cb73cc12fd9d81296ff0eaa616890b9
2017-10-01 18:19:07 +08:00
Max 6a21527a2d Move extended PDP logging macro to header
It might be useful for any user of libgtp who uses libosmocore so let's
make generalized version of it available as part of installable header.

Change-Id: I79aba10ef989384a28f059c30899e65c771ae5e1
Related: SYS#3610
2017-09-25 10:35:34 +02:00
Harald Welte 93fed3bc51 ggsn: Add per-APN VTY configuration option on G-PDU sequence numbers
This per-APN vty option determines if we are transmitting GTP sequence
numbers in downlink G-PDU messages.  This behavior is optional as per
GTP spec.  The default behavior is "true", like before this change.

Related: OS#2519
Change-Id: Ibf0de261f83951309b01b4feae998b6656c77664
2017-09-24 23:10:01 +08:00
Harald Welte ff438174aa ggsn: Fix double whitespace in writing "ifconfig" lines
This is merely a cosmetic issue, no functional change.

Change-Id: I8663ee633524eedeed5ddd45ddb65a06825052ac
2017-09-24 22:49:21 +08:00
Harald Welte 3ca419a2ef ggsn: Fix config file writing of IPv6 DNS settings
There was a copy+paste mistake that created syntax errors during the
write of a config file that contained IPv6 DNS server settings.

Change-Id: Ida40c32c72dba8155f8294b93484e46e8bd27739
2017-09-24 22:49:21 +08: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 98146776dd ggsn: Add ability to specify local IP addresses for GTP-C and GTP-U
In case the GGSN is behind some kind of DNAT, the public GTP-C and
GTP-U IP addresses as exposed inside the GTP payload information
elements are different from the (internal, behind-nat) IP address
to which it listens/binds.

Change-Id: I548c9011c9abd66d46f963b1def61575f3dabb89
2017-09-06 12:22:31 +02:00
Harald Welte 632e843e5f Rename OpenGGSN to OsmoGGSN
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-06 09:17:15 +02:00
Harald Welte e80494726c ggsn: Handle SIGTERM like SIGINT and terminate
Change-Id: I0c8773bd6ef41332b91b5b025aef9ef129af8289
2017-09-06 09:17:15 +02: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 8a03ea8a32 libgtp: Remove ctrl_handle from gsn_t, replace with private context
The control interface handle never belonged into libgtp in the first
place.  Commit 727417dd28 should not
have added this to the shared library (used by sgsnemu, osmo-sgsn, ...),
but to some private state of the GGSN.

Introducing a private context pointer at the same location will keep
ABI compatibilty.

Change-Id: I4f17516dae3e04114564828a3e5f6e2ea54212a5
2017-09-05 23:13:10 +02:00
Harald Welte 4857f3c2f3 lib/ippool: Move ippool_aton() out of ippool_new()
we rather pass the in46_prefix directly into ippool_new()

Change-Id: Iadf6274e881a9bfc75eb41f9380f5ae2d8c92a0f
2017-09-05 22:42:18 +02:00
Harald Welte 8ffd7fc782 gtp-kernel: Remove dependency to cmdline.[ch]
Change-Id: I760f25df609c309eba4d5716f3e23b49320449bf
2017-09-05 22:42:17 +02:00
Pau Espin 0ab62fe081 ggsn: Fix DNS not sent in PDP context response
During IPv6 support implementation, helper function pco_contains_proto
was added which contains an error: It is only capable of finding first
protocol correctly, and as a consequence, in my setup DNS servers where not
sent back to the SGSN/MS, resulting in phone being able to connect to
IPs but not to domain names which required DNS resolution.

The condition in the while loop is also changed to match the increment
of the variable inside the loop to make it easier to understand at first
glance.

Fixes: 1ae98777d9

Change-Id: Icc2e6716c33d78d3c3e000f529806228d8aa155e
2017-08-30 15:56:27 +02:00
Harald Welte b10ee08c2f Properly format IMSI before using it in trap
For some reason Max' commits introducing the CTRL/trap interface
about one year ago didn't convert the IMSI to its actual textual
representation before usign it in the CTRL interface.

Let's clean that up by properly interpreting the IMSI.

Change-Id: I8b20d2e47a29de266d93a7ddd5e6877f7e346a63
2017-08-12 22:53:54 +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
Harald Welte 1ae98777d9 IPv6: Support PCO for IPv6 DNS addresses
In IPv6, DNS server information is not passed along as IPCP6 like
in IPv5 with IPCP.  The reason is that IPCP6 (for PPP) doesn't
support passing DNS server information.  Rather, the relevant RFCs
indicate DHCPv6 should be used even over point-to-point links.

3GPP decided to avoid DHCPv6 dependency for stateless autoconfiguration
(the only mandatory IPv6 configuration mechanism) and added some new
non-PPP-style PCO information elements ("containers") which can among
other things inform a MS about IPV6 DNS servers.

That same mechanism can also be used to inform the MS about IPv4 DNS
servers, so for IPv4 there are now two competing mechanisms: IPCP and
the new "native" PCO container.  With this patch, we support both
for IPv4.

Change-Id: I21499afd61def8c925f7838bde76f34d28214b56
2017-08-11 10:46:00 +02:00
Harald Welte d46bcd236e IPv6: Implement IPv6 prefix assignment via ICMPv6 router advertisement
The 3GPP specs are quite strange when it comes to how an IPv6 address
or rather prefix is assigned to an IPv6 PDP context.  The designated
method for allocating the IPv6 address via the PDP EUA (End User
Address) Information Element in the GTP signalling plane is *not*
used to allocate the address/prefix.  Instead, the EUA is used to
allocate an "interface identifier" to the MS, which it the uses
to derive its link-local source address to send a router solicitation.

The GGSN subsequently answers witha router advertisement, advertising
a single/64 prefix, whihcthe MS then uses to generate it's real IPv6
source address for subsequent communication.

Change-Id: Icddf7d30e01d76a4784bcef5787b36f52f703a9f
2017-08-11 10:45:56 +02:00
Harald Welte d4d6e09fd2 ippool: Extend pool to work with /64 prefixes
In IPv6 GPRS, we actually don't want to allocate an individual v6
address (like in IPv4), but we want to allocate a prefix.  The
standard prefix lengh is 8 bytes, i.e. a /64 prefix.  This patch
extends the pool to be able to work with such v6 prefixes.

Change-Id: I0cf700b6baf195a2e5fbea000531f801acaaa443
2017-08-09 22:37:57 +02:00
Harald Welte d1bf1e11ba ggsn: Send proper errors in create_context_ind()
When we receive PDP context requests for unknown PDP types or if
we run out of dynamic addresses, we need to inform the SGSN that
PDP context creation failed.

Change-Id: Ibf199c1726130d27c8f80230b30ee51101c93b06
2017-08-09 22:09:34 +02:00
Harald Welte a0d281db1c IPv6 support for user IP
This patch enables the use of IPv6 PDP contexts.  The phone will
have to request an IPv6 End-user-Address, and the GGSN will have
to be configured for an IPv6 pool.

The outer transport-layer IP between SGSN and GGSN must still be
IPv4, it is not modified by this patch

Change-Id: I22c3bf32a98e5daf99d6eaeac8c9f95cc7574774
2017-08-09 22:09:34 +02:00
Harald Welte 63ebccdfe3 lib/tun.h: Remove non-endian-safe redefinition of IP header
We can simply use 'struct iphdr' from netinet/ip.h to achieve
the same goal (and be portable).

Change-Id: Ieece22e127dc14a7ffdc3b05656628989ad00b32
2017-08-09 22:09:34 +02:00
Harald Welte d12eab9c4e ippool: Add IPv6 support to IP pool implementation
Extend the IP pool implementation to be able to manage both pools
of 32bit addresses (IPv4) as well as pools of 128bit addresses (IPv6)

Change-Id: Ib98cc4bf634d6be9a7bf8c03a24e629455fcafc8
2017-08-09 22:08:57 +02:00
Harald Welte d9d8862a58 Proper fix for "Force Dynamic IP" in Create PDP CTX
An EUA length of *2* octets indicates dynamic IP address, while
an EUA length of 0 is invalid.  Let's fix this hack (which needs
to finally be removed anyway).

Change-Id: Ib1b57eb0654327882044d6862d955f4b32aa6bcd
2017-08-04 00:23:57 +02:00
Max 3142d8d30b ctrl: cleanup trap creation
Move common trap create/send code into separate function.

Change-Id: Iaadc921b951aeb9b3ad5ab796e13d52017139468
2017-05-16 17:10:25 +02:00
Harald Welte 875e4dc8c3 gtp-kernel: Fix tunnel creation/removal for GTP Version 1
When Linux Kernel GTP-U support is enabled, OpenGGSN so far only worked
with GTPv0,but not with GTPv1, as the TEI values were not correctly
configured.  This patch fixes the initialzation of the local and remote
TEI before using libgtpnl to create a tunnel context in the kernel.

Change-Id: I3e953ff5b4ab44c26dbbe20d18b61038fa57ff32
2017-02-23 21:10:48 +01:00
Max dbd7024919 Only send TRAP for defined PDP peer
Do not attempt to send TRAP message on PDP context deletion if peer is
unknown.

Change-Id: I5e02c1d42bb7aaf1ef81a9824aab7b12047cdd3e
Fixes: Coverity CID 150135
2016-11-02 09:32:31 +00:00
Max 727417dd28 Add control interface
Only generation of TRAP messages over Control Interface is supported so
far.

Note: requires corresponding version of libosmoctrl.

Change-Id: Ia76f841d2c9cd14394e9316fcd39f4060e23c898
Related: OS#1646
2016-10-12 09:30:30 +00:00
Max 395e213894 Remove unused function
Change-Id: Iff0f1499660b12a47277b16a435efecb42fab038
2016-10-11 15:31:49 +02:00
Pablo Neira Ayuso 176e895bd6 ggsn: fix compilation error with --disable-gtp-kernel
gtp-kernel.h: In function ‘gtp_kernel_init’:
gtp-kernel.h:25:15: error: ‘struct gengetopt_args_info’ has no member named ‘gtpnl_given’
  if (args_info->gtpnl_given) {
               ^
Makefile:422: recipe for target 'ggsn

Reported-by: Holger Freyther <holger@freyther.de>
2016-05-12 16:54:56 +02:00
Pablo Neira Ayuso d9d7be339d ggsn: cmdline: no need to specify interface anymore
--gtpnl is now gone, instead you have --gtpkernel that behaves as an on/off
toggle. We full rely on the kernel routing base to select the real device to
transmit.

I have updated ggsn/cmdline.ggo and then run 'gengetopt' to refresh the
automatic code generation for command line options that openggsn uses.
2016-05-10 19:06:01 +02:00
Pablo Neira Ayuso 7b31987a46 ggsn: gtp-kernel: adapt gtp_dev_create() to its new interface
Andreas modified this interface, so update so this compiles again.
2016-05-10 18:51:00 +02:00
Andreas Schultz c5fbf9bd68 ggsn: update gpt-kernel logging to libosmocore
Signed-off-by: Andreas Schultz <aschultz@tpip.net>
2015-12-21 08:37:26 +01:00
Pablo Neira Ayuso 4b075b6cb8 ggsn: add support for GTP kernel data encapsulation
This patch adds the -g, --gtpnl=device option that allows you to
enable the GTP kernel tunneling mode in openggsn. You have to specify
the real downlink device that will be used to tunnel traffic, eg.

	-g=eth0

This means that the gtp0 device will be created and it will use eth0
as the real device to encapsulate packet coming from the Internet that
are addressed to the MS (so the tunnel devuce encapsulates these IP
packets in GTP packets when traveling to the SGSN).

Alternatively, you can also add this to the ggsn.conf configuration file:

	gtpnl eth0

The device has to be the real device that can route packets to the SGSN,
if you select the wrong device, the kernel routing code may not find a
way to reach the SSGN, you've been warned.

Therefore, if this option is set, the operational becomes the following:

1) A gtp0 device is created via rtnetlink and configure the socket
   encapsulation infrastructure in the kernel.
2) Whenever a PDP context is created, this adds the necessary tunnel
   configuration via genetlink GTP interface.
3) Whenever a PDP context is destroyed, this deletes the tunnel via
   genetlink GTP interface.
4) Destroy the gtp0 device if ggsn is stopped, including all of the
   existing tunnels.

You require the osmo-ggsn.git tree, which contains the kernel module
gtp.ko and the libgtpnl library that you have to compile and install.
Make sure you have loaded the gtp.ko kernel module before launching
the ggsn daemon using the kernel driver mode, otherwise you will get
a nice "operation not supported" error message ;-).

This patch also adds supports for "ipup" configuration option to invoke
an external script after the gtp0 device has been brought up. Typical
command to add the route to reach the MS behind the GGSN is required,
eg. ip route add 10.0.0.0/8 dev gtp0.

The (horrible) ggsn parser has been manually extended to support the
new configuration option. That code doesn't look nice, but it just
mimics what we already have there for consistency, please don't blame
me for that.

If you want to run in debugging mode, I suggest you to use:

	sudo ggsn -c ggsn.conf -f -d

Note that you do have to run openggsn as root to bring up the gtp0
device. You have to see this message that announce that the GTP kernel
mode is enabled.

openggsn[1106]: ggsn.c: 656: Using the GTP kernel mode (genl ID is 25)

This patch also automagically sets up route to reach MS from Internet
just like tun mode does. This is fundamental to get this working,
better don't leave to the admin, he may forget to add this route.

In this patch, I tried to encapsulate this new feature as much as
possible as Harald initially suggested.

To compile this feature, you have to pass --enable-gtp-kernel, ie.

./configire --enable-gtp-kernel

Otherwise, the code to interact with the gtp kernel part is not compiled.

Signed-off-by: Andreas Schultz <aschultz@tpip.net>
2015-12-21 08:37:11 +01:00
Holger Hans Peter Freyther 6ab58b466a ggsn: Move printf to DEBUGP statements in the ggsn as well
The specific log statements are not great yet but at least they
will end up in the log file. In the future everything should be
related to the IMSI or at least the tunnel id.
2014-12-04 19:29:57 +01:00
Holger Hans Peter Freyther 8e7e3ef686 ggsn: Remove unused dump/logging method 2014-12-04 19:19:33 +01:00
Holger Hans Peter Freyther c38bf64e3f ggsn: Be able to set the log level for the text file
Fixes: SYS#599
2014-12-04 18:54:58 +01:00
Holger Hans Peter Freyther 9c7fd8edc4 logging: Switch to using libosmocore logging for all the code 2014-12-04 16:51:15 +01:00
Holger Hans Peter Freyther 9c0ff4fafe cli: Introduce a logfile command to log errors to a file
The evolution would be to introduce libosmocore and start using
the logging framework. But even then we can map this option to
the file target.

Fixes: SYS#263
2014-03-23 10:29:17 +01:00
Holger Hans Peter Freyther 1c4d9e6d87 cli: Manually patch the generated code to fix compiler warning
cmdline.c: In function ‘cmdline_parser_internal’:
cmdline.c:588:7: warning: variable ‘check_required’ set but not used [-Wunused-but-set-variable]
   int check_required;
       ^
2014-03-23 10:27:21 +01:00
Holger Hans Peter Freyther 6c0b9c2c42 cli: Re-generate the cmdline.c/cmdline.h with newer gengetopt 2014-03-23 10:27:19 +01:00
Holger Hans Peter Freyther e071e30937 build: Remove subdir-objects as it breaks make distclean
We are not using this option in any of our projects and it is breaking
make distclean. Remove the option for now.

make[2]: Entering directory `/openggsn-0.91/_build/ggsn'
Makefile:307: ../lib/.deps/getopt.Po: No such file or directory
Makefile:308: ../lib/.deps/getopt1.Po: No such file or directory
make[2]: *** No rule to make target `../lib/.deps/getopt1.Po'.  Stop.
2012-11-06 13:59:59 +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
Harald Welte 6fc42401b9 properly build a library for the content of the lib directory 2011-05-10 17:44:39 +02:00
Emmanuel Bretelle 91384a4cb0 Do not exceed 80 characters per line
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
Emmanuel Bretelle 68521860e0 Fixed compile warning,exit if cant daemonize
Relevant output of make:

ggsn.c: In function ‘main’:
ggsn.c:436: warning: ignoring return value of ‘freopen’, declared with
attribute warn_unused_result
ggsn.c:437: warning: ignoring return value of ‘freopen’, declared with
attribute warn_unused_result
ggsn.c:438: warning: ignoring return value of ‘freopen’, declared with
attribute warn_unused_result
ggsn.c:439: warning: ignoring return value of ‘daemon’, declared with
attribute warn_unused_result

Signed-off-by: Emmanuel Bretelle <chantra@debuntu.org>
2010-10-20 11:04:51 +02:00
Harald Welte 841dd49086 fix 'make distcheck': add lookup.h to Makefile.am 2010-05-24 11:02:33 +02:00