]> git.saurik.com Git - apple/xnu.git/blame - bsd/net/if_ports_used.h
xnu-7195.81.3.tar.gz
[apple/xnu.git] / bsd / net / if_ports_used.h
CommitLineData
a39ff7e2
A
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
0a7de745 43#define IP_PORTRANGE_SIZE 65536
a39ff7e2
A
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
58struct xnpigen {
0a7de745
A
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 */
a39ff7e2
A
64};
65
66union in_addr_4_6 {
0a7de745
A
67 struct in_addr _in_a_4;
68 struct in6_addr _in_a_6;
a39ff7e2
A
69};
70
94ff46dc
A
71#define NPIF_IPV4 0x0001
72#define NPIF_IPV6 0x0002
73#define NPIF_TCP 0x0004
74#define NPIF_UDP 0x0008
75#define NPIF_DELEGATED 0x0010
76#define NPIF_SOCKET 0x0020
77#define NPIF_CHANNEL 0x0040
78#define NPIF_LISTEN 0x0080
a39ff7e2
A
79
80struct net_port_info {
0a7de745
A
81 uint16_t npi_if_index;
82 uint16_t npi_flags;
83 struct timeval32 npi_timestamp; /* when passed to driver */
84 uuid_t npi_flow_uuid;
85 in_port_t npi_local_port; /* network byte order */
86 in_port_t npi_foreign_port; /* network byte order */
87 union in_addr_4_6 npi_local_addr_;
88 union in_addr_4_6 npi_foreign_addr_;
89 pid_t npi_owner_pid;
90 pid_t npi_effective_pid;
91 char npi_owner_pname[MAXCOMLEN + 1];
92 char npi_effective_pname[MAXCOMLEN + 1];
a39ff7e2
A
93};
94
95#define npi_local_addr_in npi_local_addr_._in_a_4
96#define npi_foreign_addr_in npi_foreign_addr_._in_a_4
97
98#define npi_local_addr_in6 npi_local_addr_._in_a_6
99#define npi_foreign_addr_in6 npi_foreign_addr_._in_a_6
100
101#ifdef XNU_KERNEL_PRIVATE
102
103void if_ports_used_init(void);
104
105void if_ports_used_update_wakeuuid(struct ifnet *);
106
107struct inpcb;
108void if_ports_used_add_inpcb(const uint32_t ifindex, const struct inpcb *inp);
109
110
111#endif /* XNU_KERNEL_PRIVATE */
0a7de745 112#endif /* PRIVATE */
a39ff7e2
A
113
114#endif /* _NET_IF_PORT_USED_H_ */