From f120c0c85091757b4ade3e4c91c2c7a5fed60033 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Tue, 17 Aug 1999 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1999-08-17 --- ip/devip.c | 11 +++++++++++ ip/gre.c | 2 +- ip/icmp.c | 8 ++++---- ip/igmp.c | 2 +- ip/il.c | 10 ++++++---- ip/ip.c | 5 +++-- ip/ip.h | 4 +++- ip/ipmux.c | 2 +- ip/rudp.c | 10 +++++----- ip/tcp.c | 8 ++++---- ip/udp.c | 2 +- 11 files changed, 40 insertions(+), 24 deletions(-) diff --git a/ip/devip.c b/ip/devip.c index 54226e77c43f00b8b9f70dc993645ab95f3ebd9d..e061ee4c92cdb07823302ae2eed990e5a67d9ed0 100644 --- a/ip/devip.c +++ b/ip/devip.c @@ -848,6 +848,15 @@ bindctlmsg(Proto *x, Conv *c, Cmdbuf *cb) error(p); } +static void +tosctlmsg(Conv *c, Cmdbuf *cb) +{ + if(cb->nf < 2) + c->tos = 0; + else + c->tos = atoi(cb->f[1]); +} + static void ttlctlmsg(Conv *c, Cmdbuf *cb) { @@ -917,6 +926,8 @@ ipwrite(Chan* ch, void *v, long n, vlong) bindctlmsg(x, c, cb); else if(strcmp(cb->f[0], "ttl") == 0) ttlctlmsg(c, cb); + else if(strcmp(cb->f[0], "tos") == 0) + tosctlmsg(c, cb); else if(strcmp(cb->f[0], "addmulti") == 0){ if(cb->nf < 2) error("addmulti needs interface address"); diff --git a/ip/gre.c b/ip/gre.c index e180b56da71ed0dc65580c9da6262c6649fa8592..50b4036cfc40eed0902a60e339bccad8ec4aa084 100644 --- a/ip/gre.c +++ b/ip/gre.c @@ -160,7 +160,7 @@ grekick(Conv *c, int l) ghp->frag[0] = 0; ghp->frag[1] = 0; - ipoput(c->p->f, bp, 0, c->ttl); + ipoput(c->p->f, bp, 0, c->ttl, c->tos); } static void diff --git a/ip/icmp.c b/ip/icmp.c index c4fc421d931a71c73100e7356180bbeebe8a62a4..2b86688547fdc4e0344be83dabae13c5086e6564 100644 --- a/ip/icmp.c +++ b/ip/icmp.c @@ -171,7 +171,7 @@ icmpkick(Conv *c, int l) memset(p->cksum, 0, sizeof(p->cksum)); hnputs(p->cksum, ptclcsum(bp, ICMP_IPSIZE, blocklen(bp) - ICMP_IPSIZE)); ipriv->istats.icmpOutMsgs++; - ipoput(c->p->f, bp, 0, c->ttl); + ipoput(c->p->f, bp, 0, c->ttl, c->tos); } extern void @@ -197,7 +197,7 @@ icmpttlexceeded(Fs *f, uchar *ia, Block *bp) memset(np->cksum, 0, sizeof(np->cksum)); hnputs(np->cksum, ptclcsum(nbp, ICMP_IPSIZE, blocklen(nbp) - ICMP_IPSIZE)); /* stats.out[TimeExceed]++; */ - ipoput(f, nbp, 0, MAXTTL); + ipoput(f, nbp, 0, MAXTTL, DFLTTOS); } @@ -236,7 +236,7 @@ icmpnoconv(Fs *f, Block *bp) memset(np->cksum, 0, sizeof(np->cksum)); hnputs(np->cksum, ptclcsum(nbp, ICMP_IPSIZE, blocklen(nbp) - ICMP_IPSIZE)); /* stats.out[Unreachable]++; */ - ipoput(f, nbp, 0, MAXTTL); + ipoput(f, nbp, 0, MAXTTL, DFLTTOS); } static void @@ -333,7 +333,7 @@ icmpiput(Proto *icmp, uchar*, Block *bp) case EchoRequest: r = mkechoreply(bp); ipriv->out[EchoReply]++; - ipoput(icmp->f, r, 0, MAXTTL); + ipoput(icmp->f, r, 0, MAXTTL, DFLTTOS); break; case Unreachable: if(p->code > 5 || p->code < 0) diff --git a/ip/igmp.c b/ip/igmp.c index 136ad1933a6777a6ade0e15115bf870489f4dd37..54c7af97fa37addf5b3ccc421c1c559e5c878a15 100644 --- a/ip/igmp.c +++ b/ip/igmp.c @@ -96,7 +96,7 @@ igmpsendreport(Media *m, byte *addr) hnputs(p->igmpcksum, ptclcsum(bp, IGMP_IPHDRSIZE, IGMP_HDRSIZE)); netlog(Logigmp, "igmpreport %I\n", p->group); stats.outreports++; - ipoput(bp, 0, 1); /* TTL of 1 */ + ipoput(bp, 0, 1, DFLTTOS); /* TTL of 1 */ } static int diff --git a/ip/il.c b/ip/il.c index 25de193c9fbc99e15727e1c3ef45e905ad859a7a..2f0eb11049026e6e38b6d990d0992775f1806e11 100644 --- a/ip/il.c +++ b/ip/il.c @@ -353,7 +353,7 @@ ilkick(Conv *c, int l) if(later(msec, ic->timeout, nil)) ilsettimeout(ic); - ipoput(f, bp, 0, c->ttl); + ipoput(f, bp, 0, c->ttl, c->tos); } static void @@ -784,7 +784,7 @@ ilrexmit(Ilcb *ic) ilbackoff(ic); - ipoput(c->p->f, nb, 0, ic->conv->ttl); + ipoput(c->p->f, nb, 0, ic->conv->ttl, ic->conv->tos); /* statistics */ ic->rxtot++; @@ -938,7 +938,7 @@ ilsendctl(Conv *ipc, Ilhdr *inih, int type, ulong id, ulong ack, int ilspec) Ilhdr *ih; Ilcb *ic; Block *bp; - int ttl; + int ttl, tos; bp = allocb(IL_IPSIZE+IL_HDRSIZE); bp->wp += IL_IPSIZE+IL_HDRSIZE; @@ -958,6 +958,7 @@ ilsendctl(Conv *ipc, Ilhdr *inih, int type, ulong id, ulong ack, int ilspec) hnputl(ih->ilid, nhgetl(inih->ilack)); hnputl(ih->ilack, nhgetl(inih->ilid)); ttl = MAXTTL; + tos = DFLTTOS; } else { v6tov4(ih->dst, ipc->raddr); @@ -970,6 +971,7 @@ ilsendctl(Conv *ipc, Ilhdr *inih, int type, ulong id, ulong ack, int ilspec) ic->acksent = ack; ic->acktime = msec; ttl = ipc->ttl; + tos = ipc->tos; } ih->iltype = type; ih->ilspec = ilspec; @@ -983,7 +985,7 @@ ilsendctl(Conv *ipc, Ilhdr *inih, int type, ulong id, ulong ack, int ilspec) iltype[ih->iltype], nhgetl(ih->ilid), nhgetl(ih->ilack), nhgets(ih->ilsrc), nhgets(ih->ildst)); - ipoput(ipc->p->f, bp, 0, ttl); + ipoput(ipc->p->f, bp, 0, ttl, tos); } void diff --git a/ip/ip.c b/ip/ip.c index 8d0532f62951b9e4ab5583be183a484db81aa431..429cd381c89930a0ea5fd6052f4ca7f86ab99121 100644 --- a/ip/ip.c +++ b/ip/ip.c @@ -123,7 +123,7 @@ iprouting(Fs *f, int on) } void -ipoput(Fs *f, Block *bp, int gating, int ttl) +ipoput(Fs *f, Block *bp, int gating, int ttl, int tos) { Ipifc *ifc; uchar *gate; @@ -185,6 +185,7 @@ ipoput(Fs *f, Block *bp, int gating, int ttl) eh->tos = 0; } eh->ttl = ttl; + eh->tos = tos; if(!canrlock(ifc)) goto free; @@ -400,7 +401,7 @@ ipiput(Fs *f, uchar *ia, Block *bp) } ip->istats.ipForwDatagrams++; - ipoput(f, bp, 1, h->ttl - 1); + ipoput(f, bp, 1, h->ttl - 1, h->tos); return; } diff --git a/ip/ip.h b/ip/ip.h index 8456bd17123cb893622f58cefae4606173dc3015..4a693d0c34fb4ee256ae265cb5a6999216c334b5 100644 --- a/ip/ip.h +++ b/ip/ip.h @@ -31,6 +31,7 @@ enum MAClen= 16, /* longest mac address */ MAXTTL= 255, + DFLTTOS= 0, IPaddrlen= 16, IPv4addrlen= 4, @@ -69,6 +70,7 @@ struct Conv ushort lport; /* local port number */ ushort rport; /* remote port number */ uint ttl; /* max time to live */ + uint tos; /* type of service */ char owner[NAMELEN]; /* protections */ int perm; @@ -490,7 +492,7 @@ extern void initfrag(IP*, int); extern ushort ipcsum(uchar*); extern void (*ipextprotoiput)(Block*); extern void ipiput(Fs*, uchar*, Block*); -extern void ipoput(Fs*, Block*, int, int); +extern void ipoput(Fs*, Block*, int, int, int); extern int ipstats(Fs*, char*, int); extern ushort ptclbsum(uchar*, int); extern ushort ptclcsum(Block*, int, int); diff --git a/ip/ipmux.c b/ip/ipmux.c index 159c638e5b6c860077f9c95002f950143ae45ef0..a57a95ffd470cc853affddbfd125990d868418d4 100644 --- a/ip/ipmux.c +++ b/ip/ipmux.c @@ -639,7 +639,7 @@ ipmuxkick(Conv *c, int) ih = (Iphdr*)(bp->rp); - ipoput(c->p->f, bp, 0, ih->ttl); + ipoput(c->p->f, bp, 0, ih->ttl, ih->tos); } static void diff --git a/ip/rudp.c b/ip/rudp.c index 1fa81f5839aa4042afc021f5e5e83efe8bb5ce1d..3a6e6400539de751791ccff8aaa9355874d7b09e 100644 --- a/ip/rudp.c +++ b/ip/rudp.c @@ -296,7 +296,7 @@ rudpclose(Conv *c) * randomly don't send packets */ static void -doipoput(Conv *c, Fs *f, Block *bp, int x, int ttl) +doipoput(Conv *c, Fs *f, Block *bp, int x, int ttl, int tos) { Rudpcb *ucb; @@ -304,7 +304,7 @@ doipoput(Conv *c, Fs *f, Block *bp, int x, int ttl) if(ucb->randdrop && nrand(100) < ucb->randdrop) freeblist(bp); else - ipoput(f, bp, x, ttl); + ipoput(f, bp, x, ttl, tos); } int @@ -436,7 +436,7 @@ rudpkick(Conv *c, int) DPRINT("sent: %lud/%lud, %lud/%lud\n", r->sndseq, r->sndgen, r->rcvseq, r->rcvgen); - doipoput(c, f, bp, 0, c->ttl); + doipoput(c, f, bp, 0, c->ttl, c->tos); /* flow control of sorts */ qlock(&r->lock); @@ -952,7 +952,7 @@ relsendack(Conv *c, Reliable *r) hnputs(uh->udpcksum, ptclcsum(bp, UDP_IPHDR, UDP_RHDRSIZE)); DPRINT("sendack: %lud/%lud, %lud/%lud\n", 0L, r->sndgen, r->rcvseq, r->rcvgen); - doipoput(c, f, bp, 0, c->ttl); + doipoput(c, f, bp, 0, c->ttl, c->tos); } /* @@ -1009,5 +1009,5 @@ relrexmit(Conv *c, Reliable *r) upriv->rxmits++; np = copyblock(r->unacked, blocklen(r->unacked)); DPRINT("rxmit r->ackrvcd+1 = %lud\n", r->ackrcvd+1); - doipoput(c, f, np, 0, c->ttl); + doipoput(c, f, np, 0, c->ttl, c->tos); } diff --git a/ip/tcp.c b/ip/tcp.c index 3ae52523141a068f2591e389ada4e580f50fb126..815887ad58c168133949a8b3c3902e9c75085fd8 100644 --- a/ip/tcp.c +++ b/ip/tcp.c @@ -885,7 +885,7 @@ sndrst(Proto *tcp, uchar *source, uchar *dest, ushort length, Tcp *seg) if(hbp == nil) return; - ipoput(tcp->f, hbp, 0, MAXTTL); + ipoput(tcp->f, hbp, 0, MAXTTL, DFLTTOS); } /* @@ -915,7 +915,7 @@ tcphangup(Conv *s) tcb->last_ack = tcb->rcv.nxt; hnputs(ph.tcplen, TCP_HDRSIZE); hbp = htontcp(&seg, nil, &tcb->protohdr); - ipoput(s->p->f, hbp, 0, s->ttl); + ipoput(s->p->f, hbp, 0, s->ttl, s->tos); } localclose(s, nil); poperror(); @@ -1773,7 +1773,7 @@ tcpoutput(Conv *s) tpriv->tstats.tcpOutSegs++; if(tcb->kacounter > 0) tcpgo(tpriv, &tcb->katimer); - ipoput(f, hbp, 0, s->ttl); + ipoput(f, hbp, 0, s->ttl, s->tos); } } @@ -1814,7 +1814,7 @@ tcpsendka(Conv *s) return; } - ipoput(s->p->f, hbp, 0, s->ttl); + ipoput(s->p->f, hbp, 0, s->ttl, s->tos); } /* diff --git a/ip/udp.c b/ip/udp.c index dff93c9ab5210614c155861e48ca0a2985d108ce..8d2d0c57cca73ae5214120bccc882dc23337c3b9 100644 --- a/ip/udp.c +++ b/ip/udp.c @@ -226,7 +226,7 @@ udpkick(Conv *c, int) hnputs(uh->udpcksum, ptclcsum(bp, UDP_IPHDR, dlen+UDP_HDRSIZE)); upriv->ustats.udpOutDatagrams++; - ipoput(f, bp, 0, c->ttl); + ipoput(f, bp, 0, c->ttl, c->tos); } void