Commit Graph

4235 Commits

Author SHA1 Message Date
Pau Espin f5b8ed14a9 ctrl: Pre-calculate required size before allocating msgb
This commit fixes crash when response is more than ~4096 chars.
Furthermore, we now allocate only the required memory, not 4096 for all
messages, which usually don't require it.
Test needs to be adapted since it assumed there was more available space
at the end of the msgb.

Related: OS#5169
Change-Id: I0b8f370f7b08736207f9efed13a0663b5e482824
2021-06-15 16:29:44 +00:00
Alexander Couzens 68ab9c4193 gprs_ns2_sns: bss: set gss->family
gss->family (and gss->ip) was never set.
So IPv6 should have never worked.

Fixes: e769f5226b ("gprs_ns2_sns: rework IP-SNS initial remote")
Related: OS#5036
Change-Id: I4e39dc5c7f766a7040645ceb62afdf6a9cfad00f
2021-06-13 18:31:51 +00:00
Alexander Couzens 077ce5ac94 gprs_ns2_sns: replace ns2_sns_type with address family
Reduces the code as the conversion between address family (bind)
and ns2_sns_type is not needed anymore.

Related: OS#5036
Change-Id: I1bcdd43af34c926d4b88491d00669422c299bef7
2021-06-13 18:31:51 +00:00
Alexander Couzens 019da4b082 gprs_ns2_sns: refactor nss_weight_sum_data -> ip46_weight_sum_data
Allow to use ip46_weight_sum_data for local endpoints as well.

Related: OS#5036
Change-Id: I75d88f3da89ad13e34a3fd5ae72bd967d81f4abc
2021-06-13 18:31:25 +00:00
Alexander Couzens 6231055645 gprs_ns2_sns: refactor ip4_weight_sum/ip6_weight_sum
Use the new introduced struct ns2_sns_elems instead of
the elems seperate.

Related: OS#5036
Change-Id: I0956ab6085554210569188f52cae121e32fca19b
2021-06-13 18:31:25 +00:00
Alexander Couzens cc56ddcdd0 gprs_ns2_sns: add check for duplicates to add_ip6_elem()
The ip4 version already checks for duplicates.

Related: OS#5036
Change-Id: I4a1528ea3427946ce465085919b2b522d3cedd07
2021-06-13 18:31:25 +00:00
Pau Espin af40b0b6b9 msgb_alloc_headroom: Change size args to be uint16_t
Underlaying APIs (msgb_alloc) use a uint16_t as a type, which means
until now passing a value > 2^16 would succeed providing a msgb with
less space than requested.

Since those are static inline, there's no symbols used by apps, so we
should be safe enough changing the type to be uint16_t, since change
would only be applied at re-compile time.

Change-Id: I83c8222484e4856c68134a1a9d8cf96eb91af1b8
2021-06-13 18:20:09 +00:00
Pau Espin 42bb125df1 bts_feature: Introduce feature to speak to PCU
This feature provides the BSC with information on whether the BTS talks
the IPAC_PROTO_EXT_PCU osmocom extension over the underlying IPA
multiplex of the OML link.

Related: SYS#5303
Change-Id: Id62421f7f5540875ac877a187757f2cf0556bd02
2021-06-11 16:36:29 +00:00
Pau Espin 8082c14a95 ipaccess: Add new osmo extension IPAC_PROTO_EXT_PCU
This new extension protocol is used to forward Osmocom PCUIF messages
BSC<->BTS<->PCU.
It will be sent re-using the IPA multiplex of the OML link between
BSC and BTS. BTS is responsible for forwarding the message over the unix
socket to the PCU.

Related: SYS#5303
Change-Id: I68b04def49946b6915dbd4e476999f249751cd28
2021-06-11 16:36:29 +00:00
Michael Iedema a667d85a92 ns2: use same name in ctr_group as stat_item_group
Change-Id: I7d2dcb6c7ddf72a0d06ff19f5d0e3dc740bd19ff
2021-06-10 12:57:04 +00:00
Eric Wild c3fa007610 kdf: add key derivation functions
generic sha code from git://w1.fi/hostap.git commit
5ea93947ca67ba83529798b806a15b247cdb2e93 which also happens
to be the source of our milenage code.

