From: Axel Belinfante <Axel.Belinfante@cs.utwente.nl>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] fs error msg: didn't like (1460 274) byte message
Date: Wed, 25 Sep 2002 20:19:06 +0200 [thread overview]
Message-ID: <200209251819.g8PIJ6B28388@zamenhof.cs.utwente.nl> (raw)
In-Reply-To: Your message of "Tue, 24 Sep 2002 19:42:24 -0400." <b725e9c5d41e55c4280f3e5db5bb3bd3@plan9.bell-labs.com>
[-- Attachment #1: Type: text/plain, Size: 625 bytes --]
Russ,
I'm not sure why your version fails (in the way I wrote before),
I assume it has something to do with reading/parsing the 9p format.
I rewrote your trampoline.c using read9pmsg. Now it seems to work.
My version follows below.
However, could you please check (improve) the buffer allocation (size)?
I just copied the constant 8192+IOHDRSZ from /sys/src/lib9p/srv.c
but I don't trust I got it correct (rephrased: is this the biggest
buffer we might need, or might we need more?). (too lazy to read the man).
I also put in some syslog debugging code that probably should
be en/disabled with a -d flag.
Axel.
[-- Attachment #2: trampoline.c --]
[-- Type: text/plain , Size: 4041 bytes --]
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <ndb.h>
#include <fcall.h>
enum
{
Maxpath= 128,
};
typedef struct Endpoints Endpoints;
struct Endpoints
{
char *net;
char *lsys;
char *lserv;
char *rsys;
char *rserv;
};
void xfer(int, int);
void xfer9p(int, int);
Endpoints* getendpoints(char*);
void freeendpoints(Endpoints*);
char* iptomac(char*, char*);
int macok(char*);
void
main(int argc, char **argv)
{
int fd;
int checkmac = 0;
Endpoints *ep;
char *mac;
void (*x)(int, int);
x = xfer;
ARGBEGIN{
case 'm':
checkmac = 1;
break;
case '9':
x = xfer9p;
break;
}ARGEND;
if (x == xfer9p)
syslog(0, "trampoline", "using xfer9p");
else
syslog(0, "trampoline", "using xfer");
if(argc < 1){
fprint(2, "usage: %s dialstring\n", argv0);
exits("usage");
}
if(checkmac && argc > 1){
ep = getendpoints(argv[1]);
mac = iptomac(ep->rsys, ep->net);
if(!macok(mac)){
syslog(0, "trampoline", "badmac %s from %s!%s for %s!%s on %s",
mac, ep->rsys, ep->rserv, ep->lsys, ep->lserv, ep->net);
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");
}
rfork(RFNOTEG);
switch(fork()){
case -1:
fprint(2, "%s: fork: %r\n", argv0);
exits("dial");
case 0:
(*x)(0, fd);
break;
default:
(*x)(fd, 1);
break;
}
postnote(PNGROUP, getpid(), "die yankee pig dog");
exits(0);
}
void
xfer(int from, int to)
{
char buf[12*1024];
int n;
while((n = read(from, buf, sizeof buf)) > 0)
if(write(to, buf, n) < 0)
break;
}
void
xfer9p(int from, int to)
{
char *buf;
uint nbuf;
int n, m;
nbuf = 8192+IOHDRSZ;
buf = malloc(nbuf);
if(buf == nil)
sysfatal("xfer: malloc %ud: %r", nbuf);
for(;;){
if((n = read9pmsg(from, buf, nbuf)) <= 0){
syslog(0, "trampoline", "read error (%d->%d): n=%d", from, to, n);
break;
} else
syslog(0, "trampoline", "read ok (%d->%d): n=%d", from, to, n);
if((m = write(to, buf, n)) != n) {
syslog(0, "trampoline", "write error (%d->%d): (m=%d) !=(n=%d)", from, to, m, n);
break;
} else {
syslog(0, "trampoline", "write ok (%d->%d): (m=%d) == (n=%d)", from, to, m, n);
}
}
}
void
getendpoint(char *dir, char *file, char **sysp, char **servp)
{
int fd, n;
char buf[Maxpath];
char *sys, *serv;
sys = serv = 0;
snprint(buf, sizeof buf, "%s/%s", dir, file);
fd = open(buf, OREAD);
if(fd >= 0){
n = read(fd, buf, sizeof(buf)-1);
if(n>0){
buf[n-1] = 0;
serv = strchr(buf, '!');
if(serv){
*serv++ = 0;
serv = strdup(serv);
}
sys = strdup(buf);
}
close(fd);
}
if(serv == 0)
serv = strdup("unknown");
if(sys == 0)
sys = strdup("unknown");
*servp = serv;
*sysp = sys;
}
Endpoints *
getendpoints(char *dir)
{
Endpoints *ep;
char *p;
ep = malloc(sizeof(*ep));
ep->net = strdup(dir);
p = strchr(ep->net+1, '/');
if(p == nil){
free(ep->net);
ep->net = "/net";
} else
*p = 0;
getendpoint(dir, "local", &ep->lsys, &ep->lserv);
getendpoint(dir, "remote", &ep->rsys, &ep->rserv);
return ep;
}
void
freeendpoints(Endpoints *ep)
{
free(ep->lsys);
free(ep->rsys);
free(ep->lserv);
free(ep->rserv);
free(ep);
}
char*
iptomac(char *ip, char *net)
{
char file[Maxpath];
Biobuf *b;
char *p;
char *f[5];
snprint(file, sizeof(file), "%s/arp", net);
b = Bopen(file, OREAD);
if(b == nil)
return nil;
while((p = Brdline(b, '\n')) != nil){
p[Blinelen(b)-1] = 0;
if(tokenize(p, f, nelem(f)) < 4)
continue;
if(strcmp(f[1], "OK") == 0
&& strcmp(f[2], ip) == 0){
p = strdup(f[3]);
Bterm(b);
return p;
}
}
Bterm(b);
return nil;
}
int
macok(char *mac)
{
Ndbtuple *tp;
char buf[Ndbvlen];
if(mac == nil)
return 0;
tp = csgetval("/net", "ether", mac, "trampok", buf);
if(tp == nil)
return 0;
ndbfree(tp);
return 1;
}
next prev parent reply other threads:[~2002-09-25 18:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-09-24 23:42 Russ Cox
2002-09-25 11:45 ` Axel Belinfante
2002-09-25 18:19 ` Axel Belinfante [this message]
-- strict thread matches above, loose matches on Subject: below --
2002-09-25 21:30 Russ Cox
2002-09-26 8:49 ` Axel Belinfante
2002-09-25 21:21 Russ Cox
2002-09-25 18:24 Russ Cox
2002-09-25 18:44 ` Axel Belinfante
2002-09-25 21:12 ` Axel Belinfante
2002-09-24 23:25 Axel Belinfante
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200209251819.g8PIJ6B28388@zamenhof.cs.utwente.nl \
--to=axel.belinfante@cs.utwente.nl \
--cc=9fans@cse.psu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).