jbaublitz / neli

Rust type safe netlink library
BSD 3-Clause "New" or "Revised" License
177 stars 35 forks source link

New route is not being added #244

Open pseusys opened 2 weeks ago

pseusys commented 2 weeks ago

Version of neli 0.6.4

Describe the bug I want to create a new route in a new table. Just like the following command does: ip route add default via 192.168.0.8 dev wlo1 table 7.

Please provide a minimal, ready-to-compile example that reproduces the bug Here's a rough example of the code I used:

let mut sender_socket = NlSocketHandle::connect(NlFamily::Route, None, &[])?;
let interface: i32 = 2;
let address: Ipv4Addr = Ipv4Addr::new(192, 168, 0, 8);
let table: RtTable = RtTable::UnrecognizedConst(7);
let mut route_rtbuff = RtBuffer::new();
route_rtbuff.push(Rtattr::new(None, Rta::Oif, interface)?);
route_rtbuff.push(Rtattr::new(None, Rta::Gateway, Vec::from(address.octets()))?);
let route_send_payload = Rtmsg {rtm_family: RtAddrFamily::Inet, rtm_dst_len: 0, rtm_src_len: 0, rtm_tos: 0, rtm_table: svs_table, rtm_protocol: Rtprot::Boot, rtm_scope: RtScope::Universe, rtm_type: Rtn::Unicast, rtm_flags: RtmFFlags::empty(), rtattrs: route_rtbuff};
let route_send_msg = Nlmsghdr::new(None, Rtm::Newroute, NlmFFlags::new(&[NlmF::Request, NlmF::Act, NlmF::Excl, NlmF::Create]), None, None, NlPayload::Payload(route_send_payload));
sender_socket.send(route_send_msg).unwrap();

Expected behavior I expected a route to be created. However, when I run ip route show table 7, nothing is shown. Maybe I am doing something wrong? If so, what would be the correct way to create a default route with "GATEWAY" and "DEVICE" attributes specified using neli?

Additional context In the examples above, assume there exists a network interface with name wlo1, number 7 and IP address assigned 192.168.0.8. Also, I have tried running the command specified above with strace and the only invocation of sendmsg command that appeared there looked like this: sendmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=12, msg_iov=[{iov_base=[{nlmsg_len=44, nlmsg_type=RTM_NEWROUTE, nlmsg_flags=NLM_F_REQUEST|NLM_F_ACK|NLM_F_EXCL|NLM_F_CREATE, nlmsg_seq=1726254782, nlmsg_pid=0}, {rtm_family=AF_INET, rtm_dst_len=0, rtm_src_len=0, rtm_tos=0, rtm_table=0x7, rtm_protocol=RTPROT_BOOT, rtm_scope=RT_SCOPE_UNIVERSE, rtm_type=RTN_UNICAST, rtm_flags=0}, [[{nla_len=8, nla_type=RTA_GATEWAY}, inet_addr(\"192.168.0.8\")], [{nla_len=8, nla_type=RTA_OIF}, if_nametoindex(\"wlo1\")]]], iov_len=44}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 44.

jbaublitz commented 2 weeks ago

Hi @pseusys, I will hopefully have some more time to look into this on the 16th. I will let you know when I get a chance to dig into this a bit more.