]>
git.ipfire.org Git - thirdparty/bird.git/blob - nest/proto-hooks.c
2 * BIRD -- Documentation for Protocol Hooks (dummy source file)
4 * (c) 2000 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
12 * Each protocol can provide a rich set of hook functions referred to by pointers
13 * in either the &proto or &protocol structure. They are called by the core whenever
14 * it wants the protocol to perform some action or to notify the protocol about
15 * any change of its environment. All of the hooks can be set to %NULL which means
16 * to ignore the change or to take a default action.
20 * preconfig - protocol preconfiguration
21 * @p: a routing protocol
22 * @c: new configuration
24 * The preconfig() hook is called before parsing of a new configuration.
26 void preconfig(struct protocol
*p
, struct config
*c
)
30 * postconfig - instance post-configuration
31 * @c: instance configuration
33 * The postconfig() hook is called for each configured instance after
34 * parsing of the new configuration is finished.
36 void postconfig(struct proto_config
*c
)
40 * init - initialize an instance
41 * @c: instance configuration
43 * The init() hook is called by the core to create a protocol instance
44 * according to supplied protocol configuration.
46 * Result: a pointer to the instance created
48 struct proto
*init(struct proto_config
*c
)
52 * reconfigure - request instance reconfiguration
54 * @c: new configuration
56 * The core calls the reconfigure() hook whenever it wants to ask the
57 * protocol for switching to a new configuration. If the reconfiguration
58 * is possible, the hook returns 1. Otherwise, it returns 0 and the core
59 * will shut down the instance and start a new one with the new configuration.
61 * After the protocol confirms reconfiguration, it must no longer keep any
62 * references to the old configuration since the memory it's stored in can
63 * be re-used at any time.
65 int reconfigure(struct proto
*p
, struct proto_config
*c
)
69 * dump - dump protocol state
72 * This hook dumps the complete state of the instance to the
75 void dump(struct proto
*p
)
79 * dump_attrs - dump protocol-dependent attributes
82 * This hook dumps all attributes in the &rte which belong to this
83 * protocol to the debug output.
85 void dump_attrs(rte
*e
)
89 * start - request instance startup
90 * @p: protocol instance
92 * The start() hook is called by the core when it wishes to start
93 * the instance. Multitable protocols should lock their tables here.
95 * Result: new protocol state
97 int start(struct proto
*p
)
101 * shutdown - request instance shutdown
102 * @p: protocol instance
104 * The stop() hook is called by the core when it wishes to shut
105 * the instance down for some reason.
107 * Returns: new protocol state
109 int shutdown(struct proto
*p
)
113 * cleanup - request instance cleanup
114 * @p: protocol instance
116 * The cleanup() hook is called by the core when the protocol became
117 * hungry/down, i.e. all protocol ahooks and routes are flushed.
118 * Multitable protocols should unlock their tables here.
120 void cleanup(struct proto
*p
)
124 * get_status - get instance status
125 * @p: protocol instance
126 * @buf: buffer to be filled with the status string
128 * This hook is called by the core if it wishes to obtain an brief one-line user friendly
129 * representation of the status of the instance to be printed by the <cf/show protocols/
132 void get_status(struct proto
*p
, byte
*buf
)
136 * get_route_info - get route information
138 * @buf: buffer to be filled with the resulting string
139 * @attrs: extended attributes of the route
141 * This hook is called to fill the buffer @buf with a brief user friendly
142 * representation of metrics of a route belonging to this protocol.
144 void get_route_info(rte
*e
, byte
*buf
, ea_list
*attrs
)
148 * get_attr - get attribute information
149 * @a: an extended attribute
150 * @buf: buffer to be filled with attribute information
152 * The get_attr() hook is called by the core to obtain a user friendly
153 * representation of an extended route attribute. It can either leave
154 * the whole conversion to the core (by returning %GA_UNKNOWN), fill
155 * in only attribute name (and let the core format the attribute value
156 * automatically according to the type field; by returning %GA_NAME)
157 * or doing the whole conversion (used in case the value requires extra
158 * care; return %GA_FULL).
160 int get_attr(eattr
*a
, byte
*buf
, int buflen
)
164 * if_notify - notify instance about interface changes
165 * @p: protocol instance
166 * @flags: interface change flags
167 * @i: the interface in question
169 * This hook is called whenever any network interface changes its status.
170 * The change is described by a combination of status bits (%IF_CHANGE_xxx)
171 * in the @flags parameter.
173 void if_notify(struct proto
*p
, unsigned flags
, struct iface
*i
)
177 * ifa_notify - notify instance about interface address changes
178 * @p: protocol instance
179 * @flags: address change flags
180 * @a: the interface address
182 * This hook is called to notify the protocol instance about an interface
183 * acquiring or losing one of its addresses. The change is described by
184 * a combination of status bits (%IF_CHANGE_xxx) in the @flags parameter.
186 void ifa_notify(struct proto
*p
, unsigned flags
, struct ifa
*a
)
190 * rt_notify - notify instance about routing table change
191 * @p: protocol instance
192 * @table: a routing table
193 * @net: a network entry
194 * @new: new route for the network
195 * @old: old route for the network
196 * @attrs: extended attributes associated with the @new entry
198 * The rt_notify() hook is called to inform the protocol instance about
199 * changes in the connected routing table @table, that is a route @old
200 * belonging to network @net being replaced by a new route @new with
201 * extended attributes @attrs. Either @new or @old or both can be %NULL
202 * if the corresponding route doesn't exist.
204 * If the type of route announcement is RA_OPTIMAL, it is an
205 * announcement of optimal route change, @new stores the new optimal
206 * route and @old stores the old optimal route.
208 * If the type of route announcement is RA_ANY, it is an announcement
209 * of any route change, @new stores the new route and @old stores the
210 * old route from the same protocol.
212 * @p->accept_ra_types specifies which kind of route announcements
213 * protocol wants to receive.
215 void rt_notify(struct proto
*p
, net
*net
, rte
*new, rte
*old
, ea_list
*attrs
)
219 * neigh_notify - notify instance about neighbor status change
220 * @neigh: a neighbor cache entry
222 * The neigh_notify() hook is called by the neighbor cache whenever
223 * a neighbor changes its state, that is it gets disconnected or a
224 * sticky neighbor gets connected.
226 void neigh_notify(neighbor
*neigh
)
230 * make_tmp_attrs - convert embedded attributes to temporary ones
232 * @pool: linear pool to allocate attribute memory in
234 * This hook is called by the routing table functions if they need
235 * to convert the protocol attributes embedded directly in the &rte
236 * to temporary extended attributes in order to distribute them
237 * to other protocols or to filters. make_tmp_attrs() creates
238 * an &ea_list in the linear pool @pool, fills it with values of the
239 * temporary attributes and returns a pointer to it.
241 ea_list
*make_tmp_attrs(rte
*e
, struct linpool
*pool
)
245 * store_tmp_attrs - convert temporary attributes to embedded ones
247 * @attrs: temporary attributes to be converted
249 * This hook is an exact opposite of make_tmp_attrs() -- it takes
250 * a list of extended attributes and converts them to attributes
251 * embedded in the &rte corresponding to this protocol.
253 * You must be prepared for any of the attributes being missing
254 * from the list and use default values instead.
256 void store_tmp_attrs(rte
*e
, ea_list
*attrs
)
260 * import_control - pre-filtering decisions on route import
261 * @p: protocol instance the route is going to be imported to
262 * @e: the route in question
263 * @attrs: extended attributes of the route
264 * @pool: linear pool for allocation of all temporary data
266 * The import_control() hook is called as the first step of a exporting
267 * a route from a routing table to the protocol instance. It can modify
268 * route attributes and force acceptance or rejection of the route regardless
269 * of user-specified filters. See rte_announce() for a complete description
270 * of the route distribution process.
272 * The standard use of this hook is to reject routes having originated
273 * from the same instance and to set default values of the protocol's metrics.
275 * Result: 1 if the route has to be accepted, -1 if rejected and 0 if it
276 * should be passed to the filters.
278 int import_control(struct proto
*p
, rte
**e
, ea_list
**attrs
, struct linpool
*pool
)
282 * rte_recalculate - prepare routes for comparison
283 * @table: a routing table
284 * @net: a network entry
285 * @new: new route for the network
286 * @old: old route for the network
287 * @old_best: old best route for the network (may be NULL)
289 * This hook is called when a route change (from @old to @new for a
290 * @net entry) is propagated to a @table. It may be used to prepare
291 * routes for comparison by rte_better() in the best route
292 * selection. @new may or may not be in @net->routes list,
295 * Result: 1 if the ordering implied by rte_better() changes enough
296 * that full best route calculation have to be done, 0 otherwise.
298 int rte_recalculate(struct rtable
*table
, struct network
*net
, struct rte
*new, struct rte
*old
, struct rte
*old_best
)
302 * rte_better - compare metrics of two routes
303 * @new: the new route
304 * @old: the original route
306 * This hook gets called when the routing table contains two routes
307 * for the same network which have originated from different instances
308 * of a single protocol and it wants to select which one is preferred
309 * over the other one. Protocols usually decide according to route metrics.
311 * Result: 1 if @new is better (more preferred) than @old, 0 otherwise.
313 int rte_better(rte
*new, rte
*old
)
317 * rte_same - compare two routes
321 * The rte_same() hook tests whether the routes @e1 and @e2 belonging
322 * to the same protocol instance have identical contents. Contents of
323 * &rta, all the extended attributes and &rte preference are checked
324 * by the core code, no need to take care of them here.
326 * Result: 1 if @e1 is identical to @e2, 0 otherwise.
328 int rte_same(rte
*e1
, rte
*e2
)
332 * rte_insert - notify instance about route insertion
336 * This hook is called whenever a &rte belonging to the instance
337 * is accepted for insertion to a routing table.
339 * Please avoid using this function in new protocols.
341 void rte_insert(net
*n
, rte
*e
)
345 * rte_remove - notify instance about route removal
349 * This hook is called whenever a &rte belonging to the instance
350 * is removed from a routing table.
352 * Please avoid using this function in new protocols.
354 void rte_remove(net
*n
, rte
*e
)