|
Packit |
c22fc9 |
/*
|
|
Packit |
c22fc9 |
* Soft: Keepalived is a failover program for the LVS project
|
|
Packit |
c22fc9 |
* <www.linuxvirtualserver.org>. It monitor & manipulate
|
|
Packit |
c22fc9 |
* a loadbalanced server pool using multi-layer checks.
|
|
Packit |
c22fc9 |
*
|
|
Packit |
c22fc9 |
* Part: BFD event handling
|
|
Packit |
c22fc9 |
*
|
|
Packit |
c22fc9 |
* Author: Ilya Voronin, <ivoronin@gmail.com>
|
|
Packit |
c22fc9 |
*
|
|
Packit |
c22fc9 |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
c22fc9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
c22fc9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
Packit |
c22fc9 |
* See the GNU General Public License for more details.
|
|
Packit |
c22fc9 |
*
|
|
Packit |
c22fc9 |
* This program is free software; you can redistribute it and/or
|
|
Packit |
c22fc9 |
* modify it under the terms of the GNU General Public License
|
|
Packit |
c22fc9 |
* as published by the Free Software Foundation; either version
|
|
Packit |
c22fc9 |
* 2 of the License, or (at your option) any later version.
|
|
Packit |
c22fc9 |
*
|
|
Packit |
c22fc9 |
* Copyright (C) 2015-2017 Alexandre Cassen, <acassen@gmail.com>
|
|
Packit |
c22fc9 |
*/
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
#include "config.h"
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
#include <assert.h>
|
|
Packit |
c22fc9 |
#include <unistd.h>
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
#include "bfd.h"
|
|
Packit |
c22fc9 |
#include "bfd_event.h"
|
|
Packit |
c22fc9 |
#include "bfd_daemon.h"
|
|
Packit |
c22fc9 |
#include "logger.h"
|
|
Packit |
c22fc9 |
#include "main.h"
|
|
Packit |
c22fc9 |
#include "memory.h"
|
|
Packit |
c22fc9 |
#include "bitops.h"
|
|
Packit |
c22fc9 |
#include "utils.h"
|
|
Packit |
c22fc9 |
#include "global_data.h"
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
void
|
|
Packit |
c22fc9 |
bfd_event_send(bfd_t *bfd)
|
|
Packit |
c22fc9 |
{
|
|
Packit |
c22fc9 |
bfd_event_t evt;
|
|
Packit |
c22fc9 |
int ret;
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
assert(bfd);
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
/* If there is no VRRP process running, don't write to the pipe */
|
|
Packit |
c22fc9 |
if (true
|
|
Packit |
c22fc9 |
#ifdef _WITH_VRRP_
|
|
Packit |
c22fc9 |
&& !running_vrrp()
|
|
Packit |
c22fc9 |
#endif
|
|
Packit |
c22fc9 |
#ifdef _WITH_LVS_
|
|
Packit |
c22fc9 |
&& !running_checker()
|
|
Packit |
c22fc9 |
#endif
|
|
Packit |
c22fc9 |
)
|
|
Packit |
c22fc9 |
return;
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
memset(&evt, 0, sizeof evt);
|
|
Packit |
c22fc9 |
strcpy(evt.iname, bfd->iname);
|
|
Packit |
c22fc9 |
evt.state = bfd->local_state == BFD_STATE_UP ? BFD_STATE_UP : BFD_STATE_DOWN;
|
|
Packit |
c22fc9 |
evt.sent_time = timer_now();
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
#ifdef _WITH_VRRP_
|
|
Packit |
c22fc9 |
if (bfd->vrrp) {
|
|
Packit |
c22fc9 |
ret = write(bfd_vrrp_event_pipe[1], &evt, sizeof evt);
|
|
Packit |
c22fc9 |
if (ret == -1 && __test_bit(LOG_DETAIL_BIT, &debug))
|
|
Packit |
c22fc9 |
log_message(LOG_ERR, "BFD_Instance(%s) vrrp pipe write() error %m",
|
|
Packit |
c22fc9 |
bfd->iname);
|
|
Packit |
c22fc9 |
}
|
|
Packit |
c22fc9 |
#endif
|
|
Packit |
c22fc9 |
|
|
Packit |
c22fc9 |
#ifdef _WITH_LVS_
|
|
Packit |
c22fc9 |
if (bfd->checker) {
|
|
Packit |
c22fc9 |
ret = write(bfd_checker_event_pipe[1], &evt, sizeof evt);
|
|
Packit |
c22fc9 |
if (ret == -1 && __test_bit(LOG_DETAIL_BIT, &debug))
|
|
Packit |
c22fc9 |
log_message(LOG_ERR, "BFD_Instance(%s) checker pipe write() error %m",
|
|
Packit |
c22fc9 |
bfd->iname);
|
|
Packit |
c22fc9 |
}
|
|
Packit |
c22fc9 |
#endif
|
|
Packit |
c22fc9 |
}
|