]>
Commit | Line | Data |
---|---|---|
2326b001 MM |
1 | /* |
2 | * BIRD -- Protocols | |
3 | * | |
4 | * (c) 1998 Martin Mares <mj@ucw.cz> | |
5 | * | |
6 | * Can be freely distributed and used under the terms of the GNU GPL. | |
7 | */ | |
8 | ||
7f4a3988 MM |
9 | #define LOCAL_DEBUG |
10 | ||
11 | #include <string.h> | |
12 | ||
2326b001 MM |
13 | #include "nest/bird.h" |
14 | #include "nest/protocol.h" | |
15 | #include "lib/resource.h" | |
16 | #include "lib/lists.h" | |
7f4a3988 | 17 | #include "nest/confile.h" |
47b79306 MM |
18 | #include "nest/route.h" |
19 | #include "nest/iface.h" | |
2326b001 | 20 | |
7f4a3988 | 21 | list protocol_list; |
2326b001 | 22 | list proto_list; |
47b79306 | 23 | list inactive_proto_list; |
2326b001 | 24 | |
7f4a3988 MM |
25 | void * |
26 | proto_new(struct protocol *pr, unsigned size) | |
27 | { | |
28 | struct proto *p = mp_alloc(cfg_mem, size); | |
29 | ||
30 | debug("proto_new(%s)\n", pr->name); | |
31 | bzero(p, sizeof(*p)); | |
32 | p->proto = pr; | |
33 | p->name = pr->name; | |
34 | p->debug = pr->debug; | |
35 | p->pool = rp_new(&root_pool, pr->name); | |
47b79306 | 36 | add_tail(&inactive_proto_list, &p->n); |
7f4a3988 MM |
37 | return p; |
38 | } | |
39 | ||
2326b001 | 40 | void |
7f4a3988 | 41 | protos_preconfig(void) |
2326b001 | 42 | { |
7f4a3988 MM |
43 | struct protocol *p; |
44 | ||
2326b001 | 45 | init_list(&proto_list); |
47b79306 | 46 | init_list(&inactive_proto_list); |
7f4a3988 MM |
47 | debug("Protocol preconfig\n"); |
48 | WALK_LIST(p, protocol_list) | |
49 | { | |
50 | debug("...%s\n", p->name); | |
3629bcf0 MM |
51 | if (p->preconfig) |
52 | p->preconfig(p); | |
7f4a3988 MM |
53 | } |
54 | } | |
55 | ||
56 | void | |
57 | protos_postconfig(void) | |
58 | { | |
59 | struct protocol *p; | |
60 | ||
61 | debug("Protocol postconfig\n"); | |
62 | WALK_LIST(p, protocol_list) | |
63 | { | |
64 | debug("...%s\n", p->name); | |
3629bcf0 MM |
65 | if (p->postconfig) |
66 | p->postconfig(p); | |
7f4a3988 MM |
67 | } |
68 | } | |
69 | ||
47b79306 MM |
70 | static void |
71 | proto_start(struct proto *p) | |
72 | { | |
73 | rem_node(&p->n); | |
f184ea6f | 74 | p->state = PRS_STARTING; |
47b79306 MM |
75 | if (p->start) |
76 | p->start(p); | |
77 | if_feed_baby(p); | |
78 | rt_feed_baby(p); | |
f184ea6f | 79 | p->state = PRS_UP; |
47b79306 MM |
80 | add_tail(&proto_list, &p->n); |
81 | } | |
7f4a3988 MM |
82 | |
83 | void | |
84 | protos_start(void) | |
85 | { | |
47b79306 | 86 | struct proto *p, *n; |
7f4a3988 MM |
87 | |
88 | debug("Protocol start\n"); | |
47b79306 | 89 | WALK_LIST_DELSAFE(p, n, inactive_proto_list) |
7f4a3988 MM |
90 | { |
91 | debug("...%s\n", p->name); | |
47b79306 | 92 | proto_start(p); |
7f4a3988 MM |
93 | } |
94 | } | |
95 | ||
87d2be86 PM |
96 | void |
97 | protos_dump_all(void) | |
98 | { | |
99 | struct proto *p; | |
100 | ||
101 | debug("Protocols:\n"); | |
102 | ||
103 | WALK_LIST(p, proto_list) | |
104 | { | |
105 | debug(" protocol %s:\n", p->name); | |
106 | if (p->dump) | |
107 | p->dump(p); | |
108 | } | |
47b79306 MM |
109 | WALK_LIST(p, inactive_proto_list) |
110 | debug(" inactive %s\n", p->name); | |
87d2be86 PM |
111 | } |
112 | ||
0432c017 MM |
113 | void |
114 | protos_build(void) | |
115 | { | |
116 | init_list(&protocol_list); | |
117 | add_tail(&protocol_list, &proto_device.n); | |
118 | add_tail(&protocol_list, &proto_rip.n); | |
119 | } | |
120 | ||
7f4a3988 MM |
121 | void |
122 | protos_init(void) | |
123 | { | |
124 | struct protocol *p; | |
125 | ||
126 | debug("Initializing protocols\n"); | |
7f4a3988 | 127 | WALK_LIST(p, protocol_list) |
3629bcf0 MM |
128 | if (p->init) |
129 | p->init(p); | |
2326b001 | 130 | } |