Revision 31b3e1bb nest/protocol.h

View differences:

nest/protocol.h
1 1
/*
2 2
 *	BIRD Internet Routing Daemon -- Protocols
3 3
 *
4
 *	(c) 1998 Martin Mares <mj@ucw.cz>
4
 *	(c) 1998--1999 Martin Mares <mj@ucw.cz>
5 5
 *
6 6
 *	Can be freely distributed and used under the terms of the GNU GPL.
7 7
 */
......
17 17
struct neighbor;
18 18
struct rtattr;
19 19
struct network;
20
struct proto_config;
21
struct config;
22
struct proto;
20 23

  
21 24
/*
22 25
 *	Routing Protocol
......
27 30
  char *name;
28 31
  unsigned debug;			/* Default debugging flags */
29 32

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

  
35 42
void protos_build(void);
36
void protos_init(void);
37
void protos_preconfig(void);
38
void protos_postconfig(void);
43
void protos_preconfig(struct config *);
44
void protos_postconfig(struct config *);
45
void protos_commit(struct config *);
39 46
void protos_start(void);
40 47
void protos_dump_all(void);
41 48

  
......
53 60
 *	Routing Protocol Instance
54 61
 */
55 62

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

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

  
56 73
struct proto {
57 74
  node n;
58 75
  struct protocol *proto;		/* Protocol */
59
  char *name;				/* Name of this instance */
76
  struct proto_config *cf;		/* Configuration data */
77
  pool *pool;				/* Pool containing local objects */
78

  
60 79
  unsigned debug;			/* Debugging flags */
61
  pool *pool;				/* Local objects */
62 80
  unsigned preference;			/* Default route preference */
63
  unsigned state;			/* PRS_... */
64 81
  unsigned disabled;			/* Manually disabled */
82
  unsigned proto_state;			/* Protocol state machine (see below) */
83
  unsigned core_state;			/* Core state machine (see below) */
65 84

  
66 85
  void (*if_notify)(struct proto *, unsigned flags, struct iface *new, struct iface *old);
67 86
  void (*rt_notify)(struct proto *, struct network *net, struct rte *new, struct rte *old);
68 87
  void (*neigh_notify)(struct neighbor *neigh);
69
  void (*dump)(struct proto *);			/* Debugging dump */
70
  void (*start)(struct proto *);		/* Start the instance */
71
  void (*shutdown)(struct proto *, int time);	/* Stop the instance */
72 88

  
73 89
  int (*rta_same)(struct rtattr *, struct rtattr *);
74 90
  int (*rte_better)(struct rte *, struct rte *);
75 91
  void (*rte_insert)(struct network *, struct rte *);
76 92
  void (*rte_remove)(struct network *, struct rte *);
77 93

  
78
  /* Reconfigure function? */
79 94
  /* Input/output filters */
80 95
  /* Connection to routing tables? */
81 96

  
82 97
  /* Hic sunt protocol-specific data */
83 98
};
84 99

  
85
#define PRS_DOWN 0			/* Inactive */
86
#define PRS_STARTING 1
87
#define PRS_UP 2
88

  
89
void *proto_new(struct protocol *, unsigned size);
100
void proto_build(struct proto_config *);
101
void *proto_new(struct proto_config *, unsigned size);
102
void *proto_config_new(struct protocol *, unsigned size);
90 103

  
91 104
extern list proto_list, inactive_proto_list;
92 105

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

  
144
#define PS_DOWN 0
145
#define PS_START 1
146
#define PS_UP 2
147
#define PS_STOP 3
148

  
149
void proto_notify_state(struct proto *p, unsigned state);
150

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

  
176
#define FS_HUNGRY 0
177
#define FS_FEEDING 1
178
#define FS_HAPPY 2
179
#define FS_FLUSHING 3
180

  
181
/*
94 182
 *	Known unique protocol instances as referenced by config routines
95 183
 */
96 184

  
97
extern struct proto *cf_dev_proto;
185
extern struct proto_config *cf_dev_proto;
98 186

  
99 187
#endif

Also available in: Unified diff