1 | /* |
2 | * Copyright (c) 2017-2018 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 | |
30 | #ifndef _NET_IF_PORT_USED_H_ |
31 | #define _NET_IF_PORT_USED_H_ |
32 | |
33 | #ifdef PRIVATE |
34 | |
35 | #include <sys/types.h> |
36 | #include <stdint.h> |
37 | #include <sys/proc.h> |
38 | #include <sys/queue.h> |
39 | #include <sys/_types/_timeval32.h> |
40 | #include <netinet/in.h> |
41 | #include <uuid/uuid.h> |
42 | |
43 | #define IP_PORTRANGE_SIZE 65536 |
44 | |
45 | /* |
46 | * The sysctl "net.link.generic.system.port_used.list" returns: |
47 | * - one "struct xnpigen" as a preamble |
48 | * - zero or more "struct net_port_info" according to xng_npi_count |
49 | * |
50 | * The list may contain information several interfaces if several drivers |
51 | * queried the list of port to offload |
52 | * |
53 | * The same local port may have more than one "struct net_port_info" on |
54 | * a given interface, for example when a local server has mutiple clients |
55 | * connections |
56 | */ |
57 | |
58 | struct xnpigen { |
59 | uint32_t xng_len; /* length of this data structure */ |
60 | uint32_t xng_gen; /* how many times the list was built */ |
61 | uint32_t xng_npi_count; /* number of net_port_info following */ |
62 | uint32_t xng_npi_size; /* number of struct net_port_info */ |
63 | uuid_t xng_wakeuuid; /* WakeUUID when list was built */ |
64 | }; |
65 | |
66 | union in_addr_4_6 { |
67 | struct in_addr _in_a_4; |
68 | struct in6_addr _in_a_6; |
69 | }; |
70 | |
71 | #define NPIF_IPV4 0x00000001 |
72 | #define NPIF_IPV6 0x00000002 |
73 | #define NPIF_TCP 0x00000004 |
74 | #define NPIF_UDP 0x00000008 |
75 | #define NPIF_DELEGATED 0x00000010 |
76 | #define NPIF_SOCKET 0x00000020 |
77 | #define NPIF_CHANNEL 0x00000040 |
78 | |
79 | struct net_port_info { |
80 | uint16_t npi_if_index; |
81 | uint16_t npi_flags; |
82 | struct timeval32 npi_timestamp; /* when passed to driver */ |
83 | uuid_t npi_flow_uuid; |
84 | in_port_t npi_local_port; /* network byte order */ |
85 | in_port_t npi_foreign_port; /* network byte order */ |
86 | union in_addr_4_6 npi_local_addr_; |
87 | union in_addr_4_6 npi_foreign_addr_; |
88 | pid_t npi_owner_pid; |
89 | pid_t npi_effective_pid; |
90 | char npi_owner_pname[MAXCOMLEN+1]; |
91 | char npi_effective_pname[MAXCOMLEN+1]; |
92 | }; |
93 | |
94 | #define npi_local_addr_in npi_local_addr_._in_a_4 |
95 | #define npi_foreign_addr_in npi_foreign_addr_._in_a_4 |
96 | |
97 | #define npi_local_addr_in6 npi_local_addr_._in_a_6 |
98 | #define npi_foreign_addr_in6 npi_foreign_addr_._in_a_6 |
99 | |
100 | #ifdef XNU_KERNEL_PRIVATE |
101 | |
102 | void if_ports_used_init(void); |
103 | |
104 | void if_ports_used_update_wakeuuid(struct ifnet *); |
105 | |
106 | struct inpcb; |
107 | void if_ports_used_add_inpcb(const uint32_t ifindex, const struct inpcb *inp); |
108 | |
109 | |
110 | #endif /* XNU_KERNEL_PRIVATE */ |
111 | #endif /* PRIVATE */ |
112 | |
113 | #endif /* _NET_IF_PORT_USED_H_ */ |
114 | |