Statistics
| Branch: | Revision:

iof-bird-daemon / nest / protocol.h @ ce1da96e

History | View | Annotate | Download (9.23 KB)

1
/*
2
 *        BIRD Internet Routing Daemon -- Protocols
3
 *
4
 *        (c) 1998--2000 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 eattr;
28
struct symbol;
29

    
30
/*
31
 *        Routing Protocol
32
 */
33

    
34
struct protocol {
35
  node n;
36
  char *name;
37
  char *template;                        /* Template for automatic generation of names */
38
  int name_counter;                        /* Counter for automatic name generation */
39
  int attr_class;                        /* Attribute class known to this protocol */
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, returns success */
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, struct ea_list *attrs); /* Get route information (for `show route' command) */
51
  int (*get_attr)(struct eattr *, byte *buf);        /* ASCIIfy dynamic attribute (returns GA_*) */
52
};
53

    
54
void protos_build(void);
55
void proto_build(struct protocol *);
56
void protos_preconfig(struct config *);
57
void protos_postconfig(struct config *);
58
void protos_commit(struct config *new, struct config *old, int force_restart);
59
void protos_dump_all(void);
60

    
61
#define GA_UNKNOWN        0                /* Attribute not recognized */
62
#define GA_NAME                1                /* Result = name */
63
#define GA_FULL                2                /* Result = both name and value */
64

    
65
/*
66
 *        Known protocols
67
 */
68

    
69
extern struct protocol
70
  proto_device, proto_rip, proto_static,
71
  proto_ospf, proto_pipe, proto_bgp;
72

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

    
77
struct proto_config {
78
  node n;
79
  struct config *global;                /* Global configuration data */
80
  struct protocol *protocol;                /* Protocol */
81
  struct proto *proto;                        /* Instance we've created */
82
  char *name;
83
  unsigned debug, preference, disabled;        /* Generic parameters */
84
  struct rtable_config *table;                /* Table we're attached to */
85
  struct filter *in_filter, *out_filter; /* Attached filters */
86

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

    
90
struct proto {
91
  node n;                                /* Node in *_proto_list */
92
  node glob_node;                        /* Node in global proto_list */
93
  struct protocol *proto;                /* Protocol */
94
  struct proto_config *cf;                /* Configuration data */
95
  struct proto_config *cf_new;                /* Configuration we want to switch to after shutdown (NULL=delete) */
96
  pool *pool;                                /* Pool containing local objects */
97
  struct event *attn;                        /* "Pay attention" event */
98

    
99
  char *name;                                /* Name of this instance (== cf->name) */
100
  unsigned debug;                        /* Debugging flags */
101
  unsigned preference;                        /* Default route preference */
102
  int min_scope;                        /* Minimal route scope accepted */
103
  unsigned disabled;                        /* Manually disabled */
104
  unsigned proto_state;                        /* Protocol state machine (see below) */
105
  unsigned core_state;                        /* Core state machine (see below) */
106
  unsigned core_goal;                        /* State we want to reach (see below) */
107
  unsigned reconfiguring;                /* We're shutting down due to reconfiguration */
108
  u32 hash_key;                                /* Random key used for hashing of neighbors */
109
  bird_clock_t last_state_change;        /* Time of last state transition */
110

    
111
  /*
112
   *        General protocol hooks:
113
   *
114
   *           if_notify        Notify protocol about interface state changes.
115
   *           ifa_notify        Notify protocol about interface address changes.
116
   *           rt_notify        Notify protocol about routing table updates.
117
   *           neigh_notify        Notify protocol about neighbor cache events.
118
   *           make_tmp_attrs  Construct ea_list from private attrs stored in rte.
119
   *           store_tmp_attrs Store private attrs back to the rte.
120
   *           import_control  Called as the first step of the route importing process.
121
   *                        It can construct a new rte, add private attributes and
122
   *                        decide whether the route shall be imported: 1=yes, -1=no,
123
   *                        0=process it through the import filter set by the user.
124
   */
125

    
126
  void (*if_notify)(struct proto *, unsigned flags, struct iface *i);
127
  void (*ifa_notify)(struct proto *, unsigned flags, struct ifa *a);
128
  void (*rt_notify)(struct proto *, struct network *net, struct rte *new, struct rte *old, struct ea_list *tmpa);
129
  void (*neigh_notify)(struct neighbor *neigh);
130
  struct ea_list *(*make_tmp_attrs)(struct rte *rt, struct linpool *pool);
131
  void (*store_tmp_attrs)(struct rte *rt, struct ea_list *attrs);
132
  int (*import_control)(struct proto *, struct rte **rt, struct ea_list **attrs, struct linpool *pool);
133

    
134
  /*
135
   *        Routing entry hooks (called only for rte's belonging to this protocol):
136
   *
137
   *           rte_better        Compare two rte's and decide which one is better (1=first, 0=second).
138
   *       rte_same        Compare two rte's and decide whether they are identical (1=yes, 0=no).
139
   *           rte_insert        Called whenever a rte is inserted to a routing table.
140
   *           rte_remove        Called whenever a rte is removed from the routing table.
141
   */
142

    
143
  int (*rte_better)(struct rte *, struct rte *);
144
  int (*rte_same)(struct rte *, struct rte *);
145
  void (*rte_insert)(struct network *, struct rte *);
146
  void (*rte_remove)(struct network *, struct rte *);
147

    
148
  struct rtable *table;                        /* Our primary routing table */
149
  struct filter *in_filter;                /* Input filter */
150
  struct filter *out_filter;                /* Output filter */
151
  struct announce_hook *ahooks;                /* Announcement hooks for this protocol */
152

    
153
  /* Hic sunt protocol-specific data */
154
};
155

    
156
void *proto_new(struct proto_config *, unsigned size);
157
void *proto_config_new(struct protocol *, unsigned size);
158

    
159
void proto_show(struct symbol *, int);
160
struct proto *proto_get_named(struct symbol *, struct protocol *);
161
void proto_xxable(char *, int);
162
void proto_debug(char *, unsigned int);
163

    
164
extern list active_proto_list;
165

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

    
204
#define PS_DOWN 0
205
#define PS_START 1
206
#define PS_UP 2
207
#define PS_STOP 3
208

    
209
void proto_notify_state(struct proto *p, unsigned state);
210

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

    
236
#define FS_HUNGRY 0
237
#define FS_FEEDING 1
238
#define FS_HAPPY 2
239
#define FS_FLUSHING 3
240

    
241
/*
242
 *        Debugging flags
243
 */
244

    
245
#define D_STATES 1                /* [core] State transitions */
246
#define D_ROUTES 2                /* [core] Routes passed by the filters */
247
#define D_FILTERS 4                /* [core] Routes rejected by the filters */
248
#define D_IFACES 8                /* [core] Interface events */
249
#define D_EVENTS 16                /* Protocol events */
250
#define D_PACKETS 32                /* Packets sent/received */
251

    
252
/*
253
 *        Known unique protocol instances as referenced by config routines
254
 */
255

    
256
extern struct proto_config *cf_dev_proto;
257

    
258
/*
259
 *        Route Announcement Hook
260
 */
261

    
262
struct announce_hook {
263
  node n;
264
  struct rtable *table;
265
  struct proto *proto;
266
  struct announce_hook *next;                /* Next hook for the same protocol */
267
};
268

    
269
struct announce_hook *proto_add_announce_hook(struct proto *, struct rtable *);
270

    
271
#endif