RK3588 4G 共享到以太网

android 12(S)

Posted by LXG on May 19, 2023

网络共享-AOSP

Settings

src/com/android/settings/TetherSettings.java


public class TetherSettings extends RestrictedSettingsFragment {

   private static final String KEY_ENABLE_ETHERNET_TETHERING = "enable_ethernet_tethering";

   private ConnectivityManager mCm;

    @Override
    public boolean onPreferenceTreeClick(Preference preference) {
        if (preference == mUsbTether) {
            if (mUsbTether.isChecked()) {
                startTethering(TETHERING_USB);
            } else {
                mCm.stopTethering(TETHERING_USB);
            }
        } else if (preference == mBluetoothTether) {
            if (mBluetoothTether.isChecked()) {
                startTethering(TETHERING_BLUETOOTH);
            } else {
                mCm.stopTethering(TETHERING_BLUETOOTH);
            }
        } else if (preference == mEthernetTether) {
            if (mEthernetTether.isChecked()) {
                startTethering(TETHERING_ETHERNET);
            } else {
                mCm.stopTethering(TETHERING_ETHERNET);
            }
        }

        return super.onPreferenceTreeClick(preference);
    }

    private void startTethering(int choice) {
        if (choice == TETHERING_BLUETOOTH) {
            // Turn on Bluetooth first.
            BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
            if (adapter.getState() == BluetoothAdapter.STATE_OFF) {
                mBluetoothEnableForTether = true;
                adapter.enable();
                mBluetoothTether.setEnabled(false);
                return;
            }
        }

        mCm.startTethering(choice, true, mStartTetheringCallback, mHandler);
    }

}

ConnectivityManager.java

packages/modules/Connectivity/framework/src/android/net/ConnectivityManager.java

public class ConnectivityManager {

    @SystemApi
    @Deprecated
    @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
    public void startTethering(int type, boolean showProvisioningUi,
            final OnStartTetheringCallback callback, Handler handler) {
        Objects.requireNonNull(callback, "OnStartTetheringCallback cannot be null.");

        final Executor executor = new Executor() {
            @Override
            public void execute(Runnable command) {
                if (handler == null) {
                    command.run();
                } else {
                    handler.post(command);
                }
            }
        };

        final StartTetheringCallback tetheringCallback = new StartTetheringCallback() {
            @Override
            public void onTetheringStarted() {
                callback.onTetheringStarted();
            }

            @Override
            public void onTetheringFailed(final int error) {
                callback.onTetheringFailed();
            }
        };

        final TetheringRequest request = new TetheringRequest.Builder(type)
                .setShouldShowEntitlementUi(showProvisioningUi).build();

        getTetheringManager().startTethering(request, executor, tetheringCallback);
    }

}

TetheringManager

packages/modules/Connectivity/Tethering/common/TetheringLib/src/android/net/TetheringManager.java


public class TetheringManager {

    /**
     * Invalid tethering type.
     * @see #startTethering.
     */
    public static final int TETHERING_INVALID   = -1;

    /**
     * Wifi tethering type.
     * @see #startTethering.
     */
    public static final int TETHERING_WIFI      = 0;

    /**
     * USB tethering type.
     * @see #startTethering.
     */
    public static final int TETHERING_USB       = 1;

    /**
     * Bluetooth tethering type.
     * @see #startTethering.
     */
    public static final int TETHERING_BLUETOOTH = 2;

    /**
     * Wifi P2p tethering type.
     * Wifi P2p tethering is set through events automatically, and don't
     * need to start from #startTethering.
     */
    public static final int TETHERING_WIFI_P2P = 3;

    /**
     * Ncm local tethering type.
     * @see #startTethering(TetheringRequest, Executor, StartTetheringCallback)
     */
    public static final int TETHERING_NCM = 4;

    /**
     * Ethernet tethering type.
     * @see #startTethering(TetheringRequest, Executor, StartTetheringCallback)
     */
    public static final int TETHERING_ETHERNET = 5;

    /**
     * WIGIG tethering type. Use a separate type to prevent
     * conflicts with TETHERING_WIFI
     * This type is only used internally by the tethering module
     * @hide
     */
    public static final int TETHERING_WIGIG = 6;

