Commit 0eb60fd3 authored by Laurent Rossier's avatar Laurent Rossier

Add flags in order to protect ports :

backbone ports, aob ports, atm ports, hub ports.
This works with the nodebug flag in the makefile.

Modify the doc to show how it works.
parent ec849ba8
......@@ -6,10 +6,10 @@ CC = gcc
# Compile debugging version
# Without the debugging version, LOGDEBUG has no effect.
CFLAGS += -DDEBUG
#CFLAGS += -DDEBUG
# Debug with the debugger
#CFLAGS += -g
CFLAGS += -g
# Compiler parameters style
CFLAGS += -Wall
......
......@@ -288,6 +288,7 @@ switch{BL}type{BL}{NONBLANK}+ {
do
{
(*st)->ports[ul1].protection=VS_PL_UNSPECIFIED;
(*st)->ports[ul1].flags=0;
ul1--;
} while (ul1);
......@@ -342,8 +343,8 @@ 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\n",filename,line_num);
}
......@@ -351,24 +352,144 @@ switch{BL}type{BL}{NONBLANK}+ {
<in_switch_type>port{BL}{INT}{BL}{INT} {
sscanf(CFG_yytext+sizeof("port")/sizeof(char)-1," %lu %u",&ul1,&ui1);
if (!(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet\n", filename, line_num);
return VS_R_PARSE;
}
sscanf(CFG_yytext+sizeof("port")/sizeof(char)-1, " %lu %u", &ul1,
&ui1);
if (!ul1 || (VS_PORT)ul1>(*st)->nports)
{
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : invalid port "\
"number\n",filename,line_num);
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(LOGERROR,CFG,"Parse error in %s on line %u : protection levels"\
"range from 0 to %u\n",filename,line_num,\
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);
return VS_R_PARSE;
}
(*st)->ports[ul1].protection=(VS_PROTECTION_LEVEL)ui1;
}
<in_switch_type>bbports({BL}{INT})+ {
if (!(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet\n", filename, line_num);
}
{
unsigned int i;
unsigned int j;
for (i=sizeof("bbports")/sizeof(char)-1;i<CFG_yyleng;i+=j)
{
ul1=0;
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
"port number\n", filename, line_num);
return VS_R_PARSE;
}
(*st)->ports[ul1].flags|=PF_BBPORT;
}
}
}
<in_switch_type>atmports({BL}{INT})+ {
if (!(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet\n", filename, line_num);
}
{
unsigned int i;
unsigned int j;
for (i=sizeof("atmports")/sizeof(char)-1;i<CFG_yyleng;i+=j)
{
ul1=0;
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
"port number\n", filename, line_num);
return VS_R_PARSE;
}
(*st)->ports[ul1].flags|=PF_ATMPORT;
}
}
}
<in_switch_type>aobports({BL}{INT})+ {
if (!(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet\n", filename, line_num);
}
{
unsigned int i;
unsigned int j;
for (i=sizeof("aobports")/sizeof(char)-1;i<CFG_yyleng;i+=j)
{
ul1=0;
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*st)->nports)
{
printf("%lu\n", ul1);
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
"port number\n", filename, line_num);
return VS_R_PARSE;
}
(*st)->ports[ul1].flags|=PF_AOBPORT;
}
}
}
<in_switch_type>hubports({BL}{INT})+ {
if (!(*st)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet\n", filename, line_num);
}
{
unsigned int i;
unsigned int j;
for (i=sizeof("hubports")/sizeof(char)-1;i<CFG_yyleng;i+=j)
{
ul1=0;
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*st)->nports)
{
printf("%lu\n", ul1);
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
"port number\n", filename, line_num);
return VS_R_PARSE;
}
(*st)->ports[ul1].flags|=PF_HUBPORT;
}
}
}
<in_switch_type>end{BL}switch{BL}type {
......@@ -384,8 +505,9 @@ switch{BL}type{BL}{NONBLANK}+ {
":\n",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\n",ul1,\
(unsigned long)(*st)->ports[ul1].protection);
VS_log(LOGINFO,CFG," Port %lu :\tprotection %lu \tflags %lu\n",ul1,\
(unsigned long)(*st)->ports[ul1].protection,\
(unsigned long)(*st)->ports[ul1].flags);
st=&((*st)->next);
BEGIN(INITIAL);
eof_expected=1;
......@@ -393,7 +515,7 @@ switch{BL}type{BL}{NONBLANK}+ {
}
{NONBLANK}+{BL}{IP} {
{NONBLANK}+{BL}{IP} {
for (i=0;CFG_yytext[i]!=' ' && CFG_yytext[i]!='\t';i++);
c=CFG_yytext[i];
......@@ -440,13 +562,16 @@ switch{BL}type{BL}{NONBLANK}+ {
}
ports--;
for (ul2=1;(VS_PORT)ul2<=z->nports;ul2++)
{
ports[ul2].protection=z->ports[ul2].protection;
ports[ul2].flags=z->ports[ul2].flags;
}
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;
}
}
<in_switch>community{BL}{NONBLANK}+ {
......@@ -492,7 +617,249 @@ switch{BL}type{BL}{NONBLANK}+ {
}
<in_switch>end{BL}switch {
<in_switch>bbports({BL}{INT})+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet\n", filename, line_num);
}
{
unsigned int i;
unsigned int j;
for (i=sizeof("bbports")/sizeof(char)-1;i<CFG_yyleng;i+=j)
{
ul1=0;
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
"port number\n", filename, line_num);
return VS_R_PARSE;
}
ports[ul1].flags|=PF_BBPORT;
}
}
VS_log(LOGINFO,CFG," Flag of port %lu set to %u\n",ul1,ports[ul1].flags);
}
<in_switch>atmports({BL}{INT})+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet\n", filename, line_num);
}
{
unsigned int i;
unsigned int j;
for (i=sizeof("atmports")/sizeof(char)-1;i<CFG_yyleng;i+=j)
{
ul1=0;
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
"port number\n", filename, line_num);
return VS_R_PARSE;
}
ports[ul1].flags|=PF_ATMPORT;
}
}
VS_log(LOGINFO,CFG," Flag of port %lu set to %u\n",ul1,ports[ul1].flags);
}
<in_switch>aobports({BL}{INT})+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet\n", filename, line_num);
}
{
unsigned int i;
unsigned int j;
for (i=sizeof("aobports")/sizeof(char)-1;i<CFG_yyleng;i+=j)
{
ul1=0;
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
"port number\n", filename, line_num);
return VS_R_PARSE;
}
ports[ul1].flags|=PF_AOBPORT;
}
}
VS_log(LOGINFO,CFG," Flag of port %lu set to %u\n",ul1,ports[ul1].flags);
}
<in_switch>hubports({BL}{INT})+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet\n", filename, line_num);
}
{
unsigned int i;
unsigned int j;
for (i=sizeof("hubports")/sizeof(char)-1;i<CFG_yyleng;i+=j)
{
ul1=0;
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
printf("%lu\n", ul1);
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
"port number\n", filename, line_num);
return VS_R_PARSE;
}
ports[ul1].flags|=PF_HUBPORT;
}
}
VS_log(LOGINFO,CFG," Flag of port %lu set to %u\n",ul1,ports[ul1].flags);
}
<in_switch>nobbports({BL}{INT})+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet\n", filename, line_num);
}
{
unsigned int i;
unsigned int j;
for (i=sizeof("nobbports")/sizeof(char)-1;i<CFG_yyleng;i+=j)
{
ul1=0;
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
"port number\n", filename, line_num);
return VS_R_PARSE;
}
ports[ul1].flags&=~PF_BBPORT;
}
}
VS_log(LOGINFO,CFG," Flag of port %lu set to %u\n",ul1,ports[ul1].flags);
}
<in_switch>noatmports({BL}{INT})+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet\n", filename, line_num);
}
{
unsigned int i;
unsigned int j;
for (i=sizeof("noatmports")/sizeof(char)-1;i<CFG_yyleng;i+=j)
{
ul1=0;
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
"port number\n", filename, line_num);
return VS_R_PARSE;
}
ports[ul1].flags&=~PF_ATMPORT;
}
}
VS_log(LOGINFO,CFG," Flag of port %lu set to %u\n",ul1,ports[ul1].flags);
}
<in_switch>noaobports({BL}{INT})+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet\n", filename, line_num);
}
{
unsigned int i;
unsigned int j;
for (i=sizeof("noaobports")/sizeof(char)-1;i<CFG_yyleng;i+=j)
{
ul1=0;
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
"port number\n", filename, line_num);
return VS_R_PARSE;
}
ports[ul1].flags&=~PF_AOBPORT;
}
}
VS_log(LOGINFO,CFG," Flag of port %lu set to %u\n",ul1,ports[ul1].flags);
}
<in_switch>nohubports({BL}{INT})+ {
if (!(*s)->nports)
{
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : number of ports"
"unknown yet\n", filename, line_num);
}
{
unsigned int i;
unsigned int j;
for (i=sizeof("nohubports")/sizeof(char)-1;i<CFG_yyleng;i+=j)
{
ul1=0;
sscanf(CFG_yytext+i, " %lu%n", &ul1, &j);
if (!ul1 || ul1>(*s)->nports)
{
printf("%lu\n", ul1);
VS_log(LOGERROR, CFG, "Parse error in %s on line %u : invalid "
"port number\n", filename, line_num);
return VS_R_PARSE;
}
ports[ul1].flags&=~PF_HUBPORT;
}
}
VS_log(LOGINFO,CFG," Flag of port %lu set to %u\n",ul1,ports[ul1].flags);
}
<in_switch>end{BL}switch {
if ((*s)->community==NULL)
{
......@@ -509,7 +876,7 @@ switch{BL}type{BL}{NONBLANK}+ {
BEGIN(INITIAL);
eof_expected=1;
}
}
<*>{FB}#.*\n line_num++;
......
......@@ -5,6 +5,7 @@
struct CFG_PORT
{
VS_PROTECTION_LEVEL protection;
VS_PORT_FLAGS flags;
};
/* the data struct for a switch type and the macro to get the switch type's name
......@@ -42,6 +43,7 @@ struct CFG_SWITCH
struct CFG_PORT *ports;
struct CFG_SWITCH *next;
char *community;
VS_PORT_FLAGS flags;
};
/* the data structure for the configuration parser */
......
......@@ -466,9 +466,12 @@ ERR_CODE DB_switchs_insert(struct DB_db *db,VS_SwitchId ip,\
unsigned int j;
struct SNMP_machines_elt *y;
for (j=1;j<=24;j++)
for (y=z.glop->zwitch->machines[j];y!=NULL;y=y->next)
if (!(z.glop->zwitch->ports[j].flags&(PF_BBPORT|PF_AOBPORT|PF_ATMPORT|PF_HUBPORT)))
{
DB_machines_insert(db,y->machine,ip,(VS_PORT)j,0);
for (y=z.glop->zwitch->machines[j];y!=NULL;y=y->next)
{
DB_machines_insert(db,y->machine,ip,(VS_PORT)j,0);
}
}
}
VS_log(LOGINFO,DB,"Switch %s successfuly created\n",VS_SID2A(ip));
......
......@@ -29,6 +29,12 @@ switch type switch-1
default 0
# the attributes of some special ports
port 1 2
# the aob ports
aobports 1 2
# the atm ports
atmports 25
# the hub ports
hubports 24
model 3C1000
end switch type
......@@ -38,6 +44,8 @@ switch type switch-2
# the default attributes of its ports (the first and currently only
# attribute is the privilege level one needs to modify this port's vlan)
default 0
# the backbone ports
bbports 12 24
model 3C3300
end switch type
......@@ -62,6 +70,14 @@ end switch type
#end switch
switch-1 138.195.128.18
nobbpports 12 6
noatmports 2
noaobports 15
bbports 14 34
aobports 24
atmports 7 9
hupports 24
nohubports 13 4
community CommunityString
end switch
......
#include "types.h"
#include "logger.h"
#define LOGBUFF_MAXSIZE 80
#define LOGBUFF_MAXSIZE 120
char *VS_log_errstr(ERR_CODE err)
char * VS_log_errstr(ERR_CODE err)
{
static char *str[]=
static char * str[]=
{
"no error",
"unable to send data to remote host",
......@@ -33,7 +33,7 @@ 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;
struct tm * ptmTime;
/* Record the time */
time(&MsgTime);
......@@ -46,19 +46,19 @@ ERR_CODE VS_log(LOG_LEVELS level, LOG_MODULES module, char* format, ...)
switch (module)
{
case SNMP:
sprintf(MsgBuff+strlen(MsgBuff),"[SNMP : ");
sprintf(MsgBuff+strlen(MsgBuff), "[SNMP : ");
break;
case SERVER:
sprintf(MsgBuff+strlen(MsgBuff),"[SERVER: ");
sprintf(MsgBuff+strlen(MsgBuff), "[SERVER: ");
break;
case DB:
sprintf(MsgBuff+strlen(MsgBuff),"[DB : ");
sprintf(MsgBuff+strlen(MsgBuff), "[DB : ");
break;
case CFG:
sprintf(MsgBuff+strlen(MsgBuff),"[CFG : ");
sprintf(MsgBuff+strlen(MsgBuff), "[CFG : ");
break;
}
......@@ -66,27 +66,27 @@ ERR_CODE VS_log(LOG_LEVELS level, LOG_MODULES module, char* format, ...)
switch (level)
{
case LOGDEBUG:
sprintf(MsgBuff+strlen(MsgBuff),"debug ] ");
sprintf(MsgBuff+strlen(MsgBuff), "debug ] ");
break;
case LOGINFO:
sprintf(MsgBuff+strlen(MsgBuff),"info ] ");
sprintf(MsgBuff+strlen(MsgBuff), "info ] ");
break;
case LOGWARNING:
sprintf(MsgBuff+strlen(MsgBuff),"Warning ] ");
sprintf(MsgBuff+strlen(MsgBuff), "Warning ] ");
break;
case LOGERROR:
sprintf(MsgBuff+strlen(MsgBuff),"ERROR ] ");
sprintf(MsgBuff+strlen(MsgBuff), "ERROR ] ");
break;
case LOGFATAL:
sprintf(MsgBuff+strlen(MsgBuff),"FATAL ] ");
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_start(ap, format);
vsnprintf(MsgBuff+strlen(MsgBuff), LOGBUFF_MAXSIZE, format, ap);
va_end(ap);
printf("%s",MsgBuff);
printf("%s", MsgBuff);
return 0;
}
......@@ -5,8 +5,8 @@
#include <stdarg.h>
#include <time.h>
char *VS_log_errstr(ERR_CODE err);
char * VS_log_errstr(ERR_CODE err);
ERR_CODE VS_log(LOG_LEVELS level, LOG_MODULES module, char* format, ...);
ERR_CODE VS_log(LOG_LEVELS level, LOG_MODULES module, char * format, ...);
#endif
......@@ -166,6 +166,7 @@ ERR_CODE VS_db_init(struct VLANserver * vs,\
for (port=1 ; port<=z->nports ; port++)
{
list_switch[i]->ports[port].protection=z->ports[port].protection;
list_switch[i]->ports[port].flags=z->ports[port].flags;
}
rc=DB_switchs_insert(&vs->db, z->ip, ports, z->nports, list_switch[i]);
if(rc)
......
......@@ -81,11 +81,19 @@ typedef unsigned char VS_VLAN;
/* VS_PORT : the type of a port number */
typedef unsigned char VS_PORT;
/* the flags for a port's attributes */
typedef unsigned char VS_PORT_FLAGS;
#define PF_BBPORT ((VS_PORT_FLAGS)(1<<0))
#define PF_AOBPORT ((VS_PORT_FLAGS)(1<<1))
#define PF_ATMPORT ((VS_PORT_FLAGS)(1<<2))
#define PF_HUBPORT ((VS_PORT_FLAGS)(1<<3))
/* VS_port_data : all data of a port */
struct VS_port_data
{
int vlan;
VS_PROTECTION_LEVEL protection;
VS_PORT_FLAGS flags;
};
/* returns the vlan number of a channel */
......@@ -101,7 +109,8 @@ struct VS_port_data
(channel)=(VS_CHANNEL)macro_loop_idx; }
/* returns the protection level of a channel */
#define CHANNEL_PROTECTION(cfg,channel) ((cfg).chan_map[channel].protection)
#define MAX_COMMUNITY_SIZE 32
/* define the length of the community string */
#define MAX_COMMUNITY_SIZE 32
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment