Fuchsia client network 相关模块现在只有如下几种,实现语言也很诡异。
dhcp Rust
http_client Rust
mdns C++
netstack Go
netstack3 Rust
猜测 Fuchsia 会重度使用 mDNS(multicast DNS),所以完成度比较高。苹果系统(Bonjour)重度使用了mDNS。Fuchsia 里缺省配置可能是:
{
"port": 5356,
"v4_multicast_address": "224.0.0.250",
"publications": [
{
"service": "_fuchsia._udp.",
"port": 5356,
"perform_probe": false
}
]
}
mDNS封装简洁明了,提供的接口或抽象(fidl, mdns-util)有 ServiceSubscriber, ServiceInstance,PublicationResponder,Publication。要求
<host_name> and <instance_name> cannot end in '.'
<service_name> must start with '_' and end in '._tcp.' or '._udp.'
mdns-util 比起 dns-sd (Bonjour的工具)好用太多、简单太多。
由于 mDNS 本身不太复杂,索性翻了一下整个开发变更历史,感想放在了最后。
变更历史
2013年加入 chromium 的代码结构为:
net/dns/mdns_client.cc
...
net/dns/mdns_client_impl.cc
net/dns/mdns_client.h
2017/4/17 加入 packet reader/writer,目录结构大概如下:
bin/netconnector/BUILD.gn
bin/netconnector/mdns/dns_message.c
bin/netconnector/mdns/packet_reader.cc
bin/netconnector/mdns/packet_writer.cc
bin/netconnector/mdns/dns_formatting.cc
bin/netconnector/mdns/dns_reading.cc
bin/netconnector/mdns/dns_writing.cc
public/lib/netconnector/fidl/mdns.fidl
2017/4/21 开始加入 MdnsNames/Transceiver
2017/4/26 开始加入 AddressResponder / client(mdns.fidl)
2017/4/28 开始加入 service implementation
bin/netconnector/mdns/dns_formatting.cc
bin/netconnector/mdns/mdns_addresses.cc
public/lib/netconnector/fidl/mdns.fidl
中间还有几次全局路径调整, media path 变更,ftl to fxl
2017/9/14 clang format
2017/9/26 recheck NICs when address family is unspecified
2017/10/4 delete unused netconfig.h from the include list
2017/10/12 迎来mDNS的一次大更新
2017/10/13 add MdnsService.AddResponder
2017/10/16 add ‘mdns’ tool
2017/10/16 add ‘mdns’ tool
2017/10/19 simplify mDNS question/resource send logic
2017/10/20 simplify mDNS agents using base class
2017/10/23 implement mDNS unicast response
2017/10/24 postpone distribution of host name
2017/10/26 implement address probe
2017/10/27 publish _fuchsia._tcp. instance by unique name
add service instance probing
2017/11/14 Sandbox mdns.开始加入
packages/mdns
2017/12/4 fix potential DOS exploit in DNS name parsing
2017/12/4 NET-268 use netstack RegisterListener
2017/12/4 fix potential DOS exploit in DNS name parsing
2018/1/12 move mdns tool to bin/mdns/tool from bin/mdns
bin/mdns/{ => tool}/BUILD.gn
2018/1/16 add public/lib/mdns files
public/lib/mdns/cpp/BUILD.gn
public/lib/mdns/cpp/service_subscriber.cc
public/lib/mdns/fidl/mdns.fidl
2018/1/16 update mdns command line tool to use new lib
2018/1/16 mdns 从 netconnector 独立成为一个Service
bin/{netconnector/mdns => mdns/service}/dns_formatting.cc
目录结构变更为
bin/mdns/service/mdns_service_impl.cc
bin/mdns/service/dns_formatting.cc
bin/mdns/tool/mdns_impl.cc
public/lib/mdns/cpp/service_subscriber.cc
2018/1/24 factor out interface enumeration
2018/1/26 change the non-fidl publication model
2018/1/24 add standalone mdns app (mdns_standalone)
bin/mdns/standalone/BUILD.gn
2018/1/29 add traffic reporting to mdns
2018/1/30 Update FIDL1 C++ bindings to match FIDL2 interface
2018/1/30 eliminate awkward host name dataflow
2018/2/5 handle socket init failures on address change
2018/2/7 simplify address fixup logic (and fix bug)
2018/2/12 add cpu and memory reporting to mdns_standalone
2018/2/13 Add Rust wrappers for mdns fidl service
public/rust/fidl_crates/garnet_public_lib_mdns_fidl/src/lib.rs
2018/2/12 Add beginnings of mDNS lib.
system/ulib/mdns/mdns.c
2018/2/23 Rename fidl namespace to f1dl 这个更新很诡异
2018/3/22 Make mdns tool build
bin/mdns/tool/mdns_impl.cc
public/lib/mdns/fidl/BUILD.gn
2018/3/22 Make mdns_service build
bin/mdns/service/mdns.cc
2018/3/29 Add method to add authorities to a message.
system/ulib/mdns/mdns.c
2018/4/6 remove deprecated TaskRunner/MessageLoop
2018/5/18 filter out messages from the local address
2018/6/1 Port to fit::function.
2018/6/4 git-file-format bin/mdns
2018/6/4 change fidl namespace to fuchsia.mdns
2018/6/9 use fostr formatting library
2018/8/3 reject 0.0.0.0 addresses
2018/9/28 update service configuration
2018/10/12 register mdns_service and start it in garnet default
至此 mDNS 算是正式投入使用了
2018/11/1 add mdns_service to packages/framework, add LegacySocketProvider to mdns_service’s sandbox
2018/11/1 remove mdns code.
system/ulib/mdns/mdns.c
2018/11/1 remove mdns_standalone
bin/mdns/standalone/main.cc
2018/11/1 rename mdns_service->mdns, mdns->mdns_util
bin/mdns/{tool => util}/BUILD.gn
bin/mdns/{tool => util}/main.cc
2018/11/6 respond to wildcard queries
2018/11/8 enable support for V6 addresses
2018/11/29 fix name compression exploit
fuzzer/manually tested using avahi
2018/11/8 enable support for V6 addresses
2018/12/6 publish the device as ‘_fuchsia._udp.’ by default
2018/12/10 Add bin/dev_finder command
bin/dev_finder/list.go
2018/12/13 remove raw new/delete
2018/12/20 Add fuzzer for PacketReader.
2019/1/2 fix address fix-up to enable V6
2019/1/3 use gethostname for faster startup
2019/1/8 make mdns_util a shell binary
bin/mdns/util/BUILD.gn
2019/1/22 adapt to new socket option behavior
2019/1/22 support V6 addresses on non-V4-provisioned NICs
2019/1/23 rename mdns_util to mdns-util
2019/2/12 set mdns sdk category to partner
2019/2/22 use strerror to format errno values in logs
2019/3/10 remove IP_MULTICAST_LOOP workaround/set IP{,V6}_MULTICAST_LOOP = 0
2019/3/26 update handling of setsockopt and bind errors
2019/4/8 FIDL readability improvements
2019/4/16 reviewed FIDL definition for fuchsia.net.mdns
2019/4/18 support config files
2019/4/23 Switch default port for mDNS responder to 5356
2019/4/29 add v4/v6_multicast_address properties to config
2019/4/30 transition to new fuchsia.net.mdns FIDL API
2019/5/1 move mdns implementation from garnet/bin to src
{garnet/bin => src/connectivity/network}/mdns/BUILD.gn
至此目录结构变为
src/connectivity/network/mdns/BUILD.gn
service/BUILD.gn
service/dns_formatting.cc
service/main.cc
test/dns_names_test.cc
util/mdns_impl.cc
util/main.cc
2019/5/2 change the multicast V4 address to 224.0.0.250
2019/6/7 move all mdns package targets out of garnet
感想
- 代码基于 Chromium 开始,即使差异如此的大
- 该模块未提前开发,等待核心稳定后才开始
- 2017年4月 才算开始开发,2018年10月稳定后集成,花费时间比我想象的多
- 大致流程是:开始、主体趋于稳定、集成、fuzzer 和测试,然后正常迭代
- 这个模块有固定的工程师,但是其他人也在小规模改动
- 至少使用了Avahi(mDNS 的 posix 实现) 的测试用例
- 文件名一定是下划线,但是名称会使用连字符 (符合本人口味)
- 大规模目录结构调整出现了很多次,关于 C++ 的使用规则调整也出现了至少2次