Revision 31b3e1bb nest/proto.c

View differences:

nest/proto.c
1 1
/*
2 2
 *	BIRD -- 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
 */
......
23 23
list inactive_proto_list;
24 24

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

  
30
  debug("proto_new(%s)\n", pr->name);
31
  p->cf = c;
32
  p->debug = c->debug;
33
  p->preference = c->preference;
34
  p->disabled = c->disabled;
31 35
  p->proto = pr;
32
  p->name = pr->name;
33
  p->debug = pr->debug;
34
  p->pool = rp_new(&root_pool, pr->name);
35
  add_tail(&inactive_proto_list, &p->n);
36
  p->pool = rp_new(&root_pool, c->name);
36 37
  return p;
37 38
}
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

  
39 53
void
40
protos_preconfig(void)
54
protos_preconfig(struct config *c)
41 55
{
42 56
  struct protocol *p;
43 57

  
44 58
  init_list(&proto_list);
45 59
  init_list(&inactive_proto_list);
46
  debug("Protocol preconfig\n");
60
  debug("Protocol preconfig:");
47 61
  WALK_LIST(p, protocol_list)
48 62
    {
49
      debug("...%s\n", p->name);
63
      debug(" %s", p->name);
50 64
      if (p->preconfig)
51
	p->preconfig(p);
65
	p->preconfig(p, c);
52 66
    }
67
  debug("\n");
53 68
}
54 69

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

  
60
  debug("Protocol postconfig\n");
61
  WALK_LIST(p, protocol_list)
76
  debug("Protocol postconfig:");
77
  WALK_LIST(x, c->protos)
62 78
    {
63
      debug("...%s\n", p->name);
79
      debug(" %s", x->name);
80
      p = x->proto;
64 81
      if (p->postconfig)
65
	p->postconfig(p);
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);
66 101
    }
102
  debug("\n");
67 103
}
68 104

  
69 105
static void
......
72 108
  rem_node(&p->n);
73 109
  if (p->disabled)
74 110
    return;
75
  p->state = PRS_STARTING;
76
  if (p->start)
77
    p->start(p);
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;
78 117
  if_feed_baby(p);
79 118
  rt_feed_baby(p);
80
  p->state = PRS_UP;
119
  p->core_state = FS_HAPPY;
81 120
  add_tail(&proto_list, &p->n);
82 121
}
83 122

  
......
89 128
  debug("Protocol start\n");
90 129
  WALK_LIST_DELSAFE(p, n, inactive_proto_list)
91 130
    {
92
      debug("...%s\n", p->name);
131
      debug("Starting %s\n", p->cf->name);
93 132
      proto_start(p);
94 133
    }
95 134
}
......
98 137
protos_dump_all(void)
99 138
{
100 139
  struct proto *p;
140
  static char *p_states[] = { "DOWN", "START", "UP", "STOP" };
141
  static char *c_states[] = { "HUNGRY", "FEEDING", "HAPPY", "FLUSHING" };
101 142

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

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

  
116 157
void
......
125 166
  add_tail(&protocol_list, &proto_static.n);
126 167
#endif
127 168
}
128

  
129
void
130
protos_init(void)
131
{
132
  struct protocol *p;
133

  
134
  debug("Initializing protocols\n");
135
  WALK_LIST(p, protocol_list)
136
    if (p->init)
137
      p->init(p);
138
}

Also available in: Unified diff