📄 v3mt_nfy.c
字号:
NAME: notifytable_create_cleanupPURPOSE: Cleanup after a notify create test succeeded but some other test failed. As this is a create the state pointer points to a structure that is installed, we need to deinstall it, call the backout routine, and cleanup the state. Expects the pointer to point to a VB_TPARAMETERS: ptr_t A pointer to the vb that points to the notify that we were going to create, cast as a ptr_tRETURNS: Nothing****************************************************************************/static void notifytable_create_cleanup(ptr_t notifyptr){SNMP_NOTIFY_T *notify;notify = (SNMP_NOTIFY_T *)(((VB_T *)notifyptr)->vb_priv);SNMP_V3_NOTIFY_CREATE_BACKOUT(0, notify);SNMP_Notify_Deinstall(notify);SNMP_Notify_Destroy(notify);}/****************************************************************************NAME: notifytable_update_cleanupPURPOSE: Cleanup after a notify update test succeeded but some other test failed. As this is an update the state pointer points to a structure that isn't installed. The next pointer of that structure points to the installed copy. We call the backout routine and cleanup the state.PARAMETERS: ptr_t A pointer to the vb that points to the notify that contained the update information, cast as a ptr_tRETURNS: Nothing****************************************************************************/static void notifytable_update_cleanup(ptr_t notifyptr){SNMP_NOTIFY_T *notify;notify = (SNMP_NOTIFY_T *)(((VB_T *)notifyptr)->vb_priv);SNMP_V3_NOTIFY_UPDATE_BACKOUT(notify->next, notify);SNMP_Notify_Destroy(notify);}/****************************************************************************NAME: notifytable_destroy_undoPURPOSE: This routine attempts to undo a previous destroy set. It expects the old information to be pointed to by vb_priv and tries to reinstall it. If we can't reinstall the notify we leave the cleanup routine alone in order to get the FINISHED macro to run.PARAMETERS: OIDC_T Last component of the object id leading to the leaf node in the MIB. This is usually the identifier for the particular attribute in the table. int Number of components in the unused part of the object identifier OIDC_T * Unused part of the object identifier SNMP_PKT_T * SNMP packet currently being processsed. VB_T * Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/static void notifytable_destroy_undo(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){SNMP_NOTIFY_T *notify;bits8_t name[ETC_NOTIFY_MAX];ALENGTH_T name_len = ETC_NOTIFY_MAX;/* assume things will go well and mark the vbp as done */undoproc_good(pktp, vbp);/* get the name info, no need to check as it's already been validated */oid_to_string(tcount, tlist, &name_len, name, 1);/* find the state block we saved and then reset the vb_priv info so we don't have any accidents later */notify = (SNMP_NOTIFY_T *)vbp->vb_priv;vbp->vb_priv = 0;if (SNMP_Notify_Install(notify, name, name_len) == 0) {#if defined(SNMP_V3_NOTIFY_DESTROY_UNDO) if (SNMP_V3_NOTIFY_DESTROY_UNDO(pktp, vbp, 0, notify) == 0) { vbp->vb_free_priv = 0; return; } else SNMP_Notify_Deinstall(notify);#else vbp->vb_free_priv = 0; return;#endif }SNMP_Notify_Destroy(notify);undoproc_error(pktp, vbp, UNDO_FAILED);return;}/****************************************************************************NAME: notifytable_create_undoPURPOSE: This routine attempts to undo a previous create set. It expects the new information to be pointed to by vb_priv and tries to deinstall and destroy the entry.PARAMETERS: OIDC_T Last component of the object id leading to the leaf node in the MIB. This is usually the identifier for the particular attribute in the table. int Number of components in the unused part of the object identifier OIDC_T * Unused part of the object identifier SNMP_PKT_T * SNMP packet currently being processsed. VB_T * Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/static void notifytable_create_undo(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){SNMP_NOTIFY_T *notify;/* assume things will go well */undoproc_good(pktp, vbp);/* find the state block we saved and then reset the vb_priv info so we don't have any accidents later */notify = (SNMP_NOTIFY_T *)vbp->vb_priv;vbp->vb_priv = 0;vbp->vb_free_priv = 0;#if defined(SNMP_V3_NOTIFY_CREATE_UNDO)if (SNMP_V3_NOTIFY_CREATE_UNDO(pktp, vbp, notify, 0)) { undoproc_error(pktp, vbp, UNDO_FAILED); return; }#endifSNMP_Notify_Deinstall(notify);SNMP_Notify_Destroy(notify);return;}/****************************************************************************NAME: notifytable_update_undoPURPOSE: This routine attempts to undo a previous update set. It expects the struct pointed to by vb_priv to contain the old information and a pointer to the new (installed) struct.PARAMETERS: OIDC_T Last component of the object id leading to the leaf node in the MIB. This is usually the identifier for the particular attribute in the table. int Number of components in the unused part of the object identifier OIDC_T * Unused part of the object identifier SNMP_PKT_T * SNMP packet currently being processsed. VB_T * Variable being processed.RETURNS: void****************************************************************************//*ARGSUSED*/static void notifytable_update_undo(OIDC_T last_match, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){SNMP_NOTIFY_T *cur_notify, *sav_notify;/* assume things will go well */undoproc_good(pktp, vbp);/* find the state block we saved and then reset the vb_priv info so we don't have any accidents later */sav_notify = (SNMP_NOTIFY_T *)vbp->vb_priv;vbp->vb_priv = 0;vbp->vb_free_priv = 0;cur_notify = sav_notify->next;#if defined(SNMP_V3_NOTIFY_UPDATE_UNDO)if (SNMP_V3_NOTIFY_UPDATE_UNDO(pktp, vbp, cur_notify, sav_notify)) { undoproc_error(pktp, vbp, UNDO_FAILED); SNMP_Notify_Destroy(sav_notify); return; }#endif/* swap the info from saved notify back into current notify, we only need to move strings if the names are different finally free the saved block */if (SNMP_Notify_Get_Tag(cur_notify) != SNMP_Notify_Get_Tag(sav_notify)) { EBufferClean(&cur_notify->notify_tag); MEMCPY(&cur_notify->notify_tag, &sav_notify->notify_tag, sizeof(EBUFFER_T)); EBufferInitialize(&sav_notify->notify_tag); }SNMP_Notify_Set_Type(cur_notify, SNMP_Notify_Get_Type(sav_notify));SNMP_Notify_Set_Storage(cur_notify, SNMP_Notify_Get_Storage(sav_notify));SNMP_Notify_Set_Status(cur_notify, SNMP_Notify_Get_Status(sav_notify));SNMP_Notify_Set_Flags(cur_notify, SNMP_Notify_Get_Flags(sav_notify));SNMP_Notify_Destroy(sav_notify);return;}/****************************************************************************NAME: notifytable_set_cleanupPURPOSE: Free the saved notify and indicate that we are finished.PARAMETERS: ptr_t A pointer to the vb that points to the notify that contained the update information, cast as a ptr_tRETURNS: Nothing****************************************************************************/static void notifytable_set_cleanup(ptr_t notifyptr){if (((VB_T *)notifyptr)->vb_priv) { if (((VB_T *)notifyptr)->undoproc == notifytable_create_undo) ((VB_T *)notifyptr)->vb_priv = 0; else SNMP_Notify_Destroy(((VB_T *)notifyptr)->vb_priv); }SNMP_V3_NOTIFY_FINISHED();}void snmpNotifyEntry_test(OIDC_T lastmatch, int tcount, OIDC_T *tlist, SNMP_PKT_T *pktp, VB_T *vbp){SNMP_NOTIFY_T *notify, tempnotify, *newnotify;sbits32_t value, ptret;int cago = 0, create_row = 0, tag_chg = 0;ALENGTH_T nlen = 0;VB_T *tvbp, *rs_vbp = 0;bits8_t name[ETC_NOTIFY_MAX];bits8_t *tp;ALENGTH_T name_len = ETC_NOTIFY_MAX;/* get the list of var binds that may go into this structure then mark all the vbs except the first one as having been tested, set and done. This means that vbp is taking responsibility for all of the other vbs in the row. Then mark vbp as having it's test started & done so we don't have to worry about it later. We can do this because the routine will run to completion */group_by_getproc_and_instance(pktp, vbp, tcount, tlist);for(tvbp = vbp->vb_link; tvbp; tvbp = tvbp->vb_link) setproc_all_bits(pktp, tvbp);testproc_good(pktp, vbp);/* gather the indexing information, the index will be of the form: <name> first we do some minor checks then we attempt to find the user */if ((tcount > ETC_NOTIFY_MAX) || oid_to_string(tcount, tlist, &name_len, name, 1) || (name_len == 0) || ((bits32_t)name_len != (bits32_t) tcount)) { testproc_error(pktp, vbp, NO_CREATION); return; }notify = SNMP_Notify_Lookup(name, name_len);/* is the leaf writable, (if it's read only it isn't writable) */if (notify != 0) { if (SNMP_Notify_Get_Storage(notify) == ETC_STO_RONLY) { testproc_error(pktp, vbp, NOT_WRITABLE); return; } MEMCPY(&tempnotify, notify, sizeof(SNMP_NOTIFY_T)); }else { SNMP_Notify_Set_Defaults(&tempnotify); create_row = 1; } for (tvbp = vbp; tvbp; tvbp = tvbp->vb_link) { switch(tvbp->vb_ml.ml_last_match) { case LEAF_snmpNotifyTag: nlen = EBufferUsed(&tvbp->value_u.v_string); if (nlen > MAXSIZE_snmpNotifyTag) { testproc_error(pktp, tvbp, WRONG_LENGTH); return; } for (tp = EBufferStart(&tvbp->value_u.v_string); tp < EBufferNext(&tvbp->value_u.v_string); tp++) { if (tag_whitespace(*tp)) { testproc_error(pktp, vbp, WRONG_VALUE); return; } } EBufferPreLoad(BFL_IS_STATIC, &tempnotify.notify_tag, EBufferStart(&tvbp->value_u.v_string), nlen); break; case LEAF_snmpNotifyType: value = tvbp->value_u.v_number; if ((value != VAL_snmpNotifyType_trap) && (value != VAL_snmpNotifyType_inform)) { testproc_error(pktp, tvbp, WRONG_VALUE); return; } SNMP_Notify_Set_Type(&tempnotify, (bits16_t)value); break; case LEAF_snmpNotifyStorageType: value = tvbp->value_u.v_number; if ((value < ETC_STO_OTHER) || (value > ETC_STO_RONLY) || ((notify != 0) && (value > ETC_STO_NONVOL)) || (SNMP_Notify_Get_Storage(&tempnotify) >= ETC_STO_PERM)) { testproc_error(pktp, tvbp, WRONG_VALUE); return; } SNMP_Notify_Set_Storage(&tempnotify, (bits16_t)value); break; case LEAF_snmpNotifyRowStatus: value = tvbp->value_u.v_number; switch (value) { case ETC_RS_ACTIVE: case ETC_RS_NIS: if (create_row) { testproc_error(pktp, tvbp, INCONSISTENT_VALUE); return; } break; case ETC_RS_CAGO: if (create_row == 0) { testproc_error(pktp, tvbp, INCONSISTENT_VALUE); return; } value = ETC_RS_ACTIVE; cago = 1; break; case ETC_RS_CAWAIT: if (create_row == 0) { testproc_error(pktp, tvbp, INCONSISTENT_VALUE); return; } value = ETC_RS_NREADY; break; case ETC_RS_DESTROY: if (SNMP_Notify_Get_Storage(&tempnotify) >= ETC_STO_PERM) { testproc_error(pktp, tvbp, WRONG_VALUE); return; } break; default: testproc_error(pktp, tvbp, WRONG_VALUE); return; } if (SNMP_Notify_Get_Status(&tempnotify) != ETC_RS_DESTROY) { SNMP_Notify_Set_Status(&tempnotify, (bits16_t)value); rs_vbp = tvbp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -