summaryrefslogtreecommitdiff
path: root/sys/src
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2018-05-10 19:38:01 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2018-05-10 19:38:01 +0200
commitfcb974af3a3b9747083b618fb6be7a4e70df3201 (patch)
tree9929998eeee52bb92659ec1ec2ae8677be02ceb8 /sys/src
parent0e5888a0cf993c89e4d52fd80b07990993e5abac (diff)
parenteb3951bcd48399d4d7239a9d396a113e95e38be9 (diff)
merge
Diffstat (limited to 'sys/src')
-rw-r--r--sys/src/9/ip/arp.c2
-rw-r--r--sys/src/9/ip/ip.c5
-rw-r--r--sys/src/9/ip/ip.h7
-rw-r--r--sys/src/9/ip/ipifc.c59
-rw-r--r--sys/src/9/ip/ipv6.c5
-rw-r--r--sys/src/cmd/ip/ipconfig/main.c5
-rw-r--r--sys/src/cmd/ip/linklocal.c2
-rw-r--r--sys/src/cmd/ip/ppp/ppp.c17
-rw-r--r--sys/src/cmd/ip/pppoe.c10
9 files changed, 93 insertions, 19 deletions
diff --git a/sys/src/9/ip/arp.c b/sys/src/9/ip/arp.c
index 12cb42fd1..03897c705 100644
--- a/sys/src/9/ip/arp.c
+++ b/sys/src/9/ip/arp.c
@@ -303,7 +303,7 @@ arpenter(Fs *fs, int version, uchar *ip, uchar *mac, int n, uchar *ia, Ipifc *if
freeblistchain(next);
break;
}
- ifc->m->bwrite(ifc, concatblock(bp), version, ip);
+ ipifcoput(ifc, bp, version, ip);
poperror();
}
return 1;
diff --git a/sys/src/9/ip/ip.c b/sys/src/9/ip/ip.c
index 7166619dd..f1cd74c10 100644
--- a/sys/src/9/ip/ip.c
+++ b/sys/src/9/ip/ip.c
@@ -180,6 +180,7 @@ ipoput4(Fs *f, Block *bp, int gating, int ttl, int tos, Routehint *rh)
runlock(ifc);
nexterror();
}
+
if(ifc->m == nil)
goto raise;
@@ -196,7 +197,7 @@ ipoput4(Fs *f, Block *bp, int gating, int ttl, int tos, Routehint *rh)
eh->cksum[0] = 0;
eh->cksum[1] = 0;
hnputs(eh->cksum, ipcsum(&eh->vihl));
- ifc->m->bwrite(ifc, concatblock(bp), V4, gate);
+ ipifcoput(ifc, bp, V4, gate);
runlock(ifc);
poperror();
return 0;
@@ -280,7 +281,7 @@ if((eh->frag[0] & (IP_DF>>8)) && !gating) print("%V: DF set\n", eh->dst);
feh->cksum[0] = 0;
feh->cksum[1] = 0;
hnputs(feh->cksum, ipcsum(&feh->vihl));
- ifc->m->bwrite(ifc, nb, V4, gate);
+ ipifcoput(ifc, nb, V4, gate);
ip->stats[FragCreates]++;
}
ip->stats[FragOKs]++;
diff --git a/sys/src/9/ip/ip.h b/sys/src/9/ip/ip.h
index 84edd761e..de1908dcd 100644
--- a/sys/src/9/ip/ip.h
+++ b/sys/src/9/ip/ip.h
@@ -327,6 +327,12 @@ struct Ipifc
uchar recvra6; /* flag: recv router advs on this ifc */
Routerparams rp; /* router parameters as in RFC 2461, pp.40—43.
used only if node is router */
+
+ int speed; /* link speed in bits per second */
+ int delay; /* burst delay in ms */
+ int burst; /* burst delay in bytes */
+ int load; /* bytes in flight */
+ ulong ticks;
};
/*
@@ -652,6 +658,7 @@ extern Medium pktmedium;
*/
extern Medium* ipfindmedium(char *name);
extern void addipmedium(Medium *med);
+extern void ipifcoput(Ipifc *ifc, Block *bp, int version, uchar *ip);
extern int ipforme(Fs*, uchar *addr);
extern int ipismulticast(uchar *ip);
extern Ipifc* findipifc(Fs*, uchar *local, uchar *remote, int type);
diff --git a/sys/src/9/ip/ipifc.c b/sys/src/9/ip/ipifc.c
index 037f2abd9..d0d0557a9 100644
--- a/sys/src/9/ip/ipifc.c
+++ b/sys/src/9/ip/ipifc.c
@@ -250,7 +250,7 @@ ipifcunbind(Ipifc *ifc)
char sfixedformat[] = "device %s maxtu %d sendra %d recvra %d mflag %d oflag"
" %d maxraint %d minraint %d linkmtu %d reachtime %d rxmitra %d ttl %d routerlt"
-" %d pktin %lud pktout %lud errin %lud errout %lud\n";
+" %d pktin %lud pktout %lud errin %lud errout %lud speed %d delay %d\n";
char slineformat[] = " %-40I %-10M %-40I %-12lud %-12lud\n";
@@ -267,7 +267,8 @@ ipifcstate(Conv *c, char *state, int n)
ifc->rp.mflag, ifc->rp.oflag, ifc->rp.maxraint,
ifc->rp.minraint, ifc->rp.linkmtu, ifc->rp.reachtime,
ifc->rp.rxmitra, ifc->rp.ttl, ifc->rp.routerlt,
- ifc->in, ifc->out, ifc->inerr, ifc->outerr);
+ ifc->in, ifc->out, ifc->inerr, ifc->outerr,
+ ifc->speed, ifc->delay);
rlock(ifc);
for(lifc = ifc->lifc; lifc != nil && n > m; lifc = lifc->next)
@@ -309,6 +310,50 @@ ipifcinuse(Conv *c)
return ifc->m != nil;
}
+static void
+ipifcsetdelay(Ipifc *ifc, int delay)
+{
+ if(delay < 0)
+ delay = 0;
+ else if(delay > 1000)
+ delay = 1000;
+ ifc->delay = delay;
+ ifc->burst = ((vlong)delay * ifc->speed) / 8000;
+ if(ifc->burst < ifc->maxtu)
+ ifc->burst = ifc->maxtu;
+}
+
+static void
+ipifcsetspeed(Ipifc *ifc, int speed)
+{
+ if(speed < 0)
+ speed = 0;
+ ifc->speed = speed;
+ ifc->load = 0;
+ ipifcsetdelay(ifc, ifc->delay);
+}
+
+void
+ipifcoput(Ipifc *ifc, Block *bp, int version, uchar *ip)
+{
+ if(ifc->speed){
+ ulong now = MACHP(0)->ticks;
+ int dt = TK2MS(now - ifc->ticks);
+ ifc->ticks = now;
+ ifc->load -= ((vlong)dt * ifc->speed) / 8000;
+ if(ifc->load < 0 || dt < 0 || dt > 1000)
+ ifc->load = 0;
+ else if(ifc->load > ifc->burst){
+ freeblist(bp);
+ return;
+ }
+ }
+ bp = concatblock(bp);
+ ifc->load += BLEN(bp);
+ ifc->m->bwrite(ifc, bp, version, ip);
+}
+
+
/*
* called when a process writes to an interface's 'data'
*/
@@ -358,6 +403,8 @@ ipifccreate(Conv *c)
ifc->m = nil;
ifc->reflect = 0;
ifc->reassemble = 0;
+ ipifcsetspeed(ifc, 0);
+ ipifcsetdelay(ifc, 40);
}
/*
@@ -772,6 +819,14 @@ ipifcctl(Conv* c, char **argv, int argc)
return ipifcunbind(ifc);
else if(strcmp(argv[0], "mtu") == 0)
return ipifcsetmtu(ifc, argv, argc);
+ else if(strcmp(argv[0], "speed") == 0){
+ ipifcsetspeed(ifc, argc>1? atoi(argv[1]): 0);
+ return nil;
+ }
+ else if(strcmp(argv[0], "delay") == 0){
+ ipifcsetdelay(ifc, argc>1? atoi(argv[1]): 0);
+ return nil;
+ }
else if(strcmp(argv[0], "iprouting") == 0){
iprouting(c->p->f, argc>1? atoi(argv[1]): 1);
return nil;
diff --git a/sys/src/9/ip/ipv6.c b/sys/src/9/ip/ipv6.c
index aab473c87..6b6d4eeca 100644
--- a/sys/src/9/ip/ipv6.c
+++ b/sys/src/9/ip/ipv6.c
@@ -103,7 +103,7 @@ ipoput6(Fs *f, Block *bp, int gating, int ttl, int tos, Routehint *rh)
medialen = ifc->maxtu - ifc->m->hsize;
if(len <= medialen) {
hnputs(eh->ploadlen, len - IP6HDR);
- ifc->m->bwrite(ifc, concatblock(bp), V6, gate);
+ ipifcoput(ifc, bp, V6, gate);
runlock(ifc);
poperror();
return 0;
@@ -193,8 +193,7 @@ ipoput6(Fs *f, Block *bp, int gating, int ttl, int tos, Routehint *rh)
if(xp->rp == xp->wp)
xp = xp->next;
}
-
- ifc->m->bwrite(ifc, nb, V6, gate);
+ ipifcoput(ifc, nb, V6, gate);
ip->stats[FragCreates]++;
}
ip->stats[FragOKs]++;
diff --git a/sys/src/cmd/ip/ipconfig/main.c b/sys/src/cmd/ip/ipconfig/main.c
index e051821d9..b8899d06d 100644
--- a/sys/src/cmd/ip/ipconfig/main.c
+++ b/sys/src/cmd/ip/ipconfig/main.c
@@ -318,8 +318,7 @@ main(int argc, char **argv)
plan9 = 0;
break;
case 'h':
- snprint(conf.hostname, sizeof conf.hostname, "%s",
- EARGF(usage()));
+ snprint(conf.hostname, sizeof conf.hostname, "%s", EARGF(usage()));
sendhostname = 1;
break;
case 'm':
@@ -389,7 +388,7 @@ main(int argc, char **argv)
if(dondbconfig){
dodhcp = 0;
ndbconfig();
- return;
+ break;
}
doadd();
break;
diff --git a/sys/src/cmd/ip/linklocal.c b/sys/src/cmd/ip/linklocal.c
index afe86435b..9c5066d64 100644
--- a/sys/src/cmd/ip/linklocal.c
+++ b/sys/src/cmd/ip/linklocal.c
@@ -25,7 +25,7 @@ usage(void)
void
ea2eui64(uchar *lla, uchar *ea)
{
- *lla++ = *ea++ | V60globaladm; /* oui (company id) */
+ *lla++ = *ea++ ^ V60globaladm; /* oui (company id) */
*lla++ = *ea++; /* " */
*lla++ = *ea++; /* " */
*lla++ = 0xFF; /* mac-48 in eui-64 (sic) */
diff --git a/sys/src/cmd/ip/ppp/ppp.c b/sys/src/cmd/ip/ppp/ppp.c
index 650b75c3d..1225e8373 100644
--- a/sys/src/cmd/ip/ppp/ppp.c
+++ b/sys/src/cmd/ip/ppp/ppp.c
@@ -1497,7 +1497,7 @@ ppptimer(PPP *ppp)
}
static void
-setdefroute(char *net, Ipaddr gate)
+defroute(char *net, char *verb, Ipaddr gate, Ipaddr local)
{
int fd;
char path[128];
@@ -1506,7 +1506,10 @@ setdefroute(char *net, Ipaddr gate)
fd = open(path, ORDWR);
if(fd < 0)
return;
- fprint(fd, "add 0 0 %I", gate);
+ fprint(fd, "tag ppp");
+ if(primary)
+ fprint(fd, "%s 0.0.0.0 0.0.0.0 %I", verb, gate);
+ fprint(fd, "%s 0.0.0.0 0.0.0.0 %I %I 255.255.255.255", verb, gate, local);
close(fd);
}
@@ -1550,8 +1553,9 @@ ipopen(PPP *ppp)
close(cfd);
return "can't set addresses";
}
- if(primary)
- setdefroute(ppp->net, ppp->remote);
+ if(baud)
+ fprint(cfd, "speed %d", baud);
+ defroute(ppp->net, "add", ppp->remote, ppp->local);
ppp->ipfd = fd;
ppp->ipcfd = cfd;
@@ -1570,6 +1574,7 @@ ipopen(PPP *ppp)
/* we may have changed addresses */
if(ipcmp(ppp->local, ppp->curlocal) != 0 ||
ipcmp(ppp->remote, ppp->curremote) != 0){
+ defroute(ppp->net, "remove", ppp->curremote, ppp->curlocal);
snprint(buf, sizeof buf, "remove %I 255.255.255.255 %I",
ppp->curlocal, ppp->curremote);
if(fprint(ppp->ipcfd, "%s", buf) < 0)
@@ -1578,6 +1583,7 @@ ipopen(PPP *ppp)
ppp->local, ppp->remote, ppp->mtu-10);
if(fprint(ppp->ipcfd, "%s", buf) < 0)
syslog(0, "ppp", "can't %s: %r", buf);
+ defroute(ppp->net, "add", ppp->remote, ppp->local);
}
syslog(0, "ppp", "%I/%I -> %I/%I", ppp->curlocal, ppp->curremote,
ppp->local, ppp->remote);
@@ -2634,7 +2640,7 @@ usage(void)
void
main(int argc, char **argv)
{
- int mtu, baud, framing, user, mediain, mediaout, cfd;
+ int mtu, framing, user, mediain, mediaout, cfd;
Ipaddr ipaddr, remip;
char *dev, *modemcmd;
char net[128];
@@ -2654,7 +2660,6 @@ main(int argc, char **argv)
invalidate(remip);
mtu = Defmtu;
- baud = 0;
framing = 0;
setnetmtpt(net, sizeof(net), nil);
user = 0;
diff --git a/sys/src/cmd/ip/pppoe.c b/sys/src/cmd/ip/pppoe.c
index 34bfb00f9..8dd0f3638 100644
--- a/sys/src/cmd/ip/pppoe.c
+++ b/sys/src/cmd/ip/pppoe.c
@@ -29,11 +29,12 @@ int cookielen;
uchar etherdst[6];
int mtu = 1492;
int pktcompress, hdrcompress;
+char *baud;
void
usage(void)
{
- fprint(2, "usage: pppoe [-PdcC] [-A acname] [-S srvname] [-k keyspec] [-m mtu] [-x pppnet] [ether0]\n");
+ fprint(2, "usage: pppoe [-PdcC] [-A acname] [-S srvname] [-k keyspec] [-m mtu] [-b baud] [-x pppnet] [ether0]\n");
exits("usage");
}
@@ -76,6 +77,9 @@ main(int argc, char **argv)
case 'k':
keyspec = EARGF(usage());
break;
+ case 'b':
+ baud = EARGF(usage());
+ break;
case 'c':
pktcompress = 1;
break;
@@ -533,6 +537,10 @@ execppp(int fd)
argv[argc++] = "-d";
if(primary)
argv[argc++] = "-P";
+ if(baud){
+ argv[argc++] = "-b";
+ argv[argc++] = baud;
+ }
if(hdrcompress)
argv[argc++] = "-C";
if(pktcompress)