icmp, IPPROTO_ICMP - Linux IPv4 ICMP 核心模块.

本文深入解析了基于RFC792的互联网控制报文协议(ICMP)。ICMP用于在网络主机间通讯出错时提供诊断信息,是核心协议模块的重要组成部分。文章详细介绍了ICMP的工作原理,包括其与应用层的交互方式,以及Linux系统如何通过sysctl接口设置ICMP的全局参数。此外,还探讨了ICMP在原始套接字(rawsocket)中的应用及其限制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

DESCRIPTION 描述

本网络核心协议模块实现了基于 RFC792 协议中定义的《互联网控制报文协议》。它针对网络主机间通讯出错的情况作出回应并给出诊断信息。用户不能直接使用本模块。相反本模块需与核心中的其他协议进行通讯,而这些协议将 ICMP 出错信息返回到网络协议的应用层。ICMP 核心模块也回应 ICMP 请求。

如果用 IPPROTP_ICMP 打开原始套接字(raw socket)时,用户协议有可以收到任意本地套接字 ICMP 包。 IPPROTO_ICMP. 请参阅 raw(7) 传递到套接字的 ICMP 包可以用 ICMP_FILTER 套接字选项进行过滤。核心会处理所有 ICMP 包,包括传递到用户的套接字去的。

Linux 对可以到达每个目标主机出错信息包的比率设立了限制。 ICMP_REDIRECTICMP_DEST_UNREACH 也受进入包的目标路由的限制。

 

SYSCTLS

