Statistics
| Branch: | Revision:

iof-bird-daemon / nest / protocol.h @ 02c1fbdd

History | View | Annotate | Download (8.37 KB)

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
#include "lib/timer.h"
15

    
16
struct iface;
17
struct ifa;
18
struct rte;
19
struct neighbor;
20
struct rta;
21
struct network;
22
struct proto_config;
23
struct config;
24
struct proto;
25
struct event;
26
struct ea_list;
27
struct symbol;
28

    
29
/*
30
 *        Routing Protocol
31
 */
32

    
33
struct protocol {
34
  node n;
35
  char *name;
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 */
40

    
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) */
52
};
53

    
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);
61

    
62
extern list protocol_list;
63

    
64
/*
65
 *        Known protocols
66
 */
67

    
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;
73

    
74
/*
75
 *        Routing Protocol Instance
76
 */
77

    
78
struct proto_config {
79
  node n;
80
  struct config *global;                /* Global configuration data */
81
  struct protocol *protocol;                /* Protocol */
82
  struct proto *proto;                        /* Instance we've created */
83
  char *name;
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 */
87

    
88
  /* Protocol-specific data follow... */
89
};
90

    
91
struct proto {
92
  node n;
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 */
97

    
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 */
106

    
107
  /*
108
   *        General protocol hooks:
109
   *
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.
120
   */
121

    
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);
129

    
130
  /*
131
   *        Routing entry hooks (called only for rte's belonging to this protocol):
132
   *
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.
136
   */
137

    
138
  int (*rte_better)(struct rte *, struct rte *);
139
  void (*rte_insert)(struct network *, struct rte *);
140
  void (*rte_remove)(struct network *, struct rte *);
141

    
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 */
146

    
147
  /* Hic sunt protocol-specific data */
148
};
149

    
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);
154
struct proto *proto_get_named(struct symbol *, struct protocol *);
155

    
156
extern list proto_list;
157

    
158
/*
159
 *  Each protocol instance runs two different state machines:
160
 *
161
 *  [P] The protocol machine: (implemented inside protocol)
162
 *
163
 *                DOWN    ---->    START
164
 *                  ^                   |
165
 *                  |                   V
166
 *                STOP    <----     UP
167
 *
168
 *        States:        DOWN        Protocol is down and it's waiting for the core
169
 *                        requesting protocol start.
170
 *                START        Protocol is waiting for connection with the rest
171
 *                        of the network and it's not willing to accept
172
 *                        packets. When it connects, it goes to UP state.
173
 *                UP        Protocol is up and running. When the network
174
 *                        connection breaks down or the core requests
175
 *                        protocol to be terminated, it goes to STOP state.
176
 *                STOP        Protocol is disconnecting from the network.
177
 *                        After it disconnects, it returns to DOWN state.
178
 *
179
 *        In:        start()        Called in DOWN state to request protocol startup.
180
 *                        Returns new state: either UP or START (in this
181
 *                        case, the protocol will notify the core when it
182
 *                        finally comes UP).
183
 *                stop()        Called in START, UP or STOP state to request
184
 *                        protocol shutdown. Returns new state: either
185
 *                        DOWN or STOP (in this case, the protocol will
186
 *                        notify the core when it finally comes DOWN).
187
 *
188
 *        Out:        proto_notify_state() -- called by protocol instance when
189
 *                        it does any state transition not covered by
190
 *                        return values of start() and stop(). This includes
191
 *                        START->UP (delayed protocol startup), UP->STOP
192
 *                        (spontaneous shutdown) and STOP->DOWN (delayed
193
 *                        shutdown).
194
 */
195

    
196
#define PS_DOWN 0
197
#define PS_START 1
198
#define PS_UP 2
199
#define PS_STOP 3
200

    
201
void proto_notify_state(struct proto *p, unsigned state);
202

    
203
/*
204
 *  [F] The feeder machine: (implemented in core routines)
205
 *
206
 *                HUNGRY    ---->   FEEDING
207
 *                 ^                     |
208
 *                 |                      V
209
 *                FLUSHING  <----   HAPPY
210
 *
211
 *        States:        HUNGRY        Protocol either administratively down (i.e.,
212
 *                        disabled by the user) or temporarily down
213
 *                        (i.e., [P] is not UP)
214
 *                FEEDING        The protocol came up and we're feeding it
215
 *                        initial routes. [P] is UP.
216
 *                HAPPY        The protocol is up and it's receiving normal
217
 *                        routing updates. [P] is UP.
218
 *                FLUSHING The protocol is down and we're removing its
219
 *                        routes from the table. [P] is STOP or DOWN.
220
 *
221
 *        Normal lifecycle of a protocol looks like:
222
 *
223
 *                HUNGRY/DOWN --> HUNGRY/START --> HUNGRY/UP -->
224
 *                FEEDING/UP --> HAPPY/UP --> FLUSHING/STOP|DOWN -->
225
 *                HUNGRY/STOP|DOWN --> HUNGRY/DOWN
226
 */
227

    
228
#define FS_HUNGRY 0
229
#define FS_FEEDING 1
230
#define FS_HAPPY 2
231
#define FS_FLUSHING 3
232

    
233
/*
234
 *        Known unique protocol instances as referenced by config routines
235
 */
236

    
237
extern struct proto_config *cf_dev_proto;
238

    
239
/*
240
 *        Route Announcement Hook
241
 */
242

    
243
struct announce_hook {
244
  node n;
245
  struct rtable *table;
246
  struct proto *proto;
247
  struct announce_hook *next;                /* Next hook for the same protocol */
248
};
249

    
250
struct announce_hook *proto_add_announce_hook(struct proto *, struct rtable *);
251

    
252
/*
253
 *        Callback to sysdep code when shutdown is finished
254
 */
255

    
256
void protos_shutdown_notify(void);
257

    
258
#endif