I need to access IF_RA_MANAGED
and IF_RA_OTHERCONF
(in6_dev->if_flags
) from userspace.
Does anyone know how can I do it?
Thanks
I need to access IF_RA_MANAGED
and IF_RA_OTHERCONF
(in6_dev->if_flags
) from userspace.
Does anyone know how can I do it?
Thanks
I think you can do this with a PF_NETLINK
socket.
The ip
utility, which is part of iproute2
has a monitor mode that appears to show this information, for example:
ajw@rapunzel:/tmp/iproute-20100519/ip > ip -6 monitor
2: eth0 inet6 2001:XXXX:XXXX:0:XXXX:XXXX:XXXX:XXXX/64 scope global dynamic
valid_lft 86400sec preferred_lft 14400sec
prefix 2001:XXXX:XXXX::X/64 dev eth0 onlink autoconf valid 14400 preferred 131084
(Some exact addresses removed for paranoia's sake). I don't have any RAs with those flags set on this LAN, but I'm 99% sure they would show up there too.
Poking around with strace
shows the interesting calls seem to be:
socket(PF_NETLINK, SOCK_RAW, 0) = 3
setsockopt(3, SOL_SOCKET, SO_SNDBUF, [32768], 4) = 0
setsockopt(3, SOL_SOCKET, SO_RCVBUF, [1048576], 4) = 0
bind(3, {sa_family=AF_NETLINK, pid=0, groups=fffffff7}, 12) = 0
getsockname(3, {sa_family=AF_NETLINK, pid=7151, groups=fffffff7}, [12]) = 0
time(NULL) = 1309595579
send(3, "...", 20, 0) = 20
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"...", 16384}], msg_controllen=0, msg_flags=0}, 0) = 864
The source for iproute2
has a file, ip/ipmonitor.c
, which seems to do most of the work:
int print_prefix(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);
int accept_msg(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg)
{
// Snipped some unrelated stuff
if (n->nlmsg_type == RTM_NEWPREFIX) {
if (prefix_banner)
fprintf(fp, "[PREFIX]");
print_prefix(who, n, arg);
return 0;
}
}
So I think you should be able to put together a solution using this.
This question is now answered in its duplicate"Where m flag and o flag will be stored in Linux". Specifically, the questions poster found a solution to his problem and posted the code in a blog at http://kumaran127.blogspot.jp/2013/05/get-m-and-o-flag-of-most-recently.html.