Re: Testing ethernet interface status
On 04/01/10 14:21, Peter Steele wrote: What's the best what to test the status of an Ethernet interface programmatically? We've been using this code similar to this: struct ifmediareq ifmr; memset(ifmr, 0, sizeof(ifmr)); strcpy(ifmr.ifm_name, nfe0); ioctl(sockfd, SIOCGIFMEDIA, (caddr_t)ifmr) and then checking the value of ifmr.ifm_status IFM_ACTIVE. We've found that every once in a while this code will return a false positive, indicating that the interface has gone offline when in fact it has not. So, is there a more reliable call to test if an Ethernet interface has gone offline? I was going to suggest that you look at the ifconfig(8) source code, but then I did so myself - it looks like you're doing it pretty much exactly how they are. I've never noticed ifconfig(8) returning an incorrect value, not to say it's not possible. Are you sure that nothing is causing interface state resets? i.e. mismatched duplex/speed settings between the FreeBSD machine and the switch? Have you checked dmesg(8) for logs of interface state changes? You can also check the output of 'netstat -i' to check for interface errors. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
Re: Testing ethernet interface status
I don't remember everything, but I used to do a program to do that. You should also check ifmr.ifm_active value. There was some strange behaviour (obviously normal, but unexpected when I coded it), about up/down interfaces and plug or unplugged cables and yep, ifconfig's doing it 'wrong' :) Samuel Martín Moro {EPITECH.} tek4 CamTrace S.A.S On Thu, Apr 1, 2010 at 8:56 PM, Steve Polyack kor...@comcast.net wrote: On 04/01/10 14:21, Peter Steele wrote: What's the best what to test the status of an Ethernet interface programmatically? We've been using this code similar to this: struct ifmediareq ifmr; memset(ifmr, 0, sizeof(ifmr)); strcpy(ifmr.ifm_name, nfe0); ioctl(sockfd, SIOCGIFMEDIA, (caddr_t)ifmr) and then checking the value of ifmr.ifm_status IFM_ACTIVE. We've found that every once in a while this code will return a false positive, indicating that the interface has gone offline when in fact it has not. So, is there a more reliable call to test if an Ethernet interface has gone offline? I was going to suggest that you look at the ifconfig(8) source code, but then I did so myself - it looks like you're doing it pretty much exactly how they are. I've never noticed ifconfig(8) returning an incorrect value, not to say it's not possible. Are you sure that nothing is causing interface state resets? i.e. mismatched duplex/speed settings between the FreeBSD machine and the switch? Have you checked dmesg(8) for logs of interface state changes? You can also check the output of 'netstat -i' to check for interface errors. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org
RE: Testing ethernet interface status
I was going to suggest that you look at the ifconfig(8) source code, but then I did so myself - it looks like you're doing it pretty much exactly how they are. I've never noticed ifconfig(8) returning an incorrect value, not to say it's not possible. Are you sure that nothing is causing interface state resets? i.e. mismatched duplex/speed settings between the FreeBSD machine and the switch? Have you checked dmesg(8) for logs of interface state changes? You can also check the output of 'netstat -i' to check for interface errors. I should have added that when our own monitoring code flags one of these false positives, there is no entry in /var/log/messages indicating that the nic has gone offine. I added a second call to confirm that indeed the interface is offline, and this second check seems to have largely solved the problem, but we have seen a case where even two consecutive checks return false positives. Maybe we need three tests? ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org