]> git.proxmox.com Git - mirror_frr.git/blob - bfdd/event.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / bfdd / event.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*********************************************************************
3 * Copyright 2017-2018 Network Device Education Foundation, Inc. ("NetDEF")
4 *
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
29 /* Remove previous schedule if any. */
30 bfd_recvtimer_delete(bs);
31
32 /* Don't add event if peer is deactivated. */
33 if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
34 bs->sock == -1)
35 return;
36
37 tv_normalize(&tv);
38
39 thread_add_timer_tv(master, bfd_recvtimer_cb, bs, &tv,
40 &bs->recvtimer_ev);
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
47 /* Remove previous schedule if any. */
48 bfd_echo_recvtimer_delete(bs);
49
50 /* Don't add event if peer is deactivated. */
51 if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
52 bs->sock == -1)
53 return;
54
55 tv_normalize(&tv);
56
57 thread_add_timer_tv(master, bfd_echo_recvtimer_cb, bs, &tv,
58 &bs->echo_recvtimer_ev);
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
65 /* Remove previous schedule if any. */
66 bfd_xmttimer_delete(bs);
67
68 /* Don't add event if peer is deactivated. */
69 if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
70 bs->sock == -1)
71 return;
72
73 tv_normalize(&tv);
74
75 thread_add_timer_tv(master, bfd_xmt_cb, bs, &tv, &bs->xmttimer_ev);
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
82 /* Remove previous schedule if any. */
83 bfd_echo_xmttimer_delete(bs);
84
85 /* Don't add event if peer is deactivated. */
86 if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_SHUTDOWN) ||
87 bs->sock == -1)
88 return;
89
90 tv_normalize(&tv);
91
92 thread_add_timer_tv(master, bfd_echo_xmt_cb, bs, &tv,
93 &bs->echo_xmttimer_ev);
94 }
95
96 void bfd_recvtimer_delete(struct bfd_session *bs)
97 {
98 THREAD_OFF(bs->recvtimer_ev);
99 }
100
101 void bfd_echo_recvtimer_delete(struct bfd_session *bs)
102 {
103 THREAD_OFF(bs->echo_recvtimer_ev);
104 }
105
106 void bfd_xmttimer_delete(struct bfd_session *bs)
107 {
108 THREAD_OFF(bs->xmttimer_ev);
109 }
110
111 void bfd_echo_xmttimer_delete(struct bfd_session *bs)
112 {
113 THREAD_OFF(bs->echo_xmttimer_ev);
114 }