Commit Graph

136 Commits

Author SHA1 Message Date
Pau Espin 4b9b19e998 ggsn: Improve logging on incoming DL data packets
Change-Id: I3617c8f68d8f18617871c070e28cc6ae5c6a925b
2021-04-22 16:24:55 +02: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 1719abb409 Use OSMO_FD_* instead of deprecated BSC_FD_*
Change-Id: Ib660cbbeafd8f4077c693d53127ecd1c15455455
2020-10-18 22:38:20 +02:00
Pau Espin 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 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 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 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 3eb05d2c1a cosmetic: fix formatting in if line
Fixes: eefa30dce8
Fixes: 2d6a69e69a
Change-Id: I9ee5f4142cacf912145693c72a53c0f531bad2c6
2019-08-28 11:34:51 +02:00
Pau Espin 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 012d51ed7d Introduce LOGTUN log helper
Change-Id: I237acdee0be19498804e0d509c610f4e0454ba72
2019-08-28 11:14:57 +02:00
Pau Espin 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 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 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 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 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 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 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 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
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 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
Pau Espin 72ab4bc547 ggsn: Drop unused param force in apn_stop()
Change-Id: I920679c7062d480c1cfaa3d89c90a0ed4a2ef58b
2019-05-29 19:09:02 +02: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
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
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 3e0baa6146 ggsn: ctrl iface: listen on IP configured by VTY
Previosuly, the CTRL iface of osmo-ggsn was always bound to 127.0.0.1

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

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

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

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

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

Change-Id: Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5
Related: OS#3288
2018-05-28 17:48:19 +02:00
Harald Welte 546884d9a1 ggsn: don't use gtp_kernel_tunnel_{add,del}() for userspace tun
Change-Id: I00cc8eb8c4d44532f975f78783ff4e12814b3416
2018-04-25 21:44:50 +02:00
Harald Welte f2286395e9 Move kernel GTP support from ggsn/ to lib/
This way, the IP address / route handling between TUN devices and kernel
GTP can be shared, which will provide not only a unified codebase but
also a more consistent behavior.

This also paves the road for to use kernel GTP from sgsnemu in the future.

Related: OS#3214
Change-Id: Ic53a971136edd0d8871fbd6746d7b0090ce3a188
2018-04-25 21:44:46 +02:00
Harald Welte db0366c9e4 ggsn: Don't explicitly use tun_setaddr() API anymore
tun_addaddr() internally contains a fallback to tun_setaddr() for the
first address, so we can unify the API usage a bit and use tun_addaddr()
from all call sites

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

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

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

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

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

Change-Id: Ie658a7f161103bb6f631ab0508e45e55fb42a442
2018-01-26 18:20:22 +00:00