summaryrefslogtreecommitdiff
path: root/accel-pppd/extra/net-snmp/terminate.c
diff options
context:
space:
mode:
authorKozlov Dmitry <dima@server>2011-08-19 14:04:55 +0400
committerKozlov Dmitry <dima@server>2011-08-19 14:04:55 +0400
commit5ef49162ea9763ca9878c22e3736766d8f1db014 (patch)
treef58da9adfc87ece6c608265fc694e66bd5db162c /accel-pppd/extra/net-snmp/terminate.c
parentfd52e4578dcc7de2301480fece9395563d643045 (diff)
downloadaccel-ppp-xebd-5ef49162ea9763ca9878c22e3736766d8f1db014.tar.gz
accel-ppp-xebd-5ef49162ea9763ca9878c22e3736766d8f1db014.zip
snmp support
Diffstat (limited to 'accel-pppd/extra/net-snmp/terminate.c')
-rw-r--r--accel-pppd/extra/net-snmp/terminate.c379
1 files changed, 379 insertions, 0 deletions
diff --git a/accel-pppd/extra/net-snmp/terminate.c b/accel-pppd/extra/net-snmp/terminate.c
new file mode 100644
index 0000000..bd38577
--- /dev/null
+++ b/accel-pppd/extra/net-snmp/terminate.c
@@ -0,0 +1,379 @@
+/*
+ * Note: this file originally auto-generated by mib2c using
+ * : mib2c.scalar.conf 11805 2005-01-07 09:37:18Z dts12 $
+ */
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <net-snmp/net-snmp-config.h>
+#include <net-snmp/net-snmp-includes.h>
+#include <net-snmp/agent/net-snmp-agent-includes.h>
+
+#include "triton.h"
+#include "ppp.h"
+
+#include "terminate.h"
+
+static void __terminate(struct ppp_t *ppp)
+{
+ ppp_terminate(ppp, TERM_ADMIN_RESET, 0);
+}
+
+static void terminate_by_sid(const char *val)
+{
+ struct ppp_t *ppp;
+
+ pthread_rwlock_rdlock(&ppp_lock);
+ list_for_each_entry(ppp, &ppp_list, entry) {
+ if (strncmp(ppp->sessionid, val, PPP_SESSIONID_LEN))
+ continue;
+ triton_context_call(ppp->ctrl->ctx, (triton_event_func)__terminate, ppp);
+ break;
+ }
+ pthread_rwlock_unlock(&ppp_lock);
+}
+
+static void terminate_by_ifname(const char *val, size_t len)
+{
+ struct ppp_t *ppp;
+ size_t n;
+
+ pthread_rwlock_rdlock(&ppp_lock);
+ list_for_each_entry(ppp, &ppp_list, entry) {
+ n = strlen(ppp->ifname);
+ if (n != len)
+ continue;
+ if (strncmp(ppp->ifname, val, len))
+ continue;
+ triton_context_call(ppp->ctrl->ctx, (triton_event_func)__terminate, ppp);
+ break;
+ }
+ pthread_rwlock_unlock(&ppp_lock);
+}
+
+static void terminate_by_ip(const char *val, size_t len)
+{
+ char str[len + 1];
+ in_addr_t addr;
+ struct ppp_t *ppp;
+
+ strncpy(str, val, len);
+ str[len] = 0;
+
+ addr = inet_addr(str);
+
+ pthread_rwlock_rdlock(&ppp_lock);
+ list_for_each_entry(ppp, &ppp_list, entry) {
+ if (ppp->peer_ipaddr != addr)
+ continue;
+ triton_context_call(ppp->ctrl->ctx, (triton_event_func)__terminate, ppp);
+ break;
+ }
+ pthread_rwlock_unlock(&ppp_lock);
+}
+
+static void terminate_by_username(const char *val, size_t len)
+{
+ struct ppp_t *ppp;
+ size_t n;
+
+ pthread_rwlock_rdlock(&ppp_lock);
+ list_for_each_entry(ppp, &ppp_list, entry) {
+ if (!ppp->username)
+ continue;
+ n = strlen(ppp->username);
+ if (n != len)
+ continue;
+ if (strncmp(ppp->username, val, len))
+ continue;
+ triton_context_call(ppp->ctrl->ctx, (triton_event_func)__terminate, ppp);
+ }
+ pthread_rwlock_unlock(&ppp_lock);
+}
+
+
+/** Initializes the terminate module */
+void
+init_terminate(void)
+{
+ static oid termBySID_oid[] = { 1,3,6,1,4,1,8072,100,3,1,1 };
+ static oid termByIfName_oid[] = { 1,3,6,1,4,1,8072,100,3,1,2 };
+ static oid termByIP_oid[] = { 1,3,6,1,4,1,8072,100,3,1,3 };
+ static oid termByUsername_oid[] = { 1,3,6,1,4,1,8072,100,3,1,4 };
+
+ DEBUGMSGTL(("terminate", "Initializing\n"));
+
+ netsnmp_register_scalar(
+ netsnmp_create_handler_registration("termBySID", handle_termBySID,
+ termBySID_oid, OID_LENGTH(termBySID_oid),
+ HANDLER_CAN_RWRITE
+ ));
+ netsnmp_register_scalar(
+ netsnmp_create_handler_registration("termByIfName", handle_termByIfName,
+ termByIfName_oid, OID_LENGTH(termByIfName_oid),
+ HANDLER_CAN_RWRITE
+ ));
+ netsnmp_register_scalar(
+ netsnmp_create_handler_registration("termByIP", handle_termByIP,
+ termByIP_oid, OID_LENGTH(termByIP_oid),
+ HANDLER_CAN_RWRITE
+ ));
+ netsnmp_register_scalar(
+ netsnmp_create_handler_registration("termByUsername", handle_termByUsername,
+ termByUsername_oid, OID_LENGTH(termByUsername_oid),
+ HANDLER_CAN_RWRITE
+ ));
+}
+
+int
+handle_termBySID(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ int ret;
+ /* We are never called for a GETNEXT if it's registered as a
+ "instance", as it's "magically" handled for us. */
+
+ /* a instance handler also only hands us one request at a time, so
+ we don't need to loop over a list of requests; we'll only get one. */
+
+ switch(reqinfo->mode) {
+
+ case MODE_GET:
+ netsnmp_set_request_error(reqinfo, requests, SNMP_NOSUCHINSTANCE );
+ break;
+
+ /*
+ * SET REQUEST
+ *
+ * multiple states in the transaction. See:
+ * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
+ */
+ case MODE_SET_RESERVE1:
+ /* or you could use netsnmp_check_vb_type_and_size instead */
+ ret = netsnmp_check_vb_type_and_size(requests->requestvb, ASN_OCTET_STR, PPP_SESSIONID_LEN);
+ if ( ret != SNMP_ERR_NOERROR ) {
+ netsnmp_set_request_error(reqinfo, requests, ret );
+ }
+ break;
+
+ case MODE_SET_RESERVE2:
+ break;
+
+ case MODE_SET_FREE:
+ /* XXX: free resources allocated in RESERVE1 and/or
+ RESERVE2. Something failed somewhere, and the states
+ below won't be called. */
+ break;
+
+ case MODE_SET_ACTION:
+ terminate_by_sid((char *)requests->requestvb->val.string);
+ /* XXX: perform the value change here */
+ break;
+
+ case MODE_SET_COMMIT:
+ break;
+
+ case MODE_SET_UNDO:
+ break;
+
+ default:
+ /* we should never get here, so this is a really bad error */
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_termBySID\n", reqinfo->mode );
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
+}
+int
+handle_termByIfName(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ int ret;
+ /* We are never called for a GETNEXT if it's registered as a
+ "instance", as it's "magically" handled for us. */
+
+ /* a instance handler also only hands us one request at a time, so
+ we don't need to loop over a list of requests; we'll only get one. */
+
+ switch(reqinfo->mode) {
+
+ case MODE_GET:
+ netsnmp_set_request_error(reqinfo, requests, SNMP_NOSUCHINSTANCE );
+ break;
+
+ /*
+ * SET REQUEST
+ *
+ * multiple states in the transaction. See:
+ * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
+ */
+ case MODE_SET_RESERVE1:
+ /* or you could use netsnmp_check_vb_type_and_size instead */
+ ret = netsnmp_check_vb_type(requests->requestvb, ASN_OCTET_STR);
+ if ( ret != SNMP_ERR_NOERROR ) {
+ netsnmp_set_request_error(reqinfo, requests, ret );
+ }
+ break;
+
+ case MODE_SET_RESERVE2:
+ /* XXX malloc "undo" storage buffer */
+ break;
+
+ case MODE_SET_FREE:
+ /* XXX: free resources allocated in RESERVE1 and/or
+ RESERVE2. Something failed somewhere, and the states
+ below won't be called. */
+ break;
+
+ case MODE_SET_ACTION:
+ terminate_by_ifname((char *)requests->requestvb->val.string, requests->requestvb->val_len);
+ /* XXX: perform the value change here */
+ break;
+
+ case MODE_SET_COMMIT:
+ break;
+
+ case MODE_SET_UNDO:
+ break;
+
+ default:
+ /* we should never get here, so this is a really bad error */
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_termByIfName\n", reqinfo->mode );
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
+}
+int
+handle_termByIP(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ int ret;
+ /* We are never called for a GETNEXT if it's registered as a
+ "instance", as it's "magically" handled for us. */
+
+ /* a instance handler also only hands us one request at a time, so
+ we don't need to loop over a list of requests; we'll only get one. */
+
+ switch(reqinfo->mode) {
+
+ case MODE_GET:
+ netsnmp_set_request_error(reqinfo, requests, SNMP_NOSUCHINSTANCE );
+ break;
+
+ /*
+ * SET REQUEST
+ *
+ * multiple states in the transaction. See:
+ * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
+ */
+ case MODE_SET_RESERVE1:
+ /* or you could use netsnmp_check_vb_type_and_size instead */
+ ret = netsnmp_check_vb_type(requests->requestvb, ASN_OCTET_STR);
+ if ( ret != SNMP_ERR_NOERROR ) {
+ netsnmp_set_request_error(reqinfo, requests, ret );
+ }
+ break;
+
+ case MODE_SET_RESERVE2:
+ /* XXX malloc "undo" storage buffer */
+ break;
+
+ case MODE_SET_FREE:
+ /* XXX: free resources allocated in RESERVE1 and/or
+ RESERVE2. Something failed somewhere, and the states
+ below won't be called. */
+ break;
+
+ case MODE_SET_ACTION:
+ terminate_by_ip((char *)requests->requestvb->val.string, requests->requestvb->val_len);
+ /* XXX: perform the value change here */
+ break;
+
+ case MODE_SET_COMMIT:
+ /* XXX: delete temporary storage */
+ break;
+
+ case MODE_SET_UNDO:
+ /* XXX: UNDO and return to previous value for the object */
+ break;
+
+ default:
+ /* we should never get here, so this is a really bad error */
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_termByIP\n", reqinfo->mode );
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
+}
+int
+handle_termByUsername(netsnmp_mib_handler *handler,
+ netsnmp_handler_registration *reginfo,
+ netsnmp_agent_request_info *reqinfo,
+ netsnmp_request_info *requests)
+{
+ int ret;
+ /* We are never called for a GETNEXT if it's registered as a
+ "instance", as it's "magically" handled for us. */
+
+ /* a instance handler also only hands us one request at a time, so
+ we don't need to loop over a list of requests; we'll only get one. */
+
+ switch(reqinfo->mode) {
+
+ case MODE_GET:
+ netsnmp_set_request_error(reqinfo, requests, SNMP_NOSUCHINSTANCE );
+ break;
+
+ /*
+ * SET REQUEST
+ *
+ * multiple states in the transaction. See:
+ * http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
+ */
+ case MODE_SET_RESERVE1:
+ /* or you could use netsnmp_check_vb_type_and_size instead */
+ ret = netsnmp_check_vb_type(requests->requestvb, ASN_OCTET_STR);
+ if ( ret != SNMP_ERR_NOERROR ) {
+ netsnmp_set_request_error(reqinfo, requests, ret );
+ }
+ break;
+
+ case MODE_SET_RESERVE2:
+ /* XXX malloc "undo" storage buffer */
+ break;
+
+ case MODE_SET_FREE:
+ /* XXX: free resources allocated in RESERVE1 and/or
+ RESERVE2. Something failed somewhere, and the states
+ below won't be called. */
+ break;
+
+ case MODE_SET_ACTION:
+ terminate_by_username((char *)requests->requestvb->val.string, requests->requestvb->val_len);
+ /* XXX: perform the value change here */
+ break;
+
+ case MODE_SET_COMMIT:
+ /* XXX: delete temporary storage */
+ break;
+
+ case MODE_SET_UNDO:
+ /* XXX: UNDO and return to previous value for the object */
+ break;
+
+ default:
+ /* we should never get here, so this is a really bad error */
+ snmp_log(LOG_ERR, "unknown mode (%d) in handle_termByUsername\n", reqinfo->mode );
+ return SNMP_ERR_GENERR;
+ }
+
+ return SNMP_ERR_NOERROR;
+}