Project

General

Profile

vde2-2.2.3_colour.patch

Simon Wunderlich, 10/18/2009 03:54 PM

Download (6.84 KB)

View differences:

src/vde_switch/port.c
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 {
......
614 616
				if (tarport==port)
615 617
					return; /*do not loop!*/
616 618
				if (tagged) {
617
					if (portv[tarport]->vlanuntag==vlan) /* TAG->UNTAG */
618
						SEND_PACKET_PORT(portv[tarport],tarport,TAG2UNTAG(packet,len),len);
619
					else                               /* TAG->TAG */
620
						SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
619
					if (portv[tarport]->vlanuntag==vlan) { /* TAG->UNTAG */
620
 						if (!(pflag & COLOURFUL_TAG) || portv[tarport]->colour != portv[port]->colour)
621
							SEND_PACKET_PORT(portv[tarport],tarport,TAG2UNTAG(packet,len),len);
622
					} else {                               /* TAG->TAG */
623
 						if (!(pflag & COLOURFUL_TAG) || portv[tarport]->colour != portv[port]->colour)
624
							SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
625
					}
621 626
				} else {
622
					if (portv[tarport]->vlanuntag==vlan) /* UNTAG->UNTAG */
623
						SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
624
					else                               /* UNTAG->TAG */
625
						SEND_PACKET_PORT(portv[tarport],tarport,UNTAG2TAG(packet,vlan,len),len);
627
					if (portv[tarport]->vlanuntag==vlan) { /* UNTAG->UNTAG */
628
 						if (!(pflag & COLOURFUL_TAG) || portv[tarport]->colour != portv[port]->colour)
629
							SEND_PACKET_PORT(portv[tarport],tarport,packet,len);
630
					} else {                              /* UNTAG->TAG */
631
 						if (!(pflag & COLOURFUL_TAG) || portv[tarport]->colour != portv[port]->colour)
632
							SEND_PACKET_PORT(portv[tarport],tarport,UNTAG2TAG(packet,vlan,len),len);
633
					}
626 634
				}
627 635
			} /* if(BROADCAST) */
628 636
		} /* if(HUB) */
......
635 643
{
636 644
	printoutc(fd,"Numports=%d",numports);
637 645
	printoutc(fd,"HUB=%s",(pflag & HUB_TAG)?"true":"false");
646
	printoutc(fd,"COLOURFUL=%s",(pflag & COLOURFUL_TAG)?"true":"false");
638 647
#ifdef PORTCOUNTERS
639 648
	printoutc(fd,"counters=true");
640 649
#else
......
796 805
		return close_ep(port,id);
797 806
}
798 807

  
808
static int portsetcolour(char *arg)
809
{
810
	int port,colour;
811
	if (sscanf(arg,"%i %i",&port,&colour) != 2)
812
		return EINVAL;
813
	if (port < 0 || port >= numports)
814
		return EINVAL;
815
	if (portv[port] == NULL)
816
		return ENXIO;
817
	portv[port]->colour= colour;
818
	return 0;
819
}
799 820
static char *port_getuser(uid_t uid)
800 821
{
801 822
	static char buf[6];
......
846 867
		printoutc(fd," IN:  pkts %10lld          bytes %20lld",portv[i]->pktsin,portv[i]->bytesin);
847 868
		printoutc(fd," OUT: pkts %10lld          bytes %20lld",portv[i]->pktsout,portv[i]->bytesout);
848 869
#endif
870
		printoutc(fd," colour:   %10d",portv[i]->colour);
849 871
		for (ep=portv[i]->ep; ep != NULL; ep=ep->next) 
850 872
			printoutc(fd,"  -- endpoint ID %04d module %-12s: %s",ep->fd_ctl,
851 873
					portv[i]->ms->modname,(ep->descr)?ep->descr:"no endpoint description");
......
930 952
	return 0;
931 953
}
932 954

  
955
static int portsetcolourful(int val)
956
{
957
	if (val) {
958
		portflag(P_SETFLAG,COLOURFUL_TAG);
959
	} else
960
		portflag(P_CLRFLAG,COLOURFUL_TAG);
961
	return 0;
962
}
963

  
933 964
static int portsetvlan(char *arg)
934 965
{
935 966
	int port,vlan;
......
1184 1215
	{"port/setnumports","N","set the number of ports",portsetnumports,INTARG},
1185 1216
	/*{"port/setmacaddr","MAC","set the switch MAC address",setmacaddr,STRARG},*/
1186 1217
	{"port/sethub","0/1","1=HUB 0=switch",portsethub,INTARG},
1218
	{"port/setcolourful","0/1","1=colourful 0=no colour",portsetcolourful,INTARG},
1187 1219
	{"port/setvlan","N VLAN","set port VLAN (untagged)",portsetvlan,STRARG},
1188 1220
	{"port/create","N","create the port N (inactive|notallocatable)",portcreate,INTARG},
1189 1221
	{"port/remove","N","remove the port N",portremove,INTARG},
1190 1222
	{"port/allocatable","N 0/1","Is the port allocatable as unnamed? 1=Y 0=N",portallocatable,STRARG},
1191 1223
	{"port/setuser","N user","access control: set user",portsetuser,STRARG},
1192 1224
	{"port/setgroup","N user","access control: set group",portsetgroup,STRARG},
1225
	{"port/setcolour","N COLOUR","change colour of port",portsetcolour,STRARG},
1193 1226
	{"port/epclose","N ID","remove the endpoint port N/id ID",epclose,STRARG},
1194 1227
#ifdef PORTCOUNTERS
1195 1228
	{"port/resetcounter","[N]","reset the port (N) counters",portresetcounters,STRARG},
src/vde_switch/port.h
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