summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2012-02-28 21:47:48 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2012-02-28 21:50:09 (GMT)
commit83d7c2e986bb88601dd820e5da1ac4edb92991cd (patch) (side-by-side diff)
treed435024e7eb878721143d721639feacc99df34e7
parent7e8347dccc7c87bc92bec06478eafd84778ad378 (diff)
downloadslb-83d7c2e986bb88601dd820e5da1ac4edb92991cd.tar.gz
slb-83d7c2e986bb88601dd820e5da1ac4edb92991cd.tar.bz2
Bugfixes.
* src/slb.c (slb_daemon): Wake-up exactly at the interval boundary. * src/snmploop.c (sess_init,srv_open_session): New functions. (send_requests): Skip already computed servers. Reuse already open sessions. (recv_loop): Increment slb_loop_serial and set slb_loop_ts. (snmploop): Call sess_init.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/slb.c15
-rw-r--r--src/snmploop.c164
2 files changed, 90 insertions, 89 deletions
diff --git a/src/slb.c b/src/slb.c
index b8acb5c..b456626 100644
--- a/src/slb.c
+++ b/src/slb.c
@@ -277,21 +277,12 @@ slb_daemon()
action = ACT_WAKEUP;
while (action == ACT_NONE || action == ACT_WAKEUP) {
if (action == ACT_WAKEUP) {
- time_t delta, start = time(NULL);
-
+ time_t delta;
snmploop();
slb_fmtout();
-
- delta = time(NULL) - start;
- if (delta < wakeup_interval)
- delta = wakeup_interval - delta;
- else {
- delta = wakeup_interval *
- ((delta + wakeup_interval - 1) /
- wakeup_interval);
- }
+ delta = wakeup_interval - time(NULL) % wakeup_interval;
debug(SLB_DEBCAT_MAIN, 2,
- ("scheduled wake up after %lu seconds",
+ ("scheduled wake-up after %lu seconds",
(unsigned long) delta));
alarm(delta);
}
diff --git a/src/snmploop.c b/src/snmploop.c
index 10c378f..7c5f215 100644
--- a/src/snmploop.c
+++ b/src/snmploop.c
@@ -611,6 +611,82 @@ add_table_var(void *sym, void *data)
return 0;
}
+static void
+sess_init()
+{
+ struct slb_server *srv;
+
+ for (srv = srv_head; srv; srv = srv->next)
+ srv->flags &= ~(SLB_SRV_COMPUTED|SLB_SRV_DEBUG_OUTPUT);
+}
+
+static int
+srv_open_session(struct slb_server *srv)
+{
+ struct snmp_session sess;
+
+ snmp_sess_init(&sess);
+ sess.version = srv->snmpver;
+ sess.peername = srv->peer;
+ if (srv->community) {
+ sess.community = srv->community;
+ sess.community_len = strlen((char*)sess.community);
+ }
+ if (srv->timeout)
+ sess.timeout = srv->timeout * 1000000L;
+ if (srv->retries)
+ sess.retries = srv->retries;
+ if (sess.version == SNMP_VERSION_3) {
+ sess.securityAuthProto = srv->snmp_v3.auth.proto;
+ sess.securityAuthProtoLen = srv->snmp_v3.auth.proto_len;
+ memcpy(sess.securityAuthKey,
+ srv->snmp_v3.auth.key,
+ srv->snmp_v3.auth.key_len);
+ sess.securityAuthKeyLen = srv->snmp_v3.auth.key_len;
+
+ sess.securityPrivProto = srv->snmp_v3.priv.proto;
+ sess.securityPrivProtoLen = srv->snmp_v3.priv.proto_len;
+ memcpy(sess.securityPrivKey,
+ srv->snmp_v3.priv.key,
+ srv->snmp_v3.priv.key_len);
+ sess.securityPrivKeyLen = srv->snmp_v3.priv.key_len;
+ if (srv->snmp_v3.user) {
+ sess.securityName = srv->snmp_v3.user;
+ sess.securityNameLen = strlen(sess.securityName);
+ }
+ if (srv->snmp_v3.context_name) {
+ sess.contextName = srv->snmp_v3.context_name;
+ sess.contextNameLen =
+ strlen(srv->snmp_v3.context_name);
+ }
+ if (srv->snmp_v3.security_engine_id) {
+ sess.securityEngineID =
+ srv->snmp_v3.security_engine_id;
+ sess.securityEngineIDLen =
+ srv->snmp_v3.security_engine_id_len;
+ }
+ if (srv->snmp_v3.context_engine_id) {
+ sess.contextEngineID =
+ srv->snmp_v3.context_engine_id;
+ sess.contextEngineIDLen =
+ srv->snmp_v3.context_engine_id_len;
+ }
+ sess.securityLevel = srv->snmp_v3.security_level;
+ sess.engineBoots = srv->snmp_v3.engine_boots;
+ sess.engineTime = srv->snmp_v3.engine_time;
+ }
+ sess.callback_magic = srv;
+
+ if (!(srv->sess = snmp_open(&sess))) {
+ logmsg(LOG_ERR,
+ "server %s: snmp_open failed: %s",
+ srvid(srv),
+ snmp_api_errstring(snmp_errno));
+ return 1;
+ }
+ return 0;
+}
+
static size_t
send_requests()
{
@@ -619,78 +695,20 @@ send_requests()
debug(SLB_DEBCAT_SNMP, 1, ("sending requests"));
for (srv = srv_head; srv; srv = srv->next) {
- struct snmp_session sess;
struct snmp_pdu *req;
- if (srv->flags & SLB_SRV_DISABLED)
+ if (srv->flags & (SLB_SRV_DISABLED|SLB_SRV_COMPUTED))
continue;
-
+
debug(SLB_DEBCAT_SNMP, 2,
("server %s, host %s", srvid(srv), srv->peer));
- snmp_sess_init(&sess);
- sess.version = srv->snmpver;
- sess.peername = srv->peer;
- if (srv->community) {
- sess.community = srv->community;
- sess.community_len = strlen((char*)sess.community);
- }
- if (srv->timeout)
- sess.timeout = srv->timeout * 1000000L;
- if (srv->retries)
- sess.retries = srv->retries;
- if (sess.version == SNMP_VERSION_3) {
- sess.securityAuthProto =
- srv->snmp_v3.auth.proto;
- sess.securityAuthProtoLen =
- srv->snmp_v3.auth.proto_len;
- memcpy(sess.securityAuthKey,
- srv->snmp_v3.auth.key,
- srv->snmp_v3.auth.key_len);
- sess.securityAuthKeyLen =
- srv->snmp_v3.auth.key_len;
-
- sess.securityPrivProto =
- srv->snmp_v3.priv.proto;
- sess.securityPrivProtoLen =
- srv->snmp_v3.priv.proto_len;
- memcpy(sess.securityPrivKey,
- srv->snmp_v3.priv.key,
- srv->snmp_v3.priv.key_len);
- sess.securityPrivKeyLen =
- srv->snmp_v3.priv.key_len;
- if (srv->snmp_v3.user) {
- sess.securityName = srv->snmp_v3.user;
- sess.securityNameLen =
- strlen(sess.securityName);
- }
- if (srv->snmp_v3.context_name) {
- sess.contextName =
- srv->snmp_v3.context_name;
- sess.contextNameLen =
- strlen(srv->snmp_v3.context_name);
- }
- if (srv->snmp_v3.security_engine_id) {
- sess.securityEngineID =
- srv->snmp_v3.security_engine_id;
- sess.securityEngineIDLen =
- srv->snmp_v3.security_engine_id_len;
- }
- if (srv->snmp_v3.context_engine_id) {
- sess.contextEngineID =
- srv->snmp_v3.context_engine_id;
- sess.contextEngineIDLen =
- srv->snmp_v3.context_engine_id_len;
- }
- sess.securityLevel = srv->snmp_v3.security_level;
- sess.engineBoots = srv->snmp_v3.engine_boots;
- sess.engineTime = srv->snmp_v3.engine_time;
- }
- sess.callback_magic = srv;
-
+ if (!srv->sess && srv_open_session(srv))
+ continue;
+
if ((srv->flags & SLB_SRV_TAB_REFERENCED) &&
!(srv->flags & SLB_SRV_TAB_RESOLVED)) {
- sess.callback = asynch_response_next;
+ srv->sess->callback = asynch_response_next;
refcnt++;
req = snmp_pdu_create(SNMP_MSG_GETNEXT);
@@ -698,7 +716,7 @@ send_requests()
req);
srv->flags |= SLB_SRV_TAB_RESOLVED;
} else {
- sess.callback = asynch_response;
+ srv->sess->callback = asynch_response;
varinst_unset(srv->varinst);
req = snmp_pdu_create(SNMP_MSG_GET);
@@ -709,16 +727,7 @@ send_requests()
add_snmp_assertion,
req);
}
- srv->flags &= ~(SLB_SRV_COMPUTED|SLB_SRV_DEBUG_OUTPUT);
- if (!(srv->sess = snmp_open(&sess))) {
- logmsg(LOG_ERR,
- "server %s: snmp_open failed: %s",
- srvid(srv),
- snmp_api_errstring(snmp_errno));
- continue;
- }
-
if (snmp_send(srv->sess, req)) {
active_count++;
srv->pdu = req;
@@ -736,6 +745,8 @@ send_requests()
static void
recv_loop()
{
+ slb_loop_serial++;
+ slb_loop_ts = time(NULL);
debug(SLB_DEBCAT_SNMP, 1, ("waiting for replies"));
while (active_count) {
int fds = 0, block = 1;
@@ -745,7 +756,7 @@ recv_loop()
FD_ZERO(&fdset);
snmp_select_info(&fds, &fdset, &timeout, &block);
fds = select(fds, &fdset, NULL, NULL, block ? NULL : &timeout);
- if (fds)
+ if (fds > 0)
snmp_read(&fdset);
else
snmp_timeout();
@@ -811,14 +822,13 @@ void
snmploop()
{
active_count = 0;
- slb_loop_serial++;
+ sess_init();
if (send_requests()) {
/* Process tables */
debug(SLB_DEBCAT_SNMP, 2, ("getting subtrees"));
recv_loop();
send_requests();
}
- slb_loop_ts = time(NULL);
recv_loop();
sess_cleanup();
sort();

Return to:

Send suggestions and report system problems to the System administrator.