Current implementation of ipv6IfTable never reloads list of interfaces,
deleted or added interfaces never (dis-)appear from the table.
This patch reloads the list of interfaces whenever the table is
accessed. It adds also minor optimization (store last number of
interfaces so realloc() probably won't be needed),
Please note that I've already checked the patch into SVN, not knowing
there are new checkin rules. I'll revert it if I won't get enough votes.
Jan
net-snmp/agent/mibgroup/mibII/ipv6.c | 21 ++++++++++++++++++---
1 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/net-snmp/agent/mibgroup/mibII/ipv6.c
b/net-snmp/agent/mibgroup/mibII/ipv6.c
index 1df4751..9dc0976 100644
--- a/net-snmp/agent/mibgroup/mibII/ipv6.c
+++ b/net-snmp/agent/mibgroup/mibII/ipv6.c
@@ -778,6 +778,10 @@ var_ifv6Entry(register struct variable * vp,
int max;
char *p;
+ /* Reload list of interfaces */
+ if (if_initialize() < 0)
+ return NULL;
+
max = if_maxifindex();
if (max < 0)
return NULL;
@@ -1078,6 +1082,10 @@ var_icmpv6Entry(register struct variable * vp,
int interface;
int max;
+ /* Reload list of interfaces */
+ if (if_initialize() < 0)
+ return NULL;
+
max = if_maxifindex();
if (max < 0)
return NULL;
@@ -1953,6 +1961,10 @@ var_ifv6Entry(register struct variable * vp,
struct ifreq ifr;
int s;
+ /* Reload list of interfaces */
+ if (if_initialize() < 0)
+ return NULL;
+
max = if_maxifindex();
if (max < 0)
return NULL;
@@ -2098,10 +2110,11 @@ linux_if_freenameindex(struct if_nameindex *ifndx)
int i;
if (!ifndx)
return;
- for (i = 1; ifndx[i].if_index; i++) {
+ for (i = 0; ifndx[i].if_index; i++) {
free(ifndx[i].if_name);
}
free(ifndx);
+ ifndx = NULL;
}
#define linux_freeinternalnameindex(ifni, max) { \
@@ -2122,6 +2135,7 @@ linux_if_nameindex(void)
struct if_nameindex *ifndx = NULL, *iflist = NULL, *tmp;
int i, j;
int maxidx, if_count = 0;
+ static int last_if_count;
f = fopen(LINUX_PROC_NET_IFINET6, "r");
if (f) {
@@ -2135,10 +2149,11 @@ linux_if_nameindex(void)
continue;
if_name[sizeof(if_name) - 1] = '\0';
if (maxidx < 0 || maxidx < if_index) {
-
+ if (last_if_count < if_index)
+ last_if_count = if_index;
tmp =
realloc(iflist,
- (sizeof(struct if_nameindex)) * (if_index +
+ (sizeof(struct if_nameindex)) * (last_if_count +
2));
if (!tmp) {
linux_freeinternalnameindex(iflist, if_index);
------------------------------------------------------------------------------
This SF Dev2Dev email is sponsored by:
WikiLeaks The End of the Free Internet
http://p.sf.net/sfu/therealnews-com
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders