1*43a90889SApple OSS Distributions /*
2*43a90889SApple OSS Distributions * Copyright (c) 2012-2017 Apple Inc. All rights reserved.
3*43a90889SApple OSS Distributions *
4*43a90889SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*43a90889SApple OSS Distributions *
6*43a90889SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*43a90889SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*43a90889SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*43a90889SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*43a90889SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*43a90889SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*43a90889SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*43a90889SApple OSS Distributions * terms of an Apple operating system software license agreement.
14*43a90889SApple OSS Distributions *
15*43a90889SApple OSS Distributions * Please obtain a copy of the License at
16*43a90889SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*43a90889SApple OSS Distributions *
18*43a90889SApple OSS Distributions * The Original Code and all software distributed under the License are
19*43a90889SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*43a90889SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*43a90889SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*43a90889SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*43a90889SApple OSS Distributions * Please see the License for the specific language governing rights and
24*43a90889SApple OSS Distributions * limitations under the License.
25*43a90889SApple OSS Distributions *
26*43a90889SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*43a90889SApple OSS Distributions */
28*43a90889SApple OSS Distributions
29*43a90889SApple OSS Distributions #ifndef _NETINET_MP_PCB_H_
30*43a90889SApple OSS Distributions #define _NETINET_MP_PCB_H_
31*43a90889SApple OSS Distributions
32*43a90889SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
33*43a90889SApple OSS Distributions #include <netinet/in_pcb.h>
34*43a90889SApple OSS Distributions
35*43a90889SApple OSS Distributions #include <sys/domain.h>
36*43a90889SApple OSS Distributions #include <sys/protosw.h>
37*43a90889SApple OSS Distributions #include <sys/socketvar.h>
38*43a90889SApple OSS Distributions #include <sys/types.h>
39*43a90889SApple OSS Distributions #include <sys/queue.h>
40*43a90889SApple OSS Distributions #include <kern/locks.h>
41*43a90889SApple OSS Distributions
42*43a90889SApple OSS Distributions /* Keep in sync with bsd/dev/dtrace/scripts/mptcp.d */
43*43a90889SApple OSS Distributions typedef enum mppcb_state {
44*43a90889SApple OSS Distributions MPPCB_STATE_INUSE = 1,
45*43a90889SApple OSS Distributions MPPCB_STATE_DEAD = 2,
46*43a90889SApple OSS Distributions } mppcb_state_t;
47*43a90889SApple OSS Distributions
48*43a90889SApple OSS Distributions /*
49*43a90889SApple OSS Distributions * Multipath Protocol Control Block
50*43a90889SApple OSS Distributions */
51*43a90889SApple OSS Distributions struct mppcb {
52*43a90889SApple OSS Distributions TAILQ_ENTRY(mppcb) mpp_entry; /* glue to all PCBs */
53*43a90889SApple OSS Distributions decl_lck_mtx_data(, mpp_lock); /* per PCB lock */
54*43a90889SApple OSS Distributions struct mppcbinfo *mpp_pcbinfo; /* PCB info */
55*43a90889SApple OSS Distributions struct mptses *mpp_pcbe; /* ptr to MPTCP-session */
56*43a90889SApple OSS Distributions struct socket *mpp_socket; /* back pointer to socket */
57*43a90889SApple OSS Distributions uint32_t mpp_flags; /* PCB flags */
58*43a90889SApple OSS Distributions mppcb_state_t mpp_state; /* PCB state */
59*43a90889SApple OSS Distributions int32_t mpp_inside; /* Indicates whether or not a thread is processing MPTCP */
60*43a90889SApple OSS Distributions
61*43a90889SApple OSS Distributions #if NECP
62*43a90889SApple OSS Distributions uuid_t necp_client_uuid;
63*43a90889SApple OSS Distributions struct inp_necp_attributes inp_necp_attributes;
64*43a90889SApple OSS Distributions void (*necp_cb)(void *, int, uint32_t, uint32_t, bool *);
65*43a90889SApple OSS Distributions #endif
66*43a90889SApple OSS Distributions };
67*43a90889SApple OSS Distributions
68*43a90889SApple OSS Distributions static inline struct mppcb *
mpsotomppcb(struct socket * mp_so)69*43a90889SApple OSS Distributions mpsotomppcb(struct socket *mp_so)
70*43a90889SApple OSS Distributions {
71*43a90889SApple OSS Distributions VERIFY(SOCK_DOM(mp_so) == PF_MULTIPATH);
72*43a90889SApple OSS Distributions return (struct mppcb *)mp_so->so_pcb;
73*43a90889SApple OSS Distributions }
74*43a90889SApple OSS Distributions
75*43a90889SApple OSS Distributions /* valid values for mpp_flags */
76*43a90889SApple OSS Distributions #define MPP_ATTACHED 0x001
77*43a90889SApple OSS Distributions #define MPP_INSIDE_OUTPUT 0x002 /* MPTCP-stack is inside mptcp_subflow_output */
78*43a90889SApple OSS Distributions #define MPP_INSIDE_INPUT 0x004 /* MPTCP-stack is inside mptcp_subflow_input */
79*43a90889SApple OSS Distributions #define MPP_INPUT_HANDLE 0x008 /* MPTCP-stack is handling input */
80*43a90889SApple OSS Distributions #define MPP_WUPCALL 0x010 /* MPTCP-stack is handling a read upcall */
81*43a90889SApple OSS Distributions #define MPP_SHOULD_WORKLOOP 0x020 /* MPTCP-stack should call the workloop function */
82*43a90889SApple OSS Distributions #define MPP_SHOULD_RWAKEUP 0x040 /* MPTCP-stack should call sorwakeup */
83*43a90889SApple OSS Distributions #define MPP_SHOULD_WWAKEUP 0x080 /* MPTCP-stack should call sowwakeup */
84*43a90889SApple OSS Distributions #define MPP_CREATE_SUBFLOWS 0x100 /* This connection needs to create subflows */
85*43a90889SApple OSS Distributions #define MPP_INSIDE_SETGETOPT 0x200 /* MPTCP-stack is inside mptcp_setopt/mptcp_getopt */
86*43a90889SApple OSS Distributions
87*43a90889SApple OSS Distributions static inline boolean_t
mptcp_should_defer_upcall(struct mppcb * mpp)88*43a90889SApple OSS Distributions mptcp_should_defer_upcall(struct mppcb *mpp)
89*43a90889SApple OSS Distributions {
90*43a90889SApple OSS Distributions return !!(mpp->mpp_flags & (MPP_INSIDE_OUTPUT | MPP_INSIDE_INPUT | MPP_INPUT_HANDLE | MPP_WUPCALL));
91*43a90889SApple OSS Distributions }
92*43a90889SApple OSS Distributions
93*43a90889SApple OSS Distributions /*
94*43a90889SApple OSS Distributions * Multipath PCB Information
95*43a90889SApple OSS Distributions */
96*43a90889SApple OSS Distributions struct mppcbinfo {
97*43a90889SApple OSS Distributions TAILQ_ENTRY(mppcbinfo) mppi_entry; /* glue to all PCB info */
98*43a90889SApple OSS Distributions TAILQ_HEAD(, mppcb) mppi_pcbs; /* list of PCBs */
99*43a90889SApple OSS Distributions uint32_t mppi_count; /* # of PCBs in list */
100*43a90889SApple OSS Distributions lck_attr_t mppi_lock_attr; /* lock attr */
101*43a90889SApple OSS Distributions struct mppcb *(*mppi_alloc)(void);
102*43a90889SApple OSS Distributions void (*mppi_free)(struct mppcb *);
103*43a90889SApple OSS Distributions lck_grp_t *mppi_lock_grp; /* lock grp */
104*43a90889SApple OSS Distributions decl_lck_mtx_data(, mppi_lock); /* global PCB lock */
105*43a90889SApple OSS Distributions uint32_t (*mppi_gc)(struct mppcbinfo *); /* garbage collector func */
106*43a90889SApple OSS Distributions uint32_t (*mppi_timer)(struct mppcbinfo *); /* timer func */
107*43a90889SApple OSS Distributions };
108*43a90889SApple OSS Distributions
109*43a90889SApple OSS Distributions __BEGIN_DECLS
110*43a90889SApple OSS Distributions extern void mp_pcbinfo_attach(struct mppcbinfo *);
111*43a90889SApple OSS Distributions extern int mp_pcbinfo_detach(struct mppcbinfo *);
112*43a90889SApple OSS Distributions extern int mp_pcballoc(struct socket *, struct mppcbinfo *);
113*43a90889SApple OSS Distributions extern void mp_pcbdetach(struct socket *);
114*43a90889SApple OSS Distributions extern void mptcp_pcbdispose(struct mppcb *);
115*43a90889SApple OSS Distributions extern void mp_gc_sched(void);
116*43a90889SApple OSS Distributions extern void mptcp_timer_sched(void);
117*43a90889SApple OSS Distributions extern void mptcp_handle_deferred_upcalls(struct mppcb *mpp, uint32_t flag);
118*43a90889SApple OSS Distributions extern int mp_getsockaddr(struct socket *mp_so, struct sockaddr **nam);
119*43a90889SApple OSS Distributions extern int mp_getpeeraddr(struct socket *mp_so, struct sockaddr **nam);
120*43a90889SApple OSS Distributions #if NECP
121*43a90889SApple OSS Distributions extern int necp_client_register_multipath_cb(pid_t pid, uuid_t client_id, struct mppcb *mpp);
122*43a90889SApple OSS Distributions extern void necp_mppcb_dispose(struct mppcb *mpp);
123*43a90889SApple OSS Distributions #endif
124*43a90889SApple OSS Distributions __END_DECLS
125*43a90889SApple OSS Distributions
126*43a90889SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
127*43a90889SApple OSS Distributions #endif /* !_NETINET_MP_PCB_H_ */
128