This indirection is not very helpful in understanding the code
flow. Move the check to process_coarse_timers, remove the
check function, rename the do_work function to the "real" thing
and then drop the do_work wrapper as it does no longer serve a
purpose.
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20200810143707.5834-7-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg20668.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
| ... | ... |
@@ -138,84 +138,6 @@ check_incoming_control_channel(struct context *c) |
| 138 | 138 |
#endif |
| 139 | 139 |
} |
| 140 | 140 |
|
| 141 |
-/* |
|
| 142 |
- * Should we add routes? |
|
| 143 |
- */ |
|
| 144 |
-static inline void |
|
| 145 |
-check_add_routes(struct context *c) |
|
| 146 |
-{
|
|
| 147 |
- void check_add_routes_dowork(struct context *c); |
|
| 148 |
- |
|
| 149 |
- if (event_timeout_trigger(&c->c2.route_wakeup, &c->c2.timeval, ETT_DEFAULT)) |
|
| 150 |
- {
|
|
| 151 |
- check_add_routes_dowork(c); |
|
| 152 |
- } |
|
| 153 |
-} |
|
| 154 |
- |
|
| 155 |
-/* |
|
| 156 |
- * Should we exit due to inactivity timeout? |
|
| 157 |
- */ |
|
| 158 |
-static inline void |
|
| 159 |
-check_inactivity_timeout(struct context *c) |
|
| 160 |
-{
|
|
| 161 |
- void check_inactivity_timeout_dowork(struct context *c); |
|
| 162 |
- |
|
| 163 |
- if (c->options.inactivity_timeout |
|
| 164 |
- && event_timeout_trigger(&c->c2.inactivity_interval, &c->c2.timeval, ETT_DEFAULT)) |
|
| 165 |
- {
|
|
| 166 |
- check_inactivity_timeout_dowork(c); |
|
| 167 |
- } |
|
| 168 |
-} |
|
| 169 |
- |
|
| 170 |
-#if P2MP |
|
| 171 |
- |
|
| 172 |
-static inline void |
|
| 173 |
-check_server_poll_timeout(struct context *c) |
|
| 174 |
-{
|
|
| 175 |
- void check_server_poll_timeout_dowork(struct context *c); |
|
| 176 |
- |
|
| 177 |
- if (c->options.ce.connect_timeout |
|
| 178 |
- && event_timeout_trigger(&c->c2.server_poll_interval, &c->c2.timeval, ETT_DEFAULT)) |
|
| 179 |
- {
|
|
| 180 |
- check_server_poll_timeout_dowork(c); |
|
| 181 |
- } |
|
| 182 |
-} |
|
| 183 |
- |
|
| 184 |
-/* |
|
| 185 |
- * Scheduled exit? |
|
| 186 |
- */ |
|
| 187 |
-static inline void |
|
| 188 |
-check_scheduled_exit(struct context *c) |
|
| 189 |
-{
|
|
| 190 |
- void check_scheduled_exit_dowork(struct context *c); |
|
| 191 |
- |
|
| 192 |
- if (event_timeout_defined(&c->c2.scheduled_exit)) |
|
| 193 |
- {
|
|
| 194 |
- if (event_timeout_trigger(&c->c2.scheduled_exit, &c->c2.timeval, ETT_DEFAULT)) |
|
| 195 |
- {
|
|
| 196 |
- check_scheduled_exit_dowork(c); |
|
| 197 |
- } |
|
| 198 |
- } |
|
| 199 |
-} |
|
| 200 |
-#endif /* if P2MP */ |
|
| 201 |
- |
|
| 202 |
-/* |
|
| 203 |
- * Should we write timer-triggered status file. |
|
| 204 |
- */ |
|
| 205 |
-static inline void |
|
| 206 |
-check_status_file(struct context *c) |
|
| 207 |
-{
|
|
| 208 |
- void check_status_file_dowork(struct context *c); |
|
| 209 |
- |
|
| 210 |
- if (c->c1.status_output) |
|
| 211 |
- {
|
|
| 212 |
- if (status_trigger_tv(c->c1.status_output, &c->c2.timeval)) |
|
| 213 |
- {
|
|
| 214 |
- check_status_file_dowork(c); |
|
| 215 |
- } |
|
| 216 |
- } |
|
| 217 |
-} |
|
| 218 |
- |
|
| 219 | 141 |
#ifdef ENABLE_FRAGMENT |
| 220 | 142 |
/* |
| 221 | 143 |
* Should we deliver a datagram fragment to remote? |
| ... | ... |
@@ -232,37 +154,6 @@ check_fragment(struct context *c) |
| 232 | 232 |
} |
| 233 | 233 |
#endif |
| 234 | 234 |
|
| 235 |
-#if P2MP |
|
| 236 |
- |
|
| 237 |
-/* |
|
| 238 |
- * see if we should send a push_request in response to --pull |
|
| 239 |
- */ |
|
| 240 |
-static inline void |
|
| 241 |
-check_push_request(struct context *c) |
|
| 242 |
-{
|
|
| 243 |
- void check_push_request_dowork(struct context *c); |
|
| 244 |
- |
|
| 245 |
- if (event_timeout_trigger(&c->c2.push_request_interval, &c->c2.timeval, ETT_DEFAULT)) |
|
| 246 |
- {
|
|
| 247 |
- check_push_request_dowork(c); |
|
| 248 |
- } |
|
| 249 |
-} |
|
| 250 |
- |
|
| 251 |
-#endif |
|
| 252 |
- |
|
| 253 |
-/* |
|
| 254 |
- * Should we persist our anti-replay packet ID state to disk? |
|
| 255 |
- */ |
|
| 256 |
-static inline void |
|
| 257 |
-check_packet_id_persist_flush(struct context *c) |
|
| 258 |
-{
|
|
| 259 |
- if (packet_id_persist_enabled(&c->c1.pid_persist) |
|
| 260 |
- && event_timeout_trigger(&c->c2.packet_id_persist_interval, &c->c2.timeval, ETT_DEFAULT)) |
|
| 261 |
- {
|
|
| 262 |
- packet_id_persist_save(&c->c1.pid_persist); |
|
| 263 |
- } |
|
| 264 |
-} |
|
| 265 |
- |
|
| 266 | 235 |
/* |
| 267 | 236 |
* Set our wakeup to 0 seconds, so we will be rescheduled |
| 268 | 237 |
* immediately. |
| ... | ... |
@@ -410,7 +301,7 @@ check_incoming_control_channel_dowork(struct context *c) |
| 410 | 410 |
* Periodically resend PUSH_REQUEST until PUSH message received |
| 411 | 411 |
*/ |
| 412 | 412 |
void |
| 413 |
-check_push_request_dowork(struct context *c) |
|
| 413 |
+check_push_request(struct context *c) |
|
| 414 | 414 |
{
|
| 415 | 415 |
send_push_request(c); |
| 416 | 416 |
|
| ... | ... |
@@ -521,7 +412,7 @@ check_add_routes_action(struct context *c, const bool errors) |
| 521 | 521 |
} |
| 522 | 522 |
|
| 523 | 523 |
void |
| 524 |
-check_add_routes_dowork(struct context *c) |
|
| 524 |
+check_add_routes(struct context *c) |
|
| 525 | 525 |
{
|
| 526 | 526 |
if (test_routes(c->c1.route_list, c->c1.tuntap)) |
| 527 | 527 |
{
|
| ... | ... |
@@ -559,7 +450,7 @@ check_add_routes_dowork(struct context *c) |
| 559 | 559 |
* Should we exit due to inactivity timeout? |
| 560 | 560 |
*/ |
| 561 | 561 |
void |
| 562 |
-check_inactivity_timeout_dowork(struct context *c) |
|
| 562 |
+check_inactivity_timeout(struct context *c) |
|
| 563 | 563 |
{
|
| 564 | 564 |
msg(M_INFO, "Inactivity timeout (--inactive), exiting"); |
| 565 | 565 |
register_signal(c, SIGTERM, "inactive"); |
| ... | ... |
@@ -575,7 +466,7 @@ get_server_poll_remaining_time(struct event_timeout *server_poll_timeout) |
| 575 | 575 |
#if P2MP |
| 576 | 576 |
|
| 577 | 577 |
void |
| 578 |
-check_server_poll_timeout_dowork(struct context *c) |
|
| 578 |
+check_server_poll_timeout(struct context *c) |
|
| 579 | 579 |
{
|
| 580 | 580 |
event_timeout_reset(&c->c2.server_poll_interval); |
| 581 | 581 |
ASSERT(c->c2.tls_multi); |
| ... | ... |
@@ -605,7 +496,7 @@ schedule_exit(struct context *c, const int n_seconds, const int signal) |
| 605 | 605 |
* Scheduled exit? |
| 606 | 606 |
*/ |
| 607 | 607 |
void |
| 608 |
-check_scheduled_exit_dowork(struct context *c) |
|
| 608 |
+check_scheduled_exit(struct context *c) |
|
| 609 | 609 |
{
|
| 610 | 610 |
register_signal(c, c->c2.scheduled_exit_signal, "delayed-exit"); |
| 611 | 611 |
} |
| ... | ... |
@@ -616,7 +507,7 @@ check_scheduled_exit_dowork(struct context *c) |
| 616 | 616 |
* Should we write timer-triggered status file. |
| 617 | 617 |
*/ |
| 618 | 618 |
void |
| 619 |
-check_status_file_dowork(struct context *c) |
|
| 619 |
+check_status_file(struct context *c) |
|
| 620 | 620 |
{
|
| 621 | 621 |
if (c->c1.status_output) |
| 622 | 622 |
{
|
| ... | ... |
@@ -761,10 +652,18 @@ process_coarse_timers(struct context *c) |
| 761 | 761 |
{
|
| 762 | 762 |
/* flush current packet-id to file once per 60 |
| 763 | 763 |
* seconds if --replay-persist was specified */ |
| 764 |
- check_packet_id_persist_flush(c); |
|
| 764 |
+ if (packet_id_persist_enabled(&c->c1.pid_persist) |
|
| 765 |
+ && event_timeout_trigger(&c->c2.packet_id_persist_interval, &c->c2.timeval, ETT_DEFAULT)) |
|
| 766 |
+ {
|
|
| 767 |
+ packet_id_persist_save(&c->c1.pid_persist); |
|
| 768 |
+ } |
|
| 765 | 769 |
|
| 766 |
- /* should we update status file? */ |
|
| 767 |
- check_status_file(c); |
|
| 770 |
+ /* Should we write timer-triggered status file */ |
|
| 771 |
+ if (c->c1.status_output |
|
| 772 |
+ && event_timeout_trigger(&c->c1.status_output->et, &c->c2.timeval, ETT_DEFAULT)) |
|
| 773 |
+ {
|
|
| 774 |
+ check_status_file(c); |
|
| 775 |
+ } |
|
| 768 | 776 |
|
| 769 | 777 |
/* process connection establishment items */ |
| 770 | 778 |
if (event_timeout_trigger(&c->c2.wait_for_connect, &c->c2.timeval, ETT_DEFAULT)) |
| ... | ... |
@@ -772,8 +671,11 @@ process_coarse_timers(struct context *c) |
| 772 | 772 |
check_connection_established(c); |
| 773 | 773 |
} |
| 774 | 774 |
#if P2MP |
| 775 |
- /* see if we should send a push_request in response to --pull */ |
|
| 776 |
- check_push_request(c); |
|
| 775 |
+ /* see if we should send a push_request (option --pull) */ |
|
| 776 |
+ if (event_timeout_trigger(&c->c2.push_request_interval, &c->c2.timeval, ETT_DEFAULT)) |
|
| 777 |
+ {
|
|
| 778 |
+ check_push_request(c); |
|
| 779 |
+ } |
|
| 777 | 780 |
#endif |
| 778 | 781 |
|
| 779 | 782 |
#ifdef PLUGIN_PF |
| ... | ... |
@@ -781,10 +683,18 @@ process_coarse_timers(struct context *c) |
| 781 | 781 |
#endif |
| 782 | 782 |
|
| 783 | 783 |
/* process --route options */ |
| 784 |
- check_add_routes(c); |
|
| 784 |
+ if (event_timeout_trigger(&c->c2.route_wakeup, &c->c2.timeval, ETT_DEFAULT)) |
|
| 785 |
+ {
|
|
| 786 |
+ check_add_routes(c); |
|
| 787 |
+ } |
|
| 785 | 788 |
|
| 786 | 789 |
/* possibly exit due to --inactive */ |
| 787 |
- check_inactivity_timeout(c); |
|
| 790 |
+ if (c->options.inactivity_timeout |
|
| 791 |
+ && event_timeout_trigger(&c->c2.inactivity_interval, &c->c2.timeval, ETT_DEFAULT)) |
|
| 792 |
+ {
|
|
| 793 |
+ check_inactivity_timeout(c); |
|
| 794 |
+ } |
|
| 795 |
+ |
|
| 788 | 796 |
if (c->sig->signal_received) |
| 789 | 797 |
{
|
| 790 | 798 |
return; |
| ... | ... |
@@ -800,13 +710,19 @@ process_coarse_timers(struct context *c) |
| 800 | 800 |
#if P2MP |
| 801 | 801 |
if (c->c2.tls_multi) |
| 802 | 802 |
{
|
| 803 |
- check_server_poll_timeout(c); |
|
| 803 |
+ if (c->options.ce.connect_timeout |
|
| 804 |
+ && event_timeout_trigger(&c->c2.server_poll_interval, &c->c2.timeval, ETT_DEFAULT)) |
|
| 805 |
+ {
|
|
| 806 |
+ check_server_poll_timeout(c); |
|
| 807 |
+ } |
|
| 804 | 808 |
if (c->sig->signal_received) |
| 805 | 809 |
{
|
| 806 | 810 |
return; |
| 807 | 811 |
} |
| 808 |
- |
|
| 809 |
- check_scheduled_exit(c); |
|
| 812 |
+ if (event_timeout_trigger(&c->c2.scheduled_exit, &c->c2.timeval, ETT_DEFAULT)) |
|
| 813 |
+ {
|
|
| 814 |
+ check_scheduled_exit(c); |
|
| 815 |
+ } |
|
| 810 | 816 |
if (c->sig->signal_received) |
| 811 | 817 |
{
|
| 812 | 818 |
return; |
| ... | ... |
@@ -77,9 +77,9 @@ void check_tls_errors_nco(struct context *c); |
| 77 | 77 |
#if P2MP |
| 78 | 78 |
void check_incoming_control_channel_dowork(struct context *c); |
| 79 | 79 |
|
| 80 |
-void check_scheduled_exit_dowork(struct context *c); |
|
| 80 |
+void check_scheduled_exit(struct context *c); |
|
| 81 | 81 |
|
| 82 |
-void check_push_request_dowork(struct context *c); |
|
| 82 |
+void check_push_request(struct context *c); |
|
| 83 | 83 |
|
| 84 | 84 |
#endif /* P2MP */ |
| 85 | 85 |
|
| ... | ... |
@@ -90,13 +90,13 @@ void check_fragment_dowork(struct context *c); |
| 90 | 90 |
|
| 91 | 91 |
void check_connection_established(struct context *c); |
| 92 | 92 |
|
| 93 |
-void check_add_routes_dowork(struct context *c); |
|
| 93 |
+void check_add_routes(struct context *c); |
|
| 94 | 94 |
|
| 95 |
-void check_inactivity_timeout_dowork(struct context *c); |
|
| 95 |
+void check_inactivity_timeout(struct context *c); |
|
| 96 | 96 |
|
| 97 |
-void check_server_poll_timeout_dowork(struct context *c); |
|
| 97 |
+void check_server_poll_timeout(struct context *c); |
|
| 98 | 98 |
|
| 99 |
-void check_status_file_dowork(struct context *c); |
|
| 99 |
+void check_status_file(struct context *c); |
|
| 100 | 100 |
|
| 101 | 101 |
void io_wait_dowork(struct context *c, const unsigned int flags); |
| 102 | 102 |
|
| ... | ... |
@@ -146,19 +146,6 @@ status_trigger(struct status_output *so) |
| 146 | 146 |
} |
| 147 | 147 |
} |
| 148 | 148 |
|
| 149 |
-bool |
|
| 150 |
-status_trigger_tv(struct status_output *so, struct timeval *tv) |
|
| 151 |
-{
|
|
| 152 |
- if (so) |
|
| 153 |
- {
|
|
| 154 |
- return event_timeout_trigger(&so->et, tv, ETT_DEFAULT); |
|
| 155 |
- } |
|
| 156 |
- else |
|
| 157 |
- {
|
|
| 158 |
- return false; |
|
| 159 |
- } |
|
| 160 |
-} |
|
| 161 |
- |
|
| 162 | 149 |
void |
| 163 | 150 |
status_reset(struct status_output *so) |
| 164 | 151 |
{
|
| ... | ... |
@@ -69,8 +69,6 @@ struct status_output *status_open(const char *filename, |
| 69 | 69 |
const struct virtual_output *vout, |
| 70 | 70 |
const unsigned int flags); |
| 71 | 71 |
|
| 72 |
-bool status_trigger_tv(struct status_output *so, struct timeval *tv); |
|
| 73 |
- |
|
| 74 | 72 |
bool status_trigger(struct status_output *so); |
| 75 | 73 |
|
| 76 | 74 |
void status_reset(struct status_output *so); |