/*
- * Copyright (c) 2000-2013 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
#include <sys/cdefs.h>
#include <stdint.h>
+#ifdef PRIVATE
+#include <net/if_var.h>
+#include <uuid/uuid.h>
+
+struct bpf_setup_args {
+ uuid_t bsa_uuid;
+ char bsa_ifname[IFNAMSIZ];
+};
+#endif /* PRIVATE */
+
#ifdef KERNEL
#include <sys/kernel_types.h>
+
+#if !defined(__i386__) && !defined(__x86_64__)
+#define BPF_ALIGN 1
+#else /* defined(__i386__) || defined(__x86_64__) */
+#define BPF_ALIGN 0
+#endif /* defined(__i386__) || defined(__x86_64__) */
+
+#if !BPF_ALIGN
+#define EXTRACT_SHORT(p) ((u_int16_t)ntohs(*(u_int16_t *)(void *)p))
+#define EXTRACT_LONG(p) (ntohl(*(u_int32_t *)(void *)p))
+#else
+#define EXTRACT_SHORT(p)\
+ ((u_int16_t)\
+ ((u_int16_t)*((u_char *)p+0)<<8|\
+ (u_int16_t)*((u_char *)p+1)<<0))
+#define EXTRACT_LONG(p)\
+ ((u_int32_t)*((u_char *)p+0)<<24|\
+ (u_int32_t)*((u_char *)p+1)<<16|\
+ (u_int32_t)*((u_char *)p+2)<<8|\
+ (u_int32_t)*((u_char *)p+3)<<0)
#endif
+#endif /* KERNEL */
+
/* BSD style release date */
#define BPF_RELEASE 199606
};
#ifdef KERNEL_PRIVATE
-/* LP64 version of bpf_program. all pointers
+/*
+ * LP64 version of bpf_program. all pointers
* grow when we're dealing with a 64-bit process.
* WARNING - keep in sync with bpf_program
*/
#define BIOCSETFNR64 _IOW('B',126, struct bpf_program64)
#define BIOCSETFNR32 _IOW('B',126, struct bpf_program32)
#endif /* KERNEL_PRIVATE */
-
+#ifdef PRIVATE
+#define BIOCGWANTPKTAP _IOR('B', 127, u_int)
+#define BIOCSWANTPKTAP _IOWR('B', 127, u_int)
+#define BIOCSHEADDROP _IOW('B', 128, int)
+#define BIOCGHEADDROP _IOR('B', 128, int)
+#define BIOCSTRUNCATE _IOW('B', 129, u_int)
+#define BIOCGETUUID _IOR('B', 130, uuid_t)
+#define BIOCSETUP _IOW('B', 131, struct bpf_setup_args)
+#define BIOCSPKTHDRV2 _IOW('B', 132, int)
+#define BIOCGPKTHDRV2 _IOW('B', 133, int)
+#endif /* PRIVATE */
/*
* Structure prepended to each packet.
*/
#define BPF_HDR_EXT_FLAGS_DIR_OUT 0x0001
pid_t bh_pid; /* process PID */
char bh_comm[MAXCOMLEN+1]; /* process command */
- u_char _bh_pad2[2];
+ u_char _bh_pad2[1];
+ u_char bh_pktflags;
+#define BPF_PKTFLAGS_TCP_REXMT 0x0001
+#define BPF_PKTFLAGS_START_SEQ 0x0002
+#define BPF_PKTFLAGS_LAST_PKT 0x0004
u_char bh_proto; /* kernel reserved; 0 in userland */
bpf_u_int32 bh_svc; /* service class */
bpf_u_int32 bh_flowid; /* kernel reserved; 0 in userland */
+ bpf_u_int32 bh_unsent_bytes; /* unsent bytes at interface */
+ bpf_u_int32 bh_unsent_snd; /* unsent bytes at socket buffer */
};
#define BPF_CONTROL_NAME "com.apple.net.bpf"
#define BPF_MTAG_DIR_IN 0
#define BPF_MTAG_DIR_OUT 1
};
+
#endif /* PRIVATE */
/*
/*
* For Apple private usage
*/
+#define DLT_USER0_APPLE_INTERNAL DLT_USER0 /* rdar://12019509 */
+#define DLT_USER1_APPLE_INTERNAL DLT_USER1 /* rdar://12019509 */
#define DLT_PKTAP DLT_USER2 /* rdar://11779467 */
+#define DLT_USER3_APPLE_INTERNAL DLT_USER3 /* rdar://19614531 */
+#define DLT_USER4_APPLE_INTERNAL DLT_USER4 /* rdar://19614531 */
#endif /* PRIVATE */
/*
*/
#define DLT_NFC_LLCP 245
+/*
+ * USB packets, beginning with a Darwin (macOS, etc.) USB header.
+ */
+#define DLT_USB_DARWIN 266
-#define DLT_MATCHING_MAX 245 /* highest value in the "matching" range */
+#define DLT_MATCHING_MAX 266 /* highest value in the "matching" range */
/*
* The instruction encodings.
#pragma pack()
#ifdef KERNEL_PRIVATE
+#define BPF_MIN_PKT_SIZE 40
+#define PORT_DNS 53
+#define PORT_BOOTPS 67
+#define PORT_BOOTPC 68
+#define PORT_ISAKMP 500
+#define PORT_ISAKMP_NATT 4500 /* rfc3948 */
+
/* Forward declerations */
struct ifnet;
struct mbuf;
+#define BPF_PACKET_TYPE_MBUF 0
+
+struct bpf_packet {
+ int bpfp_type;
+ void * bpfp_header; /* optional */
+ size_t bpfp_header_length;
+ union {
+ struct mbuf *bpfpu_mbuf;
+ void * bpfpu_ptr;
+ } bpfp_u;
+#define bpfp_mbuf bpfp_u.bpfpu_mbuf
+#define bpfp_ptr bpfp_u.bpfpu_ptr
+ size_t bpfp_total_length; /* length including optional header */
+};
+
extern int bpf_validate(const struct bpf_insn *, int);
extern void bpfdetach(struct ifnet *);
extern void bpfilterattach(int);
link type are specified. The callback is responsible for
releasing the mbuf whether or not it returns an error.
@param interface The interface the packet is being sent on.
- @param dlt The data link type the bpf device is attached to.
+ @param data_link_type The data link type the bpf device is attached to.
@param packet The packet to be sent.
*/
typedef errno_t (*bpf_send_func)(ifnet_t interface, u_int32_t data_link_type,
- mbuf_t packet);
+ mbuf_t packet);
/*!
@typedef bpf_tap_func
decreasing (tap in or out is stopping), the error will be
ignored.
@param interface The interface being tapped.
- @param dlt The data link type being tapped.
+ @param data_link_type The data link type being tapped.
@param direction The direction of the tap.
*/
typedef errno_t (*bpf_tap_func)(ifnet_t interface, u_int32_t data_link_type,
- bpf_tap_mode direction);
+ bpf_tap_mode direction);
/*!
@function bpfattach
@param dlt The data link type of the packet.
@param packet The packet received.
@param header An optional pointer to a header that will be prepended.
- @param headerlen If the header was specified, the length of the header.
+ @param header_len If the header was specified, the length of the header.
*/
extern void bpf_tap_in(ifnet_t interface, u_int32_t dlt, mbuf_t packet,
void *header, size_t header_len);
/*!
@function bpf_tap_out
- @discussion Call this function when your interface trasmits a
+ @discussion Call this function when your interface transmits a
packet. This function will check if any bpf devices need a
a copy of the packet.
@param interface The interface the packet was or will be transmitted on.
@param dlt The data link type of the packet.
@param packet The packet received.
@param header An optional pointer to a header that will be prepended.
- @param headerlen If the header was specified, the length of the header.
+ @param header_len If the header was specified, the length of the header.
*/
extern void bpf_tap_out(ifnet_t interface, u_int32_t dlt, mbuf_t packet,
void *header, size_t header_len);