xref: /aosp_15_r20/frameworks/native/include/android/multinetwork.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright (C) 2015 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker /**
18*38e8c45fSAndroid Build Coastguard Worker  * @addtogroup Networking
19*38e8c45fSAndroid Build Coastguard Worker  * @{
20*38e8c45fSAndroid Build Coastguard Worker  */
21*38e8c45fSAndroid Build Coastguard Worker 
22*38e8c45fSAndroid Build Coastguard Worker /**
23*38e8c45fSAndroid Build Coastguard Worker  * @file multinetwork.h
24*38e8c45fSAndroid Build Coastguard Worker  */
25*38e8c45fSAndroid Build Coastguard Worker 
26*38e8c45fSAndroid Build Coastguard Worker #ifndef ANDROID_MULTINETWORK_H
27*38e8c45fSAndroid Build Coastguard Worker #define ANDROID_MULTINETWORK_H
28*38e8c45fSAndroid Build Coastguard Worker 
29*38e8c45fSAndroid Build Coastguard Worker #include <netdb.h>
30*38e8c45fSAndroid Build Coastguard Worker #include <stdlib.h>
31*38e8c45fSAndroid Build Coastguard Worker #include <sys/cdefs.h>
32*38e8c45fSAndroid Build Coastguard Worker 
33*38e8c45fSAndroid Build Coastguard Worker __BEGIN_DECLS
34*38e8c45fSAndroid Build Coastguard Worker 
35*38e8c45fSAndroid Build Coastguard Worker /**
36*38e8c45fSAndroid Build Coastguard Worker  * The corresponding C type for android.net.Network#getNetworkHandle() return
37*38e8c45fSAndroid Build Coastguard Worker  * values.  The Java signed long value can be safely cast to a net_handle_t:
38*38e8c45fSAndroid Build Coastguard Worker  *
39*38e8c45fSAndroid Build Coastguard Worker  *     [C]    ((net_handle_t) java_long_network_handle)
40*38e8c45fSAndroid Build Coastguard Worker  *     [C++]  static_cast<net_handle_t>(java_long_network_handle)
41*38e8c45fSAndroid Build Coastguard Worker  *
42*38e8c45fSAndroid Build Coastguard Worker  * as appropriate.
43*38e8c45fSAndroid Build Coastguard Worker  */
44*38e8c45fSAndroid Build Coastguard Worker typedef uint64_t net_handle_t;
45*38e8c45fSAndroid Build Coastguard Worker 
46*38e8c45fSAndroid Build Coastguard Worker /**
47*38e8c45fSAndroid Build Coastguard Worker  * The value NETWORK_UNSPECIFIED indicates no specific network.
48*38e8c45fSAndroid Build Coastguard Worker  *
49*38e8c45fSAndroid Build Coastguard Worker  * For some functions (documented below), a previous binding may be cleared
50*38e8c45fSAndroid Build Coastguard Worker  * by an invocation with NETWORK_UNSPECIFIED.
51*38e8c45fSAndroid Build Coastguard Worker  *
52*38e8c45fSAndroid Build Coastguard Worker  * Depending on the context it may indicate an error.  It is expressly
53*38e8c45fSAndroid Build Coastguard Worker  * not used to indicate some notion of the "current default network".
54*38e8c45fSAndroid Build Coastguard Worker  */
55*38e8c45fSAndroid Build Coastguard Worker #define NETWORK_UNSPECIFIED  ((net_handle_t)0)
56*38e8c45fSAndroid Build Coastguard Worker 
57*38e8c45fSAndroid Build Coastguard Worker 
58*38e8c45fSAndroid Build Coastguard Worker /**
59*38e8c45fSAndroid Build Coastguard Worker  * All functions below that return an int return 0 on success or -1
60*38e8c45fSAndroid Build Coastguard Worker  * on failure with an appropriate errno value set.
61*38e8c45fSAndroid Build Coastguard Worker  */
62*38e8c45fSAndroid Build Coastguard Worker 
63*38e8c45fSAndroid Build Coastguard Worker /**
64*38e8c45fSAndroid Build Coastguard Worker  * Set the network to be used by the given socket file descriptor.
65*38e8c45fSAndroid Build Coastguard Worker  *
66*38e8c45fSAndroid Build Coastguard Worker  * To clear a previous socket binding, invoke with NETWORK_UNSPECIFIED.
67*38e8c45fSAndroid Build Coastguard Worker  *
68*38e8c45fSAndroid Build Coastguard Worker  * This is the equivalent of: [android.net.Network#bindSocket()](https://developer.android.com/reference/android/net/Network.html#bindSocket(java.net.Socket))
69*38e8c45fSAndroid Build Coastguard Worker  *
70*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 23.
71*38e8c45fSAndroid Build Coastguard Worker  */
72*38e8c45fSAndroid Build Coastguard Worker int android_setsocknetwork(net_handle_t network, int fd) __INTRODUCED_IN(23);
73*38e8c45fSAndroid Build Coastguard Worker 
74*38e8c45fSAndroid Build Coastguard Worker 
75*38e8c45fSAndroid Build Coastguard Worker /**
76*38e8c45fSAndroid Build Coastguard Worker  * Binds the current process to |network|.  All sockets created in the future
77*38e8c45fSAndroid Build Coastguard Worker  * (and not explicitly bound via android_setsocknetwork()) will be bound to
78*38e8c45fSAndroid Build Coastguard Worker  * |network|.  All host name resolutions will be limited to |network| as well.
79*38e8c45fSAndroid Build Coastguard Worker  * Note that if the network identified by |network| ever disconnects, all
80*38e8c45fSAndroid Build Coastguard Worker  * sockets created in this way will cease to work and all host name
81*38e8c45fSAndroid Build Coastguard Worker  * resolutions will fail.  This is by design so an application doesn't
82*38e8c45fSAndroid Build Coastguard Worker  * accidentally use sockets it thinks are still bound to a particular network.
83*38e8c45fSAndroid Build Coastguard Worker  *
84*38e8c45fSAndroid Build Coastguard Worker  * To clear a previous process binding, invoke with NETWORK_UNSPECIFIED.
85*38e8c45fSAndroid Build Coastguard Worker  *
86*38e8c45fSAndroid Build Coastguard Worker  * This is the equivalent of: [android.net.ConnectivityManager#bindProcessToNetwork()](https://developer.android.com/reference/android/net/ConnectivityManager.html#bindProcessToNetwork(android.net.Network))
87*38e8c45fSAndroid Build Coastguard Worker  *
88*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 23.
89*38e8c45fSAndroid Build Coastguard Worker  */
90*38e8c45fSAndroid Build Coastguard Worker int android_setprocnetwork(net_handle_t network) __INTRODUCED_IN(23);
91*38e8c45fSAndroid Build Coastguard Worker 
92*38e8c45fSAndroid Build Coastguard Worker 
93*38e8c45fSAndroid Build Coastguard Worker /**
94*38e8c45fSAndroid Build Coastguard Worker  * Gets the |network| bound to the current process, as per android_setprocnetwork.
95*38e8c45fSAndroid Build Coastguard Worker  *
96*38e8c45fSAndroid Build Coastguard Worker  * This is the equivalent of: [android.net.ConnectivityManager#getBoundNetworkForProcess()](https://developer.android.com/reference/android/net/ConnectivityManager.html#getBoundNetworkForProcess(android.net.Network))
97*38e8c45fSAndroid Build Coastguard Worker  * Returns 0 on success, or -1 setting errno to EINVAL if a null pointer is
98*38e8c45fSAndroid Build Coastguard Worker  * passed in.
99*38e8c45fSAndroid Build Coastguard Worker  *
100*38e8c45fSAndroid Build Coastguard Worker  *
101*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 31.
102*38e8c45fSAndroid Build Coastguard Worker  */
103*38e8c45fSAndroid Build Coastguard Worker int android_getprocnetwork(net_handle_t *network) __INTRODUCED_IN(31);
104*38e8c45fSAndroid Build Coastguard Worker 
105*38e8c45fSAndroid Build Coastguard Worker /**
106*38e8c45fSAndroid Build Coastguard Worker  * Binds domain name resolutions performed by this process to |network|.
107*38e8c45fSAndroid Build Coastguard Worker  * android_setprocnetwork takes precedence over this setting.
108*38e8c45fSAndroid Build Coastguard Worker  *
109*38e8c45fSAndroid Build Coastguard Worker  * To clear a previous process binding, invoke with NETWORK_UNSPECIFIED.
110*38e8c45fSAndroid Build Coastguard Worker  * On success 0 is returned. On error -1 is returned, and errno is set.
111*38e8c45fSAndroid Build Coastguard Worker  *
112*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 31.
113*38e8c45fSAndroid Build Coastguard Worker  */
114*38e8c45fSAndroid Build Coastguard Worker int android_setprocdns(net_handle_t network) __INTRODUCED_IN(31);
115*38e8c45fSAndroid Build Coastguard Worker 
116*38e8c45fSAndroid Build Coastguard Worker /**
117*38e8c45fSAndroid Build Coastguard Worker  * Gets the |network| to which domain name resolutions are bound on the
118*38e8c45fSAndroid Build Coastguard Worker  * current process.
119*38e8c45fSAndroid Build Coastguard Worker  *
120*38e8c45fSAndroid Build Coastguard Worker  * Returns 0 on success, or -1 setting errno to EINVAL if a null pointer is
121*38e8c45fSAndroid Build Coastguard Worker  * passed in.
122*38e8c45fSAndroid Build Coastguard Worker  *
123*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 31.
124*38e8c45fSAndroid Build Coastguard Worker  */
125*38e8c45fSAndroid Build Coastguard Worker int android_getprocdns(net_handle_t *network) __INTRODUCED_IN(31);
126*38e8c45fSAndroid Build Coastguard Worker 
127*38e8c45fSAndroid Build Coastguard Worker 
128*38e8c45fSAndroid Build Coastguard Worker /**
129*38e8c45fSAndroid Build Coastguard Worker  * Perform hostname resolution via the DNS servers associated with |network|.
130*38e8c45fSAndroid Build Coastguard Worker  *
131*38e8c45fSAndroid Build Coastguard Worker  * All arguments (apart from |network|) are used identically as those passed
132*38e8c45fSAndroid Build Coastguard Worker  * to getaddrinfo(3).  Return and error values are identical to those of
133*38e8c45fSAndroid Build Coastguard Worker  * getaddrinfo(3), and in particular gai_strerror(3) can be used as expected.
134*38e8c45fSAndroid Build Coastguard Worker  * Similar to getaddrinfo(3):
135*38e8c45fSAndroid Build Coastguard Worker  *     - |hints| may be NULL (in which case man page documented defaults apply)
136*38e8c45fSAndroid Build Coastguard Worker  *     - either |node| or |service| may be NULL, but not both
137*38e8c45fSAndroid Build Coastguard Worker  *     - |res| must not be NULL
138*38e8c45fSAndroid Build Coastguard Worker  *
139*38e8c45fSAndroid Build Coastguard Worker  * This is the equivalent of: [android.net.Network#getAllByName()](https://developer.android.com/reference/android/net/Network.html#getAllByName(java.lang.String))
140*38e8c45fSAndroid Build Coastguard Worker  *
141*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 23.
142*38e8c45fSAndroid Build Coastguard Worker  */
143*38e8c45fSAndroid Build Coastguard Worker int android_getaddrinfofornetwork(net_handle_t network,
144*38e8c45fSAndroid Build Coastguard Worker         const char *node, const char *service,
145*38e8c45fSAndroid Build Coastguard Worker         const struct addrinfo *hints, struct addrinfo **res) __INTRODUCED_IN(23);
146*38e8c45fSAndroid Build Coastguard Worker 
147*38e8c45fSAndroid Build Coastguard Worker /**
148*38e8c45fSAndroid Build Coastguard Worker  * Possible values of the flags argument to android_res_nsend and android_res_nquery.
149*38e8c45fSAndroid Build Coastguard Worker  * Values are ORed together.
150*38e8c45fSAndroid Build Coastguard Worker  */
151*38e8c45fSAndroid Build Coastguard Worker enum ResNsendFlags : uint32_t {
152*38e8c45fSAndroid Build Coastguard Worker     /**
153*38e8c45fSAndroid Build Coastguard Worker      * Send a single request to a single resolver and fail on timeout or network errors
154*38e8c45fSAndroid Build Coastguard Worker      */
155*38e8c45fSAndroid Build Coastguard Worker     ANDROID_RESOLV_NO_RETRY = 1 << 0,
156*38e8c45fSAndroid Build Coastguard Worker 
157*38e8c45fSAndroid Build Coastguard Worker     /**
158*38e8c45fSAndroid Build Coastguard Worker      * Don't lookup this request in the cache, and don't cache the result of the lookup.
159*38e8c45fSAndroid Build Coastguard Worker      * This flag implies {@link #ANDROID_RESOLV_NO_CACHE_LOOKUP}.
160*38e8c45fSAndroid Build Coastguard Worker      */
161*38e8c45fSAndroid Build Coastguard Worker     ANDROID_RESOLV_NO_CACHE_STORE = 1 << 1,
162*38e8c45fSAndroid Build Coastguard Worker 
163*38e8c45fSAndroid Build Coastguard Worker     /**
164*38e8c45fSAndroid Build Coastguard Worker      * Don't lookup the request in cache.
165*38e8c45fSAndroid Build Coastguard Worker      */
166*38e8c45fSAndroid Build Coastguard Worker     ANDROID_RESOLV_NO_CACHE_LOOKUP = 1 << 2,
167*38e8c45fSAndroid Build Coastguard Worker };
168*38e8c45fSAndroid Build Coastguard Worker 
169*38e8c45fSAndroid Build Coastguard Worker /**
170*38e8c45fSAndroid Build Coastguard Worker  * Look up the {|ns_class|, |ns_type|} Resource Record (RR) associated
171*38e8c45fSAndroid Build Coastguard Worker  * with Domain Name |dname| on the given |network|.
172*38e8c45fSAndroid Build Coastguard Worker  * The typical value for |ns_class| is ns_c_in, while |type| can be any
173*38e8c45fSAndroid Build Coastguard Worker  * record type (for instance, ns_t_aaaa or ns_t_txt).
174*38e8c45fSAndroid Build Coastguard Worker  * |flags| is a additional config to control actual querying behavior, see
175*38e8c45fSAndroid Build Coastguard Worker  * ResNsendFlags for detail.
176*38e8c45fSAndroid Build Coastguard Worker  *
177*38e8c45fSAndroid Build Coastguard Worker  * Returns a file descriptor to watch for read events, or a negative
178*38e8c45fSAndroid Build Coastguard Worker  * POSIX error code (see errno.h) if an immediate error occurs.
179*38e8c45fSAndroid Build Coastguard Worker  *
180*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 29.
181*38e8c45fSAndroid Build Coastguard Worker  */
182*38e8c45fSAndroid Build Coastguard Worker int android_res_nquery(net_handle_t network,
183*38e8c45fSAndroid Build Coastguard Worker         const char *dname, int ns_class, int ns_type, uint32_t flags) __INTRODUCED_IN(29);
184*38e8c45fSAndroid Build Coastguard Worker 
185*38e8c45fSAndroid Build Coastguard Worker /**
186*38e8c45fSAndroid Build Coastguard Worker  * Issue the query |msg| on the given |network|.
187*38e8c45fSAndroid Build Coastguard Worker  * |flags| is a additional config to control actual querying behavior, see
188*38e8c45fSAndroid Build Coastguard Worker  * ResNsendFlags for detail.
189*38e8c45fSAndroid Build Coastguard Worker  *
190*38e8c45fSAndroid Build Coastguard Worker  * Returns a file descriptor to watch for read events, or a negative
191*38e8c45fSAndroid Build Coastguard Worker  * POSIX error code (see errno.h) if an immediate error occurs.
192*38e8c45fSAndroid Build Coastguard Worker  *
193*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 29.
194*38e8c45fSAndroid Build Coastguard Worker  */
195*38e8c45fSAndroid Build Coastguard Worker int android_res_nsend(net_handle_t network,
196*38e8c45fSAndroid Build Coastguard Worker         const uint8_t *msg, size_t msglen, uint32_t flags) __INTRODUCED_IN(29);
197*38e8c45fSAndroid Build Coastguard Worker 
198*38e8c45fSAndroid Build Coastguard Worker /**
199*38e8c45fSAndroid Build Coastguard Worker  * Read a result for the query associated with the |fd| descriptor.
200*38e8c45fSAndroid Build Coastguard Worker  * Closes |fd| before returning.
201*38e8c45fSAndroid Build Coastguard Worker  *
202*38e8c45fSAndroid Build Coastguard Worker  * Available since 29.
203*38e8c45fSAndroid Build Coastguard Worker  *
204*38e8c45fSAndroid Build Coastguard Worker  * Returns:
205*38e8c45fSAndroid Build Coastguard Worker  *     < 0: negative POSIX error code (see errno.h for possible values). |rcode| is not set.
206*38e8c45fSAndroid Build Coastguard Worker  *     >= 0: length of |answer|. |rcode| is the resolver return code (e.g., ns_r_nxdomain)
207*38e8c45fSAndroid Build Coastguard Worker  */
208*38e8c45fSAndroid Build Coastguard Worker int android_res_nresult(int fd,
209*38e8c45fSAndroid Build Coastguard Worker         int *rcode, uint8_t *answer, size_t anslen) __INTRODUCED_IN(29);
210*38e8c45fSAndroid Build Coastguard Worker 
211*38e8c45fSAndroid Build Coastguard Worker /**
212*38e8c45fSAndroid Build Coastguard Worker  * Attempts to cancel the in-progress query associated with the |nsend_fd|
213*38e8c45fSAndroid Build Coastguard Worker  * descriptor.
214*38e8c45fSAndroid Build Coastguard Worker  *
215*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 29.
216*38e8c45fSAndroid Build Coastguard Worker  */
217*38e8c45fSAndroid Build Coastguard Worker void android_res_cancel(int nsend_fd) __INTRODUCED_IN(29);
218*38e8c45fSAndroid Build Coastguard Worker 
219*38e8c45fSAndroid Build Coastguard Worker /*
220*38e8c45fSAndroid Build Coastguard Worker  * Set the socket tag and owning UID for traffic statistics on the specified
221*38e8c45fSAndroid Build Coastguard Worker  * socket.
222*38e8c45fSAndroid Build Coastguard Worker  *
223*38e8c45fSAndroid Build Coastguard Worker  * Subsequent calls always replace any existing parameters. The socket tag and
224*38e8c45fSAndroid Build Coastguard Worker  * uid (if set) are kept when the socket is sent to another process using binder
225*38e8c45fSAndroid Build Coastguard Worker  * IPCs or other mechanisms such as UNIX socket fd passing. Any app can accept
226*38e8c45fSAndroid Build Coastguard Worker  * blame for future traffic performed on a socket originally created by another
227*38e8c45fSAndroid Build Coastguard Worker  * app by calling this method with its own UID (or calling
228*38e8c45fSAndroid Build Coastguard Worker  * android_tag_socket(int sockfd, int tag)). However, only apps holding the
229*38e8c45fSAndroid Build Coastguard Worker  * android.Manifest.permission#UPDATE_DEVICE_STATS permission may assign blame
230*38e8c45fSAndroid Build Coastguard Worker  * to another UIDs. If unset (default) the socket tag is 0, and the uid is the
231*38e8c45fSAndroid Build Coastguard Worker  * socket creator's uid.
232*38e8c45fSAndroid Build Coastguard Worker  *
233*38e8c45fSAndroid Build Coastguard Worker  * Returns 0 on success, or a negative POSIX error code (see errno.h) on
234*38e8c45fSAndroid Build Coastguard Worker  * failure.
235*38e8c45fSAndroid Build Coastguard Worker  *
236*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 33.
237*38e8c45fSAndroid Build Coastguard Worker  */
238*38e8c45fSAndroid Build Coastguard Worker int android_tag_socket_with_uid(int sockfd, uint32_t tag, uid_t uid) __INTRODUCED_IN(33);
239*38e8c45fSAndroid Build Coastguard Worker 
240*38e8c45fSAndroid Build Coastguard Worker /*
241*38e8c45fSAndroid Build Coastguard Worker  * Set the socket tag for traffic statistics on the specified socket.
242*38e8c45fSAndroid Build Coastguard Worker  *
243*38e8c45fSAndroid Build Coastguard Worker  * This function tags the socket with the caller's UID (accepting blame for
244*38e8c45fSAndroid Build Coastguard Worker  * future traffic performed on this socket) even if the socket was originally
245*38e8c45fSAndroid Build Coastguard Worker  * opened by another UID or was previously tagged by another UID. Subsequent
246*38e8c45fSAndroid Build Coastguard Worker  * calls always replace any existing parameters. The socket tag is kept when the
247*38e8c45fSAndroid Build Coastguard Worker  * socket is sent to another process using binder IPCs or other mechanisms such
248*38e8c45fSAndroid Build Coastguard Worker  * as UNIX socket fd passing. The tag is a value defined by the caller and used
249*38e8c45fSAndroid Build Coastguard Worker  * together with uid for data traffic accounting, so that the function callers
250*38e8c45fSAndroid Build Coastguard Worker  * can account different types of data usage for a uid.
251*38e8c45fSAndroid Build Coastguard Worker  *
252*38e8c45fSAndroid Build Coastguard Worker  * Returns 0 on success, or a negative POSIX error code (see errno.h) on
253*38e8c45fSAndroid Build Coastguard Worker  * failure.
254*38e8c45fSAndroid Build Coastguard Worker  *
255*38e8c45fSAndroid Build Coastguard Worker  * Some possible error codes:
256*38e8c45fSAndroid Build Coastguard Worker  * -EBADF           Bad socketfd.
257*38e8c45fSAndroid Build Coastguard Worker  * -EPERM           No permission.
258*38e8c45fSAndroid Build Coastguard Worker  * -EAFNOSUPPORT    Socket family is neither AF_INET nor AF_INET6.
259*38e8c45fSAndroid Build Coastguard Worker  * -EPROTONOSUPPORT Socket protocol is neither IPPROTO_UDP nor IPPROTO_TCP.
260*38e8c45fSAndroid Build Coastguard Worker  * -EMFILE          Too many stats entries.
261*38e8c45fSAndroid Build Coastguard Worker  * There are still other error codes that may provided by -errno of
262*38e8c45fSAndroid Build Coastguard Worker  * [getsockopt()](https://man7.org/linux/man-pages/man2/getsockopt.2.html) or by
263*38e8c45fSAndroid Build Coastguard Worker  * BPF maps read/write sys calls, which are set appropriately.
264*38e8c45fSAndroid Build Coastguard Worker  *
265*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 33.
266*38e8c45fSAndroid Build Coastguard Worker  */
267*38e8c45fSAndroid Build Coastguard Worker int android_tag_socket(int sockfd, uint32_t tag) __INTRODUCED_IN(33);
268*38e8c45fSAndroid Build Coastguard Worker 
269*38e8c45fSAndroid Build Coastguard Worker /*
270*38e8c45fSAndroid Build Coastguard Worker  * Untag a network socket.
271*38e8c45fSAndroid Build Coastguard Worker  *
272*38e8c45fSAndroid Build Coastguard Worker  * Future traffic on this socket will no longer be associated with any
273*38e8c45fSAndroid Build Coastguard Worker  * previously configured tag and uid. If the socket was created by another UID
274*38e8c45fSAndroid Build Coastguard Worker  * or was previously tagged by another UID, calling this function will clear the
275*38e8c45fSAndroid Build Coastguard Worker  * statistics parameters, and thus the UID blamed for traffic on the socket will
276*38e8c45fSAndroid Build Coastguard Worker  * be the UID that originally created the socket, even if the socket was
277*38e8c45fSAndroid Build Coastguard Worker  * subsequently tagged by a different UID.
278*38e8c45fSAndroid Build Coastguard Worker  *
279*38e8c45fSAndroid Build Coastguard Worker  * Returns 0 on success, or a negative POSIX error code (see errno.h) on
280*38e8c45fSAndroid Build Coastguard Worker  * failure.
281*38e8c45fSAndroid Build Coastguard Worker  *
282*38e8c45fSAndroid Build Coastguard Worker  * One of possible error code:
283*38e8c45fSAndroid Build Coastguard Worker  * -EBADF           Bad socketfd.
284*38e8c45fSAndroid Build Coastguard Worker  * Other error codes are either provided by -errno of
285*38e8c45fSAndroid Build Coastguard Worker  * [getsockopt()](https://man7.org/linux/man-pages/man2/getsockopt.2.html) or by
286*38e8c45fSAndroid Build Coastguard Worker  * BPF map element deletion sys call, which are set appropriately.
287*38e8c45fSAndroid Build Coastguard Worker  *
288*38e8c45fSAndroid Build Coastguard Worker  * Available since API level 33.
289*38e8c45fSAndroid Build Coastguard Worker  */
290*38e8c45fSAndroid Build Coastguard Worker int android_untag_socket(int sockfd) __INTRODUCED_IN(33);
291*38e8c45fSAndroid Build Coastguard Worker 
292*38e8c45fSAndroid Build Coastguard Worker __END_DECLS
293*38e8c45fSAndroid Build Coastguard Worker 
294*38e8c45fSAndroid Build Coastguard Worker #endif  // ANDROID_MULTINETWORK_H
295*38e8c45fSAndroid Build Coastguard Worker 
296*38e8c45fSAndroid Build Coastguard Worker /** @} */
297