-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Labels
Description
code like the below, the kernel returns -22 but I don't know where the error is,
I reuse Genlmsghdr as NfGenMsg, so the cmd is not the issue.
The TLV tree seems Ok, and I think maybe there are len/alignment issues, but I did not assign these by hand.
fn make_attr<T, P>(attr_type: T, nest: bool, payload: P) -> Result<Nlattr<T, Buffer>>
where
P: Size + ToBytes,
T: NlAttrType,
{
Ok(NlattrBuilder::default()
.nla_type(
AttrTypeBuilder::default()
.nla_type(attr_type)
.nla_nested(nest)
.build()?,
)
.nla_payload(payload)
.build()?)
}
pub fn delete(&self, proto: u8, ip: &Ipv4Addr) -> Result<()> {
let ip_attr = make_attr(
IpTupleAttr::CtaIpv4Src,
false,
Buffer::from(ip.octets().to_vec()),
)?;
let ip_tuple = make_attr(TupleAttr::CtaTupleIp, true, ip_attr)?;
let proto_attr = make_attr(
ProtoTupleAttr::CtaProtoNum,
false,
Buffer::from((proto as u32).to_ne_bytes().to_vec()),
)?;
let proto_tuple = make_attr(TupleAttr::CtaTupleProto, true, proto_attr)?;
let mut attr = make_attr(ConntrackAttr::CtaTupleOrig, true, ip_tuple)?;
attr = attr.nest(&proto_tuple)?;
let mut attrs = GenlBuffer::<ConntrackAttr, Buffer>::new();
attrs.push(attr);
let genlhdr = GenlmsghdrBuilder::default()
.cmd(libc::AF_INET as u8)
.version(libc::NFNETLINK_V0 as u8)
.attrs(attrs)
.build()?;
let x: NlRouterReceiverHandle<u16, Buffer> = self.socket.send(
CtNetlinkMessage::CtDelete, // CtDelete = subsys_message(CtNetlinkSubsys::CtNetlink, CtMessage::CtDelete),
NlmF::ACK | NlmF::MATCH,
NlPayload::Payload(genlhdr),
)?;
log::info!("waiting...");
for r in x {
log::info!("{r:?}"); // EINVAL reported
}
log::info!("done");
Ok(())
}