ICMP6(4)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’– 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 unreachable
  • 2 Β· toobig β€” Packet too big
  • 3 Β· timex β€” Time exceeded
  • 4 Β· paramprob β€” Invalid IPv6 header
  • 128 Β· echoreq β€” Echo service request
  • 129 Β· echorep β€” Echo service reply
  • 130 Β· groupqry β€” Group membership query
  • 130 Β· listqry β€” Multicast listener query
  • 131 Β· grouprep β€” Group membership report
  • 131 Β· listenrep β€” Multicast listener report
  • 132 Β· groupterm β€” Group membership termination
  • 132 Β· listendone β€” Multicast listener done
  • 133 Β· routersol β€” Router solicitation
  • 134 Β· routeradv β€” Router advertisement
  • 135 Β· neighbrsol β€” Neighbor solicitation
  • 136 Β· neighbradv β€” Neighbor advertisement
  • 137 Β· redir β€” Shorter route exists
  • 138 Β· routrrenum β€” Route renumbering
  • 139 Β· fqdnreq β€” FQDN query
  • 139 Β· niqry β€” Node information query
  • 139 Β· wrureq β€” Who-are-you request
  • 140 Β· fqdnrep β€” FQDN reply
  • 140 Β· nirep β€” Node information reply
  • 140 Β· wrurep β€” Who-are-you reply
  • 200 Β· mtraceresp β€” mtrace response
  • 201 Β· mtrace β€” mtrace messages

and the following codes are defined:

  • 0 Β· noroute-unr Β· type unreach β€” No route to destination
  • 1 Β· admin-unr Β· type unreach β€” Administratively prohibited
  • 2 Β· beyond-unr Β· type unreach β€” Beyond scope of source address
  • 2 Β· notnbr-unr Β· type unreach β€” Not a neighbor (obsolete)
  • 3 Β· addr-unr Β· type unreach β€” Address unreachable
  • 4 Β· port-unr Β· type unreach β€” Port unreachable
  • 0 Β· transit Β· type timex β€” Time exceeded in transit
  • 1 Β· reassemb Β· type timex β€” Time exceeded in reassembly
  • 0 Β· badhead Β· type paramprob β€” Erroneous header field
  • 1 Β· nxthdr Β· type paramprob β€” Unrecognized next header
  • 2 Β· (no abbreviation) Β· type redir β€” Unrecognized option
  • 0 Β· redironlink Β· type redir β€” Redirection to on-link node
  • 1 Β· redirrouter Β· type redir β€” 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. filterp is modified to allow all message types.
  • void ICMP6_FILTER_SETBLOCKALL(struct icmp6_filter *filterp) β€” Ignore all incoming messages. filterp is modified to ignore all message types.
  • void ICMP6_FILTER_SETPASS(int type, struct icmp6_filter *filterp) β€” Allow ICMPv6 messages with the given type. filterp is modified to allow such messages.
  • void ICMP6_FILTER_SETBLOCK(int type, struct icmp6_filter *filterp) β€” Ignore ICMPv6 messages with the given type. filterp is 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 ⭐

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