1 #include <net-snmp/net-snmp-config.h>
5 #include <net-snmp/net-snmp-includes.h>
6 #include <net-snmp/agent/net-snmp-agent-includes.h>
8 #include <net-snmp/agent/multiplexer.h>
14 /** @defgroup multiplexer multiplexer: splits mode requests into calls to different handlers.
16 * The multiplexer helper lets you split the calling chain depending
17 * on the calling mode (get vs getnext vs set). Useful if you want
18 * different routines to handle different aspects of SNMP requests,
19 * which is very common for GET vs SET type actions.
23 * -# GET requests call the get_method
24 * -# GETNEXT requests call the getnext_method, or if not present, the
26 * -# GETBULK requests call the getbulk_method, or if not present, the
27 * getnext_method, or if even that isn't present the get_method.
28 * -# SET requests call the set_method, or if not present return a
29 * SNMP_ERR_NOTWRITABLE error.
33 /** returns a multiplixer handler given a netsnmp_mib_handler_methods structure of subhandlers.
36 netsnmp_get_multiplexer_handler(netsnmp_mib_handler_methods *req)
38 netsnmp_mib_handler *ret = NULL;
42 "netsnmp_get_multiplexer_handler(NULL) called\n");
47 netsnmp_create_handler("multiplexer",
48 netsnmp_multiplexer_helper_handler);
50 ret->myvoid = (void *) req;
55 /** implements the multiplexer helper */
57 netsnmp_multiplexer_helper_handler(netsnmp_mib_handler *handler,
58 netsnmp_handler_registration *reginfo,
59 netsnmp_agent_request_info *reqinfo,
60 netsnmp_request_info *requests)
63 netsnmp_mib_handler_methods *methods;
65 if (!handler->myvoid) {
66 snmp_log(LOG_INFO, "improperly registered multiplexer found\n");
67 return SNMP_ERR_GENERR;
70 methods = (netsnmp_mib_handler_methods *) handler->myvoid;
72 switch (reqinfo->mode) {
74 handler = methods->get_handler;
76 netsnmp_set_all_requests_error(reqinfo, requests,
82 handler = methods->getnext_handler;
83 if (!handler) /* fallback to get handler */
84 handler = methods->get_handler;
89 * XXX: this needs to do better getbulk -> getnext
90 * handling (probably via a separate helper)
92 handler = methods->getbulk_handler;
93 if (!handler) /* fallback to getnext handler */
94 handler = methods->getnext_handler;
95 if (!handler) /* fallback to getnext handler */
96 handler = methods->get_handler;
99 case MODE_SET_RESERVE1:
100 case MODE_SET_RESERVE2:
101 case MODE_SET_ACTION:
102 case MODE_SET_COMMIT:
105 handler = methods->set_handler;
107 netsnmp_set_all_requests_error(reqinfo, requests,
108 SNMP_ERR_NOTWRITABLE);
109 return SNMP_ERR_NOERROR;
114 * XXX: process SETs specially, and possibly others
117 snmp_log(LOG_ERR, "unsupported mode for multiplexer: %d\n",
119 return SNMP_ERR_GENERR;
123 "No handler enabled for mode %d in multiplexer\n",
125 return SNMP_ERR_GENERR;
127 return netsnmp_call_handler(handler, reginfo, reqinfo, requests);