diff --git a/ChangeLog b/ChangeLog index d7c74b203..e4aba8512 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,33 @@ +2003-09-29 Alexandre Cassen + * keepalived-1.1.3 released. + * Stephan von Krawczynski, extended ip + address framework to support broadcast address selection. + * Extended the scheduling framework to support plain 'long' + timer. Visited the layer4 framework to support this new + scheduling scheme. Reviewed the checkers and VRRP framework + to support long timer. + * VRRP : Removed the timer micro adjust call. Its use is + obsolete with the new scheduling 'long' timer support. + * Jacob Rief, and I added support + log level selection for main daemon. A new command line + argument has been created : + --log-facility -S 0-7 Set syslog facility to + LOG_LOCAL[0-7]. (default=LOG_DAEMON) + * Extended the HTTP checker to support non blocking read + while processing stream. NONBLOCK flags is set before + read operation to catch EAGAIN error. + * VRRP : Diego Rivera, and I fixed a + notify issue while building notify exec string. + * VRRP : Diego Rivera, and I extended + FSM to support BACKUP state notifiers and smtp_alert call + during VRRP initialization. + * Jan Vanhercke, and I extended + scheduling timer computation to support micro-sec second + overlap. Extended the whole scheduling framework to support + this scheduling scheme while computing thread timers. + * Fixed scheduling framework to support child thread timers + while computing global scheduling timer. + 2003-09-07 Alexandre Cassen * keepalived-1.1.2 released. * Dominik Vogt, and I extended checker diff --git a/README b/README index 78a092b60..153816e86 100644 --- a/README +++ b/README @@ -9,7 +9,8 @@ Keepalived implementation is based on an I/O multiplexer to handle a strong multi-threading framework. All the events process use this I/O multiplexer. -Keepalived is free software. See the file COPYING for copying conditions. +Keepalived is free software, Copyright (C) Alexandre Cassen. +See the file COPYING for copying conditions. OPENSSL TOOLKIT LICENCE EXCEPTION diff --git a/VERSION b/VERSION index 45a1b3f44..781dcb07c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.2 +1.1.3 diff --git a/doc/keepalived.conf.SYNOPSIS b/doc/keepalived.conf.SYNOPSIS index cf5252607..0c572306c 100644 --- a/doc/keepalived.conf.SYNOPSIS +++ b/doc/keepalived.conf.SYNOPSIS @@ -39,8 +39,8 @@ global_defs { # Block identification The configuration block looks like : static_ipaddress { # block identification - / dev scope - / dev scope + / brd dev scope + / brd dev scope ... } @@ -127,13 +127,13 @@ vrrp_instance { # VRRP instance declaration auth_pass # Password string } virtual_ipaddress { # VRRP IP addres block - / dev scope - / dev scope + / brd dev scope + / brd dev scope ... } virtual_ipaddress_excluded { # VRRP IP excluded from VRRP - / dev scope # packets - / dev scope + / brd dev scope # packets + / brd dev scope ... } virtual_routes { # VRRP virtual routes diff --git a/genhash/http.c b/genhash/http.c index ea2397831..9eae2a2d8 100644 --- a/genhash/http.c +++ b/genhash/http.c @@ -58,7 +58,8 @@ extern REQ *req; */ /* free allocated pieces */ -static void free_all(thread * thread) +static void +free_all(thread * thread) { SOCK *sock = THREAD_ARG(thread); @@ -87,7 +88,7 @@ epilog(thread * thread) /* Simple finalization function */ int -finalize(thread *thread) +finalize(thread * thread) { SOCK *sock = THREAD_ARG(thread); unsigned char digest[16]; @@ -99,7 +100,7 @@ finalize(thread *thread) printf("\n"); printf(HTML_MD5); print_buffer(16, digest); - + printf(HTML_MD5_FINAL); } printf("MD5SUM = "); @@ -113,7 +114,8 @@ finalize(thread *thread) } /* Process incoming stream */ -int http_process_stream(SOCK *sock, int r) +int +http_process_stream(SOCK * sock, int r) { sock->size += r; sock->total_size += r; @@ -121,12 +123,13 @@ int http_process_stream(SOCK *sock, int r) if (!sock->extracted) { if (req->verbose) printf(HTTP_HEADER_HEXA); - if ((sock->extracted = - extract_html(sock->buffer, sock->size))) { + if ((sock->extracted = extract_html(sock->buffer, sock->size))) { if (req->verbose) { - print_buffer(sock->extracted - sock->buffer, sock->buffer); + print_buffer(sock->extracted - sock->buffer, + sock->buffer); printf(HTTP_HEADER_ASCII); - for (r = 0; r < sock->extracted - sock->buffer; r++) + for (r = 0; r < sock->extracted - sock->buffer; + r++) printf("%c", sock->buffer[r]); printf("\n"); printf(HTML_HEADER_HEXA); @@ -136,8 +139,7 @@ int http_process_stream(SOCK *sock, int r) if (req->verbose) print_buffer(r, sock->extracted); memcpy(sock->buffer, sock->extracted, r); - MD5_Update(&sock->context, sock->buffer, - r); + MD5_Update(&sock->context, sock->buffer, r); r = 0; } sock->size = r; @@ -152,8 +154,7 @@ int http_process_stream(SOCK *sock, int r) } else if (sock->size) { if (req->verbose) print_buffer(r, sock->buffer); - MD5_Update(&sock->context, sock->buffer, - sock->size); + MD5_Update(&sock->context, sock->buffer, sock->size); sock->size = 0; } @@ -249,13 +250,11 @@ http_request_thread(thread * thread) memset(str_request, 0, GET_BUFFER_LENGTH); snprintf(str_request, GET_BUFFER_LENGTH, REQUEST_TEMPLATE, - req->url, - (req->vhost) ? req->vhost : inet_ntop2(req->addr_ip) + req->url, (req->vhost) ? req->vhost : inet_ntop2(req->addr_ip) , ntohs(req->addr_port)); /* Send the GET request to remote Web server */ - DBG("Sending GET request [%s] on fd:%d\n", - req->url, sock->fd); + DBG("Sending GET request [%s] on fd:%d\n", req->url, sock->fd); if (req->ssl) ret = ssl_send_request(sock->ssl, str_request, @@ -269,8 +268,8 @@ http_request_thread(thread * thread) if (!ret) { fprintf(stderr, "Cannot send get request to [%s:%d].\n", - inet_ntop2(req->addr_ip) - , ntohs(req->addr_port)); + inet_ntop2(req->addr_ip) + , ntohs(req->addr_port)); return epilog(thread); } diff --git a/genhash/http.h b/genhash/http.h index 504faf4ff..6a67671cd 100644 --- a/genhash/http.h +++ b/genhash/http.h @@ -36,7 +36,7 @@ /* global defs */ #define GET_BUFFER_LENGTH 2048 #define MAX_BUFFER_LENGTH 4096 -#define HTTP_CNX_TIMEOUT 5 +#define HTTP_CNX_TIMEOUT (5 * TIMER_HZ) #define PROTO_HTTP 0x01 #define PROTO_SSL 0x02 @@ -55,9 +55,9 @@ #define HTML_MD5_FINAL DELIM_BEGIN" HTML MD5 final resulting "DELIM_END /* Define prototypes */ -extern int epilog(thread *thread); -extern int finalize(thread *thread); -extern int http_process_stream(SOCK *sock, int r); +extern int epilog(thread * thread); +extern int finalize(thread * thread); +extern int http_process_stream(SOCK * sock, int r); extern int http_request_thread(thread * thread); #endif diff --git a/genhash/layer4.c b/genhash/layer4.c index c2f53e5e6..6392752f8 100644 --- a/genhash/layer4.c +++ b/genhash/layer4.c @@ -115,15 +115,8 @@ tcp_socket_state(int fd, thread * thread, uint32_t addr_ip, uint16_t addr_port, inet_ntop2(addr_ip), ntohs(addr_port)); timer_min = timer_sub_now(thread->sands); - - if (TIMER_SEC(timer_min) <= 0) - thread_add_write(thread->master, func, - THREAD_ARG(thread) - , thread->u.fd, 0); - else - thread_add_write(thread->master, func, - THREAD_ARG(thread) - , thread->u.fd, TIMER_SEC(timer_min)); + thread_add_write(thread->master, func, THREAD_ARG(thread) + , thread->u.fd, TIMER_LONG(timer_min)); return connect_in_progress; } @@ -133,7 +126,7 @@ tcp_socket_state(int fd, thread * thread, uint32_t addr_ip, uint16_t addr_port, void tcp_connection_state(int fd, enum connect_result status, thread * thread, int (*func) (struct _thread *) - , int timeout) + , long timeout) { switch (status) { case connect_error: @@ -145,7 +138,7 @@ tcp_connection_state(int fd, enum connect_result status, thread * thread, fd, timeout); break; - /* Checking non-blocking connect, we wait until socket is writable */ + /* Checking non-blocking connect, we wait until socket is writable */ case connect_in_progress: thread_add_write(thread->master, func, THREAD_ARG(thread), fd, timeout); @@ -162,8 +155,9 @@ tcp_check_thread(thread * thread) SOCK *sock = THREAD_ARG(thread); int ret = 1; - sock->status = tcp_socket_state(thread->u.fd, thread, req->addr_ip - , req->addr_port, tcp_check_thread); + sock->status = + tcp_socket_state(thread->u.fd, thread, req->addr_ip, req->addr_port, + tcp_check_thread); switch (sock->status) { case connect_error: DBG("Error connecting server [%s:%d].\n", @@ -189,8 +183,7 @@ tcp_check_thread(thread * thread) */ sock->lock = 0; thread_add_event(thread->master, - http_request_thread, - sock, 0); + http_request_thread, sock, 0); } else { DBG("Connection trouble to: [%s:%d].\n", inet_ntop2(req->addr_ip), diff --git a/genhash/layer4.h b/genhash/layer4.h index 5ab551972..5a513c92e 100644 --- a/genhash/layer4.h +++ b/genhash/layer4.h @@ -46,18 +46,18 @@ enum connect_result { /* Prototypes defs */ extern enum connect_result -tcp_connect(int fd, uint32_t, uint16_t); + tcp_connect(int fd, uint32_t, uint16_t); extern enum connect_result -tcp_socket_state(int, thread *, uint32_t, uint16_t, - int (*func) (struct _thread *)); + tcp_socket_state(int, thread *, uint32_t, uint16_t, + int (*func) (struct _thread *)); extern void -tcp_connection_state(int, enum connect_result - , thread *, int (*func) (struct _thread *) - , int); + tcp_connection_state(int, enum connect_result + , thread *, int (*func) (struct _thread *) + , long); extern int -tcp_connect_thread(thread *); + tcp_connect_thread(thread *); #endif diff --git a/genhash/main.c b/genhash/main.c index 793543bd2..2e4b66467 100644 --- a/genhash/main.c +++ b/genhash/main.c @@ -54,13 +54,13 @@ signal_set(int signo, void (*func) (int)) sig.sa_flags = 0; #ifdef SA_RESTART sig.sa_flags |= SA_RESTART; -#endif /* SA_RESTART */ +#endif /* SA_RESTART */ ret = sigaction(signo, &sig, &osig); if (ret < 0) return (SIG_ERR); - else + else return (osig.sa_handler); } @@ -74,7 +74,6 @@ signal_init(void) signal_set(SIGKILL, sigend); } - /* Usage function */ static void usage(const char *prog) @@ -220,7 +219,7 @@ main(int argc, char **argv) /* Signal handling initialization */ signal_init(); - + /* Create the master thread */ master = thread_make_master(); @@ -238,7 +237,7 @@ main(int argc, char **argv) /* Finalize output informations */ if (req->verbose) printf("Global response time for [%s] =%lu\n", - req->url, req->response_time-req->ref_time); + req->url, req->response_time - req->ref_time); /* exit cleanly */ SSL_CTX_free(req->ctx); diff --git a/genhash/main.h b/genhash/main.h index 6bf06269d..9dd34271c 100644 --- a/genhash/main.h +++ b/genhash/main.h @@ -71,7 +71,7 @@ typedef struct { } REQ; /* Global variables */ -REQ *req; /* Cmd line arguments */ +REQ *req; /* Cmd line arguments */ unsigned int debug; /* Data buffer length description */ diff --git a/genhash/sock.c b/genhash/sock.c index f67f5b272..7f6420df8 100644 --- a/genhash/sock.c +++ b/genhash/sock.c @@ -36,7 +36,8 @@ extern thread_master *master; extern SOCK *sock; /* Close the descriptor */ -static void close_sock(SOCK *sock) +static void +close_sock(SOCK * sock) { if (sock->ssl) { SSL_shutdown(sock->ssl); @@ -46,7 +47,8 @@ static void close_sock(SOCK *sock) } /* Destroy the socket handler */ -void free_sock(SOCK *sock) +void +free_sock(SOCK * sock) { DBG("Freeing fd:%d\n", sock->fd); @@ -55,10 +57,10 @@ void free_sock(SOCK *sock) } /* Init socket handler */ -void init_sock(void) +void +init_sock(void) { - sock = (SOCK *)MALLOC(sizeof(SOCK)); - memset(sock, 0, sizeof(SOCK)); - thread_add_event(master, tcp_connect_thread, - sock, 0); + sock = (SOCK *) MALLOC(sizeof (SOCK)); + memset(sock, 0, sizeof (SOCK)); + thread_add_event(master, tcp_connect_thread, sock, 0); } diff --git a/genhash/sock.h b/genhash/sock.h index 194335365..939a1550e 100644 --- a/genhash/sock.h +++ b/genhash/sock.h @@ -44,7 +44,7 @@ typedef struct { } SOCK; /* Prototypes */ -extern void free_sock(SOCK *sock); +extern void free_sock(SOCK * sock); extern void init_sock(void); #endif diff --git a/genhash/ssl.c b/genhash/ssl.c index 0fdaa93f5..fa42d9b3b 100644 --- a/genhash/ssl.c +++ b/genhash/ssl.c @@ -106,8 +106,7 @@ ssl_connect(thread * thread) SSL_set_bio(sock->ssl, sock->bio, sock->bio); ret = SSL_connect(sock->ssl); - DBG(" SSL_connect return code = %d on fd:%d\n", - ret, thread->u.fd); + DBG(" SSL_connect return code = %d on fd:%d\n", ret, thread->u.fd); ssl_printerr(SSL_get_error(sock->ssl, ret)); return (ret > 0) ? 1 : 0; @@ -161,7 +160,7 @@ ssl_read_thread(thread * thread) * and sometime not... */ -read_stream: + read_stream: /* read the SSL stream */ memset(sock->buffer, 0, MAX_BUFFER_LENGTH); diff --git a/keepalived.spec b/keepalived.spec index 1d2c28165..bbd313dbd 100644 --- a/keepalived.spec +++ b/keepalived.spec @@ -1,7 +1,7 @@ Name: keepalived Summary: HA monitor built upon LVS, VRRP and services poller Packager: Christophe Varoqui, -Version: 1.1.1 +Version: 1.1.3 Release: 1 Source: http://www.keepalived.org/software/%{name}-%{version}.tar.gz Copyright: GPL diff --git a/keepalived/check/check_api.c b/keepalived/check/check_api.c index 7600bc81c..1f7ff45b8 100644 --- a/keepalived/check/check_api.c +++ b/keepalived/check/check_api.c @@ -5,7 +5,7 @@ * * Part: Checkers registration. * - * Version: $Id: check_api.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_api.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/check/check_ci.c b/keepalived/check/check_ci.c index f12834a43..6d23813d6 100644 --- a/keepalived/check/check_ci.c +++ b/keepalived/check/check_ci.c @@ -5,7 +5,7 @@ * * Part: CI-LINUX checker. Integration to Compaq Cluster Infrastructure. * - * Version: $Id: check_ci.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_ci.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Authors: Alexandre Cassen, * Aneesh Kumar K.V, diff --git a/keepalived/check/check_daemon.c b/keepalived/check/check_daemon.c index 2abf68a41..318cbb6fe 100644 --- a/keepalived/check/check_daemon.c +++ b/keepalived/check/check_daemon.c @@ -5,7 +5,7 @@ * * Part: Healthcheckrs child process handling. * - * Version: $Id: check_daemon.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_daemon.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -229,7 +229,7 @@ start_check_child(void) , strerror(errno)); return -1; } else if (pid) { - int poll_delay = (wdog_delay_check) ? wdog_delay_check : WATCHDOG_DELAY; + long poll_delay = (wdog_delay_check) ? wdog_delay_check : WATCHDOG_DELAY; checkers_child = pid; syslog(LOG_INFO, "Starting Healthcheck child process, pid=%d" , pid); diff --git a/keepalived/check/check_data.c b/keepalived/check/check_data.c index 35d60a43b..3b38d4cad 100644 --- a/keepalived/check/check_data.c +++ b/keepalived/check/check_data.c @@ -5,7 +5,7 @@ * * Part: Healthcheckers dynamic data structure definition. * - * Version: $Id: check_data.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_data.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/check/check_http.c b/keepalived/check/check_http.c index e13dc680f..44d10d57f 100644 --- a/keepalived/check/check_http.c +++ b/keepalived/check/check_http.c @@ -5,7 +5,7 @@ * * Part: WEB CHECK. Common HTTP/SSL checker primitives. * - * Version: $Id: check_http.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_http.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Authors: Alexandre Cassen, * Jan Holmberg, @@ -83,11 +83,11 @@ dump_http_get_check(void *data) if (http_get_chk->bindto) syslog(LOG_INFO, " Bind to = %s", inet_ntop2(http_get_chk->bindto)); - syslog(LOG_INFO, " Connection timeout = %d", - http_get_chk->connection_to); + syslog(LOG_INFO, " Connection timeout = %lu", + http_get_chk->connection_to/TIMER_HZ); syslog(LOG_INFO, " Nb get retry = %d", http_get_chk->nb_get_retry); - syslog(LOG_INFO, " Delay before retry = %d", - http_get_chk->delay_before_retry); + syslog(LOG_INFO, " Delay before retry = %lu", + http_get_chk->delay_before_retry/TIMER_HZ); dump_list(http_get_chk->url); } static http_get_checker * @@ -135,7 +135,7 @@ void connect_to_handler(vector strvec) { http_get_checker *http_get_chk = CHECKER_GET(); - http_get_chk->connection_to = CHECKER_VALUE_INT(strvec); + http_get_chk->connection_to = CHECKER_VALUE_INT(strvec) * TIMER_HZ; } void @@ -149,7 +149,7 @@ void delay_before_retry_handler(vector strvec) { http_get_checker *http_get_chk = CHECKER_GET(); - http_get_chk->delay_before_retry = CHECKER_VALUE_INT(strvec); + http_get_chk->delay_before_retry = CHECKER_VALUE_INT(strvec) * TIMER_HZ; } void @@ -544,16 +544,35 @@ http_read_thread(thread * thread) uint16_t addr_port = get_service_port(checker); unsigned char digest[16]; int r = 0; + int val; /* Handle read timeout */ if (thread->type == THREAD_READ_TIMEOUT) return timeout_epilog(thread, "=> HTTP CHECK failed on service" " : recevice data <=\n\n", "HTTP read"); + /* Set descriptor non blocking */ + val = fcntl(thread->u.fd, F_GETFL, 0); + fcntl(thread->u.fd, F_SETFL, val | O_NONBLOCK); + /* read the HTTP stream */ r = read(thread->u.fd, req->buffer + req->len, MAX_BUFFER_LENGTH - req->len); + /* restore descriptor flags */ + fcntl(thread->u.fd, F_SETFL, val); + + /* Test if data are ready */ + if (r == -1 && errno == EAGAIN) { + syslog(LOG_INFO, "Read error with server [%s:%d]: %s", + inet_ntop2(CHECKER_RIP(checker)) + , ntohs(addr_port) + , strerror(errno)); + thread_add_read(thread->master, http_read_thread, checker, + thread->u.fd, http_get_check->connection_to); + return 0; + } + if (r == -1 || r == 0) { /* -1:error , 0:EOF */ /* All the HTTP stream has been parsed */ diff --git a/keepalived/check/check_misc.c b/keepalived/check/check_misc.c index a34d3e136..0c6e04d8b 100644 --- a/keepalived/check/check_misc.c +++ b/keepalived/check/check_misc.c @@ -6,7 +6,7 @@ * Part: MISC CHECK. Perform a system call to run an extra * system prog or script. * - * Version: $Id: check_misc.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_misc.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Authors: Alexandre Cassen, * Eric Jarman, @@ -57,7 +57,7 @@ dump_misc_check(void *data) syslog(LOG_INFO, " Keepalive method = MISC_CHECK"); syslog(LOG_INFO, " script = %s", misc_chk->path); - syslog(LOG_INFO, " timeout = %d", misc_chk->timeout); + syslog(LOG_INFO, " timeout = %lu", misc_chk->timeout/TIMER_HZ); } void @@ -81,7 +81,7 @@ void misc_timeout_handler(vector strvec) { misc_checker *misc_chk = CHECKER_GET(); - misc_chk->timeout = CHECKER_VALUE_INT(strvec); + misc_chk->timeout = CHECKER_VALUE_INT(strvec) * TIMER_HZ; } void diff --git a/keepalived/check/check_parser.c b/keepalived/check/check_parser.c index 7c0b92353..c138db795 100644 --- a/keepalived/check/check_parser.c +++ b/keepalived/check/check_parser.c @@ -7,7 +7,7 @@ * data structure representation the conf file representing * the loadbalanced server pool. * - * Version: $Id: check_parser.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_parser.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/check/check_ssl.c b/keepalived/check/check_ssl.c index 0fbb5eefd..4705911b1 100644 --- a/keepalived/check/check_ssl.c +++ b/keepalived/check/check_ssl.c @@ -7,7 +7,7 @@ * url, compute a MD5 over this result and match it to the * expected value. * - * Version: $Id: check_ssl.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_ssl.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Authors: Alexandre Cassen, * Jan Holmberg, diff --git a/keepalived/check/check_tcp.c b/keepalived/check/check_tcp.c index 00df1a39c..27704c70d 100644 --- a/keepalived/check/check_tcp.c +++ b/keepalived/check/check_tcp.c @@ -5,7 +5,7 @@ * * Part: TCP checker. * - * Version: $Id: check_tcp.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_tcp.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -54,7 +54,7 @@ dump_tcp_check(void *data) ntohs(tcp_chk->connection_port)); if (tcp_chk->bindto) syslog(LOG_INFO, " Bind to = %s", inet_ntop2(tcp_chk->bindto)); - syslog(LOG_INFO, " Connection timeout = %d", tcp_chk->connection_to); + syslog(LOG_INFO, " Connection timeout = %d", tcp_chk->connection_to/TIMER_HZ); } void @@ -85,7 +85,7 @@ void connect_timeout_handler(vector strvec) { tcp_checker *tcp_chk = CHECKER_GET(); - tcp_chk->connection_to = CHECKER_VALUE_INT(strvec); + tcp_chk->connection_to = CHECKER_VALUE_INT(strvec) * TIMER_HZ; } void diff --git a/keepalived/check/ipfwwrapper.c b/keepalived/check/ipfwwrapper.c index 8c44438e5..48d890126 100644 --- a/keepalived/check/ipfwwrapper.c +++ b/keepalived/check/ipfwwrapper.c @@ -7,7 +7,7 @@ * library to add/remove server MASQ rules to the kernel * firewall framework. * - * Version: $Id: ipfwwrapper.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: ipfwwrapper.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/check/ipvswrapper.c b/keepalived/check/ipvswrapper.c index b8e27ede1..2a21de7cd 100644 --- a/keepalived/check/ipvswrapper.c +++ b/keepalived/check/ipvswrapper.c @@ -6,7 +6,7 @@ * Part: IPVS Kernel wrapper. Use setsockopt call to add/remove * server to/from the loadbalanced server pool. * - * Version: $Id: ipvswrapper.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: ipvswrapper.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/check/ipwrapper.c b/keepalived/check/ipwrapper.c index c285975fe..488e70ef3 100644 --- a/keepalived/check/ipwrapper.c +++ b/keepalived/check/ipwrapper.c @@ -5,7 +5,7 @@ * * Part: Manipulation functions for IPVS & IPFW wrappers. * - * Version: $id: ipwrapper.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $id: ipwrapper.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/core/daemon.c b/keepalived/core/daemon.c index f478f8019..0ff552ac7 100644 --- a/keepalived/core/daemon.c +++ b/keepalived/core/daemon.c @@ -5,7 +5,7 @@ * * Part: Main program structure. * - * Version: $Id: main.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: main.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -122,7 +122,7 @@ signal_set(int signo, void (*func) (int)) sig.sa_flags = 0; #ifdef SA_RESTART sig.sa_flags |= SA_RESTART; -#endif /* SA_RESTART */ +#endif /* SA_RESTART */ ret = sigaction(signo, &sig, &osig); diff --git a/keepalived/core/global_data.c b/keepalived/core/global_data.c index c6d95499d..67d4fd17c 100644 --- a/keepalived/core/global_data.c +++ b/keepalived/core/global_data.c @@ -5,7 +5,7 @@ * * Part: Dynamic data structure definition. * - * Version: $Id: global_data.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: global_data.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -35,58 +35,64 @@ extern conf_data *data; /* Default settings */ static void -set_default_lvs_id(conf_data* conf_data) +set_default_lvs_id(conf_data * conf_data) { char *new_id = NULL; int len = 0; new_id = get_local_name(); - if (!new_id || !new_id[0]) return; + if (!new_id || !new_id[0]) + return; len = strlen(new_id); conf_data->lvs_id = MALLOC(len + 1); - if (!conf_data->lvs_id) return; + if (!conf_data->lvs_id) + return; memcpy(conf_data->lvs_id, new_id, len); } static void -set_default_email_from(conf_data* conf_data) +set_default_email_from(conf_data * conf_data) { struct passwd *pwd = NULL; - char* hostname = NULL; + char *hostname = NULL; int len = 0; hostname = get_local_name(); - if (!hostname || !hostname[0]) return; + if (!hostname || !hostname[0]) + return; pwd = getpwuid(getuid()); - if (!pwd) return; + if (!pwd) + return; len = strlen(hostname) + strlen(pwd->pw_name) + 2; conf_data->email_from = MALLOC(len); - if (!conf_data->email_from) return; - + if (!conf_data->email_from) + return; + snprintf(conf_data->email_from, len, "%s@%s", pwd->pw_name, hostname); } static void -set_default_smtp_server(conf_data* conf_data) +set_default_smtp_server(conf_data * conf_data) { conf_data->smtp_server = htonl(DEFAULT_SMTP_SERVER); } static void -set_default_smtp_connection_timeout(conf_data* conf_data) +set_default_smtp_connection_timeout(conf_data * conf_data) { conf_data->smtp_connection_to = DEFAULT_SMTP_CONNECTION_TIMEOUT; } static void -set_default_values(conf_data* conf_data) +set_default_values(conf_data * conf_data) { /* No global data so don't default */ - if (!conf_data) return; + if (!conf_data) + return; set_default_lvs_id(conf_data); set_default_smtp_server(conf_data); set_default_smtp_connection_timeout(conf_data); @@ -132,7 +138,7 @@ alloc_global_data(void) } void -free_global_data(conf_data *data) +free_global_data(conf_data * data) { free_list(data->email); FREE_PTR(data->lvs_id); @@ -141,14 +147,13 @@ free_global_data(conf_data *data) } void -dump_global_data(conf_data *data) +dump_global_data(conf_data * data) { if (!data) return; if (data->lvs_id || - data->smtp_server || - data->smtp_connection_to || data->email_from) { + data->smtp_server || data->smtp_connection_to || data->email_from) { syslog(LOG_INFO, "------< Global definitions >------"); } if (data->lvs_id) @@ -157,8 +162,8 @@ dump_global_data(conf_data *data) syslog(LOG_INFO, " Smtp server = %s", inet_ntop2(data->smtp_server)); if (data->smtp_connection_to) - syslog(LOG_INFO, " Smtp server connection timeout = %d", - data->smtp_connection_to); + syslog(LOG_INFO, " Smtp server connection timeout = %lu", + data->smtp_connection_to / TIMER_HZ); if (data->email_from) { syslog(LOG_INFO, " Email notification from = %s", data->email_from); diff --git a/keepalived/core/global_parser.c b/keepalived/core/global_parser.c index 233cb5515..974d8b44e 100644 --- a/keepalived/core/global_parser.c +++ b/keepalived/core/global_parser.c @@ -7,7 +7,7 @@ * data structure representation the conf file representing * the loadbalanced server pool. * - * Version: $Id: global_parser.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: global_parser.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -50,7 +50,7 @@ emailfrom_handler(vector strvec) static void smtpto_handler(vector strvec) { - data->smtp_connection_to = atoi(VECTOR_SLOT(strvec, 1)); + data->smtp_connection_to = atoi(VECTOR_SLOT(strvec, 1)) * TIMER_HZ; } static void smtpip_handler(vector strvec) diff --git a/keepalived/core/layer4.c b/keepalived/core/layer4.c index d8916ea4c..2ef201f8c 100644 --- a/keepalived/core/layer4.c +++ b/keepalived/core/layer4.c @@ -6,7 +6,7 @@ * Part: Layer4 checkers handling. Register worker threads & * upper layer checkers. * - * Version: $Id: layer4.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: layer4.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -53,7 +53,7 @@ tcp_bind_connect(int fd, uint32_t addr_ip, uint16_t addr_port, uint32_t bind_ip) if (bind_ip) { sin.sin_family = AF_INET; sin.sin_addr.s_addr = bind_ip; - if (bind(fd, (struct sockaddr *) &sin, sizeof(sin)) != 0) + if (bind(fd, (struct sockaddr *) &sin, sizeof (sin)) != 0) return connect_error; } @@ -129,15 +129,8 @@ tcp_socket_state(int fd, thread * thread, uint32_t addr_ip, uint16_t addr_port, inet_ntop2(addr_ip), ntohs(addr_port)); timer_min = timer_sub_now(thread->sands); - - if (TIMER_SEC(timer_min) <= 0) - thread_add_write(thread->master, func, - THREAD_ARG(thread) - , thread->u.fd, 0); - else - thread_add_write(thread->master, func, - THREAD_ARG(thread) - , thread->u.fd, TIMER_SEC(timer_min)); + thread_add_write(thread->master, func, THREAD_ARG(thread) + , thread->u.fd, TIMER_LONG(timer_min)); return connect_in_progress; } else if (status != 0) { close(thread->u.fd); @@ -150,7 +143,7 @@ tcp_socket_state(int fd, thread * thread, uint32_t addr_ip, uint16_t addr_port, void tcp_connection_state(int fd, enum connect_result status, thread * thread, int (*func) (struct _thread *) - , int timeout) + , long timeout) { checker *checker; diff --git a/keepalived/core/main.c b/keepalived/core/main.c index 76730ce21..5a1c072cd 100644 --- a/keepalived/core/main.c +++ b/keepalived/core/main.c @@ -5,7 +5,7 @@ * * Part: Main program structure. * - * Version: $Id: main.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: main.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -25,6 +25,14 @@ #include "main.h" #include "watchdog.h" +/* Log faility table */ +struct { + int facility; +} LOG_FACILITY[LOG_FACILITY_MAX + 1] = { + {LOG_LOCAL0}, {LOG_LOCAL1}, {LOG_LOCAL2}, {LOG_LOCAL3}, + {LOG_LOCAL4}, {LOG_LOCAL5}, {LOG_LOCAL6}, {LOG_LOCAL7} +}; + /* Daemon stop sequence */ static void stop_keepalived(void) @@ -142,9 +150,11 @@ usage(const char *prog) " %s --dump-conf -d Dump the configuration data.\n" " %s --log-console -l Log message to local console.\n" " %s --log-detail -D Detailed log messages.\n" + " %s --log-facility -S 0-7 Set syslog facility to LOG_LOCAL[0-7]. (default=LOG_DAEMON)\n" " %s --help -h Display this short inlined help screen.\n" " %s --version -v Display the version number\n", - prog, prog, prog, prog, prog, prog, prog, prog, prog, prog, prog); + prog, prog, prog, prog, prog, prog, prog, prog, prog, prog, + prog, prog); } /* Command line parser */ @@ -160,6 +170,7 @@ parse_cmdline(int argc, char **argv) {"help", 'h', POPT_ARG_NONE, NULL, 'h'}, {"log-console", 'l', POPT_ARG_NONE, NULL, 'l'}, {"log-detail", 'D', POPT_ARG_NONE, NULL, 'D'}, + {"log-facility", 'S', POPT_ARG_STRING, &optarg, 'S'}, {"dont-release-vrrp", 'V', POPT_ARG_NONE, NULL, 'V'}, {"dont-release-ipvs", 'I', POPT_ARG_NONE, NULL, 'I'}, {"dont-fork", 'n', POPT_ARG_NONE, NULL, 'n'}, @@ -204,14 +215,17 @@ parse_cmdline(int argc, char **argv) case 'D': debug |= 32; break; + case 'S': + log_facility = LOG_FACILITY[atoi(optarg)].facility; + break; case 'f': conf_file = optarg; break; case 'R': - wdog_delay_vrrp = atoi(optarg); + wdog_delay_vrrp = atoi(optarg) * TIMER_HZ; break; case 'H': - wdog_delay_check = atoi(optarg); + wdog_delay_check = atoi(optarg) * TIMER_HZ; break; } @@ -236,14 +250,17 @@ parse_cmdline(int argc, char **argv) case 'D': debug |= 32; break; + case 'S': + log_facility = LOG_FACILITY[atoi(optarg)].facility; + break; case 'f': conf_file = optarg; break; case 'R': - wdog_delay_vrrp = atoi(optarg); + wdog_delay_vrrp = atoi(optarg) * TIMER_HZ; break; case 'H': - wdog_delay_check = atoi(optarg); + wdog_delay_check = atoi(optarg) * TIMER_HZ; break; } } @@ -272,7 +289,7 @@ main(int argc, char **argv) */ parse_cmdline(argc, argv); - openlog(PROG, LOG_PID | (debug & 1) ? LOG_CONS : 0, LOG_DAEMON); + openlog(PROG, LOG_PID | (debug & 1) ? LOG_CONS : 0, log_facility); syslog(LOG_INFO, "Starting " VERSION_STRING); /* Check if keepalived is already running */ diff --git a/keepalived/core/pidfile.c b/keepalived/core/pidfile.c index bdafb5ea8..9c5c8f316 100644 --- a/keepalived/core/pidfile.c +++ b/keepalived/core/pidfile.c @@ -5,7 +5,7 @@ * * Part: pidfile utility. * - * Version: $Id: pidfile.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: pidfile.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -31,8 +31,8 @@ pidfile_write(char *pid_file, int pid) FILE *pidfile = fopen(pid_file, "w"); if (!pidfile) { - syslog(LOG_INFO, "pidfile_write : Can not open %s pidfile" - , pid_file); + syslog(LOG_INFO, "pidfile_write : Can not open %s pidfile", + pid_file); return 0; } fprintf(pidfile, "%d\n", pid); diff --git a/keepalived/core/smtp.c b/keepalived/core/smtp.c index fcad7cb3a..8cf3ac5bc 100644 --- a/keepalived/core/smtp.c +++ b/keepalived/core/smtp.c @@ -7,7 +7,7 @@ * using the smtp protocol according to the RFC 821. A non blocking * timeouted connection is used to handle smtp protocol. * - * Version: $Id: smtp.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: smtp.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -159,7 +159,8 @@ smtp_read_thread(thread * thread) smtp_arg = THREAD_ARG(thread); if (thread->type == THREAD_READ_TIMEOUT) { - syslog(LOG_INFO, "Timeout reading data to remote SMTP server [%s:%d].", + syslog(LOG_INFO, + "Timeout reading data to remote SMTP server [%s:%d].", inet_ntop2(data->smtp_server), SMTP_PORT); SMTP_FSM_READ(QUIT, thread, 0); return -1; @@ -173,7 +174,8 @@ smtp_read_thread(thread * thread) if (rcv_buffer_size == -1) { if (errno == EAGAIN) goto end; - syslog(LOG_INFO, "Error reading data from remote SMTP server [%s:%d].", + syslog(LOG_INFO, + "Error reading data from remote SMTP server [%s:%d].", inet_ntop2(data->smtp_server), SMTP_PORT); SMTP_FSM_READ(QUIT, thread, 0); return 0; @@ -181,9 +183,10 @@ smtp_read_thread(thread * thread) /* received data overflow buffer size ? */ if (smtp_arg->buflen >= SMTP_BUFFER_MAX) { - syslog(LOG_INFO, "Received buffer from remote SMTP server [%s:%d]" - " overflow our get read buffer length." - , inet_ntop2(data->smtp_server), SMTP_PORT); + syslog(LOG_INFO, + "Received buffer from remote SMTP server [%s:%d]" + " overflow our get read buffer length.", + inet_ntop2(data->smtp_server), SMTP_PORT); SMTP_FSM_READ(QUIT, thread, 0); return 0; } else { @@ -191,7 +194,7 @@ smtp_read_thread(thread * thread) buffer[smtp_arg->buflen] = 0; /* NULL terminate */ } -end: + end: /* parse the buffer, finding the last line of the response for the code */ reply = buffer; @@ -205,8 +208,9 @@ smtp_read_thread(thread * thread) smtp_arg->buflen -= (reply - buffer); buffer[smtp_arg->buflen] = 0; - thread_add_read(thread->master, smtp_read_thread, smtp_arg, - thread->u.fd, data->smtp_connection_to); + thread_add_read(thread->master, smtp_read_thread, + smtp_arg, thread->u.fd, + data->smtp_connection_to); return 0; } @@ -241,8 +245,9 @@ smtp_read_thread(thread * thread) thread_add_write(thread->master, smtp_send_thread, smtp_arg, smtp_arg->fd, data->smtp_connection_to); } else { - syslog(LOG_INFO, "Can not read data from remote SMTP server [%s:%d].", - inet_ntop2(data->smtp_server), SMTP_PORT); + syslog(LOG_INFO, + "Can not read data from remote SMTP server [%s:%d].", + inet_ntop2(data->smtp_server), SMTP_PORT); SMTP_FSM_READ(QUIT, thread, 0); } @@ -253,9 +258,10 @@ static int smtp_send_thread(thread * thread) { smtp_thread_arg *smtp_arg = THREAD_ARG(thread); - + if (thread->type == THREAD_WRITE_TIMEOUT) { - syslog(LOG_INFO, "Timeout sending data to remote SMTP server [%s:%d].", + syslog(LOG_INFO, + "Timeout sending data to remote SMTP server [%s:%d].", inet_ntop2(data->smtp_server), SMTP_PORT); SMTP_FSM_READ(QUIT, thread, 0); return 0; @@ -274,15 +280,15 @@ smtp_send_thread(thread * thread) thread_add_read(thread->master, smtp_read_thread, smtp_arg, thread->u.fd, data->smtp_connection_to); } else { - syslog(LOG_INFO, "Can not send data to remote SMTP server [%s:%d].", - inet_ntop2(data->smtp_server), SMTP_PORT); + syslog(LOG_INFO, + "Can not send data to remote SMTP server [%s:%d].", + inet_ntop2(data->smtp_server), SMTP_PORT); SMTP_FSM_READ(QUIT, thread, 0); } return 0; } - static int connection_code(thread * thread, int status) { @@ -292,8 +298,8 @@ connection_code(thread * thread, int status) smtp_arg->stage++; } else { syslog(LOG_INFO, "Error connecting SMTP server[%s:%d]." - " SMTP status code = %d" - , inet_ntop2(data->smtp_server), SMTP_PORT, status); + " SMTP status code = %d", inet_ntop2(data->smtp_server), + SMTP_PORT, status); smtp_arg->stage = ERROR; } @@ -307,9 +313,8 @@ helo_cmd(thread * thread) smtp_thread_arg *smtp_arg = THREAD_ARG(thread); char *buffer; - buffer = (char *)MALLOC(SMTP_BUFFER_MAX); - snprintf(buffer, SMTP_BUFFER_MAX, SMTP_HELO_CMD, - get_local_name()); + buffer = (char *) MALLOC(SMTP_BUFFER_MAX); + snprintf(buffer, SMTP_BUFFER_MAX, SMTP_HELO_CMD, get_local_name()); if (send(thread->u.fd, buffer, strlen(buffer), 0) == -1) smtp_arg->stage = ERROR; FREE(buffer); @@ -324,9 +329,10 @@ helo_code(thread * thread, int status) if (status == 250) { smtp_arg->stage++; } else { - syslog(LOG_INFO, "Error processing HELO cmd on SMTP server [%s:%d]." - " SMTP status code = %d" - , inet_ntop2(data->smtp_server), SMTP_PORT, status); + syslog(LOG_INFO, + "Error processing HELO cmd on SMTP server [%s:%d]." + " SMTP status code = %d", inet_ntop2(data->smtp_server), + SMTP_PORT, status); smtp_arg->stage = ERROR; } @@ -340,9 +346,8 @@ mail_cmd(thread * thread) smtp_thread_arg *smtp_arg = THREAD_ARG(thread); char *buffer; - buffer = (char *)MALLOC(SMTP_BUFFER_MAX); - snprintf(buffer, SMTP_BUFFER_MAX, SMTP_MAIL_CMD, - data->email_from); + buffer = (char *) MALLOC(SMTP_BUFFER_MAX); + snprintf(buffer, SMTP_BUFFER_MAX, SMTP_MAIL_CMD, data->email_from); if (send(thread->u.fd, buffer, strlen(buffer), 0) == -1) smtp_arg->stage = ERROR; FREE(buffer); @@ -357,9 +362,10 @@ mail_code(thread * thread, int status) if (status == 250) { smtp_arg->stage++; } else { - syslog(LOG_INFO, "Error processing MAIL cmd on SMTP server [%s:%d]." - " SMTP status code = %d" - , inet_ntop2(data->smtp_server), SMTP_PORT, status); + syslog(LOG_INFO, + "Error processing MAIL cmd on SMTP server [%s:%d]." + " SMTP status code = %d", inet_ntop2(data->smtp_server), + SMTP_PORT, status); smtp_arg->stage = ERROR; } @@ -374,7 +380,7 @@ rcpt_cmd(thread * thread) char *buffer; char *fetched_email; - buffer = (char *)MALLOC(SMTP_BUFFER_MAX); + buffer = (char *) MALLOC(SMTP_BUFFER_MAX); /* We send RCPT TO command multiple time to add all our email receivers. * --rfc821.3.1 */ @@ -401,9 +407,10 @@ rcpt_code(thread * thread, int status) if (!fetched_email) smtp_arg->stage++; } else { - syslog(LOG_INFO, "Error processing RCPT cmd on SMTP server [%s:%d]." - " SMTP status code = %d" - , inet_ntop2(data->smtp_server), SMTP_PORT, status); + syslog(LOG_INFO, + "Error processing RCPT cmd on SMTP server [%s:%d]." + " SMTP status code = %d", inet_ntop2(data->smtp_server), + SMTP_PORT, status); smtp_arg->stage = ERROR; } @@ -429,9 +436,10 @@ data_code(thread * thread, int status) if (status == 354) { smtp_arg->stage++; } else { - syslog(LOG_INFO, "Error processing DATA cmd on SMTP server [%s:%d]." - " SMTP status code = %d" - , inet_ntop2(data->smtp_server), SMTP_PORT, status); + syslog(LOG_INFO, + "Error processing DATA cmd on SMTP server [%s:%d]." + " SMTP status code = %d", inet_ntop2(data->smtp_server), + SMTP_PORT, status); smtp_arg->stage = ERROR; } @@ -448,7 +456,7 @@ body_cmd(thread * thread) smtp_thread_arg *smtp_arg = THREAD_ARG(thread); char *buffer; - buffer = (char *)MALLOC(SMTP_BUFFER_MAX); + buffer = (char *) MALLOC(SMTP_BUFFER_MAX); snprintf(buffer, SMTP_BUFFER_MAX, SMTP_HEADERS_CMD, data->email_from, smtp_arg->subject); @@ -458,8 +466,7 @@ body_cmd(thread * thread) smtp_arg->stage = ERROR; memset(buffer, 0, SMTP_BUFFER_MAX); - snprintf(buffer, SMTP_BUFFER_MAX, SMTP_BODY_CMD, - smtp_arg->body); + snprintf(buffer, SMTP_BUFFER_MAX, SMTP_BODY_CMD, smtp_arg->body); /* send the the body field */ if (send(thread->u.fd, buffer, strlen(buffer), 0) == -1) @@ -482,9 +489,10 @@ body_code(thread * thread, int status) syslog(LOG_INFO, "SMTP alert successfully sent."); smtp_arg->stage++; } else { - syslog(LOG_INFO, "Error processing DOT cmd on SMTP server [%s:%d]." - " SMTP status code = %d" - , inet_ntop2(data->smtp_server), SMTP_PORT, status); + syslog(LOG_INFO, + "Error processing DOT cmd on SMTP server [%s:%d]." + " SMTP status code = %d", inet_ntop2(data->smtp_server), + SMTP_PORT, status); smtp_arg->stage = ERROR; } @@ -517,35 +525,32 @@ quit_code(thread * thread, int status) /* connect remote SMTP server */ static void -smtp_connect(smtp_thread_arg *smtp_arg) +smtp_connect(smtp_thread_arg * smtp_arg) { enum connect_result status; if ((smtp_arg->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) - == -1) { + == -1) { DBG("SMTP connect fail to create socket."); free_smtp_all(smtp_arg); return; } - status = tcp_connect(smtp_arg->fd, data->smtp_server, - htons(SMTP_PORT)); + status = tcp_connect(smtp_arg->fd, data->smtp_server, htons(SMTP_PORT)); /* Handle connection status code */ - thread_add_event(master, SMTP_FSM[status].send, smtp_arg, - smtp_arg->fd); + thread_add_event(master, SMTP_FSM[status].send, smtp_arg, smtp_arg->fd); } /* Main entry point */ void smtp_alert(thread_master * master, real_server * rs, vrrp_rt * vrrp, - vrrp_sgroup *vgroup, const char *subject, const char *body) + vrrp_sgroup * vgroup, const char *subject, const char *body) { smtp_thread_arg *smtp_arg; /* Only send mail if email specified */ - if (!LIST_ISEMPTY(data->email) && - data->smtp_server != 0) { + if (!LIST_ISEMPTY(data->email) && data->smtp_server != 0) { /* allocate & initialize smtp argument data structure */ smtp_arg = (smtp_thread_arg *) MALLOC(sizeof (smtp_thread_arg)); smtp_arg->subject = (char *) MALLOC(MAX_HEADERS_LENGTH); diff --git a/keepalived/include/check_api.h b/keepalived/include/check_api.h index b00c135cf..25359a72e 100644 --- a/keepalived/include/check_api.h +++ b/keepalived/include/check_api.h @@ -5,7 +5,7 @@ * * Part: Checkers arguments structures definitions. * - * Version: $Id: check_api.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_api.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/check_ci.h b/keepalived/include/check_ci.h index ec566ebfd..afd438a58 100644 --- a/keepalived/include/check_ci.h +++ b/keepalived/include/check_ci.h @@ -5,7 +5,7 @@ * * Part: check_ci.c include file. * - * Version: $Id: check_ci.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_ci.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Authors: Alexandre Cassen, * Aneesh Kumar K.V, diff --git a/keepalived/include/check_daemon.h b/keepalived/include/check_daemon.h index ee1b6baf6..32b3c3010 100644 --- a/keepalived/include/check_daemon.h +++ b/keepalived/include/check_daemon.h @@ -5,7 +5,7 @@ * * Part: check_daemon.c include file. * - * Version: $Id: check_daemon.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_daemon.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/check_data.h b/keepalived/include/check_data.h index d32ec8672..0538d0da8 100644 --- a/keepalived/include/check_data.h +++ b/keepalived/include/check_data.h @@ -5,7 +5,7 @@ * * Part: Healthcheckers dynamic data structure definition. * - * Version: $Id: check_data.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_data.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/check_http.h b/keepalived/include/check_http.h index 27947ce0d..e09be5047 100644 --- a/keepalived/include/check_http.h +++ b/keepalived/include/check_http.h @@ -5,7 +5,7 @@ * * Part: check_http.c include file. * - * Version: $Id: check_http.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_http.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Authors: Alexandre Cassen, * Jan Holmberg, @@ -67,9 +67,9 @@ typedef struct _http_get_checker { int proto; uint16_t connection_port; uint32_t bindto; - int connection_to; + long connection_to; int nb_get_retry; - int delay_before_retry; + long delay_before_retry; list url; http_arg *arg; } http_get_checker; @@ -94,7 +94,7 @@ extern void install_http_check_keyword(void); extern int epilog(thread * thread, int metod, int t, int c); extern int timeout_epilog(thread * thread, char *smtp_msg, char *debug_msg); extern url *fetch_next_url(http_get_checker * http_get_check); -extern int http_process_response(REQ *req, int r); +extern int http_process_response(REQ * req, int r); extern int http_handle_response(thread * thread, unsigned char digest[16] , int empty_buffer); #endif diff --git a/keepalived/include/check_misc.h b/keepalived/include/check_misc.h index db96709ad..5418959fa 100644 --- a/keepalived/include/check_misc.h +++ b/keepalived/include/check_misc.h @@ -5,7 +5,7 @@ * * Part: check_misc.c include file. * - * Version: $Id: check_misc.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_misc.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * Eric Jarman, @@ -35,7 +35,7 @@ /* Checker argument structure */ typedef struct _misc_checker { char *path; - int timeout; + long timeout; } misc_checker; /* Prototypes defs */ diff --git a/keepalived/include/check_parser.h b/keepalived/include/check_parser.h index f44dffdce..c7be342e6 100644 --- a/keepalived/include/check_parser.h +++ b/keepalived/include/check_parser.h @@ -5,7 +5,7 @@ * * Part: check_parser.c include file. * - * Version: $Id: check_parser.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_parser.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/check_ssl.h b/keepalived/include/check_ssl.h index 53f3b4092..d617cfbb2 100644 --- a/keepalived/include/check_ssl.h +++ b/keepalived/include/check_ssl.h @@ -5,7 +5,7 @@ * * Part: check_http.c include file. * - * Version: $Id: check_http.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_http.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Authors: Alexandre Cassen, * Jan Holmberg, diff --git a/keepalived/include/check_tcp.h b/keepalived/include/check_tcp.h index 420172b9e..6c31d9085 100644 --- a/keepalived/include/check_tcp.h +++ b/keepalived/include/check_tcp.h @@ -5,7 +5,7 @@ * * Part: check_tcp.c include file. * - * Version: $Id: check_tcp.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: check_tcp.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/daemon.h b/keepalived/include/daemon.h index 65d5aec02..8a09a8c1b 100644 --- a/keepalived/include/daemon.h +++ b/keepalived/include/daemon.h @@ -5,7 +5,7 @@ * * Part: Daemon process handling. * - * Version: $Id: daemon.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: daemon.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/global_data.h b/keepalived/include/global_data.h index 856f0e55f..d1cfb93b7 100644 --- a/keepalived/include/global_data.h +++ b/keepalived/include/global_data.h @@ -5,7 +5,7 @@ * * Part: Dynamic data structure definition. * - * Version: $Id: global_data.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: global_data.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -32,10 +32,11 @@ /* local includes */ #include "list.h" +#include "timer.h" /* constants */ #define DEFAULT_SMTP_SERVER 0x7f000001 -#define DEFAULT_SMTP_CONNECTION_TIMEOUT 30 +#define DEFAULT_SMTP_CONNECTION_TIMEOUT (30 * TIMER_HZ) /* email link list */ typedef struct _email { @@ -47,7 +48,7 @@ typedef struct _conf_data { char *lvs_id; char *email_from; uint32_t smtp_server; - int smtp_connection_to; + long smtp_connection_to; list email; } conf_data; diff --git a/keepalived/include/global_parser.h b/keepalived/include/global_parser.h index 6e10f0fb6..1c2570ed7 100644 --- a/keepalived/include/global_parser.h +++ b/keepalived/include/global_parser.h @@ -5,7 +5,7 @@ * * Part: vrrp_parser.c include file. * - * Version: $Id: global_parser.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: global_parser.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/ipfwwrapper.h b/keepalived/include/ipfwwrapper.h index f54ff3298..ddfd33eb9 100644 --- a/keepalived/include/ipfwwrapper.h +++ b/keepalived/include/ipfwwrapper.h @@ -5,7 +5,7 @@ * * Part: ipfwwrapper.c include file. * - * Version: $Id: ipfwwrapper.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: ipfwwrapper.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/ipvswrapper.h b/keepalived/include/ipvswrapper.h index 0f79fc9a2..f9623289a 100644 --- a/keepalived/include/ipvswrapper.h +++ b/keepalived/include/ipvswrapper.h @@ -5,7 +5,7 @@ * * Part: ipvswrapper.c include file. * - * Version: $Id: ipvswrapper.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: ipvswrapper.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -93,9 +93,10 @@ do { \ /* prototypes */ extern virtual_server_group *ipvs_get_group_by_name(char *gname, list l); -extern int ipvs_group_remove_entry(virtual_server *vs, - virtual_server_group_entry *vsge); -extern int ipvs_cmd(int cmd, list vs_group, virtual_server * vserver, real_server * rserver); +extern int ipvs_group_remove_entry(virtual_server * vs, + virtual_server_group_entry * vsge); +extern int ipvs_cmd(int cmd, list vs_group, virtual_server * vserver, + real_server * rserver); extern int ipvs_syncd_cmd(int cmd, char *ifname, int state); extern void ipvs_syncd_master(char *ifname); extern void ipvs_syncd_backup(char *ifname); diff --git a/keepalived/include/ipwrapper.h b/keepalived/include/ipwrapper.h index 720569741..7ac07b470 100644 --- a/keepalived/include/ipwrapper.h +++ b/keepalived/include/ipwrapper.h @@ -5,7 +5,7 @@ * * Part: ipwrapper.c include file. * - * Version: $Id: ipwrapper.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: ipwrapper.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -60,10 +60,9 @@ /* prototypes */ extern void perform_svr_state(int alive, virtual_server * vs, real_server * rs); -extern int svr_checker_up(checker_id_t cid, real_server *rs); -extern void update_svr_checker_state(int alive, checker_id_t cid - , virtual_server *vs - , real_server *rs); +extern int svr_checker_up(checker_id_t cid, real_server * rs); +extern void update_svr_checker_state(int alive, checker_id_t cid, + virtual_server * vs, real_server * rs); extern int init_services(void); extern int clear_services(void); extern int clear_diff_services(void); diff --git a/keepalived/include/layer4.h b/keepalived/include/layer4.h index a3467a872..81e3ba184 100644 --- a/keepalived/include/layer4.h +++ b/keepalived/include/layer4.h @@ -5,7 +5,7 @@ * * Part: layer4.c include file. * - * Version: $Id: layer4.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: layer4.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -46,17 +46,17 @@ enum connect_result { /* Prototypes defs */ extern enum connect_result -tcp_bind_connect(int, uint32_t, uint16_t, uint32_t); + tcp_bind_connect(int, uint32_t, uint16_t, uint32_t); extern enum connect_result -tcp_connect(int, uint32_t, uint16_t); + tcp_connect(int, uint32_t, uint16_t); extern enum connect_result -tcp_socket_state(int, thread *, uint32_t, uint16_t, - int (*func) (struct _thread *)); + tcp_socket_state(int, thread *, uint32_t, uint16_t, + int (*func) (struct _thread *)); extern void -tcp_connection_state(int, enum connect_result - , thread *, int (*func) (struct _thread *) - , int); + tcp_connection_state(int, enum connect_result + , thread *, int (*func) (struct _thread *) + , long); #endif diff --git a/keepalived/include/main.h b/keepalived/include/main.h index fbe1cd364..79e6efc72 100644 --- a/keepalived/include/main.h +++ b/keepalived/include/main.h @@ -5,7 +5,7 @@ * * Part: Main program include file. * - * Version: $Id: main.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: main.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -42,21 +42,23 @@ #include "global_data.h" /* global var */ -thread_master *master = NULL; /* Scheduling master thread */ -char *conf_file = NULL; /* Configuration file */ -int reload = 0; /* Global reloading flag */ -unsigned int debug; /* Debugging flags */ -pid_t vrrp_child = -1; /* VRRP child process ID */ -pid_t checkers_child = -1; /* Healthcheckers child process ID */ -int wdog_delay_vrrp = 0; /* VRRP child polling delay */ -int wdog_delay_check = 0; /* Healthchecker child polling delay */ -conf_data *data; /* Global configuration data */ +thread_master *master = NULL; /* Scheduling master thread */ +char *conf_file = NULL; /* Configuration file */ +int log_facility = LOG_DAEMON; /* Optional logging facilities */ +int reload = 0; /* Global reloading flag */ +unsigned int debug; /* Debugging flags */ +pid_t vrrp_child = -1; /* VRRP child process ID */ +pid_t checkers_child = -1; /* Healthcheckers child process ID */ +long wdog_delay_vrrp = 0; /* VRRP child polling delay */ +long wdog_delay_check = 0; /* Healthchecker child polling delay */ +conf_data *data; /* Global configuration data */ /* Build version */ +#define LOG_FACILITY_MAX 7 #define PROG "Keepalived" -#define VERSION_CODE 0x010102 -#define DATE_CODE 0x080903 +#define VERSION_CODE 0x010103 +#define DATE_CODE 0x1D0903 #define KEEPALIVED_VERSION(version) \ (version >> 16) & 0xFF, \ diff --git a/keepalived/include/pidfile.h b/keepalived/include/pidfile.h index 242565f85..c6b17678c 100644 --- a/keepalived/include/pidfile.h +++ b/keepalived/include/pidfile.h @@ -5,7 +5,7 @@ * * Part: pidfile.c include file. * - * Version: $Id: pidfile.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: pidfile.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/smtp.h b/keepalived/include/smtp.h index b8f860d25..e4e04c471 100644 --- a/keepalived/include/smtp.h +++ b/keepalived/include/smtp.h @@ -5,7 +5,7 @@ * * Part: smtp.c include file. * - * Version: $Id: smtp.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: smtp.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -92,6 +92,6 @@ typedef struct _smtp_thread_arg { /* Prototypes defs */ extern void smtp_alert(thread_master *, - real_server *, vrrp_rt *, vrrp_sgroup *, + real_server *, vrrp_rt *, vrrp_sgroup *, const char *, const char *); #endif diff --git a/keepalived/include/vrrp.h b/keepalived/include/vrrp.h index bafc78a09..16731ea84 100644 --- a/keepalived/include/vrrp.h +++ b/keepalived/include/vrrp.h @@ -6,7 +6,7 @@ * * Part: vrrp.c program include file. * - * Version: $Id: vrrp.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -54,19 +54,19 @@ typedef struct { /* rfc2338.5.1 */ /* protocol constants */ #define INADDR_VRRP_GROUP 0xe0000012 /* multicast addr - rfc2338.5.2.2 */ -#define VRRP_IP_TTL 255 /* in and out pkt ttl -- rfc2338.5.2.3 */ -#define IPPROTO_VRRP 112 /* IP protocol number -- rfc2338.5.2.4 */ -#define VRRP_VERSION 2 /* current version -- rfc2338.5.3.1 */ -#define VRRP_PKT_ADVERT 1 /* packet type -- rfc2338.5.3.2 */ -#define VRRP_PRIO_OWNER 255 /* priority of the ip owner -- rfc2338.5.3.4 */ -#define VRRP_PRIO_DFL 100 /* default priority -- rfc2338.5.3.4 */ -#define VRRP_PRIO_STOP 0 /* priority to stop -- rfc2338.5.3.4 */ -#define VRRP_AUTH_NONE 0 /* no authentification -- rfc2338.5.3.6 */ -#define VRRP_AUTH_PASS 1 /* password authentification -- rfc2338.5.3.6 */ -#define VRRP_AUTH_AH 2 /* AH(IPSec) authentification - rfc2338.5.3.6 */ -#define VRRP_ADVER_DFL 1 /* advert. interval (in sec) -- rfc2338.5.3.7 */ -#define VRRP_PREEMPT_DFL 1 /* rfc2338.6.1.2.Preempt_Mode */ -#define VRRP_GARP_DELAY 5 /* Default delay to launch gratuitous arp */ +#define VRRP_IP_TTL 255 /* in and out pkt ttl -- rfc2338.5.2.3 */ +#define IPPROTO_VRRP 112 /* IP protocol number -- rfc2338.5.2.4 */ +#define VRRP_VERSION 2 /* current version -- rfc2338.5.3.1 */ +#define VRRP_PKT_ADVERT 1 /* packet type -- rfc2338.5.3.2 */ +#define VRRP_PRIO_OWNER 255 /* priority of the ip owner -- rfc2338.5.3.4 */ +#define VRRP_PRIO_DFL 100 /* default priority -- rfc2338.5.3.4 */ +#define VRRP_PRIO_STOP 0 /* priority to stop -- rfc2338.5.3.4 */ +#define VRRP_AUTH_NONE 0 /* no authentification -- rfc2338.5.3.6 */ +#define VRRP_AUTH_PASS 1 /* password authentification -- rfc2338.5.3.6 */ +#define VRRP_AUTH_AH 2 /* AH(IPSec) authentification - rfc2338.5.3.6 */ +#define VRRP_ADVER_DFL 1 /* advert. interval (in sec) -- rfc2338.5.3.7 */ +#define VRRP_PREEMPT_DFL 1 /* rfc2338.6.1.2.Preempt_Mode */ +#define VRRP_GARP_DELAY (5 * TIMER_HZ) /* Default delay to launch gratuitous arp */ /* * parameters per vrrp sync group. A vrrp_sync_group is a set diff --git a/keepalived/include/vrrp_arp.h b/keepalived/include/vrrp_arp.h index 05e2f603b..6aabf7b85 100644 --- a/keepalived/include/vrrp_arp.h +++ b/keepalived/include/vrrp_arp.h @@ -5,7 +5,7 @@ * * Part: vrrp_arp.c include file. * - * Version: $Id: vrrp_arp.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_arp.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -39,17 +39,17 @@ /* types definition */ typedef struct _m_arphdr { - unsigned short int ar_hrd; /* Format of hardware address. */ - unsigned short int ar_pro; /* Format of protocol address. */ - unsigned char ar_hln; /* Length of hardware address. */ - unsigned char ar_pln; /* Length of protocol address. */ - unsigned short int ar_op; /* ARP opcode (command). */ + unsigned short int ar_hrd; /* Format of hardware address. */ + unsigned short int ar_pro; /* Format of protocol address. */ + unsigned char ar_hln; /* Length of hardware address. */ + unsigned char ar_pln; /* Length of protocol address. */ + unsigned short int ar_op; /* ARP opcode (command). */ /* Ethernet looks like this : This bit is variable sized however... */ unsigned char __ar_sha[ETH_ALEN]; /* Sender hardware address. */ - unsigned char __ar_sip[4]; /* Sender IP address. */ + unsigned char __ar_sip[4]; /* Sender IP address. */ unsigned char __ar_tha[ETH_ALEN]; /* Target hardware address. */ - unsigned char __ar_tip[4]; /* Target IP address. */ + unsigned char __ar_tip[4]; /* Target IP address. */ } m_arphdr; /* Global var */ @@ -59,6 +59,6 @@ int garp_fd; /* prototypes */ extern void gratuitous_arp_init(void); extern void gratuitous_arp_close(void); -extern int send_gratuitous_arp(ip_address *ipaddress); +extern int send_gratuitous_arp(ip_address * ipaddress); #endif diff --git a/keepalived/include/vrrp_daemon.h b/keepalived/include/vrrp_daemon.h index ad27fcc0e..8f4eb1bd3 100644 --- a/keepalived/include/vrrp_daemon.h +++ b/keepalived/include/vrrp_daemon.h @@ -5,7 +5,7 @@ * * Part: vrrp_daemon.c include file. * - * Version: $Id: vrrp_daemon.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_daemon.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/vrrp_data.h b/keepalived/include/vrrp_data.h index eb07473ef..6a5a725a7 100644 --- a/keepalived/include/vrrp_data.h +++ b/keepalived/include/vrrp_data.h @@ -5,7 +5,7 @@ * * Part: Dynamic data structure definition. * - * Version: $Id: vrrp_data.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_data.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/vrrp_if.h b/keepalived/include/vrrp_if.h index 37d57e7b5..b42fc92fa 100644 --- a/keepalived/include/vrrp_if.h +++ b/keepalived/include/vrrp_if.h @@ -5,7 +5,7 @@ * * Part: vrrp_if.c include file. * - * Version: $Id: vrrp_if.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_if.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -49,7 +49,7 @@ #define IF_HWADDR_MAX 20 /* Max MAC address length size */ #define ARPHRD_ETHER 1 #define ARPHRD_LOOPBACK 772 -#define POLLING_DELAY 1 +#define POLLING_DELAY TIMER_HZ /* Interface Linkbeat code selection */ #define LB_IOCTL 0x1 @@ -59,15 +59,15 @@ /* Interface structure definition */ typedef struct _interface { char ifname[IF_NAMESIZ + 1]; /* Interface name */ - unsigned int ifindex; /* Interface index */ - uint32_t address; /* Interface main primary IP address */ - unsigned long flags; /* flags */ - unsigned int mtu; /* MTU for this interface */ - unsigned short hw_type; /* Type of hardware address */ + unsigned int ifindex; /* Interface index */ + uint32_t address; /* Interface main primary IP address */ + unsigned long flags; /* flags */ + unsigned int mtu; /* MTU for this interface */ + unsigned short hw_type; /* Type of hardware address */ u_char hw_addr[IF_HWADDR_MAX]; /* MAC address */ - int hw_addr_len; /* MAC addresss length */ - int lb_type; /* Interface regs selection */ - int linkbeat; /* LinkBeat from MII BMSR req */ + int hw_addr_len; /* MAC addresss length */ + int lb_type; /* Interface regs selection */ + int linkbeat; /* LinkBeat from MII BMSR req */ } interface; /* Global interface queue */ @@ -98,9 +98,9 @@ extern int if_monitor_thread(thread * thread); extern void init_interface_queue(void); extern void free_interface_queue(void); extern void dump_if(void *data); -extern int if_join_vrrp_group(int sd, interface *ifp, int proto); -extern void if_leave_vrrp_group(int sd, interface *ifp); -extern int if_setsockopt_bindtodevice(int sd, interface *ifp); +extern int if_join_vrrp_group(int sd, interface * ifp, int proto); +extern void if_leave_vrrp_group(int sd, interface * ifp); +extern int if_setsockopt_bindtodevice(int sd, interface * ifp); extern int if_setsockopt_hdrincl(int sd); extern int if_setsockopt_mcast_loop(int sd); diff --git a/keepalived/include/vrrp_index.h b/keepalived/include/vrrp_index.h index 5314f87bd..dbf3315ef 100644 --- a/keepalived/include/vrrp_index.h +++ b/keepalived/include/vrrp_index.h @@ -5,7 +5,7 @@ * * Part: vrrp_index.c include file. * - * Version: $Id: vrrp_index.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_index.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/vrrp_ipaddress.h b/keepalived/include/vrrp_ipaddress.h index 34c3c3e42..0eb4f92a2 100644 --- a/keepalived/include/vrrp_ipaddress.h +++ b/keepalived/include/vrrp_ipaddress.h @@ -5,7 +5,7 @@ * * Part: vrrp_ipaddress.c include file. * - * Version: $Id: vrrp_ipaddress.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_ipaddress.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -40,6 +40,7 @@ /* types definition */ typedef struct { uint32_t addr; /* the ip address */ + uint32_t broadcast; /* the broadcast address */ uint8_t mask; /* the ip address CIDR netmask */ int ifindex; /* Interface index owning IP address */ interface *ifp; /* Interface owning IP address */ @@ -58,11 +59,11 @@ typedef struct { (X)->scope == (Y)->scope) /* prototypes */ -extern int netlink_address_ipv4(ip_address *ipaddr, int cmd); +extern int netlink_address_ipv4(ip_address * ipaddr, int cmd); extern void netlink_iplist_ipv4(list ip_list, int cmd); extern void free_ipaddress(void *data); extern void dump_ipaddress(void *data); -extern void alloc_ipaddress(list ip_list, vector strvec, interface *ifp); +extern void alloc_ipaddress(list ip_list, vector strvec, interface * ifp); extern void clear_diff_address(list l, list n); extern void clear_diff_saddresses(void); diff --git a/keepalived/include/vrrp_iproute.h b/keepalived/include/vrrp_iproute.h index a2c11c36d..7f46463f6 100644 --- a/keepalived/include/vrrp_iproute.h +++ b/keepalived/include/vrrp_iproute.h @@ -5,7 +5,7 @@ * * Part: vrrp_iproute.c include file. * - * Version: $Id: vrrp_iproute.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_iproute.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/vrrp_ipsecah.h b/keepalived/include/vrrp_ipsecah.h index cb720427c..f534e9973 100644 --- a/keepalived/include/vrrp_ipsecah.h +++ b/keepalived/include/vrrp_ipsecah.h @@ -5,7 +5,7 @@ * * Part: vrrp_ipsecah.c include file. * - * Version: $Id: vrrp_ipsecah.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_ipsecah.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/vrrp_netlink.h b/keepalived/include/vrrp_netlink.h index cef19b27a..a5232c4ba 100644 --- a/keepalived/include/vrrp_netlink.h +++ b/keepalived/include/vrrp_netlink.h @@ -5,7 +5,7 @@ * * Part: vrrp_netlink.c include file. * - * Version: $Id: vrrp_netlink.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_netlink.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -35,6 +35,9 @@ #include #include +/* local includes */ +#include "timer.h" + /* types definitions */ struct nl_handle { int fd; @@ -43,7 +46,7 @@ struct nl_handle { }; /* Define types */ -#define NETLINK_TIMER 30 +#define NETLINK_TIMER (30 * TIMER_HZ) /* Our global netlink handler */ struct nl_handle nl_kernel; /* Kernel reflection channel */ diff --git a/keepalived/include/vrrp_notify.h b/keepalived/include/vrrp_notify.h index b6844e42a..2d45530f0 100644 --- a/keepalived/include/vrrp_notify.h +++ b/keepalived/include/vrrp_notify.h @@ -6,7 +6,7 @@ * * Part: vrrp_notify.c include file. * - * Version: $Id: vrrp_notify.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_notify.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/vrrp_parser.h b/keepalived/include/vrrp_parser.h index e6e4d831c..2c13f179c 100644 --- a/keepalived/include/vrrp_parser.h +++ b/keepalived/include/vrrp_parser.h @@ -5,7 +5,7 @@ * * Part: vrrp_parser.c include file. * - * Version: $Id: vrrp_parser.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_parser.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/vrrp_scheduler.h b/keepalived/include/vrrp_scheduler.h index c0fdca24c..178842ae4 100644 --- a/keepalived/include/vrrp_scheduler.h +++ b/keepalived/include/vrrp_scheduler.h @@ -5,7 +5,7 @@ * * Part: vrrp_scheduler.c include file. * - * Version: $Id: vrrp_scheduler.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_scheduler.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/include/vrrp_sync.h b/keepalived/include/vrrp_sync.h index c9216815c..dd265dbde 100644 --- a/keepalived/include/vrrp_sync.h +++ b/keepalived/include/vrrp_sync.h @@ -5,7 +5,7 @@ * * Part: vrrp_sync.c include file. * - * Version: $Id: vrrp_sync.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_sync.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -44,6 +44,7 @@ /* extern prototypes */ extern void vrrp_init_instance_sands(vrrp_rt *); +extern void vrrp_sync_smtp_notifier(vrrp_sgroup *); extern void vrrp_sync_set_group(vrrp_sgroup *); extern int vrrp_sync_group_up(vrrp_sgroup *); extern int vrrp_sync_leave_fault(vrrp_rt *); diff --git a/keepalived/include/vrrp_track.h b/keepalived/include/vrrp_track.h index 4e59e731b..8067f2a9c 100644 --- a/keepalived/include/vrrp_track.h +++ b/keepalived/include/vrrp_track.h @@ -5,7 +5,7 @@ * * Part: vrrp_track.c include file. * - * Version: $Id: vrrp_track.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_track.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/vrrp/vrrp.c b/keepalived/vrrp/vrrp.c index a0da6f00c..603649874 100644 --- a/keepalived/vrrp/vrrp.c +++ b/keepalived/vrrp/vrrp.c @@ -8,7 +8,7 @@ * master fails, a backup server takes over. * The original implementation has been made by jerome etienne. * - * Version: $Id: vrrp.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/vrrp/vrrp_arp.c b/keepalived/vrrp/vrrp_arp.c index 899115c86..2505e063f 100644 --- a/keepalived/vrrp/vrrp_arp.c +++ b/keepalived/vrrp/vrrp_arp.c @@ -5,7 +5,7 @@ * * Part: ARP primitives. * - * Version: $Id: vrrp_arp.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_arp.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/vrrp/vrrp_daemon.c b/keepalived/vrrp/vrrp_daemon.c index e39b2dab2..e07c013a9 100644 --- a/keepalived/vrrp/vrrp_daemon.c +++ b/keepalived/vrrp/vrrp_daemon.c @@ -5,7 +5,7 @@ * * Part: VRRP child process handling. * - * Version: $Id: vrrp_daemon.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_daemon.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -235,7 +235,7 @@ start_vrrp_child(void) , strerror(errno)); return -1; } else if (pid) { - int poll_delay = (wdog_delay_vrrp) ? wdog_delay_vrrp : WATCHDOG_DELAY; + long poll_delay = (wdog_delay_vrrp) ? wdog_delay_vrrp : WATCHDOG_DELAY; vrrp_child = pid; syslog(LOG_INFO, "Starting VRRP child process, pid=%d" , pid); diff --git a/keepalived/vrrp/vrrp_data.c b/keepalived/vrrp/vrrp_data.c index aac721dab..d462e31af 100644 --- a/keepalived/vrrp/vrrp_data.c +++ b/keepalived/vrrp/vrrp_data.c @@ -5,7 +5,7 @@ * * Part: Dynamic data structure definition. * - * Version: $Id: vrrp_data.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_data.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -131,7 +131,8 @@ dump_vrrp(void *data) syslog(LOG_INFO, " Runing LVS sync daemon on interface = %s", vrrp->lvs_syncd_if); if (vrrp->garp_delay) - syslog(LOG_INFO, " Gratuitous ARP delay = %d", vrrp->garp_delay); + syslog(LOG_INFO, " Gratuitous ARP delay = %d", + vrrp->garp_delay/TIMER_HZ); syslog(LOG_INFO, " Virtual Router ID = %d", vrrp->vrid); syslog(LOG_INFO, " Priority = %d", vrrp->priority); syslog(LOG_INFO, " Advert interval = %dsec", @@ -185,7 +186,7 @@ alloc_vrrp_sync_group(char *gname) /* Allocate new VRRP group structure */ new = (vrrp_sgroup *) MALLOC(sizeof (vrrp_sgroup)); new->gname = (char *) MALLOC(size + 1); - new->state = VRRP_STATE_BACK; + new->state = VRRP_STATE_INIT; memcpy(new->gname, gname, size); list_add(vrrp_data->vrrp_sync_group, new); diff --git a/keepalived/vrrp/vrrp_if.c b/keepalived/vrrp/vrrp_if.c index dd45bf96b..39d62189a 100644 --- a/keepalived/vrrp/vrrp_if.c +++ b/keepalived/vrrp/vrrp_if.c @@ -5,7 +5,7 @@ * * Part: Interfaces manipulation. * - * Version: $Id: vrrp_if.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_if.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/vrrp/vrrp_index.c b/keepalived/vrrp/vrrp_index.c index 7219e863e..0eb93bfa3 100644 --- a/keepalived/vrrp/vrrp_index.c +++ b/keepalived/vrrp/vrrp_index.c @@ -5,7 +5,7 @@ * * Part: VRRP instance index table. * - * Version: $Id: vrrp_index.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_index.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/vrrp/vrrp_ipaddress.c b/keepalived/vrrp/vrrp_ipaddress.c index d6326007c..95869f8df 100644 --- a/keepalived/vrrp/vrrp_ipaddress.c +++ b/keepalived/vrrp/vrrp_ipaddress.c @@ -5,7 +5,7 @@ * * Part: NETLINK IPv4 address manipulation. * - * Version: $Id: vrrp_ipaddress.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_ipaddress.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -54,6 +54,9 @@ netlink_address_ipv4(ip_address *ipaddr, int cmd) req.ifa.ifa_scope = ipaddr->scope; req.ifa.ifa_prefixlen = ipaddr->mask; addattr_l(&req.n, sizeof (req), IFA_LOCAL, &ipaddr->addr, sizeof (ipaddr->addr)); + if (ipaddr->broadcast) + addattr_l(&req.n, sizeof (req), IFA_BROADCAST, + &ipaddr->broadcast, sizeof (ipaddr->broadcast)); if (netlink_talk(&nl_cmd, &req.n) < 0) status = -1; @@ -93,9 +96,10 @@ void dump_ipaddress(void *data) { ip_address *ip_addr = data; - syslog(LOG_INFO, " %s/%d dev %s scope %s" + syslog(LOG_INFO, " %s/%d brd %s dev %s scope %s" , inet_ntop2(ip_addr->addr) , ip_addr->mask + , inet_ntop2(ip_addr->broadcast) , IF_NAME(if_get_by_ifindex(ip_addr->ifindex)) , netlink_scope_n2a(ip_addr->scope)); } @@ -126,6 +130,8 @@ alloc_ipaddress(list ip_list, vector strvec, interface *ifp) new->ifindex = IF_INDEX(new->ifp); } else if (!strcmp(str, "scope")) { new->scope = netlink_scope_a2n(VECTOR_SLOT(strvec, ++i)); + } else if (!strcmp(str, "broadcast") || !strcmp(str, "brd")) { + inet_ston(VECTOR_SLOT(strvec, ++i), &new->broadcast); } else { if (inet_ston(VECTOR_SLOT(strvec, i), &ipaddr)) { inet_ston(VECTOR_SLOT(strvec, i), &new->addr); diff --git a/keepalived/vrrp/vrrp_iproute.c b/keepalived/vrrp/vrrp_iproute.c index 703804400..98859e9be 100644 --- a/keepalived/vrrp/vrrp_iproute.c +++ b/keepalived/vrrp/vrrp_iproute.c @@ -5,7 +5,7 @@ * * Part: NETLINK IPv4 routes manipulation. * - * Version: $Id: vrrp_iproute.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_iproute.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/vrrp/vrrp_ipsecah.c b/keepalived/vrrp/vrrp_ipsecah.c index ebbb2abec..3c4579e44 100644 --- a/keepalived/vrrp/vrrp_ipsecah.c +++ b/keepalived/vrrp/vrrp_ipsecah.c @@ -7,7 +7,7 @@ * authentication data encryption using HMAC MD5 according to * RFCs 2085 & 2104. * - * Version: $Id: vrrp_ipsecah.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_ipsecah.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/vrrp/vrrp_netlink.c b/keepalived/vrrp/vrrp_netlink.c index 23e255fc1..2dab1d659 100644 --- a/keepalived/vrrp/vrrp_netlink.c +++ b/keepalived/vrrp/vrrp_netlink.c @@ -5,7 +5,7 @@ * * Part: NETLINK kernel command channel. * - * Version: $Id: vrrp_netlink.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_netlink.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/keepalived/vrrp/vrrp_notify.c b/keepalived/vrrp/vrrp_notify.c index c6d977657..2701c807a 100644 --- a/keepalived/vrrp/vrrp_notify.c +++ b/keepalived/vrrp/vrrp_notify.c @@ -5,7 +5,7 @@ * * Part: VRRP state transition notification scripts handling. * - * Version: $Id: vrrp_notify.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_notify.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -111,6 +111,10 @@ script_open(char *script) static int notify_script_exec(char* script, char *type, int state_num, char* name) { + char *state = "{UNKNOWN}"; + char *command_line = NULL; + int size = 0; + /* * Determine the length of the buffer that we'll need to generate the command * to run: @@ -133,20 +137,19 @@ notify_script_exec(char* script, char *type, int state_num, char* name) * * strlen(script) + strlen(type) + strlen(state) + strlen(name) + 8 */ - - char *state = "{UNKNOWN}"; switch (state_num) { case VRRP_STATE_MAST : state = "MASTER" ; break; case VRRP_STATE_BACK : state = "BACKUP" ; break; case VRRP_STATE_FAULT : state = "FAULT" ; break; } - int size = (strlen(script) + strlen(type) + strlen(state) + strlen(name) + 8); - char *command_line = MALLOC(size); + size = strlen(script) + strlen(type) + strlen(state) + strlen(name) + 8; + command_line = MALLOC(size); if (!command_line) return 0; /* Launch the script */ + snprintf(command_line, size, "\"%s\" %s \"%s\" %s",script, type, name, state); notify_exec(command_line); FREE(command_line); return 1; diff --git a/keepalived/vrrp/vrrp_parser.c b/keepalived/vrrp/vrrp_parser.c index 1b7b1ba9f..9ea1c67fd 100644 --- a/keepalived/vrrp/vrrp_parser.c +++ b/keepalived/vrrp/vrrp_parser.c @@ -7,7 +7,7 @@ * data structure representation the conf file representing * the loadbalanced server pool. * - * Version: $Id: vrrp_parser.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_parser.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -242,7 +242,7 @@ static void vrrp_garp_delay_handler(vector strvec) { vrrp_rt *vrrp = LIST_TAIL_DATA(vrrp_data->vrrp); - vrrp->garp_delay = atoi(VECTOR_SLOT(strvec, 1)); + vrrp->garp_delay = atoi(VECTOR_SLOT(strvec, 1)) * TIMER_HZ; } static void vrrp_auth_type_handler(vector strvec) diff --git a/keepalived/vrrp/vrrp_scheduler.c b/keepalived/vrrp/vrrp_scheduler.c index 224bfc24a..35b86bb06 100644 --- a/keepalived/vrrp/vrrp_scheduler.c +++ b/keepalived/vrrp/vrrp_scheduler.c @@ -5,7 +5,7 @@ * * Part: Sheduling framework for vrrp code. * - * Version: $Id: vrrp_scheduler.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_scheduler.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -178,6 +178,7 @@ static void vrrp_init_state(list l) { vrrp_rt *vrrp; + vrrp_sgroup *vgroup; element e; for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) { @@ -203,7 +204,20 @@ vrrp_init_state(list l) #endif syslog(LOG_INFO, "VRRP_Instance(%s) Entering BACKUP STATE", vrrp->iname); + + /* Set BACKUP state */ vrrp->state = VRRP_STATE_BACK; + vrrp_smtp_notifier(vrrp); + notify_instance_exec(vrrp, VRRP_STATE_BACK); + + /* Init group if needed */ + if ((vgroup = vrrp->sync)) { + if (GROUP_STATE(vgroup) != VRRP_STATE_BACK) { + vgroup->state = VRRP_STATE_BACK; + vrrp_sync_smtp_notifier(vgroup); + notify_group_exec(vgroup, VRRP_STATE_BACK); + } + } } } } @@ -788,7 +802,6 @@ vrrp_read_dispatcher_thread(thread * thread) /* register next dispatcher thread */ vrrp_timer = vrrp_timer_fd(fd); - TIMER_MICRO_ADJUST(vrrp_timer); if (fd == -1) thread_add_timer(thread->master, vrrp_read_dispatcher_thread, (int *)THREAD_TIMER, vrrp_timer); diff --git a/keepalived/vrrp/vrrp_sync.c b/keepalived/vrrp/vrrp_sync.c index 6ed798b13..981e0e8f2 100644 --- a/keepalived/vrrp/vrrp_sync.c +++ b/keepalived/vrrp/vrrp_sync.c @@ -5,7 +5,7 @@ * * Part: VRRP synchronization framework. * - * Version: $Id: vrrp_sync.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_sync.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -38,35 +38,16 @@ vrrp_init_instance_sands(vrrp_rt * vrrp) { TIMEVAL timer = timer_now(); - /* - * We only make timer auto-recalibration while being in - * master state. Other state are transtions so recalibration - * is not needed. Here we estimate the VRRP advert time - * handling and substract it to new computed timer. - * We just take care to the usec sub timer and not sec one - * to not conflict scheduling decision. - */ - if (vrrp->state == VRRP_STATE_MAST) { - long usec; - usec = timer.tv_usec - vrrp->sands.tv_usec; - vrrp->sands.tv_sec = timer.tv_sec + vrrp->adver_int / TIMER_HZ; - vrrp->sands.tv_usec = timer.tv_usec; - if (usec > 0) - vrrp->sands.tv_usec -= usec; - return; - } - - if (vrrp->state == VRRP_STATE_GOTO_MASTER || + if (vrrp->state == VRRP_STATE_MAST || + vrrp->state == VRRP_STATE_GOTO_MASTER || vrrp->state == VRRP_STATE_GOTO_FAULT) { vrrp->sands.tv_sec = timer.tv_sec + vrrp->adver_int / TIMER_HZ; vrrp->sands.tv_usec = timer.tv_usec; return; } - if (vrrp->state == VRRP_STATE_BACK || vrrp->state == VRRP_STATE_FAULT) { - vrrp->sands.tv_sec = timer.tv_sec + vrrp->ms_down_timer / TIMER_HZ; - vrrp->sands.tv_usec = timer.tv_usec + vrrp->ms_down_timer % TIMER_HZ; - } + if (vrrp->state == VRRP_STATE_BACK || vrrp->state == VRRP_STATE_FAULT) + vrrp->sands = timer_add_long(timer, vrrp->ms_down_timer); } /* Instance name lookup */ @@ -129,7 +110,7 @@ vrrp_sync_group_up(vrrp_sgroup * vgroup) } /* SMTP alert group notifier */ -static void +void vrrp_sync_smtp_notifier(vrrp_sgroup *vgroup) { if (vgroup->smtp_alert) { @@ -172,7 +153,7 @@ vrrp_sync_master_election(vrrp_rt * vrrp) return; syslog(LOG_INFO, "VRRP_Group(%s) Transition to MASTER state", - GROUP_NAME(vrrp->sync)); + GROUP_NAME(vgroup)); /* Perform sync index */ for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) { @@ -196,13 +177,16 @@ vrrp_sync_backup(vrrp_rt * vrrp) list l = vgroup->index; element e; + if (GROUP_STATE(vgroup) == VRRP_STATE_BACK) + return; + syslog(LOG_INFO, "VRRP_Group(%s) Syncing instances to BACKUP state", GROUP_NAME(vgroup)); /* Perform sync index */ for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) { isync = ELEMENT_DATA(e); - if (isync != vrrp) { + if (isync != vrrp && isync->state != VRRP_STATE_BACK) { isync->wantstate = VRRP_STATE_BACK; vrrp_state_leave_master(isync); vrrp_init_instance_sands(isync); @@ -221,18 +205,18 @@ vrrp_sync_master(vrrp_rt * vrrp) list l = vgroup->index; element e; - if (GROUP_STATE(vrrp->sync) == VRRP_STATE_MAST) + if (GROUP_STATE(vgroup) == VRRP_STATE_MAST) return; syslog(LOG_INFO, "VRRP_Group(%s) Syncing instances to MASTER state", - GROUP_NAME(vrrp->sync)); + GROUP_NAME(vgroup)); /* Perform sync index */ for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) { isync = ELEMENT_DATA(e); /* Send the higher priority advert on all synced instances */ - if (isync != vrrp) { + if (isync != vrrp && isync->state != VRRP_STATE_MAST) { isync->wantstate = VRRP_STATE_MAST; vrrp_state_goto_master(isync); vrrp_init_instance_sands(isync); @@ -251,11 +235,11 @@ vrrp_sync_fault(vrrp_rt * vrrp) list l = vgroup->index; element e; - if (GROUP_STATE(vrrp->sync) == VRRP_STATE_FAULT) + if (GROUP_STATE(vgroup) == VRRP_STATE_FAULT) return; syslog(LOG_INFO, "VRRP_Group(%s) Syncing instances to FAULT state", - GROUP_NAME(vrrp->sync)); + GROUP_NAME(vgroup)); /* Perform sync index */ for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) { @@ -267,7 +251,7 @@ vrrp_sync_fault(vrrp_rt * vrrp) * => by default ms_down_timer is set to 3secs. * => Takeover will be less than 3secs ! */ - if (isync != vrrp) { + if (isync != vrrp && isync->state != VRRP_STATE_FAULT) { if (isync->state == VRRP_STATE_MAST) isync->wantstate = VRRP_STATE_GOTO_FAULT; if (isync->state == VRRP_STATE_BACK) diff --git a/keepalived/vrrp/vrrp_track.c b/keepalived/vrrp/vrrp_track.c index 9925944f5..fc531eff0 100644 --- a/keepalived/vrrp/vrrp_track.c +++ b/keepalived/vrrp/vrrp_track.c @@ -5,7 +5,7 @@ * * Part: Interface tracking framework. * - * Version: $Id: vrrp_track.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vrrp_track.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/lib/html.c b/lib/html.c index b157def60..1d4456819 100644 --- a/lib/html.c +++ b/lib/html.c @@ -5,7 +5,7 @@ * * Part: HTML stream parser utility functions. * - * Version: $Id: html.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: html.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Authors: Alexandre Cassen, * diff --git a/lib/html.h b/lib/html.h index f28827d4d..2b24dbbcc 100644 --- a/lib/html.h +++ b/lib/html.h @@ -5,7 +5,7 @@ * * Part: parser.c include file. * - * Version: $Id: html.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: html.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Authors: Alexandre Cassen, * diff --git a/lib/list.c b/lib/list.c index 662ad98d3..ef299edf9 100644 --- a/lib/list.c +++ b/lib/list.c @@ -5,7 +5,7 @@ * * Part: List structure manipulation. * - * Version: $Id: list.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: list.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/lib/list.h b/lib/list.h index a3a579ecc..a82d6485f 100644 --- a/lib/list.h +++ b/lib/list.h @@ -5,7 +5,7 @@ * * Part: list.c include file. * - * Version: $Id: list.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: list.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/lib/memory.c b/lib/memory.c index 18ed8800f..cdc17c006 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -6,7 +6,7 @@ * Part: Memory management framework. This framework is used to * find any memory leak. * - * Version: $Id: memory.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: memory.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Authors: Alexandre Cassen, * Jan Holmberg, diff --git a/lib/memory.h b/lib/memory.h index 606a1832d..a3a31d43e 100644 --- a/lib/memory.h +++ b/lib/memory.h @@ -5,7 +5,7 @@ * * Part: memory.c include file. * - * Version: $Id: memory.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: memory.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Authors: Alexandre Cassen, * Jan Holmberg, diff --git a/lib/notify.c b/lib/notify.c index 7393cd7cc..ee6a0e39d 100644 --- a/lib/notify.c +++ b/lib/notify.c @@ -5,7 +5,7 @@ * * Part: Forked system call to launch an extra script. * - * Version: $Id: notify.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: notify.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/lib/notify.h b/lib/notify.h index 36c194510..44ac8357a 100644 --- a/lib/notify.h +++ b/lib/notify.h @@ -5,7 +5,7 @@ * * Part: notify.c include file. * - * Version: $Id: notify.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: notify.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/lib/parser.c b/lib/parser.c index 25af2ed12..7a8986c1d 100644 --- a/lib/parser.c +++ b/lib/parser.c @@ -7,7 +7,7 @@ * data structure representation the conf file representing * the loadbalanced server pool. * - * Version: $Id: parser.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: parser.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/lib/parser.h b/lib/parser.h index 9cd04ed53..ef2be2da0 100644 --- a/lib/parser.h +++ b/lib/parser.h @@ -5,7 +5,7 @@ * * Part: cfreader.c include file. * - * Version: $Id: parser.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: parser.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/lib/scheduler.c b/lib/scheduler.c index d7c71e5cb..edb4a5a6b 100644 --- a/lib/scheduler.c +++ b/lib/scheduler.c @@ -7,7 +7,7 @@ * the thread management routine (thread.c) present in the * very nice zebra project (http://www.zebra.org). * - * Version: $Id: scheduler.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: scheduler.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -216,7 +216,6 @@ thread_add_read(thread_master * m, int (*func) (thread *) , void *arg, int fd, long timer) { thread *thread; - TIMEVAL time_now; assert(m != NULL); @@ -235,14 +234,7 @@ thread_add_read(thread_master * m, int (*func) (thread *) thread->u.fd = fd; /* Compute read timeout value */ - time_now = timer_now(); - if (timer >= TIMER_MAX_SEC) { - time_now.tv_sec += timer / TIMER_HZ; - time_now.tv_usec += timer % TIMER_HZ; - } else - time_now.tv_sec += timer; - - thread->sands = time_now; + thread->sands = timer_add_long(timer_now(), timer); /* Sort the thread. */ thread_list_add_timeval(&m->read, thread); @@ -256,7 +248,6 @@ thread_add_write(thread_master * m, int (*func) (thread *) , void *arg, int fd, long timer) { thread *thread; - TIMEVAL time_now; assert(m != NULL); @@ -275,14 +266,7 @@ thread_add_write(thread_master * m, int (*func) (thread *) thread->u.fd = fd; /* Compute write timeout value */ - time_now = timer_now(); - if (timer >= TIMER_MAX_SEC) { - time_now.tv_sec += timer / TIMER_HZ; - time_now.tv_usec += timer % TIMER_HZ; - } else - time_now.tv_sec += timer; - - thread->sands = time_now; + thread->sands = timer_add_long(timer_now(), timer); /* Sort the thread. */ thread_list_add_timeval(&m->write, thread); @@ -296,7 +280,6 @@ thread_add_timer(thread_master * m, int (*func) (thread *) , void *arg, long timer) { thread *thread; - TIMEVAL time_now; assert(m != NULL); @@ -308,14 +291,7 @@ thread_add_timer(thread_master * m, int (*func) (thread *) thread->arg = arg; /* Do we need jitter here? */ - time_now = timer_now(); - if (timer >= TIMER_MAX_SEC) { - time_now.tv_sec += timer / TIMER_HZ; - time_now.tv_usec += timer % TIMER_HZ; - } else - time_now.tv_sec += timer; - - thread->sands = time_now; + thread->sands = timer_add_long(timer_now(), timer); /* Sort by timeval. */ thread_list_add_timeval(&m->timer, thread); @@ -329,7 +305,6 @@ thread_add_child(thread_master * m, int (*func) (thread *) , void * arg, pid_t pid, long timer) { thread *thread; - TIMEVAL time_now; assert(m != NULL); @@ -343,14 +318,7 @@ thread_add_child(thread_master * m, int (*func) (thread *) thread->u.c.status = 0; /* Compute write timeout value */ - time_now = timer_now(); - if (timer >= TIMER_MAX_SEC) { - time_now.tv_sec += timer / TIMER_HZ; - time_now.tv_usec += timer % TIMER_HZ; - } else - time_now.tv_sec += timer; - - thread->sands = time_now; + thread->sands = timer_add_long(timer_now(), timer); /* Sort by timeval. */ thread_list_add_timeval(&m->child, thread); @@ -488,6 +456,14 @@ thread_compute_timer(thread_master * m, TIMEVAL * timer_wait) timer_min = m->read.head->sands; } + if (m->child.head) { + if (!TIMER_ISNULL(timer_min)) { + if (timer_cmp(m->child.head->sands, timer_min) <= 0) + timer_min = m->child.head->sands; + } else + timer_min = m->child.head->sands; + } + if (!TIMER_ISNULL(timer_min)) { timer_min = timer_sub(timer_min, time_now); if (timer_min.tv_sec < 0) { diff --git a/lib/scheduler.h b/lib/scheduler.h index 7902046ed..ebd6ec94c 100644 --- a/lib/scheduler.h +++ b/lib/scheduler.h @@ -5,7 +5,7 @@ * * Part: scheduler.c include file. * - * Version: $Id: scheduler.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: scheduler.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -92,7 +92,7 @@ typedef struct _thread_master { /* MICRO SEC def */ -#define BOOTSTRAP_DELAY 1 +#define BOOTSTRAP_DELAY TIMER_HZ /* Macros. */ #define THREAD_ARG(X) ((X)->arg) diff --git a/lib/timer.c b/lib/timer.c index ab0e609f0..da6f5ea1a 100644 --- a/lib/timer.c +++ b/lib/timer.c @@ -5,7 +5,7 @@ * * Part: Timer manipulations. * - * Version: $Id: timer.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: timer.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -71,6 +71,24 @@ timer_sub(TIMEVAL a, TIMEVAL b) return ret; } +/* timer add */ +TIMEVAL +timer_add_long(TIMEVAL a, long b) +{ + TIMEVAL ret; + + TIMER_RESET(ret); + ret.tv_usec = a.tv_usec + b % TIMER_HZ; + ret.tv_sec = a.tv_sec + b / TIMER_HZ; + + if (ret.tv_usec >= TIMER_HZ) { + ret.tv_sec++; + ret.tv_usec -= TIMER_HZ; + } + + return ret; +} + /* current time */ TIMEVAL timer_now(void) diff --git a/lib/timer.h b/lib/timer.h index 8397c27a4..eea0bde1a 100644 --- a/lib/timer.h +++ b/lib/timer.h @@ -5,7 +5,7 @@ * * Part: timer.c include file. * - * Version: $Id: timer.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: timer.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -33,15 +33,16 @@ typedef struct timeval TIMEVAL; #define TIMER_HZ 1000000 #define TIMER_MAX_SEC 1000 #define TIMER_SEC(T) ((T).tv_sec) +#define TIMER_LONG(T) ((T).tv_sec * TIMER_HZ + (T).tv_usec) #define TIMER_ISNULL(T) ((T).tv_sec == 0 && (T).tv_usec == 0) #define TIMER_RESET(T) (memset(&(T), 0, sizeof(struct timeval))) -#define TIMER_MICRO_ADJUST(T) ((T) = ((T) < TIMER_MAX_SEC)?TIMER_MAX_SEC:(T)) /* prototypes */ extern TIMEVAL timer_now(void); extern TIMEVAL timer_dup(TIMEVAL b); extern int timer_cmp(TIMEVAL a, TIMEVAL b); extern TIMEVAL timer_sub(TIMEVAL a, TIMEVAL b); +extern TIMEVAL timer_add_long(TIMEVAL a, long b); extern TIMEVAL timer_sub_now(TIMEVAL a); extern void timer_dump(TIMEVAL a); extern unsigned long timer_tol(TIMEVAL a); diff --git a/lib/utils.c b/lib/utils.c index 2161465f4..72374687e 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -5,7 +5,7 @@ * * Part: General program utils. * - * Version: $Id: utils.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: utils.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/lib/utils.h b/lib/utils.h index 92e0a347f..3a5c96215 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -5,7 +5,7 @@ * * Part: utils.h include file. * - * Version: $Id: utils.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: utils.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/lib/vector.c b/lib/vector.c index 669b78fca..ab28aa4c9 100644 --- a/lib/vector.c +++ b/lib/vector.c @@ -5,7 +5,7 @@ * * Part: Vector structure manipulation. * - * Version: $Id: vector.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vector.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/lib/vector.h b/lib/vector.h index d540da98e..5f5f34f99 100644 --- a/lib/vector.h +++ b/lib/vector.h @@ -5,7 +5,7 @@ * * Part: vector.c include file. * - * Version: $Id: vector.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: vector.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/lib/watchdog.c b/lib/watchdog.c index 2f57ee4e0..8b67d0d6f 100644 --- a/lib/watchdog.c +++ b/lib/watchdog.c @@ -5,7 +5,7 @@ * * Part: Software watchdog framework. * - * Version: $Id: watchdog.c,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: watchdog.c,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * diff --git a/lib/watchdog.h b/lib/watchdog.h index 7e14f9876..bb4f13203 100644 --- a/lib/watchdog.h +++ b/lib/watchdog.h @@ -5,7 +5,7 @@ * * Part: watchdog.c include file. * - * Version: $Id: watchdog.h,v 1.1.2 2003/09/08 01:18:41 acassen Exp $ + * Version: $Id: watchdog.h,v 1.1.3 2003/09/29 02:37:13 acassen Exp $ * * Author: Alexandre Cassen, * @@ -39,7 +39,7 @@ typedef struct _wdog_data { /* watchdog definition */ #define WATCHDOG_TIMER 30 -#define WATCHDOG_DELAY 5 +#define WATCHDOG_DELAY (5 * TIMER_HZ) #define WATCHDOG_STRING "hello" #define WDOG_READ_BUFSIZ 32