Project

General

Profile

vde2-2.3.2_colour.patch

updated patch to 2.3.2 - Martin Hundebøll, 01/11/2012 10:28 AM

Download (9.86 KB)

View differences:

vde2-2.3.2/src/vde_switch/port.c 2012-01-11 10:00:17.763662681 +0100
96 96
struct port {
97 97
	struct endpoint *ep;
98 98
	int flag;
99
	int colour;
99 100
	/* sender is already inside ms, but it needs one more memaccess */
100 101
	int (*sender)(int fd_ctl, int fd_data, void *packet, int len, int port);
101 102
	struct mod_support *ms;
......
153 154
				EVENTOUT(DBGPORTNEW,i);
154 155

  
155 156
				portv[i]=port;
157
				port->colour=0;
156 158
				port->ep=NULL;
157 159
				port->user=port->group=port->curuser=-1;
158 160
#ifdef FSTP
......
589 591
			register int i;
590 592
#ifndef VDE_PQ2
591 593
			for(i = 1; i < numports; i++)
592
				if((i != port) && (portv[i] != NULL))
594
				if((i != port) && (portv[i] != NULL) && (!(pflag & COLOURFUL_TAG) || portv[i]->colour != portv[port]->colour))
593 595
					SEND_PACKET_PORT(portv[i],i,packet,len);
594 596
#else
595 597
			void *tmpbuf=NULL;
596 598
			for(i = 1; i < numports; i++)
597
				if((i != port) && (portv[i] != NULL))
599
				if((i != port) && (portv[i] != NULL) && (!(pflag & COLOURFUL_TAG) || portv[i]->colour != portv[port]->colour))
598 600
					SEND_PACKET_PORT(portv[i],i,packet,len,&tmpbuf);
599 601
#endif
600 602
		} else { /* This is a switch, not a HUB! */
......
639 641
					register int i;
640 642
#ifndef VDE_PQ2
641 643
					ba_FORALL(vlant[vlan].bctag,numports,
642
							({if (i != port) SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
644
							({if (i != port && (!(pflag & COLOURFUL_TAG) || portv[i]->colour != portv[port]->colour)) SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
643 645
					packet=TAG2UNTAG(packet,len);
644 646
					ba_FORALL(vlant[vlan].bcuntag,numports,
645
							({if (i != port) SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
647
							({if (i != port && (!(pflag & COLOURFUL_TAG) || portv[i]->colour != portv[port]->colour)) SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
646 648
#else
647 649
					void *tmpbuft=NULL;
648 650
					void *tmpbufu=NULL;
649 651
					ba_FORALL(vlant[vlan].bctag,numports,
650
							({if (i != port) SEND_PACKET_PORT(portv[i],i,packet,len,&tmpbuft);}),i);
652
							({if (i != port && (!(pflag & COLOURFUL_TAG) || portv[i]->colour != portv[port]->colour)) SEND_PACKET_PORT(portv[i],i,packet,len,&tmpbuft);}),i);
651 653
					packet=TAG2UNTAG(packet,len);
652 654
					ba_FORALL(vlant[vlan].bcuntag,numports,
653
							({if (i != port) SEND_PACKET_PORT(portv[i],i,packet,len,&tmpbufu);}),i);
655
							({if (i != port && (!(pflag & COLOURFUL_TAG) || portv[i]->colour != portv[port]->colour)) SEND_PACKET_PORT(portv[i],i,packet,len,&tmpbufu);}),i);
654 656
#endif
655 657
				} else { /* untagged */
656 658
					register int i;
657 659
#ifndef VDE_PQ2
658 660
					ba_FORALL(vlant[vlan].bcuntag,numports,
659
							({if (i != port) SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
661
							({if (i != port && (!(pflag & COLOURFUL_TAG) || portv[i]->colour != portv[port]->colour)) SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
660 662
					packet=UNTAG2TAG(packet,vlan,len);
661 663
					ba_FORALL(vlant[vlan].bctag,numports,
662
							({if (i != port) SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
664
							({if (i != port && (!(pflag & COLOURFUL_TAG) || portv[i]->colour != portv[port]->colour)) SEND_PACKET_PORT(portv[i],i,packet,len);}),i);
663 665
#else
664 666
					void *tmpbufu=NULL;
665 667
					void *tmpbuft=NULL;
666 668
					ba_FORALL(vlant[vlan].bcuntag,numports,
667
							({if (i != port) SEND_PACKET_PORT(portv[i],i,packet,len,&tmpbufu);}),i);
669
							({if (i != port && (!(pflag & COLOURFUL_TAG) || portv[i]->colour != portv[port]->colour)) SEND_PACKET_PORT(portv[i],i,packet,len,&tmpbufu);}),i);
668 670
					packet=UNTAG2TAG(packet,vlan,len);
669 671
					ba_FORALL(vlant[vlan].bctag,numports,
670
							({if (i != port) SEND_PACKET_PORT(portv[i],i,packet,len,&tmpbuft);}),i);
672
							({if (i != port && (!(pflag & COLOURFUL_TAG) || portv[i]->colour != portv[port]->colour)) SEND_PACKET_PORT(portv[i],i,packet,len,&tmpbuft);}),i);
671 673
#endif
672 674
				}
673 675
			}
......
679 681
#ifndef VDE_PQ2
680 682
				if (tagged) {
681 683
					if (portv[tarport]->vlanuntag==vlan) { /* TAG->UNTAG */
682
						packet = TAG2UNTAG(packet,len);
683
						SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
684
						if (!(pflag & COLOURFUL_TAG) || portv[tarport]->colour != portv[port]->colour) {
685
							packet = TAG2UNTAG(packet,len);
686
							SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
687
						}
684 688
					} else {                               /* TAG->TAG */
685
						SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
689
						if (!(pflag & COLOURFUL_TAG) || portv[tarport]->colour != portv[port]->colour)
690
							SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
686 691
					}
687 692
				} else {
688 693
					if (portv[tarport]->vlanuntag==vlan) { /* UNTAG->UNTAG */
689
						SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
694
						if (!(pflag & COLOURFUL_TAG) || portv[tarport]->colour != portv[port]->colour)
695
							SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
690 696
					} else {                              /* UNTAG->TAG */
691
						packet = UNTAG2TAG(packet,vlan,len);
692
						SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
697
						if (!(pflag & COLOURFUL_TAG) || portv[tarport]->colour != portv[port]->colour) {
698
							packet = UNTAG2TAG(packet,vlan,len);
699
							SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
700
						}
693 701
					}
694 702
				}
695 703
#else
696 704
				if (tagged) {
697 705
					void *tmpbuf=NULL;
698 706
					if (portv[tarport]->vlanuntag==vlan) { /* TAG->UNTAG */
699
						packet = TAG2UNTAG(packet,len);
700
						SEND_PACKET_PORT(portv[tarport],tarport,packet,len,&tmpbuf);
707
						if (!(pflag & COLOURFUL_TAG) || portv[tarport]->colour != portv[port]->colour) {
708
							packet = TAG2UNTAG(packet,len);
709
							SEND_PACKET_PORT(portv[tarport],tarport,packet,len,&tmpbuf);
710
						}
701 711
					} else {                               /* TAG->TAG */
702
						SEND_PACKET_PORT(portv[tarport],tarport,packet,len,&tmpbuf);
712
						if (!(pflag & COLOURFUL_TAG) || portv[tarport]->colour != portv[port]->colour)
713
							SEND_PACKET_PORT(portv[tarport],tarport,packet,len,&tmpbuf);
703 714
					}
704 715
				} else {
705 716
					void *tmpbuf=NULL;
706 717
					if (portv[tarport]->vlanuntag==vlan) { /* UNTAG->UNTAG */
707
						SEND_PACKET_PORT(portv[tarport],tarport,packet,len,&tmpbuf);
718
						if (!(pflag & COLOURFUL_TAG) || portv[tarport]->colour != portv[port]->colour)
719
							SEND_PACKET_PORT(portv[tarport],tarport,packet,len,&tmpbuf);
708 720
					} else {                              /* UNTAG->TAG */
709
						packet = UNTAG2TAG(packet,vlan,len);
710
						SEND_PACKET_PORT(portv[tarport],tarport,packet,len,&tmpbuf);
721
						if (!(pflag & COLOURFUL_TAG) || portv[tarport]->colour != portv[port]->colour) {
722
							packet = UNTAG2TAG(packet,vlan,len);
723
							SEND_PACKET_PORT(portv[tarport],tarport,packet,len,&tmpbuf);
724
						}
711 725
					}
712 726
				}
713 727
#endif
......
722 736
{
723 737
	printoutc(fd,"Numports=%d",numports);
724 738
	printoutc(fd,"HUB=%s",(pflag & HUB_TAG)?"true":"false");
739
	printoutc(fd,"COLOURFUL=%s",(pflag & COLOURFUL_TAG)?"true":"false");
725 740
#ifdef PORTCOUNTERS
726 741
	printoutc(fd,"counters=true");
727 742
#else
......
921 936
}
922 937
#endif
923 938

  
939
static int portsetcolour(char *arg) 
940
{
941
	int port,colour; 
942
	if (sscanf(arg,"%i %i",&port,&colour) != 2) 
943
		return EINVAL; 
944
	if (port < 0 || port >= numports) 
945
		return EINVAL; 
946
	if (portv[port] == NULL) 
947
		return ENXIO; 
948
	portv[port]->colour= colour; 
949
	return 0; 
950
}
951

  
924 952
static char *port_getuser(uid_t uid)
925 953
{
926 954
	static char buf[6];
......
971 999
		printoutc(fd," IN:  pkts %10lld          bytes %20lld",portv[i]->pktsin,portv[i]->bytesin);
972 1000
		printoutc(fd," OUT: pkts %10lld          bytes %20lld",portv[i]->pktsout,portv[i]->bytesout);
973 1001
#endif
1002
		printoutc(fd," colour:   %10d",portv[i]->colour);
974 1003
		for (ep=portv[i]->ep; ep != NULL; ep=ep->next) {
975 1004
			printoutc(fd,"  -- endpoint ID %04d module %-12s: %s",ep->fd_ctl,
976 1005
					portv[i]->ms->modname,(ep->descr)?ep->descr:"no endpoint description");
......
1053 1082
#ifdef FSTP
1054 1083
		fstpshutdown();
1055 1084
#endif
1056
		portflag(P_SETFLAG,HUB_TAG);
1085
		portflag(P_ADDFLAG,HUB_TAG);
1057 1086
	} else
1058 1087
		portflag(P_CLRFLAG,HUB_TAG);
1059 1088
	return 0;
1060 1089
}
1061 1090

  
1091
static int portsetcolourful(int val) 
1092
{
1093
	if (val) {
1094
		portflag(P_ADDFLAG,COLOURFUL_TAG);
1095
	} else
1096
		portflag(P_CLRFLAG,COLOURFUL_TAG);
1097
	return 0;
1098
}
1099

  
1062 1100
static int portsetvlan(char *arg)
1063 1101
{
1064 1102
	int port,vlan;
......
1339 1377
	{"port/setnumports","N","set the number of ports",portsetnumports,INTARG},
1340 1378
	/*{"port/setmacaddr","MAC","set the switch MAC address",setmacaddr,STRARG},*/
1341 1379
	{"port/sethub","0/1","1=HUB 0=switch",portsethub,INTARG},
1380
	{"port/setcolourful","0/1","1=colourful 0=no colour",portsetcolourful,INTARG},
1342 1381
	{"port/setvlan","N VLAN","set port VLAN (untagged)",portsetvlan,STRARG},
1343 1382
	{"port/createauto","","create a port with an automatically allocated id (inactive|notallocatable)",portcreateauto,NOARG|WITHFILE},
1344 1383
	{"port/create","N","create the port N (inactive|notallocatable)",portcreate,INTARG},
......
1346 1385
	{"port/allocatable","N 0/1","Is the port allocatable as unnamed? 1=Y 0=N",portallocatable,STRARG},
1347 1386
	{"port/setuser","N user","access control: set user",portsetuser,STRARG},
1348 1387
	{"port/setgroup","N user","access control: set group",portsetgroup,STRARG},
1388
	{"port/setcolour","N COLOUR","change colour of port",portsetcolour,STRARG},
1349 1389
	{"port/epclose","N ID","remove the endpoint port N/id ID",epclose,STRARG},
1350 1390
#ifdef VDE_PQ2
1351 1391
	{"port/defqlen","LEN","set the default queue length for new ports",defqlen,INTARG},
vde2-2.3.2/src/vde_switch/port.h 2012-01-11 09:57:54.080058808 +0100
68 68
#define P_CLRFLAG 3
69 69

  
70 70
#define HUB_TAG 0x1
71
#define COLOURFUL_TAG 0x2
71 72

  
72 73
void port_init(int numports);
73 74