2 * BIRD Internet Routing Daemon -- Protocols
4 * (c) 1998--1999 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"
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 */
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) */
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);
62 extern list protocol_list
;
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
;
75 * Routing Protocol Instance
80 struct config
*global
; /* Global configuration data */
81 struct protocol
*protocol
; /* Protocol */
82 struct proto
*proto
; /* Instance we've created */
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 */
88 /* Protocol-specific data follow... */
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 */
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 */
108 * General protocol hooks:
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.
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
);
131 * Routing entry hooks (called only for rte's belonging to this protocol):
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.
138 int (*rte_better
)(struct rte
*, struct rte
*);
139 void (*rte_insert
)(struct network
*, struct rte
*);
140 void (*rte_remove
)(struct network
*, struct rte
*);
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 */
147 /* Hic sunt protocol-specific data */
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);
155 extern list proto_list
;
158 * Each protocol instance runs two different state machines:
160 * [P] The protocol machine: (implemented inside protocol)
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.
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
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).
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
200 void proto_notify_state(struct proto
*p
, unsigned state
);
203 * [F] The feeder machine: (implemented in core routines)
205 * HUNGRY ----> FEEDING
208 * FLUSHING <---- HAPPY
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.
220 * Normal lifecycle of a protocol looks like:
222 * HUNGRY/DOWN --> HUNGRY/START --> HUNGRY/UP -->
223 * FEEDING/UP --> HAPPY/UP --> FLUSHING/STOP|DOWN -->
224 * HUNGRY/STOP|DOWN --> HUNGRY/DOWN
230 #define FS_FLUSHING 3
233 * Known unique protocol instances as referenced by config routines
236 extern struct proto_config
*cf_dev_proto
;
239 * Route Announcement Hook
242 struct announce_hook
{
244 struct rtable
*table
;
246 struct announce_hook
*next
; /* Next hook for the same protocol */
249 struct announce_hook
*proto_add_announce_hook(struct proto
*, struct rtable
*);
252 * Callback to sysdep code when shutdown is finished
255 void protos_shutdown_notify(void);