Article delegate-en/2419 of [1-5169] on the server localhost:119
  upper oldest olders older1 this newer1 newers latest
search
[Top/Up] [oldest] - [Older+chunk] - [Newer+chunk] - [newest + Check]
[Reference:<_A2391@delegate-en.ML_>]
Newsgroups: mail-lists.delegate-en

[DeleGate-En] Re: Problem using SOCKS-Server with a MASTER and UDP
24 Sep 2003 18:58:12 GMT feedback@delegate.org (Yutaka Sato)


Hi,

In message <_A2391@delegate-en.ML_> on 09/03/03(21:23:19)
you Torsten Gesang <pk4eqbdyi-q4vsjhqsirvr.ml@ml.delegate.org> wrote:
 |I encountered the following problem with delegate 8.5.9:
 |
 |When using delegate as SOCKS-Server with a MASTER, there is a client (aka 
 |"bloomberg") that uses UDP for it's communication over SOCKS. When this 
 |client tries to connect, the requests aren't forwarded to the master. I 
 |verified the functionality of the proxy-chain with yahoomessenger and several 
 |other clients. Is it a delegate's Problem or is the client using the proxy 
 |wrong?

Relaying "UDP ASSOCIATE" of SocksV5 between DeleGates chained by MASTER
or SOCKS parameter has not been supported.  I  implemented it as follows
and will include it into the next release.

Cheers,
Yutaka
--
  @ @ Yutaka Sato <y.sato@delegate.org> http://www.delegate.org/y.sato/
 ( - ) National Institute of Advanced Industrial Science and Technology (AIST)
_<   >_ 1-1-4 Umezono, Tsukuba, Ibaraki, 305-8568 Japan
Do the more with the less -- B. Fuller

diff -cr ../dist/delegate8.7.0/rary/socks5.c ./rary/socks5.c
*** ../dist/delegate8.7.0/rary/socks5.c	Wed Sep 10 13:37:00 2003
--- ./rary/socks5.c	Thu Sep 25 03:46:44 2003
***************
*** 100,105 ****
--- 100,111 ----
   */
  SOCKS_udpassoc(msock,me,rme)
  	VSAddr *me,*rme;
+ {
+ 	return SOCKS_udpassocX(NULL,msock,me,rme);
+ }
+ SOCKS_udpassocX(ctx,msock,me,rme)
+ 	void *ctx;
+ 	VSAddr *me,*rme;
  {	int sock;
  	unsigned char req[128],resp[128];
  	unsigned char *baddr,*bport;
***************
*** 135,140 ****
--- 141,153 ----
  	salen = VSA_atosa(&sab,socks_port,socks_host);
  	syslog_DEBUG("SocksV5_connect [%x]%s:%d ...\n",
  		VSA_addr(&sab),socks_host,socks_port);
+ 
+ 	if( ctx ){
+ 		char remote[128],local[128];
+ 		strcpy(local,"*:*");
+ 		sprintf(remote,"%s:%d",socks_host,socks_port);
+ 		sock = VSocket(ctx,"CNCT/SocksV5",sock,local,remote,"proto=socks");
+ 	}else
  	rcode = connect(sock,(SAP)&sab,salen);
  
  	req[0] = 5; /* VERSION */
***************
*** 442,450 ****
--- 455,467 ----
  #define S_CLNT	1
  #define S_SERV	2
  
+ /*
  static udp_relay_socks(ctx,cntlsock,clsock,clname,flags)
+ */
+ static udp_relay_socks(ctx,cntlsock,clsock,clname,flags,viaSocks)
  	void *ctx;
  	char *clname;
+ 	VSAddr *viaSocks;
  {	char clhost[512];
  	int clport;
  	unsigned char rbuf[8*1024],*data;
***************
*** 453,458 ****
--- 470,476 ----
  	int sockV[3],sockR[3],sentN[3],xi;
  	int ns;
  	VSAddr clnt,from,to;
+ 	VSAddr serv;
  	unsigned char *baddr,*bport;
  	int btype,bleng,clntleng;
  	int len,fromlen,tolen;
***************
*** 488,493 ****
--- 506,516 ----
  	}
  	sockV[S_SERV] = svsock;
  
+ 	if( viaSocks ){
+ 		if( SOCKS_udpassocX(ctx,svsock,viaSocks,&serv) < 0 )
+ 			return -1;
+ 	}
+ 
  	if( flags != 0 )
  		syslog_ERROR("UDP/SocksV5 flags=%X\n",flags);
  
***************
*** 532,537 ****
--- 555,570 ----
  			syslog_ERROR("## BAD CLIENT: %s %s\n",froms,clname);
  			continue;
  		}
+ 		if( viaSocks ){ /* relay SOCKS packet as is */
+ 			tolen = VSA_size(&serv);
+ 			wcc = sendto(svsock,rbuf,rcc,0,(SAP)&serv,tolen);
+ 			if( sentN[S_CLNT] == 0 ){
+ 				syslog_ERROR("C-S forw %d/%d > %s:%d\n",
+ 				wcc,rcc,VSA_ntoa(&serv),VSA_port(&serv));
+ 			}
+ 			sentN[S_CLNT] += wcc;
+ 			continue;
+ 		}
  		tolen = VSA_stosa(&to,AF_INET,&rbuf[4]);
  		syslog_ERROR("UDP/SocksV5 C-S %d ATYP[%d] > %s:%d\n",
  			rcc,rbuf[3],VSA_ntoa(&to),VSA_port(&to));