Related: SYS#5324
Change-Id: Ibf2e49edada944d91ceba62bd0d6b6ce69261fcd
2021-06-08 02:38:15 +02:00
Vadim Yanitskiy e9fd81a5c3 stats_vty: also show rate counter group name (if present)
Change-Id: I358f52e81a85f041fc21960634d04d18e7883dd5
2021-06-07 14:18:45 +00:00
Alexander Couzens d3507e851e gprs_ns2_sns: move gss->remote specific check out of add_ip4_elem/add_ip6_elem
Allow to use the add_ip4_elem also with local elemens.

Related: OS#5036
Change-Id: Ib48dfd7567467e60c5af2348924ece5cc6124206
2021-06-07 12:39:47 +00:00
Alexander Couzens c2ba25e436 gprs_ns2_sns: use struct ns2_sns_elems in add/update/remove remote_elems
Prepare to use the function also with local elems.

Related: OS#5036
Change-Id: I7db43c8dbd5bd7e7b07a7d629d2615bfa18623db
2021-06-07 12:39:47 +00:00
Alexander Couzens d2c6c49724 gprs_ns2_sns: refactor ns2_clear_ipv46_entries_local to use new elems functions
Related: OS#5036
Change-Id: I7225f7a4215842f0ea601ce6d9d38220f98f808d
2021-06-07 12:39:47 +00:00
Alexander Couzens 7112867151 gprs_ns2_sns: refactor local and remote entries into a struct
The IPv4/IPv6 elemens are the same for local and remote.
Refactor the entries into a struct to use function to manipulate
them with a single function.

Related: OS#5036
Change-Id: I05e053a9eb3328655502dfe2981c8f402104e292
2021-06-07 12:39:47 +00:00
Alexander Couzens 31d52e156f gprs_ns2_sns: bss: improve validation of configuration
Some combination of IPv4 and IPv6 result in incomplete
combination.
E.g. IPv6 binds, but only IPv4 endpoints and vice versa.

Related: OS#5036
Change-Id: I2fcf67bc2431ddac23c4ae23cebbb29771e573f1
2021-06-07 12:39:47 +00:00
Alexander Couzens 6608ce9525 gprs_ns2_sns: move selection of the next bind into own function
It will be also used by del_bind() when removing an active bind

Related: OS#5036
Change-Id: Ic39f0e5474ecc055d9a1b6a7b30777574d8b741d
2021-06-07 12:39:47 +00:00
Pau Espin 05047b7f27 ns2: Use NSVC bufid in stats report
Use the new stats API to set a meaningful name for its stats group too,
so that they are easily to identify when reported.

Example on VTY "show stats":
"""
NSVC Peer Statistics (0)('UDP-NSE01800-NSVC01800'):
 ALIVE response time        :        0 ms
NS Bind Statistics:
 Transmit backlog length:        0 packets
"""

Example reporting to statsd:
"""
my-stats-reporter-prefix.ns.nsvc.UDP-NSE01800-NSVC01800.alive.delay:0|g
"""

Related: SYS#5456
Change-Id: I4c696c615ba3416f8524d0797ce06c0ecd3a18f2
2021-06-05 15:46:27 +00:00
Pau Espin 09f075fad6 stat,rate_ctr: Allow setting group name and use it at report time
This patch adds a new field "name" to the rate_ctr and osmo_stat_item_group
structs, together with an API to set it. This new field allows for easy
identification of specific group instances when several of them exists,
rather than using a sometimes random/increasing index value.

If set, this name (string) is used instead of the index by the stats
reporter.

The name, if set, is also printed during "show stats" VTY commands.

It's up to the user or application to set up unique or meaningful names
to fullfill one's needs.