    @RequiresPermission(anyOf = {
            android.Manifest.permission.TETHER_PRIVILEGED,
            android.Manifest.permission.WRITE_SETTINGS
    })
    public void startTethering(@NonNull final TetheringRequest request,
            @NonNull final Executor executor, @NonNull final StartTetheringCallback callback) {
        final String callerPkg = mContext.getOpPackageName();
        Log.i(TAG, "startTethering caller:" + callerPkg);

        final IIntResultListener listener = new IIntResultListener.Stub() {
            @Override
            public void onResult(final int resultCode) {
                executor.execute(() -> {
                    if (resultCode == TETHER_ERROR_NO_ERROR) {
                        callback.onTetheringStarted();
                    } else {
                        callback.onTetheringFailed(resultCode);
                    }
                });
            }
        };
        getConnector(c -> c.startTethering(request.getParcel(), callerPkg,
                getAttributionTag(), listener));
    }

    /**
     * Asynchronously get the ITetheringConnector to execute some operation.
     *
     * <p>If the connector is already available, the operation will be executed on the caller's
     * thread. Otherwise it will be queued and executed on a worker thread. The operation should be
     * limited to performing oneway binder calls to minimize differences due to threading.
     */
    private void getConnector(ConnectorConsumer consumer) {
        final ITetheringConnector connector;
        synchronized (mConnectorWaitQueue) {
            connector = mConnector;
            if (connector == null) {
                mConnectorWaitQueue.add(consumer);
                return;
            }
        }

        try {
            consumer.onConnectorAvailable(connector);
        } catch (RemoteException e) {
            throw new IllegalStateException(e);
        }
    }

    private interface ConnectorConsumer {
        void onConnectorAvailable(ITetheringConnector connector) throws RemoteException;
    }

}

TetheringService

packages/modules/Connectivity/Tethering/src/com/android/networkstack/tethering/TetheringService.java


public class TetheringService extends Service {

    private TetheringConnector mConnector;

    @Override
    public void onCreate() {
        final TetheringDependencies deps = makeTetheringDependencies();
        // The Tethering object needs a fully functional context to start, so this can't be done
        // in the constructor.
        mConnector = new TetheringConnector(makeTethering(deps), TetheringService.this);
    }

    /**
     * Make a reference to Tethering object.
     */
    @VisibleForTesting
    public Tethering makeTethering(TetheringDependencies deps) {
        return new Tethering(deps);
    }

    @NonNull
    @Override
    public IBinder onBind(Intent intent) {
        return mConnector;
    }

    private static class TetheringConnector extends ITetheringConnector.Stub {
        private final TetheringService mService;
        private final Tethering mTethering;

        @Override
        public void startTethering(TetheringRequestParcel request, String callerPkg,
                String callingAttributionTag, IIntResultListener listener) {
            if (checkAndNotifyCommonError(callerPkg,
                    callingAttributionTag,
                    request.exemptFromEntitlementCheck /* onlyAllowPrivileged */,
                    listener)) {
                return;
            }

            mTethering.startTethering(request, listener);
        }

    }

}

Tethering

packages/modules/Connectivity/Tethering/src/com/android/networkstack/tethering/Tethering.java


public class Tethering {

    private static final String TAG = Tethering.class.getSimpleName();
    private static final boolean DBG = false;
    private static final boolean VDBG = false;

    void startTethering(final TetheringRequestParcel request, final IIntResultListener listener) {
        mHandler.post(() -> {
            final TetheringRequestParcel unfinishedRequest = mActiveTetheringRequests.get(
                    request.tetheringType);
            // If tethering is already enabled with a different request,
            // disable before re-enabling.
            if (unfinishedRequest != null
                    && !TetheringUtils.isTetheringRequestEquals(unfinishedRequest, request)) {
                enableTetheringInternal(request.tetheringType, false /* disabled */, null);
                mEntitlementMgr.stopProvisioningIfNeeded(request.tetheringType);
            }
            mActiveTetheringRequests.put(request.tetheringType, request);

            if (request.exemptFromEntitlementCheck) {
                mEntitlementMgr.setExemptedDownstreamType(request.tetheringType);
            } else {
                mEntitlementMgr.startProvisioningIfNeeded(request.tetheringType,
                        request.showProvisioningUi);
            }
            enableTetheringInternal(request.tetheringType, true /* enabled */, listener);
        });
    }

