GithubHelp home page GithubHelp logo

netlink-packet-wireguard's People

Contributors

cathay4t avatar dave-tucker avatar dtoubelis avatar johntitor avatar leo1003 avatar little-dude avatar mcginty avatar wllenyj avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

netlink-packet-wireguard's Issues

Wireguard `SetDevice` call blocks

I'm trying to set up wireguard interface and I'm running into an issue with call being blocked at retrieving results. Here is sample code:

      
       let (connection, mut handle, _) = genetlink::new_connection().map_err(|err| {
            error!("{err}");
            Error::InternalError
        })?;
        let _ = tokio::spawn(connection);

        let nlas = vec![
            WgDeviceAttrs::IfName(self.name.clone()),
            WgDeviceAttrs::PrivateKey(self.priv_key.expect("failed to unwrap private key")),
            WgDeviceAttrs::ListenPort(self.listen_port),
            WgDeviceAttrs::Fwmark(self.fwmark),
            WgDeviceAttrs::Flags(WGDEVICE_F_REPLACE_PEERS),
        ];

        let genlmsg: GenlMessage<Wireguard> = GenlMessage::from_payload(Wireguard {
            cmd: WireguardCmd::SetDevice,
            nlas,
        });
        let mut nlmsg = NetlinkMessage::from(genlmsg);
        nlmsg.header.flags = NLM_F_REQUEST;

        // this call does not return any error if application does not have necessary capabilities
        let mut res = handle.request(nlmsg).await.map_err(|err| {
            debug!("{err}");
            Error::InternalError
        })?;

        // this call blocks if there is no error
        let _result = res.try_next().await.map_err(|err| {
            debug!("{err}");
            Error::InternalError
        })?;

According to netlink documentation only NLM_F_REQUEST flag supposed to be supplied and the kernel is not expected to return result. Which is fine but I still want to catch any permission errors.

Here are some observations:

  • If application does not have sufficient permissions - request() call goes not return any error. When I check result with either
    res.try_next() or res.next() call it returns permission error, which is reasonably okay.
  • However, when application is executed with elevated permissions, no error is expected but res.try_next() or res.next() calls block indefinitely.
  • I also noticed, that if I don't wait for the result - the device is not set up. It only gets set up when application blocks and then terminated.

I think most likely I'm doing something wrong but it also feels that it may be a bug in genetlink. Any thoughts?

publish version 0.2.2 on crates.io

commit 9b29307 bump the version to 2.2.0 but this version was never pushed to crates.io.
It would be nice to keep them in sync so we do not have to specify the git repo in cargo.toml to use the latest version.

@cathay4t PTAL

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.