1/*
2 * Copyright (c) 2021 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#ifndef _SKYWALK_NAMESPACE_FLOWIDNS_H_
29#define _SKYWALK_NAMESPACE_FLOWIDNS_H_
30
31/*
32 * The flowidns (Flow ID namespace) module provides functionality to allocate
33 * globally unique identifier for a flow.
34 */
35
36typedef uint32_t flowidns_flowid_t;
37
38typedef enum {
39 FLOWIDNS_DOMAIN_MIN = 0,
40 FLOWIDNS_DOMAIN_IPSEC = FLOWIDNS_DOMAIN_MIN,
41 FLOWIDNS_DOMAIN_FLOWSWITCH,
42 FLOWIDNS_DOMAIN_INPCB,
43 FLOWIDNS_DOMAIN_PF,
44 FLOWIDNS_DOMAIN_MAX = FLOWIDNS_DOMAIN_PF
45} flowidns_domain_id_t;
46
47struct flowidns_flow_key {
48 union {
49 struct in_addr _v4;
50 struct in6_addr _v6;
51 } ffk_laddr; /* local IP address */
52 union {
53 struct in_addr _v4;
54 struct in6_addr _v6;
55 } ffk_raddr; /* remote IP address */
56 union {
57 struct {
58 uint16_t _lport; /* local port */
59 uint16_t _rport; /* remote port */
60 } ffk_ports;
61 uint32_t ffk_spi; /* IPSec ESP/AH SPI */
62 uint32_t ffk_protoid; /* opaque protocol id */
63 };
64 uint8_t ffk_af; /* IP address family AF_INET* */
65 uint8_t ffk_proto; /* IP protocol IP_PROTO_* */
66};
67
68#define ffk_laddr_v4 ffk_laddr._v4
69#define ffk_laddr_v6 ffk_laddr._v6
70#define ffk_raddr_v4 ffk_raddr._v4
71#define ffk_raddr_v6 ffk_raddr._v6
72#define ffk_lport ffk_ports._lport
73#define ffk_rport ffk_ports._rport
74
75extern int flowidns_init(void);
76extern void flowidns_fini(void);
77
78/*
79 * Allocate a globally unique flow identifier.
80 */
81extern void flowidns_allocate_flowid(flowidns_domain_id_t domain,
82 struct flowidns_flow_key *flow_key, flowidns_flowid_t *flowid);
83
84/*
85 * Release an allocated flow identifier.
86 */
87extern void flowidns_release_flowid(flowidns_flowid_t flowid);
88
89#endif /* !_SKYWALK_NAMESPACE_FLOWIDNS_H_ */
90