]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Store protocol config size inside protocol structure
authorOndrej Zajicek <santiago@crfreenet.org>
Sat, 21 Feb 2015 20:08:23 +0000 (21:08 +0100)
committerOndrej Zajicek <santiago@crfreenet.org>
Sat, 21 Feb 2015 20:08:23 +0000 (21:08 +0100)
Make proto_config_new() use this info instead of supplied size.

Thanks to Alexander V. Chernikov for the patch.

19 files changed:
nest/config.Y
nest/proto.c
nest/protocol.h
nest/rt-dev.c
proto/bfd/bfd.c
proto/bfd/config.Y
proto/bgp/bgp.c
proto/bgp/config.Y
proto/ospf/config.Y
proto/ospf/ospf.c
proto/pipe/config.Y
proto/pipe/pipe.c
proto/radv/config.Y
proto/radv/radv.c
proto/rip/config.Y
proto/rip/rip.c
proto/static/config.Y
proto/static/static.c
sysdep/unix/krt.c

index 59a776bfdd275f5a40cf4de6820c723c98527b00..8b697292d1dbd15c77f14ca8d58ca455c7431d15 100644 (file)
@@ -307,7 +307,7 @@ tos:
 CF_ADDTO(proto, dev_proto '}')
 
 dev_proto_start: proto_start DIRECT {
-     this_proto = proto_config_new(&proto_device, sizeof(struct rt_dev_config), $1);
+     this_proto = proto_config_new(&proto_device, $1);
      init_list(&DIRECT_CFG->iface_list);
    }
  ;
index 7a1e9bf78d4356b03a182b3904e385e11dc14a80..7339e4f488c3ada99a8be4747dffc8f399ba11d5 100644 (file)
@@ -245,7 +245,6 @@ proto_free_ahooks(struct proto *p)
 /**
  * proto_config_new - create a new protocol configuration
  * @pr: protocol the configuration will belong to
- * @size: size of the structure including generic data
  * @class: SYM_PROTO or SYM_TEMPLATE
  *
  * Whenever the configuration file says that a new instance
@@ -262,9 +261,9 @@ proto_free_ahooks(struct proto *p)
  * initialized during protos_commit()).
  */
 void *
