Statistics
| Branch: | Revision:

iof-bird-daemon / nest / protocol.h @ 1d2664a4

History | View | Annotate | Download (7.91 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
struct symbol;
27

    
28
/*
29
 *        Routing Protocol
30
 */
31

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

    
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 */
43
  int (*reconfigure)(struct proto *, struct proto_config *);        /* Try to reconfigure instance */
44
  void (*dump)(struct proto *);                        /* Debugging dump */
45
  void (*dump_attrs)(struct rte *);                /* Dump protocol-dependent attributes */
46
  int (*start)(struct proto *);                        /* Start the instance */
47
  int (*shutdown)(struct proto *);                /* Stop the instance */
48
};
49

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

    
58
extern list protocol_list;
59

    
60
/*
61
 *        Known protocols
62
 */
63

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

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

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

    
84
  /* Protocol-specific data follow... */
85
};
86

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

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

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

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

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

    
133
  int (*rte_better)(struct rte *, struct rte *);
134
  void (*rte_insert)(struct network *, struct rte *);
135
  void (*rte_remove)(struct network *, struct rte *);
136

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

    
142
  /* Hic sunt protocol-specific data */
143
};
144

    
145
void proto_build(struct proto_config *);
146
void *proto_new(struct proto_config *, unsigned size);
147
void *proto_config_new(struct protocol *, unsigned size);
148
void proto_show(struct symbol *, int);
149

    
150
extern list proto_list;
151

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

    
190
#define PS_DOWN 0
191
#define PS_START 1
192
#define PS_UP 2
193
#define PS_STOP 3
194

    
195
void proto_notify_state(struct proto *p, unsigned state);
196

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

    
222
#define FS_HUNGRY 0
223
#define FS_FEEDING 1
224
#define FS_HAPPY 2
225
#define FS_FLUSHING 3
226

    
227
/*
228
 *        Known unique protocol instances as referenced by config routines
229
 */
230

    
231
extern struct proto_config *cf_dev_proto;
232

    
233
/*
234
 *        Route Announcement Hook
235
 */
236

    
237
struct announce_hook {
238
  node n;
239
  struct rtable *table;
240
  struct proto *proto;
241
  struct announce_hook *next;                /* Next hook for the same protocol */
242
};
243

    
244
struct announce_hook *proto_add_announce_hook(struct proto *, struct rtable *);
245

    
246
/*
247
 *        Callback to sysdep code when shutdown is finished
248
 */
249

    
250
void protos_shutdown_notify(void);
251

    
252
#endif