]> git.saurik.com Git - apple/xnu.git/blame - bsd/net/pktap.h
xnu-3248.60.10.tar.gz
[apple/xnu.git] / bsd / net / pktap.h
CommitLineData
39236c6e 1/*
fe8ab488 2 * Copyright (c) 2012-2014 Apple Inc. All rights reserved.
39236c6e
A
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _NET_PKTAP_H_
30#define _NET_PKTAP_H_
31
fe8ab488 32#include <sys/_types/_timeval32.h>
39236c6e
A
33#include <stdint.h>
34#include <net/if.h>
fe8ab488 35#include <uuid/uuid.h>
39236c6e
A
36
37#ifdef PRIVATE
38
39#define PKTAP_IFNAME "pktap"
40
41/* To store interface name + unit */
42#define PKTAP_IFXNAMESIZE (IF_NAMESIZE + 8)
43
44/*
45 * Commands via SIOCGDRVSPEC/SIOCSDRVSPEC
46 */
47#define PKTP_CMD_FILTER_GET 1 /* array of PKTAP_MAX_FILTERS * struct pktap_filter */
48#define PKTP_CMD_FILTER_SET 3 /* array of PKTAP_MAX_FILTERS * struct pktap_filter */
49#define PKTP_CMD_TAP_COUNT 4 /* uint32_t number of active bpf tap on the interface */
50
51/*
52 * Filtering is currently based on network interface properties --
53 * the interface type and the interface name -- and has two types of
54 * operations -- pass and skip.
55 * By default only interfaces of type IFT_ETHER and IFT_CELLULAR pass
56 * the filter.
57 * It's possible to include other interfaces by type or by name
58 * The interface type is evaluated before the interface name
59 * The first matching rule stops the evaluation.
60 * A rule with interface type 0 (zero) matches any interfaces
61 */
62#define PKTAP_FILTER_OP_NONE 0 /* For inactive entries at the end of the list */
63#define PKTAP_FILTER_OP_PASS 1
64#define PKTAP_FILTER_OP_SKIP 2
65
66#define PKTAP_FILTER_PARAM_NONE 0
67#define PKTAP_FILTER_PARAM_IF_TYPE 1
68#define PKTAP_FILTER_PARAM_IF_NAME 2
69
70#ifdef BSD_KERNEL_PRIVATE
71struct pktap_filter {
72 uint32_t filter_op;
73 uint32_t filter_param;
74 union {
75 uint32_t _filter_if_type;
76 char _filter_if_name[PKTAP_IFXNAMESIZE];
77 } param_;
78 size_t filter_ifname_prefix_len;
79};
80
81struct x_pktap_filter {
82#else
83struct pktap_filter {
84#endif /* BSD_KERNEL_PRIVATE */
85 uint32_t filter_op;
86 uint32_t filter_param;
87 union {
88 uint32_t _filter_if_type;
89 char _filter_if_name[PKTAP_IFXNAMESIZE];
90 } param_;
91};
92#define filter_param_if_type param_._filter_if_type
93#define filter_param_if_name param_._filter_if_name
94
95#define PKTAP_MAX_FILTERS 8
96
97/*
98 * Header for DLT_PKTAP
99 *
100 * In theory, there could be several types of blocks in a chain before the actual packet
101 */
102struct pktap_header {
fe8ab488
A
103 uint32_t pth_length; /* length of this header */
104 uint32_t pth_type_next; /* type of data following */
105 uint32_t pth_dlt; /* DLT of packet */
106 char pth_ifname[PKTAP_IFXNAMESIZE]; /* interface name */
107 uint32_t pth_flags; /* flags */
108 uint32_t pth_protocol_family;
109 uint32_t pth_frame_pre_length;
110 uint32_t pth_frame_post_length;
111 pid_t pth_pid; /* process ID */
112 char pth_comm[MAXCOMLEN+1]; /* process name */
113 uint32_t pth_svc; /* service class */
114 uint16_t pth_iftype;
115 uint16_t pth_ifunit;
116 pid_t pth_epid; /* effective process ID */
117 char pth_ecomm[MAXCOMLEN+1]; /* effective command name */
118 uint32_t pth_flowid;
119 uint32_t pth_ipproto;
120 struct timeval32 pth_tstamp;
121 uuid_t pth_uuid;
122 uuid_t pth_euuid;
39236c6e
A
123};
124
125/*
126 *
127 */
128#define PTH_TYPE_NONE 0 /* No more data following */
129#define PTH_TYPE_PACKET 1 /* Actual captured packet data */
130
fe8ab488
A
131#define PTH_FLAG_DIR_IN 0x0001 /* Outgoing packet */
132#define PTH_FLAG_DIR_OUT 0x0002 /* Incoming packet */
133#define PTH_FLAG_PROC_DELEGATED 0x0004 /* Process delegated */
134#define PTH_FLAG_IF_DELEGATED 0x0008 /* Interface delegated */
135#ifdef BSD_KERNEL_PRIVATE
136#define PTH_FLAG_DELAY_PKTAP 0x1000 /* Finalize pktap header on read */
137#endif /* BSD_KERNEL_PRIVATE */
138#define PTH_FLAG_TSTAMP 0x2000 /* Has time stamp */
39236c6e
A
139
140
141#ifdef BSD_KERNEL_PRIVATE
142extern void pktap_init(void);
143extern void pktap_input(struct ifnet *, protocol_family_t, struct mbuf *, char *);
144extern void pktap_output(struct ifnet *, protocol_family_t, struct mbuf *,
145 u_int32_t, u_int32_t);
146extern void pktap_fill_proc_info(struct pktap_header *, protocol_family_t ,
147 struct mbuf *, u_int32_t , int , struct ifnet *);
fe8ab488 148extern void pktap_finalize_proc_info(struct pktap_header *);
39236c6e
A
149
150#endif /* BSD_KERNEL_PRIVATE */
151#endif /* PRIVATE */
152
153#endif /* _NET_PKTAP_H_ */