From 72163bd5f3ccefc1edda585f6f605c37e774a0b8 Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Tue, 9 Jan 2018 18:42:22 +0100 Subject: Nest: Allow modification of channels inherited from templates Multiple definitions of same channels are forbidden, but inherited channel can be redefined. In such case channel options are merged. --- nest/proto.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'nest/proto.c') diff --git a/nest/proto.c b/nest/proto.c index e103fec6..d584cb93 100644 --- a/nest/proto.c +++ b/nest/proto.c @@ -455,11 +455,10 @@ const struct channel_class channel_basic = { }; void * -channel_config_new(const struct channel_class *cc, uint net_type, struct proto_config *proto) +channel_config_new(const struct channel_class *cc, const char *name, uint net_type, struct proto_config *proto) { struct channel_config *cf = NULL; struct rtable_config *tab = NULL; - const char *name = NULL; if (net_type) { @@ -470,7 +469,6 @@ channel_config_new(const struct channel_class *cc, uint net_type, struct proto_c cf_error("Different channel type"); tab = new_config->def_tables[net_type]; - name = net_label[net_type]; } if (!cc) @@ -479,6 +477,7 @@ channel_config_new(const struct channel_class *cc, uint net_type, struct proto_c cf = cfg_allocz(cc->config_size); cf->name = name; cf->channel = cc; + cf->parent = proto; cf->table = tab; cf->out_filter = FILTER_REJECT; @@ -491,6 +490,26 @@ channel_config_new(const struct channel_class *cc, uint net_type, struct proto_c return cf; } +void * +channel_config_get(const struct channel_class *cc, const char *name, uint net_type, struct proto_config *proto) +{ + struct channel_config *cf; + + /* We are using name as token, so no strcmp() */ + WALK_LIST(cf, proto->channels) + if (cf->name == name) + { + /* Allow to redefine channel only if inherited from template */ + if (cf->parent == proto) + cf_error("Multiple %s channels", name); + + cf->parent = proto; + return cf; + } + + return channel_config_new(cc, name, net_type, proto); +} + struct channel_config * channel_copy_config(struct channel_config *src, struct proto_config *proto) { -- cgit v1.2.3