ICMP6(4)
π ICMP6(4) π β the icmp6 manual, section 4 of the Kernel Interfaces Manual, bestie edition
okay so this is icmp6(4) β the Internet Control Message Protocol for IPv6 page. yes it's a kernel interfaces manual, yes it's from the Debian build dated November 1, 2018, and yes we're gonna get through it together. grab a boba. π§
β¨ NAME β¨
icmp6 β Internet Control Message Protocol for IPv6
β¨ SYNOPSIS β¨
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/icmp6.h>
int
socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
β¨ DESCRIPTION β¨
ICMPv6 is literally the error-and-control-message protocol that IPv6 and the whole IPv6 protocol family ride on (peep ip6(4) and inet6(4) if you wanna go deeper). you can reach it through a "raw socket" β that's your girl for network monitoring and diagnostic functions. π
so when you call socket(2) to make an ICMPv6 socket, the proto parameter can come from getprotobyname(3). ICMPv6 sockets are connectionless β no commitment, no strings β and they're normally used with the sendto(2) and recvfrom(2) calls. but you can also use connect(2) to fix the destination for future packets, and in that case read(2) or recv(2) plus write(2) or send(2) system calls are fair game too. π
outgoing packets automatically get an IPv6 header prepended to them (based on the destination address, slay). incoming packets on the socket are received with the IPv6 header and any extension headers removed. yes, stripped. gone. π
π¦ Types π¦
ICMPv6 messages get classified by the type and code fields sitting in the ICMPv6 header. and the abbreviations for the types and codes? those can be used in rules in pf.conf(5). iconic crossover. the following types are defined:
1Β·unreachβ Destination unreachable2Β·toobigβ Packet too big3Β·timexβ Time exceeded4Β·paramprobβ Invalid IPv6 header128Β·echoreqβ Echo service request129Β·echorepβ Echo service reply130Β·groupqryβ Group membership query130Β·listqryβ Multicast listener query131Β·grouprepβ Group membership report131Β·listenrepβ Multicast listener report132Β·grouptermβ Group membership termination132Β·listendoneβ Multicast listener done133Β·routersolβ Router solicitation134Β·routeradvβ Router advertisement135Β·neighbrsolβ Neighbor solicitation136Β·neighbradvβ Neighbor advertisement137Β·redirβ Shorter route exists138Β·routrrenumβ Route renumbering139Β·fqdnreqβ FQDN query139Β·niqryβ Node information query139Β·wrureqβ Who-are-you request140Β·fqdnrepβ FQDN reply140Β·nirepβ Node information reply140Β·wrurepβ Who-are-you reply200Β·mtracerespβ mtrace response201Β·mtraceβ mtrace messages
and the following codes are defined:
0Β·noroute-unrΒ· typeunreachβ No route to destination1Β·admin-unrΒ· typeunreachβ Administratively prohibited2Β·beyond-unrΒ· typeunreachβ Beyond scope of source address2Β·notnbr-unrΒ· typeunreachβ Not a neighbor (obsolete)3Β·addr-unrΒ· typeunreachβ Address unreachable4Β·port-unrΒ· typeunreachβ Port unreachable0Β·transitΒ· typetimexβ Time exceeded in transit1Β·reassembΒ· typetimexβ Time exceeded in reassembly0Β·badheadΒ· typeparamprobβ Erroneous header field1Β·nxthdrΒ· typeparamprobβ Unrecognized next header2Β· (no abbreviation) Β· typeredirβ Unrecognized option0Β·redironlinkΒ· typeredirβ Redirection to on-link node1Β·redirrouterΒ· typeredirβ Redirection to better router
πΈ Headers πΈ
every single ICMPv6 message gets prefixed with an ICMPv6 header. that header corresponds to the icmp6_hdr structure and has this definition, bestie, look at it:
struct icmp6_hdr {
uint8_t icmp6_type; /* type field */
uint8_t icmp6_code; /* code field */
uint16_t icmp6_cksum; /* checksum field */
union {
uint32_t icmp6_un_data32[1]; /* type-specific */
uint16_t icmp6_un_data16[2]; /* type-specific */
uint8_t icmp6_un_data8[4]; /* type-specific */
} icmp6_dataun;
} __packed;
#define icmp6_data32 icmp6_dataun.icmp6_un_data32
#define icmp6_data16 icmp6_dataun.icmp6_un_data16
#define icmp6_data8 icmp6_dataun.icmp6_un_data8
#define icmp6_pptr icmp6_data32[0] /* parameter prob */
#define icmp6_mtu icmp6_data32[0] /* packet too big */
#define icmp6_id icmp6_data16[0] /* echo request/reply */
#define icmp6_seq icmp6_data16[1] /* echo request/reply */
#define icmp6_maxdelay icmp6_data16[0] /* mcast group membership*/
icmp6_type describes the type of the message β suitable values are defined in β¨netinet/icmp6.hβ©. icmp6_code describes the sub-type of the message and it depends on icmp6_type. icmp6_cksum holds the checksum for the message, and the kernel fills it in on outgoing messages (she handles it, don't worry). the other fields are all for type-specific purposes. π«
π Filters π
so because ICMPv6 has way more extra functionality than ICMPv4, a larger number of messages may potentially be received on an ICMPv6 socket. so many messages. π that's why input filters exist β you use them to restrict input to a subset of the incoming ICMPv6 messages, so only the interesting ones get returned by the recv(2) family of calls to an application. vibe check for packets, honestly.
the icmp6_filter structure can refine the input message set according to the ICMPv6 type. by default, all message types are allowed on newly created raw ICMPv6 sockets. the following macros are the ones you use to refine that input set:
void ICMP6_FILTER_SETPASSALL(struct icmp6_filter *filterp)β Allow all incoming messages.filterpis modified to allow all message types.void ICMP6_FILTER_SETBLOCKALL(struct icmp6_filter *filterp)β Ignore all incoming messages.filterpis modified to ignore all message types.void ICMP6_FILTER_SETPASS(int type, struct icmp6_filter *filterp)β Allow ICMPv6 messages with the given type.filterpis modified to allow such messages.void ICMP6_FILTER_SETBLOCK(int type, struct icmp6_filter *filterp)β Ignore ICMPv6 messages with the given type.filterpis modified to ignore such messages.int ICMP6_FILTER_WILLPASS(int type, const struct icmp6_filter *filterp)β Determine if the given filter will allow an ICMPv6 message of the given type.int ICMP6_FILTER_WILLBLOCK(int type, const struct icmp6_filter *filterp)β Determine if the given filter will ignore an ICMPv6 message of the given type.
the getsockopt(2) and setsockopt(2) calls are how you obtain and install the filter on ICMPv6 sockets β option level IPPROTO_ICMPV6, name ICMP6_FILTER, with a pointer to the icmp6_filter structure as the option value. that's the whole recipe. π«Ά
β SEE ALSO β
getsockopt(2),recv(2),send(2),setsockopt(2),socket(2)getprotobyname(3)inet6(4),ip6(4),netintro(4)
the receipts, aka the references, all here, no gatekeeping:
- W. Stevens and M. Thomas, Advanced Sockets API for IPv6, RFC 2292, February 1998.
- A. Conta and S. Deering, Internet Control Message Protocol (ICMPv6) for the Internet Protocol Version 6 (IPv6) Specification, RFC 2463, December 1998.
- W. Stevens, M. Thomas, E. Nordmark, and T. Jinmei, Advanced Sockets Application Program Interface (API) for IPv6, RFC 3542, May 2003.
- A. Conta, S. Deering, and M. Gupta, Internet Control Message Protocol (ICMPv6) for the Internet Protocol Version 6 (IPv6) Specification, RFC 4443, March 2006.
k that's the whole page, go build something cute with raw IPv6 sockets, ily π
and that's a wrap! this edition came from Debian, dated November 1, 2018 β that's the source and the date, mwah, bye bestie πβ¨π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 1986, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms