Statistics
| Branch: | Revision:

iof-bird-daemon / nest / protocol.h @ 9c11ec9e

History | View | Annotate | Download (7.8 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

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

    
27
/*
28
 *        Routing Protocol
29
 */
30

    
31
struct protocol {
32
  node n;
33
  char *name;
34
  unsigned debug;                        /* Default debugging flags */
35
  int priority;                                /* Protocol priority (usually 0) */
36
  int name_counter;                        /* Counter for automatic name generation */
37
  int startup_counter;                        /* Number of instances waiting for initialization */
38

    
39
  void (*preconfig)(struct protocol *, struct config *);        /* Just before configuring */
40
  void (*postconfig)(struct proto_config *);                        /* After configuring each instance */
41
  struct proto * (*init)(struct proto_config *);                /* Create new instance */
42
  int (*reconfigure)(struct proto *, struct proto_config *);        /* Try to reconfigure instance */
43
  void (*dump)(struct proto *);                        /* Debugging dump */
44
  void (*dump_attrs)(struct rte *);                /* Dump protocol-dependent attributes */
45
  int (*start)(struct proto *);                        /* Start the instance */
46
  int (*shutdown)(struct proto *);                /* Stop the instance */
47
};
48

    
49
void protos_build(void);
50
void protos_preconfig(struct config *);
51
void protos_postconfig(struct config *);
52
void protos_commit(struct config *);
53
void protos_start(void);
54
void protos_dump_all(void);
55
void protos_shutdown(void);
56

    
57
extern list protocol_list;
58

    
59
/*
60
 *        Known protocols
61
 */
62

    
63
extern struct protocol proto_device;
64
extern struct protocol proto_rip;
65
extern struct protocol proto_static;
66
extern struct protocol proto_ospf;
67
extern struct protocol proto_pipe;
68

    
69
/*
70
 *        Routing Protocol Instance
71
 */
72

    
73
struct proto_config {
74
  node n;
75
  struct config *global;                /* Global configuration data */
76
  struct protocol *proto;                /* Protocol */
77
  char *name;
78
  unsigned debug, preference, disabled;        /* Generic parameters */
79
  struct rtable_config *table;                /* Table we're attached to */
80
  struct filter *in_filter, *out_filter; /* Attached filters */
81

    
82
  /* Protocol-specific data follow... */
83
};
84

    
85
struct proto {
86
  node n;
87
  struct protocol *proto;                /* Protocol */
88
  struct proto_config *cf;                /* Configuration data */
89
  pool *pool;                                /* Pool containing local objects */
90
  struct event *attn;                        /* "Pay attention" event */
91

    
92
  char *name;                                /* Name of this instance (== cf->name) */
93
  unsigned debug;                        /* Debugging flags */
94
  unsigned preference;                        /* Default route preference */
95
  unsigned disabled;                        /* Manually disabled */
96
  unsigned proto_state;                        /* Protocol state machine (see below) */
97
  unsigned core_state;                        /* Core state machine (see below) */
98
  unsigned core_goal;                        /* State we want to reach (see below) */
99

    
100
  /*
101
   *        General protocol hooks:
102
   *
103
   *           if_notify        Notify protocol about interface state changes.
104
   *           ifa_notify        Notify protocol about interface address changes.
105
   *           rt_notify        Notify protocol about routing table updates.
106
   *           neigh_notify        Notify protocol about neighbor cache events.
107
   *           make_tmp_attrs  Construct ea_list from private attrs stored in rte.
108
   *           store_tmp_attrs Store private attrs back to the rte.
109
   *           import_control  Called as the first step of the route importing process.
110
   *                        It can construct a new rte, add private attributes and
111
   *                        decide whether the route shall be imported: 1=yes, -1=no,
112
   *                        0=process it through the import filter set by the user.
113
   */
114

    
115
  void (*if_notify)(struct proto *, unsigned flags, struct iface *i);
116
  void (*ifa_notify)(struct proto *, unsigned flags, struct ifa *a);
117
  void (*rt_notify)(struct proto *, struct network *net, struct rte *new, struct rte *old, struct ea_list *tmpa);
118
  void (*neigh_notify)(struct neighbor *neigh);
119
  struct ea_list *(*make_tmp_attrs)(struct rte *rt, struct linpool *pool);
120
  void (*store_tmp_attrs)(struct rte *rt, struct ea_list *attrs);
121
  int (*import_control)(struct proto *, struct rte **rt, struct ea_list **attrs, struct linpool *pool);
122

    
123
  /*
124
   *        Routing entry hooks (called only for rte's belonging to this protocol):
125
   *
126
   *           rte_better        Compare two rte's and decide which one is better (1=first, 0=second).
127
   *           rte_insert        Called whenever a rte is inserted to a routing table.
128
   *           rte_remove        Called whenever a rte is removed from the routing table.
129
   */
130

    
131
  int (*rte_better)(struct rte *, struct rte *);
132
  void (*rte_insert)(struct network *, struct rte *);
133
  void (*rte_remove)(struct network *, struct rte *);
134

    
135
  struct rtable *table;                        /* Our primary routing table */
136
  struct filter *in_filter;                /* Input filter */
137
  struct filter *out_filter;                /* Output filter */
138
  struct announce_hook *ahooks;                /* Announcement hooks for this protocol */
139

    
140
  /* Hic sunt protocol-specific data */
141
};
142

    
143
void proto_build(struct proto_config *);
144
void *proto_new(struct proto_config *, unsigned size);
145
void *proto_config_new(struct protocol *, unsigned size);
146

    
147
extern list proto_list;
148

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

    
187
#define PS_DOWN 0
188
#define PS_START 1
189
#define PS_UP 2
190
#define PS_STOP 3
191

    
192
void proto_notify_state(struct proto *p, unsigned state);
193

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

    
219
#define FS_HUNGRY 0
220
#define FS_FEEDING 1
221
#define FS_HAPPY 2
222
#define FS_FLUSHING 3
223

    
224
/*
225
 *        Known unique protocol instances as referenced by config routines
226
 */
227

    
228
extern struct proto_config *cf_dev_proto;
229

    
230
/*
231
 *        Route Announcement Hook
232
 */
233

    
234
struct announce_hook {
235
  node n;
236
  struct rtable *table;
237
  struct proto *proto;
238
  struct announce_hook *next;                /* Next hook for the same protocol */
239
};
240

    
241
struct announce_hook *proto_add_announce_hook(struct proto *, struct rtable *);
242

    
243
/*
244
 *        Callback to sysdep code when shutdown is finished
245
 */
246

    
247
void protos_shutdown_notify(void);
248

    
249
#endif