Project

General

Profile

vde2-2.3.1_colour.patch

updated patch from Martin Hundebøll - thx - Simon Wunderlich, 03/17/2011 03:17 PM

Download (6.99 KB)

View differences:

vde2-2.3.1/src/vde_switch/port.c 2011-03-17 11:54:46.000000000 +0100
91 91
	int fd_data;
92 92
	struct endpoint *ep;
93 93
	int flag;
94
    int colour;
94 95
	/* sender is already inside ms, but it needs one more memaccess */
95 96
	int (*sender)(int fd, int fd_ctl, void *packet, int len, void *data, int port);
96 97
	struct mod_support *ms;
......
148 149
				EVENTOUT(DBGPORTNEW,i);
149 150

  
150 151
				portv[i]=port;
152
				port->colour=0;
151 153
				port->fd_data=-1;
152 154
				port->ep=NULL;
153 155
				port->user=port->group=port->curuser=-1;
......
552 554
		if (pflag & HUB_TAG) { /* this is a HUB */
553 555
			register int i;
554 556
			for(i = 1; i < numports; i++)
555
				if((i != port) && (portv[i] != NULL))
557
				if((i != port) && (portv[i] != NULL) && (!(pflag & COLOURFUL_TAG) || portv[i]->colour != portv[port]->colour))
556 558
					SEND_PACKET_PORT(portv[i],i,packet,len);
557 559
		} else { /* This is a switch, not a HUB! */
558 560
			if (packet->header.proto[0] == 0x81 && packet->header.proto[1] == 0x00) {
......
595 597
				if (tagged) {
596 598
					register int i;
597 599
					ba_FORALL(vlant[vlan].bctag,numports,
598
							({if (i != port) SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
600
							({if (i != port && (!(pflag & COLOURFUL_TAG) || portv[i]->colour != portv[port]->colour)) SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
599 601
					packet=TAG2UNTAG(packet,len);
600 602
					ba_FORALL(vlant[vlan].bcuntag,numports,
601
							({if (i != port) SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
603
							({if (i != port && (!(pflag & COLOURFUL_TAG) || portv[i]->colour != portv[port]->colour)) SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
602 604
				} else { /* untagged */
603 605
					register int i;
604 606
					ba_FORALL(vlant[vlan].bcuntag,numports,
605
							({if (i != port) SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
607
							({if (i != port && (!(pflag & COLOURFUL_TAG) || portv[i]->colour != portv[port]->colour)) SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
606 608
					packet=UNTAG2TAG(packet,vlan,len);
607 609
					ba_FORALL(vlant[vlan].bctag,numports,
608
							({if (i != port) SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
610
							({if (i != port && (!(pflag & COLOURFUL_TAG) || portv[i]->colour != portv[port]->colour)) SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
609 611
				}
610 612
			}
611 613
			else {
......
615 617
					return; /*do not loop!*/
616 618
				if (tagged) {
617 619
					if (portv[tarport]->vlanuntag==vlan) { /* TAG->UNTAG */
618
						packet = TAG2UNTAG(packet,len);
619
						SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
620
						if (!(pflag & COLOURFUL_TAG) || portv[tarport]->colour != portv[port]->colour) {
621
							packet = TAG2UNTAG(packet,len);
622
							SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
623
						}
620 624
					} else {                               /* TAG->TAG */
621
						SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
625
						if (!(pflag & COLOURFUL_TAG) || portv[tarport]->colour != portv[port]->colour)
626
							SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
622 627
					}
623 628
				} else {
624 629
					if (portv[tarport]->vlanuntag==vlan) { /* UNTAG->UNTAG */
625
						SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
630
						if (!(pflag & COLOURFUL_TAG) || portv[tarport]->colour != portv[port]->colour)
631
							SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
626 632
					} else {                              /* UNTAG->TAG */
627
						packet = UNTAG2TAG(packet,vlan,len);
628
						SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
633
						if (!(pflag & COLOURFUL_TAG) || portv[tarport]->colour != portv[port]->colour) {
634
							packet = UNTAG2TAG(packet,vlan,len);
635
							SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
636
						}
629 637
					}
630 638
				}
631 639
			} /* if(BROADCAST) */
......
639 647
{
640 648
	printoutc(fd,"Numports=%d",numports);
641 649
	printoutc(fd,"HUB=%s",(pflag & HUB_TAG)?"true":"false");
650
	printoutc(fd,"COLOURFUL=%s",(pflag & COLOURFUL_TAG)?"true":"false");
642 651
#ifdef PORTCOUNTERS
643 652
	printoutc(fd,"counters=true");
644 653
#else
......
814 823
		return close_ep(port,id);
815 824
}
816 825

  
826
static int portsetcolour(char *arg) 
827
{
828
	int port,colour; 
829
	if (sscanf(arg,"%i %i",&port,&colour) != 2) 
830
		return EINVAL; 
831
	if (port < 0 || port >= numports) 
832
		return EINVAL; 
833
	if (portv[port] == NULL) 
834
		return ENXIO; 
835
	portv[port]->colour= colour; 
836
	return 0; 
837
}
838

  
817 839
static char *port_getuser(uid_t uid)
818 840
{
819 841
	static char buf[6];
......
864 886
		printoutc(fd," IN:  pkts %10lld          bytes %20lld",portv[i]->pktsin,portv[i]->bytesin);
865 887
		printoutc(fd," OUT: pkts %10lld          bytes %20lld",portv[i]->pktsout,portv[i]->bytesout);
866 888
#endif
889
		printoutc(fd," colour:   %10d",portv[i]->colour);
867 890
		for (ep=portv[i]->ep; ep != NULL; ep=ep->next) 
868 891
			printoutc(fd,"  -- endpoint ID %04d module %-12s: %s",ep->fd_ctl,
869 892
					portv[i]->ms->modname,(ep->descr)?ep->descr:"no endpoint description");
......
948 971
	return 0;
949 972
}
950 973

  
974
static int portsetcolourful(int val) 
975
{
976
	if (val) {
977
		portflag(P_SETFLAG,COLOURFUL_TAG);
978
	} else
979
		portflag(P_CLRFLAG,COLOURFUL_TAG);
980
	return 0;
981
}
982

  
951 983
static int portsetvlan(char *arg)
952 984
{
953 985
	int port,vlan;
......
1202 1234
	{"port/setnumports","N","set the number of ports",portsetnumports,INTARG},
1203 1235
	/*{"port/setmacaddr","MAC","set the switch MAC address",setmacaddr,STRARG},*/
1204 1236
	{"port/sethub","0/1","1=HUB 0=switch",portsethub,INTARG},
1237
	{"port/setcolourful","0/1","1=colourful 0=no colour",portsetcolourful,INTARG},
1205 1238
	{"port/setvlan","N VLAN","set port VLAN (untagged)",portsetvlan,STRARG},
1206 1239
	{"port/createauto","","create a port with an automatically allocated id (inactive|notallocatable)",portcreateauto,NOARG|WITHFILE},
1207 1240
	{"port/create","N","create the port N (inactive|notallocatable)",portcreate,INTARG},
......
1209 1242
	{"port/allocatable","N 0/1","Is the port allocatable as unnamed? 1=Y 0=N",portallocatable,STRARG},
1210 1243
	{"port/setuser","N user","access control: set user",portsetuser,STRARG},
1211 1244
	{"port/setgroup","N user","access control: set group",portsetgroup,STRARG},
1245
	{"port/setcolour","N COLOUR","change colour of port",portsetcolour,STRARG},
1212 1246
	{"port/epclose","N ID","remove the endpoint port N/id ID",epclose,STRARG},
1213 1247
#ifdef PORTCOUNTERS
1214 1248
	{"port/resetcounter","[N]","reset the port (N) counters",portresetcounters,STRARG},
vde2-2.3.1/src/vde_switch/port.h 2011-03-17 11:54:46.000000000 +0100
62 62
#define P_CLRFLAG 3
63 63

  
64 64
#define HUB_TAG 0x1
65
#define COLOURFUL_TAG 0x2
65 66

  
66 67
void port_init(int numports);
67 68