157f60867SMark Johnston /* 257f60867SMark Johnston * CDDL HEADER START 357f60867SMark Johnston * 457f60867SMark Johnston * The contents of this file are subject to the terms of the 557f60867SMark Johnston * Common Development and Distribution License (the "License"). 657f60867SMark Johnston * You may not use this file except in compliance with the License. 757f60867SMark Johnston * 857f60867SMark Johnston * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 957f60867SMark Johnston * or http://www.opensolaris.org/os/licensing. 1057f60867SMark Johnston * See the License for the specific language governing permissions 1157f60867SMark Johnston * and limitations under the License. 1257f60867SMark Johnston * 1357f60867SMark Johnston * When distributing Covered Code, include this CDDL HEADER in each 1457f60867SMark Johnston * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1557f60867SMark Johnston * If applicable, add the following below this CDDL HEADER, with the 1657f60867SMark Johnston * fields enclosed by brackets "[]" replaced with your own identifying 1757f60867SMark Johnston * information: Portions Copyright [yyyy] [name of copyright owner] 1857f60867SMark Johnston * 1957f60867SMark Johnston * CDDL HEADER END 2057f60867SMark Johnston */ 2157f60867SMark Johnston /* 2257f60867SMark Johnston * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. 2357f60867SMark Johnston * Copyright (c) 2013 Mark Johnston <markj@freebsd.org> 2457f60867SMark Johnston */ 2557f60867SMark Johnston 267e518a66SMark Johnston #pragma D depends_on module kernel 2757f60867SMark Johnston #pragma D depends_on provider ip 2857f60867SMark Johnston 2957f60867SMark Johnston /* 3057f60867SMark Johnston * pktinfo is where packet ID info can be made available for deeper 3157f60867SMark Johnston * analysis if packet IDs become supported by the kernel in the future. 3257f60867SMark Johnston * The pkt_addr member is currently always NULL. 3357f60867SMark Johnston */ 3457f60867SMark Johnston typedef struct pktinfo { 3557f60867SMark Johnston uintptr_t pkt_addr; 3657f60867SMark Johnston } pktinfo_t; 3757f60867SMark Johnston 3857f60867SMark Johnston /* 3957f60867SMark Johnston * csinfo is where connection state info is made available. 4057f60867SMark Johnston */ 4157f60867SMark Johnston typedef uint32_t zoneid_t; 4257f60867SMark Johnston typedef struct csinfo { 4357f60867SMark Johnston uintptr_t cs_addr; 4457f60867SMark Johnston uint64_t cs_cid; 4557f60867SMark Johnston pid_t cs_pid; 4657f60867SMark Johnston zoneid_t cs_zoneid; 4757f60867SMark Johnston } csinfo_t; 4857f60867SMark Johnston 4957f60867SMark Johnston /* 5057f60867SMark Johnston * ipinfo contains common IP info for both IPv4 and IPv6. 5157f60867SMark Johnston */ 5257f60867SMark Johnston typedef struct ipinfo { 5357f60867SMark Johnston uint8_t ip_ver; /* IP version (4, 6) */ 5457f60867SMark Johnston uint32_t ip_plength; /* payload length */ 5557f60867SMark Johnston string ip_saddr; /* source address */ 5657f60867SMark Johnston string ip_daddr; /* destination address */ 5757f60867SMark Johnston } ipinfo_t; 5857f60867SMark Johnston 5957f60867SMark Johnston /* 6057f60867SMark Johnston * ifinfo contains network interface info. 6157f60867SMark Johnston */ 6257f60867SMark Johnston typedef struct ifinfo { 6357f60867SMark Johnston string if_name; /* interface name */ 6457f60867SMark Johnston int8_t if_local; /* is delivered locally */ 6557f60867SMark Johnston /*netstackid_t if_ipstack;*/ /* ipstack ID */ 6657f60867SMark Johnston uintptr_t if_addr; /* pointer to raw ill_t */ 6757f60867SMark Johnston } ifinfo_t; 6857f60867SMark Johnston 6957f60867SMark Johnston typedef uint32_t ipaddr_t; 7057f60867SMark Johnston typedef struct { 7157f60867SMark Johnston uint8_t ipha_version_and_hdr_length; 7257f60867SMark Johnston uint8_t ipha_type_of_service; 7357f60867SMark Johnston uint16_t ipha_length; 7457f60867SMark Johnston uint16_t ipha_ident; 7557f60867SMark Johnston uint16_t ipha_fragment_offset_and_flags; 7657f60867SMark Johnston uint8_t ipha_ttl; 7757f60867SMark Johnston uint8_t ipha_protocol; 7857f60867SMark Johnston uint16_t ipha_hdr_checksum; 7957f60867SMark Johnston ipaddr_t ipha_src; 8057f60867SMark Johnston ipaddr_t ipha_dst; 8157f60867SMark Johnston } ipha_t; 8257f60867SMark Johnston 8357f60867SMark Johnston /* 8457f60867SMark Johnston * ipv4info is a translated version of the IPv4 header (with raw pointer). 8557f60867SMark Johnston * These values are NULL if the packet is not IPv4. 8657f60867SMark Johnston */ 8757f60867SMark Johnston typedef struct ipv4info { 8857f60867SMark Johnston uint8_t ipv4_ver; /* IP version (4) */ 8957f60867SMark Johnston uint8_t ipv4_ihl; /* header length, bytes */ 9057f60867SMark Johnston uint8_t ipv4_tos; /* type of service field */ 9157f60867SMark Johnston uint16_t ipv4_length; /* length (header + payload) */ 9257f60867SMark Johnston uint16_t ipv4_ident; /* identification */ 9357f60867SMark Johnston uint8_t ipv4_flags; /* IP flags */ 9457f60867SMark Johnston uint16_t ipv4_offset; /* fragment offset */ 9557f60867SMark Johnston uint8_t ipv4_ttl; /* time to live */ 9657f60867SMark Johnston uint8_t ipv4_protocol; /* next level protocol */ 9757f60867SMark Johnston string ipv4_protostr; /* next level protocol, as a string */ 9857f60867SMark Johnston uint16_t ipv4_checksum; /* header checksum */ 9957f60867SMark Johnston ipaddr_t ipv4_src; /* source address */ 10057f60867SMark Johnston ipaddr_t ipv4_dst; /* destination address */ 10157f60867SMark Johnston string ipv4_saddr; /* source address, string */ 10257f60867SMark Johnston string ipv4_daddr; /* destination address, string */ 10357f60867SMark Johnston ipha_t *ipv4_hdr; /* pointer to raw header */ 10457f60867SMark Johnston } ipv4info_t; 10557f60867SMark Johnston 10657f60867SMark Johnston /* 10757f60867SMark Johnston * ipv6info is a translated version of the IPv6 header (with raw pointer). 10857f60867SMark Johnston * These values are NULL if the packet is not IPv6. 10957f60867SMark Johnston */ 11057f60867SMark Johnston typedef struct in6_addr in6_addr_t; 11157f60867SMark Johnston typedef struct ipv6info { 11257f60867SMark Johnston uint8_t ipv6_ver; /* IP version (6) */ 11357f60867SMark Johnston uint8_t ipv6_tclass; /* traffic class */ 11457f60867SMark Johnston uint32_t ipv6_flow; /* flow label */ 11557f60867SMark Johnston uint16_t ipv6_plen; /* payload length */ 11657f60867SMark Johnston uint8_t ipv6_nexthdr; /* next header protocol */ 11757f60867SMark Johnston string ipv6_nextstr; /* next header protocol, as a string */ 11857f60867SMark Johnston uint8_t ipv6_hlim; /* hop limit */ 11957f60867SMark Johnston in6_addr_t *ipv6_src; /* source address */ 12057f60867SMark Johnston in6_addr_t *ipv6_dst; /* destination address */ 12157f60867SMark Johnston string ipv6_saddr; /* source address, string */ 12257f60867SMark Johnston string ipv6_daddr; /* destination address, string */ 123c50c3318SMark Johnston struct ip6_hdr *ipv6_hdr; /* pointer to raw header */ 12457f60867SMark Johnston } ipv6info_t; 12557f60867SMark Johnston 1262f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_IP 12757f60867SMark Johnston inline short IPPROTO_IP = 0; 1282f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_ICMP 12957f60867SMark Johnston inline short IPPROTO_ICMP = 1; 1302f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_IGMP 13157f60867SMark Johnston inline short IPPROTO_IGMP = 2; 1322f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_IPV4 13357f60867SMark Johnston inline short IPPROTO_IPV4 = 4; 1342f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_TCP 13557f60867SMark Johnston inline short IPPROTO_TCP = 6; 1362f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_UDP 13757f60867SMark Johnston inline short IPPROTO_UDP = 17; 1382f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_IPV6 13957f60867SMark Johnston inline short IPPROTO_IPV6 = 41; 1402f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_ROUTING 14157f60867SMark Johnston inline short IPPROTO_ROUTING = 43; 1422f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_FRAGMENT 14357f60867SMark Johnston inline short IPPROTO_FRAGMENT = 44; 1442f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_RSVP 14557f60867SMark Johnston inline short IPPROTO_RSVP = 46; 1462f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_GRE 14757f60867SMark Johnston inline short IPPROTO_GRE = 47; 1482f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_ESP 14957f60867SMark Johnston inline short IPPROTO_ESP = 50; 1502f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_AH 15157f60867SMark Johnston inline short IPPROTO_AH = 51; 1522f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_MOBILE 15357f60867SMark Johnston inline short IPPROTO_MOBILE = 55; 1542f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_ICMPV6 15557f60867SMark Johnston inline short IPPROTO_ICMPV6 = 58; 1562f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_DSTOPTS 15757f60867SMark Johnston inline short IPPROTO_DSTOPTS = 60; 1582f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_ETHERIP 15957f60867SMark Johnston inline short IPPROTO_ETHERIP = 97; 1602f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_PIM 16157f60867SMark Johnston inline short IPPROTO_PIM = 103; 1622f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_IPCOMP 16357f60867SMark Johnston inline short IPPROTO_IPCOMP = 108; 1642f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_SCTP 16557f60867SMark Johnston inline short IPPROTO_SCTP = 132; 1662f28ceebSMark Johnston #pragma D binding "1.5" IPPROTO_RAW 16757f60867SMark Johnston inline short IPPROTO_RAW = 255; 1687bda9663SMichael Tuexen #pragma D binding "1.13" IPPROTO_UDPLITE 1697bda9663SMichael Tuexen inline short IPPROTO_UDPLITE = 136; 17057f60867SMark Johnston 17157f60867SMark Johnston inline uint8_t INP_IPV4 = 0x01; 17257f60867SMark Johnston inline uint8_t INP_IPV6 = 0x02; 17357f60867SMark Johnston 1742f28ceebSMark Johnston #pragma D binding "1.5" protocols 17557f60867SMark Johnston inline string protocols[int proto] = 17657f60867SMark Johnston proto == IPPROTO_IP ? "IP" : 17757f60867SMark Johnston proto == IPPROTO_ICMP ? "ICMP" : 17857f60867SMark Johnston proto == IPPROTO_IGMP ? "IGMP" : 17957f60867SMark Johnston proto == IPPROTO_IPV4 ? "IPV4" : 18057f60867SMark Johnston proto == IPPROTO_TCP ? "TCP" : 18157f60867SMark Johnston proto == IPPROTO_UDP ? "UDP" : 18257f60867SMark Johnston proto == IPPROTO_IPV6 ? "IPV6" : 18357f60867SMark Johnston proto == IPPROTO_ROUTING ? "ROUTING" : 18457f60867SMark Johnston proto == IPPROTO_FRAGMENT ? "FRAGMENT" : 18557f60867SMark Johnston proto == IPPROTO_RSVP ? "RSVP" : 18657f60867SMark Johnston proto == IPPROTO_GRE ? "GRE" : 18757f60867SMark Johnston proto == IPPROTO_ESP ? "ESP" : 18857f60867SMark Johnston proto == IPPROTO_AH ? "AH" : 18957f60867SMark Johnston proto == IPPROTO_MOBILE ? "MOBILE" : 19057f60867SMark Johnston proto == IPPROTO_ICMPV6 ? "ICMPV6" : 19157f60867SMark Johnston proto == IPPROTO_DSTOPTS ? "DSTOPTS" : 19257f60867SMark Johnston proto == IPPROTO_ETHERIP ? "ETHERIP" : 19357f60867SMark Johnston proto == IPPROTO_PIM ? "PIM" : 19457f60867SMark Johnston proto == IPPROTO_IPCOMP ? "IPCOMP" : 19557f60867SMark Johnston proto == IPPROTO_SCTP ? "SCTP" : 1967bda9663SMichael Tuexen proto == IPPROTO_UDPLITE ? "UDPLITE" : 19757f60867SMark Johnston proto == IPPROTO_RAW ? "RAW" : 19857f60867SMark Johnston "<unknown>"; 19957f60867SMark Johnston 20057f60867SMark Johnston /* 20157f60867SMark Johnston * This field is always NULL according to the current definition of the ip 20257f60867SMark Johnston * probes. 20357f60867SMark Johnston */ 2042f28ceebSMark Johnston #pragma D binding "1.5" translator 20557f60867SMark Johnston translator pktinfo_t < void *p > { 20657f60867SMark Johnston pkt_addr = NULL; 20757f60867SMark Johnston }; 20857f60867SMark Johnston 2092f28ceebSMark Johnston #pragma D binding "1.5" translator 21057f60867SMark Johnston translator csinfo_t < void *p > { 21157f60867SMark Johnston cs_addr = NULL; 21257f60867SMark Johnston cs_cid = (uint64_t)p; 21357f60867SMark Johnston cs_pid = 0; 21457f60867SMark Johnston cs_zoneid = 0; 21557f60867SMark Johnston }; 21657f60867SMark Johnston 2172f28ceebSMark Johnston #pragma D binding "1.6.3" translator 21857f60867SMark Johnston translator csinfo_t < struct inpcb *p > { 21957f60867SMark Johnston cs_addr = NULL; 22057f60867SMark Johnston cs_cid = (uint64_t)p; 22157f60867SMark Johnston cs_pid = 0; /* XXX */ 22257f60867SMark Johnston cs_zoneid = 0; 22357f60867SMark Johnston }; 22457f60867SMark Johnston 2252f28ceebSMark Johnston #pragma D binding "1.5" translator 22657f60867SMark Johnston translator ipinfo_t < uint8_t *p > { 22757f60867SMark Johnston ip_ver = p == NULL ? 0 : ((struct ip *)p)->ip_v; 22857f60867SMark Johnston ip_plength = p == NULL ? 0 : 22957f60867SMark Johnston ((struct ip *)p)->ip_v == 4 ? 23057f60867SMark Johnston ntohs(((struct ip *)p)->ip_len) - (((struct ip *)p)->ip_hl << 2): 23157f60867SMark Johnston ntohs(((struct ip6_hdr *)p)->ip6_ctlun.ip6_un1.ip6_un1_plen); 2327575d3dfSMichael Tuexen ip_saddr = p == NULL ? "<unknown>" : 23357f60867SMark Johnston ((struct ip *)p)->ip_v == 4 ? 23457f60867SMark Johnston inet_ntoa(&((struct ip *)p)->ip_src.s_addr) : 23557f60867SMark Johnston inet_ntoa6(&((struct ip6_hdr *)p)->ip6_src); 2367575d3dfSMichael Tuexen ip_daddr = p == NULL ? "<unknown>" : 23757f60867SMark Johnston ((struct ip *)p)->ip_v == 4 ? 23857f60867SMark Johnston inet_ntoa(&((struct ip *)p)->ip_dst.s_addr) : 23957f60867SMark Johnston inet_ntoa6(&((struct ip6_hdr *)p)->ip6_dst); 24057f60867SMark Johnston }; 24157f60867SMark Johnston 24282988b50SGeorge V. Neville-Neil #pragma D binding "1.13" translator 24382988b50SGeorge V. Neville-Neil translator ipinfo_t < struct mbuf *m > { 24482988b50SGeorge V. Neville-Neil ip_ver = m == NULL ? 0 : ((struct ip *)m->m_data)->ip_v; 24582988b50SGeorge V. Neville-Neil ip_plength = m == NULL ? 0 : 24682988b50SGeorge V. Neville-Neil ((struct ip *)m->m_data)->ip_v == 4 ? 24782988b50SGeorge V. Neville-Neil ntohs(((struct ip *)m->m_data)->ip_len) - 24882988b50SGeorge V. Neville-Neil (((struct ip *)m->m_data)->ip_hl << 2): 24982988b50SGeorge V. Neville-Neil ntohs(((struct ip6_hdr *)m->m_data)->ip6_ctlun.ip6_un1.ip6_un1_plen); 2507575d3dfSMichael Tuexen ip_saddr = m == NULL ? "<unknown>" : 25182988b50SGeorge V. Neville-Neil ((struct ip *)m->m_data)->ip_v == 4 ? 25282988b50SGeorge V. Neville-Neil inet_ntoa(&((struct ip *)m->m_data)->ip_src.s_addr) : 25382988b50SGeorge V. Neville-Neil inet_ntoa6(&((struct ip6_hdr *)m->m_data)->ip6_src); 2547575d3dfSMichael Tuexen ip_daddr = m == NULL ? "<unknown>" : 25582988b50SGeorge V. Neville-Neil ((struct ip *)m->m_data)->ip_v == 4 ? 25682988b50SGeorge V. Neville-Neil inet_ntoa(&((struct ip *)m->m_data)->ip_dst.s_addr) : 25782988b50SGeorge V. Neville-Neil inet_ntoa6(&((struct ip6_hdr *)m->m_data)->ip6_dst); 25882988b50SGeorge V. Neville-Neil }; 25982988b50SGeorge V. Neville-Neil 2602f28ceebSMark Johnston #pragma D binding "1.5" IFF_LOOPBACK 26157f60867SMark Johnston inline int IFF_LOOPBACK = 0x8; 26257f60867SMark Johnston 2632f28ceebSMark Johnston #pragma D binding "1.5" translator 26457f60867SMark Johnston translator ifinfo_t < struct ifnet *p > { 265*e00fd242SMichael Tuexen if_name = p == NULL ? "<unknown>" : p->if_xname; 266*e00fd242SMichael Tuexen if_local = p == NULL ? 0 : (p->if_flags & IFF_LOOPBACK) == 0 ? 0 : 1; 26757f60867SMark Johnston if_addr = (uintptr_t)p; 26857f60867SMark Johnston }; 26957f60867SMark Johnston 2702f28ceebSMark Johnston #pragma D binding "1.5" translator 27157f60867SMark Johnston translator ipv4info_t < struct ip *p > { 27257f60867SMark Johnston ipv4_ver = p == NULL ? 0 : p->ip_v; 27357f60867SMark Johnston ipv4_ihl = p == NULL ? 0 : p->ip_hl; 27457f60867SMark Johnston ipv4_tos = p == NULL ? 0 : p->ip_tos; 27557f60867SMark Johnston ipv4_length = p == NULL ? 0 : ntohs(p->ip_len); 27657f60867SMark Johnston ipv4_ident = p == NULL ? 0 : ntohs(p->ip_id); 2774349a214SAndrey V. Elsukov ipv4_flags = p == NULL ? 0 : (ntohs(p->ip_off) & 0xe000) >> 8; 2784349a214SAndrey V. Elsukov ipv4_offset = p == NULL ? 0 : ntohs(p->ip_off) & 0x1fff; 27957f60867SMark Johnston ipv4_ttl = p == NULL ? 0 : p->ip_ttl; 28057f60867SMark Johnston ipv4_protocol = p == NULL ? 0 : p->ip_p; 28157f60867SMark Johnston ipv4_protostr = p == NULL ? "<null>" : protocols[p->ip_p]; 28257f60867SMark Johnston ipv4_checksum = p == NULL ? 0 : ntohs(p->ip_sum); 28357f60867SMark Johnston ipv4_src = p == NULL ? 0 : (ipaddr_t)ntohl(p->ip_src.s_addr); 28457f60867SMark Johnston ipv4_dst = p == NULL ? 0 : (ipaddr_t)ntohl(p->ip_dst.s_addr); 28557f60867SMark Johnston ipv4_saddr = p == NULL ? 0 : inet_ntoa(&p->ip_src.s_addr); 28657f60867SMark Johnston ipv4_daddr = p == NULL ? 0 : inet_ntoa(&p->ip_dst.s_addr); 28757f60867SMark Johnston ipv4_hdr = (ipha_t *)p; 28857f60867SMark Johnston }; 28957f60867SMark Johnston 2902f28ceebSMark Johnston #pragma D binding "1.5" translator 29157f60867SMark Johnston translator ipv6info_t < struct ip6_hdr *p > { 29257f60867SMark Johnston ipv6_ver = p == NULL ? 0 : (ntohl(p->ip6_ctlun.ip6_un1.ip6_un1_flow) & 0xf0000000) >> 28; 29357f60867SMark Johnston ipv6_tclass = p == NULL ? 0 : (ntohl(p->ip6_ctlun.ip6_un1.ip6_un1_flow) & 0x0ff00000) >> 20; 29457f60867SMark Johnston ipv6_flow = p == NULL ? 0 : ntohl(p->ip6_ctlun.ip6_un1.ip6_un1_flow) & 0x000fffff; 29557f60867SMark Johnston ipv6_plen = p == NULL ? 0 : ntohs(p->ip6_ctlun.ip6_un1.ip6_un1_plen); 29657f60867SMark Johnston ipv6_nexthdr = p == NULL ? 0 : p->ip6_ctlun.ip6_un1.ip6_un1_nxt; 29757f60867SMark Johnston ipv6_nextstr = p == NULL ? "<null>" : protocols[p->ip6_ctlun.ip6_un1.ip6_un1_nxt]; 29857f60867SMark Johnston ipv6_hlim = p == NULL ? 0 : p->ip6_ctlun.ip6_un1.ip6_un1_hlim; 29957f60867SMark Johnston ipv6_src = p == NULL ? 0 : (in6_addr_t *)&p->ip6_src; 30057f60867SMark Johnston ipv6_dst = p == NULL ? 0 : (in6_addr_t *)&p->ip6_dst; 30157f60867SMark Johnston ipv6_saddr = p == NULL ? 0 : inet_ntoa6(&p->ip6_src); 30257f60867SMark Johnston ipv6_daddr = p == NULL ? 0 : inet_ntoa6(&p->ip6_dst); 303c50c3318SMark Johnston ipv6_hdr = p; 30457f60867SMark Johnston }; 305