📄 66.htm
字号:
<br>
这是/usr/src/linux-2.4/include/net/tcp.h中的一段话.我根据这句话 <br>
对照源代码去看,可能没有看明白,产生很多疑问 <br>
<br>
/* There are a few simple rules, which allow for local port reuse by <br>
* an application. In essence: <br>
* <br>
* 1) Sockets bound to different interfaces may share a local port. <br>
* Failing that, goto test 2. <br>
* 2) If all sockets have sk->reuse set, and none of them are in <br>
* TCP_LISTEN state, the port may be shared. <br>
* Failing that, goto test 3. <br>
* 3) If all sockets are bound to a specific sk->rcv_saddr local <br>
* address, and none of them are the same, the port may be <br>
* shared. <br>
* Failing this, the port cannot be shared. <br>
* <br>
* The interesting point, is test #2. This is what an FTP server does <br>
* all day. To optimize this case we use a specific flag bit defined <br>
* below. As we add sockets to a bind bucket list, we perform a <br>
* <br>
* The interesting point, is test #2. This is what an FTP server does <br>
* all day. To optimize this case we use a specific flag bit defined <br>
* below. As we add sockets to a bind bucket list, we perform a <br>
* check of: (newsk->reuse && (newsk->state != TCP_LISTEN)) <br>
* As long as all sockets added to a bind bucket pass this test, <br>
* the flag bit will be set. <br>
* The resulting situation is that tcp_v[46]_verify_bind() can just check <br>
* for this flag bit, if it is set and the socket trying to bind has <br>
* sk->reuse set, we don't even have to walk the owners list at all, <br>
* we return that it is ok to bind this socket to the requested local port. <br>
* <br>
* Sounds like a lot of work, but it is worth it. In a more naive <br>
* implementation (ie. current FreeBSD etc.) the entire list of ports <br>
* must be walked for each data port opened by an ftp server. Needless <br>
* to say, this does not scale at all. With a couple thousand FTP <br>
* users logged onto your box, isn't it nice to know that new data <br>
* ports are created in O(1) time? I thought so. ;-) -DaveM <br>
*/ <br>
<br>
【 在 scz (小四) 的大作中提到: 】 <br>
: 【 在 ysqcn (岁月无声) 的大作中提到: 】 <br>
: : 它这句话是正确的,但它是针对服务器重启动的情况。 <br>
: : 我觉得如果设了这个标志,在其它状态(例如TCP_ESTABLISHED的情况下)也能重复绑 <br>
定。 <br>
: : 有文档说,如果套接字都设了这个标志,只要其中没有套接字在倾听状态,就允许完全 <br>
: : 重复绑定。 <br>
: 那是实现相关并且带扩展味道的。 <br>
: 这个标志其他都可以不理会,只要能处理这一种情况就足够了 <br>
: 而且这个不是局限于Linux的。Linux对传统Unix以及TCP/IP的践踏 <br>
: 是有目共睹的。扩展很多。 <br>
: 你觉得在ESTABLISHED下也能重复绑定,这个文档是Linux的还是RFC的呢? <br>
: .................(以下省略) <br>
-- <br>
※ 修改:·ysqcn 於 08月31日14:38:29 修改本文·[FROM: 211.69.197.81] <br>
※ 来源:·UNIX编程 www.tiaozhan.com/unixbbs/·[FROM: 211.69.197.81] <br>
发信人: scz (小四), 信区: UNP <br>
标 题: Re: 看看这段话 <br>
发信站: UNIX编程 (2001年08月31日14:22:40 星期五), 站内信件 <br>
<br>
呵呵,快速扫完。 <br>
这段注释再次证明了Linux下不用遵守太多规矩,想怎么干就怎么干, <br>
它是不在乎移植以及和其他系统的兼容性的。践踏随处可见。 <br>
<br>
他说的没错,原因就是客户方不大可能刻意去满足一条完全重复的 <br>
相关五元组。基于这种假定,他做了那么一个判断。 <br>
<br>
再次提醒注意这句话 <br>
<br>
实际意味着 <br>
允许另一个拥有相同相关五元组的连接出现,可能处理 <br>
TCP报文时,两个连接互相干扰 <br>
<br>
而Linux的这个实现明白地说,我知道这个实际意味着,但是现实中 <br>
这种情况出现很少,没人那么多刻意来捣乱 <br>
<br>
【 在 ysqcn (岁月无声) 的大作中提到: 】 <br>
: 这是/usr/src/linux-2.4/include/net/tcp.h中的一段话.我根据这句话 <br>
: 对照源代码去看,可能没有看明白,产生很多疑问 <br>
: /* There are a few simple rules, which allow for local port reuse by <br>
: * an application. In essence: <br>
: * <br>
: * 1) Sockets bound to different interfaces may share a local port. <br>
: * Failing that, goto test 2. <br>
: * 2) If all sockets have sk->reuse set, and none of them are in <br>
: * TCP_LISTEN state, the port may be shared. <br>
: * Failing that, goto test 3. <br>
: .................(以下省略) <br>
<br>
-- <br>
<br>
也许有一天,他再从海上蓬蓬的雨点中升起, <br>
飞向西来,再形成一道江流,再冲倒两旁的石壁, <br>
再来寻夹岸的桃花。然而,我不敢说来生,也不敢信来生...... <br>
※ 修改:·scz 於 ★★ 欢迎光临 ★ 修改本文·[FROM: 211.167.65.123] <br>
※ 来源:·UNIX编程 www.tiaozhan.com/unixbbs/·[FROM: 211.167.65.123] <br>
发信人: scz (小四), 信区: UNP <br>
标 题: Re: 看看这段话 <br>
发信站: UNIX编程 (2001年08月31日14:34:45 星期五), 站内信件 <br>
<br>
之所以后来不想看Linux内核源码,就是因为我已经没精力 <br>
去区分哪个是标准,哪个是扩展。担心有天因为习惯了Linux <br>
的扩展而想当然地应用到其他Unix上去。我们现在已经不是 <br>
兴趣爱好的问题,很多东西要考虑最基本最广泛兼容的标准, <br>
可移植性越来越重要,做学生可以不考虑,干活就得考虑了。 <br>
否则就成急功近利。 <br>
<br>
Linux在tcp/ip的实现上考虑得很现实,打破了很多条条框框, <br>
所以它效率高,这是它的优点。它的扩展也是随心所欲, <br>
反正不怕升级内核。作为研究、个人兴趣爱好,实在是再妙 <br>
不过 <br>
<br>
这次讨论我也是学到不少东西,比较有意思。 <br>
<br>
【 在 ysqcn (岁月无声) 的大作中提到: 】 <br>
: 这是/usr/src/linux-2.4/include/net/tcp.h中的一段话.我根据这句话 <br>
: 对照源代码去看,可能没有看明白,产生很多疑问 <br>
: /* There are a few simple rules, which allow for local port reuse by <br>
: * an application. In essence: <br>
: * <br>
: * 1) Sockets bound to different interfaces may share a local port. <br>
: * Failing that, goto test 2. <br>
: * 2) If all sockets have sk->reuse set, and none of them are in <br>
: * TCP_LISTEN state, the port may be shared. <br>
: * Failing that, goto test 3. <br>
: .................(以下省略) <br>
<br>
-- <br>
<br>
也许有一天,他再从海上蓬蓬的雨点中升起, <br>
飞向西来,再形成一道江流,再冲倒两旁的石壁, <br>
再来寻夹岸的桃花。然而,我不敢说来生,也不敢信来生...... <br>
※ 来源:·UNIX编程 www.tiaozhan.com/unixbbs/·[FROM: 211.167.65.123] <br>
</small><hr>
<p align="center">[<a href="index.htm">回到开始</a>][<a href="54.htm">上一层</a>][<a href="67.htm">下一篇</a>]
<p align="center"><a href="http://cterm.163.net">欢迎访问Cterm主页</a></p>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -