if (srv_tmpl) {
srv->addr = src->addr;
+ srv->addr_proto = src->addr_proto;
srv->svc_port = src->svc_port;
}
return i - srv->tmpl_info.nb_low;
}
+/* Ensure server config will work with effective proxy mode
+ *
+ * This function is expected to be called after _srv_parse_init() initialization
+ * but only when the effective server's proxy mode is known, which is not always
+ * the case during parsing time, in which case the function will be called during
+ * postparsing thanks to the _srv_postparse() below.
+ *
+ * Returns ERR_NONE on success else a combination or ERR_CODE.
+ */
+static int _srv_check_proxy_mode(struct server *srv, char postparse)
+{
+ int err_code = ERR_NONE;
+
+ if (postparse && !(srv->proxy->cap & PR_CAP_LB))
+ return ERR_NONE; /* nothing to do, the check was already performed during parsing */
+
+ if (srv->conf.file)
+ set_usermsgs_ctx(srv->conf.file, srv->conf.line, NULL);
+
+ if (!srv->addr_proto) {
+ /* proto may not be set (ie: if srv_parse_init() was skipped or
+ * SRV_PARSE_PARSE_ADDR was not set, in this case, we have nothing
+ * to check
+ */
+ goto out;
+ }
+ if (srv->proxy->mode == PR_MODE_SYSLOG) {
+ /* mode log enabled:
+ * pre-resolve related log target from known infos
+ */
+
+ BUG_ON(srv->log_target);
+ srv->log_target = malloc(sizeof(*srv->log_target));
+ if (!srv->log_target) {
+ ha_alert("memory error when allocating log server\n");
+ err_code |= ERR_ALERT | ERR_FATAL;
+ goto out;
+ }
+ srv->log_target->addr = &srv->addr;
+ switch (srv->addr_proto->xprt_type) {
+ case PROTO_TYPE_DGRAM:
+ srv->log_target->type = LOG_TARGET_DGRAM;
+ break;
+ case PROTO_TYPE_STREAM:
+ /* for now BUFFER type only supports TCP server to it's almost
+ * explicit. This will require ring buffer creation during log
+ * postresolving step.
+ */
+ srv->log_target->type = LOG_TARGET_BUFFER;
+ break;
+ default:
+ ha_alert("log server type not supported for log backend server.\n");
+ err_code |= ERR_ALERT | ERR_FATAL;
+ break;
+ }
+ }
+ else {
+ /* for now, only TCP expected as srv's proto for other uses */
+ if (srv->addr_proto->xprt_type != PROTO_TYPE_STREAM || !srv->addr_proto->connect) {
+ ha_alert("unsupported protocol for server address in '%s' backend.\n", proxy_mode_str(srv->proxy->mode));
+ err_code |= ERR_ALERT | ERR_FATAL;
+ }
+ }
+ out:
+ if (srv->conf.file)
+ reset_usermsgs_ctx();
+
+ return err_code;
+}
+
+/* Perform some server postparsing checks / tasks:
+ * We must be careful that checks / postinits performed within this function
+ * don't depend or conflict with other postcheck functions that are registered
+ * using REGISTER_POST_SERVER_CHECK() hook.
+ *
+ * Returns ERR_NONE on success else a combination or ERR_CODE.
+ */
+static int _srv_postparse(struct server *srv)
+{
+ int err_code = ERR_NONE;
+
+ err_code |= _srv_check_proxy_mode(srv, 1);
+
+ return err_code;
+}
+REGISTER_POST_SERVER_CHECK(_srv_postparse);
+
/* Allocate a new server pointed by <srv> and try to parse the first arguments
* in <args> as an address for a server or an address-range for a template or
* nothing for a default-server. <cur_arg> is incremented to the next argument.
const char *err = NULL;
int err_code = 0;
char *fqdn = NULL;
- struct protocol *proto;
int tmpl_range_low = 0, tmpl_range_high = 0;
char *errmsg = NULL;
if (!(parse_flags & SRV_PARSE_PARSE_ADDR))
goto skip_addr;
- sk = str2sa_range(args[*cur_arg], &port, &port1, &port2, NULL, &proto,
+ sk = str2sa_range(args[*cur_arg], &port, &port1, &port2, NULL, &newsrv->addr_proto,
&errmsg, NULL, &fqdn,
- (parse_flags & SRV_PARSE_IN_LOG_BE ? PA_O_DGRAM : PA_O_CONNECT) |
(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) |
- PA_O_STREAM | PA_O_XPRT);
+ PA_O_STREAM | PA_O_DGRAM | PA_O_XPRT);
if (!sk) {
ha_alert("%s\n", errmsg);
err_code |= ERR_ALERT | ERR_FATAL;
}
}
- if ((parse_flags & SRV_PARSE_IN_LOG_BE) && proto) {
- /* mode log enabled, and found proto:
- * pre-resolve related log target from known infos
- */
- newsrv->log_target = malloc(sizeof(*newsrv->log_target));
- if (!newsrv->log_target) {
- ha_alert("memory error when allocating log server\n");
- err_code |= ERR_ALERT | ERR_FATAL;
- goto out;
- }
- newsrv->log_target->addr = &newsrv->addr;
- switch (proto->xprt_type) {
- case PROTO_TYPE_DGRAM:
- newsrv->log_target->type = LOG_TARGET_DGRAM;
- break;
- case PROTO_TYPE_STREAM:
- /* for now BUFFER type only supports TCP server to it's almost
- * explicit. This will require ring buffer creation during log
- * postresolving step.
- */
- newsrv->log_target->type = LOG_TARGET_BUFFER;
- break;
- default:
- ha_alert("log server type not supported for log backend server.\n");
- err_code |= ERR_ALERT | ERR_FATAL;
- break;
- }
- }
-
newsrv->addr = *sk;
newsrv->svc_port = port;
/*
}
free(fqdn);
+ if (!(curproxy->cap & PR_CAP_LB)) {
+ /* No need to wait for effective proxy mode, it is already known:
+ * Only general purpose user-declared proxies ("listen", "frontend", "backend")
+ * offer the possibility to configure the mode of the proxy. Hopefully for us,
+ * they have the PR_CAP_LB set.
+ */
+ return _srv_check_proxy_mode(newsrv, 0);
+ }
return 0;
out: