Blame SOURCES/0008-Revert-Use-interface-index-instead-of-name-in-libcon.patch

449e93
From 79658533561990d93a74fd25b4d1b26c01182a8e Mon Sep 17 00:00:00 2001
449e93
From: Aaron Conole <aconole@redhat.com>
449e93
Date: Mon, 20 Sep 2021 16:27:56 -0400
449e93
Subject: [PATCH 8/8] Revert "Use interface index instead of name in libconfig"
449e93
449e93
This reverts commit e272d34f45bc15d52424228f824c1ad96932867e.
449e93
449e93
During production, it was found that the ifindex can be unstable.
449e93
See discussion at https://github.com/intel/openlldp/pull/3
449e93
449e93
Signed-off-by: Aaron Conole <aconole@redhat.com>
449e93
(cherry picked from commit 2c7dd5e4a0db201a850f8037b957acbd14950297)
449e93
---
449e93
 config.c         | 35 ++++++++---------------------------
449e93
 include/config.h |  3 ---
449e93
 lldp_dcbx_cfg.c  | 24 +++++++-----------------
449e93
 3 files changed, 15 insertions(+), 47 deletions(-)
449e93
449e93
diff --git a/config.c b/config.c
449e93
index 41b5045..7e969b9 100644
449e93
--- a/config.c
449e93
+++ b/config.c
449e93
@@ -55,21 +55,6 @@
449e93
 
449e93
 config_t lldpad_cfg;
449e93
 
449e93
-/*
449e93
- * config_ifkey - Generates a config key
449e93
- *
449e93
- * Given an interface name this functions generates
449e93
- * a key (based on interface's index) suitable
449e93
- * to pass to libconfig.
449e93
- *
449e93
- */
449e93
-void config_ifkey(const char *name, char *ifkey) {
449e93
-	int index = if_nametoindex(name);
449e93
-	
449e93
-	if(index)
449e93
-		sprintf(ifkey, "if%d", index);
449e93
-}
449e93
-
449e93
 /*
449e93
  * init_cfg - initialze the global lldpad_cfg via config_init
449e93
  *
449e93
@@ -466,15 +451,14 @@ static int lookup_config_value(char *path, union cfg_get v, int type)
449e93
 int get_config_setting(const char *ifname, int agenttype, char *path,
449e93
 		       union cfg_get v, int type)
449e93
 {
449e93
-	char p[1024], ifkey[IFNAMSIZ];
449e93
+	char p[1024];
449e93
 	int rval = CONFIG_FALSE;
449e93
 	const char *section = agent_type2section(agenttype);
449e93
 
449e93
 	/* look for setting in section->ifname area first */
449e93
 	if (ifname) {
449e93
-		config_ifkey(ifname, ifkey);
449e93
 		snprintf(p, sizeof(p), "%s.%s.%s",
449e93
-			 section, ifkey, path);
449e93
+			 section, ifname, path);
449e93
 		rval = lookup_config_value(p, v, type);
449e93
 	}
449e93
 
