Statistics
| Branch: | Revision:

iof-bird-daemon / nest / protocol.h @ 64011f89

History | View | Annotate | Download (5.49 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 rte;
17
struct neighbor;
18
struct rtattr;
19
struct network;
20
struct proto_config;
21
struct config;
22
struct proto;
23
struct event;
24

    
25
/*
26
 *        Routing Protocol
27
 */
28

    
29
struct protocol {
30
  node n;
31
  char *name;
32
  unsigned debug;                        /* Default debugging flags */
33

    
34
  void (*preconfig)(struct protocol *, struct config *);        /* Just before configuring */
35
  void (*postconfig)(struct proto_config *);                        /* After configuring each instance */
36
  struct proto * (*init)(struct proto_config *);                /* Create new instance */
37
  int (*reconfigure)(struct proto *, struct proto_config *);        /* Try to reconfigure instance */
38
  void (*dump)(struct proto *);                        /* Debugging dump */
39
  int (*start)(struct proto *);                        /* Start the instance */
40
  int (*shutdown)(struct proto *);                /* Stop the instance */
41
};
42

    
43
void protos_build(void);
44
void protos_preconfig(struct config *);
45
void protos_postconfig(struct config *);
46
void protos_commit(struct config *);
47
void protos_start(void);
48
void protos_dump_all(void);
49

    
50
extern list protocol_list;
51

    
52
/*
53
 *        Known protocols
54
 */
55

    
56
extern struct protocol proto_device;
57
extern struct protocol proto_rip;
58
extern struct protocol proto_static;
59

    
60
/*
61
 *        Routing Protocol Instance
62
 */
63

    
64
struct proto_config {
65
  node n;
66
  struct config *global;                /* Global configuration data */
67
  struct protocol *proto;                /* Protocol */
68
  char *name;
69
  unsigned debug, preference, disabled;        /* Generic parameters */
70

    
71
  /* Protocol-specific data follow... */
72
};
73

    
74
struct proto {
75
  node n;
76
  struct protocol *proto;                /* Protocol */
77
  struct proto_config *cf;                /* Configuration data */
78
  pool *pool;                                /* Pool containing local objects */
79
  struct event *attn;                        /* "Pay attention" event */
80

    
81
  char *name;                                /* Name of this instance (== cf->name) */
82
  unsigned debug;                        /* Debugging flags */
83
  unsigned preference;                        /* Default route preference */
84
  unsigned disabled;                        /* Manually disabled */
85
  unsigned proto_state;                        /* Protocol state machine (see below) */
86
  unsigned core_state;                        /* Core state machine (see below) */
87
  unsigned core_goal;                        /* State we want to reach (see below) */
88

    
89
  void (*if_notify)(struct proto *, unsigned flags, struct iface *new, struct iface *old);
90
  void (*rt_notify)(struct proto *, struct network *net, struct rte *new, struct rte *old);
91
  void (*neigh_notify)(struct neighbor *neigh);
92

    
93
  int (*rta_same)(struct rtattr *, struct rtattr *);
94
  int (*rte_better)(struct rte *, struct rte *);
95
  void (*rte_insert)(struct network *, struct rte *);
96
  void (*rte_remove)(struct network *, struct rte *);
97

    
98
  /* Input/output filters */
99
  /* Connection to routing tables? */
100

    
101
  /* Hic sunt protocol-specific data */
102
};
103

    
104
void proto_build(struct proto_config *);
105
void *proto_new(struct proto_config *, unsigned size);
106
void *proto_config_new(struct protocol *, unsigned size);
107

    
108
extern list proto_list;
109

    
110
/*
111
 *  Each protocol instance runs two different state machines:
112
 *
113
 *  [P] The protocol machine: (implemented inside protocol)
114
 *
115
 *                DOWN    ---->    START
116
 *                  ^                   |
117
 *                  |                   V
118
 *                STOP    <----     UP
119
 *
120
 *        States:        DOWN        Protocol is down and it's waiting for the core
121
 *                        requesting protocol start.
122
 *                START        Protocol is waiting for connection with the rest
123
 *                        of the network and it's not willing to accept
124
 *                        packets. When it connects, it goes to UP state.
125
 *                UP        Protocol is up and running. When the network
126
 *                        connection breaks down or the core requests
127
 *                        protocol to be terminated, it goes to STOP state.
128
 *                STOP        Protocol is disconnecting from the network.
129
 *                        After it disconnects, it returns to DOWN state.
130
 *
131
 *        In:        start()        Called in DOWN state to request protocol startup.
132
 *                        Returns new state: either UP or START (in this
133
 *                        case, the protocol will notify the core when it
134
 *                        finally comes UP).
135
 *                stop()        Called in START, UP or STOP state to request
136
 *                        protocol shutdown. Returns new state: either
137
 *                        DOWN or STOP (in this case, the protocol will
138
 *                        notify the core when it finally comes DOWN).
139
 *
140
 *        Out:        proto_notify_state() -- called by protocol instance when
141
 *                        it does any state transition not covered by
142
 *                        return values of start() and stop(). This includes
143
 *                        START->UP (delayed protocol startup), UP->STOP
144
 *                        (spontaneous shutdown) and STOP->DOWN (delayed
145
 *                        shutdown).
146
 */
147

    
148
#define PS_DOWN 0
149
#define PS_START 1
150
#define PS_UP 2
151
#define PS_STOP 3
152

    
153
void proto_notify_state(struct proto *p, unsigned state);
154

    
155
/*
156
 *  [F] The feeder machine: (implemented in core routines)
157
 *
158
 *                HUNGRY    ---->   FEEDING
159
 *                 ^                     |
160
 *                 |                      V
161
 *                FLUSHING  <----   HAPPY
162
 *
163
 *        States:        HUNGRY        Protocol either administratively down (i.e.,
164
 *                        disabled by the user) or temporarily down
165
 *                        (i.e., [P] is not UP)
166
 *                FEEDING        The protocol came up and we're feeding it
167
 *                        initial routes. [P] is UP.
168
 *                HAPPY        The protocol is up and it's receiving normal
169
 *                        routing updates. [P] is UP.
170
 *                FLUSHING The protocol is down and we're removing its
171
 *                        routes from the table. [P] is STOP or DOWN.
172
 *
173
 *        Normal lifecycle of a protocol looks like:
174
 *
175
 *                HUNGRY/DOWN --> HUNGRY/START --> HUNGRY/UP -->
176
 *                FEEDING/UP --> HAPPY/UP --> FLUSHING/STOP|DOWN -->
177
 *                HUNGRY/STOP|DOWN --> HUNGRY/DOWN
178
 */
179

    
180
#define FS_HUNGRY 0
181
#define FS_FEEDING 1
182
#define FS_HAPPY 2
183
#define FS_FLUSHING 3
184

    
185
/*
186
 *        Known unique protocol instances as referenced by config routines
187
 */
188

    
189
extern struct proto_config *cf_dev_proto;
190

    
191
#endif