    /**
     * Enables or disables tethering for the given type. If provisioning is required, it will
     * schedule provisioning rechecks for the specified interface.
     */
    private void enableTetheringInternal(int type, boolean enable,
            final IIntResultListener listener) {
        int result = TETHER_ERROR_NO_ERROR;
        switch (type) {
            case TETHERING_WIFI:
                result = setWifiTethering(enable);
                break;
            case TETHERING_USB:
                result = setUsbTethering(enable);
                break;
            case TETHERING_BLUETOOTH:
                setBluetoothTethering(enable, listener);
                break;
            case TETHERING_NCM:
                result = setNcmTethering(enable);
                break;
            case TETHERING_ETHERNET:
                result = setEthernetTethering(enable);
                break;
            default:
                Log.w(TAG, "Invalid tether type.");
                result = TETHER_ERROR_UNKNOWN_TYPE;
        }

        // The result of Bluetooth tethering will be sent by #setBluetoothTethering.
        if (type != TETHERING_BLUETOOTH) {
            sendTetherResult(listener, result, type);
        }
    }

    private int setEthernetTethering(final boolean enable) {
        final EthernetManager em = (EthernetManager) mContext.getSystemService(
                Context.ETHERNET_SERVICE);
        if (enable) {
            if (mEthernetCallback != null) {
                Log.d(TAG, "Ethernet tethering already started");
                return TETHER_ERROR_NO_ERROR;
            }

            mEthernetCallback = new EthernetCallback();
            mEthernetIfaceRequest = em.requestTetheredInterface(mExecutor, mEthernetCallback);
        } else {
            stopEthernetTethering();
        }
        return TETHER_ERROR_NO_ERROR;
    }

}

EthernetManager

frameworks/base/core/java/android/net/EthernetManager.java


@SystemService(Context.ETHERNET_SERVICE)
public class EthernetManager {
    private static final String TAG = "EthernetManager";

    /**
     * Callback for {@link #requestTetheredInterface(TetheredInterfaceCallback)}.
     */
    public interface TetheredInterfaceCallback {
        /**
         * Called when the tethered interface is available.
         * @param iface The name of the interface.
         */
        void onAvailable(@NonNull String iface);

        /**
         * Called when the tethered interface is now unavailable.
         */
        void onUnavailable();
    }

    /**
     * Request a tethered interface in tethering mode.
     *
     * <p>When this method is called and there is at least one ethernet interface available, the
     * system will designate one to act as a tethered interface. If there is already a tethered
     * interface, the existing interface will be used.
     * @param callback A callback to be called once the request has been fulfilled.
     */
    @RequiresPermission(anyOf = {
            android.Manifest.permission.NETWORK_STACK,
            android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK
    })
    @NonNull
    public TetheredInterfaceRequest requestTetheredInterface(@NonNull final Executor executor,
            @NonNull final TetheredInterfaceCallback callback) {
        Objects.requireNonNull(callback, "Callback must be non-null");
        Objects.requireNonNull(executor, "Executor must be non-null");
        final ITetheredInterfaceCallback cbInternal = new ITetheredInterfaceCallback.Stub() {
            @Override
            public void onAvailable(String iface) {
                executor.execute(() -> callback.onAvailable(iface));
            }

            @Override
            public void onUnavailable() {
                executor.execute(() -> callback.onUnavailable());
            }
        };

        try {
            mService.requestTetheredInterface(cbInternal);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        return new TetheredInterfaceRequest(mService, cbInternal);
    }

}

EthernetServiceImpl

frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetServiceImpl.java


public class EthernetServiceImpl extends IEthernetManager.Stub {
    private static final String TAG = "EthernetServiceImpl";

    private EthernetTracker mTracker;

    public void start() {
        Log.i(TAG, "Starting Ethernet service");

        HandlerThread handlerThread = new HandlerThread("EthernetServiceThread");
        handlerThread.start();
        mHandler = new Handler(handlerThread.getLooper());

        mTracker = new EthernetTracker(mContext, mHandler);
        mTracker.start();

        mStarted.set(true);
    }

    @Override
    public void requestTetheredInterface(ITetheredInterfaceCallback callback) {
        NetworkStack.checkNetworkStackPermissionOr(mContext,
                android.Manifest.permission.NETWORK_SETTINGS);
        mTracker.requestTetheredInterface(callback);
    }

}

EthernetTracker

frameworks/opt/net/ethernet/java/com/android/server/ethernet/EthernetTracker.java


final class EthernetTracker {
    private static final int INTERFACE_MODE_CLIENT = 1;
    private static final int INTERFACE_MODE_SERVER = 2;

    // Used only on the handler thread
    private String mDefaultInterface;
    private int mDefaultInterfaceMode = INTERFACE_MODE_CLIENT;

    private final INetworkManagementService mNMService;
    private final INetd mNetd;

