Statistics
| Branch: | Revision:

iof-bird / bird-2.0.1 / proto / bfd / bfd.h @ 6b3f1a54

History | View | Annotate | Download (5.38 KB)

1
/*
2
 *        BIRD -- Bidirectional Forwarding Detection (BFD)
3
 *
4
 *        Can be freely distributed and used under the terms of the GNU GPL.
5
 */
6

    
7
#ifndef _BIRD_BFD_H_
8
#define _BIRD_BFD_H_
9

    
10
#include <pthread.h>
11

    
12
#include "nest/bird.h"
13
#include "nest/cli.h"
14
#include "nest/iface.h"
15
#include "nest/protocol.h"
16
#include "nest/route.h"
17
#include "nest/password.h"
18
#include "conf/conf.h"
19
#include "lib/hash.h"
20
#include "lib/resource.h"
21
#include "lib/socket.h"
22
#include "lib/string.h"
23

    
24
#include "nest/bfd.h"
25
#include "io.h"
26

    
27

    
28
#define BFD_CONTROL_PORT        3784
29
#define BFD_ECHO_PORT                3785
30
#define BFD_MULTI_CTL_PORT        4784
31

    
32
#define BFD_DEFAULT_MIN_RX_INT        (10 MS_)
33
#define BFD_DEFAULT_MIN_TX_INT        (100 MS_)
34
#define BFD_DEFAULT_IDLE_TX_INT        (1 S_)
35
#define BFD_DEFAULT_MULTIPLIER        5
36

    
37

    
38
struct bfd_iface_config;
39

    
40
struct bfd_config
41
{
42
  struct proto_config c;
43
  list patt_list;                /* List of iface configs (struct bfd_iface_config) */
44
  list neigh_list;                /* List of configured neighbors (struct bfd_neighbor) */
45
  struct bfd_iface_config *multihop; /* Multihop pseudoiface config */
46
};
47

    
48
struct bfd_iface_config
49
{
50
  struct iface_patt i;
51
  u32 min_rx_int;
52
  u32 min_tx_int;
53
  u32 idle_tx_int;
54
  u8 multiplier;
55
  u8 passive;
56
  u8 auth_type;                                /* Authentication type (BFD_AUTH_*) */
57
  list *passwords;                        /* Passwords for authentication */
58
};
59

    
60
struct bfd_neighbor
61
{
62
  node n;
63
  ip_addr addr;
64
  ip_addr local;
65
  struct iface *iface;
66

    
67
  struct neighbor *neigh;
68
  struct bfd_request *req;
69

    
70
  u8 multihop;
71
  u8 active;
72
};
73

    
74
struct bfd_proto
75
{
76
  struct proto p;
77
  struct birdloop *loop;
78
  pool *tpool;
79
  pthread_spinlock_t lock;
80
  node bfd_node;
81

    
82
  slab *session_slab;
83
  HASH(struct bfd_session) session_hash_id;
84
  HASH(struct bfd_session) session_hash_ip;
85

    
86
  sock *notify_rs;
87
  sock *notify_ws;
88
  list notify_list;
89

    
90
  sock *rx4_1;
91
  sock *rx6_1;
92
  sock *rx4_m;
93
  sock *rx6_m;
94
  list iface_list;
95
};
96

    
97
struct bfd_iface
98
{
99
  node n;
100
  ip_addr local;
101
  struct iface *iface;
102
  struct bfd_iface_config *cf;
103
  struct bfd_proto *bfd;
104

    
105
  sock *sk;
106
  u32 uc;
107
  u8 changed;
108
};
109

    
110
struct bfd_session
111
{
112
  node n;
113
  ip_addr addr;                                /* Address of session */
114
  struct bfd_iface *ifa;                /* Iface associated with session */
115
  struct bfd_session *next_id;                /* Next in bfd.session_hash_id */
116
  struct bfd_session *next_ip;                /* Next in bfd.session_hash_ip */
117

    
118
  u8 opened_unused;
119
  u8 passive;
120
  u8 poll_active;
121
  u8 poll_scheduled;
122

    
123
  u8 loc_state;
124
  u8 rem_state;
125
  u8 loc_diag;
126
  u8 rem_diag;
127
  u32 loc_id;                                /* Local session ID (local discriminator) */
128
  u32 rem_id;                                /* Remote session ID (remote discriminator) */
129
  u32 des_min_tx_int;                        /* Desired min rx interval, local option */
130
  u32 des_min_tx_new;                        /* Used for des_min_tx_int change */
131
  u32 req_min_rx_int;                        /* Required min tx interval, local option */
132
  u32 req_min_rx_new;                        /* Used for req_min_rx_int change */
133
  u32 rem_min_tx_int;                        /* Last received des_min_tx_int */
134
  u32 rem_min_rx_int;                        /* Last received req_min_rx_int */
135
  u8 demand_mode;                        /* Currently unused */
136
  u8 rem_demand_mode;
137
  u8 detect_mult;                        /* Announced detect_mult, local option */
138
  u8 rem_detect_mult;                        /* Last received detect_mult */
139

    
140
  btime last_tx;                        /* Time of last sent periodic control packet */
141
  btime last_rx;                        /* Time of last received valid control packet */
142

    
143
  timer *tx_timer;                        /* Periodic control packet timer */
144
  timer *hold_timer;                        /* Timer for session down detection time */
145

    
146
  list request_list;                        /* List of client requests (struct bfd_request) */
147
  btime last_state_change;                /* Time of last state change */
148
  u8 notify_running;                        /* 1 if notify hooks are running */
149

    
150
  u8 rx_csn_known;                        /* Received crypto sequence number is known */
151
  u32 rx_csn;                                /* Last received crypto sequence number */
152
  u32 tx_csn;                                /* Last transmitted crypto sequence number */
153
  u32 tx_csn_time;                        /* Timestamp of last tx_csn change */
154
};
155

    
156

    
157
extern const char *bfd_state_names[];
158

    
159
#define BFD_STATE_ADMIN_DOWN        0
160
#define BFD_STATE_DOWN                1
161
#define BFD_STATE_INIT                2
162
#define BFD_STATE_UP                3
163

    
164
#define BFD_DIAG_NOTHING        0
165
#define BFD_DIAG_TIMEOUT        1
166
#define BFD_DIAG_ECHO_FAILED        2
167
#define BFD_DIAG_NEIGHBOR_DOWN        3
168
#define BFD_DIAG_FWD_RESET        4
169
#define BFD_DIAG_PATH_DOWN        5
170
#define BFD_DIAG_C_PATH_DOWN        6
171
#define BFD_DIAG_ADMIN_DOWN        7
172
#define BFD_DIAG_RC_PATH_DOWN        8
173

    
174
#define BFD_POLL_TX                1
175
#define BFD_POLL_RX                2
176

    
177
#define BFD_FLAGS                0x3f
178
#define BFD_FLAG_POLL                (1 << 5)
179
#define BFD_FLAG_FINAL                (1 << 4)
180
#define BFD_FLAG_CPI                (1 << 3)
181
#define BFD_FLAG_AP                (1 << 2)
182
#define BFD_FLAG_DEMAND                (1 << 1)
183
#define BFD_FLAG_MULTIPOINT        (1 << 0)
184

    
185
#define BFD_AUTH_NONE                        0
186
#define BFD_AUTH_SIMPLE                        1
187
#define BFD_AUTH_KEYED_MD5                2
188
#define BFD_AUTH_METICULOUS_KEYED_MD5        3
189
#define BFD_AUTH_KEYED_SHA1                4
190
#define BFD_AUTH_METICULOUS_KEYED_SHA1        5
191

    
192
extern const u8 bfd_auth_type_to_hash_alg[];
193

    
194

    
195
static inline void bfd_lock_sessions(struct bfd_proto *p) { pthread_spin_lock(&p->lock); }
196
static inline void bfd_unlock_sessions(struct bfd_proto *p) { pthread_spin_unlock(&p->lock); }
197

    
198
/* bfd.c */
199
struct bfd_session * bfd_find_session_by_id(struct bfd_proto *p, u32 id);
200
struct bfd_session * bfd_find_session_by_addr(struct bfd_proto *p, ip_addr addr);
201
void bfd_session_process_ctl(struct bfd_session *s, u8 flags, u32 old_tx_int, u32 old_rx_int);
202
void bfd_show_sessions(struct proto *P);
203

    
204
/* packets.c */
205
void bfd_send_ctl(struct bfd_proto *p, struct bfd_session *s, int final);
206
sock * bfd_open_rx_sk(struct bfd_proto *p, int multihop, int inet_version);
207
sock * bfd_open_tx_sk(struct bfd_proto *p, ip_addr local, struct iface *ifa);
208

    
209

    
210
#endif /* _BIRD_BFD_H_ */