Plan 9 from Bell Labs’s /usr/web/sources/contrib/uriel/changes/2005/0907/1

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


Add -a option to trampoline between two different network addresses.
Change -m option to take netdir explicitly.  (See man page.)
 [rsc] --rw-rw-r-- M 284191 rsc sys 1199 Sep  7 10:54 sys/man/8/trampoline
	/n/sourcesdump/2005/0907/plan9/sys/man/8/trampoline:4,13 - 
	/n/sources/plan9/sys/man/8/trampoline:4,20
	  .SH SYNOPSIS
	  .B aux/trampoline
	  [
	- .B -m9
	+ .B -9
	  ]
	+ [
	+ .B -a
	+ .I altaddr
	+ ]
	+ [
	+ .B -m
	+ .I netdir
	+ ]
	  .I addr
	- .RI [ netdir ]
	  .SH DESCRIPTION
	  .I Trampoline
	  can be used in a service file (see
	/n/sourcesdump/2005/0907/plan9/sys/man/8/trampoline:20,35 - 
	/n/sources/plan9/sys/man/8/trampoline:27,48
	  .I addr
	  and copies data between that connection
	  and its own standard input and output.
	- Use the
	+ .PP
	+ The options are:
	+ .TP
	  .B -9
	- option if the connection carries only unencrypted 9P messages, to allow
	+ The connection carries only 9P messages.  In this case
	  .I trampoline
	- to size its buffer automatically.
	- .PP
	- Forwarding can be restricted to a particular calling machine,
	- using the
	- .B -m
	- option.
	+ will relay whole messages at a time.
	+ .TP
	+ .BI -a " altaddr
	+ Dial
	+ .I altaddr
	+ and relay between the two network connections,
	+ ignoring standard input and output.
	+ .TP
	+ .BI -m " netdir
	+ Restrict forwarding to particular machines.
	  .I Netdir
	  must be the incoming call directory.
	  .I Trampoline
	/n/sourcesdump/2005/0907/plan9/sys/man/8/trampoline:42,47 - 
	/n/sources/plan9/sys/man/8/trampoline:55,61
	  and the attribute
	  .BR trampok .
	  If no such entry is found, the call is rejected.
	+ .PD
	  .SH FILES
	  .TF /sys/log/trampoline
	  .TP
 [rsc] --rw-rw-r-- M 284191 glenda sys 3790 Sep  7 10:54 sys/src/cmd/aux/trampoline.c
	/n/sourcesdump/2005/0907/plan9/sys/src/cmd/aux/trampoline.c:27,56 - 
	/n/sources/plan9/sys/src/cmd/aux/trampoline.c:27,68
	  int		macok(char*);
	  
	  void
	+ usage(void)
	+ {
	+ 	fprint(2, "usage: trampoline [-9] [-a addr] [-m netdir] addr\n");
	+ 	exits("usage");
	+ }
	+ 
	+ void
	  main(int argc, char **argv)
	  {
	- 	int fd;
	- 	int checkmac = 0;
	- 	Endpoints *ep;
	- 	char *mac;
	+ 	char *altaddr, *checkmac, *mac;
	+ 	int fd, fd0, fd1;
	  	void (*x)(int, int);
	+ 	Endpoints *ep;
	  
	+ 	checkmac = nil;
	+ 	altaddr = nil;
	  	x = xfer;
	  	ARGBEGIN{
	- 	case 'm':
	- 		checkmac = 1;
	- 		break;
	  	case '9':
	  		x = xfer9p;
	  		break;
	+ 	case 'a':
	+ 		altaddr = EARGF(usage());
	+ 		break;
	+ 	case 'm':
	+ 		checkmac = EARGF(usage());
	+ 		break;
	+ 	default:
	+ 		usage();
	  	}ARGEND;
	  
	- 	if(argc < 1){
	- 		fprint(2, "usage: %s dialstring\n", argv0);
	- 		exits("usage");
	- 	}
	- 	if(checkmac && argc > 1){
	- 		ep = getendpoints(argv[1]);
	+ 	if(argc != 1)
	+ 		usage();
	+ 
	+ 	if(checkmac){
	+ 		ep = getendpoints(checkmac);
	  		mac = iptomac(ep->rsys, ep->net);
	  		if(!macok(mac)){
	  			syslog(0, "trampoline", "badmac %s from %s!%s for %s!%s on %s",
	/n/sourcesdump/2005/0907/plan9/sys/src/cmd/aux/trampoline.c:58,68 - 
	/n/sources/plan9/sys/src/cmd/aux/trampoline.c:70,88
	  			exits("bad mac");
	  		}
	  	}
	- 	fd = dial(argv[0], 0, 0, 0);
	- 	if(fd < 0){
	- 		fprint(2, "%s: dialing %s: %r\n", argv0, argv[0]);
	- 		exits("dial");
	+ 	
	+ 	fd0 = 0;
	+ 	fd1 = 1;
	+ 	if(altaddr){
	+ 		fd0 = dial(altaddr, 0, 0, 0);
	+ 		if(fd0 < 0)
	+ 			sysfatal("dial %s: %r", altaddr);
	+ 		fd1 = fd0;
	  	}
	+ 	fd = dial(argv[0], 0, 0, 0);
	+ 	if(fd < 0)
	+ 		sysfatal("dial %s: %r", argv[0]);
	+ 
	  	rfork(RFNOTEG);
	  	switch(fork()){
	  	case -1:
	/n/sourcesdump/2005/0907/plan9/sys/src/cmd/aux/trampoline.c:69,78 - 
	/n/sources/plan9/sys/src/cmd/aux/trampoline.c:89,98
	  		fprint(2, "%s: fork: %r\n", argv0);
	  		exits("dial");
	  	case 0:
	- 		(*x)(0, fd);
	+ 		(*x)(fd0, fd);
	  		break;
	  	default:
	- 		(*x)(fd, 1);
	+ 		(*x)(fd, fd1);
	  		break;
	  	}
	  	postnote(PNGROUP, getpid(), "die yankee pig dog");
 [sys] --rwxrwxr-x M 284191 glenda sys 83645 Sep  7 23:07 386/bin/aux/trampoline
	/sys/src/cmd/aux/trampoline.c:getendpoint
	/sys/src/cmd/aux/trampoline.c:getendpoints
	/sys/src/cmd/aux/trampoline.c:iptomac
	/sys/src/cmd/aux/trampoline.c:macok
	/sys/src/cmd/aux/trampoline.c:main
	/sys/src/cmd/aux/trampoline.c:usage
	/sys/src/cmd/aux/trampoline.c:xfer9p


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].