ref: f513438bb278dd90f88c849a39a28a5e5c89c4d2
parent: 2255e9f6bf49b6c82e07c119d03fbc69892449fd
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Sep 28 15:17:56 EDT 2022
devip: get rid of Ipifc.mintu All the mediums we have implemented know their minimum transmit unit. The minimum transfer unit is not adjustable so there is no point in caching it in the ip interface.
--- a/sys/src/9/ip/ethermedium.c
+++ b/sys/src/9/ip/ethermedium.c
@@ -9,6 +9,11 @@
#include "ip.h"
#include "ipv6.h"
+enum {
+ EHSIZE = 14,
+ EMINTU = 60,
+};
+
typedef struct Etherhdr Etherhdr;
struct Etherhdr
{
@@ -26,6 +31,7 @@
static void etherremmulti(Ipifc *ifc, uchar *a, uchar *ia);
static void etherareg(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *ip);
static Block* multicastarp(Fs *f, Arpent *a, uchar *mac, Routehint *rh);
+static Block* newEARP(void);
static void sendarpreq(Fs *f, Arpent *a);
static int multicastea(uchar *ea, uchar *ip);
static void recvarpproc(void*);
@@ -34,8 +40,8 @@
Medium ethermedium =
{
.name= "ether",
-.hsize= 14,
-.mintu= 60,
+.hsize= EHSIZE,
+.mintu= EMINTU,
.maxtu= 1514,
.maclen= 6,
.bind= etherbind,
@@ -50,8 +56,8 @@
Medium gbemedium =
{
.name= "gbe",
-.hsize= 14,
-.mintu= 60,
+.hsize= EHSIZE,
+.mintu= EMINTU,
.maxtu= 9014,
.maclen= 6,
.bind= etherbind,
@@ -279,9 +285,9 @@
assert(bp->list == nil);
/* make it a single block with space for the ether header */
- bp = padblock(bp, ifc->m->hsize);
- if(BLEN(bp) < ifc->mintu)
- bp = adjustblock(bp, ifc->mintu);
+ bp = padblock(bp, EHSIZE);
+ if(BLEN(bp) < EMINTU)
+ bp = adjustblock(bp, EMINTU);
eh = (Etherhdr*)bp->rp;
/* copy in mac addresses and ether type */
@@ -330,10 +336,10 @@
nexterror();
}
ifc->in++;
- if(ifc->lifc == nil || BLEN(bp) <= ifc->m->hsize)
+ if(ifc->lifc == nil || BLEN(bp) <= EHSIZE)
freeb(bp);
else {
- bp->rp += ifc->m->hsize;
+ bp->rp += EHSIZE;
ipiput4(er->f, ifc, bp);
}
runlock(ifc);
@@ -368,10 +374,10 @@
nexterror();
}
ifc->in++;
- if(ifc->lifc == nil || BLEN(bp) <= ifc->m->hsize)
+ if(ifc->lifc == nil || BLEN(bp) <= EHSIZE)
freeb(bp);
else {
- bp->rp += ifc->m->hsize;
+ bp->rp += EHSIZE;
ipiput6(er->f, ifc, bp);
}
runlock(ifc);
@@ -425,6 +431,17 @@
}
}
+static Block*
+newEARP(void)
+{
+ Block *bp;
+
+ bp = allocb(EMINTU);
+ bp->wp += EMINTU;
+ memset(bp->rp, 0, EMINTU);
+ return bp;
+}
+
/*
* send an ethernet arp
* (only v4, v6 uses the neighbor discovery, rfc1970)
@@ -432,7 +449,6 @@
static void
sendarpreq(Fs *f, Arpent *a)
{
- int n;
Block *bp;
Etherarp *e;
Ipifc *ifc = a->ifc;
@@ -445,12 +461,8 @@
if(!ipv4local(ifc, src, 0, targ))
return;
- n = sizeof(Etherarp);
- if(n < ifc->m->mintu)
- n = ifc->m->mintu;
- bp = allocb(n);
+ bp = newEARP();
e = (Etherarp*)bp->rp;
- memset(e, 0, n);
memmove(e->tpa, targ, sizeof(e->tpa));
memmove(e->spa, src, sizeof(e->spa));
memmove(e->sha, ifc->mac, sizeof(e->sha));
@@ -463,7 +475,6 @@
e->hln = sizeof(e->sha);
e->pln = sizeof(e->spa);
hnputs(e->op, ARPREQUEST);
- bp->wp += n;
devtab[er->achan->type]->bwrite(er->achan, bp, 0);
}
@@ -474,17 +485,12 @@
static void
sendgarp(Ipifc *ifc, uchar *ip)
{
- int n;
Block *bp;
Etherarp *e;
Etherrock *er = ifc->arg;
- n = sizeof(Etherarp);
- if(n < ifc->m->mintu)
- n = ifc->m->mintu;
- bp = allocb(n);
+ bp = newEARP();
e = (Etherarp*)bp->rp;
- memset(e, 0, n);
memmove(e->tpa, ip+IPv4off, sizeof(e->tpa));
memmove(e->spa, ip+IPv4off, sizeof(e->spa));
memmove(e->sha, ifc->mac, sizeof(e->sha));
@@ -497,7 +503,6 @@
e->hln = sizeof(e->sha);
e->pln = sizeof(e->spa);
hnputs(e->op, ARPREQUEST);
- bp->wp += n;
devtab[er->achan->type]->bwrite(er->achan, bp, 0);
}
@@ -505,7 +510,7 @@
static void
recvarp(Ipifc *ifc)
{
- int n, forme;
+ int forme;
Block *ebp, *rbp;
Etherarp *e, *r;
uchar ip[IPaddrlen];
@@ -581,12 +586,8 @@
if(arpenter(er->f, V4, e->spa, e->sha, sizeof(e->sha), e->tpa, ifc, !forme) < 0 || !forme)
break;
- n = sizeof(Etherarp);
- if(n < ifc->mintu)
- n = ifc->mintu;
- rbp = allocb(n);
+ rbp = newEARP();
r = (Etherarp*)rbp->rp;
- memset(r, 0, n);
hnputs(r->type, ETARP);
hnputs(r->hrd, 1);
hnputs(r->pro, ETIP4);
@@ -599,7 +600,6 @@
memmove(r->spa, e->tpa, sizeof(r->spa));
memmove(r->d, e->sha, sizeof(r->d));
memmove(r->s, ifc->mac, sizeof(r->s));
- rbp->wp += n;
runlock(ifc);
freeb(ebp);
--- a/sys/src/9/ip/ip.h
+++ b/sys/src/9/ip/ip.h
@@ -378,7 +378,6 @@
char dev[64]; /* device we're attached to */
Medium *m; /* Media pointer */
int maxtu; /* Maximum transfer unit */
- int mintu; /* Minumum tranfer unit */
void *arg; /* medium specific */
uchar reflect; /* allow forwarded packets to go out the same interface */
--- a/sys/src/9/ip/ipifc.c
+++ b/sys/src/9/ip/ipifc.c
@@ -180,7 +180,6 @@
/* set up parameters */
ifc->m = m;
- ifc->mintu = ifc->m->mintu;
ifc->maxtu = ifc->m->maxtu;
ifc->delay = 40;
ifc->speed = 0;
--- a/sys/src/9/ip/netdevmedium.c
+++ b/sys/src/9/ip/netdevmedium.c
@@ -93,9 +93,6 @@
{
Netdevrock *er = ifc->arg;
- if(BLEN(bp) < ifc->mintu)
- bp = adjustblock(bp, ifc->mintu);
-
devtab[er->mchan->type]->bwrite(er->mchan, bp, 0);
ifc->out++;
}
--
⑨