Skip to content

Commit

Permalink
update neli to 0.6.2
Browse files Browse the repository at this point in the history
API changes:

- impl_var!() removed in 0.6.0.
- Trait Nl removed in 0.6.0.
- Stream{Read,Write}Buffer have been obsoleted.
- There's an enum IflaInfo for IFLA_INFO_* defines.
- NlPayload type for Genlmsghdr payload.
- Track NlSocketHandle API changes (::connect() over ::open()/::bind()).
- Simplified header deserialization via FromBytesWithInput trait.
- The asize() member function disappeared.
  • Loading branch information
phi-gamma committed Sep 24, 2022
1 parent 684639c commit f402f7b
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 161 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ hex = { version = "0.4.3", optional = true }
take-until = { version = " 0.1.0", optional = true }

[target.'cfg(target_os = "linux")'.dependencies]
neli = "=0.5.3"
neli = "=0.6.2"
libc = "0.2.66"

[dev-dependencies]
Expand Down
79 changes: 40 additions & 39 deletions src/linux/attr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use neli::consts::genl::NlAttrType;
use neli::impl_var;
use neli::neli_enum;
use std::fmt;

// As of neli 0.4.3, the NLA_F_NESTED flag needs to be added to newly created
Expand Down Expand Up @@ -29,31 +29,31 @@ macro_rules! impl_bit_ops_for_nla {
};
}

impl_var!(
pub NlaNested, u16,
Unspec => 0,
#[neli_enum(serialized_type = "u16")]
pub enum NlaNested {
Unspec = 0,
// neli requires 1 non-zero argument even though WireGuard
// does not use it.
Unused => 1
);
Unused = 1,
}

impl NlAttrType for NlaNested {}

impl_bit_ops_for_nla!(NlaNested);

// https://github.com/WireGuard/WireGuard/blob/62b335b56cc99312ccedfa571500fbef3756a623/src/uapi/wireguard.h#L147
impl_var!(
pub WgDeviceAttribute, u16,
Unspec => 0,
Ifindex => 1,
Ifname => 2,
PrivateKey => 3,
PublicKey => 4,
Flags => 5,
ListenPort => 6,
Fwmark => 7,
Peers => 8
);
#[neli_enum(serialized_type = "u16")]
pub enum WgDeviceAttribute {
Unspec = 0,
Ifindex = 1,
Ifname = 2,
PrivateKey = 3,
PublicKey = 4,
Flags = 5,
ListenPort = 6,
Fwmark = 7,
Peers = 8,
}

impl NlAttrType for WgDeviceAttribute {}

