Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
b9ca9bf6
提交
b9ca9bf6
12月 27, 2011
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
lwIP if input
上级
a800fbca
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
121 行增加
和
7 行删除
+121
-7
net.c
net.c
+17
-7
if.c
net/if.c
+104
-0
没有找到文件。
net.c
浏览文件 @
b9ca9bf6
...
...
@@ -41,12 +41,6 @@ netalloc(void)
}
void
netrx
(
void
*
va
,
u16
len
)
{
cprintf
(
"netrx %lx len %x
\n
"
,
va
,
len
);
}
void
nettest
(
void
)
{
void
*
ping
;
...
...
@@ -62,6 +56,8 @@ nettest(void)
#ifdef LWIP
static
struct
netif
nif
;
struct
timer_thread
{
u64
nsec
;
struct
condvar
waitcv
;
...
...
@@ -71,6 +67,13 @@ struct timer_thread {
int
errno
;
void
netrx
(
void
*
va
,
u16
len
)
{
extern
void
if_input
(
struct
netif
*
netif
,
void
*
buf
,
u16
len
);
if_input
(
&
nif
,
va
,
len
);
}
static
void
__attribute__
((
noreturn
))
net_timer
(
void
*
x
)
{
...
...
@@ -139,7 +142,6 @@ void
initnet_worker
(
void
*
x
)
{
static
struct
timer_thread
t_arp
,
t_tcpf
,
t_tcps
,
t_dhcpf
,
t_dhcpc
;
static
struct
netif
nif
;
volatile
long
tcpip_done
=
0
;
tcpip_init
(
&
tcpip_init_done
,
(
void
*
)
&
tcpip_done
);
...
...
@@ -157,6 +159,8 @@ initnet_worker(void *x)
start_timer
(
&
t_dhcpf
,
&
dhcp_fine_tmr
,
"dhcp f timer"
,
DHCP_FINE_TIMER_MSECS
);
start_timer
(
&
t_dhcpc
,
&
dhcp_coarse_tmr
,
"dhcp c timer"
,
DHCP_COARSE_TIMER_MSECS
);
}
void
...
...
@@ -178,4 +182,10 @@ void
initnet
(
void
)
{
}
void
netrx
(
void
*
va
,
u16
len
)
{
cprintf
(
"netrx: %u
\n
"
,
len
);
}
#endif
net/if.c
浏览文件 @
b9ca9bf6
...
...
@@ -81,6 +81,110 @@ low_level_output(struct netif *netif, struct pbuf *p)
return
ERR_OK
;
}
/**
* Should allocate a pbuf and transfer the bytes of the incoming
* packet from the interface into the pbuf.
*
* @param netif the lwip network interface structure for this ethernetif
* @return a pbuf filled with the received packet (including MAC header)
* NULL on memory error
*/
static
struct
pbuf
*
low_level_input
(
struct
netif
*
netif
,
void
*
buf
,
u16_t
len
)
{
struct
pbuf
*
p
,
*
q
;
#if ETH_PAD_SIZE
len
+=
ETH_PAD_SIZE
;
/* allow room for Ethernet padding */
#endif
/* We allocate a pbuf chain of pbufs from the pool. */
p
=
pbuf_alloc
(
PBUF_RAW
,
len
,
PBUF_POOL
);
if
(
p
!=
NULL
)
{
#if ETH_PAD_SIZE
pbuf_header
(
p
,
-
ETH_PAD_SIZE
);
/* drop the padding word */
#endif
int
copied
=
0
;
/* We iterate over the pbuf chain until we have read the entire
* packet into the pbuf. */
for
(
q
=
p
;
q
!=
NULL
;
q
=
q
->
next
)
{
/* Read enough bytes to fill this pbuf in the chain. The
* available data in the pbuf is given by the q->len
* variable.
* This does not necessarily have to be a memcpy, you can also preallocate
* pbufs for a DMA-enabled MAC and after receiving truncate it to the
* actually received size. In this case, ensure the tot_len member of the
* pbuf is the sum of the chained pbuf len members.
*/
int
bytes
=
q
->
len
;
if
(
bytes
>
(
len
-
copied
))
bytes
=
len
-
copied
;
memmove
(
q
->
payload
,
buf
+
copied
,
bytes
);
copied
+=
bytes
;
}
#if ETH_PAD_SIZE
pbuf_header
(
p
,
ETH_PAD_SIZE
);
/* reclaim the padding word */
#endif
LINK_STATS_INC
(
link
.
recv
);
}
else
{
LINK_STATS_INC
(
link
.
memerr
);
LINK_STATS_INC
(
link
.
drop
);
}
return
p
;
}
/**
* This function should be called when a packet is ready to be read
* from the interface. It uses the function low_level_input() that
* should handle the actual reception of bytes from the network
* interface. Then the type of the received packet is determined and
* the appropriate input function is called.
*
* @param netif the lwip network interface structure for this ethernetif
*/
void
if_input
(
struct
netif
*
netif
,
void
*
buf
,
u16
len
)
{
struct
eth_hdr
*
ethhdr
;
struct
pbuf
*
p
;
/* move received packet into a new pbuf */
p
=
low_level_input
(
netif
,
buf
,
len
);
netfree
(
buf
);
/* no packet could be read, silently ignore this */
if
(
p
==
NULL
)
return
;
/* points to packet payload, which starts with an Ethernet header */
ethhdr
=
p
->
payload
;
switch
(
htons
(
ethhdr
->
type
))
{
/* IP or ARP packet? */
case
ETHTYPE_IP
:
case
ETHTYPE_ARP
:
#if PPPOE_SUPPORT
/* PPPoE packet? */
case
ETHTYPE_PPPOEDISC
:
case
ETHTYPE_PPPOE
:
#endif
/* PPPOE_SUPPORT */
/* full packet send to tcpip_thread to process */
if
(
netif
->
input
(
p
,
netif
)
!=
ERR_OK
)
{
LWIP_DEBUGF
(
NETIF_DEBUG
,
(
"ethernetif_input: IP input error
\n
"
));
pbuf_free
(
p
);
p
=
NULL
;
}
break
;
default:
pbuf_free
(
p
);
p
=
NULL
;
break
;
}
}
/**
* Should be called at the beginning of the program to set up the
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论