Skip to content

Commit

Permalink
Merge pull request #735 from pqarmitage/beta
Browse files Browse the repository at this point in the history
Add IPVS checker BFD_CHECK
  • Loading branch information
pqarmitage committed Jan 4, 2018
2 parents 1f46d72 + dc52bff commit 9014b68
Show file tree
Hide file tree
Showing 32 changed files with 899 additions and 221 deletions.
9 changes: 7 additions & 2 deletions doc/keepalived.conf.SYNOPSIS
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ bfd_instance <STRING> {
max_hops <INTEGER 0..255> # maximum reduction of ttl/hoplimit in received packet (default 0)
# (255 disables hop count checking)
weight # Default tracking weight
vrrp|checker # Only notify vrrp or checker process. Default is notify both.
}

2.4. VRRP synchronization group
Expand Down Expand Up @@ -959,9 +960,10 @@ virtual_server group <STRING> { # VS group declaration
# virtual_server virtualhost)

# healthcheckers. Can be multiple of each type
# HTTP_GET|SSL_GET|TCP_CHECK|SMTP_CHECK|DNS_CHECK|MISC_CHECK
# HTTP_GET|SSL_GET|TCP_CHECK|SMTP_CHECK|DNS_CHECK|MISC_CHECK|BFD_CHECK

# All checkers have the following options, except MISC_CHECK which only has alpha onwards:
# All checkers have the following options, except MISC_CHECK which only has alpha onwards,
# and BFD_CHECK which has no standard options:
CHECKER_TYPE {
connect_ip <IP ADDRESS> # IP address to connect (default real_server address)
connect_port <PORT> # Port to connect (default real_server port)
Expand Down Expand Up @@ -1034,6 +1036,9 @@ virtual_server group <STRING> { # VS group declaration
misc_dynamic
user USERNAME [GROUPNAME] # Specify user/group to run script under
}
BFD_CHECK {
name <STRING> # the name of the bfd instance
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions doc/man/man5/keepalived.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -1102,10 +1102,11 @@ A virtual_server can be a declaration of one of
inhibit_on_failure <BOOL> # see above

# healthcheckers. Can be multiple of each type
# HTTP_GET|SSL_GET|TCP_CHECK|SMTP_CHECK|DNS_CHECK|MISC_CHECK
# HTTP_GET|SSL_GET|TCP_CHECK|SMTP_CHECK|DNS_CHECK|MISC_CHECK|BFD_CHECK

# All checkers have the following options, except MISC_CHECK
# which only has options alpha onwards:
# which only has options alpha onwards, and BFD_CHECK which has none
# of the standard options:
CHECKER_TYPE {
# ======== generic connection options
# Optional IP address to connect to.
Expand Down Expand Up @@ -1224,6 +1225,9 @@ A virtual_server can be a declaration of one of
# is used
user USERNAME [GROUPNAME]
}
BFD_CHECK {
name <STRING> # the name of the bfd instance
}
} # realserver defn
} # virtual service
.PP
Expand Down
32 changes: 25 additions & 7 deletions keepalived/bfd/bfd_daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
#include "utils.h"

/* Global variables */
int bfd_event_pipe[2] = { -1, -1};
int bfd_vrrp_event_pipe[2] = { -1, -1};
int bfd_checker_event_pipe[2] = { -1, -1};

/* Local variables */
static char *bfd_syslog_ident;
Expand Down Expand Up @@ -99,13 +100,25 @@ stop_bfd(int status)

/* Daemon init sequence */
void
open_bfd_pipe(void)
open_bfd_pipes(void)
{
/* Open BFD control pipe */
if (open_pipe(bfd_event_pipe) == -1) {
log_message(LOG_ERR, "Unable to create BFD event pipe: %m");
#ifdef _WITH_VRRP_
/* Open BFD VRRP control pipe */
if (open_pipe(bfd_vrrp_event_pipe) == -1) {
log_message(LOG_ERR, "Unable to create BFD vrrp event pipe: %m");
stop_keepalived();
return;
}
#endif

#ifdef _WITH_LVS_
/* Open BFD checker control pipe */
if (open_pipe(bfd_checker_event_pipe) == -1) {
log_message(LOG_ERR, "Unable to create BFD checker event pipe: %m");
stop_keepalived();
return;
}
#endif
}

/* Daemon init sequence */
Expand Down Expand Up @@ -265,8 +278,13 @@ start_bfd_child(void)

prog_type = PROG_TYPE_BFD;

/* Close the read end of the event notification pipe */
close(bfd_event_pipe[0]);
/* Close the read end of the event notification pipes */
#ifdef _WITH_VRRP_
close(bfd_vrrp_event_pipe[0]);
#endif
#ifdef _WITH_LVS_
close(bfd_checker_event_pipe[0]);
#endif

if ((instance_name
#if HAVE_DECL_CLONE_NEWNET
Expand Down
23 changes: 18 additions & 5 deletions keepalived/bfd/bfd_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ dump_bfd(void *data)
log_message(LOG_INFO, " Neighbor IP = %s",
inet_sockaddrtos(&bfd->nbr_addr));

if (bfd->src_addr.ss_family)
if (bfd->src_addr.ss_family != AF_UNSPEC)
log_message(LOG_INFO, " Source IP = %s",
inet_sockaddrtos(&bfd->src_addr));

Expand All @@ -104,11 +104,24 @@ dump_bfd(void *data)
bfd->local_idle_tx_intv / TIMER_HZ);
log_message(LOG_INFO, " Detection multiplier = %i",
bfd->local_detect_mult);
log_message(LOG_INFO, " %s = %d",
bfd->nbr_addr.ss_family == AF_INET ? "TTL" : "hoplimit",
bfd->ttl);
log_message(LOG_INFO, " max_hops = %d",
bfd->max_hops);
#ifdef _WITH_VRRP_
log_message(LOG_INFO, " send event to VRRP process = %s",
bfd->vrrp ? "Yes" : "No");
#endif
#ifdef _WITH_LVS_
log_message(LOG_INFO, " send event to checker process = %s",
bfd->checker ? "Yes" : "No");
#endif
}

/* Looks up bfd instance by name */
static bfd_t *
find_bfd_by_name2(char *name, bfd_data_t *data)
find_bfd_by_name2(const char *name, const bfd_data_t *data)
{
element e;
bfd_t *bfd;
Expand All @@ -130,7 +143,7 @@ find_bfd_by_name2(char *name, bfd_data_t *data)
}

bfd_t *
find_bfd_by_name(char *name)
find_bfd_by_name(const char *name)
{
return find_bfd_by_name2(name, bfd_data);
}
Expand Down Expand Up @@ -228,7 +241,7 @@ free_bfd_buffer(void)
*/
/* Looks up bfd instance by neighbor address */
bfd_t *
find_bfd_by_addr(struct sockaddr_storage *addr)
find_bfd_by_addr(const struct sockaddr_storage *addr)
{
element e;
bfd_t *bfd;
Expand All @@ -249,7 +262,7 @@ find_bfd_by_addr(struct sockaddr_storage *addr)

/* Looks up bfd instance by local discriminator */
bfd_t *
find_bfd_by_discr(uint32_t discr)
find_bfd_by_discr(const uint32_t discr)
{
element e;
bfd_t *bfd;
Expand Down
30 changes: 25 additions & 5 deletions keepalived/bfd/bfd_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,36 @@ bfd_event_send(bfd_t *bfd)
assert(bfd);

/* If there is no VRRP process running, don't write to the pipe */
if (!__test_bit(DAEMON_VRRP, &daemon_mode) || !have_vrrp_instances)
if (true
#ifdef _WITH_VRRP_
&& !(__test_bit(DAEMON_VRRP, &daemon_mode) && have_vrrp_instances)
#endif
#ifdef _WITH_LVS_
&& !(__test_bit(DAEMON_CHECKERS, &daemon_mode) && have_virtual_servers)
#endif
)
return;

memset(&evt, 0, sizeof evt);
strcpy(evt.iname, bfd->iname);
evt.state = bfd->local_state == BFD_STATE_UP ? BFD_STATE_UP : BFD_STATE_DOWN;
evt.sent_time = timer_now();

ret = write(bfd_event_pipe[1], &evt, sizeof evt);
if (ret == -1 && __test_bit(LOG_DETAIL_BIT, &debug))
log_message(LOG_ERR, "BFD_Instance(%s) write() error %m",
bfd->iname);
#ifdef _WITH_VRRP_
if (bfd->vrrp) {
ret = write(bfd_vrrp_event_pipe[1], &evt, sizeof evt);
if (ret == -1 && __test_bit(LOG_DETAIL_BIT, &debug))
log_message(LOG_ERR, "BFD_Instance(%s) vrrp pipe write() error %m",
bfd->iname);
}
#endif

#ifdef _WITH_LVS_
if (bfd->checker) {
ret = write(bfd_checker_event_pipe[1], &evt, sizeof evt);
if (ret == -1 && __test_bit(LOG_DETAIL_BIT, &debug))
log_message(LOG_ERR, "BFD_Instance(%s) checker pipe write() error %m",
bfd->iname);
}
#endif
}
Loading

0 comments on commit 9014b68

Please sign in to comment.