📄 [转载] linux的tcp-ip协议栈阅读笔记(3) - 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=67724&page=192&view=collapsed&sb=5&o=all -->
<HTML><HEAD><TITLE>[转载] Linux的TCP/IP协议栈阅读笔记(3) - 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协议栈阅读笔记(3) - 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%">此话题阅读次数: 830 </TD>
<TD align=right width="33%">
<TABLE border=0>
<TBODY>
<TR>
<TD class=navigation noWrap><IMG align=absMiddle alt=*
src="[转载] Linux的TCP-IP协议栈阅读笔记(3) - China Linux Forum.files/greyflat.gif">平坦模式
</TD>
<TD class=navigation noWrap><A
href="http://www.linuxforum.net/forum/showthreaded.php?Cat=&Board=linuxK&Number=67724&page=192&view=collapsed&sb=5&o=all&vc=1"><IMG
align=absMiddle alt=树状模式,一封一封读 border=0
src="[转载] Linux的TCP-IP协议栈阅读笔记(3) - 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=67724&type=thread"
target=_blank><IMG align=top border=0
src="[转载] Linux的TCP-IP协议栈阅读笔记(3) - 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=Post67724></A><A
href="http://www.linuxforum.net/forum/showprofile.php?Cat=&User=tommytang&Number=67724&Board=linuxK&what=showflat&page=192&view=collapsed&sb=5&o=all&fpart=1&vc=1">tommytang</A><BR><SPAN
class=small>(stranger)<BR>01/03/01 21:57<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协议栈阅读笔记(3) - China Linux Forum.files/book.gif"
width=15> <B>[转载] Linux的TCP/IP协议栈阅读笔记(3)</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协议栈阅读笔记(3)<BR>发信站: 武汉白云黄鹤站 (Wed Oct 4 01:36:27
2000), 转信<BR><BR>【 以下文字转载自 Security 讨论区 】<BR>【 原文由 AngelFalls 所发表
】<BR>其中的sock_register函数的作用已经在前面说了,现在来看看<BR>struct
inet_protocol和inet_add_protocol函数。前面的结构体<BR>是在include/net/protocol.h里面:<BR>struct
inet_protocol <BR>{<BR>int (*handler)(struct sk_buff *skb, unsigned
short len);<BR>void (*err_handler)(struct sk_buff *skb, unsigned
char *dp, int len);<BR>struct inet_protocol *next;<BR>unsigned char
protocol;<BR>unsigned char copy:1;<BR>void *data;<BR>const char
*name;<BR>};<BR>第一个函数是用来接收数据的callback函数,第二个是错误处理函数,<BR>其它的copy是用来协议共享的,这个以后再说,data当然就是这个结<BR>构体的私有数据了。<BR><BR>inet_add_protocol函数是在net/ipv4/protocol.c里面的:<BR>void
inet_add_protocol(struct inet_protocol *prot)<BR>{<BR>unsigned char
hash;<BR>struct inet_protocol *p2;<BR><BR>hash = prot->protocol
& (MAX_INET_PROTOS - 1);<BR>prot ->next =
inet_protos[hash];<BR>inet_protos[hash] = prot;<BR>prot->copy =
0;<BR><BR>p2 = (struct inet_protocol *) prot->next;<BR>while(p2
!= NULL) <BR>{<BR>if (p2->protocol == prot->protocol)
<BR>{<BR>prot->copy = 1;<BR>break;<BR>}<BR>p2 = (struct
inet_protocol *)
p2->next;<BR>}<BR>}<BR>显然这个函数就是作乐一个hash表,然后每个hash表项都是一个链表头,<BR>然后通过这个hash表加链表的方式访问每个协议结构体。在这里你也见<BR>到了copy成员的用法了把。<BR><BR>arp_init函数是在net/ipv4/arp.c里面的(假定没有定义CONFIG_SYSCTL):<BR><BR>neigh_table_init(&arp_tbl);<BR>dev_add_pack(&arp_packet_type);<BR>proc_net_register(&proc_net_arp);<BR><BR>不知道是不是有人眼睛一亮啊,呵呵,看到了dev_add_pack函数。<BR>还是一步步来把。<BR>neigh_table_init函数在net/core/neighbour.c中间:<BR>void
neigh_table_init(struct neigh_table *tbl)<BR>{<BR>unsigned long now
= jiffies;<BR><BR>tbl->parms.reachable_time =
neigh_rand_reach_time(<BR>tbl->parms.base_reachable_time);<BR><BR>init_timer(&tbl->gc_timer);<BR>tbl->gc_timer.data
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -