Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

systemd-udevd on managarm: part 3, socket work #1224

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions sysdeps/managarm/generic/ioctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#include <linux/cdrom.h>
#include <linux/input.h>
#include <linux/kd.h>
#include <linux/sockios.h>
#include <linux/usb/cdc-wdm.h>
#include <linux/vt.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <scsi/sg.h>
#include <sys/ioctl.h>

#include <bits/ensure.h>
Expand Down Expand Up @@ -505,6 +507,18 @@ int sys_ioctl(int fd, unsigned long request, void *arg, int *result) {
*result = resp.result();
return 0;
}
case SIOCETHTOOL:
mlibc::infoLogger() << "\e[35mmlibc: SIOCETHTOOL is a stub" << frg::endlog;
*result = 0;
return ENOSYS;
case SIOCGSKNS:
mlibc::infoLogger() << "\e[35mmlibc: SIOCGSKNS is a stub" << frg::endlog;
*result = 0;
return ENOSYS;
case SG_IO:
mlibc::infoLogger() << "\e[35mmlibc: SG_IO is a stub" << frg::endlog;
*result = 0;
return ENOSYS;
} // end of switch()

if (_IOC_TYPE(request) == 'E' && _IOC_NR(request) == _IOC_NR(EVIOCGVERSION)) {
Expand Down
55 changes: 54 additions & 1 deletion sysdeps/managarm/generic/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,15 @@ int sys_peername(
}
}

namespace {

std::array<std::pair<int, int>, 2> getsockopt_passthrough = {{
{SOL_SOCKET, SO_PROTOCOL},
{SOL_NETLINK, NETLINK_LIST_MEMBERSHIPS},
}};

}

int
sys_getsockopt(int fd, int layer, int number, void *__restrict buffer, socklen_t *__restrict size) {
SignalGuard sguard;
Expand Down Expand Up @@ -341,6 +350,49 @@ sys_getsockopt(int fd, int layer, int number, void *__restrict buffer, socklen_t
<< frg::endlog;
*(int *)buffer = 1;
return 0;
} else if (std::find(
getsockopt_passthrough.begin(),
getsockopt_passthrough.end(),
std::pair<int, int>{layer, number}
)
!= getsockopt_passthrough.end()) {
auto handle = getHandleForFd(fd);
if (!handle)
return EBADF;

size_t buffer_size = size ? *size : 0;

managarm::fs::GetSockOpt<MemoryAllocator> req(getSysdepsAllocator());
req.set_layer(layer);
req.set_number(number);
req.set_optlen(size ? *size : 0);

auto [offer, send_req, recv_resp, recv_buffer] = exchangeMsgsSync(
handle,
helix_ng::offer(
helix_ng::sendBragiHeadOnly(req, getSysdepsAllocator()),
helix_ng::recvInline(),
helix_ng::recvBuffer(buffer, buffer_size)
)
);
HEL_CHECK(offer.error());
HEL_CHECK(send_req.error());
HEL_CHECK(recv_resp.error());
HEL_CHECK(recv_buffer.error());

managarm::fs::SvrResponse<MemoryAllocator> resp(getSysdepsAllocator());
resp.ParseFromArray(recv_resp.data(), recv_resp.length());
if (resp.error() == managarm::fs::Errors::SUCCESS)
return 0;
else if (resp.error() == managarm::fs::Errors::ILLEGAL_OPERATION_TARGET)
return EINVAL;
else if (resp.error() == managarm::fs::Errors::ILLEGAL_ARGUMENT)
return EINVAL;
else if (resp.error() == managarm::fs::Errors::INVALID_PROTOCOL_OPTION)
return ENOPROTOOPT;
else
__ensure(resp.error() == managarm::fs::Errors::SUCCESS);
__builtin_unreachable();
} else {
mlibc::panicLogger() << "\e[31mmlibc: Unexpected getsockopt() call, layer: " << layer
<< " number: " << number << "\e[39m" << frg::endlog;
Expand All @@ -358,12 +410,13 @@ std::array<std::pair<int, int>, 5> setsockopt_readonly = {{
{SOL_SOCKET, SO_TYPE},
}};

std::array<std::pair<int, int>, 5> setsockopt_passthrough = {{
std::array<std::pair<int, int>, 6> setsockopt_passthrough = {{
{SOL_PACKET, PACKET_AUXDATA},
{SOL_SOCKET, SO_LOCK_FILTER},
{SOL_SOCKET, SO_BINDTODEVICE},
{SOL_IP, IP_PKTINFO},
{SOL_NETLINK, NETLINK_ADD_MEMBERSHIP},
{SOL_NETLINK, NETLINK_PKTINFO},
}};

std::array<std::pair<int, int>, 2> setsockopt_passthrough_noopt = {{
Expand Down
Loading