Skip to content

Commit

Permalink
Regression test for #214
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Nov 3, 2023
1 parent fc27987 commit c6a18d7
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/rtnl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ where
mod test {
use super::*;

use std::net::Ipv4Addr;

use crate::{
consts::{nl::NlmF, socket::NlFamily},
nl::NlPayload,
Expand Down Expand Up @@ -532,4 +534,43 @@ mod test {
));
}
}

#[test]
#[cfg(target_env = "gnu")]
fn real_test_rtmsg_search() {
setup();

let dstip = Ipv4Addr::new(127, 0, 0, 1);
let raw_dstip = u32::from(dstip).to_be();
let route_attr = RtattrBuilder::default()
.rta_type(Rta::Dst)
.rta_payload(raw_dstip)
.build()
.unwrap();

let mut route_payload = RtBuffer::new();
route_payload.push(route_attr);

let (rtnl, _) = NlRouter::connect(NlFamily::Route, None, Groups::empty()).unwrap();

let ifroutemsg = RtmsgBuilder::default()
.rtm_family(RtAddrFamily::Inet)
.rtm_dst_len(32)
.rtm_src_len(0)
.rtm_tos(0)
.rtm_table(RtTable::Unspec)
.rtm_protocol(Rtprot::Unspec)
.rtm_scope(RtScope::Universe)
.rtm_type(Rtn::Unspec)
.rtm_flags(RtmF::from(libc::RTM_F_LOOKUP_TABLE))
.rtattrs(route_payload)
.build()
.unwrap();

let recv = rtnl
.send::<_, _, Rtm, Rtmsg>(Rtm::Getroute, NlmF::REQUEST, NlPayload::Payload(ifroutemsg))
.unwrap();

assert!(recv.count() > 0);
}
}

0 comments on commit c6a18d7

Please sign in to comment.