diff --git a/src/Linux/hsflowconfig.c b/src/Linux/hsflowconfig.c index ea4d24d7..0387b641 100644 --- a/src/Linux/hsflowconfig.c +++ b/src/Linux/hsflowconfig.c @@ -598,7 +598,12 @@ extern "C" { UTStrBuf_printf(buf, "polling.%s=%u\n", appSettings->application, appSettings->polling_secs); } } - // agentIP can ovrride the config file here if set, but otherwise print the address we selected + // agentIP can override the config file here if set, but otherwise print the address we selected + // TODO: should avoid writing in previously set agentIP or agentDevice. Should only write that in + // if it was an override. In installSFlowSettings we have to be careful to detect that a new config + // was submitted but still print the agentIP and agent lines to /etc/hsflowd.auto. Before doing that + // however, we have to check for any change to agentIP, agent or agentCIDR, and if so run the + // selectAgentAddress election again to pick an agentIP. SFLAddress agIP = settings->agentIP.type ? settings->agentIP : sp->agentIP; char ipbuf[51]; UTStrBuf_printf(buf, "agentIP=%s\n", SFLAddress_print(&agIP, ipbuf, 50)); diff --git a/src/Linux/hsflowd.c b/src/Linux/hsflowd.c index 42d5484c..a3bf78dc 100644 --- a/src/Linux/hsflowd.c +++ b/src/Linux/hsflowd.c @@ -477,6 +477,10 @@ extern "C" { if(sp->sFlowSettings_str) fputs(sp->sFlowSettings_str, sp->f_out); // repeat the revision number. The reader knows that if the revison number // has not changed under his feet then he has a consistent config. + + // TODO: if settings did not override agentIP, print here + // TODO: if settings did not override agent (device), print here + fprintf(sp->f_out, "rev_end=%u\n", sp->revisionNo); fflush(sp->f_out); // chop off anything that may be lingering from before diff --git a/src/Linux/mod_sonic.c b/src/Linux/mod_sonic.c index c814ec76..c6a12d66 100644 --- a/src/Linux/mod_sonic.c +++ b/src/Linux/mod_sonic.c @@ -49,6 +49,7 @@ extern "C" { #define HSP_SONIC_FIELD_COLLECTOR_IP "collector_ip" #define HSP_SONIC_FIELD_COLLECTOR_PORT "collector_port" +#define HSP_SONIC_DEFAULT_POLLING_INTERVAL 20 #define HSP_SONIC_MIN_POLLING_INTERVAL 5 #define HSP_MAX_EXEC_LINELEN 1024 @@ -886,6 +887,10 @@ extern "C" { myDebug(1, "sonic getSflowGlobalCB: reply=%s", db_replyStr(reply, db->replyBuf, YES)); if(reply == NULL) return; + // first extract the latest settings + bool sflow_enable = NO; + char *sflow_agent = NULL; + uint32_t sflow_polling = HSP_SONIC_DEFAULT_POLLING_INTERVAL;; if(reply->type == REDIS_REPLY_ARRAY && reply->elements > 0 && ISEVEN(reply->elements)) { @@ -896,16 +901,33 @@ extern "C" { myDebug(1, "sonic sflow: %s=%s", f_name->str, db_replyStr(f_val, db->replyBuf, YES)); if(my_strequal(f_name->str, HSP_SONIC_FIELD_SFLOW_ADMIN_STATE)) - mdata->sflow_enable = my_strequal(f_val->str, "enable"); + sflow_enable = my_strequal(f_val->str, "enable"); if(my_strequal(f_name->str, HSP_SONIC_FIELD_SFLOW_AGENT)) - mdata->sflow_agent = my_strdup(f_val->str); + sflow_agent = f_val->str; if(my_strequal(f_name->str, HSP_SONIC_FIELD_SFLOW_POLLING)) - mdata->sflow_polling = db_getU32(f_val); + sflow_polling = db_getU32(f_val); } } } + // now see if there are any changes. + if(sflow_enable != mdata->sflow_enable) { + myDebug(1, "sonic sflow_enable %u -> %u", mdata->sflow_enable, sflow_enable); + mdata->sflow_enable = sflow_enable; + } + // The sflow_agent entry will disappear if it is deleted from the config, so sflow_agent + // may still be NULL here: + if(!my_strequal(sflow_agent, mdata->sflow_agent)) { + myDebug(1, "sonic sflow_agent %s -> %s", + mdata->sflow_agent ?: "", + sflow_agent ?: ""); + setStr(&mdata->sflow_agent, sflow_agent); + } + if(sflow_polling != mdata->sflow_polling) { + myDebug(1, "sonic sflow_polling %u -> %u", mdata->sflow_polling, sflow_polling); + mdata->sflow_polling = sflow_polling; + } // if this is normal startup then don't syncConfig yet (that happens when the collectors // have been discovered for the first time). However if it was a dynamic reconfig then go // ahead and syncConfig right away...