WARNING: this commit breaks ABI and possibly creates unexpected behavior
when run with non-rebuilt apps which use the modified structs directly
to get the coutners, or if use the static inline API rate_ctr_inc2().
Existing users of these structs should migrate to use new APIs
introduced in follow-up commits instead of accessing the field directly.

Related: SYS#5456
Change-Id: I0dc510783dd9ae8436dae8005a7b3330e80d36f3
2021-06-05 15:46:27 +00:00
Alexander Couzens d794806719 gprs_ns2: rework id strings of nsvcs
Ensure all nsvcs ids are unique as UDP ids might not be unique when
multiple NSVCs connect to the same remote endpoint (multiple binds).
Change the format of all ids to look similiar.
FR: NSE11-NSVC23-FR-fr0-DLCI13.
UDP: NSE11-NSVC-UDP-10.0.0.1:23000-192.168.1.1:24000
UDP: NSE11-NSVC23-UDP-10.0.0.1:23000-192.168.1.1:24000
UDP: NSE11-NSVC66-UDP-[fd01::1]:23000-[fd03::2]:24000

Change-Id: I618e263e73fcc64d4e46b57aa3a2cb2783837907
2021-06-05 15:46:13 +00:00
Vadim Yanitskiy 7d68959b0c fsm: cosmetic: fix weird spacing in osmo_fsm_inst_alloc()
Change-Id: I199085e717c6ebdc9061a0c9fa9a96bfbc11a74a
2021-06-04 20:07:10 +00:00
Pau Espin 7b894a7de0 Use new stat item/ctr getter APIs
Generated with spatch:
"""
@@
expression E1, E2;
@@
- &E2->ctr[E1]
+ rate_ctr_group_get_ctr(E2, E1)
"""

"""
@@
expression E1, E2, E3;
@@
- E2->items[E1]
+ osmo_stat_item_group_get_item(E2, E1)
"""

Change-Id: I41297a8df68e28dfc6016330ac82b0ed5dd0ebc1
2021-06-04 18:19:37 +02:00
Vadim Yanitskiy 442ff64ad4 gsm_08_58.h: add mask for Osmocom specific VAMOS C-bits
Applying and reverting this mask allows one to quickly convert
between VAMOS and non-VAMOS variants of Bm/Lm C-bits.

Change-Id: Ia0bd8695a3f12331b696fe69117189cdd48b584d
Related: SYS#4895, OS#4941, SYS#5315, OS#4940
2021-06-03 03:33:27 +00:00
Pau Espin 5fe3de5313 stat,rate_ctr: Introduce new API to get counter at given index
Having this API and forcing apps to use it will allow easily adding new
members to the group structure without having so much impact in users of
this struct.

Related: SYS#5456
Change-Id: Iebbf401f11e36645f8964d389460918eb9e0910e
2021-06-01 21:06:55 +00:00
Harald Welte 20199da02d sim: Add osim_card_{reset,close}() API
This is required to reset and close a card under software control
after opening it with osim_card_open()

Change-Id: Ie9ec66db4d54fdb1331f4ae05ca3ca4274912e9d
2021-06-01 20:29:17 +02:00
Pau Espin 6c7ac6abcd range_enc_determine_range(): Don't dereference array on size=0
cherry-picked from osmo-bsc.git d4c391eab03ce768d7eaf483368d9cda4f9668df

Change-Id: Iae058c35506bc25c9f4790889b89ac46aea664b6
Fixes: Coverity CID#182710 (osmo-bsc.git)
2021-06-01 14:04:20 +02:00
Neels Hofmeyr 208c5b643f fixup for gsm48_chan_mode_to_non_vamos()
When modifying chan modes, I first thought rather always fail if there
is no equivalent mode.

That is true for gsm48_chan_mode_to_vamos(), but for a change to
non-VAMOS, rather return the unchanged mode for non-VAMOS modes, so that
gsm48_chan_mode_to_non_vamos(GSM_CMODE_SIGN) works without failure.

