]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
e9e2c950 RZ |
2 | /********************************************************************* |
3 | * Copyright 2017-2018 Network Device Education Foundation, Inc. ("NetDEF") | |
4 | * | |
e9e2c950 RZ |
5 | * event.c: implements the BFD loop event handlers. |
6 | * | |
7 | * Authors | |
8 | * ------- | |
9 | * Rafael Zalamena <rzalamena@opensourcerouting.org> | |
10 | */ | |
11 | ||
12 | #include <zebra.h> | |
13 | ||
14 | #include "bfd.h" | |
15 | ||
16 | void tv_normalize(struct timeval *tv); | |
17 | ||
18 | void tv_normalize(struct timeval *tv) | |
19 | { | |
20 | /* Remove seconds part from microseconds. */ | |
21 | tv->tv_sec = tv->tv_usec / 1000000; | |
22 | tv->tv_usec = tv->tv_usec % 1000000; | |
23 | } | |
24 | ||
25 | void bfd_recvtimer_update(struct bfd_session *bs) | |
26 | { | |
27 | struct timeval tv = {.tv_sec = 0, .tv_usec = bs->detect_TO}; | |
28 | ||
744f824a RZ |
29 | /* Remove previous schedule if any. */ |
30 | bfd_recvtimer_delete(bs); | |
31 | ||
e9e2c950 | 32 | /* Don't add event if peer is deactivated. */ |
b88113ef | 33 | if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) || |
d245e522 | 34 | bs->sock == -1) |
e9e2c950 RZ |
35 | return; |
36 | ||
37 | tv_normalize(&tv); | |
e9e2c950 | 38 | |
907a2395 DS |
39 | event_add_timer_tv(master, bfd_recvtimer_cb, bs, &tv, |
40 | &bs->recvtimer_ev); | |
e9e2c950 RZ |
41 | } |
42 | ||
43 | void bfd_echo_recvtimer_update(struct bfd_session *bs) | |
44 | { | |
45 | struct timeval tv = {.tv_sec = 0, .tv_usec = bs->echo_detect_TO}; | |
46 | ||
744f824a RZ |
47 | /* Remove previous schedule if any. */ |
48 | bfd_echo_recvtimer_delete(bs); | |
49 | ||
e9e2c950 | 50 | /* Don't add event if peer is deactivated. */ |
b88113ef | 51 | if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) || |
d245e522 | 52 | bs->sock == -1) |
e9e2c950 RZ |
53 | return; |
54 | ||
55 | tv_normalize(&tv); | |
e9e2c950 | 56 | |
907a2395 DS |
57 | event_add_timer_tv(master, bfd_echo_recvtimer_cb, bs, &tv, |
58 | &bs->echo_recvtimer_ev); | |
e9e2c950 RZ |
59 | } |
60 | ||
61 | void bfd_xmttimer_update(struct bfd_session *bs, uint64_t jitter) | |
62 | { | |
63 | struct timeval tv = {.tv_sec = 0, .tv_usec = jitter}; | |
64 | ||
744f824a RZ |
65 | /* Remove previous schedule if any. */ |
66 | bfd_xmttimer_delete(bs); | |
67 | ||
e9e2c950 | 68 | /* Don't add event if peer is deactivated. */ |
b88113ef | 69 | if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) || |
d245e522 | 70 | bs->sock == -1) |
e9e2c950 RZ |
71 | return; |
72 | ||
73 | tv_normalize(&tv); | |
e9e2c950 | 74 | |
907a2395 | 75 | event_add_timer_tv(master, bfd_xmt_cb, bs, &tv, &bs->xmttimer_ev); |
e9e2c950 RZ |
76 | } |
77 | ||
78 | void bfd_echo_xmttimer_update(struct bfd_session *bs, uint64_t jitter) | |
79 | { | |
80 | struct timeval tv = {.tv_sec = 0, .tv_usec = jitter}; | |
81 | ||
744f824a RZ |
82 | /* Remove previous schedule if any. */ |
83 | bfd_echo_xmttimer_delete(bs); | |
84 | ||
e9e2c950 | 85 | /* Don't add event if peer is deactivated. */ |
b88113ef | 86 | if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) || |
d245e522 | 87 | bs->sock == -1) |
e9e2c950 RZ |
88 | return; |
89 | ||
90 | tv_normalize(&tv); | |
e9e2c950 | 91 | |
907a2395 DS |
92 | event_add_timer_tv(master, bfd_echo_xmt_cb, bs, &tv, |
93 | &bs->echo_xmttimer_ev); | |
e9e2c950 RZ |
94 | } |
95 | ||
96 | void bfd_recvtimer_delete(struct bfd_session *bs) | |
97 | { | |
e16d030c | 98 | EVENT_OFF(bs->recvtimer_ev); |
e9e2c950 RZ |
99 | } |
100 | ||
101 | void bfd_echo_recvtimer_delete(struct bfd_session *bs) | |
102 | { | |
e16d030c | 103 | EVENT_OFF(bs->echo_recvtimer_ev); |
e9e2c950 RZ |
104 | } |
105 | ||
106 | void bfd_xmttimer_delete(struct bfd_session *bs) | |
107 | { | |
e16d030c | 108 | EVENT_OFF(bs->xmttimer_ev); |
e9e2c950 RZ |
109 | } |
110 | ||
111 | void bfd_echo_xmttimer_delete(struct bfd_session *bs) | |
112 | { | |
e16d030c | 113 | EVENT_OFF(bs->echo_xmttimer_ev); |
e9e2c950 | 114 | } |