Skip to content

Commit

Permalink
Customize socket creation for hosted service on Linux: Set SO_MARK
Browse files Browse the repository at this point in the history
Implements setting the SO_MARK option for sockets designated for the `hosted` services.

Signed-off-by: Tom Carroll <[email protected]>
  • Loading branch information
tomc797 committed Sep 29, 2024
1 parent 22717f8 commit 9b7f884
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions programs/ziti-edge-tunnel/netif_driver/linux/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,3 +581,33 @@ uv_os_sock_t tlsuv_socket(const struct addrinfo *ai, bool blocking)

return sd;
}

/**
* Override ziti_hosting_cbs socket factory. This factory is used to create
* the sockets used for `hosted` services.
*/
int
ziti_tunnel_hosting_socket(uv_os_sock_t *psock, const struct addrinfo *ai)
{
uv_os_sock_t sd;

sd = socket(ai->ai_family, ai->ai_socktype|SOCK_CLOEXEC|SOCK_NONBLOCK, ai->ai_protocol);
if (sd < 0) {
int uv_err = uv_translate_sys_error(errno);

ZITI_LOG(ERROR, "socket: %d/%s", uv_err, uv_strerror(uv_err));
*psock = -1;
return uv_err;
}

int mark = ZET_BYPASS_MARK;
if (setsockopt(sd, SOL_SOCKET, SO_MARK, &mark, sizeof mark) < 0) {
int uv_err = uv_translate_sys_error(errno);

ZITI_LOG(WARN, "setsockopt(SO_MARK): %d/%s", uv_err, uv_strerror(uv_err));
}

*psock = sd;

return 0;
}

0 comments on commit 9b7f884

Please sign in to comment.