]> git.pld-linux.org Git - packages/net-snmp.git/blame - net-snmp-duplicate-ip.patch
- patch not to fail if same ip seen in different interfaces; rel 11
[packages/net-snmp.git] / net-snmp-duplicate-ip.patch
CommitLineData
273fb569
ER
1Index: snmplib/container_binary_array.c
2===================================================================
3--- snmplib/container_binary_array.c (revision 16471)
4+++ snmplib/container_binary_array.c (working copy)
5@@ -579,6 +579,11 @@
6 return va;
7 }
8
9+static int _ba_options(netsnmp_container *c, int set, u_int flags)
10+{
11+ return netsnmp_binary_array_options_set(c, set, flags);
12+}
13+
14 netsnmp_container *
15 netsnmp_container_get_binary_array(void)
16 {
17@@ -604,6 +609,7 @@
18 c->get_iterator = _ba_iterator_get;
19 c->for_each = _ba_for_each;
20 c->clear = _ba_clear;
21+ c->options = _ba_options;
22
23 return c;
24 }
25Index: snmplib/container.c
26===================================================================
27--- snmplib/container.c (revision 16471)
28+++ snmplib/container.c (working copy)
29@@ -268,19 +268,64 @@
30 int CONTAINER_INSERT(netsnmp_container *x, const void *k)
31 {
32 int rc2, rc = 0;
33+ netsnmp_container *start;
34+ int silent = 0;
35
36 /** start at first container */
37 while(x->prev)
38 x = x->prev;
39+ start = x;
40+
41+ if (start->next != NULL) {
42+ /* Check if the key would create duplicity in any index.
43+ * This is not needed if there is only one index - x->insert
44+ * will check it instead. */
45+ for(; x; x = x->next) {
46+ int key_allow_duplicates = 0;
47+ CONTAINER_CHECK_OPTION(x, CONTAINER_KEY_ALLOW_DUPLICATES, key_allow_duplicates);
48+ if (key_allow_duplicates < 0)
49+ key_allow_duplicates = 0; /* cannot read the flag -> use default value */
50+
51+ if (key_allow_duplicates)
52+ continue; /* no need to check this index - duplicates are allowed */
53+
54+ if ((NULL != x->insert_filter) &&
55+ (x->insert_filter(x,k) == 1))
56+ continue; /* no need to check this index - index is filtered out */
57+
58+ rc2 = x->find(x,k);
59+ if (rc2) {
60+ /* key is already in the index -> forbid the insert */
61+ CONTAINER_CHECK_OPTION(start, CONTAINER_SILENT, silent);
62+ if (silent < 0)
63+ silent = 0; /* cannot read the flag -> use default value */
64+
65+ if (!silent) {
66+ snmp_log(LOG_ERR,"error on subcontainer '%s' insert would create duplicity (%d)\n",
67+ x->container_name ? x->container_name : "", rc2);
68+ }
69+ return -1;
70+ }
71+ }
72+ }
73+
74+ x = start;
75 for(; x; x = x->next) {
76 if ((NULL != x->insert_filter) &&
77 (x->insert_filter(x,k) == 1))
78 continue;
79 rc2 = x->insert(x,k);
80 if (rc2) {
81- snmp_log(LOG_ERR,"error on subcontainer '%s' insert (%d)\n",
82- x->container_name ? x->container_name : "", rc2);
83+ /* insert failed */
84+ CONTAINER_CHECK_OPTION(start, CONTAINER_SILENT, silent);
85+ if (silent < 0)
86+ silent = 0; /* cannot read the flag -> use default value */
87+
88+ if (!silent) {
89+ snmp_log(LOG_ERR,"error on subcontainer '%s' insert (%d)\n",
90+ x->container_name ? x->container_name : "", rc2);
91+ }
92 rc = rc2;
93 }
94 }
95 return rc;
96Index: include/net-snmp/library/container.h
97===================================================================
98--- include/net-snmp/library/container.h (revision 16471)
99+++ include/net-snmp/library/container.h (working copy)
100@@ -284,6 +284,8 @@
101 */
102 #define CONTAINER_KEY_ALLOW_DUPLICATES 0x00000001
103 #define CONTAINER_KEY_UNSORTED 0x00000002
104+/* do not print anything to log on CONTAINER_INSERT error */
105+#define CONTAINER_SILENT 0x00000004
106
107 #define CONTAINER_SET_OPTIONS(x,o,rc) do { \
108 if (NULL==(x)->options) \
109@@ -354,23 +356,68 @@
110 int CONTAINER_INSERT(netsnmp_container *x, const void *k)
111 {
112 int rc2, rc = 0;
113+ netsnmp_container *start;
114+ int silent = 0;
115
116 /** start at first container */
117 while(x->prev)
118 x = x->prev;
119+ start = x;
120+
121+ if (start->next != NULL) {
122+ /* Check if the key would create duplicity in any index.
123+ * This is not needed if there is only one index - x->insert
124+ * will check it instead. */
125+ for(; x; x = x->next) {
126+ int key_allow_duplicates = 0;
127+ CONTAINER_CHECK_OPTION(x, CONTAINER_KEY_ALLOW_DUPLICATES, key_allow_duplicates);
128+ if (key_allow_duplicates < 0)
129+ key_allow_duplicates = 0; /* cannot read the flag -> use default value */
130+
131+ if (key_allow_duplicates)
132+ continue; /* no need to check this index - duplicates are allowed */
133+
134+ if ((NULL != x->insert_filter) &&
135+ (x->insert_filter(x,k) == 1))
136+ continue; /* no need to check this index - index is filtered out */
137+
138+ rc2 = x->find(x,k);
139+ if (rc2) {
140+ /* key is already in the index -> forbid the insert */
141+ CONTAINER_CHECK_OPTION(start, CONTAINER_SILENT, silent);
142+ if (silent < 0)
143+ silent = 0; /* cannot read the flag -> use default value */
144+
145+ if (!silent) {
146+ snmp_log(LOG_ERR,"error on subcontainer '%s' insert would create duplicity (%d)\n",
147+ x->container_name ? x->container_name : "", rc2);
148+ }
149+ return -1;
150+ }
151+ }
152+ }
153+
154+ x = start;
155 for(; x; x = x->next) {
156 if ((NULL != x->insert_filter) &&
157 (x->insert_filter(x,k) == 1))
158 continue;
159 rc2 = x->insert(x,k);
160 if (rc2) {
161- snmp_log(LOG_ERR,"error on subcontainer '%s' insert (%d)\n",
162- x->container_name ? x->container_name : "", rc2);
163+ /* insert failed */
164+ CONTAINER_CHECK_OPTION(start, CONTAINER_SILENT, silent);
165+ if (silent < 0)
166+ silent = 0; /* cannot read the flag -> use default value */
167+
168+ if (!silent) {
169+ snmp_log(LOG_ERR,"error on subcontainer '%s' insert (%d)\n",
170+ x->container_name ? x->container_name : "", rc2);
171+ }
172 rc = rc2;
173 }
174 }
175 return rc;
176- }
177+ }
178
179 /*------------------------------------------------------------------
180 * These functions should EXACTLY match the function version in
181Index: agent/mibgroup/ip-mib/data_access/ipaddress_ioctl.c
182===================================================================
183--- agent/mibgroup/ip-mib/data_access/ipaddress_ioctl.c 2008-04-23 11:27:45.000000000 +0300
184+++ agent/mibgroup/ip-mib/data_access/ipaddress_ioctl.c 2008-04-23 11:37:29.000000000 +0300
185@@ -272,11 +272,14 @@
186 /*
187 * add entry to container
188 */
189- if (CONTAINER_INSERT(container, entry) < 0)
190- {
191- DEBUGMSGTL(("access:ipaddress:container","error with ipaddress_entry: insert into container failed.\n"));
192- netsnmp_access_ipaddress_entry_free(entry);
193- continue;
194+
195+ rc = CONTAINER_INSERT(container, entry);
196+ if (rc < 0) {
197+ static int logged = 0;
198+ if (!logged) {
199+ snmp_log(LOG_NOTICE, "Duplicate IPv4 address detected, some interfaces may not be visible in IP-MIB\n");
200+ logged = 1;
201+ }
202 }
203 }
204
205Index: agent/mibgroup/ip-mib/data_access/ipaddress_common.c
206===================================================================
207--- agent/mibgroup/ip-mib/data_access/ipaddress_common.c (revision 16471)
208+++ agent/mibgroup/ip-mib/data_access/ipaddress_common.c (working copy)
209@@ -54,6 +54,7 @@
210 netsnmp_access_ipaddress_container_init(u_int flags)
211 {
212 netsnmp_container *container1;
213+ int rc;
214
215 DEBUGMSGTL(("access:ipaddress:container", "init\n"));
216
217@@ -67,6 +68,12 @@
218 return NULL;
219 }
220 container1->container_name = strdup("ia_index");
221+ CONTAINER_SET_OPTIONS(container1, CONTAINER_SILENT, rc);
222+ if (rc < 0) {
223+ snmp_log(LOG_ERR, "ipaddress container: cannot set CONTAINER_SILENT flag\n");
224+ CONTAINER_FREE(container1);
225+ return NULL;
226+ }
227
228 if (flags & NETSNMP_ACCESS_IPADDRESS_INIT_ADDL_IDX_BY_ADDR) {
229 netsnmp_container *container2 =
230@@ -79,6 +86,14 @@
231
232 container2->compare = _access_ipaddress_entry_compare_addr;
233 container2->container_name = strdup("ia_addr");
234+
235+ CONTAINER_SET_OPTIONS(container2, CONTAINER_SILENT, rc);
236+ if (rc < 0) {
237+ snmp_log(LOG_ERR, "ipaddress secondary container: cannot set CONTAINER_SILENT flag\n");
238+ CONTAINER_FREE(container1);
239+ CONTAINER_FREE(container2);
240+ return NULL;
241+ }
242
243 netsnmp_container_add_index(container1, container2);
244 }
245Index: agent/mibgroup/ip-mib/data_access/ipaddress_linux.c
246===================================================================
247--- agent/mibgroup/ip-mib/data_access/ipaddress_linux.c (revision 16471)
248+++ agent/mibgroup/ip-mib/data_access/ipaddress_linux.c (working copy)
249@@ -340,7 +340,16 @@
250 /*
251 * add entry to container
252 */
253- CONTAINER_INSERT(container, entry);
254+ rc = CONTAINER_INSERT(container, entry);
255+ if (rc < 0) {
256+ static int logged = 0;
257+ if (!logged) {
258+ snmp_log(LOG_NOTICE, "Duplicate IPv6 address detected, some interfaces may not be visible in IP-MIB\n");
259+ logged = 1;
260+ }
261+ netsnmp_access_ipaddress_entry_free(entry);
262+ }
263+
264 }
265
266 fclose(in);
267
This page took 0.085914 seconds and 4 git commands to generate.