diff options
-rw-r--r-- | pingu_burst.c | 2 | ||||
-rw-r--r-- | pingu_host.c | 6 | ||||
-rw-r--r-- | pingu_host.h | 6 | ||||
-rw-r--r-- | pingu_netlink.c | 3 | ||||
-rw-r--r-- | pingu_ping.c | 4 |
5 files changed, 14 insertions, 7 deletions
diff --git a/pingu_burst.c b/pingu_burst.c index 2f4a55b..0ec89a4 100644 --- a/pingu_burst.c +++ b/pingu_burst.c @@ -22,7 +22,7 @@ void ping_burst_start(struct ev_loop *loop, struct pingu_host *host) /* we bind to device every burst in case an iface disappears and comes back. e.g ppp0 */ if (pingu_iface_bind_socket(host->iface, host->status) < 0) { - pingu_host_set_status(host, 0); + pingu_host_set_status(host, PINGU_HOST_STATUS_OFFLINE); return; } diff --git a/pingu_host.c b/pingu_host.c index 360ec6d..3630161 100644 --- a/pingu_host.c +++ b/pingu_host.c @@ -68,9 +68,9 @@ int pingu_host_set_status(struct pingu_host *host, int status) int pingu_host_verify_status(struct ev_loop *loop, struct pingu_host *host) { if (host->burst.pings_replied >= host->required_replies) { - pingu_host_set_status(host, 1); + pingu_host_set_status(host, PINGU_HOST_STATUS_ONLINE); } else if (host->burst.pings_sent >= host->max_retries) { - pingu_host_set_status(host, 0); + pingu_host_set_status(host, PINGU_HOST_STATUS_OFFLINE); } else pingu_ping_send(loop, host, 1); return 0; @@ -90,7 +90,7 @@ struct pingu_host *pingu_host_new(char *hoststr, float burst_interval, } host->host = hoststr; - host->status = 1; /* online by default */ + host->status = PINGU_HOST_DEFAULT_STATUS; host->burst_interval = burst_interval; host->max_retries = max_retries; host->required_replies = required_replies; diff --git a/pingu_host.h b/pingu_host.h index 80a1f53..78afbaf 100644 --- a/pingu_host.h +++ b/pingu_host.h @@ -5,6 +5,12 @@ #include "pingu_burst.h" +#define PINGU_HOST_STATUS_OFFLINE 0 +#define PINGU_HOST_STATUS_ONLINE 1 + +/* consider online by default */ +#define PINGU_HOST_DEFAULT_STATUS PINGU_HOST_STATUS_ONLINE + struct pingu_host { struct list_head host_list_entry; char *host; diff --git a/pingu_netlink.c b/pingu_netlink.c index 81fcad1..5c63a51 100644 --- a/pingu_netlink.c +++ b/pingu_netlink.c @@ -374,7 +374,8 @@ static int add_nexthops(struct nlmsghdr *nlh, size_t nlh_size, case RTM_NEWROUTE: host = pingu_host_find_by_iface(iface); if ((!iface->balance) || iface->index == 0 - || (host != NULL && !host->status) || route == NULL) + || (host != NULL && host->status == PINGU_HOST_STATUS_OFFLINE) + || route == NULL) continue; iface->has_multipath = 1; break; diff --git a/pingu_ping.c b/pingu_ping.c index 0f9de04..64f8ab7 100644 --- a/pingu_ping.c +++ b/pingu_ping.c @@ -93,14 +93,14 @@ int pingu_ping_send(struct ev_loop *loop, struct pingu_host *host, int seq, r; if (!pingu_iface_usable(host->iface)) - return pingu_host_set_status(host, 0) - 1; + return pingu_host_set_status(host, PINGU_HOST_STATUS_OFFLINE) - 1; seq = pingu_ping_get_seq(); r = icmp_send_ping(host->iface->fd, &host->burst.saddr.sa, sizeof(host->burst.saddr), seq, packetlen); if (r < 0) { if (set_status_on_failure) - pingu_host_set_status(host, 0); + pingu_host_set_status(host, PINGU_HOST_STATUS_OFFLINE); return -1; } |