little-dude / netlink

netlink libraries for rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`netlink-packet-wireguard`: SetDevice serialization issues

mcginty opened this issue · comments

While GetDevice and parsing works great, SetDevice encounters Invalid argument (os error 22) whenever the WgDeviceAttrs::Peers attribute is present.

It seems like there's probably some discrepancy in the encoding of the peer list - it generates an unparseable netlink message:

Example code:

    let genlmsg: GenlMessage<Wireguard> = GenlMessage::from_payload(Wireguard {
        cmd: WireguardCmd::SetDevice,
        nlas: vec![
            WgDeviceAttrs::IfName(argv[1].clone()),
            WgDeviceAttrs::PrivateKey([10u8; 32]),
            WgDeviceAttrs::Peers(vec![vec![WgPeerAttrs::PublicKey([1u8; 32]), WgPeerAttrs::PersistentKeepalive(25)]])
        ],
    });
    let mut nlmsg = NetlinkMessage::from(genlmsg);
    nlmsg.header.flags = NLM_F_REQUEST | NLM_F_ACK;

    nlmsg.finalize();
    let mut buf = [0; 4096];
    nlmsg.serialize(&mut buf);
    let len = nlmsg.buffer_len();

    // panics
    let response = NetlinkMessage::<GenlMessage<Wireguard>>::deserialize(&buf[..len]).unwrap();