-proto_config_new(struct protocol *pr, unsigned size, int class)
+proto_config_new(struct protocol *pr, int class)
 {
-  struct proto_config *c = cfg_allocz(size);
+  struct proto_config *c = cfg_allocz(pr->config_size);
 
   if (class == SYM_PROTO)
     add_tail(&new_config->protos, &c->n);
index eb43418bed463f50aeb38735f4fd2262d0bcaa5a..f46e0b137470131982c9ac4cfec0fe1623a650c4 100644 (file)
@@ -40,7 +40,8 @@ struct protocol {
   int name_counter;                    /* Counter for automatic name generation */
   int attr_class;                      /* Attribute class known to this protocol */
   int multitable;                      /* Protocol handles all announce hooks itself */
-  unsigned preference;                 /* Default protocol preference */
+  uint preference;                     /* Default protocol preference */
+  uint config_size;                    /* Size of protocol config */
 
   void (*preconfig)(struct protocol *, struct config *);       /* Just before configuring */
   void (*postconfig)(struct proto_config *);                   /* After configuring each instance */
@@ -126,7 +127,7 @@ struct proto_stats {
   u32 exp_updates_received;    /* Number of route updates received */
   u32 exp_updates_rejected;    /* Number of route updates rejected by protocol */
   u32 exp_updates_filtered;    /* Number of route updates rejected by filters */
-  u32 exp_updates_accepted;    /* Number of route updates accepted and exported */ 
+  u32 exp_updates_accepted;    /* Number of route updates accepted and exported */
   u32 exp_withdraws_received;  /* Number of route withdraws received */
   u32 exp_withdraws_accepted;  /* Number of route withdraws accepted and processed */
 };
@@ -148,7 +149,7 @@ struct proto {
   byte disabled;                       /* Manually disabled */
   byte proto_state;                    /* Protocol state machine (PS_*, see below) */
   byte core_state;                     /* Core state machine (FS_*, see below) */
-  byte export_state;                   /* Route export state (ES_*, see below) */      
+  byte export_state;                   /* Route export state (ES_*, see below) */
   byte reconfiguring;                  /* We're shutting down due to reconfiguration */
   byte refeeding;                      /* We are refeeding (valid only if export_state == ES_FEEDING) */
   byte flushing;                       /* Protocol is flushed in current flush loop round */
@@ -194,7 +195,7 @@ struct proto {
   /*
    *   Routing entry hooks (called only for routes belonging to this protocol):
    *
-   *      rte_recalculate Called at the beginning of the best route selection  
+   *      rte_recalculate Called at the beginning of the best route selection
    *      rte_better   Compare two rte's and decide which one is better (1=first, 0=second).
    *       rte_same    Compare two rte's and decide whether they are identical (1=yes, 0=no).
    *      rte_insert   Called whenever a rte is inserted to a routing table.
@@ -239,7 +240,7 @@ struct proto_spec {
 
 
 void *proto_new(struct proto_config *, unsigned size);
-void *proto_config_new(struct protocol *, unsigned size, int class);
+void *proto_config_new(struct protocol *, int class);
 void proto_copy_config(struct proto_config *dest, struct proto_config *src);
 void proto_request_feeding(struct proto *p);
 
@@ -350,7 +351,7 @@ void proto_notify_state(struct proto *p, unsigned state);
  *             FEEDING/UP --> HAPPY/UP --> FLUSHING/STOP|DOWN -->
  *             HUNGRY/STOP|DOWN --> HUNGRY/DOWN
  *
- *     Sometimes, protocol might switch from HAPPY/UP to FEEDING/UP 
+ *     Sometimes, protocol might switch from HAPPY/UP to FEEDING/UP
  *     if it wants to refeed the routes (for example BGP does so
  *     as a result of received ROUTE-REFRESH request).
  */
@@ -432,7 +433,7 @@ proto_reset_limit(struct proto_limit *l)
     l->state = PLS_INITIAL;
 }
 
+
 /*
  *     Route Announcement Hook
  */
index 53deaa529d16067125e887636b3511597ac5a774..87ffc5ecb3a0674ed78217f069cc9714f4fb2196 100644 (file)
@@ -93,7 +93,7 @@ dev_reconfigure(struct proto *p, struct proto_config *new)
 {
   struct rt_dev_config *o = (struct rt_dev_config *) p->cf;
   struct rt_dev_config *n = (struct rt_dev_config *) new;
-  
+
   return iface_patts_equal(&o->iface_list, &n->iface_list, NULL);
 }
 
@@ -115,6 +115,7 @@ struct protocol proto_device = {
   .name =              "Direct",
   .template =          "direct%d",
   .preference =        DEF_PREF_DIRECT,
+  .config_size =       sizeof(struct rt_dev_config),
   .init =              dev_init,
   .reconfigure =       dev_reconfigure,
   .copy_config =       dev_copy_config
index 23e04e408b6f44ede822d5fc7207266aa2dc49e6..5f0898466d424f39e06e1acdc88e8d65f32e5fbb 100644 (file)
@@ -1112,6 +1112,7 @@ bfd_show_sessions(struct proto *P)
 struct protocol proto_bfd = {
   .name =              "BFD",
   .template =          "bfd%d",
+  .config_size =       sizeof(struct bfd_config),
   .init =              bfd_init,
   .start =             bfd_start,
   .shutdown =          bfd_shutdown,
index 1b07495e809002a7b012c9794554d1ca43718b88..4affb927c4e0d6441c17404261ff4b29c6d0406e 100644 (file)
@@ -34,7 +34,7 @@ CF_ADDTO(proto, bfd_proto)
 
 bfd_proto_start: proto_start BFD
 {
-  this_proto = proto_config_new(&proto_bfd, sizeof(struct bfd_config), $1);
+  this_proto = proto_config_new(&proto_bfd, $1);
   init_list(&BFD_CFG->patt_list);
   init_list(&BFD_CFG->neigh_list);
 
index c8b1867b38ae44c9de0587b9c48188a9fca75c9f..016d3e6054ef5d7a9debaba0daa2fe598669dea7 100644 (file)
@@ -1455,6 +1455,7 @@ struct protocol proto_bgp = {
   .template =          "bgp%d",
   .attr_class =        EAP_BGP,
   .preference =        DEF_PREF_BGP,
+  .config_size =       sizeof(struct bgp_config),
   .init =              bgp_init,
   .start =             bgp_start,
   .shutdown =          bgp_shutdown,
index e4875b277502faafd04a63eeb9657275baeb365d..ed40634f4ff1b87f2448939e32b5240d300724e4 100644 (file)
@@ -34,7 +34,7 @@ CF_GRAMMAR
 CF_ADDTO(proto, bgp_proto '}' { bgp_check_config(BGP_CFG); } )
 
 bgp_proto_start: proto_start BGP {
-     this_proto = proto_config_new(&proto_bgp, sizeof(struct bgp_config), $1);
+     this_proto = proto_config_new(&proto_bgp, $1);
      BGP_CFG->multihop = -1;   /* undefined */
      BGP_CFG->hold_time = 240;
      BGP_CFG->connect_retry_time = 120;
index 268b95394f4b3774b98bdd3729d39744a9ead112..c859960fb778354363a4ae855d4f602dc198c04e 100644 (file)
@@ -141,7 +141,7 @@ CF_GRAMMAR
 CF_ADDTO(proto, ospf_proto '}' { ospf_proto_finish(); } )
 
 ospf_proto_start: proto_start OSPF {
-     this_proto = proto_config_new(&proto_ospf, sizeof(struct ospf_config), $1);
+     this_proto = proto_config_new(&proto_ospf, $1);
      init_list(&OSPF_CFG->area_list);
      init_list(&OSPF_CFG->vlink_list);
      OSPF_CFG->tick = OSPF_DEFAULT_TICK;
index dab7aab88da181a58028efac6457102c7ffefc14..1bc4e077c216eaafa6506def2aa6db92245aac38 100644 (file)
@@ -1457,6 +1457,7 @@ struct protocol proto_ospf = {
   .template =          "ospf%d",
   .attr_class =                EAP_OSPF,
   .preference =                DEF_PREF_OSPF,
+  .config_size =       sizeof(struct ospf_config),
   .init =              ospf_init,
   .dump =              ospf_dump,
   .start =             ospf_start,
index 40637558b4376b36ac0fc17fea37d1a789c0bbff..8daf2e7cf6bc90860015e0f1f3e7e640e3c12dc2 100644 (file)
@@ -23,7 +23,7 @@ CF_GRAMMAR
 CF_ADDTO(proto, pipe_proto '}')
 
 pipe_proto_start: proto_start PIPE {
-     this_proto = proto_config_new(&proto_pipe, sizeof(struct pipe_config), $1);
+     this_proto = proto_config_new(&proto_pipe, $1);
      PIPE_CFG->mode = PIPE_TRANSPARENT;
   }
  ;
index d6ef153ae440b7a834c3eddda4359e676f03072c..6ef803222329d82854d37777609891e70eaa4bcb 100644 (file)
@@ -247,7 +247,7 @@ pipe_reconfigure(struct proto *P, struct proto_config *new)
 
   if ((P->proto_state != PS_UP) || (proto_reconfig_type == RECONFIG_SOFT))
     return 1;
-  
+
   if ((new->preference != old->preference)
       || ! filter_same(new->in_filter, old->in_filter)
       || ! filter_same(new->out_filter, old->out_filter))
@@ -298,7 +298,7 @@ pipe_show_stats(struct pipe_proto *p)
    * (imp/exp), while stats s2 have switched 'polarity'.
    */
 
-  cli_msg(-1006, "  Routes:         %u imported, %u exported", 
+  cli_msg(-1006, "  Routes:         %u imported, %u exported",
          s1->imp_routes, s2->imp_routes);
   cli_msg(-1006, "  Route change stats:     received   rejected   filtered    ignored   accepted");
   cli_msg(-1006, "    Import updates:     %10u %10u %10u %10u %10u",
@@ -340,6 +340,7 @@ struct protocol proto_pipe = {
   .template =          "pipe%d",
   .multitable =                1,
   .preference =                DEF_PREF_PIPE,
+  .config_size =       sizeof(struct pipe_config),
   .postconfig =                pipe_postconfig,
   .init =              pipe_init,
   .start =             pipe_start,
index a26ea88e9ed95e866a336ddabdb7c7dc956ddf44..da300667cf06fd353cf9682be6dbf7bc81391444 100644 (file)
@@ -40,7 +40,7 @@ CF_ADDTO(proto, radv_proto)
 
 radv_proto_start: proto_start RADV
 {
-  this_proto = proto_config_new(&proto_radv, sizeof(struct radv_config), $1);
+  this_proto = proto_config_new(&proto_radv, $1);
   init_list(&RADV_CFG->patt_list);
   init_list(&RADV_CFG->pref_list);
   init_list(&RADV_CFG->rdnss_list);
index 6be7cd84720eaf56436bceaf267d42a459ef1eb5..6370e006f29f20bc5178a8a86f636b462e37b966 100644 (file)
@@ -207,7 +207,7 @@ radv_iface_remove(struct radv_iface *ifa)
 
 static void
 radv_if_notify(struct proto *p, unsigned flags, struct iface *iface)
-{ 
+{
   struct proto_radv *ra = (struct proto_radv *) p;
   struct radv_config *cf = (struct radv_config *) (p->cf);
 
@@ -361,7 +361,7 @@ radv_reconfigure(struct proto *p, struct proto_config *c)
   // struct radv_config *old = (struct radv_config *) (p->cf);
   struct radv_config *new = (struct radv_config *) c;
 
-  /* 
+  /*
    * The question is why there is a reconfigure function for RAdv if
    * it has almost none internal state so restarting the protocol
    * would probably suffice. One small reason is that restarting the
@@ -426,6 +426,7 @@ radv_get_status(struct proto *p, byte *buf)
 struct protocol proto_radv = {
   .name =              "RAdv",
   .template =          "radv%d",
+  .config_size =       sizeof(struct radv_config),
   .init =              radv_init,
   .start =             radv_start,
   .shutdown =          radv_shutdown,
index 7639752043f6ad6ba76016af97e4c8588b7198b0..b2b99095fe873eaf2b257ab8697cf8b9a06dbe23 100644 (file)
@@ -43,7 +43,7 @@ CF_GRAMMAR
 CF_ADDTO(proto, rip_cfg '}' { RIP_CFG->passwords = get_passwords(); } )
 
 rip_cfg_start: proto_start RIP {
-     this_proto = proto_config_new(&proto_rip, sizeof(struct rip_proto_config), $1);
+     this_proto = proto_config_new(&proto_rip, $1);
      rip_init_config(RIP_CFG);
    }
  ;
index f41f52e7b84e009f7e49947b35b1f179acd1a2a0..b77cf409da69a4902ea9c9d9e4786534b55ddbed 100644 (file)
@@ -1050,12 +1050,12 @@ struct protocol proto_rip = {
   .template =          "rip%d",
   .attr_class =                EAP_RIP,
   .preference =                DEF_PREF_RIP,
-  .get_route_info =    rip_get_route_info,
-  .get_attr =          rip_get_attr,
-
+  .config_size =       sizeof(struct rip_proto_config),
   .init =              rip_init,
   .dump =              rip_dump,
   .start =             rip_start,
   .reconfigure =       rip_reconfigure,
-  .copy_config =       rip_copy_config
+  .copy_config =       rip_copy_config,
+  .get_route_info =    rip_get_route_info,
+  .get_attr =          rip_get_attr
 };
index 2d9d4b42b3fb9cc5765af75abfdd4502e989a3f3..a8bfa36fa6f057f8bb628c1657be40e6c576af12 100644 (file)
@@ -26,7 +26,7 @@ CF_GRAMMAR
 CF_ADDTO(proto, static_proto '}')
 
 static_proto_start: proto_start STATIC {
-     this_proto = proto_config_new(&proto_static, sizeof(struct static_config), $1);
+     this_proto = proto_config_new(&proto_static, $1);
      static_init_config((struct static_config *) this_proto);
   }
  ;
index 8c31cdb8fe404a2b3c85a660e2a9603a7ca445e0..4b72fa9d37e76bc5ad7dbe7fa044b2945389b80f 100644 (file)
@@ -531,6 +531,7 @@ struct protocol proto_static = {
   .name =              "Static",
   .template =          "static%d",
   .preference =                DEF_PREF_STATIC,
+  .config_size =       sizeof(struct static_config),
   .init =              static_init,
   .dump =              static_dump,
   .start =             static_start,
index 398d1ebbe1262c31669012d24221e6187b1c6d27..78514cf5fa584fe87050e2f111d344e042f6d2fc 100644 (file)
@@ -251,7 +251,7 @@ kif_init_config(int class)
   if (kif_cf)
     cf_error("Kernel device protocol already defined");
 
-  kif_cf = (struct kif_config *) proto_config_new(&proto_unix_iface, sizeof(struct kif_config), class);
+  kif_cf = (struct kif_config *) proto_config_new(&proto_unix_iface, class);
   kif_cf->scan_time = 60;
   init_list(&kif_cf->primary);
 
@@ -280,6 +280,7 @@ struct protocol proto_unix_iface = {
   .name =              "Device",
   .template =          "device%d",
   .preference =                DEF_PREF_DIRECT,
+  .config_size =       sizeof(struct kif_config),
   .preconfig =         kif_preconfig,
   .init =              kif_init,
   .start =             kif_start,
@@ -1150,7 +1151,7 @@ krt_init_config(int class)
     cf_error("Kernel protocol already defined");
 #endif
 
-  krt_cf = (struct krt_config *) proto_config_new(&proto_unix_kernel, sizeof(struct krt_config), class);
+  krt_cf = (struct krt_config *) proto_config_new(&proto_unix_kernel, class);
   krt_cf->scan_time = 60;
 
   krt_sys_init_config(krt_cf);
@@ -1202,6 +1203,7 @@ struct protocol proto_unix_kernel = {
   .template =          "kernel%d",
   .attr_class =                EAP_KRT,
   .preference =                DEF_PREF_INHERITED,
+  .config_size =       sizeof(struct krt_config),
   .preconfig =         krt_preconfig,
   .postconfig =                krt_postconfig,
   .init =              krt_init,