Skip to content

Not all Wireguard peers are fetched #7

Description

@Francois238

Description

Hello,

First of all, thank you for creating this crate to easily manage wireguard interfaces and peers.

I have this issue that occurred when I have a great number of peers on my Wireguard interface: I do not retrieve all my Wireguard peers when I use the get_by_name function.

I created this dumb wireguard configuration file to re-create the situation with a number of 200 peers and then I do a

wg-quick up ./wg-test.conf

wg-test.conf.txt

and wg show wg-test dump | wc -l, which gives 201, my wireguard interface + the 200 peers.

Here an example code where I use the get_by_name function:

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let (conn, mut handle, _) =
        nl_wireguard::new_connection()?;
    tokio::spawn(conn);

    let config: nl_wireguard::WireguardParsed = handle.get_by_name("wg-test").await?;

    if let Some(peers) = config.peers {
        println!("Number of peers: {}", peers.len());

        for peer in &peers {
            println!(
                "Peer: {:?} - AllowedIPs: {:?} - Keepalive: {:?}",
                peer.public_key,
                peer.allowed_ips,
                peer.persistent_keepalive
            );

        }
    }

    Ok(())
}

I have this result

./target/debug/wgtest       
Number of peers: 192

instead of getting 200 peers.

Proposed solution

I see in src/handle.rs only the first WireguardMessage is taken into account, and not the others if they exist.
A solution could be to store all the WireguardMessage received in the request function, to parse them in order to return a WireguardParsed object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions