Revision f4a60a9b sysdep/unix/krt.c

View differences:

sysdep/unix/krt.c
170 170
static struct proto *
171 171
kif_init(struct proto_config *c)
172 172
{
173
  struct kif_proto *p = proto_new(c, sizeof(struct kif_proto));
173
  struct kif_proto *p = proto_new(c);
174 174

  
175 175
  kif_sys_init(p);
176 176
  return &p->p;
......
266 266
  struct kif_config *d = (struct kif_config *) dest;
267 267
  struct kif_config *s = (struct kif_config *) src;
268 268

  
269
  /* Shallow copy of everything (just scan_time currently) */
270
  proto_copy_rest(dest, src, sizeof(struct kif_config));
271

  
272 269
  /* Copy primary addr list */
273 270
  cfg_copy_list(&d->primary, &s->primary, sizeof(struct kif_primary_item));
274 271

  
......
280 277
struct protocol proto_unix_iface = {
281 278
  .name = 		"Device",
282 279
  .template = 		"device%d",
283
  .preference =		DEF_PREF_DIRECT,
280
  .proto_size =		sizeof(struct kif_proto),
284 281
  .config_size =	sizeof(struct kif_config),
285 282
  .preconfig =		kif_preconfig,
286 283
  .init =		kif_init,
......
348 345
  net *n = e->net;
349 346
  rta *aa = rta_clone(e->attrs);
350 347
  rte *ee = rte_get_temp(aa);
351
  net *nn = net_get(p->p.table, n->n.addr);
348
  net *nn = net_get(p->p.main_channel->table, n->n.addr);
352 349
  ee->net = nn;
353 350
  ee->pflags = 0;
354
  ee->pref = p->p.preference;
355 351
  ee->u.krt = e->u.krt;
356 352
  rte_update(&p->p, nn, ee);
357 353
}
......
359 355
static void
360 356
krt_learn_announce_delete(struct krt_proto *p, net *n)
361 357
{
362
  n = net_find(p->p.table, n->n.addr);
358
  n = net_find(p->p.main_channel->table, n->n.addr);
363 359
  rte_update(&p->p, n, NULL);
364 360
}
365 361

  
......
575 571
static void
576 572
krt_flush_routes(struct krt_proto *p)
577 573
{
578
  struct rtable *t = p->p.table;
574
  struct rtable *t = p->p.main_channel->table;
579 575

  
580 576
  KRT_TRACE(p, D_EVENTS, "Flushing kernel routes");
581 577
  FIB_WALK(&t->fib, net, n)
......
594 590
static struct rte *
595 591
krt_export_net(struct krt_proto *p, net *net, rte **rt_free, ea_list **tmpa)
596 592
{
597
  struct announce_hook *ah = p->p.main_ahook;
598
  struct filter *filter = ah->out_filter;
593
  struct channel *c = p->p.main_channel;
594
  struct filter *filter = c->out_filter;
599 595
  rte *rt;
600 596

  
601
  if (p->p.accept_ra_types == RA_MERGED)
602
    return rt_export_merged(ah, net, rt_free, tmpa, 1);
597
  if (c->ra_mode == RA_MERGED)
598
    return rt_export_merged(c, net, rt_free, tmpa, 1);
603 599

  
604 600
  rt = net->routes;
605 601
  *rt_free = NULL;
......
746 742
static void
747 743
krt_prune(struct krt_proto *p)
748 744
{
749
  struct rtable *t = p->p.table;
745
  struct rtable *t = p->p.main_channel->table;
750 746

  
751 747
  KRT_TRACE(p, D_EVENTS, "Pruning table %s", t->name);
752 748
  FIB_WALK(&t->fib, net, n)
......
1052 1048
    krt_scan_timer_kick(p);
1053 1049
}
1054 1050

  
1055
static int
1056
krt_reload_routes(struct proto *P)
1051
static void
1052
krt_reload_routes(struct channel *C)
1057 1053
{
1058
  struct krt_proto *p = (struct krt_proto *) P;
1054
  struct krt_proto *p = (void *) C->proto;
1059 1055

  
1060 1056
  /* Although we keep learned routes in krt_table, we rather schedule a scan */
1061 1057

  
......
1064 1060
    p->reload = 1;
1065 1061
    krt_scan_timer_kick(p);
1066 1062
  }
1067

  
1068
  return 1;
1069 1063
}
1070 1064

  
1071 1065
static void
1072
krt_feed_end(struct proto *P)
1066
krt_feed_end(struct channel *C)
1073 1067
{
1074
  struct krt_proto *p = (struct krt_proto *) P;
1068
  struct krt_proto *p = (void *) C->proto;
1075 1069

  
1076 1070
  p->ready = 1;
1077 1071
  krt_scan_timer_kick(p);
......
1092 1086

  
1093 1087
struct krt_config *krt_cf;
1094 1088

  
1089
static void
1090
krt_preconfig(struct protocol *P UNUSED, struct config *c)
1091
{
1092
  krt_cf = NULL;
1093
  krt_sys_preconfig(c);
1094
}
1095

  
1096
static void
1097
krt_postconfig(struct proto_config *CF)
1098
{
1099
  struct krt_config *cf = (void *) CF;
1100

  
1101
  if (EMPTY_LIST(CF->channels))
1102
    cf_error("Channel not specified");
1103

  
1104
#ifdef CONFIG_ALL_TABLES_AT_ONCE
1105
  if (krt_cf->scan_time != cf->scan_time)
1106
    cf_error("All kernel syncers must use the same table scan interval");
1107
#endif
1108

  
1109
  struct rtable_config *tab = proto_cf_main_channel(CF)->table;
1110
  if (tab->krt_attached)
1111
    cf_error("Kernel syncer (%s) already attached to table %s", tab->krt_attached->name, tab->name);
1112
  tab->krt_attached = CF;
1113

  
1114
  krt_sys_postconfig(cf);
1115
}
1116

  
1095 1117
static struct proto *
1096
krt_init(struct proto_config *C)
1118
krt_init(struct proto_config *CF)
1097 1119
{
1098
  struct krt_proto *p = proto_new(C, sizeof(struct krt_proto));
1099
  struct krt_config *c = (struct krt_config *) C;
1120
  struct krt_proto *p = proto_new(CF);
1121
  // struct krt_config *cf = (void *) CF;
1122

  
1123
  p->p.main_channel = proto_add_channel(&p->p, proto_cf_main_channel(CF));
1100 1124

  
1101
  p->p.accept_ra_types = c->merge_paths ? RA_MERGED : RA_OPTIMAL;
1102
  p->p.merge_limit = c->merge_paths;
1103 1125
  p->p.import_control = krt_import_control;
1104 1126
  p->p.rt_notify = krt_rt_notify;
1105 1127
  p->p.if_notify = krt_if_notify;
......
1118 1140
{
1119 1141
  struct krt_proto *p = (struct krt_proto *) P;
1120 1142

  
1121
  switch (p->p.table->addr_type)
1143
  switch (p->p.net_type)
1122 1144
  {
1123 1145
  case NET_IP4:	p->af = AF_INET; break;
1124 1146
  case NET_IP6:	p->af = AF_INET6; break;
......
1139 1161

  
1140 1162
  krt_scan_timer_start(p);
1141 1163

  
1142
  if (P->gr_recovery && KRT_CF->graceful_restart)
1143
    P->gr_wait = 1;
1164
  if (p->p.gr_recovery && KRT_CF->graceful_restart)
1165
    p->p.main_channel->gr_wait = 1;
1144 1166

  
1145 1167
  return PS_UP;
1146 1168
}
......
1169 1191
}
1170 1192

  
1171 1193
static int
1172
krt_reconfigure(struct proto *p, struct proto_config *new)
1194
krt_reconfigure(struct proto *p, struct proto_config *CF)
1173 1195
{
1174
  struct krt_config *o = (struct krt_config *) p->cf;
1175
  struct krt_config *n = (struct krt_config *) new;
1196
  struct krt_config *o = (void *) p->cf;
1197
  struct krt_config *n = (void *) CF;
1198

  
1199
  if (!proto_configure_channel(p, &p->main_channel, proto_cf_main_channel(CF)))
1200
    return 0;
1176 1201

  
1177 1202
  if (!krt_sys_reconfigure((struct krt_proto *) p, n, o))
1178 1203
    return 0;
1179 1204

  
1180 1205
  /* persist, graceful restart need not be the same */
1181
  return o->scan_time == n->scan_time && o->learn == n->learn &&
1182
    o->devroutes == n->devroutes && o->merge_paths == n->merge_paths;
1183
}
1184

  
1185
static void
1186
krt_preconfig(struct protocol *P UNUSED, struct config *c)
1187
{
1188
  krt_cf = NULL;
1189
  krt_sys_preconfig(c);
1190
}
1191

  
1192
static void
1193
krt_postconfig(struct proto_config *C)
1194
{
1195
  struct krt_config *c = (struct krt_config *) C;
1196

  
1197
#ifdef CONFIG_ALL_TABLES_AT_ONCE
1198
  if (krt_cf->scan_time != c->scan_time)
1199
    cf_error("All kernel syncers must use the same table scan interval");
1200
#endif
1201

  
1202
  if (C->table->krt_attached)
1203
    cf_error("Kernel syncer (%s) already attached to table %s", C->table->krt_attached->name, C->table->name);
1204
  C->table->krt_attached = C;
1205
  krt_sys_postconfig(c);
1206
  return o->scan_time == n->scan_time && o->learn == n->learn && o->devroutes == n->devroutes;
1206 1207
}
1207 1208

  
1208 1209
struct proto_config *
......
1226 1227
  struct krt_config *d = (struct krt_config *) dest;
1227 1228
  struct krt_config *s = (struct krt_config *) src;
1228 1229

  
1229
  /* Shallow copy of everything */
1230
  proto_copy_rest(dest, src, sizeof(struct krt_config));
1231

  
1232 1230
  /* Fix sysdep parts */
1233 1231
  krt_sys_copy_config(d, s);
1234 1232
}
......
1257 1255
  .template =		"kernel%d",
1258 1256
  .attr_class =		EAP_KRT,
1259 1257
  .preference =		DEF_PREF_INHERITED,
1258
  .channel_mask =	NB_IP,
1259
  .proto_size =		sizeof(struct krt_proto),
1260 1260
  .config_size =	sizeof(struct krt_config),
1261 1261
  .preconfig =		krt_preconfig,
1262 1262
  .postconfig =		krt_postconfig,

Also available in: Unified diff