aboutsummaryrefslogtreecommitdiffstats
path: root/src/core/socket.c
AgeCommit message (Collapse)AuthorFilesLines
2024-03-12socket: Add remote PID and local FD to AF_UNIX socknamePau Espin Pedrol1-3/+28
This allows identifying precisely an AF_UNIX socket. Change-Id: Ic465e557ea49de8e044d1ef6d91fc3c852c88ff2
2024-03-12socket: Support AF_UNIX in osmo_sock_get_name_buf()Pau Espin Pedrol1-7/+46
Right now stream_cli/srv print "<error-in-getsockname>" when using an AF_UNIX socket. This commit fixes the problem. Change-Id: I224c3712a029ee338ee1209a67d820b887170910
2024-02-23Make socket.c compile without libsctp support (--disable-libsctp)Andreas Eversberg1-0/+4
Change-Id: I214a16b60e0149a8b1cdcfd3c788cc56a1a40476
2023-12-12socket: Introduce defines OSMO_SOCK_MULTIADDR_{PEER_STR,NAME}_MAXLENPau Espin Pedrol1-3/+3
These values end up being used by API users of osmo_sock_multiaddr_get_name_buf() and osmo_multiaddr_ip_and_port_snprintf(). Change-Id: I18a0e1a652a3e8ef3e97154355eb1d07a14ef0bd
2023-12-11socket: Introduce API osmo_sock_sctp_get_peer_addr_info()pespin/multiaddrPau Espin Pedrol1-0/+77
This is a convenience helper to reetrieve the whole set of remote addresses and call getsockopt() on them, making it easy for users to analyse the full set of remote addresses of a socket simply providing an fd. Related: SYS#6636 Change-Id: I3e1c84526b006baff435bbbca49dc6cf7d201cf5
2023-12-10socket: Fix uninitialized mem ptr free in osmo_sock_init2_multiaddr2()Pau Espin Pedrol1-1/+1
The goto tag was wrong, probably due to a copy-paste mistype while reimplementing the function. Closes: Coverity CID#336546 Change-Id: I06b810fde7bf750fcb42d6d9e6223883e26f5f0b
2023-12-07socket: Introduce API osmo_sock_multiaddr_get_name_buf()Pau Espin Pedrol1-0/+106
An extra osmo_multiaddr_ip_and_port_snprintf() API is introduced which is used by osmo_sock_multiaddr_get_name_buf() but which will also be used by other app uers willing to use osmo_sock_multiaddr_get_ip_and_port() according to its needs (eg. only printing the local side). Related: SYS#6636 Change-Id: I48950754ed6f61ee5ffa04a447fab8903f10acc0
2023-12-07socket: Introduce API osmo_sock_multiaddr_get_ip_and_port()Pau Espin Pedrol1-0/+89
This API will be used internally by osmo_sock_multiaddr_get_name_buf() in a follow-up patch. This API can also be used directly by user who wish to obtain a list of local/remote IP addresses and port from an SCTP socket. Related: SYS#6636 Related: OS#5581 Change-Id: I19d560ab4aadec18a4c0f94115675ec1d7ab14d7
2023-12-06socket: osmo_sock_init2_multiaddr2(): Apply params too if no ↵Pau Espin Pedrol1-19/+21
OSMO_SOCK_F_BIND flag set Those parameters are not related to binding and hence should be applicable before binding. This allows a caller setting them while not caring about explicit binding (OSMO_SOCK_F_BIND). Until recently calling this function without OSMO_SOCK_F_BIND was not really supported, so the previous placement setting these params in the function didn't matter much. It does now. Change-Id: Ia32510e8db1de0cc0dc36cebf8a94f09e44fda70
2023-12-06socket: Reimplement osmo_sock_init2_multiaddr()Pau Espin Pedrol1-44/+103
This is an attempt to fix several downsides of current osmo_sock_init2_multiaddr() API, mainly the requirement to pass an explicit local address (!NULL). It also now works fine if OSMO_SOCK_F_BIND flag is not used. This reimplementation is based on the follwing logic: - If caller passed family=AF_INET or family=AF_INET6, that same family is used and kernel will fail if something is wrong. - If caller passes family=AF_UNSPEC, the function will try to find the required family to create the socket. The decision is taken on the assumption that an AF_INET6 socket can handle both AF_INET6 and AF_INET addresses (through v4v6 mapping). Hence, if any of the addresses in the local or remote set of addresses resolves through getaddrinfo() to an IPv6 address, then AF_INET6 is used; AF_INET is used otherwise. Related: OS#6279 Change-Id: I2641fbaca6f477404b094dbc53c0c1a3dd3fd2fd
2023-11-22add new osmo_sockaddr_from_str_and_uint() functionHarald Welte1-0/+21
The function is basically a shortcut for getaddrinfo with storing the output data into our 'struct osmo_sockaddr'. Change-Id: I6b5c0bf8ca97e6358d992fb2ff45ffd53ba15197 Related: SYS#6657
2023-10-23socket.c: Fix compilation with --disable-libsctpPau Espin Pedrol1-0/+2
Fixes: 64ba9edf173cc16f9d94c94a423a8b7a5904efaf Related: OS#6234 Change-Id: I988d01461822d18b7350a6e69e3b504f7fd5b84f
2023-10-03socket: Introduce APIs osmo_sock_multiaddr_{add,del}_local_addr()Pau Espin Pedrol1-0/+152
These APIs are used to bind or unbind an active socket adding or removing addresses from the existing set. Related: OS#6077 Change-Id: Ifc6e7d643c2a0c53f479bfd0d5c36d08c0c01953
2023-09-08socket: Support setsokopt SCTP_INITMSG in osmo_sock_init2_multiaddr2()Pau Espin Pedrol1-0/+54
This allows setting several socket paramets which can only be set before SCTP INIT phase (connect()). Since no release with osmo_sock_init2_multiaddr2() happened yet, we are allowed to extend struct osmo_sock_init2_multiaddr_pars without bumping the version field. Related: SYS#6558 Change-Id: Ibc55932d954279927d1e70ccce1e8bf32b180d44
2023-09-08socket: Remove OSMO_SOCK_F_SCTP_ASCONF_SUPPORTED, add ↵Pau Espin Pedrol1-9/+50
osmo_sock_init2_multiaddr2() The OSMO_SOCK_F_SCTP_ASCONF_SUPPORTED flag was added recently to enable use of ASCONF in osmo_sock_inti2_multiaddr. Since we didn't release yet, we are still in time to get rid of this flag. It turns out that we'll want to add more features which must be set before SCTP INIT (connect()) time, like setsockopt SCTP_INITMSG, which in turn contains a struct with several parameters. Hence, adding flags for all those makes no sense. Instead, add a new API which allows passing an extensible struct which allows much more fine-grained setup from the caller. The new struct "pars" parameter is non-const on purpose, in order to be able to extend the struct in the future if we wish to get/obtain some data from the socket. Related: SYS#6501 Related: SYS#6558 Change-Id: I1f6fd09a79b0a2bd794e5669d933be25bbf1eeaa
2023-08-28socket: Avoid aborting socket creation if setsockopt for ASCONF failsPau Espin Pedrol1-2/+4
Avoid aborting the entire socket creation, since those sockopt are fairly new in the kernel (v5.4), and the feature can still be enabled in older versions system-wide with sysctl. The worst it can happen is that the ability to submit address updates (such as Peer Primary Address) doesn't work, which is not really critical. Related: SYS#6501 Change-Id: Iff261c8592b6b3c4237c90c84b4e8e921e3c4a65
2023-08-21socket: Add osmo_sock_init flag to enable SCTP ASCONF featuresPau Espin Pedrol1-0/+53
The SCTP_ASCONF_SUPPORTED sockopt, which enables ASCONF features for the SCTP associations managed by the SCTP socket, gets its default value from to sysctl "net.sctp.addip_enable", which, at least up to current kernel 6.4.8 is set to "0" (disabled) by default. As a result, ASCONF related features such as setsockopt(SCTP_SET_PEER_PRIMARY_ADDR) fail with -EPERM since ASNCONF extensions where not negotiated during the SCTP init handshake. This commit adds support for setting SCTP_ASCONF_SUPPORTED=1 during socket creation, since that needs to be applied before the first bind()/connect() (before first assoc is created). Furthermore, for ASCONF features to work properly, the assoc also needs to announce/use the AUTH extension, as per RFC5061 section 4.2.7. Otherwise, the peer receiving an SCTP INIT with ExtensionFeatures=ASCONF,ASCONF_ACK but without AUTH, will reject the assoc with an ABORT since it's not complying with spec (this behavior can be tweaked through sysctl "net.sctp.addip_noauth_enable"). The AUTH extension is enabled through sockopt SCTP_AUTH_SUPPORTED, and its default value is that of sysctl "net.sctp.auth_enable", which is also disabled (0) by default. Kernel support for those is relatively new: SCTP_FUTURE_ASSOC added in: 80df2704a375bb4b3c9c5cce9c00052361b16d61 Follows: v5.0-rc4 Precedes: v5.1-rc1 SCTP_ASCONF_SUPPORTED added in: df2c71ffdfae58961981d7cbcccea93688fc4e96 Follows: v5.3-rc5 Precedes: v5.4-rc1 SCTP_AUTH_SUPPORTED added in: 56dd525abd56f7acd7b44a52935726e3ada4916c Follows: v5.3-rc5 Precedes: v5.4-rc1 Related: OS#6076 Change-Id: Iac07031927b66a9d32d2bb2faab817e4c922a359
2023-07-12socket: Cache errno before calling further functionsPau Espin Pedrol1-6/+12
No issue is in principle expected with previous code since snprintf doesn't seem to be setting errno according to "man snprintf", but better be safe, specially in case someone calls the functions calling snprintf in the future, or if snprintf sets errno in other implementations. Change-Id: I6969be10db867b4821e05aed50bc22a7ccd4a633
2023-06-19socket: Ensure fd is not negative in osmo_sock_get_name_buf()Daniel Willmann1-0/+5
Write to str even in case of error because this is already the current behaviour and it's what osmo_stream_cli_get_sockname() and osmo_sock_get_name2{,_c}() expect. Change-Id: I76727993224ef87b475c33360c24966e82e866ec Fixes: Coverity CID#321044
2023-03-14error log: osmo_sock_init2_multiaddr() v4/v6 mixNeels Hofmeyr1-1/+5
Provide some more information for the error case when local and remote addresses mix v4 and v6. Change-Id: I0fd12b08e0788ce3af6dc519ff8c82ad196a115f
2023-02-15socket: propagate error in osmo_sock_unix_init() to the callerMax1-4/+4
Change-Id: Ia90d2ca3106b58dc5953d930f13df829d5b6966f
2023-01-18Fix all references to config.hPau Espin Pedrol1-1/+1
config.h is created in $(top_buildir)/config.h. Let's make sure all CPPFLAGS add correct -Ipath includes, and that all code includes the correct file. Change-Id: Ie9ea38bb009bc715b01cde4d66d181f7bec2e7bd
2023-01-18Move src/*.{c,h} to src/core/Pau Espin Pedrol1-0/+2062
This way we have all libosmocore.so in an own subdir instead of having lots of files in the parent dir, which also contains subdirs to other libraries. This also matches the schema under include/osmocom/. Change-Id: I6c76fafebdd5e961aed88bbecd2c16bc69d580e2