2 * BIRD Internet Routing Daemon -- Protocols
4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
9 #ifndef _BIRD_PROTOCOL_H_
10 #define _BIRD_PROTOCOL_H_
12 #include "lib/lists.h"
13 #include "lib/resource.h"
14 #include "lib/timer.h"
15 #include "conf/conf.h"
39 char *template; /* Template for automatic generation of names */
40 int name_counter
; /* Counter for automatic name generation */
41 int attr_class
; /* Attribute class known to this protocol */
43 void (*preconfig
)(struct protocol
*, struct config
*); /* Just before configuring */
44 void (*postconfig
)(struct proto_config
*); /* After configuring each instance */
45 struct proto
* (*init
)(struct proto_config
*); /* Create new instance */
46 int (*reconfigure
)(struct proto
*, struct proto_config
*); /* Try to reconfigure instance, returns success */
47 void (*dump
)(struct proto
*); /* Debugging dump */
48 void (*dump_attrs
)(struct rte
*); /* Dump protocol-dependent attributes */
49 int (*start
)(struct proto
*); /* Start the instance */
50 int (*shutdown
)(struct proto
*); /* Stop the instance */
51 void (*get_status
)(struct proto
*, byte
*buf
); /* Get instance status (for `show protocols' command) */
52 void (*get_route_info
)(struct rte
*, byte
*buf
, struct ea_list
*attrs
); /* Get route information (for `show route' command) */
53 int (*get_attr
)(struct eattr
*, byte
*buf
, int buflen
); /* ASCIIfy dynamic attribute (returns GA_*) */
56 void protos_build(void);
57 void proto_build(struct protocol
*);
58 void protos_preconfig(struct config
*);
59 void protos_postconfig(struct config
*);
60 void protos_commit(struct config
*new, struct config
*old
, int force_restart
, int type
);
61 void protos_dump_all(void);
63 #define GA_UNKNOWN 0 /* Attribute not recognized */
64 #define GA_NAME 1 /* Result = name */
65 #define GA_FULL 2 /* Result = both name and value */
71 extern struct protocol
72 proto_device
, proto_rip
, proto_static
,
73 proto_ospf
, proto_pipe
, proto_bgp
;
76 * Routing Protocol Instance
81 struct config
*global
; /* Global configuration data */
82 struct protocol
*protocol
; /* Protocol */
83 struct proto
*proto
; /* Instance we've created */
86 u32 debug
, mrtdump
; /* Debugging bitfields, both use D_* constants */
87 unsigned preference
, disabled
; /* Generic parameters */
88 u32 router_id
; /* Protocol specific router ID */
89 struct rtable_config
*table
; /* Table we're attached to */
90 struct filter
*in_filter
, *out_filter
; /* Attached filters */
92 /* Protocol-specific data follow... */
95 /* Protocol statistics */
97 /* Import - from protocol to core */
98 u32 imp_routes
; /* Number of routes successfully imported to the (adjacent) routing table */
99 u32 pref_routes
; /* Number of routes that are preferred, sum over all routing table */
100 u32 imp_updates_received
; /* Number of route updates received */
101 u32 imp_updates_invalid
; /* Number of route updates rejected as invalid */
102 u32 imp_updates_filtered
; /* Number of route updates rejected by filters */
103 u32 imp_updates_ignored
; /* Number of route updates rejected as already in route table */
104 u32 imp_updates_accepted
; /* Number of route updates accepted and imported */
105 u32 imp_withdraws_received
; /* Number of route withdraws received */
106 u32 imp_withdraws_invalid
; /* Number of route withdraws rejected as invalid */
107 u32 imp_withdraws_ignored
; /* Number of route withdraws rejected as already not in route table */
108 u32 imp_withdraws_accepted
; /* Number of route withdraws accepted and processed */
110 /* Export - from core to protocol */
111 u32 exp_routes
; /* Number of routes successfully exported to the protocol */
112 u32 exp_updates_received
; /* Number of route updates received */
113 u32 exp_updates_rejected
; /* Number of route updates rejected by protocol */
114 u32 exp_updates_filtered
; /* Number of route updates rejected by filters */
115 u32 exp_updates_accepted
; /* Number of route updates accepted and exported */
116 u32 exp_withdraws_received
; /* Number of route withdraws received */
117 u32 exp_withdraws_accepted
; /* Number of route withdraws accepted and processed */
121 node n
; /* Node in *_proto_list */
122 node glob_node
; /* Node in global proto_list */
123 struct protocol
*proto
; /* Protocol */
124 struct proto_config
*cf
; /* Configuration data */
125 struct proto_config
*cf_new
; /* Configuration we want to switch to after shutdown (NULL=delete) */
126 pool
*pool
; /* Pool containing local objects */
127 struct event
*attn
; /* "Pay attention" event */
129 char *name
; /* Name of this instance (== cf->name) */
130 u32 debug
; /* Debugging flags */
131 u32 mrtdump
; /* MRTDump flags */
132 unsigned preference
; /* Default route preference */
133 int min_scope
; /* Minimal route scope accepted */
134 unsigned accept_ra_types
; /* Which types of route announcements are accepted (RA_OPTIMAL or RA_ANY) */
135 unsigned disabled
; /* Manually disabled */
136 unsigned proto_state
; /* Protocol state machine (see below) */
137 unsigned core_state
; /* Core state machine (see below) */
138 unsigned core_goal
; /* State we want to reach (see below) */
139 unsigned reconfiguring
; /* We're shutting down due to reconfiguration */
140 unsigned refeeding
; /* We are refeeding (valid only if core_state == FS_FEEDING) */
141 u32 hash_key
; /* Random key used for hashing of neighbors */
142 bird_clock_t last_state_change
; /* Time of last state transition */
143 char *last_state_name_announced
; /* Last state name we've announced to the user */
144 struct proto_stats stats
; /* Current protocol statistics */
147 * General protocol hooks:
149 * if_notify Notify protocol about interface state changes.
150 * ifa_notify Notify protocol about interface address changes.
151 * rt_notify Notify protocol about routing table updates.
152 * neigh_notify Notify protocol about neighbor cache events.
153 * make_tmp_attrs Construct ea_list from private attrs stored in rte.
154 * store_tmp_attrs Store private attrs back to the rte.
155 * import_control Called as the first step of the route importing process.
156 * It can construct a new rte, add private attributes and
157 * decide whether the route shall be imported: 1=yes, -1=no,
158 * 0=process it through the import filter set by the user.
159 * reload_routes Request protocol to reload all its routes to the core
160 * (using rte_update()). Returns: 0=reload cannot be done,
161 * 1= reload is scheduled and will happen (asynchronously).
164 void (*if_notify
)(struct proto
*, unsigned flags
, struct iface
*i
);
165 void (*ifa_notify
)(struct proto
*, unsigned flags
, struct ifa
*a
);
166 void (*rt_notify
)(struct proto
*, struct rtable
*table
, struct network
*net
, struct rte
*new, struct rte
*old
, struct ea_list
*attrs
);
167 void (*neigh_notify
)(struct neighbor
*neigh
);
168 struct ea_list
*(*make_tmp_attrs
)(struct rte
*rt
, struct linpool
*pool
);
169 void (*store_tmp_attrs
)(struct rte
*rt
, struct ea_list
*attrs
);
170 int (*import_control
)(struct proto
*, struct rte
**rt
, struct ea_list
**attrs
, struct linpool
*pool
);
171 int (*reload_routes
)(struct proto
*);
174 * Routing entry hooks (called only for rte's belonging to this protocol):
176 * rte_better Compare two rte's and decide which one is better (1=first, 0=second).
177 * rte_same Compare two rte's and decide whether they are identical (1=yes, 0=no).
178 * rte_insert Called whenever a rte is inserted to a routing table.
179 * rte_remove Called whenever a rte is removed from the routing table.
182 int (*rte_better
)(struct rte
*, struct rte
*);
183 int (*rte_same
)(struct rte
*, struct rte
*);
184 void (*rte_insert
)(struct network
*, struct rte
*);
185 void (*rte_remove
)(struct network
*, struct rte
*);
187 struct rtable
*table
; /* Our primary routing table */
188 struct filter
*in_filter
; /* Input filter */
189 struct filter
*out_filter
; /* Output filter */
190 struct announce_hook
*ahooks
; /* Announcement hooks for this protocol */
192 struct fib_iterator
*feed_iterator
; /* Routing table iterator used during protocol feeding */
193 struct announce_hook
*feed_ahook
; /* Announce hook we currently feed */
195 /* Hic sunt protocol-specific data */
204 void *proto_new(struct proto_config
*, unsigned size
);
205 void *proto_config_new(struct protocol
*, unsigned size
);
206 void proto_request_feeding(struct proto
*p
);
208 void proto_cmd_show(struct proto
*, unsigned int, int);
209 void proto_cmd_disable(struct proto
*, unsigned int, int);
210 void proto_cmd_enable(struct proto
*, unsigned int, int);
211 void proto_cmd_restart(struct proto
*, unsigned int, int);
212 void proto_cmd_reload(struct proto
*, unsigned int, int);
213 void proto_cmd_debug(struct proto
*, unsigned int, int);
214 void proto_cmd_mrtdump(struct proto
*, unsigned int, int);
216 void proto_apply_cmd(struct proto_spec ps
, void (* cmd
)(struct proto
*, unsigned int, int), unsigned int arg
);
217 struct proto
*proto_get_named(struct symbol
*, struct protocol
*);
220 #define CMD_RELOAD_IN 1
221 #define CMD_RELOAD_OUT 2
224 proto_get_router_id(struct proto_config
*pc
)
226 return pc
->router_id
? pc
->router_id
: pc
->global
->router_id
;
229 extern list active_proto_list
;
232 * Each protocol instance runs two different state machines:
234 * [P] The protocol machine: (implemented inside protocol)
241 * States: DOWN Protocol is down and it's waiting for the core
242 * requesting protocol start.
243 * START Protocol is waiting for connection with the rest
244 * of the network and it's not willing to accept
245 * packets. When it connects, it goes to UP state.
246 * UP Protocol is up and running. When the network
247 * connection breaks down or the core requests
248 * protocol to be terminated, it goes to STOP state.
249 * STOP Protocol is disconnecting from the network.
250 * After it disconnects, it returns to DOWN state.
252 * In: start() Called in DOWN state to request protocol startup.
253 * Returns new state: either UP or START (in this
254 * case, the protocol will notify the core when it
256 * stop() Called in START, UP or STOP state to request
257 * protocol shutdown. Returns new state: either
258 * DOWN or STOP (in this case, the protocol will
259 * notify the core when it finally comes DOWN).
261 * Out: proto_notify_state() -- called by protocol instance when
262 * it does any state transition not covered by
263 * return values of start() and stop(). This includes
264 * START->UP (delayed protocol startup), UP->STOP
265 * (spontaneous shutdown) and STOP->DOWN (delayed
274 void proto_notify_state(struct proto
*p
, unsigned state
);
277 * [F] The feeder machine: (implemented in core routines)
279 * HUNGRY ----> FEEDING
282 * FLUSHING <---- HAPPY
284 * States: HUNGRY Protocol either administratively down (i.e.,
285 * disabled by the user) or temporarily down
286 * (i.e., [P] is not UP)
287 * FEEDING The protocol came up and we're feeding it
288 * initial routes. [P] is UP.
289 * HAPPY The protocol is up and it's receiving normal
290 * routing updates. [P] is UP.
291 * FLUSHING The protocol is down and we're removing its
292 * routes from the table. [P] is STOP or DOWN.
294 * Normal lifecycle of a protocol looks like:
296 * HUNGRY/DOWN --> HUNGRY/START --> HUNGRY/UP -->
297 * FEEDING/UP --> HAPPY/UP --> FLUSHING/STOP|DOWN -->
298 * HUNGRY/STOP|DOWN --> HUNGRY/DOWN
300 * Sometimes, protocol might switch from HAPPY/UP to FEEDING/UP
301 * if it wants to refeed the routes (for example BGP does so
302 * as a result of received ROUTE-REFRESH request).
308 #define FS_FLUSHING 3
314 #define D_STATES 1 /* [core] State transitions */
315 #define D_ROUTES 2 /* [core] Routes passed by the filters */
316 #define D_FILTERS 4 /* [core] Routes rejected by the filters */
317 #define D_IFACES 8 /* [core] Interface events */
318 #define D_EVENTS 16 /* Protocol events */
319 #define D_PACKETS 32 /* Packets sent/received */
325 #define MD_STATES 1 /* Protocol state changes (BGP4MP_MESSAGE_AS4) */
326 #define MD_MESSAGES 2 /* Protocol packets (BGP4MP_MESSAGE_AS4) */
329 * Known unique protocol instances as referenced by config routines
332 extern struct proto_config
*cf_dev_proto
;
335 * Route Announcement Hook
338 struct announce_hook
{
340 struct rtable
*table
;
342 struct announce_hook
*next
; /* Next hook for the same protocol */
345 struct announce_hook
*proto_add_announce_hook(struct proto
*, struct rtable
*);
348 * Some pipe-specific nest hacks
352 #include "proto/pipe/pipe.h"