    private void maybeTrackInterface(String iface) {
        if (!iface.matches(mIfaceMatch)) {
            return;
        }

        // If we don't already track this interface, and if this interface matches
        // our regex, start tracking it.
        if (mFactory.hasInterface(iface) || iface.equals(mDefaultInterface)) {
            if (DBG) Log.w(TAG, "Ignoring already-tracked interface " + iface);
            return;
        }
        if (DBG) Log.i(TAG, "maybeTrackInterface: " + iface);

        // TODO: avoid making an interface default if it has configured NetworkCapabilities.
        if (mDefaultInterface == null) {
            mDefaultInterface = iface;
        }

        if (mIpConfigForDefaultInterface != null) {
            updateIpConfiguration(iface, mIpConfigForDefaultInterface);
            mIpConfigForDefaultInterface = null;
        }

        addInterface(iface);
    }

    public void requestTetheredInterface(ITetheredInterfaceCallback callback) {
        mHandler.post(() -> {
            if (!mTetheredInterfaceRequests.register(callback)) {
                // Remote process has already died
                return;
            }
            if (mDefaultInterfaceMode == INTERFACE_MODE_SERVER) {
                if (mTetheredInterfaceWasAvailable) {
                    notifyTetheredInterfaceAvailable(callback, mDefaultInterface);
                }
                return;
            }

            setDefaultInterfaceMode(INTERFACE_MODE_SERVER);
        });
    }


    private void setDefaultInterfaceMode(int mode) {
        Log.d(TAG, "Setting default interface mode to " + mode);
        mDefaultInterfaceMode = mode;
        if (mDefaultInterface != null) {
            removeInterface(mDefaultInterface);
            addInterface(mDefaultInterface);
        }
    }

    private void addInterface(String iface) {
        InterfaceConfiguration config = null;
        // Bring up the interface so we get link status indications.
        try {
            NetworkStack.checkNetworkStackPermission(mContext);
            NetdUtils.setInterfaceUp(mNetd, iface);
            config = mNMService.getInterfaceConfig(iface);
        } catch (RemoteException | IllegalStateException e) {
            // Either the system is crashing or the interface has disappeared. Just ignore the
            // error; we haven't modified any state because we only do that if our calls succeed.
            Log.e(TAG, "Error upping interface " + iface, e);
        }

        if (config == null) {
            Log.e(TAG, "Null interface config for " + iface + ". Bailing out.");
            return;
        }

        final String hwAddress = config.getHardwareAddress();

        NetworkCapabilities nc = mNetworkCapabilities.get(iface);
        if (nc == null) {
            // Try to resolve using mac address
            nc = mNetworkCapabilities.get(hwAddress);
            if (nc == null) {
                final boolean isTestIface = iface.matches(TEST_IFACE_REGEXP);
                nc = createDefaultNetworkCapabilities(isTestIface);
            }
        }

        final int mode = getInterfaceMode(iface);
        if (mode == INTERFACE_MODE_CLIENT) {
            IpConfiguration ipConfiguration = mIpConfigurations.get(iface);
            if (ipConfiguration == null) {
                ipConfiguration = createDefaultIpConfiguration();
            }

            Log.d(TAG, "Tracking interface in client mode: " + iface);
            mFactory.addInterface(iface, hwAddress, nc, ipConfiguration);
        } else {
            maybeUpdateServerModeInterfaceState(iface, true);
        }

        // Note: if the interface already has link (e.g., if we crashed and got
        // restarted while it was running), we need to fake a link up notification so we
        // start configuring it.
        if (config.hasFlag("running")) {
            updateInterfaceState(iface, true);
        }
    }