Expand All @@ -66,20 +66,20 @@ impl fmt::Display for WgDeviceAttribute {
impl_bit_ops_for_nla!(WgDeviceAttribute);

// https://github.com/WireGuard/WireGuard/blob/62b335b56cc99312ccedfa571500fbef3756a623/src/uapi/wireguard.h#L165
impl_var!(
pub WgPeerAttribute, u16,
Unspec => 0,
PublicKey => 1,
PresharedKey => 2,
Flags => 3,
Endpoint => 4,
PersistentKeepaliveInterval => 5,
LastHandshakeTime => 6,
RxBytes => 7,
TxBytes => 8,
AllowedIps => 9,
ProtocolVersion => 10
);
#[neli_enum(serialized_type = "u16")]
pub enum WgPeerAttribute {
Unspec = 0,
PublicKey = 1,
PresharedKey = 2,
Flags = 3,
Endpoint = 4,
PersistentKeepaliveInterval = 5,
LastHandshakeTime = 6,
RxBytes = 7,
TxBytes = 8,
AllowedIps = 9,
ProtocolVersion = 10,
}

impl NlAttrType for WgPeerAttribute {}

Expand All @@ -92,11 +92,12 @@ impl fmt::Display for WgPeerAttribute {
impl_bit_ops_for_nla!(WgPeerAttribute);

// https://github.com/WireGuard/WireGuard/blob/62b335b56cc99312ccedfa571500fbef3756a623/src/uapi/wireguard.h#L181
impl_var!(
pub WgAllowedIpAttribute, u16,
Unspec => 0,
Family => 1,
IpAddr => 2,
CidrMask => 3
);
#[neli_enum(serialized_type = "u16")]
pub enum WgAllowedIpAttribute {
Unspec = 0,
Family = 1,
IpAddr = 2,
CidrMask = 3,
}

impl NlAttrType for WgAllowedIpAttribute {}
13 changes: 7 additions & 6 deletions src/linux/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use neli::{consts::genl::Cmd, impl_var};
use neli::consts::genl::Cmd;
use neli::neli_enum;

// https://github.com/WireGuard/WireGuard/blob/62b335b56cc99312ccedfa571500fbef3756a623/src/uapi/wireguard.h#L137
impl_var!(
pub WgCmd, u8,
GetDevice => 0,
SetDevice => 1
);
#[neli_enum(serialized_type = "u8")]
pub enum WgCmd {
GetDevice = 0,
SetDevice = 1,
}

impl Cmd for WgCmd {}
7 changes: 6 additions & 1 deletion src/linux/err/connect_error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use neli::consts::{
genl::{CtrlAttr, CtrlCmd},
nl::GenlId,
};
use neli::err::NlError;
use neli::genl::Genlmsghdr;
use thiserror::Error;

#[derive(Error, Debug)]
Expand All @@ -7,7 +12,7 @@ pub enum ConnectError {
NlError(NlError),

#[error("Unable to connect to the WireGuard DKMS. Is WireGuard installed?")]
ResolveFamilyError(#[source] NlError),
ResolveFamilyError(#[source] NlError<GenlId, Genlmsghdr<CtrlCmd, CtrlAttr>>),
}

impl From<NlError> for ConnectError {
Expand Down
12 changes: 4 additions & 8 deletions src/linux/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ impl<'a> TryFrom<&DeviceInterface<'a>> for Nlattr<WgDeviceAttribute, Buffer> {
fn try_from(interface: &DeviceInterface) -> Result<Self, Self::Error> {
let attr = match interface {
&DeviceInterface::Index(ifindex) => {
Nlattr::new(None, false, false, WgDeviceAttribute::Ifindex, ifindex)?
Nlattr::new(false, false, WgDeviceAttribute::Ifindex, ifindex)?
}
DeviceInterface::Name(ifname) => {
Nlattr::new(false, false, WgDeviceAttribute::Ifname, ifname.as_ref())?
}
DeviceInterface::Name(ifname) => Nlattr::new(
None,
false,
false,
WgDeviceAttribute::Ifname,
ifname.as_ref(),
)?,
};
Ok(attr)
}
Expand Down
5 changes: 1 addition & 4 deletions src/linux/set/allowed_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ impl<'a> TryFrom<&AllowedIp<'a>> for Nlattr<NlaNested, Buffer> {

fn try_from(allowed_ip: &AllowedIp) -> Result<Self, Self::Error> {
let mut nested =
Nlattr::new::<Vec<u8>>(None, false, false, NlaNested::Unspec | NLA_F_NESTED, vec![])?;
Nlattr::new::<Vec<u8>>(false, false, NlaNested::Unspec | NLA_F_NESTED, vec![])?;

let family = match allowed_ip.ipaddr {
IpAddr::V4(_) => libc::AF_INET as u16,
IpAddr::V6(_) => libc::AF_INET6 as u16,
};
nested.add_nested_attribute(&Nlattr::new(
None,
false,
false,
WgAllowedIpAttribute::Family,
Expand All @@ -45,7 +44,6 @@ impl<'a> TryFrom<&AllowedIp<'a>> for Nlattr<NlaNested, Buffer> {
IpAddr::V6(addr) => addr.octets().to_vec(),
};
nested.add_nested_attribute(&Nlattr::new(
None,
false,
false,
WgAllowedIpAttribute::IpAddr,
Expand All @@ -57,7 +55,6 @@ impl<'a> TryFrom<&AllowedIp<'a>> for Nlattr<NlaNested, Buffer> {
IpAddr::V6(_) => 128,
});
nested.add_nested_attribute(&Nlattr::new(
None,
false,
false,
WgAllowedIpAttribute::CidrMask,
Expand Down
Loading

0 comments on commit f402f7b

Please sign in to comment.