]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/pktap.h
cecb5cb9461ce9547df8aca1dfae77e4546597f8
[apple/xnu.git] / bsd / net / pktap.h
1 /*
2 * Copyright (c) 2012-2013 Apple Inc. All rights reserved.
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
32 #include <stdint.h>
33 #include <net/if.h>
34
35 #ifdef PRIVATE
36
37 #define PKTAP_IFNAME "pktap"
38
39 /* To store interface name + unit */
40 #define PKTAP_IFXNAMESIZE (IF_NAMESIZE + 8)
41
42 /*
43 * Commands via SIOCGDRVSPEC/SIOCSDRVSPEC
44 */
45 #define PKTP_CMD_FILTER_GET 1 /* array of PKTAP_MAX_FILTERS * struct pktap_filter */
46 #define PKTP_CMD_FILTER_SET 3 /* array of PKTAP_MAX_FILTERS * struct pktap_filter */
47 #define PKTP_CMD_TAP_COUNT 4 /* uint32_t number of active bpf tap on the interface */
48
49 /*
50 * Filtering is currently based on network interface properties --
51 * the interface type and the interface name -- and has two types of
52 * operations -- pass and skip.
53 * By default only interfaces of type IFT_ETHER and IFT_CELLULAR pass
54 * the filter.
55 * It's possible to include other interfaces by type or by name
56 * The interface type is evaluated before the interface name
57 * The first matching rule stops the evaluation.
58 * A rule with interface type 0 (zero) matches any interfaces
59 */
60 #define PKTAP_FILTER_OP_NONE 0 /* For inactive entries at the end of the list */
61 #define PKTAP_FILTER_OP_PASS 1
62 #define PKTAP_FILTER_OP_SKIP 2
63
64 #define PKTAP_FILTER_PARAM_NONE 0
65 #define PKTAP_FILTER_PARAM_IF_TYPE 1
66 #define PKTAP_FILTER_PARAM_IF_NAME 2
67
68 #ifdef BSD_KERNEL_PRIVATE
69 struct pktap_filter {
70 uint32_t filter_op;
71 uint32_t filter_param;
72 union {
73 uint32_t _filter_if_type;
74 char _filter_if_name[PKTAP_IFXNAMESIZE];
75 } param_;
76 size_t filter_ifname_prefix_len;
77 };
78
79 struct x_pktap_filter {
80 #else
81 struct pktap_filter {
82 #endif /* BSD_KERNEL_PRIVATE */
83 uint32_t filter_op;
84 uint32_t filter_param;
85 union {
86 uint32_t _filter_if_type;
87 char _filter_if_name[PKTAP_IFXNAMESIZE];
88 } param_;
89 };
90 #define filter_param_if_type param_._filter_if_type
91 #define filter_param_if_name param_._filter_if_name
92
93 #define PKTAP_MAX_FILTERS 8
94
95 /*
96 * Header for DLT_PKTAP
97 *
98 * In theory, there could be several types of blocks in a chain before the actual packet
99 */
100 struct pktap_header {
101 uint32_t pth_length; /* length of this header */
102 uint32_t pth_type_next; /* type of data following */
103 uint32_t pth_dlt; /* DLT of packet */
104 char pth_ifname[PKTAP_IFXNAMESIZE]; /* interface name */
105 uint32_t pth_flags; /* flags */
106 uint32_t pth_protocol_family;
107 uint32_t pth_frame_pre_length;
108 uint32_t pth_frame_post_length;
109 pid_t pth_pid; /* process ID */
110 char pth_comm[MAXCOMLEN+1]; /* process command name */
111 uint32_t pth_svc; /* service class */
112 uint16_t pth_iftype;
113 uint16_t pth_ifunit;
114 pid_t pth_epid; /* effective process ID */
115 char pth_ecomm[MAXCOMLEN+1]; /* effective command name */
116 };
117
118 /*
119 *
120 */
121 #define PTH_TYPE_NONE 0 /* No more data following */
122 #define PTH_TYPE_PACKET 1 /* Actual captured packet data */
123
124 #define PTH_FLAG_DIR_IN 0x0001 /* Outgoing packet */
125 #define PTH_FLAG_DIR_OUT 0x0002 /* Incoming packet */
126 #define PTH_FLAG_PROC_DELEGATED 0x0004 /* Process delegated */
127 #define PTH_FLAG_IF_DELEGATED 0x0008 /* Interface delegated */
128
129
130 #ifdef BSD_KERNEL_PRIVATE
131 extern void pktap_init(void);
132 extern void pktap_input(struct ifnet *, protocol_family_t, struct mbuf *, char *);
133 extern void pktap_output(struct ifnet *, protocol_family_t, struct mbuf *,
134 u_int32_t, u_int32_t);
135 extern void pktap_fill_proc_info(struct pktap_header *, protocol_family_t ,
136 struct mbuf *, u_int32_t , int , struct ifnet *);
137
138 #endif /* BSD_KERNEL_PRIVATE */
139 #endif /* PRIVATE */
140
141 #endif /* _NET_PKTAP_H_ */