The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
session.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/*
19 * $Id: a90d90db4c750a0c463c1808702b531cc6895065 $
20 *
21 * @file src/listen/bfd/session.h
22 * @brief BFD Session handling
23 *
24 * @copyright 2023 Network RADIUS SAS (legal@networkradius.com)
25 */
26#include "proto_bfd.h"
27
28typedef struct {
29 fr_client_t client; //!< might as well reuse this, others need it
30
31 uint16_t port; //!< peer port where packets are sent to
32
33 char const *server_name; //!< our name
34
35 bool only_state_changes; //!< copied from proto_bfd_udp.c
36
37 /*
38 * Peers are defined globally to a virtual server. Each
39 * peer can only have one session associated with it.
40 */
41 void *inst; //!< proto_bfd_udp instance using this session
42 fr_listen_t *listen; //!< associated listener
43
44 int sockfd; //!< cached for laziness
45 fr_event_list_t *el; //!< event list
46 fr_network_t *nr; //!< network side of things
47
48 struct sockaddr_storage remote_sockaddr; //!< cached for laziness
49 socklen_t remote_salen;
50
51 struct sockaddr_storage local_sockaddr; //!< cached for laziness
52 socklen_t local_salen;
53
54 /*
55 * Internal state management
56 */
57 fr_event_timer_t const *ev_timeout; //!< when we time out for not receiving a packet
58 fr_event_timer_t const *ev_packet; //!< for when we next send a packet
59 fr_time_t last_recv; //!< last received packet
60 fr_time_t next_recv; //!< when we next expect to receive a packet
61 fr_time_t last_sent; //!< the last time we sent a packet
62
63 bfd_session_state_t session_state; //!< our view of the session state
64 bfd_session_state_t remote_session_state; //!< their view of the session state
65
66 /*
67 * BFD state machine, and fields we use to manage it.
68 *
69 * The public names in the configuration files are what makes sense.
70 *
71 * The names here are the names from the protocol, so that we can be sure the state machine is
72 * implemented correctly.
73 */
74 uint32_t local_disc; //!< our session ID, which is unique to this session
75 uint32_t remote_disc; //!< their session ID
76
77 bfd_diag_t local_diag; //!< diagnostics for errors
78
80
81 fr_time_delta_t desired_min_tx_interval; //!< intervals between transmits
82 fr_time_delta_t required_min_rx_interval; //!< intervals between receives
83
84 fr_time_delta_t remote_min_rx_interval; //!< their min_rx_interval
85
86 fr_time_delta_t my_min_echo_rx_interval; //!< what we send for echo_rx_interval
87
88 fr_time_delta_t next_min_tx_interval; //!< how to update this when we're polling
89
90
91 bool demand_mode; //!< demand is "once session is up, stop sending packets"
92 bool remote_demand_mode; //!< their demand mode
93
95
96 /*
97 * Authentication configuration and states.
98 */
99 bool auth_seq_known; //!< do we know the authentication sequence number?
100
101 bfd_auth_type_t auth_type; //!< what kind of authentication is used
102
103 uint32_t recv_auth_seq; //!< their auth_seq number
104 uint32_t xmit_auth_seq; //!< our auth_seq number
105
106 size_t secret_len; //!< doesn't change while we're running
107
108 fr_time_delta_t detection_time; //!< used to set ev_timeout
109 int detection_timeouts; //!< too many timeouts means !auth_seq_known
110
111 bool passive; //!< active or passive role from RFC 5880 - unused
113
114/*
115 * Common APIs between the listen and process routines. There's no real reason for these definitions to
116 * be here, other than it's an easy place to put common code and definitions.
117 *
118 * Unlike other protocols, BFD has no association between request and reply. Instead, there are two
119 * independent streams of packets. One is sent by us to the peer, and the other is sent by the peer to
120 * us.
121 *
122 * In addition, there are state changes associated with BFD packets.
123 */
130
131typedef enum {
133 BFD_STATE_CHANGE_NONE, //!< no state change
134 BFD_STATE_CHANGE_ADMIN_DOWN, //!< we are admin-down
135 BFD_STATE_CHANGE_PEER_DOWN, //!< the peer has signalled us that he's Down.
136 BFD_STATE_CHANGE_INIT, //!< we are going to INIT
137 BFD_STATE_CHANGE_UP, //!< we are going to UP
140
147
148int bfd_session_init(bfd_session_t *session);
149
150void bfd_session_start(bfd_session_t *session);
151
153
154bfd_state_change_t bfd_session_process(bfd_session_t *session, bfd_packet_t *bfd);
bfd_auth_type_t
Definition bfd.h:52
bfd_diag_t
Definition bfd.h:40
bfd_session_state_t
Definition bfd.h:33
Describes a host allowed to send packets to the server.
Definition client.h:80
Stores all information relating to an event list.
Definition event.c:411
A timer event.
Definition event.c:102
socklen_t local_salen
Definition session.h:52
uint32_t recv_auth_seq
their auth_seq number
Definition session.h:103
int sockfd
cached for laziness
Definition session.h:44
fr_time_delta_t my_min_echo_rx_interval
what we send for echo_rx_interval
Definition session.h:86
bfd_state_change_t
Definition session.h:131
@ BFD_STATE_CHANGE_UP
we are going to UP
Definition session.h:137
@ BFD_STATE_CHANGE_TIMEOUT_DOWN
Definition session.h:138
@ BFD_STATE_CHANGE_INIT
we are going to INIT
Definition session.h:136
@ BFD_STATE_CHANGE_PEER_DOWN
the peer has signalled us that he's Down.
Definition session.h:135
@ BFD_STATE_CHANGE_INVALID
Definition session.h:132
@ BFD_STATE_CHANGE_ADMIN_DOWN
we are admin-down
Definition session.h:134
@ BFD_STATE_CHANGE_NONE
no state change
Definition session.h:133
void bfd_session_start(bfd_session_t *session)
Definition session.c:1087
size_t secret_len
doesn't change while we're running
Definition session.h:106
bool demand_mode
demand is "once session is up, stop sending packets"
Definition session.h:91
bool doing_poll
Definition session.h:94
fr_listen_t * listen
associated listener
Definition session.h:42
bfd_session_state_t remote_session_state
their view of the session state
Definition session.h:64
fr_time_t last_recv
last received packet
Definition session.h:59
fr_time_delta_t required_min_rx_interval
intervals between receives
Definition session.h:82
socklen_t remote_salen
Definition session.h:49
bfd_session_state_t session_state
our view of the session state
Definition session.h:63
uint32_t local_disc
our session ID, which is unique to this session
Definition session.h:74
bfd_wrapper_type_t
Definition session.h:124
@ BFD_WRAPPER_STATE_CHANGE
Definition session.h:128
@ BFD_WRAPPER_SEND_PACKET
Definition session.h:127
@ BFD_WRAPPER_RECV_PACKET
Definition session.h:126
@ BFD_WRAPPER_INVALID
Definition session.h:125
fr_time_t last_sent
the last time we sent a packet
Definition session.h:61
fr_client_t client
might as well reuse this, others need it
Definition session.h:29
uint32_t remote_disc
their session ID
Definition session.h:75
char const * server_name
our name
Definition session.h:33
bool only_state_changes
copied from proto_bfd_udp.c
Definition session.h:35
uint16_t port
peer port where packets are sent to
Definition session.h:31
bfd_auth_type_t auth_type
what kind of authentication is used
Definition session.h:101
int bfd_session_init(bfd_session_t *session)
Definition session.c:1063
bfd_session_t * session
Definition session.h:144
bfd_state_change_t bfd_session_process(bfd_session_t *session, bfd_packet_t *bfd)
Definition session.c:150
fr_event_timer_t const * ev_timeout
when we time out for not receiving a packet
Definition session.h:57
uint32_t detect_multi
Definition session.h:79
uint32_t xmit_auth_seq
our auth_seq number
Definition session.h:104
bool passive
active or passive role from RFC 5880 - unused
Definition session.h:111
fr_time_delta_t desired_min_tx_interval
intervals between transmits
Definition session.h:81
bool remote_demand_mode
their demand mode
Definition session.h:92
void * inst
proto_bfd_udp instance using this session
Definition session.h:41
fr_network_t * nr
network side of things
Definition session.h:46
bfd_state_change_t state_change
Definition session.h:143
int detection_timeouts
too many timeouts means !auth_seq_known
Definition session.h:109
fr_event_list_t * el
event list
Definition session.h:45
fr_time_delta_t next_min_tx_interval
how to update this when we're polling
Definition session.h:88
bool auth_seq_known
do we know the authentication sequence number?
Definition session.h:99
uint32_t type
Definition session.h:142
fr_time_t next_recv
when we next expect to receive a packet
Definition session.h:60
fr_time_delta_t detection_time
used to set ev_timeout
Definition session.h:108
bfd_diag_t local_diag
diagnostics for errors
Definition session.h:77
fr_event_timer_t const * ev_packet
for when we next send a packet
Definition session.h:58
void bfd_session_admin_down(bfd_session_t *session)
Definition session.c:75
fr_time_delta_t remote_min_rx_interval
their min_rx_interval
Definition session.h:84
unsigned short uint16_t
unsigned int uint32_t
unsigned char uint8_t
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
"server local" time.
Definition time.h:69