This makes more convenient checking, e.g. in osmo-bsc's lchan_fsm.c
making sure that a non-VAMOS lchan has a non-VAMOS chan_mode, for all
types of lchans.

Change-Id: Ibf20f04d167e0e0599012ff530bc17ba8c8ab562
2021-05-29 23:45:22 +00:00
Vadim Yanitskiy fc02ff459a gsm_08_58.h: add Osmocom specific Bm/Lm CBITs for VAMOS
Change-Id: If33c1695922d110c0d2c60d5c0136caf2587194e
Related: SYS#4895, OS#4941, SYS#5315, OS#4940
2021-05-26 21:18:11 +02:00
Vadim Yanitskiy 57850ae188 rsl: make rsl_dec_chan_nr() more readable, use RSL_CHAN_NR_MASK
Change-Id: I1650e3b02e79461e42499268fa8ed30bff667489
2021-05-26 21:02:06 +02:00
Alexander Couzens 15596899a3 gprs_ns2: vty: fix removing a bind from a SNS
Return 0 after removing a bind. Otherwise the vty would return a
wrong error to the user.

Change-Id: I088c18abafc82ae7bd7b8c487ad9e9b448c42ba9
2021-05-23 10:32:40 +00:00
Alexander Couzens a35c296b6b gprs_ns2: sns: fix del bind()
When the bind to be removed is not the last entry, it would
remove the wrong SNS bind resulting in use-after-free memory.

Change-Id: I79062d404ebba9d5c8f7f209bebde146fa08c71f
2021-05-23 10:32:40 +00:00
Neels Hofmeyr fef61cd2dd add RSL_CMOD_CRT_OSMO_TCH_VAMOS_Bm, RSL_CMOD_CRT_OSMO_TCH_VAMOS_Lm
These indicate VAMOS mode to osmo-bts during channel activation and
channel mode modification.

Change-Id: Ib4ea11c870683a58f0bbc8c9cd942faceba8c4d9
2021-05-19 18:36:12 +02:00
Neels Hofmeyr dd6f13636e add RSL_IE_OSMO_TRAINING_SEQUENCE
This IE is explained in the Abis manual in osmo-bts commit
Ie583bd5969fdb45f772af198033e58d7c4077306
http://git.osmocom.org/osmo-bts/commit/?id=823cd529649b667af20bfa4e383255a8ed5931f1

Change-Id: I573c26b1431ee789e42f6fa620947b003c384dc0
2021-05-19 18:34:33 +02:00
Pau Espin 645aec8237 vty: Introduce API vty_read_config_filep
This new API doesn't use host_config_set(), and allows passing a FILE*
from any source, not only a filesystem path.

Related: SYS#5369
Change-Id: I720ac04386261628c0798a1bfcaa91e2490a86c3
2021-05-18 14:56:52 +02:00
Pau Espin ebb6c1fc4d vty: Implement missing public API host_config_file()
The API was defined in the header file but not implemented.

Change-Id: I69de9864fa7cd421557b9fc630beefea6d90b4cc
2021-05-17 18:54:23 +02:00
Harald Welte 24980baac9 osmo_sock_*_ofd(): Mark OSMO_FD_WRITE on non-blocking connect()
When we perform a non-blocking connect, the completion of the connect
will be signaled by marking the fd as WRITE-able.  So we should
automatically set OSMO_FD_WRITE to make sure the user gets notified
on completion.

Change-Id: I22964c5d5da849abcd97a900bd86ab5b4ada05da
2021-05-08 10:40:13 +00:00
Pau Espin a5af04477e gb: Fix missing exporting symbol bssgp_encode_rim_pdu
The symbol was not in the list of exported symbols.

Change-Id: I4c3792c3b22989571548e40aa4fbf26912e699df
2021-05-06 20:28:27 +02:00
Pau Espin adef546ff9 Revert "gb: Fix naming and export symbol bssgp_enc_rim_pdu"
This reverts commit 43ad616e4b.

 _enc_ functions are for some ies while the _encode_ and _decode_ are
