| 1 |
/* |
| 2 |
*Copyright(c)2004,Cisco URP imburses and Network Information Center in Beijing University of Posts and Telecommunications researches. |
| 3 |
* |
| 4 |
*All right reserved |
| 5 |
* |
| 6 |
*File Name:lookupResultsTable.c |
| 7 |
*File Description:Rows of the lookupResultsTable MIB read. |
| 8 |
* |
| 9 |
*Current Version:1.0 |
| 10 |
*Author:ChenJing |
| 11 |
*Date:2004.8.20 |
| 12 |
*/ |
| 13 |
|
| 14 |
/* |
| 15 |
* This should always be included first before anything else |
| 16 |
*/ |
| 17 |
|
| 18 |
#include <net-snmp/net-snmp-config.h> |
| 19 |
#include <net-snmp/net-snmp-includes.h> |
| 20 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 21 |
|
| 22 |
#include "lookupCtlTable.h" |
| 23 |
#include "lookupResultsTable.h" |
| 24 |
#include "header_complex.h" |
| 25 |
|
| 26 |
|
| 27 |
oid lookupResultsTable_variables_oid[] = |
| 28 |
{ 1, 3, 6, 1, 2, 1, 82, 1, 4 }; |
| 29 |
|
| 30 |
struct variable2 lookupResultsTable_variables[] = { |
| 31 |
{COLUMN_LOOKUPRESULTSADDRESSTYPE, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, |
| 32 |
var_lookupResultsTable, 2, {1, 2}}, |
| 33 |
{COLUMN_LOOKUPRESULTSADDRESS, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, |
| 34 |
var_lookupResultsTable, 2, {1, 3}} |
| 35 |
}; |
| 36 |
|
| 37 |
|
| 38 |
int |
| 39 |
lookupResultsTable_inadd(struct lookupResultsTable_data *thedata); |
| 40 |
|
| 41 |
void |
| 42 |
lookupResultsTable_cleaner(struct header_complex_index *thestuff) |
| 43 |
{ |
| 44 |
struct header_complex_index *hciptr, *nhciptr; |
| 45 |
struct lookupResultsTable_data *StorageDel; |
| 46 |
|
| 47 |
DEBUGMSGTL(("lookupResultsTable", "cleanerout ")); |
| 48 |
for (hciptr = thestuff; hciptr; hciptr = nhciptr) { |
| 49 |
nhciptr = hciptr->next; |
| 50 |
StorageDel = header_complex_extract_entry(&lookupResultsTableStorage, |
| 51 |
hciptr); |
| 52 |
if (StorageDel != NULL) { |
| 53 |
SNMP_FREE(StorageDel->lookupCtlOwnerIndex); |
| 54 |
SNMP_FREE(StorageDel->lookupCtlOperationName); |
| 55 |
SNMP_FREE(StorageDel->lookupResultsAddress); |
| 56 |
SNMP_FREE(StorageDel); |
| 57 |
} |
| 58 |
DEBUGMSGTL(("lookupResultsTable", "cleaner ")); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
void |
| 63 |
init_lookupResultsTable(void) |
| 64 |
{ |
| 65 |
|
| 66 |
DEBUGMSGTL(("lookupResultsTable", "initializing... ")); |
| 67 |
|
| 68 |
|
| 69 |
/* |
| 70 |
* register ourselves with the agent to handle our mib tree |
| 71 |
*/ |
| 72 |
REGISTER_MIB("lookupResultsTable", lookupResultsTable_variables, |
| 73 |
variable2, lookupResultsTable_variables_oid); |
| 74 |
|
| 75 |
|
| 76 |
/* |
| 77 |
* register our config handler(s) to deal with registrations |
| 78 |
*/ |
| 79 |
snmpd_register_config_handler("lookupResultsTable", |
| 80 |
parse_lookupResultsTable, NULL, NULL); |
| 81 |
|
| 82 |
/* |
| 83 |
* we need to be called back later to store our data |
| 84 |
*/ |
| 85 |
snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA, |
| 86 |
store_lookupResultsTable, NULL); |
| 87 |
|
| 88 |
DEBUGMSGTL(("lookupResultsTable", "done.\n")); |
| 89 |
} |
| 90 |
|
| 91 |
/* |
| 92 |
* parse_mteObjectsTable(): |
| 93 |
* parses .conf file entries needed to configure the mib. |
| 94 |
*/ |
| 95 |
|
| 96 |
void |
| 97 |
parse_lookupResultsTable(const char *token, char *line) |
| 98 |
{ |
| 99 |
size_t tmpint; |
| 100 |
struct lookupResultsTable_data *StorageTmp = |
| 101 |
SNMP_MALLOC_STRUCT(lookupResultsTable_data); |
| 102 |
|
| 103 |
DEBUGMSGTL(("lookupResultsTable", "parsing config... ")); |
| 104 |
|
| 105 |
|
| 106 |
if (StorageTmp == NULL) { |
| 107 |
config_perror("malloc failure"); |
| 108 |
return; |
| 109 |
} |
| 110 |
|
| 111 |
line = |
| 112 |
read_config_read_data(ASN_OCTET_STR, line, |
| 113 |
&StorageTmp->lookupCtlOwnerIndex, |
| 114 |
&StorageTmp->lookupCtlOwnerIndexLen); |
| 115 |
if (StorageTmp->lookupCtlOwnerIndex == NULL) { |
| 116 |
config_perror("invalid specification for lookupCtlOwnerIndex"); |
| 117 |
free(StorageTmp); |
| 118 |
return; |
| 119 |
} |
| 120 |
|
| 121 |
line = |
| 122 |
read_config_read_data(ASN_OCTET_STR, line, |
| 123 |
&StorageTmp->lookupCtlOperationName, |
| 124 |
&StorageTmp->lookupCtlOperationNameLen); |
| 125 |
if (StorageTmp->lookupCtlOperationName == NULL) { |
| 126 |
config_perror("invalid specification for lookupCtlOperationName"); |
| 127 |
free(StorageTmp); |
| 128 |
return; |
| 129 |
} |
| 130 |
|
| 131 |
line = |
| 132 |
read_config_read_data(ASN_UNSIGNED, line, |
| 133 |
&StorageTmp->lookupResultsIndex, &tmpint); |
| 134 |
line = |
| 135 |
read_config_read_data(ASN_INTEGER, line, |
| 136 |
&StorageTmp->lookupResultsAddressType, |
| 137 |
&tmpint); |
| 138 |
line = |
| 139 |
read_config_read_data(ASN_OCTET_STR, line, |
| 140 |
&StorageTmp->lookupResultsAddress, |
| 141 |
&StorageTmp->lookupResultsAddressLen); |
| 142 |
if (StorageTmp->lookupResultsAddress == NULL) { |
| 143 |
config_perror("invalid specification for lookupResultsAddress"); |
| 144 |
free(StorageTmp); |
| 145 |
return; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
lookupResultsTable_inadd(StorageTmp); |
| 150 |
|
| 151 |
/* lookupResultsTable_cleaner(lookupResultsTableStorage); */ |
| 152 |
|
| 153 |
DEBUGMSGTL(("lookupResultsTable", "done.\n")); |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
/* |
| 161 |
* store_lookupResultsTable(): |
| 162 |
* stores .conf file entries needed to configure the mib. |
| 163 |
*/ |
| 164 |
|
| 165 |
int |
| 166 |
store_lookupResultsTable(int majorID, int minorID, void *serverarg, |
| 167 |
void *clientarg) |
| 168 |
{ |
| 169 |
char line[SNMP_MAXBUF]; |
| 170 |
char *cptr = NULL; |
| 171 |
size_t tmpint; |
| 172 |
struct lookupResultsTable_data *StorageTmp = NULL; |
| 173 |
struct header_complex_index *hcindex = NULL; |
| 174 |
|
| 175 |
|
| 176 |
DEBUGMSGTL(("lookupResultsTable", "storing data... ")); |
| 177 |
|
| 178 |
|
| 179 |
for (hcindex = lookupResultsTableStorage; hcindex != NULL; |
| 180 |
hcindex = hcindex->next) { |
| 181 |
StorageTmp = (struct lookupResultsTable_data *) hcindex->data; |
| 182 |
|
| 183 |
if (StorageTmp->storagetype != ST_READONLY) { |
| 184 |
memset(line, 0, sizeof(line)); |
| 185 |
strcat(line, "lookupResultsTable "); |
| 186 |
cptr = line + strlen(line); |
| 187 |
|
| 188 |
cptr = |
| 189 |
read_config_store_data(ASN_OCTET_STR, cptr, |
| 190 |
&StorageTmp->lookupCtlOwnerIndex, |
| 191 |
&StorageTmp-> |
| 192 |
lookupCtlOwnerIndexLen); |
| 193 |
|
| 194 |
cptr = |
| 195 |
read_config_store_data(ASN_OCTET_STR, cptr, |
| 196 |
&StorageTmp->lookupCtlOperationName, |
| 197 |
&StorageTmp-> |
| 198 |
lookupCtlOperationNameLen); |
| 199 |
cptr = |
| 200 |
read_config_store_data(ASN_UNSIGNED, cptr, |
| 201 |
&StorageTmp->lookupResultsIndex, |
| 202 |
&tmpint); |
| 203 |
cptr = |
| 204 |
read_config_store_data(ASN_INTEGER, cptr, |
| 205 |
&StorageTmp-> |
| 206 |
lookupResultsAddressType, &tmpint); |
| 207 |
cptr = |
| 208 |
read_config_store_data(ASN_OCTET_STR, cptr, |
| 209 |
&StorageTmp->lookupResultsAddress, |
| 210 |
&StorageTmp-> |
| 211 |
lookupResultsAddressLen); |
| 212 |
|
| 213 |
snmpd_store_config(line); |
| 214 |
} |
| 215 |
} |
| 216 |
DEBUGMSGTL(("lookupResultsTable", "done.\n")); |
| 217 |
return SNMPERR_SUCCESS; |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
int |
| 222 |
lookupResultsTable_inadd(struct lookupResultsTable_data *thedata) |
| 223 |
{ |
| 224 |
netsnmp_variable_list *vars_list = NULL; |
| 225 |
|
| 226 |
snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_OCTET_STR, |
| 227 |
(char *) thedata->lookupCtlOwnerIndex, |
| 228 |
thedata->lookupCtlOwnerIndexLen); |
| 229 |
snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_OCTET_STR, |
| 230 |
(char *) thedata->lookupCtlOperationName, |
| 231 |
thedata->lookupCtlOperationNameLen); |
| 232 |
snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_UNSIGNED, |
| 233 |
(char *) &thedata->lookupResultsIndex, |
| 234 |
sizeof(thedata->lookupResultsIndex)); |
| 235 |
|
| 236 |
/* |
| 237 |
* XXX: fill in default row values here into StorageNew |
| 238 |
* |
| 239 |
*/ |
| 240 |
|
| 241 |
|
| 242 |
DEBUGMSGTL(("lookupResultsTable", "adding data... ")); |
| 243 |
/* |
| 244 |
* add the index variables to the varbind list, which is |
| 245 |
* used by header_complex to index the data |
| 246 |
*/ |
| 247 |
|
| 248 |
header_complex_add_data(&lookupResultsTableStorage, vars_list, |
| 249 |
thedata); |
| 250 |
DEBUGMSGTL(("lookupResultsTable", "registered an entry\n")); |
| 251 |
|
| 252 |
|
| 253 |
DEBUGMSGTL(("lookupResultsTable", "done.\n")); |
| 254 |
vars_list = NULL; |
| 255 |
return SNMPERR_SUCCESS; |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
/* |
| 260 |
* var_lookupResultsTable(): |
| 261 |
* Handle this table separately from the scalar value case. |
| 262 |
* The workings of this are basically the same as for var_lookupResultsTable above. |
| 263 |
*/ |
| 264 |
unsigned char * |
| 265 |
var_lookupResultsTable(struct variable *vp, |
| 266 |
oid * name, |
| 267 |
size_t *length, |
| 268 |
int exact, |
| 269 |
size_t *var_len, WriteMethod ** write_method) |
| 270 |
{ |
| 271 |
|
| 272 |
|
| 273 |
struct lookupResultsTable_data *StorageTmp = NULL; |
| 274 |
|
| 275 |
*write_method = NULL; |
| 276 |
/* |
| 277 |
* this assumes you have registered all your data properly |
| 278 |
*/ |
| 279 |
if ((StorageTmp = |
| 280 |
header_complex(lookupResultsTableStorage, vp, name, length, exact, |
| 281 |
var_len, write_method)) == NULL) { |
| 282 |
return NULL; |
| 283 |
} |
| 284 |
|
| 285 |
/* |
| 286 |
* this is where we do the value assignments for the mib results. |
| 287 |
*/ |
| 288 |
|
| 289 |
switch (vp->magic) { |
| 290 |
|
| 291 |
case COLUMN_LOOKUPRESULTSADDRESSTYPE: |
| 292 |
*var_len = sizeof(StorageTmp->lookupResultsAddressType); |
| 293 |
return (u_char *) & StorageTmp->lookupResultsAddressType; |
| 294 |
|
| 295 |
case COLUMN_LOOKUPRESULTSADDRESS: |
| 296 |
*var_len = (StorageTmp->lookupResultsAddressLen); |
| 297 |
return (u_char *) StorageTmp->lookupResultsAddress; |
| 298 |
|
| 299 |
default: |
| 300 |
ERROR_MSG(""); |
| 301 |
} |
| 302 |
|
| 303 |
return NULL; |
| 304 |
} |