/* * ***** BEGIN LICENSE BLOCK ***** Copyright (C) 2022 Olof Hagsand and Kristofer Hallin This file is part of CLIXON. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Alternatively, the contents of this file may be used under the terms of the GNU General Public License Version 3 or later (the "GPL"), in which case the provisions of the GPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of the GPL, and not to allow others to use your version of this file under the terms of Apache License version 2, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the Apache License version 2 or the GPL. ***** END LICENSE BLOCK ***** */ #ifdef HAVE_CONFIG_H #include "clixon_config.h" /* generated by config & autoconf */ #endif #include #include #include #include #include #include #include /* net-snmp */ #include #include #include /* cligen */ #include /* clicon */ #include #include "snmp_mib_yang.h" /* Command line options to be passed to getopt(3) */ #define SNMP_OPTS "hD:f:l:o:" /*! Signal terminates process * Just set exit flag for proper exit in event loop */ static void clixon_snmp_sig_term(int arg) { clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d", __PROGRAM__, __FUNCTION__, getpid(), arg); /* This should ensure no more accepts or incoming packets are processed because next time eventloop * is entered, it will terminate. * However there may be a case of sockets closing rather abruptly for clients */ clixon_exit_set(1); } /*! Callback for single socket * This is a workaround for netsnmps API usiing fdset:s, instead an fdset is created before calling * the snmp api * @param[in] s Read socket * @param[in] arg Clixon handle */ static int clixon_snmp_input_cb(int s, void *arg) { int retval = -1; fd_set readfds; // clicon_handle h = (clicon_handle)arg; clicon_debug(1, "%s", __FUNCTION__); FD_ZERO(&readfds); FD_SET(s, &readfds); snmp_read(&readfds); retval = 0; // done: return retval; } /*! Get which sockets are used from SNMP API, the register single sockets into clixon event system * * This is a workaround for netsnmps API usiing fdset:s, instead an fdset is created before calling * the snmp api * if you use select(), see snmp_select_info() in snmp_api(3) * snmp_select_info(int *numfds, fd_set *fdset, struct timeval *timeout, int *block) * @see clixon_snmp_input_cb */ static int clixon_snmp_fdset_register(clicon_handle h) { int retval = -1; int numfds = 0; fd_set readfds; struct timeval timeout = { LONG_MAX, 0 }; int block = 0; int nr; int i; FD_ZERO(&readfds); if ((nr = snmp_sess_select_info(NULL, &numfds, &readfds, &timeout, &block)) < 0){ clicon_err(OE_SNMP, errno, "snmp_select_error"); goto done; } for (i=0; i\tDebug level\n" "\t-f \tConfiguration file (mandatory)\n" "\t-l (e|o|s|f) Log on std(e)rr, std(o)ut, (s)yslog(default), (f)ile\n" "\t-o \"