]>
git.ipfire.org Git - thirdparty/bird.git/blob - nest/protocol.h
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"
32 unsigned debug
; /* Default debugging flags */
33 int priority
; /* Protocol priority (usually 0) */
34 int name_counter
; /* Counter for automatic name generation */
36 void (*preconfig
)(struct protocol
*, struct config
*); /* Just before configuring */
37 void (*postconfig
)(struct proto_config
*); /* After configuring each instance */
38 struct proto
* (*init
)(struct proto_config
*); /* Create new instance */
39 int (*reconfigure
)(struct proto
*, struct proto_config
*); /* Try to reconfigure instance */
40 void (*dump
)(struct proto
*); /* Debugging dump */
41 void (*dump_attrs
)(struct rte
*); /* Dump protocol-dependent attributes */
42 int (*start
)(struct proto
*); /* Start the instance */
43 int (*shutdown
)(struct proto
*); /* Stop the instance */
46 void protos_build(void);
47 void protos_preconfig(struct config
*);
48 void protos_postconfig(struct config
*);
49 void protos_commit(struct config
*);
50 void protos_start(void);
51 void protos_dump_all(void);
52 void protos_shutdown(void);
54 extern list protocol_list
;
60 extern struct protocol proto_device
;
61 extern struct protocol proto_rip
;
62 extern struct protocol proto_static
;
63 extern struct protocol proto_ospf
;
66 * Routing Protocol Instance
71 struct config
*global
; /* Global configuration data */
72 struct protocol
*proto
; /* Protocol */
74 unsigned debug
, preference
, disabled
; /* Generic parameters */
75 struct filter
*in_filter
, *out_filter
; /* Attached filters */
77 /* Protocol-specific data follow... */
82 struct protocol
*proto
; /* Protocol */
83 struct proto_config
*cf
; /* Configuration data */
84 pool
*pool
; /* Pool containing local objects */
85 struct event
*attn
; /* "Pay attention" event */
87 char *name
; /* Name of this instance (== cf->name) */
88 unsigned debug
; /* Debugging flags */
89 unsigned preference
; /* Default route preference */
90 unsigned disabled
; /* Manually disabled */
91 unsigned proto_state
; /* Protocol state machine (see below) */
92 unsigned core_state
; /* Core state machine (see below) */
93 unsigned core_goal
; /* State we want to reach (see below) */
95 void (*if_notify
)(struct proto
*, unsigned flags
, struct iface
*new, struct iface
*old
);
96 void (*rt_notify
)(struct proto
*, struct network
*net
, struct rte
*new, struct rte
*old
);
97 void (*neigh_notify
)(struct neighbor
*neigh
);
99 int (*rte_better
)(struct rte
*, struct rte
*);
100 void (*rte_insert
)(struct network
*, struct rte
*);
101 void (*rte_remove
)(struct network
*, struct rte
*);
103 struct rtable
*table
; /* Routing table we're connected to */
104 struct filter
*in_filter
; /* Input filter */
105 struct filter
*out_filter
; /* Output filter */
107 /* Hic sunt protocol-specific data */
110 void proto_build(struct proto_config
*);
111 void *proto_new(struct proto_config
*, unsigned size
);
112 void *proto_config_new(struct protocol
*, unsigned size
);
114 extern list proto_list
;
117 * Each protocol instance runs two different state machines:
119 * [P] The protocol machine: (implemented inside protocol)
126 * States: DOWN Protocol is down and it's waiting for the core
127 * requesting protocol start.
128 * START Protocol is waiting for connection with the rest
129 * of the network and it's not willing to accept
130 * packets. When it connects, it goes to UP state.
131 * UP Protocol is up and running. When the network
132 * connection breaks down or the core requests
133 * protocol to be terminated, it goes to STOP state.
134 * STOP Protocol is disconnecting from the network.
135 * After it disconnects, it returns to DOWN state.
137 * In: start() Called in DOWN state to request protocol startup.
138 * Returns new state: either UP or START (in this
139 * case, the protocol will notify the core when it
141 * stop() Called in START, UP or STOP state to request
142 * protocol shutdown. Returns new state: either
143 * DOWN or STOP (in this case, the protocol will
144 * notify the core when it finally comes DOWN).
146 * Out: proto_notify_state() -- called by protocol instance when
147 * it does any state transition not covered by
148 * return values of start() and stop(). This includes
149 * START->UP (delayed protocol startup), UP->STOP
150 * (spontaneous shutdown) and STOP->DOWN (delayed
159 void proto_notify_state(struct proto
*p
, unsigned state
);
162 * [F] The feeder machine: (implemented in core routines)
164 * HUNGRY ----> FEEDING
167 * FLUSHING <---- HAPPY
169 * States: HUNGRY Protocol either administratively down (i.e.,
170 * disabled by the user) or temporarily down
171 * (i.e., [P] is not UP)
172 * FEEDING The protocol came up and we're feeding it
173 * initial routes. [P] is UP.
174 * HAPPY The protocol is up and it's receiving normal
175 * routing updates. [P] is UP.
176 * FLUSHING The protocol is down and we're removing its
177 * routes from the table. [P] is STOP or DOWN.
179 * Normal lifecycle of a protocol looks like:
181 * HUNGRY/DOWN --> HUNGRY/START --> HUNGRY/UP -->
182 * FEEDING/UP --> HAPPY/UP --> FLUSHING/STOP|DOWN -->
183 * HUNGRY/STOP|DOWN --> HUNGRY/DOWN
189 #define FS_FLUSHING 3
192 * Known unique protocol instances as referenced by config routines
195 extern struct proto_config
*cf_dev_proto
;
198 * Callback to sysdep code when shutdown is finished
201 void protos_shutdown_notify(void);