-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Route multicast events (with nl_pid > 0
) are ignored
#218
Comments
Just used recvfrom(9, [
{
nlmsg_len=80,
nlmsg_type=RTM_NEWADDR,
nlmsg_flags=0,
nlmsg_seq=1688203532,
nlmsg_pid=8187
},
{
ifa_family=AF_INET,
ifa_prefixlen=32,
ifa_flags=IFA_F_PERMANENT,
ifa_scope=RT_SCOPE_UNIVERSE,
ifa_index=if_nametoindex("wlan0")
},
[
[
{
nla_len=8,
nla_type=IFA_ADDRESS
},
inet_addr("10.0.0.254")
],
[
{
nla_len=8,
nla_type=IFA_LOCAL
},
inet_addr("10.0.0.254")
],
[
{
nla_len=10,
nla_type=IFA_LABEL
},
"wlan0"
],
[
{
nla_len=8,
nla_type=IFA_FLAGS
},
IFA_F_PERMANENT
],
[
{
nla_len=20,
nla_type=IFA_CACHEINFO
},
{
ifa_prefered=4294967295,
ifa_valid=4294967295,
cstamp=38685,
tstamp=38685
}
]
]
], 32768, 0, NULL, NULL) = 80 Is this because I need a specific type before |
I'll update this with any further findings... Debugging Tips
Confusing things...
Findings My current findings are that the This is a combination of So, for some reason - messages received here don't have Is this ignoring of events intended behaviour? ❓ |
I've changed the title - I think this should be updated to a EDIT:
I created #219 in an attempt to fix this. |
NlRouter
seems to ignore multicast events when nl_pid != 0
NlRouter
seems to ignore multicast events when nl_pid != 0
nl_pid
is not 0
when receiving NlFamily::Route
multicast events
nl_pid
is not 0
when receiving NlFamily::Route
multicast eventsnl_pid > 0
are ignored
Alright, the whole thing is working (provided my fork that's in #219 is used). Here's some sample code: // setup socket for netlink route
let (socket, mut multicast) =
NlRouter::connect(NlFamily::Route, None, Groups::empty()).unwrap();
// add multicast membership for ipv4-addr updates
socket
.add_mcast_membership(Groups::new_groups(&[RTNLGRP_IPV4_IFADDR]))
.unwrap();
// listen for multicast events
// NOTE: currently requires the changes here: https://github.com/jbaublitz/neli/pull/219
type Next = Option<Result<Nlmsghdr<u16, Ifaddrmsg>, RouterError<u16, Ifaddrmsg>>>;
match multicast.next_typed::<u16, Ifaddrmsg>() as Next {
None => todo!(),
// we got a multicast message
Some(response) => {
// if there are errors on the multicast channel, they'll be here in this result
let response = response.unwrap();
// get message payload
let ifaddr_msg = response.get_payload().unwrap();
// get a handle to the message's rt attributes
let rt_attrs_handle = ifaddr_msg.rtattrs().get_attr_handle();
// get the address attribute
let addr_attr = rt_attrs_handle.get_attribute(Ifa::Address).unwrap();
// convert the raw bytes from the attribute into an `Ipv4Addr` struct
let bytes: &[u8] = addr_attr.rta_payload().as_ref();
let bytes: &[u8; 4] = bytes.try_into().unwrap();
let ipv4 = Ipv4Addr::from(*bytes);
// 🎉 we did it!
dbg!(ipv4);
}
} I'm leaving this issue open as the tracking issue for ignored multicast events. |
nl_pid > 0
are ignorednl_pid > 0
) are ignored
Again, this issue is now more or less a diary of my experience learning about I think I was originally right, actually. The thing that confused me is reading recvmsg(3, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=0x000010}, msg_namelen=12, msg_iov=[{iov_base=[{nlmsg_len=80, nlmsg_type=RTM_DELADDR, nlmsg_flags=0, nlmsg_seq=1688293504, nlmsg_pid=19010}, {ifa_family=AF_INET, ifa_prefixlen=32, ifa_flags=IFA_F_PERMANENT, ifa_scope=RT_SCOPE_UNIVERSE, ifa_index=if_nametoindex("wlan0")}, [[{nla_len=8, nla_type=IFA_ADDRESS}, inet_addr("10.0.0.254")], [{nla_len=8, nla_type=IFA_LOCAL}, inet_addr("10.0.0.254")], [{nla_len=10, nla_type=IFA_LABEL}, "wlan0"], [{nla_len=8, nla_type=IFA_FLAGS}, IFA_F_PERMANENT], [{nla_len=20, nla_type=IFA_CACHEINFO}, {ifa_prefered=4294967295, ifa_valid=4294967295, cstamp=142503, tstamp=142503}]]], iov_len=16384}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 80 I was confusing the first part of the {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=0x000010} ...thinking that contained the actual {nlmsg_len=80, nlmsg_type=RTM_DELADDR, nlmsg_flags=0, nlmsg_seq=1688293504, nlmsg_pid=19010} So, I believe my previous comments about multicast messages with |
@acheronfail Can you test #209 and let me know if that resolves the issue. Someone else suggested that I use |
Ah yes! Thank you so much, I was going around in circle so many times 😅 I can confirm that works for me! |
I'm trying to make something that functions similar to
nl-monitor ipv4-ifaddr
withneli
, but I'm struggling to get anywhere with it.This is my current attempt:
As far as I can tell, this should be reporting events any time an ipv4 address on the machine changes, but I get no output at all with this setup. I've been looking at how
nl-monitor
works, and comparing that toneli
and they look very similar here, so I'm not sure what's different...Any chance you might know where I should look next? 🙏
The text was updated successfully, but these errors were encountered: