TSG-13912 支持对第三方设备健康检查
bfdd程序重启后, 支持将配置重新下发给bfdd程序
This commit is contained in:
@@ -14,6 +14,8 @@ struct bfd_vtysh_client {
|
|||||||
|
|
||||||
// exec after connect server
|
// exec after connect server
|
||||||
int (*pre_config)(struct bfd_vtysh_client *);
|
int (*pre_config)(struct bfd_vtysh_client *);
|
||||||
|
// recover config after connect server
|
||||||
|
int (*recover_config)(struct bfd_vtysh_client *);
|
||||||
};
|
};
|
||||||
|
|
||||||
int bfd_vtysh_connect(struct bfd_vtysh_client *client);
|
int bfd_vtysh_connect(struct bfd_vtysh_client *client);
|
||||||
|
|||||||
@@ -63,6 +63,12 @@ int bfd_vtysh_connect(struct bfd_vtysh_client *client)
|
|||||||
bfd_vtysh_close(client);
|
bfd_vtysh_close(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (client->recover_config) {
|
||||||
|
ret = client->recover_config(client);
|
||||||
|
if (ret < 0)
|
||||||
|
bfd_vtysh_close(client);
|
||||||
|
}
|
||||||
|
|
||||||
LOG_DEBUG("bfd vtysh_connect(%d): succ", client->fd);
|
LOG_DEBUG("bfd vtysh_connect(%d): succ", client->fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -71,7 +77,7 @@ int bfd_vtysh_connect(struct bfd_vtysh_client *client)
|
|||||||
// return -1 : fail
|
// return -1 : fail
|
||||||
void bfd_vtysh_close(struct bfd_vtysh_client *client)
|
void bfd_vtysh_close(struct bfd_vtysh_client *client)
|
||||||
{
|
{
|
||||||
if (client->fd >= 0) {
|
if (client->fd > 0) {
|
||||||
close(client->fd);
|
close(client->fd);
|
||||||
client->fd = -1;
|
client->fd = -1;
|
||||||
}
|
}
|
||||||
@@ -147,9 +153,6 @@ static int bfd_vtysh_cmd_exec(struct bfd_vtysh_client *client, const char *cmd,
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out_err;
|
goto out_err;
|
||||||
|
|
||||||
// if (data == NULL)
|
|
||||||
// return 0;
|
|
||||||
|
|
||||||
bufvalid = buf;
|
bufvalid = buf;
|
||||||
do {
|
do {
|
||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
@@ -277,7 +280,6 @@ int bfd_vtysh_del_dev(struct bfd_vtysh_client *client, const char *peer_addr)
|
|||||||
|
|
||||||
// return 1 : up
|
// return 1 : up
|
||||||
// return 0 : down
|
// return 0 : down
|
||||||
// return -1 : fail
|
|
||||||
int bfd_vtysh_get_dev_active(struct bfd_vtysh_client *client, char *addr)
|
int bfd_vtysh_get_dev_active(struct bfd_vtysh_client *client, char *addr)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@@ -285,6 +287,9 @@ int bfd_vtysh_get_dev_active(struct bfd_vtysh_client *client, char *addr)
|
|||||||
char cmd[256] = {0};
|
char cmd[256] = {0};
|
||||||
char stackbuf[4096];
|
char stackbuf[4096];
|
||||||
|
|
||||||
|
if (client->fd <= 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
snprintf(cmd, sizeof(cmd), "do show bfd peer %s", addr);
|
snprintf(cmd, sizeof(cmd), "do show bfd peer %s", addr);
|
||||||
ret = bfd_vtysh_cmd_exec(client, cmd, stackbuf, sizeof(stackbuf)-1);
|
ret = bfd_vtysh_cmd_exec(client, cmd, stackbuf, sizeof(stackbuf)-1);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@@ -294,7 +299,7 @@ int bfd_vtysh_get_dev_active(struct bfd_vtysh_client *client, char *addr)
|
|||||||
|
|
||||||
// ex: Status: up/Status: down
|
// ex: Status: up/Status: down
|
||||||
if ((p = strstr(stackbuf, "Status: ")) == NULL)
|
if ((p = strstr(stackbuf, "Status: ")) == NULL)
|
||||||
return -1;
|
return 0;
|
||||||
if (strncmp(p+8, "up", 2) == 0)
|
if (strncmp(p+8, "up", 2) == 0)
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -80,6 +80,22 @@ void health_check_session_init(const char *profile)
|
|||||||
health_check_session_foreach();
|
health_check_session_foreach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int health_check_session_recover_cfg(struct bfd_vtysh_client *client)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
struct session_iterm *tmp = NULL;
|
||||||
|
struct session_iterm *node = NULL;
|
||||||
|
HASH_ITER(hh1, g_handle.root_by_id, node, tmp) {
|
||||||
|
if (node->policy.method != HEALTH_CHECK_METHOD_BFD)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ret = bfd_vtysh_add_dev(client, node->policy.address, node->policy.retires, node->policy.interval_ms);
|
||||||
|
if (ret != 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void health_check_session_init_bfd_client(struct bfd_vtysh_client *client)
|
static void health_check_session_init_bfd_client(struct bfd_vtysh_client *client)
|
||||||
{
|
{
|
||||||
memset(client, 0, sizeof(*client));
|
memset(client, 0, sizeof(*client));
|
||||||
@@ -87,6 +103,14 @@ static void health_check_session_init_bfd_client(struct bfd_vtysh_client *client
|
|||||||
client->pre_config = bfd_vtysh_pre_config;
|
client->pre_config = bfd_vtysh_pre_config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void health_check_session_recover_bfd(struct bfd_vtysh_client *client)
|
||||||
|
{
|
||||||
|
memset(client, 0, sizeof(*client));
|
||||||
|
snprintf(client->path, sizeof(client->path), path);
|
||||||
|
client->pre_config = bfd_vtysh_pre_config;
|
||||||
|
client->recover_config = health_check_session_recover_cfg;
|
||||||
|
}
|
||||||
|
|
||||||
// return 0 : success
|
// return 0 : success
|
||||||
// return -1 : key exist
|
// return -1 : key exist
|
||||||
// struct health_check *policy : need deep copy
|
// struct health_check *policy : need deep copy
|
||||||
@@ -264,8 +288,15 @@ static void *_health_check_session_foreach(void *arg)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
is_active = bfd_vtysh_get_dev_active(&client, node->policy.address);
|
is_active = bfd_vtysh_get_dev_active(&client, node->policy.address);
|
||||||
if (is_active == -1)
|
if (is_active == -1) {
|
||||||
continue;
|
bfd_vtysh_close(&client);
|
||||||
|
health_check_session_recover_bfd(&client);
|
||||||
|
bfd_vtysh_connect(&client);
|
||||||
|
is_active = bfd_vtysh_get_dev_active(&client, node->policy.address);
|
||||||
|
if (is_active == -1)
|
||||||
|
is_active = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (node->is_active != is_active) {
|
if (node->is_active != is_active) {
|
||||||
node->is_active = is_active;
|
node->is_active = is_active;
|
||||||
if (node->is_active == 1) {
|
if (node->is_active == 1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user