DTRACE_IP(4)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’… DTRACE_IP πŸ’…

okay so bestie, welcome to the dtrace_ip page β€” that's the DTrace provider for tracing all the stuff that goes down with the IPv4 and IPv6 protocols, no cap ✨


🌸 NAME 🌸

dtrace_ip β€” a DTrace provider for tracing events related to the IPv4 and IPv6 protocols. that's it, that's the whole vibe πŸ¦‹


✨ SYNOPSIS ✨

ip:::receive(pktinfo_t *, csinfo_t *, ipinfo_t *, ifinfo_t *,
    ipv4info_t *, ipv6info_t *);

ip:::send(pktinfo_t *, csinfo_t *, ipinfo_t *, ifinfo_t *, ipv4info_t *,
    ipv6info_t *);

πŸŽ€ DESCRIPTION πŸŽ€

So the DTrace ip provider lets you trace events inside the ip(4) and ip6(4) protocol implementations. literally iconic.

  • ip:::send() β€” this probe fires whenever the kernel gets ready to transmit an IP packet, slay πŸ”₯
  • ip:::receive() β€” this one fires whenever the kernel receives an IP packet πŸ’–

The arguments to these probes give you detailed info about the IP headers of the packet in question, plus the network interface it was sent or received on. the way that's so useful 🫢

okay important caveat bestie: unlike the dtrace_tcp(4) and dtrace_udp(4) providers, ip provider probes are triggered by forwarded packets. that means the probes will fire on packets that are not destined to the local host. yes really. don't come for me, that's just how it is πŸ’€

πŸ‘‘ ARGUMENTS πŸ‘‘

🧚 pktinfo_t

This argument is currently unimplemented and is only included for compatibility with other implementations of this provider. its fields are:

  • uintptr_t pkt_addr β€” always set to 0.

🌈 csinfo_t

Also currently unimplemented, also just there for compatibility with other implementations of this provider. its fields are:

  • uintptr_t cs_addr β€” always set to 0.
  • uint64_t cs_cid β€” a pointer to the struct inpcb for this packet, or NULL.
  • pid_t cs_pid β€” always set to 0.

πŸ¦‹ ipinfo_t

This one has the IP fields that are common to both IPv4 and IPv6 packets. its fields are:

  • uint8_t ip_ver β€” IP version of the packet: 4 for IPv4 packets and 6 for IPv6 packets.
  • uint32_t ip_plength β€” IP payload size. this does not include the size of the IP header or the IPv6 option headers.
  • string ip_saddr β€” IP source address.
  • string ip_daddr β€” IP destination address.

πŸ’– ifinfo_t

Describes the outgoing and incoming interfaces for the packet in the ip:::send() and ip:::receive() probes respectively. its fields are:

  • string if_name β€” the interface name.
  • int8_t if_local β€” a boolean value indicating whether or not the interface is a loopback interface.
  • uintptr_t if_addr β€” a pointer to the struct ifnet which describes the interface. see the ifnet(9) manual page, iykyk.

πŸ“ ipv4info_t

Contains the fields of the IP header for IPv4 packets. this argument is NULL for IPv6 packets, so heads up πŸ™ˆ β€” DTrace scripts should use the ip_ver() field in the ipinfo_t argument to figure out whether to use this argument. its fields are:

  • uint8_t ipv4_ver β€” IP version. this will always be 4 for IPv4 packets.
  • uint8_t ipv4_ihl β€” the IP header length, including options, in 32-bit words.
  • uint8_t ipv4_tos β€” IP type of service field.
  • uint16_t ipv4_length β€” the total packet length, including the header, in bytes.
  • uint16_t ipv4_ident β€” identification field.
  • uint8_t ipv4_flags β€” the IP flags.
  • uint16_t ipv4_offset β€” the fragment offset of the packet.
  • uint8_t ipv4_ttl β€” time to live field.
  • uint8_t ipv4_protocol β€” next-level protocol ID.
  • string ipv4_protostr β€” a string containing the name of the encapsulated protocol. the protocol strings are defined in the protocol array in /usr/lib/dtrace/ip.d ⭐
  • uint16_t ipv4_checksum β€” the IP checksum.
  • ipaddr_t ipv4_src β€” IPv4 source address.
  • ipaddr_t ipv4_dst β€” IPv4 destination address.
  • string ipv4_saddr β€” a string representation of the source address.
  • string ipv4_daddr β€” a string representation of the destination address.
  • ipha_t *ipv4_hdr β€” a pointer to the raw IPv4 header.

