summaryrefslogtreecommitdiff
path: root/lib/kernel/src/inet_int.hrl
Commit message (Collapse)AuthorAgeFilesLines
* [erts, kernel] reuseaddr/reuseport/exclusiveaddruse support/fixesRickard Green2023-02-021-0/+3
| | | | | | | | | | | | | | | * Introduce socket option 'reuseport' which may or may not have load balancing. * Introduce socket option 'reuseport_lb' with load balancing. * Introduce socket option 'exclusiveaddruse'. This socket option is Windows specific and will silently be ignored on other systems. * Change behavior on Windows so that SO_REUSEADDR is only set if both 'reusaddr' and 'reuseport' have been set. This since SO_REUSEADDR on Windows behaves as BSD behaves if both SO_REUSEADDR and SO_REUSEPORT have been set.
* [erts|preloaded] Add handling debug optionMicael Karlberg2022-05-181-0/+1
| | | | OTP-18032
* Update copyright yearErlang/OTP2022-03-231-1/+1
|
* Code cleanupRaimo Niskanen2022-03-011-8/+13
| | | | | | | | | | | | | | | | | | | | | | | | Re-use and restructure type checking functions in prim_inet. Fix a bug in gen_sctp:connect that did not handle port number as a service name correctly. Align gen_sctp:connectx_init more with gen_udp:send that is one of the few functions to handle different kinds of addresses, for SockAddr style addresses. Drop the combination of SockAddrs and Timeout since it is not meaningful. The Timeout is only used for address lookup and SockAddrs are already looked up. Fix the type spec for connecx_init to show that Port can be a Service. Clean up the code that enforces the same port number in all addresses to be more efficient. Write a dedicated function loop to look up addresses instead of using throw() from a lists:map/2.
* Introduce gen_sctp:connectx_init/* for initiating multi-homedSimon Cornish2022-03-011-0/+1
| | | | SCTP connections using sctp_connectx(3)
* [kernel|gen-udp-socket] Add socket based gen_udpMicael Karlberg2021-07-291-1/+1
| | | | | | First stage of the 'socket' based gen_udp. OTP-17410
* Improve handling of when to bindRaimo Niskanen2021-05-271-1/+0
|
* Improve handling of when to bindRaimo Niskanen2021-05-271-4/+12
|
* inet_tcp, inet6_tcp: do not bind connecting sockets by defaultMaxim Fedorov2021-01-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There is no need to bind a socket intended to be used for outgoing connection. This operation exhaust ephemeral port range, preventing large number of concurrent outgoing connections. Omitting bind call also saves an extra trip to kernel. There is no reliable way to test this, as different platforms have various limitations on number of file descriptors open, ephemeral port count and socket allocation mechanisms. Manual testing can be done using this code: verify(0) -> ok; verify(Remain) -> receive {result, {error, Good}} when Good =:= timeout; Good =:= econnrefused -> verify(Remain - 1); {result, Any} -> Any end. test_conn() -> Self = self(), Expect = 32000, %% this number is guaranteed to be larger than ephemeral port count [spawn( fun() -> Res = catch (gen_tcp:connect( {10, 20, (Seq div 254 + 1) rem 254, Seq rem 254 + 1}, 12345, [], 5000)), Self ! {result, Res} end) || Seq <- lists:seq(1, Expect)], verify(Expect). To run this code, system must be configured for high file descriptor limit (e.g."ulimit -n 100000").
* Add nopush TCP socket optionIgor Slepchin2018-10-111-0/+1
| | | | | | | | | | | This translates to TCP_CORK on Linux and TCP_NOPUSH on BSD. In effect, this acts as super-Nagle: no partial TCP segments are sent out until this option is turned off. Once turned off, all accumulated unsent data is sent out immediately. The latter is *not* the case on OSX, hence the implementation ignores "nopush" on OSX to reduce confusion.
* Implement socket option recvtos and friendsRaimo Niskanen2018-09-041-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implement socket options recvtclass, recvtos, recvttl and pktoptions. Document the implemented socket options, new types and message formats. The options recvtclass, recvtos and recvttl are boolean options that when activated (true) for a socket will cause ancillary data to be received through recvmsg(). That is for packet oriented sockets (UDP and SCTP). The required options for this feature were recvtclass and recvtos, and recvttl was only added to test that the ancillary data parsing handled multiple data items in one message correctly. These options does not work on Windows since ancillary data is not handled by the Winsock2 API. For stream sockets (TCP) there is no clear connection between a received packet and what is returned when reading data from the socket, so recvmsg() is not useful. It is possible to get the same ancillary data through a getsockopt() call with the IPv6 socket option IPV6_PKTOPTIONS, on Linux named IPV6_2292PKTOPTIONS after the now obsoleted RFC where it originated. (unfortunately RFC 3542 that obsoletes it explicitly undefines this way to get packet ancillary data from a stream socket) Linux also has got a way to get packet ancillary data for IPv4 TCP sockets through a getsockopt() call with IP_PKTOPTIONS, which appears to be Linux specific. This implementation uses a flag field in the inet_drv.c socket internal data that records if any setsockopt() call with recvtclass, recvtos or recvttl (IPV6_RECVTCLASS, IP_RECVTOS or IP_RECVTTL) has been activated. If so recvmsg() is used instead of recvfrom(). Ancillary data is delivered to the application by a new return tuple format from gen_udp:recv/2,3 containing a list of ancillary data tuples [{tclass,TCLASS} | {tos,TOS} | {ttl,TTL}], as returned by recvmsg(). For a socket in active mode a new message format, containing the ancillary data list, delivers the data in the same way. For gen_sctp the ancillary data is delivered in the same way, except that the gen_sctp return tuple format already contained an ancillary data list so there are just more possible elements when using these socket options. Note that the active mode message format has got an extra tuple level for the ancillary data compared to what is now implemented gen_udp. The gen_sctp active mode format was considered to be the odd one - now all tuples containing ancillary data are flat, except for gen_sctp active mode. Note that testing has not shown that Linux SCTP sockets deliver any ancillary data for these socket options, so it is probably not implemented yet. Remains to be seen what FreeBSD does... For gen_tcp inet:getopts([pktoptions]) will deliver the latest received ancillary data for any activated socket option recvtclass, recvtos or recvttl, on platforms where IP_PKTOPTIONS is defined for an IPv4 socket, or where IPV6_PKTOPTIONS or IPV6_2292PKTOPTIONS is defined for an IPv6 socket. It will be delivered as a list of ancillary data items in the same way as for gen_udp (and gen_sctp). On some platforms, e.g the BSD:s, when you activate IP_RECVTOS you get ancillary data tagged IP_RECVTOS with the TOS value, but on Linux you get ancillary data tagged IP_TOS with the TOS value. Linux follows the style of RFC 2292, and the BSD:s use an older notion. For RFC 2292 that defines the IP_PKTOPTIONS socket option it is more logical to tag the items with the tag that is the item's, than with the tag that defines that you want the item. Therefore this implementation translates all BSD style ancillary data tags to the corresponding Linux style data tags, so the application will only see the tags 'tclass', 'tos' and 'ttl' on all platforms.
* Reimplement efile_drv as a dirty NIFJohn Högberg2017-11-301-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This improves the latency of file operations as dirty schedulers are a bit more eager to run jobs than async threads, and use a single global queue rather than per-thread queues, eliminating the risk of a job stalling behind a long-running job on the same thread while other async threads sit idle. There's no such thing as a free lunch though; the lowered latency comes at the cost of increased busy-waiting which may have an adverse effect on some applications. This behavior can be tweaked with the +sbwt flag, but unfortunately it affects all types of schedulers and not just dirty ones. We plan to add type-specific flags at a later stage. sendfile has been moved to inet_drv to lessen the effect of a nasty race; the cooperation between inet_drv and efile has never been airtight and the socket dying at the wrong time (Regardless of reason) could result in fd aliasing. Moving it to the inet driver makes it impossible to trigger this by closing the socket in the middle of a sendfile operation, while still allowing it to be aborted -- something that can't be done if it stays in the file driver. The race still occurs if the controlling process dies in the short window between dispatching the sendfile operation and the dup(2) call in the driver, but it's much less likely to happen now. A proper fix is in the works. -- Notable functional differences: * The use_threads option for file:sendfile/5 no longer has any effect. * The file-specific DTrace probes have been removed. The same effect can be achieved with normal tracing together with the nif__entry/nif__return probes to track scheduling. -- OTP-14256
* Update copyright yearRaimo Niskanen2017-05-041-1/+1
|
* implement SO_BINDTODEVICE for inet protocolsAndreas Schultz2017-04-201-0/+1
| | | | | | | bind to device is needed to properly support VRF-Lite under Linux (see [1] for details). [1]: https://www.kernel.org/doc/Documentation/networking/vrf.txt
* Implement IPV6_TCLASSRaimo Niskanen2016-09-121-0/+1
|
* Remove internal state BOUND from inet_drvRaimo Niskanen2016-06-081-0/+1
|
* Rewrite inet* for address family 'local'Raimo Niskanen2016-06-011-3/+0
|
* Rewrite inet_drv for AF_LOCALRaimo Niskanen2016-06-011-1/+2
|
* Assign externally open fd to gen_tcp (UDS support)Serge Aleynikov2016-01-121-1/+5
| | | | | | | | | | | When a AF_LOCAL file descriptor is created externally (e.g. Unix Domain Socket) and passed to `gen_tcp:listen(0, [{fd, FD}])`, the implementation incorrectly assigned the address family to be equal to `inet`, which in the inet_drv driver translated to AF_INET instead of AF_LOCAL (or AF_UNIX), and an `einval` error code was returned. This patch fixes this problem such that the file descriptors of the `local` address family are supported in the inet:fdopen/5, gen_tcp:connect/3, gen_tcp:listen/2, gen_udp:open/2 calls
* erts: Add {line_delimiter, byte()} option to inet:setopts/2Serge Aleynikov2015-10-261-0/+1
| | | | | | | | | A new {line_delimiter, byte()} option allows line-oriented TCP-based protocols to use a custom line delimiting character. It is to be used in conjunction with {packet, line}. This option also works with erlang:decode_packet/3 when its first argument is 'line'.
* Change license text to APLv2Bruce Yinhe2015-06-181-10/+11
|
* Add 'show_econnreset' TCP socket optionRory Byrne2015-06-091-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | An ECONNRESET is a socket error which tells us that a TCP peer has sent an RST. The RST indicates that they have aborted the connection and that the payload we have received should not be considered complete. Up until now, the implementation of TCP in inet_drv.c has hidden the receipt of the RST from the user, treating it as though it was just a FIN terminating the read side of the socket. There are many cases where user code needs to be able to distinguish between a socket that was closed normally and one that was aborted. Setting the option {show_econnreset, true} enables the user to receive ECONNRESET errors on both active and passive sockets. A connected socket returned from gen_tcp:accept/1 will inherit the show_econnreset setting of the listening socket. By default this option is set to {show_econnreset, false}. Note that this patch only enables the reporting of ECONNRESET when the socket is being read from. It does not report ECONNRESET (or EPIPE) when the user tries to write to a connection when an RST has already been received. Currently the TCP implementation in inet_drv.c hides all such send errors from the user in favour of returning {error, close}. A separate patch will be needed to enable the reporting of such errors.
* Merge branch 'maint'Raimo Niskanen2013-11-261-0/+2
|\ | | | | | | | | | | Conflicts: erts/preloaded/ebin/prim_inet.beam lib/kernel/test/gen_sctp_SUITE.erl
| * Implement prim_inet:socknames/1,2 and prim_inet:peernames/1,2Raimo Niskanen2013-11-071-0/+2
| |
* | add {active,N} socket option for TCP, UDP, and SCTPSteve Vinoski2013-09-231-0/+1
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add the {active,N} socket option, where N is an integer in the range -32768..32767, to allow a caller to specify the number of data messages to be delivered to the controlling process. Once the socket's delivered message count either reaches 0 or is explicitly set to 0 with inet:setopts/2 or by including {active,0} as an option when the socket is created, the socket transitions to passive ({active, false}) mode and the socket's controlling process receives a message to inform it of the transition. TCP sockets receive {tcp_passive,Socket}, UDP sockets receive {udp_passive,Socket} and SCTP sockets receive {sctp_passive,Socket}. The socket's delivered message counter defaults to 0, but it can be set using {active,N} via any gen_tcp, gen_udp, or gen_sctp function that takes socket options as arguments, or via inet:setopts/2. New N values are added to the socket's current counter value, and negative numbers can be used to reduce the counter value. Specifying a number that would cause the socket's counter value to go above 32767 causes an einval error. If a negative number is specified such that the counter value would become negative, the socket's counter value is set to 0 and the socket transitions to passive mode. If the counter value is already 0 and inet:setopts(Socket, [{active,0}]) is specified, the counter value remains at 0 but the appropriate passive mode transition message is generated for the socket. This commit contains a modified preloaded prim_inet.beam due to changes in prim_inet.erl. Add tests for {active,N} mode for TCP, UDP, and SCTP sockets. Add documentation for {active,N} mode for inet, gen_tcp, gen_udp, and gen_sctp.
* Implement emulator netns support for TCP and UDPRaimo Niskanen2013-07-171-0/+1
|
* Update copyright yearsBjörn-Egil Dahlberg2013-06-121-1/+1
|
* Make high_msgq_watermark and low_msgq_watermark generic inet optionsRickard Green2013-05-061-2/+2
|
* Merge branch 'rickard/port-optimizations/OTP-10336' into ↵Rickard Green2012-12-071-0/+2
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | rickard/r16/port-optimizations/OTP-10336 * rickard/port-optimizations/OTP-10336: Change annotate level for emacs-22 in cerl Update etp-commands Add documentation on communication in Erlang Add support for busy port message queue Add driver callback epilogue Implement true asynchronous signaling between processes and ports Add erl_drv_[send|output]_term Move busy port flag Use rwlock for driver list Optimize management of port tasks Improve configuration of process and port tables Remove R9 compatibility features Use ptab functionality also for ports Prepare for use of ptab functionality also for ports Atomic port state Generalize process table implementation Implement functionality for delaying thread progress from unmanaged threads Conflicts: erts/doc/src/erl_driver.xml erts/doc/src/erlang.xml erts/emulator/beam/beam_bif_load.c erts/emulator/beam/beam_bp.c erts/emulator/beam/beam_emu.c erts/emulator/beam/bif.c erts/emulator/beam/copy.c erts/emulator/beam/erl_alloc.c erts/emulator/beam/erl_alloc.types erts/emulator/beam/erl_bif_info.c erts/emulator/beam/erl_bif_port.c erts/emulator/beam/erl_bif_trace.c erts/emulator/beam/erl_init.c erts/emulator/beam/erl_message.c erts/emulator/beam/erl_port_task.c erts/emulator/beam/erl_process.c erts/emulator/beam/erl_process.h erts/emulator/beam/erl_process_lock.c erts/emulator/beam/erl_trace.c erts/emulator/beam/export.h erts/emulator/beam/global.h erts/emulator/beam/io.c erts/emulator/sys/unix/sys.c erts/emulator/sys/vxworks/sys.c erts/emulator/test/port_SUITE.erl erts/etc/unix/cerl.src erts/preloaded/ebin/erlang.beam erts/preloaded/ebin/prim_inet.beam erts/preloaded/src/prim_inet.erl lib/hipe/cerl/erl_bif_types.erl lib/kernel/doc/src/inet.xml lib/kernel/src/inet.erl
| * Add support for busy port message queueRickard Green2012-12-071-0/+2
| |
* | erts,kernel: Implement socket option ipv6_v6only in erlang codeRaimo Niskanen2012-10-311-1/+2
| |
* | kernel, erts: Remove bit8 option from inetBjörn-Egil Dahlberg2012-04-161-7/+0
|/
* Implement ignorefd for TCPLukas Larsson2011-12-011-0/+2
| | | | | | | | | | | | | | Ignore fd is a feature used by sendfile to temporarily remove all driver_select calls on that fd so that another driver can select on it. It also delays all actions which sends or receives data in that fd until in the fd is no longer ignored. Only the controlling_process should use the feature as it is otherwise possible that the ignore will never be cleaned up and hence create a memory leak in the driver. An ignored driver will not detect that an fd has been closed until it is unignored.
* erts,kernel: Implement gen_sctp:peeloff/2Raimo Niskanen2011-11-171-1/+2
|
* erts,kernel: Add type stream sockets to SCTPRaimo Niskanen2011-11-171-1/+2
|
* erts,kernel: Rename operations common to TCP and SCTPRaimo Niskanen2011-11-161-4/+6
|
* Implement basic inet:getifaddrs/0Raimo Niskanen2010-11-091-1/+2
|
* The R13B03 release.OTP_R13B03Erlang/OTP2009-11-201-0/+414