Commit 9566126a authored by Laurent Rossier's avatar Laurent Rossier

-Add the dns resolution : we can give the dns of the vlanbridge in the...

-Add the dns resolution : we can give the dns of the vlanbridge in the vlanserver.conf and the dns of the server in the client
-Remove this job from the TODO list and a new job
-Clean the logger.c and the types.h : modify the ERR_CODE
parent 4762944f
(snmp 1): possible GPA
Gérer les numéros de ports de la même manière que les vlans et non
avec ce putain de #define
(snmp 7):
Prévenir le serveur d'un linkup/linkdown lors d'un catch snmp-trap
......@@ -34,10 +30,11 @@
Vérifier à la fin de la config qu'on a bien toutes les infos dont on a
besoin (IP, login, passwd du vlb, par exemple)
(cfg 4):
permettre d'utiliser des DNS au lieu des IPs dans le fichier de config
(cfg 5):
Inscrire une expression reguliere pour valider la dns.
(cfg 6):
ptet un jour mettre au point un protocole a la con pour qu'il y ait
detection automatique du (des ?) vls. ptet un jour :)
......
......@@ -5,7 +5,7 @@
#include <arpa/inet.h> /* types.h */
#include <string.h> /* strncmp */
#include <string.h> /* strdup, strncmp */
#include "../types.h"
#include "../logger.h"
......@@ -32,11 +32,13 @@ inline int CFG_yywrap(void) {return 1;}
%}
BL [ \t]+
FB [ \t]*
INT [0-9]+
BL [ \t]+
FB [ \t]*
INT [0-9]+
NONBLANK [^ \t\n]
IP ([0-9]{1,3}[.]){3}([0-9]{1,3})
IP ([0-9]{1,3}[.]){3}([0-9]{1,3})
DNS ([A-Za-z0-9-]|[.])*
DNSORIP ([A-Za-z0-9-]|[.])*
%x in_channel_raw_data
%x in_switch_type
......@@ -153,9 +155,9 @@ nchannels{BL}{INT} {
}
vlanbridge{BL}{IP} {
vlanbridge{BL}{DNSORIP} {
if (cfg->vlanbridge[0])
if (cfg->vlanbridge!=NULL)
{
VS_log(LOGERROR,CFG,"Parse error in %s on line %u : duplicated "\
"vlanbridge address defition",filename,line_num);
......@@ -163,10 +165,9 @@ vlanbridge{BL}{IP} {
}
for (ui1=CFG_yyleng-1;\
CFG_yytext[ui1-1]!=' ' && CFG_yytext[ui1-1]!='\t';ui1--);
memcpy(cfg->vlanbridge,CFG_yytext+ui1,CFG_yyleng-ui1);
cfg->vlanbridge[CFG_yyleng-ui1]=0;
cfg->vlanbridge=strdup(CFG_yytext+ui1);
}
}
vlanbridge_login{BL}{NONBLANK}+ {
......@@ -510,7 +511,6 @@ switch{BL}type{BL}{NONBLANK}+ {
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", filename, line_num);
return VS_R_PARSE;
......@@ -539,7 +539,6 @@ switch{BL}type{BL}{NONBLANK}+ {
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", filename, line_num);
return VS_R_PARSE;
......@@ -800,7 +799,6 @@ switch{BL}type{BL}{NONBLANK}+ {
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", filename, line_num);
return VS_R_PARSE;
......@@ -832,7 +830,6 @@ switch{BL}type{BL}{NONBLANK}+ {
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", filename, line_num);
return VS_R_PARSE;
......@@ -957,7 +954,6 @@ switch{BL}type{BL}{NONBLANK}+ {
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", filename, line_num);
return VS_R_PARSE;
......@@ -1088,7 +1084,7 @@ ERR_CODE CFG_init(struct VS_config *cfg,int argc,char *argv[])
cfg->nchannels=0;
cfg->chan_map=NULL;
cfg->switch_types=NULL;
cfg->vlanbridge[0]=0;
cfg->vlanbridge=NULL;
cfg->vlanbridge_login=NULL;
cfg->vlanbridge_password=NULL;
cfg->zwitches=NULL;
......
......@@ -57,7 +57,7 @@ struct VS_config
channel i */
struct CFG_SWITCH_TYPE *switch_types; /* the list of switch types */
struct CFG_SWITCH *zwitches; /* the list of switches */
char vlanbridge[VS_IP_LENGTH]; /* the IP address of the vlanbridge */
char * vlanbridge; /* the DNS address of the vlanbridge */
char *vlanbridge_login; /* the login on the vlanbridge */
char *vlanbridge_password; /* the password on the vlanbridge */
char *logfile; /* the file where we will log */
......
......@@ -9,7 +9,7 @@ logfile test.log # the name of the file where to log
nchannels 7 # the number of channels, they will range from 0 to 6
vlanbridge 138.195.143.202 # the IP address of the vlanbridge
vlanbridge toto.bla.net # the DNS or the IP address of the vlanbridge
vlanbridge_login VLANserver # the login on the vlanbridge
vlanbridge_password password # the password on the vlanbridge
......
......@@ -432,23 +432,25 @@ char * VS_log_errstr(ERR_CODE err)
static char * str[]=
{
"no error",
"unable to send data to remote host",
"unable to connect to remote host",
"unable to execute a select() operation",
"unable to receive data from remote host",
"unable to open a socket",
"unable to bind a socket",
"timeout",
"unable to allocate memory",
"object not found",
"unable to spawn a thread",
"trying to do a walk on a switch is currently walked by an other thread",
"unable to bind a socket",
"unable to connect to remote host",
"unable to resolve the dns",
"initiatization of the switch failed",
"unable to open, read or write a file",
"unable to allocate memory",
"parse error",
"snmp error",
"pipe creation error",
"unable to write to a pipe",
"trying to do a walk on a switch is currently walked by an other thread",
"initiatization of the switch failed"
"unable to spawn a thread",
"unable to receive data from remote host",
"unable to send data to remote host",
"unable to execute a select() operation",
"snmp error",
"unable to open a socket",
"time error",
"timeout"
};
return str[err];
}
......@@ -7,6 +7,8 @@
#include <sys/ioctl.h> /* ioctl */
#include <sys/socket.h> /* bind, sendto */
#include <sys/time.h> /* time */
#include <netdb.h> /* gethostbyname */
#include <errno.h> /* herror */
#include "../types.h"
#include "../config.h"
......@@ -17,17 +19,17 @@
/* vishnou*/
//#define SERVER_IP "138.195.139.95"
//#define SERVER "vishnou.via.ecp.fr"
/* titi */
//#define SERVER_IP "138.195.130.90"
//#define SERVER "titi.via.ecp.fr"
/* obelix */
//#define SERVER_IP "138.195.140.47"
//#define SERVER "obelix.via.ecp.fr"
/* ekaki */
//#define SERVER_IP "138.195.138.42"
//#define SERVER "ekaki.via.ecp.fr"
/* blutch */
#define SERVER_IP "138.195.140.61"
#define SERVER "blutch.via.ecp.fr"
/* maceo [Tooney] */
//#define SERVER_IP "138.195.141.185"
//#define SERVER "maceo.via.ecp.fr"
int VS_client(VS_CHANNEL Channel_dest)
......@@ -41,6 +43,7 @@ int VS_client(VS_CHANNEL Channel_dest)
char mess[mess_length];
struct timeval *date_cl;
struct timeval time;
struct hostent * h;
long unsigned int date;
int nbanswer;
char answer[6];
......@@ -66,22 +69,20 @@ int VS_client(VS_CHANNEL Channel_dest)
/*
* Getting the server's information
*/
if((h=gethostbyname(SERVER))==NULL)
{
herror("Server name ");
return 1;
}
bzero(&sa_server,sizeof(struct sockaddr_in));
sa_server.sin_family=AF_INET;
sa_server.sin_port=htons(DEFAULT_PORT);
inet_aton(SERVER_IP,&(sa_server.sin_addr));
sa_server.sin_addr=*((struct in_addr *)h->h_addr);
/*
* Looking for the interface MAC address
*/
ioctl(socket_cl,SIOCGIFHWADDR,&interface);
printf("macaddr == %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
interface.ifr_hwaddr.sa_data[0] & 0xff,
interface.ifr_hwaddr.sa_data[1] & 0xff,
interface.ifr_hwaddr.sa_data[2] & 0xff,
interface.ifr_hwaddr.sa_data[3] & 0xff,
interface.ifr_hwaddr.sa_data[4] & 0xff,
interface.ifr_hwaddr.sa_data[5] & 0xff);
/*
* Getting date of the client
......
......@@ -14,6 +14,8 @@
#include <ucd-snmp/snmp_api.h> /* if_snmp.h */
#include <ucd-snmp/snmp_client.h> /* if_snmp.h */
#include <ucd-snmp/mib.h> /* if_snmp.h */
#include <netdb.h> /* gethostbyname */
#include <errno.h> /* herror */
#include "../types.h"
#include "../logger.h"
......@@ -232,6 +234,7 @@ ERR_CODE VS_connect(struct sockaddr_in server_client,
struct VS_select_args * args)
{
unsigned int rc;
struct hostent * h;
bzero(&server_client, sizeof(struct sockaddr_in));
server_client.sin_family=AF_INET;
......@@ -248,7 +251,14 @@ ERR_CODE VS_connect(struct sockaddr_in server_client,
server_interface.sin_port=0;
server_interface.sin_addr.s_addr=inet_addr("127.0.0.1");
vs->vlb_params.sin_addr.s_addr=inet_addr(vs->cfg->vlanbridge);
if((h=gethostbyname(vs->cfg->vlanbridge))==NULL)
{
herror("VLANbridge address ");
return VS_R_DNS;
}
VS_log(LOGINFO, SERVER, "VLANbrdige IP : %s",
inet_ntoa(*((struct in_addr *)h->h_addr)));
vs->vlb_params.sin_addr=*((struct in_addr *)h->h_addr);
vs->vlb_params.sin_family=AF_INET;
vs->vlb_params.sin_port=htons(DEFAULT_ROUTER_PORT);
memset(&(vs->vlb_params.sin_zero), '\0', 8);
......
......@@ -37,9 +37,10 @@ typedef enum {VS_R_OK,
VS_R_ABSENT,
VS_R_ALREADY_WALKING,
VS_R_BIND,
VS_R_FILE,
VS_R_CONNECT,
VS_R_DNS,
VS_R_INIT_FAILED,
VS_R_FILE,
VS_R_MEMORY,
VS_R_PARSE,
VS_R_PIPE,
......
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