Commit 8f210a93 authored by Damien Lucas's avatar Damien Lucas

. First part of a new way to logg messages

. VS_log_debug, Vs_log_info, work still but should not be used any more
. config/ db/ and snmp/ are now clear.

. The new debug function is
 ERR_CODE VS_log(LOG_LEVELS level, LOG_LODULES module, char* msg...);
 where level can be LOGDEBUG, LOGINFO, LOGWARNING, LOGERROR or LOGFATAL
       module can be CFG, DB, SERVER or SNMP
 last arguments work jsut like a printf.
parent 03991eaa
......@@ -82,23 +82,23 @@ nchannels{BL}{INT} {
if (cfg->nchannels)
{
VS_log_error("CFG: parse error in %s on line %u : nchannels has "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : nchannels has "\
"already been defined\n",filename,line_num);
return VS_R_PARSE;
}
sscanf(CFG_yytext+sizeof("nchannels")/sizeof(char)-1," %lu",&ul1);
if (!ul1)
{
VS_log_error("CFG: parse error in %s on line %u : nchannels can't "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : nchannels can't "\
"be 0\n",filename,line_num);
return VS_R_PARSE;
}
cfg->nchannels=(VS_CHANNEL)ul1;
VS_log_info("CFG: number of channels set to : %lu\n",ul1);
VS_log(LOGINFO,CFG,"Number of channels set to : %lu\n",ul1);
cfg->chan_map=malloc(ul1*sizeof(struct CFG_CHANNEL));
if (cfg->chan_map==NULL)
{
VS_log_error("CFG: unable to allocate memory to create the channels "\
VS_log(LOGERROR,CFG,"Unable to allocate memory to create the channels "\
" table\n");
return VS_R_MEMORY;
}
......@@ -118,7 +118,7 @@ vlanbridge{BL}{IP} {
if (cfg->vlanbridge[0])
{
VS_log_error("CFG: parse error in %s on line %u : duplicated "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : duplicated "\
"vlanbridge address defition\n",filename,line_num);
return VS_R_PARSE;
}
......@@ -133,7 +133,7 @@ vlanbridge_login{BL}{NONBLANK}+ {
if (cfg->vlanbridge_login!=NULL)
{
VS_log_error("CFG: parse error in %s on line %u : duplicated "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : duplicated "\
"vlanbridge login\n",filename,line_num);
return VS_R_PARSE;
}
......@@ -142,7 +142,7 @@ vlanbridge_login{BL}{NONBLANK}+ {
cfg->vlanbridge_login=malloc((CFG_yyleng-ui1+1)*sizeof(char));
if (cfg->vlanbridge_login==NULL)
{
VS_log_error("CFG: unable to allocate memory to store vlanbridge "\
VS_log(LOGERROR,CFG,"Unable to allocate memory to store vlanbridge "\
"login\n");
return VS_R_MEMORY;
}
......@@ -155,7 +155,7 @@ vlanbridge_password{BL}{NONBLANK}+ {
if (cfg->vlanbridge_password!=NULL)
{
VS_log_error("CFG: parse error in %s on line %u : duplicated "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : duplicated "\
"vlanbridge password\n",filename,line_num);
return VS_R_PARSE;
}
......@@ -164,7 +164,7 @@ vlanbridge_password{BL}{NONBLANK}+ {
cfg->vlanbridge_password=malloc((CFG_yyleng-ui1+1)*sizeof(char));
if (cfg->vlanbridge_password==NULL)
{
VS_log_error("CFG: unable to allocate memory to store VLB "\
VS_log(LOGERROR,CFG,"Unable to allocate memory to store VLB "\
"password\n");
return VS_R_MEMORY;
}
......@@ -199,33 +199,33 @@ channel{BL}{INT}{BL}vlan{BL}{INT}{BL}protection{BL}{INT} {
if ((VS_CHANNEL)ul1>=cfg->nchannels)
{
VS_log_error("CFG: parse error in %s on line %u : invalid channel "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : invalid channel "\
"number\n",filename,line_num);
return VS_R_PARSE;
}
if (cfg->chan_map[ul1].protection!=VS_PL_UNSPECIFIED)
{
VS_log_error("CFG: parse error in %s on line %u : channel %lu has"\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : channel %lu has"\
" already been defined\n",filename,line_num,ul1);
return VS_R_PARSE;
}
if ((VS_PROTECTION_LEVEL)ui1>=VS_PL_NUMBER)
{
VS_log_error("CFG: parse error in %s on line %u : protection levels "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : protection levels "\
"range from 0 to %lu\n",filename,line_num,\
(unsigned long)VS_PL_NUMBER-1);
return VS_R_PARSE;
}
if (!raw_data_allowed && CFG_yyleng)
{
VS_log_error("CFG: parse error in %s on line %u : expecting "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : expecting "\
"integer\n",filename,line_num);
return VS_R_PARSE;
}
cfg->chan_map[ul1].raw_data=malloc((CFG_yyleng+1)*sizeof(char));
if (cfg->chan_map[ul1].raw_data==NULL)
{
VS_log_error("CFG: unable to allocate memory to store raw data for "\
VS_log(LOGERROR,CFG,"Unable to allocate memory to store raw data for "\
"channel %lu\n",ul1);
return VS_R_MEMORY;
}
......@@ -237,7 +237,7 @@ channel{BL}{INT}{BL}vlan{BL}{INT}{BL}protection{BL}{INT} {
line_num++;
BEGIN(INITIAL);
eof_expected=1;
VS_log_info("CFG: successfuly defined channel %lu on vlan "\
VS_log(LOGINFO,CFG,"Successfuly defined channel %lu on vlan "\
"%lu protection %u %s",ul1,ul2,ui1,CFG_yytext);
}
......@@ -250,7 +250,7 @@ switch{BL}type{BL}{NONBLANK}+ {
(CFG_yyleng-i+1)*sizeof(char));
if (*st==NULL)
{
VS_log_error("CFG: unable to allocate memory to create a switch "\
VS_log(LOGERROR,CFG,"Unable to allocate memory to create a switch "\
"type\n");
return VS_R_MEMORY;
}
......@@ -270,7 +270,7 @@ switch{BL}type{BL}{NONBLANK}+ {
if ((*st)->nports)
{
VS_log_error("CFG: parse error in %s on line %u : nports has "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : nports has "\
"already been defined\n",filename,line_num);
return VS_R_PARSE;
}
......@@ -281,7 +281,7 @@ switch{BL}type{BL}{NONBLANK}+ {
(*st)->ports--;
if ((((*st)->ports)+1)==NULL)
{
VS_log_error("CFG: unable to allocate memory to store a switch "\
VS_log(LOGERROR,CFG,"Unable to allocate memory to store a switch "\
"type's ports table\n");
return VS_R_MEMORY;
}
......@@ -316,7 +316,7 @@ switch{BL}type{BL}{NONBLANK}+ {
}
else
{
VS_log_error("CFG: parse error in %s on line %u : unknown switch "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : unknown switch "\
"type\n",filename,line_num);
return VS_R_PARSE;
}
......@@ -329,7 +329,7 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+sizeof("default")/sizeof(char)-1," %u",&ui1);
if (ui1>=VS_PL_NUMBER)
{
VS_log_error("CFG: parse error in %s on line %u : protection levels "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : protection levels "\
"range from 0 to %lu\n",filename,line_num,\
(unsigned long)VS_PL_NUMBER-1);
return VS_R_PARSE;
......@@ -342,7 +342,7 @@ switch{BL}type{BL}{NONBLANK}+ {
i=1;
}
if (!i)
VS_log_error("CFG: warning, in %s on line %u : useless 'default' "\
VS_log(LOGWARNING,CFG,"In %s on line %u : useless 'default' "\
"statement in switch type definition, going on "\
"however\n",filename,line_num);
......@@ -354,13 +354,13 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+sizeof("port")/sizeof(char)-1," %lu %u",&ul1,&ui1);
if (!ul1 || (VS_PORT)ul1>(*st)->nports)
{
VS_log_error("CFG: parse error in %s on line %u : invalid port "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : invalid port "\
"number\n",filename,line_num);
return VS_R_PARSE;
}
if ((VS_PROTECTION_LEVEL)ui1>=VS_PL_NUMBER)
{
VS_log_error("CFG: parse error in %s on line %u : protection levels"\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : protection levels"\
"range from 0 to %u\n",filename,line_num,\
(unsigned int)VS_PL_NUMBER-1);
return (VS_R_PARSE);
......@@ -375,16 +375,16 @@ switch{BL}type{BL}{NONBLANK}+ {
for (ul1=1;(VS_PORT)ul1<=(*st)->nports;ul1++)
if ((*st)->ports[ul1].protection==VS_PL_UNSPECIFIED)
{
VS_log_error("CFG: parse error in %s on line %u : switch type %s "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : switch type %s "\
"has not been completely specified\n",filename,\
line_num,CFG_SWITCH_TYPE_NAME(**st));
return VS_R_PARSE;
}
VS_log_info("CFG: switch type %s defined with the %lu following ports "\
VS_log(LOGINFO,CFG,"Switch type %s defined with the %lu following ports "\
":\n",CFG_SWITCH_TYPE_NAME(**st),\
(unsigned long)(*st)->nports);
for (ul1=1;(VS_PORT)ul1<=(*st)->nports;ul1++)
VS_log_info("CFG: port %lu :\tprotection %lu\n",ul1,\
VS_log(LOGINFO,CFG," Port %lu :\tprotection %lu\n",ul1,\
(unsigned long)(*st)->ports[ul1].protection);
st=&((*st)->next);
BEGIN(INITIAL);
......@@ -401,7 +401,7 @@ switch{BL}type{BL}{NONBLANK}+ {
z=CFG_switch_type(cfg,CFG_yytext);
if (z==NULL)
{
VS_log_error("CFG: parse error in %s on line %u : unknown switch "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : unknown switch "\
"type\n",filename,line_num);
return VS_R_PARSE;
}
......@@ -409,7 +409,7 @@ switch{BL}type{BL}{NONBLANK}+ {
for(i=CFG_yyleng-1;CFG_yytext[i-1]!=' ' && CFG_yytext[i-1]!='\t';i--);
if (!VS_A2SID(CFG_yytext+i,ip))
{
VS_log_error("CFG: parse error in %s on line %u : invalid IP "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : invalid IP "\
"address\n",filename,line_num);
return VS_R_PARSE;
}
......@@ -418,7 +418,7 @@ switch{BL}type{BL}{NONBLANK}+ {
*s=malloc(sizeof(struct CFG_SWITCH));
if(*s==NULL)
{
VS_log_error("CFG: unable to allocate memory to create a new "\
VS_log(LOGERROR,CFG,"Unable to allocate memory to create a new "\
"switch in the database\n");
return VS_R_MEMORY;
}
......@@ -434,14 +434,14 @@ switch{BL}type{BL}{NONBLANK}+ {
/* UGLY, but we don't wanna waste memory nor cpu, do we ? */
if (ports==NULL)
{
VS_log_error("CFG: unable to allocate memory to create a new switch "\
VS_log(LOGERROR,CFG,"Unable to allocate memory to create a new switch "\
"in the database\n");
return VS_R_MEMORY;
}
ports--;
for (ul2=1;(VS_PORT)ul2<=z->nports;ul2++)
ports[ul2].protection=z->ports[ul2].protection;
VS_log_info("CFG: creating switch %s with type %s (%lu ports)...\n",\
VS_log(LOGINFO,CFG,"Creating switch %s with type %s (%lu ports)...\n",\
CFG_yytext+i,CFG_SWITCH_TYPE_NAME(*z),ul2-1);
BEGIN(in_switch);
eof_expected=0;
......@@ -457,7 +457,7 @@ switch{BL}type{BL}{NONBLANK}+ {
{
ports++;
free(ports);
VS_log_error("CFG: unable to allocate memory to store a switch's "\
VS_log(LOGERROR,CFG,"Unable to allocate memory to store a switch's "\
"community string\n");
return VS_R_MEMORY;
}
......@@ -471,7 +471,7 @@ switch{BL}type{BL}{NONBLANK}+ {
sscanf(CFG_yytext+sizeof("port")/sizeof(char)-1," %lu %u",&ul1,&ui1);
if ((VS_PORT)ul1>z->nports || !ul1)
{
VS_log_error("CFG: parse error in %s on line %u : invalid port "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : invalid port "\
"number\n",filename,line_num);
ports++;
free(ports);
......@@ -479,7 +479,7 @@ switch{BL}type{BL}{NONBLANK}+ {
}
if ((VS_PROTECTION_LEVEL)ui1>=VS_PL_NUMBER)
{
VS_log_error("CFG: parse error in %s on line %u : protection levels"\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : protection levels"\
"range from 0 to %u\n",filename,line_num,\
(unsigned int)ui1);
ports++;
......@@ -487,7 +487,7 @@ switch{BL}type{BL}{NONBLANK}+ {
return VS_R_PARSE;
}
ports[ul1].protection=(VS_PROTECTION_LEVEL)ui1;
VS_log_info("CFG: protection of port %lu set to %u\n",ul1,ui1);
VS_log(LOGINFO,CFG," Protection of port %lu set to %u\n",ul1,ui1);
}
......@@ -496,7 +496,7 @@ switch{BL}type{BL}{NONBLANK}+ {
if ((*s)->community==NULL)
{
VS_log_error("CFG: parse error in %s on line %u : community string "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : community string "\
"unspecified\n",filename,line_num);
ports++;
free(ports);
......@@ -517,7 +517,7 @@ switch{BL}type{BL}{NONBLANK}+ {
<*>.|\n {
VS_log_error("CFG: parse error in %s on line %u\n",filename,line_num);
VS_log(LOGERROR,CFG,"Parse error in %s on line %u\n",filename,line_num);
if (ports+1!=NULL)
free(ports+1);
return VS_R_PARSE;
......@@ -528,13 +528,13 @@ switch{BL}type{BL}{NONBLANK}+ {
if (!eof_expected)
{
VS_log_error("CFG: parse error in %s on line %u : unexpected end of "\
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : unexpected end of "\
"file\n",filename,line_num);
if (ports+1!=NULL)
free(ports+1);
return VS_R_PARSE;
}
VS_log_info("CFG: parsing of %s over, %u lines parsed\n",filename,\
VS_log(LOGINFO,CFG,"Parsing of %s over, %u lines parsed\n",filename,\
line_num);
return 0;
......@@ -589,22 +589,22 @@ ERR_CODE CFG_init(struct VS_config *cfg,int argc,char *argv[])
filepath=argv[i];
else
{
VS_log_error("CFG: expecting filename after option -f\n");
VS_log(LOGERROR,CFG,"Expecting filename after option -f\n");
return VS_R_PARSE;
}
}
break;
default:
VS_log_error("CFG: unknown option %s\n",argv[i]);
VS_log(LOGERROR,CFG,"Unknown option %s\n",argv[i]);
return VS_R_PARSE;
}
else
{
VS_log_error("CFG: unknown otpion %s\n",argv[i]);
VS_log(LOGERROR,CFG,"Unknown otpion %s\n",argv[i]);
return VS_R_PARSE;
}
VS_log_info("CFG: reading configuration file %s...\n",filepath);
VS_log(LOGINFO,CFG,"Reading configuration file %s...\n",filepath);
cfg->nchannels=0;
cfg->chan_map=NULL;
cfg->switch_types=NULL;
......@@ -617,15 +617,15 @@ ERR_CODE CFG_init(struct VS_config *cfg,int argc,char *argv[])
ret=CFG_yylex(cfg,CFG_FILE_PATH);
else
{
VS_log_error("CFG: unable to open %s\n",filepath);
VS_log(LOGERROR,CFG,"Unable to open %s\n",filepath);
return VS_R_FILE;
}
if (fclose(CFG_yyin))
VS_log_error("CFG: an error occured while closing %s, still going on",\
VS_log(LOGERROR,CFG,"An error occured while closing %s, still going on",\
filepath);
if (ret)
cleanup(cfg);
else
VS_log_info("CFG: setup successfuly terminated\n");
VS_log(LOGINFO,CFG,"Setup successfuly terminated\n");
return ret;
}
......@@ -292,13 +292,13 @@ static void *DB_machines_loop(struct DB_db *db)
{
struct DB_M_request *z;
VS_log_info("DB: machines loop started\n");
VS_log(LOGINFO,DB,"Machines loop started\n");
pthread_mutex_lock(&db->db_lock);
pthread_mutex_unlock(&db->db_lock);
pthread_mutex_destroy(&db->db_lock);
if (db->runlevel==DB_CANCEL)
{
VS_log_error("DB: machines loop canceled\n");
VS_log(LOGERROR,DB,"Machines loop canceled\n");
return NULL;
}
while (db->runlevel<DB_STOP)
......@@ -318,7 +318,7 @@ static void *DB_machines_loop(struct DB_db *db)
pthread_mutex_unlock(&db->machines_requests_lock);
}
}
VS_log_info("DB: machines loop stopped\n");
VS_log(LOGINFO,DB,"Machines loop stopped\n");
return NULL;
}
......@@ -328,7 +328,7 @@ static void *DB_switchs_loop(struct DB_db *db)
{
struct DB_S_request *z;
VS_log_info("DB: switchs loop started\n");
VS_log(LOGINFO,DB,"Switchs loop started\n");
while (db->runlevel<DB_STOP)
{
pthread_mutex_lock(&db->switchs_requests_lock);
......@@ -345,7 +345,7 @@ static void *DB_switchs_loop(struct DB_db *db)
pthread_mutex_unlock(&db->switchs_requests_lock);
}
}
VS_log_info("DB: switchs loop stopped\n");
VS_log(LOGINFO,DB,"Switchs loop stopped\n");
return NULL;
}
......@@ -359,7 +359,7 @@ static void DB_cancel(struct DB_db *db)
pthread_mutex_destroy(&db->switchs_requests_lock);
pthread_cond_destroy(&db->machines_requests_cond);
pthread_cond_destroy(&db->switchs_requests_cond);
VS_log_error("DB: unable to spawn the database engine\n");
VS_log(LOGERROR,DB,"Unable to spawn the database engine\n");
}
/*****************************************************************************/
......@@ -372,7 +372,7 @@ ERR_CODE DB_start(struct DB_db *db)
{
unsigned int i;
VS_log_info("DB: starting the database engine...\n");
VS_log(LOGINFO,DB,"Starting the database engine...\n");
db->runlevel=DB_INIT;
pthread_mutex_init(&db->machines_requests_lock,NULL);
pthread_mutex_init(&db->switchs_requests_lock,NULL);
......@@ -400,7 +400,7 @@ ERR_CODE DB_start(struct DB_db *db)
}
db->runlevel=DB_RUN;
pthread_mutex_unlock(&db->db_lock);
VS_log_info("DB: database engine successfuly started\n");
VS_log(LOGINFO,DB,"Database engine successfuly started\n");
return 0;
}
......@@ -471,7 +471,7 @@ ERR_CODE DB_switchs_insert(struct DB_db *db,VS_SwitchId ip,\
DB_machines_insert(db,y->machine,ip,(VS_PORT)j,0);
}
}
VS_log_info("DB: Switch %s successfuly created\n",VS_SID2A(ip));
VS_log(LOGINFO,DB,"Switch %s successfuly created\n",VS_SID2A(ip));
return req.ret_value;
}
else
......
#include "types.h"
#include "logger.h"
#define LOGBUFF_MAXSIZE 80
char *VS_log_errstr(ERR_CODE err)
{
......@@ -26,3 +27,66 @@ char *VS_log_errstr(ERR_CODE err)
};
return str[err];
}
ERR_CODE VS_log(LOG_LEVELS level, LOG_MODULES module, char* format, ...)
{
va_list ap;
char MsgBuff[LOGBUFF_MAXSIZE];
time_t MsgTime;
struct tm* ptmTime;
/* Record the time */
time(&MsgTime);
ptmTime=localtime(&MsgTime);
sprintf(MsgBuff, "%02i/%02i %02i:%02i:%02i ", ptmTime->tm_mday,
ptmTime->tm_mon+1, ptmTime->tm_hour,
ptmTime->tm_min, ptmTime->tm_sec);
/* Determinate in which module it happened */
switch (module)
{
case SNMP:
sprintf(MsgBuff+strlen(MsgBuff),"[SNMP : ");
break;
case SERVER:
sprintf(MsgBuff+strlen(MsgBuff),"[SERVER: ");
break;
case DB:
sprintf(MsgBuff+strlen(MsgBuff),"[DB : ");
break;
case CFG:
sprintf(MsgBuff+strlen(MsgBuff),"[CFG : ");
break;
}
/* Determinate the error level */
switch (level)
{
case LOGDEBUG:
sprintf(MsgBuff+strlen(MsgBuff),"debug ] ");
break;
case LOGINFO:
sprintf(MsgBuff+strlen(MsgBuff),"info ] ");
break;
case LOGWARNING:
sprintf(MsgBuff+strlen(MsgBuff),"Warning ] ");
break;
case LOGERROR:
sprintf(MsgBuff+strlen(MsgBuff),"ERROR ] ");
break;
case LOGFATAL:
sprintf(MsgBuff+strlen(MsgBuff),"FATAL ] ");
break;
}
/* XXX No error checking ! What length is the message ? */
va_start(ap,format);
vsnprintf(MsgBuff+strlen(MsgBuff), LOGBUFF_MAXSIZE, format,ap);
va_end(ap);
printf("%s",MsgBuff);
return 0;
}
......@@ -2,6 +2,8 @@
#define __LOGGER_H__
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#ifdef DEBUG
#define VS_log_debug(format,args...) printf(format, ##args)
......@@ -19,4 +21,6 @@
char *VS_log_errstr(ERR_CODE err);
ERR_CODE VS_log(LOG_LEVELS level, LOG_MODULES module, char* format, ...);
#endif
......@@ -31,7 +31,7 @@ static ERR_CODE SNMP_push_req(struct SNMP_snmp *snmp,struct SNMP_req *request)
}
else
{
VS_log_error("SNMP: unable to write to pipe\n");
VS_log(LOGERROR,SNMP,"Unable to write to pipe\n");
return VS_R_PIPE_WRITE;
}
}
......@@ -52,7 +52,7 @@ ERR_CODE SNMP_set_vlan(struct SNMP_snmp *snmp,struct SNMP_switch *zwitch,\
}
else
{
VS_log_error("SNMP: unable to allocate memory to push a request\n");
VS_log(LOGERROR,SNMP,"Unable to allocate memory to push a request\n");
return VS_R_MEMORY;
}
}
......@@ -70,7 +70,7 @@ ERR_CODE SNMP_fill_table(struct SNMP_snmp *snmp, struct SNMP_switch *zwitch)
}
else
{
VS_log_error("SNMP: unable to allocate memory to push a request\n");
VS_log(LOGERROR,SNMP,"Unable to allocate memory to push a request\n");
return VS_R_MEMORY;
}
}
......@@ -88,7 +88,7 @@ ERR_CODE SNMP_get_macs(struct SNMP_snmp *snmp,struct SNMP_switch *zwitch)
}
else
{
VS_log_error("SNMP: unable to allocate memory to push a request\n");
VS_log(LOGERROR,SNMP,"Unable to allocate memory to push a request\n");
return VS_R_MEMORY;
}
}
......@@ -106,7 +106,7 @@ ERR_CODE SNMP_get_vlans(struct SNMP_snmp *snmp,struct SNMP_switch *zwitch)
}
else
{
VS_log_error("SNMP: unable to allocate memory to push a request\n");
VS_log(LOGERROR,SNMP,"Unable to allocate memory to push a request\n");
return VS_R_MEMORY;
}
}
......@@ -122,7 +122,7 @@ static void *SNMP_loop(struct SNMP_snmp *snmp)
char foobar;
snmp->session_num=1;
VS_log_info("SNMP: snmp loop started\n");
VS_log(LOGINFO,SNMP,"Snmp loop started\n");
snmp->runlevel=SNMP_RUN;
while (snmp->runlevel<SNMP_STOP)
......@@ -149,7 +149,7 @@ static void *SNMP_loop(struct SNMP_snmp *snmp)
}
else
{
VS_log_error("SNMP: unable to read from pipe\n");
VS_log(LOGERROR,SNMP,"Unable to read from pipe\n");
}
}
else
......@@ -159,7 +159,7 @@ static void *SNMP_loop(struct SNMP_snmp *snmp)
}
else
{
VS_log_error("SNMP: error in select statement\n");
VS_log(LOGERROR,SNMP,"Error in select statement\n");
}
}
return NULL;
......@@ -170,18 +170,18 @@ static void SNMP_cancel(struct SNMP_snmp *snmp)
close(snmp->pipe[0]);
close(snmp->pipe[1]);
pthread_mutex_destroy(&snmp->fifo_mutex);
VS_log_error("SNMP: unable to spawn the snmp engine\n");
VS_log(LOGERROR,SNMP,"Unable to spawn the snmp engine\n");
}
ERR_CODE SNMP_start(struct SNMP_snmp *snmp)
{
VS_log_info("SNMP: starting the SNMP engine...\n");
VS_log(LOGINFO,SNMP,"Starting the SNMP engine...\n");
snmp->runlevel=SNMP_INIT;
init_snmp("snmp_app");
snmp->first=NULL;
if (pipe(snmp->pipe))
{
VS_log_error("SNMP: could not open pipe for snmp locking\n");
VS_log(LOGERROR,SNMP,"Could not open pipe for snmp locking\n");
return VS_R_PIPE;
}
snmp->numfds=snmp->pipe[0]+1;
......
......@@ -47,14 +47,14 @@ static ERR_CODE SNMP_SW_set_vlan(union SNMP_arg_union *arg,
Snmp_PORT(arg->set_vlan.port));
if(rc==-1)
{
VS_log_error("SNMP: Error in printing the variable\n");
VS_log(LOGERROR,SNMP,"Error in printing the variable\n");
return VS_R_SNMP;
}
/* Init a new snmp_session from the existing one */
if ((session=snmp_open(&(arg->set_vlan.zwitch->s2)))==NULL)
{
VS_log_error("SNMP: Unable to open a new snmp session\n");
VS_log(LOGERROR,SNMP,"Unable to open a new snmp session\n");
return VS_R_SNMP;
}
......@@ -62,7 +62,7 @@ static ERR_CODE SNMP_SW_set_vlan(union SNMP_arg_union *arg,
pdu=(struct snmp_pdu *)snmp_pdu_create(SNMP_MSG_SET);
if(pdu==NULL)
{
VS_log_error("SNMP: Unable to create the pdu\n");
VS_log(LOGERROR,SNMP,"Unable to create the pdu\n");
return VS_R_SNMP;
}
......@@ -72,14 +72,14 @@ static ERR_CODE SNMP_SW_set_vlan(union SNMP_arg_union *arg,
/* Read the OID and put it into snmp_string*/
if (!read_objid(snmp_string,name,&name_length))
{
VS_log_error("SNMP: unable to read objid\n");
VS_log(LOGERROR,SNMP,"Unable to read objid\n");
return VS_R_SNMP;
}
/* Complete the pdu */
if (snmp_add_var(pdu,name,name_length,'i',"4"))
{
VS_log_error("SNMP: unable to execute SNMPADDVAR\n");
VS_log(LOGERROR,SNMP,"Unable to execute SNMPADDVAR\n");
return VS_R_SNMP;
}
......@@ -90,7 +90,7 @@ static ERR_CODE SNMP_SW_set_vlan(union SNMP_arg_union *arg,
/* Send the request */
if(!snmp_send(session,pdu))
{
VS_log_error("SNMP: unable to send the pdu\n");
VS_log(LOGERROR,SNMP,"Unable to send the pdu\n");
snmp_free_pdu(pdu);
return VS_R_SNMP;
}
......@@ -124,14 +124,14 @@ static ERR_CODE SNMP_SW_get_macs(union SNMP_arg_union *arg,\
rc=sprintf(snmp_string,".1.3.6.1.4.1.43.10.22.2.1.3");
if(rc==-1)
{
VS_log_error("SNMP: Unable to print the variable\n");
VS_log(LOGERROR,SNMP,"Unable to print the variable\n");
return VS_R_SNMP;
}
/* Opening and Initializing the session s1 */
if ((session=snmp_open(&arg->get_macs.zwitch->s2))==NULL)
{
VS_log_error("SNMP: unable to open a new snmp session\n");
VS_log(LOGERROR,SNMP,"Unable to open a new snmp session\n");
return VS_R_SNMP;
}
......@@ -139,20 +139,20 @@ static ERR_CODE SNMP_SW_get_macs(union SNMP_arg_union *arg,\
if (!read_objid(snmp_string,name,&name_length))
{
VS_log_error("SNMP: unable to read objid\n");
VS_log(LOGERROR,SNMP,"Unable to read objid\n");
return VS_R_SNMP;
}
pdu=(struct snmp_pdu *)snmp_pdu_create(SNMP_MSG_GETNEXT);
if(pdu==NULL)
{
VS_log_error("SNMP: Unable to create the pdu\n");
VS_log(LOGERROR,SNMP,"Unable to create the pdu\n");
return VS_R_SNMP;
}
if (!snmp_add_null_var(pdu,name,name_length))
{
VS_log_error("SNMP: unable to execute SNMPADDNULLVAR\n");
VS_log(LOGERROR,SNMP,"Unable to execute SNMPADDNULLVAR\n");
return VS_R_SNMP;
}
......@@ -166,7 +166,7 @@ static ERR_CODE SNMP_SW_get_macs(union SNMP_arg_union *arg,\
if(arg->get_macs.zwitch->machines==NULL)
{
VS_log_error("SNMP: unable to allocate memory\n");
VS_log(LOGERROR,SNMP,"Unable to allocate memory\n");
snmp_free_pdu(pdu);
return VS_R_MEMORY;
}
......@@ -178,7 +178,7 @@ static ERR_CODE SNMP_SW_get_macs(union SNMP_arg_union *arg,\
/* Sending the request */
if (!snmp_send(session,pdu))
{
VS_log_error("SNMP: unable to send the pdu\n");
VS_log(LOGERROR,SNMP,"Unable to send the pdu\n");
snmp_free_pdu(pdu);
free(arg->get_macs.zwitch->machines);
return VS_R_SNMP;
......@@ -212,14 +212,14 @@ ERR_CODE SNMP_SW_fill_table(union SNMP_arg_union *arg,struct SNMP_snmp *snmp)
rc=sprintf(snmp_string,".1.3.6.1.2.1.2.2.1.2");
if(rc==-1)
{
VS_log_error("SNMP: Unable to print the variable\n");
VS_log(LOGERROR,SNMP,"Unable to print the variable\n");
return VS_R_SNMP;
}
/* Opening and Initializing the session s1 */
if ((session=snmp_open(&arg->fill_table.zwitch->s2))==NULL)
{
VS_log_error("SNMP: unable to open a new snmp session\n");
VS_log(LOGERROR,SNMP,"Unable to open a new snmp session\n");
return VS_R_SNMP;
}
......@@ -227,20 +227,20 @@ ERR_CODE SNMP_SW_fill_table(union SNMP_arg_union *arg,struct SNMP_snmp *snmp)
if (!read_objid(snmp_string,name,&name_length))
{
VS_log_error("SNMP: unable to read objid\n");
VS_log(LOGERROR,SNMP,"Unable to read objid\n");
return VS_R_SNMP;
}
pdu=(struct snmp_pdu *)snmp_pdu_create(SNMP_MSG_GETNEXT);
if(pdu==NULL)
{
VS_log_error("SNMP:Unable to create the pdu\n");
VS_log(LOGERROR,SNMP,"Unable to create the pdu\n");
return VS_R_SNMP;
}
if (!snmp_add_null_var(pdu,name,name_length))
{
VS_log_error("SNMP: unable to execute SNMPADDNULLVAR\n");
VS_log(LOGERROR,SNMP,"Unable to execute SNMPADDNULLVAR\n");
return VS_R_SNMP;
}
......@@ -253,7 +253,7 @@ ERR_CODE SNMP_SW_fill_table(union SNMP_arg_union *arg,struct SNMP_snmp *snmp)
/* Sending the request */