]> git.ipfire.org Git - thirdparty/bird.git/blame - nest/protocol.h
Renamed command `shutdown' to `down', so that `s' can be used as an
[thirdparty/bird.git] / nest / protocol.h
CommitLineData
58ef912c
MM
1/*
2 * BIRD Internet Routing Daemon -- Protocols
3 *
7293c5dd 4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
58ef912c
MM
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
2326b001 12#include "lib/lists.h"
1feea03e 13#include "lib/resource.h"
9685deb9 14#include "lib/timer.h"
58ef912c 15
2326b001 16struct iface;
9a158361 17struct ifa;
2326b001
MM
18struct rte;
19struct neighbor;
1b769b08 20struct rta;
8c43696d 21struct network;
31b3e1bb
MM
22struct proto_config;
23struct config;
24struct proto;
64011f89 25struct event;
bb027be1 26struct ea_list;
ae97b946 27struct symbol;
2326b001 28
58ef912c
MM
29/*
30 * Routing Protocol
31 */
32
33struct protocol {
a5f1a60e 34 node n;
58ef912c 35 char *name;
d272fe22 36 char *template; /* Template for automatic generation of names */
58ef912c 37 unsigned debug; /* Default debugging flags */
4ba84ebc 38 int name_counter; /* Counter for automatic name generation */
58ef912c 39
31b3e1bb
MM
40 void (*preconfig)(struct protocol *, struct config *); /* Just before configuring */
41 void (*postconfig)(struct proto_config *); /* After configuring each instance */
42 struct proto * (*init)(struct proto_config *); /* Create new instance */
50fe90ed 43 int (*reconfigure)(struct proto *, struct proto_config *); /* Try to reconfigure instance, returns success */
31b3e1bb 44 void (*dump)(struct proto *); /* Debugging dump */
69ec9087 45 void (*dump_attrs)(struct rte *); /* Dump protocol-dependent attributes */
31b3e1bb
MM
46 int (*start)(struct proto *); /* Start the instance */
47 int (*shutdown)(struct proto *); /* Stop the instance */
9685deb9 48 void (*get_status)(struct proto *, byte *buf); /* Get instance status (for `show protocols' command) */
04a60c68
MM
49 void (*get_route_info)(struct rte *, byte *buf); /* Get route information (for `show route' command) */
50 void (*show_route_data)(struct rte *); /* Print verbose route information (`show route' again) */
58ef912c
MM
51};
52
0432c017 53void protos_build(void);
31b3e1bb
MM
54void protos_preconfig(struct config *);
55void protos_postconfig(struct config *);
50fe90ed 56void protos_commit(struct config *new, struct config *old, int force_restart);
87d2be86 57void protos_dump_all(void);
a5f1a60e
MM
58
59extern list protocol_list;
58ef912c
MM
60
61/*
62 * Known protocols
63 */
64
a5f1a60e 65extern struct protocol proto_device;
87d2be86 66extern struct protocol proto_rip;
a1bf6440 67extern struct protocol proto_static;
c1f8dc91 68extern struct protocol proto_ospf;
9c11ec9e 69extern struct protocol proto_pipe;
58ef912c
MM
70
71/*
72 * Routing Protocol Instance
73 */
74
31b3e1bb
MM
75struct proto_config {
76 node n;
77 struct config *global; /* Global configuration data */
1d2664a4
MM
78 struct protocol *protocol; /* Protocol */
79 struct proto *proto; /* Instance we've created */
31b3e1bb
MM
80 char *name;
81 unsigned debug, preference, disabled; /* Generic parameters */
0e02abfd 82 struct rtable_config *table; /* Table we're attached to */
529c4149 83 struct filter *in_filter, *out_filter; /* Attached filters */
31b3e1bb
MM
84
85 /* Protocol-specific data follow... */
86};
87
58ef912c 88struct proto {
f14a4bec
MM
89 node n; /* Node in *_proto_list */
90 node glob_node; /* Node in global proto_list */
58ef912c 91 struct protocol *proto; /* Protocol */
31b3e1bb 92 struct proto_config *cf; /* Configuration data */
50fe90ed 93 struct proto_config *cf_new; /* Configuration we want to switch to after shutdown (NULL=delete) */
31b3e1bb 94 pool *pool; /* Pool containing local objects */
64011f89 95 struct event *attn; /* "Pay attention" event */
31b3e1bb 96
64011f89 97 char *name; /* Name of this instance (== cf->name) */
58ef912c 98 unsigned debug; /* Debugging flags */
58ef912c 99 unsigned preference; /* Default route preference */
0da472d7 100 int min_scope; /* Minimal route scope accepted */
bd5d0d62 101 unsigned disabled; /* Manually disabled */
31b3e1bb
MM
102 unsigned proto_state; /* Protocol state machine (see below) */
103 unsigned core_state; /* Core state machine (see below) */
64011f89 104 unsigned core_goal; /* State we want to reach (see below) */
50fe90ed 105 unsigned reconfiguring; /* We're shutting down due to reconfiguration */
7293c5dd 106 u32 hash_key; /* Random key used for hashing of neighbors */
9685deb9 107 bird_clock_t last_state_change; /* Time of last state transition */
58ef912c 108
9e0e485e
MM
109 /*
110 * General protocol hooks:
111 *
112 * if_notify Notify protocol about interface state changes.
9a158361 113 * ifa_notify Notify protocol about interface address changes.
9e0e485e
MM
114 * rt_notify Notify protocol about routing table updates.
115 * neigh_notify Notify protocol about neighbor cache events.
116 * make_tmp_attrs Construct ea_list from private attrs stored in rte.
117 * store_tmp_attrs Store private attrs back to the rte.
118 * import_control Called as the first step of the route importing process.
119 * It can construct a new rte, add private attributes and
120 * decide whether the route shall be imported: 1=yes, -1=no,
121 * 0=process it through the import filter set by the user.
122 */
123
9a158361
MM
124 void (*if_notify)(struct proto *, unsigned flags, struct iface *i);
125 void (*ifa_notify)(struct proto *, unsigned flags, struct ifa *a);
bb027be1 126 void (*rt_notify)(struct proto *, struct network *net, struct rte *new, struct rte *old, struct ea_list *tmpa);
4cc78c50 127 void (*neigh_notify)(struct neighbor *neigh);
9e0e485e
MM
128 struct ea_list *(*make_tmp_attrs)(struct rte *rt, struct linpool *pool);
129 void (*store_tmp_attrs)(struct rte *rt, struct ea_list *attrs);
130 int (*import_control)(struct proto *, struct rte **rt, struct ea_list **attrs, struct linpool *pool);
131
132 /*
133 * Routing entry hooks (called only for rte's belonging to this protocol):
134 *
135 * rte_better Compare two rte's and decide which one is better (1=first, 0=second).
136 * rte_insert Called whenever a rte is inserted to a routing table.
137 * rte_remove Called whenever a rte is removed from the routing table.
138 */
58ef912c 139
2326b001 140 int (*rte_better)(struct rte *, struct rte *);
acc62f5e
MM
141 void (*rte_insert)(struct network *, struct rte *);
142 void (*rte_remove)(struct network *, struct rte *);
2326b001 143
0e02abfd 144 struct rtable *table; /* Our primary routing table */
529c4149
MM
145 struct filter *in_filter; /* Input filter */
146 struct filter *out_filter; /* Output filter */
0e02abfd 147 struct announce_hook *ahooks; /* Announcement hooks for this protocol */
529c4149 148
58ef912c
MM
149 /* Hic sunt protocol-specific data */
150};
151
31b3e1bb
MM
152void proto_build(struct proto_config *);
153void *proto_new(struct proto_config *, unsigned size);
154void *proto_config_new(struct protocol *, unsigned size);
f14a4bec 155
0d3e6bce 156void proto_show(struct symbol *, int);
02c1fbdd 157struct proto *proto_get_named(struct symbol *, struct protocol *);
f14a4bec 158void proto_xxable(char *, int);
58ef912c 159
f14a4bec 160extern list active_proto_list;
2326b001 161
31b3e1bb
MM
162/*
163 * Each protocol instance runs two different state machines:
164 *
165 * [P] The protocol machine: (implemented inside protocol)
166 *
167 * DOWN ----> START
168 * ^ |
169 * | V
170 * STOP <---- UP
171 *
172 * States: DOWN Protocol is down and it's waiting for the core
173 * requesting protocol start.
174 * START Protocol is waiting for connection with the rest
175 * of the network and it's not willing to accept
176 * packets. When it connects, it goes to UP state.
177 * UP Protocol is up and running. When the network
178 * connection breaks down or the core requests
179 * protocol to be terminated, it goes to STOP state.
180 * STOP Protocol is disconnecting from the network.
181 * After it disconnects, it returns to DOWN state.
182 *
183 * In: start() Called in DOWN state to request protocol startup.
184 * Returns new state: either UP or START (in this
185 * case, the protocol will notify the core when it
186 * finally comes UP).
187 * stop() Called in START, UP or STOP state to request
188 * protocol shutdown. Returns new state: either
189 * DOWN or STOP (in this case, the protocol will
190 * notify the core when it finally comes DOWN).
191 *
192 * Out: proto_notify_state() -- called by protocol instance when
193 * it does any state transition not covered by
194 * return values of start() and stop(). This includes
195 * START->UP (delayed protocol startup), UP->STOP
196 * (spontaneous shutdown) and STOP->DOWN (delayed
197 * shutdown).
198 */
199
200#define PS_DOWN 0
201#define PS_START 1
202#define PS_UP 2
203#define PS_STOP 3
204
205void proto_notify_state(struct proto *p, unsigned state);
206
207/*
208 * [F] The feeder machine: (implemented in core routines)
209 *
210 * HUNGRY ----> FEEDING
211 * ^ |
212 * | V
213 * FLUSHING <---- HAPPY
214 *
215 * States: HUNGRY Protocol either administratively down (i.e.,
216 * disabled by the user) or temporarily down
217 * (i.e., [P] is not UP)
218 * FEEDING The protocol came up and we're feeding it
219 * initial routes. [P] is UP.
220 * HAPPY The protocol is up and it's receiving normal
221 * routing updates. [P] is UP.
222 * FLUSHING The protocol is down and we're removing its
223 * routes from the table. [P] is STOP or DOWN.
224 *
225 * Normal lifecycle of a protocol looks like:
226 *
227 * HUNGRY/DOWN --> HUNGRY/START --> HUNGRY/UP -->
228 * FEEDING/UP --> HAPPY/UP --> FLUSHING/STOP|DOWN -->
229 * HUNGRY/STOP|DOWN --> HUNGRY/DOWN
230 */
231
232#define FS_HUNGRY 0
233#define FS_FEEDING 1
234#define FS_HAPPY 2
235#define FS_FLUSHING 3
236
50d8424a
MM
237/*
238 * Known unique protocol instances as referenced by config routines
239 */
240
31b3e1bb 241extern struct proto_config *cf_dev_proto;
50d8424a 242
0e02abfd
MM
243/*
244 * Route Announcement Hook
245 */
246
247struct announce_hook {
248 node n;
249 struct rtable *table;
250 struct proto *proto;
251 struct announce_hook *next; /* Next hook for the same protocol */
252};
253
254struct announce_hook *proto_add_announce_hook(struct proto *, struct rtable *);
255
58ef912c 256#endif