    private void maybeUpdateServerModeInterfaceState(String iface, boolean available) {
        if (available == mTetheredInterfaceWasAvailable || !iface.equals(mDefaultInterface)) return;

        Log.d(TAG, (available ? "Tracking" : "No longer tracking")
                + " interface in server mode: " + iface);

        final int pendingCbs = mTetheredInterfaceRequests.beginBroadcast();
        for (int i = 0; i < pendingCbs; i++) {
            ITetheredInterfaceCallback item = mTetheredInterfaceRequests.getBroadcastItem(i);
            if (available) {
                notifyTetheredInterfaceAvailable(item, iface);
            } else {
                notifyTetheredInterfaceUnavailable(item);
            }
        }
        mTetheredInterfaceRequests.finishBroadcast();
        mTetheredInterfaceWasAvailable = available;
    }

}

system log


2023-05-20 10:55:07.927   943-943   LXG                     com.android.settings                 E  =====startTethering====5
2023-05-20 10:55:07.927   943-943   TetheringManager        com.android.settings                 I  startTethering caller:com.android.settings
2023-05-20 10:55:07.929   617-766   EthernetTracker         system_process                       D  Setting default interface mode to 2
2023-05-20 10:55:07.977   617-766   EthernetTracker         system_process                       D  Tracking interface in server mode: eth0

2023-05-20 10:55:07.977   617-1102  Tethering               system_process                       I  adding IpServer for: eth0
2023-05-20 10:55:07.979   617-1102  Tethering               system_process                       I  [BpfCoordinator] Monitoring started

2023-05-20 10:55:07.992   943-943   TetheringSettings       com.android.settings                 D  onTetheredInterfacesChanged() interfaces : [eth0]

2023-05-20 10:55:07.994   425-425   netd                    pid-425                              I  ipfwdEnableForwarding(Tethering) <0.30ms>
2023-05-20 10:55:07.994   425-425   TetherController        pid-425                              D  Starting tethering services
2023-05-20 10:55:07.995   425-425   TetherController        pid-425                              D  Tethering services running
2023-05-20 10:55:07.997   617-1102  Tethering               system_process                       E  ERROR getIOffloadConfig error java.util.NoSuchElementException
2023-05-20 10:55:07.997   617-1102  Tethering               system_process                       E  [OffloadHardwareInterface] ERROR Could not find IOffloadConfig service
2023-05-20 10:55:07.997   617-1102  Tethering               system_process                       I  [OffloadController] tethering offload config not supported
2023-05-20 10:55:08.001   617-1102  Tethering               system_process                       I  [BpfCoordinator] Polling started
2023-05-20 10:55:08.005   617-1102  Tethering               system_process                       I  Looking for default routes on: {InterfaceName: usb0 LinkAddresses: [ 10.131.62.239/8 ] DnsAddresses: [ /183.230.126.224,/183.230.126.225 ] Domains: null MTU: 1500 TcpBufferSizes: 524288,1048576,2097152,262144,524288,1048576 Routes: [ 0.0.0.0/0 -> 10.131.62.16 usb0 mtu 1500,10.0.0.0/8 -> 0.0.0.0 usb0 mtu 0 ]}
2023-05-20 10:55:08.006   617-1102  Tethering               system_process                       I  Found upstream interface(s): [usb0]
2023-05-20 10:55:08.011   617-1102  Tethering               system_process                       I  Looking for default routes on: {InterfaceName: usb0 LinkAddresses: [ 10.131.62.239/8 ] DnsAddresses: [ /183.230.126.224,/183.230.126.225 ] Domains: null MTU: 1500 TcpBufferSizes: 524288,1048576,2097152,262144,524288,1048576 Routes: [ 0.0.0.0/0 -> 10.131.62.16 usb0 mtu 1500,10.0.0.0/8 -> 0.0.0.0 usb0 mtu 0 ]}
2023-05-20 10:55:08.011   617-1102  Tethering               system_process                       I  Found upstream interface(s): [usb0]
2023-05-20 10:55:08.015   617-1102  Tethering               system_process                       E  [api31.BpfCoordinatorShimImpl] ERROR Could not attach program: java.io.IOException: tc filter add dev (4[eth0]) ingress prio PRIO_TETHER6 protocol ipv6 failure: java.io.IOException: retrieveProgram failed Permission denied
2023-05-20 10:55:08.016   617-1102  Tethering               system_process                       E  [api31.BpfCoordinatorShimImpl] ERROR Could not attach program: java.io.IOException: tc filter add dev (13[usb0]) ingress prio PRIO_TETHER6 protocol ipv6 failure: java.io.IOException: retrieveProgram failed Permission denied
2023-05-20 10:55:13.004   617-1102  Tethering               system_process                       E  [api31.BpfCoordinatorShimImpl] ERROR Fail to fetch tethering stats from BPF map: : getNextMapKey failed: EBADF (Bad file descriptor)

netd log


2023-05-20 10:55:07.971   425-492   netd                    pid-425                              I  interfaceSetEnableIPv6(eth0, false) <0.26ms>
2023-05-20 10:55:07.972   425-492   netd                    pid-425                              I  interfaceClearAddrs(eth0) <0.44ms>
2023-05-20 10:55:07.973   425-492   netd                    pid-425                              I  setProcSysNet(6, 1, eth0, accept_ra, 2) <0.09ms>
2023-05-20 10:55:07.974   425-492   netd                    pid-425                              I  interfaceGetCfg(eth0) -> {InterfaceConfigurationParcel{ifName: eth0, hwAddr: e6:5a:a0:fd:94:df, ipv4Addr: 0.0.0.0, prefixLength: 0, flags: [up, broadcast, running, multicast]}} <0.30ms>
2023-05-20 10:55:07.975   425-492   netd                    pid-425                              I  interfaceSetCfg(InterfaceConfigurationParcel{ifName: eth0, hwAddr: e6:5a:a0:fd:94:df, ipv4Addr: 0.0.0.0, prefixLength: 0, flags: [broadcast, running, multicast, up]}) <0.32ms>
2023-05-20 10:55:07.975   425-492   netd                    pid-425                              I  interfaceGetCfg(eth0) -> {InterfaceConfigurationParcel{ifName: eth0, hwAddr: e6:5a:a0:fd:94:df, ipv4Addr: 0.0.0.0, prefixLength: 0, flags: [up, broadcast, running, multicast]}} <0.12ms>
2023-05-20 10:55:07.980   425-492   netd                    pid-425                              I  interfaceSetCfg(InterfaceConfigurationParcel{ifName: eth0, hwAddr: , ipv4Addr: 192.168.21.74, prefixLength: 24, flags: []}) <0.38ms>
2023-05-20 10:55:07.984   425-492   netd                    pid-425                              I  tetherInterfaceAdd(eth0) <0.46ms>
2023-05-20 10:55:07.988   425-492   netd                    pid-425                              I  networkAddInterface(99, eth0) <3.36ms>
2023-05-20 10:55:07.989   425-492   netd                    pid-425                              I  networkAddRoute(99, eth0, 192.168.21.0/24, ) <0.15ms>
2023-05-20 10:55:07.989   425-492   netd                    pid-425                              I  networkAddRoute(99, eth0, fe80::/64, ) <0.22ms>
2023-05-20 10:55:07.994   425-425   netd                    pid-425                              I  ipfwdEnableForwarding(Tethering) <0.30ms>
2023-05-20 10:55:07.995   425-425   netd                    pid-425                              I  tetherStartWithConfiguration(TetherConfigParcel{usingLegacyDnsProxy: true, dhcpRanges: []}) <1.02ms>
2023-05-20 10:55:08.006   425-2286  netd                    pid-425                              I  tetherDnsSet(100, [183.230.126.224, 183.230.126.225]) <0.08ms>
2023-05-20 10:55:08.011   425-2286  netd                    pid-425                              I  tetherDnsSet(100, [183.230.126.224, 183.230.126.225]) <0.27ms>
2023-05-20 10:55:08.018   425-2286  netd                    pid-425                              I  tetherAddForward(eth0, usb0) <2.40ms>
2023-05-20 10:55:08.018   425-2286  netd                    pid-425                              I  ipfwdAddInterfaceForward(eth0, usb0) <0.09ms>
2023-05-20 10:55:08.020   425-492   netd                    pid-425                              I  trafficSwapActiveStatsMap() <24.22ms>
2023-05-20 10:55:08.021   425-492   netd                    pid-425                              I  tetherGetStats() -> {[TetherStatsParcel{iface: usb0, rxBytes: 0, rxPackets: 0, txBytes: 0, txPackets: 0, ifIndex: 0}]} <0.77ms>
2023-05-20 10:55:08.043   425-492   netd                    pid-425                              I  trafficSwapActiveStatsMap() <20.84ms>
2023-05-20 10:55:08.044   425-492   netd                    pid-425                              I  tetherGetStats() -> {[TetherStatsParcel{iface: usb0, rxBytes: 0, rxPackets: 0, txBytes: 0, txPackets: 0, ifIndex: 0}]} <0.48ms>
2023-05-20 10:55:08.047   425-492   netd                    pid-425                              I  bandwidthRemoveInterfaceQuota(usb0) <0.83ms>
2023-05-20 10:55:08.047   425-2286  netd                    pid-425                              I  bandwidthSetInterfaceQuota(usb0, 9223372036854775807) <0.46ms>
2023-05-20 10:55:08.049   425-2286  netd                    pid-425                              I  bandwidthRemoveInterfaceQuota(usb0) <0.47ms>
2023-05-20 10:55:08.049   425-492   netd                    pid-425                              I  bandwidthSetInterfaceQuota(usb0, 9223372036854775807) <0.43ms>

ifconfig


rk3588_s:/ $ ifconfig
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0 
          inet6 addr: ::1/128 Scope: Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:0 TX bytes:0 

dummy0    Link encap:Ethernet  HWaddr f2:fa:48:73:48:ae
          inet6 addr: fe80::f0fa:48ff:fe73:48ae/64 Scope: Link
          UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:4 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:0 TX bytes:280 

eth0      Link encap:Ethernet  HWaddr e6:5a:a0:fd:94:df  Driver rk_gmac-dwmac
          inet addr:192.168.170.174  Bcast:192.168.170.255  Mask:255.255.255.0 
          inet6 addr: fe80::5035:e8e6:2b97:908b/64 Scope: Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:21 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:1640 TX bytes:3422 
          Interrupt:74 

eth1      Link encap:Ethernet  HWaddr 8a:25:6b:9f:ff:a9  Driver r8168
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:0 TX bytes:0 
          Interrupt:173 Base address:0xf000 

usb0      Link encap:Ethernet  HWaddr ae:0c:29:a3:9b:6d  Driver cdc_ether
          inet addr:10.178.107.143  Bcast:10.255.255.255  Mask:255.0.0.0 
          inet6 addr: fe80::ac0c:29ff:fea3:9b6d/64 Scope: Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:173 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:220 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:66620 TX bytes:26582

dumpsys ethernet


rk3588_s:/ $ dumpsys ethernet
Current Ethernet state: 
  EthernetTracker
  Ethernet interface name filter: eth\d
  Default interface: eth0
  Default interface mode: 2
  Tethered interface requests: 1
  Listeners: 1
  IP Configurations:
  
