15: ccmni1: <NOARP> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/none
16: ccmni2: <NOARP> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/none
17: ccmni3: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
18: ccmni4: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
19: ccmni5: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
20: ccmni6: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
21: ccmni7: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
22: ccmni8: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
23: ccmni9: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
24: ccmni10: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
25: ccmni11: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
26: ccmni12: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
27: ccmni13: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
28: ccmni14: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
29: ccmni15: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
30: ccmni16: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
31: ccmni17: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
32: ccmni18: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
33: ccmni19: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
34: ccmni20: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/none
35: ccmni-lan: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether
36: miw_oem0: <NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 06:90:b8:bf:93:38 brd ff:ff:ff:ff:ff:ff
38: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 3000
link/ether 5a:e6:b8:80:15:6f brd ff:ff:ff:ff:ff:ff
inet 192.168.124.16/24 brd 192.168.124.255 scope global wlan0
valid_lft forever preferred_lft forever
inet6 fe80::58e6:b8ff:fe80:156f/64 scope link
valid_lft forever preferred_lft forever
39: wlan1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 3000
link/ether 4c:e0:db:8e:6b:0e brd ff:ff:ff:ff:ff:ff
42: p2p0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether 4e:e0:db:8c:6b:0e brd ff:ff:ff:ff:ff:ff
412: tun0: <POINTOPOINT> mtu 1380 qdisc pfifo_fast state DOWN group default qlen
link/none
在手机使用 adb shell ip addr, 发现有大量的网络接口,其中包括 ccmni1~ ccmni20, 不明白的是为什么会有这么多重复接口? 还有一个就是 android 的 vpn service 在关闭后,tun0 应该也会关闭,但还是存在, 只有将 app 杀死后 tun0 才会消失? 有熟悉 android 网络这块的朋友帮我看看,能够解答我的疑惑
1
choury 2023-05-07 00:23:26 +08:00
ip -d link 看下接口信息吧,另外 DOWN 状态的接口就不用管它了吧
|
2
jackyzy823 2023-05-07 02:10:46 +08:00 via Android
|
3
jackyzy823 2023-05-07 02:29:24 +08:00 via Android
vpn 我的理解是 vpn service 关闭后只是调用了 reset interface (flag 为 0 即 down) https://android.googlesource.com/platform/frameworks/base/+/master/services/core/jni/com_android_server_connectivity_Vpn.cpp#316
以上 cpp 文件只有在打开 /dev/tun 出错时才会关闭 tun 这个 fd ,别的任何地方都没有关闭 tun 这个 fd 的接口。 根据内核文档 https://www.kernel.org/doc/Documentation/networking/tuntap.txt tun 接口是在 tun 这个 fd 关闭后删除的 ,那么可以猜到 app 关闭后,系统清理进程打开的所有 fd ,于是 tun 接口关闭。 |
4
iceheart 2023-05-07 05:18:17 +08:00 via Android
tun 就是收发 ip 包用的网关,用 udp 转发 ip 包,即 ip over udp ,就是 vpn 。 特点就是 mtu 要小。 打开一个 tun 文件就是创建了一个虚拟的网卡。杀掉 vpn 的应用进程,内核会关掉这个进程打开的所有文件句柄,虚拟出来的网卡自然就销毁了
|