| 1 |
/* |
| 2 |
* DisMan Event MIB: |
| 3 |
* Implementation of the mteEventNotificationTable MIB interface |
| 4 |
* See 'mteEvent.c' for active behaviour of this table. |
| 5 |
* |
| 6 |
* (based on mib2c.table_data.conf output) |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <net-snmp/net-snmp-config.h> |
| 10 |
#include <net-snmp/net-snmp-features.h> |
| 11 |
#include <net-snmp/net-snmp-includes.h> |
| 12 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 13 |
#include "disman/event/mteEvent.h" |
| 14 |
#include "disman/event/mteEventNotificationTable.h" |
| 15 |
|
| 16 |
netsnmp_feature_require(table_tdata); |
| 17 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 18 |
netsnmp_feature_require(check_vb_type_and_max_size); |
| 19 |
netsnmp_feature_require(check_vb_oid); |
| 20 |
#endif /* NETSNMP_NO_WRITE_SUPPORT */ |
| 21 |
|
| 22 |
static netsnmp_table_registration_info *table_info; |
| 23 |
|
| 24 |
/* Initializes the mteEventNotificationTable module */ |
| 25 |
void |
| 26 |
init_mteEventNotificationTable(void) |
| 27 |
{ |
| 28 |
static oid mteEventNotificationTable_oid[] = { 1, 3, 6, 1, 2, 1, 88, 1, 4, 3 }; |
| 29 |
size_t mteEventNotificationTable_oid_len = OID_LENGTH(mteEventNotificationTable_oid); |
| 30 |
netsnmp_handler_registration *reg; |
| 31 |
|
| 32 |
/* |
| 33 |
* Ensure the (combined) table container is available... |
| 34 |
*/ |
| 35 |
init_event_table_data(); |
| 36 |
|
| 37 |
/* |
| 38 |
* ... then set up the MIB interface to the mteEventNotificationTable slice |
| 39 |
*/ |
| 40 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 41 |
reg = netsnmp_create_handler_registration("mteEventNotificationTable", |
| 42 |
mteEventNotificationTable_handler, |
| 43 |
mteEventNotificationTable_oid, |
| 44 |
mteEventNotificationTable_oid_len, |
| 45 |
HANDLER_CAN_RWRITE); |
| 46 |
#else /* !NETSNMP_NO_WRITE_SUPPORT */ |
| 47 |
reg = netsnmp_create_handler_registration("mteEventNotificationTable", |
| 48 |
mteEventNotificationTable_handler, |
| 49 |
mteEventNotificationTable_oid, |
| 50 |
mteEventNotificationTable_oid_len, |
| 51 |
HANDLER_CAN_RONLY); |
| 52 |
#endif /* !NETSNMP_NO_WRITE_SUPPORT */ |
| 53 |
|
| 54 |
table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); |
| 55 |
netsnmp_table_helper_add_indexes(table_info, |
| 56 |
ASN_OCTET_STR, /* index: mteOwner */ |
| 57 |
/* index: mteEventName */ |
| 58 |
ASN_PRIV_IMPLIED_OCTET_STR, |
| 59 |
0); |
| 60 |
|
| 61 |
table_info->min_column = COLUMN_MTEEVENTNOTIFICATION; |
| 62 |
table_info->max_column = COLUMN_MTEEVENTNOTIFICATIONOBJECTS; |
| 63 |
|
| 64 |
/* Register this using the (common) event_table_data container */ |
| 65 |
netsnmp_tdata_register(reg, event_table_data, table_info); |
| 66 |
DEBUGMSGTL(("disman:event:init", "Event Notify Table container (%p)\n", |
| 67 |
event_table_data)); |
| 68 |
} |
| 69 |
|
| 70 |
void |
| 71 |
shutdown_mteEventNotificationTable(void) |
| 72 |
{ |
| 73 |
if (table_info) { |
| 74 |
netsnmp_table_registration_info_free(table_info); |
| 75 |
table_info = NULL; |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
/** handles requests for the mteEventNotificationTable table */ |
| 81 |
int |
| 82 |
mteEventNotificationTable_handler(netsnmp_mib_handler *handler, |
| 83 |
netsnmp_handler_registration *reginfo, |
| 84 |
netsnmp_agent_request_info *reqinfo, |
| 85 |
netsnmp_request_info *requests) |
| 86 |
{ |
| 87 |
|
| 88 |
netsnmp_request_info *request; |
| 89 |
netsnmp_table_request_info *tinfo; |
| 90 |
struct mteEvent *entry; |
| 91 |
int ret; |
| 92 |
|
| 93 |
DEBUGMSGTL(("disman:event:mib", "Notification Table handler (%d)\n", reqinfo->mode)); |
| 94 |
|
| 95 |
switch (reqinfo->mode) { |
| 96 |
/* |
| 97 |
* Read-support (also covers GetNext requests) |
| 98 |
*/ |
| 99 |
case MODE_GET: |
| 100 |
for (request = requests; request; request = request->next) { |
| 101 |
if (request->processed) |
| 102 |
continue; |
| 103 |
|
| 104 |
entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request); |
| 105 |
tinfo = netsnmp_extract_table_info(request); |
| 106 |
|
| 107 |
/* |
| 108 |
* The mteEventNotificationTable should only contains entries |
| 109 |
* for rows where the mteEventActions 'notification(0)' bit |
| 110 |
* is set. So skip entries where this isn't the case. |
| 111 |
*/ |
| 112 |
if (!entry || !(entry->mteEventActions & MTE_EVENT_NOTIFICATION)) |
| 113 |
continue; |
| 114 |
|
| 115 |
switch (tinfo->colnum) { |
| 116 |
case COLUMN_MTEEVENTNOTIFICATION: |
| 117 |
snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID, |
| 118 |
(u_char *) entry->mteNotification, |
| 119 |
entry->mteNotification_len*sizeof(oid)); |
| 120 |
break; |
| 121 |
case COLUMN_MTEEVENTNOTIFICATIONOBJECTSOWNER: |
| 122 |
snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, |
| 123 |
(u_char *) entry->mteNotifyOwner, |
| 124 |
strlen(entry->mteNotifyOwner)); |
| 125 |
break; |
| 126 |
case COLUMN_MTEEVENTNOTIFICATIONOBJECTS: |
| 127 |
snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR, |
| 128 |
(u_char *) entry->mteNotifyObjects, |
| 129 |
strlen(entry->mteNotifyObjects)); |
| 130 |
break; |
| 131 |
} |
| 132 |
} |
| 133 |
break; |
| 134 |
|
| 135 |
|
| 136 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 137 |
/* |
| 138 |
* Write-support |
| 139 |
*/ |
| 140 |
case MODE_SET_RESERVE1: |
| 141 |
for (request = requests; request; request = request->next) { |
| 142 |
if (request->processed) |
| 143 |
continue; |
| 144 |
|
| 145 |
tinfo = netsnmp_extract_table_info(request); |
| 146 |
|
| 147 |
/* |
| 148 |
* Since the mteEventNotificationTable only contains entries |
| 149 |
* for rows where the mteEventActions 'notification(0)' |
| 150 |
* bit is set, strictly speaking we should reject |
| 151 |
* assignments where this isn't the case. |
| 152 |
* But SET requests that include an assignment of the |
| 153 |
* 'notification(0)' bit at the same time are valid, |
| 154 |
* so would need to be accepted. Unfortunately, this |
| 155 |
* assignment is only applied in the COMMIT pass, so |
| 156 |
* it's difficult to detect whether this holds or not. |
| 157 |
* |
| 158 |
* Let's fudge things for now, by processing assignments |
| 159 |
* even if the 'notification(0)' bit isn't set. |
| 160 |
*/ |
| 161 |
|
| 162 |
switch (tinfo->colnum) { |
| 163 |
case COLUMN_MTEEVENTNOTIFICATION: |
| 164 |
ret = netsnmp_check_vb_oid( request->requestvb ); |
| 165 |
if (ret != SNMP_ERR_NOERROR) { |
| 166 |
netsnmp_set_request_error(reqinfo, request, ret); |
| 167 |
return SNMP_ERR_NOERROR; |
| 168 |
} |
| 169 |
break; |
| 170 |
case COLUMN_MTEEVENTNOTIFICATIONOBJECTSOWNER: |
| 171 |
case COLUMN_MTEEVENTNOTIFICATIONOBJECTS: |
| 172 |
ret = netsnmp_check_vb_type_and_max_size( |
| 173 |
request->requestvb, ASN_OCTET_STR, MTE_STR1_LEN); |
| 174 |
if (ret != SNMP_ERR_NOERROR) { |
| 175 |
netsnmp_set_request_error(reqinfo, request, ret); |
| 176 |
return SNMP_ERR_NOERROR; |
| 177 |
} |
| 178 |
break; |
| 179 |
default: |
| 180 |
netsnmp_set_request_error(reqinfo, request, |
| 181 |
SNMP_ERR_NOTWRITABLE); |
| 182 |
return SNMP_ERR_NOERROR; |
| 183 |
} |
| 184 |
|
| 185 |
/* |
| 186 |
* The Event MIB is somewhat ambiguous as to whether |
| 187 |
* mteEventNotificationTable (and mteEventSetTable) |
| 188 |
* entries can be modified once the main mteEventTable |
| 189 |
* entry has been marked 'active'. |
| 190 |
* But it's clear from discussion on the DisMan mailing |
| 191 |
* list is that the intention is not. |
| 192 |
* |
| 193 |
* So check for whether this row is already active, |
| 194 |
* and reject *all* SET requests if it is. |
| 195 |
*/ |
| 196 |
entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request); |
| 197 |
if (entry && |
| 198 |
entry->flags & MTE_EVENT_FLAG_ACTIVE ) { |
| 199 |
netsnmp_set_request_error(reqinfo, request, |
| 200 |
SNMP_ERR_INCONSISTENTVALUE); |
| 201 |
return SNMP_ERR_NOERROR; |
| 202 |
} |
| 203 |
} |
| 204 |
break; |
| 205 |
|
| 206 |
case MODE_SET_RESERVE2: |
| 207 |
case MODE_SET_FREE: |
| 208 |
case MODE_SET_UNDO: |
| 209 |
break; |
| 210 |
|
| 211 |
case MODE_SET_ACTION: |
| 212 |
for (request = requests; request; request = request->next) { |
| 213 |
if (request->processed) |
| 214 |
continue; |
| 215 |
|
| 216 |
entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request); |
| 217 |
if (!entry) { |
| 218 |
/* |
| 219 |
* New rows must be created via the RowStatus column |
| 220 |
* (in the main mteEventTable) |
| 221 |
*/ |
| 222 |
netsnmp_set_request_error(reqinfo, request, |
| 223 |
SNMP_ERR_NOCREATION); |
| 224 |
/* or inconsistentName? */ |
| 225 |
return SNMP_ERR_NOERROR; |
| 226 |
|
| 227 |
} |
| 228 |
} |
| 229 |
break; |
| 230 |
|
| 231 |
case MODE_SET_COMMIT: |
| 232 |
/* |
| 233 |
* All these assignments are "unfailable", so it's |
| 234 |
* (reasonably) safe to apply them in the Commit phase |
| 235 |
*/ |
| 236 |
for (request = requests; request; request = request->next) { |
| 237 |
if (request->processed) |
| 238 |
continue; |
| 239 |
|
| 240 |
entry = (struct mteEvent *) netsnmp_tdata_extract_entry(request); |
| 241 |
tinfo = netsnmp_extract_table_info(request); |
| 242 |
|
| 243 |
switch (tinfo->colnum) { |
| 244 |
case COLUMN_MTEEVENTNOTIFICATION: |
| 245 |
memset(entry->mteNotification, 0, sizeof(entry->mteNotification)); |
| 246 |
memcpy(entry->mteNotification, request->requestvb->val.objid, |
| 247 |
request->requestvb->val_len); |
| 248 |
entry->mteNotification_len = request->requestvb->val_len/sizeof(oid); |
| 249 |
break; |
| 250 |
case COLUMN_MTEEVENTNOTIFICATIONOBJECTSOWNER: |
| 251 |
memset(entry->mteNotifyOwner, 0, sizeof(entry->mteNotifyOwner)); |
| 252 |
memcpy(entry->mteNotifyOwner, request->requestvb->val.string, |
| 253 |
request->requestvb->val_len); |
| 254 |
break; |
| 255 |
case COLUMN_MTEEVENTNOTIFICATIONOBJECTS: |
| 256 |
memset(entry->mteNotifyObjects, 0, sizeof(entry->mteNotifyObjects)); |
| 257 |
memcpy(entry->mteNotifyObjects, request->requestvb->val.string, |
| 258 |
request->requestvb->val_len); |
| 259 |
break; |
| 260 |
} |
| 261 |
} |
| 262 |
break; |
| 263 |
#endif /* !NETSNMP_NO_WRITE_SUPPORT */ |
| 264 |
} |
| 265 |
return SNMP_ERR_NOERROR; |
| 266 |
} |