  Network Capabilities:
  
  providerId=1, ScoreFilter=Score(70 ; Policies : 0), Filter=[ Transports: ETHERNET Capabilities: NOT_METERED&INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN&NOT_ROAMING&NOT_CONGESTED&NOT_SUSPENDED&NOT_VCN_MANAGED], requests=11
    {NetworkRequest [ REQUEST id=7, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VCN_MANAGED Uid: 1000 RequestorUid: 1000 RequestorPkg: android] ], requested=false}
    {NetworkRequest [ REQUEST id=14, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VCN_MANAGED Uid: 1000 RequestorUid: 1000 RequestorPkg: android] ], requested=false}
    {NetworkRequest [ REQUEST id=27, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VCN_MANAGED Uid: 1001 RequestorUid: 1001 RequestorPkg: com.android.phone] ], requested=false}
    {NetworkRequest [ REQUEST id=1, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN&NOT_VCN_MANAGED RequestorUid: 1000 RequestorPkg: android] ], requested=false}
    {NetworkRequest [ REQUEST id=21, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VCN_MANAGED Uid: 10048 RequestorUid: 10048 RequestorPkg: com.android.systemui] ], requested=false}
    {NetworkRequest [ REQUEST id=16, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VCN_MANAGED Uid: 1000 RequestorUid: 1000 RequestorPkg: com.android.networkstack.inprocess] ], requested=false}
    {NetworkRequest [ REQUEST id=24, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VCN_MANAGED Uid: 10048 RequestorUid: 10048 RequestorPkg: com.android.systemui] ], requested=false}
    {NetworkRequest [ REQUEST id=31, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VCN_MANAGED Uid: 1000 RequestorUid: 1000 RequestorPkg: android] ], requested=false}
    {NetworkRequest [ REQUEST id=32, [ Capabilities: NOT_RESTRICTED&TRUSTED&NOT_VPN&NOT_VCN_MANAGED Uid: 1000 RequestorUid: 1000 RequestorPkg: com.wif.baseservice] ], requested=true}
    {NetworkRequest [ REQUEST id=37, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VCN_MANAGED Uid: 10044 RequestorUid: 1000 RequestorPkg: android] ], requested=true}
    {NetworkRequest [ REQUEST id=39, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VCN_MANAGED Uid: 10012 RequestorUid: 1000 RequestorPkg: android] ], requested=true}
  EthernetNetworkFactory
  Tracking interfaces:
    eth1:NetworkInterfaceState{ refCount: 0, iface: eth1, up: false, hwAddress: 8a:25:6b:9f:ff:a9, networkCapabilities: [ Transports: ETHERNET Capabilities: NOT_METERED&INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN&NOT_ROAMING&NOT_CONGESTED&NOT_SUSPENDED&NOT_VCN_MANAGED LinkUpBandwidth>=100000Kbps LinkDnBandwidth>=100000Kbps], networkAgent: null, score: 0, ipClient: android.net.ip.IIpClient$Stub$Proxy@8c6a170,linkProperties: {LinkAddresses: [ ] DnsAddresses: [ ] Domains: null MTU: 0 Routes: [ ]}}
      IpClient logs have moved to dumpsys network_stack
