您尚未登录。

#1 2020-10-11 11:33:48

Mr.I
路人丙
所在地: Kerbal
注册时间: 2015-08-29
帖子: 308

NetworkManager 在服务启动的时候会访问 archlinux.org 的 HTTP 服务? 为什么?

事情的起因是这样的:我做了一些 IPv4 raw socket 相关的实验,我写的测试脚本会在运行过程中监听到所有目的地为本机的网络层的 TCP 报文(在这件事情中起到的作用等同于抓包程序)代码如下:

#!/usr/bin/python

import socket as s

sock = s.socket(s.AF_INET, s.SOCK_RAW, s.IPPROTO_TCP)


# 这两个掩码用来计算 IP Header 中的 Version 和 IHL 字段,
# 我们需要 IHL 来计算 IP Header 的实际长度
VER_MASK = 0b11110000
IHL_MASK = 0b00001111


while True:
    data, src = sock.recvfrom(65535)

    # IP 报文的首个字节为 Version + IHL
    first = data[0]
    ver = (first & VER_MASK) >> 4
    ihl = first & IHL_MASK

    assert ver == 4
    iphdr_len = 32 if ihl > 5 else 20

    ip_header = data[0:iphdr_len]
    ip_payload = data[iphdr_len:]

    print(src)
    print(ip_header)
    print('\n')
    print(ip_payload)

    print('\n-------------\n')

然后在测试过程中,我意外地抓到了下面这些报文。

这些报文在我 systemctl restart NetworkManager 的时候会复现,传输层 Header 中的源端口为 80,138.201.81.199 我查了一下是 archlinux.org 的地址,这也就是说,NetworkManager 在启动时会使用 HTTP 协议和 archlinux.org 通信并且得到了 archlinux.org 的响应: "NetworkManager is online"。

所以,为什么呢? 为什么 NetworkManager 需要向 archlinux.org 确认其在线?


('138.201.81.199', 0)
b'E\x00\x00<\x00\x00@\x005\x06\xa7|\x8a\xc9Q\xc7\xc0\xa8\x01\x07'


b'\x00P\xa6f\x97\xa1\x9c\x1eE(\x89\xd9\xa0\x12\xfe\x88x\xd5\x00\x00\x02\x04\x05\xb4\x04\x02\x08\n\xcdLs4\xbc\xaa\x8b\xad\x01\x03\x03\x07'

-------------

('138.201.81.199', 0)
b'E\x00\x00<\x00\x00@\x005\x06\xa7|\x8a\xc9Q\xc7\xc0\xa8\x01\x07'


b'\x00P\xa6j\xeb\xaf\\\x16m,G\xf2\xa0\x12\xfe\x88~\xad\x00\x00\x02\x04\x05\xb4\x04\x02\x08\n\xcdLs5\xbc\xaa\x8b\xad\x01\x03\x03\x07'

-------------

('138.201.81.199', 0)
b'E\x00\x00<\x00\x00@\x005\x06\xa7|\x8a\xc9Q\xc7\xc0\xa8\x01\x07'


b"\x00P\xa6n\x96~\x81w\xce\xb66\xc3\xa0\x12\xfe\x88]\x17\x00\x00\x02\x04\x05\xb4\x04\x02\x08\n\xcdLs\xc2\xbc\xaa\x8c'\x01\x03\x03\x07"

-------------

('138.201.81.199', 0)
b'E\x00\x004\x04_@\x005\x06\xa3%\x8a\xc9Q\xc7\xc0\xa8\x01\x07'


b'\x00P\xa6f\x97\xa1\x9c\x1fE(\x8a<\x80\x10\x01\xfd\xa2(\x00\x00\x01\x01\x08\n\xcdLt\x05\xbc\xaa\x8c~'

-------------

('138.201.81.199', 0)
b'E\x00\x01\x06\x04`@\x005\x06\xa2R\x8a\xc9Q\xc7\xc0\xa8\x01\x07'


