ref: 0ed8a3bd7b1bbe2a3857f2abcaabdc4edd2d8b05
parent: 30c5296f32b87d83529d772732726891e1261c9c
author: cinap_lenrek <[email protected]>
date: Sun Nov 20 10:30:15 EST 2022
icmp6: no need set vcf and ttl before ipoput6(), use MAXTTL instead of HOP_LIMIT
--- a/sys/src/9/ip/icmp6.c
+++ b/sys/src/9/ip/icmp6.c
@@ -279,7 +279,6 @@
}
set_cksum(bp);
- p->vcf[0] = 0x06 << 4;
if(p->type <= Maxtype6)
ipriv->out[p->type]++;
ipoput6(c->p->f, bp, 0, c->ttl, c->tos, nil);
@@ -378,9 +377,6 @@
nbp->wp -= NDPKTSZ - NDISCSZ;
set_cksum(nbp);
- np = (Ndpkt*)nbp->rp;
- np->ttl = HOP_LIMIT;
- np->vcf[0] = 0x06 << 4;
ipriv->out[NbrSolicit]++;
netlog(f, Logicmp, "sending neighbor solicitation %I\n", targ);
ipoput6(f, nbp, 0, MAXTTL, DFLTTOS, nil);
@@ -413,9 +409,6 @@
memmove(np->lnaddr, mac, sizeof(np->lnaddr));
set_cksum(nbp);
- np = (Ndpkt*)nbp->rp;
- np->ttl = HOP_LIMIT;
- np->vcf[0] = 0x06 << 4;
ipriv->out[NbrAdvert]++;
netlog(f, Logicmp, "sending neighbor advertisement %I\n", targ);
ipoput6(f, nbp, 0, MAXTTL, DFLTTOS, nil);
@@ -448,14 +441,18 @@
np->code = code;
memmove(nbp->rp + IPICMPSZ, bp->rp, sz - IPICMPSZ);
set_cksum(nbp);
- np->ttl = HOP_LIMIT;
- np->vcf[0] = 0x06 << 4;
ipriv->out[UnreachableV6]++;
- if(tome)
+ if(tome){
+ np = (IPICMP *)nbp->rp;
+ np->vcf[0] = IP_VER6 | DFLTTOS>>4;
+ np->vcf[1] = DFLTTOS<<4;
+ np->ttl = MAXTTL;
+
ipiput6(f, ifc, nbp);
- else
- ipoput6(f, nbp, 0, MAXTTL, DFLTTOS, nil);
+ return;
+ }
+ ipoput6(f, nbp, 0, MAXTTL, DFLTTOS, nil);
}
void
@@ -485,8 +482,6 @@
np->code = 0;
memmove(nbp->rp + IPICMPSZ, bp->rp, sz - IPICMPSZ);
set_cksum(nbp);
- np->ttl = HOP_LIMIT;
- np->vcf[0] = 0x06 << 4;
ipriv->out[TimeExceedV6]++;
ipoput6(f, nbp, 0, MAXTTL, DFLTTOS, nil);
}
@@ -519,8 +514,6 @@
hnputl(np->icmpid, ifc->maxtu - ifc->m->hsize);
memmove(nbp->rp + IPICMPSZ, bp->rp, sz - IPICMPSZ);
set_cksum(nbp);
- np->ttl = HOP_LIMIT;
- np->vcf[0] = 0x06 << 4;
ipriv->out[PacketTooBigV6]++;
ipoput6(f, nbp, 0, MAXTTL, DFLTTOS, nil);
}
@@ -532,9 +525,10 @@
valid(Proto *icmp, Ipifc *, Block *bp, Icmppriv6 *ipriv)
{
int sz, osz, unsp, ttl;
+ ulong vcf;
int pktsz = BLEN(bp);
uchar *packet = bp->rp;
- IPICMP *p = (IPICMP *) packet;
+ IPICMP *p = (IPICMP *)packet;
Ndpkt *np;
if(pktsz < IPICMPSZ) {
@@ -549,7 +543,8 @@
netlog(icmp->f, Logicmp, "icmp error: extension header\n");
goto err;
}
- memset(packet, 0, 4);
+ vcf = nhgetl(p->vcf);
+ hnputl(p->vcf, 0); /* borrow IP header as pseudoheader */
ttl = p->ttl;
p->ttl = p->proto;
p->proto = 0;
@@ -560,12 +555,13 @@
}
p->proto = p->ttl;
p->ttl = ttl;
+ hnputl(p->vcf, vcf);
/* additional tests for some pkt types */
if (p->type == NbrSolicit || p->type == NbrAdvert ||
p->type == RouterAdvert || p->type == RouterSolicit ||
p->type == RedirectV6) {
- if(p->ttl != HOP_LIMIT) {
+ if(p->ttl != MAXTTL) {
ipriv->stats[HoplimErrs6]++;
goto err;
}