Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (8.63 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, 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); /* 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 *new, struct config *old, int force_restart);
58
void protos_dump_all(void);
59

    
60
extern list protocol_list;
61

    
62
/*
63
 *        Known protocols
64
 */
65

    
66
extern struct protocol proto_device;
67
extern struct protocol proto_rip;
68
extern struct protocol proto_static;
69
extern struct protocol proto_ospf;
70
extern struct protocol proto_pipe;
71

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

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

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

    
89
struct proto {
90
  node n;                                /* Node in *_proto_list */
91
  node glob_node;                        /* Node in global proto_list */
92
  struct protocol *proto;                /* Protocol */
93
  struct proto_config *cf;                /* Configuration data */
94
  struct proto_config *cf_new;                /* Configuration we want to switch to after shutdown (NULL=delete) */
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
  int min_scope;                        /* Minimal route scope accepted */
102
  unsigned disabled;                        /* Manually disabled */
103
  unsigned proto_state;                        /* Protocol state machine (see below) */
104
  unsigned core_state;                        /* Core state machine (see below) */
105
  unsigned core_goal;                        /* State we want to reach (see below) */
106
  unsigned reconfiguring;                /* We're shutting down due to reconfiguration */
107
  bird_clock_t last_state_change;        /* Time of last state transition */
108

    
109
  /*
110
   *        General protocol hooks:
111
   *
112
   *           if_notify        Notify protocol about interface state changes.
113
   *           ifa_notify        Notify protocol about interface address changes.
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

    
124
  void (*if_notify)(struct proto *, unsigned flags, struct iface *i);
125
  void (*ifa_notify)(struct proto *, unsigned flags, struct ifa *a);
126
  void (*rt_notify)(struct proto *, struct network *net, struct rte *new, struct rte *old, struct ea_list *tmpa);
127
  void (*neigh_notify)(struct neighbor *neigh);
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
   */
139

    
140
  int (*rte_better)(struct rte *, struct rte *);
141
  void (*rte_insert)(struct network *, struct rte *);
142
  void (*rte_remove)(struct network *, struct rte *);
143

    
144
  struct rtable *table;                        /* Our primary routing table */
145
  struct filter *in_filter;                /* Input filter */
146
  struct filter *out_filter;                /* Output filter */
147
  struct announce_hook *ahooks;                /* Announcement hooks for this protocol */
148

    
149
  /* Hic sunt protocol-specific data */
150
};
151

    
152
void proto_build(struct proto_config *);
153
void *proto_new(struct proto_config *, unsigned size);
154
void *proto_config_new(struct protocol *, unsigned size);
155

    
156
void proto_show(struct symbol *, int);
157
struct proto *proto_get_named(struct symbol *, struct protocol *);
158
void proto_xxable(char *, int);
159

    
160
extern list active_proto_list;
161

    
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

    
205
void 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

    
237
/*
238
 *        Known unique protocol instances as referenced by config routines
239
 */
240

    
241
extern struct proto_config *cf_dev_proto;
242

    
243
/*
244
 *        Route Announcement Hook
245
 */
246

    
247
struct 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

    
254
struct announce_hook *proto_add_announce_hook(struct proto *, struct rtable *);
255

    
256
#endif