3 * Implemented server-style in a pthread.
4 * --------------------------------------
5 * Copyright (C) 2017 Cumulus Networks, Inc.
7 * This file is part of Free Range Routing.
9 * Free Range Routing is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any later
14 * Free Range Routing is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 * You should have received a copy of the GN5U General Public License along
20 * with Free Range Routing; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 #ifndef _BGP_KEEPALIVES_H_
25 #define _BGP_KEEPALIVES_H_
29 /* Thread control flag.
31 * Setting this flag to 'false' while the thread is running will result in
34 extern bool bgp_keepalives_thread_run
;
36 /* Turns on keepalives for a peer.
38 * This function adds the peer to an internal list of peers to generate
41 * At set intervals, a BGP KEEPALIVE packet is generated and placed on
42 * peer->obuf. This operation is thread-safe with respect to peer->obuf.
44 * peer->v_keepalive determines the interval. Changing this value before
45 * unregistering this peer with peer_keepalives_off() results in undefined
48 * If the peer is already registered for keepalives via this function, nothing
51 extern void peer_keepalives_on(struct peer
*);
53 /* Turns off keepalives for a peer.
55 * Removes the peer from the internal list of peers to generate keepalives for.
57 * If the peer is already unregistered for keepalives, nothing happens.
59 extern void peer_keepalives_off(struct peer
*);
61 /* Pre-run initialization function for keepalives pthread.
63 * Initializes synchronization primitives. This should be called before
64 * anything else to avoid race conditions.
66 extern void peer_keepalives_init(void);
68 /* Entry function for keepalives pthread.
70 * This function loops over an internal list of peers, generating keepalives at
71 * regular intervals as determined by each peer's keepalive timer.
73 * See peer_keepalives_on() for additional details.
75 * @param arg pthread arg, not used
77 extern void *peer_keepalives_start(void *arg
);
79 /* Poking function for keepalives pthread.
81 * Under normal circumstances the pthread will automatically wake itself
82 * whenever it is necessary to do work. This function may be used to force the
83 * thread to wake up and see if there is any work to do, or if it is time to
86 * It is not necessary to call this after peer_keepalives_on().
88 extern void peer_keepalives_wake(void);
91 int peer_keepalives_stop(void **result
);
93 #endif /* _BGP_KEEPALIVES_H */