Store protocol config size inside protocol structure
Make proto_config_new() use this info instead of supplied size. Thanks to Alexander V. Chernikov for the patch.
This commit is contained in:
parent
374917adcc
commit
2bbc308321
19 changed files with 38 additions and 29 deletions
|
@ -307,7 +307,7 @@ tos:
|
||||||
CF_ADDTO(proto, dev_proto '}')
|
CF_ADDTO(proto, dev_proto '}')
|
||||||
|
|
||||||
dev_proto_start: proto_start DIRECT {
|
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);
|
init_list(&DIRECT_CFG->iface_list);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
|
@ -245,7 +245,6 @@ proto_free_ahooks(struct proto *p)
|
||||||
/**
|
/**
|
||||||
* proto_config_new - create a new protocol configuration
|
* proto_config_new - create a new protocol configuration
|
||||||
* @pr: protocol the configuration will belong to
|
* @pr: protocol the configuration will belong to
|
||||||
* @size: size of the structure including generic data
|
|
||||||
* @class: SYM_PROTO or SYM_TEMPLATE
|
* @class: SYM_PROTO or SYM_TEMPLATE
|
||||||
*
|
*
|
||||||
* Whenever the configuration file says that a new instance
|
* Whenever the configuration file says that a new instance
|
||||||
|
@ -262,9 +261,9 @@ proto_free_ahooks(struct proto *p)
|
||||||
* initialized during protos_commit()).
|
* initialized during protos_commit()).
|
||||||
*/
|
*/
|
||||||
void *
|
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)
|
if (class == SYM_PROTO)
|
||||||
add_tail(&new_config->protos, &c->n);
|
add_tail(&new_config->protos, &c->n);
|
||||||
|
|
|
@ -40,7 +40,8 @@ struct protocol {
|
||||||
int name_counter; /* Counter for automatic name generation */
|
int name_counter; /* Counter for automatic name generation */
|
||||||
int attr_class; /* Attribute class known to this protocol */
|
int attr_class; /* Attribute class known to this protocol */
|
||||||
int multitable; /* Protocol handles all announce hooks itself */
|
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 (*preconfig)(struct protocol *, struct config *); /* Just before configuring */
|
||||||
void (*postconfig)(struct proto_config *); /* After configuring each instance */
|
void (*postconfig)(struct proto_config *); /* After configuring each instance */
|
||||||
|
@ -239,7 +240,7 @@ struct proto_spec {
|
||||||
|
|
||||||
|
|
||||||
void *proto_new(struct proto_config *, unsigned size);
|
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_copy_config(struct proto_config *dest, struct proto_config *src);
|
||||||
void proto_request_feeding(struct proto *p);
|
void proto_request_feeding(struct proto *p);
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,7 @@ struct protocol proto_device = {
|
||||||
.name = "Direct",
|
.name = "Direct",
|
||||||
.template = "direct%d",
|
.template = "direct%d",
|
||||||
.preference = DEF_PREF_DIRECT,
|
.preference = DEF_PREF_DIRECT,
|
||||||
|
.config_size = sizeof(struct rt_dev_config),
|
||||||
.init = dev_init,
|
.init = dev_init,
|
||||||
.reconfigure = dev_reconfigure,
|
.reconfigure = dev_reconfigure,
|
||||||
.copy_config = dev_copy_config
|
.copy_config = dev_copy_config
|
||||||
|
|
|
@ -1112,6 +1112,7 @@ bfd_show_sessions(struct proto *P)
|
||||||
struct protocol proto_bfd = {
|
struct protocol proto_bfd = {
|
||||||
.name = "BFD",
|
.name = "BFD",
|
||||||
.template = "bfd%d",
|
.template = "bfd%d",
|
||||||
|
.config_size = sizeof(struct bfd_config),
|
||||||
.init = bfd_init,
|
.init = bfd_init,
|
||||||
.start = bfd_start,
|
.start = bfd_start,
|
||||||
.shutdown = bfd_shutdown,
|
.shutdown = bfd_shutdown,
|
||||||
|
|
|
@ -34,7 +34,7 @@ CF_ADDTO(proto, bfd_proto)
|
||||||
|
|
||||||
bfd_proto_start: proto_start BFD
|
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->patt_list);
|
||||||
init_list(&BFD_CFG->neigh_list);
|
init_list(&BFD_CFG->neigh_list);
|
||||||
|
|
||||||
|
|
|
@ -1455,6 +1455,7 @@ struct protocol proto_bgp = {
|
||||||
.template = "bgp%d",
|
.template = "bgp%d",
|
||||||
.attr_class = EAP_BGP,
|
.attr_class = EAP_BGP,
|
||||||
.preference = DEF_PREF_BGP,
|
.preference = DEF_PREF_BGP,
|
||||||
|
.config_size = sizeof(struct bgp_config),
|
||||||
.init = bgp_init,
|
.init = bgp_init,
|
||||||
.start = bgp_start,
|
.start = bgp_start,
|
||||||
.shutdown = bgp_shutdown,
|
.shutdown = bgp_shutdown,
|
||||||
|
|
|
@ -34,7 +34,7 @@ CF_GRAMMAR
|
||||||
CF_ADDTO(proto, bgp_proto '}' { bgp_check_config(BGP_CFG); } )
|
CF_ADDTO(proto, bgp_proto '}' { bgp_check_config(BGP_CFG); } )
|
||||||
|
|
||||||
bgp_proto_start: proto_start BGP {
|
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->multihop = -1; /* undefined */
|
||||||
BGP_CFG->hold_time = 240;
|
BGP_CFG->hold_time = 240;
|
||||||
BGP_CFG->connect_retry_time = 120;
|
BGP_CFG->connect_retry_time = 120;
|
||||||
|
|
|
@ -141,7 +141,7 @@ CF_GRAMMAR
|
||||||
CF_ADDTO(proto, ospf_proto '}' { ospf_proto_finish(); } )
|
CF_ADDTO(proto, ospf_proto '}' { ospf_proto_finish(); } )
|
||||||
|
|
||||||
ospf_proto_start: proto_start OSPF {
|
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->area_list);
|
||||||
init_list(&OSPF_CFG->vlink_list);
|
init_list(&OSPF_CFG->vlink_list);
|
||||||
OSPF_CFG->tick = OSPF_DEFAULT_TICK;
|
OSPF_CFG->tick = OSPF_DEFAULT_TICK;
|
||||||
|
|
|
@ -1457,6 +1457,7 @@ struct protocol proto_ospf = {
|
||||||
.template = "ospf%d",
|
.template = "ospf%d",
|
||||||
.attr_class = EAP_OSPF,
|
.attr_class = EAP_OSPF,
|
||||||
.preference = DEF_PREF_OSPF,
|
.preference = DEF_PREF_OSPF,
|
||||||
|
.config_size = sizeof(struct ospf_config),
|
||||||
.init = ospf_init,
|
.init = ospf_init,
|
||||||
.dump = ospf_dump,
|
.dump = ospf_dump,
|
||||||
.start = ospf_start,
|
.start = ospf_start,
|
||||||
|
|
|
@ -23,7 +23,7 @@ CF_GRAMMAR
|
||||||
CF_ADDTO(proto, pipe_proto '}')
|
CF_ADDTO(proto, pipe_proto '}')
|
||||||
|
|
||||||
pipe_proto_start: proto_start PIPE {
|
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;
|
PIPE_CFG->mode = PIPE_TRANSPARENT;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
|
@ -340,6 +340,7 @@ struct protocol proto_pipe = {
|
||||||
.template = "pipe%d",
|
.template = "pipe%d",
|
||||||
.multitable = 1,
|
.multitable = 1,
|
||||||
.preference = DEF_PREF_PIPE,
|
.preference = DEF_PREF_PIPE,
|
||||||
|
.config_size = sizeof(struct pipe_config),
|
||||||
.postconfig = pipe_postconfig,
|
.postconfig = pipe_postconfig,
|
||||||
.init = pipe_init,
|
.init = pipe_init,
|
||||||
.start = pipe_start,
|
.start = pipe_start,
|
||||||
|
|
|
@ -40,7 +40,7 @@ CF_ADDTO(proto, radv_proto)
|
||||||
|
|
||||||
radv_proto_start: proto_start RADV
|
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->patt_list);
|
||||||
init_list(&RADV_CFG->pref_list);
|
init_list(&RADV_CFG->pref_list);
|
||||||
init_list(&RADV_CFG->rdnss_list);
|
init_list(&RADV_CFG->rdnss_list);
|
||||||
|
|
|
@ -426,6 +426,7 @@ radv_get_status(struct proto *p, byte *buf)
|
||||||
struct protocol proto_radv = {
|
struct protocol proto_radv = {
|
||||||
.name = "RAdv",
|
.name = "RAdv",
|
||||||
.template = "radv%d",
|
.template = "radv%d",
|
||||||
|
.config_size = sizeof(struct radv_config),
|
||||||
.init = radv_init,
|
.init = radv_init,
|
||||||
.start = radv_start,
|
.start = radv_start,
|
||||||
.shutdown = radv_shutdown,
|
.shutdown = radv_shutdown,
|
||||||
|
|
|
@ -43,7 +43,7 @@ CF_GRAMMAR
|
||||||
CF_ADDTO(proto, rip_cfg '}' { RIP_CFG->passwords = get_passwords(); } )
|
CF_ADDTO(proto, rip_cfg '}' { RIP_CFG->passwords = get_passwords(); } )
|
||||||
|
|
||||||
rip_cfg_start: proto_start RIP {
|
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);
|
rip_init_config(RIP_CFG);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
|
@ -1050,12 +1050,12 @@ struct protocol proto_rip = {
|
||||||
.template = "rip%d",
|
.template = "rip%d",
|
||||||
.attr_class = EAP_RIP,
|
.attr_class = EAP_RIP,
|
||||||
.preference = DEF_PREF_RIP,
|
.preference = DEF_PREF_RIP,
|
||||||
.get_route_info = rip_get_route_info,
|
.config_size = sizeof(struct rip_proto_config),
|
||||||
.get_attr = rip_get_attr,
|
|
||||||
|
|
||||||
.init = rip_init,
|
.init = rip_init,
|
||||||
.dump = rip_dump,
|
.dump = rip_dump,
|
||||||
.start = rip_start,
|
.start = rip_start,
|
||||||
.reconfigure = rip_reconfigure,
|
.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
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,7 +26,7 @@ CF_GRAMMAR
|
||||||
CF_ADDTO(proto, static_proto '}')
|
CF_ADDTO(proto, static_proto '}')
|
||||||
|
|
||||||
static_proto_start: proto_start STATIC {
|
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);
|
static_init_config((struct static_config *) this_proto);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
|
@ -531,6 +531,7 @@ struct protocol proto_static = {
|
||||||
.name = "Static",
|
.name = "Static",
|
||||||
.template = "static%d",
|
.template = "static%d",
|
||||||
.preference = DEF_PREF_STATIC,
|
.preference = DEF_PREF_STATIC,
|
||||||
|
.config_size = sizeof(struct static_config),
|
||||||
.init = static_init,
|
.init = static_init,
|
||||||
.dump = static_dump,
|
.dump = static_dump,
|
||||||
.start = static_start,
|
.start = static_start,
|
||||||
|
|
|
@ -251,7 +251,7 @@ kif_init_config(int class)
|
||||||
if (kif_cf)
|
if (kif_cf)
|
||||||
cf_error("Kernel device protocol already defined");
|
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;
|
kif_cf->scan_time = 60;
|
||||||
init_list(&kif_cf->primary);
|
init_list(&kif_cf->primary);
|
||||||
|
|
||||||
|
@ -280,6 +280,7 @@ struct protocol proto_unix_iface = {
|
||||||
.name = "Device",
|
.name = "Device",
|
||||||
.template = "device%d",
|
.template = "device%d",
|
||||||
.preference = DEF_PREF_DIRECT,
|
.preference = DEF_PREF_DIRECT,
|
||||||
|
.config_size = sizeof(struct kif_config),
|
||||||
.preconfig = kif_preconfig,
|
.preconfig = kif_preconfig,
|
||||||
.init = kif_init,
|
.init = kif_init,
|
||||||
.start = kif_start,
|
.start = kif_start,
|
||||||
|
@ -1150,7 +1151,7 @@ krt_init_config(int class)
|
||||||
cf_error("Kernel protocol already defined");
|
cf_error("Kernel protocol already defined");
|
||||||
#endif
|
#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_cf->scan_time = 60;
|
||||||
|
|
||||||
krt_sys_init_config(krt_cf);
|
krt_sys_init_config(krt_cf);
|
||||||
|
@ -1202,6 +1203,7 @@ struct protocol proto_unix_kernel = {
|
||||||
.template = "kernel%d",
|
.template = "kernel%d",
|
||||||
.attr_class = EAP_KRT,
|
.attr_class = EAP_KRT,
|
||||||
.preference = DEF_PREF_INHERITED,
|
.preference = DEF_PREF_INHERITED,
|
||||||
|
.config_size = sizeof(struct krt_config),
|
||||||
.preconfig = krt_preconfig,
|
.preconfig = krt_preconfig,
|
||||||
.postconfig = krt_postconfig,
|
.postconfig = krt_postconfig,
|
||||||
.init = krt_init,
|
.init = krt_init,
|
||||||
|
|
Loading…
Reference in a new issue