File: dropped_25_duplicate_iftable.patch

package info (click to toggle)
net-snmp 5.7.2.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 34,348 kB
  • sloc: ansic: 268,086; sh: 18,217; perl: 17,235; makefile: 3,702; xml: 508; python: 495; pascal: 124; sql: 47
file content (115 lines) | stat: -rw-r--r-- 4,490 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
Patch from
http://sourceforge.net/tracker/index.php?func=detail&aid=1513191&group_id=12694&atid=312694 :

This patch fixes bug #1238981 for me. If a new device
will be added, the old device are first checked. If
there's an old device with the same name is found, the
old device is removed from the list. This fixes the
problem that i have tons of ppp0 interfaces in the
snmpd ifTable.

Signed-of-by: Sven Schnelle <svens@gmx.de>

-> not applied to current code. need to investigate more 
  Hideki Yamane <henrich@debian.org>


diff -ru net-snmp-5.4.2.1.orig/agent/mibgroup/if-mib/data_access/interface.c net-snmp-5.4.2.1/agent/mibgroup/if-mib/data_access/interface.c
--- net-snmp-5.4.2.1.orig/agent/mibgroup/if-mib/data_access/interface.c	2008-02-23 00:52:33.000000000 +0100
+++ net-snmp-5.4.2.1/agent/mibgroup/if-mib/data_access/interface.c	2009-07-31 17:10:49.000000000 +0200
@@ -469,12 +469,12 @@
         if (index != tmp) {
             static int logged = 0;
             if (!logged) {
-                snmp_log(LOG_ERR, "IfIndex of an interface changed. Such " \
-                         "interfaces will appear multiple times in IF-MIB.\n");
+                snmp_log(LOG_ERR, "IfIndex of an interface changed.\n");
                 logged = 1;
             }
-            DEBUGMSGTL(("access:interface:ifIndex", "index %d != tmp for %s\n",
-                         index, name));
+	    se_remove_value_from_slist("interfaces", name);
+	    se_add_pair_to_slist("interfaces", strdup(name), index);
+	    DEBUGMSGTL(("access:interface:ifIndex", "ifname %s, old index %d, already existing, replaced with %d\n", name, tmp, index));
         }
 }
 
diff -ru net-snmp-5.4.2.1.orig/agent/mibgroup/if-mib/ifTable/ifTable_data_access.c net-snmp-5.4.2.1/agent/mibgroup/if-mib/ifTable/ifTable_data_access.c
--- net-snmp-5.4.2.1.orig/agent/mibgroup/if-mib/ifTable/ifTable_data_access.c	2008-02-12 20:05:24.000000000 +0100
+++ net-snmp-5.4.2.1/agent/mibgroup/if-mib/ifTable/ifTable_data_access.c	2009-07-31 17:04:17.000000000 +0200
@@ -266,8 +266,21 @@
 _add_new_interface(netsnmp_interface_entry *ifentry,
                    netsnmp_container *container)
 {
-    ifTable_rowreq_ctx *rowreq_ctx;
-
+    ifTable_rowreq_ctx *rowreq_ctx, *container_entry;
+    netsnmp_iterator *ctxit;
+    ctxit = CONTAINER_ITERATOR(container);
+    container_entry = ITERATOR_FIRST(ctxit);
+
+    for(; container_entry; container_entry = ITERATOR_NEXT(ctxit)) {
+	if(!strcmp(ifentry->name, container_entry->data.ifName) && \
+	    ifentry->index != container_entry->data.ifentry->index) {
+		DEBUGMSGTL(("ifTable:access", "removing old entry %s (index %d != %d)\n",
+		    container_entry->data.ifName, container_entry->data.ifentry->index, ifentry->index));
+		    se_remove_value_from_slist("interfaces", container_entry->data.ifName);
+		CONTAINER_REMOVE(container, container_entry);
+		ifTable_release_rowreq_ctx(container_entry);
+		}
+    }
     DEBUGMSGTL(("ifTable:access", "creating new entry\n"));
 
     /*
Nur in net-snmp-5.4.2.1/agent/mibgroup/if-mib/ifTable: ifTable_data_access.c.orig.
diff -ru net-snmp-5.4.2.1.orig/snmplib/snmp_enum.c net-snmp-5.4.2.1/snmplib/snmp_enum.c
--- net-snmp-5.4.2.1.orig/snmplib/snmp_enum.c	2005-02-09 20:46:35.000000000 +0100
+++ net-snmp-5.4.2.1/snmplib/snmp_enum.c	2009-07-31 17:04:17.000000000 +0200
@@ -213,6 +213,27 @@
     return SE_DNE;              /* XXX: um, no good solution here */
 }
 
+int se_remove_value_from_list(struct snmp_enum_list **list, const char *label)
+{
+   struct snmp_enum_list *lastlist;
+   if(!list)
+     return SE_DNE;
+
+   lastlist = NULL;
+   while(*list) {
+      if(strcmp((*list)->label, label) == 0) {
+	 free((*list)->label);
+	 if(lastlist)
+	   lastlist->next = (*list)->next;
+	 free(*list);
+	 *list = NULL;
+	 return 0;
+      }
+      lastlist = *list;
+      (*list) = (*list)->next;
+   }
+   
+}
 int
 se_find_free_value_in_list(struct snmp_enum_list *list)
 {
@@ -331,6 +352,19 @@
     return (se_find_value_in_list(se_find_slist(listname), label));
 }
 
+void se_remove_value_from_slist(const char *listname, const char *label)
+{
+   struct snmp_enum_list_str *sptr, *lastp = NULL;
+   struct snmp_enum_list *list;
+   if (!listname)
+     return;
+
+   for (sptr = sliststorage;
+	sptr != NULL; lastp = sptr, sptr = sptr->next)
+     if (sptr->name && strcmp(sptr->name, listname) == 0)
+       se_remove_value_from_list(&sptr->list, label);
+}
+
 int
 se_find_free_value_in_slist(const char *listname)
 {