REQ libXfont
[unleashed-userland.git] / components / net-snmp / patches / 035.15997718-17208688.interface.patch
blobc9aa6711e6d11961e8c8ffdcb1828ac16c3d3024
1 The following are the community bug/patch details.
2 snmpd: BUG: 1400101: remove deleted interfaces from ifTable
3 http://sourceforge.net/p/net-snmp/patches/640/
5 ===================================================================
6 --- a/agent/mibgroup/if-mib/ifTable/ifTable_data_access.c (revision 17653)
7 +++ b/agent/mibgroup/if-mib/ifTable/ifTable_data_access.c (working copy)
8 @@ -23,6 +23,11 @@
9 # include "mibgroup/ip-mib/ipv4InterfaceTable/ipv4InterfaceTable.h"
10 #endif
12 +typedef struct cd_container_s {
13 + netsnmp_container *current;
14 + netsnmp_container *deleted;
15 +} cd_container;
18 * flag so we know not to set row/table last change times
19 * during startup.
20 @@ -158,10 +163,11 @@
22 static void
23 _check_interface_entry_for_updates(ifTable_rowreq_ctx * rowreq_ctx,
24 - netsnmp_container *ifcontainer)
25 + cd_container *cdc)
27 char oper_changed = 0;
28 u_long lastchange = rowreq_ctx->data.ifLastChange;
29 + netsnmp_container *ifcontainer = cdc->current;
32 * check for matching entry. We can do this directly, since
33 @@ -291,16 +297,31 @@
34 * deleted (and thus need to update ifTableLastChanged)?
36 if (!rowreq_ctx->known_missing) {
37 - DEBUGMSGTL(("ifTable:access", "updating missing entry\n"));
38 rowreq_ctx->known_missing = 1;
39 + DEBUGMSGTL(("ifTable:access", "updating missing entry %s\n",rowreq_ctx->data.ifName));
40 rowreq_ctx->data.ifAdminStatus = IFADMINSTATUS_DOWN;
41 - if ((!(rowreq_ctx->data.ifentry->ns_flags & NETSNMP_INTERFACE_FLAGS_HAS_LASTCHANGE))
42 - && (rowreq_ctx->data.ifOperStatus != IFOPERSTATUS_DOWN))
43 - oper_changed = 1;
44 rowreq_ctx->data.ifOperStatus = IFOPERSTATUS_DOWN;
45 + oper_changed = 1;
46 + } else {
47 + time_t now = netsnmp_get_agent_uptime();
48 + u_long diff = (now - rowreq_ctx->data.ifLastChange) / 100;
49 + DEBUGMSGTL(("verbose:ifTable:access", "missing entry for %ld seconds\n", diff));
50 + if (diff > IFTABLE_REMOVE_MISSING_AFTER) {
51 + DEBUGMSGTL(("ifTable:access", "marking missing entry %s for "
52 + "removal after %d seconds\n", rowreq_ctx->data.ifName,
53 + IFTABLE_REMOVE_MISSING_AFTER));
54 + if (NULL == cdc->deleted)
55 + cdc->deleted = netsnmp_container_find("ifTable_deleted:linked_list");
56 + if (NULL == cdc->deleted)
57 + snmp_log(LOG_ERR, "couldn't create container for deleted interface\n");
58 + else {
59 + CONTAINER_INSERT(cdc->deleted, rowreq_ctx);
60 + }
61 + }
63 } else {
64 - DEBUGMSGTL(("ifTable:access", "updating existing entry\n"));
65 + DEBUGMSGTL(("ifTable:access", "updating existing entry %s\n",
66 + rowreq_ctx->data.ifName));
68 #ifdef USING_IF_MIB_IFXTABLE_IFXTABLE_MODULE
70 @@ -428,6 +449,21 @@
73 /**
74 + * add new entry
75 + */
76 +static void
77 +_delete_missing_interface(ifTable_rowreq_ctx *rowreq_ctx,
78 + netsnmp_container *container)
80 + DEBUGMSGTL(("ifTable:access", "removing missing entry %s\n",
81 + rowreq_ctx->data.ifName));
83 + CONTAINER_REMOVE(container, rowreq_ctx);
85 + ifTable_release_rowreq_ctx(rowreq_ctx);
88 +/**
89 * container shutdown
91 * @param container_ptr A pointer to the container.
92 @@ -491,7 +527,7 @@
93 int
94 ifTable_container_load(netsnmp_container *container)
96 - netsnmp_container *ifcontainer;
97 + cd_container cdc;
99 DEBUGMSGTL(("verbose:ifTable:ifTable_container_load", "called\n"));
101 @@ -504,31 +540,41 @@
103 * ifTable gets its data from the netsnmp_interface API.
105 - ifcontainer =
106 + cdc.current =
107 netsnmp_access_interface_container_load(NULL,
108 NETSNMP_ACCESS_INTERFACE_INIT_NOFLAGS);
109 - if (NULL == ifcontainer)
110 + if (NULL == cdc.current)
111 return MFD_RESOURCE_UNAVAILABLE; /* msg already logged */
113 + cdc.deleted = NULL; /* created as needed */
116 * we just got a fresh copy of interface data. compare it to
117 * what we've already got, and make any adjustements...
119 CONTAINER_FOR_EACH(container, (netsnmp_container_obj_func *)
120 - _check_interface_entry_for_updates, ifcontainer);
121 + _check_interface_entry_for_updates, &cdc);
124 * now add any new interfaces
126 - CONTAINER_FOR_EACH(ifcontainer,
127 + CONTAINER_FOR_EACH(cdc.current,
128 (netsnmp_container_obj_func *) _add_new_interface,
129 container);
132 + * now remove any missing interfaces
133 + */
134 + if (NULL != cdc.deleted)
135 + CONTAINER_FOR_EACH(cdc.deleted,
136 + (netsnmp_container_obj_func *) _delete_missing_interface,
137 + container);
139 + /*
140 * free the container. we've either claimed each ifentry, or released it,
141 * so the dal function doesn't need to clear the container.
143 - netsnmp_access_interface_container_free(ifcontainer,
144 + netsnmp_access_interface_container_free(cdc.current,
145 NETSNMP_ACCESS_INTERFACE_FREE_DONT_CLEAR);
147 DEBUGMSGT(("verbose:ifTable:ifTable_cache_load",
148 Index: agent/mibgroup/if-mib/ifTable/ifTable_data_access.h
149 ===================================================================
150 --- a/agent/mibgroup/if-mib/ifTable/ifTable_data_access.h (revision 17653)
151 +++ b/agent/mibgroup/if-mib/ifTable/ifTable_data_access.h (working copy)
152 @@ -48,6 +48,8 @@
154 #define IFTABLE_CACHE_TIMEOUT 15
156 +#define IFTABLE_REMOVE_MISSING_AFTER (5 * 60) /* seconds */
158 void ifTable_container_init(netsnmp_container
159 **container_ptr_ptr,
160 netsnmp_cache * cache);