Android 实际上在哪里调用 "ip link" 或 "ifconfig" 来启动接口?

Where does Android actually invoke "ip link" or "ifconfig" to bring an interface up?

我花了几个小时阅读 AOSP 源代码,试图找到在需要启动 eth0 时如何以及在何处调用“ip link”或“ifconfig”。

Android10 是否使用“ip link”或“ifconfig”来设置地址并启动 eth0?

或者它是否以其他方式操纵网络接口?

既然你提到了 eth0,我假设你对以太网接口感兴趣。每种传输类型都有自己的 IP 供应管理方式。对于以太网接口,您可以在 EthernetNetworkFactory link. The method you are interested in seeing how this works is EthernetNetworkFactory#provisionIpClient link.

找到拥有的 class

最终,如果您遵循代码,您会看到它最终到达 netd 这里 NetdNativeService#interfaceAddAddress link。此时我们处于原生层。

然后最终到达ifc_utils#ifc_act_on_address link. This is where the ip address will ultimately be added to the ethernet interface. After all of this detective work, we see in this function that a socket is opened to send a NETLINK_ROUTE message link设置ip地址。