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
Even if not bound to a IF they just exist and work as expected, and make
distinguishing traffic for local setups easy.
Change-Id: I1043dfd8075f14481011f43db45c943e9320413c
After my system's gcc was upgraded, I get false positivies in a couple
places. Let's initialize those to make gcc happy.
"""
/git/libosmocore/src/socket.c: In function ‘osmo_sock_init’:
/git/libosmocore/src/socket.c:958:25: error: ‘sfd’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
958 | close(sfd);
| ^~~~~~~~~~
/git/libosmocore/src/gsm/gsm48.c: In function ‘osmo_mobile_identity_decode’:
/git/libosmocore/src/gsm/gsm48.c:690:20: error: ‘str_size’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
690 | if (rc < 1 || rc >= str_size) {
| ~~~~~~~^~~~~~~~~~~~~~~~~
/git/libosmocore/src/gsm/gsm48.c:679:22: error: ‘str’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
679 | rc = osmo_bcd2str(str, str_size, mi_data, 1, 1 + nibbles_len, allow_hex);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
Change-Id: I8aacfbc21e23f63a65e8baee3fd536a1fe1bdd8a
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
Every socket function that can be passed a 'flags' argument now
supports the following two additional macros that can be or-ed in
with the flags:
* OSMO_SOCK_F_DSCP(x) -- specify the IP DSCP of the socket
* OSMO_SOCK_F_PRIO(x) -- specify the priority of the socket
The existing osmo_sock_set_{dscp,priority}() functions are useful,
but you cannot call them in between the socket creation and the
connect() operation when using our socket helpers. This means that
the first packet sent will have the default DSCP/priority, and only
later packets would have the desired values.
When using the functionality introduced by this patch, we can ensure
that even the very first packet of e.g. a TCP or SCTP connect()
will have the correct DSCP/priority applied.
Change-Id: If22988735fe05e51226c6b091a5348dcf1208cdf
Related: SYS#5427
Common bits shared by various functions (currently setting
non-blocking) should not be copy+pasted around.
Change-Id: I95056940ddc26b65f63eedaeaab6882edaef6317
In some situations we want to set the SO_PRIORITY socket option
to determine the in-kernel priority of packets generated by this
socket.
Change-Id: I89abffcd125e6d073338a5c6437b9433220e1823
Related: SYS#5427
At least on Linux, sockets have a IP_TOS socket option that can be
configured to set the TOS. However, TOS (of RFC791) was replaced
by the DSCP (of RFC2474) in 1998.
As the DCSP bits are only the upper 6 bits of the TOS bits, let's
introduce a helper to get, mask and set the DSCP values in the TOS
bits.
Related: OS#5136, SYS#5427
Change-Id: Ia4ba389a5b7e3e9d5f17a742a900d6fd68c08e40
On IPv6 sockets, getsockname() and inet_ntop() would act upon a
structure struct sockaddr_in.
First getsockname() would succeed but truncate the address, and later on
inet_ntop would read out of the scope of the structure.
Change-Id: If781d56680758a97643b1b38e78d3431ea649020
sctp_bindx() fails if passed both "0.0.0.0" and "::", only "::" must
be passed instead, which covers both.
As a result, it is fine in this case and makes sense having only IPv6
formatted IPs in the local side (which actually also includes all IPv4
ones in th system) and IPv4-only addresses on the remote side.
Change-Id: I0b590113e5def20edcbcb098426b19cd504eabff
The flag was added recently in cd133316cf,
and it is causing issues while running unit tests in environement like
OBS where probably there's no non-loopback address configured.
Change-Id: I47c31953f1db39fcd2870bde0b984057b8e7b4c4
Under some specific cases, res_loc could be leaked. Under some others,
res_loc and res_rem were freed without being initialized previously.
Fixes: CID#212863
Fixes: CID#212861
Change-Id: Id9c4eda6fd1172e7324aa23c81e8658967a8dd0b
Drop one of the two log lines since it would be a duplicated and anyway
it misses context (return code).
Change-Id: I4620bf86f4bcda58ae85209278ac9ae9a0f3012a
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
Address resolution is done first and once we have the information, it
proceeds to create the socket. This separation in steps will help when
adding support for IPv6+IPv4 sets, where AF_UNSPEC is passed and created
socket needs to be AF_INET6 in order to handle addr of both versions.
Change-Id: I03147e3033a0c1fd04c9ac61d2ffbd78a1bb784a
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
Those two functions are only used by osmo_sock_init2_multiaddr(), which
is only built if HAVE_LIBSCTP is defined. Avoid compiler warning about
unusued function helpers if osmo_sock_init2_multiaddr() is not being
built.
Change-Id: I52769d6b8f70af1a8bda23d60b3230a932e71fab
Since we return error at the start of the function if proto !=
IPPROTO_SCTP, it makes no sense to check for proto != IPPROTO_UDP later
on.
Fixes: CID#205088
Change-Id: Ibba7eacaa9debb77d536d47dc85170c5ee79e479
This API will be used by libosmo-netif's osmo_stream for SCTP sockets,
which in turn will be used by libosmo-sccp to support multi-homed
connections.
Related: OS#3608
Change-Id: Ic8681d9e093216c99c6bca4be81c31ef83688ed1
ubsan will report undefined behavior due to the SUN_LEN macros interaction with a null pointer,
so let's tell ubsan to ignore this function. After carefully reviewing the final publically
availlable drafts of the C99,C11 and C18 standards I can confirm that dereferencing null pointers
is still undefined behavior, as such ubsan will always warn with absolutely every existing compiler
version. Since the sanitizers are periodically synced between llvm and gcc I'm also fairly confident
that rebuilding everything with compiler_rt to use the integrated sanitizers would result in the same message.
I sincerly hope that this explanation provides to be sufficient, If not I'd be willing to show up at
the next llvm dev meeting to provide quotes from actual sanitizer developers to back up these claims.
Change-Id: I0ff445072f1b46390c9f70b21d61c789e39358d5
We have a number of library-internal static global buffers which are
mainly used for various stringification functions. This worked as
all of the related Osmocom programs were strictly single-threaded.
Let's make those buffers at least thread-local. This way every thread
gets their own set of buffers, and it's safe for multiple threads to
execute the same functions once. They're of course still not
re-entrant. If you need re-entrancy, you will need to use the _c()
or _buf() suffix version of those functions and work with your own
(stack or heap) buffers.
Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07
osmo_sock_get_name_buf():
In case the getsockname() call is failing for some weird reason,
we shouldn't return an uninitialized, non-zero-terminated string
buffer to the caller, as most callers will be too lazy to test the
return value.
This holds even more true for users of the internal
osmo_sock_get_name2() and osmo_sock_get_name2_c() functions which indeed
very much ignore the return value of osmo_sock_get_name_buf().
Change-Id: I2d56327e96b7a6783cca38b828c5ee74aed776ae
Calling sizeof() on a pointer to dynamically allocated memory would
result in getting size of the pointer (usually 4 or 8 bytes) itself,
but not the size of allocated memory.
Change-Id: I8ffda4dea2b7f9b4b76dfeecad1fab6384c5a62c
Fixes: CID#197629, CID#197628, CID#197627
Fixes: CID#197626, CID#197625, CID#197624
We have a habit of returning static buffers from some functions,
particularly when generating some kind of string values. This is
convenient in terms of memory management, but it comes at the expense
of not being thread-safe, and not allowing for two calls of the
related function within one printf() statement.
Let's introduce _c suffix versions of those functions where the
caller passes in a talloc context from which the output buffer shall
be allocated.
Change-Id: I8481c19b68ff67cfa22abb93c405ebcfcb0ab19b
The naming of these constants dates back to when the code was private
within OpenBSC. Everything else was renamed (bsc_fd -> osmo_fd) at
the time, but somehow the BSC_FD_* defines have been missed at the
time.
Keep compatibility #defines around, but allow us to migrate the
applications to a less confusing naming meanwhile.
Change-Id: Ifae33ed61a7cf0ae54ad487399e7dd2489986436
The function osmo_sock_get_name_buf() can be used to write a string
representation to a user provided memory. Unfortunately the proper
length for the user provided memory is not obvious. To make using
osmo_sock_get_name_buf() more practical, add a define constant that
defines the length of the required memory. Also use this define in
socket.c.
Change-Id: If8be8c2c0d4935da17ab13b2c2127b719ceefbcc
Basically, I am applying code review that I would have given had I not been on
vacation when the last osmo_sock_get_name* stuff was merged.
osmo_sock_get_name2() is so far a static internal function. However, it is
nothing like osmo_sock_get_name(), so instead rename it to
osmo_sock_get_ip_and_port(). Also make it public API, no need to hide it. I'm
adding an "and" in the name to hopefully clarify: "ip_port" vs. "ip_and_port"
-- there already are _get_X_ip_port() functions that only return the port
string, despite "ip" in the name.
Add new public osmo_sock_get_name2(), which is like osmo_sock_get_name(),
except it uses a static string instead of talloc, and omits the braces. This
is most convenient for log statement formats, avoiding dyn allocations.
Add new osmo_sock_get_name_buf(), which is like osmo_sock_get_name2() but
writes to a caller provided char buffer.
Use osmo_sock_get_name_buf() in the implementation of osmo_sock_get_name(),
but use another (non-static) local string buffer, because adding braces is too
complex without talloc_snprintf().
Rationale:
I want to improve the logging of socket errors, e.g. change
DLMGCP ERROR Failed to read: 111/Connection refused (mgcp_client.c:720)
to
DLMGCP ERROR Failed to read: r=10.0.99.2:2427<->l=10.0.99.2:2728: 111='Connection refused' (mgcp_client.c:721)
but it is just not handy to compose logging with the current API:
- osmo_sock_get_name() requires a talloc_free().
- all the others require output buffers.
- the only way to conveniently compose a logging string and,
- notably, the only trivial way to skip the string composition if the logging
level is currently muted, is to have a function that returns a static string:
the new osmo_sock_get_name2().
- (I think the osmo_sock_get_{local,remote}_* convenience wrappers should never
have been added, because they encourage the caller to invoke the same code
twice, for IP addr and port, and throw away one half each time.)
Related: Iae728192f499330d16836d9435648f6b8ed213b6 (osmo-mgw)
Change-Id: I8ad89ac447c9c582742e70d082072bdd40a5a398
It's similar to osmo_sockaddr_to_str_and_uint() but does not require odd
typecasting for AF_INET case. Make osmo_sockaddr_to_str_and_uint() into
wrapper around new function and make sure to check for address family
before typecasting. Also use proper return type.
Change-Id: Ie384483124d407a960ab6732e6a7fd90554389d2
Use INET6_ADDRSTRLEN (46) instead of 64 for IP address buffers, and 6
instead of 16 for port buffers (the highest possible port number is
65535).
Change-Id: Ia25e2f3277ad2f60df31c08d12f42c1e6d2a14a6
Return only the IP or port of either the local or remote connection,
not the whole set of IP and port of both the local and remote
connection like osmo_sock_get_name() does it. This is needed for
OS#2841, where we only want to print the remote IP.
Related: OS#2841
Change-Id: I6803c204771c59a2002bc6a0e6b79c83c35f87e1
The unix(7) man page recommends that sun_path is NUL-terminated
when struct sockaddr_un is passed to a bind() or connect() call.
Non-NUL-terminated paths only need to be dealt with at the
receiving end of a UNIX domain socket.
Commit 896ff6d erroneously assumed otherwise.
This commit almost reverts 896ff6d: It only leaves the added
osmo_strlcpy() overflow check in place.
Change-Id: I6c4ac6b0a0eef4842beae4107f6f09f6cd29172a
Fixes: 896ff6db16
Related: OS#2673