关于raw socket以及内核转发问题

fgkenshin 2010-03-09 09:32:14
通过raw socket来收取icmp信息时,建立了raw socket后,系统内核会向这个socket转发一份内容。
请问一下
1.多个raw socket接收时,内核如何转发及处理?什么时候触发icmpInOverflows?
2.比如我一个进程建立一个raw发送ICMP,一个进程raw建立一个raw接收,这时候居然icmpInOverflows
2010 Mar 9 20:41:02, icmpInEchoReps=49;icmpInMsgs=49;icmpInOverflows=49;

UNIX Network Programming Volume 1
When the kernel has an IP datagram to pass to the raw sockets, all raw sockets for all processes are examined, looking for all matching sockets. A copy of the IP datagram is delivered to each matching socket.

dtrace监控icmp mib

#!/usr/sbin/dtrace -s
/*
* icmpstat.d - print ICMP statistics. Uses DTrace.
*
* This prints ICMP statistics every second, retrieved from the MIB provider.
* This is a simple script to demonstrate the ability to trace ICMP events.
*
* $Id: icmpstat.d 3 2007-08-01 10:50:08Z brendan $
*
* USAGE: icmpstat.d
*
* FIELDS:
* STATISTIC ICMP statistic name
* VALUE total of statistic during sample
*
* The above ICMP statistics are documented in the mib2_icmp struct
* in the /usr/include/inet/mib2.h file; and also in the mib provider
* chapter of the DTrace Guide, http://docs.sun.com/db/doc/817-6223.
*
* COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at Docs/cddl1.txt
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* CDDL HEADER END
*
* 25-Jul-2005 Brendan Gregg Created this.
* 25-Jul-2005 " " Last update.
*/

#pragma D option quiet

/*
* Save Data
*/
mib:::icmp*
{
@icmp[probename] = sum(arg0);
}

/*
* Print Output
*/
profile:::tick-5sec
{
printf("%Y,\t", walltimestamp);
printa("%s=%@d;", @icmp);
printf("\n");
trunc(@icmp);
}

...全文
205 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
fgkenshin 2010-03-12
  • 打赏
  • 举报
回复
2.比如我一个进程建立一个raw发送ICMP,一个进程raw建立一个raw接收,这时候居然icmpInOverflows
2010 Mar 9 20:41:02, icmpInEchoReps=49;icmpInMsgs=49;icmpInOverflows=49;

创建raw socket后,内核就会给该raw socket转相应的内容的副本。当然,如果该raw socket不接受的话,内核发送的副本将会被当作overflow给丢弃掉,这就是为什么会出现 icmpInOverflows 的情况。
目前没探索出如何多个raw发送,一个raw去接收的情况。
  • 打赏
  • 举报
回复
我插一楼,然后楼主又可以整三楼了!
fgkenshin 2010-03-12
  • 打赏
  • 举报
回复
....真悲剧,居然没人回复我。。。自己给自己回答吧。。。占一楼
fgkenshin 2010-03-09
  • 打赏
  • 举报
回复
忘记说了。操作系统是Solaris5.10

70,020

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