]> git.ipfire.org Git - thirdparty/bird.git/blob - nest/protocol.h
Added get_route_info and show_route_data hooks to struct protocol.
[thirdparty/bird.git] / nest / protocol.h
1 /*
2 * BIRD Internet Routing Daemon -- Protocols
3 *
4 * (c) 1998--1999 Martin Mares <mj@ucw.cz>
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
12 #include "lib/lists.h"
13 #include "lib/resource.h"
14 #include "lib/timer.h"
15
16 struct iface;
17 struct ifa;
18 struct rte;
19 struct neighbor;
20 struct rta;
21 struct network;
22 struct proto_config;
23 struct config;
24 struct proto;
25 struct event;
26 struct ea_list;
27 struct symbol;
28
29 /*
30 * Routing Protocol
31 */
32
33 struct protocol {
34 node n;
35 char *name;
36 unsigned debug; /* Default debugging flags */
37 int priority; /* Protocol priority (usually 0) */
38 int name_counter; /* Counter for automatic name generation */
39 int startup_counter; /* Number of instances waiting for initialization */
40
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 */
44 int (*reconfigure)(struct proto *, struct proto_config *); /* Try to reconfigure instance */
45 void (*dump)(struct proto *); /* Debugging dump */
46 void (*dump_attrs)(struct rte *); /* Dump protocol-dependent attributes */
47 int (*start)(struct proto *); /* Start the instance */
48 int (*shutdown)(struct proto *); /* Stop the instance */
49 void (*get_status)(struct proto *, byte *buf); /* Get instance status (for `show protocols' command) */
50 void (*get_route_info)(struct rte *, byte *buf); /* Get route information (for `show route' command) */
51 void (*show_route_data)(struct rte *); /* Print verbose route information (`show route' again) */
52 };
53
54 void protos_build(void);
55 void protos_preconfig(struct config *);
56 void protos_postconfig(struct config *);
57 void protos_commit(struct config *);
58 void protos_start(void);
59 void protos_dump_all(void);
60 void protos_shutdown(void);
61
62 extern list protocol_list;
63
64 /*
65 * Known protocols
66 */
67
68 extern struct protocol proto_device;
69 extern struct protocol proto_rip;
70 extern struct protocol proto_static;
71 extern struct protocol proto_ospf;
72 extern struct protocol proto_pipe;
73
74 /*
75 * Routing Protocol Instance
76 */
77
78 struct proto_config {
79 node n;
80 struct config *global; /* Global configuration data */
81 struct protocol *protocol; /* Protocol */
82 struct proto *proto; /* Instance we've created */
83 char *name;
84 unsigned debug, preference, disabled; /* Generic parameters */
85 struct rtable_config *table; /* Table we're attached to */
86 struct filter *in_filter, *out_filter; /* Attached filters */
87
88 /* Protocol-specific data follow... */
89 };
90
91 struct proto {
92 node n;
93 struct protocol *proto; /* Protocol */
94 struct proto_config *cf; /* Configuration data */
95 pool *pool; /* Pool containing local objects */
96 struct event *attn; /* "Pay attention" event */
97
98 char *name; /* Name of this instance (== cf->name) */
99 unsigned debug; /* Debugging flags */
100 unsigned preference; /* Default route preference */
101 unsigned disabled; /* Manually disabled */
102 unsigned proto_state; /* Protocol state machine (see below) */
103 unsigned core_state; /* Core state machine (see below) */
104 unsigned core_goal; /* State we want to reach (see below) */
105 bird_clock_t last_state_change; /* Time of last state transition */
106
107 /*
108 * General protocol hooks:
109 *
110 * if_notify Notify protocol about interface state changes.
111 * ifa_notify Notify protocol about interface address changes.
112 * rt_notify Notify protocol about routing table updates.
113 * neigh_notify Notify protocol about neighbor cache events.
114 * make_tmp_attrs Construct ea_list from private attrs stored in rte.
115 * store_tmp_attrs Store private attrs back to the rte.
116 * import_control Called as the first step of the route importing process.
117 * It can construct a new rte, add private attributes and
118 * decide whether the route shall be imported: 1=yes, -1=no,
119 * 0=process it through the import filter set by the user.
120 */
121
122 void (*if_notify)(struct proto *, unsigned flags, struct iface *i);
123 void (*ifa_notify)(struct proto *, unsigned flags, struct ifa *a);
124 void (*rt_notify)(struct proto *, struct network *net, struct rte *new, struct rte *old, struct ea_list *tmpa);
125 void (*neigh_notify)(struct neighbor *neigh);
126 struct ea_list *(*make_tmp_attrs)(struct rte *rt, struct linpool *pool);
127 void (*store_tmp_attrs)(struct rte *rt, struct ea_list *attrs);
128 int (*import_control)(struct proto *, struct rte **rt, struct ea_list **attrs, struct linpool *pool);
129
130 /*
131 * Routing entry hooks (called only for rte's belonging to this protocol):
132 *
133 * rte_better Compare two rte's and decide which one is better (1=first, 0=second).
134 * rte_insert Called whenever a rte is inserted to a routing table.
135 * rte_remove Called whenever a rte is removed from the routing table.
136 */
137
138 int (*rte_better)(struct rte *, struct rte *);
139 void (*rte_insert)(struct network *, struct rte *);
140 void (*rte_remove)(struct network *, struct rte *);
141
142 struct rtable *table; /* Our primary routing table */
143 struct filter *in_filter; /* Input filter */
144 struct filter *out_filter; /* Output filter */
145 struct announce_hook *ahooks; /* Announcement hooks for this protocol */
146
147 /* Hic sunt protocol-specific data */
148 };
149
150 void proto_build(struct proto_config *);
151 void *proto_new(struct proto_config *, unsigned size);
152 void *proto_config_new(struct protocol *, unsigned size);
153 void proto_show(struct symbol *, int);
154
155 extern list proto_list;
156
157 /*
158 * Each protocol instance runs two different state machines:
159 *
160 * [P] The protocol machine: (implemented inside protocol)
161 *
162 * DOWN ----> START
163 * ^ |
164 * | V
165 * STOP <---- UP
166 *
167 * States: DOWN Protocol is down and it's waiting for the core
168 * requesting protocol start.
169 * START Protocol is waiting for connection with the rest
170 * of the network and it's not willing to accept
171 * packets. When it connects, it goes to UP state.
172 * UP Protocol is up and running. When the network
173 * connection breaks down or the core requests
174 * protocol to be terminated, it goes to STOP state.
175 * STOP Protocol is disconnecting from the network.
176 * After it disconnects, it returns to DOWN state.
177 *
178 * In: start() Called in DOWN state to request protocol startup.
179 * Returns new state: either UP or START (in this
180 * case, the protocol will notify the core when it
181 * finally comes UP).
182 * stop() Called in START, UP or STOP state to request
183 * protocol shutdown. Returns new state: either
184 * DOWN or STOP (in this case, the protocol will
185 * notify the core when it finally comes DOWN).
186 *
187 * Out: proto_notify_state() -- called by protocol instance when
188 * it does any state transition not covered by
189 * return values of start() and stop(). This includes
190 * START->UP (delayed protocol startup), UP->STOP
191 * (spontaneous shutdown) and STOP->DOWN (delayed
192 * shutdown).
193 */
194
195 #define PS_DOWN 0
196 #define PS_START 1
197 #define PS_UP 2
198 #define PS_STOP 3
199
200 void proto_notify_state(struct proto *p, unsigned state);
201
202 /*
203 * [F] The feeder machine: (implemented in core routines)
204 *
205 * HUNGRY ----> FEEDING
206 * ^ |
207 * | V
208 * FLUSHING <---- HAPPY
209 *
210 * States: HUNGRY Protocol either administratively down (i.e.,
211 * disabled by the user) or temporarily down
212 * (i.e., [P] is not UP)
213 * FEEDING The protocol came up and we're feeding it
214 * initial routes. [P] is UP.
215 * HAPPY The protocol is up and it's receiving normal
216 * routing updates. [P] is UP.
217 * FLUSHING The protocol is down and we're removing its
218 * routes from the table. [P] is STOP or DOWN.
219 *
220 * Normal lifecycle of a protocol looks like:
221 *
222 * HUNGRY/DOWN --> HUNGRY/START --> HUNGRY/UP -->
223 * FEEDING/UP --> HAPPY/UP --> FLUSHING/STOP|DOWN -->
224 * HUNGRY/STOP|DOWN --> HUNGRY/DOWN
225 */
226
227 #define FS_HUNGRY 0
228 #define FS_FEEDING 1
229 #define FS_HAPPY 2
230 #define FS_FLUSHING 3
231
232 /*
233 * Known unique protocol instances as referenced by config routines
234 */
235
236 extern struct proto_config *cf_dev_proto;
237
238 /*
239 * Route Announcement Hook
240 */
241
242 struct announce_hook {
243 node n;
244 struct rtable *table;
245 struct proto *proto;
246 struct announce_hook *next; /* Next hook for the same protocol */
247 };
248
249 struct announce_hook *proto_add_announce_hook(struct proto *, struct rtable *);
250
251 /*
252 * Callback to sysdep code when shutdown is finished
253 */
254
255 void protos_shutdown_notify(void);
256
257 #endif