packet.h revision 336069c20319c172c4ff9d87d67e8f6301c98a5d
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major/*
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * CDDL HEADER START
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major *
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * The contents of this file are subject to the terms of the
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * Common Development and Distribution License (the "License").
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * You may not use this file except in compliance with the License.
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major *
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * or http://www.opensolaris.org/os/licensing.
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * See the License for the specific language governing permissions
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * and limitations under the License.
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major *
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * When distributing Covered Code, include this CDDL HEADER in each
1919390f93ec8db650084d8b1bf252bf71f37b0bPeter Major * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * If applicable, add the following below this CDDL HEADER, with the
2dd75eff92ef66e22cca286b6f4fe5a9c929af9dPhill Cunnington * fields enclosed by brackets "[]" replaced with your own identifying
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * information: Portions Copyright [yyyy] [name of copyright owner]
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major *
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper * CDDL HEADER END
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major */
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major/*
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * Copyright 2015 Joyent, Inc. All rights reserved.
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major */
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#ifndef _PACKET_H
2dd75eff92ef66e22cca286b6f4fe5a9c929af9dPhill Cunnington#define _PACKET_H
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major#include <sys/socket_impl.h>
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major#include <net/if_arp.h>
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major#include <net/bpf.h>
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major/*
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major * With which we do the reverse of what it libpcap does....
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major */
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major#define PACKET_OUTGOING LINUX_SLL_OUTGOING
c49a898cb851f8fef7d7a6a9501c66b8f03ae05cPhill Cunnington#define PACKET_HOST LINUX_SLL_HOST
c49a898cb851f8fef7d7a6a9501c66b8f03ae05cPhill Cunnington#define PACKET_BROADCAST LINUX_SLL_BROADCAST
c49a898cb851f8fef7d7a6a9501c66b8f03ae05cPhill Cunnington#define PACKET_MULTICAST LINUX_SLL_MULTICAST
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define PACKET_OTHERHOST LINUX_SLL_OTHERHOST
c49a898cb851f8fef7d7a6a9501c66b8f03ae05cPhill Cunnington
c49a898cb851f8fef7d7a6a9501c66b8f03ae05cPhill Cunnington#define PACKET_STATISTICS_SHORT 1
c49a898cb851f8fef7d7a6a9501c66b8f03ae05cPhill Cunnington#define PACKET_ADD_MEMBERSHIP 2
c49a898cb851f8fef7d7a6a9501c66b8f03ae05cPhill Cunnington#define PACKET_DROP_MEMBERSHIP 3
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define PACKET_AUXDATA 4
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define PACKET_STATISTICS 5
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Majorstruct packet_mreq {
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper uint32_t mr_ifindex;
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper uint16_t mr_type;
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper uint16_t mr_alen;
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper uint8_t mr_address[8];
4e722da7d7f08efee88f34533f20f63671572b28Joe Bandenburg};
c49a898cb851f8fef7d7a6a9501c66b8f03ae05cPhill Cunnington
c49a898cb851f8fef7d7a6a9501c66b8f03ae05cPhill Cunnington#define PACKET_MR_MULTICAST 1
c49a898cb851f8fef7d7a6a9501c66b8f03ae05cPhill Cunnington#define PACKET_MR_PROMISC 2
c49a898cb851f8fef7d7a6a9501c66b8f03ae05cPhill Cunnington#define PACKET_MR_ALLMULTI 3
c49a898cb851f8fef7d7a6a9501c66b8f03ae05cPhill Cunnington
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Majortypedef enum tpkt_status_e {
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major TP_STATUS_KERNEL,
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major TP_STATUS_USER,
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major TP_STATUS_COPY,
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major TP_STATUS_LOSING,
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major TP_STATUS_CSUMNOTREADY
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major} tpkt_status_t;
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Majorstruct tpacket_auxdata { /* tp_macoff/tp_netoff ?? */
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major tpkt_status_t tp_status;
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major uint32_t tp_len;
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major uint32_t tp_snaplen;
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major uint16_t tp_macoff;
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major uint16_t tp_netoff;
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper uint16_t tp_vlan_vci;
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major};
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Majorstruct tpacket_hdr { /* tp_macoff/tp_netoff ?? */
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper uint64_t tp_status;
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper uint32_t tp_len;
4e722da7d7f08efee88f34533f20f63671572b28Joe Bandenburg uint32_t tp_snaplen;
3f8e1f04bbd8911cb74fbfa55dd463065fd4e1edJoe Bandenburg uint16_t tp_macoff;
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper uint16_t tp_netoff;
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper uint32_t tp_sec;
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper uint32_t tp_usec;
4e722da7d7f08efee88f34533f20f63671572b28Joe Bandenburg};
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Majorstruct tpacket2_hdr { /* tp_macoff/tp_netoff ?? */
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major tpkt_status_t tp_status;
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major uint32_t tp_len;
4e722da7d7f08efee88f34533f20f63671572b28Joe Bandenburg uint32_t tp_snaplen;
1919390f93ec8db650084d8b1bf252bf71f37b0bPeter Major uint16_t tp_macoff;
3f8e1f04bbd8911cb74fbfa55dd463065fd4e1edJoe Bandenburg uint16_t tp_netoff;
3f8e1f04bbd8911cb74fbfa55dd463065fd4e1edJoe Bandenburg uint32_t tp_sec;
3f8e1f04bbd8911cb74fbfa55dd463065fd4e1edJoe Bandenburg uint32_t tp_nsec;
3f8e1f04bbd8911cb74fbfa55dd463065fd4e1edJoe Bandenburg uint16_t tp_vlan_tci;
3f8e1f04bbd8911cb74fbfa55dd463065fd4e1edJoe Bandenburg};
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Majorstruct tpacket_stats {
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper uint32_t tp_packets;
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major uint32_t tp_drops;
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major};
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major
4e722da7d7f08efee88f34533f20f63671572b28Joe Bandenburgstruct tpacket_stats_short {
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper uint16_t tp_packets;
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper uint16_t tp_drops;
4e722da7d7f08efee88f34533f20f63671572b28Joe Bandenburg};
4e722da7d7f08efee88f34533f20f63671572b28Joe Bandenburg
4e722da7d7f08efee88f34533f20f63671572b28Joe Bandenburgstruct sock_filter { /* Fields named from bpf_insn */
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major uint16_t code;
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major uint8_t jt;
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major uint8_t jf;
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major uint32_t k;
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper};
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Majorstruct sock_fprog {
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major uint16_t len;
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major struct sock_filter *filter;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna};
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna/*
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna * Linux ARPHRD_ symbols needed...
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna *
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna * The numbers above 50000 are because their real value is unknown from
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna * libpcap's source, so a number has been chosen that is unlikely to be
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna * confused with the real one on Linux. Those that are already found in
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna * Solaris inside <net/if_arp.h> may have a different value to that found
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna * in Linux but it should be used instead as the Solaris value originates
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna * from the IANA whereas the Linux values seem to ignore it.
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna */
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna/* ARPHRD_AX25 see <net/if_arp.h> */
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna/* ARPHRD_CHAOS see <net/if_arp.h> */
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_CSLIP 50005
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_CSLIP6 50006
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_DLCI 15
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna/* ARPHRD_EETHER see <net/if_arp.h> */
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna/* ARPHRD_ETHER see <net/if_arp.h> */
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_FCAL 785
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_FCFABRIC 787
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_FCPL 786
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_FCPP 784
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_FRAD 770
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_FDDI 774
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna/* ARPHRD_IEEE802 see <net/if_arp.h> */
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_IEEE802_TR 800
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_IEEE80211 801
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_IEEE80211_PRISM 802
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_IEEE80211_RADIOTAP 803
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_IRDA 783
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_LAPD 8445
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_LOCALTLK 50010
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_LOOPBACK 50011
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna/* ARPHRD_METRICOM see <net/if_arp.h> */
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_PRONET 50013
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_PPP 50014
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_RAWHDLC 518
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_SIT 776
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_SLIP6 50015
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ARPHRD_SLIP 50016
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna/* ARPHRD_TUNNEL see <net/if_arp.h> */
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ETH_P_ALL 0
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ETH_P_802_2 0xaa /* LSAP_SAP */
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ETH_P_803_3 0
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ETH_P_IP 0x800
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ETH_P_ARP 0x806
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#define ETH_P_IPV6 0x86dd
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna#ifdef _KERNEL
20047479f8803c17039bbf35e28b4e232beb9da9Quentin CASTEL/*
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper * PFP socket structure.
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper */
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reepertypedef struct pfpsock {
96370cf5fc50b43f71fa99e0f14fa212dc63e287Mark de Reeper struct bpf_program ps_bpf;
20047479f8803c17039bbf35e28b4e232beb9da9Quentin CASTEL krwlock_t ps_bpflock;
20047479f8803c17039bbf35e28b4e232beb9da9Quentin CASTEL sock_upper_handle_t ps_upper;
20047479f8803c17039bbf35e28b4e232beb9da9Quentin CASTEL sock_upcalls_t *ps_upcalls;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna mac_handle_t ps_mh;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna mac_client_handle_t ps_mch;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna mac_promisc_handle_t ps_phd;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna int ps_type;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna int ps_proto;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna uint_t ps_max_sdu;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna boolean_t ps_bound;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna mac_client_promisc_type_t ps_promisc;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna boolean_t ps_auxdata;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna struct tpacket_stats ps_stats;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna struct sockaddr ps_sock;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna datalink_id_t ps_linkid;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna kmutex_t ps_lock;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna boolean_t ps_flow_ctrld;
de64160be7ccd8f2ef5329cdc7242db6935f8d97Peter Major ulong_t ps_flow_ctrl_drops;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna timespec_t ps_timestamp;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna size_t ps_rcvbuf;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna} pfpsock_t;
cd085ff36bed57615d33434450ffc7c44ca016edDavid Luna
cd085ff36bed57615d33434450ffc7c44ca016edDavid Lunatypedef struct pfp_kstats_s {
f015d695b84915f1c2c3fcf81f339548af1852c4Peter Major kstat_named_t kp_recv_mac_hdr_fail;
kstat_named_t kp_recv_bad_proto;
kstat_named_t kp_recv_alloc_fail;
kstat_named_t kp_recv_ok;
kstat_named_t kp_recv_fail;
kstat_named_t kp_recv_filtered;
kstat_named_t kp_recv_flow_cntrld;
kstat_named_t kp_send_unbound;
kstat_named_t kp_send_failed;
kstat_named_t kp_send_too_big;
kstat_named_t kp_send_alloc_fail;
kstat_named_t kp_send_uiomove_fail;
kstat_named_t kp_send_no_memory;
kstat_named_t kp_send_open_fail;
kstat_named_t kp_send_wrong_family;
kstat_named_t kp_send_short_msg;
kstat_named_t kp_send_ok;
} pfp_kstats_t;
#endif /* _KERNEL */
#endif /* _PACKET_H */