Skip to content

Commit a75e35a

Browse files
liuhangbinapconole
authored andcommitted
lldpad: remove device from config file when ports are removed
When ports are removed, there is no need to keep them in the configuration file. Otherwise, the port list could grow too large to manage. For example, if a user adds hundreds of virtual ports for testing and then removes them after the test, the configuration file would retain this information indefinitely. Removing these entries ensures the configuration file remains manageable. Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Signed-off-by: Aaron Conole <aconole@redhat.com>
1 parent f487b89 commit a75e35a

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

config.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,32 @@ int get_config_setting(const char *ifname, int agenttype, char *path,
472472
return (rval == CONFIG_FALSE) ? cmd_failed : cmd_success;
473473
}
474474

475+
int remove_config_device(const char *ifname, int agenttype)
476+
{
477+
const char *section = agent_type2section(agenttype);
478+
config_setting_t *setting = NULL;
479+
int rval = cmd_failed;
480+
481+
setting = config_lookup(&lldpad_cfg, section);
482+
483+
if (setting != NULL) {
484+
rval = config_setting_remove(setting, ifname);
485+
if (rval == CONFIG_TRUE) {
486+
LLDPAD_DBG("In %s, remove %s from section %s\n", __func__, ifname, section);
487+
if (config_write_file(&lldpad_cfg, cfg_file_name)) {
488+
rval = cmd_success;
489+
} else {
490+
LLDPAD_DBG("In %s, update config failed\n", __func__);
491+
rval = cmd_failed;
492+
}
493+
}
494+
} else {
495+
LLDPAD_DBG("In %s, can't find section %s\n", __func__, section);
496+
}
497+
498+
return rval;
499+
}
500+
475501
int remove_config_setting(const char *ifname, int agenttype, char *parent,
476502
char *name)
477503
{

include/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ int get_cfg(const char *ifname, int agenttype, char *path, union cfg_get value,
7979
int set_cfg(const char *ifname, int agenttype, char *path, union cfg_set value, int type);
8080
int get_config_setting(const char *ifname, int agenttype, char *path, union cfg_get value, int type);
8181
int set_config_setting(const char *ifname, int agenttype, char *path, union cfg_set value, int type);
82+
int remove_config_device(const char *ifname, int agenttype);
8283
int remove_config_setting(const char *ifname, int agenttype, char *parent, char *name);
8384
int get_config_tlvfield(const char *ifname, int agenttype, u32 tlvid, const char *field, union cfg_get value, int type);
8485
int get_config_tlvfield_int(const char *ifname, int agenttype, u32 tlvid, const char *field, int *value);

lldp/ports.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ int remove_port(const char *ifname)
355355
free(agent->tx.frameout);
356356

357357
LIST_REMOVE(agent, entry);
358+
359+
remove_config_device(ifname, agent->type);
360+
358361
free(agent);
359362
}
360363

0 commit comments

Comments
 (0)