]> git.ipfire.org Git - thirdparty/bird.git/blame - nest/protocol.h
Adds support for soft reconfiguration.
[thirdparty/bird.git] / nest / protocol.h
CommitLineData
58ef912c
MM
1/*
2 * BIRD Internet Routing Daemon -- Protocols
3 *
7293c5dd 4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
58ef912c
MM
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9#ifndef _BIRD_PROTOCOL_H_
10#define _BIRD_PROTOCOL_H_
11
2326b001 12#include "lib/lists.h"
1feea03e 13#include "lib/resource.h"
9685deb9 14#include "lib/timer.h"
58ef912c 15
2326b001 16struct iface;
9a158361 17struct ifa;
2326b001
MM
18struct rte;
19struct neighbor;
1b769b08 20struct rta;
8c43696d 21struct network;
31b3e1bb
MM
22struct proto_config;
23struct config;
24struct proto;
64011f89 25struct event;
bb027be1 26struct ea_list;
3991d84e 27struct eattr;
ae97b946 28struct symbol;
2326b001 29
58ef912c
MM
30/*
31 * Routing Protocol
32 */
33
34struct protocol {
a5f1a60e 35 node n;
58ef912c 36 char *name;
d272fe22 37 char *template; /* Template for automatic generation of names */
4ba84ebc 38 int name_counter; /* Counter for automatic name generation */
3991d84e 39 int attr_class; /* Attribute class known to this protocol */
58ef912c 40
31b3e1bb
MM
41 void (*preconfig)(struct protocol *, struct config *); /* Just before configuring */
42 void (*postconfig)(struct proto_config *); /* After configuring each instance */
43 struct proto * (*init)(struct proto_config *); /* Create new instance */
50fe90ed 44 int (*reconfigure)(struct proto *, struct proto_config *); /* Try to reconfigure instance, returns success */
31b3e1bb 45 void (*dump)(struct proto *); /* Debugging dump */
69ec9087 46 void (*dump_attrs)(struct rte *); /* Dump protocol-dependent attributes */
31b3e1bb
MM
47 int (*start)(struct proto *); /* Start the instance */
48 int (*shutdown)(struct proto *); /* Stop the instance */
9685deb9 49 void (*get_status)(struct proto *, byte *buf); /* Get instance status (for `show protocols' command) */
ce1da96e 50 void (*get_route_info)(struct rte *, byte *buf, struct ea_list *attrs); /* Get route information (for `show route' command) */
aebe06b4 51 int (*get_attr)(struct eattr *, byte *buf, int buflen); /* ASCIIfy dynamic attribute (returns GA_*) */
58ef912c
MM
52};
53
0432c017 54void protos_build(void);
3991d84e 55void proto_build(struct protocol *);
31b3e1bb
MM
56void protos_preconfig(struct config *);
57void protos_postconfig(struct config *);
bf1aec97 58void protos_commit(struct config *new, struct config *old, int force_restart, int type);
87d2be86 59void protos_dump_all(void);
a5f1a60e 60
3991d84e
MM
61#define GA_UNKNOWN 0 /* Attribute not recognized */
62#define GA_NAME 1 /* Result = name */
63#define GA_FULL 2 /* Result = both name and value */
58ef912c
MM
64
65/*
66 * Known protocols
67 */
68
2638249d
MM
69extern struct protocol
70 proto_device, proto_rip, proto_static,
71 proto_ospf, proto_pipe, proto_bgp;
58ef912c
MM
72
73/*
74 * Routing Protocol Instance
75 */
76
31b3e1bb
MM
77struct proto_config {
78 node n;
79 struct config *global; /* Global configuration data */
1d2664a4
MM
80 struct protocol *protocol; /* Protocol */
81 struct proto *proto; /* Instance we've created */
31b3e1bb
MM
82 char *name;
83 unsigned debug, preference, disabled; /* Generic parameters */
0e02abfd 84 struct rtable_config *table; /* Table we're attached to */
529c4149 85 struct filter *in_filter, *out_filter; /* Attached filters */
31b3e1bb
MM
86
87 /* Protocol-specific data follow... */
88};
89
925fe2d3
OZ
90 /* Protocol statistics */
91struct proto_stats {
92 /* Import - from protocol to core */
93 u32 imp_routes; /* Number of routes successfully imported to the (adjacent) routing table */
94 u32 pref_routes; /* Number of routes that are preferred, sum over all routing table */
95 u32 imp_updates_received; /* Number of route updates received */
96 u32 imp_updates_invalid; /* Number of route updates rejected as invalid */
97 u32 imp_updates_filtered; /* Number of route updates rejected by filters */
98 u32 imp_updates_ignored; /* Number of route updates rejected as already in route table */
99 u32 imp_updates_accepted; /* Number of route updates accepted and imported */
100 u32 imp_withdraws_received; /* Number of route withdraws received */
101 u32 imp_withdraws_invalid; /* Number of route withdraws rejected as invalid */
102 u32 imp_withdraws_ignored; /* Number of route withdraws rejected as already not in route table */
103 u32 imp_withdraws_accepted; /* Number of route withdraws accepted and processed */
104
105 /* Export - from core to protocol */
106 u32 exp_routes; /* Number of routes successfully exported to the protocol */
107 u32 exp_updates_received; /* Number of route updates received */
108 u32 exp_updates_rejected; /* Number of route updates rejected by protocol */
109 u32 exp_updates_filtered; /* Number of route updates rejected by filters */
110 u32 exp_updates_accepted; /* Number of route updates accepted and exported */
111 u32 exp_withdraws_received; /* Number of route withdraws received */
112 u32 exp_withdraws_accepted; /* Number of route withdraws accepted and processed */
113};
114
58ef912c 115struct proto {
f14a4bec
MM
116 node n; /* Node in *_proto_list */
117 node glob_node; /* Node in global proto_list */
58ef912c 118 struct protocol *proto; /* Protocol */
31b3e1bb 119 struct proto_config *cf; /* Configuration data */
50fe90ed 120 struct proto_config *cf_new; /* Configuration we want to switch to after shutdown (NULL=delete) */
31b3e1bb 121 pool *pool; /* Pool containing local objects */
64011f89 122 struct event *attn; /* "Pay attention" event */
31b3e1bb 123
64011f89 124 char *name; /* Name of this instance (== cf->name) */
58ef912c 125 unsigned debug; /* Debugging flags */
58ef912c 126 unsigned preference; /* Default route preference */
0da472d7 127 int min_scope; /* Minimal route scope accepted */
23ac9e9a 128 unsigned accept_ra_types; /* Which types of route announcements are accepted (RA_OPTIMAL or RA_ANY) */
bd5d0d62 129 unsigned disabled; /* Manually disabled */
31b3e1bb
MM
130 unsigned proto_state; /* Protocol state machine (see below) */
131 unsigned core_state; /* Core state machine (see below) */
64011f89 132 unsigned core_goal; /* State we want to reach (see below) */
50fe90ed 133 unsigned reconfiguring; /* We're shutting down due to reconfiguration */
7293c5dd 134 u32 hash_key; /* Random key used for hashing of neighbors */
9685deb9 135 bird_clock_t last_state_change; /* Time of last state transition */
df9f0fb3 136 char *last_state_name_announced; /* Last state name we've announced to the user */
925fe2d3 137 struct proto_stats stats; /* Current protocol statistics */
58ef912c 138
9e0e485e
MM
139 /*
140 * General protocol hooks:
141 *
142 * if_notify Notify protocol about interface state changes.
9a158361 143 * ifa_notify Notify protocol about interface address changes.
9e0e485e
MM
144 * rt_notify Notify protocol about routing table updates.
145 * neigh_notify Notify protocol about neighbor cache events.
146 * make_tmp_attrs Construct ea_list from private attrs stored in rte.
147 * store_tmp_attrs Store private attrs back to the rte.
148 * import_control Called as the first step of the route importing process.
149 * It can construct a new rte, add private attributes and
150 * decide whether the route shall be imported: 1=yes, -1=no,
151 * 0=process it through the import filter set by the user.
152 */
153
9a158361
MM
154 void (*if_notify)(struct proto *, unsigned flags, struct iface *i);
155 void (*ifa_notify)(struct proto *, unsigned flags, struct ifa *a);
08f0290a 156 void (*rt_notify)(struct proto *, struct network *net, struct rte *new, struct rte *old, struct ea_list *attrs);
4cc78c50 157 void (*neigh_notify)(struct neighbor *neigh);
9e0e485e
MM
158 struct ea_list *(*make_tmp_attrs)(struct rte *rt, struct linpool *pool);
159 void (*store_tmp_attrs)(struct rte *rt, struct ea_list *attrs);
160 int (*import_control)(struct proto *, struct rte **rt, struct ea_list **attrs, struct linpool *pool);
161
162 /*
163 * Routing entry hooks (called only for rte's belonging to this protocol):
164 *
165 * rte_better Compare two rte's and decide which one is better (1=first, 0=second).
67be5b23 166 * rte_same Compare two rte's and decide whether they are identical (1=yes, 0=no).
9e0e485e
MM
167 * rte_insert Called whenever a rte is inserted to a routing table.
168 * rte_remove Called whenever a rte is removed from the routing table.
169 */
58ef912c 170
2326b001 171 int (*rte_better)(struct rte *, struct rte *);
67be5b23 172 int (*rte_same)(struct rte *, struct rte *);
acc62f5e
MM
173 void (*rte_insert)(struct network *, struct rte *);
174 void (*rte_remove)(struct network *, struct rte *);
2326b001 175
0e02abfd 176 struct rtable *table; /* Our primary routing table */
529c4149
MM
177 struct filter *in_filter; /* Input filter */
178 struct filter *out_filter; /* Output filter */
0e02abfd 179 struct announce_hook *ahooks; /* Announcement hooks for this protocol */
529c4149 180
ac5d8012
MM
181 struct fib_iterator *feed_iterator; /* Routing table iterator used during protocol feeding */
182 struct announce_hook *feed_ahook; /* Announce hook we currently feed */
183
58ef912c
MM
184 /* Hic sunt protocol-specific data */
185};
186
31b3e1bb
MM
187void *proto_new(struct proto_config *, unsigned size);
188void *proto_config_new(struct protocol *, unsigned size);
f14a4bec 189
0d3e6bce 190void proto_show(struct symbol *, int);
02c1fbdd 191struct proto *proto_get_named(struct symbol *, struct protocol *);
f14a4bec 192void proto_xxable(char *, int);
96d8e3bf 193void proto_debug(char *, unsigned int);
58ef912c 194
f14a4bec 195extern list active_proto_list;
2326b001 196
31b3e1bb
MM
197/*
198 * Each protocol instance runs two different state machines:
199 *
200 * [P] The protocol machine: (implemented inside protocol)
201 *
202 * DOWN ----> START
203 * ^ |
204 * | V
205 * STOP <---- UP
206 *
207 * States: DOWN Protocol is down and it's waiting for the core
208 * requesting protocol start.
209 * START Protocol is waiting for connection with the rest
210 * of the network and it's not willing to accept
211 * packets. When it connects, it goes to UP state.
212 * UP Protocol is up and running. When the network
213 * connection breaks down or the core requests
214 * protocol to be terminated, it goes to STOP state.
215 * STOP Protocol is disconnecting from the network.
216 * After it disconnects, it returns to DOWN state.
217 *
218 * In: start() Called in DOWN state to request protocol startup.
219 * Returns new state: either UP or START (in this
220 * case, the protocol will notify the core when it
221 * finally comes UP).
222 * stop() Called in START, UP or STOP state to request
223 * protocol shutdown. Returns new state: either
224 * DOWN or STOP (in this case, the protocol will
225 * notify the core when it finally comes DOWN).
226 *
227 * Out: proto_notify_state() -- called by protocol instance when
228 * it does any state transition not covered by
229 * return values of start() and stop(). This includes
230 * START->UP (delayed protocol startup), UP->STOP
231 * (spontaneous shutdown) and STOP->DOWN (delayed
232 * shutdown).
233 */
234
235#define PS_DOWN 0
236#define PS_START 1
237#define PS_UP 2
238#define PS_STOP 3
239
240void proto_notify_state(struct proto *p, unsigned state);
241
242/*
243 * [F] The feeder machine: (implemented in core routines)
244 *
245 * HUNGRY ----> FEEDING
246 * ^ |
247 * | V
248 * FLUSHING <---- HAPPY
249 *
250 * States: HUNGRY Protocol either administratively down (i.e.,
251 * disabled by the user) or temporarily down
252 * (i.e., [P] is not UP)
253 * FEEDING The protocol came up and we're feeding it
254 * initial routes. [P] is UP.
255 * HAPPY The protocol is up and it's receiving normal
256 * routing updates. [P] is UP.
257 * FLUSHING The protocol is down and we're removing its
258 * routes from the table. [P] is STOP or DOWN.
259 *
260 * Normal lifecycle of a protocol looks like:
261 *
262 * HUNGRY/DOWN --> HUNGRY/START --> HUNGRY/UP -->
263 * FEEDING/UP --> HAPPY/UP --> FLUSHING/STOP|DOWN -->
264 * HUNGRY/STOP|DOWN --> HUNGRY/DOWN
265 */
266
267#define FS_HUNGRY 0
268#define FS_FEEDING 1
269#define FS_HAPPY 2
270#define FS_FLUSHING 3
271
96d8e3bf
MM
272/*
273 * Debugging flags
274 */
275
276#define D_STATES 1 /* [core] State transitions */
277#define D_ROUTES 2 /* [core] Routes passed by the filters */
6a9f28b0
MM
278#define D_FILTERS 4 /* [core] Routes rejected by the filters */
279#define D_IFACES 8 /* [core] Interface events */
280#define D_EVENTS 16 /* Protocol events */
281#define D_PACKETS 32 /* Packets sent/received */
96d8e3bf 282
50d8424a
MM
283/*
284 * Known unique protocol instances as referenced by config routines
285 */
286
31b3e1bb 287extern struct proto_config *cf_dev_proto;
50d8424a 288
0e02abfd
MM
289/*
290 * Route Announcement Hook
291 */
292
293struct announce_hook {
294 node n;
295 struct rtable *table;
296 struct proto *proto;
297 struct announce_hook *next; /* Next hook for the same protocol */
298};
299
300struct announce_hook *proto_add_announce_hook(struct proto *, struct rtable *);
301
58ef912c 302#endif