aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom/core/socket.h
AgeCommit message (Collapse)AuthorFilesLines
2023-12-12socket: Introduce defines OSMO_SOCK_MULTIADDR_{PEER_STR,NAME}_MAXLENPau Espin Pedrol1-3/+11
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/+3
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-07socket: Introduce API osmo_sock_multiaddr_get_name_buf()Pau Espin Pedrol1-0/+4
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/+2
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-11-22add new osmo_sockaddr_from_str_and_uint() functionHarald Welte1-0/+1
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-03socket: Introduce APIs osmo_sock_multiaddr_{add,del}_local_addr()Pau Espin Pedrol1-1/+2
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/+12
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-3/+26
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-21socket: Add osmo_sock_init flag to enable SCTP ASCONF featuresPau Espin Pedrol1-0/+2
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-03-02Add osmo_sockaddr_size() to return the size of the variant usedDaniel Willmann1-0/+23
Change-Id: I952b6bb752441fe019fc18f89bce4bbfbe58994a
2023-01-17socket.h: Introduce API osmo_sockaddr_netmask_to_prefixlen()Pau Espin Pedrol1-0/+2
Implementation is imported from osmo-ggsn.git 97f60e3dca581797007524e0006ca9fafad59713 in46a_netmasklen() and adapter to work with an osmo_sockaddr. This will be used by osmocom-bb's "modem" app. Change-Id: I75e75e251c6776801fffdde745aebedf21c68799
2022-10-04socket: Introduce API osmo_sockaddr_is_anyPau Espin Pedrol1-0/+1
Change-Id: I2810a889fc14052d0e0be6a2b500ad4e5088ffa9
2022-10-04socket.h: Reorder sockaddr APIs to have them all togetherPau Espin Pedrol1-25/+25
Change-Id: Iab2ee2854be8027ee5978e06a83248b530a39bf7
2022-03-01add osmo_sockaddr_set_port()Neels Hofmeyr1-0/+1
Do it like osmo_sockaddr_port() in reverse. Related: SYS#5599 Change-Id: I9512e44c3203daebb3fe3435fceef167613c1a73
2022-02-07add osmo_sockaddr_from/to_octets()Neels Hofmeyr1-0/+3
Shorthand for the INET/INET6 switch() to get/put the addr part, useful for encoding and decoding message buffers. Related: OS#5599 Change-Id: Ie9e33bfac525c59c30714663d2bfcc62ec9eeb81
2022-01-31add osmo_sockaddr_to_str_c(), osmo_sockaddr_to_str_buf2()Neels Hofmeyr1-0/+2
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
2021-04-28socket: QoS support for all our socket init functionsHarald Welte1-0/+9
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
2021-04-27socket: Introduce osmo_sock_set_priority() helper functionHarald Welte1-0/+1
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
2021-04-27socket: Introduce osmo_sock_set_dscp() to set socket DSCP valueHarald Welte1-0/+2
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
2020-10-12add osmo_sockaddr_to_str_buf/osmo_sockaddr_to_strAlexander Couzens1-0/+4
Add helper to format osmo_sockaddr into a string. Change-Id: I917f25ebd1239eae5855d973ced15b93731e33a0
2020-10-09socket: make the arguments of osmo_sockaddr_cmp() constVadim Yanitskiy1-1/+2
Change-Id: Ibfdfdd40c52709b32ac934974cc78ee821fa83ba
2020-09-07add osmo_sockaddr_local_ip() to determine the local address for a remote.Alexander Couzens1-0/+2
Similiar to osmo_sock_local_ip but for osmo_sockaddr. Change-Id: I9cd2c5ceb28183e2fd2d28f9c9088c3fcac643d2
2020-09-02socket: add osmo_sockaddr_cmp()Alexander Couzens1-0/+2
Compare two osmo_sockaddr. Change-Id: I2d12ebae2710ffd17cf071e6ada0804e73f87dd6
2020-09-02socket: introduce osmo_sock_init_osa & osmo_sock_init_osa_ofdAlexander Couzens1-0/+10
osmo_sock_init_osa() takes osmo_sockaddr* as local and remote endpoints to setup a socket. Change-Id: I1eece543e3241ef0e095eb63bb831f7c15a16794
2020-08-31socket: Add some osmo_sockaddr print helpersPau Espin Pedrol1-0/+3
These are APIs useful to inline in log calls. Change-Id: Ie07a38b05b7888885dba4ae795e9f3d9a561543d
2020-08-10socket.h: introduce osmo_sockaddr to hold v4 and v6 endpointsAlexander Couzens1-2/+11
When dealing with IPv4 and IPv6 address, the struct sockaddr allows to hold IPv4 and IPv6. However even when struct sockaddr is being used, a cast to the IPv4 or IPv6 family must happen. To work around this additional code, use a union for the most common types. Change-Id: If80172373735193401af872b18e1ff00c93880e7
2020-03-10socket: Add osmo_sock_mcast_iface_set() to bind multicast to deviceHarald Welte1-0/+1
Change-Id: Ib52d22710020b56965aefcef09bde8247ace4a9c Related: OS#2966
2019-10-18socket: Introduce API osmo_sock_init2_multiaddr()Pau Espin Pedrol1-0/+7
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
2019-04-10Add _c versions of functions that otherwise return static buffersHarald Welte1-0/+1
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
2019-03-19socket: osmo_sock_get_name() Use "const void *" as talloc contextHarald Welte1-1/+1
Change-Id: Ie6877277cddb0a9e049449c260afe3314ba65050
2019-02-04socket.h: add missing includeMax1-2/+7
socket.h uses INET6_ADDRSTRLEN without including arpa/inet.h where it's defined which might break external users of socket.h Fix this by adding missing include. The error was introduced in 64b51eb68bd272b6b1f2cefa2b33e9dd74024d0c Change-Id: I2883addcb81cec038577e401e356e8f07a947d4c
2019-01-17socket: add define for socket name lengthPhilipp Maier1-0/+2
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
2018-12-19add to osmo_sock_get_name*() APINeels Hofmeyr1-0/+3
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
2018-12-07Add osmo_sockaddr_in_to_str_and_uint()Max1-0/+3
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
2018-10-26add osmo_sock_get_{local,remote}_ip{,_port}()Oliver Smith1-0/+6
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
2018-08-23socket: add flag to enforce SO_REUSEADDR on UDP socketsPhilipp Maier1-0/+2
When IPPROTO_UDP is used then SO_REUSEADDR omitted since UDP is connection less we do not have to wait until lingering connections time out. There were also negative effects such as that two applicatications could use the same UDP port, normally one of the two applications would get an error, but with SO_REUSEADDR this is supressed. However, there are applications (UDP MULTICAST) where two applications must be able to use the same port. In the osmocom project those are osmo-bts-virtual, virtphy and gsmtap in general. Lets introduce a flag that the API user can supply in order to have SO_REUSEADDR applied. - Add new flag OSMO_SOCK_F_UDP_REUSEADDR Change-Id: I94aaf6d5224ab23bde5ea5c4a83569b6145ab32b Related: OS#3497
2018-07-20add osmo_sockaddr_to_str_and_uint()Neels Hofmeyr1-0/+3
This came from osmo-bsc refactoring patch I82e3f918295daa83274a4cf803f046979f284366 https://gerrit.osmocom.org/#/c/osmo-bsc/+/9671/6/src/osmo-bsc/gsm_data.c@1708 Add regression test in utils_test.c. Change-Id: I1f2918418c38918c5ac70acaa51a47adfca12b5e
2017-10-23socket: add function osmo_sock_local_ip() to query local ipPhilipp Maier1-0/+2
In some cases it is required to know the ip-address of the interface through that a given remote IP-Address can be reached. Add function osmo_sock_local_ip() to determine the local ip-address for a given remote ip-address Change-Id: I2988cc52b196fc8476703d1287e24cb4a48491c2
2017-07-13socket: Add new OSMO_SOCK_F_NO_MCAST_ALL optionHarald Welte1-0/+2
Using this option at socket creation, the caller can request disabling the IP_MULTICAST_ALL socket option. Change-Id: I5ab5de45c0b64ceb3636ea98245a23defa24ffd4
2017-07-13socket: Allow disabling multicast loop on socket creationHarald Welte1-0/+2
This introduces a new flag OSMO_SOCK_F_NO_MCAST_LOOP, which can be used to disable the looping back of multicast packets transmitted throug this socket to other local sockets on the machine. As this looping-back is active by default, a single option to deviate from the default is deemed sufficient. Change-Id: I24a5b1ebc3f84d2d5d4734e54df50efaea26490b
2017-07-13socket.c: Add multicast related convenience functionsHarald Welte1-0/+6
Change-Id: Id703e7a7a1e065181a4c76c088b8dcc1b7fe15a2
2017-06-23doxygen: unify use of \file across the boardNeels Hofmeyr1-5/+4
Considering the various styles and implications found in the sources, edit scores of files to follow the same API doc guidelines around the doxygen grouping and the \file tag. Many files now show a short description in the generated API doc that was so far only available as C comment. The guidelines and reasoning behind it is documented at https://osmocom.org/projects/cellular-infrastructure/wiki/Guidelines_for_API_documentation In some instances, remove file comments and add to the corresponding group instead, to be shared among several files (e.g. bitvec). Change-Id: Ifa70e77e90462b5eb2b0457c70fd25275910c72b
2017-06-23doxygen: enable AUTOBRIEF, drop \briefNeels Hofmeyr1-1/+1
Especially for short descriptions, it is annoying to have to type \brief for every single API doc. Drop all \brief and enable the AUTOBRIEF feature of doxygen, which always takes the first sentence of an API doc as the brief description. Change-Id: I11a8a821b065a128108641a2a63fb5a2b1916e87
2017-05-26socket: Add osmo_sock_init2_ofd() functionPau Espin Pedrol1-0/+4
Will be used by osmo-bts-trx Change-Id: I3c655a4af64fb80497a5aaa811cce8005dba9cd9
2017-04-09Add osmo_sock_init2() function, allowing both BIND *and* CONNECTHarald Welte1-0/+4
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-01-27socket: Introduce function to obtain socket nameHarald Welte1-0/+2
Using this function, one can obtain a human-readable string identifying the host and port names of the socket. Change-Id: Ib5de5c7b9effe1b0a363e4473a7be7fa38ca6ef3
2016-05-05Update doxygen annotations in libosmocoreHarald Welte1-0/+3
This adds and improves doxygen API descriptions all over libosmocore, reducing the 'white spots' that don't have any documentation.
2014-06-16include: Switch to #pragma once patternSylvain Munaut1-4/+1
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2014-03-26src/socket: Adding unix domain socket supportÁlvaro Neira Ayuso1-0/+6
Added some function for adding the unix domain socket support. Signed-off-by: Alvaro Neira Ayuso <anayuso@sysmocom.de>
2012-04-18doc: Fix the Doxygen section endingsSylvain Munaut1-1/+1
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>