Commit 49e25f05 authored by Damien Lucas's avatar Damien Lucas

. Don't print logs with LOGDEBUG level when compiling without the -DDEBUG

  option

. Wait the end of the snmp init before starting sending requests to it

. New function inside telnetd: reload forces to flush the database

. Support for matrixed switched
   config (need to enter the unit) default is 1
   snmp changed in port-vlan and port-mac
   added a 3COM specific kludge
parent f1d7da89
......@@ -6,7 +6,7 @@ CC = gcc
# Compile debugging version
# Without the debugging version, LOGDEBUG has no effect.
CFLAGS += -DDEBUG
#CFLAGS += -DDEBUG
#Debug messages in color
CFLAGS += -DLINUX_COLOR
......
......@@ -94,7 +94,7 @@ nchannels{BL}{INT} {
return VS_R_PARSE;
}
cfg->nchannels=(VS_CHANNEL)ul1;
VS_log(LOGINFO,CFG,"Number of channels set to : %lu",ul1);
VS_log(LOGDEBUG,CFG,"Number of channels set to : %lu",ul1);
cfg->chan_map=malloc(ul1*sizeof(struct CFG_CHANNEL));
if (cfg->chan_map==NULL)
{
......@@ -238,7 +238,7 @@ channel{BL}{INT}{BL}vlan{BL}{INT}{BL}protection{BL}{INT} {
BEGIN(INITIAL);
eof_expected=1;
CFG_yytext[strlen(CFG_yytext)-1]='\0';
VS_log(LOGINFO,CFG,"Successfuly defined channel %lu on vlan "\
VS_log(LOGDEBUG,CFG,"Successfuly defined channel %lu on vlan "\
"%lu protection %u %s",ul1,ul2,ui1,CFG_yytext);
}
......@@ -256,6 +256,7 @@ switch{BL}type{BL}{NONBLANK}+ {
return VS_R_MEMORY;
}
(*st)->nports=(VS_PORT)0;
(*st)->unit=VS_UNIT_UNSPECIFIED;
(*st)->ports=((struct CFG_PORT *)NULL)-1;
(*st)->next=NULL;
memcpy(CFG_SWITCH_TYPE_NAME(**st),CFG_yytext+i,\
......@@ -348,13 +349,28 @@ switch{BL}type{BL}{NONBLANK}+ {
i=1;
}
if (!i)
VS_log(LOGWARNING,CFG,"In %s on line %u : useless 'default' "
"statement in switch type definition, going on "
VS_log(LOGWARNING,CFG,"In %s on line %u : useless 'default' "\
"statement in switch type definition, going on "\
"however",filename,line_num);
}
<in_switch_type>unit{BL}{INT} {
sscanf(CFG_yytext+sizeof("unit")/sizeof(char)-1," %u",&ui1);
if (ui1>VS_UNIT_MAX || ui1<1)
{
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : Switch unit "\
"range from 1 to %lu",filename,line_num,\
(unsigned long)VS_UNIT_MAX);
return VS_R_PARSE;
}
(*st)->unit=(VS_UNIT)ui1;
VS_log(LOGINFO,CFG,"Switch type %s on unit %u",\
CFG_SWITCH_TYPE_NAME(**st),ui1);
}
<in_switch_type>port{BL}{INT}{BL}{INT} {
if (!(*st)->nports)
......@@ -506,11 +522,11 @@ switch{BL}type{BL}{NONBLANK}+ {
line_num,CFG_SWITCH_TYPE_NAME(**st));
return VS_R_PARSE;
}
VS_log(LOGINFO,CFG,"Switch type %s defined with the %lu following ports "\
VS_log(LOGDEBUG,CFG,"Switch type %s defined with the %lu following ports "\
":",CFG_SWITCH_TYPE_NAME(**st),\
(unsigned long)(*st)->nports);
for (ul1=1;(VS_PORT)ul1<=(*st)->nports;ul1++)
VS_log(LOGINFO,CFG," Port %lu :\tprotection %lu \tflags %lu",ul1,\
VS_log(LOGDEBUG,CFG," Port %lu :\tprotection %lu \tflags %lu",ul1,\
(unsigned long)(*st)->ports[ul1].protection,\
(unsigned long)(*st)->ports[ul1].flags);
st=&((*st)->next);
......@@ -552,6 +568,7 @@ switch{BL}type{BL}{NONBLANK}+ {
// and complete s
(*s)->ip=ip;
(*s)->unit=z->unit;
(*s)->nports=z->nports;
(*s)->type=z->type;
(*s)->next=NULL;
......@@ -621,7 +638,19 @@ switch{BL}type{BL}{NONBLANK}+ {
}
<in_switch>unit{BL}{INT} {
sscanf(CFG_yytext+sizeof("unit")/sizeof(char)-1," %u",&ui1);
if (ui1>VS_UNIT_MAX || ui1<1)
{
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : invalid unit "\
"number",filename,line_num);
return VS_R_PARSE;
}
(*s)->unit=ui1;
VS_log(LOGINFO,CFG," Unit of switch set to %u",ui1);
}
<in_switch>bbports({BL}{INT})+ {
if (!(*s)->nports)
......
......@@ -14,6 +14,7 @@ struct CFG_SWITCH_TYPE /* note the type's name is stored just at the
end of this structure */
{
VS_SwitchType type;
VS_UNIT unit; /* the default unit in case of matrix use */
VS_PORT nports; /* the number of ports, ports numbers will go
from 1 to nports */
struct CFG_PORT *ports; /* an array of default values (ports[1] is the
......@@ -38,6 +39,7 @@ struct CFG_CHANNEL
struct CFG_SWITCH
{
VS_SwitchType type;
VS_UNIT unit;
VS_SwitchId ip;
VS_PORT nports;
struct CFG_PORT *ports;
......
......@@ -3,9 +3,15 @@
#include "../types.h"
#include "../logger.h"
#include "../snmp/snmp_switch.h"
#include "../snmp/if_snmp.h"
#include "../snmp/snmp.h"
#include "../db/db.h"
#include "../config/config.h"
#include "telnet.h"
#include "interface.h"
#include "../server/server.h"
#include "../vlanserver.h"
ERR_CODE IF_start(void)
{
......@@ -18,3 +24,11 @@ ERR_CODE IF_start(void)
}
return 0;
}
ERR_CODE IF_reload(void)
{
VS_reinit_switchs(vs->info_poller);
return 0;
}
ERR_CODE IF_start(void);
ERR_CODE IF_reload(void);
......@@ -9,9 +9,10 @@
#include "../types.h"
#include "../logger.h"
#include "./telnet.h"
#include "./interface.h"
#define PORT 7891
#define SERVER "138.195.140.61"
#define SERVER "138.195.138.42"
#define MAXCONNECTIONS 20 // how many connections are queued
/* TELNET Interface */
......@@ -35,6 +36,9 @@ static void IF_telnet_commands (int iSocket, char* sUser);
static void Menu_init (struct IF_Menu* mMenu);
static void Menu_send (int iSocket, struct IF_Menu mMenu);
ERR_CODE TELNET_stop(unsigned int * uStop);
ERR_CODE TELNET_reload(unsigned int * uStop);
static char* Catch_Word (int iSocket);
static char* Catch_Passwd (int iSocket);
......@@ -57,10 +61,12 @@ void* IF_telnet(void* ar)
int size;
unsigned int stop;
int rc;
int iOpt;
stop=0;
size=sizeof(struct sockaddr_in);
iOpt=1;
/* Initialization */
sock=socket(AF_INET,SOCK_STREAM,0);
if(sock==-1)
......@@ -75,7 +81,7 @@ void* IF_telnet(void* ar)
addr.sin_addr.s_addr = inet_addr(SERVER);
bzero(&(addr.sin_zero),8);
setsockopt(sock,SOL_SOCKET, SO_REUSEADDR, &iOpt,sizeof(iOpt));
rc=bind(sock,(struct sockaddr *)&addr,sizeof(struct sockaddr));
if(rc==-1)
{
......@@ -125,6 +131,7 @@ static void IF_telnet_init(int isocket)
/* Need to negociate Terminal ... */
Request_send(isocket, WILL, TELOPT_ECHO);
Request_send(isocket, WILL, TELOPT_SGA);
Request_send(isocket, WILL, TELOPT_OUTMRK);
Request_send(isocket, DONT, TELOPT_LINEMODE);
}
......@@ -193,7 +200,7 @@ static void IF_telnet_commands (int iSocket, char* sUser)
{
if(!strcmp(sCmd,z->sName))
{
uStop=1;
z->function(&uStop);
}
}
free(sCmd);
......@@ -209,15 +216,31 @@ static void IF_telnet_commands (int iSocket, char* sUser)
static void Menu_init (struct IF_Menu* mMenu)
{
mMenu->Command=malloc(sizeof(struct IFT_Command));
mMenu->Command->next=malloc(sizeof(struct IFT_Command));
mMenu->Command->iIndex='0';
mMenu->Command->function=TELNET_stop;
sprintf(mMenu->Command->sName,"logout");
sprintf(mMenu->Command->sDescr,"Close the current connection");
mMenu->Command->next=NULL;
}
mMenu->Command->next->iIndex='1';
mMenu->Command->next->function=TELNET_reload;
sprintf(mMenu->Command->next->sName,"reload");
sprintf(mMenu->Command->next->sDescr,"Reload the database");
mMenu->Command->next->next=NULL;
}
ERR_CODE TELNET_stop(unsigned int * uStop)
{
*uStop=1;
return 0;
}
ERR_CODE TELNET_reload(unsigned int * uStop)
{
IF_reload();
return 1;
}
/******************************************************************************
* Menu_send() *
******************************************************************************
......@@ -276,8 +299,12 @@ static char* Catch_Word (int iSocket)
case 0x7F:
if(iPos>0)
{
unsigned char b4Buff[4];
sData[iPos-1]='\0';
Request_send(iSocket,247,TELOPT_OUTMRK);
b4Buff[0]=0x08;
b4Buff[1]=0x20;
b4Buff[2]=0x08;
Message_send(iSocket,&bBuff,4);
}
case KEY_UP:
......
......@@ -9,6 +9,7 @@ struct IFT_Command
char sName[17];
char sDescr[40];
struct IFT_Command* next;
ERR_CODE (*function)();
};
......
......@@ -35,6 +35,10 @@ ERR_CODE VS_log(LOG_LEVELS level, LOG_MODULES module, char* format, ...)
time_t MsgTime;
struct tm * ptmTime;
#ifndef DEBUG
if(level!=LOGDEBUG)
{
#endif
/* Record the time */
time(&MsgTime);
ptmTime=localtime(&MsgTime);
......@@ -119,6 +123,8 @@ ERR_CODE VS_log(LOG_LEVELS level, LOG_MODULES module, char* format, ...)
va_end(ap);
printf("%s", MsgBuff);
#ifndef DEBUG
}
#endif
return 0;
}
#define __DEF_VS_INIT__
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
......@@ -12,13 +13,20 @@
#include "config/config.h"
#include "server/server.h"
#include "vlanserver.h"
struct VLANserver *vs;
int main(int argc,char *argv[])
{
struct VLANserver vs;
ERR_CODE rc;
rc=VS_init(&vs,argc,argv);
vs=malloc(sizeof(struct VLANserver));
if(vs==NULL)
{
VS_log(LOGFATAL,SERVER,"Unable to allocate memory");
return 1;
}
rc=VS_init(argc,argv);
if (rc)
{
VS_log(LOGFATAL,SERVER,"%s",VS_log_errstr(rc));
......
......@@ -35,10 +35,10 @@ ERR_CODE VS_poll_switch(struct VLANserver *vs, struct SNMP_switch *zwitch, struc
/*
* Try three times to reinit the swith if it failed
*/
VS_log(LOGERROR,SERVER,"Initialization of switch failed. "\
VS_log(LOGWARNING,SERVER,"Initialization of switch failed. "\
"Retrying. Number of try : %u",a);
SNMP_init_switch(&vs->snmp,z->type,z->ip,\
z->nports,z->community,zwitch);
z->nports,z->community,z->unit, zwitch);
sleep(8);
rc=SNMP_is_inited(zwitch);
a++;
......
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <semaphore.h>
#include "../types.h"
#include "../logger.h"
......@@ -24,7 +25,7 @@ ERR_CODE VS_reinit_switchs_thread(struct VS_info_poller * info_poller)
while (info_poller->runlevel<VS_POLL_STOP)
{
sleep(400);
sleep(1000000000);
VS_log(LOGINFO, SERVER, "Reinitialization of the db");
rc=VS_reinit_switchs (info_poller);
if(rc)
......@@ -57,7 +58,7 @@ ERR_CODE VS_reinit_switchs (struct VS_info_poller * info_poller)
return VS_R_MEMORY;
}
rc=SNMP_stop(&(info_poller->vs->snmp));
rc=SNMP_stop(&(vs->snmp));
if(rc)
{
VS_log(LOGERROR, SERVER, "unable to stop the snmp");
......@@ -68,7 +69,7 @@ ERR_CODE VS_reinit_switchs (struct VS_info_poller * info_poller)
/* sleep for the timeout of the switches */
sleep(12);
rc=DB_flush(&(info_poller->vs->db));
rc=DB_flush(&(vs->db));
if(rc)
{
VS_log(LOGERROR, SERVER, "unable to stop the db");
......@@ -78,13 +79,17 @@ ERR_CODE VS_reinit_switchs (struct VS_info_poller * info_poller)
}
rc=SNMP_start(&(info_poller->vs->snmp));
sem_init(vs->snmp.sem,0,0);
rc=SNMP_start(&(vs->snmp));
if(rc)
{
VS_log(LOGERROR, SERVER, "unable to restart the snmp");
return 12;
}
/* We should not start the db_init before snmp loop started */
sem_wait(vs->snmp.sem);
rc=VS_db_init(list_switch, info_poller);
if(rc)
{
......
......@@ -8,6 +8,7 @@
#include <arpa/inet.h>
#include <sys/time.h>
#include <unistd.h>
#include <semaphore.h>
#include "../types.h"
#include "../logger.h"
......@@ -23,7 +24,7 @@
#include "server.h"
#include "request_handler.h"
ERR_CODE VS_start(struct VLANserver * vs)
ERR_CODE VS_start()
{
struct sockaddr_in server_client;
struct sockaddr_in server_snmp;
......@@ -33,20 +34,22 @@ ERR_CODE VS_start(struct VLANserver * vs)
struct SNMP_switch ** list_switch;
struct VS_info_poller * info_poller;
/* WARNING : do not put anything that may fail or return beforewe initialize
/* WARNING : do not put anything that may fail or return before we initialize
* vs->cnx_lost, or add a flag to say if it has been initialized */
vs->runlevel=VS_INIT;
pthread_mutex_init(&vs->cnx_lock, NULL);
info_poller=malloc(sizeof(struct VS_info_poller));
if(info_poller==NULL)
vs->info_poller=malloc(sizeof(struct VS_info_poller));
if(vs->info_poller==NULL)
{
VS_log(LOGERROR,SERVER,"Unable to allocate memory");
VS_stop(info_poller);
VS_stop(vs->info_poller);
return VS_R_MEMORY;
}
info_poller=vs->info_poller;
info_poller->args=malloc(sizeof(struct VS_select_args));
if(info_poller->args==NULL)
{
......@@ -66,7 +69,6 @@ ERR_CODE VS_start(struct VLANserver * vs)
info_poller->args->session_id=0;
info_poller->args->thread=0;
info_poller->vs=vs;
rc=VS_db_thread(info_poller);
if(rc)
......@@ -76,6 +78,9 @@ ERR_CODE VS_start(struct VLANserver * vs)
return VS_R_PTHREAD;
}
/* We should not run db_init before snmp_loop started */
sem_wait(vs->snmp.sem);
rc=VS_db_init(list_switch, info_poller);
if(rc)
{
......@@ -157,7 +162,7 @@ ERR_CODE VS_db_init(struct SNMP_switch ** list_switch,\
/* Initialization of the switches read in the config file */
VS_log(LOGINFO,SERVER,"Sending SNMP requests");
for(z=info_poller->vs->cfg.zwitches, i=1 ; z!=NULL ; z=z->next, i++)
for(z=vs->cfg.zwitches, i=1 ; z!=NULL ; z=z->next, i++)
{
zwitch=malloc(sizeof(struct SNMP_switch));
if(zwitch==NULL)
......@@ -165,8 +170,8 @@ ERR_CODE VS_db_init(struct SNMP_switch ** list_switch,\
VS_stop(info_poller);
return VS_R_MEMORY;
}
SNMP_init_switch(&(info_poller->vs->snmp), z->type, z->ip, z->nports, z->community,\
zwitch);
SNMP_init_switch(&(vs->snmp), z->type, z->ip, z->nports, z->community,
z->unit, zwitch);
list_switch[i]=zwitch;
}
list_switch[i]=NULL;
......@@ -177,9 +182,9 @@ ERR_CODE VS_db_init(struct SNMP_switch ** list_switch,\
sleep(15);
/* Insert the switch inside the database */
for(z=info_poller->vs->cfg.zwitches, i=1 ; z!=NULL ; z=z->next, i++)
for(z=vs->cfg.zwitches, i=1 ; z!=NULL ; z=z->next, i++)
{
b=VS_poll_switch(info_poller->vs, list_switch[i], z);
b=VS_poll_switch(vs, list_switch[i], z);
if(!b)
{
ports=malloc((((int)z->nports)+1)*sizeof(struct DB_port));
......@@ -193,7 +198,7 @@ ERR_CODE VS_db_init(struct SNMP_switch ** list_switch,\
list_switch[i]->ports[port].protection=z->ports[port].protection;
list_switch[i]->ports[port].flags=z->ports[port].flags;
}
rc=DB_switchs_insert(&(info_poller->vs->db), z->ip, ports, z->nports, list_switch[i]);
rc=DB_switchs_insert(&(vs->db), z->ip, ports, z->nports, list_switch[i]);
if(rc)
{
VS_log(LOGERROR,SERVER,"Unable to insert switch in the database");
......@@ -442,11 +447,11 @@ ERR_CODE VS_request_snmp(struct VLANserver * vs, struct VS_select_args * args)
*****************************************************************************/
ERR_CODE VS_stop(struct VS_info_poller * info_poller)
{
info_poller->vs->runlevel=VS_STOP;
vs->runlevel=VS_STOP;
info_poller->runlevel=VS_POLL_STOP;
/* WRNING we do not verify cnx_lost has been initialized because currently, we
* are sure it has been */
pthread_mutex_destroy(&(info_poller->vs->cnx_lock));
pthread_mutex_destroy(&(vs->cnx_lock));
close(info_poller->args->socket_se);
close(info_poller->args->socket_snmp);
close(info_poller->args->socket_interface);
......
......@@ -41,12 +41,11 @@ struct VS_info_poller
} runlevel;
pthread_t thread;
pthread_attr_t thread_attr;
struct VLANserver * vs;
struct VS_select_args * args;
};
ERR_CODE VS_start(struct VLANserver * vs);
ERR_CODE VS_start();
ERR_CODE VS_db_thread(struct VS_info_poller * info_poller);
......
......@@ -12,10 +12,6 @@ struct snmp_pdu * snmp_pdu_create (int command);
void sprint_variable (char *, oid *,size_t, struct variable_list *);
struct variable_list* snmp_add_null_var (struct snmp_pdu *, oid *, size_t);
/* TODO Write a walk in order to have this table for each switch */
#define Snmp_PORT(x) ( (x)+100 )
#define PORT_Snmp(x) ( (x)-100 )
/******************************************************************************
* Callback_Vlans() *
......@@ -52,9 +48,10 @@ inline static void Callback_Vlans(struct snmp_session *session,
case VS_ST_3C3300:
if(sscanf(buffer+59,"%Lu.%u = active(1)",&vlan,&port)==2)
{
if (port<Snmp_PORT(zwitch->nb_ports)+1&&port>100)
if (port<Snmp_PORT(zwitch->nb_ports,zwitch->unit)+1
&& port>100*zwitch->unit)
{
zwitch->ports[PORT_Snmp(port)].vlan=vlan;
zwitch->ports[PORT_Snmp(port,zwitch->unit)].vlan=vlan;
}
}
break;
......@@ -204,8 +201,8 @@ inline static void Callback_Macs(struct snmp_session *session,
if(!memcmp(buffer, zwitch->walk_macs.stop,zwitch->walk_macs.stop_size))
{
/* Need to operate on received pdu
* enterprises.43.10.22.2.1.3.1.port.i1.i2.i3...
* ^ 29 */
* enterprises.43.10.22.2.1.3.unit.port.i1.i2.i3...
* ^ 29 */
if(sscanf(buffer+29,"%u.%Lu.%Lu.%u.%u.%u.%u",&port,&mac,
&i2,&i3,&i4,&i5,&i6)!=7)
......
......@@ -123,9 +123,7 @@ static void *SNMP_loop(struct SNMP_snmp *snmp)
char foobar;
snmp->session_num=1;
VS_log(LOGINFO,SNMP,"Snmp loop started");
snmp->runlevel=SNMP_RUN;
/* Need to create an snmp session to catch traps */
session.peername=NULL;
session.community=NULL;
......@@ -144,6 +142,11 @@ static void *SNMP_loop(struct SNMP_snmp *snmp)
VS_log(LOGFATAL,SNMP,"Unable to open the session to catch traps");
}
/* Ready to start */
VS_log(LOGINFO,SNMP,"Snmp loop started");
snmp->runlevel=SNMP_RUN;
sem_post(snmp->sem);
/* Beginning of the main loop */
while (snmp->runlevel<SNMP_STOP)
{
......@@ -183,10 +186,11 @@ static void *SNMP_loop(struct SNMP_snmp *snmp)
}
}
VS_log(LOGINFO, SNMP, "SNMP engine stopped");
sem_destroy(snmp->sem);
return NULL;
}
static void SNMP_cancel(struct SNMP_snmp *snmp)
static void SNMP_cancel(struct SNMP_snmp * snmp)
{
close(snmp->pipe[0]);
close(snmp->pipe[1]);
......@@ -194,7 +198,7 @@ static void SNMP_cancel(struct SNMP_snmp *snmp)
VS_log(LOGERROR,SNMP,"Unable to spawn the snmp engine");
}
ERR_CODE SNMP_start(struct SNMP_snmp *snmp)
ERR_CODE SNMP_start(struct SNMP_snmp * snmp)
{
VS_log(LOGINFO,SNMP,"Starting the SNMP engine...");
snmp->runlevel=SNMP_INIT;
......
......@@ -17,6 +17,7 @@ struct SNMP_snmp
{
pthread_t loop;
pthread_mutex_t fifo_mutex;
sem_t* sem;
enum {
SNMP_INIT,
SNMP_RUN,
......@@ -30,7 +31,8 @@ struct SNMP_snmp
unsigned short int se_port; /* Port number for the socket with the server */
};
ERR_CODE SNMP_start(struct SNMP_snmp *snmp);
ERR_CODE SNMP_start(struct SNMP_snmp * snmp);
ERR_CODE SNMP_stop(struct SNMP_snmp * snmp);
ERR_CODE SNMP_set_vlan(struct SNMP_snmp *snmp,struct SNMP_switch *zwitch,\
VS_PORT port,VS_VLAN vlan);
......@@ -41,5 +43,4 @@ ERR_CODE SNMP_get_macs(struct SNMP_snmp *snmp,struct SNMP_switch *zwitch);
ERR_CODE SNMP_get_vlans(struct SNMP_snmp *snmp, struct SNMP_switch *zwitch);
ERR_CODE SNMP_stop(struct SNMP_snmp * snmp);
#endif
......@@ -20,8 +20,6 @@ struct variable_list* snmp_add_null_var (struct snmp_pdu *, oid *, size_t);
/* Defines the snmp version */
#define DS_LIBRARY_ID 0
#define DS_LIB_SNMPVERSION 2
#define Snmp_PORT(x) ( (x)+100 )
#define PORT_Snmp(x) ( (x)-100 )
/******************************************************************************
......@@ -44,7 +42,7 @@ static ERR_CODE SNMP_SW_set_vlan(union SNMP_arg_union *arg,
/* Definition of the snmp_string */
rc=sprintf(snmp_string,"31.1.2.1.3.%d.%d",\
arg->set_vlan.zwitch->vlanid[arg->set_vlan.vlan],\
Snmp_PORT(arg->set_vlan.port));
Snmp_PORT(arg->set_vlan.port,arg->set_vlan.zwitch->unit));
if(rc==-1)
{
VS_log(LOGERROR,SNMP,"Error in printing the variable");
......@@ -125,7 +123,8 @@ static ERR_CODE SNMP_SW_get_macs(union SNMP_arg_union *arg,\
}
/* Definition of the snmp_string */
rc=sprintf(snmp_string,".1.3.6.1.4.1.43.10.22.2.1.3");
rc=sprintf(snmp_string,".1.3.6.1.4.1.43.10.22.2.1.3.%u",
arg->get_macs.zwitch->unit);
if(rc==-1)
{
VS_log(LOGERROR,SNMP,"Unable to print the variable");
......@@ -352,13 +351,14 @@ ERR_CODE SNMP_SW_get_vlans(union SNMP_arg_union *arg,struct SNMP_snmp *snmp)
ERR_CODE SNMP_init_switch(struct SNMP_snmp *snmp,VS_SwitchType type,\
VS_SwitchId ip,VS_PORT nports,char *community_string,\
struct SNMP_switch *zwitch)
VS_UNIT unit, struct SNMP_switch *zwitch)
{
unsigned int i;
zwitch->type=type;
zwitch->nb_ports=nports;
zwitch->unit=unit;
snmp_sess_init(&zwitch->s2);
zwitch->s2.version=ds_get_int(DS_LIBRARY_ID, DS_LIB_SNMPVERSION);
......@@ -372,9 +372,13 @@ ERR_CODE SNMP_init_switch(struct SNMP_snmp *snmp,VS_SwitchType type,\
zwitch->fill_table=SNMP_SW_fill_table;
zwitch->get_vlans=SNMP_SW_get_vlans;
zwitch->walk_macs.stop_size=27;
/* XXX this line is 3Com specific */
strcpy(zwitch->walk_macs.stop,"enterprises.43.10.22.2.1.3.");
/* XXX these lines are 3Com specific */
{
char buffer[29];
sprintf(buffer,"enterprises.43.10.22.2.1.3.%1u",unit);
strcpy(zwitch->walk_macs.stop,buffer);
zwitch->walk_macs.stop_size=28;
}
zwitch->walk_table.stop_size=35;
strcpy(zwitch->walk_table.stop,"interfaces.ifTable.ifEntry.ifDescr.");
zwitch->walk_vlans.stop_size=11;
......
......@@ -4,7 +4,7 @@
ERR_CODE SNMP_init_switch(struct SNMP_snmp *snmp,VS_SwitchType type,\
VS_SwitchId ip,VS_PORT nports,char *community_string,\
struct SNMP_switch *zwitch);
VS_UNIT unit, struct SNMP_switch *zwitch);
ERR_CODE SNMP_is_inited(struct SNMP_switch *zwitch);
......
......@@ -10,6 +10,12 @@
#define MAX_VLAN_NB 16
#define MAX_PORTS_NB 26
/* TODO Write a walk in order to have this table for each switch */
#define Snmp_PORT(x,y) ( (x) + 100*(y) )
#define PORT_Snmp(x,y) ( (x) - 100*(y) )
struct SNMP_machines_elt
{
VS_MachineId machine;
......@@ -43,6 +49,7 @@ struct SNMP_switch
{
VS_SwitchType type;
VS_PORT nb_ports;
VS_UNIT unit;
struct SNMP_vlans walk_vlans;
struct SNMP_walk walk_macs;
struct SNMP_table walk_table;
......
......@@ -7,6 +7,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>
#include "types.h"
#include "logger.h"
......@@ -20,7 +21,7 @@
#include "vlanserver.h"
#include "interface/interface.h"
unsigned int VS_init(struct VLANserver *vs,int argc,char *argv[])
unsigned int VS_init(int argc,char *argv[])
{
ERR_CODE grumpf;
......@@ -56,6 +57,8 @@ unsigned int VS_init(struct VLANserver *vs,int argc,char *argv[])
return grumpf;
// Initializing the SNMP
vs->snmp.sem=malloc(sizeof(sem_t));
sem_init(vs->snmp.sem,0,0);
grumpf=SNMP_start(&vs->snmp);
if (grumpf)
return grumpf;
......@@ -65,8 +68,8 @@ unsigned int VS_init(struct VLANserver *vs,int argc,char *argv[])
if (grumpf)
return grumpf;
// Starting the server
grumpf=VS_start(vs);
// Starting the server