The Android operating system contains standard Linux networking utilities such as
ifconfig
,ip
, andip6tables
. These utilities reside on the system image and enable configuration of the entire Linux networking stack. On devices running Android 7.x and earlier, vendor code is allowed to call these binaries directly, which presents the following problems:
- Because network utilities are updated in the system image, they do not provide a stable implementation.
- The scope of the networking utilities is so broad it is difficult to evolve the system image while guaranteeing predictable behaviour.
Android 系统中包含了标准的 Linux 网络工具,比如 ipconfig
,ip
和 ip6tables
。这些实用程序保留在系统映像上,并且启用整个 Linux 网络栈的配置。在运行 Android 7.x 或者更早期的版本的设备上,供应商代码允许直接调用这些二进制文件,这就出现了以下的几个问题:
On devices running Android 8.0, the vendor partition can remain the same while the system partition receives an update. To achieve this, Android 8.0 provides the ability to define a stable, versioned interface while also using SELinux restrictions to keep the interdependency of vendor and system image to a known good set.
在运行 Android 8.0 的设备上,当系统分区有所更新时,供应商分区可以保持不变。为了保证这样的情况,Android 8.0 提供了一个稳定定义的能力,在版本化接口的同时,也使用 SELinux 限制将供应商和系统映像的相互依赖关系保持到一个已知的良好的集合中。
Vendors can use the platform-provided network configuration utilities to configure the Linux networking stack, but these utilities do not yet include a HIDL interface wrapper. To define such an interface, Android 8.0 includes the
netutils-wrapper-1.0
tool.
供应商可以使用平台所提供的网络配置工具去配置 Linux 的网络栈,但是这些工具还没包含到 HIDL 接口封装中。为了定义这样的接口,Android 8.0 引入了 netutils-wrapper-1.0
工具。
(Netutils wrapper)
Thenetutils
wrapper utility provides a subset of the Linux network stack configuration that is not affected by system partition updates. Android 8.0 contains version 1.0 of the wrappers, which allows you to pass the same arguments as the wrapped utilities, installed in the system partition at/system/bin
as follows:
netutils
包装的实用工具提供了一个不受系统分区更新所影响的 Linux 网络栈配置工具子集。Android 8.0 中包含了 1.0 版本的封装,它允许您传递与封装工具相同的参数,安装在 /system/bin
的系统分区中如下:
u:object_r:system_file:s0 /system/bin/ip-wrapper-1.0 -> netutils-wrapper-1.0
u:object_r:system_file:s0 /system/bin/ip6tables-wrapper-1.0 -> netutils-wrapper-1.0
u:object_r:system_file:s0 /system/bin/iptables-wrapper-1.0 -> netutils-wrapper-1.0
u:object_r:system_file:s0 /system/bin/ndc-wrapper-1.0 -> netutils-wrapper-1.0
u:object_r:netutils_wrapper_exec:s0 /system/bin/netutils-wrapper-1.0
u:object_r:system_file:s0 /system/bin/tc-wrapper-1.0 -> netutils-wrapper-1.0
Symlinks show the networking utilities wrapped by the
netutils
wrapper, which include:
符号连接表示了由封装器 netutils
所封装的网络工具,包括:
ip
iptables
ip6tables
ndc
tc
To use these utilities in Android 8.0 and later, vendor implementations must adhere to the following rules:
- Vendor processes must not execute
/system/bin/netutils-wrapper-1.0
directly; attempts to do so will result in error.- All utilities wrapped by
netutils-wrapper-1.0
must be launched using their symlinks. For example, change the vendor code that did this before (/system/bin/ip
) to/system/bin/ip-wrapper-1.0
.- Executing the wrappers without domain transition is prohibited in platform SELinux policy. This rule must not be changed and is tested against in the Android Compatibility Test Suite (CTS).
- Executing the utilities directly (e.g.,
/system/bin/ip
) from the vendor processes is also prohibited in the platform SELinux policies. This rule must not be changed and is tested against in CTS.- Any vendor domain (process) that needs to launch a wrapper must add the following domain transition rule in the SELinux policy:
domain_auto_trans(VENDOR-DOMAIN-NAME, netutils_wrapper_exec, netutils_wrapper)
.
为了在 Android 8.0 及以后的版本中使用它们,供应商的实现必须遵守以下规则:
/system/bin/netutils-wrapper-1.0
,尝试执行时会导致程序错误。netutils-wrapper-1.0
封装的工具都需要通过符号链接进行使用。比如将以前的供应商代码 /system/bin/ip
改变为 /system/bin/ip-wrapper-1.0
。/system/bin/ip
)也是被禁止的。这一规则不能再 Android 兼容性测试套件(CTS)中进行更改与测试。domain_auto_trans(VENDOR-DOMAIN-NAME, netutils_wrapper_exec, netutils_wrapper)
。(Netutils wrapper filters)
Wrapped utilities can be used to configure almost any aspect of the Linux networking stack. However, to ensure it is possible to maintain a stable interface and allow updates to the system partition, only certain combinations of command line arguments are allowed; other commands will be rejected.
封装的工具可以用于几乎任何 Linux 网络栈方面的配置。但是,为了确保能可维护一个稳定的接口,并且允许对系统分区进行更新,我们只允许某些命令行参数组合,其它的命令将会被拒绝。
(Vendor interfaces and chains)
The wrapper has a concept of vendor interfaces. These are interfaces typically managed by vendor code, such as cellular data interfaces. Typically, other types of interfaces (such as Wi-Fi) are managed by the HALs and the framework. The wrapper recognizes vendor interfaces by name (using a regular expression) and allows vendor code to perform many operations on them. Currently, vendor interfaces are:
- Interfaces whose names end in “oem” followed by a number, such as
oem0
orr_oem1234
.- Interfaces used by current SOC and OEM implementations, such as
rmnet_data[0-9]
.
封装器有一个供应商接口的概念。这些接口通常由供应商代码来管理,比如蜂窝数据接口。通常来说,其它类型的接口(比如 Wi-Fi)是由 HAL 以及框架管理的。封装器通过名称来识别供应商接口(使用正则表达式),并且允许供应商代码执行许多操作。目前供应商接口如下:
oem
并且跟着一串数字的接口,比如 oem0
或者 r_oem1234
。rmnet_data[0-9]
。Names of interfaces that are typically managed by the framework (such as
wlan0
) are never vendor interfaces.
通常由框架所管理的接口名称(比如 wlan0
)不会是供应商接口。
The wrapper has a similar concept of vendor chains. These are used in
iptables
commands and are also recognized by name. Currently, vendor chains:
- Start with
oem_
.- Are used by current SOC and OEM implementations, e.g., chains starting in
nm_
orqcom_
.
封装器中有类似于供应商链的概念,这在 iptables
命令中使用,并且也通过名称来识别。目前供应商链命名如下:
oem_
开始的。nm_
或 qcom_
开头的链。(Allowed commands)
Currently allowed commands are listed below. Restrictions are implemented via a set of regular expressions on the executed command lines. For details, refer tosystem/netd/netutils_wrappers/NetUtilsWrapper-1.0.cpp
.
目前允许的命令列在下面。限制是通过所执行命令行上的一组正则表达式实现的。要了解更细节的内容,可以参阅 system/netd/netutils_wrappers/NetUtilsWrapper-1.0.cpp
。
The
ip
command is used to configure IP addresses, routing, IPsec encryption, and a number of other network parameters. The wrapper allows the following commands:
- Add and remove IP addresses from vendor-managed interfaces.
- Configure IPsec encryption.
ip
命令是用来设置 IP 地址,路由,安全加密以及其它一些网络参数的。封装器允许以下的命令:
The
iptables
andip6tables
commands are used to configure firewalling, packet mangling, NAT, and other per-packet processing. The wrapper allows the following commands:
- Add and delete vendor chains.
- Add and delete rules in any chain that refers to packets going into (-i) or out of (-o) a vendor interface.
- Jump to a vendor chain from any point in any other chain.
iptables
与 ip6tables
命令是用来配置防火墙,数据报处理,网络地址转换(NAT)以及其它每个包的处理。允许使用的命令如下:
ndc
is used to communicate to the netd daemon that performs most network configuration on Android. The wrapper allows the following commands:
- Create and destroy OEM networks (
oemXX
).- Add vendor-managed interfaces to OEM networks.
- Add routes to OEM networks.
- Enable or disable IP forwarding globally and on vendor interfaces.
ndc
命令是用于与后台程序 netd
通讯的,这个程序执行了大部分 Android O 中的网络配置。允许使用的命令如下:
- 创建或销毁一个 OEM 网络(oemXX
)。
- 将供应商管理的接口添加到 OEM 网络中。
- 向 OEM 网络添加路由。
- 开启或禁用全局的 IP 转发,或供应商接口的 IP 转发。
The
tc
command is used to configure traffic queueing and shaping on vendor interfaces.
tc
命令是用于配置供应商接口的网络传输的排队与成形的。