rust-netlink / netlink-proto

Other
8 stars 14 forks source link

handle.link().get() only returns first 10 interfaces #9

Closed mcr closed 1 year ago

mcr commented 1 year ago

I have finished some network protocol code (an RFC8995 Join Proxy handler if you care). It seems to work great on Ubuntu/Debian/Devuan platforms with rust 1.68, and 1.71.0-nightly. I cross-compile it for OpenWRT (which took some gyrations, but got it done). That is a arm_cortex-a9+vfpv3-d16_musl_eabi / armv7-unknown-linux-musleabihf flavour.

I run code like this when I start to get a list of all existing interfaces (then process new one that appear via netlink socket):

    let mut list = handle.link().get().execute();
    debug.debug_info(format!("scanning existing interfaces")).await;

    while let Some(link) = list.try_next().await.unwrap() {
        debug.debug_info(format!("link message {}", cnt)).await;
        AllInterfaces::gather_link_info(&lallif,
                                        &options,
                                        debugextra.clone(),
                                        link).await.unwrap();
        cnt += 1;
    }

Bizarrely, this loop finishes when cnt gets to 10, even though I have many more interfaces. (See below)

I don't really know what finger to point at next. I'm just posting this for google fodder, and I'll update it as I learn more.

I will be strace'ing the executable next to see if the NETLINK might actually be only sending 10 results. Maybe there is a read buffer which is truncating things? I will also be doing a review of what versions of dependencies get pulled in. For instance, I need the IPsec patches I upstreamed earlier this year, and I did have troubles getting OpenWRT's cargo/rustc to pick a consistent set of libraries. (Tweaks to Cargo.toml resulted)

root@hera:/etc# ip link ls
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 532
    link/ether d8:58:d7:00:8d:11 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 532
    link/ether d8:58:d7:00:8d:0f brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 532
    link/ether d8:58:d7:00:8d:10 brd ff:ff:ff:ff:ff:ff
5: lan0@eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-lan state UP mode DEFAULT group default qlen 1000
    link/ether d8:58:d7:00:8d:0f brd ff:ff:ff:ff:ff:ff
6: lan1@eth1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br-lan state LOWERLAYERDOWN mode DEFAULT group default qlen 1000
    link/ether d8:58:d7:00:8d:0f brd ff:ff:ff:ff:ff:ff
7: lan2@eth1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br-lan state LOWERLAYERDOWN mode DEFAULT group default qlen 1000
    link/ether d8:58:d7:00:8d:0f brd ff:ff:ff:ff:ff:ff
8: lan3@eth1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br-lan state LOWERLAYERDOWN mode DEFAULT group default qlen 1000
    link/ether d8:58:d7:00:8d:0f brd ff:ff:ff:ff:ff:ff
9: lan4@eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue master br-lan state LOWERLAYERDOWN mode DEFAULT group default qlen 1000
    link/ether d8:58:d7:00:8d:11 brd ff:ff:ff:ff:ff:ff
10: ip6tnl0@NONE: <NOARP> mtu 1452 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/tunnel6 :: brd ::
11: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/sit 0.0.0.0 brd 0.0.0.0
12: ifb0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 32
    link/ether ea:ad:3d:5b:e6:5b brd ff:ff:ff:ff:ff:ff
13: ifb1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 32
    link/ether a6:51:e2:2a:7a:ca brd ff:ff:ff:ff:ff:ff
14: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 04:f0:21:32:3d:0d brd ff:ff:ff:ff:ff:ff
15: wlan1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 04:f0:21:31:91:38 brd ff:ff:ff:ff:ff:ff
23: br-guest_turris: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
    link/ether e2:cc:83:52:21:03 brd ff:ff:ff:ff:ff:ff
24: br-lan: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether d8:58:d7:00:8d:0f brd ff:ff:ff:ff:ff:ff
mcr commented 1 year ago

Yeah, my stupid. Interface 10, ip6tnl arrives with a [0] length L2 address, which causes a panic in a thread... which I couldn't see in this stripped/optimized build, because of another panic in another thread at almost the same time.

It now all works on openwrt with Rust. Wow.