Android HIDL 官方文档(七,END)—— 网络堆栈配置工具(Network Stack Configuration Tools)

来源:互联网 发布:前海开源人工智能 编辑:程序博客网 时间:2024/06/05 07:05

  • 网络工具封装
  • 网络工具封装过滤器
    • 1 供应商接口与链
    • 2 允许使用的命令
      • 21 ip
      • 22 iptables ip6tables
      • 23 ndc
      • 24 tc


  • 对应的官方文档地址:HIDL(General) - Network Stack Configuration Tools
  • 官方目前已经出了中文文档,后面翻译的就不用传啦,所以把这篇改成完结了,有需要的朋友就继续到官方地址去看吧。
  • 最近项目多,组里人手又不太够,开始赶鸭子上架让我参与需求开发了……时不时突然给我分七八个 Bug 解一解,然后还要去改高通 HAL 或者 MTK HAL 里面的代码……作为新手真是有些应付不来了。
  • 最近有些 Bug,是跟 Hidl 机制有关的,正好看了官方文档有了一定的了解,处理起来就没有那么吃力了,刚刚学到的知识,就用上了,感觉还是挺有意思的。

The Android operating system contains standard Linux networking utilities such as ifconfig, ip, and ip6tables. 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 网络工具,比如 ipconfigipip6tables。这些实用程序保留在系统映像上,并且启用整个 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 工具。

1. 网络工具封装

(Netutils wrapper)
The netutils 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.0u:object_r:system_file:s0           /system/bin/ip6tables-wrapper-1.0 -> netutils-wrapper-1.0u:object_r:system_file:s0           /system/bin/iptables-wrapper-1.0 -> netutils-wrapper-1.0u:object_r:system_file:s0           /system/bin/ndc-wrapper-1.0 -> netutils-wrapper-1.0u:object_r:netutils_wrapper_exec:s0 /system/bin/netutils-wrapper-1.0u: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 <FOO> <BAR>) to /system/bin/ip-wrapper-1.0 <FOO> <BAR>.
  • 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 <FOO> <BAR>) 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 <FOO> <BAR> 改变为 /system/bin/ip-wrapper-1.0 <FOO> <BAR>
  • 在平台 SELinux 策略中,禁止执行没有进行域转换的封装。这一规则不能再 Android 兼容性测试套件(CTS)中进行更改与测试。
  • 在平台 SELinux 策略中,从供应商进程中直接执行工具程序(如 /system/bin/ip <FOO> <BAR>)也是被禁止的。这一规则不能再 Android 兼容性测试套件(CTS)中进行更改与测试。
  • 任何需要启动封装器的供应商域(进程)必须在 SELinux 策略中加入这些域转换规则:domain_auto_trans(VENDOR-DOMAIN-NAME, netutils_wrapper_exec, netutils_wrapper)

2. 网络工具封装过滤器

(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 网络栈方面的配置。但是,为了确保能可维护一个稳定的接口,并且允许对系统分区进行更新,我们只允许某些命令行参数组合,其它的命令将会被拒绝。

2.1 供应商接口与链

(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 or r_oem1234.
  • Interfaces used by current SOC and OEM implementations, such as rmnet_data[0-9].

       封装器有一个供应商接口的概念。这些接口通常由供应商代码来管理,比如蜂窝数据接口。通常来说,其它类型的接口(比如 Wi-Fi)是由 HAL 以及框架管理的。封装器通过名称来识别供应商接口(使用正则表达式),并且允许供应商代码执行许多操作。目前供应商接口如下:

  • 名称末尾带有 oem 并且跟着一串数字的接口,比如 oem0 或者 r_oem1234
  • 当前的 SOC 与 OEM 实现所使用的接口,比如说 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_ or qcom_.

       封装器中有类似于供应商链的概念,这在 iptables 命令中使用,并且也通过名称来识别。目前供应商链命名如下:

  • oem_ 开始的。
  • 目前被 SOC 与 OEM 实现所使用的,比如以 nm_qcom_ 开头的链。

2.2 允许使用的命令

(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 to system/netd/netutils_wrappers/NetUtilsWrapper-1.0.cpp.

       目前允许的命令列在下面。限制是通过所执行命令行上的一组正则表达式实现的。要了解更细节的内容,可以参阅 system/netd/netutils_wrappers/NetUtilsWrapper-1.0.cpp

2.2.1 ip

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 地址,路由,安全加密以及其它一些网络参数的。封装器允许以下的命令:

  • 从供应商所管理的接口中添加或删除 IP 地址。
  • 安全加密配置。

2.2.2 iptables / ip6tables

The iptables and ip6tables 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.

       iptablesip6tables 命令是用来配置防火墙,数据报处理,网络地址转换(NAT)以及其它每个包的处理。允许使用的命令如下:

  • 添加或删除供应商链。
  • 添加或删除关于进出供应商接口的包的规则。
  • 从任意其它的链的任意一个点跳到供应商链中。

2.2.3 ndc

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 转发。

2.2.4 tc

The tc command is used to configure traffic queueing and shaping on vendor interfaces.

       tc 命令是用于配置供应商接口的网络传输的排队与成形的。

阅读全文
0 0
原创粉丝点击