} addr;
};
+/* holds socket and xprt types for a given address */
+struct net_addr_type {
+ int proto_type; // socket layer
+ int xprt_type; // transport layer
+};
+
#endif /* _HAPROXY_TOOLS_T_H */
* address (typically the path to a unix socket).
*/
struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int *high, int *fd,
- struct protocol **proto, char **err,
- const char *pfx, char **fqdn, unsigned int opts);
+ struct protocol **proto, struct net_addr_type *sa_type,
+ char **err, const char *pfx, char **fqdn, unsigned int opts);
/* converts <addr> and <port> into a string representation of the address and port. This is sort
else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
err_code |= ERR_WARN;
- sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
+ sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL, NULL,
&errmsg, NULL, NULL,
PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_STREAM | PA_O_XPRT | PA_O_CONNECT);
if (!sk) {
ha_free(&curproxy->conn_src.iface_name);
curproxy->conn_src.iface_len = 0;
- sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL,
+ sk = str2sa_range(args[1], NULL, &port1, &port2, NULL, NULL, NULL,
&errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
if (!sk) {
ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
} else {
struct sockaddr_storage *sk;
- sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
+ sk = str2sa_range(args[cur_arg + 1], NULL, &port1, &port2, NULL, NULL, NULL,
&errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
if (!sk) {
ha_alert("parsing [%s:%d] : '%s %s' : %s\n",
*next++ = 0;
}
- ss2 = str2sa_range(str, NULL, &port, &end, &fd, &proto, err,
+ ss2 = str2sa_range(str, NULL, &port, &end, &fd, &proto, NULL, err,
(curproxy == global.cli_fe || curproxy == mworker_proxy) ? NULL : global.unix_bind.prefix,
NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_PORT_RANGE |
PA_O_SOCKET_FD | PA_O_STREAM | PA_O_XPRT);
*next++ = 0;
}
- ss2 = str2sa_range(str, NULL, &port, &end, &fd, &proto, err,
+ ss2 = str2sa_range(str, NULL, &port, &end, &fd, &proto, NULL, err,
curproxy == global.cli_fe ? NULL : global.unix_bind.prefix,
NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_PORT_RANGE |
PA_O_SOCKET_FD | PA_O_DGRAM | PA_O_XPRT);
newmailer->id = strdup(args[1]);
- sk = str2sa_range(args[2], NULL, &port1, &port2, NULL, &proto,
+ sk = str2sa_range(args[2], NULL, &port1, &port2, NULL, &proto, NULL,
&errmsg, NULL, NULL,
PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_STREAM | PA_O_XPRT | PA_O_CONNECT);
if (!sk) {
goto error;
}
- sk = str2sa_range(args[*cur_arg+1], NULL, &port1, &port2, NULL, NULL, errmsg, NULL, NULL,
+ sk = str2sa_range(args[*cur_arg+1], NULL, &port1, &port2, NULL, NULL, NULL, errmsg, NULL, NULL,
PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
if (!sk) {
memprintf(errmsg, "'%s' : %s", args[*cur_arg], *errmsg);
newsrv->conf.line = 0;
memprintf(&msg, "sockpair@%d", child->ipc_fd[0]);
- if ((sk = str2sa_range(msg, &port, &port1, &port2, NULL, &proto,
+ if ((sk = str2sa_range(msg, &port, &port1, &port2, NULL, &proto, NULL,
&errmsg, NULL, NULL, PA_O_STREAM)) == 0) {
goto error;
}
csk_ctx->srv = socket_tcp;
/* Parse ip address. */
- addr = str2sa_range(ip, NULL, &low, &high, NULL, NULL, NULL, NULL, NULL, PA_O_PORT_OK | PA_O_STREAM);
+ addr = str2sa_range(ip, NULL, &low, &high, NULL, NULL, NULL, NULL, NULL, NULL, PA_O_PORT_OK | PA_O_STREAM);
if (!addr) {
xref_unlock(&socket->xref, peer);
WILL_LJMP(luaL_error(L, "connect: cannot parse destination address '%s'", ip));
sockaddr_free(&hc->dst);
/* 'sk' is statically allocated (no need to be freed). */
- sk = str2sa_range(dst, NULL, NULL, NULL, NULL, NULL,
+ sk = str2sa_range(dst, NULL, NULL, NULL, NULL, NULL, NULL,
&errmsg, NULL, NULL,
PA_O_PORT_OK | PA_O_STREAM | PA_O_XPRT | PA_O_CONNECT);
if (!sk) {
target->type = LOG_TARGET_DGRAM; // default type
/* parse the target address */
- sk = str2sa_range(raw, NULL, &port1, &port2, &fd, &proto,
+ sk = str2sa_range(raw, NULL, &port1, &port2, &fd, &proto, NULL,
err, NULL, NULL,
PA_O_RESOLVE | PA_O_PORT_OK | PA_O_RAW_FD | PA_O_DGRAM | PA_O_STREAM | PA_O_DEFAULT_DGRAM);
if (!sk)
}
}
- sk = str2sa_range(args[2], NULL, &port1, &port2, NULL, &proto,
+ sk = str2sa_range(args[2], NULL, &port1, &port2, NULL, &proto, NULL,
&errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_DGRAM | PA_O_STREAM | PA_O_DEFAULT_DGRAM);
if (!sk) {
ha_alert("parsing [%s:%d] : '%s %s' : %s\n", file, linenum, args[0], args[1], errmsg);
}
/* 'sk' is statically allocated (no need to be freed). */
- sk = str2sa_range(args[*cur_arg + 1], NULL, &port_low, &port_high, NULL, NULL,
+ sk = str2sa_range(args[*cur_arg + 1], NULL, &port_low, &port_high, NULL, NULL, NULL,
&errmsg, NULL, NULL,
PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_RANGE | PA_O_STREAM | PA_O_CONNECT);
if (!sk) {
int port1, port2;
/* 'sk' is statically allocated (no need to be freed). */
- sk = str2sa_range(args[*cur_arg + 1], NULL, &port1, &port2, NULL, NULL,
+ sk = str2sa_range(args[*cur_arg + 1], NULL, &port1, &port2, NULL, NULL, NULL,
&errmsg, NULL, NULL,
PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
if (!sk) {
}
/* 'sk' is statically allocated (no need to be freed). */
- sk = str2sa_range(args[*cur_arg + 1], NULL, &port_low, &port_high, NULL, NULL,
+ sk = str2sa_range(args[*cur_arg + 1], NULL, &port_low, &port_high, NULL, NULL, NULL,
&errmsg, NULL, NULL,
PA_O_RESOLVE | PA_O_PORT_OK | PA_O_PORT_MAND | PA_O_STREAM | PA_O_CONNECT);
if (!sk) {
if (!(parse_flags & SRV_PARSE_PARSE_ADDR))
goto skip_addr;
- sk = str2sa_range(args[*cur_arg], &port, &port1, &port2, NULL, &newsrv->addr_proto,
+ sk = str2sa_range(args[*cur_arg], &port, &port1, &port2, NULL, &newsrv->addr_proto, NULL,
&errmsg, NULL, &fqdn,
(parse_flags & SRV_PARSE_INITIAL_RESOLVE ? PA_O_RESOLVE : 0) | PA_O_PORT_OK |
(parse_flags & SRV_PARSE_IN_PEER_SECTION ? PA_O_PORT_MAND : PA_O_PORT_OFS) |
goto error;
}
- sk = str2sa_range(args[cur_arg+1], NULL, &port1, &port2, NULL, NULL,
+ sk = str2sa_range(args[cur_arg+1], NULL, &port1, &port2, NULL, NULL, NULL,
errmsg, NULL, NULL, PA_O_RESOLVE | PA_O_PORT_OK | PA_O_STREAM | PA_O_CONNECT);
if (!sk) {
memprintf(errmsg, "'%s' : %s.", args[cur_arg], *errmsg);
* AF_CUST_EXISTING_FD.
*
* The matching protocol will be set into <proto> if non-null.
+ * The address protocol and transport types hints which are directly resolved
+ * will be set into <sa_type> if not NULL.
*
* Any known file descriptor is also assigned to <fd> if non-null, otherwise it
* is forced to -1.
*/
struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int *high, int *fd,
- struct protocol **proto, char **err,
- const char *pfx, char **fqdn, unsigned int opts)
+ struct protocol **proto, struct net_addr_type *sa_type,
+ char **err, const char *pfx, char **fqdn, unsigned int opts)
{
static THREAD_LOCAL struct sockaddr_storage ss;
struct sockaddr_storage *ret = NULL;
int portl, porth, porta;
int abstract = 0;
int new_fd = -1;
- enum proto_type proto_type;
- int ctrl_type;
+ enum proto_type proto_type = 0; // to shut gcc warning
+ int ctrl_type = 0; // to shut gcc warning
portl = porth = porta = 0;
if (fqdn)
*fd = new_fd;
if (proto)
*proto = new_proto;
+ if (sa_type) {
+ sa_type->proto_type = proto_type;
+ sa_type->xprt_type = (ctrl_type == SOCK_DGRAM) ? PROTO_TYPE_DGRAM : PROTO_TYPE_STREAM;
+ }
free(back);
return ret;
}
sa = &ss;
}
else {
- sa = str2sa_range(ipstring, NULL, NULL, NULL, NULL, NULL, &errmsg, NULL, NULL,
+ sa = str2sa_range(ipstring, NULL, NULL, NULL, NULL, NULL, NULL, &errmsg, NULL, NULL,
PA_O_PORT_OK | PA_O_STREAM | PA_O_DGRAM | PA_O_XPRT | PA_O_CONNECT |
PA_O_PORT_RANGE | PA_O_PORT_OFS | PA_O_RESOLVE);
if (sa == NULL) {