-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarget.c
58 lines (49 loc) · 1.34 KB
/
target.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Copyright (C) 2024 TDT AG <[email protected]>
*
* This is free software, licensed under the GNU General Public License v2.
* See https://www.gnu.org/licenses/gpl-2.0.txt for more information.
*
*/
#include "interface.h"
#include "logging.h"
#include "ping.h"
#include "target.h"
void target_free(struct target *target)
{
if (target->remote)
free(target->remote);
if (target->device)
free(target->device);
free(target);
}
void target_add(struct interface *iface, const char *remote, const char *device)
{
struct target *target;
int ret;
target = (struct target *) calloc(1, sizeof(struct target));
target->remote = strdup(remote);
target->device = strdup(device);
target->iface = iface;
target->interval = iface->interval;
ret = ping_init(target);
if (ret < 0) {
target_free(target);
}
ping_send(target);
ret = uloop_timeout_set(&target->timeout_send, 1000);
if (ret < 0)
LOGGING_ERR("%s, could not add uloop ping timeout for '%s'",
__func__, iface->name);
list_add(&target->list, &iface->targets);
LOGGING_INFO("%s: adding tracking ip '%s'", __func__, remote);
}
void targets_del(struct interface *iface)
{
struct target *target, *tmp;
list_for_each_entry_safe(target, tmp, &iface->targets, list) {
LOGGING_INFO("%s: del target '%s'", __func__, target->remote);
list_del(&target->list);
target_free(target);
}
}