for the full pdu.  so the old name is correct.

Change-Id: Ib0b4a6fd7f8c96e4647a373541e3cccb324c6a11
2021-05-06 18:28:12 +00:00
Vadim Yanitskiy f466a1592f gsm/abis_nm: add missing NM_OC_IPAC_* value-string entries
Change-Id: I2181af229e8e7da12d716c176ab9230f09e29eef
2021-05-06 16:32:29 +00:00
Pau Espin 43ad616e4b gb: Fix naming and export symbol bssgp_enc_rim_pdu
The symbol was not in the list of exported symbols.
Take the chance that it was not used anywhere outside libosmocore to
rename it in order to follow similar naming as other existing APIs.

Change-Id: I534db7d8bc5ceb19a2a6866f07d5f5c70e456c5c
2021-05-06 17:56:47 +02:00
Pau Espin a488639e42 osmo_timer_pending: Make arg const
Change-Id: I250c25c3ac61ac364335f81d8ba50cb32fd6976e
2021-04-29 20:14:51 +00:00
Harald Welte 5782fec9ff ns2: change the 'priority' setting name to 'socket-priority'
This has been changed based on feedback from Pau Espin in osmo-mgw,
and for consistency we also adjust it here.  No backwards compat
needed as it was just introduced yesterday.

Change-Id: I88989dc17c8996609b895c43012f8cca98aa81dc
2021-04-29 21:29:48 +02:00
Harald Welte a545842609 ipa_ccm_make_id_resp: Make it work at all
This could never possibly have worked.  When iterating over the
different IEs to encode, we must of course use the tag of the current
iterator item, and not the hard-coded value of the second tag in the
list.

Change-Id: I148799c5bdb95f70118691c1150330ebac4fdf21
2021-04-29 19:59:12 +02:00
Harald Welte b189b5f29c Fix ipa_ccm_make_id_resp_from_req to work at all
The parser was so horribly broken, it could not ever have possibly
worked.

Change-Id: Ibed0ff7f8d36504ef783f2653c9982d4e25e874f
2021-04-29 19:59:09 +02:00
Harald Welte 539272dd8e Fix ipa_ccm_make_id_resp_from_req
In 2018, I4723361e1094b358310541a7dc4c5c921c778a15 introuced a
check against an integer unterflow.  However, the fheck got the
logic wrong, with the result of breaking the function completely:
It would always only detect the first tag within the IPA request
and then take the branch that assumes an integer underflow.

Change-Id: I344975d0bda565ff196a1c0c69305cd349b98a19
2021-04-29 19:55:43 +02:00
Harald Welte d99e4eee2b ns2: Allow setting the socket priority for a UDP bind
Change-Id: Ifdfa086ce1c8d62b256abb3454b70cf53da9dcdb
2021-04-29 19:55:34 +02:00
Harald Welte 915caf75e2 gprs_ns: Fix another DSCP vs. TOS mistake in old NS code
DSCP is a 6-bit value stored in the upper 8 bit of what was used to
be known as TOS.  Let's use the newly introduced OSMO_SOCK_F_DSCP()
to prevent having to worry about this in higher level code.

Change-Id: I6b9848fd0752d99d3df5346313618d5847d64fb8
Related: OS#5136
2021-04-29 15:54:59 +02:00
Harald Welte 485b3f7c85 ns2: migrate from osmo_sock_set_dscp() to OSMO_SOCK_F_DSCP()
The latter is much more compact than the former.

Change-Id: I2a24c0cbb17fad8ed84297267dcd63730efbc014
2021-04-29 15:54:59 +02:00
Harald Welte f8a4e133d5 gprs_ns2_frgre: Ensure DSCP is sin premitted value range
gors_ns2_udp has this check, but gprs_ns2_frgre was missing it.

Change-Id: I9bb9c6bdfe81fa6f02b11a02550ac9a54d3bfeaf
2021-04-29 15:54:59 +02:00