aboutsummaryrefslogtreecommitdiff
path: root/src/socket.c
AgeCommit message (Collapse)AuthorFilesLines
2022-03-04socket: Handle ECONNABORTED from recvRich1-2/+2
recv can return ECONNABORTED due to a time-out on the socket. The socket is no longer useable once it enters this state.
2022-02-11Rename insque/remque -> slirp_[ins|rem]queBrett Nash1-6/+6
Avoid a macro translation when not needed, and potentially doing really weird things to headers.
2022-02-10mbuf: Use SLIRP_DEBUG to enable mbuf debugging instead of DEBUG Brett Nash1-1/+1
DEBUG is set by a number of IDEs and development environments (*cough* xcode *cough*). This means we use mbuf duplication when we don't need (or expect) it. Change the name to SLIRP_DEBUG to enable this feature. Signed-off-by: Pablo Fiori <pablofiori@fb.com> Signed-off-by: Brett Nash <nash@fb.com>
2021-12-12Drop fixed TODOSamuel Thibault1-1/+0
2021-11-30socket: Move closesocket(so->s_aux) to sofreeNicholas Ngai1-0/+4
Signed-off-by: Nicholas Ngai <nicholas@ngai.me>
2021-11-29socket: Check so_type instead of so_tcpcb for Unix-to-inet translationNicholas Ngai1-3/+22
Signed-off-by: Nicholas Ngai <nicholas@ngai.me>
2021-11-29Merge branch 'master' into hostfwd-unixNicholas Ngai1-2/+3
Signed-off-by: Nicholas Ngai <nicholas@ngai.me>
2021-11-29socket: Add s_aux field to struct socket for storing auxilliary socketNicholas Ngai1-2/+3
Signed-off-by: Nicholas Ngai <nicholas@ngai.me>
2021-11-29socket: Initialize so_type in socreateNicholas Ngai1-2/+3
Signed-off-by: Nicholas Ngai <nicholas@ngai.me>
2021-11-27socket: Allocate Unix-to-TCP hostfwd port from OS by binding to port 0Nicholas Ngai1-4/+73
Signed-off-by: Nicholas Ngai <nicholas@ngai.me>
2021-10-12socket: Check address family for Unix-to-inet accept translationNicholas Ngai1-3/+11
Signed-off-by: Nicholas Ngai <nicholas@ngai.me>
2021-10-12socket: Add debug args for tcpx_listen (inet and Unix sockets)Nicholas Ngai1-0/+33
Signed-off-by: Nicholas Ngai <nicholas@ngai.me>
2021-09-27Support Unix sockets in hostfwdNicholas Ngai1-12/+7
QEMU has an issue open (https://gitlab.com/qemu-project/qemu/-/issues/347) to forward a Unix domain socket to guest TCP port. Both of these protocols support stream modes of operation (and user-mode networking can only access the stream anyway), so this patch enables Unix-to-TCP hostfwds. Like with localhost hostfwds, the sotranslate_accept function will translate a Unix domain socket connection to a TCP connection originating from vhost_addr and a randomized ephemeral port. Signed-off-by: Nicholas Ngai <nicholas@ngai.me>
2021-04-12Merge branch 'lazy-ipv6-resolution' into 'master'Samuel Thibault1-0/+81
Perform lazy guest address resolution for IPv6 See merge request slirp/libslirp!81
2021-04-12Perform lazy guest address resolution for IPv6Doug Evans1-0/+81
Previously QEMU rejected IPv6 host-forward attempts that had an unspecified guest address. This is because for IPv6 the guest's IP address isn't necessarily known ahead of time: Libslirp only provides a "stateless" DHCPv6 server, which if the macaddr is random then the IPv6 address is random too. This patch changes this to do the address resolution lazily, in the hopes that the guest's IPv6 address is known at the time the user wants to connect to the guest. The request can still fail if the guest doesn't have an IPv6 address yet (e.g., it's still early in the boot). Such requests are immediately rejected. Signed-off-by: Doug Evans <dje@google.com>
2021-04-07Merge branch 'listen_v6only' into 'master'Samuel Thibault1-0/+1
Listen v6only See merge request slirp/libslirp!77
2021-04-06Merge branch 'newtcpcb-no-fail' into 'master'Samuel Thibault1-4/+1
tcpx_listen: tcp_newtcpcb doesn't fail See merge request slirp/libslirp!79
2021-04-06slirp_add_host*fwd: Ensure all error paths set errnoDoug Evans1-0/+1
Debugging bind/listen failures without errno can get painful. Signed-off-by: Doug Evans <dje@google.com>
2021-03-29tcpx_listen: tcp_newtcpcb doesn't failDoug Evans1-4/+1
Signed-off-by: Doug Evans <dje@google.com>
2021-03-29Remove slirp_add/remove_ipv6_hostfwdSamuel Thibault1-19/+0
They are superseded by slirp_add/remove_hostxfwd Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
2021-03-17hostfwd: Add SLIRP_HOSTFWD_V6ONLY flagSamuel Thibault1-0/+1
That allows to request binding on v6 addresses only. Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
2021-03-05udpx/tcpx_listen: Use struct sockaddr * typesSamuel Thibault1-10/+11
This actually makes most of the code simpler.
2021-03-01udpx/tcpx_listen: Add missing const qualifierSamuel Thibault1-7/+7
2021-02-28Expose udpx_listen and tcpx_listen as taking sockaddrSamuel Thibault1-53/+43
This generalizes adding hostfwd, and opens the path for cross ipv4/6 forward. Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
2021-02-28TODO for generalizing the hostfwd callsSamuel Thibault1-0/+2
2021-02-11tcpx_listen: Pass sizeof(addr) to memsetDoug Evans1-2/+2
Signed-off-by: Doug Evans <dje@google.com>
2021-02-03Add ipv6 host forward supportDoug Evans1-26/+66
Two exported functions are added which are the ipv6 versions of their ipv4 counterparts: slirp_add_ipv6_hostfwd, slirp_remove_ipv6_hostfwd. Signed-off-by: Doug Evans <dje@google.com>
2020-12-01Merge branch 'consume-empty-packet' into 'master'Samuel Thibault1-3/+0
socket: consume empty packets See merge request slirp/libslirp!55
2020-12-01socket: consume empty packetsGiuseppe Scrivano1-3/+0
it fixes a tightloop when a packet with len==0 is received. Closes: https://github.com/rootless-containers/slirp4netns/issues/227 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-11-27Merge branch 'errors' into 'master'Samuel Thibault1-1/+59
Enable forwarding ICMP errors See merge request slirp/libslirp!49
2020-08-19sosendoob: better document what urgc is used forSamuel Thibault1-3/+4
2020-07-19udp, udp6, icmp, icmp6: Enable forwarding errors on LinuxSamuel Thibault1-1/+59
Not all icmp errors are reported as errno errors. Linux however lets us get them through a message error queue. Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
2020-06-01Remove unnecessary breakPhilippe Mathieu-Daudé1-3/+0
The code is unreachable, so no need to break. This silence static analyzer warnings. Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
2020-03-24limit vnameserver_addr to port 535eraph1-2/+2
Fixes #16 Signed-off-by: 5eraph <5eraph@protonmail.com>
2020-03-23disable_dns option5eraph1-2/+2
Fixes #16 Signed-off-by: 5eraph <5eraph@protonmail.com>
2020-03-17Revert "socket: remove need for extra scope_id variable"Marc-André Lureau1-1/+6
Oops, it turns out the variable is there for portability reasons. This reverts commit d65f3030a82743bf506b0611a6a1a0358ea5d52b. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-03-16socket: do not fallback on loopback addr for addresses in our mask/prefixMarc-André Lureau1-16/+12
Currently, any address within the subnetwork will fallback on loopback. It seems it has always been like that, but it seems wrong, and I don't see a good reason to keep it this way. Fortunately, lack of ARP reply made this unusable in practice, so we shouldn't break much existing users. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-03-16socket: do not fallback on host loopback if get_dns_addr() failedMarc-André Lureau1-6/+2
Somewhat related to #16, but not as restrictive. (imho, it should be possible to access any port on the given DNS IP, not just 53) Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-03-16socket: remove need for extra scope_id variableMarc-André Lureau1-3/+1
The value is only set on success. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-03-16socket: factor out sotranslate ipv4/ipv6 handlingMarc-André Lureau1-42/+54
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-03-16socket: remove extra label and variableMarc-André Lureau1-9/+6
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-12-01Merge branch 'mem-cleanups' into 'master'Marc-André Lureau1-1/+1
Mem cleanups See merge request slirp/libslirp!20
2019-11-22Merge branch 'broadcast' into 'master'Samuel Thibault1-0/+6
Make host receive broadcast packets Closes #9 See merge request slirp/libslirp!15
2019-11-21Replace remaining malloc/free user with glibMarc-André Lureau1-1/+1
glib mem functions are already used in various places. Let's not mix the two, and instead abort on OOM conditions. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2019-11-21socket: avoid getpeername after shutdown(SHUT_WR)Giuseppe Scrivano1-1/+3
avoid using getpeername(2) if the socket was already closed for writing, as it will report the socket as disconnected. Using getsockopt instead ensures there is no error returned. Closes: https://gitlab.freedesktop.org/slirp/libslirp/issues/12 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-13Make host receive broadcast packetsSamuel Thibault1-0/+6
This is needed for using an external DHCP server Fixes #9
2019-08-01add disable_host_loopback (prohibit connections to 127.0.0.1)Akihiro Suda1-10/+20
From https://github.com/rootless-containers/slirp4netns/blob/4889f5299f407d7d7566c76a3b8b5f71c99b6db5/qemu_patches/0003-slirp-add-disable_host_loopback-prohibit-connections.patch Original commits: * https://github.com/rootless-containers/slirp4netns/commit/6325473781bb344c225f54e2d28800fb0619d7ee * https://github.com/rootless-containers/slirp4netns/commit/13b24026867d4c30d5d1465ac82e3bb890bf4caa Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2019-04-15Gcc 9 -O3 fixDr. David Alan Gilbert1-1/+4
Gcc 9 needs some convincing that sopreprbuf really is going to fill in iov in the call from soreadbuf, even though the failure case shouldn't happen. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Message-Id: <20190415121740.9881-1-dgilbert@redhat.com> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
2019-03-22slirp: remove reference to COPYRIGHT fileMarc-André Lureau1-3/+0
The slirp COPYRIGHT file is a BSD-3 license. Instead of referring to another project file, the SPDX license notice present in all source files states that unequivocally. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
2019-03-22slirp: clarify license of slirp files using SPDX: implicit via COPYRIGHTMarc-André Lureau1-0/+1
Add SPDX license identifier to clarify the license of files with reference to BSD license from slirp COPYRIGHT file. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com>