449e93
@@ -491,16 +475,15 @@ int get_config_setting(const char *ifname, int agenttype, char *path,
449e93
 int remove_config_setting(const char *ifname, int agenttype, char *parent,
449e93
 			  char *name)
449e93
 {
449e93
-	char p[1024], ifkey[IFNAMSIZ];
449e93
+	char p[1024];
449e93
 	int rval = CONFIG_FALSE;
449e93
 	config_setting_t *setting = NULL;
449e93
 	const char *section = agent_type2section(agenttype);
449e93
 
449e93
 	/* look for setting in section->ifname area first */
449e93
-	if (ifname) { 
449e93
-		config_ifkey(ifname, ifkey);
449e93
+	if (ifname) {
449e93
 		snprintf(p, sizeof(p), "%s.%s.%s",
449e93
-			 section, ifkey, parent);
449e93
+			 section, ifname, parent);
449e93
 		setting = config_lookup(&lldpad_cfg, p);
449e93
 	}
449e93
 
449e93
@@ -587,17 +570,15 @@ int set_config_setting(const char *ifname, int agenttype, char *path,
449e93
 		       union cfg_set v, int type)
449e93
 {
449e93
 	config_setting_t *setting = NULL;
449e93
-	char p[1024], ifkey[IFNAMSIZ];
449e93
+	char p[1024];
449e93
 	int rval = cmd_success;
449e93
 	const char *section = agent_type2section(agenttype);
449e93
 
449e93
 	LLDPAD_DBG("%s(%i): \n", __func__, __LINE__);
449e93
 
449e93
-	if (strlen(ifname)){
449e93
-		config_ifkey(ifname, ifkey);
449e93
+	if (strlen(ifname))
449e93
 		snprintf(p, sizeof(p), "%s.%s.%s",
449e93
-			 section, ifkey, path);
449e93
-	}
449e93
+			 section, ifname, path);
449e93
 	else
449e93
 		snprintf(p, sizeof(p), "%s.%s.%s",
449e93
 			 section, LLDP_COMMON, path);
449e93
diff --git a/include/config.h b/include/config.h
449e93
index 3abf8e8..61cb5da 100644
449e93
--- a/include/config.h
449e93
+++ b/include/config.h
449e93
@@ -111,7 +111,4 @@ void destroy_cfg(void);
449e93
 int check_cfg_file(void);
449e93
 int check_for_old_file_format(void);
449e93
 void init_ports(void);
449e93
-
449e93
-void config_ifkey(const char *name, char *ifkey);
449e93
-
449e93
 #endif /* _CONFIG_H_ */
449e93
diff --git a/lldp_dcbx_cfg.c b/lldp_dcbx_cfg.c
449e93
index 40cabb2..ab9cc35 100644
449e93
--- a/lldp_dcbx_cfg.c
449e93
+++ b/lldp_dcbx_cfg.c
449e93
@@ -99,15 +99,12 @@ static config_setting_t *construct_new_setting(char *device_name)
449e93
 	config_setting_t *tmp2_setting = NULL;
449e93
 	char abuf[32];
449e93
 	int i;
449e93
-	char device_name_sanitized[IFNAMSIZ];
449e93
 
449e93
 	dcbx_setting = config_lookup(&lldpad_cfg, DCBX_SETTING);
449e93
 	if (!dcbx_setting)
449e93
 		return NULL;
449e93
 
449e93
-	config_ifkey(device_name, device_name_sanitized);
449e93
-
449e93
-	eth_setting = config_setting_add(dcbx_setting, device_name_sanitized,
449e93
+	eth_setting = config_setting_add(dcbx_setting, device_name,
449e93
 		CONFIG_TYPE_GROUP);
449e93
 	if (!eth_setting)
449e93
 		goto set_error;
449e93
@@ -374,13 +371,11 @@ static int _set_persistent(char *device_name, int dcb_enable,
449e93
 	config_setting_t *setting_value = NULL;
449e93
 	char abuf[2*DCB_MAX_TLV_LENGTH + 1];
449e93
 	int result, i;
449e93
-	char device_name_sanitized[IFNAMSIZ];
449e93
 
449e93
 	dcbx_setting = config_lookup(&lldpad_cfg, DCBX_SETTING);
449e93
-	config_ifkey(device_name, device_name_sanitized);
449e93
 	if (dcbx_setting)
449e93
 		eth_settings = config_setting_get_member(dcbx_setting,
449e93
-							 device_name_sanitized);
449e93
+							 device_name);
449e93
 
449e93
 	/* init the internal data store for device_name */
449e93
 	if (NULL == eth_settings) {
449e93
@@ -787,15 +782,13 @@ int get_persistent(char *device_name, full_dcb_attribs *attribs)
449e93
 	int result = cmd_failed, i;
449e93
 	int results[MAX_USER_PRIORITIES];
449e93
 	int len;
449e93
-	char abuf[32], device_name_sanitized[IFNAMSIZ];
449e93
+	char abuf[32];
449e93
 
449e93
 	memset(attribs, 0, sizeof(*attribs));
449e93
 	dcbx_setting = config_lookup(&lldpad_cfg, DCBX_SETTING);
449e93
-
449e93
-	config_ifkey(device_name, device_name_sanitized);
449e93
 	if (dcbx_setting)
449e93
-		eth_settings = config_setting_get_member(dcbx_setting, 
449e93
-							 device_name_sanitized);
449e93
+		eth_settings = config_setting_get_member(dcbx_setting,
449e93
+							 device_name);
449e93
 
449e93
 	/* init the internal data store for device_name */
449e93
 	result = get_default_persistent(device_name, attribs);
449e93
@@ -1074,16 +1067,13 @@ int get_dcb_enable_state(char *ifname, int *result)
449e93
 	int rc = EINVAL;
449e93
 	config_setting_t *settings = NULL;
449e93
 	char path[sizeof(DCBX_SETTING) + IFNAMSIZ + 16];
449e93
-	char ifkey[IFNAMSIZ];
449e93
-
449e93
-	config_ifkey(ifname, ifkey);
449e93
 
449e93
 	memset(path, 0, sizeof(path));
449e93
-	snprintf(path, sizeof(path), "%s.%s.dcb_enable", DCBX_SETTING, ifkey); 
449e93
+	snprintf(path, sizeof(path), "%s.%s.dcb_enable", DCBX_SETTING, ifname);
449e93
 	settings = config_lookup(&lldpad_cfg, path);
449e93
 	if (!settings) {
449e93
 		LLDPAD_INFO("### %s:%s:failed on %s\n", __func__, ifname, path);
449e93
-		snprintf(path, sizeof(path), "%s.dcb_enable", ifkey); 
449e93
+		snprintf(path, sizeof(path), "%s.dcb_enable", ifname);
449e93
 		settings = config_lookup(&lldpad_cfg, path);
449e93
 		if (!settings) {
449e93
 			LLDPAD_INFO("### %s:%s:failed again %s\n", __func__, ifname, path);
449e93
-- 
449e93
2.31.1
449e93