Debian Codegraph @

agent/mibgroup/tcp-mib/data_access/tcpConn_common.c

raw
1 /*
2 * TcpConn MIB architecture support
3 *
4 * $Id$
5 */
6 #include <net-snmp/net-snmp-config.h>
7 #include <net-snmp/net-snmp-includes.h>
8
9 #include <net-snmp/agent/net-snmp-agent-includes.h>
10 #include <net-snmp/data_access/tcpConn.h>
11
12 #include "tcp-mib/tcpConnectionTable/tcpConnectionTable_constants.h"
13 #include "tcp-mib/data_access/tcpConn_private.h"
14
15 /**---------------------------------------------------------------------*/
16 /*
17 * local static prototypes
18 */
19 static void _access_tcpconn_entry_release(void *entry, void *unused);
20
21 /**---------------------------------------------------------------------*/
22 /*
23 * container functions
24 */
25 /**
26 */
27 netsnmp_container *
28 netsnmp_access_tcpconn_container_init(u_int flags)
29 {
30 netsnmp_container *container1;
31
32 DEBUGMSGTL(("access:tcpconn:container", "init\n"));
33
34 /*
35 * create the container
36 */
37 container1 = netsnmp_container_find("access:tcpconn:table_container");
38 if (NULL == container1) {
39 snmp_log(LOG_ERR, "tcpconn primary container not found\n");
40 return NULL;
41 }
42 container1->container_name = strdup("tcpConnTable");
43
44 return container1;
45 }
46
47 /**
48 * @retval NULL error
49 * @retval !NULL pointer to container
50 */
51 netsnmp_container*
52 netsnmp_access_tcpconn_container_load(netsnmp_container* container, u_int load_flags)
53 {
54 int rc;
55
56 DEBUGMSGTL(("access:tcpconn:container", "load\n"));
57
58 if (NULL == container)
59 container = netsnmp_access_tcpconn_container_init(load_flags);
60 if (NULL == container) {
61 snmp_log(LOG_ERR, "no container specified/found for access_tcpconn\n");
62 return NULL;
63 }
64
65 rc = netsnmp_arch_tcpconn_container_load(container, load_flags);
66 if (0 != rc) {
67 netsnmp_access_tcpconn_container_free(container,
68 NETSNMP_ACCESS_TCPCONN_FREE_NOFLAGS);
69 container = NULL;
70 }
71
72 return container;
73 }
74
75 void
76 netsnmp_access_tcpconn_container_free(netsnmp_container *container, u_int free_flags)
77 {
78 DEBUGMSGTL(("access:tcpconn:container", "free\n"));
79
80 if (NULL == container) {
81 snmp_log(LOG_ERR, "invalid container for netsnmp_access_tcpconn_free\n");
82 return;
83 }
84
85 if(! (free_flags & NETSNMP_ACCESS_TCPCONN_FREE_DONT_CLEAR)) {
86 /*
87 * free all items.
88 */
89 CONTAINER_CLEAR(container, _access_tcpconn_entry_release, NULL);
90 }
91
92 if(! (free_flags & NETSNMP_ACCESS_TCPCONN_FREE_KEEP_CONTAINER))
93 CONTAINER_FREE(container);
94 }
95
96 /**---------------------------------------------------------------------*/
97 /*
98 * tcpconn_entry functions
99 */
100 /**
101 */
102 /**
103 */
104 netsnmp_tcpconn_entry *
105 netsnmp_access_tcpconn_entry_create(void)
106 {
107 netsnmp_tcpconn_entry *entry =
108 SNMP_MALLOC_TYPEDEF(netsnmp_tcpconn_entry);
109 int rc = 0;
110
111 DEBUGMSGTL(("verbose:access:tcpconn:entry", "create\n"));
112
113 entry->oid_index.len = 1;
114 entry->oid_index.oids = &entry->arbitrary_index;
115
116 /*
117 * init arch data
118 */
119 rc = netsnmp_arch_tcpconn_entry_init(entry);
120 if (SNMP_ERR_NOERROR != rc) {
121 DEBUGMSGT(("access:tcpconn:create","error %d in arch init\n", rc));
122 netsnmp_access_tcpconn_entry_free(entry);
123 }
124
125 return entry;
126 }
127
128 /**
129 */
130 void
131 netsnmp_access_tcpconn_entry_free(netsnmp_tcpconn_entry * entry)
132 {
133 if (NULL == entry)
134 return;
135
136 DEBUGMSGTL(("verbose:access:tcpconn:entry", "free\n"));
137
138 if (NULL != entry->arch_data)
139 netsnmp_arch_tcpconn_entry_cleanup(entry);
140
141 free(entry);
142 }
143
144 #ifdef TCPCONN_DELETE_SUPPORTED
145
146 /* XXX TODO: these are currently unsupported everywhere; to enable the
147 functions first implement netsnmp_arch_tcpconn_entry_delete in the
148 tcpConn_{OS}.c file and then define TCPCONN_DELETE_SUPPORTED in the
149 tcpConn_{OS}.h file (which may need to be created first). */
150
151 /**
152 * update underlying data store (kernel) for entry
153 *
154 * @retval 0 : success
155 * @retval -1 : error
156 */
157 int
158 netsnmp_access_tcpconn_entry_set(netsnmp_tcpconn_entry * entry)
159 {
160 int rc = SNMP_ERR_NOERROR;
161
162 if (NULL == entry) {
163 netsnmp_assert(NULL != entry);
164 return -1;
165 }
166
167 DEBUGMSGTL(("access:tcpconn:entry", "set\n"));
168
169
170 /*
171 * only option is delete
172 */
173 if (! (entry->flags & NETSNMP_ACCESS_TCPCONN_DELETE))
174 return -1;
175
176 rc = netsnmp_arch_tcpconn_entry_delete(entry);
177
178 return rc;
179 }
180 #endif /* TCPCONN_DELETE_SUPPORTED */
181
182 /**
183 * update an old tcpconn_entry from a new one
184 *
185 * @note: only mib related items are compared. Internal objects
186 * such as oid_index, ns_ia_index and flags are not compared.
187 *
188 * @retval -1 : error
189 * @retval >=0 : number of fileds updated
190 */
191 int
192 netsnmp_access_tcpconn_entry_update(netsnmp_tcpconn_entry *lhs,
193 netsnmp_tcpconn_entry *rhs)
194 {
195 int rc, changed = 0;
196
197 DEBUGMSGTL(("access:tcpconn:entry", "update\n"));
198
199 if (lhs->tcpConnState != rhs->tcpConnState) {
200 ++changed;
201 lhs->tcpConnState = rhs->tcpConnState;
202 }
203
204 if (lhs->pid != rhs->pid) {
205 ++changed;
206 lhs->pid = rhs->pid;
207 }
208
209 /*
210 * copy arch stuff. we don't care if it changed
211 */
212 rc = netsnmp_arch_tcpconn_entry_copy(lhs,rhs);
213 if (0 != rc) {
214 snmp_log(LOG_ERR,"arch tcpconn copy failed\n");
215 return -1;
216 }
217
218 return changed;
219 }
220
221 /**---------------------------------------------------------------------*/
222 /*
223 * Utility routines
224 */
225
226 /**
227 */
228 void
229 _access_tcpconn_entry_release(void *entry, void *context)
230 {
231 netsnmp_access_tcpconn_entry_free(entry);
232 }
233
234
235 #ifdef NETSNMP_TCPCONN_TEST
236
237 int
238 main(int argc, char** argv)
239 {
240 netsnmp_container *container;
241
242 netsnmp_config("debugTokens access:tcp,verbose:access:tcp,tcp,verbose:tcp");
243
244 netsnmp_container_init_list();
245
246 dodebug = 1;
247
248 container = netsnmp_access_tcpconn_container_load(NULL, 0);
249
250 netsnmp_access_tcpconn_container_free(container, 0);
251 }
252 #endif