Statistics
| Branch: | Revision:

iof-bird-daemon / nest / proto.c @ 31b3e1bb

History | View | Annotate | Download (3.22 KB)

1
/*
2
 *        BIRD -- 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
#define LOCAL_DEBUG
10

    
11
#include <string.h>
12

    
13
#include "nest/bird.h"
14
#include "nest/protocol.h"
15
#include "lib/resource.h"
16
#include "lib/lists.h"
17
#include "conf/conf.h"
18
#include "nest/route.h"
19
#include "nest/iface.h"
20

    
21
list protocol_list;
22
list proto_list;
23
list inactive_proto_list;
24

    
25
void *
26
proto_new(struct proto_config *c, unsigned size)
27
{
28
  struct protocol *pr = c->proto;
29
  struct proto *p = cfg_allocz(size);        /* FIXME: Allocate from global pool */
30

    
31
  p->cf = c;
32
  p->debug = c->debug;
33
  p->preference = c->preference;
34
  p->disabled = c->disabled;
35
  p->proto = pr;
36
  p->pool = rp_new(&root_pool, c->name);
37
  return p;
38
}
39

    
40
void *
41
proto_config_new(struct protocol *pr, unsigned size)
42
{
43
  struct proto_config *c = cfg_allocz(size);
44

    
45
  add_tail(&new_config->protos, &c->n);
46
  c->global = new_config;
47
  c->proto = pr;
48
  c->debug = pr->debug;
49
  c->name = pr->name;
50
  return c;
51
}
52

    
53
void
54
protos_preconfig(struct config *c)
55
{
56
  struct protocol *p;
57

    
58
  init_list(&proto_list);
59
  init_list(&inactive_proto_list);
60
  debug("Protocol preconfig:");
61
  WALK_LIST(p, protocol_list)
62
    {
63
      debug(" %s", p->name);
64
      if (p->preconfig)
65
        p->preconfig(p, c);
66
    }
67
  debug("\n");
68
}
69

    
70
void
71
protos_postconfig(struct config *c)
72
{
73
  struct proto_config *x;
74
  struct protocol *p;
75

    
76
  debug("Protocol postconfig:");
77
  WALK_LIST(x, c->protos)
78
    {
79
      debug(" %s", x->name);
80
      p = x->proto;
81
      if (p->postconfig)
82
        p->postconfig(x);
83
    }
84
  debug("\n");
85
}
86

    
87
void
88
protos_commit(struct config *c)
89
{
90
  struct proto_config *x;
91
  struct protocol *p;
92
  struct proto *q;
93

    
94
  debug("Protocol commit:");
95
  WALK_LIST(x, c->protos)
96
    {
97
      debug(" %s", x->name);
98
      p = x->proto;
99
      q = p->init(x);
100
      add_tail(&inactive_proto_list, &q->n);
101
    }
102
  debug("\n");
103
}
104

    
105
static void
106
proto_start(struct proto *p)
107
{
108
  rem_node(&p->n);
109
  if (p->disabled)
110
    return;
111
  p->proto_state = PS_DOWN;
112
  p->core_state = FS_HUNGRY;
113
  if (p->proto->start && p->proto->start(p) != PS_UP)
114
    bug("Delayed protocol start not supported yet");
115
  p->proto_state = PS_UP;
116
  p->core_state = FS_FEEDING;
117
  if_feed_baby(p);
118
  rt_feed_baby(p);
119
  p->core_state = FS_HAPPY;
120
  add_tail(&proto_list, &p->n);
121
}
122

    
123
void
124
protos_start(void)
125
{
126
  struct proto *p, *n;
127

    
128
  debug("Protocol start\n");
129
  WALK_LIST_DELSAFE(p, n, inactive_proto_list)
130
    {
131
      debug("Starting %s\n", p->cf->name);
132
      proto_start(p);
133
    }
134
}
135

    
136
void
137
protos_dump_all(void)
138
{
139
  struct proto *p;
140
  static char *p_states[] = { "DOWN", "START", "UP", "STOP" };
141
  static char *c_states[] = { "HUNGRY", "FEEDING", "HAPPY", "FLUSHING" };
142

    
143
  debug("Protocols:\n");
144

    
145
  WALK_LIST(p, proto_list)
146
    {
147
      debug("  protocol %s: state %s/%s\n", p->cf->name, p_states[p->proto_state], c_states[p->core_state]);
148
      if (p->disabled)
149
        debug("\tDISABLED\n");
150
      else if (p->proto->dump)
151
        p->proto->dump(p);
152
    }
153
  WALK_LIST(p, inactive_proto_list)
154
    debug("  inactive %s\n", p->cf->name);
155
}
156

    
157
void
158
protos_build(void)
159
{
160
  init_list(&protocol_list);
161
  add_tail(&protocol_list, &proto_device.n);
162
#ifdef CONFIG_RIP
163
  add_tail(&protocol_list, &proto_rip.n);
164
#endif
165
#ifdef CONFIG_STATIC
166
  add_tail(&protocol_list, &proto_static.n);
167
#endif
168
}