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