WIP: create abnsz

For now it's the same as abns. We'll need to modify sock_unix_addrcmp(),
and a few other ones to support strnlen() when dealing with the \0. Let's
check with Tristan's patch for this.
This commit is contained in:
Willy Tarreau 2024-08-09 21:12:23 +02:00
parent ddacf47820
commit bb471dd06d
7 changed files with 102 additions and 3 deletions

View File

@ -41,7 +41,8 @@ struct connection;
#define AF_CUST_SOCKPAIR (AF_MAX + 2) #define AF_CUST_SOCKPAIR (AF_MAX + 2)
#define AF_CUST_RHTTP_SRV (AF_MAX + 3) #define AF_CUST_RHTTP_SRV (AF_MAX + 3)
#define AF_CUST_ABNS (AF_MAX + 4) #define AF_CUST_ABNS (AF_MAX + 4)
#define AF_CUST_MAX (AF_MAX + 5) #define AF_CUST_ABNSZ (AF_MAX + 5)
#define AF_CUST_MAX (AF_MAX + 6)
/* /*
* Test in case AF_CUST_MAX overflows the sa_family_t (unsigned int) * Test in case AF_CUST_MAX overflows the sa_family_t (unsigned int)

View File

@ -30,6 +30,7 @@
extern struct proto_fam proto_fam_unix; extern struct proto_fam proto_fam_unix;
extern struct proto_fam proto_fam_abns; extern struct proto_fam proto_fam_abns;
extern struct proto_fam proto_fam_abnsz;
int sock_unix_addrcmp(const struct sockaddr_storage *a, const struct sockaddr_storage *b); int sock_unix_addrcmp(const struct sockaddr_storage *a, const struct sockaddr_storage *b);
int sock_unix_bind_receiver(struct receiver *rx, char **errmsg); int sock_unix_bind_receiver(struct receiver *rx, char **errmsg);

View File

@ -713,7 +713,8 @@ static inline int is_addr(const struct sockaddr_storage *addr)
/* WT: ideally we should use real_family(addr->ss_family) here, but we /* WT: ideally we should use real_family(addr->ss_family) here, but we
* have so few custom addresses that it's simple enough to test them all. * have so few custom addresses that it's simple enough to test them all.
*/ */
if (addr->ss_family == AF_UNIX || addr->ss_family == AF_CUST_ABNS || addr->ss_family == AF_CUST_SOCKPAIR) if (addr->ss_family == AF_UNIX || addr->ss_family == AF_CUST_ABNS ||
addr->ss_family == AF_CUST_ABNSZ || addr->ss_family == AF_CUST_SOCKPAIR)
return 1; return 1;
else else
return is_inet_addr(addr); return is_inet_addr(addr);
@ -753,6 +754,7 @@ static inline int get_addr_len(const struct sockaddr_storage *addr)
return sizeof(struct sockaddr_in6); return sizeof(struct sockaddr_in6);
case AF_UNIX: case AF_UNIX:
case AF_CUST_ABNS: case AF_CUST_ABNS:
case AF_CUST_ABNSZ:
return sizeof(struct sockaddr_un); return sizeof(struct sockaddr_un);
} }
return 0; return 0;

View File

