Compare commits

...

344 Commits

Author SHA1 Message Date
Oliver Smith
ba3d8905f9 Bump version: 1.12.0.37-cf65-dirty → 1.13.0
Change-Id: I7dbdd71d62fb13ba2ffc30d7d50fb4207a06340b
2025-02-12 12:09:58 +01:00
Alexander Couzens
cf65292b0d gtp: split gtp_req into 2 parts: transmit and fill header
Split the preparing the data from the socket and queue handling into two functions:
gtp_req(): preparing the data
gtp_req_transmit(): selecting socket, port and adding it to the transmit queue.
In a following commit gtp_req_transmit() can be used by gtpv1 function
as well.

Change-Id: Icda0ef7b0ce3631e23da88827dd54cf019878b5d
2025-01-12 21:03:39 +01:00
Alexander Couzens
71fefdad09 gtpie: add gtp_encaps a modern encapsulation method
No idea why the previous ones started at the second IE.
Further add more length arguments to the encapsulation method.

Change-Id: I8bb086c568e07052c52d880df06049490346e91e
2025-01-12 21:03:27 +01:00
Daniel Willmann
4b8ebcd784 gtp: Rework gtp_resp() into gtp_resp_pdp()
gtp_resp() requires a PDP context. To support more generic messages
without a PDP context, rename gtp_resp() into gtp_resp_pdp() and
create a more generic function to transmit a GTP response.

Will be used by the SGSN Context Req/Resp/Ack code.

Change-Id: Id9ff95e0e2a10a22e65ecf42b2a2b06a0f2d1a45
2025-01-07 13:39:01 +01:00
Alexander Couzens
446dd65de1 gtp_new(): use talloc instead of calloc/free
Required for SGSN Context Req fsm which is using talloc.
Adds a new api to set the libgtp talloc context via gtp_set_talloc_ctx()

Change-Id: I7c4a29c4bb1ef3c7bf506e59e99b3a804cabe34b
2025-01-07 13:35:54 +01:00
Pau Espin Pedrol
09142e1c27 jenkins.sh: Use --disable-doxygen configure param
Change-Id: I0c73c5e5c94bb712975f8ae0c6cff4743e148210
2024-12-10 17:07:54 +01:00
Alexander Couzens
04f5ea4ffa gtp.h: add more GTP cause code from 29.060 v15.3.30
Change-Id: I1571286f01a24adf10243c9551ca81bacc12f8f9
2024-11-25 16:29:08 +01:00
Daniel Willmann
839c2b9c84 gtp: Make peer addr const in gtp_req/gtp_resp
Change-Id: I955b82ba8022754c3d23979d5c55bb61233047b1
2024-11-25 16:29:08 +01:00
Alexander Couzens
65e133b42c gtpie: fix comment
Change-Id: I5aed6a7a2ae4138567944988bc81cebdbf129276
2024-11-25 16:29:08 +01:00
Alexander Couzens
95746b9588 gtp_internal.h: add missing include to <stdint.h>
Change-Id: I4b9a9b582854368b3492cb7438b3acb1a9652f9e
2024-11-25 16:29:08 +01:00
Pau Espin Pedrol
2b161df6af doc: Update all iptables references with nftables
Change-Id: I3caf316e8ccf1d757b83f7a119271084c55e018c
2024-10-25 14:58:52 +00:00
Pau Espin Pedrol
13d23077d2 doc: Document MTU features in User Manual and example config files
Related: OS#6298
Related: SYS#7122
Change-Id: Ib6e974b38107fe48072380f768e1881f0fc95e80
2024-10-25 14:58:52 +00:00
Pau Espin Pedrol
a4cb3eb011 tun: Use OSMO_STRLCPY_ARRAY
tun->devname buffer is already IFNAMSIZ bytes long, so simplify the
code.

Change-Id: I40b370f4152748d5acf6ee576462e54c9a46a8a3
2024-10-25 16:28:43 +02:00
Pau Espin Pedrol
9f1fd42148 Refactor tun_t fields and alloc APIs
The previous state of code made allocation code more complex for no good
reason; use usual alloc() type function instead, splitting between the 2
types of tun_t implementations available to make it easier to
understand.

Move the several tun-iface specific mode fields to a substruct to make
it clear those are only really containing useful information when the
tun_t is created in tun-iface mode.

Change-Id: Ic71f91c62cd5bd48c6d35534eaac2091e4c69735
2024-10-24 15:49:39 +02:00
Pau Espin Pedrol
ad03073219 Rename tun_encaps -> tun_inject_pkt
The terminology of "encapsulating" used in tun_encaps is confusing,
since in this case we are not really encapsulating anything, but
actually delivering ("injecting") the packet to the system network
stack.
Using the "encapsulating" term is also confusing because readers may
think it may be doing the GTP-U encapsulation, which is not.

Change-Id: Ibb17c792b81668571e69d79918f3adf0e9e0f6c8
2024-10-23 18:45:16 +02:00
Pau Espin Pedrol
234cd12ea5 tun.h: Remove non-existent tun_decaps()
Change-Id: If9cc5d2d54b87e38feefa55cb9410715fa9bd11f
2024-10-23 18:44:05 +02:00
Pau Espin Pedrol
d73801ebea ggsn: Rename confusing functions
It's really confusing having a function operating on a rx path called
"encaps" since it's not really encapsulating anything.
This confuses the reader by thinking this is the function encapsulating
packets into GTP-U.

Change-Id: I7ff54f5e57ccc2c436becd1be1b0f728cbcdb12c
2024-10-23 18:42:43 +02:00
Pau Espin Pedrol
1d7e86ae48 ggsn: Avoid forwarding IPv6 solicited-node multicast addr to tun device
There's no need to forward those. Morevoer, they cannot be forwarded
when using gtpu kernel mode since it doesn't support reinjecting packets
we got from it, so avoid erroring out when trying to inject them later
on.

Related: OS#6600
Related: OS#6382
Change-Id: Iac8f14083620d86f3872aa951930fbe8f680ff24
2024-10-23 18:20:57 +02:00
Pau Espin Pedrol
56a6e025d3 tun: Fix null pointer derefence when in kernel gtp mode
When using gtp kernel module, the kernel sends GTP-U packets to
userspace (osmo-ggsn) when it is unable to find a related pdp ctx for
the packet.
This is so far processes through the code path:
ggsn_gtp_fd_cb => gtp_decaps1u => gtp_gpdu_ind => encaps_tun = > tun_encaps

In usual circumstances, if the gtp module sends a packet to userspace
because it is unable to find a pdp ctx, userspace shouldn't be able
anyway, so it should go through a different code path and answer over
GTP-U with a "Error Indication".
Other specific packets (such as ICMPv6 with link local address) are also
being forwarded to userspace. Some of them are being handled in
encaps_tun() in a special way (eg. Router Soliciation), but others, such
as Neighbor Solicitation, are not being handled there and follow the
generic path where they try to be forwarded over the tun towards the
Internet.

When using the kernel gtp mode, there's no way to re-inject into the
network stack a packet we received from the gtp mode, like done when
using the tun device mode.

Prior to 38b607ece3, a bug existed in
tun_encaps() which would still try to use tun->fd (-1) when in gtp
kernel module, which ended up in an error being printed.
After the mentioned commit was applied, when in gtp kernel module it
started accessing tun->tundev which is is NULL under that setup, hence
making the bug consequences worse.

Add a pointer guard with a log line to inform about the problem, while
still discussing the originating problem in OS#6600.

Related: OS#6600
Change-Id: I508758696a0bcbb7c780a0ed33b28ba640602488
2024-10-23 15:39:47 +02:00
Pau Espin Pedrol
c075d032b9 doc: Reorder some chapters
Move general/generic osmocom chapters (logging, vty) further to the end,
so that the osmo-ggsn specific chapters stay together and don't get lost
in tons of generic content.

Change-Id: I6441944cc365bae40ab0f3cc4f1ecd1ac790c5c5
2024-10-22 19:45:18 +02:00
Pau Espin Pedrol
d44bf6fd73 doc: Fix typo: wrong interface named
Change-Id: Ib7ef619c74bf0e6453f0d5ba509e7727bf90f838
2024-10-22 19:45:18 +02:00
Pau Espin Pedrol
77d4ae0470 doc: Remove reference to non longer existing osmo-ggsn.init
The init file was removed at some point in the past.
Nowadays only a systemd service is provided.

Change-Id: I47f889a223bfaf7bd4848898211a3cc62df5e08c
2024-10-22 19:45:18 +02:00
Pau Espin Pedrol
e6feda5185 doc: Fix typo in user manual
Change-Id: I9b0024cfdb748febcecf01a097125103bc0f39c1
2024-10-22 19:45:18 +02:00
Pau Espin Pedrol
f92d875119 ggsn: apply configured APN MTU to tun
Related: OS#6298
Related: SYS#7122
Change-Id: Ifae556169d895860812c9ea5633292d7e3fab338
2024-10-22 19:45:18 +02:00
Pau Espin Pedrol
454110a007 ggsn: Use osmo_netdev_addaddr() libosmocore API
This allows dropping a lot of duplicated code.
While at it, drop references to non-linux systems, which are not
maintained anymore.
Param "dstaddr" was not used anywhere in the old APIs, so it can also be
dropped.
Param "tun->routes" was also used in BSD code, so it can also be
dropped.

Change-Id: I1fccfd658542481cd61536fbd3c7a3a32a1c253b
2024-10-22 19:45:06 +02:00
Pau Espin Pedrol
38b607ece3 ggsn: use libosmocore tundev API to create apn tun device
This way we can start dropping old osmo-ggsn specific API, avoiding
duplication of code.
Moreover, the osmo-ggsn code is using older ioctl APIs, which are
discouraged nowadays in favour of netlink, which osmo_tundev/osmo_netdev
from libosmocore is used.
Even better, we win for free non-blocking write behavior in the tundev
when switching to the new API, since it already has its own internal
wqueue.

While doing this, BSD code is dropped since anyway it's not been
maintained for a long time.
If needed, the BSD support can be added to libosmocore
osmo_tundev/osmo_netdev API.

This is a first step (already working). Follow-up commits will replace
the APIs to set up routes and addresses, and later on osmo-ggsn will win
support to set MTU on the interface.

Furthermore, this will allow easily adding netns support to osmo-ggsn
later on if ever needed.

Depends: libosmocore.git Change-Id Ia8a7e7ec6d96c7aebc80528236a0e0d035e7f38d
Change-Id: I4d99ba147ac0f3b414d2efef0068b6b8d6cf0014
2024-10-21 18:45:32 +02:00
Pau Espin Pedrol
41bec9529f ggsn: Support announcing APN MTU over ICMPv6 RA
Related: OS#6298
Related: SYS#7122
Change-Id: I8bb67915dd5f39ad9ffb80e5aaf9af1e7d70c96c
2024-10-21 18:45:32 +02:00
Pau Espin Pedrol
6041554cef ggsn: Support announcing APN MTU over PCO
This is only useful for IPv4 (or IPv4v6) APNs.
IPv6 APNs obtain this information from SLAAC RA.

Related: OS#6298
Related: SYS#7122
Change-Id: I8532acfffadda9e83962b30e4f6b17eb8b3362ac
2024-10-21 18:45:32 +02:00
Pau Espin Pedrol
6d1d181403 vty: Fix missing newline in description of 'apn tun-device' cmd
Change-Id: I92002acdb83455eb6becc688c33192d3856b0aa6
2024-10-21 18:45:24 +02:00
Pau Espin Pedrol
7d80216717 Move g_ggsn_list declaration to ggsn.c
The llist belongs to the data domain, not the vty.

Change-Id: I0a93aacbdecc283dd4f6b32892430ebdb0b94e50
2024-10-17 18:58:10 +02:00
Pau Espin Pedrol
de385e0253 Move ggsn allocation code out of vty file
The details of creation of data structures don't belong on the vty file.
While at it, split allocation code into its own function to quickly find
out where the allocation of the object happens.

Change-Id: Iaa4cd86c44957321c238d268ea62daafa1b79c69
2024-10-17 18:56:55 +02:00
Pau Espin Pedrol
ce691d8e64 Move apn allocation code out of vty file
The details of creation of data structures don't belong on the vty file.
While at it, split allocation code into its own function to quickly find
out where the allocation of the object happens.

Change-Id: If15a4158dd6599341017efd24dbf67ca565a7c34
2024-10-17 18:51:39 +02:00
Pau Espin Pedrol
8c015bd89a ggsn: kernel gtpu: Support updating pdp ctx remote IP address and TEID
Whenever the SGSN sends the GGSN a UpdatePDPCtxReq, it may offer a new
remote IP address or/and remote TEID, eg. because it wants to establish
a Direct Tunnel and point the GTPU towards the RNC, or to point it back
to itself.
If the gtpu kernel is used, osmo-ggsn lacked updating the kernel with
the new remote data.
The gtp kernel module doesn't provide an efficient/explicit way to
update a pdp context keeping the4 same local IP+TEID and changing only
the remote remote IP+TEID, hence first destroy the pdp ctx in the gtp
kernel module and then recreate it.

This fixes test GGSN_Tests_v4_only.TC_pdp4_act_update_teid in
ttcn3-ggsn-test-kernel-net-next.

Related: OS#6523
Change-Id: I1fc48be5c0f177ccf6fbe97c003b4df44809c0fe
2024-08-19 11:57:23 +02:00
Pau Espin Pedrol
5f8960b206 ggsn: Mark internal cb function static
Change-Id: Ic9fdd50ae098058cc69e5aa6a0085819d69e3599
2024-08-01 17:45:49 +02:00
Pau Espin Pedrol
0828b2afc3 gtp: Allow setting callback to receive update_context_ind
This will be used by:
* SGSN: Get to know that RNC has gonne down according to GGSN (re-attempt
  Direct Tunnel or go back to tun SGSN<->GGSN).
* GGSN: Maybe find out that Direct Flags are used (should be handled
  internally directly in the rx path probably)

Related: OS#6512
Change-Id: Ic80a9a928c55b6ff85be96014920bb42793cb943
2024-07-31 17:23:59 +02:00
Pau Espin Pedrol
70a1d64e55 gtp: Allow UpdatePDPContext initiated by GGSN
The Update PDP Context procedure can be initiated GGSN -> SGSN, as
described in TS 29.060 7.3.3.

Related: OS#6512
Change-Id: I1c3441c71b90c5bbf6f4545484586222e6180fe1
2024-07-31 17:20:58 +02:00
Pau Espin Pedrol
ea3cf1b8ae gtp: Store rx Direct Tunnel Flags in UpdatePDPCtx{Req,Resp}
In Update PDP Ctx Response, only SGSN is expected to transmit Direct
Tunnel Flags in the message.

Related: SYS#5435
Change-Id: Ia3e360a35d30858eab1e438dc2508fd756c2e22e
2024-07-31 17:20:58 +02:00
Pau Espin Pedrol
7ce14f5e93 gtp: Allow tx Direct Tunnel Flags in UpdatePDPCtx{Req,Resp}
In Update PDP Ctx Response, only SGSN is expected to transmit Direct
Tunnel Flags in the message.

Related: SYS#5435
Change-Id: I36d93619e2fe9cafd3092515df18b82d29099d2d
2024-07-31 17:20:54 +02:00
Oliver Smith
561a9bc77c Bump version: 1.11.0.31-7ae1-dirty → 1.12.0
Change-Id: Idf8b178290cbb14e5199590feb584c82dc076dd0
2024-07-24 16:22:26 +02:00
Vadim Yanitskiy
7ae1177e04 README.md: cosmetic: fix a typo
Change-Id: Ia04c62a682cfeca2b054c8fb1ff9fff2aab2860d
2024-06-05 18:34:07 +07:00
Oliver Smith
57585767dc {contrib,debian}/osmo-ggsn.init: remove
Remove SysV init scripts. These are not really maintained anymore and
this makes it consistent with other Osmocom projects.

Avoids synchronizing with SysV scripts on debian:
  # systemctl enable osmo-ggsn
  Synchronizing state of osmo-ggsn.service with SysV service script with /lib/systemd/systemd-sysv-install.
  Executing: /lib/systemd/systemd-sysv-install enable osmo-ggsn

Change-Id: I11bfb5122344b54970b7f742470cb74b95fa37e0
2024-05-16 09:00:21 +00:00
Oliver Smith
488972b442 Use uniform log format for default config files
Related: OS#6272
Change-Id: I272767e029e95b64f2525d4f19efdfa1f0e29ca2
2024-05-16 09:00:21 +00:00
Oliver Smith
08239ccac3 contrib/systemd: run as osmocom user
Related: OS#4107
Change-Id: I915f2fc12d0bd905d24636aacb2760a6b72a55e3
2024-05-16 09:00:21 +00:00
Oliver Smith
fbc56063c5 doc: set state-dir to /var/lib/osmocom/osmo-ggsn
Prepare to run osmo-ggsn as user with the systemd service. As with other
Osmocom service files, we will set StateDirectory= and WorkingDirectory=
options. This results in osmo-ggsn only being able to write to
/var/lib/osmocom, therefore let's change the state-dir from /tmp to
/var/lib/osmocom/osmo-ggsn to avoid:

  gsn.c:411 fopen(path=/tmp/gsn_restart, mode=w) failed: Error = Permission denied

Having the state in /var/lib/osmocom also makes more sense, because then
it doesn't get deleted on reboot.

Change-Id: I5b51529b4f8bd2462e54f58a1ce2e2d7c76ff46a
2024-05-16 09:00:21 +00:00
Oliver Smith
c1598e0eb4 ggsn/ggsn_vty: create state-dir
Prepare to change the state-dir in the default config in a follow-up
commit. Create the directory if it does not exist.

Change-Id: I91349fb284336a9de6af41475f1b824eb0e021b0
2024-05-16 09:00:21 +00:00
Oliver Smith
519a2e401d gtp/gtp_internal.h: new file
While at it, move internal functions of gtp.h to a separate file too.
Make all functions that are only used inside gtp.c static.

The following APIs are unexpectedly public:
* imsi_gtp2str gets used by pdp.h
* gsna2in_addr, gtp_echo_req gets used by osmo-sgsn

Change-Id: I72c40cbdec33449ca8104fb3cad8df1a9e07dfd7
2024-05-14 11:13:45 +02:00
Oliver Smith
fbef527222 gtp: move conversion functions up
Move the conversion functions above the first user, so we can make
in_addr2gsna static in a follow-up commit and remove the extra
declaration.

Change-Id: I51e6a7c1161320fc54b0e8197ae57e4327976eb1
2024-05-14 11:13:45 +02:00
Oliver Smith
68f5b086ad gtp: remove unused conversion functions
Remove ipv42eua and eua2ipv4, which are in the "internal functions"
section of gtp.h, but are not used anywhere in the code anymore. This is
in preparation of moving the internal functions that are used in
multiple .c files into a separate header file, and to make the other
internal functions static. (Compiler complains about unused static
functions.)

Change-Id: I90e2750f6a6e3e6122e9c562103fda77d7326932
2024-05-14 11:13:41 +02:00
Oliver Smith
3cb3423a59 gtp/gtp.c: move gtp_create_context_resp down
Move gtp_create_context_resp below gtp_create_pdp_resp, which it calls.
In a follow-up commit, we can make gtp_create_pdp_resp static and
remove the additional declaration.

Change-Id: I34efe7592013a8423f4f280758272d81f24b65fa
2024-05-13 15:16:58 +02:00
Oliver Smith
bad5eeba0f gtp/gsn_internal.h: new file
Change-Id: I999462e39411fc4ec7e50bd0212e870006fbc4f1
2024-05-13 15:16:58 +02:00
Oliver Smith
1dd16fa12f libgtp: move includes to osmocom/include/gtp
Move all includes from /usr/include/….h to
/usr/include/osmocom/gtp/….h to be more consistent with other Osmocom
projects, and to not "pollute" the top include directory if we add more
header files.

Also the new directory structure makes more obvious, which headers are
public and which ones aren't.

Adjust libgtp.pc.in so both #include <gtp.h> (legacy)
and #include <osmocom/gtp/gtp.h> can be used.

Related: OS#6373
Change-Id: If7e01c61168819bf7120667344e40c857da5490b
2024-05-13 15:16:58 +02:00
Oliver Smith
3372625ad9 contrib: remove rpm spec file
Related: https://osmocom.org/news/255
Related: OS#6446
Change-Id: I7cfe55fa2fda43da4eaa1e1b8d40b31d1c8aaf30
2024-05-08 14:40:58 +02:00
Harald Welte
1f9cc2674f README.md: Major overhaul
A lot of the existing contents was still from the old openggsn days, and
predated osmo-ggsn.

Change-Id: I6ec92260da0f55e9493a15db2e8178e5436143a0
2024-03-23 16:32:45 +01:00
Harald Welte
4abe361f33 README.md: Add Forum + Issue Tracker sections
Change-Id: I7b03a78178de77ebf733587ed178fd48c019663c
2024-03-23 16:15:42 +01:00
Harald Welte
bb0655d5aa README.md: Improve markdown formatting
Change-Id: I4e5d99384978d22e6ba0310e97e93d87b610a174
2024-03-23 16:11:50 +01:00
Harald Welte
4e6fe42731 Add funding link to github mirror
see https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/displaying-a-sponsor-button-in-your-repository

Change-Id: I75ba8c4f8635d5a2d36d5bb97566d737e27bcec9
2024-03-23 16:06:28 +01:00
Oliver Smith
19a506b705 Add clear error for kernel not supporting IPv6
Make it clear to the user, that if adding a tunnel fails with kernel GTP
and IPv6: the reason is that the kernel doesn't support IPv6 yet.

Related: OS#6096
Change-Id: I1d3c8cbb51212c91136292347dad9529a5c58a31
2024-03-04 11:15:07 +01:00
Oliver Smith
ea6c02ac1f doc: fix typo ndoe -> node
Change-Id: Ib78b5de45b93a7534163de2cd91211e9be75445d
2024-03-01 08:08:43 +00:00
Oliver Smith
ec357c5377 lib/gtp-kernel.c: check rc of in46a_from_eua
Fixes: b17fe7bf ("kernel-gtp: support IPv6 on inner layer")
Change-Id: I40e4de1517de8871224a45c173208810b42312ff
2024-02-27 16:04:42 +01:00
Oliver Smith
768d6d5be9 lib/gtp-kernel.c: initialize ret with 0
Fix -Werror=maybe-uninitialize found in Pau's build env:

/home/pespin/dev/sysmocom/git/osmo-ggsn/lib/gtp-kernel.c: In function ‘gtp_kernel_tunnel_add’:
/home/pespin/dev/sysmocom/git/osmo-ggsn/lib/gtp-kernel.c:111:13: error: ‘ret’ may be used uninitialized [-Werror=maybe-uninitialize]
  111 |         int ret;
      |             ^~~
/home/pespin/dev/sysmocom/git/osmo-ggsn/lib/gtp-kernel.c: In function ‘gtp_kernel_tunnel_del’:
/home/pespin/dev/sysmocom/git/osmo-ggsn/lib/gtp-kernel.c:167:13: error: ‘ret’ may be used uninitialized [-Werror=maybe-uninitialize]
  167 |         int ret;
      |             ^~~

Fixes: b17fe7bf ("kernel-gtp: support IPv6 on inner layer")
Change-Id: I19067ebe561d4c067b9ace7f5b201e15af6b342e
2024-02-27 15:00:59 +01:00
Oliver Smith
fa91a10498 Cosmetic: {lib,gtp}/Makefile.am: diff friendly
Change-Id: Ib1956794edc6e82cfa6c5419b2609565674d98a4
2024-02-23 13:25:32 +01:00
Oliver Smith
6929391ecf Cosmetic: AM_CFLAGS: make diff friendly
Change-Id: I3303cd8ba8c8b21ff267608833d9fb4833ffc471
2024-02-23 12:08:48 +01:00
Oliver Smith
9baac03927 Cosmetic: Makefile.am: make SUBDIRS diff friendly
Change-Id: I49e1b08e48dc324f313228e8c69679c37aa774f4
2024-02-23 12:08:48 +01:00
Oliver Smith
9bd2711f39 Revert "kernel-gtp: support IPv6 on outer layer"
This reverts commit 0917ce4e22,
as it breaks building osmo-sgsn. This needs to be reworked to be
backwards compatible.

Related: OS#6373
Change-Id: I2c2b2ff0875217e041d94c8e2cef030d2a86c2d8
2024-02-22 16:06:33 +01:00
Oliver Smith
b17fe7bfe9 kernel-gtp: support IPv6 on inner layer
Related: OS#6096
Change-Id: I3df47b6c209f1e2f8254ba139581d6e622c6b35f
2024-02-21 16:22:24 +01:00
Oliver Smith
0917ce4e22 kernel-gtp: support IPv6 on outer layer
Related: OS#1953, OS#6096
Change-Id: I257fff1dcd9d030a7f9ea936b2693a3f13208230
2024-02-21 16:22:21 +01:00
Oliver Smith
2a0d37cb1d gtp_new: deduplicate create_and_bind_socket code
Change-Id: Iff3cfdfb0c08033d869c51499754b3416c71732b
2024-02-21 13:06:04 +01:00
Oliver Smith
f3d541e353 Fix a typo
Change-Id: I508274a1a466651025c488ad897aeed739e4b799
2024-02-21 13:05:56 +01:00
Pau Espin Pedrol
8d976444b8 pco: Improve IPCP spec reference documentation
Change-Id: I1dd4a41bae491c61197e8e307efcfc8c63945a71
2024-01-26 16:12:08 +01:00
Daniel Willmann
77734ac81b libgtp: Remove defines for reserved causes in gtp.h
As discussed in Gerrit change I9c3bf64537ef2223e29f8082861fa32fde26bf68
remove defines that don't serve any purpose. These are defines for
reserved values and changing them later if a newer spec defined them
would break API.

Keep the comments to explain the missing values.

Change-Id: I8db0aa0ade59785443a407b51dea326144406dcf
2023-11-29 16:40:49 +01:00
Oliver Smith
848ec697e2 Bump version: 1.10.2.1-a625 → 1.11.0
Change-Id: I1f116e1cded135f231f22ebc9b817aebf3736fc2
2023-11-28 13:07:17 +00:00
Daniel Willmann
6a2e82542d libgtp: Use gtp_cause_successful() instead of GTPCAUSE_ACC_REQ
In some cases the phone requests a PDP context type that isn't available
no the PGW/GGSN, e.g. phone requests a combined IPv4/v6 context, but
only IPv4 is supported.

In that case the GGSN can send a Create PDP Context Response with cause
"New PDP type due to network preference" or "New PDP type due to single
address bearer only". libgtp should continue handling these cause values
like the "Request Accepted" cause. Use the new gtp_cause_successful()
function for that.

Related: OS#6268
Change-Id: I7dd1e0aa185530e1e2d0402742df833c61a787a7
2023-11-24 09:48:22 +01:00
Daniel Willmann
a625bdd136 gtp: Add net GTP cause values and a function to check for success
According to the spec the upf/pgw can accept a modified pdp context from
the request e.g. if an ipv4/6 context was requested, but only ipv4 is
availiable. Introduce a function that checks all cause values that are
considered successful.

See also: 3GPP TS 29.060 Ch 7.3.2

Related: OS#6268
Change-Id: I9c3bf64537ef2223e29f8082861fa32fde26bf68
2023-11-22 12:36:49 +01:00
Pau Espin Pedrol
08bb5182a4 Bump version: 1.10.1.8-4963-dirty → 1.10.2
Change-Id: I148375902975aba0a374e4507c97f1ff67d687bc
2023-09-12 14:36:11 +02:00
Oliver Smith
4963d1c2ea lib/in46_addr: add in46a_from_gsna
Prepare to use it in gtp-kernel.c in a future patch.

Related: OS#6096
Change-Id: I3e76eb7ee89ba338f085c617662d15cffa2a62d5
2023-07-24 15:06:03 +02:00
Oliver Smith
37daa5d003 doc: running: update kernel-gtp limitations
Related: OS#6096
Change-Id: Ie4f1452ecefbe0db0e4093caa8177f1c87bd3950
2023-07-21 12:59:41 +02:00
Oliver Smith
c4c4d90b85 README: update documentation section
Change-Id: I3320dc5eb3d183a18c2bd2fe3139f729978ea2a1
2023-07-21 11:19:14 +02:00
Oliver Smith
59f1539ece systemd: depend on networking-online.target
Related: SYS#6400
Change-Id: I29e547242b2ed1cfc4750c7d7e5f8636c2e8f3dc
2023-05-26 14:10:45 +02:00
Oliver Smith
eff88c08e7 debian: set compat level to 10
Related: OS#5958
Change-Id: I4b2988fffba12cc84ff0834bb9ef0f3d9de2bcda
2023-04-25 16:48:22 +02:00
Oliver Smith
92ac7249f9 doc/manuals/chapters/configuration: fix typo
Change-Id: I0e9d2c77200c7c8b49aec669bc39ca91d5d4cf1f
2023-04-11 17:18:34 +02:00
Vadim Yanitskiy
5cf6b75dc9 tests: use -no-install libtool flag to avoid ./lt-* scripts
This option should be used for any executables which are used only
for testing, or for generating other files and are consequently never
installed.  By specifying this option, we are telling Libtool that
the executable it links will only ever be executed from where it is
built in the build tree.  Libtool is usually able to considerably
speed up the link process for such executables.

Change-Id: I2ca675e93dc5b34bb08d3b841adc115e93558137
2023-03-11 04:36:59 +07:00
Vadim Yanitskiy
4aa2e417c9 Do not hard-code -g and -O2 in CFLAGS
Let the user decide on the optimization level and debugging info.

Change-Id: I4b0b523b7dac4d67413bda37b546964262e5ea0d
2023-03-09 17:17:03 +07:00
Vadim Yanitskiy
f14c056310 Bump version: 1.10.0.4-bf69 → 1.10.1
Change-Id: Ibde9f259bccce29638d35efbd597669f5584e295
2023-02-27 22:35:47 +07:00
Vadim Yanitskiy
bf69ddbfef gtp: use OSMO_ASSERT() in gtp_new()
When using built-in static_assert() [1], gcc v12.2.1 fails:

In file included from gsn.c:27:
gsn.c: In function 'gtp_new':
gsn.c:444:54: error: expression in static assertion is not constant
  444 |         osmo_static_assert(gtp_T_defs[0].default_val != 0, first_default_val_not_zero);
      |                                                      ^

The reason is likely that gtp_T_defs[] is not const, so it cannot
be assert()ed statically.  With the current osmo_static_assert()
implementation, this assert does nothing.  One can change the
gtp_T_defs[0].default_val to 0 and the code will still compile.

Change-Id: Ia8af1736b63d501661046fe70befe5bbabc1045a
Related: [1] libosmocore.git I5ca34bc14c05e8c38c721d7df33feb1c6c41c76e
2023-02-27 17:07:26 +07:00
Vadim Yanitskiy
70a4e2e6f8 gtp/gsn.c: fix 'No newline at end of file'
git complains if it's missing, vim adds it automatically.

Change-Id: I3b4808a76da89e65b934d818e7ca280bc0651483
2023-02-27 17:07:26 +07:00
Vadim Yanitskiy
99afe979ef lib/icmpv6.h: fix struct icmpv6_{radv_hdr,opt_prefix}
Fix wrong field order in the big-endian variants.

Change-Id: Ifaa63bb5496e056805bd13b964c8b430fb11c24c
2023-02-27 17:07:05 +07:00
Oliver Smith
35066fb0b0 debian/libgtp6.shlibs: new file
List the most recent library version where new symbols where added, so
debian properly upgrades libgtp6 when upgrading osmo-sgsn from the
version that is currently in Debian to a version from the Osmocom
repositories.

Closes: OS#5318
Change-Id: Ida5dae4655c0acaeb377bc9d556a2ac333bca10a
2023-02-08 18:11:54 +01:00
Pau Espin Pedrol
55fe62f634 Bump version: 1.9.0.10-4fac-dirty → 1.10.0
Change-Id: I553fb72c577181c32005093eaf4fa986ae0e6ca8
2023-02-07 14:29:49 +01:00
Pau Espin Pedrol
4fac842826 Fix typos in comments and VTY descriptions
Change-Id: I359425152dc18d29c57047f1b10942480b7a61e5
2023-01-17 14:17:18 +01:00
arehbein
97f60e3dca osmo-ggsn: Transition to use of 'telnet_init_default'
Related: OS#5809
Change-Id: I51b7c175192759e26d1791723540841e72879b02
2022-12-23 11:13:31 +00:00
Max
a727e6ed38 ctrl: take both address and port from vty config
Change-Id: Ib31d67591657e308eebd1e6b7e23f79e6a3656e9
2022-12-17 21:14:57 +03:00
Pau Espin Pedrol
3a55b89777 gtp: Introduce VTY configurable GTP timer X3
This timer controls the amount of time a resp message transmitted by the
local gsn is to be stored in the resp queue. This is used in order to
detect duplicate requests received, since GTP states the exact same
response should be answered if a duplicate request is received.

Prior to this patch, this timer was hardcoded to 60 seconds.
This patch actually should be set, in general, to a value
equal than (T3-RESPONSE * N3-REQUESTS) values configured at
the peer, since that is the maximum period during which the local gsn
expects to receive req retransmissions from the peer.
Hence, this value must be user configurable to adapt it to the peers
connected to the GSN.

The 60 seconds hardcoded value is therefore changed to default to our
local (T3-RESPONSE * N3-REQUESTS), since the most common scenario for
osmo-ggsn/osmo-sgsn is to run it against a peer osmo-sgsn/osmo-ggsn,
which will have the same values by default.
This way we avoid by default caching response messages for way too long,
potentially filling the queue.

Related: OS#5485
Change-Id: Ia15c1cfd201d7c43e9a1d6ceb6725ddf392d2c65
2022-11-04 11:21:25 +01:00
Pau Espin Pedrol
9f1f747d8e ggsn: Introduce tdef and make it configurable over VTY
Related: OS#5485
Change-Id: I10bc8e2e197c0e8753b23b684b5ae41025672bf7
2022-11-02 20:33:39 +01:00
Pau Espin Pedrol
b9036af7ca Use rate_ctr for gsn_t available_counters
This way they can be inspected with regular osmocom means.

Change-Id: I529305b4f824600c6e733a3c0d2c2c6673f99faf
2022-11-02 18:41:38 +01:00
Pau Espin Pedrol
724ecc6680 Split gsn_t related APIs out of gtp.{c,h}
This way we split the gsn_t object API/logic from the protocol (message
handling) code.

Change-Id: I47cebb51bf08b9fcf7f115fc8dbea5f3493d4388
2022-11-02 18:41:34 +01:00
Pau Espin Pedrol
0d3bd3435f cosmetic: gtp: Fix typo in comment
Change-Id: I54b80bba3126cb3ae534938e253721961d4e08c4
2022-11-02 13:22:17 +01:00
Max
3ed252b58e Ignore .deb build byproducts
Change-Id: Iec63ef5ea0acfc5e6621054926be15ae4754d65d
2022-08-30 19:24:48 +07:00
Max
ac802e63d7 Set working directory in systemd service file
By default systemd will execute service with root directory (or home directory for user instance) which might result in
attempts to create files in unexpected place. Let's set it to 'osmocom' subdir of state directory (/var/lib for system
instance) instead.

Related: OS#4821
Change-Id: Idffc115c21cac77f6f43356333de538ba549fc6a
2022-08-30 19:24:48 +07:00
Pau Espin Pedrol
bc583d9763 Bump version: 1.8.0.13-ade4-dirty → 1.9.0
Change-Id: Id61cbe354437233fc6baf187ea90284da6a6944b
2022-06-28 17:48:22 +02:00
Harald Welte
ade4dc191b update git URLs (git -> https; gitea)
Change-Id: I9d59b62493bcdcb1bdbfbfd0525bae2988359f27
2022-06-18 12:04:24 +02:00
Vadim Yanitskiy
cd05da79e7 tests: use 'check_PROGRAMS' instead of 'noinst_PROGRAMS'
When using 'check_PROGRAMS', autoconf/automake generates smarter
Makefiles, so that the test programs are not being compiled during
the normal 'make all', but only during 'make check'.

Change-Id: Ia8b8dade0056c51d2dd1d814a89d1de064597344
2022-04-13 19:55:33 +03:00
Pau Espin Pedrol
5545bcea5d pco.h: Fix typo in reference to spec
Change-Id: Ic428892161123b62d25a7619128ef7325bf85500
2022-03-24 12:51:17 +01:00
Pau Espin Pedrol
c97286f839 gtp: Fix typo in comment
Change-Id: I0e38e0966081d8b37c3f816f5330b4f52f81b7fa
2022-03-07 16:22:53 +01:00
Pau Espin Pedrol
f471800168 gtp: Log retrans queue register&free entries
Change-Id: I4e12376652fc7a6a96fbdcb579dbe916c1473012
2022-03-07 16:22:53 +01:00
Pau Espin Pedrol
bdf0697a5a gtp: Specify retrans queue name & seqnum in log lines
Change-Id: I4f193d7a482ace33afd8526b5f50d2d03467d5fa
2022-03-07 12:55:07 +01:00
Pau Espin Pedrol
674a912fb5 gtp: Small log improvements in gtp_create_pdp_ind()
Drop unneeded log line, rewrite line to better fit code path.

Change-Id: Id254e04d539cc055fee8c16fb66cd897b041557e
2022-03-07 12:44:15 +01:00
Pau Espin Pedrol
1bf3b3d0f9 gtp: Log detection of rx duplicate
Change-Id: I8bc9143db6743ad4fae2fe6d6fe0417648e9eec9
2022-03-07 12:20:13 +01:00
Pau Espin Pedrol
fb9303c610 gtp: Use switch statement in gtp_create_pdp_ind()
Double if had to be changed to if-else anyway, so let's simply use a
switch statement.

Change-Id: I91e8722947e58776742521d89abef8ae7584cb25
2022-03-07 11:34:30 +01:00
Pau Espin Pedrol
0585769741 libgtp: Define retransmit QUEUE_SIZE relative to PDP_MAX (increase)
QUEUE_SIZE holds the number of pending transmitted messages
which can be handled concurrently.
Current value was 1024, same as PDP contexts (PDP_MAX). However, that
seems to be a quite low amount, which can be filled under certain
conditions, for instance if recovery procedure is triggered on the GSN
which is running full (around PDP_MAX pdp contexts created).
In this scenario, the GSN would need to send around PDP_MAX concurrent
messages (DeletePDPContextReq), which means the queue would very likely
end up being full.
Hence, let's define QUEUE_SIZE based on PDP_MAX, and set it to twice the
size to make sure it won't be filled in extreme conditions.

Change-Id: I6034b0fab2b2e5962314c2fca2f893246ce5cf4f
2022-03-01 12:39:08 +01:00
Pau Espin Pedrol
9b288b788e libgtp: Fix ggsn crash if pdp alloc array is full (PDP_MAX)
osmo-ggsn crashes when concurrent pdp context num 1024 is created, due to
the gsn->pdpa array (of size PDP_MAX, 1024) being full.
The crash happens because return code of gtp_pdp_newpdp was not checked,
and hence a pointer "pdp" pointing to a temporary not-fully-allocated
object was being passed to gsn->cb_create_context_ind() callback.

Let's avoid crashing and instead reject the PDP context.

Related: OS#5469
Change-Id: I0d94ffad97eb4fef477d981bf285bf99740592a3
2022-03-01 12:38:58 +01:00
Pau Espin Pedrol
134ac7e7c8 vty: Fix cmd 'no echo-interval' doing nothing
It was incorrectly implemented and in practice was a NOOP.

Change-Id: I5e03c4965d05871d3f2e56675da6e75af0ec18c2
2022-02-25 17:25:00 +01:00
Pau Espin Pedrol
46f04343a5 tests: in46a_test: Make coverity happy when calling in46a_from_eua
Coverity warns around that test code:
"Overrunning struct type in46_addr of 20 bytes by passing it to a
function which accesses it at byte offset 39."

That's basically because in64a_from_eua expects to be passed a 2 element
array to be filled. The second element, though, is only accessed in the
case where an IPv4v6 EUA is passed, so in the cases where the test
explicitly passes an IPv4 or IPv6 EUA it's not really an issue, hence
coverity throwing a false positive here.
Let's anyway rewrite the code to pass a 2 element array for completeness,
since it doesn't hurt and makes coverity happy.

Related: Coverity CID#249006
Change-Id: Idfc9104f48eeee6e7f11ebc5c17d4b0e4b2fe9e2
2022-02-09 09:41:46 +01:00
Pau Espin Pedrol
a3ca2d185b Bump version: 1.7.1.20-8cbd-dirty → 1.8.0
Change-Id: I21502c6e0b804237fe9bd8f5579dbabd519d6d51
2021-11-16 13:49:16 +01:00
Pau Espin Pedrol
8cbdd21867 gtp_echo_responder: report invalid chars present in node-feautres cmdline arg as error
from "man strtoul":
"""
If endptr is not NULL, strtoul() stores the address of the first invalid character in *endptr.
In particular, if *nptr is not '\0' but **endptr is '\0' on return, the entire string is valid.
"""

Fixes: ae81195418
Change-Id: I89d26a575ef81ee17483db035924354588d9d094
2021-10-08 17:28:16 +02:00
Pau Espin Pedrol
ae81195418 Introduce program gtp-echo-responder
This is a small standalone program (under MIT license, hence cannot make
use of libosmocore) whose only purpose is to answer GTPC (v1 and v2)
Echo Request messages with Echo Reply ones, with information provided
from the command line.

A small python script companion is provided to easily test the program.

Related: SYS#5598
Change-Id: Ibdd6d8f6920571db0c60cf8b3b25d541b15ad3f1
2021-10-04 14:06:51 +02:00
Pau Espin Pedrol
6ee5fa939a cosmetic: configure.ac: Fix tabulation in line
Change-Id: I5cfc90ace5f9cc9c3fe4dde7aeccbdf1909da007
2021-09-23 13:35:13 +02:00
Pau Espin Pedrol
b6a0e3fd2e ggsn: Fix heap-use-after-free during Recovery without associated PDP
Related: OS#4641
Change-Id: Ib4dca2e30e723a196084b0fa0040fbceca835359
2021-06-10 19:41:00 +02:00
Pau Espin Pedrol
bd2b55679e ggsn: Log tun fd write errors
Change-Id: I5f681b5edcc4cf525629d2078ae0c0ffd7ebb72d
2021-06-01 12:00:21 +02:00
Pau Espin Pedrol
f32c6a9095 gtp: Support tx/rx RAN Information Relay message
See 3GPP TS 29.060 sec 7.5.14.1 RAN Information Relay.

Related: SYS#5314
Change-Id: Iea3eb032ccd4aed5187baca7f7719349d76039d4
2021-05-06 18:57:12 +02:00
Pau Espin Pedrol
2eed6ec5ec gtp: constify pointer arg
Change-Id: Ib5b5a8b64247202a2538c2ff8f8601981ccda822
2021-05-05 17:51:34 +02:00
Pau Espin Pedrol
641206ad5e cosmetic: gtpie.c: Fix trailing whitespace
Change-Id: I552e3b5f694e1b49fe5e21fa4023e4a24ffc2784
2021-05-03 17:24:30 +02:00
Pau Espin Pedrol
bfd3119ae4 gtp: Improve logging of failing pdp ctx resolution from TEI/TID
Change-Id: I4f2084ec7e3a830e0224dd998ff0fe6654cc23bd
2021-04-22 16:24:55 +02:00
Pau Espin Pedrol
4b9b19e998 ggsn: Improve logging on incoming DL data packets
Change-Id: I3617c8f68d8f18617871c070e28cc6ae5c6a925b
2021-04-22 16:24:55 +02:00
Pau Espin Pedrol
00e0559e17 gtp: Rework parsing logic of UpdatePdpCtxResponse
The previous order of parsing lead to non-optimal information gathering
when pushing events to upper layers.

This patch rearranges parsing of packet data to always gather as much
info as possible for the benefit of the upper layer. This way it can
gather information such as the cause, which is important in the case of
"Non-existent", since user should then drop the context.

First we want to parse the recovery state, but delay cb to upper layers
until we tried to gather the pdp ctx (meaning all except that pdp ctx
should be freed).
Second, we want to parse the cause, in order to know if there's an
associated pdp ctx we can gather from TEID.
Third, once we know if we should expect a meaningul TEID, parse it.

Related: SYS#5435
Change-Id: Idd10b494e8fbac8703c49ecd8f9bbe4246e51c57
2021-04-22 16:24:48 +02:00
Pau Espin Pedrol
0b1d9dbc40 gtp: Update teic_confirmed only on resp success
Change-Id: I54c54cbb51bfa5d1520855f448fa27511037b396
2021-04-21 19:45:23 +02:00
Harald Welte
5379273ea3 vty: Inform user that static IP addresses are not supported
Currently, osmo-ggsn doesn't implement PDP contexts with static IP
addresses.  The code for specifying ranges that can be used for
static IPs was always present even from OpenGGSN days, but we never
really treated them.  Let's not raise the impression we do by
warning accordingly if the user configures them.

Change-Id: I7787dae037c46c0c5052aa6dd000be330984f144
Related: OS#5097
2021-03-27 19:03:30 +01:00
Harald Welte
ecef920b8f ggsn: Reject PDP CTX ACT for static IP addresses
We don't implement handling of static IP addresses for now,
let's properly reject those rather than allocating a dynamic address
anyway.

Change-Id: Iac8868438655fe4e5e07d167d7dbd6273dbb7678
Related: OS#5097
2021-03-27 19:00:34 +01:00
Harald Welte
eb9267b15e Don't install sgsnemu.conf to /etc/osmocom/
This is an auxiliary example config file, which should not be installed
to /etc/ and hence not be in OSMOCONF_FILES

This fixes the following rpm packaging error:
[  149s] error: Installed (but unpackaged) file(s) found:
[  149s]    /etc/osmocom/sgsnemu.conf

Change-Id: Id31f6542590405531ff61a9434041c15e779865b
Fixes: Icd6f3efcf5a9ef50237a3d0a76d4cce55051f447
2021-03-03 08:10:56 +01:00
Harald Welte
1efb2bcd90 Don't install osmo-ggsn-kernel-gtp.cfg to /etc/osmocom/
This is an auxiliary example config file, which should not be installed
to /etc/ and hence not be in OSMOCONF_FILES

This fixes the following rpm packaging error:
[  149s] error: Installed (but unpackaged) file(s) found:
[  149s]    /etc/osmocom/osmo-ggsn-kernel-gtp.cfg

Change-Id: If118ed26491a1edda83eda7f95479e165ca4c150
Fixes: I6fbe8a8e55bad41532e9aed3cf71ebebffdcee52
2021-03-03 08:10:23 +01:00
Oliver Smith
878593f205 gitignore: add ggsn_vty_reference.xml
Change-Id: I39bd36e4bde457b7c7a62ca6aa6d5dadea4051fc
2021-03-02 09:03:20 +01:00
Oliver Smith
1596463985 doc/manuals: describe GTP-U kernel module
Related: OS#3209
Change-Id: Ib45cbfe03077960f216a83cf500ab3203d02cb3b
2021-03-02 09:03:09 +01:00
Oliver Smith
9d82492e49 doc/examples/osmo-ggsn-kernel-gtp.cfg: new file
Add a copy of osmo-ggsn.cfg, with gtpu-mode set to kernel-gtp and apn
inet6 and inet46 removed (as the kernel module only supports ipv4).

Related: OS#3209
Change-Id: I6fbe8a8e55bad41532e9aed3cf71ebebffdcee52
2021-03-01 15:37:39 +01:00
Oliver Smith
303aeea8a8 doc/examples/Makefile.am: add sgsnemu.conf
Related: OS#3209
Change-Id: Icd6f3efcf5a9ef50237a3d0a76d4cce55051f447
2021-03-01 15:03:10 +01:00
Pau Espin Pedrol
18898b4a9f Bump version: 1.7.0.2-17ce → 1.7.1
Change-Id: Ideca49e0762eb20799375a33a04469673dfeb168
2021-02-23 17:31:24 +01:00
Harald Welte
17cee2056c manuals: generate vty reference xml at build time
Remove ggsn_vty_reference from the source tree.

In manuals/Makefile.am use the new BUILT_REFERENCE_XML feature recently added
to osmo-gsm-manuals, and add a build target to generate the XML using the new
osmo-ggsn --vty-ref-xml cmdline switch.

Change-Id: I772293cc78a6c95e07565a7048c1c8dadf87d2fc
Depends: I613d692328050a036d05b49a436ab495fc2087ba
Related: OS#5041
2021-02-23 17:08:14 +01:00
Harald Welte
67a3c833af main: add --vty-ref-mode, use vty_dump_xml_ref_mode()
Change-Id: I966715ab2a430497bbccf26c50aef72d0901997f
Depends: Ie2022a7f9e167e5ceacf15350c037dd43768ff40
Related: OS#5041
2021-02-23 17:08:06 +01:00
Pau Espin Pedrol
b1f641b5b7 Bump version: 1.6.0.22-f01c-dirty → 1.7.0
Change-Id: I05d9bee0791cec5aebbeb1602be6697ecc2e2b74
2021-02-23 13:34:40 +01:00
Harald Welte
f01ce65f5b gtp-kernel: don't #include libmnl headers
* we don't check for libmnl via pkg-config in configure.ac
* we don't add libmnl include path to CFLAGS

As a result, we cannot #include related files.

libmnl is completely encapsulated by libgtpnl.  It even
includes a forward-declaration of 'struct mnl_socket'.

Change-Id: I0af869cc3c8e30b69d73a4985c56ef7743565e95
2021-02-20 11:28:59 +01:00
Harald Welte
be1cf99e9a gtp-kernel: Remove duplicate #include section
This was probably a wrong patch merge at some point.

Change-Id: I54191aca8fd55de84d86591035fe9785d379205f
2021-02-20 11:05:53 +01:00
Oliver Smith
7710080ffd deb/rpm: build with --enable-gtp-linux
Allow optional use of the GTP kernel module.

Related: OS#3208
Change-Id: Ic001ec6c5ec9887706a5b27f2a48cd61942ab4ee
2021-02-19 18:28:04 +01:00
Oliver Smith
798a81d48d .gitignore: ignore debian/libgtp*
Change-Id: I41fa611917defeab13f01a59dcc3f95961f10bda
2021-02-19 18:25:58 +01:00
Pau Espin Pedrol
51930f7b63 tests: Replace deprecated API log_set_print_filename
Change-Id: I35eb879d82e1030ea8be56ce9039277c021bb6fa
2021-02-19 13:23:00 +01:00
Pau Espin Pedrol
00ef1b0d6e tests: Explicitly drop category from log
Let's disable category here since we don't care about its formatting here.

In any case, every test relying on logging output validation should
always explicitly state the config to avoid issues in the future if
default values change.

Change-Id: Icce09882ef3ed07328679594ff84902383d16c72
Related: OS#5034
2021-02-19 13:22:28 +01:00
Oliver Smith
02a82c3c9b apn_start: avoid segfault if missing tun-device
Check if tun-device is defined and give the user a hint that it is
missing instead of segfaulting with gtpu-mode kernel-gtp:
  20210205141701206 DGGSN <0002> ggsn.c:186 APN(internet): Starting
  20210205141701206 DGGSN <0002> ggsn.c:204 APN(internet): Opening Kernel GTP device (null)
  Segmentation fault

With gtpu-mode tun it didn't segfault, but still tried to open the NULL
device:
  20210205141557598 DGGSN <0002> ggsn.c:186 APN(internet): Starting
  20210205141557599 DGGSN <0002> ggsn.c:189 APN(internet): Opening TUN device (null)
  20210205141557599 DTUN <0001> tun.c:195 errno=1/Operation not permitted ioctl() failed

Related: OS#3208
Change-Id: I9f71af65cc0eed71728c04b774e5c08352947913
2021-02-05 16:37:02 +01:00
Oliver Smith
349cbfcf50 configure.ac: set -std=gnu11
Change-Id: I7fed7d43242f804e6d2b005277c5b2b1bd197aa8
2021-01-28 09:28:56 +00:00
Oliver Smith
51f99ae250 contrib/jenkins: don't build osmo-gsm-manuals
Related: OS#4912
Change-Id: Ie77a81d3bd7cdb739fa082d9e1b5ddeba433a9db
2021-01-13 13:05:20 +01:00
Pau Espin Pedrol
12304c0e5a ggsn: generate coredump and exit upon SIGABRT received
Previous code relied on abort() switching sigaction to SIG_FDL +
retriggering SIGABRT in case the signal handler returns, which would
then generate the coredump + terminate the process.
However, if a SIGABRT is received from somewhere else (kill -SIGABRT),
then the process would print the talloc report and continue running,
which is not desired.

Change-Id: I7acfdfe5020320d853cba98b5add7479f8aaaf39
Fixes: OS#4865
2020-11-25 18:49:16 +01:00
Harald Welte
1719abb409 Use OSMO_FD_* instead of deprecated BSC_FD_*
Change-Id: Ib660cbbeafd8f4077c693d53127ecd1c15455455
2020-10-18 22:38:20 +02:00
Pau Espin Pedrol
3ddf4c6933 contrib/jenkins: Enable parallel make in make distcheck
Change-Id: Id7d4e6682be1d4f77979e896089b42f35548ca98
Related: OS#4421
2020-10-12 19:32:31 +02:00
Keith
fb2a7298e0 GTP: Replace recently introduced imsi_str2gtp()
Replace with the version from osmo-sgsn, renamed so
as not to collide with that version.

Change-Id: I910d5339a823332277ce7b5854d5c943ed69ea81
2020-10-12 15:47:26 +02:00
Keith
568ac5ee8e sgsnemu: relax check on length of IMSI cmdline arg.
Change-Id: I0374ff8773ae528c916fbee5f3f1efd89a5d2a08
2020-10-12 13:17:49 +02:00
Keith
23c832bb4b Use imsi_str2gtp() in sgsnemu
Change-Id: I94168c84dd613cfe51715e247b0d8b57308017d0
2020-10-12 13:11:26 +02:00
Keith
4831851ca3 Minor: remove code duplication
Change-Id: Id18ebcd3b3c20ce28e383edf9354e9f8516e1e81
2020-10-12 13:11:26 +02:00
Keith
080dcfaabe Prevent Crash in show pdp-context from vty
Fix test for return value from gtp_pdp_getimsi() so
we do not call show_one_pdp() with an uninitialised pdp_t

Change-Id: Ic40429939b185f97c020dd3904e054fe860b91e8
2020-10-12 13:11:25 +02:00
Keith
cbc07bdd82 Fix vty PDP lookups by IMSI
The PDP context is searched on the hash which is generated
on context creation from the IMSI in gtp format. - A hash
created from "human-readable" IMSI does not match.
Check user input for length then convert the IMSI to gtp format
before continuing.

Change-Id: Icd2e2bc6068c06fbf5d5fe905ebcda8954f33f04
2020-10-12 13:11:19 +02:00
Pau Espin Pedrol
aedae4c971 Support setting rt-prio and cpu-affinity mask through VTY
Change-Id: Ic8d38a5f64c661ce650004c68d73bd77149caef4
Depends: libosmocore.git Change-Id If76a4bd2cc7b3c7adf5d84790a944d78be70e10a
Depends: osmo-gsm-masnuals.git Change-Id Icd75769ef630c3fa985fc5e2154d5521689cdd3c
Related: SYS#4986
2020-08-18 12:52:56 +02:00
Pau Espin Pedrol
b36eb9d12f doc: Update VTY reference xml file
Change-Id: I2e8bebb67e63000c6f571a23baec04a68fc2974e
2020-08-18 12:47:39 +02:00
Pau Espin Pedrol
8df01fad14 configure.ac: Fix trailing whitespace
Change-Id: Ia7b0ff11e58375842be15823d6b5dcaafc0f1f82
2020-08-18 12:47:26 +02:00
Vadim Yanitskiy
c8020b959d debian/control: change maintainer to the Osmocom team / mailing list
Change-Id: Ia93dd2bf84ebb2c4d11917021888d4c6a5085d50
2020-08-13 15:00:43 +00:00
Harald Welte
2154607fb0 Bump version: 1.5.0.37-d08a → 1.6.0
Change-Id: I2248595ca11f4d808d38a9e25e7c3d3b64134427
2020-08-13 12:26:20 +02:00
Pau Espin Pedrol
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 Pedrol
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 Pedrol
962146085c sgsnemu: Implement ping on IPv6 APNs
Related: OS#4434
Change-Id: If9ca7c37a1a397bbc3f8912d67bccdabc4968e0c
2020-04-21 16:40:39 +02:00
Pau Espin Pedrol
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 Pedrol
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 Pedrol
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 Pedrol
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 Pedrol
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 Pedrol
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 Pedrol
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 Pedrol
ee1529e5ac icmpv6.c: Mark internal function as static
Change-Id: Ib38907c3a05c1651faa86ef57381ee22643e0d53
2020-04-15 16:40:10 +02:00
Pau Espin Pedrol
29e7bd0510 cosmetic: icmpv6.c: fix typo in comment
Change-Id: I2217dfb0b0a1e6e029ac817902e80c771ed219c3
2020-04-15 16:39:51 +02:00
Pau Espin Pedrol
cdcaeda81c sgsnemu: Fix ping transmitted statistics output
Change-Id: I6e23e024ee30d6049c6b8b614c50d062d80a5260
2020-04-15 16:39:28 +02:00
Pau Espin Pedrol
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 Pedrol
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 Pedrol
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 Pedrol
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 Pedrol
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 Pedrol
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
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 Pedrol
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 Pedrol
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 Pedrol
b283c32027 cosmetic: Fix comment typo
Change-Id: I8240b388ffb8c1806bf0d34a9e59146b403a13be
2020-02-25 14:13:09 +01:00
Pau Espin Pedrol
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 Pedrol
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 Pedrol
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 Pedrol
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 Pedrol
4e605b32d4 cosmetic: gtp: Improve documentation of gtp_delete_context_req2()
Change-Id: I1f85c7cc7684e146fca4f17914927d45410dbb84
2019-08-29 14:07:04 +02:00
Pau Espin Pedrol
494d873fe3 cosmetic: gtp: Drop commented out code calling pdp_freepdp()
That code was commented out in 0b076a331e
(year 2003), and indeed it makes no sense to call those in current pdp
lifecycle (they are expected to be freed by the application).

Change-Id: I096d8cb8d749ff9b737d6f3f96b1d423660ece37
2019-08-29 14:07:00 +02:00
Pau Espin Pedrol
b4c98e7397 gtp: Log msg retransmits and timeouts
Change-Id: Ie768ddb45313582b4b5358b97a981080be64fd42
2019-08-28 18:47:58 +02:00
Pau Espin Pedrol
3eb05d2c1a cosmetic: fix formatting in if line
Fixes: eefa30dce8
Fixes: 2d6a69e69a
Change-Id: I9ee5f4142cacf912145693c72a53c0f531bad2c6
2019-08-28 11:34:51 +02:00
Pau Espin Pedrol
f5fbb419ef ggsn: Implement echo req/resp and recovery
This patch is quite big because implementing echo req/resp and recovery
requires having knowledge and managing differentiated state for each GSN
peer attached/connected to osmo-ggsn. This kind of information was not
available in osmo-ggsn nor in libgtp.

So osmo-ggsn is now able to track GSN peers connected to a
ggsn_ctx (associated gsn_t from libgtp) by means of "sgsn_peer" data
structure, and accessible from the ggsn through a list. The instances of
sgsn_peer are currently allocated and destroyed dynamically based on
discovered peer who have at least a pdp context attached to us (we are
not interested in peers without pdp contexts because we don't need to
send echo requests/responses and maintain state in that case).

A new private pointer (pdp_t->priv) data structure struct pdp_priv_t is
added to be able to relate a pdp_t to an sgsn as well as the already
existing pointer to an apn.

An "echo-interval <0-36000>" VTY command is added which allows
configuring time wait between echo requests being sent to each
sgsn_peer. Transmission of echo requests is disabled by default.

Finally, a new "show sgsn" VTY command is introduced, and its output is
also printed during "show ggsn".

Related: OS#4165
Change-Id: Id2c84165dc59dff495106758146a701ca488834f
2019-08-28 11:34:11 +02:00
Pau Espin Pedrol
5d8b226597 libgtp: Introduce cb_recovery3
Since osmo-ggsn can manage several GSN structures simultaneously, it
needs the gsn_t pointer to know the ggsn it should forward the call to.

Related: OS#4165
Change-Id: I33b4fe594d5833993af01cce34737e61e597b320
2019-08-28 11:24:08 +02:00
Pau Espin Pedrol
c602d7cf00 doc: Update vty reference xml file
Change-Id: I49e7db4d0f5c7868b86a4947d8b5739c2068da46
2019-08-28 11:21:23 +02:00
Pau Espin Pedrol
a019631c0b ggsn_vty.c: Improve output of VTY show pdp-context
GTP version and primary/secondary information is printed now for each
pdp context.

Related: OS#4154
Change-Id: If9682fe343e9a1e78175a12538fb80d4bda54802
2019-08-28 11:20:32 +02:00
Pau Espin Pedrol
88ce94c2bd pdp: constify param in pdp_count_secondary()
Change-Id: Ie772f2c54264c8bc91f50d9030479861dd8868b7
2019-08-28 11:14:57 +02:00
Pau Espin Pedrol
310ea1db10 ggsn_vty.c: Avoid printing duplicates for pdp context with v4v6 EUAs
Fixes potential duplicates when calling following VTY cmd:
show pdp-context ggsn NAME
show pdp-context ggsn NAME apn APN

Related: OS#4154
Change-Id: I98db39a710a72a1438d71aabaf4f8227984643e3
2019-08-28 11:14:57 +02:00
Pau Espin Pedrol
012d51ed7d Introduce LOGTUN log helper
Change-Id: I237acdee0be19498804e0d509c610f4e0454ba72
2019-08-28 11:14:57 +02:00
Pau Espin Pedrol
1ef2621d3f gtp-kernel.c: Fix wrong use of in46a_from_eua, print IPv6 euas
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-28 11:14:57 +02:00
Pau Espin Pedrol
f612ffea82 Move pdp_get_peer_ipv() to lib/util.*
Preparation for next commit, where this function will be needed inside
libmisc (lib/*).

Change-Id: Ibab4f6c09d1e5f0e9cfaea28ae1e7ab5b5c219b5
2019-08-28 11:14:57 +02:00
Pau Espin Pedrol
421f22e8cf ggsn: Split application lifecycle related code into ggsn_main.c
This way we further shrink ggsn.c and leave there GGSN related code.

Change-Id: I9e6a3beac7657f0a8c02d514b54c6f1caa93bba7
2019-08-28 11:14:57 +02:00
Pau Espin Pedrol
03cce86941 ggsn_vty.c: Fix wrong use of in46a_from_eua, print IPv6 euas
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.

Related OS#4154
Change-Id: Ia34939957bb7856388cb52a741cec0c015a08c70
2019-08-28 11:14:57 +02:00
Pau Espin Pedrol
95cd897c3f in46_addr: Improve in46a_ntop documentation
Change-Id: I27238c330f9b805ac9e734e735d2c7ae158fe524
2019-08-28 11:14:51 +02:00
Pau Espin Pedrol
f7884e880e ggsn: Move PCO handling code into its own file
This way ggsn.c is shrinked in size and get rid of a lot of code there,
which is of no interest unless the reader is interested in that really
specific part.

Change-Id: Ieaa7e71f17c7fd9377c76ef53362eab596d669a6
2019-08-28 11:13:46 +02:00
Pau Espin Pedrol
60ee0dbfa4 Introduce in46a_is_v{4,6}() helpers
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
2019-08-28 11:13:32 +02:00
Pau Espin Pedrol
d950134c53 libgtp: announce pdp ctx deletion upon CreatePdpCtx being rejected
The libgtp application  may have already allocated related resources
associated to the pdp context, so we need to signal its deletion in
order to let the application free the resources.

This should fix the duplication of pdp contexts seen in osmo-ggsn when
"show pdp-context" related VTY commands are used.
It was spotted due to some MS requesting a v4v6 context on a
v4-only APN, where first v4 address was allocated, and then upon v6
allocation create_context_ind() called
gtp_create_context_resp(GTPCAUSE_MISSING_APN) but the first address was
not freed. Upon receiving the callback, osmo-ggsn should now free the
related resources.

Related: OS#4154
Change-Id: I6c6215a4ce478afabc78ffaf5ffb0cf829e41226
2019-08-23 14:39:35 +02:00
Pau Espin Pedrol
623c5b36e9 libgtp: Remove packets in tx queue belonging pdp being freed
Doing so should avoid the crash seen in OS#3956, where a message is
received in osmo-sgsn gtp iface after having received a DeleteCtxAccept
message where pdp and associated cbp is freed. As a result, when new
confirmation arrives, it can still be matched against an old request and
be sent to upper layers providing an already freed cbp.

With this patch, since all queued messages belonging to that pdp are
dropped, confirmation won't find a match and be discarded in libgtp.

In order to be able to drop all req messages belonging to a pdp, a new list
is added to pdp_t and qmsg_t are added to that list when inserted into the per-gsn
req transmit queue. This way upon pdp free time it's simply a
matter of iterating over that list to remove all messages.

There's no need to do same for resp queue, and it'd be actually
counter-productive, because it wouldn't be possible to detect and
discard duplicates anymore after pdp ctx has been freed.

Related: OS#3956
Change-Id: Id86d0b241454d3ad49c64c28087fd2710fa2d17a
2019-08-23 14:38:56 +02:00
Jan Engelhardt
aab47afe58 build: switch AC_CANONICAL_TARGET for AC_CANONICAL_HOST
$target/$target_os is never used, so AC_CANONICAL_TARGET is useless.
$host is, so employ AC_CANONICAL_HOST.

Change-Id: I6dc505888b42cfb686043470d3a3548c24cbe1f7
2019-08-15 14:12:00 +02:00
Pau Espin Pedrol
67aebc9d1c Bump version: 1.3.0.50-ea1c-dirty → 1.4.0
Change-Id: I5ca7ada037a9b91c3b747cea6d83654d0b9afed3
2019-08-07 21:28:30 +02:00
Pau Espin Pedrol
ea1cb3fa33 Require libosmocore 1.1.0
Older commit made use of gsm48_decode_bcd_number2(), which is available
in libosmocore 1.1.0 onwards, but forgot to increase configure.ac
requirements.

Fixes: fb62504160
Change-Id: I89b37be55fc4ba22b90e9aab9a5989573df2ae38
2019-08-07 21:27:00 +02:00
Pau Espin Pedrol
0036a60c44 Remove undefined param passed to {logging,osmo_stats}_vty_add_cmds
Since March 15th 2017, libosmocore API logging_vty_add_cmds() had its
parameter removed (c65c5b4ea075ef6cef11fff9442ae0b15c1d6af7). However,
definition in C file doesn't contain "(void)", which means number of
parameters is undefined and thus compiler doesn't complain. Let's remove
parameters from all callers before enforcing "(void)" on it.
API osmo_stats_vty_add_cmds never had a param list but has seem problem
(no "void"), so some users decided to pass a parameter to it.

Change-Id: I0a89586ce683ad060212355b37470c349992ec49
Related: OS#4138
2019-08-05 17:47:55 +00:00
Pau Espin Pedrol
e47932976c sgsnemu: Fix unaligned pointer access during ip/icmp checksum
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-29 18:06:20 +02:00
Harald Welte
f1e01517bc sgsnemu: Fix format string argument count
Change-Id: I6bb8c3df53a585913d5e0351ecad2e6ae9f0b886
Closes: CID#178643
2019-07-21 12:36:27 +02:00
Oliver Smith
ad252e70aa contrib/jenkins.sh: run "make maintainer-clean"
Related: OS#3047
Change-Id: I0ad159a3973d28ac79ea7fb433401c72b247c2b0
2019-07-10 12:25:35 +02:00
Pau Espin Pedrol
08ca425bc2 configure.ac: some versions of linux/if.h require including sys/socket.h
Related: OS#3230
Change-Id: Iba869a75745cea01024fa3ce04917c02fa608a13
2019-07-01 12:14:13 +02:00
Pau Espin Pedrol
1eeb113c34 configure.ac: Use prefered AC_CONFIG_HEADERS over AM_CONFIG_HEADER
This macro is preferred by autofoo upstream. It was added around
automake 1.7, and offers backward compatibility with AM_CONFIG_HEADER.

Related: OS#3230
Change-Id: I88707d4895d9c231715d5252d2cfab589b42fe0c
2019-07-01 12:13:56 +02:00
Pau Espin Pedrol
d0ba664fec configure.ac: Use brackets in AC_INIT params
Change applied as a result of running "autoupdate".

Change-Id: I955b535737f0a0cbdf25377609cec8f3d8d3eb45
2019-07-01 12:13:56 +02:00
Pau Espin Pedrol
ec1d8c4004 configure.ac: Replace obosolete macro AC_CANONICAL_SYSTEM
$ autoconf -Wall
configure.ac:11: warning: The macro `AC_CANONICAL_SYSTEM' is obsolete.
configure.ac:11: You should run autoupdate.

autoupdate applied the change present in this commit.

Change-Id: Iee59e6e9a7670867d5bc55ba96f79130bc6982f6
2019-07-01 12:13:56 +02:00
Pau Espin Pedrol
36e12d4db8 ggsn: Use structures instead of raw arrays when parsing ipcp_hdr
We have a structure to handle that data type, so let's use it.

Change-Id: I991e53544b733df7773d66280ffa19a2a5123d97
2019-07-01 12:13:56 +02:00
Pau Espin Pedrol
2404c5b0b7 ggsn: Avoid unaligned mem access reading PCO proto id
Change-Id: I3d80833319869503691a52927892e6ac30744915
2019-07-01 12:13:56 +02:00
Harald Welte
32b76ee1af ggsn: More logging from PCO handling (e.g. in case of malconfiguration)
Change-Id: I38c2c4178ff4fd795f54638adec63166b1c0838e
2019-07-01 12:13:56 +02:00
Harald Welte
7bdc80de00 ggsn: Add minimalistic PAP support
Some modems are configured to use PAP as an additional authentication
mechanism beyond the GSM authentication that's part of GMM.  Let's
handle such PAP authentication requests by simply acknowledging them
all, without actually checking any credentials database.

This is the most sane thing we can do for now, without adding external
requirements / interfaces like radius servers or the like.

Closes: OS#3914
Change-Id: I81875f30f9f1497199253497f84718510747f731
2019-07-01 12:13:51 +02:00
Pau Espin Pedrol
83f5266f43 gtp: queue: Add unit test queue_test
Closes: OS#1740
Change-Id: Id09bc5e23aa7a4b864822bc92cc23a4b60db52c3
2019-06-21 11:57:50 +02:00
Pau Espin Pedrol
e725d87d13 gtp: queue.c: Document queue APIs
Change-Id: I8523a0d0508d7fb870a4a9119aa8eb4c3a4d6f17
2019-06-20 16:47:11 +00:00
Pau Espin Pedrol
8b90bce962 gtp: Add missing headers
Those headers are using types defined in other places (like sockaddr_in)
and don't explicitly include them, which makes future queue_test fail.

Change-Id: I65e12a067d89ef71be3719636b64f4d93ea73cc4
2019-06-20 17:08:13 +02:00
Pau Espin Pedrol
f0829ff34b cosmetic: gtp: queue: remove trailing whitespace
Change-Id: I20c83cd607ae8e1025fdc1a810c0d27bad80b178
2019-06-20 17:08:06 +02:00
Daniel Willmann
e589c6544c manuals: Add script to regenerate vty/counter documentation
Related: OS#1700
Change-Id: I2f51ff19d2a1d7bcfdf569309a79a6e91a848302
2019-06-19 11:33:38 +02:00
Pau Espin Pedrol
d1a2ddfee6 sgsnemu: Replace use of deprecated libgtp API pdp_newpdp with new one
Related: OS#2873
Change-Id: I9742b82c382ae2e63f8aff4c5c32e2450059082b
2019-06-04 17:46:15 +02:00
Pau Espin Pedrol
7b52f00192 ggsn: vty: Require ggsn param in <show pdp-context> cmd
Other similar commands already do it. This way we also get rid of
deprecated APIs, supporting search when more than one GSN is set up.

Related: OS#2873
Change-Id: I8357e20076348c8ded5e9f5b8e7252566b0fbfea
2019-06-04 17:45:36 +02:00
Pau Espin Pedrol
25ab381c0f ggsn_vty_reference.xml: Update from last code changes
Change-Id: I5de2e5223e4532bbbec77b928fbdecb57ef2bca7
2019-06-04 17:45:36 +02:00
Pau Espin Pedrol
9fbcb10568 gtp: Make use of new libgtp APIs with multi-gsn support
Drop use of deprecated APIs everywhere in libgtp and use the new ones instead.

Related: OS#2873
Change-Id: Ibf56a063f01d1f95a2a3271416da6e062e85fdfa
2019-06-04 17:45:06 +02:00
Pau Espin Pedrol
eefa30dce8 gtp: Introduce new pdp APIs (and deprecate old ones) to support multiple GSN
Move static global pdp storage arrays to be per GSN. This way now
several GSN per process are supported without collisions.

* pdp_init() is defined in public API but it's actually only intended
for use (and currently only used) internally in gtp_new(). So let's
document that and re-use it for backward compatibility with now
deprecated API, where only one GSN per process is supported.

* Back pointer to gsn_t (pdp->gsn) moved from gtp.c:gtp_new() to
gtp_pdp_newpdp(), since it makes more sense to have it there. This way
backpointer is always set, even in case were app calls pdp_newpdp() API
directly instead of creating them through gtp.c, like osmo-sgsn does.

* Create new versions of required APIs with a pointer to gsn_t where the
pdp ctx is to be created/found. Some APIs receiving a pointer to a pdp
ctx can be left intact because we have a backpointer to its gsn_t.

* pdp_getpdp() is nowhere used, and makes little sense now that we have
pdpa reachable in gsn->pdpa, so let's deprecate it without adding a
replacement.

* Deprecate gtp.h gtp_newpdp(), since it's nowhere used and useless
(does same as new gtp_pdp_newpdp() and doesn't allow for old_pdp to be
passed as parameter).

Fixes: OS#2873
Change-Id: I653cbdc185165592d985e3efab6e3f1add97877b
2019-06-04 17:42:16 +02:00
Pau Espin Pedrol
5560001af5 ggsn: Fix undefined behaviour shifting beyond sign bit
Fixes following ASan complaint during VTY "show running-config":
osmo-ggsn/ggsn/ggsn_vty.c:657:37: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'

Change-Id: I2b8d163dbc108b0fb5a1e820dc23181835d12869
2019-06-04 08:43:03 +00:00
Pau Espin Pedrol
a469a90d5e cosmetic: gtp.h: Remove trailing whitespaces
Change-Id: I60f8cf5e36bcef767f90b150a488a800445bf744
2019-05-31 16:44:01 +02:00
Pau Espin Pedrol
84515f4b8b pdp: Drop unused code for haship
Nowadays we have one tun device per APN, so we don't need this hash
table because we use the ippool of the APN to find the related PDP ctx
pointer.

Change-Id: Ife3f222daa87f0630ff34ffc3e63f4dad2ad914b
2019-05-31 16:44:01 +02:00
Oliver Smith
1cde2c1691 ggsn: Use gtp_delete_context_req2() everywhere
Replace calls to gtp_delete_context_req() with
gtp_delete_context_req2().

Related: OS#2741
Change-Id: Iecc8c5ac45207e7e20129559c4ac7f3c67dfb36a
2019-05-31 16:44:01 +02:00
Pau Espin Pedrol
93dd798a99 gtp: Re-arrange free pdp ctx code in non-teardown scenario
Code modified actually behaves the same, since gtp_freepdp() also calls
delete cb, and this way it's more consistent with rest of the code base.

Change-Id: I299765816e9d885497110d2e834f7ccdc943052c
2019-05-31 16:42:07 +02:00
Pau Espin Pedrol
8651573632 cosmetic: gtp: Document free pdp ctx in non-teardown scenario
Change-Id: Ia47ac792111fe1e9aa68222b32b5da823642206b
2019-05-31 16:40:39 +02:00
Pau Espin Pedrol
0d0b0592f0 gtp: Refactor code to use gtp_freepdp(_teardown) APIs
* API gtp_freepdp was already there but was not really being used by
anyone currently, so we can change its behaviour to call cb_delete_ctx.
It makes sense to call the cb in there too to be consistent with rest of
APIs.
* Add API gtp_freepdp_teardown, which calls gtp_freepdp on pdp and its
secondary contexts. It will also be used later on by osmo-ggsn.
* Use new APIs in internal code to simplify it.

Change-Id: I9f0b774e9385a7a8d81ec9702f158e2f9a50d571
2019-05-31 16:34:32 +02:00
Pau Espin Pedrol
aad77a0acf gtp_create_pdp_ind: simplify code by reordering and compacting parsing
Move all parsing with same conditions under same blocks to make code
easier to follow and make it more compact.

Change-Id: I52d5a3543ce6cf764bd84303b5a0d8b0643d998d
2019-05-31 16:34:32 +02:00
Pau Espin Pedrol
9ee8d3264b pdp: Introduce new API pdp_count_secondary
Change-Id: Id2d84ad1cdb0f3b500efeda4cc0fbccb24ae0c61
2019-05-31 16:34:32 +02:00
Pau Espin Pedrol
de72d26f49 gtp: Fix typo dublicate->duplicate
Change-Id: Ic572c216e74fa937dfd12f9f3dc03de18b6b123e
2019-05-31 14:25:57 +00:00
Pau Espin Pedrol
ceac078d77 gtp: Take queue_resp into account to schedule retrans timer
Before this patch they were not taken into account, which means some
resp messages could stay more time than required enqueued.

Change-Id: Iebf405b2310a34785f3b363cc2a9f415281f6030
2019-05-31 14:25:57 +00:00
Pau Espin Pedrol
cd87c5f963 ggsn: Start gtp retrans timer during startup
This timer was added in osmo-ggsn.git
dda21ed7d4,
but it was never initially started since it was introducing, and as a
result retransmissions never being triggered.

Also as a consequence, gtp_retrans is never called. That function is
responsible from triggering retransmissions and to free old responses
waiting in the resp queue (to check for duplicates). Since it's never
called, the retransmit resp queue will grow over time.

Fixes: dda21ed7d4
Fixes: OS#3997
Change-Id: Ie4adc52829446539fbbb5e9e0cf75a04f91c7eea
2019-05-31 14:25:57 +00:00
Oliver Smith
154f93da51 debian: create -doc subpackage with pdf manuals
I have verified, that the resulting debian packages build in my own OBS
namespace (see the -doc packages):
https://download.opensuse.org/repositories/home:/osmith42/Debian_9.0/all/
https://build.opensuse.org/project/show/home:osmith42

Depends: Ib7251cca9116151e473798879375cd5eb48ff3ad (osmo-ci)
Related: OS#3899
Change-Id: I5563e023dc3c8b158a79ce0c9e1478e117b0ec37
2019-05-31 14:25:07 +00:00
Pau Espin Pedrol
742a6b55ce gtp: Document spec reasoning drop of Rx DeleteCtxReq
Change-Id: I563fc0b48595d71ebdf56a50f4e9984eee423676
2019-05-30 13:36:56 +02:00
Pau Espin Pedrol
72ab4bc547 ggsn: Drop unused param force in apn_stop()
Change-Id: I920679c7062d480c1cfaa3d89c90a0ed4a2ef58b
2019-05-29 19:09:02 +02:00
Vadim Yanitskiy
fb62504160 osmo-ggsn: properly show subscriber's MSISDN in the VTY
Instead of printing subscriber's MSISDN as a hex-string, let's
attempt to decode it using gsm48_decode_bcd_number2().

Change-Id: I3f3a105dc8d0d582f2b9d8e1ff6c5785369e569b
2019-05-19 02:00:41 +07:00
Vadim Yanitskiy
d7030d268c osmo-ggsn: print requested / actual APN in PDP info
An actual APN can be different from the one that was requested by
user, e.g. when 'default-apn' VTY parameter is used. The one that
was requested is already being stored in the PDP context state.
Let's also store a chosen APN in create_context_ind().

Change-Id: I9cbe195f64e5b83d5158c175aad2e81ba2487850
2019-05-14 08:33:25 +00:00
Vadim Yanitskiy
2e8e57a3de osmo-ggsn: check result of osmo_apn_to_str()
Change-Id: I03d0eb266dca176f342e77a54f0291cc5bd7df43
2019-05-13 22:09:15 +07:00
Vadim Yanitskiy
ca276e01eb osmo-ggsn: add VTY command to show PDP context by IPv4
Change-Id: Iad60de34c562803a1a1fc024287d1a60e071afab
2019-05-13 15:37:02 +07:00
Vadim Yanitskiy
977b339abe osmo-ggsn: fix VTY command for getting PDP contexts by APN
Change-Id: I0a7f4b245c4664afdae83c660358acb1a5f88ce5
2019-05-13 15:36:58 +07:00
Harald Welte
9272d212c3 ggsn.c: Refactor PCO processing during PDP activation
The existing PCO processing is implemented in a rather convoluted
way.  We scan the list of PCO elements several times for different
PCO protocols.  Let's change to a straight-forward model where we
simply do one iteration over the list of PCO elements and generate
responses step by step.

Change-Id: I4a7d09279b6b259e2b95f1f51159b16838b2d94c
2019-04-11 19:41:00 +02:00
Harald Welte
f653c5bc33 ggsn: Fix build_ipcp_pco() in presence of invalid IPCP content
When build_ipcp_pco() iterated over the PCO list, it didn't use
the "outer" pco length as an increment, but used the "inner" IPCP
length.

If an IPCP message with an invalid "inner" length was being processed
(see pcap file attached to OS#3914), the PCO iteration beyond that
broken IPCP would fail, possibly rendering false hits.

Let's make pco_contains_proto() return a pointer to the the pco_element,
so that the caller can use the outer length as an increment.

Change-Id: I8e9cffde092c8c5824abfaeecb742afcf949802c
Related: OS#3914
2019-04-11 19:27:17 +02:00
Harald Welte
549417e675 ggsn: Remove magic numbers from ipcp_contains_option()
Let's remove some magic numbers and use a data structure instead.

Change-Id: I5b1abc6f403f85986407e9e8359924dfcb58031a
2019-04-11 19:27:17 +02:00
Harald Welte
42c9fa4958 ggsn: const-ify input / read-only arguments of PCO related functions
Change-Id: Ia0877988180ded4e3c033d7f1fb6e1c2acd60163
2019-04-11 19:27:17 +02:00
Harald Welte
df404c4296 ggsn: Remove magic numbers from pco_contains_proto()
Let's remove some magic numbers and use a data structure to describe
the PCO element header.

Change-Id: I9871ffced677320aa82438332bfdb951ab129f04
2019-04-11 19:27:17 +02:00
Harald Welte
ffa227307c process_pco() const-ify 'apn' argument
Change-Id: I2a96b0fbe077c7c49342553de0880bfc58318669
2019-04-11 14:59:51 +00:00
Max
3fc9cc97de Don't return error on normal shutdown
Previously we've always returned error code from main() even in case of
regular expected shutdown. Let's not confuse it with actual error
shutdown and return 0 by default.

Change-Id: I7fe0d3e052953d5b87ce65649d88d83476fee3c0
2019-03-14 11:16:55 +01:00
Harald Welte
f5a268a96d Bump version: 1.2.2.44-6da8-dirty → 1.3.0
Change-Id: Ie12af1d57df178a9ab27937ef0b764c98dd96e32
2019-01-20 21:34:23 +01:00
Oliver Smith
6da888c5d0 contrib: fix makedistcheck with disabled systemd
EXTRA_DIST files need to be distributed, no matter if the systemd option
is configured or not.

Change-Id: Ibd348eac3adca88663bd510172efbe4ec0bf3599
2018-12-06 13:43:26 +01:00
Oliver Smith
33c537e5a7 contrib/jenkins.sh: build and publish manuals
Add new environment variables WITH_MANUALS and PUBLISH to control if
the manuals should be built and uploaded. Describe all environment vars
on top of the file.

When WITH_MANUALS is set, install osmo-gsm-manuals like any other
dependency and add --enable-manuals to the configure flags (for "make"
and "make distcheck"). Add the bin subdir of the installed files to
PATH, so osmo-gsm-manuals-check-depends can be used by ./configure.

Related: OS#3385
Change-Id: I43e3b592c593237eb4df2d70c926c031ddb7b20b
2018-12-05 13:16:14 +01:00
Oliver Smith
aa69034c00 Fix DISTCHECK_CONFIGURE_FLAGS override
Set AM_DISTCHECK_CONFIGURE_FLAGS in Makefile.am instead of
DISTCHECK_CONFIGURE_FLAGS. This is the recommended way from the
automake manual, as otherwise the flag can't be changed by the user
anymore.

Related: OS#3718
Change-Id: I810b2b96ea077e8bd5ab01df5137e214a4349628
2018-12-04 15:33:20 +01:00
Oliver Smith
bf47f71785 build manuals moved here from osmo-gsm-manuals.git
Moved to doc/manuals/, with full commit history, in preceding merge commit.
Now incorporate in the build system.

Build with:

$ autoreconf -fi
$ ./configure --enable-manuals
$ make

Shared files from osmo-gsm-manuals.git are found automatically if
- the repository is checked out in ../osmo-gsm-manuals; or
- if it osmo-gsm-manuals was installed with "make install"; or
- OSMO_GSM_MANUALS_DIR is set.

Related: OS#3385
Change-Id: I14533676d5774ee0d0ee5054ba77d7dac32cff43
2018-11-27 18:28:24 +01:00
Neels Hofmeyr
2b7a860ffb Merge history from osmo-gsm-manuals.git
Change-Id: Ic7cebd4e6f2836be80a6186939f98057969207d4
2018-11-27 18:27:58 +01:00
Neels Hofmeyr
932eeec240 ggsn: update vty reference
Change-Id: I8a5c37505c0180d5c04c7792d6d0afdb0dffb282
2018-11-27 18:27:47 +01:00
Harald Welte
6f7aabf6a3 vty-ref: Update URI of docbook 5.0 schema
... to match the /etc/xml/catalog file on debian (no "www" in hostname)

Change-Id: Id9f3579c7f2bc3af13fe30b5268f249b6f59ed0d
2018-11-27 18:27:47 +01:00
Neels Hofmeyr
a491e42129 OsmoGGSN: update vty reference
Add new (generic) logging commands, talloc context print commands.
Add the jitter buffer logging category.

Change-Id: Ifdc735df6221bf6e9b6247912f2958974dcfc4f2
2018-11-27 18:27:47 +01:00
Neels Hofmeyr
1ce111f72b OsmoGGSN: fix VTY additions' node IDs
Change-Id: I8cd5eb64300151d0de8023ed019568cfdc4fe453
2018-11-27 18:27:47 +01:00
Neels Hofmeyr
e010dea56e OsmoGGSN vty: update VTY reference
Apply VTY reference changes from libosmocore: change node IDs from index
numbers to meaningful names from VTY node prompts.

Introduce section with common commands, do not repeat the common commands on
each child node.

Populate section names (so far empty).

Add apn / gpdu VTY reference.

This is generated using the recent libosmocore vty doc patches that conclude in
libosmocore change-id Iedd67750539b676271de0e0e9316d4e6f794406a.

Change-Id: Ia269c4bda0aa0b905abcccc75338f5f808e01727
2018-11-27 18:27:47 +01:00
Neels Hofmeyr
f4530447f6 OsmoGGSN VTY ref: prep: convert newlines to unix
To omit whitespace changes in an upcoming patch that updates the VTY reference
and will use '\n' line breaks, convert line breaks from '\r\n' to '\n' without
any other changes.

Change-Id: Id0d1a3a82c3d670cbb041884554b5d79fdfb0f28
2018-11-27 18:27:47 +01:00
Neels Hofmeyr
e7361067ac OsmoGGSN: typo: priveleges
Change-Id: Id7e59f5dfcbb632fde6c35ef014e9b85099fe06d
2018-11-27 18:27:47 +01:00
Neels Hofmeyr
606837597f OsmoGGSN: add Routing section for IP forward and masquerading
Change-Id: Ie49ca7a45113f49e89ce09017500008cbec757f5
2018-11-27 18:27:47 +01:00
Neels Hofmeyr
5f8b332e6b OsmoGGSN: multiple instances: mention GTP port
Change-Id: I781feeb955ace17d93206bc98d12bc423584ce32
2018-11-27 18:27:47 +01:00
Neels Hofmeyr
43001cbc7a OsmoGGSN: more info on non-root operation / tun creation
Add examples for 'ip addr add' and mention correspondence to config file,
add examples for enabling masquerading and IP forwarding,
place the non-root config in its own section and highlight the diffs.

Add tiny hint at systemd-networkd.

Change-Id: I02bd9cfa35c7f2fb338d5d92c2e968fe80574a78
2018-11-27 18:27:47 +01:00
Neels Hofmeyr
65d61c347b GGSN: don't say 'NITB'
Change-Id: I960ce8ee749621176ceaa556a1fe93b54e08b6fc
2018-11-27 18:27:47 +01:00
Neels Hofmeyr
c8ca02b937 refactor Makefile build rules, don't use the FORCE
The initial goal was to make sure we don't have overall FORCE rules causing
unnecessary rebuilds -- annoying while writing documentation. As I looked
through possible dependencies, I finally understood what's going on here.

Remove code dup and nicely sort which belongs where in build/Makefile.*.inc. In
each, describe in a top comment how to use it, and also unify how they are
used:

- Rename Makefile.inc to Makefile.docbook.inc and refactor
- Add Makefile.vty-reference.inc
- Add Makefile.common.inc

Make sure that we accurately pick up all dependencies.

Drop use of the macro called 'command', that silenced the actual command lines
invoked and replaced them with short strings: it obscures what is actually
going on and makes the Makefiles hard to read and understand.

Each manual's makefile is greatly reduced to few definitions and a Makefile
include, e.g. one for asciidoc, one for VTY reference.

Move common/bsc_vty_additions.xml to OsmoBSC/vty/libbsc_vty_additions.xml, link
from OsmoNITB. It applies only to OsmoBSC and OsmoNITB.

Add a script that combines a VTY reference file with *all* additions files
found in a manual's vty/ dir. Call this from Makefile.vty-reference.inc.

Change-Id: I9758e04162a480e28c7dc83475b514cf7fd25ec0
2018-11-27 18:27:47 +01:00
Harald Welte
3ce5a3648a GGSN: Document how 'ip tuntap' is used for non-root; call netdev 'apn0'
* Some people want to manually create/configure their tun devices,
  show them how to do this using ip with the correct parameters
* Let's not call the network device 'ggsn' but rather 'apn0', as
  the device has a 1:1 correspondence to the APN, not to the GGSN.

Change-Id: I2fef818bfcb8cb521397136539f492922d5f6def
2018-11-27 18:27:47 +01:00
Max
a4cb02699e Expand OsmoGGSN manual
* add cross-references
* add example of running without root priviledges

Change-Id: I1743f370ee2b351d2847f2e29e0f59f35cd401f4
2018-11-27 18:27:47 +01:00
Harald Welte
f0fb2c2ddd OsmoGGSN: Add VTY reference manual
Change-Id: Iddf6fe26689172d7db001198943c816eaaed7931
2018-11-27 18:27:47 +01:00
Harald Welte
8a1e7b8658 initial version of OsmoGGSN user manual
Closes: OS#1721
Change-Id: I7cdf150e8dd4f9dfc5e6d28e780d05dc1e1e5458
2018-11-27 18:27:47 +01:00
Neels Hofmeyr
b7782d4d41 Importing history from osmo-gsm-manuals.git
Change-Id: I79f406ae78de4a82966cffebac0dcec2abab21c2
2018-11-27 18:27:29 +01: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
3730c550cd fix a format string directives in queue_seqset()
Coverity pointed out that a format string used inappropriate
format string directives for variables of type size_t.

Change-Id: I889019aad963932fdc032421e60a72c809a93bca
Related: CID#135197
2018-11-22 13:17:18 +00:00
Stefan Sperling
cc8181fefe fix format string error in ippool_printaddr()
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-22 13:17:01 +00:00
Stefan Sperling
7327360d10 initialize local variable addr in ippool_new()
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-22 13:16:50 +00:00
Stefan Sperling
e405c2f196 replace bogus memcpy() call in ippool_newip()
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-22 13:16:29 +00:00
Stefan Sperling
411ff3b984 fix allocation of ippool's hash table
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-22 07:00:54 +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
fb75adfeda ippool.c: Use "%td" format string for ptrdiff_t
Change-Id: Iacafa0919baebac6b5a799deb41a673c022c6743
Fixes: Coverity CID#135225
2018-10-21 13:30:07 +02:00
Harald Welte
7b9230acfe sgsnemu: Fix printing of tun device name
Change-Id: I6cd89b7b59a6c1d506cfbe9d3088cb844d133313
Fixes: Coverity CID#178638
2018-10-21 13:30:07 +02:00
Harald Welte
5662cb2152 osmo-ggsn.cfg: Ensure well-formed config file example
Change-Id: Ic7fd91745e7442eda741d46748c0a4a02dedef80
2018-09-25 18:52:02 +00:00
Alexander Couzens
e1412d9493 libgtp: implement gtp_clear_queues to clear req/resp queue
Clearing the request and response queue is useful for debugging
to reset "some" state. Otherwise some tests will get un-expected
packets.

Change-Id: I279d1d7cbf5d37dd5609c2b968f317fe9a0e348d
2018-09-16 10:30:10 +00:00
Pau Espin Pedrol
d1e2342f91 Install sample cfg file to /etc/osmocom
Change-Id: If41e69295ac23a61df138ceea83794059f111086
2018-09-12 18:37:08 +02:00
Pau Espin Pedrol
381b723543 Install systemd services with autotools
Change-Id: I563559f5b501eded44efafc60bb0c9ffdea20b3e
2018-09-10 16:10:05 +02:00
Harald Welte
ee44b82b96 debian/rules: Don't overwrite .tarball-version
The .tarball-version file should contain the *source version* uniquely
identifying the git commit, and not the Debian package name.

With https://gerrit.osmocom.org/#/c/osmo-ci/+/10343/ there is a correct
.tarball-version file in the .tar.xz of the nightly source packages.

Change-Id: I1466936033c2f60edd1078eb41f3508d87da4402
Related: OS#3449
2018-08-06 11:15:00 +02:00
Pau Espin Pedrol
b5f93346df gtp: Add new replacement cb_recovery2 for cb_recovery
Sometimes the originating pdp ctx causing the Recovery Procedure is
required, in order to drop all pdp ctx but this one, which specs specify
should be handled as valid:
"""
The SGSN receiving the Recovery information element shall handle it as when an
Echo Response message is received but shall consider the PDP context being created as active if the response indicates
successful context activation at the GGSN.
"""

Change-Id: I53e92298f2f6b84d662a3300d922e8c2ccb178bc
2018-07-23 11:25:53 +02:00
Pau Espin Pedrol
8e8c7ef3c7 gtp: Add new API to avoid freeing pdp contexts during DEL CTX REQ
With this API, user is expectd to free the PDP ctx when the confirmation
for the release has been received (cb_conf time). This way user can
maintain the pdp ctx alive during all this time. Extra code is added to
gtp_delete_pdp_resp() since it's now possible to match it and push it up
to the user cb_conf.

This way, cb_conf() can be used for locally-initiated DEL CTX REQ, while
delete_context() cb is left for remotely-initiated DEL CTX REQ. In this
later case, when the DEL CTX RESP is sent the ctx is deleted and the
delete_context() is called, where the user can do related actions or
trigger consequence events (in the case of SGSN, it will drop all
related GGSN bits for that PDP ctx and forward the DEACT PDP CTX to the
MS).

Change-Id: I29d366253bb98dcba328c7ce8aa3e4daf8f75e6c
2018-07-21 17:22:54 +00:00
Stefan Sperling
57238889eb fix support for multiple IPCP in PDP protocol configuration options
Parse multiple IPCP IEs embedded in Protocol Configuration Options,
and return IPCP responses for all of them. Makes the associated
TTCN3 GGSN test pass.

Depends: Ia1410abb216831864042f95679330f4508e1af3d
Change-Id: I51ecab4e35f3ee638e68ca773b0da90cc0294ab0
Related: OS#3319
2018-07-19 19:45:01 +02:00
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 Pedrol
d1bd6fce9c gtp: Log ignore CTX DEL REQ due to no teardown and only 1 ctx active
Change-Id: Ic950c04d309d5686bfbeab332f79c48678e743ae
2018-07-13 19:11:59 +02:00
Pau Espin Pedrol
a32e4c4fb8 gtp: Allow recv DEL CTX REQ in sgsn and DEL CTX RSP in ggsn
According to 3GPP TS 29.060 section "7.3.5
Delete PDP Context Request", both directions are valid in both GSNs.

This allows osmo-sgsn receive delete ctx indication (cb_delete_context)
in order to implement GGSN initiated requests.

Change-Id: I6927c07be4ddf74defe338d01d947056e15cd14d
2018-07-13 19:05:03 +02:00
Pau Espin Pedrol
3b84e92ab3 gtp: Log type name of unexpected signalling message
Change-Id: Iae0f045e4128cf97aa7824d7d774b59bf966cbe8
2018-07-13 18:32:38 +02:00
Pau Espin Pedrol
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
Pau Espin Pedrol
b673d1c438 Bump version: 1.2.1.3-6a28 → 1.2.2
Change-Id: Idbc183ca37196082e95a107901bea53d37aa2ff3
2018-05-31 12:44:54 +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
Pau Espin Pedrol
ac07625086 Bump version: 1.2.0.1-36c4 → 1.2.1
Change-Id: I4a8bdcbee300296496f039b90795ff981018e17d
2018-05-04 12:19:58 +02:00
Pau Espin Pedrol
36c4fac9c9 debian/rules: Fix debian packaging after 1.2.0 release
The 1.2.0 release bumped lib version to 3 and updated the debian package
file accordingly, but forgot to increase dh_strip line in debian/rules.

Change-Id: Ib54f231943348c06acecd6f413b2c96b24f6db28
2018-05-04 11:28:24 +02:00
Pau Espin Pedrol
a06b2d3877 Bump version: 1.1.0.90-5468-dirty → 1.2.0
Change-Id: I2af8c8ff75d5153456b814b9dfe4fbddafe5af7a
2018-05-03 16:05:28 +02: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
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
31e1dab2c0 sgsnemu: Convert from tun_setaddr() to tun_addaddr()
This converts the last caller of tun_setaddr() outside of lib/tun.c to
use tun_addaddr().

Change-Id: Ia301d6a4ee3d02c1af1c85f2fe1041d3013268b0
2018-04-25 21:41:43 +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
47adad0817 lib/netdev.c: Cosmetic changes (coding style / cleanups)
Change-Id: I60cbca616a4f727e2374c52715f9286a0f4c5e4b
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
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
109 changed files with 22235 additions and 4129 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1 @@
open_collective: osmocom

21
.gitignore vendored
View File

@@ -16,7 +16,6 @@ install-sh
libtool
ltmain.sh
missing
osmo-ggsn.spec
stamp-h1
INSTALL
m4/
@@ -28,7 +27,7 @@ osmo-ggsn-*.tar*
# debian
debian/osmo-ggsn/
debian/*.debhelper
debian/libgtp1
debian/libgtp*/
debian/osmo-ggsn-dbg
debian/*.log
debian/autoreconf.*
@@ -69,3 +68,21 @@ tests/*/*_test
tests/testsuite
tests/testsuite.log
tests/package.m4
# manuals
doc/manuals/*.html
doc/manuals/*.svg
doc/manuals/*.pdf
doc/manuals/*__*.png
doc/manuals/*.check
doc/manuals/generated/
doc/manuals/osmomsc-usermanual.xml
doc/manuals/common
doc/manuals/build
doc/manuals/vty/ggsn_vty_reference.xml
contrib/osmo-ggsn.spec
/debian/gtp-echo-responder-dbg/
/debian/gtp-echo-responder/
/debian/osmo-ggsn-doc/
/utils/gtp-echo-responder

View File

@@ -1,5 +1,15 @@
## Process this file with automake to produce Makefile.in
SUBDIRS = lib gtp ggsn sgsnemu doc tests
SUBDIRS = \
include \
lib \
gtp \
ggsn \
sgsnemu \
doc \
contrib \
utils \
tests \
$(NULL)
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libgtp.pc
@@ -10,6 +20,16 @@ $(top_srcdir)/.version:
dist-hook:
echo $(VERSION) > $(distdir)/.tarball-version
EXTRA_DIST = git-version-gen .version README.md README.FreeBSD README.MacOSX
EXTRA_DIST = \
.version \
README.FreeBSD \
README.MacOSX \
README.md \
debian \
git-version-gen \
$(NULL)
AM_DISTCHECK_CONFIGURE_FLAGS = \
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
@RELMAKE@

169
README.md
View File

@@ -5,57 +5,71 @@ This repository contains a C-language implementation of a GGSN (Gateway
GPRS Support Node), a core network element of ETSI/3GPP cellular
networks such as GPRS, EDGE, UMTS or HSPA.
OsmoGGSN is part of the [Osmocom](https://osmocom.org/) Open Source
Mobile Communications projects and the successor to OpenGGSN.
OpenGGSN was developed until 2004 by Mondru AB.
**OsmoGGSN** is part of the [Osmocom](https://osmocom.org/) Open Source
Mobile Communications projects and the successor to OpenGGSN (which was
developed until 2004 by Mondru AB).
Homepage
--------
The official homepage of the project is
https://osmocom.org/projects/openggsn/wiki
The official homepage of the project is <https://osmocom.org/projects/openggsn/wiki>.
GIT Repository
--------------
You can clone from the official osmo-ggsn.git repository using
git clone git://git.osmocom.org/osmo-ggsn.git
git clone https://gitea.osmocom.org/cellular-infrastructure/osmo-ggsn
There is a cgit interface at http://git.osmocom.org/osmo-ggsn/
There is a web interface at <https://gitea.osmocom.org/cellular-infrastructure/osmo-ggsn>
Documentation
-------------
There currently is no other documentation other than the wiki on the
homepage. It would be great if somebody would work towards a user
manual that can become part of the osmo-gsm-manuals project.
The user manual and VTY reference are optionally built in PDF form
as part of the build process. Pre-rendered versions are available here:
* [osmo-ggsn user manual](https://ftp.osmocom.org/docs/osmo-ggsn/master/osmoggsn-usermanual.pdf)
* [osmo-ggsn VTY reference](https://ftp.osmocom.org/docs/osmo-ggsn/master/osmoggsn-vty-reference.pdf)
Forum
-----
We welcome any pySim related discussions in the
[Cellular Network Infrastructure -> 2G/3G Core Network](https://discourse.osmocom.org/c/cni/2g-3g-cn/)
section of the osmocom discourse (web based Forum).
Mailing List
------------
Discussions related to OsmoGGSN are happening on the
osmocom-net-gprs@lists.osmocom.org mailing list, please see
https://lists.osmocom.org/mailman/listinfo/osmocom-net-gprs for
<https://lists.osmocom.org/mailman/listinfo/osmocom-net-gprs> for
subscription options and the list archive.
Please observe the [Osmocom Mailing List
Rules](https://osmocom.org/projects/cellular-infrastructure/wiki/Mailing_List_Rules)
Please observe the [Osmocom Mailing List Rules](https://osmocom.org/projects/cellular-infrastructure/wiki/Mailing_List_Rules)
when posting.
Issue Tracker
-------------
We use the [issue tracker of the osmo-ggsn project on osmocom.org](https://osmocom.org/projects/openggsn/issues) for
tracking the state of bug reports and feature requests. Feel free to submit any issues you may find, or help
us out by resolving existing issues.
Contributing
------------
Our coding standards are described at
https://osmocom.org/projects/cellular-infrastructure/wiki/Coding_standards
<https://osmocom.org/projects/cellular-infrastructure/wiki/Coding_standards>
We us a gerrit based patch submission/review process for managing
We use a Gerrit based patch submission/review process for managing
contributions. Please see
https://osmocom.org/projects/cellular-infrastructure/wiki/Gerrit for
<https://osmocom.org/projects/cellular-infrastructure/wiki/Gerrit> for
more details
The current patch queue for OsmoGGSN can be seen at
https://gerrit.osmocom.org/#/q/project:osmo-ggsn+status:open
<https://gerrit.osmocom.org/#/q/project:osmo-ggsn+status:open>
QuickStart
@@ -75,61 +89,33 @@ The tun driver is required for proper operation of openggsn. For Linux
kernels later than 2.4.7 the driver is typically included, but might
need to be configured for automatic loading:
1. Add the following line to /etc/modules.conf: alias char-major-10-200 tun
2. depmod -a
1. Add the following line to `/etc/modules.conf`: `alias char-major-10-200 tun`
2. `depmod -a`
Installation from binary
------------------------
OsmoGGSN is built for common versions of Debian and Ubuntu as part of
OsmoGGSN is built for common versions of Debian, Ubuntu and other distributions part of
the [Osmocom Nightly Builds](https://osmocom.org/projects/cellular-infrastructure/wiki/Nightly_Builds)
project. If you don't want to do development, it is suggested to simply
use those binary packages, rather than building yourself from source.
and [Osmocom Latest Builds](https://osmocom.org/projects/cellular-infrastructure/wiki/Latest_Builds).
If you don't want to do development, it is suggested to simply use those binary packages, rather than building
yourself from source.
Installation from source
------------------------
1. ./configure
2. make
3. make install
```
./configure
make
make install
```
You need to be root in order to install the package, but not in order
to compile.
Running
-------
*sgsnemu*
Start the emulator as root using the command:
sgsnemu -l 10.0.0.50 -r 10.0.0.40 --createif --defaultroute
This will cause the sgsn emulator to bind to local address 10.0.0.50
and connect to the ggsn found at 10.0.0.40. It will first send off an
ECHO_REQUEST message. After this it will attempt to establish a pdp
context. If successful it will create a local interface and set up
routing. Now you should be able to ping through the connection. Use a
network analysator such as ethereal to monitor the traffic.
sgsnemu -h will show a list of available options.
sgsnemu -c sgsnemu.conf will use sgsnemu.conf as a configuration
file. A sample file is provided in examples/sgsnemu.conf.
*ggsn*
Edit the configuration file ggsn.conf found under openggsn/examples.
Start the ggsn as root using the command:
ggsn --fg -c examples/ggsn.conf -l 10.0.0.40 --statedir ./
This will run the ggsn in foreground using the local interface
10.0.0.40. If you don't have a GSM network available for testing you
can use sgsnemu to test the GGSN.
Support
-------
@@ -144,9 +130,10 @@ OsmoGGSN is an open source implementation of GPRS Support Nodes
version 1.
OsmoGGSN provides 3 components:
* gtplib
* osmo-ggsn
* sgsnemu
* *libgtp*, a shared library for the GTPv1C protocol
* *osmo-ggsn*, the GGSN itself
* *sgsnemu*, a SGSN emulator
*gtplib*
This library contains all functionality relating to the GTP
@@ -182,10 +169,10 @@ Both osmo-ggsn and sgsnemu uses the tun package. You need at least tun
version 1.1. With Linux tun is normally included from kernel version
2.4.7. To configure automatic loading:
1. Add the following line to /etc/modules.conf: alias char-major-10-200 tun
2. depmod -a
1. Add the following line to `/etc/modules.conf`: `alias char-major-10-200 tun`
2. `depmod -a`
Alternatively you can execute "modprobe tun" on the commandline.
Alternatively you can execute `modprobe tun` on the commandline.
Gengetopt
---------
@@ -195,11 +182,13 @@ cmdline.ggo source file. You need at least gengetopt version 2.8. If
you are just going to compile the programs you don't need gengetopt.
To use gengetopt for the sgsnemu do the following:
```
cd sgsnemu
gengetopt < cmdline.ggo --conf-parser
```
For more information about gengetopt see
http://www.gnu.org/software/gengetopt/gengetopt.html
<http://www.gnu.org/software/gengetopt/gengetopt.html>
Compilation and Installation
@@ -213,27 +202,21 @@ Running osmo-ggsn
Use osmo-ggsn -h for a list of available options. All options available on
the command line can also be given in a configuration file. See
examples/osmo-ggsn.cfg for the format of this file.
`doc/examples/osmo-ggsn.cfg` for the format of this file.
Start osmo-ggsn as root using the command:
osmo-ggsn -c examples/osmo-ggsn.cfg
`osmo-ggsn -c doc/examples/osmo-ggsn.cfg`
First a tun network interface will be created. In the above example
the network interface address is 192.168.0.0 and the mask is
255.255.255.0. You can check that this interface is up by using
ifconfig.
First, a tun network interface will be created for each configured apn.
After tun has been successfully established the ggsn will wait for GTP
create PDP context requests on the local interface
10.0.0.40. Currently all requests are accepted, and no password,
username or APN validation is performed.
create PDP context requests on the configured `gtp bind-ip` address.
Currently all requests are accepted, and no password, username validation is performed.
When receiving a create PDP context request a dynamic IP address will
be allocated from the address pool determined by --dynip. In the above
example the first allocated address will be 192.168.0.1, followed by
192.168.0.2 and so on. The request is confirmed by sending a create
PDP context response message to the peer (SGSN).
When receiving a create PDP context request for a given APN, a dynamic IP address will
be allocated from the address pool defined in the config file section for that apn.
The request is confirmed by sending a create PDP context response message to the peer (SGSN).
Now IP packets will be forwarded between the tun network interface and
the established GTP tunnel. In order to allow users to access the
@@ -241,22 +224,22 @@ external network routing needs to be set up. If private addresses are
used you need to configure network address translation. See the Linux
Networking HOWTO for details.
Remember to enable routing:
Remember to enable routing:
echo 1 > /proc/sys/net/ipv4/ip_forward
`echo 1 > /proc/sys/net/ipv4/ip_forward`
If you installed using a binary RPM package it is possible to start
osmo-ggsn by using the Sys 5 script:
If you're using systemd and did `make install` or installed from a bianry package,
you can start osmo-ggsn by using the included systemd service/unit file:
/etc/init.d/osmo-ggsn start
`systemctl start osmo-ggsn`
Running sgsnemu
===============
Use sgsnemu -h for a list of available options. All options available
Use `sgsnemu -h` for a list of available options. All options available
on the command line can also be given in a configuration file. See
examples/sgsnemu.conf for the format of this file.
`doc/examples/sgsnemu.conf` for the format of this file.
If you want to test a GRX roaming connection you will need to do the
following:
@@ -269,11 +252,11 @@ subnet mask and default route. See the Linux Networking HOWTO for
details.
4. Launch sgsnemu with something like:
sgsnemu --listen 10.0.0.50 --remote 10.0.0.40 --dns 10.20.38.51 --timelimit 10 --contexts 0
`sgsnemu --listen 10.0.0.50 --remote 10.0.0.40 --dns 10.20.38.51 --timelimit 10 --contexts 0`
sgsnemu will print something like the following on the screen:
```
Using DNS server: 10.20.38.51 (10.20.38.51)
Local IP address is: 10.0.0.50 (10.0.0.50)
Remote IP address is: 10.0.0.40 (10.0.0.40)
@@ -289,6 +272,7 @@ sgsnemu will print something like the following on the screen:
Waiting for response from ggsn........
Received echo response. Cause value: 0
```
This is quite good. It means that you managed to send off an echo
request to a remote GGSN, and it was friendly enough to answer you. If
@@ -306,10 +290,11 @@ testing. Also note that you are establishing a connection to the Gi
network, so please be carefull not to route internet traffic onto the
GPRS core network! Assuming you know what you are doing:
sgsnemu --listen 10.0.0.50 --remote 10.0.0.40 --dns 10.20.38.51 --timelimit 10 --contexts 1 --apn internet --imsi 240011234567890 --msisdn 46702123456 --createif --defaultroute
`sgsnemu --listen 10.0.0.50 --remote 10.0.0.40 --dns 10.20.38.51 --timelimit 10 --contexts 1 --apn internet --imsi 240011234567890 --msisdn 46702123456 --createif --defaultroute`
sgsnemu will print something like the following on the screen:
```
Using DNS server: 10.20.38.51 (10.20.38.51)
Local IP address is: 10.0.0.50 (10.0.0.50)
Remote IP address is: 10.0.0.40 (10.0.0.40)
@@ -330,7 +315,7 @@ sgsnemu will print something like the following on the screen:
Setting up interface and routing
/sbin/ifconfig tun0 192.168.0.1
/sbin/route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.0.1
```
Now a context is established to the remote GGSN. The IP address of the
context is 192.168.0.1. You should be able to ping a known address on
@@ -344,13 +329,13 @@ do this is to use policy routing. Also note that you are effectively
connecting the same computer to both the Gn and Gi network, so please
be carefull not to route internet traffic onto the GPRS core network
and please protect yourself against hackers! For this reason it is
advised to always use --contexts 0 when testing a live network.
advised to always use `--contexts 0` when testing a live network.
After --timelimit seconds the PDP context is disconnected with the
After `--timelimit seconds` the PDP context is disconnected with the
following messages from sgsnemu:
```
Disconnecting PDP context #0
Received delete PDP context response. Cause value: 128
Deleting tun interface
```

View File

@@ -1,9 +1,9 @@
# When cleaning up this file: bump API version in corresponding Makefile.am and rename corresponding debian/lib*.install
# according to https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info
# In short:
# according to https://osmocom.org/projects/cellular-infrastructure/wiki/Make_a_new_release
# In short: https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info
# LIBVERSION=c:r:a
# If the library source code has changed at all since the last update, then increment revision: c:r + 1:a.
# If any interfaces have been added, removed, or changed since the last update: c + 1:0:0.
# If any interfaces have been added, removed, or changed since the last update: c + 1:0:a.
# If any interfaces have been added since the last public release: c:r:a + 1.
# If any interfaces have been removed or changed since the last public release: c:r:0.
#library what description / commit summary line
#library what description / commit summary line

View File

@@ -1,14 +1,15 @@
# Process this file with autoconf to produce a configure script.
AC_INIT(osmo-ggsn, m4_esyscmd([./git-version-gen .tarball-version]), osmocom-net-gprs@lists.osmocom.org)
AC_INIT([osmo-ggsn],[m4_esyscmd(./git-version-gen .tarball-version)],[osmocom-net-gprs@lists.osmocom.org])
AC_CONFIG_SRCDIR([gtp/gtp.c])
AM_CONFIG_HEADER([config.h])
#AC_CONFIG_HEADER([config.h])
AC_CONFIG_HEADERS([config.h])
dnl *This* is the root dir, even if an install-sh exists in ../ or ../../
AC_CONFIG_AUX_DIR([.])
AC_CONFIG_TESTDIR(tests)
AC_CANONICAL_SYSTEM
AC_CANONICAL_HOST
CFLAGS="$CFLAGS -std=gnu11"
dnl kernel style compile messages
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
@@ -20,6 +21,11 @@ AC_PROG_AWK
AC_PROG_CPP
LT_INIT
dnl patching ${archive_cmds} to affect generation of file "libtool" to fix linking with clang
AS_CASE(["$LD"],[*clang*],
[AS_CASE(["${host_os}"],
[*linux*],[archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib'])])
dnl check for pkg-config (explained in detail in libosmocore/configure.ac)
AC_PATH_PROG(PKG_CONFIG_INSTALLED, pkg-config, no)
if test "x$PKG_CONFIG_INSTALLED" = "xno"; then
@@ -38,9 +44,9 @@ AC_SUBST(EXEC_LDFLAGS)
case "${host}" in
i*86-*-linux-gnu*)
i*86-*-linux-gnu*)
EXEC_LDADD="" ;;
*solaris*)
*solaris*)
EXEC_LDADD="-lresolv -lsocket -lnsl" ;;
esac
@@ -65,7 +71,7 @@ AC_ARG_ENABLE([gtp-linux],
[enable_gtp_linux="$enableval"], [enable_gtp_linux="no"])
AS_IF([test "x$enable_gtp_linux" = "xyes"], [
PKG_CHECK_MODULES([LIBGTPNL], [libgtpnl >= 1.0.0])
PKG_CHECK_MODULES([LIBGTPNL], [libgtpnl >= 1.3.0])
])
AM_CONDITIONAL([ENABLE_GTP_KERNEL], [test "$enable_gtp_linux" = "yes"])
@@ -75,8 +81,12 @@ AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h sys/time.h unistd.h])
# Check for if header
AC_CHECK_HEADERS([linux/if.h net/if.h])
# Check for if header. Some versions of linux/if.h fail without sys/socket.h included beforehand:
# see https://algorithmicallyrandom.blogspot.com/2012/07/error-on-including-include.html
AC_CHECK_HEADERS([linux/if.h net/if.h], [], [], [#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
# endif
])
# Check for tun header
AC_CHECK_HEADERS([linux/if_tun.h net/if_tun.h])
@@ -123,10 +133,19 @@ AC_EGREP_HEADER(struct iphdr, netinet/ip.h,
AC_DEFINE([HAVE_IPHDR])],
AC_MSG_RESULT(no))
# Address generation modes (enum) implemented in linux 3.17 (bc91b0f07ada5535427373a4e2050877bcc12218)
# /proc/sys/net/ipv6/conf/${iface}/addr_gen_mode was added in linux 4.11 (d35a00b8e33dab7385f724e713ae71c8be0a49f4)
AC_MSG_CHECKING(whether enum in6_addr_gen_mode.IN6_ADDR_GEN_MODE_NONE exists)
AH_TEMPLATE(HAVE_IN6_ADDR_GEN_MODE_NONE)
AC_EGREP_HEADER(IN6_ADDR_GEN_MODE_NONE, linux/if_link.h,
[AC_MSG_RESULT(yes)
AC_DEFINE([HAVE_IN6_ADDR_GEN_MODE_NONE])],
AC_MSG_RESULT(no))
# Checks for library functions.
AC_PROG_GCC_TRADITIONAL
# AC_FUNC_MALLOC
# AC_FUNC_MEMCMP
# AC_FUNC_MEMCMP
AC_CHECK_FUNCS([gethostbyname inet_ntoa memset select socket strdup strerror strtol])
AC_CHECK_FUNCS(inet_aton inet_addr, break)
@@ -135,9 +154,9 @@ adl_FUNC_GETOPT_LONG
AM_INIT_AUTOMAKE([foreign])
PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 0.6.4)
PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 0.3.0)
PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl)
PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 1.11.0)
PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 1.11.0)
PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl >= 1.11.0)
AC_ARG_ENABLE(sanitize,
[AS_HELP_STRING(
@@ -169,6 +188,64 @@ then
CPPFLAGS="$CPPFLAGS $WERROR_FLAGS"
fi
# Generate manuals
AC_ARG_ENABLE(manuals,
[AS_HELP_STRING(
[--enable-manuals],
[Generate manual PDFs [default=no]],
)],
[osmo_ac_build_manuals=$enableval], [osmo_ac_build_manuals="no"])
AM_CONDITIONAL([BUILD_MANUALS], [test x"$osmo_ac_build_manuals" = x"yes"])
AC_ARG_VAR(OSMO_GSM_MANUALS_DIR, [path to common osmo-gsm-manuals files, overriding pkg-config and "../osmo-gsm-manuals"
fallback])
if test x"$osmo_ac_build_manuals" = x"yes"
then
# Find OSMO_GSM_MANUALS_DIR (env, pkg-conf, fallback)
if test -n "$OSMO_GSM_MANUALS_DIR"; then
echo "checking for OSMO_GSM_MANUALS_DIR... $OSMO_GSM_MANUALS_DIR (from env)"
else
OSMO_GSM_MANUALS_DIR="$($PKG_CONFIG osmo-gsm-manuals --variable=osmogsmmanualsdir 2>/dev/null)"
if test -n "$OSMO_GSM_MANUALS_DIR"; then
echo "checking for OSMO_GSM_MANUALS_DIR... $OSMO_GSM_MANUALS_DIR (from pkg-conf)"
else
OSMO_GSM_MANUALS_DIR="../osmo-gsm-manuals"
echo "checking for OSMO_GSM_MANUALS_DIR... $OSMO_GSM_MANUALS_DIR (fallback)"
fi
fi
if ! test -d "$OSMO_GSM_MANUALS_DIR"; then
AC_MSG_ERROR("OSMO_GSM_MANUALS_DIR does not exist! Install osmo-gsm-manuals or set OSMO_GSM_MANUALS_DIR.")
fi
# Find and run check-depends
CHECK_DEPENDS="$OSMO_GSM_MANUALS_DIR/check-depends.sh"
if ! test -x "$CHECK_DEPENDS"; then
CHECK_DEPENDS="osmo-gsm-manuals-check-depends"
fi
if ! $CHECK_DEPENDS; then
AC_MSG_ERROR("missing dependencies for --enable-manuals")
fi
# Put in Makefile with absolute path
OSMO_GSM_MANUALS_DIR="$(realpath "$OSMO_GSM_MANUALS_DIR")"
AC_SUBST([OSMO_GSM_MANUALS_DIR])
fi
# https://www.freedesktop.org/software/systemd/man/daemon.html
AC_ARG_WITH([systemdsystemunitdir],
[AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files])],,
[with_systemdsystemunitdir=auto])
AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"], [
def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)
AS_IF([test "x$def_systemdsystemunitdir" = "x"],
[AS_IF([test "x$with_systemdsystemunitdir" = "xyes"],
[AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])])
with_systemdsystemunitdir=no],
[with_systemdsystemunitdir="$def_systemdsystemunitdir"])])
AS_IF([test "x$with_systemdsystemunitdir" != "xno"],
[AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])])
AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$with_systemdsystemunitdir" != "xno"])
AC_MSG_RESULT([CFLAGS="$CFLAGS"])
AC_MSG_RESULT([CPPFLAGS="$CPPFLAGS"])
@@ -180,12 +257,18 @@ AC_CONFIG_FILES([Makefile
lib/Makefile
intl/Makefile
po/Makefile
utils/Makefile
sgsnemu/Makefile
doc/manuals/Makefile
contrib/Makefile
contrib/systemd/Makefile
tests/Makefile
tests/lib/Makefile
tests/gtp/Makefile
libgtp.pc
osmo-ggsn.spec])
include/Makefile
include/osmocom/Makefile
include/osmocom/gtp/Makefile
libgtp.pc])
AC_OUTPUT
echo "

1
contrib/Makefile.am Normal file
View File

@@ -0,0 +1 @@
SUBDIRS = systemd

View File

@@ -1,5 +1,11 @@
#!/usr/bin/env bash
# jenkins build helper script for openbsc. This is how we build on jenkins.osmocom.org
#
# environment variables:
# * GTP: configure GTP tunneling Linux kernel (values: "--enable-gtp-linux" or "--disable-gtp-linux")
# * WITH_MANUALS: build manual PDFs if set to "1"
# * PUBLISH: upload manuals after building if set to "1" (ignored without WITH_MANUALS = "1")
#
if ! [ -x "$(command -v osmo-build-dep.sh)" ]; then
echo "Error: We need to have scripts/osmo-deps.sh from http://git.osmocom.org/osmo-ci/ in PATH !"
@@ -21,12 +27,19 @@ mkdir "$deps" || true
if [ "x$GTP" == "x--enable-gtp-linux" ]; then
osmo-build-dep.sh libgtpnl
fi
osmo-build-dep.sh libosmocore "" ac_cv_path_DOXYGEN=false
osmo-build-dep.sh libosmocore "" --disable-doxygen
verify_value_string_arrays_are_terminated.py $(find . -name "*.[hc]")
export PKG_CONFIG_PATH="$inst/lib/pkgconfig:$PKG_CONFIG_PATH"
export LD_LIBRARY_PATH="$inst/lib"
export PATH="$inst/bin:$PATH"
# Additional configure options and depends
CONFIG=""
if [ "$WITH_MANUALS" = "1" ]; then
CONFIG="--enable-manuals"
fi
set +x
echo
@@ -38,8 +51,13 @@ set -x
cd "$base"
autoreconf --install --force
./configure --enable-sanitize --enable-werror $GTP
./configure --enable-sanitize --enable-werror $GTP $CONFIG
$MAKE $PARALLEL_MAKE
$MAKE distcheck
DISTCHECK_CONFIGURE_FLAGS="$CONFIG" $MAKE $PARALLEL_MAKE distcheck
if [ "$WITH_MANUALS" = "1" ] && [ "$PUBLISH" = "1" ]; then
make -C "$base/doc/manuals" publish
fi
$MAKE $PARALLEL_MAKE maintainer-clean
osmo-clean-workspace.sh

View File

@@ -1,97 +0,0 @@
#!/bin/sh
#
# osmo-ggsn This shell script takes care of starting and stopping
# osmo-ggsn.
#
# chkconfig: - 65 35
# description: osmo-ggsn is a Gateway GPRS Support Node.
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
if [ -f /etc/sysconfig/osmo-ggsn ]; then
. /etc/sysconfig/osmo-ggsn
fi
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -f /usr/bin/osmo-ggsn ] || exit 0
[ -f /etc/osmo-ggsn.cfg ] || exit 0
RETVAL=0
prog="osmo-ggsn"
start() {
# Start daemons.
echo -n $"Starting $prog: "
# Load tun module
/sbin/modprobe tun >/dev/null 2>&1
# Enable routing of packets: WARNING!!!
# Users should enable this explicitly
# echo 1 > /proc/sys/net/ipv4/ip_forward
# Check for runtime directory of nonvolatile data
if [ ! -d /var/lib/osmo-ggsn ]; then
mkdir /var/lib/osmo-ggsn
fi
# Check for GTP restart counter
if [ ! -d /var/lib/osmo-ggsn/gsn_restart ]; then
echo 0 > /var/lib/osmo-ggsn/gsn_restart
fi
daemon /usr/bin/osmo-ggsn
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/osmo-ggsn
return $RETVAL
}
stop() {
# Stop daemons.
echo -n $"Shutting down $prog: "
killproc osmo-ggsn
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/osmo-ggsn /var/run/osmo-ggsn.pid
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
condrestart)
if [ -f /var/lock/subsys/osmo-ggsn ] ; then
stop
start
RETVAL=$?
fi
;;
status)
status osmo-ggsn
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1
esac
exit $RETVAL

View File

@@ -1,13 +0,0 @@
[Unit]
Description=OsmoGGSN
After=networking.service
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/osmo-ggsn -c /etc/osmocom/osmo-ggsn.cfg
RestartSec=2
RestartPreventExitStatus=1
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,10 @@
EXTRA_DIST = \
osmo-ggsn.service \
ggsn.network \
apn0.netdev \
$(NULL)
if HAVE_SYSTEMD
systemdsystemunit_DATA = \
osmo-ggsn.service
endif

View File

@@ -0,0 +1,7 @@
[NetDev]
Name=apn0
Kind=tun
[Tun]
User=username
Group=username

View File

@@ -0,0 +1,6 @@
[Match]
Name=apn0
[Network]
Address=192.168.7.1/24
IPMasquerade=yes

View File

@@ -0,0 +1,20 @@
[Unit]
Description=OsmoGGSN
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
Restart=always
StateDirectory=osmocom
WorkingDirectory=%S/osmocom
ExecStart=/usr/bin/osmo-ggsn -c /etc/osmocom/osmo-ggsn.cfg
RestartSec=2
RestartPreventExitStatus=1
User=osmocom
Group=osmocom
# For setting up the gtp0/tun0 devices
AmbientCapabilities=CAP_NET_ADMIN
[Install]
WantedBy=multi-user.target

596
debian/changelog vendored
View File

@@ -1,3 +1,599 @@
osmo-ggsn (1.13.0) unstable; urgency=medium
[ Pau Espin Pedrol ]
* gtp: Allow tx Direct Tunnel Flags in UpdatePDPCtx{Req,Resp}
* gtp: Store rx Direct Tunnel Flags in UpdatePDPCtx{Req,Resp}
* gtp: Allow UpdatePDPContext initiated by GGSN
* gtp: Allow setting callback to receive update_context_ind
* ggsn: Mark internal cb function static
* ggsn: kernel gtpu: Support updating pdp ctx remote IP address and TEID
* Move apn allocation code out of vty file
* Move ggsn allocation code out of vty file
* Move g_ggsn_list declaration to ggsn.c
* vty: Fix missing newline in description of 'apn tun-device' cmd
* ggsn: Support announcing APN MTU over PCO
* ggsn: Support announcing APN MTU over ICMPv6 RA
* ggsn: use libosmocore tundev API to create apn tun device
* ggsn: Use osmo_netdev_addaddr() libosmocore API
* ggsn: apply configured APN MTU to tun
* doc: Fix typo in user manual
* doc: Remove reference to non longer existing osmo-ggsn.init
* doc: Fix typo: wrong interface named
* doc: Reorder some chapters
* tun: Fix null pointer derefence when in kernel gtp mode
* ggsn: Avoid forwarding IPv6 solicited-node multicast addr to tun device
* ggsn: Rename confusing functions
* tun.h: Remove non-existent tun_decaps()
* Rename tun_encaps -> tun_inject_pkt
* Refactor tun_t fields and alloc APIs
* tun: Use OSMO_STRLCPY_ARRAY
* doc: Document MTU features in User Manual and example config files
* doc: Update all iptables references with nftables
* jenkins.sh: Use --disable-doxygen configure param
[ Alexander Couzens ]
* gtp_internal.h: add missing include to <stdint.h>
* gtpie: fix comment
* gtp.h: add more GTP cause code from 29.060 v15.3.30
* gtp_new(): use talloc instead of calloc/free
* gtpie: add gtp_encaps a modern encapsulation method
* gtp: split gtp_req into 2 parts: transmit and fill header
[ Daniel Willmann ]
* gtp: Make peer addr const in gtp_req/gtp_resp
* gtp: Rework gtp_resp() into gtp_resp_pdp()
-- Oliver Smith <osmith@sysmocom.de> Wed, 12 Feb 2025 12:09:58 +0100
osmo-ggsn (1.12.0) unstable; urgency=medium
[ Daniel Willmann ]
* libgtp: Remove defines for reserved causes in gtp.h
[ Pau Espin Pedrol ]
* pco: Improve IPCP spec reference documentation
[ Oliver Smith ]
* Fix a typo
* gtp_new: deduplicate create_and_bind_socket code
* kernel-gtp: support IPv6 on outer layer
* kernel-gtp: support IPv6 on inner layer
* Revert "kernel-gtp: support IPv6 on outer layer"
* Cosmetic: Makefile.am: make SUBDIRS diff friendly
* Cosmetic: AM_CFLAGS: make diff friendly
* Cosmetic: {lib,gtp}/Makefile.am: diff friendly
* lib/gtp-kernel.c: initialize ret with 0
* lib/gtp-kernel.c: check rc of in46a_from_eua
* doc: fix typo ndoe -> node
* Add clear error for kernel not supporting IPv6
* contrib: remove rpm spec file
* libgtp: move includes to osmocom/include/gtp
* gtp/gsn_internal.h: new file
* gtp/gtp.c: move gtp_create_context_resp down
* gtp: remove unused conversion functions
* gtp: move conversion functions up
* gtp/gtp_internal.h: new file
* ggsn/ggsn_vty: create state-dir
* doc: set state-dir to /var/lib/osmocom/osmo-ggsn
* contrib/systemd: run as osmocom user
* Use uniform log format for default config files
* {contrib,debian}/osmo-ggsn.init: remove
[ Harald Welte ]
* Add funding link to github mirror
* README.md: Improve markdown formatting
* README.md: Add Forum + Issue Tracker sections
* README.md: Major overhaul
[ Vadim Yanitskiy ]
* README.md: cosmetic: fix a typo
-- Oliver Smith <osmith@sysmocom.de> Wed, 24 Jul 2024 15:13:31 +0200
osmo-ggsn (1.11.0) unstable; urgency=medium
[ Daniel Willmann ]
* gtp: Add net GTP cause values and a function to check for success
-- Oliver Smith <osmith@sysmocom.de> Tue, 28 Nov 2023 13:38:29 +0100
osmo-ggsn (1.10.2) unstable; urgency=medium
[ Vadim Yanitskiy ]
* Do not hard-code -g and -O2 in CFLAGS
* tests: use -no-install libtool flag to avoid ./lt-* scripts
[ Oliver Smith ]
* doc/manuals/chapters/configuration: fix typo
* debian: set compat level to 10
* systemd: depend on networking-online.target
* README: update documentation section
* doc: running: update kernel-gtp limitations
* lib/in46_addr: add in46a_from_gsna
-- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 12 Sep 2023 14:36:10 +0200
osmo-ggsn (1.10.1) unstable; urgency=medium
[ Oliver Smith ]
* debian/libgtp6.shlibs: new file
[ Vadim Yanitskiy ]
* lib/icmpv6.h: fix struct icmpv6_{radv_hdr,opt_prefix}
* gtp/gsn.c: fix 'No newline at end of file'
* gtp: use OSMO_ASSERT() in gtp_new()
-- Vadim Yanitskiy <vyanitskiy@sysmocom.de> Mon, 27 Feb 2023 22:35:47 +0700
osmo-ggsn (1.10.0) unstable; urgency=medium
[ Max ]
* Set working directory in systemd service file
* Ignore .deb build byproducts
* ctrl: take both address and port from vty config
[ Pau Espin Pedrol ]
* cosmetic: gtp: Fix typo in comment
* Split gsn_t related APIs out of gtp.{c,h}
* Use rate_ctr for gsn_t available_counters
* ggsn: Introduce tdef and make it configurable over VTY
* gtp: Introduce VTY configurable GTP timer X3
* Fix typos in comments and VTY descriptions
[ arehbein ]
* osmo-ggsn: Transition to use of 'telnet_init_default'
-- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 07 Feb 2023 14:29:48 +0100
osmo-ggsn (1.9.0) unstable; urgency=medium
[ Pau Espin Pedrol ]
* tests: in46a_test: Make coverity happy when calling in46a_from_eua
* vty: Fix cmd 'no echo-interval' doing nothing
* libgtp: Fix ggsn crash if pdp alloc array is full (PDP_MAX)
* libgtp: Define retransmit QUEUE_SIZE relative to PDP_MAX (increase)
* gtp: Use switch statement in gtp_create_pdp_ind()
* gtp: Log detection of rx duplicate
* gtp: Small log improvements in gtp_create_pdp_ind()
* gtp: Specify retrans queue name & seqnum in log lines
* gtp: Log retrans queue register&free entries
* gtp: Fix typo in comment
* pco.h: Fix typo in reference to spec
[ Vadim Yanitskiy ]
* tests: use 'check_PROGRAMS' instead of 'noinst_PROGRAMS'
[ Harald Welte ]
* update git URLs (git -> https; gitea)
-- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 28 Jun 2022 17:48:22 +0200
osmo-ggsn (1.8.0) unstable; urgency=medium
[ Oliver Smith ]
* doc/examples/Makefile.am: add sgsnemu.conf
* doc/examples/osmo-ggsn-kernel-gtp.cfg: new file
* doc/manuals: describe GTP-U kernel module
* gitignore: add ggsn_vty_reference.xml
[ Harald Welte ]
* Don't install osmo-ggsn-kernel-gtp.cfg to /etc/osmocom/
* Don't install sgsnemu.conf to /etc/osmocom/
* ggsn: Reject PDP CTX ACT for static IP addresses
* vty: Inform user that static IP addresses are not supported
[ Pau Espin Pedrol ]
* gtp: Update teic_confirmed only on resp success
* gtp: Rework parsing logic of UpdatePdpCtxResponse
* ggsn: Improve logging on incoming DL data packets
* gtp: Improve logging of failing pdp ctx resolution from TEI/TID
* cosmetic: gtpie.c: Fix trailing whitespace
* gtp: constify pointer arg
* gtp: Support tx/rx RAN Information Relay message
* ggsn: Log tun fd write errors
* ggsn: Fix heap-use-after-free during Recovery without associated PDP
* cosmetic: configure.ac: Fix tabulation in line
* Introduce program gtp-echo-responder
* gtp_echo_responder: report invalid chars present in node-feautres cmdline arg as error
-- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 16 Nov 2021 13:49:16 +0100
osmo-ggsn (1.7.1) unstable; urgency=medium
[ Harald Welte ]
* main: add --vty-ref-mode, use vty_dump_xml_ref_mode()
* manuals: generate vty reference xml at build time
-- Pau Espin Pedrol <pespin@sysmocom.de> Tue, 23 Feb 2021 17:31:24 +0100
osmo-ggsn (1.7.0) unstable; urgency=medium
[ Vadim Yanitskiy ]
* debian/control: change maintainer to the Osmocom team / mailing list
[ Pau Espin Pedrol ]
* configure.ac: Fix trailing whitespace
* doc: Update VTY reference xml file
* Support setting rt-prio and cpu-affinity mask through VTY
* contrib/jenkins: Enable parallel make in make distcheck
* ggsn: generate coredump and exit upon SIGABRT received
* tests: Explicitly drop category from log
* tests: Replace deprecated API log_set_print_filename
[ Keith ]
* Fix vty PDP lookups by IMSI
* Prevent Crash in show pdp-context from vty
* Minor: remove code duplication
* Use imsi_str2gtp() in sgsnemu
* sgsnemu: relax check on length of IMSI cmdline arg.
* GTP: Replace recently introduced imsi_str2gtp()
[ Harald Welte ]
* Use OSMO_FD_* instead of deprecated BSC_FD_*
* gtp-kernel: Remove duplicate #include section
* gtp-kernel: don't #include libmnl headers
[ Oliver Smith ]
* contrib/jenkins: don't build osmo-gsm-manuals
* configure.ac: set -std=gnu11
* apn_start: avoid segfault if missing tun-device
* .gitignore: ignore debian/libgtp*
* deb/rpm: build with --enable-gtp-linux
-- Pau Espin Pedrol <pespin@espeweb.net> Tue, 23 Feb 2021 13:34:39 +0100
osmo-ggsn (1.6.0) unstable; urgency=medium
[ Pau Espin Pedrol ]
* cosmetic: Fix comment typo
* netns: Improve error checking
* sgsnemu: cmdline: Drop unused function cmdline_parser_params_create()
* sgsnemu: Pass array of in64_addr to in46a_from_eua()
* sgsnemu: Rename sgsnemu's libgtp cb_conf
* sgsnemu: Set its default loglevel category to INFO
* Move icmpv6 and checksum files from ggsn/ dir to lib/
* netdev_addaddr6: Use prefixlen arg
* sgsnemu: Avoid adding extra autogenerated local link ipv6 addr to tun iface
* sgsnemu: Fix ping transmitted statistics output
* cosmetic: icmpv6.c: fix typo in comment
* icmpv6.c: Mark internal function as static
* sgsnemu: Get rid of duplicated options.destaddr
* sgsnemu: Get rid of duplicated options.net
* sgsnemu: tun_addaddr: Don't set local addr as dstaddr
* icmpv6.c: Move code generating ipv6 hdr to its own function
* Rename netdev_*route to end in route4
* sgsnemu: Fix build/run against linux < 4.11 (no sysctl addr_gen_mode support)
* sgsnemu: Handle IPv6 SLAAC in tun iface manually
* sgsnemu: Implement ping on IPv6 APNs
* sgsnemu: Fix assumption ipv6 Interface-Identifier of public addr == announced Prefix
* gtp: queue_test: Fix printf gcc warn under ARM
[ Andreas Schultz ]
* add Linux network namespace support for TUN device
[ Vadim Yanitskiy ]
* lib/netns: fix open_ns(): return fd from open()
[ Philipp Maier ]
* doc: do not use random ip address for dns in default conf
* doc: use 127.0.0.2 instead of 127.0.0.6 as bind ip.
* debug: use LOGL_NOTICE instead of LOGL_DEBUG
[ Eric ]
* configure.ac: fix libtool issue with clang and sanitizer
[ Harald Welte ]
* lib/netns.c: Add comments to the code, including doxygen API docs
* lib/netns: OSMO_ASSERT() if user doesn't call init_netns()
* lib/netns: Fix up error paths
* example config: use RFC1918 addresses for GGSN pools
[ Dmitri Kalashnik ]
* sgsnemu: use real tun device name after the device is up.
[ Oliver Smith ]
* osmo-ggsn.spec.in: remove
* contrib: import RPM spec
* contrib: integrate RPM spec
* Makefile.am: EXTRA_DIST: debian, contrib/*.spec.in
-- Harald Welte <laforge@osmocom.org> Thu, 13 Aug 2020 12:26:20 +0200
osmo-ggsn (1.5.0) unstable; urgency=medium
[ Jan Engelhardt ]
* build: switch AC_CANONICAL_TARGET for AC_CANONICAL_HOST
[ Pau Espin Pedrol ]
* libgtp: Remove packets in tx queue belonging pdp being freed
* libgtp: announce pdp ctx deletion upon CreatePdpCtx being rejected
* Introduce in46a_is_v{4,6}() helpers
* ggsn: Move PCO handling code into its own file
* in46_addr: Improve in46a_ntop documentation
* ggsn_vty.c: Fix wrong use of in46a_from_eua, print IPv6 euas
* ggsn: Split application lifecycle related code into ggsn_main.c
* Move pdp_get_peer_ipv() to lib/util.*
* gtp-kernel.c: Fix wrong use of in46a_from_eua, print IPv6 euas
* Introduce LOGTUN log helper
* ggsn_vty.c: Avoid printing duplicates for pdp context with v4v6 EUAs
* pdp: constify param in pdp_count_secondary()
* ggsn_vty.c: Improve output of VTY show pdp-context
* doc: Update vty reference xml file
* libgtp: Introduce cb_recovery3
* ggsn: Implement echo req/resp and recovery
* cosmetic: fix formatting in if line
* gtp: Log msg retransmits and timeouts
* cosmetic: gtp: Drop commented out code calling pdp_freepdp()
* cosmetic: gtp: Improve documentation of gtp_delete_context_req2()
* ggsn: rx DeletePdpReq confirmation: Improve documentation and use gtp_freepdp()
* gtp: Manage queue timers internally
* ggsn, sgsnemu: Drop use of no-op deprecated gtp_retrans* APIs
[ Vadim Yanitskiy ]
* gtp_update_pdp_ind(): fix NULL-pointer dereference
* gtp_error_ind_conf(): fix: guard against an unknown GTP version
* gtp/gtp.c: cosmetic: use get_tid() where we need TID
* manuals/configuration.adoc: fix Network Address without prefix length
* manuals/configuration.adoc: fix IPv4 address mismatch in <<ggsn_no_root>>
* contrib/systemd: add systemd-networkd examples from manuals
[ Harald Welte ]
* sgsnemu: Fix null-pointer format string argument
* manual: Fix copy+paste error
-- Pau Espin Pedrol <pespin@sysmocom.de> Thu, 02 Jan 2020 20:39:39 +0100
osmo-ggsn (1.4.0) unstable; urgency=medium
[ Max ]
* Don't return error on normal shutdown
[ Harald Welte ]
* process_pco() const-ify 'apn' argument
* ggsn: Remove magic numbers from pco_contains_proto()
* ggsn: const-ify input / read-only arguments of PCO related functions
* ggsn: Remove magic numbers from ipcp_contains_option()
* ggsn: Fix build_ipcp_pco() in presence of invalid IPCP content
* ggsn.c: Refactor PCO processing during PDP activation
* ggsn: Add minimalistic PAP support
* ggsn: More logging from PCO handling (e.g. in case of malconfiguration)
* sgsnemu: Fix format string argument count
[ Vadim Yanitskiy ]
* osmo-ggsn: fix VTY command for getting PDP contexts by APN
* osmo-ggsn: add VTY command to show PDP context by IPv4
* osmo-ggsn: check result of osmo_apn_to_str()
* osmo-ggsn: print requested / actual APN in PDP info
* osmo-ggsn: properly show subscriber's MSISDN in the VTY
[ Pau Espin Pedrol ]
* ggsn: Drop unused param force in apn_stop()
* gtp: Document spec reasoning drop of Rx DeleteCtxReq
* ggsn: Start gtp retrans timer during startup
* gtp: Take queue_resp into account to schedule retrans timer
* gtp: Fix typo dublicate->duplicate
* pdp: Introduce new API pdp_count_secondary
* gtp_create_pdp_ind: simplify code by reordering and compacting parsing
* gtp: Refactor code to use gtp_freepdp(_teardown) APIs
* cosmetic: gtp: Document free pdp ctx in non-teardown scenario
* gtp: Re-arrange free pdp ctx code in non-teardown scenario
* pdp: Drop unused code for haship
* cosmetic: gtp.h: Remove trailing whitespaces
* ggsn: Fix undefined behaviour shifting beyond sign bit
* gtp: Introduce new pdp APIs (and deprecate old ones) to support multiple GSN
* gtp: Make use of new libgtp APIs with multi-gsn support
* ggsn_vty_reference.xml: Update from last code changes
* ggsn: vty: Require ggsn param in <show pdp-context> cmd
* sgsnemu: Replace use of deprecated libgtp API pdp_newpdp with new one
* cosmetic: gtp: queue: remove trailing whitespace
* gtp: Add missing headers
* gtp: queue.c: Document queue APIs
* gtp: queue: Add unit test queue_test
* ggsn: Avoid unaligned mem access reading PCO proto id
* ggsn: Use structures instead of raw arrays when parsing ipcp_hdr
* configure.ac: Replace obosolete macro AC_CANONICAL_SYSTEM
* configure.ac: Use brackets in AC_INIT params
* configure.ac: Use prefered AC_CONFIG_HEADERS over AM_CONFIG_HEADER
* configure.ac: some versions of linux/if.h require including sys/socket.h
* sgsnemu: Fix unaligned pointer access during ip/icmp checksum
* Remove undefined param passed to {logging,osmo_stats}_vty_add_cmds
* Require libosmocore 1.1.0
[ Oliver Smith ]
* debian: create -doc subpackage with pdf manuals
* ggsn: Use gtp_delete_context_req2() everywhere
* contrib/jenkins.sh: run "make maintainer-clean"
[ Daniel Willmann ]
* manuals: Add script to regenerate vty/counter documentation
-- Pau Espin Pedrol <pespin@sysmocom.de> Wed, 07 Aug 2019 21:28:30 +0200
osmo-ggsn (1.3.0) unstable; urgency=medium
[ Pau Espin Pedrol ]
* ggsn: ctrl iface: listen on IP configured by VTY
* gtp: Log type name of unexpected signalling message
* gtp: Allow recv DEL CTX REQ in sgsn and DEL CTX RSP in ggsn
* gtp: Log ignore CTX DEL REQ due to no teardown and only 1 ctx active
* gtp: Add new API to avoid freeing pdp contexts during DEL CTX REQ
* gtp: Add new replacement cb_recovery2 for cb_recovery
* Install systemd services with autotools
* Install sample cfg file to /etc/osmocom
[ Stefan Sperling ]
* fix unaligned access in build_ipcp_pco()
* fix support for multiple IPCP in PDP protocol configuration options
* check ioctl() call return value in tun_new()
* fix allocation of ippool's hash table
* replace bogus memcpy() call in ippool_newip()
* initialize local variable addr in ippool_new()
* fix format string error in ippool_printaddr()
* fix a format string directives in queue_seqset()
* properly store IPv6 addresses in struct tun_t
[ Harald Welte ]
* debian/rules: Don't overwrite .tarball-version
* osmo-ggsn.cfg: Ensure well-formed config file example
* sgsnemu: Fix printing of tun device name
* ippool.c: Use "%td" format string for ptrdiff_t
* initial version of OsmoGGSN user manual
* OsmoGGSN: Add VTY reference manual
* GGSN: Document how 'ip tuntap' is used for non-root; call netdev 'apn0'
* vty-ref: Update URI of docbook 5.0 schema
[ Alexander Couzens ]
* libgtp: implement gtp_clear_queues to clear req/resp queue
[ Neels Hofmeyr ]
* Importing history from osmo-gsm-manuals.git
* refactor Makefile build rules, don't use the FORCE
* GGSN: don't say 'NITB'
* OsmoGGSN: more info on non-root operation / tun creation
* OsmoGGSN: multiple instances: mention GTP port
* OsmoGGSN: add Routing section for IP forward and masquerading
* OsmoGGSN: typo: priveleges
* OsmoGGSN VTY ref: prep: convert newlines to unix
* OsmoGGSN vty: update VTY reference
* OsmoGGSN: fix VTY additions' node IDs
* OsmoGGSN: update vty reference
* ggsn: update vty reference
[ Max ]
* Expand OsmoGGSN manual
[ Oliver Smith ]
* build manuals moved here from osmo-gsm-manuals.git
* Fix DISTCHECK_CONFIGURE_FLAGS override
* contrib/jenkins.sh: build and publish manuals
* contrib: fix makedistcheck with disabled systemd
-- Harald Welte <laforge@gnumonks.org> Sun, 20 Jan 2019 21:34:22 +0100
osmo-ggsn (1.2.2) unstable; urgency=medium
[ Vadim Yanitskiy ]
* ggsn_vty.c: fix: use CONFIG_NODE as parent by default
[ Philipp Maier ]
* ggsn: fix misinterpreted length field in ipcp_contains_option()
* ggsn: make sure ipcp_option_hdr and and ipcp_hdr are packed
-- Pau Espin Pedrol <pespin@sysmocom.de> Thu, 31 May 2018 12:44:54 +0200
osmo-ggsn (1.2.1) unstable; urgency=medium
* debian/rules: Fix debian packaging after 1.2.0 release
-- Pau Espin Pedrol <pespin@sysmocom.de> Fri, 04 May 2018 12:19:58 +0200
osmo-ggsn (1.2.0) unstable; urgency=medium
[ Neels Hofmeyr ]
* fix compiler warnings: return 0 in main(), in 3 tests
* add --enable-sanitize config option
* sanitize build: ensure uint16/32 alignment in gtpie_test and in46a_test
* configure: add --enable-werror
* jenkins.sh: use --enable-werror configure flag, not CFLAGS
[ Harald Welte ]
* sgsnemu: Don't leak FILE handle in proc_read()
* sgsnemu: Fix format string in printing tun-device name
* sgsnemu: Make sure buffer has space for terminating-NUL
* sgsnemu: Free strings in error path
* gtp: Fix buffer overflow in imsi_gtp2str()
* gtp: Explicit OSMO_ASSERT to ensure pdp variable is set
* tun: Don't copy 16byte IPv6 address to 'struct in_addr'
* ippool: Correctly compute size of static pool
* remove unused argument to alloc_ippool_blacklist()
* factor out netdev_ip_local_get() from tun_ip_local_get()
* Properly NULL-out blacklist in alloc_ippool_blacklist()
* gtp_kernel: Change gtp_kernel_init() function signature
* gtp-kernel: Re-add support for kernel GTP-U acceleration
* gtp-kernel: Get rid of hard-coded kernel GTP device name
* gtp-kernel: shut down kernel GTP device in apn_down()
* gtp-kernel: Align logging for APN start in kernel-gtp case with that of TUN
* gtp-kernel: Avoid global state variable
* gtp-kernel: Make sure repeated calls to gtp_kernel_init() are safe
* gtp-kernel: proper cleanup in error path
* gtp-kernel: Get rid of SYS_ERR where not applicable
* gtp-kernel: Add function name to pdp_debug() function calls
* gtp-kernel: Add device nime in pdp_debug() log statements
* contrib/jenkins.sh: Allow jenkins job to specify if kernel GTP is used
* ggsn.c: Fix byte order of IPCP IPv4 DNS servers
* ggsn: Ignore PCO with length 0, don't abort processing
* README.md: Remove misleading sentence on sgsnemu
* Add talloc context introspection via VTY
* fix segfault in case of kernel gtp-u
* lib/tun.c: Generalize tun_sifflags() to netdev_sifflags
* lib/tun.c: generalize tun_*route() to netdev_*route()
* lib/tun.c: Generalize tun_{set,add}addr*() functions
* lib/tun: split generic network device related stuff to lib/netdev
* lib/netdev.c: Cosmetic changes (coding style / cleanups)
* ggsn: Don't explicitly use tun_setaddr() API anymore
* sgsnemu: Convert from tun_setaddr() to tun_addaddr()
* lib/tun: Remove tun_setaddr() API, as everyone is using tun_addaddr() now
* Move kernel GTP support from ggsn/ to lib/
* ggsn: don't use gtp_kernel_tunnel_{add,del}() for userspace tun
[ Pau Espin Pedrol ]
* ggsn_vty: Stop using deprecated API vty_install_default
* contrib/jenkins.sh: Enable Werror in C(PP)FLAGS
* examples: Add secondary ipv6 google DNS to osmo-ggsn.cfg
* tun_setaddr6: Fix log typo
* cosmetic: Reorder tun_addaddr to get rid of decl of tun_setaddr4
* ggsn.c: Print version of unhandled ip packet
* Remove unused empty src/Makefile.in
* tests: Split ipv6 specific tests into a new test group
* Add support for IPv4v6 End User Addresses
* contrib: jenkins.sh: Build libgtpnl as dep when building with gtp kernel support
* cosmetic: sgsnemu.c: Fix trailing whitespace
* ggsn.c: Improve logging info on link-local ipv6 addr not found
* tun.c: tun_addaddr: Fix segfault and wrong usage of tun_nlattr
* Set tun_addaddr ipv agnostic and add support for ipv6
* ggsn: Add 'ipv6 link-local' vty cmd
* ggsn_vty.c: Print ipv6 link-local cmd when writing config to file
* gtp.c: Fix trailing whitespace
* gtp.c: Determine GTP version from header
* gtp.c: Log unsupported GTP version number
* gtp/pdp: Fix trailing whitespace
* gtp/pdp: Remove unused APIs pdp_ntoeua pdp_euaton
* gtp.c: gtp_gpdu_ind: Convert ifelse to switch statement
* gtp.c: gtp_gpdu_ind: Early return to avoid use of uninitialized var
* gtp/gtp.c: Remove unused function char2ul_t
* gtp/gtp.c: Mark non exported functions as static
* gtp/gtp.c: Use uint8_t for version param in static functions
* ggsn: encaps_tun: Avoid forwarding packet if EUA is unassigned, fix crash
* ggsn: Validate packet src addr from MS
* ggsn: Parse PCO_IPCP
* ggsn: Parse PCO_IPCP for IPv4v6 pdp ctx
* ggsn: Print all addresses on successful pdp ctx creation
* ggsn.c: cb_tun_ind: Convert ifelse to switch statement
* ggsn.c: cb_tun_ind: log dst addr of packet without pdp ctx
* ggsn.c: cb_tun_ind: Don't drop packets targeting pdp ctx ll addr
* sgsnemu: Fix bad ptr during context deallocation
* sgsnemu: listen param is a host, not an interface
* use osmo_init_logging2
[ Max ]
* Log APN and tun names for packets
* Enable sanitize for CI tests
* Fix stow-enabled jenkins build failure
* Add GTP message names
[ Viktor Tsymbalyuk ]
* sgsnemu: sgsnemu stopped after recieving "Request accepted" from ggsn
* sgsnemu: created "pinghost" and "createif" modes for mutual exclusion
* sgsnemu: fix: no outgoing GTP-U in "createif" mode
[ Martin Hauke ]
* build: Remove AC_PROG_CXX, C++ is never used
[ Stefan Sperling ]
* remove the -f option from osmo-ggsn.service
-- Pau Espin Pedrol <pespin@sysmocom.de> Thu, 03 May 2018 16:05:27 +0200
osmo-ggsn (1.1.0) unstable; urgency=medium
* libgtp: pdp.h: Addition of new tx_gpdu_seq struct member member

2
debian/compat vendored
View File

@@ -1 +1 @@
9
10

44
debian/control vendored
View File

@@ -1,16 +1,18 @@
Source: osmo-ggsn
Maintainer: Harald Welte <laforge@gnumonks.org>
Maintainer: Osmocom team <openbsc@lists.osmocom.org>
Section: net
Priority: optional
Build-Depends: debhelper (>= 9),
Build-Depends: debhelper (>= 10),
autotools-dev,
pkg-config,
libdpkg-perl, git,
dh-autoreconf,
libosmocore-dev (>= 0.8.0)
libosmocore-dev (>= 1.11.0),
osmo-gsm-manuals-dev (>= 1.6.0),
libgtpnl-dev (>= 1.3.0)
Standards-Version: 3.9.6
Vcs-Browser: http://git.osmocom.org/osmo-ggsn/
Vcs-Git: git://git.osmocom.org/osmo-ggsn
Vcs-Browser: https://gitea.osmocom.org/cellular-infrastructure/osmo-ggsn
Vcs-Git: https://gitea.osmocom.org/cellular-infrastructure/osmo-ggsn
Homepage: https://projects.osmocom.org/projects/openggsn
Package: osmo-ggsn
@@ -22,7 +24,7 @@ Description: Osmocom Gateway GPRS Support Node (GGSN)
operators as the interface between the Internet and the rest of the
mobile network infrastructure.
Package: libgtp2
Package: libgtp11
Architecture: any
Multi-Arch: same
Section: libs
@@ -36,12 +38,18 @@ Description: library implementing the GTP protocol between SGSN and GGSN
This library is part of OsmoGGSN and implements the GTP protocol between
SGSN (Serving GPRS support node) and GGSN.
Package: gtp-echo-responder
Architecture: any
Depends: ${shlibs:Depends},
${misc:Depends}
Description: Small program answering GTP ECHO Request with GTP ECHO Response
Package: libgtp-dev
Architecture: any
Multi-Arch: same
Section: libdevel
Depends: ${misc:Depends},
libgtp2 (= ${binary:Version})
libgtp11 (= ${binary:Version})
Description: Development files for libgtp
OsmoGGSN is a Gateway GPRS Support Node (GGSN). It is used by mobile
operators as the interface between the Internet and the rest of the
@@ -54,18 +62,27 @@ Package: osmo-ggsn-dbg
Section: debug
Architecture: any
Priority: extra
Depends: ${shlibs:Depends}, ${misc:Depends}, libgtp2 (= ${binary:Version}), osmo-ggsn (= ${binary:Version})
Depends: ${shlibs:Depends}, ${misc:Depends}, libgtp11 (= ${binary:Version}), osmo-ggsn (= ${binary:Version})
Multi-Arch: same
Description: Debug symbols for OsmoGGSN
OsmoGGSN is a Gateway GPRS Support Node (GGSN). It is used by mobile
operators as the interface between the Internet and the rest of the
mobile network infrastructure.
Package: gtp-echo-responder-dbg
Section: debug
Architecture: any
Priority: extra
Depends: ${shlibs:Depends}, ${misc:Depends}, gtp-echo-responder (= ${binary:Version})
Multi-Arch: same
Description: Debug symbols for gtp-echo-responder
Small program answering GTP ECHO Request with GTP ECHO Response.
Package: libgtp-dbg
Section: debug
Architecture: any
Priority: extra
Depends: ${shlibs:Depends}, ${misc:Depends}, libgtp2 (= ${binary:Version})
Depends: ${shlibs:Depends}, ${misc:Depends}, libgtp11 (= ${binary:Version})
Multi-Arch: same
Description: Debug symbols for OsmoGGSN
OsmoGGSN is a Gateway GPRS Support Node (GGSN). It is used by mobile
@@ -74,3 +91,12 @@ Description: Debug symbols for OsmoGGSN
.
The library libgtp implements the GTP protocol between SGSN and GGSN
and this package contains the development files for this library.
Package: osmo-ggsn-doc
Architecture: all
Section: doc
Priority: optional
Depends: ${misc:Depends}
Description: ${misc:Package} PDF documentation
Various manuals: user manual, VTY reference manual and/or
protocol/interface manuals.

5
debian/copyright vendored
View File

@@ -16,6 +16,11 @@ Files: lib/getopt.c
Copyright: 1987-2001 Free Software Foundation, Inc.
License: LGPL-2.1+
Files: utils/gtp_echo_responder.c
utils/gtp_echo_responder_test.py
Copyright: 2021 sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
License: MIT
Files: debian/*
Copyright: 2010-2017 Harald Welte <laforge@gnumonks.org>
2016 Ruben Undheim <ruben.undheim@gmail.com>

1
debian/gtp-echo-responder.install vendored Normal file
View File

@@ -0,0 +1 @@
/usr/bin/gtp-echo-responder

2
debian/libgtp11.shlibs vendored Normal file
View File

@@ -0,0 +1,2 @@
# Most recent version of the package that added new symbols (OS#5318)
libgtp 11 libgtp11 (>= 1.13.0)

1
debian/osmo-ggsn-doc.install vendored Normal file
View File

@@ -0,0 +1 @@
usr/share/doc/osmo-ggsn-doc/*.pdf

View File

@@ -1,2 +1,3 @@
doc/examples/osmo-ggsn.cfg
doc/examples/osmo-ggsn-kernel-gtp.cfg
doc/examples/sgsnemu.conf

163
debian/osmo-ggsn.init vendored
View File

@@ -1,163 +0,0 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: osmo-ggsn
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Gateway GPRS Support Node
# Description: Gateway GPRS Support Node
### END INIT INFO
# Author: Harald Welte <laforge@gnumonks.org>
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="OsmoGGSN Gateway GPRS Support Node"
NAME=ggsn
DAEMON=/usr/bin/osmo-ggsn
DAEMON_ARGS="" # Arguments to run the daemon with
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/osmo-ggsn
# Exit if the package is not installed
[ -x $DAEMON ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/osmo-ggsn ] && . /etc/default/osmo-ggsn
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
DAEMON_ARGS="$DAEMON_ARGS"
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
# Check for runtime directory of nonvolatile data
if [ ! -d /var/lib/osmo-ggsn ]; then
mkdir /var/lib/osmo-ggsn
fi
# Check for GTP restart counter
if [ ! -f /var/lib/osmo-ggsn/gsn_restart ]; then
echo 0 > /var/lib/osmo-ggsn/gsn_restart
fi
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some time.
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
#log_daemon_msg "Reloading $DESC" "$NAME"
#do_reload
#log_end_msg $?
#;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
:

View File

@@ -1,3 +1,5 @@
/etc/osmocom/osmo-ggsn.cfg
/lib/systemd/system/osmo-ggsn.service
/usr/bin/osmo-ggsn
/usr/bin/sgsnemu
/usr/share/man/man8/*

View File

@@ -1 +0,0 @@
../contrib/osmo-ggsn.service

39
debian/postinst vendored Executable file
View File

@@ -0,0 +1,39 @@
#!/bin/sh -e
case "$1" in
configure)
# Create the osmocom group and user (if it doesn't exist yet)
if ! getent group osmocom >/dev/null; then
groupadd --system osmocom
fi
if ! getent passwd osmocom >/dev/null; then
useradd \
--system \
--gid osmocom \
--home-dir /var/lib/osmocom \
--shell /sbin/nologin \
--comment "Open Source Mobile Communications" \
osmocom
fi
# Fix permissions of previous (root-owned) install (OS#4107)
if dpkg --compare-versions "$2" le "1.13.0"; then
if [ -e /etc/osmocom/osmo-ggsn.cfg ]; then
chown -v osmocom:osmocom /etc/osmocom/osmo-ggsn.cfg
chmod -v 0660 /etc/osmocom/osmo-ggsn.cfg
fi
if [ -d /etc/osmocom ]; then
chown -v root:osmocom /etc/osmocom
chmod -v 2775 /etc/osmocom
fi
mkdir -p /var/lib/osmocom
chown -R -v osmocom:osmocom /var/lib/osmocom
fi
;;
esac
# dh_installdeb(1) will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#

14
debian/rules vendored
View File

@@ -16,8 +16,14 @@ export DEB_BUILD_MAINT_OPTIONS = hardening=+all
override_dh_strip:
dh_strip -posmo-ggsn --dbg-package=osmo-ggsn-dbg
dh_strip -plibgtp2 --dbg-package=libgtp-dbg
dh_strip -plibgtp11 --dbg-package=libgtp-dbg
override_dh_autoreconf:
echo $(VERSION) > .tarball-version
dh_autoreconf
override_dh_auto_configure:
dh_auto_configure -- \
--enable-gtp-linux \
--with-systemdsystemunitdir=/lib/systemd/system \
--enable-manuals
# Don't create .pdf.gz files (barely saves space and they can't be opened directly by most pdf readers)
override_dh_compress:
dh_compress -X.pdf

View File

@@ -4,4 +4,5 @@ EXTRA_DIST = $(man_MANS)
SUBDIRS = \
examples \
manuals \
$(NULL)

View File

@@ -1,4 +1,13 @@
CFG_FILES = find $(srcdir) -name '*.cfg*' | sed -e 's,^$(srcdir),,'
OSMOCONF_FILES = \
osmo-ggsn.cfg \
$(NULL)
osmoconfdir = $(sysconfdir)/osmocom
osmoconf_DATA = $(OSMOCONF_FILES)
EXTRA_DIST = $(OSMOCONF_FILES)
CFG_FILES = find $(srcdir) -name '*.cfg' -o -name '*.conf' | sed -e 's,^$(srcdir),,'
dist-hook:
for f in $$($(CFG_FILES)); do \

View File

@@ -13,36 +13,36 @@
# to and from the Gn interface.
# * Masquerede on Gi interface.
IPTABLES="/sbin/iptables"
NFT="nft"
IFGN="eth0"
IFGI="eth1"
$IPTABLES -P INPUT DROP
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -P OUTPUT ACCEPT
$NFT add chain ip filter input '{ policy drop; }'
$NFT add chain ip filter forward '{ policy accept; }'
$NFT add chain ip filter output '{ policy accept; }'
#Allow related and established on all interfaces (input)
$IPTABLES -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
$NFT add rule ip filter input ct state related,established counter accept
#Allow releated, established, GTP and ssh on $IFGN. Reject everything else.
$IPTABLES -A INPUT -i $IFGN -p tcp -m tcp --dport 22 --syn -j ACCEPT
$IPTABLES -A INPUT -i $IFGN -p udp -m udp --dport 2123 -j ACCEPT
$IPTABLES -A INPUT -i $IFGN -p udp -m udp --dport 2152 -j ACCEPT
$IPTABLES -A INPUT -i $IFGN -p udp -m udp --dport 3386 -j ACCEPT
$IPTABLES -A INPUT -i $IFGN -j REJECT
$NFT add rule ip filter input iifname $IFGN tcp dport 22 tcp flags syn / fin,syn,rst,ack counter accept
$NFT add rule ip filter input iifname $IFGN udp dport 2123 counter accept
$NFT add rule ip filter input iifname $IFGN udp dport 2152 counter accept
$NFT add rule ip filter input iifname $IFGN udp dport 3386 counter accept
$NFT add rule ip filter input iifname $IFGN counter reject
#Allow related, established and ssh. Drop everything else.
$IPTABLES -A INPUT -i $IFGI -p tcp -m tcp --dport 22 --syn -j ACCEPT
$IPTABLES -A INPUT -i $IFGI -j DROP
$NFT add rule ip filter input iifname $IFGI tcp dport 22 tcp flags syn / fin,syn,rst,ack counter accept
$NFT add rule ip filter input iifname $IFGI counter drop
# Masquerade everything going out on $IFGI
$IPTABLES -t nat -A POSTROUTING -o $IFGI -j MASQUERADE
$NFT add rule ip nat POSTROUTING oifname $IFGI counter masquerade
#Allow everything on loopback interface.
$IPTABLES -A INPUT -i lo -j ACCEPT
$NFT add rule ip filter input iifname "lo" counter accept
# Drop everything to and from $IFGN (forward)
$IPTABLES -A FORWARD -i $IFGN -j DROP
$IPTABLES -A FORWARD -o $IFGN -j DROP
$NFT add rule ip filter forward iifname $IFGN counter drop
$NFT add rule ip filter forward oifname $IFGN counter drop

View File

@@ -0,0 +1,54 @@
!
! OpenGGSN (0.94.1-adac) configuration saved from vty
!!
!
log stderr
logging color 1
logging print category-hex 0
logging print category 1
logging timestamp 0
logging print file basename last
logging print level 1
logging level ip info
logging level tun info
logging level ggsn info
logging level sgsn notice
logging level icmp6 notice
logging level lglobal notice
logging level llapd notice
logging level linp notice
logging level lmux notice
logging level lmi notice
logging level lmib notice
logging level lsms notice
logging level lctrl notice
logging level lgtp info
logging level lstats notice
logging level lgsup notice
logging level loap notice
logging level lss7 notice
logging level lsccp notice
logging level lsua notice
logging level lm3ua notice
logging level lmgcp notice
!
stats interval 5
!
line vty
no login
!
ggsn ggsn0
gtp state-dir /var/lib/osmocom/osmo-ggsn
gtp bind-ip 127.0.0.2
apn internet
gtpu-mode kernel-gtp
tun-device tun4
type-support v4
mtu default apply
ip prefix dynamic 172.16.222.0/24
ip dns 0 8.8.8.8
ip dns 1 8.8.4.4
ip ifconfig 172.16.222.0/24
no shutdown
default-apn internet
no shutdown ggsn

View File

@@ -3,32 +3,34 @@
!!
!
log stderr
logging filter all 1
logging color 1
logging print category 0
logging timestamp 0
logging level ip info
logging level tun info
logging level ggsn info
logging level sgsn notice
logging level icmp6 notice
logging level lglobal notice
logging level llapd notice
logging level linp notice
logging level lmux notice
logging level lmi notice
logging level lmib notice
logging level lsms notice
logging level lctrl notice
logging level lgtp info
logging level lstats notice
logging level lgsup notice
logging level loap notice
logging level lss7 notice
logging level lsccp notice
logging level lsua notice
logging level lm3ua notice
logging level lmgcp notice
logging color 1
logging print category-hex 0
logging print category 1
logging timestamp 0
logging print file basename last
logging print level 1
logging level ip info
logging level tun info
logging level ggsn info
logging level sgsn notice
logging level icmp6 notice
logging level lglobal notice
logging level llapd notice
logging level linp notice
logging level lmux notice
logging level lmi notice
logging level lmib notice
logging level lsms notice
logging level lctrl notice
logging level lgtp info
logging level lstats notice
logging level lgsup notice
logging level loap notice
logging level lss7 notice
logging level lsccp notice
logging level lsua notice
logging level lm3ua notice
logging level lmgcp notice
!
stats interval 5
!
@@ -36,21 +38,23 @@ line vty
no login
!
ggsn ggsn0
gtp state-dir /tmp
gtp bind-ip 127.0.0.6
gtp state-dir /var/lib/osmocom/osmo-ggsn
gtp bind-ip 127.0.0.2
apn internet
gtpu-mode tun
tun-device tun4
type-support v4
ip prefix dynamic 176.16.222.0/24
ip dns 0 192.168.100.1
ip dns 1 8.8.8.8
ip ifconfig 176.16.222.0/24
mtu default apply
ip prefix dynamic 172.16.222.0/24
ip dns 0 8.8.8.8
ip dns 1 8.8.4.4
ip ifconfig 172.16.222.0/24
no shutdown
apn inet6
gtpu-mode tun
tun-device tun6
type-support v6
mtu default apply
ipv6 prefix dynamic 2001:780:44:2000:0:0:0:0/56
ipv6 dns 0 2001:4860:4860::8888
ipv6 dns 1 2001:4860:4860::8844
@@ -60,10 +64,11 @@ ggsn ggsn0
gtpu-mode tun
tun-device tun46
type-support v4v6
ip prefix dynamic 176.16.46.0/24
ip dns 0 192.168.100.1
ip dns 1 8.8.8.8
ip ifconfig 176.16.46.0/24
mtu default apply
ip prefix dynamic 172.16.46.0/24
ip dns 0 8.8.8.8
ip dns 1 8.8.4.4
ip ifconfig 172.16.46.0/24
ipv6 prefix dynamic 2001:780:44:2100:0:0:0:0/56
ipv6 dns 0 2001:4860:4860::8888
ipv6 dns 1 2001:4860:4860::8844

24
doc/manuals/Makefile.am Normal file
View File

@@ -0,0 +1,24 @@
EXTRA_DIST = osmoggsn-usermanual.adoc \
osmoggsn-usermanual-docinfo.xml \
osmoggsn-vty-reference.xml \
regen_doc.sh \
chapters \
vty
if BUILD_MANUALS
ASCIIDOC = osmoggsn-usermanual.adoc
ASCIIDOC_DEPS = $(srcdir)/chapters/*.adoc
include $(OSMO_GSM_MANUALS_DIR)/build/Makefile.asciidoc.inc
VTY_REFERENCE = osmoggsn-vty-reference.xml
BUILT_REFERENCE_XML = $(builddir)/vty/ggsn_vty_reference.xml
$(builddir)/vty/ggsn_vty_reference.xml: $(top_builddir)/ggsn/osmo-ggsn
mkdir -p $(builddir)/vty
$(top_builddir)/ggsn/osmo-ggsn --vty-ref-xml > $@
include $(OSMO_GSM_MANUALS_DIR)/build/Makefile.vty-reference.inc
OSMO_REPOSITORY=osmo-ggsn
include $(OSMO_GSM_MANUALS_DIR)/build/Makefile.common.inc
endif

View File

@@ -0,0 +1,346 @@
[[osmoggsn_configuring]]
== Configuring OsmoGGSN
All configuration of OsmoGGSN is performed using the VTY. For more
general information on the VTY interface, see <<vty>>.
=== Configuring a virtual GGSN instance
OsmoGGSN can run multiple GGSN instances inside one program/process.
Each GGSN instance binds to its own transport-layer GTP IP address and
has its own set of APNs and associated IP address pools + tun/gtp
devices.
In most usage cases, yo will only have a single GGSN instance inside
your configuration file, like in below example:
.Example: Single GGSN configuration section
----
ggsn ggsn0
gtp state-dir /var/lib/osmocom/osmo-ggsn
gtp bind-ip 127.0.0.6
apn internet
gtpu-mode tun
tun-device tun4
type-support v4
mtu default apply
ip prefix dynamic 176.16.222.0/24
ip dns 0 192.168.100.1
ip dns 1 8.8.8.8
ip ifconfig 176.16.222.0/24
no shutdown
----
==== Creating/Editing a GGSN instance
Creating/Editing a GGSN instance can be done by the following sequence
of VTY commands:
----
OsmoGGSN> enable <1>
OsmoGGSN# configure terminal <2>
OsmoGGSN(config)# ggsn ggsn0 <3>
OsmoGGSN(config-ggsn)# <4>
----
<1> Change into privileged mode
<2> Enter the interactive configuration mode
<3> Create or edit the GGSN instance `ggsn0`. The name can be any ASCII
string, its significance is only to the local user.
<4> Your prompt is now in the `ggsn` config node, where you can
configure the properties of this GGSN instance.
NOTE:: After creating a new GGSN instance, it is in `shutdown` mode. See
<<unshutdown_apn>> to take it out of shutdown, but make sure to configure it fully
before taking it out of shutdown.
==== Configuring a GGSN instance
The following two mandatory configuration statements have to be given
for every GGSN instance:
----
OsmoGGSN(config-ggsn)# gtp state-dir /var/lib/osmocom/osmo-ggsn <1>
OsmoGGSN(config-ggsn)# gtp bind-ip 127.0.0.6 <2>
----
<1> Store the GSN restart state in the specified directory
<2> Bind the GGSN instance to the specified local IPv4 address
There are some further configuration statements that can be used at the
GGSN node, some examples are given below. For a full list, see the
_OsmoGGSN VTY reference manual_ <<vty-ref-osmoggsn>>.
----
OsmoGGSN(config-ggsn)# default-apn foobar <1>
----
<1> Configure a default APN to be used if the user-requested APN is not
found. The named APN must previously be configured
==== Deleting a GGSN instance
A GGSN instance can be removed like this
.Example: Deleting a GGSN instance
----
OsmoGGSN> enable <1>
OsmoGGSN# configure terminal <2>
OsmoGGSN(config)# no ggsn ggsn0 <3>
----
<1> Change into privileged mode
<2> Enter the interactive configuration mode
<3> Delete the GGSN instance
==== Taking a GGSN instance out of shutdown
.Example: Taking a GGSN instance out of shutdown
----
OsmoGGSN> enable <1>
OsmoGGSN# configure terminal <2>
OsmoGGSN(config)# ggsn ggsn0 <3>
OsmoGGSN(config-ggsn)# no shutdown ggsn <4>
----
<1> Change into privileged mode
<2> Enter the interactive configuration mode
<3> Enter the config node of the GGSN instance `ggsn0`
<4> Take the GGSN instance out of shutdown
==== Shutting a GGSN instance down
If you would like to take a GGSN instance out of service, you can
put it into shutdown mode. This will make the entire GGSN unavailable
to user traffic and permit you to e.g. reconfigure it before taking it
out of shutdown again.
.Example: Shutting down a GGSN instance
----
OsmoGGSN> enable <1>
OsmoGGSN# configure terminal <2>
OsmoGGSN(config)# ggsn ggsn0 <3>
OsmoGGSN(config-ggsn)# shutdown ggsn <4>
----
<1> Change into privileged mode
<2> Enter the interactive configuration mode
<3> Enter the config node of the GGSN instance `ggsn0`
<4> Shut down the GGSN instance
=== Configuring an Access Point Name
An Access Point Name (APN) represents a connection to an external packet
data network, such as the public Internet or private corporate networsk.
APNs are selected by terminals (MS/UE) when establishing PDP contexts.
Each OsmoGGSN GGSN instance can have any number of APNs configured.
Each APN is identified by a string name.
==== Creating/Editing an APN
.Example: Creating a new APN
----
OsmoGGSN> enable <1>
OsmoGGSN# configure terminal <2>
OsmoGGSN(config)# ggsn ggsn0 <3>
OsmoGGSN(config-ggsn)# apn internet <4>
OsmoGGSN(config-ggsn-apn)# <5>
----
<1> Change into privileged mode
<2> Enter the interactive configuration mode
<3> Enter the config node of the GGSN instance `ggsn0`
<4> Create or Edit an APN called `internet`
<5> Your prompt is now in the `ggsn` config node, where you can
configure the properties of this GGSN instance.
NOTE:: The newly-create APN is created in `shutdown` mode. See <<unshutdown_apn>> to take it
out of shutdown.
==== Configuring an APN
.Example: Configuring an APN
----
OsmoGGSN(config-ggsn-apn)# gtpu-mode tun <1>
OsmoGGSN(config-ggsn-apn)# type-support v4 <2>
OsmoGGSN(config-ggsn-apn)# mtu 1420 apply <3>
OsmoGGSN(config-ggsn-apn)# ip prefix dynamic 176.16.222.0/24 <4>
OsmoGGSN(config-ggsn-apn)# ip dns 0 192.168.100.1 <5>
OsmoGGSN(config-ggsn-apn)# ip dns 1 8.8.8.8 <6>
OsmoGGSN(config-ggsn-apn)# ip ifconfig 176.16.222.0/24 <7>
----
<1> Use the userspace GTP-U handling using a TUN device
<2> Support (only) IPv4 Addresses
<3> Specify MTU to announce to MS. Apply the MTU on the tunnel interface.
<4> Specify the pool of dynamic IPv4 addresses to be allocated to PDP
contexts
<5> Specify the primary DNS server to be provided using IPCP/PCO
<6> Specify the secondary DNS server to be provided using IPCP/PCO
<7> Request OsmoGGSN to configure the `tun4` device network/netmask
NOTE:: If you use the optional `ip ifconfig` command to set the network
device address/mask, OsmoGGSN must run with root or `CAP_NET_ADMIN`
support. It might be better to configure related tun devices at system
startup and run OsmoGGSN as non-privileged user. See <<ggsn_no_root>> for more
details.
==== Deleting an APN
An APN configuration can be removed like this
.Example: Deleting an APN
----
OsmoGGSN> enable <1>
OsmoGGSN# configure terminal <2>
OsmoGGSN(config)# ggsn ggsn0 <3>
OsmoGGSN(config-ggsn)# no apn internet <4>
----
<1> Change into privileged mode
<2> Enter the interactive configuration mode
<3> Enter the config node of the GGSN instance `ggsn0`
<4> Delete the APN `internet`
[[unshutdown_apn]]
==== Taking an APN out of shutdown
In order to bring a deactived APN in `shutdown` state into active
operation, use the `no shutdown` command at the APN node as explained in
the following example:
.Example: Taking an APN out of shutdown
----
OsmoGGSN> enable <1>
OsmoGGSN# configure terminal <2>
OsmoGGSN(config)# ggsn ggsn0 <3>
OsmoGGSN(config-ggsn)# apn internet <4>
OsmoGGSN(config-ggsn-apn)# no shutdown <5>
----
<1> Change into privileged mode
<2> Enter the interactive configuration mode
<3> Enter the config node of the GGSN instance `ggsn0`
<4> Enter the config node of the APN `internet`
<5> Take the APN out of shutdown
==== Shutting an APN down
If you would like to take an APN instance out of service, you can
put it into shutdown mode. This will make the APN unavailable
to user traffic and permit you to e.g. reconfigure it before taking it
out of shutdown again.
.Example: Shutting down an APN
----
OsmoGGSN> enable <1>
OsmoGGSN# configure terminal <2>
OsmoGGSN(config)# ggsn ggsn0 <3>
OsmoGGSN(config-ggsn)# apn internet <4>
OsmoGGSN(config-ggsn-apn)# shutdown <5>
----
<1> Change into privileged mode
<2> Enter the interactive configuration mode
<3> Enter the config node of the GGSN instance `ggsn0`
<4> Enter the config node of the APN `internet`
<5> Shut down the APN
[[ggsn_no_root]]
=== Configuring for running without root privileges
It's possible to run OsmoGGSN without root privileges if the tun devices are already configured.
The interface creation + configuration must then happen before osmo-ggsn starting up. This can be
achieved by means such as
* a custom shell script run as root before starting osmo-ggsn (e.g. as init script)
* systemd .netdev and .network files, if your system is using systemd-networkd (see `networkctl status`).
==== Manual TUN device creation / configuration
If you chose to go for custom shell/init scripts, you may use the `ip` program which is the standard
tool for network interface configuration on Linux, part of the `iproute2` package. In order to
create a tun device, you must call it like this:
.Example: iproute2 command to create a tun device
----
# ip tuntap add dev apn0 mode tun user username group groupname
----
Where _username_ and _groupname_ correspond to the User and Group that will have ownership over the
device, i.e. the privileges which you intend to run osmo-ggsn under, and _apn0_ will be the
name of the network device created. After creating the interface, you can configure its addresses
using standard means like `ip addr add` or your distribution-specific utilities/tools
to match the `ip prefix dynamic` config item, and activate the link, for example:
----
# ip addr add 192.168.7.1/24 dev apn0
# ip link set mtu 1420 dev apn0
# ip link set apn0 up
----
==== systemd based TUN device creation+configuration
If you want to have systemd take care of creating and configuring a tun device for you,
you can use the below example config files.
.Example: device config via systemd-networkd using apn0.netdev
----
[NetDev]
Name=apn0 <1>
Kind=tun
[Tun]
User=username <2>
Group=username <3>
----
<1> The network interface name of the newly-created device
<2> The username under which you will run OsmoGGSN
<3> The group name under which you will run OsmoGGSN
.Example: network settings via systemd-networkd using ggsn.network
----
[Match]
Name=apn0 <1>
[Link]
MTUBytes=1420 <2>
[Network]
Address=192.168.7.1/24 <3>
IPMasquerade=yes <4>
----
<1> The network device name, which must match the one in the apn0.netdev unit file above
<2> Requesting systemd to set the MTU for this interface. The MTU of the tun
interface should be lower than regular, since it must accommodate the extra IP/UDP/GTPv1U headers.
<3> The local IP address configured on the device
<4> Requesting systemd to configure IP masquerading for this interface. Depending on your needs,
You may not want this if you have proper end-to-end routing set up, and want to have transparent
inbound IP access to your GPRS-attached devices.
==== Config Changes
With the tun device pre-configured in one of the ways outlined above, the main
changes in your osmo-ggsn.cfg file are:
* remove `ip ifconfig` directive,
* make sure that `no shutdown` is present in the `apn` section as well as
`no shutdown ggsn` in the `ggsn` section.
.Example: using externally configured tun device `apn0` as non-root
----
ggsn ggsn0
gtp state-dir /tmp
gtp bind-ip 127.0.0.6
apn internet
gtpu-mode tun
tun-device apn0
type-support v4
mtu 1420
ip prefix dynamic 192.168.7.0/24
ip dns 0 192.168.100.1
ip dns 1 8.8.8.8
no shutdown
default-apn internet
no shutdown ggsn
----

View File

@@ -0,0 +1,171 @@
=== MTU considerations
When running OsmoGGSN, the user may want to take network Maximum Transmission
Unit (MTU) into consideration, and configure it based on network specific setup.
Applying and announcing a proper MTU provides, for the MS employing it, reduced
transmission overhead (ie. due to IP fragmentation) and avoids potential
problems due to misconfigured nodes in the path (e.g. ICMP packet filtering).
In OsmoGGSN, the MTU can be configured per APN through the VTY, see
<<osmoggsn_configuring>>. If told so by the config, osmo-ggsn will apply the MTU
on the APN network interface.
==== MTU announced to MS
The configured MTU is also announced to the MS through:
* IPv4 APN: GTPv1C Create PDP Context Response, PCO IE "IPv4 Link MTU", 3GPP TS
24.008 Table 10.5.154.
* IPv6 APN: ICMPv6 Routing Advertisement during IPv6 SLAAC procedure, RFC 4861.
NOTE: It is up to the MS to request and use the link MTU size provided by the
network. Hence, providing an MTU size does not guarantee that there will be no
packets larger than the provided value.
==== GTP-U tunnel overhead
OsmoGGSN is encapsulating traffic over GTP-U, it means the packets being received,
encapsulated and transmitted over the tunnel get their size increased by the sum of
IP/UDP/GTPv1U headers being prepended:
* IP: IPv4 headers can take up to 60 bytes (due to IPv4 options). IPv6 headers
can take up to 40 bytes (assuming no extension headers for IPv6 in general,
since they are uncommon). Hence, the 60 bytes of IPv4 are picked since that's
greater than the IPv4.
* UDP: The UDP header takes 8 bytes.
* GTPv1U: The GTPv1U header takes 12 bytes, assuming here no extensions headers
are used (OsmoGGSN doesn't use them).
Hence, these headers add an overhead of up to `80`` bytes, as per the below formula:
----
GTPv1U_OVERHEAD = 60 + 8 + 12 = 80 bytes
----
==== Figuring out optimal MTU value
There is no golden MTU value, since it really depends on the local (and remote)
networks where traffic is routed. The idea is finding out a value that:
* Is as big as possible, to avoid need to split big chunks of data into lots of
small packets, hence affecting performance due to processing overhead: extra
headers being trnasmitted, plus processing of extra packets.
* Is small enough so that it can be transported over the lower layers of the
links involving the communication, avoiding IP fragmentation, which again hurts
performance.
OsmoGGSN, by default, assumes that traffic is transported over an Ethernet
network, which has a standarized maximum MTU of 1500 bytes. Hence, by default it
announces an MTU of of `1420` bytes as per the following formula:
----
TUNNEL_MTU = ETH_MTU - GTPv1U_OVERHEAD = 1500 - 80 = 1420 bytes
----
Under certain networks, the base MTU may already be smaller than Ethernet's MTU
(1500 bytes), due to, for instance, existence of some sort of extra tunneling
protocol in the path, such as a VPN, ipsec, extra VLAN levels, etc. Under this
scenario, the user must take care of figuring out the new base MTU value to use
for the calculations presented above. This can be accomplished by packet
inspection (eg. `wireshark`) or with tools such as `ping`, running it with a
certain packet size and the IPv4 DF bit set, and see up to which packet size the
networks is able to forward the message.
.Example: Test if packets of 1420 bytes can reach peer host 176.16.222.4
----
$ ping -M probe 176.16.222.4 -s 1420
----
=== Increasing outer MTU
Specifications at IEEE 802.3 establish that standard Ethernet has a maximum MTU
of `1500` bytes.
However, many Ethernet controllers can nowadays overcome this limit and allow
the use of so called _jumbo frames_. The _jumbo frames_ maximum MTU varies
depending on the implementation, with `9000` bytes being a commonly used limit.
Note that using MTUs over the standarized `1500` bytes by means of _jumbo frames_
can create interoperability problems with networks not supporting such frames
(eg. forcing of IP packet fragmentation), plus the fact that larger frames
consume more Ethernet link transmission time, causing greater delays and
increasing latency.
Nevertheless, if the operator:
* is in control of the whole GTP-U path between OsmoGGSN and the MS, and
* has Ethernet NICs supporting MTUs bigger than 1500 or uses any other link
layer supporting as well bigger MTUs.
Then, it may be wise for the operator to configure such links with an increased
outer MTU so that they can end up transporting GTP-U inner payload of 1500 bytes
without fragmentation ocurring.
Hence, following the examples presented on the above sections, one could
configure *all the links* which are part of the GTP-U path to use an outer MTU
of `1580` bytes, as per the following formula:
----
TUNNEL_MTU = ETH_MTU + GTPv1U_OVERHEAD = 1500 + 80 = 1580 bytes
----
.Example: Setting an MTU of `1580` to network interface `eth0` under Linux
----
ip link set mtu 1580 dev eth0
----
==== TCP MSS Clamping
Usually endpoints use Path MTU Discovery (PMTUD) to determine the maximum MTU to
reach the peer. However, this technique may sometimes not be optimal for all
users of OsmoGGSN:
* MS may not support requesting and/or configuring the MTU OsmoGGSN announced.
* MS may not support PMTUD on its network stack, or may not have it enabled or
may be buggy.
* Network may be misconfigured or some middlebox may be buggy (eg. not
forwarding ICMP `Packet Too Big` packets).
Furthermore, PMTUD takes time to figure out the maximum MTU to use, since it
relies on sending data and checking if it got lost, and adapting to the fact,
reducing efficiency (throughput) of connections or even stalling them completely
when big packets are generated.
Hence, it may become useful for the operator of OsmoGGSN to, on top of MTU
configuration, also configure its network to tune TCP Maximum Segment Size (MSS)
option of TCP connections being established over the GTPv1U tunnel. This will
make sure at least TCP connections can use the full capacity of the path MTU
without passing its imit.
The MSS TCP option is an optional parameter in the TCP header sent during TCP
initial handshake (`SYN,SYN/ACK`) that specifies the maximum amount of bytes of
TCP payload a TCP chunk may transport. The MSS value doesn't count the
underlaying IP/TCP headers.
Hence, following up on MTU size calculations from previous section, with a
sample GTPv1U MTU of 1420 bytes and IP header of 60 bytes, plus taking into
account that TCP header can span up to 56 bytes, we'd get to an MSS value of:
----
MSS = TUNNEL_MTU - IP_HDR - TCP_HDR = 1420 - 60 - 56 = 1304
----
In linux, the MSS of TCP connections can be clamped using nftables:
----
nft 'add rule ip nat prerouting iifname "apn0" tcp flags syn / syn,rst counter tcp option maxseg size set 1304'
nft 'insert rule ip nat postrouting oifname "apn0" tcp flags syn / syn,rst counter tcp option maxseg size set 1304'
nft 'add rule ip6 nat prerouting iifname "apn0" tcp flags syn / syn,rst counter tcp option maxseg size set 1304'
nft 'insert rule ip6 nat postrouting oifname "apn0" tcp flags syn / syn,rst counter tcp option maxseg size set 1304'
----
==== Further Reading
Check the following specs regarding MTU in 3GPP mobile networks:
* 3GPP TS 29.061 section 11.2.1.5
* 3GPP TS 290.060 section 13.2 IP Fragmentation
* 3GPP TS 25.414 section 6.1.3.3
* 3GPP TS 23.060 section 9.3, Annex C
* 3GPP TS 24.008 (PCO IPv4 MTU)
* RFC 4861 (IPv6 Router Advertisement)

View File

@@ -0,0 +1,140 @@
[[chapter_introduction]]
== Overview
[[intro_overview]]
=== About OsmoGGSN
OsmoGGSN is a Free / Open Source Software implementation of the GPRS
GGSN (Gateway GPRS support node) element in side the packet switched
core network of 2G and 3G cellular networks.
The GGSN function is the tunnel endpoint on the core network side,
from where the external (IP) packet data network
=== Software Components
==== GTP Implementation (libgtp)
The OsmoGGSN source code includes a shared library implementation of
the GTP protocol used on the GGSN-SGSN interface. This library
and associated header files are installed system-wide and are
available to other programs/applications.
In fact, libgtp is what the OsmoSGSN also uses for its use of GTP.
==== sgsnemu
In order to test OsmoGGSN without running a SGSN and other elements
of a cellular network, there is a small command-line utility called
*sgsnemu* which is able to simulate the customary operations of a SGSN
towards the GGSN, such as a PDP Context Activation.
*sgsnemu* can even be used for testing against other GGSNs, as the GTP
protocol is standardized across implementations.
==== osmo-ggsn
*osmo-ggsn* is the actual name of the OsmoGGSN executable program. It
implements the GGSN functionality. All parameters are set using the
configuration file, by default located in *./osmo-ggsn.cfg*
==== systemd service file
In *contrib/osmo-ggsn.service* you can find a sample service file for
OsmoGGSN which can be used with systemd.
=== Limitations
OsmoGGSN supports both GTP0 (GSM 09.60) and GTP1 (3GPP 29.060). In the
following tables the support of each individual message type is
detailed. The numbers before each feature indicates the relevant
section in the standard.
==== GSM 09.60 (GTPv0)
[options="header",cols="50%,15%,15%,15%,5%"]
|===
| Feature | gtplib | osmo-ggsn | sgsnemu | notes
5+<|*7.4 Path Management Messages*
|7.4.1 Echo Request |Supported |Supported |Supported |
|7.4.2 Echo Response |Supported |Supported |Supported |
|7.4.3 Version Not Supported |Supported |Supported |Supported |
5+<| *7.5 Tunnel Management Messages*
|7.5.1 Create PDP Context Request|Supported |Supported |Supported |
|7.5.2 Create PDP Context Response|Supported |Supported |Supported |
|7.5.3 Update PDP Context Request|Supported |Supported |Not |
|7.5.4 Update PDP Context Response|Supported |Supported |Not |
|7.5.5 Delete PDP Context Request|Supported |Supported |Supported |
|7.5.6 Delete PDP Context Response|Supported |Supported |Supported |
|7.5.7 Create AA PDP Context Request|Unsupported |Unsupported |Unsupported |
|7.5.8 Create AA PDP Response|Unsupported |Unsupported |Unsupported |
|7.5.9 Delete AA PDP Context Request|Unsupported |Unsupported |Unsupported |
|7.5.10 Delete AA PDP Context Response|Unsupported |Unsupported |Unsupported |
|7.5.11 Error Indication |Supported |Supported |Supported |
|7.5.12 PDU Notification Request|Unsupported |Unsupported |Unsupported |
|7.5.13 PDU Notification Response|Unsupported |Unsupported |Unsupported |
|7.5.14 PDU Notification Reject Request|Unsupported |Unsupported |Unsupported |
|7.5.15 PDU Notification Reject Response|Unsupported |Unsupported |Unsupported |
5+<| *7.6 Location Management Messages*
|7.6.1 Send Routeing Information for GPRS Request|Unsupported |Unsupported |Not applicable |
|7.6.2 Send Routeing Information for GPRS Response|Unsupported |Unsupported |Not applicable |
|7.6.3 Failure Report Request|Unsupported |Unsupported |Not applicable |
|7.6.3 Failure Report Response|Unsupported |Unsupported |Not applicable |
|7.6.5 Note MS GPRS Present Request|Unsupported |Unsupported |Not applicable|
|7.6.6 Note MS GPRS Present Response|Unsupported |Unsupported |Not applicable|
5+<| *7.5 Mobility Management Messages*
|7.5.1 Identification Request|Unsupported |Not applicable|Not applicable|
|7.5.2 Identification Response|Unsupported |Not applicable|Not applicable |
|7.5.3 SGSN Context Request|Unsupported |Not applicable|Not applicable|
|7.5.4 SGSN Context Response|Unsupported |Not applicable|Not applicable|
|7.5.5 SGSN Context Acknowledge|Unsupported |Not applicable|Not applicable|
|===
==== 3GPP 29.060 (GTPv1)
[options="header",cols="50%,15%,15%,15%,5%"]
|===
|Feature |gtplib |osmo-ggsn |sgsnemu |notes
5+<|*7.2 Path Management Messages*
|7.2.1 Echo Request |Supported |Supported |Supported |
|7.2.2 Echo Response |Supported |Supported |Supported |
|7.2.3 Version Not Supported|Supported |Supported |Supported |
|7.2.4 Extension Headers Notification|Supported |Supported |Supported |
5+<|*7.3 Tunnel Management Messages*
|7.3.1 Create PDP Context Request|Supported |Supported |Supported |1
|7.3.2 Create PDP Context Response|Supported |Supported |Supported |
|7.3.3 Update PDP Context Request|Supported |Supported |Not applicable|1
|7.3.4 Update PDP Context Response|Supported |Supported |Not applicable|
|7.3.5 Delete PDP Context Request|Supported |Supported |Supported |
|7.3.6 Delete PDP Context Response|Supported |Supported |Supported |
|7.3.7 Error Indication |Supported |Supported |Supported |
|7.3.8 PDU Notification Request|Unsupported |Unsupported |Unsupported |
|7.3.9 PDU Notification Response|Unsupported |Unsupported |Unsupported |
|7.3.10 PDU Notification Reject Request|Unsupported |Unsupported |Unsupported |
|7.3.10 PDU Notification Reject Response|Unsupported |Unsupported |Unsupported |
5+<|*7.4 Location Management Messages*
|7.4.1 Send Routeing Information for GPRS Request|Unsupported |Unsupported |Not applicable |
|7.4.2 Send Routeing Information for GPRS Response|Unsupported |Unsupported |Not applicable |
|7.4.3 Failure Report Request|Unsupported |Unsupported |Not applicable|
|7.4.3 Failure Report Response|Unsupported |Unsupported |Not applicable|
|7.4.5 Note MS GPRS Present Request|Unsupported |Unsupported |Not applicable|
|7.4.6 Note MS GPRS Present Response|Unsupported |Unsupported |Not applicable|
5+<|*7.5 Mobility Management Messages*
|7.5.1 Identification Request|Unsupported |Not applicable|Not applicable|
|7.5.2 Identification Response|Unsupported |Not applicable |Not applicable|
|7.5.3 SGSN Context Request|Unsupported |Not applicable|Not applicable|
|7.5.4 SGSN Context Response|Unsupported |Not applicable |Not applicable|
|7.5.5 SGSN Context Acknowledge|Unsupported |Not applicable|Not applicable|
|7.5.6 Forward Relocation Request|Unsupported |Not applicable|Not applicable|
|7.5.7 Forward Relocation Response|Unsupported |Not applicable|Not applicable|
|7.5.8 Forward Relocation Complete|Unsupported |Not applicable|Not applicable|
|7.5.9 Relocation Cancel Request|Unsupported |Not applicable|Not applicable|
|7.5.10 Relocation Cancel Response|Unsupported |Not applicable|Not applicable|
|7.5.11 Forward Relocation Complete |Unsupported |Not applicable |Not applicable |
|7.5.12 Forward SRNS Context Acknowledge|Unsupported |Not applicable|Not applicable|
|7.5.13 Forward SRNS Context|Unsupported |Not applicable|Not applicable|
|===
Notes
1) The "Secondary PDP Context Activation Procedure" is not supported.

View File

@@ -0,0 +1,133 @@
== Running OsmoGGSN
The OsmoGGSN executable (`osmo-ggsn`) offers the following command-line
arguments:
=== SYNOPSIS
*osmo-ggsn* [-h|-V] [-D] [-c 'CONFIGFILE']
=== OPTIONS
*-h, --help*::
Print a short help message about the supported options
*-V, --version*::
Print the compile-time version number of the program
*-D, --daemonize*::
Fork the process as a daemon into background.
*-c, --config-file 'CONFIGFILE'*::
Specify the file and path name of the configuration file to be
used. If none is specified, use `osmo-ggsn.cfg` in the current
working directory.
=== Routing
Operating the OpenGGSN tun device naturally creates a network setup with
multiple interfaces. Consider:
* Typical Linux setups prevent forwarding of packets between separate
interfaces by default. To let subscribers reach the internet uplink from the
tun device, it may be required to enable IP forwarding.
* Having a locally defined address range assigned to the tun device requires
either sensible routing for this address range, or that masquerading is
enabled to allow your single uplink IP address to "proxy" for the tun.
These are decisions to be made on a network administration level.
In a trivial case where you have a single box serving GPRS to few subscribers
on an arbitrary IP address range not known in the larger network, the easiest
way to enable GPRS uplink would be to enable IP forwarding and masquerading.
To manually enable IPv4 forwarding and masquerading ad-hoc, you can do:
----
sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
nft 'add rule ip nat postrouting oifname "\*" counter masquerade'
----
(You may want to replace `*` with the network device name, like `-o eth0`)
There are various ways to enable these settings persistently, please refer to
your distribution's documentation -- e.g. look for @net.ipv4.ip_forward=1@ in
@/etc/sysctl.d/@, and https://wiki.debian.org/nftables for masquerading.
include::{srcdir}/chapters/mtu.adoc[]
=== Multiple instances
Running multiple instances of `osmo-ggsn` is possible if all GGSN instances
are binding to different local IP addresses and all other interfaces (VTY,
CTRL) are separated using the appropriate configuration options. The IP based
interfaces are binding to local host by default. In order to separate the
processes, the user has to bind those services to specific but different
IP addresses.
The VTY and the control interface can be bound to IP addresses from the loopback
address range.
.Example: Binding VTY and control interface to a specific ip-address
----
line vty
bind 127.0.0.2
ctrl
bind 127.0.0.2
----
Also make sure to place each instance's GTP bind on a separate IP address (GTP
uses a port number that is fixed in the GTP specifications, so it will not be
possible to pick differing ports on the same IP address), like:
----
ggsn ggsn0
gtp bind-ip 127.0.0.2
----
=== GTP-U kernel module
WARNING: As of writing, IPv6 support for the kernel module has not been
upstreamed yet (OS#1952).
WARNING: As of writing, it is not possible to configure multiple APNs with
gtpu-mode kernel-gpt. This is a limitation in OsmoGGSN, not in the
kernel module (OS#6106).
OsmoGGSN has support to use the Linux kernel GTP-U tunnel driver to accelerate
the data/user plane while still implementing the control plane (GTP-C) in
userspace in OsmoGGSN. The kernel module is included in Linux 4.7.0 and higher.
Notably the Debian GNU/Linux distribution has it enabled by default.
In order to use this feature, make sure that your Linux kernel was configured
to support it (`CONFIG_GTP=m` or `=y`). Furthermore, `osmo-ggsn` must have been
built with `./configure` argument `--enable-gtp-linux` (which requires libgtpnl
to be installed).
Load the kernel module with:
----
$ sudo modprobe gtp
----
Then start OsmoGGSN with a configuration file that uses `gtpu-mode kernel-gtp`.
A full example configuration is in `osmo-ggsn-kernel-gtp.cfg`.
----
$ sudo osmo-ggsn -c /usr/share/doc/osmo-ggsn/examples/osmo-ggsn-kernel-gtp.cfg
----
.Example: APN with kernel-gtp
----
ggsn ggsn0
gtp state-dir /tmp
gtp bind-ip 127.0.0.2
apn internet
gtpu-mode kernel-gtp
tun-device tun4
type-support v4
ip prefix dynamic 172.16.222.0/24
ip dns 0 8.8.8.8
ip dns 1 8.8.4.4
ip ifconfig 172.16.222.0/24
no shutdown
----

View File

@@ -0,0 +1,46 @@
<revhistory>
<revision>
<revnumber>1</revnumber>
<date>August 2017</date>
<authorinitials>HW</authorinitials>
<revremark>
Initial version.
</revremark>
</revision>
</revhistory>
<authorgroup>
<author>
<firstname>Harald</firstname>
<surname>Welte</surname>
<email>hwelte@sysmocom.de</email>
<authorinitials>HW</authorinitials>
<affiliation>
<shortaffil>sysmocom</shortaffil>
<orgname>sysmocom - s.f.m.c. GmbH</orgname>
<jobtitle>Managing Director</jobtitle>
</affiliation>
</author>
</authorgroup>
<copyright>
<year>2013-2017</year>
<holder>sysmocom - s.f.m.c. GmbH</holder>
</copyright>
<legalnotice>
<para>
Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
Version 1.3 or any later version published by the Free Software
Foundation; with no Invariant Sections, no Front-Cover Texts,
and no Back-Cover Texts. A copy of the license is included in
the section entitled "GNU Free Documentation License".
</para>
<para>
The Asciidoc source code of this manual can be found at
<ulink url="http://git.osmocom.org/osmo-gsm-manuals/">
http://git.osmocom.org/osmo-gsm-manuals/
</ulink>
</para>
</legalnotice>

View File

@@ -0,0 +1,30 @@
OsmoGGSN User Manual
====================
Harald Welte <hwelte@sysmocom.de>
include::./common/chapters/preface.adoc[]
include::{srcdir}/chapters/overview.adoc[]
include::{srcdir}/chapters/running.adoc[]
//include::{srcdir}/chapters/control.adoc[]
include::{srcdir}/chapters/configuration.adoc[]
include::./common/chapters/vty.adoc[]
include::./common/chapters/logging.adoc[]
include::./common/chapters/control_if.adoc[]
include::./common/chapters/vty_cpu_sched.adoc[]
include::./common/chapters/port_numbers.adoc[]
include::./common/chapters/bibliography.adoc[]
include::./common/chapters/glossary.adoc[]
include::./common/chapters/gfdl.adoc[]

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
ex:ts=2:sw=42sts=2:et
-*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
-->
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML 5.0//EN"
"http://docbook.org/xml/5.0/dtd/docbook.dtd" [
<!ENTITY chapter-vty SYSTEM "./common/chapters/vty.xml" >
<!ENTITY sections-vty SYSTEM "generated/docbook_vty.xml" >
]>
<book>
<info>
<revhistory>
<revision>
<revnumber>v1</revnumber>
<date>06th September 2017</date>
<authorinitials>hw</authorinitials>
<revremark>Initial version as of OsmoGGSN v1.0.0</revremark>
</revision>
</revhistory>
<title>OsmoGGSN VTY Reference</title>
<copyright>
<year>2017</year>
</copyright>
<legalnotice>
<para>This work is copyright by <orgname>sysmocom - s.f.m.c. GmbH</orgname>. All rights reserved.
</para>
</legalnotice>
</info>
<!-- Main chapters-->
&chapter-vty;
</book>

17
doc/manuals/regen_doc.sh Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/sh -x
if [ -z "$DOCKER_PLAYGROUND" ]; then
echo "You need to set DOCKER_PLAYGROUND"
exit 1
fi
SCRIPT=$(realpath "$0")
MANUAL_DIR=$(dirname "$SCRIPT")
COMMIT=${COMMIT:-$(git log -1 --format=format:%H)}
cd "$DOCKER_PLAYGROUND/scripts" || exit 1
OSMO_GGSN_BRANCH=$COMMIT ./regen_doc.sh osmo-ggsn 4260 \
"$MANUAL_DIR/chapters/counters_generated.adoc" \
"$MANUAL_DIR/vty/ggsn_vty_reference.xml"

View File

@@ -0,0 +1,30 @@
<vtydoc xmlns='urn:osmocom:xml:libosmocore:vty:doc:1.0'>
<node id='config-line'>
<child_of nodeid='config' />
<name>Telnet/VTY Configuration Node</name>
<description>
Configure parameters of the Telnet/VTY Interface, such as to which IP address it should bind/listen to.
</description>
</node>
<node id='config-ctrl'>
<child_of nodeid='config' />
<name>CTRL Configuration Node</name>
<description>
Configure parameters of the CTRL Interface, such as to which IP address it should bind/listen to.
</description>
</node>
<node id='config-ggsn'>
<child_of nodeid='config' />
<name>GGSN Instance Configuration Node</name>
<description>
Configure an Instance of a (virtual) GGSN
</description>
</node>
<node id='config-ggsn-apn'>
<child_of nodeid='config-ggsn' />
<name>APN Configuration Node</name>
<description>
Configure an Access Point Name (APN) inside a GGSN Instance
</description>
</node>
</vtydoc>

View File

@@ -2,7 +2,16 @@ bin_PROGRAMS = osmo-ggsn
AM_LDFLAGS = @EXEC_LDFLAGS@
AM_CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb $(LIBOSMOCORE_CFLAGS) $(LIBOSMOCTRL_CFLAGS) $(LIBOSMOVTY_CFLAGS)
AM_CFLAGS = \
-D_GNU_SOURCE \
-fno-builtin \
-Wall \
-DSBINDIR='"$(sbindir)"' \
-I$(top_srcdir)/include \
$(LIBOSMOCORE_CFLAGS) \
$(LIBOSMOCTRL_CFLAGS) \
$(LIBOSMOVTY_CFLAGS) \
$(NULL)
osmo_ggsn_LDADD = @EXEC_LDADD@ -lgtp -L../gtp ../lib/libmisc.a $(LIBOSMOCORE_LIBS) $(LIBOSMOCTRL_LIBS) $(LIBOSMOVTY_LIBS)
@@ -12,8 +21,4 @@ osmo_ggsn_LDADD += $(LIBGTPNL_LIBS)
endif
osmo_ggsn_DEPENDENCIES = ../gtp/libgtp.la ../lib/libmisc.a
osmo_ggsn_SOURCES = ggsn_vty.c ggsn.c ggsn.h gtp-kernel.h icmpv6.c icmpv6.h checksum.c checksum.h
if ENABLE_GTP_KERNEL
osmo_ggsn_SOURCES += gtp-kernel.c
endif
osmo_ggsn_SOURCES = ggsn_main.c ggsn_vty.c ggsn.c ggsn.h sgsn.c sgsn.h pco.c pco.h

File diff suppressed because it is too large Load Diff

View File

@@ -6,17 +6,34 @@
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/select.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/tdef.h>
#include <osmocom/ctrl/control_if.h>
#include <osmocom/gtp/gtp.h>
#include "../lib/tun.h"
#include "../lib/ippool.h"
#include "../lib/syserr.h"
#include "../lib/in46_addr.h"
#include "../gtp/gtp.h"
#include "sgsn.h"
#define APN_TYPE_IPv4 0x01 /* v4-only */
#define APN_TYPE_IPv6 0x02 /* v6-only */
#define APN_TYPE_IPv4v6 0x04 /* v4v6 dual-stack */
/* The maximum sane MTU over GTP-U somebody may wish to configure:
* 9000 bytes aka jumbo frames. */
#define MAX_POSSIBLE_APN_MTU 9000
/* See 3GPP TS 23.060 Annex C: */
#define ETHERNET_MTU 1500
#define IPV4_HDR_MAX_SIZE 60
#define IPV6_HDR_MAX_SIZE 40 /* Assume no extension headers in general... */
#define UDP_HDR_MAX_SIZE 8
#define GTPU_HDR_MAX_SIZE 12 /* Assume no extension headers in general... */
#define MAX_DESIRED_APN_MTU ((ETHERNET_MTU) - (GTPU_HDR_MAX_SIZE) - (UDP_HDR_MAX_SIZE) - (IPV4_HDR_MAX_SIZE))
/* MAX_DESIRED_APN_MTU = 1500 - 60 - 8 - 12 = 1500 - 80 = 1420 */
struct ggsn_ctx;
struct apn_ctx_ip {
@@ -62,10 +79,12 @@ struct apn_ctx {
uint32_t apn_type_mask;
/* GTP-U via TUN device or in Linux kernel */
enum apn_gtpu_mode gtpu_mode;
/* administratively shut-down (true) or not (false) */
/* administratively shut down (true) or not (false) */
bool shutdown;
/* transmit G-PDU sequeence numbers (true) or not (false) */
/* transmit G-PDU sequence numbers (true) or not (false) */
bool tx_gpdu_seq;
/* MTU announced to the UE */
uint16_t mtu;
} cfg;
/* corresponding tun device */
@@ -76,9 +95,10 @@ struct apn_ctx {
/* ip-up and ip-down script names/paths */
char *ipup_script;
char *ipdown_script;
/* Whether to apply the MTU (apn->cfg.mtu) on the tun device: */
bool mtu_apply;
} cfg;
struct tun_t *tun;
struct osmo_fd fd;
} tun;
/* ipv6 link-local address */
@@ -88,6 +108,14 @@ struct apn_ctx {
struct apn_ctx_ip v6;
};
struct pdp_priv_t {
struct pdp_t *lib; /* pointer to libgtp associated pdp_t instance */
struct sgsn_peer *sgsn;
struct apn_ctx *apn;
struct llist_head entry; /* to be included into sgsn_peer */
/* struct ggsn_ctx can be reached through lib->gsn->priv, or through sgsn->ggsn */
};
struct ggsn_ctx {
/* global list of GGSNs */
struct llist_head list;
@@ -95,6 +123,9 @@ struct ggsn_ctx {
/* list of APNs in this GGSN */
struct llist_head apn_list;
/* list of SGSN peers (struct sgsn_peer) in this GGSN. TODO: hash table with key <ip+port>? */
struct llist_head sgsn_list;
bool started;
struct {
@@ -111,7 +142,9 @@ struct ggsn_ctx {
struct in46_addr gtpu_addr;
/* directory for state file */
char *state_dir;
/* administratively shut-down (true) or not (false) */
/* Time between Echo requests on each SGSN */
unsigned int echo_interval;
/* administratively shut down (true) or not (false) */
bool shutdown;
} cfg;
@@ -122,8 +155,6 @@ struct ggsn_ctx {
struct osmo_fd gtp_fd0;
struct osmo_fd gtp_fd1c;
struct osmo_fd gtp_fd1u;
struct osmo_timer_list gtp_timer;
};
/* ggsn_vty.c */
@@ -135,9 +166,22 @@ struct ggsn_ctx *ggsn_find_or_create(void *ctx, const char *name);
struct apn_ctx *ggsn_find_apn(struct ggsn_ctx *ggsn, const char *name);
struct apn_ctx *ggsn_find_or_create_apn(struct ggsn_ctx *ggsn, const char *name);
/* ggsn.c */
/* ggsn_main.c */
extern struct ctrl_handle *g_ctrlh;
extern void *tall_ggsn_ctx;
extern struct osmo_tdef_group ggsn_tdef_group[];
/* ggsn.c */
extern int ggsn_start(struct ggsn_ctx *ggsn);
extern int ggsn_stop(struct ggsn_ctx *ggsn);
extern int apn_start(struct apn_ctx *apn);
extern int apn_stop(struct apn_ctx *apn, bool force);
extern int apn_stop(struct apn_ctx *apn);
void ggsn_close_one_pdp(struct pdp_t *pdp);
#define LOGPAPN(level, apn, fmt, args...) \
LOGP(DGGSN, level, "APN(%s): " fmt, (apn)->cfg.name, ## args)
#define LOGPGGSN(level, ggsn, fmt, args...) \
LOGP(DGGSN, level, "GGSN(%s): " fmt, (ggsn)->cfg.name, ## args)
#define LOGPPDP(level, pdp, fmt, args...) LOGPDPX(DGGSN, level, pdp, fmt, ## args)

261
ggsn/ggsn_main.c Normal file
View File

@@ -0,0 +1,261 @@
/*
* OsmoGGSN - Gateway GPRS Support Node
* Copyright (C) 2002, 2003, 2004 Mondru AB.
* Copyright (C) 2017-2019 by Harald Welte <laforge@gnumonks.org>
* Copyright (C) 2019 sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
* notice and this permission notice is included in all copies or
* substantial portions of the software.
*
*/
#include "../config.h"
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include <getopt.h>
#include <ctype.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <inttypes.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <osmocom/core/application.h>
#include <osmocom/core/select.h>
#include <osmocom/core/stats.h>
#include <osmocom/core/rate_ctr.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/tdef.h>
#include <osmocom/core/utils.h>
#include <osmocom/ctrl/control_if.h>
#include <osmocom/ctrl/control_cmd.h>
#include <osmocom/ctrl/control_vty.h>
#include <osmocom/ctrl/ports.h>
#include <osmocom/vty/telnet_interface.h>
#include <osmocom/vty/logging.h>
#include <osmocom/vty/stats.h>
#include <osmocom/vty/ports.h>
#include <osmocom/vty/command.h>
#include <osmocom/vty/misc.h>
#include <osmocom/vty/cpu_sched_vty.h>
#include "ggsn.h"
void *tall_ggsn_ctx;
static int end = 0;
static int daemonize = 0;
struct ctrl_handle *g_ctrlh;
struct ul255_t qos;
struct ul255_t apn;
static char *config_file = "osmo-ggsn.cfg";
struct osmo_tdef_group ggsn_tdef_group[] = {
{.name = "gtp", .tdefs = gtp_T_defs, .desc = "GTP (libgtp) timers" },
{ }
};
/* To exit gracefully. Used with GCC compilation flag -pg and gprof */
static void signal_handler(int s)
{
LOGP(DGGSN, LOGL_NOTICE, "signal %d received\n", s);
switch (s) {
case SIGINT:
case SIGTERM:
LOGP(DGGSN, LOGL_NOTICE, "SIGINT received, shutting down\n");
end = 1;
break;
case SIGABRT:
/* in case of abort, we want to obtain a talloc report and
* then run default SIGABRT handler, who will generate coredump
* and abort the process. abort() should do this for us after we
* return, but program wouldn't exit if an external SIGABRT is
* received.
*/
talloc_report(tall_vty_ctx, stderr);
talloc_report_full(tall_ggsn_ctx, stderr);
signal(SIGABRT, SIG_DFL);
raise(SIGABRT);
break;
case SIGUSR1:
talloc_report(tall_vty_ctx, stderr);
talloc_report_full(tall_ggsn_ctx, stderr);
break;
case SIGUSR2:
talloc_report_full(tall_vty_ctx, stderr);
break;
default:
break;
}
}
static void print_usage()
{
printf("Usage: osmo-ggsn [-h] [-D] [-c configfile] [-V]\n");
}
static void print_help()
{
printf( " Some useful help...\n"
" -h --help This help text\n"
" -D --daemonize Fork the process into a background daemon\n"
" -c --config-file filename The config file to use\n"
" -V --version Print the version of OsmoGGSN\n"
);
printf("\nVTY reference generation:\n");
printf(" --vty-ref-mode MODE VTY reference generation mode (e.g. 'expert').\n");
printf(" --vty-ref-xml Generate the VTY reference XML output and exit.\n");
}
static void handle_long_options(const char *prog_name, const int long_option)
{
static int vty_ref_mode = VTY_REF_GEN_MODE_DEFAULT;
switch (long_option) {
case 1:
vty_ref_mode = get_string_value(vty_ref_gen_mode_names, optarg);
if (vty_ref_mode < 0) {
fprintf(stderr, "%s: Unknown VTY reference generation "
"mode '%s'\n", prog_name, optarg);
exit(2);
}
break;
case 2:
fprintf(stderr, "Generating the VTY reference in mode '%s' (%s)\n",
get_value_string(vty_ref_gen_mode_names, vty_ref_mode),
get_value_string(vty_ref_gen_mode_desc, vty_ref_mode));
vty_dump_xml_ref_mode(stdout, (enum vty_ref_gen_mode) vty_ref_mode);
exit(0);
default:
fprintf(stderr, "%s: error parsing cmdline options\n", prog_name);
exit(2);
}
}
static void handle_options(int argc, char **argv)
{
while (1) {
int option_index = 0, c;
static int long_option = 0;
static struct option long_options[] = {
{ "help", 0, 0, 'h' },
{ "daemonize", 0, 0, 'D' },
{ "config-file", 1, 0, 'c' },
{ "version", 0, 0, 'V' },
{ "vty-ref-mode", 1, &long_option, 1 },
{ "vty-ref-xml", 0, &long_option, 2 },
{ 0, 0, 0, 0 }
};
c = getopt_long(argc, argv, "hdc:V", long_options, &option_index);
if (c == -1)
break;
switch (c) {
case 0:
handle_long_options(argv[0], long_option);
break;
case 'h':
print_usage();
print_help();
exit(0);
case 'D':
daemonize = 1;
break;
case 'c':
config_file = optarg;
break;
case 'V':
print_version(1);
exit(0);
break;
}
}
}
int main(int argc, char **argv)
{
struct ggsn_ctx *ggsn;
int rc;
tall_ggsn_ctx = talloc_named_const(NULL, 0, "OsmoGGSN");
msgb_talloc_ctx_init(tall_ggsn_ctx, 0);
g_vty_info.tall_ctx = tall_ggsn_ctx;
/* Handle keyboard interrupt SIGINT */
signal(SIGINT, &signal_handler);
signal(SIGTERM, &signal_handler);
signal(SIGABRT, &signal_handler);
signal(SIGUSR1, &signal_handler);
signal(SIGUSR2, &signal_handler);
osmo_init_ignore_signals();
osmo_init_logging2(tall_ggsn_ctx, &log_info);
osmo_stats_init(tall_ggsn_ctx);
vty_init(&g_vty_info);
logging_vty_add_cmds();
osmo_talloc_vty_add_cmds();
osmo_stats_vty_add_cmds();
ggsn_vty_init();
ctrl_vty_init(tall_ggsn_ctx);
osmo_cpu_sched_vty_init(tall_ggsn_ctx);
handle_options(argc, argv);
rate_ctr_init(tall_ggsn_ctx);
rc = vty_read_config_file(config_file, NULL);
if (rc < 0) {
fprintf(stderr, "Failed to open config file: '%s'\n", config_file);
exit(2);
}
rc = telnet_init_default(tall_ggsn_ctx, NULL, OSMO_VTY_PORT_GGSN);
if (rc < 0)
exit(1);
g_ctrlh = ctrl_interface_setup(NULL, OSMO_CTRL_PORT_GGSN, NULL);
if (!g_ctrlh) {
LOGP(DGGSN, LOGL_ERROR, "Failed to create CTRL interface.\n");
exit(1);
}
if (daemonize) {
rc = osmo_daemonize();
if (rc < 0) {
perror("Error during daemonize");
exit(1);
}
}
#if 0
/* qos */
qos.l = 3;
qos.v[2] = (args_info.qos_arg) & 0xff;
qos.v[1] = ((args_info.qos_arg) >> 8) & 0xff;
qos.v[0] = ((args_info.qos_arg) >> 16) & 0xff;
#endif
/* Main select loop */
while (!end) {
osmo_select_main(0);
}
llist_for_each_entry(ggsn, &g_ggsn_list, list)
ggsn_stop(ggsn);
return 0;
}

View File

@@ -22,94 +22,39 @@
#include <inttypes.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/rate_ctr.h>
#include <osmocom/gsm/apn.h>
#include <osmocom/gsm/gsm48_ie.h>
#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
#include <osmocom/vty/command.h>
#include <osmocom/vty/vty.h>
#include <osmocom/vty/misc.h>
#include <osmocom/vty/tdef_vty.h>
#include "../gtp/gtp.h"
#include "../gtp/pdp.h"
#include <osmocom/gtp/gtp.h>
#include <osmocom/gtp/pdp.h>
#include "../lib/util.h"
#include "ggsn.h"
#include "sgsn.h"
#include "../gtp/gtp_internal.h"
#define PREFIX_STR "Prefix (Network/Netmask)\n"
#define IFCONFIG_STR "GGSN-based interface configuration\n"
#define GGSN_STR "Gateway GPRS Support NODE (GGSN)\n"
LLIST_HEAD(g_ggsn_list);
enum ggsn_vty_node {
GGSN_NODE = _LAST_OSMOVTY_NODE + 1,
APN_NODE,
};
struct ggsn_ctx *ggsn_find(const char *name)
{
struct ggsn_ctx *ggsn;
llist_for_each_entry(ggsn, &g_ggsn_list, list) {
if (!strcmp(ggsn->cfg.name, name))
return ggsn;
}
return NULL;
}
struct ggsn_ctx *ggsn_find_or_create(void *ctx, const char *name)
{
struct ggsn_ctx *ggsn;
ggsn = ggsn_find(name);
if (ggsn)
return ggsn;
ggsn = talloc_zero(ctx, struct ggsn_ctx);
if (!ggsn)
return NULL;
ggsn->cfg.name = talloc_strdup(ggsn, name);
ggsn->cfg.state_dir = talloc_strdup(ggsn, "/tmp");
ggsn->cfg.shutdown = true;
INIT_LLIST_HEAD(&ggsn->apn_list);
llist_add_tail(&ggsn->list, &g_ggsn_list);
return ggsn;
}
struct apn_ctx *ggsn_find_apn(struct ggsn_ctx *ggsn, const char *name)
{
struct apn_ctx *apn;
llist_for_each_entry(apn, &ggsn->apn_list, list) {
if (!strcmp(apn->cfg.name, name))
return apn;
}
return NULL;
}
struct apn_ctx *ggsn_find_or_create_apn(struct ggsn_ctx *ggsn, const char *name)
{
struct apn_ctx *apn = ggsn_find_apn(ggsn, name);
if (apn)
return apn;
apn = talloc_zero(ggsn, struct apn_ctx);
if (!apn)
return NULL;
apn->ggsn = ggsn;
apn->cfg.name = talloc_strdup(apn, name);
apn->cfg.shutdown = true;
apn->cfg.tx_gpdu_seq = true;
INIT_LLIST_HEAD(&apn->cfg.name_list);
llist_add_tail(&apn->list, &ggsn->apn_list);
return apn;
}
/* GGSN Node */
static struct cmd_node ggsn_node = {
@@ -216,6 +161,11 @@ DEFUN(cfg_ggsn_state_dir, cfg_ggsn_state_dir_cmd,
{
struct ggsn_ctx *ggsn = (struct ggsn_ctx *) vty->index;
if (mkdir(argv[0], 0755) == -1 && errno != EEXIST) {
vty_out(vty, "%% Failed to create state-dir: %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
osmo_talloc_replace_string(ggsn, &ggsn->cfg.state_dir, argv[0]);
return CMD_SUCCESS;
@@ -292,7 +242,7 @@ DEFUN(cfg_ggsn_no_default_apn, cfg_ggsn_no_default_apn_cmd,
DEFUN(cfg_ggsn_shutdown, cfg_ggsn_shutdown_cmd,
"shutdown ggsn",
"Put the GGSN in administrative shut-down\n" GGSN_STR)
"Put the GGSN in administrative shutdown\n" GGSN_STR)
{
struct ggsn_ctx *ggsn = (struct ggsn_ctx *) vty->index;
@@ -309,7 +259,7 @@ DEFUN(cfg_ggsn_shutdown, cfg_ggsn_shutdown_cmd,
DEFUN(cfg_ggsn_no_shutdown, cfg_ggsn_no_shutdown_cmd,
"no shutdown ggsn",
NO_STR GGSN_STR "Remove the GGSN from administrative shut-down\n")
NO_STR GGSN_STR "Remove the GGSN from administrative shutdown\n")
{
struct ggsn_ctx *ggsn = (struct ggsn_ctx *) vty->index;
@@ -324,6 +274,79 @@ DEFUN(cfg_ggsn_no_shutdown, cfg_ggsn_no_shutdown_cmd,
return CMD_SUCCESS;
}
static void show_one_sgsn(struct vty *vty, const struct sgsn_peer *sgsn, const char* prefix)
{
char buf[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &sgsn->addr, buf, sizeof(buf));
vty_out(vty, "%s(S)GSN %s%s", prefix, buf, VTY_NEWLINE);
vty_out(vty, "%s Restart Counter: %d%s", prefix, sgsn->remote_restart_ctr, VTY_NEWLINE);
vty_out(vty, "%s PDP contexts: %d%s", prefix, llist_count(&sgsn->pdp_list), VTY_NEWLINE);
vty_out(vty, "%s Echo Requests in-flight: %u%s", prefix, sgsn->tx_msgs_queued, VTY_NEWLINE);
}
DEFUN(cfg_ggsn_show_sgsn, cfg_ggsn_show_sgsn_cmd,
"show sgsn",
NO_STR GGSN_STR "Remove the GGSN from administrative shutdown\n")
{
struct ggsn_ctx *ggsn = (struct ggsn_ctx *) vty->index;
struct sgsn_peer *sgsn;
llist_for_each_entry(sgsn, &ggsn->sgsn_list, entry) {
show_one_sgsn(vty, sgsn, "");
}
return CMD_SUCCESS;
}
/* Seee 3GPP TS 29.060 section 7.2.1 */
DEFUN(cfg_ggsn_echo_interval, cfg_ggsn_echo_interval_cmd,
"echo-interval <1-36000>",
GGSN_STR "GGSN Number\n"
"Send an echo request to this static GGSN every interval\n"
"Interval between echo requests in seconds\n")
{
struct ggsn_ctx *ggsn = (struct ggsn_ctx *) vty->index;
int prev_interval = ggsn->cfg.echo_interval;
struct sgsn_peer *sgsn;
ggsn->cfg.echo_interval = atoi(argv[0]);
if (ggsn->cfg.echo_interval < 60)
vty_out(vty, "%% 3GPP TS 29.060 section states interval should " \
"not be lower than 60 seconds, use this value for " \
"testing purposes only!%s", VTY_NEWLINE);
if (prev_interval == ggsn->cfg.echo_interval)
return CMD_SUCCESS;
/* Re-enable echo timer for all sgsn */
llist_for_each_entry(sgsn, &ggsn->sgsn_list, entry)
sgsn_echo_timer_start(sgsn);
return CMD_SUCCESS;
}
DEFUN(cfg_ggsn_no_echo_interval, cfg_ggsn_no_echo_interval_cmd,
"no echo-interval",
GGSN_STR "GGSN Number\n"
NO_STR "Send an echo request to this static GGSN every interval.\n")
{
struct ggsn_ctx *ggsn = (struct ggsn_ctx *) vty->index;
struct sgsn_peer *sgsn;
if (ggsn->cfg.echo_interval == 0)
return CMD_SUCCESS;
ggsn->cfg.echo_interval = 0;
/* Disable echo timer for all sgsn */
llist_for_each_entry(sgsn, &ggsn->sgsn_list, entry)
sgsn_echo_timer_stop(sgsn);
return CMD_SUCCESS;
}
/* APN Node */
static struct cmd_node apn_node = {
@@ -389,13 +412,46 @@ DEFUN(cfg_apn_gtpu_mode, cfg_apn_gtpu_mode_cmd,
DEFUN(cfg_apn_tun_dev_name, cfg_apn_tun_dev_name_cmd,
"tun-device NAME",
"Configure tun device name\n"
"TUN device name")
"TUN device name\n")
{
struct apn_ctx *apn = (struct apn_ctx *) vty->index;
osmo_talloc_replace_string(apn, &apn->tun.cfg.dev_name, argv[0]);
return CMD_SUCCESS;
}
/* MAX_POSSIBLE_APN_MTU = 9000
* MAX_DESIRED_APN_MTU = 1420 */
DEFUN(cfg_apn_mtu, cfg_apn_mtu_cmd,
"mtu (<0-" OSMO_STRINGIFY_VAL(MAX_POSSIBLE_APN_MTU) ">|default) [apply]",
"Configure announced MTU\n"
"MTU of the APN, announced to the UE\n"
"Default value of the MTU of the APN (1420)\n"
"Apply the MTU on the tun-device of the APN\n")
{
struct apn_ctx *apn = (struct apn_ctx *) vty->index;
int rc;
if (strcmp(argv[0], "default") == 0)
apn->cfg.mtu = MAX_DESIRED_APN_MTU;
else
apn->cfg.mtu = atoi(argv[0]);
apn->tun.cfg.mtu_apply = (argc > 1);
if (apn->tun.cfg.mtu_apply && apn->tun.tun) {
rc = osmo_netdev_set_mtu(apn->tun.tun->netdev, apn->cfg.mtu);
if (rc < 0) {
char buf_err[128];
strerror_r(errno, buf_err, sizeof(buf_err));
LOGPAPN(LOGL_ERROR, apn, "Failed to set tun interface MTU %u: %s (%d)\n",
apn->cfg.mtu, buf_err, rc);
vty_out(vty, "%% Failed to set tun interface MTU %u: %s (%d)%s",
apn->cfg.mtu, buf_err, rc, VTY_NEWLINE);
return CMD_WARNING;
}
}
return CMD_SUCCESS;
}
DEFUN(cfg_apn_ipup_script, cfg_apn_ipup_script_cmd,
"ipup-script PATH",
"Configure name/path of ip-up script\n"
@@ -453,9 +509,11 @@ DEFUN(cfg_apn_ip_prefix, cfg_apn_ip_prefix_cmd,
struct in46_prefix *pfx;
/* first update our parsed prefix */
if (!strcmp(argv[0], "static"))
if (!strcmp(argv[0], "static")) {
pfx = &apn->v4.cfg.static_prefix;
else
vty_out(vty, "%% static IP addresses currently not yet supported%s", VTY_NEWLINE);
return CMD_WARNING;
} else
pfx = &apn->v4.cfg.dynamic_prefix;
str2prefix(pfx, argv[1]);
@@ -487,9 +545,11 @@ DEFUN(cfg_apn_ipv6_prefix, cfg_apn_ipv6_prefix_cmd,
struct apn_ctx *apn = (struct apn_ctx *) vty->index;
struct in46_prefix *pfx;
if (!strcmp(argv[0], "static"))
if (!strcmp(argv[0], "static")) {
pfx = &apn->v6.cfg.static_prefix;
else
vty_out(vty, "%% static IP addresses currently not yet supported%s", VTY_NEWLINE);
return CMD_WARNING;
} else
pfx = &apn->v6.cfg.dynamic_prefix;
str2prefix(pfx, argv[1]);
return CMD_SUCCESS;
@@ -597,12 +657,12 @@ DEFUN(cfg_apn_no_gpdu_seq, cfg_apn_no_gpdu_seq_cmd,
DEFUN(cfg_apn_shutdown, cfg_apn_shutdown_cmd,
"shutdown",
"Put the APN in administrative shut-down\n")
"Put the APN in administrative shutdown\n")
{
struct apn_ctx *apn = (struct apn_ctx *) vty->index;
if (!apn->cfg.shutdown) {
if (apn_stop(apn, false)) {
if (apn_stop(apn)) {
vty_out(vty, "%% Failed to Stop APN%s", VTY_NEWLINE);
return CMD_WARNING;
}
@@ -614,11 +674,15 @@ DEFUN(cfg_apn_shutdown, cfg_apn_shutdown_cmd,
DEFUN(cfg_apn_no_shutdown, cfg_apn_no_shutdown_cmd,
"no shutdown",
NO_STR "Remove the APN from administrative shut-down\n")
NO_STR "Remove the APN from administrative shutdown\n")
{
struct apn_ctx *apn = (struct apn_ctx *) vty->index;
if (apn->cfg.shutdown) {
if (!apn->tun.cfg.dev_name) {
vty_out(vty, "%% Failed to start APN, tun-device is not configured%s", VTY_NEWLINE);
return CMD_WARNING;
}
if (apn_start(apn) < 0) {
vty_out(vty, "%% Failed to start APN, check log for details%s", VTY_NEWLINE);
return CMD_WARNING;
@@ -652,12 +716,15 @@ static void config_write_apn(struct vty *vty, struct apn_ctx *apn)
vty_out(vty, " ipdown-script %s%s", apn->tun.cfg.ipdown_script, VTY_NEWLINE);
for (i = 0; i < 32; i++) {
if (!(apn->cfg.apn_type_mask & (1 << i)))
if (!(apn->cfg.apn_type_mask & (UINT32_C(1) << i)))
continue;
vty_out(vty, " type-support %s%s", get_value_string(pdp_type_names, (1 << i)),
vty_out(vty, " type-support %s%s", get_value_string(pdp_type_names, (UINT32_C(1) << i)),
VTY_NEWLINE);
}
vty_out(vty, " mtu %" PRIu16 "%s%s", apn->cfg.mtu,
apn->tun.cfg.mtu_apply ? " apply" : "", VTY_NEWLINE);
if (!apn->cfg.tx_gpdu_seq)
vty_out(vty, " no g-pdu tx-sequence-numbers%s", VTY_NEWLINE);
@@ -708,10 +775,13 @@ static int config_write_ggsn(struct vty *vty)
vty_out(vty, " gtp control-ip %s%s", in46a_ntoa(&ggsn->cfg.gtpc_addr), VTY_NEWLINE);
if (ggsn->cfg.gtpu_addr.v4.s_addr)
vty_out(vty, " gtp user-ip %s%s", in46a_ntoa(&ggsn->cfg.gtpu_addr), VTY_NEWLINE);
osmo_tdef_vty_groups_write(vty, " ");
llist_for_each_entry(apn, &ggsn->apn_list, list)
config_write_apn(vty, apn);
if (ggsn->cfg.default_apn)
vty_out(vty, " default-apn %s%s", ggsn->cfg.default_apn->cfg.name, VTY_NEWLINE);
if (ggsn->cfg.echo_interval)
vty_out(vty, " echo-interval %u%s", ggsn->cfg.echo_interval, VTY_NEWLINE);
/* must be last */
vty_out(vty, " %sshutdown ggsn%s", ggsn->cfg.shutdown ? "" : "no ", VTY_NEWLINE);
}
@@ -723,19 +793,46 @@ static const char *print_gsnaddr(const struct ul16_t *in)
{
struct in46_addr in46;
in46.len = in->l;
OSMO_ASSERT(in->l <= sizeof(in46.v6));
memcpy(&in46.v6, in->v, in->l);
in46a_from_gsna(in, &in46);
return in46a_ntoa(&in46);
}
static void show_one_pdp(struct vty *vty, struct pdp_t *pdp)
/* Useful for v4v6 APNs, where we first iterate over v4 pool and then over v6
pool. param v4only can be used to avoid printing duplicates for pdp context
containing both IPv4 and IPv6 addresses. */
static void show_one_pdp_v4only(struct vty *vty, struct pdp_t *pdp, bool v4only)
{
struct in46_addr eua46;
struct ippoolm_t *peer4, *peer6;
char name_buf[256];
char *apn_name;
int rc;
peer4 = pdp_get_peer_ipv(pdp, false);
peer6 = pdp_get_peer_ipv(pdp, true);
if (v4only && peer6)
return;
/* Attempt to decode MSISDN */
rc = gsm48_decode_bcd_number2(name_buf, sizeof(name_buf),
pdp->msisdn.v, pdp->msisdn.l, 0);
vty_out(vty, "IMSI: %s, NSAPI: %u, MSISDN: %s%s", imsi_gtp2str(&pdp->imsi), pdp->nsapi,
osmo_hexdump_nospc(pdp->msisdn.v, pdp->msisdn.l), VTY_NEWLINE);
rc ? "(NONE)" : name_buf, VTY_NEWLINE);
vty_out(vty, " Version: %d", pdp->version);
if (pdp->version == 1) {
if (!pdp->secondary) {
vty_out(vty, ", Primary, Num Secondaries: %d%s%s",
pdp_count_secondary(pdp) - 1, /* primary included in count */
pdp->nodata ? ", No User Plane": "",
VTY_NEWLINE);
} else {
vty_out(vty, ", Secondary%s", VTY_NEWLINE);
}
} else {
vty_out(vty, "%s", VTY_NEWLINE);
}
vty_out(vty, " Control: %s:%08x ", print_gsnaddr(&pdp->gsnlc), pdp->teic_own);
vty_out(vty, "<-> %s:%08x%s", print_gsnaddr(&pdp->gsnrc), pdp->teic_gn, VTY_NEWLINE);
@@ -743,32 +840,61 @@ static void show_one_pdp(struct vty *vty, struct pdp_t *pdp)
vty_out(vty, " Data: %s:%08x ", print_gsnaddr(&pdp->gsnlu), pdp->teid_own);
vty_out(vty, "<-> %s:%08x%s", print_gsnaddr(&pdp->gsnru), pdp->teid_gn, VTY_NEWLINE);
in46a_from_eua(&pdp->eua, &eua46);
vty_out(vty, " End-User Address: %s%s", in46a_ntoa(&eua46), VTY_NEWLINE);
apn_name = osmo_apn_to_str(name_buf, pdp->apn_req.v, pdp->apn_req.l);
vty_out(vty, " APN requested: %s%s", apn_name ? name_buf : "(NONE)", VTY_NEWLINE);
apn_name = osmo_apn_to_str(name_buf, pdp->apn_use.v, pdp->apn_use.l);
vty_out(vty, " APN in use: %s%s", apn_name ? name_buf : "(NONE)", VTY_NEWLINE);
if (peer4)
vty_out(vty, " End-User Address (IPv4): %s%s",
in46a_ntop(&peer4->addr, name_buf, sizeof(name_buf)), VTY_NEWLINE);
if (peer6)
vty_out(vty, " End-User Address (IPv6): %s%s",
in46a_ntop(&peer6->addr, name_buf, sizeof(name_buf)), VTY_NEWLINE);
vty_out(vty, " Transmit GTP Sequence Number for G-PDU: %s%s",
pdp->tx_gpdu_seq ? "Yes" : "No", VTY_NEWLINE);
}
static void show_one_pdp(struct vty *vty, struct pdp_t *pdp)
{
show_one_pdp_v4only(vty, pdp, false);
}
DEFUN(show_pdpctx_imsi, show_pdpctx_imsi_cmd,
"show pdp-context imsi IMSI [<0-15>]",
"show pdp-context ggsn NAME imsi IMSI [<0-15>]",
SHOW_STR "Display information on PDP Context\n"
GGSN_STR "GGSN Name\n"
"PDP contexts for given IMSI\n"
"PDP context for given NSAPI\n")
{
uint64_t imsi = strtoull(argv[0], NULL, 10);
struct ggsn_ctx *ggsn;
uint64_t imsi;
unsigned int nsapi;
struct pdp_t *pdp;
int num_found = 0;
if (argc > 1) {
nsapi = atoi(argv[1]);
if (pdp_getimsi(&pdp, imsi, nsapi)) {
ggsn = ggsn_find(argv[0]);
if (!ggsn) {
vty_out(vty, "%% No such GGSN '%s'%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
if (strlen(argv[1]) < 6 || strlen(argv[1]) > 15) {
vty_out(vty, "%% Invalid IMSI '%s'%s", argv[1], VTY_NEWLINE);
return CMD_WARNING;
}
imsi = gtp_imsi_str2gtp(argv[1]);
if (argc > 2) {
nsapi = atoi(argv[2]);
if (!gtp_pdp_getimsi(ggsn->gsn, &pdp, imsi, nsapi)) {
show_one_pdp(vty, pdp);
num_found++;
}
} else {
for (nsapi = 0; nsapi < PDP_MAXNSAPI; nsapi++) {
if (pdp_getimsi(&pdp, imsi, nsapi))
if (gtp_pdp_getimsi(ggsn->gsn, &pdp, imsi, nsapi))
continue;
show_one_pdp(vty, pdp);
num_found++;
@@ -781,8 +907,49 @@ DEFUN(show_pdpctx_imsi, show_pdpctx_imsi_cmd,
return CMD_SUCCESS;
}
DEFUN(show_pdpctx_ip, show_pdpctx_ip_cmd,
"show pdp-context ggsn NAME ipv4 A.B.C.D",
SHOW_STR "Display information on PDP Context\n"
GGSN_STR "GGSN Name\n" "IPv4 address type\n" "IP address\n")
{
struct ggsn_ctx *ggsn;
struct apn_ctx *apn;
unsigned int i;
ggsn = ggsn_find(argv[0]);
if (!ggsn) {
vty_out(vty, "%% No such GGSN '%s'%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
/* Iterate over all APNs of a given GGSN */
llist_for_each_entry(apn, &ggsn->apn_list, list) {
struct ippool_t *pool = apn->v4.pool;
/* In some rare cases, if GGSN fails to init TUN/TAP interfaces
* (e.g. due to insufficient permissions), it will continue to
* work in such broken state, and pool would be NULL. */
if (!pool)
continue;
/* Iterate over all IPv4 pool members */
for (i = 0; i < pool->listsize; i++) {
struct ippoolm_t *member = &pool->member[i];
if (member->inuse == 0)
continue;
if (strcmp(argv[1], in46a_ntoa(&member->addr)) == 0) {
show_one_pdp(vty, member->peer);
return CMD_SUCCESS;
}
}
}
vty_out(vty, "%% No PDP context found for IP '%s'%s", argv[1], VTY_NEWLINE);
return CMD_WARNING;
}
/* show all (active) PDP contexts within a pool */
static void ippool_show_pdp_contexts(struct vty *vty, struct ippool_t *pool)
static void ippool_show_pdp_contexts(struct vty *vty, struct ippool_t *pool, bool pdp_v4only)
{
unsigned int i;
@@ -793,21 +960,21 @@ static void ippool_show_pdp_contexts(struct vty *vty, struct ippool_t *pool)
struct ippoolm_t *member = &pool->member[i];
if (member->inuse == 0)
continue;
show_one_pdp(vty, member->peer);
show_one_pdp_v4only(vty, member->peer, pdp_v4only);
}
}
/* show all (active) PDP contexts within an APN */
static void apn_show_pdp_contexts(struct vty *vty, struct apn_ctx *apn)
{
ippool_show_pdp_contexts(vty, apn->v4.pool);
ippool_show_pdp_contexts(vty, apn->v6.pool);
ippool_show_pdp_contexts(vty, apn->v4.pool, true);
ippool_show_pdp_contexts(vty, apn->v6.pool, false);
}
DEFUN(show_pdpctx, show_pdpctx_cmd,
"show pdp-context ggsn NAME [apn APN]",
"show pdp-context ggsn NAME",
SHOW_STR "Show PDP Context Information\n"
GGSN_STR "GGSN Name\n") // FIXME
GGSN_STR "GGSN Name\n")
{
struct ggsn_ctx *ggsn;
struct apn_ctx *apn;
@@ -817,21 +984,45 @@ DEFUN(show_pdpctx, show_pdpctx_cmd,
vty_out(vty, "%% No such GGSN '%s'%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
if (argc < 2) {
llist_for_each_entry(apn, &ggsn->apn_list, list)
apn_show_pdp_contexts(vty, apn);
} else {
apn = ggsn_find_apn(ggsn, argv[1]);
if (!apn) {
vty_out(vty, "%% No such APN '%s'%s", argv[1], VTY_NEWLINE);
return CMD_WARNING;
}
llist_for_each_entry(apn, &ggsn->apn_list, list)
apn_show_pdp_contexts(vty, apn);
}
return CMD_SUCCESS;
}
DEFUN(show_pdpctx_apn, show_pdpctx_apn_cmd,
"show pdp-context ggsn NAME apn APN",
SHOW_STR "Show PDP Context Information\n"
GGSN_STR "GGSN Name\n" "Filter by APN\n" "APN name\n")
{
struct ggsn_ctx *ggsn;
struct apn_ctx *apn;
ggsn = ggsn_find(argv[0]);
if (!ggsn) {
vty_out(vty, "%% No such GGSN '%s'%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
apn = ggsn_find_apn(ggsn, argv[1]);
if (!apn) {
vty_out(vty, "%% No such APN '%s'%s", argv[1], VTY_NEWLINE);
return CMD_WARNING;
}
apn_show_pdp_contexts(vty, apn);
return CMD_SUCCESS;
}
/* Backwards compatibility: the VTY parser is (mis)interpreting
* "[apn APN]" as two separate elements: "[apn" and "APN]",
* but the first part somehow turns into command "ap". */
ALIAS_DEPRECATED(show_pdpctx_apn, show_deprecated_pdpctx_apn_cmd,
"show pdp-context ggsn NAME ap APN",
SHOW_STR "Show PDP Context Information\n"
GGSN_STR "GGSN Name\n" "Filter by APN\n" "APN name\n");
static void show_apn(struct vty *vty, struct apn_ctx *apn)
{
vty_out(vty, " APN: %s%s", apn->cfg.name, VTY_NEWLINE);
@@ -841,12 +1032,15 @@ static void show_apn(struct vty *vty, struct apn_ctx *apn)
static void show_one_ggsn(struct vty *vty, struct ggsn_ctx *ggsn)
{
struct apn_ctx *apn;
struct sgsn_peer *sgsn;
vty_out(vty, "GGSN %s: Bound to %s%s", ggsn->cfg.name, in46a_ntoa(&ggsn->cfg.listen_addr),
VTY_NEWLINE);
/* FIXME */
llist_for_each_entry(apn, &ggsn->apn_list, list)
show_apn(vty, apn);
llist_for_each_entry(sgsn, &ggsn->sgsn_list, entry)
show_one_sgsn(vty, sgsn, " ");
}
DEFUN(show_ggsn, show_ggsn_cmd,
@@ -871,7 +1065,10 @@ DEFUN(show_ggsn, show_ggsn_cmd,
int ggsn_vty_init(void)
{
install_element_ve(&show_pdpctx_cmd);
install_element_ve(&show_pdpctx_apn_cmd);
install_element_ve(&show_deprecated_pdpctx_apn_cmd);
install_element_ve(&show_pdpctx_imsi_cmd);
install_element_ve(&show_pdpctx_ip_cmd);
install_element_ve(&show_ggsn_cmd);
install_element(CONFIG_NODE, &cfg_ggsn_cmd);
@@ -890,6 +1087,11 @@ int ggsn_vty_init(void)
install_element(GGSN_NODE, &cfg_ggsn_no_apn_cmd);
install_element(GGSN_NODE, &cfg_ggsn_default_apn_cmd);
install_element(GGSN_NODE, &cfg_ggsn_no_default_apn_cmd);
install_element(GGSN_NODE, &cfg_ggsn_show_sgsn_cmd);
install_element(GGSN_NODE, &cfg_ggsn_echo_interval_cmd);
install_element(GGSN_NODE, &cfg_ggsn_no_echo_interval_cmd);
osmo_tdef_vty_groups_init(GGSN_NODE, ggsn_tdef_group);
install_node(&apn_node, NULL);
install_element(APN_NODE, &cfg_description_cmd);
@@ -900,6 +1102,7 @@ int ggsn_vty_init(void)
install_element(APN_NODE, &cfg_apn_type_support_cmd);
install_element(APN_NODE, &cfg_apn_no_type_support_cmd);
install_element(APN_NODE, &cfg_apn_tun_dev_name_cmd);
install_element(APN_NODE, &cfg_apn_mtu_cmd);
install_element(APN_NODE, &cfg_apn_ipup_script_cmd);
install_element(APN_NODE, &cfg_apn_no_ipup_script_cmd);
install_element(APN_NODE, &cfg_apn_ipdown_script_cmd);
@@ -948,6 +1151,10 @@ static int ggsn_vty_go_parent(struct vty *vty)
vty->index_sub = &apn->ggsn->cfg.description;
}
break;
default:
vty->node = CONFIG_NODE;
vty->index = NULL;
vty->index_sub = NULL;
}
return vty->node;

View File

@@ -1,196 +0,0 @@
#ifdef __linux__
#define _GNU_SOURCE 1 /* strdup() prototype, broken arpa/inet.h */
#endif
#include "../config.h"
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <libgtpnl/gtp.h>
#include <libgtpnl/gtpnl.h>
#include <libmnl/libmnl.h>
#include <errno.h>
#include <time.h>
#include "../lib/tun.h"
#include "../lib/syserr.h"
#include "../gtp/pdp.h"
#include "../gtp/gtp.h"
#include <libgtpnl/gtp.h>
#include <libgtpnl/gtpnl.h>
#include <libmnl/libmnl.h>
#include "gtp-kernel.h"
static void pdp_debug(const char *prefix, const char *devname, struct pdp_t *pdp)
{
struct in46_addr ia46;
struct in_addr ia;
in46a_from_eua(&pdp->eua, &ia46);
gsna2in_addr(&ia, &pdp->gsnrc);
LOGPDPX(DGGSN, LOGL_DEBUG, pdp, "%s %s v%u TEID %"PRIx64" EUA=%s SGSN=%s\n", prefix,
devname, pdp->version,
pdp->version == 0 ? pdp_gettid(pdp->imsi, pdp->nsapi) : pdp->teid_gn,
in46a_ntoa(&ia46), inet_ntoa(ia));
}
static struct {
int genl_id;
struct mnl_socket *nl;
} gtp_nl;
static int gtp_kernel_init_once(void)
{
/* only initialize once */
if (gtp_nl.nl)
return 0;
gtp_nl.nl = genl_socket_open();
if (gtp_nl.nl == NULL) {
LOGP(DGGSN, LOGL_ERROR, "cannot create genetlink socket\n");
return -1;
}
gtp_nl.genl_id = genl_lookup_family(gtp_nl.nl, "gtp");
if (gtp_nl.genl_id < 0) {
LOGP(DGGSN, LOGL_ERROR, "cannot lookup GTP genetlink ID\n");
genl_socket_close(gtp_nl.nl);
gtp_nl.nl = NULL;
return -1;
}
LOGP(DGGSN, LOGL_NOTICE, "Initialized GTP kernel mode (genl ID is %d)\n", gtp_nl.genl_id);
return 0;
}
int gtp_kernel_init(struct gsn_t *gsn, const char *devname, struct in46_prefix *prefix, const char *ipup)
{
struct in_addr net;
const char *net_arg;
if (!gtp_nl.nl)
gtp_kernel_init_once();
if (prefix->addr.len != 4) {
LOGP(DGGSN, LOGL_ERROR, "we only support IPv4 in this path :/");
return -1;
}
net = prefix->addr.v4;
if (gtp_dev_create(-1, devname, gsn->fd0, gsn->fd1u) < 0) {
LOGP(DGGSN, LOGL_ERROR, "cannot create GTP tunnel device: %s\n",
strerror(errno));
return -1;
}
net_arg = in46p_ntoa(prefix);
DEBUGP(DGGSN, "Setting route to reach %s via %s\n", net_arg, devname);
if (gtp_dev_config(devname, &net, prefix->prefixlen) < 0) {
LOGP(DGGSN, LOGL_ERROR, "Cannot add route to reach network %s\n", net_arg);
}
/* launch script if it is set to bring up the route to reach
* the MS, eg. ip ro add 10.0.0.0/8 dev gtp0. Better add this
* using native rtnetlink interface given that we know the
* MS network mask, later.
*/
if (ipup) {
char cmd[1024];
int err;
/* eg. /home/ggsn/ipup gtp0 10.0.0.0/8 */
snprintf(cmd, sizeof(cmd), "%s %s %s", ipup, devname, net_arg);
cmd[sizeof(cmd)-1] = '\0';
err = system(cmd);
if (err < 0) {
LOGP(DGGSN, LOGL_ERROR, "Failed to launch script `%s'\n", ipup);
return -1;
}
}
LOGP(DGGSN, LOGL_NOTICE, "GTP kernel configured\n");
return 0;
}
void gtp_kernel_stop(const char *devname)
{
gtp_dev_destroy(devname);
}
int gtp_kernel_tunnel_add(struct pdp_t *pdp, const char *devname)
{
struct in_addr ms, sgsn;
struct gtp_tunnel *t;
int ret;
pdp_debug(__func__, devname, pdp);
t = gtp_tunnel_alloc();
if (t == NULL)
return -1;
memcpy(&ms, &pdp->eua.v[2], sizeof(struct in_addr));
memcpy(&sgsn, &pdp->gsnrc.v[0], sizeof(struct in_addr));
gtp_tunnel_set_ifidx(t, if_nametoindex(devname));
gtp_tunnel_set_version(t, pdp->version);
gtp_tunnel_set_ms_ip4(t, &ms);
gtp_tunnel_set_sgsn_ip4(t, &sgsn);
if (pdp->version == 0) {
gtp_tunnel_set_tid(t, pdp_gettid(pdp->imsi, pdp->nsapi));
gtp_tunnel_set_flowid(t, pdp->flru);
} else {
gtp_tunnel_set_i_tei(t, pdp->teid_own);
/* use the TEI advertised by SGSN when sending packets
* towards the SGSN */
gtp_tunnel_set_o_tei(t, pdp->teid_gn);
}
ret = gtp_add_tunnel(gtp_nl.genl_id, gtp_nl.nl, t);
gtp_tunnel_free(t);
return ret;
}
int gtp_kernel_tunnel_del(struct pdp_t *pdp, const char *devname)
{
struct gtp_tunnel *t;
int ret;
pdp_debug(__func__, devname, pdp);
t = gtp_tunnel_alloc();
if (t == NULL)
return -1;
gtp_tunnel_set_ifidx(t, if_nametoindex(devname));
gtp_tunnel_set_version(t, pdp->version);
if (pdp->version == 0) {
gtp_tunnel_set_tid(t, pdp_gettid(pdp->imsi, pdp->nsapi));
gtp_tunnel_set_flowid(t, pdp->flru);
} else {
gtp_tunnel_set_i_tei(t, pdp->teid_own);
}
ret = gtp_del_tunnel(gtp_nl.genl_id, gtp_nl.nl, t);
gtp_tunnel_free(t);
return ret;
}

View File

@@ -1,232 +0,0 @@
/* Minimal ICMPv6 code for generating router advertisements as required by
* relevant 3GPP specs for a GGSN with IPv6 PDP contexts */
/* (C) 2017 by Harald Welte <laforge@gnumonks.org>
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
* notice and this permission notice is included in all copies or
* substantial portions of the software.
*/
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <netinet/in.h>
#if defined(__FreeBSD__)
#include <sys/types.h> /* FreeBSD 10.x needs this before ip6.h */
#include <sys/endian.h>
#endif
#include <netinet/ip6.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/utils.h>
#include "checksum.h"
#include "../gtp/gtp.h"
#include "../gtp/pdp.h"
#include "../lib/ippool.h"
#include "../lib/syserr.h"
#include "config.h"
/* 29.061 11.2.1.3.4 IPv6 Router Configuration Variables in GGSN */
#define GGSN_MaxRtrAdvInterval 21600 /* 6 hours */
#define GGSN_MinRtrAdvInterval 16200 /* 4.5 hours */
#define GGSN_AdvValidLifetime 0xffffffff /* infinite */
#define GGSN_AdvPreferredLifetime 0xffffffff /* infinite */
struct icmpv6_hdr {
uint8_t type;
uint8_t code;
uint16_t csum;
} __attribute__ ((packed));
/* RFC4861 Section 4.2 */
struct icmpv6_radv_hdr {
struct icmpv6_hdr hdr;
uint8_t cur_ho_limit;
#if BYTE_ORDER == LITTLE_ENDIAN
uint8_t res:6,
m:1,
o:1;
#elif BYTE_ORDER == BIG_ENDIAN
uint8_t m:1,
o:1,
res:6;
#else
# error "Please fix <bits/endian.h>"
#endif
uint16_t router_lifetime;
uint32_t reachable_time;
uint32_t retrans_timer;
uint8_t options[0];
} __attribute__ ((packed));
/* RFC4861 Section 4.6 */
struct icmpv6_opt_hdr {
uint8_t type;
/* length in units of 8 octets, including type+len! */
uint8_t len;
uint8_t data[0];
} __attribute__ ((packed));
/* RFC4861 Section 4.6.2 */
struct icmpv6_opt_prefix {
struct icmpv6_opt_hdr hdr;
uint8_t prefix_len;
#if BYTE_ORDER == LITTLE_ENDIAN
uint8_t res:6,
a:1,
l:1;
#elif BYTE_ORDER == BIG_ENDIAN
uint8_t l:1,
a:1,
res:6;
#else
# error "Please fix <bits/endian.h>"
#endif
uint32_t valid_lifetime;
uint32_t preferred_lifetime;
uint32_t res2;
uint8_t prefix[16];
} __attribute__ ((packed));
/*! construct a 3GPP 29.061 compliant router advertisement for a given prefix
* \param[in] saddr Source IPv6 address for router advertisement
* \param[in] daddr Destination IPv6 address for router advertisement IPv6 header
* \param[in] prefix The single prefix to be advertised (/64 implied!)i
* \returns callee-allocated message buffer containing router advertisement */
struct msgb *icmpv6_construct_ra(const struct in6_addr *saddr,
const struct in6_addr *daddr,
const struct in6_addr *prefix)
{
struct msgb *msg = msgb_alloc_headroom(512,128, "IPv6 RA");
struct icmpv6_radv_hdr *ra;
struct icmpv6_opt_prefix *ra_opt_pref;
struct ip6_hdr *i6h;
uint32_t len;
uint16_t skb_csum;
OSMO_ASSERT(msg);
ra = (struct icmpv6_radv_hdr *) msgb_put(msg, sizeof(*ra));
ra->hdr.type = 134; /* see RFC4861 4.2 */
ra->hdr.code = 0; /* see RFC4861 4.2 */
ra->hdr.csum = 0; /* updated below */
ra->cur_ho_limit = 64; /* seems reasonable? */
/* the GGSN shall leave the M-flag cleared in the Router
* Advertisement messages */
ra->m = 0;
/* The GGSN may set the O-flag if there are additional
* configuration parameters that need to be fetched by the MS */
ra->o = 0; /* no DHCPv6 */
ra->res = 0;
/* RFC4861 Default: 3 * MaxRtrAdvInterval */
ra->router_lifetime = htons(3*GGSN_MaxRtrAdvInterval);
ra->reachable_time = 0; /* Unspecified */
/* RFC4861 Section 4.6.2 */
ra_opt_pref = (struct icmpv6_opt_prefix *) msgb_put(msg, sizeof(*ra_opt_pref));
ra_opt_pref->hdr.type = 3; /* RFC4861 4.6.2 */
ra_opt_pref->hdr.len = 4; /* RFC4861 4.6.2 */
ra_opt_pref->prefix_len = 64; /* only prefix length as per 3GPP */
/* The Prefix is contained in the Prefix Information Option of
* the Router Advertisements and shall have the A-flag set
* and the L-flag cleared */
ra_opt_pref->a = 1;
ra_opt_pref->l = 0;
ra_opt_pref->res = 0;
/* The lifetime of the prefix shall be set to infinity */
ra_opt_pref->valid_lifetime = htonl(GGSN_AdvValidLifetime);
ra_opt_pref->preferred_lifetime = htonl(GGSN_AdvPreferredLifetime);
ra_opt_pref->res2 = 0;
memcpy(ra_opt_pref->prefix, prefix, sizeof(ra_opt_pref->prefix));
/* checksum */
skb_csum = csum_partial(msgb_data(msg), msgb_length(msg), 0);
len = msgb_length(msg);
ra->hdr.csum = csum_ipv6_magic(saddr, daddr, len, IPPROTO_ICMPV6, skb_csum);
/* Push IPv6 header in front of ICMPv6 packet */
i6h = (struct ip6_hdr *) msgb_push(msg, sizeof(*i6h));
/* 4 bits version, 8 bits TC, 20 bits flow-ID */
i6h->ip6_ctlun.ip6_un1.ip6_un1_flow = htonl(0x60000000);
i6h->ip6_ctlun.ip6_un1.ip6_un1_plen = htons(len);
i6h->ip6_ctlun.ip6_un1.ip6_un1_nxt = IPPROTO_ICMPV6;
i6h->ip6_ctlun.ip6_un1.ip6_un1_hlim = 255;
i6h->ip6_src = *saddr;
i6h->ip6_dst = *daddr;
return msg;
}
/* Walidate an ICMPv6 router solicitation according to RFC4861 6.1.1 */
static bool icmpv6_validate_router_solicit(const uint8_t *pack, unsigned len)
{
const struct ip6_hdr *ip6h = (struct ip6_hdr *)pack;
//const struct icmpv6_hdr *ic6h = (struct icmpv6_hdr *) (pack + sizeof(*ip6h));
/* Hop limit field must have 255 */
if (ip6h->ip6_ctlun.ip6_un1.ip6_un1_hlim != 255)
return false;
/* FIXME: ICMP checksum is valid */
/* ICMP length (derived from IP length) is 8 or more octets */
if (ip6h->ip6_ctlun.ip6_un1.ip6_un1_plen < 8)
return false;
/* FIXME: All included options have a length > 0 */
/* FIXME: If IP source is unspecified, no source link-layer addr option */
return true;
}
/* handle incoming packets to the all-routers multicast address */
int handle_router_mcast(struct gsn_t *gsn, struct pdp_t *pdp,
const struct in6_addr *pdp_prefix,
const struct in6_addr *own_ll_addr,
const uint8_t *pack, unsigned len)
{
const struct ip6_hdr *ip6h = (struct ip6_hdr *)pack;
const struct icmpv6_hdr *ic6h = (struct icmpv6_hdr *) (pack + sizeof(*ip6h));
struct msgb *msg;
if (len < sizeof(*ip6h)) {
LOGP(DICMP6, LOGL_NOTICE, "Packet too short: %u bytes\n", len);
return -1;
}
/* we only treat ICMPv6 here */
if (ip6h->ip6_ctlun.ip6_un1.ip6_un1_nxt != IPPROTO_ICMPV6) {
LOGP(DICMP6, LOGL_DEBUG, "Ignoring non-ICMP to all-routers mcast\n");
return 0;
}
if (len < sizeof(*ip6h) + sizeof(*ic6h)) {
LOGP(DICMP6, LOGL_NOTICE, "Short ICMPv6 packet: %s\n", osmo_hexdump(pack, len));
return -1;
}
switch (ic6h->type) {
case 133: /* router solicitation */
if (ic6h->code != 0) {
LOGP(DICMP6, LOGL_NOTICE, "ICMPv6 type 133 but code %d\n", ic6h->code);
return -1;
}
if (!icmpv6_validate_router_solicit(pack, len)) {
LOGP(DICMP6, LOGL_NOTICE, "Invalid Router Solicitation: %s\n",
osmo_hexdump(pack, len));
return -1;
}
/* Send router advertisement from GGSN link-local
* address to MS link-local address, including prefix
* allocated to this PDP context */
msg = icmpv6_construct_ra(own_ll_addr, &ip6h->ip6_src, pdp_prefix);
/* Send the constructed RA to the MS */
gtp_data_req(gsn, pdp, msgb_data(msg), msgb_length(msg));
msgb_free(msg);
break;
default:
LOGP(DICMP6, LOGL_DEBUG, "Unknown ICMPv6 type %u\n", ic6h->type);
break;
}
return 0;
}

View File

@@ -1,9 +0,0 @@
#pragma once
#include "../gtp/gtp.h"
#include "../gtp/pdp.h"
int handle_router_mcast(struct gsn_t *gsn, struct pdp_t *pdp,
const struct in6_addr *pdp_prefix,
const struct in6_addr *own_ll_addr,
const uint8_t *pack, unsigned len);

263
ggsn/pco.c Normal file
View File

@@ -0,0 +1,263 @@
/*
* PCO parsing related code
* Copyright (C) 2002, 2003, 2004 Mondru AB.
* Copyright (C) 2017-2019 by Harald Welte <laforge@gnumonks.org>
* Copyright (C) 2019 sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
* notice and this permission notice is included in all copies or
* substantial portions of the software.
*
*/
#include <unistd.h>
#include <string.h>
#include <osmocom/core/msgb.h>
#include <osmocom/gsm/tlv.h>
#include "../lib/util.h"
#include "pco.h"
#include "ggsn.h"
/* determine if IPCP contains given option */
static const uint8_t *ipcp_contains_option(const struct ipcp_hdr *ipcp, size_t ipcp_len,
enum ipcp_options opt, size_t opt_minlen)
{
const uint8_t *cur_opt = ipcp->options;
/* iterate over Options and check if protocol contained */
while (cur_opt + sizeof(struct ipcp_option_hdr) <= (uint8_t*)ipcp + ipcp_len) {
const struct ipcp_option_hdr *cur_opt_hdr = (const struct ipcp_option_hdr *)cur_opt;
/* length value includes 2 bytes type/length */
if (cur_opt_hdr->len < sizeof(struct ipcp_option_hdr))
return NULL;
if (cur_opt_hdr->type == opt &&
cur_opt_hdr->len >= sizeof(struct ipcp_option_hdr) + opt_minlen)
return cur_opt;
cur_opt += cur_opt_hdr->len;
}
return NULL;
}
static const char *pap_welcome = "Welcome to OsmoGGSN " PACKAGE_VERSION;
/* Handle PAP protocol according to RFC 1334 */
static void process_pco_element_pap(const struct pco_element *pco_in, struct msgb *resp,
const struct apn_ctx *apn, struct pdp_t *pdp)
{
const struct pap_element *pap_in = (const struct pap_element *) pco_in->data;
uint16_t pap_in_len;
uint8_t peer_id_len;
const uint8_t *peer_id;
unsigned int pap_welcome_len;
uint8_t pap_out_size;
struct pap_element *pap_out;
if (pco_in->length < sizeof(struct pap_element))
goto ret_broken;
pap_in_len = osmo_load16be(&pap_in->len);
if (pco_in->length < pap_in_len)
goto ret_broken;
/* "pco_in->length > pap_in_len" is allowed: RFC1334 2.2 states:
"Octets outside the range of the Length field should be treated as
Data Link Layer padding and should be ignored on reception."
*/
switch (pap_in->code) {
case PAP_CODE_AUTH_REQ:
if (pap_in_len < sizeof(struct pap_element) + 1)
goto ret_broken_auth;
peer_id_len = pap_in->data[0];
if (pap_in_len < sizeof(struct pap_element) + 1 + peer_id_len)
goto ret_broken_auth;
peer_id = &pap_in->data[1];
LOGPPDP(LOGL_DEBUG, pdp, "PCO PAP PeerId = %s, ACKing\n",
osmo_quote_str((const char *)peer_id, peer_id_len));
/* Password-Length + Password following here, but we don't care */
/* Prepare response, we ACK all of them: */
pap_welcome_len = strlen(pap_welcome);
/* +1: Length field of pap_welcome Message */
pap_out_size = sizeof(struct pap_element) + 1 + pap_welcome_len;
pap_out = alloca(pap_out_size);
pap_out->code = PAP_CODE_AUTH_ACK;
pap_out->id = pap_in->id;
pap_out->len = htons(pap_out_size);
pap_out->data[0] = pap_welcome_len;
memcpy(pap_out->data+1, pap_welcome, pap_welcome_len);
msgb_t16lv_put(resp, PCO_P_PAP, pap_out_size, (uint8_t *) pap_out);
break;
case PAP_CODE_AUTH_ACK:
case PAP_CODE_AUTH_NAK:
default:
LOGPPDP(LOGL_NOTICE, pdp, "Unsupported PAP PCO Code %u, ignoring\n", pap_in->code);
break;
}
return;
ret_broken_auth:
LOGPPDP(LOGL_NOTICE, pdp, "Invalid PAP AuthenticateReq: %s, ignoring\n",
osmo_hexdump_nospc((const uint8_t *)pco_in, pco_in->length));
return;
ret_broken:
LOGPPDP(LOGL_NOTICE, pdp, "Invalid PAP PCO Length: %s, ignoring\n",
osmo_hexdump_nospc((const uint8_t *)pco_in, pco_in->length));
}
/* Handle IP Control Protocol, RFC 1332, extensions in RFC 1877 */
static void process_pco_element_ipcp(const struct pco_element *pco_elem, struct msgb *resp,
const struct apn_ctx *apn, struct pdp_t *pdp)
{
struct ippoolm_t *peer_v4 = pdp_get_peer_ipv(pdp, false);
const struct in46_addr *dns1 = &apn->v4.cfg.dns[0];
const struct in46_addr *dns2 = &apn->v4.cfg.dns[1];
uint8_t *start = resp->tail;
const struct ipcp_hdr *ipcp;
uint16_t ipcp_len;
uint8_t *len1, *len2;
unsigned int len_appended;
ptrdiff_t consumed;
size_t remain;
if (!peer_v4) {
LOGPPDP(LOGL_ERROR, pdp, "IPCP but no IPv4 type ?!?\n");
return;
}
ipcp = (const struct ipcp_hdr *)pco_elem->data;
consumed = (pco_elem->data - &pdp->pco_req.v[0]);
remain = sizeof(pdp->pco_req.v) - consumed;
ipcp_len = osmo_load16be(&ipcp->len);
if (remain < 0 || remain < ipcp_len) {
LOGPPDP(LOGL_ERROR, pdp, "Malformed IPCP, ignoring\n");
return;
}
/* Three byte T16L header */
msgb_put_u16(resp, 0x8021); /* IPCP */
len1 = msgb_put(resp, 1); /* Length of contents: delay */
msgb_put_u8(resp, 0x02); /* ACK */
msgb_put_u8(resp, ipcp->id); /* ID: Needs to match request */
msgb_put_u8(resp, 0x00); /* Length MSB */
len2 = msgb_put(resp, 1); /* Length LSB: delay */
if (dns1->len == 4 && ipcp_contains_option(ipcp, ipcp_len, IPCP_OPT_PRIMARY_DNS, 4)) {
msgb_put_u8(resp, 0x81); /* DNS1 Tag */
msgb_put_u8(resp, 2 + dns1->len); /* DNS1 Length, incl. TL */
msgb_put_u32(resp, ntohl(dns1->v4.s_addr));
}
if (dns2->len == 4 && ipcp_contains_option(ipcp, ipcp_len, IPCP_OPT_SECONDARY_DNS, 4)) {
msgb_put_u8(resp, 0x83); /* DNS2 Tag */
msgb_put_u8(resp, 2 + dns2->len); /* DNS2 Length, incl. TL */
msgb_put_u32(resp, ntohl(dns2->v4.s_addr));
}
/* patch in length values */
len_appended = resp->tail - start;
*len1 = len_appended - 3;
*len2 = len_appended - 3;
}
static void process_pco_element_dns_ipv6(const struct pco_element *pco_elem, struct msgb *resp,
const struct apn_ctx *apn, struct pdp_t *pdp)
{
unsigned int i;
const uint8_t *tail = resp->tail;
for (i = 0; i < ARRAY_SIZE(apn->v6.cfg.dns); i++) {
const struct in46_addr *i46a = &apn->v6.cfg.dns[i];
if (i46a->len != 16)
continue;
msgb_t16lv_put(resp, PCO_P_DNS_IPv6_ADDR, i46a->len, i46a->v6.s6_addr);
}
if (resp->tail == tail)
LOGPPDP(LOGL_NOTICE, pdp, "MS requested IPv6 DNS, but APN has none configured\n");
}
static void process_pco_element_dns_ipv4(const struct pco_element *pco_elem, struct msgb *resp,
const struct apn_ctx *apn, struct pdp_t *pdp)
{
unsigned int i;
const uint8_t *tail = resp->tail;
for (i = 0; i < ARRAY_SIZE(apn->v4.cfg.dns); i++) {
const struct in46_addr *i46a = &apn->v4.cfg.dns[i];
if (i46a->len != 4)
continue;
msgb_t16lv_put(resp, PCO_P_DNS_IPv4_ADDR, i46a->len, (uint8_t *)&i46a->v4);
}
if (resp->tail == tail)
LOGPPDP(LOGL_NOTICE, pdp, "MS requested IPv4 DNS, but APN has none configured\n");
}
static void process_pco_element_link_mtu_ipv4(const struct pco_element *pco_elem, struct msgb *resp,
const struct apn_ctx *apn, struct pdp_t *pdp)
{
const uint16_t val_be = osmo_htons(apn->cfg.mtu);
msgb_t16lv_put(resp, PCO_P_IPv4_LINK_MTU, 2, (const uint8_t *)&val_be);
}
static void process_pco_element(const struct pco_element *pco_elem, struct msgb *resp,
const struct apn_ctx *apn, struct pdp_t *pdp)
{
uint16_t protocol_id = osmo_load16be(&pco_elem->protocol_id);
LOGPPDP(LOGL_DEBUG, pdp, "PCO Protocol 0x%04x\n", protocol_id);
switch (protocol_id) {
case PCO_P_PAP:
process_pco_element_pap(pco_elem, resp, apn, pdp);
break;
case PCO_P_IPCP:
process_pco_element_ipcp(pco_elem, resp, apn, pdp);
break;
case PCO_P_DNS_IPv6_ADDR:
process_pco_element_dns_ipv6(pco_elem, resp, apn, pdp);
break;
case PCO_P_DNS_IPv4_ADDR:
process_pco_element_dns_ipv4(pco_elem, resp, apn, pdp);
break;
case PCO_P_IPv4_LINK_MTU:
process_pco_element_link_mtu_ipv4(pco_elem, resp, apn, pdp);
break;
default:
LOGPPDP(LOGL_INFO, pdp, "Unknown/Unimplemented PCO Protocol 0x%04x: %s\n",
protocol_id, osmo_hexdump_nospc(pco_elem->data, pco_elem->length));
break;
}
}
/* process one PCO request from a MS/UE, putting together the proper responses */
void process_pco(const struct apn_ctx *apn, struct pdp_t *pdp)
{
struct msgb *resp = msgb_alloc(256, "PCO.resp");
const struct ul255_t *pco = &pdp->pco_req;
const struct pco_element *pco_elem;
const uint8_t *cur;
/* build the header of the PCO response */
OSMO_ASSERT(resp);
msgb_put_u8(resp, 0x80); /* ext-bit + configuration protocol byte */
/* iterate over the PCO elements in the request; call process_pco_element() for each */
for (cur = pco->v + 1, pco_elem = (const struct pco_element *) cur;
cur + sizeof(struct pco_element) <= pco->v + pco->l;
cur += pco_elem->length + sizeof(*pco_elem), pco_elem = (const struct pco_element *) cur) {
process_pco_element(pco_elem, resp, apn, pdp);
}
/* copy the PCO response msgb and copy its contents over to the PDP context */
if (msgb_length(resp) > 1) {
memcpy(pdp->pco_neg.v, msgb_data(resp), msgb_length(resp));
pdp->pco_neg.l = msgb_length(resp);
} else
pdp->pco_neg.l = 0;
msgb_free(resp);
}

80
ggsn/pco.h Normal file
View File

@@ -0,0 +1,80 @@
#pragma once
#include <stdint.h>
#include <osmocom/gtp/pdp.h>
/* 3GPP TS 24.008 10.5.6.3 */
enum pco_protocols {
PCO_P_LCP = 0xC021,
PCO_P_PAP = 0xC023,
PCO_P_CHAP = 0xC223,
PCO_P_IPCP = 0x8021,
PCO_P_PCSCF_ADDR = 0x0001,
PCO_P_IM_CN_SS_F = 0x0002,
PCO_P_DNS_IPv6_ADDR = 0x0003,
PCO_P_POLICY_CTRL_REJ = 0x0004, /* only in Network->MS */
PCO_P_MS_SUP_NETREQ_BCI = 0x0005,
/* reserved */
PCO_P_DSMIPv6_HA_ADDR = 0x0007,
PCO_P_DSMIPv6_HN_PREF = 0x0008,
PCO_P_DSMIPv6_v4_HA_ADDR= 0x0009,
PCO_P_IP_ADDR_VIA_NAS = 0x000a, /* only MS->Network */
PCO_P_IPv4_ADDR_VIA_DHCP= 0x000b, /* only MS->Netowrk */
PCO_P_PCSCF_IPv4_ADDR = 0x000c,
PCO_P_DNS_IPv4_ADDR = 0x000d,
PCO_P_MSISDN = 0x000e,
PCO_P_IFOM_SUPPORT = 0x000f,
PCO_P_IPv4_LINK_MTU = 0x0010,
PCO_P_MS_SUPP_LOC_A_TFT = 0x0011,
PCO_P_PCSCF_RESEL_SUP = 0x0012, /* only MS->Network */
PCO_P_NBIFOM_REQ = 0x0013,
PCO_P_NBIFOM_MODE = 0x0014,
PCO_P_NONIP_LINK_MTU = 0x0015,
PCO_P_APN_RATE_CTRL_SUP = 0x0016,
PCO_P_PS_DATA_OFF_UE = 0x0017,
PCO_P_REL_DATA_SVC = 0x0018,
};
struct pco_element {
uint16_t protocol_id; /* network byte order */
uint8_t length; /* length of data below */
uint8_t data[0];
} __attribute__((packed));
/* RFC 1332 IP Control Protocol options, extensions in RFC 1877 */
enum ipcp_options {
IPCP_OPT_IPADDR = 3, /* RFC 1332 3.3 */
IPCP_OPT_PRIMARY_DNS = 129, /* RFC 1877 1.1 */
IPCP_OPT_SECONDARY_DNS = 131, /* RFC 1877 1.2 */
};
struct ipcp_option_hdr {
uint8_t type;
uint8_t len;
uint8_t data[0];
} __attribute__ ((packed));
struct ipcp_hdr {
uint8_t code;
uint8_t id;
uint16_t len;
uint8_t options[0];
} __attribute__ ((packed));
/* RFC 1334, section 3.2. Packet Format */
struct pap_element {
uint8_t code;
uint8_t id;
uint16_t len; /* length including header */
uint8_t data[0];
} __attribute__((packed));
enum pap_code {
PAP_CODE_AUTH_REQ = 1,
PAP_CODE_AUTH_ACK = 2,
PAP_CODE_AUTH_NAK = 3,
};
struct apn_ctx;
void process_pco(const struct apn_ctx *apn, struct pdp_t *pdp);

168
ggsn/sgsn.c Normal file
View File

@@ -0,0 +1,168 @@
#include "sgsn.h"
#include "ggsn.h"
#include "../gtp/gtp_internal.h"
static bool sgsn_peer_attempt_free(struct sgsn_peer *sgsn)
{
/* We have to be careful here, since if all pdp ctx for that sgsn were
deactivated in-between we sent the Echo Req and receivied the timeout
indication, the sgsn (cbp) may be already gone. We need to add some
counter reference of echo requets in flight and only free sgsn
structures when it goes to zero decreased for all Echo Resp. We do it
this way because currently in libgtp there's no understanding of "gsn
peer" for which messages are grouped and hence we cannot request
libgtp to drop all queued messages for a specific peer. */
if (sgsn->tx_msgs_queued) {
LOGSGSN(LOGL_INFO, sgsn, "Delaying delete, still %u echo messages queued\n",
sgsn->tx_msgs_queued);
return false;
}
llist_del(&sgsn->entry);
LOGSGSN(LOGL_INFO, sgsn, "Deleting SGSN\n");
talloc_free(sgsn);
return true;
}
static void sgsn_peer_echo_req(struct sgsn_peer *sgsn)
{
struct ggsn_ctx *ggsn = sgsn->ggsn;
LOGSGSN(LOGL_INFO, sgsn, "Tx Echo Request\n");
gtp_echo_req(ggsn->gsn, sgsn->gtp_version, sgsn, &sgsn->addr);
sgsn->tx_msgs_queued++;
}
void sgsn_peer_echo_resp(struct sgsn_peer *sgsn, bool timeout)
{
if (timeout) {
LOGSGSN(LOGL_NOTICE, sgsn, "Rx Echo Request timed out!\n");
sgsn_peer_drop_all_pdp(sgsn);
} else {
LOGSGSN(LOGL_INFO, sgsn, "Rx Echo Response\n");
}
/* We decrement it here after dropping all pdps to make sure sgsn was
not freed upon last pdp ctx deleted and is still alive now */
sgsn->tx_msgs_queued--;
if (llist_empty(&sgsn->pdp_list))
sgsn_peer_attempt_free(sgsn);
}
void sgsn_echo_timer_start(struct sgsn_peer *sgsn)
{
if (sgsn->ggsn->cfg.echo_interval == 0)
return;
sgsn_peer_echo_req(sgsn);
osmo_timer_schedule(&sgsn->echo_timer, sgsn->ggsn->cfg.echo_interval, 0);
}
void sgsn_echo_timer_stop(struct sgsn_peer *sgsn)
{
osmo_timer_del(&sgsn->echo_timer);
}
static void sgsn_echo_timer_cb(void *data)
{
struct sgsn_peer *sgsn = (struct sgsn_peer *) data;
sgsn_echo_timer_start(sgsn);
}
struct sgsn_peer *sgsn_peer_allocate(struct ggsn_ctx *ggsn, struct in_addr *ia, unsigned int gtp_version)
{
struct sgsn_peer *sgsn;
sgsn = talloc_zero_size(ggsn, sizeof(struct sgsn_peer));
sgsn->ggsn = ggsn;
sgsn->addr = *ia;
sgsn->gtp_version = gtp_version;
sgsn->remote_restart_ctr = -1;
INIT_LLIST_HEAD(&sgsn->pdp_list);
INIT_LLIST_HEAD(&sgsn->entry);
osmo_timer_setup(&sgsn->echo_timer, sgsn_echo_timer_cb, sgsn);
LOGSGSN(LOGL_INFO, sgsn, "Discovered\n");
return sgsn;
}
void sgsn_peer_add_pdp_priv(struct sgsn_peer *sgsn, struct pdp_priv_t *pdp_priv)
{
bool was_empty = llist_empty(&sgsn->pdp_list);
pdp_priv->sgsn = sgsn;
llist_add(&pdp_priv->entry, &sgsn->pdp_list);
if (was_empty)
sgsn_echo_timer_start(sgsn);
}
void sgsn_peer_remove_pdp_priv(struct pdp_priv_t* pdp_priv)
{
struct sgsn_peer *sgsn = pdp_priv->sgsn;
llist_del(&pdp_priv->entry);
if (sgsn && llist_empty(&sgsn->pdp_list)) {
/* No PDP contexts associated to this SGSN, no need to keep it */
sgsn_echo_timer_stop(sgsn);
/* sgsn may not be freed if there are some messages still queued
in libgtp which could return a pointer to it */
sgsn_peer_attempt_free(sgsn);
}
pdp_priv->sgsn = NULL;
}
/* High-level function to be called in case a GGSN has disappeared or
* otherwise lost state (recovery procedure). It will detach all related pdp ctx
* from a ggsn and communicate deact to MS. Optionally (!NULL), one pdp ctx can
* be kept alive to allow handling later message which contained the Recovery IE. */
static unsigned int sgsn_peer_drop_all_pdp_except(struct sgsn_peer *sgsn, struct pdp_priv_t *except)
{
unsigned int num = 0;
char buf[INET_ADDRSTRLEN];
unsigned int count = llist_count(&sgsn->pdp_list);
inet_ntop(AF_INET, &sgsn->addr, buf, sizeof(buf));
struct pdp_priv_t *pdp, *pdp2;
llist_for_each_entry_safe(pdp, pdp2, &sgsn->pdp_list, entry) {
if (pdp == except)
continue;
ggsn_close_one_pdp(pdp->lib);
num++;
if (num == count) {
/* Note: if except is NULL, all pdp contexts are freed and sgsn
* is most probably already freed at this point.
* As a result, last access to sgsn->pdp_list before exiting
* loop would access already freed memory. Avoid it by exiting
* the loop without the last check, and make sure sgsn is not
* accessed after this loop. */
break;
}
}
LOGP(DGGSN, LOGL_INFO, "SGSN(%s) Dropped %u PDP contexts\n", buf, num);
return num;
}
unsigned int sgsn_peer_drop_all_pdp(struct sgsn_peer *sgsn)
{
return sgsn_peer_drop_all_pdp_except(sgsn, NULL);
}
int sgsn_peer_handle_recovery(struct sgsn_peer *sgsn, struct pdp_t *pdp, uint8_t recovery)
{
struct pdp_priv_t *pdp_priv = NULL;
if (sgsn->remote_restart_ctr == -1) {
/* First received ECHO RESPONSE, note the restart ctr */
sgsn->remote_restart_ctr = recovery;
} else if (sgsn->remote_restart_ctr != recovery) {
/* counter has changed (SGSN restart): release all PDP */
LOGSGSN(LOGL_NOTICE, sgsn, "SGSN recovery (%u->%u) pdp=%p, "
"releasing all%s PDP contexts\n",
sgsn->remote_restart_ctr, recovery, pdp, pdp ? " other" : "");
sgsn->remote_restart_ctr = recovery;
if (pdp)
pdp_priv = pdp->priv;
sgsn_peer_drop_all_pdp_except(sgsn, pdp_priv);
}
return 0;
}

46
ggsn/sgsn.h Normal file
View File

@@ -0,0 +1,46 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/timer.h>
#include <osmocom/gtp/pdp.h>
struct ggsn_ctx;
struct pdp_priv_t;
struct sgsn_peer {
struct llist_head entry; /* to be included into ggsn_ctx */
struct ggsn_ctx *ggsn; /* backpointer to ggsn_ctx */
struct in_addr addr; /* Addr of the sgsn peer */
unsigned int gtp_version; /* GTP version */
int remote_restart_ctr; /* Last received Restart Ctr from sgsn peer, -1 == unknown */
/* list of pdp contexts associated with this sgsn */
struct llist_head pdp_list;
/* Sends echo request towards SGSN on expiration. Echo Resp is received
through cb_recovery2(), and echo Req timeout through
cb_conf(GTP_ECHO_REQ, EOF, NULL, cbp); */
struct osmo_timer_list echo_timer;
/* Number of GTP messages in libgtp transmit queue */
unsigned int tx_msgs_queued;
};
struct sgsn_peer *sgsn_peer_allocate(struct ggsn_ctx *ggsn, struct in_addr *ia, unsigned int gtp_version);
void sgsn_peer_add_pdp_priv(struct sgsn_peer *sgsn, struct pdp_priv_t *pdp_priv);
void sgsn_peer_remove_pdp_priv(struct pdp_priv_t *pdp_priv);
void sgsn_echo_timer_start(struct sgsn_peer *sgsn);
void sgsn_echo_timer_stop(struct sgsn_peer *sgsn);
void sgsn_peer_echo_resp(struct sgsn_peer *sgsn, bool timeout);
unsigned int sgsn_peer_drop_all_pdp(struct sgsn_peer *sgsn);
int sgsn_peer_handle_recovery(struct sgsn_peer *sgsn, struct pdp_t *pdp, uint8_t recovery);
#define LOGSGSN(level, sgsn, fmt, args...) { \
char _buf[INET_ADDRSTRLEN]; \
LOGP(DGGSN, level, "SGSN(%s): " fmt, inet_ntop(AF_INET, &sgsn->addr, _buf, sizeof(_buf)), ## args); \
} while (0)

View File

@@ -1,17 +1,31 @@
# This is _NOT_ the library release version, it's an API version.
# Please read chapter "Library interface versions" of the libtool documentation
# before making any modifications: https://www.gnu.org/software/libtool/manual/html_node/Versioning.html
LIBVERSION=2:0:0
# If major=current-age is increased, remember to update the dh_strip line in debian/rules!
LIBVERSION=11:0:0
lib_LTLIBRARIES = libgtp.la
include_HEADERS = gtp.h pdp.h gtpie.h
AM_CFLAGS = \
-fno-builtin \
-Wall \
-DSBINDIR='"$(sbindir)"' \
-I$(top_srcdir)/include \
$(LIBOSMOCORE_CFLAGS) \
$(NULL)
AM_CFLAGS = -O2 -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb $(LIBOSMOCORE_CFLAGS)
libgtp_la_SOURCES = \
gsn.c \
gsn_internal.h \
gtp.c \
gtp_internal.h \
gtpie.c \
lookupa.c \
lookupa.h \
pdp.c \
queue.c \
queue.h \
$(NULL)
libgtp_la_SOURCES = gtp.c gtp.h gtpie.c gtpie.h pdp.c pdp.h lookupa.c lookupa.h queue.c queue.h
libgtp_la_LDFLAGS = -version-info $(LIBVERSION) -no-undefined
libgtp_la_LIBADD = $(LIBOSMOCORE_LIBS)

587
gtp/gsn.c Normal file
View File

@@ -0,0 +1,587 @@
/*
* OsmoGGSN - Gateway GPRS Support Node
* Copyright (C) 2002, 2003, 2004 Mondru AB.
* Copyright (C) 2010-2011, 2016-2017 Harald Welte <laforge@gnumonks.org>
* Copyright (C) 2015-2017 sysmocom - s.f.m.c. GmbH
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
* notice and this permission notice is included in all copies or
* substantial portions of the software.
*
*/
/*
* gtp.c: Contains all GTP functionality. Should be able to handle multiple
* tunnels in the same program.
*
* TODO:
* - Do we need to handle fragmentation?
*/
#ifdef __linux__
#define _GNU_SOURCE 1
#endif
#include <osmocom/core/logging.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/stats.h>
#include <osmocom/core/rate_ctr.h>
#if defined(__FreeBSD__)
#include <sys/endian.h>
#endif
#include "../config.h"
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <arpa/inet.h>
/* #include <stdint.h> ISO C99 types */
#include <osmocom/gtp/pdp.h>
#include <osmocom/gtp/gtp.h>
#include <osmocom/gtp/gtpie.h>
#include "queue.h"
#include "gsn_internal.h"
#include "gtp_internal.h"
/* Error reporting functions */
#define LOGP_WITH_ADDR(ss, level, addr, fmt, args...) \
LOGP(ss, level, "addr(%s:%d) " fmt, \
inet_ntoa((addr).sin_addr), htons((addr).sin_port), \
##args)
static const struct rate_ctr_desc gsn_ctr_description[] = {
[GSN_CTR_ERR_SOCKET] = { "err:socket", "Socket error" },
[GSN_CTR_ERR_READFROM] = { "err:readfrom", "readfrom() errors" },
[GSN_CTR_ERR_SENDTO] = { "err:sendto", "sendto() errors" },
[GSN_CTR_ERR_QUEUEFULL] = { "err:queuefull", "Failed to queue message because queue is full" },
[GSN_CTR_ERR_SEQ] = { "err:seq", "Sequence number out of range" },
[GSN_CTR_ERR_ADDRESS] = { "err:address", "GSN address conversion failed" },
[GSN_CTR_ERR_UNKNOWN_PDP] = { "err:unknown_pdp", "Failed looking up PDP context" },
[GSN_CTR_ERR_UNEXPECTED_CAUSE] = { "err:unexpected_cause", "Unexpected cause value received" },
[GSN_CTR_ERR_OUT_OF_PDP] = { "err:out_of_pdp", "Out of storage for PDP contexts" },
[GSN_CTR_PKT_EMPTY] = { "pkt:empty", "Empty packet received" },
[GSN_CTR_PKT_UNSUP] = { "pkt:unsupported", "Unsupported GTP version received" },
[GSN_CTR_PKT_TOOSHORT] = { "pkt:too_short", "Packet too short received" },
[GSN_CTR_PKT_UNKNOWN] = { "pkt:unknown", "Unknown packet type received" },
[GSN_CTR_PKT_UNEXPECT] = { "pkt:unexpected", "Unexpected packet type received" },
[GSN_CTR_PKT_DUPLICATE] = { "pkt:duplicate", "Duplicate or unsolicited packet received" },
[GSN_CTR_PKT_MISSING] = { "pkt:missing", "Missing IE in packet received" },
[GSN_CTR_PKT_INCORRECT] = { "pkt:incorrect", "Incorrect IE in packet received" },
[GSN_CTR_PKT_INVALID] = { "pkt:invalid", "Invalid format in packet received" },
};
static const struct rate_ctr_group_desc gsn_ctrg_desc = {
"gsn",
"GSN Statistics",
OSMO_STATS_CLASS_PEER,
ARRAY_SIZE(gsn_ctr_description),
gsn_ctr_description,
};
static unsigned int gsn_ctr_next_idx = 0;
/* Global timer definitions for GTP operation, provided for convenience. To make these user configurable, it is convenient to add
* gtp_gsn_tdefs as one of your program's osmo_tdef_group entries and call osmo_tdef_vty_init(). */
struct osmo_tdef gtp_T_defs[] = {
{ .T = GTP_GSN_TIMER_T3_RESPONSE, .default_val = 5, .unit = OSMO_TDEF_S,
.desc = "Timer T3-RESPONSE holds the maximum wait time for a response of a request message"
},
{ .T = GTP_GSN_TIMER_N3_REQUESTS, .default_val = 3, .unit = OSMO_TDEF_CUSTOM,
.desc = "Counter N3-REQUESTS holds the maximum number of attempts made by GTP to send a request message"
},
{ .T = GTP_GSN_TIMER_T3_HOLD_RESPONSE, .default_val = 5 * 3 /* (GTP_GSN_TIMER_T3_RESPONSE * GTP_GSN_TIMER_N3_REQUESTS) */, .unit = OSMO_TDEF_S,
.desc = "Time a GTP respoonse message is kept cached to re-transmit it when a duplicate request is received. Value is generally equal to (T3-RESPONSE * N3-REQUESTS) set at the peer"
},
{}
};
/* API Functions */
/* Deprecated, use gtp_pdp_newpdp() instead */
int gtp_newpdp(struct gsn_t *gsn, struct pdp_t **pdp,
uint64_t imsi, uint8_t nsapi)
{
int rc;
rc = gtp_pdp_newpdp(gsn, pdp, imsi, nsapi, NULL);
return rc;
}
int gtp_freepdp(struct gsn_t *gsn, struct pdp_t *pdp)
{
if (gsn->cb_delete_context)
gsn->cb_delete_context(pdp);
return pdp_freepdp(pdp);
}
/* Free pdp and all its secondary PDP contexts. Must be called on the primary PDP context. */
int gtp_freepdp_teardown(struct gsn_t *gsn, struct pdp_t *pdp)
{
int n;
struct pdp_t *secondary_pdp;
OSMO_ASSERT(!pdp->secondary);
for (n = 0; n < PDP_MAXNSAPI; n++) {
if (pdp->secondary_tei[n]) {
if (gtp_pdp_getgtp1(gsn, &secondary_pdp,
pdp->secondary_tei[n])) {
LOGP(DLGTP, LOGL_ERROR,
"Unknown secondary PDP context\n");
continue;
}
if (pdp != secondary_pdp) {
gtp_freepdp(gsn, secondary_pdp);
}
}
}
return gtp_freepdp(gsn, pdp);
}
/* gtp_gpdu */
extern int gtp_fd(struct gsn_t *gsn)
{
return gsn->fd0;
}
int gtp_set_cb_unsup_ind(struct gsn_t *gsn,
int (*cb) (struct sockaddr_in * peer))
{
gsn->cb_unsup_ind = cb;
return 0;
}
int gtp_set_cb_extheader_ind(struct gsn_t *gsn,
int (*cb) (struct sockaddr_in * peer))
{
gsn->cb_extheader_ind = cb;
return 0;
}
int gtp_set_cb_ran_info_relay_ind(struct gsn_t *gsn,
int (*cb) (struct sockaddr_in * peer, union gtpie_member **ie))
{
gsn->cb_ran_info_relay_ind = cb;
return 0;
}
/* API: Initialise delete context callback */
/* Called whenever a pdp context is deleted for any reason */
int gtp_set_cb_delete_context(struct gsn_t *gsn, int (*cb) (struct pdp_t * pdp))
{
gsn->cb_delete_context = cb;
return 0;
}
int gtp_set_cb_conf(struct gsn_t *gsn,
int (*cb) (int type, int cause,
struct pdp_t * pdp, void *cbp))
{
gsn->cb_conf = cb;
return 0;
}
int gtp_set_cb_recovery(struct gsn_t *gsn,
int (*cb) (struct sockaddr_in * peer, uint8_t recovery))
{
gsn->cb_recovery = cb;
return 0;
}
/* cb_recovery()
* pdp may be NULL if Recovery IE was received from a message independent
* of any PDP ctx (such as Echo Response), or because pdp ctx is unknown to the
* local setup. In case pdp is known, caller may want to keep that pdp alive to
* handle subsequent msg cb as this specific pdp ctx is still valid according to
* specs.
*/
int gtp_set_cb_recovery2(struct gsn_t *gsn,
int (*cb_recovery2) (struct sockaddr_in * peer, struct pdp_t * pdp, uint8_t recovery))
{
gsn->cb_recovery2 = cb_recovery2;
return 0;
}
/* cb_recovery()
* pdp may be NULL if Recovery IE was received from a message independent
* of any PDP ctx (such as Echo Response), or because pdp ctx is unknown to the
* local setup. In case pdp is known, caller may want to keep that pdp alive to
* handle subsequent msg cb as this specific pdp ctx is still valid according to
* specs.
*/
int gtp_set_cb_recovery3(struct gsn_t *gsn,
int (*cb_recovery3) (struct gsn_t *gsn, struct sockaddr_in *peer,
struct pdp_t *pdp, uint8_t recovery))
{
gsn->cb_recovery3 = cb_recovery3;
return 0;
}
int gtp_set_cb_data_ind(struct gsn_t *gsn,
int (*cb_data_ind) (struct pdp_t * pdp,
void *pack, unsigned len))
{
gsn->cb_data_ind = cb_data_ind;
return 0;
}
static int queue_timer_retrans(struct gsn_t *gsn)
{
/* Retransmit any outstanding packets */
/* Remove from queue if maxretrans exceeded */
time_t now;
struct qmsg_t *qmsg;
unsigned int t3_response, n3_requests;
now = time(NULL);
t3_response = osmo_tdef_get(gsn->tdef, GTP_GSN_TIMER_T3_RESPONSE, OSMO_TDEF_S, -1);
n3_requests = osmo_tdef_get(gsn->tdef, GTP_GSN_TIMER_N3_REQUESTS, OSMO_TDEF_CUSTOM, -1);
/* get first element in queue, as long as the timeout of that
* element has expired */
while ((!queue_getfirst(gsn->queue_req, &qmsg)) &&
(qmsg->timeout <= now)) {
if (qmsg->retrans > n3_requests) { /* Too many retrans */
LOGP(DLGTP, LOGL_NOTICE, "Retransmit req queue timeout of seq %" PRIu16 "\n",
qmsg->seq);
if (gsn->cb_conf)
gsn->cb_conf(qmsg->type, EOF, NULL, qmsg->cbp);
queue_freemsg(gsn->queue_req, qmsg);
} else {
LOGP(DLGTP, LOGL_INFO, "Retransmit (%d) of seq %" PRIu16 "\n",
qmsg->retrans, qmsg->seq);
if (sendto(qmsg->fd, &qmsg->p, qmsg->l, 0,
(struct sockaddr *)&qmsg->peer,
sizeof(struct sockaddr_in)) < 0) {
rate_ctr_inc2(gsn->ctrg, GSN_CTR_ERR_SENDTO);
LOGP(DLGTP, LOGL_ERROR,
"Sendto(fd0=%d, msg=%lx, len=%d) failed: Error = %s\n",
gsn->fd0, (unsigned long)&qmsg->p,
qmsg->l, strerror(errno));
}
queue_back(gsn->queue_req, qmsg);
qmsg->timeout = now + t3_response;
qmsg->retrans++;
}
}
/* Also clean up reply timeouts */
while ((!queue_getfirst(gsn->queue_resp, &qmsg)) &&
(qmsg->timeout < now)) {
LOGP(DLGTP, LOGL_DEBUG, "Retransmit resp queue seq %"
PRIu16 " expired, removing from queue\n", qmsg->seq);
queue_freemsg(gsn->queue_resp, qmsg);
}
return 0;
}
static int queue_timer_retranstimeout(struct gsn_t *gsn, struct timeval *timeout)
{
time_t now, later, diff;
struct qmsg_t *qmsg;
timeout->tv_usec = 0;
if (queue_getfirst(gsn->queue_req, &qmsg)) {
timeout->tv_sec = 10;
} else {
now = time(NULL);
later = qmsg->timeout;
timeout->tv_sec = later - now;
if (timeout->tv_sec < 0)
timeout->tv_sec = 0; /* No negative allowed */
if (timeout->tv_sec > 10)
timeout->tv_sec = 10; /* Max sleep for 10 sec */
}
if (queue_getfirst(gsn->queue_resp, &qmsg)) {
/* already set by queue_req, do nothing */
} else { /* trigger faster if earlier timeout exists in queue_resp */
now = time(NULL);
later = qmsg->timeout;
diff = later - now;
if (diff < 0)
diff = 0;
if (diff < timeout->tv_sec)
timeout->tv_sec = diff;
}
return 0;
}
void gtp_queue_timer_start(struct gsn_t *gsn)
{
struct timeval next;
/* Retrieve next retransmission as timeval */
queue_timer_retranstimeout(gsn, &next);
/* re-schedule the timer */
osmo_timer_schedule(&gsn->queue_timer, next.tv_sec, next.tv_usec/1000);
}
/* timer callback for libgtp retransmission and ping */
static void queue_timer_cb(void *data)
{
struct gsn_t *gsn = data;
/* do all the retransmissions as needed */
queue_timer_retrans(gsn);
gtp_queue_timer_start(gsn);
}
/**
* @brief clear the request and response queue. Useful for debugging to reset "some" state.
* @param gsn The GGSN instance
*/
void gtp_clear_queues(struct gsn_t *gsn)
{
struct qmsg_t *qmsg;
LOGP(DLGTP, LOGL_INFO, "Clearing req & resp retransmit queues\n");
while (!queue_getfirst(gsn->queue_req, &qmsg)) {
queue_freemsg(gsn->queue_req, qmsg);
}
while (!queue_getfirst(gsn->queue_resp, &qmsg)) {
queue_freemsg(gsn->queue_resp, qmsg);
}
}
/* Perform restoration and recovery error handling as described in 29.060 */
static void log_restart(struct gsn_t *gsn)
{
FILE *f;
int i, rc;
int counter = 0;
char *filename;
filename = talloc_asprintf(NULL, "%s/%s", gsn->statedir, RESTART_FILE);
OSMO_ASSERT(filename);
/* We try to open file. On failure we will later try to create file */
if (!(f = fopen(filename, "r"))) {
LOGP(DLGTP, LOGL_NOTICE,
"State information file (%s) not found. Creating new file.\n",
filename);
} else {
rc = fscanf(f, "%d", &counter);
if (rc != 1) {
LOGP(DLGTP, LOGL_ERROR,
"fscanf failed to read counter value\n");
goto close_file;
}
if (fclose(f)) {
LOGP(DLGTP, LOGL_ERROR,
"fclose failed: Error = %s\n", strerror(errno));
}
}
gsn->restart_counter = (unsigned char)counter;
gsn->restart_counter++;
/* Keep the umask closely wrapped around our fopen() call in case the
* log outputs cause file creation. */
i = umask(022);
f = fopen(filename, "w");
umask(i);
if (!f) {
LOGP(DLGTP, LOGL_ERROR,
"fopen(path=%s, mode=%s) failed: Error = %s\n", filename,
"w", strerror(errno));
goto free_filename;
}
fprintf(f, "%d\n", gsn->restart_counter);
close_file:
if (fclose(f))
LOGP(DLGTP, LOGL_ERROR,
"fclose failed: Error = %s\n", strerror(errno));
free_filename:
talloc_free(filename);
}
static int create_and_bind_socket(const char *name, struct gsn_t *gsn, int *fd, int domain,
const struct in_addr *listen, int port)
{
struct sockaddr_in addr;
int type = SOCK_DGRAM;
int protocol = 0;
*fd = socket(domain, type, protocol);
if (*fd < 0) {
rate_ctr_inc2(gsn->ctrg, GSN_CTR_ERR_SOCKET);
LOGP(DLGTP, LOGL_ERROR,
"%s socket(domain=%d, type=%d, protocol=%d) failed: Error = %s\n",
name, domain, type, protocol, strerror(errno));
return -errno;
}
memset(&addr, 0, sizeof(addr));
addr.sin_family = domain;
addr.sin_addr = *listen;
addr.sin_port = htons(port);
#if defined(__FreeBSD__) || defined(__APPLE__)
addr.sin_len = sizeof(addr);
#endif
if (bind(*fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
rate_ctr_inc2(gsn->ctrg, GSN_CTR_ERR_SOCKET);
LOGP_WITH_ADDR(DLGTP, LOGL_ERROR, addr,
"%s bind(fd=%d) failed: Error = %s\n",
name, *fd, strerror(errno));
return -errno;
}
return 0;
}
int gtp_new(struct gsn_t **gsn, char *statedir, struct in_addr *listen,
int mode)
{
LOGP(DLGTP, LOGL_NOTICE, "GTP: gtp_newgsn() started at %s\n", inet_ntoa(*listen));
*gsn = talloc_zero(tall_libgtp_ctx, struct gsn_t);
(*gsn)->statedir = statedir;
log_restart(*gsn);
/* Initialise sequence number */
(*gsn)->seq_next = (*gsn)->restart_counter * 1024;
/* Initialize timers: */
(*gsn)->tdef = gtp_T_defs;
/* Small hack to properly reset tdef for old clients not using the tdef_group: */
OSMO_ASSERT(gtp_T_defs[0].default_val != 0);
if (gtp_T_defs[0].val == 0)
osmo_tdefs_reset((*gsn)->tdef);
/* Initialise request retransmit queue */
queue_new(&(*gsn)->queue_req);
queue_new(&(*gsn)->queue_resp);
/* Initialise pdp table */
pdp_init(*gsn);
/* Initialize internal queue timer */
osmo_timer_setup(&(*gsn)->queue_timer, queue_timer_cb, *gsn);
/* Initialize counter group: */
(*gsn)->ctrg = rate_ctr_group_alloc(NULL, &gsn_ctrg_desc, gsn_ctr_next_idx++);
/* Initialise call back functions */
(*gsn)->cb_create_context_ind = 0;
(*gsn)->cb_update_context_ind = 0;
(*gsn)->cb_delete_context = 0;
(*gsn)->cb_unsup_ind = 0;
(*gsn)->cb_conf = 0;
(*gsn)->cb_data_ind = 0;
/* Store function parameters */
/* Same IP for user traffic and signalling */
(*gsn)->gsnc = *listen;
(*gsn)->gsnu = *listen;
(*gsn)->mode = mode;
(*gsn)->fd0 = -1;
(*gsn)->fd1c = -1;
(*gsn)->fd1u = -1;
/* Create GTP version 0 socket */
if (create_and_bind_socket("GTPv0", *gsn, &(*gsn)->fd0, AF_INET, listen, GTP0_PORT) < 0)
goto error;
/* Create GTP version 1 control plane socket */
if (create_and_bind_socket("GTPv1 control plane", *gsn, &(*gsn)->fd1c, AF_INET, listen, GTP1C_PORT) < 0)
goto error;
/* Create GTP version 1 user plane socket */
if (create_and_bind_socket("GTPv1 user plane", *gsn, &(*gsn)->fd1u, AF_INET, listen, GTP1U_PORT) < 0)
goto error;
/* Start internal queue timer */
gtp_queue_timer_start(*gsn);
return 0;
error:
gtp_free(*gsn);
*gsn = NULL;
return -1;
}
int gtp_free(struct gsn_t *gsn)
{
/* Cleanup internal queue timer */
osmo_timer_del(&gsn->queue_timer);
/* Clean up retransmit queues */
queue_free(gsn->queue_req);
queue_free(gsn->queue_resp);
close(gsn->fd0);
close(gsn->fd1c);
close(gsn->fd1u);
rate_ctr_group_free(gsn->ctrg);
talloc_free(gsn);
return 0;
}
/* API: Register create context indication callback */
int gtp_set_cb_create_context_ind(struct gsn_t *gsn,
int (*cb_create_context_ind) (struct pdp_t *
pdp))
{
gsn->cb_create_context_ind = cb_create_context_ind;
return 0;
}
int gtp_set_cb_update_context_ind(struct gsn_t *gsn,
int (*cb_update_context_ind)(struct pdp_t *pdp))
{
gsn->cb_update_context_ind = cb_update_context_ind;
return 0;
}
int gtp_retrans(struct gsn_t *gsn)
{
/* dummy API, deprecated. */
return 0;
}
int gtp_retranstimeout(struct gsn_t *gsn, struct timeval *timeout)
{
timeout->tv_sec = 24*60*60;
timeout->tv_usec = 0;
/* dummy API, deprecated. Return a huge timer to do nothing */
return 0;
}

3
gtp/gsn_internal.h Normal file
View File

@@ -0,0 +1,3 @@
#pragma once
void gtp_queue_timer_start(struct gsn_t *gsn);

1735
gtp/gtp.c

File diff suppressed because it is too large Load Diff

8
gtp/gtp_internal.h Normal file
View File

@@ -0,0 +1,8 @@
#pragma once
#include <stdint.h>
#include <talloc.h>
uint64_t gtp_imsi_str2gtp(const char *str);
extern TALLOC_CTX *tall_libgtp_ctx;

View File

@@ -1,17 +1,17 @@
/*
/*
* OsmoGGSN - Gateway GPRS Support Node
* Copyright (C) 2002 Mondru AB.
*
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
* notice and this permission notice is included in all copies or
* substantial portions of the software.
*
*
*/
/*
* gtpie.c: Contains functions to encapsulate and decapsulate GTP
* information elements
* gtpie.c: Contains functions to encapsulate and decapsulate GTP
* information elements
*
*
* Encapsulation
@@ -37,7 +37,7 @@
#include <netinet/in.h>
#include <string.h>
#include "gtpie.h"
#include <osmocom/gtp/gtpie.h>
/*! Encode a TLV type Information Element.
* \param[inout] p Pointer to output packet to which IE is appended
@@ -770,7 +770,7 @@ int gtpie_encaps(union gtpie_member *ie[], void *pack, unsigned *len)
/*! Encode GTP packet payload from Array of Information Elements.
* \param[out] ie Input Array of GTPIE
* \param[in] size Size of ?
* \param[in] size Size of ie
* \param[out] pack Pointer to caller-allocated buffer for raw GTP packet (GTPIE_MAX length)
* \param[out] len Encoded length of \a pack in bytes
* \returns 0 on sucess; 2 for out-of-space */
@@ -944,3 +944,189 @@ int gtpie_encaps2(union gtpie_member ie[], unsigned int size,
}
return 0;
}
/*! Encode GTP packet payload from Array of Information Elements.
* \param[in] ie Input Array of GTPIE
* \param[in] ie_len Length of \a ie array
* \param[in] pack Pointer to caller-allocated buffer for raw GTP packet (GTPIE_MAX length)
* \param[in] pack_len Length of \a pack buffer
* \param[out] encoded_len Encoded length of \a pack in bytes
* \returns 0 on success; 2 for out-of-space
* GTP requires a certain order, the call must follow those which are defined for every message */
int gtpie_encaps3(union gtpie_member *ies[], unsigned int ie_len,
void *pack, unsigned pack_len, unsigned *encoded_len)
{
unsigned int i;
unsigned char *p;
unsigned char *end;
int iesize;
union gtpie_member *ie;
*encoded_len = 0;
p = pack;
memset(pack, 0, pack_len);
end = p + pack_len;
for (i = 0; i < ie_len; i++) {
if (!ies[i])
continue;
ie = ies[i];
if (GTPIE_DEBUG)
printf
("gtpie_encaps. Number %d, Type %d\n",
i, ie->t);
switch (ie->t) {
case GTPIE_CAUSE: /* TV GTPIE types with value length 1 */
case GTPIE_REORDER:
case GTPIE_MAP_CAUSE:
case GTPIE_MS_VALIDATED:
case GTPIE_RECOVERY:
case GTPIE_SELECTION_MODE:
case GTPIE_TEARDOWN:
case GTPIE_NSAPI:
case GTPIE_RANAP_CAUSE:
case GTPIE_RP_SMS:
case GTPIE_RP:
case GTPIE_MS_NOT_REACH:
case GTPIE_BCM:
iesize = 2;
break;
case GTPIE_PFI: /* TV GTPIE types with value length 2 */
case GTPIE_CHARGING_C:
case GTPIE_TRACE_REF:
case GTPIE_TRACE_TYPE:
iesize = 3;
break;
case GTPIE_QOS_PROFILE0: /* TV GTPIE types with value length 3 */
case GTPIE_P_TMSI_S:
iesize = 4;
break;
case GTPIE_TLLI: /* TV GTPIE types with value length 4 */
case GTPIE_P_TMSI:
case GTPIE_TEI_DI:
case GTPIE_TEI_C:
case GTPIE_CHARGING_ID:
iesize = 5;
break;
case GTPIE_TEI_DII: /* TV GTPIE types with value length 5 */
iesize = 6;
break;
case GTPIE_RAI: /* TV GTPIE types with value length 6 */
iesize = 7;
break;
case GTPIE_RAB_CONTEXT: /* TV GTPIE types with value length 7 */
iesize = 8;
break;
case GTPIE_IMSI: /* TV GTPIE types with value length 8 */
iesize = 9;
break;
case GTPIE_AUTH_TRIPLET: /* TV GTPIE types with value length 28 */
iesize = 29;
break;
case GTPIE_EXT_HEADER_T: /* GTP extension header */
iesize = 2 + hton8(ie->ext.l);
break;
case GTPIE_EUA: /* TLV GTPIE types with length length 2 */
case GTPIE_MM_CONTEXT:
case GTPIE_PDP_CONTEXT:
case GTPIE_APN:
case GTPIE_PCO:
case GTPIE_GSN_ADDR:
case GTPIE_MSISDN:
case GTPIE_QOS_PROFILE:
case GTPIE_AUTH_QUINTUP:
case GTPIE_TFT:
case GTPIE_TARGET_INF:
case GTPIE_UTRAN_TRANS:
case GTPIE_RAB_SETUP:
case GTPIE_TRIGGER_ID:
case GTPIE_OMC_ID:
case GTPIE_RAN_T_CONTAIN:
case GTPIE_PDP_CTX_PRIO:
case GTPIE_ADDL_RAB_S_I:
case GTPIE_SGSN_NUMBER:
case GTPIE_COMMON_FLAGS:
case GTPIE_APN_RESTR:
case GTPIE_R_PRIO_LCS:
case GTPIE_RAT_TYPE:
case GTPIE_USER_LOC:
case GTPIE_MS_TZ:
case GTPIE_IMEI_SV:
case GTPIE_CML_CHG_I_CT:
case GTPIE_MBMS_UE_CTX:
case GTPIE_TMGI:
case GTPIE_RIM_ROUT_ADDR:
case GTPIE_MBMS_PCO:
case GTPIE_MBMS_SA:
case GTPIE_SRNC_PDCP_CTX:
case GTPIE_ADDL_TRACE:
case GTPIE_HOP_CTR:
case GTPIE_SEL_PLMN_ID:
case GTPIE_MBMS_SESS_ID:
case GTPIE_MBMS_2_3G_IND:
case GTPIE_ENH_NSAPI:
case GTPIE_MBMS_SESS_DUR:
case GTPIE_A_MBMS_TRAC_I:
case GTPIE_MBMS_S_REP_N:
case GTPIE_MBMS_TTDT:
case GTPIE_PS_HO_REQ_CTX:
case GTPIE_BSS_CONTAINER:
case GTPIE_CELL_ID:
case GTPIE_PDU_NUMBERS:
case GTPIE_BSSGP_CAUSE:
case GTPIE_RQD_MBMS_BCAP:
case GTPIE_RIM_RA_DISCR:
case GTPIE_L_SETUP_PFCS:
case GTPIE_PS_HO_XID_PAR:
case GTPIE_MS_CHG_REP_A:
case GTPIE_DIR_TUN_FLAGS:
case GTPIE_CORREL_ID:
case GTPIE_MBMS_FLOWI:
case GTPIE_MBMS_MC_DIST:
case GTPIE_MBMS_DIST_ACK:
case GTPIE_R_IRAT_HO_INF:
case GTPIE_RFSP_IDX:
case GTPIE_FQDN:
case GTPIE_E_ALL_PRIO_1:
case GTPIE_E_ALL_PRIO_2:
case GTPIE_E_CMN_FLAGS:
case GTPIE_U_CSG_INFO:
case GTPIE_CSG_I_REP_ACT:
case GTPIE_CSG_ID:
case GTPIE_CSG_MEMB_IND:
case GTPIE_AMBR:
case GTPIE_UE_NET_CAPA:
case GTPIE_UE_AMBR:
case GTPIE_APN_AMBR_NS:
case GTPIE_GGSN_BACKOFF:
case GTPIE_S_PRIO_IND:
case GTPIE_S_PRIO_IND_NS:
case GTPIE_H_BR_16MBPS_F:
case GTPIE_A_MMCTX_SRVCC:
case GTPIE_A_FLAGS_SRVCC:
case GTPIE_STN_SR:
case GTPIE_C_MSISDN:
case GTPIE_E_RANAP_CAUSE:
case GTPIE_ENODEB_ID:
case GTPIE_SEL_MODE_NS:
case GTPIE_ULI_TIMESTAMP:
case GTPIE_CHARGING_ADDR:
case GTPIE_PRIVATE:
iesize = 3 + hton16(ie->tlv.l);
break;
default:
return 2; /* We received something unknown */
}
if (p + iesize < end) {
memcpy(p, ie, iesize);
p += iesize;
*encoded_len += iesize;
} else
return 2; /* Out of space */
}
return 0;
}

170
gtp/pdp.c
View File

@@ -28,17 +28,12 @@
#include <netinet/in.h>
#include <string.h>
#include <inttypes.h>
#include "pdp.h"
#include "gtp.h"
#include <osmocom/gtp/pdp.h>
#include <osmocom/gtp/gtp.h>
#include "lookupa.h"
/* ***********************************************************
* Global variables TODO: most should be moved to gsn_t
*************************************************************/
static struct pdp_t pdpa[PDP_MAX]; /* PDP storage */
static struct pdp_t *hashtid[PDP_MAX]; /* Hash table for IMSI + NSAPI */
/* struct pdp_t* haship[PDP_MAX]; Hash table for IP and network interface */
#include "queue.h"
/* ***********************************************************
* Functions related to PDP storage
@@ -112,11 +107,16 @@ static struct pdp_t *hashtid[PDP_MAX]; /* Hash table for IMSI + NSAPI */
*
*************************************************************/
int pdp_init()
static struct gsn_t *g_gsn;
int pdp_init(struct gsn_t *gsn)
{
memset(&pdpa, 0, sizeof(pdpa));
memset(&hashtid, 0, sizeof(hashtid));
/* memset(&haship, 0, sizeof(haship)); */
if (!g_gsn) {
g_gsn = gsn;
} else {
LOGP(DLGTP, LOGL_FATAL, "This interface is depreacted and doesn't support multiple GGSN!");
return -1;
}
return 0;
}
@@ -124,6 +124,13 @@ int pdp_init()
int pdp_newpdp(struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi,
struct pdp_t *pdp_old)
{
return gtp_pdp_newpdp(g_gsn, pdp, imsi, nsapi, pdp_old);
}
int gtp_pdp_newpdp(struct gsn_t *gsn, struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi,
struct pdp_t *pdp_old)
{
struct pdp_t *pdpa = gsn->pdpa;
int n;
for (n = 0; n < PDP_MAX; n++) { /* TODO: Need to do better than linear search */
if (pdpa[n].inuse == 0) {
@@ -133,6 +140,7 @@ int pdp_newpdp(struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi,
else
memset(*pdp, 0, sizeof(struct pdp_t));
(*pdp)->inuse = 1;
(*pdp)->gsn = gsn;
(*pdp)->imsi = imsi;
(*pdp)->nsapi = nsapi;
(*pdp)->fllc = (uint16_t) n + 1;
@@ -151,7 +159,7 @@ int pdp_newpdp(struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi,
}
/* Default: Generate G-PDU sequence numbers on Tx */
(*pdp)->tx_gpdu_seq = true;
INIT_LLIST_HEAD(&(*pdp)->qmsg_list_req);
return 0;
}
}
@@ -160,6 +168,18 @@ int pdp_newpdp(struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi,
int pdp_freepdp(struct pdp_t *pdp)
{
struct qmsg_t *qmsg, *qmsg2;
struct pdp_t *pdpa = pdp->gsn->pdpa;
int rc;
/* Remove all enqueued messages belonging to this pdp from req tx transmit
queue. queue_freemsg will call llist_del(). */
llist_for_each_entry_safe(qmsg, qmsg2, &pdp->qmsg_list_req, entry) {
if ((rc = queue_freemsg(pdp->gsn->queue_req, qmsg)))
LOGP(DLGTP, LOGL_ERROR,
"Failed freeing qmsg from qmsg_list_req during pdp_freepdp()! %d\n", rc);
}
pdp_tiddel(pdp);
/* Remove any references in primary context */
@@ -174,12 +194,20 @@ int pdp_freepdp(struct pdp_t *pdp)
int pdp_getpdp(struct pdp_t **pdp)
{
*pdp = &pdpa[0];
*pdp = &g_gsn->pdpa[0];
return 0;
}
int pdp_getgtp0(struct pdp_t **pdp, uint16_t fl)
{
return gtp_pdp_getgtp0(g_gsn, pdp, fl);
}
int gtp_pdp_getgtp0(struct gsn_t *gsn, struct pdp_t **pdp, uint16_t fl)
{
struct pdp_t *pdpa = gsn->pdpa;
if ((fl > PDP_MAX) || (fl < 1)) {
return EOF; /* Not found */
} else {
@@ -194,6 +222,13 @@ int pdp_getgtp0(struct pdp_t **pdp, uint16_t fl)
int pdp_getgtp1(struct pdp_t **pdp, uint32_t tei)
{
return gtp_pdp_getgtp1(g_gsn, pdp, tei);
}
int gtp_pdp_getgtp1(struct gsn_t *gsn, struct pdp_t **pdp, uint32_t tei)
{
struct pdp_t *pdpa = gsn->pdpa;
if ((tei > PDP_MAX) || (tei < 1)) {
return EOF; /* Not found */
} else {
@@ -209,6 +244,12 @@ int pdp_getgtp1(struct pdp_t **pdp, uint32_t tei)
/* get a PDP based on the *peer* address + TEI-Data. Used for matching inbound Error Ind */
int pdp_getgtp1_peer_d(struct pdp_t **pdp, const struct sockaddr_in *peer, uint32_t teid_gn)
{
return gtp_pdp_getgtp1_peer_d(g_gsn, pdp, peer, teid_gn);
}
int gtp_pdp_getgtp1_peer_d(struct gsn_t *gsn, struct pdp_t **pdp, const struct sockaddr_in *peer, uint32_t teid_gn)
{
struct pdp_t *pdpa = gsn->pdpa;
unsigned int i;
/* this is O(n) but we don't have (nor want) another hash... */
@@ -231,6 +272,7 @@ int pdp_tidhash(uint64_t tid)
int pdp_tidset(struct pdp_t *pdp, uint64_t tid)
{
struct pdp_t **hashtid = pdp->gsn->hashtid;
int hash = pdp_tidhash(tid);
struct pdp_t *pdp2;
struct pdp_t *pdp_prev = NULL;
@@ -249,6 +291,7 @@ int pdp_tidset(struct pdp_t *pdp, uint64_t tid)
int pdp_tiddel(struct pdp_t *pdp)
{
struct pdp_t **hashtid = pdp->gsn->hashtid;
int hash = pdp_tidhash(pdp->tid);
struct pdp_t *pdp2;
struct pdp_t *pdp_prev = NULL;
@@ -270,6 +313,12 @@ int pdp_tiddel(struct pdp_t *pdp)
int pdp_tidget(struct pdp_t **pdp, uint64_t tid)
{
return gtp_pdp_tidget(g_gsn, pdp, tid);
}
int gtp_pdp_tidget(struct gsn_t *gsn, struct pdp_t **pdp, uint64_t tid)
{
struct pdp_t **hashtid = gsn->hashtid;
int hash = pdp_tidhash(tid);
struct pdp_t *pdp2;
DEBUGP(DLGTP, "Begin pdp_tidget tid = %"PRIx64"\n", tid);
@@ -286,82 +335,15 @@ int pdp_tidget(struct pdp_t **pdp, uint64_t tid)
int pdp_getimsi(struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi)
{
return pdp_tidget(pdp,
(imsi & 0x0fffffffffffffffull) +
((uint64_t) nsapi << 60));
return gtp_pdp_getimsi(g_gsn, pdp, imsi, nsapi);
}
/*
int pdp_iphash(void* ipif, struct ul66_t *eua) {
/#printf("IPhash %ld\n", lookup(eua->v, eua->l, ipif) % PDP_MAX);#/
return (lookup(eua->v, eua->l, ipif) % PDP_MAX);
int gtp_pdp_getimsi(struct gsn_t *gsn, struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi)
{
return gtp_pdp_tidget(gsn, pdp, pdp_gettid(imsi, nsapi));
}
int pdp_ipset(struct pdp_t *pdp, void* ipif, struct ul66_t *eua) {
int hash;
struct pdp_t *pdp2;
struct pdp_t *pdp_prev = NULL;
if (PDP_DEBUG) printf("Begin pdp_ipset %d %d %2x%2x%2x%2x\n",
(unsigned) ipif, eua->l,
eua->v[2], eua->v[3],
eua->v[4], eua->v[5]);
pdp->ipnext = NULL;
pdp->ipif = ipif;
pdp->eua.l = eua->l;
memcpy(pdp->eua.v, eua->v, eua->l);
hash = pdp_iphash(pdp->ipif, &pdp->eua);
for (pdp2 = haship[hash]; pdp2; pdp2 = pdp2->ipnext)
pdp_prev = pdp2;
if (!pdp_prev)
haship[hash] = pdp;
else
pdp_prev->ipnext = pdp;
if (PDP_DEBUG) printf("End pdp_ipset\n");
return 0;
}
int pdp_ipdel(struct pdp_t *pdp) {
int hash = pdp_iphash(pdp->ipif, &pdp->eua);
struct pdp_t *pdp2;
struct pdp_t *pdp_prev = NULL;
if (PDP_DEBUG) printf("Begin pdp_ipdel\n");
for (pdp2 = haship[hash]; pdp2; pdp2 = pdp2->ipnext) {
if (pdp2 == pdp) {
if (!pdp_prev)
haship[hash] = pdp2->ipnext;
else
pdp_prev->ipnext = pdp2->ipnext;
if (PDP_DEBUG) printf("End pdp_ipdel: PDP found\n");
return 0;
}
pdp_prev = pdp2;
}
if (PDP_DEBUG) printf("End pdp_ipdel: PDP not found\n");
return EOF; /# End of linked list and not found #/
}
int pdp_ipget(struct pdp_t **pdp, void* ipif, struct ul66_t *eua) {
int hash = pdp_iphash(ipif, eua);
struct pdp_t *pdp2;
/#printf("Begin pdp_ipget %d %d %2x%2x%2x%2x\n", (unsigned)ipif, eua->l,
eua->v[2],eua->v[3],eua->v[4],eua->v[5]);#/
for (pdp2 = haship[hash]; pdp2; pdp2 = pdp2->ipnext) {
if ((pdp2->ipif == ipif) && (pdp2->eua.l == eua->l) &&
(memcmp(&pdp2->eua.v, &eua->v, eua->l) == 0)) {
*pdp = pdp2;
/#printf("End pdp_ipget. Found\n");#/
return 0;
}
}
if (PDP_DEBUG) printf("End pdp_ipget Notfound %d %d %2x%2x%2x%2x\n",
(unsigned)ipif, eua->l, eua->v[2],eua->v[3],eua->v[4],eua->v[5]);
return EOF; /# End of linked list and not found #/
}
*/
/* Various conversion functions */
uint64_t pdp_gettid(uint64_t imsi, uint8_t nsapi)
@@ -374,3 +356,17 @@ void pdp_set_imsi_nsapi(struct pdp_t *pdp, uint64_t teid)
pdp->imsi = teid & 0x0fffffffffffffffull;
pdp->nsapi = (teid & 0xf000000000000000ull) >> 60;
}
/* Count amount of secondary PDP contexts linked to this primary PDP context
* (itself included). Must be called on a primary PDP context. */
unsigned int pdp_count_secondary(const struct pdp_t *pdp)
{
unsigned int n;
unsigned int count = 0;
OSMO_ASSERT(!pdp->secondary);
for (n = 0; n < PDP_MAXNSAPI; n++)
if (pdp->secondary_tei[n])
count++;
return count;
}

View File

@@ -1,14 +1,14 @@
/*
/*
* OsmoGGSN - Gateway GPRS Support Node
* Copyright (C) 2002, 2003, 2004 Mondru AB.
* Copyright (C) 2011 Harald Welte <laforge@gnumonks.org>
* Copyright (C) 2016 sysmocom - s.f.m.c. GmbH
*
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
* notice and this permission notice is included in all copies or
* substantial portions of the software.
*
*
*/
/*
@@ -27,8 +27,10 @@
#include <sys/time.h>
#include <netinet/in.h>
#include <string.h>
#include "pdp.h"
#include "gtp.h"
#include <osmocom/gtp/pdp.h>
#include <osmocom/gtp/gtp.h>
#include "queue.h"
/*! \brief dump a queue_t to stdout */
@@ -62,7 +64,7 @@ static int queue_seqhash(struct sockaddr_in *peer, uint16_t seq)
return seq % QUEUE_HASH_SIZE;
}
/*! \brief Insert a message with given sequence number into the hash
/*! \brief Insert a message with given sequence number into the hash.
*
* This function sets the peer and the seq of the qmsg and then inserts
* the qmsg into the queue hash. To do so, it does a hashtable lookup
@@ -79,7 +81,7 @@ static int queue_seqset(struct queue_t *queue, struct qmsg_t *qmsg,
if (QUEUE_DEBUG)
printf("Begin queue_seqset seq = %d\n", (int)seq);
if (QUEUE_DEBUG)
printf("SIZEOF PEER %d, *PEER %d\n", sizeof(peer),
printf("SIZEOF PEER %zu, *PEER %zu\n", sizeof(peer),
sizeof(*peer));
qmsg->seq = seq;
@@ -121,7 +123,10 @@ static int queue_seqdel(struct queue_t *queue, struct qmsg_t *qmsg)
return EOF; /* End of linked list and not found */
}
/*! \brief Allocates and initialises new queue structure */
/*! Allocates and initialises new queue structure.
* \param[out] queue pointer where to store the allocated object. Must be freed with queue_free
* \returns zero on success, non-zero on error
*/
int queue_new(struct queue_t **queue)
{
if (QUEUE_DEBUG)
@@ -138,7 +143,10 @@ int queue_new(struct queue_t **queue)
return 0;
}
/*! \brief Deallocates queue structure */
/*! Deallocates queue structure.
* \param[in] queue pointer previously allocated by queue_new
* \returns zero on success, non-zero on error.
*/
int queue_free(struct queue_t *queue)
{
if (QUEUE_DEBUG)
@@ -149,7 +157,13 @@ int queue_free(struct queue_t *queue)
return 0;
}
/*! \brief Add a new message to the queue */
/*! Add a new message to the queue.
* \param[in] queue pointer previously allocated by queue_new
* \param[out] qmsg first message from the queue (if succeeds)
* \param[in] peer who sent the message to add
* \param[in] seq sequence number of the message to add
* \returns zero on success, non-zero on error.
*/
int queue_newmsg(struct queue_t *queue, struct qmsg_t **qmsg,
struct sockaddr_in *peer, uint16_t seq)
{
@@ -160,6 +174,7 @@ int queue_newmsg(struct queue_t *queue, struct qmsg_t **qmsg,
} else {
*qmsg = &queue->qmsga[queue->next];
queue_seqset(queue, *qmsg, peer, seq);
INIT_LLIST_HEAD(&(*qmsg)->entry);
(*qmsg)->state = 1; /* Space taken */
(*qmsg)->this = queue->next;
(*qmsg)->next = -1; /* End of the queue */
@@ -176,7 +191,11 @@ int queue_newmsg(struct queue_t *queue, struct qmsg_t **qmsg,
}
}
/*! \brief Simply remoev a given qmsg_t from the queue
/*! Remove an element from the queue.
* \param[in] queue pointer previously allocated by queue_new
* \param[in] qmsg message to free
* \returns zero on success, non-zero on error.
*
* Internally, we first delete the entry from the queue, and then update
* up our global queue->first / queue->last pointers. Finally,
@@ -190,6 +209,8 @@ int queue_freemsg(struct queue_t *queue, struct qmsg_t *qmsg)
return EOF; /* Not in queue */
}
llist_del(&qmsg->entry);
queue_seqdel(queue, qmsg);
if (qmsg->next == -1) /* Are we the last in queue? */
@@ -210,7 +231,11 @@ int queue_freemsg(struct queue_t *queue, struct qmsg_t *qmsg)
return 0;
}
/*! \brief Move a given qmsg_t to the end of the queue ?!? */
/*! Move a given qmsg_t to the end of the queue.
* \param[in] queue pointer previously allocated by queue_new
* \param[in] qmsg message to move to the end of the queue
* \returns zero on success, non-zero on error.
*/
int queue_back(struct queue_t *queue, struct qmsg_t *qmsg)
{
if (QUEUE_DEBUG)
@@ -236,7 +261,11 @@ int queue_back(struct queue_t *queue, struct qmsg_t *qmsg)
return 0;
}
/*! \brief Get the first element in the entire queue */
/*! Get the first element in the entire queue.
* \param[in] queue pointer previously allocated by queue_new
* \param[out] qmsg first message from the queue (if succeeds)
* \returns zero on success, non-zero on error.
*/
int queue_getfirst(struct queue_t *queue, struct qmsg_t **qmsg)
{
/*printf("queue_getfirst\n"); */
@@ -250,7 +279,13 @@ int queue_getfirst(struct queue_t *queue, struct qmsg_t **qmsg)
return 0;
}
/*! \brief Get a queue entry for a given peer + seq */
/*! Get a queue entry for a given peer + seq.
* \param[in] queue pointer previously allocated by queue_new
* \param[out] qmsg first message from the queue (if succeeds)
* \param[in] peer who sent the message to retrieve
* \param[in] seq sequence number of the message to retrive
* \returns zero on success, non-zero on error.
*/
int queue_seqget(struct queue_t *queue, struct qmsg_t **qmsg,
struct sockaddr_in *peer, uint16_t seq)
{
@@ -272,7 +307,14 @@ int queue_seqget(struct queue_t *queue, struct qmsg_t **qmsg,
return EOF; /* End of linked list and not found */
}
/*! \brief look-up a given seq/peer, return cbp + type and free entry */
/*! look-up a given seq/peer, return cbp + type and free entry.
* \param[in] queue pointer previously allocated by queue_new
* \param[in] peer who sent the message to retrieve
* \param[in] seq sequence number of the message to retrive
* \param[out] type GTP message type
* \param[out] type callback pointer of the message
* \returns zero on success, non-zero on error.
*/
int queue_freemsg_seq(struct queue_t *queue, struct sockaddr_in *peer,
uint16_t seq, uint8_t * type, void **cbp)
{

View File

@@ -1,12 +1,12 @@
/*
/*
* OsmoGGSN - Gateway GPRS Support Node
* Copyright (C) 2002 Mondru AB.
*
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
* notice and this permission notice is included in all copies or
* substantial portions of the software.
*
*
*/
/*
@@ -17,9 +17,13 @@
#ifndef _QUEUE_H
#define _QUEUE_H
#include <osmocom/core/linuxlist.h>
#include <osmocom/gtp/gtp.h>
#define QUEUE_DEBUG 0 /* Print debug information */
#define QUEUE_SIZE 1024 /* Size of retransmission queue */
#define QUEUE_SIZE (PDP_MAX*2) /* Size of retransmission queue */
#define QUEUE_HASH_SIZE 65536 /* Size of hash table (2^16) */
struct qmsg_t { /* Holder for queued packets */
@@ -37,6 +41,7 @@ struct qmsg_t { /* Holder for queued packets */
int this; /* Pointer to myself */
time_t timeout; /* When do we retransmit this packet? */
int retrans; /* How many times did we retransmit this? */
struct llist_head entry; /* Listed with other qmsg_t belonging to a pdp_t->qmsg_list_req */
};
struct queue_t {

3
include/Makefile.am Normal file
View File

@@ -0,0 +1,3 @@
SUBDIRS = \
osmocom \
$(NULL)

View File

@@ -0,0 +1,3 @@
SUBDIRS = \
gtp \
$(NULL)

View File

@@ -0,0 +1,8 @@
libgtp_HEADERS = \
gsn.h \
gtp.h \
gtpie.h \
pdp.h \
$(NULL)
libgtpdir = $(includedir)/osmocom/gtp

181
include/osmocom/gtp/gsn.h Normal file
View File

@@ -0,0 +1,181 @@
/*
* OsmoGGSN - Gateway GPRS Support Node
* Copyright (C) 2002, 2003, 2004 Mondru AB.
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
* notice and this permission notice is included in all copies or
* substantial portions of the software.
*
*/
#ifndef _GSN_H
#define _GSN_H
#include <osmocom/core/utils.h>
#include <osmocom/core/defs.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/tdef.h>
#include <osmocom/core/rate_ctr.h>
#include "pdp.h"
#define GTP_MODE_GGSN 1
#define GTP_MODE_SGSN 2
#define RESTART_FILE "gsn_restart"
extern struct osmo_tdef gtp_T_defs[];
/* ***********************************************************
* Information storage for each gsn instance
*
* Normally each instance of the application corresponds to
* one instance of a gsn.
*
* In order to avoid global variables in the application, and
* also in order to allow several instances of a gsn in the same
* application this struct is provided in order to store all
* relevant information related to the gsn.
*
* Note that this does not include information storage for '
* each pdp context. This is stored in another struct.
*************************************************************/
enum gsn_rate_ctr_keys {
GSN_CTR_ERR_SOCKET,
GSN_CTR_ERR_READFROM, /* Number of readfrom errors */
GSN_CTR_ERR_SENDTO, /* Number of sendto errors */
GSN_CTR_ERR_QUEUEFULL, /* Number of times queue was full */
GSN_CTR_ERR_SEQ, /* Number of seq out of range */
GSN_CTR_ERR_ADDRESS, /* GSN address conversion failed */
GSN_CTR_ERR_UNKNOWN_PDP, /* GSN address conversion failed */
GSN_CTR_ERR_UNEXPECTED_CAUSE, /* Unexpected cause value received */
GSN_CTR_ERR_OUT_OF_PDP, /* Out of storage for PDP contexts */
GSN_CTR_PKT_EMPTY, /* Number of empty packets */
GSN_CTR_PKT_UNSUP, /* Number of unsupported version 29.60 11.1.1 */
GSN_CTR_PKT_TOOSHORT, /* Number of too short headers 29.60 11.1.2 */
GSN_CTR_PKT_UNKNOWN, /* Number of unknown messages 29.60 11.1.3 */
GSN_CTR_PKT_UNEXPECT, /* Number of unexpected messages 29.60 11.1.4 */
GSN_CTR_PKT_DUPLICATE, /* Number of duplicate or unsolicited replies */
GSN_CTR_PKT_MISSING, /* Number of missing information field messages */
GSN_CTR_PKT_INCORRECT, /* Number of incorrect information field messages */
GSN_CTR_PKT_INVALID, /* Number of invalid message format messages */
};
/* 3GPP TS 29.006 14.1, 14,2 */
enum gtp_gsn_timers {
GTP_GSN_TIMER_T3_RESPONSE = 3,
GTP_GSN_TIMER_N3_REQUESTS = 1003,
GTP_GSN_TIMER_T3_HOLD_RESPONSE = -3,
};
struct gsn_t {
/* Parameters related to the network interface */
int fd0; /* GTP0 file descriptor */
int fd1c; /* GTP1 control plane file descriptor */
int fd1u; /* GTP0 user plane file descriptor */
int mode; /* Mode of operation: GGSN or SGSN */
struct in_addr gsnc; /* IP address of this gsn for signalling */
struct in_addr gsnu; /* IP address of this gsn for user traffic */
/* Parameters related to signalling messages */
uint16_t seq_next; /* Next sequence number to use */
int seq_first; /* First packet in queue (oldest timeout) */
int seq_last; /* Last packet in queue (youngest timeout) */
unsigned char restart_counter; /* Increment on restart. Stored on disk */
char *statedir; /* Disk location for permanent storage */
void *priv; /* used by libgtp users to attach their own state) */
struct queue_t *queue_req; /* Request queue */
struct queue_t *queue_resp; /* Response queue */
struct pdp_t pdpa[PDP_MAX]; /* PDP storage */
struct pdp_t *hashtid[PDP_MAX]; /* Hash table for IMSI + NSAPI */
struct osmo_timer_list queue_timer; /* internal queue_{req,resp} timer */
/* Call back functions */
int (*cb_delete_context) (struct pdp_t *);
int (*cb_create_context_ind) (struct pdp_t *);
int (*cb_update_context_ind)(struct pdp_t *pdp);
int (*cb_unsup_ind) (struct sockaddr_in * peer);
int (*cb_extheader_ind) (struct sockaddr_in * peer);
int (*cb_ran_info_relay_ind) (struct sockaddr_in *peer, union gtpie_member **ie);
int (*cb_conf) (int type, int cause, struct pdp_t * pdp, void *cbp);
int (*cb_data_ind) (struct pdp_t * pdp, void *pack, unsigned len);
int (*cb_recovery) (struct sockaddr_in * peer, uint8_t recovery);
int (*cb_recovery2) (struct sockaddr_in * peer, struct pdp_t * pdp, uint8_t recovery);
int (*cb_recovery3) (struct gsn_t *gsn, struct sockaddr_in *peer, struct pdp_t *pdp, uint8_t recovery);
/* Counters */
struct rate_ctr_group *ctrg;
/* Timers: */
struct osmo_tdef *tdef;
};
/* External API functions */
extern int gtp_new(struct gsn_t **gsn, char *statedir, struct in_addr *listen,
int mode);
extern int gtp_free(struct gsn_t *gsn);
extern int gtp_newpdp(struct gsn_t *gsn, struct pdp_t **pdp,
uint64_t imsi, uint8_t nsapi) OSMO_DEPRECATED("Use gtp_pdp_newpdp() instead");
extern int gtp_freepdp(struct gsn_t *gsn, struct pdp_t *pdp);
extern int gtp_freepdp_teardown(struct gsn_t *gsn, struct pdp_t *pdp);
extern int gtp_create_context_req(struct gsn_t *gsn, struct pdp_t *pdp,
void *cbp);
extern int gtp_set_cb_create_context_ind(struct gsn_t *gsn,
int (*cb_create_context_ind) (struct
pdp_t *
pdp));
extern int gtp_set_cb_update_context_ind(struct gsn_t *gsn,
int (*cb_update_context_ind)(struct pdp_t *pdp));
extern int gtp_set_cb_data_ind(struct gsn_t *gsn,
int (*cb_data_ind) (struct pdp_t * pdp,
void *pack, unsigned len));
extern int gtp_set_cb_delete_context(struct gsn_t *gsn,
int (*cb_delete_context) (struct pdp_t *
pdp));
/*extern int gtp_set_cb_create_context(struct gsn_t *gsn,
int (*cb_create_context) (struct pdp_t* pdp)); */
extern int gtp_set_cb_unsup_ind(struct gsn_t *gsn,
int (*cb) (struct sockaddr_in * peer));
extern int gtp_set_cb_extheader_ind(struct gsn_t *gsn,
int (*cb) (struct sockaddr_in * peer));
extern int gtp_set_cb_ran_info_relay_ind(struct gsn_t *gsn,
int (*cb) (struct sockaddr_in * peer, union gtpie_member **ie));
extern int gtp_set_cb_conf(struct gsn_t *gsn,
int (*cb) (int type, int cause, struct pdp_t * pdp,
void *cbp));
int gtp_set_cb_recovery(struct gsn_t *gsn,
int (*cb) (struct sockaddr_in * peer,
uint8_t recovery))
OSMO_DEPRECATED("Use gtp_set_cb_recovery2() instead, to obtain pdp ctx originating the recovery");
int gtp_set_cb_recovery2(struct gsn_t *gsn,
int (*cb) (struct sockaddr_in * peer,
struct pdp_t * pdp,
uint8_t recovery))
OSMO_DEPRECATED("Use gtp_set_cb_recovery3() instead, to obtain gsn handling the recovery");
int gtp_set_cb_recovery3(struct gsn_t *gsn,
int (*cb) (struct gsn_t * gsn, struct sockaddr_in * peer,
struct pdp_t * pdp,
uint8_t recovery));
void gtp_clear_queues(struct gsn_t *gsn);
extern int gtp_fd(struct gsn_t *gsn);
extern int gtp_retrans(struct gsn_t *gsn) OSMO_DEPRECATED("This API is a no-op, libgtp already does the job internally");
extern int gtp_retranstimeout(struct gsn_t *gsn, struct timeval *timeout) OSMO_DEPRECATED("This API is a no-op and will return a 1 day timeout");
#endif /* !_GSN_H */

View File

@@ -1,12 +1,12 @@
/*
/*
* OsmoGGSN - Gateway GPRS Support Node
* Copyright (C) 2002, 2003, 2004 Mondru AB.
*
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
* notice and this permission notice is included in all copies or
* substantial portions of the software.
*
*
*/
#ifndef _GTP_H
@@ -14,8 +14,9 @@
#include <osmocom/core/utils.h>
#define GTP_MODE_GGSN 1
#define GTP_MODE_SGSN 2
#include "gtpie.h"
#include "pdp.h"
#include "gsn.h"
#define GTP0_PORT 3386
#define GTP1C_PORT 2123
@@ -27,12 +28,10 @@
#define GTP1_HEADER_SIZE_SHORT 8
#define GTP1_HEADER_SIZE_LONG 12
#define NAMESIZE 1024
#define SYSLOG_PRINTSIZE 255
#define ERRMSG_SIZE 255
#define RESTART_FILE "gsn_restart"
#define NAMESIZE 1024
/* GTP version 1 extension header type definitions. */
#define GTP_EXT_PDCP_PDU 0xC0 /* PDCP PDU Number */
@@ -54,7 +53,7 @@
#define GTP_UPDATE_PDP_RSP 19 /* Update PDP Context Response */
#define GTP_DELETE_PDP_REQ 20 /* Delete PDP Context Request */
#define GTP_DELETE_PDP_RSP 21 /* Delete PDP Context Response */
/* 22-25 For future use. *//* In version GTP 1 anonomous PDP context */
/* 22-25 For future use. *//* In version GTP 1 anonomous PDP context */
#define GTP_ERROR 26 /* Error Indication */
#define GTP_PDU_NOT_REQ 27 /* PDU Notification Request */
#define GTP_PDU_NOT_RSP 28 /* PDU Notification Response */
@@ -81,6 +80,7 @@
#define GTP_FWD_SRNS 58 /* Forward SRNS Context */
#define GTP_FWD_RELOC_ACK 59 /* Forward Relocation Complete Acknowledge */
#define GTP_FWD_SRNS_ACK 60 /* Forward SRNS Context Acknowledge */
#define GTP_RAN_INFO_RELAY 70 /* RAN Information Relay */
/* 61-239 For future use. */
#define GTP_DATA_TRAN_REQ 240 /* Data Record Transfer Request */
#define GTP_DATA_TRAN_RSP 241 /* Data Record Transfer Response */
@@ -91,7 +91,7 @@ extern const struct value_string gtp_type_names[];
static inline const char *gtp_type_name(uint8_t val)
{ return get_value_string(gtp_type_names, val); }
/* GTP information element cause codes from 29.060 v3.9.0 7.7 */
/* GTP information element cause codes from 29.060 v15.3.0 7.7.1 */
/* */
#define GTPCAUSE_REQ_IMSI 0 /* Request IMSI */
#define GTPCAUSE_REQ_IMEI 1 /* Request IMEI */
@@ -99,19 +99,26 @@ static inline const char *gtp_type_name(uint8_t val)
#define GTPCAUSE_NO_ID_NEEDED 3 /* No identity needed */
#define GTPCAUSE_MS_REFUSES_X 4 /* MS refuses */
#define GTPCAUSE_MS_NOT_RESP_X 5 /* MS is not GPRS responding */
#define GTPCAUSE_006 6 /* For future use 6-48 */
#define GTPCAUSE_049 49 /* Cause values reserved for GPRS charging protocol use (See GTP' in GSM 12.15) 49-63 */
#define GTPCAUSE_064 64 /* For future use 64-127 */
#define GTPCAUSE_REACTIVATION_REQ 6 /* Reactivation Requested */
#define GTPCAUSE_PDP_ADDR_INACT 7 /* PDP address inactivity timer expires */
#define GTPCAUSE_NET_FAILURE 8 /* Network failure */
#define GTPCAUSE_QOS_MISMATCH 9 /* QoS parameter mismatch */
/* 10-48 For future use */
/* 49-63 Cause values reserved for GPRS charging protocol use (See GTP' 3GPP TS 32.295) */
/* 64-127 For future use */
#define GTPCAUSE_ACC_REQ 128 /* Request accepted */
#define GTPCAUSE_129 129 /* For future use 129-176 */
#define GTPCAUSE_177 177 /* Cause values reserved for GPRS charging protocol use (See GTP' In GSM 12.15) 177-191 */
#define GTPCAUSE_NEW_PDP_NET_PREF 129 /* New PDP type due to network preference */
#define GTPCAUSE_NEW_PDP_ADDR_BEAR 130 /* New PDP type due to single address bearer only */
/* 131-176 For future use */
/* 177-191 Cause values reserved for GPRS charging protocol use (See GTP' 3GPP TS 32.295) */
#define GTPCAUSE_NON_EXIST 192 /* Non-existent */
#define GTPCAUSE_INVALID_MESSAGE 193 /* Invalid message format */
#define GTPCAUSE_IMSI_NOT_KNOWN 194 /* IMSI not known */
#define GTPCAUSE_MS_DETACHED 195 /* MS is GPRS detached */
#define GTPCAUSE_MS_NOT_RESP 196 /* MS is not GPRS responding */
#define GTPCAUSE_MS_REFUSES 197 /* MS refuses */
#define GTPCAUSE_198 198 /* For future use */
#define GTPCAUSE_VERSION_NOT_SUPPORTED 198 /* Version not supported */
#define GTPCAUSE_NO_RESOURCES 199 /* No resources available */
#define GTPCAUSE_NOT_SUPPORTED 200 /* Service not supported */
#define GTPCAUSE_MAN_IE_INCORRECT 201 /* Mandatory IE incorrect */
@@ -134,14 +141,21 @@ static inline const char *gtp_type_name(uint8_t val)
#define GTPCAUSE_SYN_ERR_FILTER 218 /* Syntactic errors in packet filter(s) */
#define GTPCAUSE_MISSING_APN 219 /* Missing or unknown APN */
#define GTPCAUSE_UNKNOWN_PDP 220 /* Unknown PDP address or PDP type */
#define GTPCAUSE_221 221 /* For Future Use 221-240 */
#define GTPCAUSE_241 241 /* Cause Values Reserved For Gprs Charging Protocol Use (See Gtp' In Gsm 12.15) 241-255 */
/* 234-240 For future use */
/* 241-255 Cause Values Reserved For Gprs Charging Protocol Use (See Gtp' 3GPP TS 32.295) */
static inline bool gtp_cause_successful(uint8_t cause)
{
return cause == GTPCAUSE_ACC_REQ ||
cause == GTPCAUSE_NEW_PDP_NET_PREF ||
cause == GTPCAUSE_NEW_PDP_ADDR_BEAR;
}
struct ul66_t;
struct ul16_t;
struct pdp_t;
/* GTP 0 header.
/* GTP 0 header.
* Explanation to some of the fields:
* SNDCP NPDU Number flag = 0 except for inter SGSN handover situations
* SNDCP N-PDU LCC Number 0 = 0xff except for inter SGSN handover situations
@@ -226,193 +240,48 @@ union gtp_packet {
struct gtp1_packet_long gtp1l;
} __attribute__ ((packed));
/* ***********************************************************
* Information storage for each gsn instance
*
* Normally each instance of the application corresponds to
* one instance of a gsn.
*
* In order to avoid global variables in the application, and
* also in order to allow several instances of a gsn in the same
* application this struct is provided in order to store all
* relevant information related to the gsn.
*
* Note that this does not include information storage for '
* each pdp context. This is stored in another struct.
*************************************************************/
struct gsn_t {
/* Parameters related to the network interface */
int fd0; /* GTP0 file descriptor */
int fd1c; /* GTP1 control plane file descriptor */
int fd1u; /* GTP0 user plane file descriptor */
int mode; /* Mode of operation: GGSN or SGSN */
struct in_addr gsnc; /* IP address of this gsn for signalling */
struct in_addr gsnu; /* IP address of this gsn for user traffic */
/* Parameters related to signalling messages */
uint16_t seq_next; /* Next sequence number to use */
int seq_first; /* First packet in queue (oldest timeout) */
int seq_last; /* Last packet in queue (youngest timeout) */
unsigned char restart_counter; /* Increment on restart. Stored on disk */
char *statedir; /* Disk location for permanent storage */
void *priv; /* used by libgtp users to attach their own state) */
struct queue_t *queue_req; /* Request queue */
struct queue_t *queue_resp; /* Response queue */
/* Call back functions */
int (*cb_delete_context) (struct pdp_t *);
int (*cb_create_context_ind) (struct pdp_t *);
int (*cb_unsup_ind) (struct sockaddr_in * peer);
int (*cb_extheader_ind) (struct sockaddr_in * peer);
int (*cb_conf) (int type, int cause, struct pdp_t * pdp, void *cbp);
int (*cb_data_ind) (struct pdp_t * pdp, void *pack, unsigned len);
int (*cb_recovery) (struct sockaddr_in * peer, uint8_t recovery);
/* Counters */
uint64_t err_socket; /* Number of socket errors */
uint64_t err_readfrom; /* Number of readfrom errors */
uint64_t err_sendto; /* Number of sendto errors */
uint64_t err_memcpy; /* Number of memcpy */
uint64_t err_queuefull; /* Number of times queue was full */
uint64_t err_seq; /* Number of seq out of range */
uint64_t err_address; /* GSN address conversion failed */
uint64_t err_unknownpdp; /* GSN address conversion failed */
uint64_t err_unknowntid; /* Application supplied unknown imsi+nsapi */
uint64_t err_cause; /* Unexpected cause value received */
uint64_t err_outofpdp; /* Out of storage for PDP contexts */
uint64_t empty; /* Number of empty packets */
uint64_t unsup; /* Number of unsupported version 29.60 11.1.1 */
uint64_t tooshort; /* Number of too short headers 29.60 11.1.2 */
uint64_t unknown; /* Number of unknown messages 29.60 11.1.3 */
uint64_t unexpect; /* Number of unexpected messages 29.60 11.1.4 */
uint64_t duplicate; /* Number of duplicate or unsolicited replies */
uint64_t missing; /* Number of missing information field messages */
uint64_t incorrect; /* Number of incorrect information field messages */
uint64_t invalid; /* Number of invalid message format messages */
};
/* External API functions */
extern const char *gtp_version();
extern int gtp_new(struct gsn_t **gsn, char *statedir, struct in_addr *listen,
int mode);
extern int gtp_free(struct gsn_t *gsn);
extern int gtp_newpdp(struct gsn_t *gsn, struct pdp_t **pdp,
uint64_t imsi, uint8_t nsapi);
extern int gtp_freepdp(struct gsn_t *gsn, struct pdp_t *pdp);
extern int gtp_create_context_req(struct gsn_t *gsn, struct pdp_t *pdp,
void *cbp);
extern int gtp_set_cb_create_context_ind(struct gsn_t *gsn,
int (*cb_create_context_ind) (struct
pdp_t *
pdp));
extern int gtp_create_context_resp(struct gsn_t *gsn, struct pdp_t *pdp,
int cause);
extern int gtp_update_context(struct gsn_t *gsn, struct pdp_t *pdp,
void *cbp, struct in_addr *inetaddr);
extern int gtp_update_context_resp(struct gsn_t *gsn, struct pdp_t *pdp,
int cause);
extern int gtp_delete_context_req(struct gsn_t *gsn, struct pdp_t *pdp,
void *cbp, int teardown);
void *cbp, int teardown)
OSMO_DEPRECATED("Use gtp_delete_context_req2() instead, to avoid freeing pdp ctx before reply");
extern int gtp_delete_context_req2(struct gsn_t *gsn, struct pdp_t *pdp,
void *cbp, int teardown);
extern int gtp_data_req(struct gsn_t *gsn, struct pdp_t *pdp,
void *pack, unsigned len);
extern int gtp_set_cb_data_ind(struct gsn_t *gsn,
int (*cb_data_ind) (struct pdp_t * pdp,
void *pack, unsigned len));
extern int gtp_ran_info_relay_req(struct gsn_t *gsn, const struct sockaddr_in *peer,
const uint8_t *ran_container, size_t ran_container_len,
const uint8_t *rim_route_addr, size_t rim_route_addr_len,
uint8_t rim_route_addr_discr);
extern int gtp_fd(struct gsn_t *gsn);
extern int gtp_decaps0(struct gsn_t *gsn);
extern int gtp_decaps1c(struct gsn_t *gsn);
extern int gtp_decaps1u(struct gsn_t *gsn);
extern int gtp_retrans(struct gsn_t *gsn);
extern int gtp_retranstimeout(struct gsn_t *gsn, struct timeval *timeout);
extern int gtp_set_cb_delete_context(struct gsn_t *gsn,
int (*cb_delete_context) (struct pdp_t *
pdp));
/*extern int gtp_set_cb_create_context(struct gsn_t *gsn,
int (*cb_create_context) (struct pdp_t* pdp)); */
extern int gtp_set_cb_unsup_ind(struct gsn_t *gsn,
int (*cb) (struct sockaddr_in * peer));
extern int gtp_set_cb_extheader_ind(struct gsn_t *gsn,
int (*cb) (struct sockaddr_in * peer));
extern int gtp_set_cb_conf(struct gsn_t *gsn,
int (*cb) (int type, int cause, struct pdp_t * pdp,
void *cbp));
int gtp_set_cb_recovery(struct gsn_t *gsn,
int (*cb) (struct sockaddr_in * peer,
uint8_t recovery));
/* Internal functions (not part of the API */
extern int gtp_echo_req(struct gsn_t *gsn, int version, void *cbp,
struct in_addr *inetaddrs);
extern int gtp_echo_resp(struct gsn_t *gsn, int version,
struct sockaddr_in *peer, int fd,
void *pack, unsigned len);
extern int gtp_echo_ind(struct gsn_t *gsn, int version,
struct sockaddr_in *peer, int fd,
void *pack, unsigned len);
extern int gtp_echo_conf(struct gsn_t *gsn, int version,
struct sockaddr_in *peer, void *pack, unsigned len);
extern int gtp_unsup_req(struct gsn_t *gsn, int version,
struct sockaddr_in *peer,
int fd, void *pack, unsigned len);
extern int gtp_unsup_ind(struct gsn_t *gsn, struct sockaddr_in *peer,
void *pack, unsigned len);
extern int gtp_create_pdp_resp(struct gsn_t *gsn, int version,
struct pdp_t *pdp, uint8_t cause);
extern int gtp_create_pdp_ind(struct gsn_t *gsn, int version,
struct sockaddr_in *peer, int fd,
void *pack, unsigned len);
extern int gtp_create_pdp_conf(struct gsn_t *gsn, int version,
struct sockaddr_in *peer,
void *pack, unsigned len);
extern int gtp_update_pdp_req(struct gsn_t *gsn, int version, void *cbp,
struct in_addr *inetaddr, struct pdp_t *pdp);
extern int gtp_delete_pdp_req(struct gsn_t *gsn, int version, void *cbp,
struct pdp_t *pdp);
extern int gtp_delete_pdp_resp(struct gsn_t *gsn, int version,
struct sockaddr_in *peer, int fd,
void *pack, unsigned len,
struct pdp_t *pdp, struct pdp_t *linked_pdp,
uint8_t cause, int teardown);
extern int gtp_delete_pdp_ind(struct gsn_t *gsn, int version,
struct sockaddr_in *peer, int fd,
void *pack, unsigned len);
extern int gtp_delete_pdp_conf(struct gsn_t *gsn, int version,
struct sockaddr_in *peer,
void *pack, unsigned len);
extern int ipv42eua(struct ul66_t *eua, struct in_addr *src);
extern int eua2ipv4(struct in_addr *dst, struct ul66_t *eua);
extern int gsna2in_addr(struct in_addr *dst, struct ul16_t *gsna);
extern int in_addr2gsna(struct ul16_t *gsna, struct in_addr *src);
extern const char *imsi_gtp2str(const uint64_t *imsi);
/*! Set the talloc context for internal objects */
void gtp_set_talloc_ctx(void *ctx);
#endif /* !_GTP_H */

View File

@@ -321,5 +321,7 @@ extern int gtpie_decaps(union gtpie_member *ie[], int version,
extern int gtpie_encaps(union gtpie_member *ie[], void *pack, unsigned *len);
extern int gtpie_encaps2(union gtpie_member ie[], unsigned int size,
void *pack, unsigned *len);
extern int gtpie_encaps3(union gtpie_member *ie[], unsigned int ie_len,
void *pack, unsigned pack_len, unsigned *encoded_len);
#endif /* !_GTPIE_H */

View File

@@ -14,6 +14,10 @@
#define _PDP_H
#include <stdbool.h>
#include <netinet/in.h>
#include <osmocom/core/defs.h>
#include <osmocom/core/linuxlist.h>
struct gsn_t;
@@ -42,6 +46,11 @@ struct ul_t {
unsigned char *v;
};
struct ul1_t {
unsigned int l;
unsigned char v[1];
};
struct ul16_t {
unsigned int l;
unsigned char v[16];
@@ -235,38 +244,44 @@ struct pdp_t {
/* to be used by libgtp callers/users (to attach their own private state) */
void *priv;
struct gsn_t *gsn;
struct gsn_t *gsn; /* Back pointer to GSN where this pdp ctx belongs to */
bool tx_gpdu_seq; /* Transmit (true) or suppress G-PDU sequence numbers */
struct llist_head qmsg_list_req; /* list of req qmsg_t in retrans queue belonging this pdp ctx */
struct ul1_t dir_tun_flags; /* Direct Tunnel Flags, TS 29.060 7.7.81 */
};
/* functions related to pdp_t management */
int pdp_init();
int pdp_newpdp(struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi,
struct pdp_t *pdp_old);
int gtp_pdp_newpdp(struct gsn_t *gsn, struct pdp_t **pdp, uint64_t imsi,
uint8_t nsapi, struct pdp_t *pdp_old);
int pdp_freepdp(struct pdp_t *pdp);
int pdp_getpdp(struct pdp_t **pdp);
int pdp_getgtp0(struct pdp_t **pdp, uint16_t fl);
int pdp_getgtp1(struct pdp_t **pdp, uint32_t tei);
int pdp_getgtp1_peer_d(struct pdp_t **pdp, const struct sockaddr_in *peer, uint32_t teid_gn);
int pdp_getimsi(struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi);
int gtp_pdp_getgtp0(struct gsn_t *gsn, struct pdp_t **pdp, uint16_t fl);
int gtp_pdp_getgtp1(struct gsn_t *gsn, struct pdp_t **pdp, uint32_t tei);
int gtp_pdp_getgtp1_peer_d(struct gsn_t *gsn, struct pdp_t **pdp, const struct sockaddr_in *peer, uint32_t teid_gn);
int gtp_pdp_getimsi(struct gsn_t *gsn, struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi);
int gtp_pdp_tidget(struct gsn_t *gsn, struct pdp_t **pdp, uint64_t tid);
int pdp_tidhash(uint64_t tid);
int pdp_tidset(struct pdp_t *pdp, uint64_t tid);
int pdp_tiddel(struct pdp_t *pdp);
int pdp_tidget(struct pdp_t **pdp, uint64_t tid);
void pdp_set_imsi_nsapi(struct pdp_t *pdp, uint64_t teid);
/*
int pdp_iphash(void* ipif, struct ul66_t *eua);
int pdp_ipset(struct pdp_t *pdp, void* ipif, struct ul66_t *eua);
int pdp_ipdel(struct pdp_t *pdp);
int pdp_ipget(struct pdp_t **pdp, void* ipif, struct ul66_t *eua);
*/
uint64_t pdp_gettid(uint64_t imsi, uint8_t nsapi);
void pdp_set_imsi_nsapi(struct pdp_t *pdp, uint64_t teid);
unsigned int pdp_count_secondary(const struct pdp_t *pdp);
/* Deprecated APIs (support for only 1 GSN per process). Must be used only after first call to gtp_new() and until it is freed. */
int pdp_init(struct gsn_t *gsn); /* Use only allowed inside libgtp to keep compatiblity with deprecated APIs defined here. */
int pdp_newpdp(struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi,
struct pdp_t *pdp_old) OSMO_DEPRECATED("Use gtp_pdp_newpdp() instead");
int pdp_getpdp(struct pdp_t **pdp) OSMO_DEPRECATED("Use gsn_t->pdpa field instead");
int pdp_getgtp0(struct pdp_t **pdp, uint16_t fl) OSMO_DEPRECATED("Use gtp_pdp_getgtp0() instead");
int pdp_getgtp1(struct pdp_t **pdp, uint32_t tei) OSMO_DEPRECATED("Use gtp_pdp_getgtp1() instead");
int pdp_getgtp1_peer_d(struct pdp_t **pdp, const struct sockaddr_in *peer, uint32_t teid_gn) OSMO_DEPRECATED("Use gtp_pdp_getgtp1_peer_d() instead");
int pdp_getimsi(struct pdp_t **pdp, uint64_t imsi, uint8_t nsapi) OSMO_DEPRECATED("Use gtp_pdp_getimsi() instead");
int pdp_tidget(struct pdp_t **pdp, uint64_t tid) OSMO_DEPRECATED("Use gtp_pdp_tidget() instead");
#endif /* !_PDP_H */

View File

@@ -1,7 +1,44 @@
noinst_LIBRARIES = libmisc.a
noinst_HEADERS = gnugetopt.h ippool.h lookup.h syserr.h tun.h in46_addr.h
noinst_HEADERS = \
checksum.h \
gnugetopt.h \
gtp-kernel.h \
icmpv6.h \
in46_addr.h \
ippool.h \
lookup.h \
netdev.h \
netns.h \
syserr.h \
tun.h \
util.h \
$(NULL)
AM_CFLAGS = -O2 -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb $(LIBOSMOCORE_CFLAGS)
AM_CFLAGS = \
-fno-builtin \
-Wall \
-DSBINDIR='"$(sbindir)"' \
-I$(top_srcdir)/include \
$(LIBOSMOCORE_CFLAGS) \
$(NULL)
libmisc_a_SOURCES = getopt1.c getopt.c ippool.c lookup.c tun.c debug.c in46_addr.c
libmisc_a_SOURCES = \
checksum.c \
debug.c \
getopt.c \
getopt1.c \
icmpv6.c \
in46_addr.c \
ippool.c \
lookup.c \
netdev.c \
netns.c \
tun.c \
util.c \
$(NULL)
if ENABLE_GTP_KERNEL
AM_CFLAGS += -DGTP_KERNEL $(LIBGTPNL_CFLAGS)
libmisc_a_SOURCES += gtp-kernel.c
endif

View File

@@ -24,12 +24,12 @@ static const struct log_info_cat default_categories[] = {
[DSGSN] = {
.name = "DSGSN",
.description = "SGSN Emulator",
.enabled = 1, .loglevel = LOGL_NOTICE,
.enabled = 1, .loglevel = LOGL_INFO,
},
[DICMP6] = {
.name = "DICMP6",
.description = "ICMPv6",
.enabled = 1, .loglevel = LOGL_DEBUG,
.enabled = 1, .loglevel = LOGL_NOTICE,
},
};

201
lib/gtp-kernel.c Normal file
View File

@@ -0,0 +1,201 @@
#ifdef __linux__
#define _GNU_SOURCE 1 /* strdup() prototype, broken arpa/inet.h */
#endif
#include "../config.h"
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <libgtpnl/gtp.h>
#include <libgtpnl/gtpnl.h>
#include <errno.h>
#include <time.h>
#include <osmocom/gtp/pdp.h>
#include <osmocom/gtp/gtp.h>
#include "../lib/tun.h"
#include "../lib/syserr.h"
#include "../lib/util.h"
#include "../lib/ippool.h"
#include "gtp-kernel.h"
static void pdp_debug(const char *prefix, const char *devname, struct pdp_t *pdp)
{
char buf4[INET_ADDRSTRLEN], buf6[INET6_ADDRSTRLEN];
struct ippoolm_t *peer;
struct in_addr ia;
buf4[0] = '\0';
if ((peer = pdp_get_peer_ipv(pdp, false)))
in46a_ntop(&peer->addr, buf4, sizeof(buf4));
buf6[0] = '\0';
if ((peer = pdp_get_peer_ipv(pdp, true)))
in46a_ntop(&peer->addr, buf6, sizeof(buf6));
gsna2in_addr(&ia, &pdp->gsnrc);
LOGPDPX(DGGSN, LOGL_DEBUG, pdp, "%s %s v%u TEID %"PRIx64" EUA=(%s,%s) SGSN=%s\n", prefix,
devname, pdp->version,
pdp->version == 0 ? pdp_gettid(pdp->imsi, pdp->nsapi) : pdp->teid_gn,
buf4, buf6, inet_ntoa(ia));
}
static struct {
int genl_id;
struct mnl_socket *nl;
} gtp_nl;
static int gtp_kernel_init_once(void)
{
/* only initialize once */
if (gtp_nl.nl)
return 0;
gtp_nl.nl = genl_socket_open();
if (gtp_nl.nl == NULL) {
LOGP(DGGSN, LOGL_ERROR, "cannot create genetlink socket\n");
return -1;
}
gtp_nl.genl_id = genl_lookup_family(gtp_nl.nl, "gtp");
if (gtp_nl.genl_id < 0) {
LOGP(DGGSN, LOGL_ERROR, "cannot lookup GTP genetlink ID\n");
genl_socket_close(gtp_nl.nl);
gtp_nl.nl = NULL;
return -1;
}
LOGP(DGGSN, LOGL_NOTICE, "Initialized GTP kernel mode (genl ID is %d)\n", gtp_nl.genl_id);
return 0;
}
int gtp_kernel_create(int dest_ns, const char *devname, int fd0, int fd1u)
{
if (gtp_kernel_init_once() < 0)
return -1;
return gtp_dev_create(dest_ns, devname, fd0, fd1u);
}
int gtp_kernel_create_sgsn(int dest_ns, const char *devname, int fd0, int fd1u)
{
if (gtp_kernel_init_once() < 0)
return -1;
return gtp_dev_create_sgsn(dest_ns, devname, fd0, fd1u);
}
void gtp_kernel_stop(const char *devname)
{
gtp_dev_destroy(devname);
}
int gtp_kernel_tunnel_add(struct pdp_t *pdp, const char *devname)
{
int ms_addr_count;
struct in46_addr ms[2];
struct in46_addr sgsn;
struct gtp_tunnel *t;
int ret = 0;
pdp_debug(__func__, devname, pdp);
in46a_from_gsna(&pdp->gsnrc, &sgsn);
ms_addr_count = in46a_from_eua(&pdp->eua, ms);
if (ms_addr_count < 0)
return -1;
for (int i = 0; i < ms_addr_count; i++) {
t = gtp_tunnel_alloc();
if (t == NULL)
return -1;
gtp_tunnel_set_ifidx(t, if_nametoindex(devname));
gtp_tunnel_set_version(t, pdp->version);
if (in46a_to_af(&ms[i]) == AF_INET)
gtp_tunnel_set_ms_ip4(t, &ms[i].v4);
else {
/* In IPv6, EUA doesn't contain the actual IP
* addr/prefix. Set higher bits to 0 to get the 64 bit
* netmask. */
memset(((void *)&ms[i].v6) + 8, 0, 8);
gtp_tunnel_set_ms_ip6(t, &ms[i].v6);
}
if (in46a_to_af(&sgsn) == AF_INET)
gtp_tunnel_set_sgsn_ip4(t, &sgsn.v4);
else
gtp_tunnel_set_sgsn_ip6(t, &sgsn.v6);
if (pdp->version == 0) {
gtp_tunnel_set_tid(t, pdp_gettid(pdp->imsi, pdp->nsapi));
gtp_tunnel_set_flowid(t, pdp->flru);
} else {
gtp_tunnel_set_i_tei(t, pdp->teid_own);
/* use the TEI advertised by SGSN when sending packets
* towards the SGSN */
gtp_tunnel_set_o_tei(t, pdp->teid_gn);
}
ret = gtp_add_tunnel(gtp_nl.genl_id, gtp_nl.nl, t);
gtp_tunnel_free(t);
if (ret != 0)
break;
}
return ret;
}
int gtp_kernel_tunnel_del(struct pdp_t *pdp, const char *devname)
{
int ms_addr_count;
struct in46_addr ms[2];
struct gtp_tunnel *t;
int ret = 0;
pdp_debug(__func__, devname, pdp);
ms_addr_count = in46a_from_eua(&pdp->eua, ms);
if (ms_addr_count < 0)
return -1;
for (int i = 0; i < ms_addr_count; i++) {
t = gtp_tunnel_alloc();
if (t == NULL)
return -1;
gtp_tunnel_set_ifidx(t, if_nametoindex(devname));
gtp_tunnel_set_family(t, in46a_to_af(&ms[i]));
gtp_tunnel_set_version(t, pdp->version);
if (pdp->version == 0) {
gtp_tunnel_set_tid(t, pdp_gettid(pdp->imsi, pdp->nsapi));
gtp_tunnel_set_flowid(t, pdp->flru);
} else {
gtp_tunnel_set_i_tei(t, pdp->teid_own);
}
ret = gtp_del_tunnel(gtp_nl.genl_id, gtp_nl.nl, t);
gtp_tunnel_free(t);
if (ret != 0)
break;
}
return ret;
}

View File

@@ -7,18 +7,20 @@ extern int debug;
extern char *ipup;
#ifdef GTP_KERNEL
int gtp_kernel_init(struct gsn_t *gsn, const char *devname, struct in46_prefix *prefix, const char *ipup);
int gtp_kernel_create(int dest_ns, const char *devname, int fd0, int fd1u);
int gtp_kernel_create_sgsn(int dest_ns, const char *devname, int fd0, int fd1u);
void gtp_kernel_stop(const char *devname);
int gtp_kernel_tunnel_add(struct pdp_t *pdp, const char *devname);
int gtp_kernel_tunnel_del(struct pdp_t *pdp, const char *devname);
#else
static inline int gtp_kernel_init(struct gsn_t *gsn, const char *devname, struct in46_prefix *prefix, const char *ipup)
static inline int gtp_kernel_create(int dest_ns, const char *devname, int fd0, int fd1u)
{
SYS_ERR(DGGSN, LOGL_ERROR, 0, "ggsn compiled without GTP kernel support!\n");
return -1;
}
#define gtp_kernel_create_sgsn gtp_kernel_create
static inline void gtp_kernel_stop(const char *devname) {}

335
lib/icmpv6.c Normal file
View File

@@ -0,0 +1,335 @@
/* Minimal ICMPv6 code for generating router advertisements as required by
* relevant 3GPP specs for a GGSN with IPv6 PDP contexts */
/* (C) 2017 by Harald Welte <laforge@gnumonks.org>
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
* notice and this permission notice is included in all copies or
* substantial portions of the software.
*/
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <netinet/in.h>
#if defined(__FreeBSD__)
#include <sys/types.h> /* FreeBSD 10.x needs this before ip6.h */
#include <sys/endian.h>
#endif
#include <netinet/ip6.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/utils.h>
#include <osmocom/gtp/gtp.h>
#include <osmocom/gtp/pdp.h>
#include "checksum.h"
#include "ippool.h"
#include "syserr.h"
#include "icmpv6.h"
#include "config.h"
/* 29.061 11.2.1.3.4 IPv6 Router Configuration Variables in GGSN */
#define GGSN_MaxRtrAdvInterval 21600 /* 6 hours */
#define GGSN_MinRtrAdvInterval 16200 /* 4.5 hours */
#define GGSN_AdvValidLifetime 0xffffffff /* infinite */
#define GGSN_AdvPreferredLifetime 0xffffffff /* infinite */
/* RFC3307 link-local scope multicast address */
const struct in6_addr all_router_mcast_addr = {
.s6_addr = { 0xff,0x02,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,2 }
};
/* RFC4291 link-local solicited-node multicast address, FF02:0:0:0:0:1:FF, 104 bits = 13 bytes */
const uint8_t solicited_node_mcast_addr_prefix[13] = {
0xff, 0x02, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01,
0xFF
};
/* Prepends the ipv6 header and returns checksum content */
uint16_t icmpv6_prepend_ip6hdr(struct msgb *msg, const struct in6_addr *saddr,
const struct in6_addr *daddr)
{
uint32_t len;
uint16_t skb_csum;
struct ip6_hdr *i6h;
/* checksum */
skb_csum = csum_partial(msgb_data(msg), msgb_length(msg), 0);
len = msgb_length(msg);
skb_csum = csum_ipv6_magic(saddr, daddr, len, IPPROTO_ICMPV6, skb_csum);
/* Push IPv6 header in front of ICMPv6 packet */
i6h = (struct ip6_hdr *) msgb_push(msg, sizeof(*i6h));
/* 4 bits version, 8 bits TC, 20 bits flow-ID */
i6h->ip6_ctlun.ip6_un1.ip6_un1_flow = htonl(0x60000000);
i6h->ip6_ctlun.ip6_un1.ip6_un1_plen = htons(len);
i6h->ip6_ctlun.ip6_un1.ip6_un1_nxt = IPPROTO_ICMPV6;
i6h->ip6_ctlun.ip6_un1.ip6_un1_hlim = 255;
i6h->ip6_src = *saddr;
i6h->ip6_dst = *daddr;
return skb_csum;
}
/*! construct a RFC4861 compliant ICMPv6 router soliciation
* \param[in] saddr Source IPv6 address for router advertisement
* \param[in] daddr Destination IPv6 address for router advertisement IPv6 header
* \param[in] prefix The single prefix to be advertised (/64 implied!)
* \returns callee-allocated message buffer containing router advertisement */
struct msgb *icmpv6_construct_rs(const struct in6_addr *saddr)
{
struct msgb *msg = msgb_alloc_headroom(512,128, "IPv6 RS");
struct icmpv6_rsol_hdr *rs;
OSMO_ASSERT(msg);
rs = (struct icmpv6_rsol_hdr *) msgb_put(msg, sizeof(*rs));
rs->hdr.type = 133; /* see RFC4861 4.1 */
rs->hdr.code = 0; /* see RFC4861 4.1 */
rs->hdr.csum = 0; /* updated below */
rs->reserved = 0; /* see RFC4861 4.1 */
rs->hdr.csum = icmpv6_prepend_ip6hdr(msg, saddr, &all_router_mcast_addr);
return msg;
}
/*! construct a 3GPP 29.061 compliant router advertisement for a given prefix
* \param[in] saddr Source IPv6 address for router advertisement
* \param[in] daddr Destination IPv6 address for router advertisement IPv6 header
* \param[in] prefix The single prefix to be advertised (/64 implied!)
* \returns callee-allocated message buffer containing router advertisement */
static struct msgb *icmpv6_construct_ra(const struct in6_addr *saddr,
const struct in6_addr *daddr,
const struct in6_addr *prefix,
uint32_t mtu)
{
struct msgb *msg = msgb_alloc_headroom(512,128, "IPv6 RA");
struct icmpv6_radv_hdr *ra;
struct icmpv6_opt_prefix *ra_opt_pref;
struct icmpv6_opt_mtu *ra_opt_mtu;
OSMO_ASSERT(msg);
ra = (struct icmpv6_radv_hdr *) msgb_put(msg, sizeof(*ra));
ra->hdr.type = 134; /* see RFC4861 4.2 */
ra->hdr.code = 0; /* see RFC4861 4.2 */
ra->hdr.csum = 0; /* updated below */
ra->cur_ho_limit = 64; /* seems reasonable? */
/* the GGSN shall leave the M-flag cleared in the Router
* Advertisement messages */
ra->m = 0;
/* The GGSN may set the O-flag if there are additional
* configuration parameters that need to be fetched by the MS */
ra->o = 0; /* no DHCPv6 */
ra->res = 0;
/* RFC4861 Default: 3 * MaxRtrAdvInterval */
ra->router_lifetime = htons(3*GGSN_MaxRtrAdvInterval);
ra->reachable_time = 0; /* Unspecified */
/* RFC4861 Section 4.6.2 */
ra_opt_pref = (struct icmpv6_opt_prefix *) msgb_put(msg, sizeof(*ra_opt_pref));
ra_opt_pref->hdr.type = 3; /* RFC4861 4.6.2 */
ra_opt_pref->hdr.len = 4; /* RFC4861 4.6.2 */
ra_opt_pref->prefix_len = 64; /* only prefix length as per 3GPP */
/* The Prefix is contained in the Prefix Information Option of
* the Router Advertisements and shall have the A-flag set
* and the L-flag cleared */
ra_opt_pref->a = 1;
ra_opt_pref->l = 0;
ra_opt_pref->res = 0;
/* The lifetime of the prefix shall be set to infinity */
ra_opt_pref->valid_lifetime = htonl(GGSN_AdvValidLifetime);
ra_opt_pref->preferred_lifetime = htonl(GGSN_AdvPreferredLifetime);
ra_opt_pref->res2 = 0;
memcpy(ra_opt_pref->prefix, prefix, sizeof(ra_opt_pref->prefix));
/* RFC4861 Section 4.6.4, MTU */
ra_opt_mtu = (struct icmpv6_opt_mtu *) msgb_put(msg, sizeof(*ra_opt_mtu));
ra_opt_mtu->hdr.type = 5; /* RFC4861 4.6.4 */
ra_opt_mtu->hdr.len = 1; /* RFC4861 4.6.4 */
ra_opt_mtu->reserved = 0;
ra_opt_mtu->mtu = htonl(mtu);
/* The Prefix is contained in the Prefix Information Option of
* the Router Advertisements and shall have the A-flag set
* and the L-flag cleared */
ra_opt_pref->a = 1;
ra_opt_pref->l = 0;
ra_opt_pref->res = 0;
/* The lifetime of the prefix shall be set to infinity */
ra_opt_pref->valid_lifetime = htonl(GGSN_AdvValidLifetime);
ra_opt_pref->preferred_lifetime = htonl(GGSN_AdvPreferredLifetime);
ra_opt_pref->res2 = 0;
memcpy(ra_opt_pref->prefix, prefix, sizeof(ra_opt_pref->prefix));
/* checksum */
ra->hdr.csum = icmpv6_prepend_ip6hdr(msg, saddr, daddr);
return msg;
}
/* Validate an ICMPv6 router solicitation according to RFC4861 6.1.1 */
static bool icmpv6_validate_router_solicit(const uint8_t *pack, unsigned len)
{
const struct ip6_hdr *ip6h = (struct ip6_hdr *)pack;
//const struct icmpv6_hdr *ic6h = (struct icmpv6_hdr *) (pack + sizeof(*ip6h));
/* Hop limit field must have 255 */
if (ip6h->ip6_ctlun.ip6_un1.ip6_un1_hlim != 255)
return false;
/* FIXME: ICMP checksum is valid */
/* ICMP length (derived from IP length) is 8 or more octets */
if (ip6h->ip6_ctlun.ip6_un1.ip6_un1_plen < 8)
return false;
/* FIXME: All included options have a length > 0 */
/* FIXME: If IP source is unspecified, no source link-layer addr option */
return true;
}
/* Validate an ICMPv6 neighbor solicitation according to RFC4861 7.1.1 */
static bool icmpv6_validate_neigh_solicit(const uint8_t *pack, unsigned len)
{
const struct ip6_hdr *ip6h = (struct ip6_hdr *)pack;
/* Hop limit field must have 255 */
if (ip6h->ip6_ctlun.ip6_un1.ip6_un1_hlim != 255)
return false;
/* FIXME: ICMP checksum is valid */
/* ICMP length (derived from IP length) is 24 or more octets */
if (ip6h->ip6_ctlun.ip6_un1.ip6_un1_plen < 24)
return false;
/* FIXME: All included options have a length > 0 */
/* FIXME: If the IP source address is the unspecified address, the IP
* destination address is a solicited-node multicast address. */
/* FIXME: If IP source is unspecified, no source link-layer addr option */
return true;
}
/* Validate an ICMPv6 router advertisement according to RFC4861 6.1.2.
Returns pointer packet header on success, NULL otherwise. */
struct icmpv6_radv_hdr *icmpv6_validate_router_adv(const uint8_t *pack, unsigned len)
{
const struct ip6_hdr *ip6h = (struct ip6_hdr *)pack;
const struct icmpv6_hdr *ic6h = (struct icmpv6_hdr *) (pack + sizeof(*ip6h));
/* ICMP length (derived from IP length) is 16 or more octets */
if (len < sizeof(*ip6h) + 16)
return NULL;
if (ic6h->type != 134) /* router advertismenet type */
return NULL;
/*Routers must use their link-local address */
if (!IN6_IS_ADDR_LINKLOCAL(&ip6h->ip6_src))
return NULL;
/* Hop limit field must have 255 */
if (ip6h->ip6_ctlun.ip6_un1.ip6_un1_hlim != 255)
return NULL;
/* ICMP Code is 0 */
if (ic6h->code != 0)
return NULL;
/* ICMP length (derived from IP length) is 16 or more octets */
if (ip6h->ip6_ctlun.ip6_un1.ip6_un1_plen < 16)
return NULL;
/* FIXME: All included options have a length > 0 */
/* FIXME: If IP source is unspecified, no source link-layer addr option */
return (struct icmpv6_radv_hdr *)ic6h;
}
/* handle incoming packets to the all-routers multicast address */
int handle_router_mcast(struct gsn_t *gsn, struct pdp_t *pdp,
const struct in6_addr *pdp_prefix,
const struct in6_addr *own_ll_addr,
uint32_t mtu,
const uint8_t *pack, unsigned len)
{
const struct ip6_hdr *ip6h = (struct ip6_hdr *)pack;
const struct icmpv6_hdr *ic6h = (struct icmpv6_hdr *) (pack + sizeof(*ip6h));
struct msgb *msg;
if (len < sizeof(*ip6h)) {
LOGP(DICMP6, LOGL_NOTICE, "Packet too short: %u bytes\n", len);
return -1;
}
/* we only treat ICMPv6 here */
if (ip6h->ip6_ctlun.ip6_un1.ip6_un1_nxt != IPPROTO_ICMPV6) {
LOGP(DICMP6, LOGL_DEBUG, "Ignoring non-ICMP to all-routers mcast\n");
return 0;
}
if (len < sizeof(*ip6h) + sizeof(*ic6h)) {
LOGP(DICMP6, LOGL_NOTICE, "Short ICMPv6 packet: %s\n", osmo_hexdump(pack, len));
return -1;
}
switch (ic6h->type) {
case 133: /* router solicitation */
if (ic6h->code != 0) {
LOGP(DICMP6, LOGL_NOTICE, "ICMPv6 type 133 but code %d\n", ic6h->code);
return -1;
}
if (!icmpv6_validate_router_solicit(pack, len)) {
LOGP(DICMP6, LOGL_NOTICE, "Invalid Router Solicitation: %s\n",
osmo_hexdump(pack, len));
return -1;
}
/* Send router advertisement from GGSN link-local
* address to MS link-local address, including prefix
* allocated to this PDP context */
msg = icmpv6_construct_ra(own_ll_addr, &ip6h->ip6_src, pdp_prefix, mtu);
/* Send the constructed RA to the MS */
gtp_data_req(gsn, pdp, msgb_data(msg), msgb_length(msg));
msgb_free(msg);
break;
default:
LOGP(DICMP6, LOGL_DEBUG, "Unknown ICMPv6 type %u\n", ic6h->type);
break;
}
return 0;
}
/* handle incoming packets to the solicited-node multicast address */
int handle_solicited_node_mcast(const uint8_t *pack, unsigned len)
{
const struct ip6_hdr *ip6h = (struct ip6_hdr *)pack;
const struct icmpv6_hdr *ic6h = (struct icmpv6_hdr *) (pack + sizeof(*ip6h));
if (len < sizeof(*ip6h)) {
LOGP(DICMP6, LOGL_NOTICE, "Packet too short: %u bytes\n", len);
return -1;
}
/* we only treat ICMPv6 here */
if (ip6h->ip6_ctlun.ip6_un1.ip6_un1_nxt != IPPROTO_ICMPV6) {
LOGP(DICMP6, LOGL_DEBUG, "Ignoring non-ICMP solicited-node mcast\n");
return 0;
}
if (len < sizeof(*ip6h) + sizeof(*ic6h)) {
LOGP(DICMP6, LOGL_NOTICE, "Short ICMPv6 packet: %s\n", osmo_hexdump(pack, len));
return -1;
}
switch (ic6h->type) {
case 135: /* Neighbor Solicitation. RFC2461, RFC2462 */
if (ic6h->code != 0) {
LOGP(DICMP6, LOGL_NOTICE, "ICMPv6 type 135 but code %d\n", ic6h->code);
return -1;
}
if (!icmpv6_validate_neigh_solicit(pack, len)) {
LOGP(DICMP6, LOGL_NOTICE, "Invalid Neighbor Solicitation: %s\n",
osmo_hexdump(pack, len));
return -1;
}
/* RFC 2462: Ignore Neighbor (Duplicate Address Detection) */
LOGP(DICMP6, LOGL_DEBUG, "Ignoring Rx ICMPv6 Neighbor Soliciation: %s\n", osmo_hexdump(pack, len));
break;
default:
LOGP(DICMP6, LOGL_DEBUG, "Unknown ICMPv6 type %u\n", ic6h->type);
break;
}
return 0;
}

109
lib/icmpv6.h Normal file
View File

@@ -0,0 +1,109 @@
#pragma once
#include <stdbool.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/endian.h>
#include <osmocom/gtp/gtp.h>
#include <osmocom/gtp/pdp.h>
#define ICMPv6_OPT_TYPE_PREFIX_INFO 0x03
#define foreach_icmpv6_opt(icmpv6_pkt, icmpv6_len, opt_hdr) \
for (opt_hdr = (struct icmpv6_opt_hdr *)(icmpv6_pkt)->options; \
(uint8_t*)(opt_hdr) + sizeof(struct icmpv6_opt_hdr) <= (((uint8_t*)(icmpv6_pkt)) + (icmpv6_len)); \
opt_hdr = (struct icmpv6_opt_hdr*)((uint8_t*)(opt_hdr) + (opt_hdr)->len) \
)
struct icmpv6_hdr {
uint8_t type;
uint8_t code;
uint16_t csum;
} __attribute__ ((packed));
struct icmpv6_echo_hdr {
struct icmpv6_hdr hdr;
uint16_t ident; /* Identifier */
uint16_t seq; /* Sequence number */
uint8_t data[0]; /* Data */
} __attribute__ ((packed));
/* RFC4861 Section 4.1 */
struct icmpv6_rsol_hdr {
struct icmpv6_hdr hdr;
uint32_t reserved;
uint8_t options[0];
} __attribute__ ((packed));
/* RFC4861 Section 4.2 */
struct icmpv6_radv_hdr {
struct icmpv6_hdr hdr;
uint8_t cur_ho_limit;
#if OSMO_IS_LITTLE_ENDIAN
uint8_t res:6,
m:1,
o:1;
#elif OSMO_IS_BIG_ENDIAN
/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */
uint8_t o:1, m:1, res:6;
#endif
uint16_t router_lifetime;
uint32_t reachable_time;
uint32_t retrans_timer;
uint8_t options[0];
} __attribute__ ((packed));
/* RFC4861 Section 4.6 */
struct icmpv6_opt_hdr {
uint8_t type;
/* length in units of 8 octets, including type+len! */
uint8_t len;
uint8_t data[0];
} __attribute__ ((packed));
/* RFC4861 Section 4.6.2 */
struct icmpv6_opt_prefix {
struct icmpv6_opt_hdr hdr;
uint8_t prefix_len;
#if OSMO_IS_LITTLE_ENDIAN
uint8_t res:6,
a:1,
l:1;
#elif OSMO_IS_BIG_ENDIAN
/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */
uint8_t l:1, a:1, res:6;
#endif
uint32_t valid_lifetime;
uint32_t preferred_lifetime;
uint32_t res2;
uint8_t prefix[16];
} __attribute__ ((packed));
/* RFC4861 Section 4.6.4 */
struct icmpv6_opt_mtu {
struct icmpv6_opt_hdr hdr;
uint16_t reserved;
uint32_t mtu;
} __attribute__ ((packed));
uint16_t icmpv6_prepend_ip6hdr(struct msgb *msg, const struct in6_addr *saddr,
const struct in6_addr *daddr);
struct msgb *icmpv6_construct_rs(const struct in6_addr *saddr);
int handle_router_mcast(struct gsn_t *gsn, struct pdp_t *pdp,
const struct in6_addr *pdp_prefix,
const struct in6_addr *own_ll_addr,
uint32_t mtu,
const uint8_t *pack, unsigned len);
int handle_solicited_node_mcast(const uint8_t *pack, unsigned len);
struct icmpv6_radv_hdr *icmpv6_validate_router_adv(const uint8_t *pack, unsigned len);
/* RFC3307 link-local scope multicast address */
extern const struct in6_addr all_router_mcast_addr;
extern const uint8_t solicited_node_mcast_addr_prefix[13];

View File

@@ -10,7 +10,7 @@
*/
#include "../lib/in46_addr.h"
#include "../gtp/pdp.h"
#include <osmocom/gtp/pdp.h>
#include <osmocom/core/utils.h>
@@ -60,7 +60,11 @@ int in46a_to_sas(struct sockaddr_storage *out, const struct in46_addr *in)
return 0;
}
/*! Convenience wrapper around inet_ntop() for \ref in46_addr */
/*! Convenience wrapper around inet_ntop() for in46_addr.
* \param[in] in the in46_addr to print
* \param[out] dst destination buffer where string representation of the address is stored
* \param[out] dst_size size dst. Usually it should be at least INET6_ADDRSTRLEN.
* \return address of dst on success, NULL on error */
const char *in46a_ntop(const struct in46_addr *in, char *dst, socklen_t dst_size)
{
int af;
@@ -371,3 +375,10 @@ default_to_dyn_v4:
dst->v4.s_addr = 0;
return 1;
}
void in46a_from_gsna(const struct ul16_t *in, struct in46_addr *dst)
{
dst->len = in->l;
OSMO_ASSERT(in->l <= sizeof(dst->v6));
memcpy(&dst->v6, in->v, in->l);
}

View File

@@ -2,7 +2,7 @@
#include <stdint.h>
#include <netinet/in.h>
#include "../gtp/pdp.h"
#include <osmocom/gtp/pdp.h>
/* a simple wrapper around an in6_addr to also contain the length of the address,
* thereby implicitly indicating the address family of the address */
@@ -31,3 +31,13 @@ unsigned int in46a_netmasklen(const struct in46_addr *netmask);
int in46a_to_eua(const struct in46_addr *src, unsigned int size, struct ul66_t *eua);
int in46a_from_eua(const struct ul66_t *eua, struct in46_addr *dst);
static inline bool in46a_is_v6(const struct in46_addr *addr) {
return addr->len == 8 || addr->len == 16;
}
static inline bool in46a_is_v4(const struct in46_addr *addr) {
return addr->len == sizeof(struct in_addr);
}
void in46a_from_gsna(const struct ul16_t *in, struct in46_addr *dst);

View File

@@ -26,16 +26,16 @@ int ippool_printaddr(struct ippool_t *this)
{
unsigned int n;
printf("ippool_printaddr\n");
printf("Firstdyn %d\n", this->firstdyn - this->member);
printf("Lastdyn %d\n", this->lastdyn - this->member);
printf("Firststat %d\n", this->firststat - this->member);
printf("Laststat %d\n", this->laststat - this->member);
printf("Listsize %d\n", this->listsize);
printf("Firstdyn %td\n", this->firstdyn - this->member);
printf("Lastdyn %td\n", this->lastdyn - this->member);
printf("Firststat %td\n", this->firststat - this->member);
printf("Laststat %td\n", this->laststat - this->member);
printf("Listsize %u\n", this->listsize);
for (n = 0; n < this->listsize; n++) {
char s[256];
in46a_ntop(&this->member[n].addr, s, sizeof(s));
printf("Unit %d inuse %d prev %d next %d addr %s\n",
printf("Unit %d inuse %d prev %td next %td addr %s\n",
n,
this->member[n].inuse,
this->member[n].prev - this->member,
@@ -202,7 +202,7 @@ int ippool_new(struct ippool_t **this, const struct in46_prefix *dyn, const stru
/* Parse only first instance of pool for now */
int i;
struct in46_addr addr;
struct in46_addr addr = { 0 };
size_t addrprefixlen;
struct in46_addr stataddr;
size_t stataddrprefixlen;
@@ -276,9 +276,8 @@ int ippool_new(struct ippool_t **this, const struct in46_prefix *dyn, const stru
(*this)->hashmask = (*this)->hashsize - 1;
/* Allocate hash table */
if (!
((*this)->hash =
calloc(sizeof(struct ippoolm_t), (*this)->hashsize))) {
(*this)->hash = calloc((*this)->hashsize, sizeof(struct ippoolm_t *));
if (!(*this)->hash) {
SYS_ERR(DIP, LOGL_ERROR, 0,
"Failed to allocate memory for hash members in ippool");
return -1;
@@ -513,7 +512,15 @@ int ippool_newip(struct ippool_t *this, struct ippoolm_t **member,
p2->next = NULL;
p2->prev = NULL;
p2->inuse = 2; /* Static address in use */
memcpy(&p2->addr, addr, sizeof(addr));
/* p2->addr.len and addr->len already match (see above). */
if (p2->addr.len == sizeof(struct in_addr))
p2->addr.v4 = addr->v4;
else if (p2->addr.len == sizeof(struct in6_addr))
p2->addr.v6 = addr->v6;
else {
SYS_ERR(DIP, LOGL_ERROR, 0, "MS requested unsupported PDP context type");
return -GTPCAUSE_UNKNOWN_PDP;
}
*member = p2;
(void)ippool_hashadd(this, *member);
if (0)

View File

@@ -13,7 +13,7 @@
#define _IPPOOL_H
#include "../lib/in46_addr.h"
#include "../gtp/gtp.h"
#include <osmocom/gtp/gtp.h>
/* Assuming that the address space is fragmented we need a hash table
in order to return the addresses.

284
lib/netdev.c Normal file
View File

@@ -0,0 +1,284 @@
/*
* TUN interface functions.
* Copyright (C) 2002, 2003, 2004 Mondru AB.
* Copyright (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
* notice and this permission notice is included in all copies or
* substantial portions of the software.
*
*/
/*
* netdev.c: Contains generic network device related functionality.
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <errno.h>
#include <net/route.h>
#include <net/if.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include "netdev.h"
#include "syserr.h"
#include <linux/ipv6.h>
static int netdev_route4(struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask, int delete)
{
int fd;
#if defined(__linux__)
struct rtentry r;
memset(&r, '\0', sizeof(r));
r.rt_flags = RTF_UP | RTF_GATEWAY; /* RTF_HOST not set */
/* Create a channel to the NET kernel. */
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
return -1;
}
r.rt_dst.sa_family = AF_INET;
r.rt_gateway.sa_family = AF_INET;
r.rt_genmask.sa_family = AF_INET;
memcpy(&((struct sockaddr_in *)&r.rt_dst)->sin_addr, dst, sizeof(*dst));
memcpy(&((struct sockaddr_in *)&r.rt_gateway)->sin_addr, gateway,
sizeof(*gateway));
memcpy(&((struct sockaddr_in *)&r.rt_genmask)->sin_addr, mask,
sizeof(*mask));
if (delete) {
if (ioctl(fd, SIOCDELRT, (void *)&r) < 0) {
SYS_ERR(DTUN, LOGL_ERROR, errno,
"ioctl(SIOCDELRT) failed");
close(fd);
return -1;
}
} else {
if (ioctl(fd, SIOCADDRT, (void *)&r) < 0) {
SYS_ERR(DTUN, LOGL_ERROR, errno,
"ioctl(SIOCADDRT) failed");
close(fd);
return -1;
}
}
#elif defined(__FreeBSD__) || defined (__APPLE__)
struct {
struct rt_msghdr rt;
struct sockaddr_in dst;
struct sockaddr_in gate;
struct sockaddr_in mask;
} req;
struct rt_msghdr *rtm;
if ((fd = socket(AF_ROUTE, SOCK_RAW, 0)) == -1) {
SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
return -1;
}
memset(&req, 0x00, sizeof(req));
rtm = &req.rt;
rtm->rtm_msglen = sizeof(req);
rtm->rtm_version = RTM_VERSION;
if (delete) {
rtm->rtm_type = RTM_DELETE;
} else {
rtm->rtm_type = RTM_ADD;
}
rtm->rtm_flags = RTF_UP | RTF_GATEWAY | RTF_STATIC; /* TODO */
rtm->rtm_addrs = RTA_DST | RTA_GATEWAY | RTA_NETMASK;
rtm->rtm_pid = getpid();
rtm->rtm_seq = 0044; /* TODO */
req.dst.sin_family = AF_INET;
req.dst.sin_len = sizeof(req.dst);
req.mask.sin_family = AF_INET;
req.mask.sin_len = sizeof(req.mask);
req.gate.sin_family = AF_INET;
req.gate.sin_len = sizeof(req.gate);
req.dst.sin_addr.s_addr = dst->s_addr;
req.mask.sin_addr.s_addr = mask->s_addr;
req.gate.sin_addr.s_addr = gateway->s_addr;
if (write(fd, rtm, rtm->rtm_msglen) < 0) {
SYS_ERR(DTUN, LOGL_ERROR, errno, "write() failed");
close(fd);
return -1;
}
#endif
close(fd);
return 0;
}
static int netdev_route6(struct in6_addr *dst, struct in6_addr *gateway, int prefixlen, const char *gw_iface, int delete)
{
int fd;
#if defined(__linux__)
struct in6_rtmsg r;
struct ifreq ifr;
memset(&r, 0, sizeof(r));
r.rtmsg_flags = RTF_UP | RTF_GATEWAY; /* RTF_HOST not set */
r.rtmsg_metric = 1;
/* Create a channel to the NET kernel. */
if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
return -1;
}
if (gw_iface) {
strncpy(ifr.ifr_name, gw_iface, IFNAMSIZ);
ifr.ifr_name[IFNAMSIZ - 1] = 0; /* Make sure to terminate */
if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
SYS_ERR(DTUN, LOGL_ERROR, errno,
"ioctl(SIOCGIFINDEX) failed");
close(fd);
return -1;
}
r.rtmsg_ifindex = ifr.ifr_ifindex;
}
memcpy(&r.rtmsg_dst, dst->s6_addr, sizeof(struct in6_addr));
memcpy(&r.rtmsg_gateway, gateway->s6_addr, sizeof(struct in6_addr));
r.rtmsg_dst_len = prefixlen;
if (delete) {
if (ioctl(fd, SIOCDELRT, (void *)&r) < 0) {
SYS_ERR(DTUN, LOGL_ERROR, errno,
"ioctl(SIOCDELRT) failed");
close(fd);
return -1;
}
} else {
if (ioctl(fd, SIOCADDRT, (void *)&r) < 0) {
SYS_ERR(DTUN, LOGL_ERROR, errno,
"ioctl(SIOCADDRT) failed");
close(fd);
return -1;
}
}
close(fd);
#endif
return 0;
}
int netdev_addroute4(struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask)
{
return netdev_route4(dst, gateway, mask, 0);
}
int netdev_delroute4(struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask)
{
return netdev_route4(dst, gateway, mask, 1);
}
int netdev_addroute6(struct in6_addr *dst, struct in6_addr *gateway, int prefixlen, const char *gw_iface)
{
return netdev_route6(dst, gateway, prefixlen, gw_iface, 0);
}
int netdev_delroute6(struct in6_addr *dst, struct in6_addr *gateway, int prefixlen, const char *gw_iface)
{
return netdev_route6(dst, gateway, prefixlen, gw_iface, 1);
}
#include <ifaddrs.h>
/*! Obtain the local address of a network device
* \param[in] devname Target device owning the IP
* \param[out] prefix_list List of prefix structures to fill with each IPv4/6 and prefix length found.
* \param[in] prefix_size Amount of elements allowed to be fill in the prefix_list array.
* \param[in] flags Specify which kind of IP to look for: IP_TYPE_IPv4, IP_TYPE_IPv6_LINK, IP_TYPE_IPv6_NONLINK
* \returns The number of ips found following the criteria specified by flags, -1 on error.
*
* This function will fill prefix_list with up to prefix_size IPs following the
* criteria specified by flags parameter. It returns the number of IPs matching
* the criteria. As a result, the number returned can be bigger than
* prefix_size. It can be used with prefix_size=0 to get an estimate of the size
* needed for prefix_list.
*/
int netdev_ip_local_get(const char *devname, struct in46_prefix *prefix_list, size_t prefix_size, int flags)
{
static const uint8_t ll_prefix[] = { 0xfe,0x80, 0,0, 0,0, 0,0 };
struct ifaddrs *ifaddr, *ifa;
struct in46_addr netmask;
size_t count = 0;
bool is_ipv6_ll;
if (getifaddrs(&ifaddr) == -1) {
return -1;
}
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr == NULL)
continue;
if (strcmp(ifa->ifa_name, devname))
continue;
if (ifa->ifa_addr->sa_family == AF_INET && (flags & IP_TYPE_IPv4)) {
struct sockaddr_in *sin4 = (struct sockaddr_in *) ifa->ifa_addr;
struct sockaddr_in *netmask4 = (struct sockaddr_in *) ifa->ifa_netmask;
if (count < prefix_size) {
netmask.len = sizeof(netmask4->sin_addr);
netmask.v4 = netmask4->sin_addr;
prefix_list[count].addr.len = sizeof(sin4->sin_addr);
prefix_list[count].addr.v4 = sin4->sin_addr;
prefix_list[count].prefixlen = in46a_netmasklen(&netmask);
}
count++;
}
if (ifa->ifa_addr->sa_family == AF_INET6 && (flags & IP_TYPE_IPv6)) {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) ifa->ifa_addr;
struct sockaddr_in6 *netmask6 = (struct sockaddr_in6 *) ifa->ifa_netmask;
is_ipv6_ll = !memcmp(sin6->sin6_addr.s6_addr, ll_prefix, sizeof(ll_prefix));
if ((flags & IP_TYPE_IPv6_NONLINK) && is_ipv6_ll)
continue;
if ((flags & IP_TYPE_IPv6_LINK) && !is_ipv6_ll)
continue;
if (count < prefix_size) {
netmask.len = sizeof(netmask6->sin6_addr);
netmask.v6 = netmask6->sin6_addr;
prefix_list[count].addr.len = sizeof(sin6->sin6_addr);
prefix_list[count].addr.v6 = sin6->sin6_addr;
prefix_list[count].prefixlen = in46a_netmasklen(&netmask);
}
count++;
}
}
freeifaddrs(ifaddr);
return count;
}

62
lib/netdev.h Normal file
View File

@@ -0,0 +1,62 @@
#pragma once
/*
* TUN interface functions.
* Copyright (C) 2002, 2003 Mondru AB.
* Copyright (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
* notice and this permission notice is included in all copies or
* substantial portions of the software.
*
*/
#include <net/if.h>
#include "../lib/in46_addr.h"
#define TUN_NLBUFSIZE 1024
#include "config.h"
/* ipv6 ip type flags for tun_ipv6_local_get() */
enum {
IP_TYPE_IPv4 = 1,
IP_TYPE_IPv6_LINK = 2,
IP_TYPE_IPv6_NONLINK = 4,
};
#define IP_TYPE_IPv6 (IP_TYPE_IPv6_LINK | IP_TYPE_IPv6_NONLINK)
#ifndef HAVE_IPHDR
struct iphdr
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned int ihl:4;
unsigned int version:4;
#elif __BYTE_ORDER == __BIG_ENDIAN
unsigned int version:4;
unsigned int ihl:4;
#else
# error "Please fix <bits/endian.h>"
#endif
u_int8_t tos;
u_int16_t tot_len;
u_int16_t id;
u_int16_t frag_off;
u_int8_t ttl;
u_int8_t protocol;
u_int16_t check;
u_int32_t saddr;
u_int32_t daddr;
/*The options start here. */
};
#endif /* !HAVE_IPHDR */
extern int netdev_addroute4(struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask);
extern int netdev_delroute4(struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask);
extern int netdev_addroute6(struct in6_addr *dst, struct in6_addr *gateway, int prefixlen, const char *gw_iface);
extern int netdev_delroute6(struct in6_addr *dst, struct in6_addr *gateway, int prefixlen, const char *gw_iface);
extern int netdev_ip_local_get(const char *devname, struct in46_prefix *prefix_list,
size_t prefix_size, int flags);

272
lib/netns.c Normal file
View File

@@ -0,0 +1,272 @@
/*
* Copyright (C) 2014-2017, Travelping GmbH <info@travelping.com>
* Copyright (C) 2020, Harald Welte <laforge@gnumonks.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#if defined(__linux__)
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/mount.h>
#include <sys/param.h>
#include <fcntl.h>
#include <errno.h>
#include <osmocom/core/utils.h>
#include "netns.h"
#define NETNS_PATH "/var/run/netns"
/*! default namespace of the GGSN process */
static int default_nsfd = -1;
/*! switch to a (non-default) namespace, store existing signal mask in oldmask.
* \param[in] nsfd file descriptor representing the namespace to whch we shall switch
* \param[out] oldmask caller-provided memory location to which old signal mask is stored
* \ returns 0 on success or negative (errno) in case of error */
int switch_ns(int nsfd, sigset_t *oldmask)
{
sigset_t intmask;
int rc;
OSMO_ASSERT(default_nsfd >= 0);
if (sigfillset(&intmask) < 0)
return -errno;
if ((rc = sigprocmask(SIG_BLOCK, &intmask, oldmask)) != 0)
return -rc;
if (setns(nsfd, CLONE_NEWNET) < 0) {
/* restore old mask if we couldn't switch the netns */
sigprocmask(SIG_SETMASK, oldmask, NULL);
return -errno;
}
return 0;
}
/*! switch back to the default namespace, restoring signal mask.
* \param[in] oldmask signal mask to restore after returning to default namespace
* \returns 0 on successs; negative errno value in case of error */
int restore_ns(sigset_t *oldmask)
{
OSMO_ASSERT(default_nsfd >= 0);
int rc;
if (setns(default_nsfd, CLONE_NEWNET) < 0)
return -errno;
if ((rc = sigprocmask(SIG_SETMASK, oldmask, NULL)) != 0)
return -rc;
return 0;
}
/*! open a file from within specified network namespace */
int open_ns(int nsfd, const char *pathname, int flags)
{
sigset_t intmask, oldmask;
int ret;
int fd = -1;
int rc;
OSMO_ASSERT(default_nsfd >= 0);
/* mask off all signals, store old signal mask */
if (sigfillset(&intmask) < 0)
return -errno;
if ((rc = sigprocmask(SIG_BLOCK, &intmask, &oldmask)) != 0)
return -rc;
/* associate the calling thread with namespace file descriptor */
if (setns(nsfd, CLONE_NEWNET) < 0) {
ret = -errno;
goto restore_sigmask;
}
/* open the requested file/path */
if ((fd = open(pathname, flags)) < 0) {
ret = -errno;
goto restore_defaultns;
}
ret = fd;
restore_defaultns:
/* return back to default namespace */
if (setns(default_nsfd, CLONE_NEWNET) < 0) {
if (fd >= 0)
close(fd);
return -errno;
}
restore_sigmask:
/* restore process mask */
if ((rc = sigprocmask(SIG_SETMASK, &oldmask, NULL)) != 0) {
if (fd >= 0)
close(fd);
return -rc;
}
return ret;
}
/*! create a socket in another namespace.
* Switches temporarily to namespace indicated by nsfd, creates a socket in
* that namespace and then returns to the default namespace.
* \param[in] nsfd File descriptor of the namspace in which to create socket
* \param[in] domain Domain of the socket (AF_INET, ...)
* \param[in] type Type of the socket (SOCK_STREAM, ...)
* \param[in] protocol Protocol of the socket (IPPROTO_TCP, ...)
* \returns 0 on success; negative errno in case of error */
int socket_ns(int nsfd, int domain, int type, int protocol)
{
sigset_t intmask, oldmask;
int ret;
int sk = -1;
int rc;
OSMO_ASSERT(default_nsfd >= 0);
/* mask off all signals, store old signal mask */
if (sigfillset(&intmask) < 0)
return -errno;
if ((rc = sigprocmask(SIG_BLOCK, &intmask, &oldmask)) != 0)
return -rc;
/* associate the calling thread with namespace file descriptor */
if (setns(nsfd, CLONE_NEWNET) < 0) {
ret = -errno;
goto restore_sigmask;
}
/* create socket of requested domain/type/proto */
if ((sk = socket(domain, type, protocol)) < 0) {
ret = -errno;
goto restore_defaultns;
}
ret = sk;
restore_defaultns:
/* return back to default namespace */
if (setns(default_nsfd, CLONE_NEWNET) < 0) {
if (sk >= 0)
close(sk);
return -errno;
}
restore_sigmask:
/* restore process mask */
if ((rc = sigprocmask(SIG_SETMASK, &oldmask, NULL)) != 0) {
if (sk >= 0)
close(sk);
return -rc;
}
return ret;
}
/*! initialize this network namespace helper module.
* Must be called before using any other functions of this file.
* \returns 0 on success; negative errno in case of error */
int init_netns()
{
/* store the default namespace for later reference */
if ((default_nsfd = open("/proc/self/ns/net", O_RDONLY)) < 0)
return -errno;
return 0;
}
/*! create obtain file descriptor for network namespace of give name.
* Creates /var/run/netns if it doesn't exist already.
* \param[in] name Name of the network namespace (in /var/run/netns/)
* \returns File descriptor of network namespace; negative errno in case of error */
int get_nsfd(const char *name)
{
int ret = 0;
int rc;
int fd;
sigset_t intmask, oldmask;
char path[MAXPATHLEN] = NETNS_PATH;
OSMO_ASSERT(default_nsfd >= 0);
/* create /var/run/netns, if it doesn't exist already */
rc = mkdir(path, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
if (rc < 0 && errno != EEXIST)
return rc;
/* create /var/run/netns/[name], if it doesn't exist already */
snprintf(path, sizeof(path), "%s/%s", NETNS_PATH, name);
fd = open(path, O_RDONLY|O_CREAT|O_EXCL, 0);
if (fd < 0) {
if (errno == EEXIST) {
if ((fd = open(path, O_RDONLY)) < 0)
return -errno;
return fd;
}
return -errno;
}
if (close(fd) < 0)
return -errno;
/* mask off all signals, store old signal mask */
if (sigfillset(&intmask) < 0)
return -errno;
if ((rc = sigprocmask(SIG_BLOCK, &intmask, &oldmask)) != 0)
return -rc;
/* create a new network namespace */
if (unshare(CLONE_NEWNET) < 0) {
ret = -errno;
goto restore_sigmask;
}
if (mount("/proc/self/ns/net", path, "none", MS_BIND, NULL) < 0)
ret = -errno;
/* switch back to default namespace */
if (setns(default_nsfd, CLONE_NEWNET) < 0)
return -errno;
restore_sigmask:
/* restore process mask */
if ((rc = sigprocmask(SIG_SETMASK, &oldmask, NULL)) != 0)
return -rc;
/* might have been set above in case mount fails */
if (ret < 0)
return ret;
/* finally, open the created namespace file descriptor from default ns */
if ((fd = open(path, O_RDONLY)) < 0)
return -errno;
return fd;
}
#endif

35
lib/netns.h Normal file
View File

@@ -0,0 +1,35 @@
/*
* Copyright (C) 2014-2017, Travelping GmbH <info@travelping.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __NETNS_H
#define __NETNS_H
#if defined(__linux__)
int init_netns(void);
int switch_ns(int nsfd, sigset_t *oldmask);
int restore_ns(sigset_t *oldmask);
int open_ns(int nsfd, const char *pathname, int flags);
int socket_ns(int nsfd, int domain, int type, int protocol);
int get_nsfd(const char *name);
#endif
#endif

1020
lib/tun.c

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
/*
* TUN interface functions.
* Copyright (C) 2002, 2003 Mondru AB.
* Copyright (C) 2017 by Harald Welte <laforge@gnumonks.org>
* Copyright (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
@@ -13,81 +13,49 @@
#ifndef _TUN_H
#define _TUN_H
#include <stdbool.h>
#include <net/if.h>
#include <osmocom/core/netdev.h>
#include <osmocom/core/tun.h>
#include "../lib/in46_addr.h"
#define PACKET_MAX 8196 /* Maximum packet size we receive */
#define TUN_SCRIPTSIZE 256
#define TUN_ADDRSIZE 128
#define TUN_NLBUFSIZE 1024
#include "config.h"
/* ipv6 ip type flags for tun_ipv6_local_get() */
enum {
IP_TYPE_IPv4 = 1,
IP_TYPE_IPv6_LINK = 2,
IP_TYPE_IPv6_NONLINK = 4,
};
#define IP_TYPE_IPv6 (IP_TYPE_IPv6_LINK | IP_TYPE_IPv6_NONLINK)
#ifndef HAVE_IPHDR
struct iphdr
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned int ihl:4;
unsigned int version:4;
#elif __BYTE_ORDER == __BIG_ENDIAN
unsigned int version:4;
unsigned int ihl:4;
#else
# error "Please fix <bits/endian.h>"
#endif
u_int8_t tos;
u_int16_t tot_len;
u_int16_t id;
u_int16_t frag_off;
u_int8_t ttl;
u_int8_t protocol;
u_int16_t check;
u_int32_t saddr;
u_int32_t daddr;
/*The options start here. */
};
#endif /* !HAVE_IPHDR */
#include "netdev.h"
/* ***********************************************************
* Information storage for each tun instance
*************************************************************/
struct tun_t {
int fd; /* File descriptor to tun interface */
struct in_addr addr;
struct in_addr dstaddr;
/* In tun device mode: operates on the tun interface, owned by tun.tundev below.
* In gtp kernel mode: operates on the gtp device, allocated explicitly */
struct osmo_netdev *netdev;
struct in46_addr addr;
struct in_addr netmask;
int addrs; /* Number of allocated IP addresses */
int routes; /* One if we allocated an automatic route */
char devname[IFNAMSIZ]; /* Name of the tun device */
int (*cb_ind) (struct tun_t * tun, void *pack, unsigned len);
/* to be used by libgtp callers/users (to attach their own private state) */
void *priv;
/* Fields only in use when using the tun device mode: */
struct {
struct osmo_tundev *tundev; /* Manages the tun interface; NULL on gtp kernel mode */
int fd; /* File descriptor to tun interface; -1 on gtp kernel mode */
} tundev;
};
extern int tun_new(struct tun_t **tun, const char *dev_name);
extern struct tun_t *tun_alloc_tundev(const char *devname);
extern struct tun_t *tun_alloc_gtpdev(const char *devname, int fd0, int fd1u);
extern int tun_free(struct tun_t *tun);
extern int tun_decaps(struct tun_t *this);
extern int tun_encaps(struct tun_t *tun, void *pack, unsigned len);
extern int tun_inject_pkt(struct tun_t *tun, void *pack, unsigned len);
extern int tun_addaddr(struct tun_t *this, struct in46_addr *addr,
struct in46_addr *dstaddr, size_t prefixlen);
extern int tun_setaddr(struct tun_t *this, struct in46_addr *our_adr,
struct in46_addr *his_adr, size_t prefixlen);
int tun_addroute(struct tun_t *this, struct in_addr *dst,
struct in_addr *gateway, struct in_addr *mask);
extern int tun_addaddr(struct tun_t *this, struct in46_addr *addr, size_t prefixlen);
extern int tun_set_cb_ind(struct tun_t *this,
int (*cb_ind) (struct tun_t * tun, void *pack,
@@ -95,10 +63,10 @@ extern int tun_set_cb_ind(struct tun_t *this,
extern int tun_runscript(struct tun_t *tun, char *script);
int netdev_ip_local_get(const char *devname, struct in46_prefix *prefix_list,
size_t prefix_size, int flags);
int tun_ip_local_get(const struct tun_t *tun, struct in46_prefix *prefix_list,
size_t prefix_size, int flags);
#define LOGTUN(level, tun, fmt, args...) \
LOGP(DTUN, level, "TUN(%s): " fmt, (tun)->devname, ## args)
#endif /* !_TUN_H */

35
lib/util.c Normal file
View File

@@ -0,0 +1,35 @@
/*
* misc helpers
* Copyright 2019 sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
* notice and this permission notice is included in all copies or
* substantial portions of the software.
*
*/
#include <osmocom/gtp/pdp.h>
#include "ippool.h"
#include "in46_addr.h"
/*! Get the peer of pdp based on IP version used.
* \param[in] pdp PDP context to select the peer from.
* \param[in] v4v6 IP version to select. Valid values are 4 and 6.
* \returns The selected peer matching the given IP version. NULL if not present.
*/
struct ippoolm_t *pdp_get_peer_ipv(struct pdp_t *pdp, bool is_ipv6) {
uint8_t i;
for (i = 0; i < 2; i++) {
struct ippoolm_t * ippool = pdp->peer[i];
if (!ippool)
continue;
if (is_ipv6 && in46a_is_v6(&ippool->addr))
return ippool;
else if (!is_ipv6 && in46a_is_v4(&ippool->addr))
return ippool;
}
return NULL;
}

18
lib/util.h Normal file
View File

@@ -0,0 +1,18 @@
#pragma once
/*
* misc helpers
* Copyright 2019 sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
*
* The contents of this file may be used under the terms of the GNU
* General Public License Version 2, provided that the above copyright
* notice and this permission notice is included in all copies or
* substantial portions of the software.
*
*/
#include <stdbool.h>
struct ippoolm_t;
struct pdp_t;
struct ippoolm_t *pdp_get_peer_ipv(struct pdp_t *pdp, bool is_ipv6);

View File

@@ -7,5 +7,8 @@ Name: OsmoGGSN GTP Library
Description: C Utility Library
Version: @VERSION@
Libs: -L${libdir} -lgtp
Cflags: -I${includedir}/
# Add two include paths to support:
# * #include <osmocom/gtp/gtp.h> (like other Osmocom headers)
# * #include <gtp.h> (legacy compat)
Cflags: -I${includedir}/osmocom/gtp/ -I${includedir}/

View File

@@ -1,90 +0,0 @@
Summary: Osmocom Gateway GPRS Support Node (GGSN)
Name: @PACKAGE@
Version: @VERSION@
Release: 1
URL: https://osmocom.org/projects/openggsn
Source0: http://prdownloads.sourceforge.net/ggsn/%{name}-%{version}.tar.gz
License: GPL
Group: System Environment/Daemons
BuildRoot: %{_tmppath}/%{name}-root
%description
OsmoGGSN is a Gateway GPRS Support Node (GGSN). It is used by mobile
operators as the interface between the Internet and the rest of the
mobile network infrastructure. The project also provides an SGSN
emulator suitable for GPRS core network testing.
%prep
%setup -q
%build
./configure --prefix=/usr --enable-static-exec
make
%install
make install prefix=$RPM_BUILD_ROOT/usr
strip $RPM_BUILD_ROOT/usr/bin/osmo-ggsn
strip $RPM_BUILD_ROOT/usr/bin/sgsnemu
#Copy osmo-ggsn init script in place
mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d
install -m755 examples/osmo-ggsn.init \
$RPM_BUILD_ROOT/etc/rc.d/init.d/osmo-ggsn
#Copy osmo-ggsn.conf in place
install -m755 examples/osmo-ggsn.cfg \
$RPM_BUILD_ROOT/etc/osmo-ggsn.cfg
#Copy gsn_restart file in place
mkdir -p $RPM_BUILD_ROOT/var/lib/osmo-ggsn
echo "0" > $RPM_BUILD_ROOT/var/lib/osmo-ggsn/gsn_restart
#Clean up unwanted library files
rm -rf $RPM_BUILD_ROOT/usr/include/*
rm -rf $RPM_BUILD_ROOT/usr/lib/*
%clean
rm -rf $RPM_BUILD_ROOT
make clean
%post
/sbin/chkconfig --add osmo-ggsn
%files
%defattr(-,root,root)
/usr/bin/osmo-ggsn
/usr/bin/sgsnemu
/etc/rc.d/init.d/osmo-ggsn
%dir /var/lib/osmo-ggsn
/var/lib/osmo-ggsn/gsn_restart
%doc AUTHORS COPYING INSTALL NEWS README.md
%doc examples/osmo-ggsn.conf
%doc examples/sgsnemu.conf
%doc examples/osmo-ggsn.init
%doc examples/firewall
%doc /usr/man/man8/osmo-ggsn.8.gz
%doc /usr/man/man8/sgsnemu.8.gz
%config /etc/osmo-ggsn.cfg
#/usr/lib/libgtp.a
#/usr/lib/libgtp.la
#/usr/lib/libgtp.so
#/usr/lib/libgtp.so.0
#/usr/lib/libgtp.so.0.0.0
%changelog
* Mon Jun 30 2017 <laforge@gnumonks.org>
- Update to OsmoGGSN
* Mon Jun 30 2003 <jj@openggsn.org>
- Initial build.

View File

@@ -2,8 +2,24 @@ bin_PROGRAMS = sgsnemu
AM_LDFLAGS = @EXEC_LDFLAGS@
AM_CFLAGS = -O2 -D_GNU_SOURCE -fno-builtin -Wall -DSBINDIR='"$(sbindir)"' -ggdb $(LIBOSMOCORE_CFLAGS)
AM_CFLAGS = \
-D_GNU_SOURCE \
-fno-builtin \
-Wall \
-DSBINDIR='"$(sbindir)"' \
-I$(top_srcdir)/include \
$(LIBOSMOCORE_CFLAGS) \
$(NULL)
sgsnemu_LDADD = @EXEC_LDADD@ -lgtp -L../gtp ../lib/libmisc.a $(LIBOSMOCORE_LIBS)
if ENABLE_GTP_KERNEL
AM_CFLAGS += \
-DGTP_KERNEL \
$(LIBGTPNL_CFLAGS) \
$(NULL)
sgsnemu_LDADD += $(LIBGTPNL_LIBS)
endif
sgsnemu_DEPENDENCIES = ../gtp/libgtp.la ../lib/libmisc.a
sgsnemu_SOURCES = sgsnemu.c cmdline.c cmdline.h

View File

@@ -72,6 +72,7 @@ const char *gengetopt_args_info_help[] = {
" --ipup=STRING Script to run after link-up",
" --ipdown=STRING Script to run after link-down",
" --tun-device=STRING Name of the local network interface",
" --netns=STRING Network namespace to use",
"\n Mode: pinghost\n generate ICMP payload inside G-PDU without setting up tun interface",
" --pinghost=STRING Ping remote host",
" --pingrate=INT Number of ping req per second (default=`1')",
@@ -163,6 +164,7 @@ void clear_given(struct gengetopt_args_info *args_info)
args_info->ipup_given = 0;
args_info->ipdown_given = 0;
args_info->tun_device_given = 0;
args_info->netns_given = 0;
args_info->pinghost_given = 0;
args_info->pingrate_given = 0;
args_info->pingsize_given = 0;
@@ -244,6 +246,8 @@ void clear_args(struct gengetopt_args_info *args_info)
args_info->ipdown_orig = NULL;
args_info->tun_device_arg = NULL;
args_info->tun_device_orig = NULL;
args_info->netns_arg = NULL;
args_info->netns_orig = NULL;
args_info->pinghost_arg = NULL;
args_info->pinghost_orig = NULL;
args_info->pingrate_arg = 1;
@@ -300,13 +304,14 @@ void init_args_info(struct gengetopt_args_info *args_info)
args_info->ipup_help = gengetopt_args_info_help[35];
args_info->ipdown_help = gengetopt_args_info_help[36];
args_info->tun_device_help = gengetopt_args_info_help[37];
args_info->pinghost_help = gengetopt_args_info_help[39];
args_info->pingrate_help = gengetopt_args_info_help[40];
args_info->pingsize_help = gengetopt_args_info_help[41];
args_info->pingcount_help = gengetopt_args_info_help[42];
args_info->pingquiet_help = gengetopt_args_info_help[43];
args_info->no_tx_gpdu_seq_help = gengetopt_args_info_help[44];
args_info->pdp_type_help = gengetopt_args_info_help[45];
args_info->netns_help = gengetopt_args_info_help[38];
args_info->pinghost_help = gengetopt_args_info_help[40];
args_info->pingrate_help = gengetopt_args_info_help[41];
args_info->pingsize_help = gengetopt_args_info_help[42];
args_info->pingcount_help = gengetopt_args_info_help[43];
args_info->pingquiet_help = gengetopt_args_info_help[44];
args_info->no_tx_gpdu_seq_help = gengetopt_args_info_help[45];
args_info->pdp_type_help = gengetopt_args_info_help[46];
}
@@ -363,14 +368,6 @@ void cmdline_parser_params_init(struct cmdline_parser_params *params)
}
}
struct cmdline_parser_params *cmdline_parser_params_create(void)
{
struct cmdline_parser_params *params = (struct cmdline_parser_params *)
malloc(sizeof(struct cmdline_parser_params));
cmdline_parser_params_init(params);
return params;
}
static void free_string_field(char **s)
{
if (*s) {
@@ -432,6 +429,8 @@ static void cmdline_parser_release(struct gengetopt_args_info *args_info)
free_string_field(&(args_info->ipdown_orig));
free_string_field(&(args_info->tun_device_arg));
free_string_field(&(args_info->tun_device_orig));
free_string_field(&(args_info->netns_arg));
free_string_field(&(args_info->netns_orig));
free_string_field(&(args_info->pinghost_arg));
free_string_field(&(args_info->pinghost_orig));
free_string_field(&(args_info->pingrate_orig));
@@ -545,6 +544,8 @@ int cmdline_parser_dump(FILE * outfile, struct gengetopt_args_info *args_info)
if (args_info->tun_device_given)
write_into_file(outfile, "tun-device",
args_info->tun_device_orig, 0);
if (args_info->netns_given)
write_into_file(outfile, "netns", args_info->netns_orig, 0);
if (args_info->pinghost_given)
write_into_file(outfile, "pinghost", args_info->pinghost_orig,
0);
@@ -709,6 +710,12 @@ cmdline_parser_required2(struct gengetopt_args_info *args_info,
prog_name, (additional_error ? additional_error : ""));
error_occurred = 1;
}
if (args_info->netns_given && !args_info->createif_given) {
fprintf(stderr,
"%s: '--netns' option depends on option 'createif'%s\n",
prog_name, (additional_error ? additional_error : ""));
error_occurred = 1;
}
if (args_info->pingrate_given && !args_info->pinghost_given) {
fprintf(stderr,
"%s: '--pingrate' option depends on option 'pinghost'%s\n",
@@ -954,6 +961,7 @@ cmdline_parser_internal(int argc, char **argv,
{"ipup", 1, NULL, 0},
{"ipdown", 1, NULL, 0},
{"tun-device", 1, NULL, 0},
{"netns", 1, NULL, 0},
{"pinghost", 1, NULL, 0},
{"pingrate", 1, NULL, 0},
{"pingsize", 1, NULL, 0},
@@ -1493,6 +1501,22 @@ cmdline_parser_internal(int argc, char **argv,
additional_error))
goto failure;
}
/* Network namespace to use. */
else if (strcmp
(long_options[option_index].name,
"netns") == 0) {
args_info->createif_mode_counter += 1;
if (update_arg((void *)&(args_info->netns_arg),
&(args_info->netns_orig),
&(args_info->netns_given),
&(local_args_info.netns_given),
optarg, 0, 0, ARG_STRING,
check_ambiguity, override, 0, 0,
"netns", '-', additional_error))
goto failure;
}
/* Ping remote host. */
else if (strcmp
@@ -1609,11 +1633,12 @@ cmdline_parser_internal(int argc, char **argv,
int createif_given[] =
{ args_info->createif_given, args_info->net_given,
args_info->defaultroute_given, args_info->ipup_given,
args_info->ipdown_given, args_info->tun_device_given, -1
args_info->ipdown_given, args_info->tun_device_given,
args_info->netns_given, -1
};
const char *createif_desc[] =
{ "--createif", "--net", "--defaultroute", "--ipup",
"--ipdown", "--tun-device", 0
"--ipdown", "--tun-device", "--netns", 0
};
int pinghost_given[] =
{ args_info->pinghost_given, args_info->pingrate_given,

View File

@@ -59,6 +59,7 @@ modeoption "defaultroute" - "Create default route" flag dependon="
modeoption "ipup" - "Script to run after link-up" string dependon="createif" no mode="createif"
modeoption "ipdown" - "Script to run after link-down" string dependon="createif" no mode="createif"
modeoption "tun-device" - "Name of the local network interface" string dependon="createif" no mode="createif"
modeoption "netns" - "Network namespace to use" string dependon="createif" no mode="createif"
modeoption "pinghost" - "Ping remote host" string no mode="pinghost"
modeoption "pingrate" - "Number of ping req per second" int default="1" dependon="pinghost" no mode="pinghost"

View File

@@ -242,6 +242,12 @@ extern "C" {
/**< @brief Name of the local network interface original value given at command line. */
const char *tun_device_help;
/**< @brief Name of the local network interface help description. */
char *netns_arg;
/**< @brief Network namespace to use. */
char *netns_orig;
/**< @brief Network namespace to use original value given at command line. */
const char *netns_help;
/**< @brief Network namespace to use help description. */
char *pinghost_arg;
/**< @brief Ping remote host. */
char *pinghost_orig;
@@ -355,6 +361,8 @@ extern "C" {
/**< @brief Whether ipdown was given. */
unsigned int tun_device_given;
/**< @brief Whether tun-device was given. */
unsigned int netns_given;
/**< @brief Whether netns was given. */
unsigned int pinghost_given;
/**< @brief Whether pinghost was given. */
unsigned int pingrate_given;
@@ -471,13 +479,6 @@ extern "C" {
*/
void cmdline_parser_params_init(struct cmdline_parser_params *params);
/**
* Allocates dynamically a cmdline_parser_params structure and initializes
* all its fields to their default values
* @return the created and initialized cmdline_parser_params structure
*/
struct cmdline_parser_params *cmdline_parser_params_create(void);
/**
* Initializes the passed gengetopt_args_info structure's fields
* (also set default values for options that have a default)

File diff suppressed because it is too large Load Diff

View File

@@ -1,19 +1,36 @@
AM_CFLAGS = -Wall -I$(top_srcdir)/include $(LIBOSMOCORE_CFLAGS) -g
AM_CFLAGS = \
-Wall \
-I$(top_srcdir)/include \
$(LIBOSMOCORE_CFLAGS) \
$(NULL)
AM_LDFLAGS = -no-install
EXTRA_DIST = \
gtpie_test.ok \
queue_test.ok \
$(NULL)
noinst_PROGRAMS = \
check_PROGRAMS = \
gtpie_test \
queue_test \
$(NULL)
gtpie_test_SOURCES = \
gtpie_test.c \
$(NULL)
queue_test_SOURCES = \
queue_test.c \
$(NULL)
gtpie_test_LDADD = \
$(top_builddir)/lib/debug.o \
$(top_builddir)/gtp/libgtp.la \
$(LIBOSMOCORE_LIBS) \
$(NULL)
queue_test_LDADD = \
$(top_builddir)/lib/debug.o \
$(top_builddir)/gtp/libgtp.la \
$(LIBOSMOCORE_LIBS) \
$(NULL)

View File

@@ -10,8 +10,9 @@
#include <osmocom/core/msgb.h>
#include <osmocom/core/bits.h>
#include <osmocom/gtp/gtpie.h>
#include "../../lib/syserr.h"
#include "../../gtp/gtpie.h"
static const uint8_t in[] = { 1,2,3,4,5,6 };
static uint8_t buf[256];
@@ -113,7 +114,7 @@ int main(int argc, char **argv)
msgb_talloc_ctx_init(tall_ctx, 0);
osmo_init_logging2(tall_ctx, &log_info);
log_set_use_color(osmo_stderr_target, 0);
log_set_print_filename(osmo_stderr_target, 0);
log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
srand(time(NULL));

Some files were not shown because too many files have changed in this diff Show More