b'\x00P\xa6f\x97\xa1\x9c\x1fE(\x8a<\x80\x18\x01\xfd7\xaf\x00\x00\x01\x01\x08\n\xcdLt\x05\xbc\xaa\x8c~HTTP/1.1 200 OK\r\nServer: nginx/1.18.0\r\nDate: Sun, 11 Oct 2020 03:14:27 GMT\r\nContent-Type: text/plain\r\nContent-Length: 24\r\nConnection: close\r\nCache-Control: max-age=0, must-revalidate\r\n\r\nNetworkManager is online'

离线

#2 2020-10-11 12:25:25

依云
会员
所在地: a.k.a. 百合仙子
注册时间: 2011-08-21
帖子: 8,934
个人网站

Re: NetworkManager 在服务启动的时候会访问 archlinux.org 的 HTTP 服务? 为什么?

为了看你的网是不是通的。如果你连上的网络有 captive portal,它好弹出来东西让你登录。
火狐也会访问 mozilla,Android 看厂商会访问 google、qualcomm 或者 xiaomi 等等。

离线

#3 2020-10-11 12:57:18

Mr.I
路人丙
所在地: Kerbal
注册时间: 2015-08-29
帖子: 308

Re: NetworkManager 在服务启动的时候会访问 archlinux.org 的 HTTP 服务? 为什么?

啊,我懂了,谢谢依云 big_smile

离线

#4 2020-12-31 12:51:48

lily
会员
注册时间: 2020-12-31
帖子: 18

Re: NetworkManager 在服务启动的时候会访问 archlinux.org 的 HTTP 服务? 为什么?

man NetworkManager.conf 

