summaryrefslogtreecommitdiffstats
path: root/src/socket.c
Commit message (Collapse)AuthorAgeFilesLines
* osmo_sockaddr_is_local: Fix memleakPau Espin Pedrol2018-04-181-1/+4
| | | | | | | | | | | | | | | Catched by AddressSanitizer in osmo-bts-trx while running tests in osmo-gsm-tester: ==31738==ERROR: LeakSanitizer: detected memory leaks Direct leak of 5744 byte(s) in 1 object(s) allocated from: #0 0x7ff7ec789ed0 in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1ed0) #1 0x7ff7e952697c (/lib/x86_64-linux-gnu/libc.so.6+0x10297c) #2 0x7ff7e95274df in getifaddrs (/lib/x86_64-linux-gnu/libc.so.6+0x1034df) #3 0x7ff7eadcdc8f in osmo_sockaddr_is_local libosmocore/src/socket.c:537 Change-Id: I778d3c1f162abce0595e62670c29c5134bccd28d
* socket.c: osmo_sock_init: Several logic fixes and log improvementsPau Espin Pedrol2018-04-051-8/+16
| | | | | | See explanations in previous commit. Change-Id: I4889e777d8627fdfb52c97ab3ab353b6ed34aab2
* socket.c: osmo_sock_init2: connect: Several logic fixes and log improvementsPau Espin Pedrol2018-04-051-8/+17
| | | | | | See explanations in previous commits. Change-Id: Ib2f7577b9f498ae9d388ed1f79f6ca0ec6f09664
* socket.c: osmo_sock_init2: bind: Several logic fixes and log improvementsPau Espin Pedrol2018-04-051-7/+19
| | | | | | | | | | | | | | | | | | | | | | | After investigating osmo-msc showing this log message and looking at the code, it's a bit difficult to find out what's going on in the code: socket.c:224 unable to bind socket: (null):0: Protocol not supported The root cause was not yet found, but probably SCTP is not enabled in the kernel of the host running it. The cod eis most probably failing during socket() and not due to bind error as the log says, so let's print an error if socket() fails. Then, if setsockopt fails, we want to still keep trying in case an extra addr was offered by addrinfo_helper. It is definetly wrong to continue if setsockopt fails, because then we are skipping the bind(), which is a fundamental part of what osmo_sock_init2 does. Then, let's print the bind error when it really happens, and re-write the extra log at the end if we reach the point at which no suitable addr is found. Change-Id: I1854422ad92dadf33ed4d849e15c0380c3bf1626
* socket: use inet_ntop() instead of inet_ntoa() in osmo_sock_local_ip()Philipp Maier2018-01-221-2/+2
| | | | | | | | | | | | | | | The function inet_ntoa() stores its result in a static buffer and returns the pointer. When inet_ntoa() is called subsequently it overwrite the content of its static buffer with the new result. Since we osmo_sock_local_ip() is a library function we should use the more safe variant inet_ntop() in order to prevent unintentionally overwriting data that the caller might still need. Such an error would be hard to find. - Use the more safe inet_ntop() inestead of inet_ntoa() Change-Id: I9852b57736432032542bd96b6fdd4a2f08fc1f64
* socket: fix socket leak in osmo_sock_local_ip()Philipp Maier2018-01-221-0/+1
| | | | | | | | | The socket that is opend to probe the correct local ip-address is not closed when the test is done. - Close socket when it is not needed anymore Change-Id: I7f3562a344b58f6298d2068314be1626a96e1b1d
* Fix/Update copyright notices; Add SPDX annotationHarald Welte2017-11-131-0/+2
| | | | | | | | Let's fix some erroneous/accidential references to wrong license, update copyright information where applicable and introduce a SPDX-License-Identifier to all files. Change-Id: I39af26c6aaaf5c926966391f6565fc5936be21af
* socket: add function osmo_sock_local_ip() to query local ipPhilipp Maier2017-10-231-0/+53
| | | | | | | | | | 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
* osmo_sock_init2(): Fix creation of non-bound socketsHarald Welte2017-07-211-1/+1
| | | | | | | | | If osmo_sock_init2() was used with CONNECT flag but without BIND flag, an invalid check for "did we create a socket yet" caused the socket to never be created, and subsequently the entire function to return an error. Change-Id: I0206dbb9c5b8f74d7fb088576941b092acd2ca22
* socket: Add new OSMO_SOCK_F_NO_MCAST_ALL optionHarald Welte2017-07-131-0/+10
| | | | | | | Using this option at socket creation, the caller can request disabling the IP_MULTICAST_ALL socket option. Change-Id: I5ab5de45c0b64ceb3636ea98245a23defa24ffd4
* socket: Allow disabling multicast loop on socket creationHarald Welte2017-07-131-4/+16
| | | | | | | | | | | 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
* socket: Unify listen() calls and check for erroneous returnsHarald Welte2017-07-131-20/+33
| | | | | | | | | We had three places at the end of socket initialization functions calling listen(). Let's unify that and fix some bugs: * close + return error in case of bad listen() result * don't call listen() on AF_UNIX SOCK_DGRAM sockets Change-Id: I7e8dbe3c0486bb3b9810b0add1331e93fc106d82
* socket.c: Add multicast related convenience functionsHarald Welte2017-07-131-0/+135
| | | | Change-Id: Id703e7a7a1e065181a4c76c088b8dcc1b7fe15a2
* osmo_sock_get_name(): clearly indicate local and remoteNeels Hofmeyr2017-07-031-2/+2
| | | | | | | | | | | | | | | | 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
* doxygen: unify use of \file across the boardNeels Hofmeyr2017-06-231-4/+3
| | | | | | | | | | | | | | | | | 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
* doxygen: enable AUTOBRIEF, drop \briefNeels Hofmeyr2017-06-231-11/+11
| | | | | | | | | | 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
* update/extend doxygen documentationHarald Welte2017-06-121-3/+2
| | | | | | | | | It's a pity that even with this patch we still are fare away from having the whole API documented. However, at least we have a more solid foundation. Updates not only extend the documentation, but also make sure it is rendered properly in the doxygen HTML. Change-Id: I1344bd1a6869fb00de7c1899a8db93bba9bafce3
* socket: Add osmo_sock_init2_ofd() functionPau Espin Pedrol2017-05-261-0/+23
| | | | | | Will be used by osmo-bts-trx Change-Id: I3c655a4af64fb80497a5aaa811cce8005dba9cd9
* Add osmo_sock_init2() function, allowing both BIND *and* CONNECTHarald Welte2017-04-091-33/+187
| | | | | | | | | 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
* cosmetic: replace fprintf with LOGPPhilipp Maier2017-02-091-8/+12
| | | | | | | socket.c still uses fprintf to output error messages. This commit replaces the fprintf with proper LOGP messages. Change-Id: Ia2993415d5f5c33ccd719af239ff59252d11b764
* socket: Introduce function to obtain socket nameHarald Welte2017-01-271-1/+43
| | | | | | | Using this function, one can obtain a human-readable string identifying the host and port names of the socket. Change-Id: Ib5de5c7b9effe1b0a363e4473a7be7fa38ca6ef3
* osmo_sock_init(): Fix memory leak in error pathHarald Welte2016-11-261-0/+1
| | | | | | | We forgot to call freeaddrinfo() in an error path. Change-Id: Iccbd3beef4c4a70dc443131b909c45e650d8c6a2 Fixes: Coverity CID 135217
* fix printf format for commit 'osmo_sock_init(): include host and port in ↵Neels Hofmeyr2016-08-291-1/+1
| | | | | | | error messages' Related: CID#143566 Change-Id: I75c542089749a0875d3d1913151fe838d7722ff2
* osmo_sock_init(): include host and port in error messagesNeels Hofmeyr2016-08-271-5/+16
| | | | | | | | | | | For programs like osmo-hnbgw with numerous sockets, the message that some unspecified connection was refused is not very helpful. Also output the host and port where an error occured. Instead of perror, use fprintf(stderr, ..., strerror()) to be able to include a format string and print host and port as passed to osmo_sock_init(). Change-Id: I8d0343f51310699b78fcb83fd76fd93764acf3dc
* Update doxygen annotations in libosmocoreHarald Welte2016-05-051-0/+6
| | | | | This adds and improves doxygen API descriptions all over libosmocore, reducing the 'white spots' that don't have any documentation.
* Move common socket routine into separate functionMax2014-10-131-29/+24
| | | | Signed-off-by: Max <max.suraev@fairwaves.co>
* add missing copyright statements to source code filesHarald Welte2014-09-111-0/+21
| | | | | | Some source code files didn't have the usual copyright and licence statement at their top. I'm adding them baesed on information in the commitlog.
* src/socket: Adding unix domain socket supportÁlvaro Neira Ayuso2014-03-261-0/+102
| | | | | | Added some function for adding the unix domain socket support. Signed-off-by: Alvaro Neira Ayuso <anayuso@sysmocom.de>
* misc: Doxygen tweaks: fixed some typos and minor errorsKaterina Barone-Adesi2013-02-151-1/+1
| | | | | Doxygen generates quite a lot of warnings on libosmocore. Some of them are obvious typos - this patch aims to fix such low-hanging fruit.
* socket: fix osmo_sock_init with SOCK_RAW and IPPROTO_RAWPablo Neira Ayuso2013-01-151-3/+16
| | | | | | | | | | | | | getaddrinfo returns EAI_SERVICE (-8) if that combination is used. More information available in here: http://sourceware.org/bugzilla/show_bug.cgi?id=15015 Reported by Holger Hans Peter Freyther. While at it, this patch also removes hints.ai_flags = 0 as memset to zero already happened just a bit before that.
* doc: Fix the Doxygen section endingsSylvain Munaut2012-04-181-1/+1
| | | | Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
* sync prototype of osmo_sockaddr_is_local with declarationHarald Welte2012-04-081-1/+1
| | | | | in e476442cf0e84c65565ace545f5b73602b5f0ffc we changed from sockle_t to unsigned int, but only in the header, not in the implementation!
* freebsd: Fixes for the compilation of libosmocore on FreeBSDHolger Hans Peter Freyther2011-11-091-0/+2
| | | | | | | | | | | alloca.h is not available on FreeBSD, use the default autoconf function to check for it, there is a complete list[1] of what to do for using alloca but let us see how far we get with this test. Include netinet/in.h for the IPv4 and IPv6 socket address. Check for dlopen in libraries and use this instead of linking -dl. [1] http://www.gnu.org/s/hello/manual/autoconf/Particular-Functions.html
* some more doxygen work (include the notion of modules)Harald Welte2011-08-171-1/+48
|
* socket: add OSMO_SOCK_F_[CONNECT|BIND|NON_BLOCK] flagsPablo Neira Ayuso2011-06-131-10/+28
| | | | | | | | This extends the socket infrastructure in libosmocore to allow to create non-blocking sockets. Basically, it replaces the connect0_bind1 parameter by one flags parameter.
* socket: getaddrinfo(): set AI_PASSIVE if we want to bindHarald Welte2011-05-311-0/+3
| | | | This will tell getaddrinfo() that we want a INADDR_ANY style socket
* socket: remove unused IPv4 related header includesHarald Welte2011-05-291-2/+0
|
* socket: Skip ifa's without ifa->ifa_addrHarald Welte2011-05-241-0/+2
| | | | Apparently getifaddrs() returns ifa's without an ifa_addr set.
* socket: use listen() and SO_REUSEADDR, new osmo_sock_init_ofd() functionHarald Welte2011-05-221-1/+34
| | | | | | osmo_sock_init_ofd() is a wrapper around osmo_sock_init() which will take care of initializing and registering a 'struct osmo_fd' for the newly-created socket.
* remove debug printf from socket.cHarald Welte2011-05-221-1/+0
|
* GSMTAP/socket code: Check for sys/socket.h and conditionally compileHarald Welte2011-05-221-1/+5
|
* gsmtap: rework GSMTAP API to be more future-proofHarald Welte2011-05-221-0/+143
* use write_queue where applicable * provide functions that work on raw FD and those with osmo_fd * add support for multiple gsmtap instances (no global variables)