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