📄 [转载] linux的tcp-ip协议栈阅读笔记(6) - china linux forum.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0110)http://www.linuxforum.net/forum/showflat.php?Cat=&Board=linuxK&Number=67729&page=192&view=collapsed&sb=5&o=all -->
<HTML><HEAD><TITLE>[转载] Linux的TCP/IP协议栈阅读笔记(6) - China Linux Forum</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<META content="MSHTML 5.00.2920.0" name=GENERATOR></HEAD>
<BODY>
<CENTER><FONT color=red>著名软件中国镜像:</FONT> <A
href="http://apache.linuxforum.net/"><FONT color=red>Apache|</FONT></A> <A
href="http://php.linuxforum.net/"><FONT color=red>Php|</FONT></A> <A
href="http://debian.linuxforum.net/"><FONT color=red>Debian|</FONT></A> <A
href="http://mysql.linuxforum.net/"><FONT color=red>Mysql|</FONT></A> <A
href="http://proftpd.linuxforum.net/"><FONT color=red>Proftp|</FONT></A> <A
href="http://qmail.linuxforum.net/top.html"><FONT color=red>Qmail|</FONT></A> <A
href="http://samba.linuxforum.net/samba.html"><FONT color=red>Samba|</FONT></A>
<A href="http://www1.cn.squid-cache.org/"><FONT color=red>Squid|</FONT></A> <A
href="http://xfree86.linuxforum.net/"><FONT color=red>Xfree86|</FONT></A> <A
href="http://cpan.linuxforum.net/"><FONT color=red>CPAN|</FONT></A> <A
href="http://ldp.linuxforum.net/"><FONT color=red>LDP|</FONT></A> <A
href="http://gnu.linuxforum.net/"><FONT
color=red>GNU|</FONT></A></CENTER><BR><LINK
href="[转载] Linux的TCP-IP协议栈阅读笔记(6) - China Linux Forum.files/stylesheet2.css"
rel=stylesheet type=text/css><SPAN class=onbody>
<TABLE align=center border=0 cellPadding=3 cellSpacing=0 class=p9 width="95%">
<TBODY>
<TR align=right bgColor=#0099cc vAlign=center>
<TD align=left width="20%"><A
href="http://www.linuxforum.net/index.php"><FONT
color=#ffffff>中国Linux论坛首页</FONT></A></TD>
<TD width="80%"><A
href="http://www.linuxforum.net/forum/ubbthreads.php"><FONT
color=#ffffff>技术论坛|</FONT></A><FON color="#FFFFFF" t> <A
href="http://www.linuxforum.net/docnew/index.php"><FONT
color=#ffffff>文章荟萃</FONT></A><FONT color=#ffffff>| <A
href="http://www.linuxforum.net/books/index.php"><FONT
color=#ffffff>藏经阁</FONT></A>| <A href="http://mail.linuxforum.net/"><FONT
color=#ffffff>会员信箱</FONT></A>| <A href="http://sf.linuxforum.net/"><FONT
color=#ffffff>项目计划</FONT></A>| <A
href="http://www.linuxforum.net/poll2/index.php"><FONT
color=#ffffff>在线调查</FONT></A>| <A href="ftp://ftp.linuxforum.net/"><FONT
color=#ffffff>软件仓库</FONT></A>| <A
href="http://www.linuxforum.net/about.php"><FONT
color=#ffffff>关于本站</FONT></A>| </FONT></TD></TR></TBODY></TABLE><BR></SPAN>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width="95%">
<TBODY>
<TR>
<TD class=tableborders>
<TABLE border=0 cellPadding=3 cellSpacing=1 width="100%">
<TBODY>
<TR>
<TD align=right class=menubar><A
href="http://www.linuxforum.net/forum/ubbthreads.php?Cat=">讨论区列表</A>
| <A href="http://www.linuxforum.net/forum/search.php?Cat=">搜寻文章</A>
| <A
href="http://www.linuxforum.net/forum/newuser.php?Cat=">新用户注册</A> |
<A href="http://www.linuxforum.net/forum/login.php?Cat=">登入论坛</A> |
<A href="http://www.linuxforum.net/forum/online.php?Cat=">在线用户</A> |
<A
href="http://www.linuxforum.net/forum/faq_chinese.php?Cat=">常见问题</A>
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<P>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width="95%">
<TBODY>
<TR>
<TD class=tableborders>
<TABLE border=0 cellPadding=3 cellSpacing=1 width="100%">
<TBODY>
<TR class=darktable>
<TD>
<TABLE cellPadding=0 cellSpacing=0 width="100%">
<TBODY>
<TR class=darktable>
<TD align=left width="33%"><SPAN class=catandforum><A
href="http://www.linuxforum.net/forum/ubbthreads.php?Cat=&C=4">Linux
高级应用</A> <BR> >> <A
href="http://www.linuxforum.net/forum/postlist.php?Cat=&Board=linuxK&page=192&view=collapsed&sb=5&o=all">Linux内核技术</A>
</SPAN></TD>
<TD align=middle width="33%">此话题阅读次数: 648 </TD>
<TD align=right width="33%">
<TABLE border=0>
<TBODY>
<TR>
<TD class=navigation noWrap><IMG align=absMiddle alt=*
src="[转载] Linux的TCP-IP协议栈阅读笔记(6) - China Linux Forum.files/greyflat.gif">平坦模式
</TD>
<TD class=navigation noWrap><A
href="http://www.linuxforum.net/forum/showthreaded.php?Cat=&Board=linuxK&Number=67729&page=192&view=collapsed&sb=5&o=all&vc=1"><IMG
align=absMiddle alt=树状模式,一封一封读 border=0
src="[转载] Linux的TCP-IP协议栈阅读笔记(6) - China Linux Forum.files/threaded.gif">树状模式</A>
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE align=center border=0 cellPadding=4 cellSpacing=0 width="95%">
<TBODY>
<TR>
<TD align=left class=small> </TD>
<TD align=right class=small><A
href="http://www.linuxforum.net/forum/printthread.php?Cat=&Board=linuxK&main=67729&type=thread"
target=_blank><IMG align=top border=0
src="[转载] Linux的TCP-IP协议栈阅读笔记(6) - China Linux Forum.files/printthread.gif">
打印</A> </TD></TR></TBODY></TABLE>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width="95%">
<TBODY>
<TR>
<TD class=tableborders>
<TABLE border=0 cellPadding=3 cellSpacing=1 width="100%">
<TBODY>
<TR>
<TD class=darktable rowSpan=2 vAlign=top width="17%"><A
name=Post67729></A><A
href="http://www.linuxforum.net/forum/showprofile.php?Cat=&User=tommytang&Number=67729&Board=linuxK&what=showflat&page=192&view=collapsed&sb=5&o=all&fpart=1&vc=1">tommytang</A><BR><SPAN
class=small>(newbie)<BR>01/03/01 21:59<BR></SPAN></TD>
<TD class=subjecttable width="83%">
<TABLE border=0 class=subjecttable width="100%">
<TBODY>
<TR>
<TD align=left width="70%"><IMG height=15
src="[转载] Linux的TCP-IP协议栈阅读笔记(6) - China Linux Forum.files/book.gif"
width=15> <B>[转载] Linux的TCP/IP协议栈阅读笔记(6)</B> </TD>
<TD align=right width="30%"> </TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD class=lighttable width="83%"><BR>
<P class=post>发信人: AngelFalls (TRY IT), 信区: SysInternals<BR>标 题:
[转载] Linux的TCP/IP协议栈阅读笔记(6)<BR>发信站: 武汉白云黄鹤站 (Wed Oct 4 01:37:11
2000), 转信<BR><BR>【 以下文字转载自 Security 讨论区 】<BR>【 原文由 AngelFalls 所发表
】<BR>let's start from bottom up
:)<BR>有的时候用英语说话比汉语要简洁和有意思一点:)<BR><BR>一个lance得到数据以后总会这样处理:<BR>skb =
dev_alloc_skb (....);<BR>skb->protocol = eth_type_trans(skb,
dev);<BR>....<BR>netif_rx
(skb);<BR><BR>eth_type_trans函数在net/ethernet/eth.c里面,作用当然很简单了,大家可以<BR>自己看;).<BR>而netif_rx函数是在net/core/dev.c里面的,假定没有定义CONFIG_CPU_IS_SLOW<BR>(我觉得自己的CPU不慢:))和CONFIG_NET_HW_FLOWCONTROL(很少有人会意识到很<BR>多网卡有流量控制把,不过没有交换设备的支持,想凭这个东西达到Qos也没什么<BR>用)以后的代码是这样的:<BR>void
netif_rx(struct sk_buff *skb)<BR>{<BR>skb->stamp =
xtime;<BR><BR>if (backlog.qlen <= netdev_max_backlog) {<BR>if
(backlog.qlen) {<BR>if (netdev_dropping == 0)
{<BR>skb_queue_tail(&backlog,skb);<BR>mark_bh(NET_BH);<BR>return;<BR>}<BR>atomic_inc(&netdev_rx_dropped);<BR>kfree_skb(skb);<BR>return;<BR>}<BR>netdev_dropping
=
0;<BR>skb_queue_tail(&backlog,skb);<BR>mark_bh(NET_BH);<BR>return;<BR>}<BR>netdev_dropping
=
1;<BR>atomic_inc(&netdev_rx_dropped);<BR>kfree_skb(skb);<BR>}<BR><BR>xtime是当前的时间,一个struct
timeval,利用gettimeofday函数得到的就是这个<BR>东西的内容.backlog是一个sk_buff的双向链表,
netdev_dropping初始化为0,如果<BR>没有定义CONFIG_NET_HW_FLOWCONTROL,这个变量一直都将是0.skb_queue_tail就是<BR>把一个sk_buff加入到backlog双向队列中去.然后mark_bh是设置了一个全局变量相<BR>对位移NET_BH处的bit就返回了.这个bit的设置将使得内核下次schedule的时候从<BR>TIMER_BH向下处理时检查到NET_BH处发现有设置就会调用对应NET_BH优先级的函数<BR>net_bh来处理,这个回调函数是在net_dev_init函数里面调用init_bh设置的,呵呵,<BR>兄弟们,如果感兴趣可以自己再init_bh看看设置一个自己的处理backlog的函数啊.<BR>Linux在这里采取了一个古怪的策略进行控制权的转移和处理机优先级的处理.另一<BR>个函数net_bh来处理从backlog中间得到包,它是这样的(假定没定义CONFIG_BRIDGE<BR>这个选项):<BR>void
net_bh(void)<BR>{<BR>struct packet_type *ptype;<BR>struct
packet_type *pt_prev;<BR>unsigned short type;<BR>unsigned long
start_time = jiffies;<BR><BR>NET_PROFILE_ENTER(net_bh);<BR><BR>if
(qdisc_head.forw !=
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -