use neli::consts::genl::NlAttrType;
use neli::neli_enum;
use std::fmt;
pub(crate) const NLA_F_NESTED: u16 = libc::NLA_F_NESTED as u16;
pub(crate) const NLA_TYPE_MASK: u16 = libc::NLA_TYPE_MASK as u16;
macro_rules! impl_bit_ops_for_nla {
($name:ident) => {
impl std::ops::BitOr<u16> for $name {
type Output = Self;
fn bitor(self, rhs: u16) -> Self {
Self::from(u16::from(self) | rhs)
}
}
impl std::ops::BitAnd<u16> for $name {
type Output = Self;
fn bitand(self, rhs: u16) -> Self {
Self::from(u16::from(self) & rhs)
}
}
};
}
#[neli_enum(serialized_type = "u16")]
pub enum NlaNested {
Unspec = 0,
Unused = 1,
}
impl NlAttrType for NlaNested {}
impl_bit_ops_for_nla!(NlaNested);
#[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 {}
impl fmt::Display for WgDeviceAttribute {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{self:?}")
}
}
impl_bit_ops_for_nla!(WgDeviceAttribute);
#[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 {}
impl fmt::Display for WgPeerAttribute {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{self:?}")
}
}
impl_bit_ops_for_nla!(WgPeerAttribute);
#[neli_enum(serialized_type = "u16")]
pub enum WgAllowedIpAttribute {
Unspec = 0,
Family = 1,
IpAddr = 2,
CidrMask = 3,
}
impl NlAttrType for WgAllowedIpAttribute {}