Skip to content

Commit

Permalink
Merge pull request #1276 from microsoft/enhancement-shim-sockopt
Browse files Browse the repository at this point in the history
[shim] Interpose `getsockopt()` and `setsockopt()`
  • Loading branch information
ppenna committed May 15, 2024
2 parents 4b1ed79 + eaa37c1 commit ffaf885
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
38 changes: 31 additions & 7 deletions shim/src/ctrl/getsockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../utils.h"
#include <demi/libos.h>
#include <errno.h>
#include <netinet/tcp.h>
#include <sys/socket.h>

/**
Expand Down Expand Up @@ -35,12 +36,35 @@ int __getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *op

TRACE("sockfd=%d, level=%d, optname=%d, optval=%p, optlen=%p", sockfd, level, optname, optval, (void *)optlen);

// TODO: Hook in demi_getsockopt().
UNUSED(level);
UNUSED(optname);
UNUSED(optval);
UNUSED(optlen);
UNIMPLEMETED("demi_getsockopt() is not hooked in");
// Issue warnings for common options that are not supported.
if (level == SOL_SOCKET && optname == SO_KEEPALIVE)
{
WARN("%s is not supported", "SO_KEEPALIVE");
}
else if (level == SOL_SOCKET && optname == SO_REUSEADDR)
{
WARN("%s is not supported", "SO_REUSEADDR");
}
else if (level == IPPROTO_TCP && optname == TCP_NODELAY)
{
WARN("%s is not supported", "TCP_NODELAY");
}
else if (level == IPPROTO_TCP && optname == TCP_KEEPIDLE)
{
WARN("%s is not supported", "TCP_KEEPIDLE");
}
else if (level == IPPROTO_TCP && optname == TCP_KEEPINTVL)
{
WARN("%s is not supported", "TCP_KEEPINTLVL");
}
else if (level == IPPROTO_TCP && optname == TCP_KEEPCNT)
{
WARN("%s is not supported", "TCP_KEEPCNT");
}
else if (level == IPPROTO_TCP && optname == TCP_ULP)
{
WARN("%s is not supported", "TCP_ULP");
}

return (ret);
return (demi_getsockopt(sockfd, level, optname, optval, optlen));
}
37 changes: 9 additions & 28 deletions shim/src/ctrl/setsockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <sys/socket.h>
#include <netinet/tcp.h>


/**
* @brief Sets socket options.
*
Expand All @@ -33,53 +32,35 @@ int __setsockopt(int sockfd, int level, int optname, const void *optval, socklen

TRACE("sockfd=%d, level=%d, optname=%d, optval=%p, optlen=%d", sockfd, level, optname, optval, optlen);

// Issue warnings for common options that are not supported.
if (level == SOL_SOCKET && optname == SO_KEEPALIVE)
{
// Ignore.
INFO("setting %s", "SO_KEEPALIVE");
WARN("%s is not supported", "SO_KEEPALIVE");
}
else if (level == SOL_SOCKET && optname == SO_REUSEADDR)
{
// Ignore.
INFO("setting %s", "SO_REUSEADDR");
}
else if (level == SOL_SOCKET && optname == SO_LINGER)
{
// Ignore.
INFO("setting %s", "SO_LINGER");
WARN("%s is not supported", "SO_REUSEADDR");
}
else if (level == IPPROTO_TCP && optname == TCP_NODELAY)
{
// Ignore.
INFO("setting %s", "TCP_NODELAY");
WARN("%s is not supported", "TCP_NODELAY");
}
else if (level == IPPROTO_TCP && optname == TCP_KEEPIDLE)
{
// Ignore.
INFO("setting %s", "TCP_KEEPIDLE");
WARN("%s is not supported", "TCP_KEEPIDLE");
}
else if (level == IPPROTO_TCP && optname == TCP_KEEPINTVL)
{
// Ignore.
INFO("setting %s", "TCP_KEEPINTLVL");
WARN("%s is not supported", "TCP_KEEPINTLVL");
}
else if (level == IPPROTO_TCP && optname == TCP_KEEPCNT)
{
// Ignore.
INFO("setting %s", "TCP_KEEPCNT");
WARN("%s is not supported", "TCP_KEEPCNT");
}
else if (level == IPPROTO_TCP && optname == TCP_ULP)
{
// Ignore.
INFO("setting %s", "TCP_ULP");
}
else
{
// Option not supported.
ERROR("option not supported");
errno = ENOTSUP;
return -1;
WARN("%s is not supported", "TCP_ULP");
}

return 0;
return (demi_setsockopt(sockfd, level, optname, optval, optlen));
}

0 comments on commit ffaf885

Please sign in to comment.