From 91d9628a51c1dcfea0a07027a98be8f5c73e453c Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 13 Mar 2015 15:47:26 +0100 Subject: [PATCH] MINOR: peers: centralize configuration of the peers frontend This is in order to stop exporting the peer_accept() function. --- include/proto/peers.h | 3 +-- src/cfgparse.c | 9 +-------- src/peers.c | 14 +++++++++++++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/include/proto/peers.h b/include/proto/peers.h index 349fda51e..39835fffd 100644 --- a/include/proto/peers.h +++ b/include/proto/peers.h @@ -29,8 +29,7 @@ #include void peers_register_table(struct peers *, struct stktable *table); - -int peer_accept(struct session *); +void peers_setup_frontend(struct proxy *fe); #endif /* _PROTO_PEERS_H */ diff --git a/src/cfgparse.c b/src/cfgparse.c index 8d7efb32e..cdb65035b 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -1861,17 +1861,10 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) init_new_proxy(curpeers->peers_fe); curpeers->peers_fe->parent = curpeers; - - curpeers->peers_fe->last_change = now.tv_sec; curpeers->peers_fe->id = strdup(args[1]); - curpeers->peers_fe->cap = PR_CAP_FE; - curpeers->peers_fe->maxconn = 0; - curpeers->peers_fe->conn_retries = CONN_RETRIES; - curpeers->peers_fe->timeout.client = MS_TO_TICKS(5000); - curpeers->peers_fe->accept = peer_accept; - curpeers->peers_fe->options2 |= PR_O2_INDEPSTR | PR_O2_SMARTCON | PR_O2_SMARTACC; curpeers->peers_fe->conf.args.file = curpeers->peers_fe->conf.file = strdup(file); curpeers->peers_fe->conf.args.line = curpeers->peers_fe->conf.line = linenum; + peers_setup_frontend(curpeers->peers_fe); bind_conf = bind_conf_alloc(&curpeers->peers_fe->conf.bind, file, linenum, args[2]); diff --git a/src/peers.c b/src/peers.c index 792260f55..1181aaeac 100644 --- a/src/peers.c +++ b/src/peers.c @@ -1094,7 +1094,7 @@ static void peer_session_forceshutdown(struct session * session) * value in case of success, or zero if it is a success but the session must be * closed ASAP and ignored. */ -int peer_accept(struct session *s) +static int peer_accept(struct session *s) { s->target = &peer_applet.obj_type; /* no need to initialize the applet, it will start with st0=st1 = 0 */ @@ -1117,6 +1117,18 @@ int peer_accept(struct session *s) return 1; } +/* Pre-configures a peers frontend to accept incoming connections */ +void peers_setup_frontend(struct proxy *fe) +{ + fe->last_change = now.tv_sec; + fe->cap = PR_CAP_FE; + fe->maxconn = 0; + fe->conn_retries = CONN_RETRIES; + fe->timeout.client = MS_TO_TICKS(5000); + fe->accept = peer_accept; + fe->options2 |= PR_O2_INDEPSTR | PR_O2_SMARTCON | PR_O2_SMARTACC; +} + /* * Create a new peer session in assigned state (connect will start automatically) */