CONNECTIVITY SECTION
       This section controls NetworkManager's optional connectivity checking functionality.
       This allows NetworkManager to detect whether or not the system can actually access
       the internet or whether it is behind a captive portal.

       Connectivity checking serves two purposes. For one, it exposes a connectivity state
       on D-Bus, which other applications may use. For example, Gnome's portal helper uses
       this as signal to show a captive portal login page. The other use is that
       default-route of devices without global connectivity get a penalty of +20000 to the
       route-metric. This has the purpose to give a better default-route to devices that
       have global connectivity. For example, when being connected to WWAN and to a Wi-Fi
       network which is behind a captive portal, WWAN still gets preferred until login.

       Note that your distribution might set /proc/sys/net/ipv4/conf/*/rp_filter to strict
       filtering. That works badly with per-device connectivity checking, which uses
       SO_BINDDEVICE to send requests on all devices. A strict rp_filter setting will
       reject any response and the connectivity check on all but the best route will fail.

       enabled
           Whether connectivity check is enabled. Note that to enable connectivity check, a
           valid uri must also be configured. The value defaults to true, but since the uri
           is unset by default, connectivity check may be disabled. The main purpose of
           this option is to have a single flag to disable connectivity check. Note that
           this setting can also be set via D-Bus API at runtime. In that case, the value
           gets stored in /var/lib/NetworkManager/NetworkManager-intern.conf file.

       uri
           The URI of a web page to periodically request when connectivity is being
           checked. This page should return the header "X-NetworkManager-Status" with a
           value of "online". Alternatively, its body content should be set to
           "NetworkManager is online". The body content check can be controlled by the
           response option. If this option is blank or missing, connectivity checking is
           disabled.

       interval
           Specified in seconds; controls how often connectivity is checked when a network
           connection exists. If set to 0 connectivity checking is disabled. If missing,
           the default is 300 seconds.

       response
           If set, controls what body content NetworkManager checks for when requesting the
           URI for connectivity checking. Note that this only compares that the HTTP
           response starts with the specifid text, it does not compare the exact string.
           This behavior might change in the future, so avoid relying on it. If missing,
           the response defaults to "NetworkManager is online". If set to empty, the HTTP
           server is expected to answer with status code 204 or send no data.

如需禁用,创建 /etc/NetworkManager/conf.d/connectivity.conf

[connectivity]
enabled=false

离线

#5 2021-01-08 08:51:31

xtricman
エクス·トリクマン
注册时间: 2012-12-26
帖子: 1,267

Re: NetworkManager 在服务启动的时候会访问 archlinux.org 的 HTTP 服务? 为什么?

lily 说:

man NetworkManager.conf 

CONNECTIVITY SECTION
       This section controls NetworkManager's optional connectivity checking functionality.
       This allows NetworkManager to detect whether or not the system can actually access
       the internet or whether it is behind a captive portal.

       Connectivity checking serves two purposes. For one, it exposes a connectivity state
       on D-Bus, which other applications may use. For example, Gnome's portal helper uses
       this as signal to show a captive portal login page. The other use is that
       default-route of devices without global connectivity get a penalty of +20000 to the
       route-metric. This has the purpose to give a better default-route to devices that
       have global connectivity. For example, when being connected to WWAN and to a Wi-Fi
       network which is behind a captive portal, WWAN still gets preferred until login.

       Note that your distribution might set /proc/sys/net/ipv4/conf/*/rp_filter to strict
       filtering. That works badly with per-device connectivity checking, which uses
       SO_BINDDEVICE to send requests on all devices. A strict rp_filter setting will
       reject any response and the connectivity check on all but the best route will fail.

       enabled
           Whether connectivity check is enabled. Note that to enable connectivity check, a
           valid uri must also be configured. The value defaults to true, but since the uri
           is unset by default, connectivity check may be disabled. The main purpose of
           this option is to have a single flag to disable connectivity check. Note that
           this setting can also be set via D-Bus API at runtime. In that case, the value
           gets stored in /var/lib/NetworkManager/NetworkManager-intern.conf file.

       uri
           The URI of a web page to periodically request when connectivity is being
           checked. This page should return the header "X-NetworkManager-Status" with a
           value of "online". Alternatively, its body content should be set to
           "NetworkManager is online". The body content check can be controlled by the
           response option. If this option is blank or missing, connectivity checking is
           disabled.

       interval
           Specified in seconds; controls how often connectivity is checked when a network
           connection exists. If set to 0 connectivity checking is disabled. If missing,
           the default is 300 seconds.

       response
           If set, controls what body content NetworkManager checks for when requesting the
           URI for connectivity checking. Note that this only compares that the HTTP
           response starts with the specifid text, it does not compare the exact string.
           This behavior might change in the future, so avoid relying on it. If missing,
           the response defaults to "NetworkManager is online". If set to empty, the HTTP
           server is expected to answer with status code 204 or send no data.

如需禁用,创建 /etc/NetworkManager/conf.d/connectivity.conf

[connectivity]
enabled=false

意思是这个地址是可以部署后配置而不是编译期嵌入程序的对吧


反社会,精神极其不稳定,随时可能炸碎身边所有人

离线

#6 2021-01-08 11:04:44

yw662
大会员
所在地: localhost
注册时间: 2018-10-10
帖子: 424

Re: NetworkManager 在服务启动的时候会访问 archlinux.org 的 HTTP 服务? 为什么?

所以其实我不是很理解这种功能有什么用,让用户自己去登录不就好了


ecmascript是世界上最好的语言

离线

#7 2021-01-08 11:50:03

依云
会员
所在地: a.k.a. 百合仙子
注册时间: 2011-08-21
帖子: 8,934
个人网站

Re: NetworkManager 在服务启动的时候会访问 archlinux.org 的 HTTP 服务? 为什么?

yw662 说:

所以其实我不是很理解这种功能有什么用,让用户自己去登录不就好了

用户:我上不了网!打不开网站!求解决方案,急急急!

离线

#8 2021-01-08 14:57:36

Mr.I
路人丙
所在地: Kerbal
注册时间: 2015-08-29
帖子: 308

Re: NetworkManager 在服务启动的时候会访问 archlinux.org 的 HTTP 服务? 为什么?

lily 说:

如需禁用,创建 /etc/NetworkManager/conf.d/connectivity.conf

[connectivity]
enabled=false

谢谢 big_smile

离线

页脚