]> git.ipfire.org Git - thirdparty/bird.git/blob - nest/protocol.h
Added new protocol hook for dumping of protocol-dependent route
[thirdparty/bird.git] / nest / protocol.h
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 rte;
17 struct neighbor;
18 struct rta;
19 struct network;
20 struct proto_config;
21 struct config;
22 struct proto;
23 struct event;
24
25 /*
26 * Routing Protocol
27 */
28
29 struct protocol {
30 node n;
31 char *name;
32 unsigned debug; /* Default debugging flags */
33 int priority; /* Protocol priority (usually 0) */
34 int name_counter; /* Counter for automatic name generation */
35
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 */
44 };
45
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);
53
54 extern list protocol_list;
55
56 /*
57 * Known protocols
58 */
59
60 extern struct protocol proto_device;
61 extern struct protocol proto_rip;
62 extern struct protocol proto_static;
63 extern struct protocol proto_ospf;
64
65 /*
66 * Routing Protocol Instance
67 */
68
69 struct proto_config {
70 node n;
71 struct config *global; /* Global configuration data */
72 struct protocol *proto; /* Protocol */
73 char *name;
74 unsigned debug, preference, disabled; /* Generic parameters */
75 struct filter *in_filter, *out_filter; /* Attached filters */
76
77 /* Protocol-specific data follow... */
78 };
79
80 struct proto {
81 node n;
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 */
86
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) */
94
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);
98
99 int (*rte_better)(struct rte *, struct rte *);
100 void (*rte_insert)(struct network *, struct rte *);
101 void (*rte_remove)(struct network *, struct rte *);
102
103 struct rtable *table; /* Routing table we're connected to */
104 struct filter *in_filter; /* Input filter */
105 struct filter *out_filter; /* Output filter */
106
107 /* Hic sunt protocol-specific data */
108 };
109
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);
113
114 extern list proto_list;
115
116 /*
117 * Each protocol instance runs two different state machines:
118 *
119 * [P] The protocol machine: (implemented inside protocol)
120 *
121 * DOWN ----> START
122 * ^ |
123 * | V
124 * STOP <---- UP
125 *
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.
136 *
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
140 * finally comes UP).
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).
145 *
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
151 * shutdown).
152 */
153
154 #define PS_DOWN 0
155 #define PS_START 1
156 #define PS_UP 2
157 #define PS_STOP 3
158
159 void proto_notify_state(struct proto *p, unsigned state);
160
161 /*
162 * [F] The feeder machine: (implemented in core routines)
163 *
164 * HUNGRY ----> FEEDING
165 * ^ |
166 * | V
167 * FLUSHING <---- HAPPY
168 *
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.
178 *
179 * Normal lifecycle of a protocol looks like:
180 *
181 * HUNGRY/DOWN --> HUNGRY/START --> HUNGRY/UP -->
182 * FEEDING/UP --> HAPPY/UP --> FLUSHING/STOP|DOWN -->
183 * HUNGRY/STOP|DOWN --> HUNGRY/DOWN
184 */
185
186 #define FS_HUNGRY 0
187 #define FS_FEEDING 1
188 #define FS_HAPPY 2
189 #define FS_FLUSHING 3
190
191 /*
192 * Known unique protocol instances as referenced by config routines
193 */
194
195 extern struct proto_config *cf_dev_proto;
196
197 /*
198 * Callback to sysdep code when shutdown is finished
199 */
200
201 void protos_shutdown_notify(void);
202
203 #endif