/* SMUX message read function. */ int smux_read (struct thread *t) { int sock; int len; u_char buf[SMUXMAXPKTSIZE]; int ret; /* Clear thread. */ sock = THREAD_FD (t); smux_read_thread = NULL; if (debug_smux) zlog_debug ("SMUX read start"); /* Read message from SMUX socket. */ len = recv (sock, buf, SMUXMAXPKTSIZE, 0); if (len < 0) { zlog_warn ("Can't read all SMUX packet: %s", safe_strerror (errno)); close (sock); smux_sock = -1; smux_event (SMUX_CONNECT, 0); return -1; } if (len == 0) { zlog_warn ("SMUX connection closed: %d", sock); close (sock); smux_sock = -1; smux_event (SMUX_CONNECT, 0); return -1; } if (debug_smux) zlog_debug ("SMUX read len: %d", len); /* Parse the message. */ ret = smux_parse (buf, len); if (ret < 0) { close (sock); smux_sock = -1; smux_event (SMUX_CONNECT, 0); return -1; } /* Regiser read thread. */ smux_event (SMUX_READ, sock); return 0; }
/* Try to connect to SNMP agent. */ int smux_connect (struct thread *t) { int ret; if (debug_smux) zlog_debug ("SMUX connect try %d", fail + 1); /* Clear thread poner of myself. */ smux_connect_thread = NULL; /* Make socket. Try to connect. */ smux_sock = smux_socket (); if (smux_sock < 0) { if (++fail < SMUX_MAX_FAILURE) smux_event (SMUX_CONNECT, 0); return 0; } /* Send OPEN PDU. */ ret = smux_open (smux_sock); if (ret < 0) { zlog_warn ("SMUX open message send failed: %s", safe_strerror (errno)); close (smux_sock); smux_sock = -1; if (++fail < SMUX_MAX_FAILURE) smux_event (SMUX_CONNECT, 0); return -1; } /* Send any outstanding register PDUs. */ ret = smux_register (smux_sock); if (ret < 0) { zlog_warn ("SMUX register message send failed: %s", safe_strerror (errno)); close (smux_sock); smux_sock = -1; if (++fail < SMUX_MAX_FAILURE) smux_event (SMUX_CONNECT, 0); return -1; } /* Everything goes fine. */ smux_event (SMUX_READ, smux_sock); return 0; }
void snmp_stop (struct lib_globals *zg) { /* closes the connection. */ #ifdef HAVE_AGENTX agentx_event (zg, AGENTX_STOP, 0); #else smux_event (zg, SMUX_STOP, 0); #endif }
void snmp_start (struct lib_globals *zg) { /* Schedule first connection. */ #ifdef HAVE_AGENTX agentx_event (zg, AGENTX_SCHEDULE, 0); #else smux_event (zg, SMUX_SCHEDULE, 0); #endif }
void snmp_restart (struct lib_globals *zg) { /* restarts the connection. */ #ifdef HAVE_AGENTX if (zg->snmp.fail >= AGENTX_MAX_FAILURE) zg->snmp.fail = 0; agentx_event (zg, AGENTX_RESTART, 0); #else if (zg->snmp.fail >= SMUX_MAX_FAILURE) zg->snmp.fail = 0; smux_event (zg, SMUX_RESTART, 0); #endif }