πŸ’œ ipv6info_t

Contains the fields of the IP header for IPv6 packets. its fields are not set for IPv4 packets β€” and same as with the ipv4info_t argument, use the ip_ver() field to determine whether this argument is valid. its fields are:

  • uint8_t ipv6_ver β€” IP version. this will always be 6 for IPv6 packets.
  • uint8_t ipv6_tclass β€” the traffic class, used to set the differentiated services codepoint and extended congestion notification flags.
  • uint32_t ipv6_flow β€” the flow label of the packet.
  • uint16_t ipv6_plen β€” the IP payload size, including extension headers, in bytes.
  • uint8_t ipv6_nexthdr β€” an identifier for the type of the next header.
  • string ipv6_nextstr β€” a string representation of the type of the next header.
  • uint8_t ipv6_hlim β€” the hop limit.
  • ip6_addr_t *ipv6_src β€” IPv6 source address.
  • ip6_addr_t *ipv6_dst β€” IPv6 destination address.
  • string ipv6_saddr β€” a string representation of the source address.
  • string ipv6_daddr β€” a string representation of the destination address.
  • struct ip6_hdr *ipv6_hdr β€” a pointer to the raw IPv6 header.

πŸŽ€ FILES πŸŽ€

  • /usr/lib/dtrace/ip.d β€” DTrace type and translator definitions for the ip provider. literally the moment πŸ’…

πŸ”₯ EXAMPLES πŸ”₯

okay so this first script counts received packets by remote host address. eat:

ip:::receive
{
        @num[args[2]->ip_saddr] = count();
}

and this script prints some details of each IP packet as it's sent or received by the kernel. main character script fr fr:

#pragma D option quiet
#pragma D option switchrate=10Hz

dtrace:::BEGIN
{
        printf(" %10s %30s    %-30s %8s %6s\n", "DELTA(us)", "SOURCE",
            "DEST", "INT", "BYTES");
        last = timestamp;
}

ip:::send
{
        this->elapsed = (timestamp - last) / 1000;
        printf(" %10d %30s -> %-30s %8s %6d\n", this->elapsed,
            args[2]->ip_saddr, args[2]->ip_daddr, args[3]->if_name,
            args[2]->ip_plength);
        last = timestamp;
}

ip:::receive
{
        this->elapsed = (timestamp - last) / 1000;
        printf(" %10d %30s <- %-30s %8s %6d\n", this->elapsed,
            args[2]->ip_daddr, args[2]->ip_saddr, args[3]->if_name,
            args[2]->ip_plength);
        last = timestamp;
}

🌈 COMPATIBILITY 🌈

This provider is compatible with the ip providers found in Solaris and Darwin. bestie behaviour honestly 🫢


⭐ SEE ALSO ⭐

dtrace(1), dtrace_tcp(4), dtrace_udp(4), ip(4), ip6(4), ifnet(9), SDT(9)


🌸 HISTORY 🌸

The ip provider first appeared in FreeBSD 10.0. a classic, an icon, a legend πŸ‘‘


πŸ’– AUTHORS πŸ’–

This manual page was written by Mark Johnston <markj@FreeBSD.org>. thank you king 🫑


and that's the whole page bestie ✨ this one came from the Debian gang, dated September 14, 2015, and it's the DTRACE_IP(4) kernel interfaces manual β€” go forth and trace those packets πŸ’…πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from