Handler:
  EthernetServiceImplHandler (android.os.Handler) {e630ce9} @ 144631
  EthernetServiceImpl  Looper (EthernetServiceThread, tid 126) {351ad6e}
  EthernetServiceImpl    (Total messages: 0, polling=true, quitting=false)

dumpsys tethering


rk3588_s:/ $ dumpsys tethering
Tethering:
  Configuration:
    activeDataSubId: 1
    tetherableUsbRegexs: [usb\d, rndis\d]
    tetherableWifiRegexs: [wlan\d, softap\d, ap_br_wlan\d, ap_br_softap\d]
    tetherableWifiP2pRegexs: [p2p-p2p\d-.*, p2p-wlan\d-.*, p2p-dev-wlan\d, p2p\d]
    tetherableBluetoothRegexs: [bt-pan]
    tetherableNcmRegexs: []
    isDunRequired: false
    chooseUpstreamAutomatically: true
    legacyPreredUpstreamIfaceTypes: [9, 0, 5]
    legacyDhcpRanges: [192.168.42.2, 192.168.42.254, 192.168.43.2, 192.168.43.254, 192.168.44.2, 192.168.44.254, 192.168.45.2, 192.168.45.254, 192.168.46.2, 192.168.46.254, 192.168.47.2, 192.168.47.254, 192.168.48.2, 192.168.48.254, 192.168.49.2, 192.168.49.254]
    defaultIPv4DNS: [8.8.4.4, 8.8.8.8]
    offloadPollInterval: 5000
    provisioningApp: []
    provisioningAppNoUi: 
    enableBpfOffload: true
    enableLegacyDhcpServer: false
    enableWifiP2pDedicatedIp: false
    mEnableSelectAllPrefixRange: true
    mUsbTetheringFunction: RNDIS
  Entitlement:
    isCellularUpstreamPermitted: true
    Type: TETHERING UNKNOWN TYPE (5), Value: empty
    Exempted: []
  Tether state:
    eth0 - TetheredState - lastError = 0
    Upstream wanted: true
    Current upstream interface(s): [usb0]
  Hardware offload:
    Offload HALs not started
    Offload Control HAL version: None
    Current upstream: null
    Exempt prefixes: []
    NAT timeout update callbacks received during the last offload session: 0
    NAT timeout update netlink errors during the last offload session: 0
  BPF offload:
    mIsBpfEnabled: true
    Polling started
    Stats provider registered
    Upstream quota: {usb0=9223372036854775807}
    Polling interval: 5000 ms
    Bpf shim: mBpfDownstream6Map{OK}, mBpfUpstream6Map{OK}, mBpfDownstream4Map{OK}, mBpfUpstream4Map{OK}, mBpfStatsMap{OK}, mBpfLimitMap{OK}, mBpfDevMap{OK}
    Forwarding stats:
      <empty>
    BPF stats:
      Error dumping BPF stats map: android.system.ErrnoException: getNextMapKey failed: EBADF (Bad file descriptor)
    
    Forwarding rules:
      Error dumping IPv6 upstream map: android.system.ErrnoException: getNextMapKey failed: EBADF (Bad file descriptor)
      No IPv6 rules
      IPv4 Upstream: proto [inDstMac] iif(iface) src -> nat -> dst [outDstMac] age
        Error dumping IPv4 map: android.system.ErrnoException: getNextMapKey failed: EBADF (Bad file descriptor)
      
      Device map:
        Error dumping dev map: android.system.ErrnoException: getNextMapKey failed: EBADF (Bad file descriptor)
    Client Information:
      {name=eth0 state=TetheredState={/192.168.170.93=downstream: 4 (e6:5a:a0:fd:94:df), client: /192.168.170.93 (46:a0:74:82:6f:12)}}
    IPv4 Upstream Indices:
      <empty>
    
    Forwarding counters:
      Error dumping counter map: android.system.ErrnoException: getNextMapKey failed: EBADF (Bad file descriptor)
  Private address coordinator:
    mTetheringPrefixes:
      192.168.0.0/16
      172.16.0.0/12
      10.0.0.0/8
    mUpstreamPrefixMap:
      100 - [10.0.0.0/8]
    mDownstreams:
      5 - 192.168.170.174/24
    mCachedAddresses:
      2 - 192.168.44.1/24
      3 - 192.168.49.1/24
      5 - 192.168.170.174/24