summaryrefslogtreecommitdiff
path: root/sys/src/9/ip
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2022-09-28 19:17:56 +0000
committercinap_lenrek <cinap_lenrek@felloff.net>2022-09-28 19:17:56 +0000
commit6b38e52e4b38370d3097a32550ba9cace6782888 (patch)
tree9a927e0317e85b98c907924febc3853aaf0835dd /sys/src/9/ip
parent23e378a960f6027f8daba93f34ebeb1ae3d00517 (diff)
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.
Diffstat (limited to 'sys/src/9/ip')
-rw-r--r--sys/src/9/ip/ethermedium.c64
-rw-r--r--sys/src/9/ip/ip.h1
-rw-r--r--sys/src/9/ip/ipifc.c1
-rw-r--r--sys/src/9/ip/netdevmedium.c3
4 files changed, 32 insertions, 37 deletions
diff --git a/sys/src/9/ip/ethermedium.c b/sys/src/9/ip/ethermedium.c
index 19cc65eb7..3a1c65100 100644
--- 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 etheraddmulti(Ipifc *ifc, uchar *a, uchar *ia);
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 @@ static void etherpref2addr(uchar *pref, uchar *ea);
Medium ethermedium =
{
.name= "ether",
-.hsize= 14,
-.mintu= 60,
+.hsize= EHSIZE,
+.mintu= EMINTU,
.maxtu= 1514,
.maclen= 6,
.bind= etherbind,
@@ -50,8 +56,8 @@ Medium ethermedium =
Medium gbemedium =
{
.name= "gbe",
-.hsize= 14,
-.mintu= 60,
+.hsize= EHSIZE,
+.mintu= EMINTU,
.maxtu= 9014,
.maclen= 6,
.bind= etherbind,
@@ -279,9 +285,9 @@ etherbwrite(Ipifc *ifc, Block *bp, int version, uchar *ip, Routehint *rh)
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 @@ etherread4(void *a)
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 @@ etherread6(void *a)
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 @@ etherremmulti(Ipifc *ifc, uchar *a, uchar *)
}
}
+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 @@ etherremmulti(Ipifc *ifc, uchar *a, uchar *)
static void
sendarpreq(Fs *f, Arpent *a)
{
- int n;
Block *bp;
Etherarp *e;
Ipifc *ifc = a->ifc;
@@ -445,12 +461,8 @@ sendarpreq(Fs *f, Arpent *a)
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 @@ sendarpreq(Fs *f, Arpent *a)
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 @@ sendarpreq(Fs *f, Arpent *a)
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 @@ sendgarp(Ipifc *ifc, uchar *ip)
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 @@ sendgarp(Ipifc *ifc, uchar *ip)
static void
recvarp(Ipifc *ifc)
{
- int n, forme;
+ int forme;
Block *ebp, *rbp;
Etherarp *e, *r;
uchar ip[IPaddrlen];
@@ -581,12 +586,8 @@ recvarp(Ipifc *ifc)
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 @@ recvarp(Ipifc *ifc)
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);
diff --git a/sys/src/9/ip/ip.h b/sys/src/9/ip/ip.h
index 56d94d4cf..bf4b2cea3 100644
--- a/sys/src/9/ip/ip.h
+++ b/sys/src/9/ip/ip.h
@@ -378,7 +378,6 @@ struct Ipifc
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 */
diff --git a/sys/src/9/ip/ipifc.c b/sys/src/9/ip/ipifc.c
index 653fd1117..18d9cfeec 100644
--- a/sys/src/9/ip/ipifc.c
+++ b/sys/src/9/ip/ipifc.c
@@ -180,7 +180,6 @@ ipifcbind(Conv *c, char **argv, int argc)
/* set up parameters */
ifc->m = m;
- ifc->mintu = ifc->m->mintu;
ifc->maxtu = ifc->m->maxtu;
ifc->delay = 40;
ifc->speed = 0;
diff --git a/sys/src/9/ip/netdevmedium.c b/sys/src/9/ip/netdevmedium.c
index f60d43b3a..9ad95b40e 100644
--- a/sys/src/9/ip/netdevmedium.c
+++ b/sys/src/9/ip/netdevmedium.c
@@ -93,9 +93,6 @@ netdevbwrite(Ipifc *ifc, Block *bp, int, uchar*, Routehint*)
{
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++;
}