Re: Netlink Implementation.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Eric Bambach wrote:
On Friday 22 October 2004 05:51 pm, Eric Bambach wrote:

On Wednesday 20 October 2004 08:17 pm, Eric Bambach wrote:

Hello,

In response to my previous message, maybe my questions were not specific enough. I have been debugging/understanding the code for a little time now and constantly run into this problem. I get a SIGSEGV here


Hello again code gurus :)

Yes another fight in my netlink saga. Thanks to all who have replied before and I have learned alot from the rfc's and zebra/iproute and have contructed a much more robust implementation. I have sent the kernel a message defined as below. However I have not learned what exactly I should be expecting from the kernel. That is, my message gets a reply from the kernel about eth0, however on my machine i have eth0,1,2,ppp0 and I would like information about them all. I have NLM_F_ROOT set on the packet as I was under the impression that this would dump information about all the interfaces. I have also tried incrementing msg.info.ifi_index to 0,1,2,3 etc. No matter what these values I always recieve this output form my program.
#./nl_test_prog
Found device: eth0 - 1
Found address: <--(Dont care about blank yet, main problem is only
1 if shows. This is minor)


-Am I wrong to expect the kernel to send me data about all the interfaces? -Am I calling this wrong?
-What can I do to query all the interfaces?


I do loop through all the rta messages and I receive only 1 packet from the kernel when calling recvmsg(). I have also tried without OR'ing NLM_F_MATCH. I have run it through a debugger and confirmed although there are multiple RTA atributes in my netlink packet, they all refer to eth0.

-Should I be expecting multiple packets (NLM_F_MULTI)?

Here is my nl_packet construction.

msg.hdr.nlmsg_len = sizeof(msg);
msg.hdr.nlmsg_type = RTM_GETLINK;
msg.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT | NLM_F_MATCH; msg.hdr.nlmsg_pid = getpid();
msg.hdr.nlmsg_seq = seq++; msg.info.ifi_family = AF_UNSPEC; //AF_UNSPEC for ipv4
msg.info.ifi_type = NETLINK_ROUTE;
msg.info.ifi_index = 0;
msg.info.ifi_change = (0-1);


----------------Looping over the attributes later in code--------------
/* Loop over the attributes in this message */
while(RTA_OK(rta, len))
{
switch(rta->rta_type)
{
case IFLA_IFNAME:
cout << "Found device: " << (char *)RTA_DATA(rta)<< " - " << info->ifi_index << endl;
break;
case IFLA_ADDRESS:
cout << "Found address: " << (char *)RTA_DATA(rta) << endl;
break;
}
rta = RTA_NEXT(rta, len);
/* We hit the next packet */
}// Packet Looping while()



More info/code available upon request.

Any help would be appreciated.

----------------------------------------
EB

Stephen H. is correct, the iproute2.c code is probably going to be your best guide. You don't have all your code posted here, so its not possible to tell, but if I had to guess, I would say that your likely just not receiving the entire netlink message. How big is the buffer that you pass to recvmsg/recvfrom? I would bet that at the netlink (not NETLINK_ROUTE or rtnetlink) level, you have a truncated message. This is indicated if the nlmsg_flags field of the netlink header will have the NLM_F_MULTI bit set. If this bit is set, the entire datagram will be terminated with a netlink message that has an nlmsg_type field set as NLMSG_DONE. In the event you test for, and encounter this NLM_F_MULTI bit, you should check to see if you have an NLMSG_DONE message type, and if not, process the message as normal, and then call receive again. The next segment of the message will be written to your buffer then. Repeat this process until you receive a nlmsghdr structure with NLMSG_DONE set as the type.
HTH
Neil
--
/***************************************************
*Neil Horman
*Software Engineer
*Red Hat, Inc.
*nhorman@redhat.com
*gpg keyid: 1024D / 0x92A74FA1
*http://pgp.mit.edu
***************************************************/
-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux