mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-20 21:31:28 +02:00
MEDIUM: make the trash be a chunk instead of a char *
The trash is used everywhere to store the results of temporary strings built out of s(n)printf, or as a storage for a chunk when chunks are needed. Using global.tune.bufsize is not the most convenient thing either. So let's replace trash with a chunk and directly use it as such. We can then use trash.size as the natural way to get its size, and get rid of many intermediary chunks that were previously used. The patch is huge because it touches many areas but it makes the code a lot more clear and even outlines places where trash was used without being that obvious.
This commit is contained in:
parent
7780473c3b
commit
19d14ef104
@ -131,7 +131,7 @@ extern int relative_pid; /* process id starting at 1 */
|
|||||||
extern int actconn; /* # of active sessions */
|
extern int actconn; /* # of active sessions */
|
||||||
extern int listeners;
|
extern int listeners;
|
||||||
extern int jobs; /* # of active jobs */
|
extern int jobs; /* # of active jobs */
|
||||||
extern char *trash;
|
extern struct chunk trash;
|
||||||
extern char *swap_buffer;
|
extern char *swap_buffer;
|
||||||
extern int nb_oldpids; /* contains the number of old pids found */
|
extern int nb_oldpids; /* contains the number of old pids found */
|
||||||
extern const int zero;
|
extern const int zero;
|
||||||
|
@ -1308,9 +1308,9 @@ static int acl_read_patterns_from_file( struct acl_keyword *aclkw,
|
|||||||
opaque = 0;
|
opaque = 0;
|
||||||
pattern = NULL;
|
pattern = NULL;
|
||||||
args[1] = "";
|
args[1] = "";
|
||||||
while (fgets(trash, global.tune.bufsize, file) != NULL) {
|
while (fgets(trash.str, trash.size, file) != NULL) {
|
||||||
line++;
|
line++;
|
||||||
c = trash;
|
c = trash.str;
|
||||||
|
|
||||||
/* ignore lines beginning with a dash */
|
/* ignore lines beginning with a dash */
|
||||||
if (*c == '#')
|
if (*c == '#')
|
||||||
|
@ -97,13 +97,9 @@ static struct task *appsession_refresh(struct task *t)
|
|||||||
if (tick_is_expired(element->expire, now_ms)) {
|
if (tick_is_expired(element->expire, now_ms)) {
|
||||||
if ((global.mode & MODE_DEBUG) &&
|
if ((global.mode & MODE_DEBUG) &&
|
||||||
(!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))) {
|
(!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))) {
|
||||||
int len;
|
chunk_printf(&trash, "appsession_refresh: cleaning up expired Session '%s' on Server %s\n",
|
||||||
/*
|
|
||||||
on Linux NULL pointers are caught by sprintf, on solaris -> segfault
|
|
||||||
*/
|
|
||||||
len = sprintf(trash, "appsession_refresh: cleaning up expired Session '%s' on Server %s\n",
|
|
||||||
element->sessid, element->serverid?element->serverid:"(null)");
|
element->sessid, element->serverid?element->serverid:"(null)");
|
||||||
if (write(1, trash, len) < 0) /* shut gcc warning */;
|
if (write(1, trash.str, trash.len) < 0) /* shut gcc warning */;
|
||||||
}
|
}
|
||||||
/* delete the expired element from within the hash table */
|
/* delete the expired element from within the hash table */
|
||||||
LIST_DEL(&element->hash_list);
|
LIST_DEL(&element->hash_list);
|
||||||
|
@ -582,7 +582,7 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
|
|||||||
global.tune.bufsize = atol(args[1]);
|
global.tune.bufsize = atol(args[1]);
|
||||||
if (global.tune.maxrewrite >= global.tune.bufsize / 2)
|
if (global.tune.maxrewrite >= global.tune.bufsize / 2)
|
||||||
global.tune.maxrewrite = global.tune.bufsize / 2;
|
global.tune.maxrewrite = global.tune.bufsize / 2;
|
||||||
trash = realloc(trash, global.tune.bufsize);
|
chunk_init(&trash, realloc(trash.str, global.tune.bufsize), global.tune.bufsize);
|
||||||
}
|
}
|
||||||
else if (!strcmp(args[0], "tune.maxrewrite")) {
|
else if (!strcmp(args[0], "tune.maxrewrite")) {
|
||||||
if (*(args[1]) == 0) {
|
if (*(args[1]) == 0) {
|
||||||
@ -1100,9 +1100,6 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
|
|||||||
if (kwl->kw[index].section != CFG_GLOBAL)
|
if (kwl->kw[index].section != CFG_GLOBAL)
|
||||||
continue;
|
continue;
|
||||||
if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
|
if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
|
||||||
/* prepare error message just in case */
|
|
||||||
snprintf(trash, global.tune.bufsize,
|
|
||||||
"error near '%s' in '%s' section", args[0], "global");
|
|
||||||
rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg);
|
rc = kwl->kw[index].parse(args, CFG_GLOBAL, NULL, NULL, file, linenum, &errmsg);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
|
Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
|
||||||
@ -2928,9 +2925,9 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
expr = sample_parse_expr(args, &myidx, trash, global.tune.bufsize);
|
expr = sample_parse_expr(args, &myidx, trash.str, trash.size);
|
||||||
if (!expr) {
|
if (!expr) {
|
||||||
Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], trash);
|
Alert("parsing [%s:%d] : '%s': %s\n", file, linenum, args[0], trash.str);
|
||||||
err_code |= ERR_ALERT | ERR_FATAL;
|
err_code |= ERR_ALERT | ERR_FATAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -5308,8 +5305,6 @@ stats_error_parsing:
|
|||||||
continue;
|
continue;
|
||||||
if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
|
if (strcmp(kwl->kw[index].kw, args[0]) == 0) {
|
||||||
/* prepare error message just in case */
|
/* prepare error message just in case */
|
||||||
snprintf(trash, global.tune.bufsize,
|
|
||||||
"error near '%s' in %s section", args[0], cursection);
|
|
||||||
rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, file, linenum, &errmsg);
|
rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, &defproxy, file, linenum, &errmsg);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
|
Alert("parsing [%s:%d] : %s\n", file, linenum, errmsg);
|
||||||
@ -6607,10 +6602,8 @@ out_uri_auth_compat:
|
|||||||
/* enable separate counters */
|
/* enable separate counters */
|
||||||
if (curproxy->options2 & PR_O2_SOCKSTAT) {
|
if (curproxy->options2 & PR_O2_SOCKSTAT) {
|
||||||
listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters));
|
listener->counters = (struct licounters *)calloc(1, sizeof(struct licounters));
|
||||||
if (!listener->name) {
|
if (!listener->name)
|
||||||
sprintf(trash, "sock-%d", listener->luid);
|
memprintf(&listener->name, "sock-%d", listener->luid);
|
||||||
listener->name = strdup(trash);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curproxy->options & PR_O_TCP_NOLING)
|
if (curproxy->options & PR_O_TCP_NOLING)
|
||||||
|
80
src/checks.c
80
src/checks.c
@ -198,10 +198,8 @@ static void server_status_printf(struct chunk *msg, struct server *s, unsigned o
|
|||||||
* Show information in logs about failed health check if server is UP
|
* Show information in logs about failed health check if server is UP
|
||||||
* or succeeded health checks if server is DOWN.
|
* or succeeded health checks if server is DOWN.
|
||||||
*/
|
*/
|
||||||
static void set_server_check_status(struct server *s, short status, char *desc) {
|
static void set_server_check_status(struct server *s, short status, char *desc)
|
||||||
|
{
|
||||||
struct chunk msg;
|
|
||||||
|
|
||||||
if (status == HCHK_STATUS_START) {
|
if (status == HCHK_STATUS_START) {
|
||||||
s->result = SRV_CHK_UNKNOWN; /* no result yet */
|
s->result = SRV_CHK_UNKNOWN; /* no result yet */
|
||||||
s->check.desc[0] = '\0';
|
s->check.desc[0] = '\0';
|
||||||
@ -238,7 +236,7 @@ static void set_server_check_status(struct server *s, short status, char *desc)
|
|||||||
|
|
||||||
int health, rise, fall, state;
|
int health, rise, fall, state;
|
||||||
|
|
||||||
chunk_init(&msg, trash, global.tune.bufsize);
|
chunk_reset(&trash);
|
||||||
|
|
||||||
/* FIXME begin: calculate local version of the health/rise/fall/state */
|
/* FIXME begin: calculate local version of the health/rise/fall/state */
|
||||||
health = s->health;
|
health = s->health;
|
||||||
@ -274,22 +272,22 @@ static void set_server_check_status(struct server *s, short status, char *desc)
|
|||||||
}
|
}
|
||||||
/* FIXME end: calculate local version of the health/rise/fall/state */
|
/* FIXME end: calculate local version of the health/rise/fall/state */
|
||||||
|
|
||||||
chunk_appendf(&msg,
|
chunk_appendf(&trash,
|
||||||
"Health check for %sserver %s/%s %s%s",
|
"Health check for %sserver %s/%s %s%s",
|
||||||
s->state & SRV_BACKUP ? "backup " : "",
|
s->state & SRV_BACKUP ? "backup " : "",
|
||||||
s->proxy->id, s->id,
|
s->proxy->id, s->id,
|
||||||
(s->result & SRV_CHK_DISABLE)?"conditionally ":"",
|
(s->result & SRV_CHK_DISABLE)?"conditionally ":"",
|
||||||
(s->result & SRV_CHK_RUNNING)?"succeeded":"failed");
|
(s->result & SRV_CHK_RUNNING)?"succeeded":"failed");
|
||||||
|
|
||||||
server_status_printf(&msg, s, SSP_O_HCHK, -1);
|
server_status_printf(&trash, s, SSP_O_HCHK, -1);
|
||||||
|
|
||||||
chunk_appendf(&msg, ", status: %d/%d %s",
|
chunk_appendf(&trash, ", status: %d/%d %s",
|
||||||
(state & SRV_RUNNING) ? (health - rise + 1) : (health),
|
(state & SRV_RUNNING) ? (health - rise + 1) : (health),
|
||||||
(state & SRV_RUNNING) ? (fall) : (rise),
|
(state & SRV_RUNNING) ? (fall) : (rise),
|
||||||
(state & SRV_RUNNING)?"UP":"DOWN");
|
(state & SRV_RUNNING)?"UP":"DOWN");
|
||||||
|
|
||||||
Warning("%s.\n", trash);
|
Warning("%s.\n", trash.str);
|
||||||
send_log(s->proxy, LOG_NOTICE, "%s.\n", trash);
|
send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,7 +391,6 @@ static void shutdown_backup_sessions(struct proxy *px, int why)
|
|||||||
void set_server_down(struct server *s)
|
void set_server_down(struct server *s)
|
||||||
{
|
{
|
||||||
struct server *srv;
|
struct server *srv;
|
||||||
struct chunk msg;
|
|
||||||
int xferred;
|
int xferred;
|
||||||
|
|
||||||
if (s->state & SRV_MAINTAIN) {
|
if (s->state & SRV_MAINTAIN) {
|
||||||
@ -418,28 +415,28 @@ void set_server_down(struct server *s)
|
|||||||
*/
|
*/
|
||||||
xferred = redistribute_pending(s);
|
xferred = redistribute_pending(s);
|
||||||
|
|
||||||
chunk_init(&msg, trash, global.tune.bufsize);
|
chunk_reset(&trash);
|
||||||
|
|
||||||
if (s->state & SRV_MAINTAIN) {
|
if (s->state & SRV_MAINTAIN) {
|
||||||
chunk_appendf(&msg,
|
chunk_appendf(&trash,
|
||||||
"%sServer %s/%s is DOWN for maintenance", s->state & SRV_BACKUP ? "Backup " : "",
|
"%sServer %s/%s is DOWN for maintenance", s->state & SRV_BACKUP ? "Backup " : "",
|
||||||
s->proxy->id, s->id);
|
s->proxy->id, s->id);
|
||||||
} else {
|
} else {
|
||||||
chunk_appendf(&msg,
|
chunk_appendf(&trash,
|
||||||
"%sServer %s/%s is DOWN", s->state & SRV_BACKUP ? "Backup " : "",
|
"%sServer %s/%s is DOWN", s->state & SRV_BACKUP ? "Backup " : "",
|
||||||
s->proxy->id, s->id);
|
s->proxy->id, s->id);
|
||||||
|
|
||||||
server_status_printf(&msg, s,
|
server_status_printf(&trash, s,
|
||||||
((!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? SSP_O_HCHK : 0),
|
((!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? SSP_O_HCHK : 0),
|
||||||
xferred);
|
xferred);
|
||||||
}
|
}
|
||||||
Warning("%s.\n", trash);
|
Warning("%s.\n", trash.str);
|
||||||
|
|
||||||
/* we don't send an alert if the server was previously paused */
|
/* we don't send an alert if the server was previously paused */
|
||||||
if (srv_was_paused)
|
if (srv_was_paused)
|
||||||
send_log(s->proxy, LOG_NOTICE, "%s.\n", trash);
|
send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.str);
|
||||||
else
|
else
|
||||||
send_log(s->proxy, LOG_ALERT, "%s.\n", trash);
|
send_log(s->proxy, LOG_ALERT, "%s.\n", trash.str);
|
||||||
|
|
||||||
if (prev_srv_count && s->proxy->srv_bck == 0 && s->proxy->srv_act == 0)
|
if (prev_srv_count && s->proxy->srv_bck == 0 && s->proxy->srv_act == 0)
|
||||||
set_backend_down(s->proxy);
|
set_backend_down(s->proxy);
|
||||||
@ -459,7 +456,6 @@ void set_server_down(struct server *s)
|
|||||||
void set_server_up(struct server *s) {
|
void set_server_up(struct server *s) {
|
||||||
|
|
||||||
struct server *srv;
|
struct server *srv;
|
||||||
struct chunk msg;
|
|
||||||
int xferred;
|
int xferred;
|
||||||
unsigned int old_state = s->state;
|
unsigned int old_state = s->state;
|
||||||
|
|
||||||
@ -510,24 +506,24 @@ void set_server_up(struct server *s) {
|
|||||||
*/
|
*/
|
||||||
xferred = check_for_pending(s);
|
xferred = check_for_pending(s);
|
||||||
|
|
||||||
chunk_init(&msg, trash, global.tune.bufsize);
|
chunk_reset(&trash);
|
||||||
|
|
||||||
if (old_state & SRV_MAINTAIN) {
|
if (old_state & SRV_MAINTAIN) {
|
||||||
chunk_appendf(&msg,
|
chunk_appendf(&trash,
|
||||||
"%sServer %s/%s is UP (leaving maintenance)", s->state & SRV_BACKUP ? "Backup " : "",
|
"%sServer %s/%s is UP (leaving maintenance)", s->state & SRV_BACKUP ? "Backup " : "",
|
||||||
s->proxy->id, s->id);
|
s->proxy->id, s->id);
|
||||||
} else {
|
} else {
|
||||||
chunk_appendf(&msg,
|
chunk_appendf(&trash,
|
||||||
"%sServer %s/%s is UP", s->state & SRV_BACKUP ? "Backup " : "",
|
"%sServer %s/%s is UP", s->state & SRV_BACKUP ? "Backup " : "",
|
||||||
s->proxy->id, s->id);
|
s->proxy->id, s->id);
|
||||||
|
|
||||||
server_status_printf(&msg, s,
|
server_status_printf(&trash, s,
|
||||||
((!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? SSP_O_HCHK : 0),
|
((!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? SSP_O_HCHK : 0),
|
||||||
xferred);
|
xferred);
|
||||||
}
|
}
|
||||||
|
|
||||||
Warning("%s.\n", trash);
|
Warning("%s.\n", trash.str);
|
||||||
send_log(s->proxy, LOG_NOTICE, "%s.\n", trash);
|
send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.str);
|
||||||
|
|
||||||
if (s->state & SRV_CHECKED)
|
if (s->state & SRV_CHECKED)
|
||||||
for(srv = s->tracknext; srv; srv = srv->tracknext)
|
for(srv = s->tracknext; srv; srv = srv->tracknext)
|
||||||
@ -544,7 +540,6 @@ void set_server_up(struct server *s) {
|
|||||||
static void set_server_disabled(struct server *s) {
|
static void set_server_disabled(struct server *s) {
|
||||||
|
|
||||||
struct server *srv;
|
struct server *srv;
|
||||||
struct chunk msg;
|
|
||||||
int xferred;
|
int xferred;
|
||||||
|
|
||||||
s->state |= SRV_GOINGDOWN;
|
s->state |= SRV_GOINGDOWN;
|
||||||
@ -557,19 +552,19 @@ static void set_server_disabled(struct server *s) {
|
|||||||
*/
|
*/
|
||||||
xferred = redistribute_pending(s);
|
xferred = redistribute_pending(s);
|
||||||
|
|
||||||
chunk_init(&msg, trash, global.tune.bufsize);
|
chunk_reset(&trash);
|
||||||
|
|
||||||
chunk_appendf(&msg,
|
chunk_appendf(&trash,
|
||||||
"Load-balancing on %sServer %s/%s is disabled",
|
"Load-balancing on %sServer %s/%s is disabled",
|
||||||
s->state & SRV_BACKUP ? "Backup " : "",
|
s->state & SRV_BACKUP ? "Backup " : "",
|
||||||
s->proxy->id, s->id);
|
s->proxy->id, s->id);
|
||||||
|
|
||||||
server_status_printf(&msg, s,
|
server_status_printf(&trash, s,
|
||||||
((!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? SSP_O_HCHK : 0),
|
((!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? SSP_O_HCHK : 0),
|
||||||
xferred);
|
xferred);
|
||||||
|
|
||||||
Warning("%s.\n", trash);
|
Warning("%s.\n", trash.str);
|
||||||
send_log(s->proxy, LOG_NOTICE, "%s.\n", trash);
|
send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.str);
|
||||||
|
|
||||||
if (!s->proxy->srv_bck && !s->proxy->srv_act)
|
if (!s->proxy->srv_bck && !s->proxy->srv_act)
|
||||||
set_backend_down(s->proxy);
|
set_backend_down(s->proxy);
|
||||||
@ -582,7 +577,6 @@ static void set_server_disabled(struct server *s) {
|
|||||||
static void set_server_enabled(struct server *s) {
|
static void set_server_enabled(struct server *s) {
|
||||||
|
|
||||||
struct server *srv;
|
struct server *srv;
|
||||||
struct chunk msg;
|
|
||||||
int xferred;
|
int xferred;
|
||||||
|
|
||||||
s->state &= ~SRV_GOINGDOWN;
|
s->state &= ~SRV_GOINGDOWN;
|
||||||
@ -594,27 +588,27 @@ static void set_server_enabled(struct server *s) {
|
|||||||
*/
|
*/
|
||||||
xferred = check_for_pending(s);
|
xferred = check_for_pending(s);
|
||||||
|
|
||||||
chunk_init(&msg, trash, global.tune.bufsize);
|
chunk_reset(&trash);
|
||||||
|
|
||||||
chunk_appendf(&msg,
|
chunk_appendf(&trash,
|
||||||
"Load-balancing on %sServer %s/%s is enabled again",
|
"Load-balancing on %sServer %s/%s is enabled again",
|
||||||
s->state & SRV_BACKUP ? "Backup " : "",
|
s->state & SRV_BACKUP ? "Backup " : "",
|
||||||
s->proxy->id, s->id);
|
s->proxy->id, s->id);
|
||||||
|
|
||||||
server_status_printf(&msg, s,
|
server_status_printf(&trash, s,
|
||||||
((!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? SSP_O_HCHK : 0),
|
((!s->track && !(s->proxy->options2 & PR_O2_LOGHCHKS)) ? SSP_O_HCHK : 0),
|
||||||
xferred);
|
xferred);
|
||||||
|
|
||||||
Warning("%s.\n", trash);
|
Warning("%s.\n", trash.str);
|
||||||
send_log(s->proxy, LOG_NOTICE, "%s.\n", trash);
|
send_log(s->proxy, LOG_NOTICE, "%s.\n", trash.str);
|
||||||
|
|
||||||
if (s->state & SRV_CHECKED)
|
if (s->state & SRV_CHECKED)
|
||||||
for(srv = s->tracknext; srv; srv = srv->tracknext)
|
for(srv = s->tracknext; srv; srv = srv->tracknext)
|
||||||
set_server_enabled(srv);
|
set_server_enabled(srv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void health_adjust(struct server *s, short status) {
|
void health_adjust(struct server *s, short status)
|
||||||
|
{
|
||||||
int failed;
|
int failed;
|
||||||
int expire;
|
int expire;
|
||||||
|
|
||||||
@ -652,7 +646,7 @@ void health_adjust(struct server *s, short status) {
|
|||||||
if (s->consecutive_errors < s->consecutive_errors_limit)
|
if (s->consecutive_errors < s->consecutive_errors_limit)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sprintf(trash, "Detected %d consecutive errors, last one was: %s",
|
chunk_printf(&trash, "Detected %d consecutive errors, last one was: %s",
|
||||||
s->consecutive_errors, get_analyze_status(status));
|
s->consecutive_errors, get_analyze_status(status));
|
||||||
|
|
||||||
switch (s->onerror) {
|
switch (s->onerror) {
|
||||||
@ -669,7 +663,7 @@ void health_adjust(struct server *s, short status) {
|
|||||||
|
|
||||||
case HANA_ONERR_FAILCHK:
|
case HANA_ONERR_FAILCHK:
|
||||||
/* simulate a failed health check */
|
/* simulate a failed health check */
|
||||||
set_server_check_status(s, HCHK_STATUS_HANA, trash);
|
set_server_check_status(s, HCHK_STATUS_HANA, trash.str);
|
||||||
|
|
||||||
if (s->health > s->rise) {
|
if (s->health > s->rise) {
|
||||||
s->health--; /* still good */
|
s->health--; /* still good */
|
||||||
@ -683,7 +677,7 @@ void health_adjust(struct server *s, short status) {
|
|||||||
case HANA_ONERR_MARKDWN:
|
case HANA_ONERR_MARKDWN:
|
||||||
/* mark server down */
|
/* mark server down */
|
||||||
s->health = s->rise;
|
s->health = s->rise;
|
||||||
set_server_check_status(s, HCHK_STATUS_HANA, trash);
|
set_server_check_status(s, HCHK_STATUS_HANA, trash.str);
|
||||||
set_server_down(s);
|
set_server_down(s);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -1298,7 +1292,7 @@ static struct task *process_chk(struct task *t)
|
|||||||
}
|
}
|
||||||
else if ((s->proxy->options2 & PR_O2_CHK_ANY) == PR_O2_HTTP_CHK) {
|
else if ((s->proxy->options2 & PR_O2_CHK_ANY) == PR_O2_HTTP_CHK) {
|
||||||
if (s->proxy->options2 & PR_O2_CHK_SNDST)
|
if (s->proxy->options2 & PR_O2_CHK_SNDST)
|
||||||
bo_putblk(s->check.bo, trash, httpchk_build_status_header(s, trash));
|
bo_putblk(s->check.bo, trash.str, httpchk_build_status_header(s, trash.str));
|
||||||
bo_putstr(s->check.bo, "\r\n");
|
bo_putstr(s->check.bo, "\r\n");
|
||||||
*s->check.bo->p = '\0'; /* to make gdb output easier to read */
|
*s->check.bo->p = '\0'; /* to make gdb output easier to read */
|
||||||
}
|
}
|
||||||
|
@ -282,15 +282,14 @@ void conn_update_sock_polling(struct connection *c)
|
|||||||
int conn_recv_proxy(struct connection *conn, int flag)
|
int conn_recv_proxy(struct connection *conn, int flag)
|
||||||
{
|
{
|
||||||
char *line, *end;
|
char *line, *end;
|
||||||
int len;
|
|
||||||
|
|
||||||
/* we might have been called just after an asynchronous shutr */
|
/* we might have been called just after an asynchronous shutr */
|
||||||
if (conn->flags & CO_FL_SOCK_RD_SH)
|
if (conn->flags & CO_FL_SOCK_RD_SH)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
len = recv(conn->t.sock.fd, trash, global.tune.bufsize, MSG_PEEK);
|
trash.len = recv(conn->t.sock.fd, trash.str, trash.size, MSG_PEEK);
|
||||||
if (len < 0) {
|
if (trash.len < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
if (errno == EAGAIN) {
|
if (errno == EAGAIN) {
|
||||||
@ -301,18 +300,18 @@ int conn_recv_proxy(struct connection *conn, int flag)
|
|||||||
}
|
}
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
if (len < 6)
|
if (trash.len < 6)
|
||||||
goto missing;
|
goto missing;
|
||||||
|
|
||||||
line = trash;
|
line = trash.str;
|
||||||
end = trash + len;
|
end = trash.str + trash.len;
|
||||||
|
|
||||||
/* Decode a possible proxy request, fail early if it does not match */
|
/* Decode a possible proxy request, fail early if it does not match */
|
||||||
if (strncmp(line, "PROXY ", 6) != 0)
|
if (strncmp(line, "PROXY ", 6) != 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
line += 6;
|
line += 6;
|
||||||
if (len < 18) /* shortest possible line */
|
if (trash.len < 18) /* shortest possible line */
|
||||||
goto missing;
|
goto missing;
|
||||||
|
|
||||||
if (!memcmp(line, "TCP4 ", 5) != 0) {
|
if (!memcmp(line, "TCP4 ", 5) != 0) {
|
||||||
@ -425,12 +424,12 @@ int conn_recv_proxy(struct connection *conn, int flag)
|
|||||||
* exact line at once. If we don't get the exact same result, we
|
* exact line at once. If we don't get the exact same result, we
|
||||||
* fail.
|
* fail.
|
||||||
*/
|
*/
|
||||||
len = line - trash;
|
trash.len = line - trash.str;
|
||||||
do {
|
do {
|
||||||
int len2 = recv(conn->t.sock.fd, trash, len, 0);
|
int len2 = recv(conn->t.sock.fd, trash.str, trash.len, 0);
|
||||||
if (len2 < 0 && errno == EINTR)
|
if (len2 < 0 && errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
if (len2 != len)
|
if (len2 != trash.len)
|
||||||
goto fail;
|
goto fail;
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
@ -542,7 +541,7 @@ int make_proxy_line(char *buf, int buf_len, struct sockaddr_storage *src, struct
|
|||||||
*/
|
*/
|
||||||
int conn_local_send_proxy(struct connection *conn, unsigned int flag)
|
int conn_local_send_proxy(struct connection *conn, unsigned int flag)
|
||||||
{
|
{
|
||||||
int ret, len;
|
int ret;
|
||||||
|
|
||||||
/* we might have been called just after an asynchronous shutw */
|
/* we might have been called just after an asynchronous shutw */
|
||||||
if (conn->flags & CO_FL_SOCK_WR_SH)
|
if (conn->flags & CO_FL_SOCK_WR_SH)
|
||||||
@ -557,14 +556,14 @@ int conn_local_send_proxy(struct connection *conn, unsigned int flag)
|
|||||||
if (!(conn->flags & CO_FL_ADDR_TO_SET))
|
if (!(conn->flags & CO_FL_ADDR_TO_SET))
|
||||||
goto out_error;
|
goto out_error;
|
||||||
|
|
||||||
len = make_proxy_line(trash, global.tune.bufsize, &conn->addr.from, &conn->addr.to);
|
trash.len = make_proxy_line(trash.str, trash.size, &conn->addr.from, &conn->addr.to);
|
||||||
if (!len)
|
if (!trash.len)
|
||||||
goto out_error;
|
goto out_error;
|
||||||
|
|
||||||
/* we have to send trash from len bytes. If the data layer has a
|
/* we have to send the whole trash. If the data layer has a
|
||||||
* pending write, we'll also set MSG_MORE.
|
* pending write, we'll also set MSG_MORE.
|
||||||
*/
|
*/
|
||||||
ret = send(conn->t.sock.fd, trash, len, (conn->flags & CO_FL_DATA_WR_ENA) ? MSG_MORE : 0);
|
ret = send(conn->t.sock.fd, trash.str, trash.len, (conn->flags & CO_FL_DATA_WR_ENA) ? MSG_MORE : 0);
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
goto out_wait;
|
goto out_wait;
|
||||||
@ -575,7 +574,7 @@ int conn_local_send_proxy(struct connection *conn, unsigned int flag)
|
|||||||
goto out_error;
|
goto out_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != len)
|
if (ret != trash.len)
|
||||||
goto out_error;
|
goto out_error;
|
||||||
|
|
||||||
/* The connection is ready now, simply return and let the connection
|
/* The connection is ready now, simply return and let the connection
|
||||||
|
534
src/dumpstats.c
534
src/dumpstats.c
File diff suppressed because it is too large
Load Diff
@ -163,26 +163,25 @@ int frontend_accept(struct session *s)
|
|||||||
|
|
||||||
if (unlikely((global.mode & MODE_DEBUG) && (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) {
|
if (unlikely((global.mode & MODE_DEBUG) && (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) {
|
||||||
char pn[INET6_ADDRSTRLEN];
|
char pn[INET6_ADDRSTRLEN];
|
||||||
int len = 0;
|
|
||||||
|
|
||||||
conn_get_from_addr(s->req->prod->conn);
|
conn_get_from_addr(s->req->prod->conn);
|
||||||
|
|
||||||
switch (addr_to_str(&s->req->prod->conn->addr.from, pn, sizeof(pn))) {
|
switch (addr_to_str(&s->req->prod->conn->addr.from, pn, sizeof(pn))) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
len = sprintf(trash, "%08x:%s.accept(%04x)=%04x from [%s:%d]\n",
|
chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [%s:%d]\n",
|
||||||
s->uniq_id, s->fe->id, (unsigned short)s->listener->fd, (unsigned short)cfd,
|
s->uniq_id, s->fe->id, (unsigned short)s->listener->fd, (unsigned short)cfd,
|
||||||
pn, get_host_port(&s->req->prod->conn->addr.from));
|
pn, get_host_port(&s->req->prod->conn->addr.from));
|
||||||
break;
|
break;
|
||||||
case AF_UNIX:
|
case AF_UNIX:
|
||||||
/* UNIX socket, only the destination is known */
|
/* UNIX socket, only the destination is known */
|
||||||
len = sprintf(trash, "%08x:%s.accept(%04x)=%04x from [unix:%d]\n",
|
chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [unix:%d]\n",
|
||||||
s->uniq_id, s->fe->id, (unsigned short)s->listener->fd, (unsigned short)cfd,
|
s->uniq_id, s->fe->id, (unsigned short)s->listener->fd, (unsigned short)cfd,
|
||||||
s->listener->luid);
|
s->listener->luid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write(1, trash, len) < 0) /* shut gcc warning */;
|
if (write(1, trash.str, trash.len) < 0) /* shut gcc warning */;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->fe->mode == PR_MODE_HTTP)
|
if (s->fe->mode == PR_MODE_HTTP)
|
||||||
|
@ -155,7 +155,7 @@ static int *oldpids = NULL;
|
|||||||
static int oldpids_sig; /* use USR1 or TERM */
|
static int oldpids_sig; /* use USR1 or TERM */
|
||||||
|
|
||||||
/* this is used to drain data, and as a temporary buffer for sprintf()... */
|
/* this is used to drain data, and as a temporary buffer for sprintf()... */
|
||||||
char *trash = NULL;
|
struct chunk trash = { };
|
||||||
|
|
||||||
/* this buffer is always the same size as standard buffers and is used for
|
/* this buffer is always the same size as standard buffers and is used for
|
||||||
* swapping data inside a buffer.
|
* swapping data inside a buffer.
|
||||||
@ -345,37 +345,37 @@ void sig_dump_state(struct sig_handler *sh)
|
|||||||
|
|
||||||
send_log(p, LOG_NOTICE, "SIGHUP received, dumping servers states for proxy %s.\n", p->id);
|
send_log(p, LOG_NOTICE, "SIGHUP received, dumping servers states for proxy %s.\n", p->id);
|
||||||
while (s) {
|
while (s) {
|
||||||
snprintf(trash, global.tune.bufsize,
|
chunk_printf(&trash,
|
||||||
"SIGHUP: Server %s/%s is %s. Conn: %d act, %d pend, %lld tot.",
|
"SIGHUP: Server %s/%s is %s. Conn: %d act, %d pend, %lld tot.",
|
||||||
p->id, s->id,
|
p->id, s->id,
|
||||||
(s->state & SRV_RUNNING) ? "UP" : "DOWN",
|
(s->state & SRV_RUNNING) ? "UP" : "DOWN",
|
||||||
s->cur_sess, s->nbpend, s->counters.cum_sess);
|
s->cur_sess, s->nbpend, s->counters.cum_sess);
|
||||||
Warning("%s\n", trash);
|
Warning("%s\n", trash.str);
|
||||||
send_log(p, LOG_NOTICE, "%s\n", trash);
|
send_log(p, LOG_NOTICE, "%s\n", trash.str);
|
||||||
s = s->next;
|
s = s->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: those info are a bit outdated. We should be able to distinguish between FE and BE. */
|
/* FIXME: those info are a bit outdated. We should be able to distinguish between FE and BE. */
|
||||||
if (!p->srv) {
|
if (!p->srv) {
|
||||||
snprintf(trash, global.tune.bufsize,
|
chunk_printf(&trash,
|
||||||
"SIGHUP: Proxy %s has no servers. Conn: act(FE+BE): %d+%d, %d pend (%d unass), tot(FE+BE): %lld+%lld.",
|
"SIGHUP: Proxy %s has no servers. Conn: act(FE+BE): %d+%d, %d pend (%d unass), tot(FE+BE): %lld+%lld.",
|
||||||
p->id,
|
p->id,
|
||||||
p->feconn, p->beconn, p->totpend, p->nbpend, p->fe_counters.cum_conn, p->be_counters.cum_conn);
|
p->feconn, p->beconn, p->totpend, p->nbpend, p->fe_counters.cum_conn, p->be_counters.cum_conn);
|
||||||
} else if (p->srv_act == 0) {
|
} else if (p->srv_act == 0) {
|
||||||
snprintf(trash, global.tune.bufsize,
|
chunk_printf(&trash,
|
||||||
"SIGHUP: Proxy %s %s ! Conn: act(FE+BE): %d+%d, %d pend (%d unass), tot(FE+BE): %lld+%lld.",
|
"SIGHUP: Proxy %s %s ! Conn: act(FE+BE): %d+%d, %d pend (%d unass), tot(FE+BE): %lld+%lld.",
|
||||||
p->id,
|
p->id,
|
||||||
(p->srv_bck) ? "is running on backup servers" : "has no server available",
|
(p->srv_bck) ? "is running on backup servers" : "has no server available",
|
||||||
p->feconn, p->beconn, p->totpend, p->nbpend, p->fe_counters.cum_conn, p->be_counters.cum_conn);
|
p->feconn, p->beconn, p->totpend, p->nbpend, p->fe_counters.cum_conn, p->be_counters.cum_conn);
|
||||||
} else {
|
} else {
|
||||||
snprintf(trash, global.tune.bufsize,
|
chunk_printf(&trash,
|
||||||
"SIGHUP: Proxy %s has %d active servers and %d backup servers available."
|
"SIGHUP: Proxy %s has %d active servers and %d backup servers available."
|
||||||
" Conn: act(FE+BE): %d+%d, %d pend (%d unass), tot(FE+BE): %lld+%lld.",
|
" Conn: act(FE+BE): %d+%d, %d pend (%d unass), tot(FE+BE): %lld+%lld.",
|
||||||
p->id, p->srv_act, p->srv_bck,
|
p->id, p->srv_act, p->srv_bck,
|
||||||
p->feconn, p->beconn, p->totpend, p->nbpend, p->fe_counters.cum_conn, p->be_counters.cum_conn);
|
p->feconn, p->beconn, p->totpend, p->nbpend, p->fe_counters.cum_conn, p->be_counters.cum_conn);
|
||||||
}
|
}
|
||||||
Warning("%s\n", trash);
|
Warning("%s\n", trash.str);
|
||||||
send_log(p, LOG_NOTICE, "%s\n", trash);
|
send_log(p, LOG_NOTICE, "%s\n", trash.str);
|
||||||
|
|
||||||
p = p->next;
|
p = p->next;
|
||||||
}
|
}
|
||||||
@ -403,7 +403,7 @@ void init(int argc, char **argv)
|
|||||||
char *change_dir = NULL;
|
char *change_dir = NULL;
|
||||||
struct tm curtime;
|
struct tm curtime;
|
||||||
|
|
||||||
trash = malloc(global.tune.bufsize);
|
chunk_init(&trash, malloc(global.tune.bufsize), global.tune.bufsize);
|
||||||
|
|
||||||
/* NB: POSIX does not make it mandatory for gethostname() to NULL-terminate
|
/* NB: POSIX does not make it mandatory for gethostname() to NULL-terminate
|
||||||
* the string in case of truncation, and at least FreeBSD appears not to do
|
* the string in case of truncation, and at least FreeBSD appears not to do
|
||||||
|
102
src/peers.c
102
src/peers.c
@ -230,30 +230,30 @@ switchstate:
|
|||||||
si->applet.st0 = PEER_SESSION_GETVERSION;
|
si->applet.st0 = PEER_SESSION_GETVERSION;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case PEER_SESSION_GETVERSION:
|
case PEER_SESSION_GETVERSION:
|
||||||
reql = bo_getline(si->ob, trash, global.tune.bufsize);
|
reql = bo_getline(si->ob, trash.str, trash.size);
|
||||||
if (reql <= 0) { /* closed or EOL not found */
|
if (reql <= 0) { /* closed or EOL not found */
|
||||||
if (reql == 0)
|
if (reql == 0)
|
||||||
goto out;
|
goto out;
|
||||||
si->applet.st0 = PEER_SESSION_END;
|
si->applet.st0 = PEER_SESSION_END;
|
||||||
goto switchstate;
|
goto switchstate;
|
||||||
}
|
}
|
||||||
if (trash[reql-1] != '\n') {
|
if (trash.str[reql-1] != '\n') {
|
||||||
si->applet.st0 = PEER_SESSION_END;
|
si->applet.st0 = PEER_SESSION_END;
|
||||||
goto switchstate;
|
goto switchstate;
|
||||||
}
|
}
|
||||||
else if (reql > 1 && (trash[reql-2] == '\r'))
|
else if (reql > 1 && (trash.str[reql-2] == '\r'))
|
||||||
trash[reql-2] = 0;
|
trash.str[reql-2] = 0;
|
||||||
else
|
else
|
||||||
trash[reql-1] = 0;
|
trash.str[reql-1] = 0;
|
||||||
|
|
||||||
bo_skip(si->ob, reql);
|
bo_skip(si->ob, reql);
|
||||||
|
|
||||||
/* test version */
|
/* test version */
|
||||||
if (strcmp(PEER_SESSION_PROTO_NAME " 1.0", trash) != 0) {
|
if (strcmp(PEER_SESSION_PROTO_NAME " 1.0", trash.str) != 0) {
|
||||||
si->applet.st0 = PEER_SESSION_EXIT;
|
si->applet.st0 = PEER_SESSION_EXIT;
|
||||||
si->applet.st1 = PEER_SESSION_ERRVERSION;
|
si->applet.st1 = PEER_SESSION_ERRVERSION;
|
||||||
/* test protocol */
|
/* test protocol */
|
||||||
if (strncmp(PEER_SESSION_PROTO_NAME " ", trash, strlen(PEER_SESSION_PROTO_NAME)+1) != 0)
|
if (strncmp(PEER_SESSION_PROTO_NAME " ", trash.str, strlen(PEER_SESSION_PROTO_NAME)+1) != 0)
|
||||||
si->applet.st1 = PEER_SESSION_ERRPROTO;
|
si->applet.st1 = PEER_SESSION_ERRPROTO;
|
||||||
goto switchstate;
|
goto switchstate;
|
||||||
}
|
}
|
||||||
@ -261,26 +261,26 @@ switchstate:
|
|||||||
si->applet.st0 = PEER_SESSION_GETHOST;
|
si->applet.st0 = PEER_SESSION_GETHOST;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
case PEER_SESSION_GETHOST:
|
case PEER_SESSION_GETHOST:
|
||||||
reql = bo_getline(si->ob, trash, global.tune.bufsize);
|
reql = bo_getline(si->ob, trash.str, trash.size);
|
||||||
if (reql <= 0) { /* closed or EOL not found */
|
if (reql <= 0) { /* closed or EOL not found */
|
||||||
if (reql == 0)
|
if (reql == 0)
|
||||||
goto out;
|
goto out;
|
||||||
si->applet.st0 = PEER_SESSION_END;
|
si->applet.st0 = PEER_SESSION_END;
|
||||||
goto switchstate;
|
goto switchstate;
|
||||||
}
|
}
|
||||||
if (trash[reql-1] != '\n') {
|
if (trash.str[reql-1] != '\n') {
|
||||||
si->applet.st0 = PEER_SESSION_END;
|
si->applet.st0 = PEER_SESSION_END;
|
||||||
goto switchstate;
|
goto switchstate;
|
||||||
}
|
}
|
||||||
else if (reql > 1 && (trash[reql-2] == '\r'))
|
else if (reql > 1 && (trash.str[reql-2] == '\r'))
|
||||||
trash[reql-2] = 0;
|
trash.str[reql-2] = 0;
|
||||||
else
|
else
|
||||||
trash[reql-1] = 0;
|
trash.str[reql-1] = 0;
|
||||||
|
|
||||||
bo_skip(si->ob, reql);
|
bo_skip(si->ob, reql);
|
||||||
|
|
||||||
/* test hostname match */
|
/* test hostname match */
|
||||||
if (strcmp(localpeer, trash) != 0) {
|
if (strcmp(localpeer, trash.str) != 0) {
|
||||||
si->applet.st0 = PEER_SESSION_EXIT;
|
si->applet.st0 = PEER_SESSION_EXIT;
|
||||||
si->applet.st1 = PEER_SESSION_ERRHOST;
|
si->applet.st1 = PEER_SESSION_ERRHOST;
|
||||||
goto switchstate;
|
goto switchstate;
|
||||||
@ -291,27 +291,27 @@ switchstate:
|
|||||||
case PEER_SESSION_GETPEER: {
|
case PEER_SESSION_GETPEER: {
|
||||||
struct peer *curpeer;
|
struct peer *curpeer;
|
||||||
char *p;
|
char *p;
|
||||||
reql = bo_getline(si->ob, trash, global.tune.bufsize);
|
reql = bo_getline(si->ob, trash.str, trash.size);
|
||||||
if (reql <= 0) { /* closed or EOL not found */
|
if (reql <= 0) { /* closed or EOL not found */
|
||||||
if (reql == 0)
|
if (reql == 0)
|
||||||
goto out;
|
goto out;
|
||||||
si->applet.st0 = PEER_SESSION_END;
|
si->applet.st0 = PEER_SESSION_END;
|
||||||
goto switchstate;
|
goto switchstate;
|
||||||
}
|
}
|
||||||
if (trash[reql-1] != '\n') {
|
if (trash.str[reql-1] != '\n') {
|
||||||
/* Incomplete line, we quit */
|
/* Incomplete line, we quit */
|
||||||
si->applet.st0 = PEER_SESSION_END;
|
si->applet.st0 = PEER_SESSION_END;
|
||||||
goto switchstate;
|
goto switchstate;
|
||||||
}
|
}
|
||||||
else if (reql > 1 && (trash[reql-2] == '\r'))
|
else if (reql > 1 && (trash.str[reql-2] == '\r'))
|
||||||
trash[reql-2] = 0;
|
trash.str[reql-2] = 0;
|
||||||
else
|
else
|
||||||
trash[reql-1] = 0;
|
trash.str[reql-1] = 0;
|
||||||
|
|
||||||
bo_skip(si->ob, reql);
|
bo_skip(si->ob, reql);
|
||||||
|
|
||||||
/* parse line "<peer name> <pid>" */
|
/* parse line "<peer name> <pid>" */
|
||||||
p = strchr(trash, ' ');
|
p = strchr(trash.str, ' ');
|
||||||
if (!p) {
|
if (!p) {
|
||||||
si->applet.st0 = PEER_SESSION_EXIT;
|
si->applet.st0 = PEER_SESSION_EXIT;
|
||||||
si->applet.st1 = PEER_SESSION_ERRPROTO;
|
si->applet.st1 = PEER_SESSION_ERRPROTO;
|
||||||
@ -321,7 +321,7 @@ switchstate:
|
|||||||
|
|
||||||
/* lookup known peer */
|
/* lookup known peer */
|
||||||
for (curpeer = curpeers->remote; curpeer; curpeer = curpeer->next) {
|
for (curpeer = curpeers->remote; curpeer; curpeer = curpeer->next) {
|
||||||
if (strcmp(curpeer->id, trash) == 0)
|
if (strcmp(curpeer->id, trash.str) == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,7 +344,7 @@ switchstate:
|
|||||||
size_t key_size;
|
size_t key_size;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
reql = bo_getline(si->ob, trash, global.tune.bufsize);
|
reql = bo_getline(si->ob, trash.str, trash.size);
|
||||||
if (reql <= 0) { /* closed or EOL not found */
|
if (reql <= 0) { /* closed or EOL not found */
|
||||||
if (reql == 0)
|
if (reql == 0)
|
||||||
goto out;
|
goto out;
|
||||||
@ -355,20 +355,20 @@ switchstate:
|
|||||||
/* Re init si->conn->xprt_ctx to null, to handle correctly a release case */
|
/* Re init si->conn->xprt_ctx to null, to handle correctly a release case */
|
||||||
si->conn->xprt_ctx = NULL;
|
si->conn->xprt_ctx = NULL;
|
||||||
|
|
||||||
if (trash[reql-1] != '\n') {
|
if (trash.str[reql-1] != '\n') {
|
||||||
/* Incomplete line, we quit */
|
/* Incomplete line, we quit */
|
||||||
si->applet.st0 = PEER_SESSION_END;
|
si->applet.st0 = PEER_SESSION_END;
|
||||||
goto switchstate;
|
goto switchstate;
|
||||||
}
|
}
|
||||||
else if (reql > 1 && (trash[reql-2] == '\r'))
|
else if (reql > 1 && (trash.str[reql-2] == '\r'))
|
||||||
trash[reql-2] = 0;
|
trash.str[reql-2] = 0;
|
||||||
else
|
else
|
||||||
trash[reql-1] = 0;
|
trash.str[reql-1] = 0;
|
||||||
|
|
||||||
bo_skip(si->ob, reql);
|
bo_skip(si->ob, reql);
|
||||||
|
|
||||||
/* Parse line "<table name> <type> <size>" */
|
/* Parse line "<table name> <type> <size>" */
|
||||||
p = strchr(trash, ' ');
|
p = strchr(trash.str, ' ');
|
||||||
if (!p) {
|
if (!p) {
|
||||||
si->applet.st0 = PEER_SESSION_EXIT;
|
si->applet.st0 = PEER_SESSION_EXIT;
|
||||||
si->applet.st1 = PEER_SESSION_ERRPROTO;
|
si->applet.st1 = PEER_SESSION_ERRPROTO;
|
||||||
@ -388,7 +388,7 @@ switchstate:
|
|||||||
key_size = (size_t)atoi(p);
|
key_size = (size_t)atoi(p);
|
||||||
for (st = curpeers->tables; st; st = st->next) {
|
for (st = curpeers->tables; st; st = st->next) {
|
||||||
/* If table name matches */
|
/* If table name matches */
|
||||||
if (strcmp(st->table->id, trash) == 0) {
|
if (strcmp(st->table->id, trash.str) == 0) {
|
||||||
/* If key size mismatches */
|
/* If key size mismatches */
|
||||||
if (key_size != st->table->key_size) {
|
if (key_size != st->table->key_size) {
|
||||||
si->applet.st0 = PEER_SESSION_EXIT;
|
si->applet.st0 = PEER_SESSION_EXIT;
|
||||||
@ -445,8 +445,8 @@ switchstate:
|
|||||||
case PEER_SESSION_SENDSUCCESS:{
|
case PEER_SESSION_SENDSUCCESS:{
|
||||||
struct peer_session *ps = (struct peer_session *)si->conn->xprt_ctx;
|
struct peer_session *ps = (struct peer_session *)si->conn->xprt_ctx;
|
||||||
|
|
||||||
repl = snprintf(trash, global.tune.bufsize, "%d\n", PEER_SESSION_SUCCESSCODE);
|
repl = snprintf(trash.str, trash.size, "%d\n", PEER_SESSION_SUCCESSCODE);
|
||||||
repl = bi_putblk(si->ib, trash, repl);
|
repl = bi_putblk(si->ib, trash.str, repl);
|
||||||
if (repl <= 0) {
|
if (repl <= 0) {
|
||||||
if (repl == -1)
|
if (repl == -1)
|
||||||
goto out;
|
goto out;
|
||||||
@ -496,7 +496,7 @@ switchstate:
|
|||||||
struct peer_session *ps = (struct peer_session *)si->conn->xprt_ctx;
|
struct peer_session *ps = (struct peer_session *)si->conn->xprt_ctx;
|
||||||
|
|
||||||
/* Send headers */
|
/* Send headers */
|
||||||
repl = snprintf(trash, global.tune.bufsize,
|
repl = snprintf(trash.str, trash.size,
|
||||||
PEER_SESSION_PROTO_NAME " 1.0\n%s\n%s %d\n%s %lu %d\n",
|
PEER_SESSION_PROTO_NAME " 1.0\n%s\n%s %d\n%s %lu %d\n",
|
||||||
ps->peer->id,
|
ps->peer->id,
|
||||||
localpeer,
|
localpeer,
|
||||||
@ -505,12 +505,12 @@ switchstate:
|
|||||||
ps->table->table->type,
|
ps->table->table->type,
|
||||||
(int)ps->table->table->key_size);
|
(int)ps->table->table->key_size);
|
||||||
|
|
||||||
if (repl >= global.tune.bufsize) {
|
if (repl >= trash.size) {
|
||||||
si->applet.st0 = PEER_SESSION_END;
|
si->applet.st0 = PEER_SESSION_END;
|
||||||
goto switchstate;
|
goto switchstate;
|
||||||
}
|
}
|
||||||
|
|
||||||
repl = bi_putblk(si->ib, trash, repl);
|
repl = bi_putblk(si->ib, trash.str, repl);
|
||||||
if (repl <= 0) {
|
if (repl <= 0) {
|
||||||
if (repl == -1)
|
if (repl == -1)
|
||||||
goto out;
|
goto out;
|
||||||
@ -528,27 +528,27 @@ switchstate:
|
|||||||
if (si->ib->flags & CF_WRITE_PARTIAL)
|
if (si->ib->flags & CF_WRITE_PARTIAL)
|
||||||
ps->statuscode = PEER_SESSION_CONNECTEDCODE;
|
ps->statuscode = PEER_SESSION_CONNECTEDCODE;
|
||||||
|
|
||||||
reql = bo_getline(si->ob, trash, global.tune.bufsize);
|
reql = bo_getline(si->ob, trash.str, trash.size);
|
||||||
if (reql <= 0) { /* closed or EOL not found */
|
if (reql <= 0) { /* closed or EOL not found */
|
||||||
if (reql == 0)
|
if (reql == 0)
|
||||||
goto out;
|
goto out;
|
||||||
si->applet.st0 = PEER_SESSION_END;
|
si->applet.st0 = PEER_SESSION_END;
|
||||||
goto switchstate;
|
goto switchstate;
|
||||||
}
|
}
|
||||||
if (trash[reql-1] != '\n') {
|
if (trash.str[reql-1] != '\n') {
|
||||||
/* Incomplete line, we quit */
|
/* Incomplete line, we quit */
|
||||||
si->applet.st0 = PEER_SESSION_END;
|
si->applet.st0 = PEER_SESSION_END;
|
||||||
goto switchstate;
|
goto switchstate;
|
||||||
}
|
}
|
||||||
else if (reql > 1 && (trash[reql-2] == '\r'))
|
else if (reql > 1 && (trash.str[reql-2] == '\r'))
|
||||||
trash[reql-2] = 0;
|
trash.str[reql-2] = 0;
|
||||||
else
|
else
|
||||||
trash[reql-1] = 0;
|
trash.str[reql-1] = 0;
|
||||||
|
|
||||||
bo_skip(si->ob, reql);
|
bo_skip(si->ob, reql);
|
||||||
|
|
||||||
/* Register status code */
|
/* Register status code */
|
||||||
ps->statuscode = atoi(trash);
|
ps->statuscode = atoi(trash.str);
|
||||||
|
|
||||||
/* Awake main task */
|
/* Awake main task */
|
||||||
task_wakeup(ps->table->sync_task, TASK_WOKEN_MSG);
|
task_wakeup(ps->table->sync_task, TASK_WOKEN_MSG);
|
||||||
@ -866,11 +866,11 @@ incomplete:
|
|||||||
if (ps->pushack != ps->lastack) {
|
if (ps->pushack != ps->lastack) {
|
||||||
uint32_t netinteger;
|
uint32_t netinteger;
|
||||||
|
|
||||||
trash[0] = 'A';
|
trash.str[0] = 'A';
|
||||||
netinteger = htonl(ps->pushack);
|
netinteger = htonl(ps->pushack);
|
||||||
memcpy(&trash[1], &netinteger, sizeof(netinteger));
|
memcpy(&trash.str[1], &netinteger, sizeof(netinteger));
|
||||||
|
|
||||||
repl = bi_putblk(si->ib, trash, 1+sizeof(netinteger));
|
repl = bi_putblk(si->ib, trash.str, 1+sizeof(netinteger));
|
||||||
if (repl <= 0) {
|
if (repl <= 0) {
|
||||||
/* no more write possible */
|
/* no more write possible */
|
||||||
if (repl == -1)
|
if (repl == -1)
|
||||||
@ -903,10 +903,10 @@ incomplete:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ts = eb32_entry(eb, struct stksess, upd);
|
ts = eb32_entry(eb, struct stksess, upd);
|
||||||
msglen = peer_prepare_datamsg(ts, ps, trash, global.tune.bufsize);
|
msglen = peer_prepare_datamsg(ts, ps, trash.str, trash.size);
|
||||||
if (msglen) {
|
if (msglen) {
|
||||||
/* message to buffer */
|
/* message to buffer */
|
||||||
repl = bi_putblk(si->ib, trash, msglen);
|
repl = bi_putblk(si->ib, trash.str, msglen);
|
||||||
if (repl <= 0) {
|
if (repl <= 0) {
|
||||||
/* no more write possible */
|
/* no more write possible */
|
||||||
if (repl == -1)
|
if (repl == -1)
|
||||||
@ -937,10 +937,10 @@ incomplete:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ts = eb32_entry(eb, struct stksess, upd);
|
ts = eb32_entry(eb, struct stksess, upd);
|
||||||
msglen = peer_prepare_datamsg(ts, ps, trash, global.tune.bufsize);
|
msglen = peer_prepare_datamsg(ts, ps, trash.str, trash.size);
|
||||||
if (msglen) {
|
if (msglen) {
|
||||||
/* message to buffer */
|
/* message to buffer */
|
||||||
repl = bi_putblk(si->ib, trash, msglen);
|
repl = bi_putblk(si->ib, trash.str, msglen);
|
||||||
if (repl <= 0) {
|
if (repl <= 0) {
|
||||||
/* no more write possible */
|
/* no more write possible */
|
||||||
if (repl == -1)
|
if (repl == -1)
|
||||||
@ -995,10 +995,10 @@ incomplete:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ts = eb32_entry(eb, struct stksess, upd);
|
ts = eb32_entry(eb, struct stksess, upd);
|
||||||
msglen = peer_prepare_datamsg(ts, ps, trash, global.tune.bufsize);
|
msglen = peer_prepare_datamsg(ts, ps, trash.str, trash.size);
|
||||||
if (msglen) {
|
if (msglen) {
|
||||||
/* message to buffer */
|
/* message to buffer */
|
||||||
repl = bi_putblk(si->ib, trash, msglen);
|
repl = bi_putblk(si->ib, trash.str, msglen);
|
||||||
if (repl <= 0) {
|
if (repl <= 0) {
|
||||||
/* no more write possible */
|
/* no more write possible */
|
||||||
if (repl == -1)
|
if (repl == -1)
|
||||||
@ -1015,9 +1015,9 @@ incomplete:
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
case PEER_SESSION_EXIT:
|
case PEER_SESSION_EXIT:
|
||||||
repl = snprintf(trash, global.tune.bufsize, "%d\n", si->applet.st1);
|
repl = snprintf(trash.str, trash.size, "%d\n", si->applet.st1);
|
||||||
|
|
||||||
if (bi_putblk(si->ib, trash, repl) == -1)
|
if (bi_putblk(si->ib, trash.str, repl) == -1)
|
||||||
goto out;
|
goto out;
|
||||||
si->applet.st0 = PEER_SESSION_END;
|
si->applet.st0 = PEER_SESSION_END;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
@ -1229,7 +1229,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
|
|||||||
if ((s->req->buf = pool_alloc2(pool2_buffer)) == NULL)
|
if ((s->req->buf = pool_alloc2(pool2_buffer)) == NULL)
|
||||||
goto out_fail_req_buf; /* no memory */
|
goto out_fail_req_buf; /* no memory */
|
||||||
|
|
||||||
s->req->buf->size = global.tune.bufsize;
|
s->req->buf->size = trash.size;
|
||||||
channel_init(s->req);
|
channel_init(s->req);
|
||||||
s->req->prod = &s->si[0];
|
s->req->prod = &s->si[0];
|
||||||
s->req->cons = &s->si[1];
|
s->req->cons = &s->si[1];
|
||||||
@ -1255,7 +1255,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
|
|||||||
if ((s->rep->buf = pool_alloc2(pool2_buffer)) == NULL)
|
if ((s->rep->buf = pool_alloc2(pool2_buffer)) == NULL)
|
||||||
goto out_fail_rep_buf; /* no memory */
|
goto out_fail_rep_buf; /* no memory */
|
||||||
|
|
||||||
s->rep->buf->size = global.tune.bufsize;
|
s->rep->buf->size = trash.size;
|
||||||
channel_init(s->rep);
|
channel_init(s->rep);
|
||||||
s->rep->prod = &s->si[1];
|
s->rep->prod = &s->si[1];
|
||||||
s->rep->cons = &s->si[0];
|
s->rep->cons = &s->si[0];
|
||||||
|
255
src/proto_http.c
255
src/proto_http.c
@ -390,21 +390,19 @@ const char http_is_ver_token[256] = {
|
|||||||
#if defined(DEBUG_FSM)
|
#if defined(DEBUG_FSM)
|
||||||
static void http_silent_debug(int line, struct session *s)
|
static void http_silent_debug(int line, struct session *s)
|
||||||
{
|
{
|
||||||
int size = 0;
|
chunk_printf(&trash,
|
||||||
size += snprintf(trash + size, global.tune.bufsize - size,
|
|
||||||
"[%04d] req: p=%d(%d) s=%d bf=%08x an=%08x data=%p size=%d l=%d w=%p r=%p o=%p sm=%d fw=%ld tf=%08x\n",
|
"[%04d] req: p=%d(%d) s=%d bf=%08x an=%08x data=%p size=%d l=%d w=%p r=%p o=%p sm=%d fw=%ld tf=%08x\n",
|
||||||
line,
|
line,
|
||||||
s->si[0].state, s->si[0].fd, s->txn.req.msg_state, s->req->flags, s->req->analysers,
|
s->si[0].state, s->si[0].fd, s->txn.req.msg_state, s->req->flags, s->req->analysers,
|
||||||
s->req->buf->data, s->req->buf->size, s->req->l, s->req->w, s->req->r, s->req->buf->p, s->req->buf->o, s->req->to_forward, s->txn.flags);
|
s->req->buf->data, s->req->buf->size, s->req->l, s->req->w, s->req->r, s->req->buf->p, s->req->buf->o, s->req->to_forward, s->txn.flags);
|
||||||
write(-1, trash, size);
|
write(-1, trash.str, trash.len);
|
||||||
size = 0;
|
|
||||||
size += snprintf(trash + size, global.tune.bufsize - size,
|
chunk_printf(&trash,
|
||||||
" %04d rep: p=%d(%d) s=%d bf=%08x an=%08x data=%p size=%d l=%d w=%p r=%p o=%p sm=%d fw=%ld\n",
|
" %04d rep: p=%d(%d) s=%d bf=%08x an=%08x data=%p size=%d l=%d w=%p r=%p o=%p sm=%d fw=%ld\n",
|
||||||
line,
|
line,
|
||||||
s->si[1].state, s->si[1].fd, s->txn.rsp.msg_state, s->rep->flags, s->rep->analysers,
|
s->si[1].state, s->si[1].fd, s->txn.rsp.msg_state, s->rep->flags, s->rep->analysers,
|
||||||
s->rep->buf->data, s->rep->buf->size, s->rep->l, s->rep->w, s->rep->r, s->rep->buf->p, s->rep->buf->o, s->rep->to_forward);
|
s->rep->buf->data, s->rep->buf->size, s->rep->l, s->rep->w, s->rep->r, s->rep->buf->p, s->rep->buf->o, s->rep->to_forward);
|
||||||
|
write(-1, trash.str, trash.len);
|
||||||
write(-1, trash, size);
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define http_silent_debug(l,s) do { } while (0)
|
#define http_silent_debug(l,s) do { } while (0)
|
||||||
@ -761,27 +759,24 @@ http_get_path(struct http_txn *txn)
|
|||||||
void perform_http_redirect(struct session *s, struct stream_interface *si)
|
void perform_http_redirect(struct session *s, struct stream_interface *si)
|
||||||
{
|
{
|
||||||
struct http_txn *txn;
|
struct http_txn *txn;
|
||||||
struct chunk rdr;
|
|
||||||
struct server *srv;
|
struct server *srv;
|
||||||
char *path;
|
char *path;
|
||||||
int len, rewind;
|
int len, rewind;
|
||||||
|
|
||||||
/* 1: create the response header */
|
/* 1: create the response header */
|
||||||
rdr.len = strlen(HTTP_302);
|
trash.len = strlen(HTTP_302);
|
||||||
rdr.str = trash;
|
memcpy(trash.str, HTTP_302, trash.len);
|
||||||
rdr.size = global.tune.bufsize;
|
|
||||||
memcpy(rdr.str, HTTP_302, rdr.len);
|
|
||||||
|
|
||||||
srv = target_srv(&s->target);
|
srv = target_srv(&s->target);
|
||||||
|
|
||||||
/* 2: add the server's prefix */
|
/* 2: add the server's prefix */
|
||||||
if (rdr.len + srv->rdr_len > rdr.size)
|
if (trash.len + srv->rdr_len > trash.size)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* special prefix "/" means don't change URL */
|
/* special prefix "/" means don't change URL */
|
||||||
if (srv->rdr_len != 1 || *srv->rdr_pfx != '/') {
|
if (srv->rdr_len != 1 || *srv->rdr_pfx != '/') {
|
||||||
memcpy(rdr.str + rdr.len, srv->rdr_pfx, srv->rdr_len);
|
memcpy(trash.str + trash.len, srv->rdr_pfx, srv->rdr_len);
|
||||||
rdr.len += srv->rdr_len;
|
trash.len += srv->rdr_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 3: add the request URI. Since it was already forwarded, we need
|
/* 3: add the request URI. Since it was already forwarded, we need
|
||||||
@ -798,18 +793,18 @@ void perform_http_redirect(struct session *s, struct stream_interface *si)
|
|||||||
if (!path)
|
if (!path)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (rdr.len + len > rdr.size - 4) /* 4 for CRLF-CRLF */
|
if (trash.len + len > trash.size - 4) /* 4 for CRLF-CRLF */
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memcpy(rdr.str + rdr.len, path, len);
|
memcpy(trash.str + trash.len, path, len);
|
||||||
rdr.len += len;
|
trash.len += len;
|
||||||
|
|
||||||
if (unlikely(txn->flags & TX_USE_PX_CONN)) {
|
if (unlikely(txn->flags & TX_USE_PX_CONN)) {
|
||||||
memcpy(rdr.str + rdr.len, "\r\nProxy-Connection: close\r\n\r\n", 29);
|
memcpy(trash.str + trash.len, "\r\nProxy-Connection: close\r\n\r\n", 29);
|
||||||
rdr.len += 29;
|
trash.len += 29;
|
||||||
} else {
|
} else {
|
||||||
memcpy(rdr.str + rdr.len, "\r\nConnection: close\r\n\r\n", 23);
|
memcpy(trash.str + trash.len, "\r\nConnection: close\r\n\r\n", 23);
|
||||||
rdr.len += 23;
|
trash.len += 23;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* prepare to return without error. */
|
/* prepare to return without error. */
|
||||||
@ -820,7 +815,7 @@ void perform_http_redirect(struct session *s, struct stream_interface *si)
|
|||||||
si->state = SI_ST_CLO;
|
si->state = SI_ST_CLO;
|
||||||
|
|
||||||
/* send the message */
|
/* send the message */
|
||||||
http_server_error(s, si, SN_ERR_PRXCOND, SN_FINST_C, 302, &rdr);
|
http_server_error(s, si, SN_ERR_PRXCOND, SN_FINST_C, 302, &trash);
|
||||||
|
|
||||||
/* FIXME: we should increase a counter of redirects per server and per backend. */
|
/* FIXME: we should increase a counter of redirects per server and per backend. */
|
||||||
if (srv)
|
if (srv)
|
||||||
@ -2048,8 +2043,6 @@ int select_compression_response_header(struct session *s, struct buffer *res)
|
|||||||
struct http_msg *msg = &txn->rsp;
|
struct http_msg *msg = &txn->rsp;
|
||||||
struct hdr_ctx ctx;
|
struct hdr_ctx ctx;
|
||||||
struct comp_type *comp_type;
|
struct comp_type *comp_type;
|
||||||
char *hdr_val;
|
|
||||||
int hdr_len;
|
|
||||||
|
|
||||||
/* no common compression algorithm was found in request header */
|
/* no common compression algorithm was found in request header */
|
||||||
if (s->comp_algo == NULL)
|
if (s->comp_algo == NULL)
|
||||||
@ -2059,7 +2052,6 @@ int select_compression_response_header(struct session *s, struct buffer *res)
|
|||||||
if (!(msg->flags & HTTP_MSGF_VER_11))
|
if (!(msg->flags & HTTP_MSGF_VER_11))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
hdr_val = trash;
|
|
||||||
ctx.idx = 0;
|
ctx.idx = 0;
|
||||||
|
|
||||||
/* Content-Length is null */
|
/* Content-Length is null */
|
||||||
@ -2105,12 +2097,12 @@ int select_compression_response_header(struct session *s, struct buffer *res)
|
|||||||
* header.
|
* header.
|
||||||
*/
|
*/
|
||||||
if (s->comp_algo->add_data != identity_add_data) {
|
if (s->comp_algo->add_data != identity_add_data) {
|
||||||
hdr_len = 18;
|
trash.len = 18;
|
||||||
memcpy(hdr_val, "Content-Encoding: ", hdr_len);
|
memcpy(trash.str, "Content-Encoding: ", trash.len);
|
||||||
memcpy(hdr_val + hdr_len, s->comp_algo->name, s->comp_algo->name_len);
|
memcpy(trash.str + trash.len, s->comp_algo->name, s->comp_algo->name_len);
|
||||||
hdr_len += s->comp_algo->name_len;
|
trash.len += s->comp_algo->name_len;
|
||||||
hdr_val[hdr_len] = '\0';
|
trash.str[trash.len] = '\0';
|
||||||
http_header_add_tail2(&txn->rsp, &txn->hdr_idx, hdr_val, hdr_len);
|
http_header_add_tail2(&txn->rsp, &txn->hdr_idx, trash.str, trash.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize compression */
|
/* initialize compression */
|
||||||
@ -3104,16 +3096,14 @@ int http_process_req_common(struct session *s, struct channel *req, int an_bit,
|
|||||||
* either to pass or to access stats.
|
* either to pass or to access stats.
|
||||||
*/
|
*/
|
||||||
if (http_req_last_rule && http_req_last_rule->action == HTTP_REQ_ACT_HTTP_AUTH) {
|
if (http_req_last_rule && http_req_last_rule->action == HTTP_REQ_ACT_HTTP_AUTH) {
|
||||||
struct chunk msg;
|
|
||||||
char *realm = http_req_last_rule->http_auth.realm;
|
char *realm = http_req_last_rule->http_auth.realm;
|
||||||
|
|
||||||
if (!realm)
|
if (!realm)
|
||||||
realm = do_stats?STATS_DEFAULT_REALM:px->id;
|
realm = do_stats?STATS_DEFAULT_REALM:px->id;
|
||||||
|
|
||||||
sprintf(trash, (txn->flags & TX_USE_PX_CONN) ? HTTP_407_fmt : HTTP_401_fmt, realm);
|
chunk_printf(&trash, (txn->flags & TX_USE_PX_CONN) ? HTTP_407_fmt : HTTP_401_fmt, realm);
|
||||||
chunk_initlen(&msg, trash, global.tune.bufsize, strlen(trash));
|
|
||||||
txn->status = 401;
|
txn->status = 401;
|
||||||
stream_int_retnclose(req->prod, &msg);
|
stream_int_retnclose(req->prod, &trash);
|
||||||
/* on 401 we still count one error, because normal browsing
|
/* on 401 we still count one error, because normal browsing
|
||||||
* won't significantly increase the counter but brute force
|
* won't significantly increase the counter but brute force
|
||||||
* attempts will.
|
* attempts will.
|
||||||
@ -3219,7 +3209,6 @@ int http_process_req_common(struct session *s, struct channel *req, int an_bit,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
struct chunk rdr = { .str = trash, .size = global.tune.bufsize, .len = 0 };
|
|
||||||
const char *msg_fmt;
|
const char *msg_fmt;
|
||||||
|
|
||||||
/* build redirect message */
|
/* build redirect message */
|
||||||
@ -3236,7 +3225,7 @@ int http_process_req_common(struct session *s, struct channel *req, int an_bit,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely(!chunk_strcpy(&rdr, msg_fmt)))
|
if (unlikely(!chunk_strcpy(&trash, msg_fmt)))
|
||||||
goto return_bad_req;
|
goto return_bad_req;
|
||||||
|
|
||||||
switch(rule->type) {
|
switch(rule->type) {
|
||||||
@ -3275,32 +3264,32 @@ int http_process_req_common(struct session *s, struct channel *req, int an_bit,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check if we can add scheme + "://" + host + path */
|
/* check if we can add scheme + "://" + host + path */
|
||||||
if (rdr.len + rule->rdr_len + 3 + hostlen + pathlen > rdr.size - 4)
|
if (trash.len + rule->rdr_len + 3 + hostlen + pathlen > trash.size - 4)
|
||||||
goto return_bad_req;
|
goto return_bad_req;
|
||||||
|
|
||||||
/* add scheme */
|
/* add scheme */
|
||||||
memcpy(rdr.str + rdr.len, rule->rdr_str, rule->rdr_len);
|
memcpy(trash.str + trash.len, rule->rdr_str, rule->rdr_len);
|
||||||
rdr.len += rule->rdr_len;
|
trash.len += rule->rdr_len;
|
||||||
|
|
||||||
/* add "://" */
|
/* add "://" */
|
||||||
memcpy(rdr.str + rdr.len, "://", 3);
|
memcpy(trash.str + trash.len, "://", 3);
|
||||||
rdr.len += 3;
|
trash.len += 3;
|
||||||
|
|
||||||
/* add host */
|
/* add host */
|
||||||
memcpy(rdr.str + rdr.len, host, hostlen);
|
memcpy(trash.str + trash.len, host, hostlen);
|
||||||
rdr.len += hostlen;
|
trash.len += hostlen;
|
||||||
|
|
||||||
/* add path */
|
/* add path */
|
||||||
memcpy(rdr.str + rdr.len, path, pathlen);
|
memcpy(trash.str + trash.len, path, pathlen);
|
||||||
rdr.len += pathlen;
|
trash.len += pathlen;
|
||||||
|
|
||||||
/* append a slash at the end of the location is needed and missing */
|
/* append a slash at the end of the location is needed and missing */
|
||||||
if (rdr.len && rdr.str[rdr.len - 1] != '/' &&
|
if (trash.len && trash.str[trash.len - 1] != '/' &&
|
||||||
(rule->flags & REDIRECT_FLAG_APPEND_SLASH)) {
|
(rule->flags & REDIRECT_FLAG_APPEND_SLASH)) {
|
||||||
if (rdr.len > rdr.size - 5)
|
if (trash.len > trash.size - 5)
|
||||||
goto return_bad_req;
|
goto return_bad_req;
|
||||||
rdr.str[rdr.len] = '/';
|
trash.str[trash.len] = '/';
|
||||||
rdr.len++;
|
trash.len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -3328,7 +3317,7 @@ int http_process_req_common(struct session *s, struct channel *req, int an_bit,
|
|||||||
pathlen = 1;
|
pathlen = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rdr.len + rule->rdr_len + pathlen > rdr.size - 4)
|
if (trash.len + rule->rdr_len + pathlen > trash.size - 4)
|
||||||
goto return_bad_req;
|
goto return_bad_req;
|
||||||
|
|
||||||
/* add prefix. Note that if prefix == "/", we don't want to
|
/* add prefix. Note that if prefix == "/", we don't want to
|
||||||
@ -3336,43 +3325,43 @@ int http_process_req_common(struct session *s, struct channel *req, int an_bit,
|
|||||||
* configure a self-redirection.
|
* configure a self-redirection.
|
||||||
*/
|
*/
|
||||||
if (rule->rdr_len != 1 || *rule->rdr_str != '/') {
|
if (rule->rdr_len != 1 || *rule->rdr_str != '/') {
|
||||||
memcpy(rdr.str + rdr.len, rule->rdr_str, rule->rdr_len);
|
memcpy(trash.str + trash.len, rule->rdr_str, rule->rdr_len);
|
||||||
rdr.len += rule->rdr_len;
|
trash.len += rule->rdr_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add path */
|
/* add path */
|
||||||
memcpy(rdr.str + rdr.len, path, pathlen);
|
memcpy(trash.str + trash.len, path, pathlen);
|
||||||
rdr.len += pathlen;
|
trash.len += pathlen;
|
||||||
|
|
||||||
/* append a slash at the end of the location is needed and missing */
|
/* append a slash at the end of the location is needed and missing */
|
||||||
if (rdr.len && rdr.str[rdr.len - 1] != '/' &&
|
if (trash.len && trash.str[trash.len - 1] != '/' &&
|
||||||
(rule->flags & REDIRECT_FLAG_APPEND_SLASH)) {
|
(rule->flags & REDIRECT_FLAG_APPEND_SLASH)) {
|
||||||
if (rdr.len > rdr.size - 5)
|
if (trash.len > trash.size - 5)
|
||||||
goto return_bad_req;
|
goto return_bad_req;
|
||||||
rdr.str[rdr.len] = '/';
|
trash.str[trash.len] = '/';
|
||||||
rdr.len++;
|
trash.len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case REDIRECT_TYPE_LOCATION:
|
case REDIRECT_TYPE_LOCATION:
|
||||||
default:
|
default:
|
||||||
if (rdr.len + rule->rdr_len > rdr.size - 4)
|
if (trash.len + rule->rdr_len > trash.size - 4)
|
||||||
goto return_bad_req;
|
goto return_bad_req;
|
||||||
|
|
||||||
/* add location */
|
/* add location */
|
||||||
memcpy(rdr.str + rdr.len, rule->rdr_str, rule->rdr_len);
|
memcpy(trash.str + trash.len, rule->rdr_str, rule->rdr_len);
|
||||||
rdr.len += rule->rdr_len;
|
trash.len += rule->rdr_len;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rule->cookie_len) {
|
if (rule->cookie_len) {
|
||||||
memcpy(rdr.str + rdr.len, "\r\nSet-Cookie: ", 14);
|
memcpy(trash.str + trash.len, "\r\nSet-Cookie: ", 14);
|
||||||
rdr.len += 14;
|
trash.len += 14;
|
||||||
memcpy(rdr.str + rdr.len, rule->cookie_str, rule->cookie_len);
|
memcpy(trash.str + trash.len, rule->cookie_str, rule->cookie_len);
|
||||||
rdr.len += rule->cookie_len;
|
trash.len += rule->cookie_len;
|
||||||
memcpy(rdr.str + rdr.len, "\r\n", 2);
|
memcpy(trash.str + trash.len, "\r\n", 2);
|
||||||
rdr.len += 2;
|
trash.len += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add end of headers and the keep-alive/close status.
|
/* add end of headers and the keep-alive/close status.
|
||||||
@ -3392,16 +3381,16 @@ int http_process_req_common(struct session *s, struct channel *req, int an_bit,
|
|||||||
/* keep-alive possible */
|
/* keep-alive possible */
|
||||||
if (!(msg->flags & HTTP_MSGF_VER_11)) {
|
if (!(msg->flags & HTTP_MSGF_VER_11)) {
|
||||||
if (unlikely(txn->flags & TX_USE_PX_CONN)) {
|
if (unlikely(txn->flags & TX_USE_PX_CONN)) {
|
||||||
memcpy(rdr.str + rdr.len, "\r\nProxy-Connection: keep-alive", 30);
|
memcpy(trash.str + trash.len, "\r\nProxy-Connection: keep-alive", 30);
|
||||||
rdr.len += 30;
|
trash.len += 30;
|
||||||
} else {
|
} else {
|
||||||
memcpy(rdr.str + rdr.len, "\r\nConnection: keep-alive", 24);
|
memcpy(trash.str + trash.len, "\r\nConnection: keep-alive", 24);
|
||||||
rdr.len += 24;
|
trash.len += 24;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memcpy(rdr.str + rdr.len, "\r\n\r\n", 4);
|
memcpy(trash.str + trash.len, "\r\n\r\n", 4);
|
||||||
rdr.len += 4;
|
trash.len += 4;
|
||||||
bo_inject(req->prod->ob, rdr.str, rdr.len);
|
bo_inject(req->prod->ob, trash.str, trash.len);
|
||||||
/* "eat" the request */
|
/* "eat" the request */
|
||||||
bi_fast_delete(req->buf, msg->sov);
|
bi_fast_delete(req->buf, msg->sov);
|
||||||
msg->sov = 0;
|
msg->sov = 0;
|
||||||
@ -3413,13 +3402,13 @@ int http_process_req_common(struct session *s, struct channel *req, int an_bit,
|
|||||||
} else {
|
} else {
|
||||||
/* keep-alive not possible */
|
/* keep-alive not possible */
|
||||||
if (unlikely(txn->flags & TX_USE_PX_CONN)) {
|
if (unlikely(txn->flags & TX_USE_PX_CONN)) {
|
||||||
memcpy(rdr.str + rdr.len, "\r\nProxy-Connection: close\r\n\r\n", 29);
|
memcpy(trash.str + trash.len, "\r\nProxy-Connection: close\r\n\r\n", 29);
|
||||||
rdr.len += 29;
|
trash.len += 29;
|
||||||
} else {
|
} else {
|
||||||
memcpy(rdr.str + rdr.len, "\r\nConnection: close\r\n\r\n", 23);
|
memcpy(trash.str + trash.len, "\r\nConnection: close\r\n\r\n", 23);
|
||||||
rdr.len += 23;
|
trash.len += 23;
|
||||||
}
|
}
|
||||||
stream_int_retnclose(req->prod, &rdr);
|
stream_int_retnclose(req->prod, &trash);
|
||||||
goto return_prx_cond;
|
goto return_prx_cond;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3534,10 +3523,10 @@ int http_process_request(struct session *s, struct channel *req, int an_bit)
|
|||||||
build_logline(s, s->unique_id, UNIQUEID_LEN, &s->fe->format_unique_id);
|
build_logline(s, s->unique_id, UNIQUEID_LEN, &s->fe->format_unique_id);
|
||||||
|
|
||||||
if (s->fe->header_unique_id && s->unique_id) {
|
if (s->fe->header_unique_id && s->unique_id) {
|
||||||
int ret = snprintf(trash, global.tune.bufsize, "%s: %s", s->fe->header_unique_id, s->unique_id);
|
chunk_printf(&trash, "%s: %s", s->fe->header_unique_id, s->unique_id);
|
||||||
if (ret < 0 || ret > global.tune.bufsize)
|
if (trash.len < 0)
|
||||||
goto return_bad_req;
|
goto return_bad_req;
|
||||||
if (unlikely(http_header_add_tail(&txn->req, &txn->hdr_idx, trash) < 0))
|
if (unlikely(http_header_add_tail2(&txn->req, &txn->hdr_idx, trash.str, trash.len) < 0))
|
||||||
goto return_bad_req;
|
goto return_bad_req;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3576,14 +3565,14 @@ int http_process_request(struct session *s, struct channel *req, int an_bit)
|
|||||||
*/
|
*/
|
||||||
if (s->be->fwdfor_hdr_len) {
|
if (s->be->fwdfor_hdr_len) {
|
||||||
len = s->be->fwdfor_hdr_len;
|
len = s->be->fwdfor_hdr_len;
|
||||||
memcpy(trash, s->be->fwdfor_hdr_name, len);
|
memcpy(trash.str, s->be->fwdfor_hdr_name, len);
|
||||||
} else {
|
} else {
|
||||||
len = s->fe->fwdfor_hdr_len;
|
len = s->fe->fwdfor_hdr_len;
|
||||||
memcpy(trash, s->fe->fwdfor_hdr_name, len);
|
memcpy(trash.str, s->fe->fwdfor_hdr_name, len);
|
||||||
}
|
}
|
||||||
len += sprintf(trash + len, ": %d.%d.%d.%d", pn[0], pn[1], pn[2], pn[3]);
|
len += sprintf(trash.str + len, ": %d.%d.%d.%d", pn[0], pn[1], pn[2], pn[3]);
|
||||||
|
|
||||||
if (unlikely(http_header_add_tail2(&txn->req, &txn->hdr_idx, trash, len) < 0))
|
if (unlikely(http_header_add_tail2(&txn->req, &txn->hdr_idx, trash.str, len) < 0))
|
||||||
goto return_bad_req;
|
goto return_bad_req;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3604,14 +3593,14 @@ int http_process_request(struct session *s, struct channel *req, int an_bit)
|
|||||||
*/
|
*/
|
||||||
if (s->be->fwdfor_hdr_len) {
|
if (s->be->fwdfor_hdr_len) {
|
||||||
len = s->be->fwdfor_hdr_len;
|
len = s->be->fwdfor_hdr_len;
|
||||||
memcpy(trash, s->be->fwdfor_hdr_name, len);
|
memcpy(trash.str, s->be->fwdfor_hdr_name, len);
|
||||||
} else {
|
} else {
|
||||||
len = s->fe->fwdfor_hdr_len;
|
len = s->fe->fwdfor_hdr_len;
|
||||||
memcpy(trash, s->fe->fwdfor_hdr_name, len);
|
memcpy(trash.str, s->fe->fwdfor_hdr_name, len);
|
||||||
}
|
}
|
||||||
len += sprintf(trash + len, ": %s", pn);
|
len += sprintf(trash.str + len, ": %s", pn);
|
||||||
|
|
||||||
if (unlikely(http_header_add_tail2(&txn->req, &txn->hdr_idx, trash, len) < 0))
|
if (unlikely(http_header_add_tail2(&txn->req, &txn->hdr_idx, trash.str, len) < 0))
|
||||||
goto return_bad_req;
|
goto return_bad_req;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3647,14 +3636,14 @@ int http_process_request(struct session *s, struct channel *req, int an_bit)
|
|||||||
*/
|
*/
|
||||||
if (s->be->orgto_hdr_len) {
|
if (s->be->orgto_hdr_len) {
|
||||||
len = s->be->orgto_hdr_len;
|
len = s->be->orgto_hdr_len;
|
||||||
memcpy(trash, s->be->orgto_hdr_name, len);
|
memcpy(trash.str, s->be->orgto_hdr_name, len);
|
||||||
} else {
|
} else {
|
||||||
len = s->fe->orgto_hdr_len;
|
len = s->fe->orgto_hdr_len;
|
||||||
memcpy(trash, s->fe->orgto_hdr_name, len);
|
memcpy(trash.str, s->fe->orgto_hdr_name, len);
|
||||||
}
|
}
|
||||||
len += sprintf(trash + len, ": %d.%d.%d.%d", pn[0], pn[1], pn[2], pn[3]);
|
len += sprintf(trash.str + len, ": %d.%d.%d.%d", pn[0], pn[1], pn[2], pn[3]);
|
||||||
|
|
||||||
if (unlikely(http_header_add_tail2(&txn->req, &txn->hdr_idx, trash, len) < 0))
|
if (unlikely(http_header_add_tail2(&txn->req, &txn->hdr_idx, trash.str, len) < 0))
|
||||||
goto return_bad_req;
|
goto return_bad_req;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3957,13 +3946,13 @@ int http_send_name_header(struct http_txn *txn, struct proxy* be, const char* sr
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Add the new header requested with the server value */
|
/* Add the new header requested with the server value */
|
||||||
hdr_val = trash;
|
hdr_val = trash.str;
|
||||||
memcpy(hdr_val, hdr_name, hdr_name_len);
|
memcpy(hdr_val, hdr_name, hdr_name_len);
|
||||||
hdr_val += hdr_name_len;
|
hdr_val += hdr_name_len;
|
||||||
*hdr_val++ = ':';
|
*hdr_val++ = ':';
|
||||||
*hdr_val++ = ' ';
|
*hdr_val++ = ' ';
|
||||||
hdr_val += strlcpy2(hdr_val, srv_name, trash + global.tune.bufsize - hdr_val);
|
hdr_val += strlcpy2(hdr_val, srv_name, trash.str + trash.size - hdr_val);
|
||||||
http_header_add_tail2(&txn->req, &txn->hdr_idx, trash, hdr_val - trash);
|
http_header_add_tail2(&txn->req, &txn->hdr_idx, trash.str, hdr_val - trash.str);
|
||||||
|
|
||||||
if (old_o) {
|
if (old_o) {
|
||||||
/* If this was a forwarded request, we must readjust the amount of
|
/* If this was a forwarded request, we must readjust the amount of
|
||||||
@ -5347,7 +5336,6 @@ int http_process_res_common(struct session *t, struct channel *rep, int an_bit,
|
|||||||
(!t->be->cookie_maxlife && txn->cookie_first_date)) && // remove the first_date
|
(!t->be->cookie_maxlife && txn->cookie_first_date)) && // remove the first_date
|
||||||
(!(t->be->ck_opts & PR_CK_POST) || (txn->meth == HTTP_METH_POST)) &&
|
(!(t->be->ck_opts & PR_CK_POST) || (txn->meth == HTTP_METH_POST)) &&
|
||||||
!(t->flags & SN_IGNORE_PRST)) {
|
!(t->flags & SN_IGNORE_PRST)) {
|
||||||
int len;
|
|
||||||
/* the server is known, it's not the one the client requested, or the
|
/* the server is known, it's not the one the client requested, or the
|
||||||
* cookie's last seen date needs to be refreshed. We have to
|
* cookie's last seen date needs to be refreshed. We have to
|
||||||
* insert a set-cookie here, except if we want to insert only on POST
|
* insert a set-cookie here, except if we want to insert only on POST
|
||||||
@ -5355,41 +5343,43 @@ int http_process_res_common(struct session *t, struct channel *rep, int an_bit,
|
|||||||
* (eg: some backup servers) will return a full cookie removal request.
|
* (eg: some backup servers) will return a full cookie removal request.
|
||||||
*/
|
*/
|
||||||
if (!target_srv(&t->target)->cookie) {
|
if (!target_srv(&t->target)->cookie) {
|
||||||
len = sprintf(trash,
|
chunk_printf(&trash,
|
||||||
"Set-Cookie: %s=; Expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/",
|
"Set-Cookie: %s=; Expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/",
|
||||||
t->be->cookie_name);
|
t->be->cookie_name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
len = sprintf(trash, "Set-Cookie: %s=%s", t->be->cookie_name, target_srv(&t->target)->cookie);
|
chunk_printf(&trash, "Set-Cookie: %s=%s", t->be->cookie_name, target_srv(&t->target)->cookie);
|
||||||
|
|
||||||
if (t->be->cookie_maxidle || t->be->cookie_maxlife) {
|
if (t->be->cookie_maxidle || t->be->cookie_maxlife) {
|
||||||
/* emit last_date, which is mandatory */
|
/* emit last_date, which is mandatory */
|
||||||
trash[len++] = COOKIE_DELIM_DATE;
|
trash.str[trash.len++] = COOKIE_DELIM_DATE;
|
||||||
s30tob64((date.tv_sec+3) >> 2, trash + len); len += 5;
|
s30tob64((date.tv_sec+3) >> 2, trash.str + trash.len);
|
||||||
|
trash.len += 5;
|
||||||
|
|
||||||
if (t->be->cookie_maxlife) {
|
if (t->be->cookie_maxlife) {
|
||||||
/* emit first_date, which is either the original one or
|
/* emit first_date, which is either the original one or
|
||||||
* the current date.
|
* the current date.
|
||||||
*/
|
*/
|
||||||
trash[len++] = COOKIE_DELIM_DATE;
|
trash.str[trash.len++] = COOKIE_DELIM_DATE;
|
||||||
s30tob64(txn->cookie_first_date ?
|
s30tob64(txn->cookie_first_date ?
|
||||||
txn->cookie_first_date >> 2 :
|
txn->cookie_first_date >> 2 :
|
||||||
(date.tv_sec+3) >> 2, trash + len);
|
(date.tv_sec+3) >> 2, trash.str + trash.len);
|
||||||
len += 5;
|
trash.len += 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
len += sprintf(trash + len, "; path=/");
|
chunk_appendf(&trash, "; path=/");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t->be->cookie_domain)
|
if (t->be->cookie_domain)
|
||||||
len += sprintf(trash+len, "; domain=%s", t->be->cookie_domain);
|
chunk_appendf(&trash, "; domain=%s", t->be->cookie_domain);
|
||||||
|
|
||||||
if (t->be->ck_opts & PR_CK_HTTPONLY)
|
if (t->be->ck_opts & PR_CK_HTTPONLY)
|
||||||
len += sprintf(trash+len, "; HttpOnly");
|
chunk_appendf(&trash, "; HttpOnly");
|
||||||
|
|
||||||
if (t->be->ck_opts & PR_CK_SECURE)
|
if (t->be->ck_opts & PR_CK_SECURE)
|
||||||
len += sprintf(trash+len, "; Secure");
|
chunk_appendf(&trash, "; Secure");
|
||||||
|
|
||||||
if (unlikely(http_header_add_tail2(&txn->rsp, &txn->hdr_idx, trash, len) < 0))
|
if (unlikely(http_header_add_tail2(&txn->rsp, &txn->hdr_idx, trash.str, trash.len) < 0))
|
||||||
goto return_bad_resp;
|
goto return_bad_resp;
|
||||||
|
|
||||||
txn->flags &= ~TX_SCK_MASK;
|
txn->flags &= ~TX_SCK_MASK;
|
||||||
@ -5800,7 +5790,7 @@ int apply_filter_to_req_headers(struct session *t, struct channel *req, struct h
|
|||||||
int cur_idx, old_idx, last_hdr;
|
int cur_idx, old_idx, last_hdr;
|
||||||
struct http_txn *txn = &t->txn;
|
struct http_txn *txn = &t->txn;
|
||||||
struct hdr_idx_elem *cur_hdr;
|
struct hdr_idx_elem *cur_hdr;
|
||||||
int len, delta;
|
int delta;
|
||||||
|
|
||||||
last_hdr = 0;
|
last_hdr = 0;
|
||||||
|
|
||||||
@ -5882,8 +5872,8 @@ int apply_filter_to_req_headers(struct session *t, struct channel *req, struct h
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ACT_REPLACE:
|
case ACT_REPLACE:
|
||||||
len = exp_replace(trash, cur_ptr, exp->replace, pmatch);
|
trash.len = exp_replace(trash.str, cur_ptr, exp->replace, pmatch);
|
||||||
delta = buffer_replace2(req->buf, cur_ptr, cur_end, trash, len);
|
delta = buffer_replace2(req->buf, cur_ptr, cur_end, trash.str, trash.len);
|
||||||
/* FIXME: if the user adds a newline in the replacement, the
|
/* FIXME: if the user adds a newline in the replacement, the
|
||||||
* index will not be recalculated for now, and the new line
|
* index will not be recalculated for now, and the new line
|
||||||
* will not be counted as a new header.
|
* will not be counted as a new header.
|
||||||
@ -5933,8 +5923,7 @@ int apply_filter_to_req_line(struct session *t, struct channel *req, struct hdr_
|
|||||||
char *cur_ptr, *cur_end;
|
char *cur_ptr, *cur_end;
|
||||||
int done;
|
int done;
|
||||||
struct http_txn *txn = &t->txn;
|
struct http_txn *txn = &t->txn;
|
||||||
int len, delta;
|
int delta;
|
||||||
|
|
||||||
|
|
||||||
if (unlikely(txn->flags & (TX_CLDENY | TX_CLTARPIT)))
|
if (unlikely(txn->flags & (TX_CLDENY | TX_CLTARPIT)))
|
||||||
return 1;
|
return 1;
|
||||||
@ -6007,8 +5996,8 @@ int apply_filter_to_req_line(struct session *t, struct channel *req, struct hdr_
|
|||||||
|
|
||||||
case ACT_REPLACE:
|
case ACT_REPLACE:
|
||||||
*cur_end = term; /* restore the string terminator */
|
*cur_end = term; /* restore the string terminator */
|
||||||
len = exp_replace(trash, cur_ptr, exp->replace, pmatch);
|
trash.len = exp_replace(trash.str, cur_ptr, exp->replace, pmatch);
|
||||||
delta = buffer_replace2(req->buf, cur_ptr, cur_end, trash, len);
|
delta = buffer_replace2(req->buf, cur_ptr, cur_end, trash.str, trash.len);
|
||||||
/* FIXME: if the user adds a newline in the replacement, the
|
/* FIXME: if the user adds a newline in the replacement, the
|
||||||
* index will not be recalculated for now, and the new line
|
* index will not be recalculated for now, and the new line
|
||||||
* will not be counted as a new header.
|
* will not be counted as a new header.
|
||||||
@ -6707,7 +6696,7 @@ int apply_filter_to_resp_headers(struct session *t, struct channel *rtr, struct
|
|||||||
int cur_idx, old_idx, last_hdr;
|
int cur_idx, old_idx, last_hdr;
|
||||||
struct http_txn *txn = &t->txn;
|
struct http_txn *txn = &t->txn;
|
||||||
struct hdr_idx_elem *cur_hdr;
|
struct hdr_idx_elem *cur_hdr;
|
||||||
int len, delta;
|
int delta;
|
||||||
|
|
||||||
last_hdr = 0;
|
last_hdr = 0;
|
||||||
|
|
||||||
@ -6756,8 +6745,8 @@ int apply_filter_to_resp_headers(struct session *t, struct channel *rtr, struct
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ACT_REPLACE:
|
case ACT_REPLACE:
|
||||||
len = exp_replace(trash, cur_ptr, exp->replace, pmatch);
|
trash.len = exp_replace(trash.str, cur_ptr, exp->replace, pmatch);
|
||||||
delta = buffer_replace2(rtr->buf, cur_ptr, cur_end, trash, len);
|
delta = buffer_replace2(rtr->buf, cur_ptr, cur_end, trash.str, trash.len);
|
||||||
/* FIXME: if the user adds a newline in the replacement, the
|
/* FIXME: if the user adds a newline in the replacement, the
|
||||||
* index will not be recalculated for now, and the new line
|
* index will not be recalculated for now, and the new line
|
||||||
* will not be counted as a new header.
|
* will not be counted as a new header.
|
||||||
@ -6805,7 +6794,7 @@ int apply_filter_to_sts_line(struct session *t, struct channel *rtr, struct hdr_
|
|||||||
char *cur_ptr, *cur_end;
|
char *cur_ptr, *cur_end;
|
||||||
int done;
|
int done;
|
||||||
struct http_txn *txn = &t->txn;
|
struct http_txn *txn = &t->txn;
|
||||||
int len, delta;
|
int delta;
|
||||||
|
|
||||||
|
|
||||||
if (unlikely(txn->flags & TX_SVDENY))
|
if (unlikely(txn->flags & TX_SVDENY))
|
||||||
@ -6846,8 +6835,8 @@ int apply_filter_to_sts_line(struct session *t, struct channel *rtr, struct hdr_
|
|||||||
|
|
||||||
case ACT_REPLACE:
|
case ACT_REPLACE:
|
||||||
*cur_end = term; /* restore the string terminator */
|
*cur_end = term; /* restore the string terminator */
|
||||||
len = exp_replace(trash, cur_ptr, exp->replace, pmatch);
|
trash.len = exp_replace(trash.str, cur_ptr, exp->replace, pmatch);
|
||||||
delta = buffer_replace2(rtr->buf, cur_ptr, cur_end, trash, len);
|
delta = buffer_replace2(rtr->buf, cur_ptr, cur_end, trash.str, trash.len);
|
||||||
/* FIXME: if the user adds a newline in the replacement, the
|
/* FIXME: if the user adds a newline in the replacement, the
|
||||||
* index will not be recalculated for now, and the new line
|
* index will not be recalculated for now, and the new line
|
||||||
* will not be counted as a new header.
|
* will not be counted as a new header.
|
||||||
@ -7658,18 +7647,18 @@ unsigned int http_get_hdr(const struct http_msg *msg, const char *hname, int hle
|
|||||||
*/
|
*/
|
||||||
void debug_hdr(const char *dir, struct session *t, const char *start, const char *end)
|
void debug_hdr(const char *dir, struct session *t, const char *start, const char *end)
|
||||||
{
|
{
|
||||||
int len, max;
|
int max;
|
||||||
len = sprintf(trash, "%08x:%s.%s[%04x:%04x]: ", t->uniq_id, t->be->id,
|
chunk_printf(&trash, "%08x:%s.%s[%04x:%04x]: ", t->uniq_id, t->be->id,
|
||||||
dir, (unsigned short)si_fd(t->req->prod), (unsigned short)si_fd(t->req->cons));
|
dir, (unsigned short)si_fd(t->req->prod), (unsigned short)si_fd(t->req->cons));
|
||||||
|
|
||||||
for (max = 0; start + max < end; max++)
|
for (max = 0; start + max < end; max++)
|
||||||
if (start[max] == '\r' || start[max] == '\n')
|
if (start[max] == '\r' || start[max] == '\n')
|
||||||
break;
|
break;
|
||||||
|
|
||||||
UBOUND(max, global.tune.bufsize - len - 3);
|
UBOUND(max, trash.size - trash.len - 3);
|
||||||
len += strlcpy2(trash + len, start, max + 1);
|
trash.len += strlcpy2(trash.str + trash.len, start, max + 1);
|
||||||
trash[len++] = '\n';
|
trash.str[trash.len++] = '\n';
|
||||||
if (write(1, trash, len) < 0) /* shut gcc warning */;
|
if (write(1, trash.str, trash.len) < 0) /* shut gcc warning */;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -8377,9 +8366,9 @@ smp_fetch_base(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
|
|||||||
return smp_fetch_path(px, l4, l7, opt, args, smp);
|
return smp_fetch_path(px, l4, l7, opt, args, smp);
|
||||||
|
|
||||||
/* OK we have the header value in ctx.line+ctx.val for ctx.vlen bytes */
|
/* OK we have the header value in ctx.line+ctx.val for ctx.vlen bytes */
|
||||||
memcpy(trash, ctx.line + ctx.val, ctx.vlen);
|
memcpy(trash.str, ctx.line + ctx.val, ctx.vlen);
|
||||||
smp->type = SMP_T_STR;
|
smp->type = SMP_T_STR;
|
||||||
smp->data.str.str = trash;
|
smp->data.str.str = trash.str;
|
||||||
smp->data.str.len = ctx.vlen;
|
smp->data.str.len = ctx.vlen;
|
||||||
|
|
||||||
/* now retrieve the path */
|
/* now retrieve the path */
|
||||||
|
@ -158,7 +158,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
|
|||||||
* - HEALTH mode without HTTP check => just send "OK"
|
* - HEALTH mode without HTTP check => just send "OK"
|
||||||
* - TCP mode from monitoring address => just close
|
* - TCP mode from monitoring address => just close
|
||||||
*/
|
*/
|
||||||
recv(cfd, trash, global.tune.bufsize, MSG_DONTWAIT);
|
recv(cfd, trash.str, trash.size, MSG_DONTWAIT);
|
||||||
if (p->mode == PR_MODE_HTTP ||
|
if (p->mode == PR_MODE_HTTP ||
|
||||||
(p->mode == PR_MODE_HEALTH && (p->options2 & PR_O2_CHK_ANY) == PR_O2_HTTP_CHK))
|
(p->mode == PR_MODE_HEALTH && (p->options2 & PR_O2_CHK_ANY) == PR_O2_HTTP_CHK))
|
||||||
send(cfd, "HTTP/1.0 200 OK\r\n\r\n", 19, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_MORE);
|
send(cfd, "HTTP/1.0 200 OK\r\n\r\n", 19, MSG_DONTWAIT|MSG_NOSIGNAL|MSG_MORE);
|
||||||
@ -2292,24 +2292,22 @@ struct task *process_session(struct task *t)
|
|||||||
if (unlikely((global.mode & MODE_DEBUG) &&
|
if (unlikely((global.mode & MODE_DEBUG) &&
|
||||||
(!(global.mode & MODE_QUIET) ||
|
(!(global.mode & MODE_QUIET) ||
|
||||||
(global.mode & MODE_VERBOSE)))) {
|
(global.mode & MODE_VERBOSE)))) {
|
||||||
int len;
|
|
||||||
|
|
||||||
if (s->si[1].state == SI_ST_CLO &&
|
if (s->si[1].state == SI_ST_CLO &&
|
||||||
s->si[1].prev_state == SI_ST_EST) {
|
s->si[1].prev_state == SI_ST_EST) {
|
||||||
len = sprintf(trash, "%08x:%s.srvcls[%04x:%04x]\n",
|
chunk_printf(&trash, "%08x:%s.srvcls[%04x:%04x]\n",
|
||||||
s->uniq_id, s->be->id,
|
s->uniq_id, s->be->id,
|
||||||
(unsigned short)si_fd(&s->si[0]),
|
(unsigned short)si_fd(&s->si[0]),
|
||||||
(unsigned short)si_fd(&s->si[1]));
|
(unsigned short)si_fd(&s->si[1]));
|
||||||
if (write(1, trash, len) < 0) /* shut gcc warning */;
|
if (write(1, trash.str, trash.len) < 0) /* shut gcc warning */;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->si[0].state == SI_ST_CLO &&
|
if (s->si[0].state == SI_ST_CLO &&
|
||||||
s->si[0].prev_state == SI_ST_EST) {
|
s->si[0].prev_state == SI_ST_EST) {
|
||||||
len = sprintf(trash, "%08x:%s.clicls[%04x:%04x]\n",
|
chunk_printf(&trash, "%08x:%s.clicls[%04x:%04x]\n",
|
||||||
s->uniq_id, s->be->id,
|
s->uniq_id, s->be->id,
|
||||||
(unsigned short)si_fd(&s->si[0]),
|
(unsigned short)si_fd(&s->si[0]),
|
||||||
(unsigned short)si_fd(&s->si[1]));
|
(unsigned short)si_fd(&s->si[1]));
|
||||||
if (write(1, trash, len) < 0) /* shut gcc warning */;
|
if (write(1, trash.str, trash.len) < 0) /* shut gcc warning */;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2412,11 +2410,10 @@ struct task *process_session(struct task *t)
|
|||||||
|
|
||||||
if (unlikely((global.mode & MODE_DEBUG) &&
|
if (unlikely((global.mode & MODE_DEBUG) &&
|
||||||
(!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) {
|
(!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) {
|
||||||
int len;
|
chunk_printf(&trash, "%08x:%s.closed[%04x:%04x]\n",
|
||||||
len = sprintf(trash, "%08x:%s.closed[%04x:%04x]\n",
|
|
||||||
s->uniq_id, s->be->id,
|
s->uniq_id, s->be->id,
|
||||||
(unsigned short)si_fd(s->req->prod), (unsigned short)si_fd(s->req->cons));
|
(unsigned short)si_fd(s->req->prod), (unsigned short)si_fd(s->req->cons));
|
||||||
if (write(1, trash, len) < 0) /* shut gcc warning */;
|
if (write(1, trash.str, trash.len) < 0) /* shut gcc warning */;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->logs.t_close = tv_ms_elapsed(&s->logs.tv_accept, &now);
|
s->logs.t_close = tv_ms_elapsed(&s->logs.tv_accept, &now);
|
||||||
|
@ -173,17 +173,17 @@ static int ssl_sock_switchctx_cbk(SSL *ssl, int *al, struct bind_conf *s)
|
|||||||
if (!servername)
|
if (!servername)
|
||||||
return SSL_TLSEXT_ERR_NOACK;
|
return SSL_TLSEXT_ERR_NOACK;
|
||||||
|
|
||||||
for (i = 0; i < global.tune.bufsize; i++) {
|
for (i = 0; i < trash.size; i++) {
|
||||||
if (!servername[i])
|
if (!servername[i])
|
||||||
break;
|
break;
|
||||||
trash[i] = tolower(servername[i]);
|
trash.str[i] = tolower(servername[i]);
|
||||||
if (!wildp && (trash[i] == '.'))
|
if (!wildp && (trash.str[i] == '.'))
|
||||||
wildp = &trash[i];
|
wildp = &trash.str[i];
|
||||||
}
|
}
|
||||||
trash[i] = 0;
|
trash.str[i] = 0;
|
||||||
|
|
||||||
/* lookup in full qualified names */
|
/* lookup in full qualified names */
|
||||||
node = ebst_lookup(&s->sni_ctx, trash);
|
node = ebst_lookup(&s->sni_ctx, trash.str);
|
||||||
if (!node) {
|
if (!node) {
|
||||||
if (!wildp)
|
if (!wildp)
|
||||||
return SSL_TLSEXT_ERR_ALERT_WARNING;
|
return SSL_TLSEXT_ERR_ALERT_WARNING;
|
||||||
@ -887,7 +887,7 @@ int ssl_sock_handshake(struct connection *conn, unsigned int flag)
|
|||||||
* TCP sockets. We first try to drain possibly pending
|
* TCP sockets. We first try to drain possibly pending
|
||||||
* data to avoid this as much as possible.
|
* data to avoid this as much as possible.
|
||||||
*/
|
*/
|
||||||
ret = recv(conn->t.sock.fd, trash, global.tune.bufsize, MSG_NOSIGNAL|MSG_DONTWAIT);
|
ret = recv(conn->t.sock.fd, trash.str, trash.size, MSG_NOSIGNAL|MSG_DONTWAIT);
|
||||||
goto out_error;
|
goto out_error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -507,7 +507,7 @@ int conn_si_send_proxy(struct connection *conn, unsigned int flag)
|
|||||||
* (which is recomputed every time since it's constant). If
|
* (which is recomputed every time since it's constant). If
|
||||||
* it is positive, it means we have to send from the start.
|
* it is positive, it means we have to send from the start.
|
||||||
*/
|
*/
|
||||||
ret = make_proxy_line(trash, global.tune.bufsize, &si->ob->prod->conn->addr.from, &si->ob->prod->conn->addr.to);
|
ret = make_proxy_line(trash.str, trash.size, &si->ob->prod->conn->addr.from, &si->ob->prod->conn->addr.to);
|
||||||
if (!ret)
|
if (!ret)
|
||||||
goto out_error;
|
goto out_error;
|
||||||
|
|
||||||
@ -517,7 +517,7 @@ int conn_si_send_proxy(struct connection *conn, unsigned int flag)
|
|||||||
/* we have to send trash from (ret+sp for -sp bytes). If the
|
/* we have to send trash from (ret+sp for -sp bytes). If the
|
||||||
* data layer has a pending write, we'll also set MSG_MORE.
|
* data layer has a pending write, we'll also set MSG_MORE.
|
||||||
*/
|
*/
|
||||||
ret = send(conn->t.sock.fd, trash + ret + si->send_proxy_ofs, -si->send_proxy_ofs,
|
ret = send(conn->t.sock.fd, trash.str + ret + si->send_proxy_ofs, -si->send_proxy_ofs,
|
||||||
(conn->flags & CO_FL_DATA_WR_ENA) ? MSG_MORE : 0);
|
(conn->flags & CO_FL_DATA_WR_ENA) ? MSG_MORE : 0);
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user