diff options
Diffstat (limited to 'os/ip')
| -rw-r--r-- | os/ip/devip.c | 2 | ||||
| -rw-r--r-- | os/ip/ip.h | 1 | ||||
| -rw-r--r-- | os/ip/ipifc.c | 88 | ||||
| -rw-r--r-- | os/ip/iproute.c | 2 | ||||
| -rw-r--r-- | os/ip/ipv6.h | 14 | ||||
| -rw-r--r-- | os/ip/tcp.c | 72 |
6 files changed, 96 insertions, 83 deletions
diff --git a/os/ip/devip.c b/os/ip/devip.c index 8564e987..bb37d341 100644 --- a/os/ip/devip.c +++ b/os/ip/devip.c @@ -982,7 +982,6 @@ Fsstdannounce(Conv* c, char* argv[], int argc) case 2: return setladdrport(c, argv[1], 1); } - return nil; } /* @@ -1033,7 +1032,6 @@ Fsstdbind(Conv* c, char* argv[], int argc) case 2: return setladdrport(c, argv[1], 0); } - return nil; } static void @@ -669,5 +669,4 @@ extern Chan* chandial(char*, char*, char*, Chan**); /* * global to all of the stack */ -extern int debug; extern void (*igmpreportfn)(Ipifc*, uchar*); diff --git a/os/ip/ipifc.c b/os/ip/ipifc.c index 345c7404..a044a57e 100644 --- a/os/ip/ipifc.c +++ b/os/ip/ipifc.c @@ -11,11 +11,11 @@ #define DPRINT if(0)print enum { - Maxmedia = 32, - Nself = Maxmedia*5, - NHASH = (1<<6), - NCACHE = 256, - QMAX = 64*1024-1, + Maxmedia = 32, + Nself = Maxmedia*5, + NHASH = (1<<6), + NCACHE = 256, + QMAX = 64*1024-1, }; Medium *media[Maxmedia] = @@ -135,7 +135,7 @@ ipifcbind(Conv *c, char **argv, int argc) if(argc > 2) strncpy(ifc->dev, argv[2], sizeof(ifc->dev)); else - sprint(ifc->dev, "%s%d", m->name, c->x); + snprint(ifc->dev, sizeof ifc->dev, "%s%d", m->name, c->x); ifc->dev[sizeof(ifc->dev)-1] = 0; /* set up parameters */ @@ -144,15 +144,15 @@ ipifcbind(Conv *c, char **argv, int argc) ifc->maxtu = ifc->m->maxtu; if(ifc->m->unbindonclose == 0) ifc->conv->inuse++; - ifc->rp.mflag = 0; // default not managed - ifc->rp.oflag = 0; - ifc->rp.maxraint = 600000; // millisecs - ifc->rp.minraint = 200000; - ifc->rp.linkmtu = 0; // no mtu sent - ifc->rp.reachtime = 0; - ifc->rp.rxmitra = 0; - ifc->rp.ttl = MAXTTL; - ifc->rp.routerlt = 3*(ifc->rp.maxraint); + ifc->rp.mflag = 0; // default not managed + ifc->rp.oflag = 0; + ifc->rp.maxraint = 600000; // millisecs + ifc->rp.minraint = 200000; + ifc->rp.linkmtu = 0; // no mtu sent + ifc->rp.reachtime = 0; + ifc->rp.rxmitra = 0; + ifc->rp.ttl = MAXTTL; + ifc->rp.routerlt = 3*(ifc->rp.maxraint); /* any ancillary structures (like routes) no longer pertain */ ifc->ifcid++; @@ -229,7 +229,7 @@ ipifcstate(Conv *c, char *state, int n) ifc = (Ipifc*)c->ptcl; - m = snprint(state, n, sfixedformat, + m = snprint(state, n, sfixedformat, ifc->dev, ifc->maxtu, ifc->sendra6, ifc->recvra6, ifc->rp.mflag, ifc->rp.oflag, ifc->rp.maxraint, ifc->rp.minraint, ifc->rp.linkmtu, ifc->rp.reachtime, @@ -328,7 +328,7 @@ ipifccreate(Conv *c) ifc->reassemble = 0; } -/* +/* * called after last close of ipifc data or ctl * called with c locked, we must unlock */ @@ -424,7 +424,7 @@ ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp) /* ignore if this is already a local address for this ifc */ for(lifc = ifc->lifc; lifc; lifc = lifc->next) { if(ipcmp(lifc->local, ip) == 0) { - if(lifc->tentative != tentative) + if(lifc->tentative != tentative) lifc->tentative = tentative; if(lifcp != nil) { lifc->onlink = lifcp->onlink; @@ -506,7 +506,7 @@ ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp) addselfcache(f, ifc, lifc, bcast, Rbcast); addselfcache(f, ifc, lifc, IPv4bcast, Rbcast); - } + } else { if(ipcmp(ip, v6loopback) == 0) { /* add node-local mcast address */ @@ -535,7 +535,7 @@ ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp) out: wunlock(ifc); - if(tentative && sendnbrdisc) + if(tentative && sendnbrdisc) icmpns(f, 0, SRC_UNSPEC, ip, TARG_MULTI, ifc->mac); return nil; } @@ -721,29 +721,29 @@ ipifcsetpar6(Ipifc *ifc, char **argv, int argc) return Ebadarg; while (argsleft > 1) { - if(strcmp(argv[i],"recvra")==0) + if(strcmp(argv[i],"recvra")==0) ifc->recvra6 = (atoi(argv[i+1]) != 0); - else if(strcmp(argv[i],"sendra")==0) + else if(strcmp(argv[i],"sendra")==0) ifc->sendra6 = (atoi(argv[i+1]) != 0); - else if(strcmp(argv[i],"mflag")==0) + else if(strcmp(argv[i],"mflag")==0) ifc->rp.mflag = (atoi(argv[i+1]) != 0); - else if(strcmp(argv[i],"oflag")==0) + else if(strcmp(argv[i],"oflag")==0) ifc->rp.oflag = (atoi(argv[i+1]) != 0); else if(strcmp(argv[i],"maxraint")==0) ifc->rp.maxraint = atoi(argv[i+1]); else if(strcmp(argv[i],"minraint")==0) ifc->rp.minraint = atoi(argv[i+1]); - else if(strcmp(argv[i],"linkmtu")==0) + else if(strcmp(argv[i],"linkmtu")==0) ifc->rp.linkmtu = atoi(argv[i+1]); - else if(strcmp(argv[i],"reachtime")==0) + else if(strcmp(argv[i],"reachtime")==0) ifc->rp.reachtime = atoi(argv[i+1]); - else if(strcmp(argv[i],"rxmitra")==0) + else if(strcmp(argv[i],"rxmitra")==0) ifc->rp.rxmitra = atoi(argv[i+1]); - else if(strcmp(argv[i],"ttl")==0) + else if(strcmp(argv[i],"ttl")==0) ifc->rp.ttl = atoi(argv[i+1]); - else if(strcmp(argv[i],"routerlt")==0) + else if(strcmp(argv[i],"routerlt")==0) ifc->rp.routerlt = atoi(argv[i+1]); - else + else return Ebadarg; argsleft -= 2; @@ -778,7 +778,7 @@ ipifcrecvra6(Ipifc *ifc, char **argv, int argc) int i; i = 0; - if(argc > 1) + if(argc > 1) i = atoi(argv[1]); ifc->recvra6 = (i!=0); return nil; @@ -826,7 +826,7 @@ ipifcctl(Conv* c, char**argv, int argc) return ipifcaddpref6(ifc, argv, argc); else if(strcmp(argv[0], "setpar6") == 0) return ipifcsetpar6(ifc, argv, argc); - else if(strcmp(argv[0], "sendra6") == 0) + else if(strcmp(argv[0], "sendra6") == 0) return ipifcsendra6(ifc, argv, argc); else if(strcmp(argv[0], "recvra6") == 0) return ipifcrecvra6(ifc, argv, argc); @@ -1097,7 +1097,7 @@ ipselftabread(Fs *f, char *cp, ulong offset, int n) } int -iptentative(Fs *f, uchar *addr) +iptentative(Fs *f, uchar *addr) { Ipself *p; @@ -1210,8 +1210,8 @@ v6addrtype(uchar *addr) #define v6addrcurr(lifc) (( (lifc)->origint + (lifc)->preflt >= (NOW/10^3) ) || ( (lifc)->preflt == 0xffffffff )) -void -findprimaryip6(Fs *f, uchar *local) +static void +findprimaryipv6(Fs *f, uchar *local) { Conv **cp, **e; Ipifc *ifc; @@ -1231,7 +1231,7 @@ findprimaryip6(Fs *f, uchar *local) ifc = (Ipifc*)(*cp)->ptcl; for(lifc = ifc->lifc; lifc; lifc = lifc->next){ atypel = v6addrtype(lifc->local); - if(atypel > atype) + if(atypel > atype) if(v6addrcurr(lifc)) { ipmove(local, lifc->local); atype = atypel; @@ -1243,10 +1243,10 @@ findprimaryip6(Fs *f, uchar *local) } /* - * returns first ip address configured + * returns first ip address configured */ -void -findprimaryip(Fs *f, uchar *local) +static void +findprimaryipv4(Fs *f, uchar *local) { Conv **cp, **e; Ipifc *ifc; @@ -1258,7 +1258,7 @@ findprimaryip(Fs *f, uchar *local) if(*cp == 0) continue; ifc = (Ipifc*)(*cp)->ptcl; - for(lifc = ifc->lifc; lifc; lifc = lifc->next){ + if((lifc = ifc->lifc) != nil){ ipmove(local, lifc->local); return; } @@ -1329,10 +1329,10 @@ findlocalip(Fs *f, uchar *local, uchar *remote) switch(version){ case V4: - findprimaryip(f, local); + findprimaryipv4(f, local); break; case V6: - findprimaryip6(f, local); + findprimaryipv6(f, local); break; default: panic("findlocalip2: version %d", version); @@ -1642,7 +1642,7 @@ adddefroute6(Fs *f, uchar *gate, int force) Route *r; r = v6lookup(f, v6Unspecified, nil); - if(r!=nil) + if(r!=nil) if(!(force) && (strcmp(r->tag,"ra")!=0)) // route entries generated return; // by all other means take // precedence over router annc @@ -1705,7 +1705,7 @@ ipifcaddpref6(Ipifc *ifc, char**argv, int argc) lifc->preflt = preflt; lifc->origint = origint; - if(ifc->m->pref2addr!=nil) + if(ifc->m->pref2addr!=nil) ifc->m->pref2addr(prefix, ifc->mac); else return Ebadarg; diff --git a/os/ip/iproute.c b/os/ip/iproute.c index 3229435e..1888a89c 100644 --- a/os/ip/iproute.c +++ b/os/ip/iproute.c @@ -662,7 +662,7 @@ sprintroute(Route *r, Routewalk *rw) iname = "-"; if(nifc != -1) { iname = ifbuf; - sprint(ifbuf, "%d", nifc); + snprint(ifbuf, sizeof ifbuf, "%d", nifc); } p = seprint(rw->p, rw->e, rformat, addr, mask, gate, t, r->tag, iname); if(rw->o < 0){ diff --git a/os/ip/ipv6.h b/os/ip/ipv6.h index 8da63cfd..d0a06cf5 100644 --- a/os/ip/ipv6.h +++ b/os/ip/ipv6.h @@ -61,12 +61,12 @@ enum { /* Header Types */ RSVP = 46, AH = 51, ESP = 52, - ICMPv6 = 58, + ICMPv6 = 58, NNH = 59, DOH = 60, ISO_IP = 80, IGRP = 88, - OSPF = 89, + OSPF = 89, Maxhdrtype = 256, }; @@ -98,7 +98,7 @@ enum { // various flags & constants - v6MINTU = 1280, + v6MINTU = 1280, HOP_LIMIT = 255, ETHERHDR_LEN = 14, IPV6HDR_LEN = 40, @@ -113,7 +113,7 @@ enum { MTU_OPTION = 5, SRC_UNSPEC = 0, - SRC_UNI = 1, + SRC_UNI = 1, TARG_UNI = 2, TARG_MULTI = 3, @@ -124,7 +124,7 @@ enum { // Router constants (all times in milliseconds) MAX_INITIAL_RTR_ADVERT_INTERVAL = 16000, - MAX_INITIAL_RTR_ADVERTISEMENTS = 3, + MAX_INITIAL_RTR_ADVERTISEMENTS = 3, MAX_FINAL_RTR_ADVERTISEMENTS = 3, MIN_DELAY_BETWEEN_RAS = 3000, MAX_RA_DELAY_TIME = 500, @@ -140,9 +140,9 @@ enum { MAX_MULTICAST_SOLICIT = 3, MAX_UNICAST_SOLICIT = 3, MAX_ANYCAST_DELAY_TIME = 1000, - MAX_NEIGHBOR_ADVERTISEMENT = 3, + MAX_NEIGHBOR_ADVERTISEMENT = 3, REACHABLE_TIME = 30000, - RETRANS_TIMER = 1000, + RETRANS_TIMER = 1000, DELAY_FIRST_PROBE_TIME = 5000, }; diff --git a/os/ip/tcp.c b/os/ip/tcp.c index c2bf7274..c6e0a54f 100644 --- a/os/ip/tcp.c +++ b/os/ip/tcp.c @@ -54,7 +54,7 @@ enum TCP_CONNECT = 1, /* Outgoing connection */ SYNACK_RXTIMER = 250, /* ms between SYNACK retransmits */ - TCPREXMTTHRESH = 3, /* dupack threshhold for rxt */ + TCPREXMTTHRESH = 3, /* dupack threshhold for rxt */ FORCE = 1, CLONE = 2, @@ -285,7 +285,7 @@ struct Limbo }; int tcp_irtt = DEF_RTT; /* Initial guess at round trip time */ -ushort tcp_mss = DEF_MSS; /* Maximum segment size to be sent */ +ushort tcp_mss = DEF_MSS; /* Maximum segment size to be sent */ enum { /* MIB stats */ @@ -350,7 +350,7 @@ struct Tcppriv ulong stats[Nstats]; }; -/* +/* * Setting tcpporthogdefense to non-zero enables Dong Lin's * solution to hijacked systems staking out port's as a form * of DoS attack. @@ -375,7 +375,7 @@ void tcprcvwin(Conv*); void tcpacktimer(void*); void tcpkeepalive(void*); void tcpsetkacounter(Tcpctl*); -void tcprxmit(Conv*); +void tcprxmit(Conv*); void tcpsettimer(Tcpctl*); void tcpsynackrtt(Conv*); void tcpsetscale(Conv*, Tcpctl*, ushort, ushort); @@ -711,7 +711,7 @@ backoff(int n) } void -localclose(Conv *s, char *reason) /* called with tcb locked */ +localclose(Conv *s, char *reason) /* called with tcb locked */ { Tcpctl *tcb; Reseq *rp,*rp1; @@ -1804,8 +1804,8 @@ update(Conv *s, Tcp *seg) /* * update window */ - if( seq_gt(seg->ack, tcb->snd.wl2) - || (tcb->snd.wl2 == seg->ack && seg->wnd > tcb->snd.wnd)){ + if(seq_gt(seg->ack, tcb->snd.wl2) + || (tcb->snd.wl2 == seg->ack && seg->wnd > tcb->snd.wnd)){ tcb->snd.wnd = seg->wnd; tcb->snd.wl2 = seg->ack; } @@ -1821,9 +1821,9 @@ update(Conv *s, Tcp *seg) return; } - /* + /* * any positive ack turns off fast rxt, - * (should we do new-reno on partial acks?) + * (should we do new-reno on partial acks?) */ if(!tcb->snd.recovery || seq_ge(seg->ack, tcb->snd.rxt)) { tcb->snd.dupacks = 0; @@ -1925,7 +1925,7 @@ tcpiput(Proto *tcp, Ipifc*, Block *bp) f = tcp->f; tpriv = tcp->priv; - + tpriv->stats[InSegs]++; h4 = (Tcp4hdr*)(bp->rp); @@ -1939,7 +1939,7 @@ tcpiput(Proto *tcp, Ipifc*, Block *bp) h4->Unused = 0; hnputs(h4->tcplen, length-TCP4_PKT); - if(!(bp->flag & Btcpck) && (h4->tcpcksum[0] || h4->tcpcksum[1]) && + if(!(bp->flag & Btcpck) && (h4->tcpcksum[0] || h4->tcpcksum[1]) && ptclcsum(bp, TCP4_IPLEN, length-TCP4_IPLEN)) { tpriv->stats[CsumErrs]++; tpriv->stats[InErrs]++; @@ -1978,7 +1978,7 @@ tcpiput(Proto *tcp, Ipifc*, Block *bp) h6->ploadlen[0] = h6->ploadlen[1] = h6->proto = 0; h6->ttl = proto; hnputl(h6->vcf, length); - if((h6->tcpcksum[0] || h6->tcpcksum[1]) && + if((h6->tcpcksum[0] || h6->tcpcksum[1]) && ptclcsum(bp, TCP6_IPLEN, length+TCP6_PHDRSIZE)) { tpriv->stats[CsumErrs]++; tpriv->stats[InErrs]++; @@ -2277,7 +2277,7 @@ reset: qpassnolim(s->rq, bp); bp = nil; - /* + /* * Force an ack every 2 data messages. This is * a hack for rob to make his home system run * faster. @@ -2412,20 +2412,20 @@ tcpoutput(Conv *s) for(msgs = 0; msgs < 100; msgs++) { tcb = (Tcpctl*)s->ptcl; - + switch(tcb->state) { case Listen: case Closed: case Finwait2: return; } - + /* force an ack when a window has opened up */ if(tcb->rcv.blocked && tcb->rcv.wnd > 0){ tcb->rcv.blocked = 0; tcb->flags |= FORCE; } - + sndcnt = qlen(s->wq)+tcb->flgcnt; sent = tcb->snd.ptr - tcb->snd.una; @@ -2841,8 +2841,7 @@ int addreseq(Tcpctl *tcb, Tcppriv *tpriv, Tcp *seg, Block *bp, ushort length) { Reseq *rp, *rp1; - int i; - static int once; + int i, rqlen, qmax; rp = malloc(sizeof(Reseq)); if(rp == nil){ @@ -2864,9 +2863,9 @@ addreseq(Tcpctl *tcb, Tcppriv *tpriv, Tcp *seg, Block *bp, ushort length) return 0; } - length = 0; + rqlen = 0; for(i = 0;; i++) { - length += rp1->length; + rqlen += rp1->length; if(rp1->next == nil || seq_lt(seg->seq, rp1->next->seg.seq)) { rp->next = rp1->next; rp1->next = rp; @@ -2876,12 +2875,29 @@ addreseq(Tcpctl *tcb, Tcppriv *tpriv, Tcp *seg, Block *bp, ushort length) } rp1 = rp1->next; } - if(length > QMAX && once++ == 0){ - print("very long tcp resequence queue: %d\n", length); - for(rp1 = tcb->reseq, i = 0; i < 10 && rp1 != nil; rp1 = rp1->next, i++) - print("0x%lux 0x%lux 0x%ux\n", rp1->seg.seq, rp1->seg.ack, - rp1->seg.flags); - return -1; + qmax = QMAX<<tcb->rcv.scale; + if(rqlen > qmax){ + print("resequence queue > window: %d > %d\n", rqlen, qmax); + i = 0; + for(rp1 = tcb->reseq; rp1 != nil; rp1 = rp1->next){ + print("%#lux %#lux %#ux\n", rp1->seg.seq, + rp1->seg.ack, rp1->seg.flags); + if(i++ > 10){ + print("...\n"); + break; + } + } + + // delete entire reassembly queue; wait for retransmit. + // - should we be smarter and only delete the tail? + for(rp = tcb->reseq; rp != nil; rp = rp1){ + rp1 = rp->next; + freeblist(rp->bp); + free(rp); + } + tcb->reseq = nil; + + return -1; } return 0; } @@ -2994,7 +3010,7 @@ tcpadvise(Proto *tcp, Block *bp, char *msg) v4tov6(source, h4->tcpsrc); psource = nhgets(h4->tcpsport); pdest = nhgets(h4->tcpdport); - } + } else { ipmove(dest, h6->tcpdst); ipmove(source, h6->tcpsrc); @@ -3122,7 +3138,7 @@ tcpsettimer(Tcpctl *tcb) /* round trip dependency */ x = backoff(tcb->backoff) * - (tcb->mdev + (tcb->srtt>>LOGAGAIN) + MSPTICK) / MSPTICK; + (tcb->mdev + (tcb->srtt>>LOGAGAIN) + MSPTICK) / MSPTICK; /* bounded twixt 1/2 and 64 seconds */ if(x < 500/MSPTICK) |
