📄 baby_steps.c
字号:
/* * baby_steps.c * $Id: baby_steps.c,v 1.10.2.1 2004/12/10 03:30:19 rstory Exp $ */#include <net-snmp/net-snmp-config.h>#include <net-snmp/net-snmp-includes.h>#include <net-snmp/agent/net-snmp-agent-includes.h>#include <net-snmp/agent/baby_steps.h>#if HAVE_DMALLOC_H#include <dmalloc.h>#endif#define BABY_STEPS_PER_MODE_MAX 4#define BSTEP_USE_ORIGINAL 0xffffstatic u_short get_mode_map[BABY_STEPS_PER_MODE_MAX] = { MODE_BSTEP_PRE_REQUEST, MODE_BSTEP_OBJECT_LOOKUP, BSTEP_USE_ORIGINAL, MODE_BSTEP_POST_REQUEST };static u_short set_mode_map[SNMP_MSG_INTERNAL_SET_MAX][BABY_STEPS_PER_MODE_MAX] = { /*R1*/ { MODE_BSTEP_PRE_REQUEST, MODE_BSTEP_OBJECT_LOOKUP, MODE_BSTEP_ROW_CREATE, MODE_BSTEP_CHECK_VALUE }, /*R2*/ { MODE_BSTEP_UNDO_SETUP, BABY_STEP_NONE, BABY_STEP_NONE, BABY_STEP_NONE }, /*A */ { MODE_BSTEP_SET_VALUE,MODE_BSTEP_CHECK_CONSISTENCY, MODE_BSTEP_COMMIT, BABY_STEP_NONE }, /*C */ { MODE_BSTEP_IRREVERSIBLE_COMMIT, MODE_BSTEP_UNDO_CLEANUP, MODE_BSTEP_POST_REQUEST, BABY_STEP_NONE}, /*F */ { MODE_BSTEP_UNDO_CLEANUP, MODE_BSTEP_POST_REQUEST, BABY_STEP_NONE, BABY_STEP_NONE }, /*U */ { MODE_BSTEP_UNDO_COMMIT, MODE_BSTEP_UNDO_SET, MODE_BSTEP_UNDO_CLEANUP, MODE_BSTEP_POST_REQUEST}};static int_baby_steps_helper(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests);static int_baby_steps_access_multiplexer(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests); /** @defgroup baby_steps baby_steps: calls your handler in baby_steps for set processing. * @ingroup handler * @{ *//** returns a baby_steps handler that can be injected into a given * handler chain. */netsnmp_mib_handler *netsnmp_baby_steps_handler_get(u_long modes){ netsnmp_mib_handler *mh; netsnmp_baby_steps_modes *md; mh = netsnmp_create_handler("baby_steps", _baby_steps_helper); if(!mh) return NULL; md = SNMP_MALLOC_TYPEDEF(netsnmp_baby_steps_modes); if (NULL == md) { snmp_log(LOG_ERR,"malloc failed in netsnmp_baby_steps_handler_get\n"); netsnmp_handler_free(mh); mh = NULL; } else { mh->myvoid = md; if (0 == modes) modes = BABY_STEP_ALL; md->registered = modes; } /* * don't set MIB_HANDLER_AUTO_NEXT, since we need to call lower * handlers with a munged mode. */ return mh;}/** @internal Implements the baby_steps handler */static int_baby_steps_helper(netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests){ netsnmp_baby_steps_modes *bs_modes; int save_mode, i, rc = SNMP_ERR_NOERROR; u_short *mode_map_ptr; DEBUGMSGTL(("baby_steps", "Got request, mode %s\n", se_find_label_in_slist("agent_mode",reqinfo->mode))); bs_modes = handler->myvoid; netsnmp_assert(NULL != bs_modes); switch (reqinfo->mode) { case MODE_SET_RESERVE1: /* * clear completed modes * xxx-rks: this will break for pdus with set requests to different * rows in the same table when the handler is set up to use the row * merge helper as well (or if requests are serialized). */ bs_modes->completed = 0; /** fall through */ case MODE_SET_RESERVE2: case MODE_SET_ACTION: case MODE_SET_COMMIT: case MODE_SET_FREE: case MODE_SET_UNDO: mode_map_ptr = set_mode_map[reqinfo->mode]; break; default: /* * clear completed modes */ bs_modes->completed = 0; mode_map_ptr = get_mode_map; } /* * NOTE: if you update this chart, please update the versions in * local/mib2c-conf.d/parent-set.m2i * agent/mibgroup/helpers/baby_steps.c * while you're at it. */ /* *********************************************************************** * Baby Steps Flow Chart (2004.06.05) * * * * +--------------+ +================+ U = unconditional path * * |optional state| ||required state|| S = path for success * * +--------------+ +================+ E = path for error * *********************************************************************** * * +--------------+ * | pre | * | request | * +--------------+ * | U * +-------------+ +==============+ * | row |f|<-------|| object || * | create |1| E || lookup || * +-------------+ +==============+ * E | | S | S * | +------------------>| * | +==============+ * | E || check || * |<---------------|| values || * | +==============+ * | | S * | +==============+ * | +<-------|| undo || * | | E || setup || * | | +==============+ * | | | S * | | +==============+ * | | || set ||-------------------------->+ * | | || value || E | * | | +==============+ | * | | | S | * | | +--------------+ | * | | | check |-------------------------->| * | | | consistency | E | * | | +--------------+ | * | | | S | * | | +==============+ +==============+ | * | | || commit ||-------->|| undo || | * | | || || E || commit || | * | | +==============+ +==============+ | * | | | S U |<--------+ * | | +--------------+ +==============+ * | | | irreversible | || undo || * | | | commit | || set || * | | +--------------+ +==============+ * | | | U U | * | +-------------->|<------------------------+ * | +==============+ * | || undo || * | || cleanup || * | +==============+ * +---------------------->| U * | * (err && f1)------------------->+ * | | * +--------------+ +--------------+ * | post |<--------| row | * | request | U | release | * +--------------+ +--------------+ * */ /* * save original mode */ save_mode = reqinfo->mode; for(i = 0; i < BABY_STEPS_PER_MODE_MAX; ++i ) { /* * break if we run out of baby steps for this mode */ if(mode_map_ptr[i] == BABY_STEP_NONE) break; DEBUGMSGTL(("baby_steps", " baby step mode %s\n", se_find_label_in_slist("babystep_mode",mode_map_ptr[i]))); /* * skip modes the handler didn't register for */ if (BSTEP_USE_ORIGINAL != mode_map_ptr[i]) { u_int mode_flag; /* * skip undo commit if commit wasn't hit, and * undo_cleanup if undo_setup wasn't hit. */ if((MODE_SET_UNDO == save_mode) && (MODE_BSTEP_UNDO_COMMIT == mode_map_ptr[i]) && !(BABY_STEP_COMMIT & bs_modes->completed)) { DEBUGMSGTL(("baby_steps", " skipping commit undo (no commit)\n")); continue; } else if((MODE_SET_FREE == save_mode) && (MODE_BSTEP_UNDO_CLEANUP == mode_map_ptr[i]) && !(BABY_STEP_UNDO_SETUP & bs_modes->completed)) { DEBUGMSGTL(("baby_steps", " skipping undo cleanup (no undo setup)\n")); continue; } reqinfo->mode = mode_map_ptr[i]; mode_flag = netsnmp_baby_step_mode2flag( mode_map_ptr[i] ); if((mode_flag & bs_modes->registered)) bs_modes->completed |= mode_flag; else { DEBUGMSGTL(("baby_steps", " skipping mode (not registered)\n")); continue; } } else { reqinfo->mode = save_mode;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -