1 /**
2  * Copyright (c) 2022, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.net.connectivity.aidl;
18 
19 interface ConnectivityNative {
20     /**
21      * Blocks a port from being assigned during bind(). The caller is responsible for updating
22      * /proc/sys/net/ipv4/ip_local_port_range with the port being blocked so that calls to connect()
23      * will not automatically assign one of the blocked ports.
24      * Will return success even if port was already blocked.
25      *
26      * @param port Int corresponding to port number.
27      *
28      * @throws IllegalArgumentException if the port is invalid.
29      * @throws SecurityException if the UID of the client doesn't have network stack permission.
30      * @throws ServiceSpecificException in case of failure, with an error code corresponding to the
31      *         unix errno.
32      */
blockPortForBind(in int port)33     void blockPortForBind(in int port);
34 
35     /**
36      * Unblocks a port that has previously been blocked.
37      * Will return success even if port was already unblocked.
38      *
39      * @param port Int corresponding to port number.
40      *
41      * @throws IllegalArgumentException if the port is invalid.
42      * @throws SecurityException if the UID of the client doesn't have network stack permission.
43      * @throws ServiceSpecificException in case of failure, with an error code corresponding to the
44      *         unix errno.
45      */
unblockPortForBind(in int port)46     void unblockPortForBind(in int port);
47 
48     /**
49      * Unblocks all ports that have previously been blocked.
50      */
unblockAllPortsForBind()51     void unblockAllPortsForBind();
52 
53     /**
54      * Gets the list of ports that have been blocked.
55      *
56      * @return List of blocked ports.
57      */
getPortsBlockedForBind()58     int[] getPortsBlockedForBind();
59 }