ethdemux.c,v
来自「TCP-IP红宝书源代码」· C,V 代码 · 共 132 行
C,V
132 行
head 1.2;
access;
symbols;
locks
dls:1.2; strict;
comment @ * @;
1.2
date 94.01.07.03.10.26; author dls; state Old;
branches;
next 1.1;
1.1
date 93.09.02.15.29.56; author dls; state Dist;
branches;
next ;
desc
@@
1.2
log
@*** empty log message ***
@
text
@/* ethdemux.c - ethdemux */
#include <conf.h>
#include <kernel.h>
#include <network.h>
/*------------------------------------------------------------------------
* ethdemux - select a port to send an incoming packet (ETHER or OTHER?)
*------------------------------------------------------------------------
*/
int ethdemux(etptr)
struct etblk *etptr;
{
struct bre *pbre;
struct le_md *pmd;
struct otblk *otptr;
struct ep *pep;
int noth, readlen, errs, ifnum;
char *dest;
ifnum = etptr->etintf;
pbre = &etptr->etbrr[etptr->etnextbuf];
pmd = pbre->pmd;
errs = pmd->lmd_flags & (RMD_FRAM|RMD_OFLO|RMD_CRC|RMD_BUFF);
if ( errs != 0) {
if (errs & RMD_FRAM)
kprintf("ethread: framing error\n");
if (errs & RMD_OFLO)
kprintf("ethread: buffer overflow\n");
if (errs & RMD_CRC)
kprintf("ethread: CRC error\n");
if (errs & RMD_BUFF)
kprintf("ethread: don't own next buffer\n");
goto drop;
}
readlen = pmd->lmd_mcnt;
if (readlen > (EP_DLEN+18))
goto drop;
pep = (struct ep *)nbgetbuf(Net.netpool);
if (pep == 0) {
if (ifnum >= 0 && ifnum < NIF)
nif[ifnum].ni_idiscard++;
goto drop2;
}
blkcopy(&pep->ep_eh, pbre->buf, readlen-EP_CRC);
/* give this buffer back to the ethernet chip */
pmd->lmd_flags = LMD_OWN;
pbre->flags = 0;
/* deliver it to the interface */
#if Noth > 0
dest = (char *)pep->ep_dst;
for (noth=0; noth<Noth; ++noth) {
otptr = etptr->etoth[noth];
if (otptr == 0 || !otptr->ot_valid)
continue;
if (blkequ(dest, otptr->ot_paddr, EP_ALEN) ||
blkequ(dest, otptr->ot_baddr, EP_ALEN))
break;
}
if (noth != Noth)
ifnum = otptr->ot_intf;
#endif /* Noth > 0 */
if (ifnum < 0)
return freebuf(pep);
if (nif[ifnum].ni_state != NIS_UP) {
nif[ifnum].ni_idiscard++;
return freebuf(pep);
}
pep->ep_type = net2hs(pep->ep_type);
if (pep->ep_type == EPT_IP) {
struct ip *pip = (struct ip *)pep->ep_data;
kprintf("ed: IP, pr %x\n", pip->ip_proto);
if (pip->ip_proto == IPT_ICMP) {
struct icmp *pic = (struct icmp *)pip->ip_data;
kprintf("ed: if %d seq %d len %d\n", ifnum, pic->ic_seq, readlen);
}
}
ni_in(&nif[ifnum], pep, readlen);
return OK;
drop:
if (ifnum >= 0 && ifnum < NIF)
nif[ifnum].ni_ierrors++;
drop2:
/* give this buffer back to the ethernet chip */
pmd->lmd_flags = LMD_OWN;
pbre->flags = 0;
return SYSERR;
}
@
1.1
log
@Initial revision
@
text
@d39 2
a40 2
pep = (struct ep *)getbuf(Net.netpool);
if ((int)pep == SYSERR) {
d71 8
@
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?