1 /*
2  *  UDP-MIB endpoint architecture support
3  *
4  * $Id$
5  */
6 #include <net-snmp/net-snmp-config.h>
7 #include <net-snmp/net-snmp-features.h>
8 #include <net-snmp/net-snmp-includes.h>
9 #include "udp-mib/udpEndpointTable/udpEndpointTable_constants.h"
10 
11 #include <net-snmp/agent/net-snmp-agent-includes.h>
12 #include <net-snmp/data_access/ipaddress.h>
13 #include <net-snmp/data_access/udp_endpoint.h>
14 
15 #include "udp_endpoint_private.h"
16 
17 netsnmp_feature_child_of(udp_endpoint_common, libnetsnmpmibs);
18 
19 netsnmp_feature_child_of(udp_endpoint_entry_create, udp_endpoint_common);
20 
21 /**---------------------------------------------------------------------*/
22 /*
23  * local static vars
24  */
25 
26 
27 /**---------------------------------------------------------------------*/
28 /*
29  * initialization
30  */
31 
32 /**---------------------------------------------------------------------*/
33 /*
34  * container functions
35  */
36 /**
37  * initialize udp_endpoint container
38  */
39 netsnmp_container *
netsnmp_access_udp_endpoint_container_init(u_int flags)40 netsnmp_access_udp_endpoint_container_init(u_int flags)
41 {
42     netsnmp_container *container;
43 
44     DEBUGMSGTL(("access:udp_endpoint:container", "init\n"));
45 
46     /*
47      * create the containers.
48      */
49     container = netsnmp_container_find("access_udp_endpoint:table_container");
50     if (NULL == container)
51         return NULL;
52 
53     return container;
54 }
55 
56 /**
57  * load udp_endpoint information in specified container
58  *
59  * @param container empty container, or NULL to have one created for you
60  * @param load_flags flags to modify behaviour.
61  *
62  * @retval NULL  error
63  * @retval !NULL pointer to container
64  */
65 netsnmp_container*
netsnmp_access_udp_endpoint_container_load(netsnmp_container * container,u_int load_flags)66 netsnmp_access_udp_endpoint_container_load(netsnmp_container* container,
67                                            u_int load_flags)
68 {
69     int rc;
70 
71     DEBUGMSGTL(("access:udp_endpoint:container", "load\n"));
72 
73     if (NULL == container)
74         container = netsnmp_access_udp_endpoint_container_init(0);
75     if (NULL == container) {
76         snmp_log(LOG_ERR,
77                  "no container specified/found for access_udp_endpoint\n");
78         return NULL;
79     }
80 
81     rc =
82         netsnmp_arch_udp_endpoint_container_load(container, load_flags);
83     if (0 != rc) {
84         netsnmp_access_udp_endpoint_container_free(container, 0);
85         container = NULL;
86     }
87 
88     return container;
89 }
90 
_netsnmp_access_udp_endpoint_entry_free(void * data,void * context)91 static void _netsnmp_access_udp_endpoint_entry_free(void *data, void *context)
92 {
93     netsnmp_access_udp_endpoint_entry_free(data);
94 }
95 
96 void
netsnmp_access_udp_endpoint_container_free(netsnmp_container * container,u_int free_flags)97 netsnmp_access_udp_endpoint_container_free(netsnmp_container *container,
98                                            u_int free_flags)
99 {
100     DEBUGMSGTL(("access:udp_endpoint:container", "free\n"));
101 
102     if (NULL == container) {
103         snmp_log(LOG_ERR,
104                  "invalid container for netsnmp_access_udp_endpoint_free\n");
105         return;
106     }
107 
108     if(! (free_flags & NETSNMP_ACCESS_UDP_ENDPOINT_FREE_DONT_CLEAR)) {
109         /*
110          * free all items.
111          */
112         CONTAINER_CLEAR(container, _netsnmp_access_udp_endpoint_entry_free,
113                         NULL);
114     }
115 
116     if(! (free_flags & NETSNMP_ACCESS_UDP_ENDPOINT_FREE_KEEP_CONTAINER))
117         CONTAINER_FREE(container);
118 }
119 
120 /**---------------------------------------------------------------------*/
121 /*
122  * entry functions
123  */
124 /**
125  */
126 #ifndef NETSNMP_FEATURE_REMOVE_UDP_ENDPOINT_ENTRY_CREATE
127 netsnmp_udp_endpoint_entry *
netsnmp_access_udp_endpoint_entry_create(void)128 netsnmp_access_udp_endpoint_entry_create(void)
129 {
130     netsnmp_udp_endpoint_entry *entry =
131         SNMP_MALLOC_TYPEDEF(netsnmp_udp_endpoint_entry);
132 
133     DEBUGMSGTL(("access:udp_endpoint:entry", "create\n"));
134 
135     if(NULL == entry)
136         return NULL;
137 
138     entry->oid_index.len = 1;
139     entry->oid_index.oids = (oid *) & entry->index;
140 
141     return entry;
142 }
143 #endif /* NETSNMP_FEATURE_REMOVE_UDP_ENDPOINT_ENTRY_CREATE */
144 
145 /**
146  */
147 void
netsnmp_access_udp_endpoint_entry_free(netsnmp_udp_endpoint_entry * entry)148 netsnmp_access_udp_endpoint_entry_free(netsnmp_udp_endpoint_entry * entry)
149 {
150     DEBUGMSGTL(("access:udp_endpoint:entry", "free\n"));
151 
152     if (NULL == entry)
153         return;
154 
155     /*
156      * SNMP_FREE not needed, for any of these,
157      * since the whole entry is about to be freed
158      */
159 
160     free(entry);
161 }
162