@ -97,8 +97,40 @@ struct protocol proto_abns_dgram = {
.nb_receivers = 0, .nb_receivers = 0,
}; };
/* Note: must not be declared <const> as its list will be overwritten */
struct protocol proto_abnsz_dgram = {
.name = "abnsz_dgram",
/* connection layer */
.xprt_type = PROTO_TYPE_DGRAM,
.listen = uxdg_bind_listener,
.enable = uxdg_enable_listener,
.disable = uxdg_disable_listener,
.add = default_add_listener,
.unbind = default_unbind_listener,
.suspend = default_suspend_listener,
.resume = default_resume_listener,
/* binding layer */
.rx_suspend = uxdg_suspend_receiver,
/* address family */
.fam = &proto_fam_abnsz,
/* socket layer */
.proto_type = PROTO_TYPE_DGRAM,
.sock_type = SOCK_DGRAM,
.sock_prot = 0,
.rx_enable = sock_enable,
.rx_disable = sock_disable,
.rx_unbind = sock_unbind,
.receivers = LIST_HEAD_INIT(proto_abnsz_dgram.receivers),
.nb_receivers = 0,
};
INITCALL1(STG_REGISTER, protocol_register, &proto_uxdg); INITCALL1(STG_REGISTER, protocol_register, &proto_uxdg);
INITCALL1(STG_REGISTER, protocol_register, &proto_abns_dgram); INITCALL1(STG_REGISTER, protocol_register, &proto_abns_dgram);
INITCALL1(STG_REGISTER, protocol_register, &proto_abnsz_dgram);
/* This function tries to bind dgram unix socket listener. It may return a warning or /* This function tries to bind dgram unix socket listener. It may return a warning or
* an error message in <errmsg> if the message is at most <errlen> bytes long * an error message in <errmsg> if the message is at most <errlen> bytes long

View File

@ -124,8 +124,49 @@ struct protocol proto_abns_stream = {
.nb_receivers = 0, .nb_receivers = 0,
}; };
/* Note: must not be declared <const> as its list will be overwritten */
struct protocol proto_abnsz_stream = {
.name = "abnsz_stream",
/* connection layer */
.xprt_type = PROTO_TYPE_STREAM,
.listen = uxst_bind_listener,
.enable = uxst_enable_listener,
.disable = uxst_disable_listener,
.add = default_add_listener,
.unbind = default_unbind_listener,
.suspend = default_suspend_listener,
.resume = default_resume_listener,
.accept_conn = sock_accept_conn,
.ctrl_init = sock_conn_ctrl_init,
.ctrl_close = sock_conn_ctrl_close,
.connect = uxst_connect_server,
.drain = sock_drain,
.check_events = sock_check_events,
.ignore_events = sock_ignore_events,
/* binding layer */
.rx_suspend = uxst_suspend_receiver,
/* address family */
.fam = &proto_fam_abnsz,
/* socket layer */
.proto_type = PROTO_TYPE_STREAM,
.sock_type = SOCK_STREAM,
.sock_prot = 0,
.rx_enable = sock_enable,
.rx_disable = sock_disable,
.rx_unbind = sock_unbind,
.rx_listening = sock_accepting_conn,
.default_iocb = sock_accept_iocb,
.nb_receivers = 0,
};
INITCALL1(STG_REGISTER, protocol_register, &proto_uxst); INITCALL1(STG_REGISTER, protocol_register, &proto_uxst);
INITCALL1(STG_REGISTER, protocol_register, &proto_abns_stream); INITCALL1(STG_REGISTER, protocol_register, &proto_abns_stream);
INITCALL1(STG_REGISTER, protocol_register, &proto_abnsz_stream);
/******************************** /********************************
* 1) low-level socket functions * 1) low-level socket functions

View File

@ -63,6 +63,19 @@ struct proto_fam proto_fam_abns = {
.get_dst = sock_get_dst, .get_dst = sock_get_dst,
}; };
struct proto_fam proto_fam_abnsz = {
.name = "abnsz",
.sock_domain = AF_UNIX,
.sock_family = AF_CUST_ABNSZ,
.real_family = AF_UNIX,
.sock_addrlen = sizeof(struct sockaddr_un),
.l3_addrlen = sizeof(((struct sockaddr_un*)0)->sun_path),
.addrcmp = sock_unix_addrcmp,
.bind = sock_unix_bind_receiver,
.get_src = sock_get_src,
.get_dst = sock_get_dst,
};
/* PLEASE NOTE for functions below: /* PLEASE NOTE for functions below:
* *
* The address family SHOULD always be checked. In some cases a function will * The address family SHOULD always be checked. In some cases a function will

View File

@ -1045,6 +1045,11 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
abstract = 1; abstract = 1;
ss.ss_family = AF_CUST_ABNS; ss.ss_family = AF_CUST_ABNS;
} }
else if (strncmp(str2, "abnsz@", 5) == 0) {
str2 += 6;
abstract = 1;
ss.ss_family = AF_CUST_ABNSZ;
}
else if (strncmp(str2, "ip@", 3) == 0) { else if (strncmp(str2, "ip@", 3) == 0) {
str2 += 3; str2 += 3;
ss.ss_family = AF_UNSPEC; ss.ss_family = AF_UNSPEC;
@ -1186,7 +1191,7 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
goto out; goto out;
} }
} }
else if (ss.ss_family == AF_UNIX || ss.ss_family == AF_CUST_ABNS) { else if (ss.ss_family == AF_UNIX || ss.ss_family == AF_CUST_ABNS || ss.ss_family == AF_CUST_ABNSZ) {
struct sockaddr_un *un = (struct sockaddr_un *)&ss; struct sockaddr_un *un = (struct sockaddr_un *)&ss;
int prefix_path_len; int prefix_path_len;
int max_path_len; int max_path_len;
@ -1436,6 +1441,7 @@ char * sa2str(const struct sockaddr_storage *addr, int port, int map_ports)
break; break;
case AF_UNIX: case AF_UNIX:
case AF_CUST_ABNS: case AF_CUST_ABNS:
case AF_CUST_ABNSZ:
path = ((struct sockaddr_un *)addr)->sun_path; path = ((struct sockaddr_un *)addr)->sun_path;
if (path[0] == '\0') { if (path[0] == '\0') {
const int max_length = sizeof(struct sockaddr_un) - offsetof(struct sockaddr_un, sun_path) - 1; const int max_length = sizeof(struct sockaddr_un) - offsetof(struct sockaddr_un, sun_path) - 1;
@ -1884,6 +1890,7 @@ int addr_to_str(const struct sockaddr_storage *addr, char *str, int size)
break; break;
case AF_UNIX: case AF_UNIX:
case AF_CUST_ABNS: case AF_CUST_ABNS:
case AF_CUST_ABNSZ:
memcpy(str, "unix", 5); memcpy(str, "unix", 5);
return addr->ss_family; return addr->ss_family;
default: default:
@ -1922,6 +1929,7 @@ int port_to_str(const struct sockaddr_storage *addr, char *str, int size)
break; break;
case AF_UNIX: case AF_UNIX:
case AF_CUST_ABNS: case AF_CUST_ABNS:
case AF_CUST_ABNSZ:
memcpy(str, "unix", 5); memcpy(str, "unix", 5);
return addr->ss_family; return addr->ss_family;
default: default:
@ -6356,6 +6364,7 @@ const char *hash_ipanon(uint32_t scramble, char *ipstring, int hasport)
case AF_UNIX: case AF_UNIX:
case AF_CUST_ABNS: case AF_CUST_ABNS:
case AF_CUST_ABNSZ:
return HA_ANON_STR(scramble, ipstring); return HA_ANON_STR(scramble, ipstring);
break; break;