***************
*** 544,549 ****
--- 577,592 ----
  		fromlen = sizeof(VSAddr);
  		rcc = recvfrom(svsock,data,len,0,(SAP)&from,&fromlen);
  	SV2CL:
+ 		if( viaSocks ){ /* relay SOCKS packet as is */
+ 			clntleng = VSA_size(&clnt);
+ 			wcc = sendto(clsock,data,rcc,0,(SAP)&clnt,clntleng);
+ 			if( sentN[S_SERV] == 0 ){
+ 				syslog_ERROR("S-C forw %d/%d > %s:%d\n",
+ 				wcc,rcc,VSA_ntoa(&clnt),VSA_port(&clnt));
+ 			}
+ 			sentN[S_SERV] += rcc;
+ 			continue;
+ 		}
  		bleng = VSA_decomp(&from,&baddr,&btype,&bport);
  		syslog_DEBUG("UDP/SocksV5 S-C %d < %s:%d\n",rcc,
  			VSA_ntoa(&from),VSA_port(&from));
***************
*** 563,568 ****
--- 606,614 ----
  	}
  	syslog_ERROR("UDP/SocksV5 C-S:%d S-C:%d\n",
  		sentN[S_CLNT],sentN[S_SERV]);
+ 	if( viaSocks ){
+ 		SOCKS_udpclose(svsock);
+ 	}
  }
  
  static send_resp(tc,rep,bound)
***************
*** 615,620 ****
--- 661,667 ----
  	int ai;
  	char rhost[512];
  	int rport,viasocks;
+ 	VSAddr qp;
  	char *opt;
  
  	bound = "";
***************
*** 788,793 ****
--- 835,845 ----
  	    case 3: /* UDP ASSOCIATE */
  		bsock = -1;
  		opt = "protocol=udp,noreuseaddr";
+ 		if( viasocks = GetViaSocks(ctx,host,port) ){
+ 			sv1log("UDP ASSOC via upstream Socks: %s:%d\n",
+ 				host,port);
+ 			VSA_atosa(&qp,port,host);
+ 		}
  		if( bsock < 0 && port != 0 ){
  			sprintf(local,"%s:%d",host,port);
  			bsock = VSocket(ctx,"BIND/SocksV5",-1,local,"*:*",opt);
***************
*** 811,817 ****
--- 863,872 ----
  			sprintf(local,"%s:%d",host,port);
  		}
  		send_resp(tc,rep,bound=local);
+ 		/*
  		udp_relay_socks(ctx,fromcl,bsock,remote,Q_RSV);
+ 		*/
+ 		udp_relay_socks(ctx,fromcl,bsock,remote,Q_RSV,viasocks?&qp:0);
  		close(bsock);
  		break;
  
diff -cr ../dist/delegate8.7.0/src/delegated.c ./src/delegated.c
*** ../dist/delegate8.7.0/src/delegated.c	Tue Sep 16 08:26:25 2003
--- ./src/delegated.c	Thu Sep 25 03:46:09 2003
***************
*** 3736,3741 ****
--- 3736,3752 ----
  		goto EXIT;
  	}
  
+ 	/*
+ 	 * SERVER=socks MASTER=... SOCKS=-.- means using MASTER as SOCKS server
+ 	 */
+ 	if( strcaseeq(proto,"socks") ){
+ 		if( getEnv(P_MASTER) ){
+ 			if( getEnv(P_SOCKS) == 0 ){
+ 				scan_SOCKS(Conn,"-.-");
+ 			}
+ 		}
+ 	}
+ 
  	if( streq(proto,"http") || BORN_SPECIALIST == 0 ){
  		int size;
  		size = expand_stack(1024*1024);
diff -cr ../dist/delegate8.7.0/src/socks.c ./src/socks.c
*** ../dist/delegate8.7.0/src/socks.c	Fri Aug 22 17:50:51 2003
--- ./src/socks.c	Wed Sep 24 23:20:19 2003
***************
*** 210,219 ****
--- 210,228 ----
  socks_addservers(){
  	int sx;
  	char *host;
+ 	char *addr;
  
  	for( sx = 0; host = sockservs[sx].s_host; sx++ )
  	if( *host )
+ 	{
+ 		addr = gethostaddr(host);
+ 		if( addr == NULL )
+ 			addr = host;
+ 		SOCKS_addserv("*",0,addr,sockservs[sx].s_port);
+ 		/*
  		SOCKS_addserv("*",0,gethostaddr(host),sockservs[sx].s_port);
+ 		*/
+ 	}
  	return sx;
  }
  
***************
*** 558,563 ****
--- 567,573 ----
  
  	if( ibuf[0] == 5 ){
  		extern int IO_TIMEOUT;
+ 		socks_addservers();
  		return SOCKS_serverV5(Conn,FromC,ToC,IO_TIMEOUT*1000);
  	}
  	SocksV4_server(Conn,ToS,FromS,FromC,ToC);

  admin search upper oldest olders older1 this newer1 newers latest
[Top/Up] [oldest] - [Older+chunk] - [Newer+chunk] - [newest + Check]
@_@V