Migrate NetdUtils from networkAddRoute to networkAddRouteParcel.
This will allow us to deprecate networkAddRoute. Bug:412629841 Test: atest TetheringTests Flag: EXEMPT Using device config kill-switch Change-Id: I20e988f760b8ad22b51effdc1f0e204763c6e240
This commit is contained in:
parent
169a584691
commit
98e5827ccc
2 changed files with 184 additions and 79 deletions
|
|
@ -176,27 +176,27 @@ public class NetdUtils {
|
|||
|
||||
/** Add |routes| to the given network. */
|
||||
public static void addRoutesToNetwork(final INetd netd, int netId, final String iface,
|
||||
final List<RouteInfo> routes) {
|
||||
final List<RouteInfo> routes, final boolean useRouteParcel) {
|
||||
|
||||
for (RouteInfo route : routes) {
|
||||
if (!route.isDefaultRoute()) {
|
||||
modifyRoute(netd, ModifyOperation.ADD, netId, route);
|
||||
modifyRoute(netd, ModifyOperation.ADD, netId, route, useRouteParcel);
|
||||
}
|
||||
}
|
||||
|
||||
// IPv6 link local should be activated always.
|
||||
modifyRoute(netd, ModifyOperation.ADD, netId,
|
||||
new RouteInfo(new IpPrefix("fe80::/64"), null, iface, RTN_UNICAST));
|
||||
new RouteInfo(new IpPrefix("fe80::/64"), null, iface, RTN_UNICAST), useRouteParcel);
|
||||
}
|
||||
|
||||
/** Remove routes from the given network. */
|
||||
public static int removeRoutesFromNetwork(final INetd netd, int netId,
|
||||
final List<RouteInfo> routes) {
|
||||
final List<RouteInfo> routes, final boolean useRouteParcel) {
|
||||
int failures = 0;
|
||||
|
||||
for (RouteInfo route : routes) {
|
||||
try {
|
||||
modifyRoute(netd, ModifyOperation.REMOVE, netId, route);
|
||||
modifyRoute(netd, ModifyOperation.REMOVE, netId, route, useRouteParcel);
|
||||
} catch (IllegalStateException e) {
|
||||
failures++;
|
||||
}
|
||||
|
|
@ -231,18 +231,26 @@ public class NetdUtils {
|
|||
|
||||
/** Add or remove |route|. */
|
||||
public static void modifyRoute(final INetd netd, final ModifyOperation op, final int netId,
|
||||
final RouteInfo route) {
|
||||
final String ifName = route.getInterface();
|
||||
final String dst = route.getDestination().toString();
|
||||
final String nextHop = findNextHop(route);
|
||||
|
||||
final RouteInfo route, final boolean useRouteParcel) {
|
||||
try {
|
||||
switch(op) {
|
||||
case ADD:
|
||||
netd.networkAddRoute(netId, ifName, dst, nextHop);
|
||||
if (useRouteParcel) {
|
||||
RouteInfoParcel routeParcel = NetdUtils.toRouteInfoParcel(route);
|
||||
netd.networkAddRouteParcel(netId, routeParcel);
|
||||
} else {
|
||||
netd.networkAddRoute(netId, route.getInterface(),
|
||||
route.getDestination().toString(), findNextHop(route));
|
||||
}
|
||||
break;
|
||||
case REMOVE:
|
||||
netd.networkRemoveRoute(netId, ifName, dst, nextHop);
|
||||
if (useRouteParcel) {
|
||||
RouteInfoParcel routeParcel = NetdUtils.toRouteInfoParcel(route);
|
||||
netd.networkRemoveRouteParcel(netId, routeParcel);
|
||||
} else {
|
||||
netd.networkRemoveRoute(netId, route.getInterface(),
|
||||
route.getDestination().toString(), findNextHop(route));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unsupported modify operation:" + op);
|
||||
|
|
@ -256,31 +264,10 @@ public class NetdUtils {
|
|||
* Convert a RouteInfo into a RouteInfoParcel.
|
||||
*/
|
||||
public static RouteInfoParcel toRouteInfoParcel(RouteInfo route) {
|
||||
final String nextHop;
|
||||
|
||||
switch (route.getType()) {
|
||||
case RouteInfo.RTN_UNICAST:
|
||||
if (route.hasGateway()) {
|
||||
nextHop = route.getGateway().getHostAddress();
|
||||
} else {
|
||||
nextHop = INetd.NEXTHOP_NONE;
|
||||
}
|
||||
break;
|
||||
case RouteInfo.RTN_UNREACHABLE:
|
||||
nextHop = INetd.NEXTHOP_UNREACHABLE;
|
||||
break;
|
||||
case RouteInfo.RTN_THROW:
|
||||
nextHop = INetd.NEXTHOP_THROW;
|
||||
break;
|
||||
default:
|
||||
nextHop = INetd.NEXTHOP_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
final RouteInfoParcel rip = new RouteInfoParcel();
|
||||
rip.ifName = route.getInterface();
|
||||
rip.destination = route.getDestination().toString();
|
||||
rip.nextHop = nextHop;
|
||||
rip.nextHop = findNextHop(route);
|
||||
rip.mtu = route.getMtu();
|
||||
|
||||
return rip;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (C) 2025 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.net.module.util;
|
||||
|
||||
/**
|
||||
* Collection of flag constants shared across modules.
|
||||
* @hide
|
||||
*/
|
||||
public class ConnectivityCommonFlags {
|
||||
|
||||
/**
|
||||
* A feature flag to use the network{Add,Remove}RouteParcel netd IPCs instead of the legacy
|
||||
* network{Add,Remote}Route IPCs. This flag is used by both the connectivity and wifi modules.
|
||||
*/
|
||||
public static final String USE_ROUTE_PARCEL_IPCS = "use_route_parcel_ipcs";
|
||||
}
|
||||
Loading…
Reference in a new issue