Project

General

Profile

Vde switch virtual network » vde2-2.3.1-wirefilter-ethertype.patch

Antonio Quartulli, 10/24/2011 08:10 PM

View differences:

src/wirefilter.c 2011-10-24 18:21:01.122126068 +0200
char debuglevel[NPFD];
char *progname;
char *mgmt;
char ether_type[2];
unsigned char ether_num_bytes;
char ether_bytes[10];
int mgmtmode=0700;
#define LR 0
#define RL 1
......
void handle_packet(int dir,const unsigned char *buf,int size)
{
int i;
/* MTU */
/* if the packet is incosistent with the MTU of the line just drop it */
if (min_wirevalue(markov_current,MTU,dir) > 0 && size > min_wirevalue(markov_current,MTU,dir))
return;
/* if the packet has the whitelisted ethertype or etherbytes just send it */
if ((ether_type[0] == 0 && ether_type[1] == 0) || (size < 16))
goto wire_check;
if ((ether_type[0] != buf[14]) || (ether_type[1] != buf[15]))
goto wire_check;
if (ether_num_bytes == 0) {
writepacket(dir,buf,size);
return;
} else {
if (size < 17)
goto wire_check;
for (i = 0; i < ether_num_bytes; i++) {
if (ether_bytes[i] != buf[16])
continue;
writepacket(dir,buf,size);
return;
}
}
/* LOSS */
/* Total packet loss */
wire_check:
if (min_wirevalue(markov_current,LOSS,dir) >= 100.0)
return;
/* probabilistic loss */
......
"\t--pidfile pidfile\n"
"\t--blink blinksocket\n"
"\t--blinkid blink_id_string\n"
"\t--ether ether_type<:byte><:byte>\n"
,progname);
exit (1);
}
......
int option_index;
int mgmtindex=-1;
int consoleindex=-1;
char *ptr;
static struct option long_options[] = {
{"help",0 , 0, 'h'},
{"rcfile", 1, 0, 'f'},
......
{"daemon",0 , 0, DAEMONIZEARG},
{"pidfile", 1, 0, PIDFILEARG},
{"blink",1,0,LOGSOCKETARG},
{"blinkid",1,0,LOGIDARG}
{"blinkid",1,0,LOGIDARG},
{"ether", 1, 0, 'e'},
};
progname=basename(argv[0]);
markov_resize(1);
setsighandlers();
atexit(cleanup);
ether_num_bytes = 0;
memset(ether_bytes, 0, sizeof(ether_bytes));
while(1) {
int c;
c = GETOPT_LONG (argc, argv, "hnl:d:M:D:m:b:s:c:v:L:f:",
c = GETOPT_LONG (argc, argv, "hnl:d:M:D:m:b:s:c:v:L:f:e:",
long_options, &option_index);
if (c<0)
break;
......
case 'N':
nofifo=1;
break;
case 'e':
sscanf(optarg,"%2hhx%2hhx", &ether_type[0], &ether_type[1]);
ptr = optarg;
for (n = 0; n < sizeof(ether_bytes); n++) {
ptr = strchr(ptr, ':');
if (!ptr)
break;
ptr++;
sscanf(ptr, "%hhx", &ether_bytes[n]);
ether_num_bytes++;
}
break;
case 'v':
{
char *colon;
(5-5/8)