]> git.saurik.com Git - apple/xnu.git/blame - bsd/netinet/flow_divert.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / netinet / flow_divert.h
CommitLineData
39236c6e 1/*
f427ee49 2 * Copyright (c) 2012-2017, 2020 Apple Inc. All rights reserved.
39236c6e
A
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
39236c6e
A
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.
0a7de745 14 *
39236c6e
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
39236c6e
A
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.
0a7de745 25 *
39236c6e
A
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef __FLOW_DIVERT_H__
30#define __FLOW_DIVERT_H__
31
32#include <sys/mbuf.h>
33
34struct flow_divert_group;
39037602 35struct flow_divert_trie_node;
39236c6e
A
36
37struct flow_divert_pcb {
0a7de745 38 decl_lck_mtx_data(, mtx);
f427ee49
A
39 socket_t so;
40 RB_ENTRY(flow_divert_pcb) rb_link;
41 uint32_t hash;
42 mbuf_t connect_token;
43 uint32_t flags;
44 uint32_t send_window;
45 struct flow_divert_group *group;
46 uint32_t control_group_unit;
47 uint32_t aggregate_unit;
48 uint32_t policy_control_unit;
49 int32_t ref_count;
50 uint32_t bytes_written_by_app;
51 uint32_t bytes_read_by_app;
52 uint32_t bytes_sent;
53 uint32_t bytes_received;
54 uint8_t log_level;
55 SLIST_ENTRY(flow_divert_pcb) tmp_list_entry;
56 mbuf_t connect_packet;
57 uint8_t *app_data;
58 size_t app_data_length;
59 union sockaddr_in_4_6 local_endpoint;
60 struct sockaddr *original_remote_endpoint;
61 struct ifnet *original_last_outifp6;
62 struct ifnet *original_last_outifp;
63 uint8_t original_vflag;
39236c6e
A
64};
65
66RB_HEAD(fd_pcb_tree, flow_divert_pcb);
67
0a7de745 68struct flow_divert_trie {
39037602
A
69 struct flow_divert_trie_node *nodes;
70 uint16_t *child_maps;
71 uint8_t *bytes;
72 void *memory;
f427ee49
A
73 uint16_t nodes_count;
74 uint16_t child_maps_count;
75 uint16_t bytes_count;
76 uint16_t nodes_free_next;
77 uint16_t child_maps_free_next;
78 uint16_t bytes_free_next;
39037602
A
79 uint16_t root;
80};
81
39236c6e 82struct flow_divert_group {
0a7de745
A
83 decl_lck_rw_data(, lck);
84 struct fd_pcb_tree pcb_tree;
85 uint32_t ctl_unit;
86 uint8_t atomic_bits;
87 MBUFQ_HEAD(send_queue_head) send_queue;
88 uint8_t *token_key;
89 size_t token_key_size;
90 uint32_t flags;
91 struct flow_divert_trie signing_id_trie;
39236c6e
A
92};
93
0a7de745
A
94void flow_divert_init(void);
95void flow_divert_detach(struct socket *so);
96errno_t flow_divert_token_set(struct socket *so, struct sockopt *sopt);
97errno_t flow_divert_token_get(struct socket *so, struct sockopt *sopt);
f427ee49 98errno_t flow_divert_pcb_init(struct socket *so);
0a7de745
A
99errno_t flow_divert_connect_out(struct socket *so, struct sockaddr *to, proc_t p);
100errno_t flow_divert_implicit_data_out(struct socket *so, int flags, mbuf_t data, struct sockaddr *to, mbuf_t control, struct proc *p);
39236c6e
A
101
102#endif /* __FLOW_DIVERT_H__ */