Commit Graph

19 Commits

Author SHA1 Message Date
Max 3e65693b4d Add osmo_sock_get_name_multiaddr_buf()
It's similar to osmo_sock_get_name_buf() but supports multi-homed SCTP sockets
bound to several addresses.

Related: OS#5581
Change-Id: If76595ebd1cf26ba904887a36c4cc14a1b5c4521
2022-09-29 12:27:21 +07:00
Neels Hofmeyr 09d6574a45 add osmo_sockaddr_to_str_c(), osmo_sockaddr_to_str_buf2()
To easily log and print a sockaddr using OTC_SELECT, add
osmo_sockaddr_to_str_c().

Implement osmo_sockaddr_to_str_buf2() using osmo_strbuf, so that we can
return the chars_needed which osmo_sockaddr_to_str_c() uses.

From previous osmo_sockaddr_to_str_buf(), call
osmo_sockaddr_to_str_buf2() and return NULL if the buf_len was
insufficient, to mimick previous behavior. This makes it more
consistently returning NULL for insufficient buf_len, as shown in the
tweak that is needed in socket_test.c. Before osmo_sockaddr_to_str_buf()
would return a truncated port number, now it's all or NULL.

I will use osmo_sockaddr_to_str_c() in the new osmo-upf implementation.

Related: SYS#5599
Change-Id: I12771bf8a021e6785217b1faad03c09ec1cfef0e
2022-01-31 15:03:53 +00:00
Oliver Smith 04bfb7165b treewide: remove FSF address
Remove the paragraph about writing to the Free Software Foundation's
mailing address. The FSF has changed addresses in the past, and may do
so again. In 2021 this is not useful, let's rather have a bit less
boilerplate at the start of source files.

Change-Id: I5050285e75cf120407a1d883e99b3c4bcae8ffd7
2021-12-14 12:44:03 +01:00
Pau Espin 01e0d3e7fd Drop use of log_set_print_filename() API inside libosmocore
Let's use log_set_print_filename2() API instead, which has less ackward
behavior implications like changing the print status of category-hex.

Related: OS#5034
Change-Id: Ifc78e1dcba5baf0b41f6ccbbbd1e3f06552d73da
2021-02-20 17:13:58 +00:00
Pau Espin 690b661fbc tests: Set print_category values explicitly
This will alow easily changing default values for print_category vs
print_category_hex later.

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.

Related: OS#5034
Change-Id: If29b40557d5c2bcda04b964f344070bad58d8f28
2021-02-20 17:13:58 +00:00
Alexander Couzens 80788fac9e add osmo_sockaddr_to_str_buf/osmo_sockaddr_to_str
Add helper to format osmo_sockaddr into a string.

Change-Id: I917f25ebd1239eae5855d973ced15b93731e33a0
2020-10-12 15:13:43 +00:00
Alexander Couzens 43957e69ca socket: introduce osmo_sock_init_osa & osmo_sock_init_osa_ofd
osmo_sock_init_osa() takes osmo_sockaddr* as local and remote endpoints
to setup a socket.

Change-Id: I1eece543e3241ef0e095eb63bb831f7c15a16794
2020-09-02 18:42:21 +02:00
Alexander Couzens ea19839ade tests/socket: add testcase test_get_ip_and_port
Check if osmo_sock_get_ip_and_port() works correct.

Change-Id: I4e69d814367168c05f0da161ec9b705db36ad096
2020-09-02 17:23:43 +02:00
Pau Espin d8cf52b993 socket: Fix bug in osmo_sock_init2(AF_UNSPEC) matching IP versions
See previous commit for a bug description.

Fixes: 2c962f5de1

Change-Id: I59bf4b4b3ed14766a5a5285923d1ffa9fc8b2294
2020-08-31 19:01:02 +02:00
Pau Espin d9e04177a2 tests: Add test to showcase osmo_sock_init2 bug with AF_UNSPEC
The function is checking for IP version matching between local and
remote addresses even if only one is needed based on flags. For example,
if user only desired to bind, the remote address should not be
used nor checked.

