mirror of
https://github.com/yrutschle/sslh.git
synced 2025-04-12 15:17:14 +03:00
new is_unix field to create listen unix sockets
This commit is contained in:
parent
59d89e34f0
commit
bf082292c2
@ -1,3 +1,10 @@
|
|||||||
|
vNEXT:
|
||||||
|
Added a boolean setting "is_unix" for listen and
|
||||||
|
protocol entries. This will use the 'host' setting
|
||||||
|
as a path name to a socket file, and connections
|
||||||
|
(listening or connecting) will be performed on Unix
|
||||||
|
socket instead of Internet sockets.
|
||||||
|
|
||||||
v2.1.3:
|
v2.1.3:
|
||||||
Fix Landlock access to /etc/hosts.deny and
|
Fix Landlock access to /etc/hosts.deny and
|
||||||
/etc/hosts.allow.
|
/etc/hosts.allow.
|
||||||
|
37
common.c
37
common.c
@ -178,6 +178,7 @@ static int start_listen_inet(struct listen_endpoint *sockfd[], int num_addr, str
|
|||||||
*sockfd = realloc(*sockfd, num_addr * sizeof(*sockfd[0]));
|
*sockfd = realloc(*sockfd, num_addr * sizeof(*sockfd[0]));
|
||||||
(*sockfd)[num_addr-1].socketfd = listen_single_addr(addr, cfg->keepalive, cfg->is_udp);
|
(*sockfd)[num_addr-1].socketfd = listen_single_addr(addr, cfg->keepalive, cfg->is_udp);
|
||||||
(*sockfd)[num_addr-1].type = cfg->is_udp ? SOCK_DGRAM : SOCK_STREAM;
|
(*sockfd)[num_addr-1].type = cfg->is_udp ? SOCK_DGRAM : SOCK_STREAM;
|
||||||
|
(*sockfd)[num_addr-1].family = AF_INET;
|
||||||
print_message(msg_config, "%d:\t%s\t[%s] [%s]\n", (*sockfd)[num_addr-1].socketfd, sprintaddr(buf, sizeof(buf), addr),
|
print_message(msg_config, "%d:\t%s\t[%s] [%s]\n", (*sockfd)[num_addr-1].socketfd, sprintaddr(buf, sizeof(buf), addr),
|
||||||
cfg->keepalive ? "keepalive" : "",
|
cfg->keepalive ? "keepalive" : "",
|
||||||
cfg->is_udp ? "udp" : "");
|
cfg->is_udp ? "udp" : "");
|
||||||
@ -186,6 +187,31 @@ static int start_listen_inet(struct listen_endpoint *sockfd[], int num_addr, str
|
|||||||
return num_addr;
|
return num_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Same, but for UNIX sockets */
|
||||||
|
static int start_listen_unix(struct listen_endpoint *sockfd[], int num_addr, struct sslhcfg_listen_item* cfg)
|
||||||
|
{
|
||||||
|
int fd = socket(AF_UNIX, cfg->is_udp ? SOCK_DGRAM : SOCK_STREAM, 0);
|
||||||
|
CHECK_RES_DIE(fd, "socket(AF_UNIX)");
|
||||||
|
|
||||||
|
struct sockaddr_un sun;
|
||||||
|
sun.sun_family = AF_UNIX;
|
||||||
|
strncpy(sun.sun_path, cfg->host, sizeof(sun.sun_path)-1);
|
||||||
|
printf("binding [%s]\n", sun.sun_path);
|
||||||
|
int res = bind(fd, (struct sockaddr*)&sun, sizeof(sun));
|
||||||
|
CHECK_RES_DIE(res, "bind(AF_UNIX)");
|
||||||
|
|
||||||
|
res = listen(fd, 50);
|
||||||
|
|
||||||
|
num_addr++;
|
||||||
|
*sockfd = realloc(*sockfd, num_addr * sizeof(*sockfd[0]));
|
||||||
|
(*sockfd)[num_addr-1].socketfd = fd;
|
||||||
|
(*sockfd)[num_addr-1].type = cfg->is_udp ? SOCK_DGRAM : SOCK_STREAM;
|
||||||
|
(*sockfd)[num_addr-1].family = AF_INET;
|
||||||
|
|
||||||
|
return num_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Starts listening sockets on specified addresses.
|
/* Starts listening sockets on specified addresses.
|
||||||
* OUT: *sockfd[] pointer to newly-allocated array of listen_endpoint objects
|
* OUT: *sockfd[] pointer to newly-allocated array of listen_endpoint objects
|
||||||
* Returns number of addresses bound
|
* Returns number of addresses bound
|
||||||
@ -206,7 +232,11 @@ int start_listen_sockets(struct listen_endpoint *sockfd[])
|
|||||||
print_message(msg_config, "Listening to:\n");
|
print_message(msg_config, "Listening to:\n");
|
||||||
|
|
||||||
for (i = 0; i < cfg.listen_len; i++) {
|
for (i = 0; i < cfg.listen_len; i++) {
|
||||||
num_addr = start_listen_inet(sockfd, num_addr, &cfg.listen[i]);
|
if (cfg.listen[i].is_unix) {
|
||||||
|
num_addr = start_listen_unix(sockfd, num_addr, &cfg.listen[i]);
|
||||||
|
} else {
|
||||||
|
num_addr = start_listen_inet(sockfd, num_addr, &cfg.listen[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return num_addr;
|
return num_addr;
|
||||||
@ -425,7 +455,7 @@ static int connect_unix(struct connection *cnx, int fd_from, connect_blocking bl
|
|||||||
|
|
||||||
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
sun->sun_family = AF_UNIX;
|
sun->sun_family = AF_UNIX;
|
||||||
strcpy(sun->sun_path, cnx->proto->host);
|
strncpy(sun->sun_path, cnx->proto->host, sizeof(sun->sun_path)-1);
|
||||||
|
|
||||||
int res = connect(fd, (struct sockaddr*)sun, sizeof(*sun));
|
int res = connect(fd, (struct sockaddr*)sun, sizeof(*sun));
|
||||||
CHECK_RES_RETURN(res, "connect", res);
|
CHECK_RES_RETURN(res, "connect", res);
|
||||||
@ -588,6 +618,9 @@ char* sprintaddr(char* buf, size_t size, struct addrinfo *a)
|
|||||||
char host[NI_MAXHOST], serv[NI_MAXSERV];
|
char host[NI_MAXHOST], serv[NI_MAXSERV];
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
|
memset(host, 0, sizeof(host));
|
||||||
|
memset(serv, 0, sizeof(serv));
|
||||||
|
|
||||||
res = getnameinfo(a->ai_addr, a->ai_addrlen,
|
res = getnameinfo(a->ai_addr, a->ai_addrlen,
|
||||||
host, sizeof(host),
|
host, sizeof(host),
|
||||||
serv, sizeof(serv),
|
serv, sizeof(serv),
|
||||||
|
1
common.h
1
common.h
@ -132,6 +132,7 @@ struct connection {
|
|||||||
struct listen_endpoint {
|
struct listen_endpoint {
|
||||||
int socketfd; /* file descriptor of listening socket */
|
int socketfd; /* file descriptor of listening socket */
|
||||||
int type; /* SOCK_DGRAM | SOCK_STREAM */
|
int type; /* SOCK_DGRAM | SOCK_STREAM */
|
||||||
|
int family; /* AF_INET | AF_UNIX */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define FD_CNXCLOSED 0
|
#define FD_CNXCLOSED 0
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
|
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
|
||||||
* on Sun Dec 22 00:05:31 2024.
|
* on Sun Dec 22 22:40:51 2024.
|
||||||
|
|
||||||
# conf2struct: generate libconf parsers that read to structs
|
# conf2struct: generate libconf parsers that read to structs
|
||||||
# Copyright (C) 2018-2024 Yves Rutschle
|
# Copyright (C) 2018-2024 Yves Rutschle
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
|
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
|
||||||
* on Sun Dec 22 00:05:31 2024.
|
* on Sun Dec 22 22:40:51 2024.
|
||||||
|
|
||||||
# conf2struct: generate libconf parsers that read to structs
|
# conf2struct: generate libconf parsers that read to structs
|
||||||
# Copyright (C) 2018-2024 Yves Rutschle
|
# Copyright (C) 2018-2024 Yves Rutschle
|
||||||
|
@ -53,7 +53,8 @@ listen:
|
|||||||
(
|
(
|
||||||
{ host: "thelonious"; port: "443"; },
|
{ host: "thelonious"; port: "443"; },
|
||||||
{ host: "thelonious"; port: "8080"; keepalive: true; },
|
{ host: "thelonious"; port: "8080"; keepalive: true; },
|
||||||
{ host: "thelonious"; is_udp: true; port: "443" }
|
{ host: "thelonious"; is_udp: true; port: "443"; },
|
||||||
|
{ host: "/tmp/unix_socket"; is_unix: true; port: ""; }
|
||||||
);
|
);
|
||||||
|
|
||||||
# List of protocols
|
# List of protocols
|
||||||
|
23
sslh-conf.c
23
sslh-conf.c
@ -1,5 +1,5 @@
|
|||||||
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
|
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
|
||||||
* on Sun Dec 22 16:13:50 2024.
|
* on Sun Dec 22 22:40:51 2024.
|
||||||
|
|
||||||
# conf2struct: generate libconf parsers that read to structs
|
# conf2struct: generate libconf parsers that read to structs
|
||||||
# Copyright (C) 2018-2024 Yves Rutschle
|
# Copyright (C) 2018-2024 Yves Rutschle
|
||||||
@ -777,7 +777,7 @@ static struct config_desc table_sslhcfg_protocols[] = {
|
|||||||
},
|
},
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct config_desc table_sslhcfg_listen[] = {
|
static struct config_desc table_sslhcfg_listen[] = {
|
||||||
|
|
||||||
|
|
||||||
@ -829,6 +829,22 @@ static struct config_desc table_sslhcfg_listen[] = {
|
|||||||
/* default_val*/ .default_val.def_bool = 0
|
/* default_val*/ .default_val.def_bool = 0
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
/* name */ "is_unix",
|
||||||
|
/* type */ CFG_BOOL,
|
||||||
|
/* sub_group*/ NULL,
|
||||||
|
/* arg_cl */ NULL,
|
||||||
|
/* base_addr */ NULL,
|
||||||
|
/* offset */ offsetof(struct sslhcfg_listen_item, is_unix),
|
||||||
|
/* offset_len */ 0,
|
||||||
|
/* offset_present */ 0,
|
||||||
|
/* size */ sizeof(int),
|
||||||
|
/* array_type */ -1,
|
||||||
|
/* mandatory */ 0,
|
||||||
|
/* optional */ 0,
|
||||||
|
/* default_val*/ .default_val.def_bool = 0
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
/* name */ "keepalive",
|
/* name */ "keepalive",
|
||||||
/* type */ CFG_BOOL,
|
/* type */ CFG_BOOL,
|
||||||
@ -2429,6 +2445,9 @@ static void sslhcfg_listen_fprint(
|
|||||||
fprintf(out, "is_udp: %d", sslhcfg_listen->is_udp);
|
fprintf(out, "is_udp: %d", sslhcfg_listen->is_udp);
|
||||||
fprintf(out, "\n");
|
fprintf(out, "\n");
|
||||||
indent(out, depth);
|
indent(out, depth);
|
||||||
|
fprintf(out, "is_unix: %d", sslhcfg_listen->is_unix);
|
||||||
|
fprintf(out, "\n");
|
||||||
|
indent(out, depth);
|
||||||
fprintf(out, "keepalive: %d", sslhcfg_listen->keepalive);
|
fprintf(out, "keepalive: %d", sslhcfg_listen->keepalive);
|
||||||
fprintf(out, "\n");
|
fprintf(out, "\n");
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
|
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
|
||||||
* on Sun Dec 22 16:13:50 2024.
|
* on Sun Dec 22 22:40:51 2024.
|
||||||
|
|
||||||
# conf2struct: generate libconf parsers that read to structs
|
# conf2struct: generate libconf parsers that read to structs
|
||||||
# Copyright (C) 2018-2024 Yves Rutschle
|
# Copyright (C) 2018-2024 Yves Rutschle
|
||||||
@ -44,6 +44,7 @@ struct sslhcfg_listen_item {
|
|||||||
char* host;
|
char* host;
|
||||||
char* port;
|
char* port;
|
||||||
int is_udp;
|
int is_udp;
|
||||||
|
int is_unix;
|
||||||
int keepalive;
|
int keepalive;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -98,6 +98,7 @@ config: {
|
|||||||
{ name: "host"; type: "string"; var: true; },
|
{ name: "host"; type: "string"; var: true; },
|
||||||
{ name: "port"; type: "string"; var: true; },
|
{ name: "port"; type: "string"; var: true; },
|
||||||
{ name: "is_udp"; type: "bool"; default: false },
|
{ name: "is_udp"; type: "bool"; default: false },
|
||||||
|
{ name: "is_unix"; type: "bool"; default: false },
|
||||||
{ name: "keepalive"; type: "bool"; default: false; }
|
{ name: "keepalive"; type: "bool"; default: false; }
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
3
test.cfg
3
test.cfg
@ -32,7 +32,8 @@ listen:
|
|||||||
(
|
(
|
||||||
{ host: "localhost"; port: "8080"; keepalive: true; },
|
{ host: "localhost"; port: "8080"; keepalive: true; },
|
||||||
{ host: "localhost"; port: "8081"; keepalive: true; },
|
{ host: "localhost"; port: "8081"; keepalive: true; },
|
||||||
{ host: "ip4-localhost"; is_udp: true; port: "8086"; }
|
{ host: "ip4-localhost"; is_udp: true; port: "8086"; },
|
||||||
|
{ host: "/tmp/sslh.sock"; is_unix: true; port: ""; }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user