ICMP 支持通过 sysctl 接口来设置一些全局 IP 参数。对 Sysctl 的访问可以通过读、写 /proc/sys/net/ipv4/* 下的文件通过 sysctl(2) 接口进行. 大多数这些 sysctls 对特定 ICMP 类型的数据包数量进行了限制。 Linux 2.2 使用记号单元过滤器对 ICMP 包进行限制。 此值表示超时错误,以秒计,直到到顶后记号单元过滤器被清除为止。

icmp_destunreach_rate
发送目的地不可到达 ICMP 消息包的最大数据包比率。这限制了发送到任意一个路由或目的地的数据包的比率。这个限制不影响发送用来发现数据链路最大传送单位(MTU)的 ICMP_FRAG_NEEDED包 数据包。
icmp_echo_ignore_all
如果该值不为零,Linux将忽略所有的 ICMP_ECHO 请求。
icmp_echo_ignore_broadcasts
如果该值不为零,Linux将忽略所有发送到广播地址的 ICMP_ECHO 数据包。
icmp_echoreply_rate
发送响应 ICMP_ECHOREQUEST 请求的 ICMP_ECHOREPLY 数据包比率的最大值。
icmp_paramprob_rate
发送 ICMP_PARAMETERPROB 数据包比率的最大值。当一个具有非法 IP 报头数据包到达时将发送这些包。
icmp_timeexceed_rate
发送 ICMP_TIME_EXCEEDED 包比率的最大值。当一个数据包通过太多网段时,这些包用作防止路由回环。

NOTES

由于在许多其他实现中不支持 IPPROTO_ICMP 原始套接字(raw socket),可移植程序不能依靠这一特性。

 

当Linux不作为路由器时,将不被发送 ICMP_REDIRECT 包。内核也只有在路由表中的旧网关和路由重新定向超时时才接受这些包。

ICMP_TIMESTAMP 返回的 64 位毫秒为单位的时间戳是自1970年1月1日以来的时间.

Linux 的 ICMP 在内部使用原始套接字(raw socket)来发送ICMP包。这个原始套接字可能在 netstat(8) 消息输出中出现,带着一个“zero inode”信息。 

转载于:https://www.cnblogs.com/fanweisheng/p/11087891.html

编译xdp_redirect.c,20个报错 In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:31:8: error: redefinition of 'in_addr' struct in_addr ^ /usr/include/linux/in.h:89:8: note: previous definition is here struct in_addr { ^ In file included from xdp_redirect.c:8: In file included from /usr/include/netinet/in.h:37: /usr/include/x86_64-linux-gnu/bits/in.h:150:8: error: redefinition of 'ip_mreqn' struct ip_mreqn ^ /usr/include/linux/in.h:180:8: note: previous definition is here struct ip_mreqn { ^ In file included from xdp_redirect.c:8: In file included from /usr/include/netinet/in.h:37: /usr/include/x86_64-linux-gnu/bits/in.h:158:8: error: redefinition of 'in_pktinfo' struct in_pktinfo ^ /usr/include/linux/in.h:251:8: note: previous definition is here struct in_pktinfo { ^ In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:42:5: error: redefinition of enumerator 'IPPROTO_IP' IPPROTO_IP = 0, /* Dummy protocol for TCP. */ ^ /usr/include/linux/in.h:30:21: note: expanded from macro 'IPPROTO_IP' #define IPPROTO_IP IPPROTO_IP ^ /usr/include/linux/in.h:29:3: note: previous definition is here IPPROTO_IP = 0, /* Dummy protocol for TCP */ ^ In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:44:5: error: redefinition of enumerator 'IPPROTO_ICMP' IPPROTO_ICMP = 1, /* Internet Control Message Protocol. */ ^ /usr/include/linux/in.h:32:23: note: expanded from macro 'IPPROTO_ICMP' #define IPPROTO_ICMP IPPROTO_ICMP ^ /usr/include/linux/in.h:31:3: note: previous definition is here IPPROTO_ICMP = 1, /* Internet Control Message Protocol */ ^ In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:46:5: error: redefinition of enumerator 'IPPROTO_IGMP' IPPROTO_IGMP = 2, /* Internet Group Management Protocol. */ ^ /usr/include/linux/in.h:34:23: note: expanded from macro 'IPPROTO_IGMP' #define IPPROTO_IGMP IPPROTO_IGMP ^ /usr/include/linux/in.h:33:3: note: previous definition is here IPPROTO_IGMP = 2, /* Internet Group Management Protocol */ ^ In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:48:5: error: redefinition of enumerator 'IPPROTO_IPIP' IPPROTO_IPIP = 4, /* IPIP tunnels (older KA9Q tunnels use 94). */ ^ /usr/include/linux/in.h:36:23: note: expanded from macro 'IPPROTO_IPIP' #define IPPROTO_IPIP IPPROTO_IPIP ^ /usr/include/linux/in.h:35:3: note: previous definition is here IPPROTO_IPIP = 4, /* IPIP tunnels (older KA9Q tunnels use 94) */ ^ In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:50:5: error: redefinition of enumerator 'IPPROTO_TCP' IPPROTO_TCP = 6, /* Transmission Control Protocol. */ ^ /usr/include/linux/in.h:38:22: note: expanded from macro 'IPPROTO_TCP' #define IPPROTO_TCP IPPROTO_TCP ^ /usr/include/linux/in.h:37:3: note: previous definition is here IPPROTO_TCP = 6, /* Transmission Control Protocol */ ^ In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:52:5: error: redefinition of enumerator 'IPPROTO_EGP' IPPROTO_EGP = 8, /* Exterior Gateway Protocol. */ ^ /usr/include/linux/in.h:40:22: note: expanded from macro 'IPPROTO_EGP' #define IPPROTO_EGP IPPROTO_EGP ^ /usr/include/linux/in.h:39:3: note: previous definition is here IPPROTO_EGP = 8, /* Exterior Gateway Protocol */ ^ In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:54:5: error: redefinition of enumerator 'IPPROTO_PUP' IPPROTO_PUP = 12, /* PUP protocol. */ ^ /usr/include/linux/in.h:42:22: note: expanded from macro 'IPPROTO_PUP' #define IPPROTO_PUP IPPROTO_PUP ^ /usr/include/linux/in.h:41:3: note: previous definition is here IPPROTO_PUP = 12, /* PUP protocol */ ^ In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:56:5: error: redefinition of enumerator 'IPPROTO_UDP' IPPROTO_UDP = 17, /* User Datagram Protocol. */ ^ /usr/include/linux/in.h:44:22: note: expanded from macro 'IPPROTO_UDP' #define IPPROTO_UDP IPPROTO_UDP ^ /usr/include/linux/in.h:43:3: note: previous definition is here IPPROTO_UDP = 17, /* User Datagram Protocol */ ^ In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:58:5: error: redefinition of enumerator 'IPPROTO_IDP' IPPROTO_IDP = 22, /* XNS IDP protocol. */ ^ /usr/include/linux/in.h:46:22: note: expanded from macro 'IPPROTO_IDP' #define IPPROTO_IDP IPPROTO_IDP ^ /usr/include/linux/in.h:45:3: note: previous definition is here IPPROTO_IDP = 22, /* XNS IDP protocol */ ^ In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:60:5: error: redefinition of enumerator 'IPPROTO_TP' IPPROTO_TP = 29, /* SO Transport Protocol Class 4. */ ^ /usr/include/linux/in.h:48:21: note: expanded from macro 'IPPROTO_TP' #define IPPROTO_TP IPPROTO_TP ^ /usr/include/linux/in.h:47:3: note: previous definition is here IPPROTO_TP = 29, /* SO Transport Protocol Class 4 */ ^ In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:62:5: error: redefinition of enumerator 'IPPROTO_DCCP' IPPROTO_DCCP = 33, /* Datagram Congestion Control Protocol. */ ^ /usr/include/linux/in.h:50:23: note: expanded from macro 'IPPROTO_DCCP' #define IPPROTO_DCCP IPPROTO_DCCP ^ /usr/include/linux/in.h:49:3: note: previous definition is here IPPROTO_DCCP = 33, /* Datagram Congestion Control Protocol */ ^ In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:64:5: error: redefinition of enumerator 'IPPROTO_IPV6' IPPROTO_IPV6 = 41, /* IPv6 header. */ ^ /usr/include/linux/in.h:52:23: note: expanded from macro 'IPPROTO_IPV6' #define IPPROTO_IPV6 IPPROTO_IPV6 ^ /usr/include/linux/in.h:51:3: note: previous definition is here IPPROTO_IPV6 = 41, /* IPv6-in-IPv4 tunnelling */ ^ In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:66:5: error: redefinition of enumerator 'IPPROTO_RSVP' IPPROTO_RSVP = 46, /* Reservation Protocol. */ ^ /usr/include/linux/in.h:54:23: note: expanded from macro 'IPPROTO_RSVP' #define IPPROTO_RSVP IPPROTO_RSVP ^ /usr/include/linux/in.h:53:3: note: previous definition is here IPPROTO_RSVP = 46, /* RSVP Protocol */ ^ In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:68:5: error: redefinition of enumerator 'IPPROTO_GRE' IPPROTO_GRE = 47, /* General Routing Encapsulation. */ ^ /usr/include/linux/in.h:56:22: note: expanded from macro 'IPPROTO_GRE' #define IPPROTO_GRE IPPROTO_GRE ^ /usr/include/linux/in.h:55:3: note: previous definition is here IPPROTO_GRE = 47, /* Cisco GRE tunnels (rfc 1701,1702) */ ^ In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:70:5: error: redefinition of enumerator 'IPPROTO_ESP' IPPROTO_ESP = 50, /* encapsulating security payload. */ ^ /usr/include/linux/in.h:58:22: note: expanded from macro 'IPPROTO_ESP' #define IPPROTO_ESP IPPROTO_ESP ^ /usr/include/linux/in.h:57:3: note: previous definition is here IPPROTO_ESP = 50, /* Encapsulation Security Payload protocol */ ^ In file included from xdp_redirect.c:8: /usr/include/netinet/in.h:72:5: error: redefinition of enumerator 'IPPROTO_AH' IPPROTO_AH = 51, /* authentication header. */ ^ /usr/include/linux/in.h:60:21: note: expanded from macro 'IPPROTO_AH' #define IPPROTO_AH IPPROTO_AH ^ /usr/include/linux/in.h:59:3: note: previous definition is here IPPROTO_AH = 51, /* Authentication Header protocol */ ^ fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated.
最新发布
06-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值