10a0e9771SDarren Reed /* 20a0e9771SDarren Reed * CDDL HEADER START 30a0e9771SDarren Reed * 40a0e9771SDarren Reed * The contents of this file are subject to the terms of the 50a0e9771SDarren Reed * Common Development and Distribution License (the "License"). 60a0e9771SDarren Reed * You may not use this file except in compliance with the License. 70a0e9771SDarren Reed * 80a0e9771SDarren Reed * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90a0e9771SDarren Reed * or http://www.opensolaris.org/os/licensing. 100a0e9771SDarren Reed * See the License for the specific language governing permissions 110a0e9771SDarren Reed * and limitations under the License. 120a0e9771SDarren Reed * 130a0e9771SDarren Reed * When distributing Covered Code, include this CDDL HEADER in each 140a0e9771SDarren Reed * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150a0e9771SDarren Reed * If applicable, add the following below this CDDL HEADER, with the 160a0e9771SDarren Reed * fields enclosed by brackets "[]" replaced with your own identifying 170a0e9771SDarren Reed * information: Portions Copyright [yyyy] [name of copyright owner] 180a0e9771SDarren Reed * 190a0e9771SDarren Reed * CDDL HEADER END 200a0e9771SDarren Reed */ 210a0e9771SDarren Reed 220a0e9771SDarren Reed /* 23a6911619SDarren Reed * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. 24336069c2SPatrick Mooney * Copyright 2015 Joyent, Inc. All rights reserved. 250a0e9771SDarren Reed */ 260a0e9771SDarren Reed 270a0e9771SDarren Reed #ifndef _PACKET_H 280a0e9771SDarren Reed #define _PACKET_H 290a0e9771SDarren Reed 300a0e9771SDarren Reed #include <sys/socket_impl.h> 31a6911619SDarren Reed #include <net/if_arp.h> 320a0e9771SDarren Reed #include <net/bpf.h> 330a0e9771SDarren Reed 340a0e9771SDarren Reed /* 350a0e9771SDarren Reed * With which we do the reverse of what it libpcap does.... 360a0e9771SDarren Reed */ 370a0e9771SDarren Reed #define PACKET_OUTGOING LINUX_SLL_OUTGOING 380a0e9771SDarren Reed #define PACKET_HOST LINUX_SLL_HOST 390a0e9771SDarren Reed #define PACKET_BROADCAST LINUX_SLL_BROADCAST 400a0e9771SDarren Reed #define PACKET_MULTICAST LINUX_SLL_MULTICAST 410a0e9771SDarren Reed #define PACKET_OTHERHOST LINUX_SLL_OTHERHOST 420a0e9771SDarren Reed 43336069c2SPatrick Mooney #define PACKET_STATISTICS_SHORT 1 440a0e9771SDarren Reed #define PACKET_ADD_MEMBERSHIP 2 450a0e9771SDarren Reed #define PACKET_DROP_MEMBERSHIP 3 460a0e9771SDarren Reed #define PACKET_AUXDATA 4 47336069c2SPatrick Mooney #define PACKET_STATISTICS 5 480a0e9771SDarren Reed 490a0e9771SDarren Reed 500a0e9771SDarren Reed struct packet_mreq { 510a0e9771SDarren Reed uint32_t mr_ifindex; 520a0e9771SDarren Reed uint16_t mr_type; 530a0e9771SDarren Reed uint16_t mr_alen; 540a0e9771SDarren Reed uint8_t mr_address[8]; 550a0e9771SDarren Reed }; 560a0e9771SDarren Reed 570a0e9771SDarren Reed #define PACKET_MR_MULTICAST 1 580a0e9771SDarren Reed #define PACKET_MR_PROMISC 2 590a0e9771SDarren Reed #define PACKET_MR_ALLMULTI 3 600a0e9771SDarren Reed 610a0e9771SDarren Reed typedef enum tpkt_status_e { 620a0e9771SDarren Reed TP_STATUS_KERNEL, 630a0e9771SDarren Reed TP_STATUS_USER, 640a0e9771SDarren Reed TP_STATUS_COPY, 650a0e9771SDarren Reed TP_STATUS_LOSING, 660a0e9771SDarren Reed TP_STATUS_CSUMNOTREADY 670a0e9771SDarren Reed } tpkt_status_t; 680a0e9771SDarren Reed 690a0e9771SDarren Reed struct tpacket_auxdata { /* tp_macoff/tp_netoff ?? */ 700a0e9771SDarren Reed tpkt_status_t tp_status; 710a0e9771SDarren Reed uint32_t tp_len; 720a0e9771SDarren Reed uint32_t tp_snaplen; 730a0e9771SDarren Reed uint16_t tp_macoff; 740a0e9771SDarren Reed uint16_t tp_netoff; 750a0e9771SDarren Reed uint16_t tp_vlan_vci; 760a0e9771SDarren Reed }; 770a0e9771SDarren Reed 780a0e9771SDarren Reed struct tpacket_hdr { /* tp_macoff/tp_netoff ?? */ 790a0e9771SDarren Reed uint64_t tp_status; 800a0e9771SDarren Reed uint32_t tp_len; 810a0e9771SDarren Reed uint32_t tp_snaplen; 820a0e9771SDarren Reed uint16_t tp_macoff; 830a0e9771SDarren Reed uint16_t tp_netoff; 840a0e9771SDarren Reed uint32_t tp_sec; 850a0e9771SDarren Reed uint32_t tp_usec; 860a0e9771SDarren Reed }; 870a0e9771SDarren Reed 880a0e9771SDarren Reed struct tpacket2_hdr { /* tp_macoff/tp_netoff ?? */ 890a0e9771SDarren Reed tpkt_status_t tp_status; 900a0e9771SDarren Reed uint32_t tp_len; 910a0e9771SDarren Reed uint32_t tp_snaplen; 920a0e9771SDarren Reed uint16_t tp_macoff; 930a0e9771SDarren Reed uint16_t tp_netoff; 940a0e9771SDarren Reed uint32_t tp_sec; 950a0e9771SDarren Reed uint32_t tp_nsec; 960a0e9771SDarren Reed uint16_t tp_vlan_tci; 970a0e9771SDarren Reed }; 980a0e9771SDarren Reed 990a0e9771SDarren Reed struct tpacket_stats { 100336069c2SPatrick Mooney uint32_t tp_packets; 101336069c2SPatrick Mooney uint32_t tp_drops; 102336069c2SPatrick Mooney }; 103336069c2SPatrick Mooney 104336069c2SPatrick Mooney struct tpacket_stats_short { 1050a0e9771SDarren Reed uint16_t tp_packets; 1060a0e9771SDarren Reed uint16_t tp_drops; 1070a0e9771SDarren Reed }; 1080a0e9771SDarren Reed 1090a0e9771SDarren Reed struct sock_filter { /* Fields named from bpf_insn */ 1100a0e9771SDarren Reed uint16_t code; 1110a0e9771SDarren Reed uint8_t jt; 1120a0e9771SDarren Reed uint8_t jf; 1130a0e9771SDarren Reed uint32_t k; 1140a0e9771SDarren Reed }; 1150a0e9771SDarren Reed 1160a0e9771SDarren Reed struct sock_fprog { 1170a0e9771SDarren Reed uint16_t len; 1180a0e9771SDarren Reed struct sock_filter *filter; 1190a0e9771SDarren Reed }; 1200a0e9771SDarren Reed 1210a0e9771SDarren Reed /* 1220a0e9771SDarren Reed * Linux ARPHRD_ symbols needed... 1230a0e9771SDarren Reed * 1240a0e9771SDarren Reed * The numbers above 50000 are because their real value is unknown from 1250a0e9771SDarren Reed * libpcap's source, so a number has been chosen that is unlikely to be 126a6911619SDarren Reed * confused with the real one on Linux. Those that are already found in 127a6911619SDarren Reed * Solaris inside <net/if_arp.h> may have a different value to that found 128a6911619SDarren Reed * in Linux but it should be used instead as the Solaris value originates 129a6911619SDarren Reed * from the IANA whereas the Linux values seem to ignore it. 1300a0e9771SDarren Reed */ 131a6911619SDarren Reed /* ARPHRD_AX25 see <net/if_arp.h> */ 132a6911619SDarren Reed /* ARPHRD_CHAOS see <net/if_arp.h> */ 1330a0e9771SDarren Reed #define ARPHRD_CSLIP 50005 1340a0e9771SDarren Reed #define ARPHRD_CSLIP6 50006 1350a0e9771SDarren Reed #define ARPHRD_DLCI 15 136a6911619SDarren Reed /* ARPHRD_EETHER see <net/if_arp.h> */ 137a6911619SDarren Reed /* ARPHRD_ETHER see <net/if_arp.h> */ 1380a0e9771SDarren Reed #define ARPHRD_FCAL 785 1390a0e9771SDarren Reed #define ARPHRD_FCFABRIC 787 1400a0e9771SDarren Reed #define ARPHRD_FCPL 786 1410a0e9771SDarren Reed #define ARPHRD_FCPP 784 1420a0e9771SDarren Reed #define ARPHRD_FRAD 770 1430a0e9771SDarren Reed #define ARPHRD_FDDI 774 144a6911619SDarren Reed /* ARPHRD_IEEE802 see <net/if_arp.h> */ 1450a0e9771SDarren Reed #define ARPHRD_IEEE802_TR 800 1460a0e9771SDarren Reed #define ARPHRD_IEEE80211 801 1470a0e9771SDarren Reed #define ARPHRD_IEEE80211_PRISM 802 1480a0e9771SDarren Reed #define ARPHRD_IEEE80211_RADIOTAP 803 1490a0e9771SDarren Reed #define ARPHRD_IRDA 783 1500a0e9771SDarren Reed #define ARPHRD_LAPD 8445 1510a0e9771SDarren Reed #define ARPHRD_LOCALTLK 50010 1520a0e9771SDarren Reed #define ARPHRD_LOOPBACK 50011 153a6911619SDarren Reed /* ARPHRD_METRICOM see <net/if_arp.h> */ 1540a0e9771SDarren Reed #define ARPHRD_PRONET 50013 1550a0e9771SDarren Reed #define ARPHRD_PPP 50014 1560a0e9771SDarren Reed #define ARPHRD_RAWHDLC 518 1570a0e9771SDarren Reed #define ARPHRD_SIT 776 1580a0e9771SDarren Reed #define ARPHRD_SLIP6 50015 1590a0e9771SDarren Reed #define ARPHRD_SLIP 50016 160a6911619SDarren Reed /* ARPHRD_TUNNEL see <net/if_arp.h> */ 161a6911619SDarren Reed 162a6911619SDarren Reed #define ETH_P_ALL 0 163a6911619SDarren Reed #define ETH_P_802_2 0xaa /* LSAP_SAP */ 164a6911619SDarren Reed #define ETH_P_803_3 0 165a6911619SDarren Reed #define ETH_P_IP 0x800 166a6911619SDarren Reed #define ETH_P_ARP 0x806 167a6911619SDarren Reed #define ETH_P_IPV6 0x86dd 1680a0e9771SDarren Reed 1690a0e9771SDarren Reed #ifdef _KERNEL 1700a0e9771SDarren Reed /* 1710a0e9771SDarren Reed * PFP socket structure. 1720a0e9771SDarren Reed */ 1730a0e9771SDarren Reed typedef struct pfpsock { 1740a0e9771SDarren Reed struct bpf_program ps_bpf; 1750a0e9771SDarren Reed krwlock_t ps_bpflock; 1760a0e9771SDarren Reed sock_upper_handle_t ps_upper; 1770a0e9771SDarren Reed sock_upcalls_t *ps_upcalls; 1780a0e9771SDarren Reed mac_handle_t ps_mh; 1790a0e9771SDarren Reed mac_client_handle_t ps_mch; 1800a0e9771SDarren Reed mac_promisc_handle_t ps_phd; 1810a0e9771SDarren Reed int ps_type; 1820a0e9771SDarren Reed int ps_proto; 1830a0e9771SDarren Reed uint_t ps_max_sdu; 1840a0e9771SDarren Reed boolean_t ps_bound; 1850a0e9771SDarren Reed mac_client_promisc_type_t ps_promisc; 1860a0e9771SDarren Reed boolean_t ps_auxdata; 1870a0e9771SDarren Reed struct tpacket_stats ps_stats; 188*3b4315d3SPatrick Mooney struct sockaddr_ll ps_sock; 1890a0e9771SDarren Reed datalink_id_t ps_linkid; 1900a0e9771SDarren Reed kmutex_t ps_lock; 1910a0e9771SDarren Reed boolean_t ps_flow_ctrld; 1920a0e9771SDarren Reed ulong_t ps_flow_ctrl_drops; 193336069c2SPatrick Mooney timespec_t ps_timestamp; 194336069c2SPatrick Mooney size_t ps_rcvbuf; 1950a0e9771SDarren Reed } pfpsock_t; 1960a0e9771SDarren Reed 1970a0e9771SDarren Reed typedef struct pfp_kstats_s { 1980a0e9771SDarren Reed kstat_named_t kp_recv_mac_hdr_fail; 1990a0e9771SDarren Reed kstat_named_t kp_recv_bad_proto; 2000a0e9771SDarren Reed kstat_named_t kp_recv_alloc_fail; 2010a0e9771SDarren Reed kstat_named_t kp_recv_ok; 2020a0e9771SDarren Reed kstat_named_t kp_recv_fail; 2030a0e9771SDarren Reed kstat_named_t kp_recv_filtered; 2040a0e9771SDarren Reed kstat_named_t kp_recv_flow_cntrld; 2050a0e9771SDarren Reed kstat_named_t kp_send_unbound; 2060a0e9771SDarren Reed kstat_named_t kp_send_failed; 2070a0e9771SDarren Reed kstat_named_t kp_send_too_big; 2080a0e9771SDarren Reed kstat_named_t kp_send_alloc_fail; 2090a0e9771SDarren Reed kstat_named_t kp_send_uiomove_fail; 2100a0e9771SDarren Reed kstat_named_t kp_send_no_memory; 2110a0e9771SDarren Reed kstat_named_t kp_send_open_fail; 2120a0e9771SDarren Reed kstat_named_t kp_send_wrong_family; 2130a0e9771SDarren Reed kstat_named_t kp_send_short_msg; 2140a0e9771SDarren Reed kstat_named_t kp_send_ok; 2150a0e9771SDarren Reed } pfp_kstats_t; 2160a0e9771SDarren Reed #endif /* _KERNEL */ 2170a0e9771SDarren Reed 2180a0e9771SDarren Reed #endif /* _PACKET_H */ 219