]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/agentx.c
Merge pull request #3356 from opensourcerouting/router-id-loopbacks
[mirror_frr.git] / lib / agentx.c
index c36e642c89e919976d0d0cd6754525bd2687ac33..40cac722ae8dba1a4a47db2cecea6661ff73680b 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with GNU Zebra; see the file COPYING.  If not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <zebra.h>
@@ -32,6 +31,7 @@
 #include "memory.h"
 #include "linklist.h"
 #include "version.h"
+#include "lib_errors.h"
 
 static int agentx_enabled = 0;
 
@@ -82,9 +82,11 @@ static void agentx_events_update(void)
        FD_ZERO(&fds);
        snmp_select_info(&maxfd, &fds, &timeout, &block);
 
-       if (!block)
-               timeout_thr = thread_add_timer_tv(agentx_tm, agentx_timeout,
-                                                 NULL, &timeout);
+       if (!block) {
+               timeout_thr = NULL;
+               thread_add_timer_tv(agentx_tm, agentx_timeout, NULL, &timeout,
+                                   &timeout_thr);
+       }
 
        ln = listhead(events);
        thr = ln ? listgetdata(ln) : NULL;
@@ -108,7 +110,8 @@ static void agentx_events_update(void)
                /* need listener, but haven't hit one where it would be */
                else if (FD_ISSET(fd, &fds)) {
                        struct listnode *newln;
-                       thr = thread_add_read(agentx_tm, agentx_read, NULL, fd);
+                       thr = NULL;
+                       thread_add_read(agentx_tm, agentx_read, NULL, fd, &thr);
                        newln = listnode_add_before(events, ln, thr);
                        thr->arg = newln;
                }
@@ -125,9 +128,9 @@ static void agentx_events_update(void)
 }
 
 /* AgentX node. */
-static struct cmd_node agentx_node = {
-       SMUX_NODE, "" /* AgentX has no interface. */
-};
+static struct cmd_node agentx_node = {SMUX_NODE,
+                                     "", /* AgentX has no interface. */
+                                     1};
 
 /* Logging NetSNMP messages */
 static int agentx_log_callback(int major, int minor, void *serverarg,
@@ -139,19 +142,20 @@ static int agentx_log_callback(int major, int minor, void *serverarg,
                msg[strlen(msg) - 1] = '\0';
        switch (slm->priority) {
        case LOG_EMERG:
-               zlog_err("snmp[emerg]: %s", msg ? msg : slm->msg);
+               flog_err(EC_LIB_SNMP, "snmp[emerg]: %s", msg ? msg : slm->msg);
                break;
        case LOG_ALERT:
-               zlog_err("snmp[alert]: %s", msg ? msg : slm->msg);
+               flog_err(EC_LIB_SNMP, "snmp[alert]: %s", msg ? msg : slm->msg);
                break;
        case LOG_CRIT:
-               zlog_err("snmp[crit]: %s", msg ? msg : slm->msg);
+               flog_err(EC_LIB_SNMP, "snmp[crit]: %s", msg ? msg : slm->msg);
                break;
        case LOG_ERR:
-               zlog_err("snmp[err]: %s", msg ? msg : slm->msg);
+               flog_err(EC_LIB_SNMP, "snmp[err]: %s", msg ? msg : slm->msg);
                break;
        case LOG_WARNING:
-               zlog_warn("snmp[warning]: %s", msg ? msg : slm->msg);
+               flog_warn(EC_LIB_SNMP, "snmp[warning]: %s",
+                         msg ? msg : slm->msg);
                break;
        case LOG_NOTICE:
                zlog_notice("snmp[notice]: %s", msg ? msg : slm->msg);
@@ -170,39 +174,35 @@ static int agentx_log_callback(int major, int minor, void *serverarg,
 static int config_write_agentx(struct vty *vty)
 {
        if (agentx_enabled)
-               vty_out(vty, "agentx%s", VTY_NEWLINE);
-       return 0;
+               vty_out(vty, "agentx\n");
+       return 1;
 }
 
 DEFUN (agentx_enable,
        agentx_enable_cmd,
        "agentx",
-       "SNMP AgentX protocol settings\n"
-       "SNMP AgentX settings\n")
+       "SNMP AgentX protocol settings\n")
 {
        if (!agentx_enabled) {
                init_snmp(FRR_SMUX_NAME);
                events = list_new();
                agentx_events_update();
                agentx_enabled = 1;
-               return CMD_SUCCESS;
        }
-       vty_out(vty, "SNMP AgentX already enabled%s", VTY_NEWLINE);
-       return CMD_WARNING;
+
+       return CMD_SUCCESS;
 }
 
 DEFUN (no_agentx,
        no_agentx_cmd,
        "no agentx",
        NO_STR
-       "SNMP AgentX protocol settings\n"
-       "SNMP AgentX settings\n")
+       "SNMP AgentX protocol settings\n")
 {
        if (!agentx_enabled)
                return CMD_SUCCESS;
-       vty_out(vty, "SNMP AgentX support cannot be disabled once enabled%s",
-               VTY_NEWLINE);
-       return CMD_WARNING;
+       vty_out(vty, "SNMP AgentX support cannot be disabled once enabled\n");
+       return CMD_WARNING_CONFIG_FAILED;
 }
 
 void smux_init(struct thread_master *tm)
@@ -231,7 +231,7 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename,
              size_t enamelen, const oid *name, size_t namelen,
              const oid *iname, size_t inamelen,
              const struct trap_object *trapobj, size_t trapobjlen,
-             u_char sptrap)
+             uint8_t sptrap)
 {
        oid objid_snmptrap[] = {1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0};
        size_t objid_snmptrap_len = sizeof objid_snmptrap / sizeof(oid);
@@ -249,7 +249,7 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename,
        notification_oid_len = enamelen + 1;
        snmp_varlist_add_variable(&notification_vars, objid_snmptrap,
                                  objid_snmptrap_len, ASN_OBJECT_ID,
-                                 (u_char *)notification_oid,
+                                 (uint8_t *)notification_oid,
                                  notification_oid_len * sizeof(oid));
 
        /* Provided bindings */
@@ -257,7 +257,7 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename,
                unsigned int j;
                oid oid[MAX_OID_LEN];
                size_t oid_len, onamelen;
-               u_char *val;
+               uint8_t *val;
                size_t val_len;
                WriteMethod *wm = NULL;
                struct variable cvp;