Bug was introduced here: 2c962f5de1

Change-Id: I87afd1db9bd017426abcc959fa515d15784cdf1c
2020-08-31 18:59:04 +02:00
Pau Espin 16b076cd15 tests: Split SCTP tests to its own file and run them conditionally
Some systmes (like the ones available in OBS) don't support creating
SCTP sockets, so we need to skip those tests there.

Change-Id: I1d16280674625877ec22cc60cbc5deb67868a656
2020-08-25 14:22:03 +02:00
Pau Espin ba828c30a0 socket: Log proper getaddrinfo() error
Drop one of the two log lines since it would be a duplicated and anyway
it misses context (return code).

Change-Id: I4620bf86f4bcda58ae85209278ac9ae9a0f3012a
2020-08-24 08:29:19 +00:00
Pau Espin cd133316cf socket: multiaddr: Support IPv4 + IPv6 addresses in SCTP associations
The function is improved to support AF_INET:v4->v4, AF_INET6:v6->v6 and
AF_UNSPEC:v4+v6->v4+v6.
Unit tests for the function are added to make sure function behaves
correctly in several scenarios.

Change-Id: I36d8ab85d92bba4d6adb83bc1875eb61094ed2ef
2020-08-24 08:29:19 +00:00
Alexander Couzens 2c962f5de1 osmo_sock_init2: improve support for AF_UNSPEC
osmo_sock_init2 abstract two calls of getaddrinfo into one.
While there aren't problems with AF_INET or AF_INET6. When using
AF_UNSPEC there are corner cases when this fails. E.g. calling
local_host with "" and remote_host with an IPv6 only address results in
setting up a local socket with AF_INET while trying to connect from there towards
AF_INET6 will most likely fail.
To prevent such cases with AF_UNSPEC, search prio calling any syscalls if local and remote site
supports AF_INET or AF_INET6. In case both supported, prefer AF_INET6

Change-Id: I397c633931fd00d4f083955a3c49a40fb002d766
2020-08-06 16:41:20 +00:00
Neels Hofmeyr a829b45c85 use osmo_init_logging2() with proper talloc ctx
Ironically, when deprecating osmo_init_logging() in
I216837780e9405fdaec8059c63d10699c695b360, I forgot to change the callers
within libosmocore itself, i.e. in the various regression tests.

Change-Id: Ia36c248f99353d5baaa2533f46a2f60a8579bdf8
2018-04-06 04:37:50 +02:00
Neels Hofmeyr 1f82d0aecf osmo_sock_get_name(): clearly indicate local and remote
In a string like

  127.0.0.1:2905<->127.0.0.1:60661

it is hard to tell which is the local part. I'd have expected it on the left,
but it is actually on the right.

To avoid doubt and bypass bikesheds on which side should be what, clearly mark
the two sides as remote and local.

  (r=127.0.0.1:2905<->l=127.0.0.1:60661)

Change-Id: I43dcc6a1906429bd0955fd7fe2eb5b8495b592d8
2017-07-03 17:29:05 +00:00
Harald Welte dda70fca79 Add osmo_sock_init2() function, allowing both BIND *and* CONNECT
The old osmo_sock_init() function allows only either a bind (for a
server socket), or a connect (for a client socket), but not both
together.  So there's no way to have a client socket that is bound to a
specific local IP and/or port, which is needed for some use cases.

Change-Id: Idab124bcca47872f55311a82d6818aed590965e6
2017-04-09 21:46:21 +02:00
Philipp Maier 6f0f560eab cosmetic: replace fprintf with LOGP
socket.c still uses fprintf to output error messages. This commit
replaces the fprintf with proper LOGP messages.

Change-Id: Ia2993415d5f5c33ccd719af239ff59252d11b764
2017-02-09 16:21:01 +01:00
Harald Welte 4ffb43f654 Add minimal testing of socket.c helper functions
Change-Id: I2773b3859a206f96fb8fa095d50a653d9eeb8d79
2017-02-08 18:23:06 +01:00