Author: adamg Date: Fri May 2 17:20:16 2008 GMT Module: SOURCES Tag: AC-branch ---- Log message: - official fix (from http://net-snmp.svn.sourceforge.net/viewvc/net-snmp?view=rev&revision=16804)
---- Files affected: SOURCES: net-snmp-duplicate-ip.patch (1.1 -> 1.1.2.1) ---- Diffs: ================================================================ Index: SOURCES/net-snmp-duplicate-ip.patch diff -u SOURCES/net-snmp-duplicate-ip.patch:1.1 SOURCES/net-snmp-duplicate-ip.patch:1.1.2.1 --- SOURCES/net-snmp-duplicate-ip.patch:1.1 Wed Apr 23 23:21:14 2008 +++ SOURCES/net-snmp-duplicate-ip.patch Fri May 2 19:20:11 2008 @@ -1,267 +1,115 @@ -Index: snmplib/container_binary_array.c -=================================================================== ---- snmplib/container_binary_array.c (revision 16471) -+++ snmplib/container_binary_array.c (working copy) -@@ -579,6 +579,11 @@ - return va; - } - -+static int _ba_options(netsnmp_container *c, int set, u_int flags) +borrowed from: + + http://net-snmp.svn.sourceforge.net/viewvc/net-snmp?view=rev&revision=16804 + +--- branches/V5-4-patches/net-snmp/snmplib/container.c 2008/02/13 23:11:48 16803 ++++ branches/V5-4-patches/net-snmp/snmplib/container.c 2008/02/13 23:37:48 16804 +@@ -268,25 +268,35 @@ + * These functions should EXACTLY match the inline version in + * container.h. If you change one, change them both. + */ +-int CONTAINER_INSERT(netsnmp_container *x, const void *k) +-{ +- int rc2, rc = 0; +- +- /** start at first container */ +- while(x->prev) +- x = x->prev; +- for(; x; x = x->next) { +- if ((NULL != x->insert_filter) && +- (x->insert_filter(x,k) == 1)) +- continue; +- rc2 = x->insert(x,k); +- if (rc2) { ++int CONTAINER_INSERT_HELPER(netsnmp_container* x, const void* k) +{ -+ return netsnmp_binary_array_options_set(c, set, flags); -+} -+ - netsnmp_container * - netsnmp_container_get_binary_array(void) - { -@@ -604,6 +609,7 @@ - c->get_iterator = _ba_iterator_get; - c->for_each = _ba_for_each; - c->clear = _ba_clear; -+ c->options = _ba_options; - - return c; - } -Index: snmplib/container.c -=================================================================== ---- snmplib/container.c (revision 16471) -+++ snmplib/container.c (working copy) -@@ -268,19 +268,64 @@ - int CONTAINER_INSERT(netsnmp_container *x, const void *k) - { - int rc2, rc = 0; -+ netsnmp_container *start; -+ int silent = 0; - - /** start at first container */ - while(x->prev) - x = x->prev; -+ start = x; -+ -+ if (start->next != NULL) { -+ /* Check if the key would create duplicity in any index. -+ * This is not needed if there is only one index - x->insert -+ * will check it instead. */ -+ for(; x; x = x->next) { -+ int key_allow_duplicates = 0; -+ CONTAINER_CHECK_OPTION(x, CONTAINER_KEY_ALLOW_DUPLICATES, key_allow_duplicates); -+ if (key_allow_duplicates < 0) -+ key_allow_duplicates = 0; /* cannot read the flag -> use default value */ -+ -+ if (key_allow_duplicates) -+ continue; /* no need to check this index - duplicates are allowed */ -+ -+ if ((NULL != x->insert_filter) && -+ (x->insert_filter(x,k) == 1)) -+ continue; /* no need to check this index - index is filtered out */ -+ -+ rc2 = x->find(x,k); -+ if (rc2) { -+ /* key is already in the index -> forbid the insert */ -+ CONTAINER_CHECK_OPTION(start, CONTAINER_SILENT, silent); -+ if (silent < 0) -+ silent = 0; /* cannot read the flag -> use default value */ -+ -+ if (!silent) { -+ snmp_log(LOG_ERR,"error on subcontainer '%s' insert would create duplicity (%d)\n", -+ x->container_name ? x->container_name : "", rc2); -+ } -+ return -1; -+ } -+ } -+ } -+ -+ x = start; - for(; x; x = x->next) { - if ((NULL != x->insert_filter) && - (x->insert_filter(x,k) == 1)) - continue; - rc2 = x->insert(x,k); - if (rc2) { -- snmp_log(LOG_ERR,"error on subcontainer '%s' insert (%d)\n", ++ while(x && x->insert_filter && x->insert_filter(x,k) == 1) ++ x = x->next; ++ if(x) { ++ int rc = x->insert(x,k); ++ if(rc) + snmp_log(LOG_ERR,"error on subcontainer '%s' insert (%d)\n", - x->container_name ? x->container_name : "", rc2); -+ /* insert failed */ -+ CONTAINER_CHECK_OPTION(start, CONTAINER_SILENT, silent); -+ if (silent < 0) -+ silent = 0; /* cannot read the flag -> use default value */ -+ -+ if (!silent) { -+ snmp_log(LOG_ERR,"error on subcontainer '%s' insert (%d)\n", -+ x->container_name ? x->container_name : "", rc2); -+ } - rc = rc2; +- rc = rc2; ++ x->container_name ? x->container_name : "", rc); ++ else { ++ rc = CONTAINER_INSERT_HELPER(x->next, k); ++ if(rc) ++ x->remove(x,k); } ++ return rc; } - return rc; -Index: include/net-snmp/library/container.h -=================================================================== ---- include/net-snmp/library/container.h (revision 16471) -+++ include/net-snmp/library/container.h (working copy) -@@ -284,6 +284,8 @@ - */ - #define CONTAINER_KEY_ALLOW_DUPLICATES 0x00000001 - #define CONTAINER_KEY_UNSORTED 0x00000002 -+/* do not print anything to log on CONTAINER_INSERT error */ -+#define CONTAINER_SILENT 0x00000004 +- return rc; ++ return 0; ++} ++ ++/*------------------------------------------------------------------ ++ * These functions should EXACTLY match the inline version in ++ * container.h. If you change one, change them both. ++ */ ++int CONTAINER_INSERT(netsnmp_container* x, const void* k) ++{ ++ /** start at first container */ ++ while(x->prev) ++ x = x->prev; ++ return CONTAINER_INSERT_HELPER(x, k); + } - #define CONTAINER_SET_OPTIONS(x,o,rc) do { \ - if (NULL==(x)->options) \ -@@ -354,23 +356,68 @@ - int CONTAINER_INSERT(netsnmp_container *x, const void *k) + /*------------------------------------------------------------------ +--- branches/V5-4-patches/net-snmp/include/net-snmp/library/container.h 2008/02/13 23:11:48 16803 ++++ branches/V5-4-patches/net-snmp/include/net-snmp/library/container.h 2008/02/13 23:37:48 16804 +@@ -351,27 +351,38 @@ + * container.c. If you change one, change them both. + */ + NETSNMP_STATIC_INLINE /* gcc docs recommend static w/inline */ +- int CONTAINER_INSERT(netsnmp_container *x, const void *k) ++ int CONTAINER_INSERT_HELPER(netsnmp_container* x, const void* k) { - int rc2, rc = 0; -+ netsnmp_container *start; -+ int silent = 0; - - /** start at first container */ - while(x->prev) - x = x->prev; -+ start = x; -+ -+ if (start->next != NULL) { -+ /* Check if the key would create duplicity in any index. -+ * This is not needed if there is only one index - x->insert -+ * will check it instead. */ -+ for(; x; x = x->next) { -+ int key_allow_duplicates = 0; -+ CONTAINER_CHECK_OPTION(x, CONTAINER_KEY_ALLOW_DUPLICATES, key_allow_duplicates); -+ if (key_allow_duplicates < 0) -+ key_allow_duplicates = 0; /* cannot read the flag -> use default value */ -+ -+ if (key_allow_duplicates) -+ continue; /* no need to check this index - duplicates are allowed */ -+ -+ if ((NULL != x->insert_filter) && -+ (x->insert_filter(x,k) == 1)) -+ continue; /* no need to check this index - index is filtered out */ -+ -+ rc2 = x->find(x,k); -+ if (rc2) { -+ /* key is already in the index -> forbid the insert */ -+ CONTAINER_CHECK_OPTION(start, CONTAINER_SILENT, silent); -+ if (silent < 0) -+ silent = 0; /* cannot read the flag -> use default value */ -+ -+ if (!silent) { -+ snmp_log(LOG_ERR,"error on subcontainer '%s' insert would create duplicity (%d)\n", -+ x->container_name ? x->container_name : "", rc2); -+ } -+ return -1; -+ } -+ } -+ } -+ -+ x = start; - for(; x; x = x->next) { - if ((NULL != x->insert_filter) && - (x->insert_filter(x,k) == 1)) - continue; - rc2 = x->insert(x,k); - if (rc2) { -- snmp_log(LOG_ERR,"error on subcontainer '%s' insert (%d)\n", +- int rc2, rc = 0; +- +- /** start at first container */ +- while(x->prev) +- x = x->prev; +- for(; x; x = x->next) { +- if ((NULL != x->insert_filter) && +- (x->insert_filter(x,k) == 1)) +- continue; +- rc2 = x->insert(x,k); +- if (rc2) { ++ while(x && x->insert_filter && x->insert_filter(x,k) == 1) ++ x = x->next; ++ if(x) { ++ int rc = x->insert(x,k); ++ if(rc) + snmp_log(LOG_ERR,"error on subcontainer '%s' insert (%d)\n", - x->container_name ? x->container_name : "", rc2); -+ /* insert failed */ -+ CONTAINER_CHECK_OPTION(start, CONTAINER_SILENT, silent); -+ if (silent < 0) -+ silent = 0; /* cannot read the flag -> use default value */ -+ -+ if (!silent) { -+ snmp_log(LOG_ERR,"error on subcontainer '%s' insert (%d)\n", -+ x->container_name ? x->container_name : "", rc2); -+ } - rc = rc2; +- rc = rc2; ++ x->container_name ? x->container_name : "", rc); ++ else { ++ rc = CONTAINER_INSERT_HELPER(x->next, k); ++ if(rc) ++ x->remove(x,k); } ++ return rc; } - return rc; -- } -+ } - - /*------------------------------------------------------------------ - * These functions should EXACTLY match the function version in -Index: agent/mibgroup/ip-mib/data_access/ipaddress_ioctl.c -=================================================================== ---- agent/mibgroup/ip-mib/data_access/ipaddress_ioctl.c 2008-04-23 11:27:45.000000000 +0300 -+++ agent/mibgroup/ip-mib/data_access/ipaddress_ioctl.c 2008-04-23 11:37:29.000000000 +0300 -@@ -272,11 +272,14 @@ - /* - * add entry to container - */ -- if (CONTAINER_INSERT(container, entry) < 0) -- { -- DEBUGMSGTL(("access:ipaddress:container","error with ipaddress_entry: insert into container failed.\n")); -- netsnmp_access_ipaddress_entry_free(entry); -- continue; -+ -+ rc = CONTAINER_INSERT(container, entry); -+ if (rc < 0) { -+ static int logged = 0; -+ if (!logged) { -+ snmp_log(LOG_NOTICE, "Duplicate IPv4 address detected, some interfaces may not be visible in IP-MIB\n"); -+ logged = 1; -+ } - } - } - -Index: agent/mibgroup/ip-mib/data_access/ipaddress_common.c -=================================================================== ---- agent/mibgroup/ip-mib/data_access/ipaddress_common.c (revision 16471) -+++ agent/mibgroup/ip-mib/data_access/ipaddress_common.c (working copy) -@@ -54,6 +54,7 @@ - netsnmp_access_ipaddress_container_init(u_int flags) - { - netsnmp_container *container1; -+ int rc; - - DEBUGMSGTL(("access:ipaddress:container", "init\n")); - -@@ -67,6 +68,12 @@ - return NULL; +- return rc; ++ return 0; } - container1->container_name = strdup("ia_index"); -+ CONTAINER_SET_OPTIONS(container1, CONTAINER_SILENT, rc); -+ if (rc < 0) { -+ snmp_log(LOG_ERR, "ipaddress container: cannot set CONTAINER_SILENT flag\n"); -+ CONTAINER_FREE(container1); -+ return NULL; +- ++ ++ /*------------------------------------------------------------------ ++ * These functions should EXACTLY match the function version in ++ * container.c. If you change one, change them both. ++ */ ++ NETSNMP_STATIC_INLINE /* gcc docs recommend static w/inline */ ++ int CONTAINER_INSERT(netsnmp_container* x, const void* k) ++ { ++ /** start at first container */ ++ while(x->prev) ++ x = x->prev; ++ return CONTAINER_INSERT_HELPER(x, k); + } - - if (flags & NETSNMP_ACCESS_IPADDRESS_INIT_ADDL_IDX_BY_ADDR) { - netsnmp_container *container2 = -@@ -79,6 +86,14 @@ - - container2->compare = _access_ipaddress_entry_compare_addr; - container2->container_name = strdup("ia_addr"); + -+ CONTAINER_SET_OPTIONS(container2, CONTAINER_SILENT, rc); -+ if (rc < 0) { -+ snmp_log(LOG_ERR, "ipaddress secondary container: cannot set CONTAINER_SILENT flag\n"); -+ CONTAINER_FREE(container1); -+ CONTAINER_FREE(container2); -+ return NULL; -+ } - - netsnmp_container_add_index(container1, container2); - } -Index: agent/mibgroup/ip-mib/data_access/ipaddress_linux.c -=================================================================== ---- agent/mibgroup/ip-mib/data_access/ipaddress_linux.c (revision 16471) -+++ agent/mibgroup/ip-mib/data_access/ipaddress_linux.c (working copy) -@@ -340,7 +340,16 @@ - /* - * add entry to container - */ -- CONTAINER_INSERT(container, entry); -+ rc = CONTAINER_INSERT(container, entry); -+ if (rc < 0) { -+ static int logged = 0; -+ if (!logged) { -+ snmp_log(LOG_NOTICE, "Duplicate IPv6 address detected, some interfaces may not be visible in IP-MIB\n"); -+ logged = 1; -+ } -+ netsnmp_access_ipaddress_entry_free(entry); -+ } -+ - } - - fclose(in); - + /*------------------------------------------------------------------ + * These functions should EXACTLY match the function version in + * container.c. If you change one, change them both. ================================================================ ---- CVS-web: http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/net-snmp-duplicate-ip.patch?r1=1.1&r2=1.1.2.1&f=u _______________________________________________ pld-cvs-commit mailing list [email protected] http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit
