EmbeddedRelated.com
Forums

Driver function to clear ARP entries?

Started by Washington Ratso June 23, 2009
Is there a function that can be called in a Linux network device
driver that can clear the ARP entries for a particular interface?  I
am running Linux 2.6.26 for powerpc.
On Jun 23, 8:41=A0pm, Washington Ratso <jobhunt...@aol.com> wrote:
> Is there a function that can be called in a Linux network device > driver that can clear the ARP entries for a particular interface? =A0I
Since arp(8) can do this, I assume yes... use the source?
On Jun 24, 3:41=A0am, Washington Ratso <jobhunt...@aol.com> wrote:
> Is there a function that can be called in a Linux network device > driver that can clear the ARP entries for a particular interface? =A0I > am running Linux 2.6.26 for powerpc.
-Would you tell me why you want to clear the ARP cache? -I don't know why the people that wrote arp command on Linux didn't enable some option to do so, Or may there is amethod and I don't know it, It can be done on Windows like this arp -d * Some times I was restrting the network service on Linux to clear the ARP cache, Some thing like "/etc/init.d/network restart" will clear the ARP cache and mainly will not close your network connections, try to do a simple search may you will find a better way to do what you want to do, or may they help you here. Regards,
On Jun 24, 4:03=A0am, habibielwa7id <fouad...@gmail.com> wrote:

> -Would you tell me why you want to clear the ARP cache?
A common reason would be unplugging one embedded device and plugging in a different one with the same ip address but a different MAC address. If you don't delete the arp entry you have to wait a bit before you can talk to it. I second the recommendation for looking at the source of arp.c... it's not very long. Looks to me like if there's no global delete function in the kernel, you could get the cache out of /proc/net/arp and simply issue an SIOCDARP ioctl on each entry. You could also perform this with a shoprt shell script to parse the / proc/net/arp and run arp -d on each entry. Actually I think it can be done in one line with grep and xargs, but must admit I'm not getting it to work. You will of course need superuser permission.
On 6/24/2009 1:03 AM, habibielwa7id wrote:
> [...] > -Would you tell me why you want to clear the ARP cache?
Here's one really good reason: <http://linux.derkeiler.com/Newsgroups/comp.os.linux.development.system/2005-03/0315.html>
In comp.os.linux.networking cs_posting@hotmail.com wrote:
> On Jun 24, 4:03?am, habibielwa7id <fouad...@gmail.com> wrote:
> > -Would you tell me why you want to clear the ARP cache?
> A common reason would be unplugging one embedded device and plugging > in a different one with the same ip address but a different MAC > address. If you don't delete the arp entry you have to wait a bit > before you can talk to it.
I'd think that might have issues with (default at least) udev device naming behaviour - isn't that based on MAC address (again, by default)? Anyhow wouldn't the problem in that case be the _remote_ ARP caches, not the one local to the system where the device has been swapped which means that remote drivers would have to have some sort of magic way to know a device was swapped? And isn't that what a gratuitous ARP is supposed to be for? rick jones -- No need to believe in either side, or any side. There is no cause. There's only yourself. The belief is in your own precision. - Joubert these opinions are mine, all mine; HP might not want them anyway... :) feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...
On Jun 23, 5:41=A0pm, Washington Ratso <jobhunt...@aol.com> wrote:
> Is there a function that can be called in a Linux network device > driver that can clear the ARP entries for a particular interface? =A0I > am running Linux 2.6.26 for powerpc.
I discovered that calling neigh_ifdown from linux/net/core/neighbor.c does it. #include <net/neighbour.h> extern struct neigh_table arp_tbl; /* exported in /linux/net/ipv4/ arp.c */ int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev) where: tbl =3D arp_tbl. dev =3D pointer to network device structure of the device that the ARP entries are to be cleared. Thank you for the suggestions.
On Jun 23, 5:41=A0pm, Washington Ratso <jobhunt...@aol.com> wrote:
> Is there a function that can be called in a Linux network device > driver that can clear the ARP entries for a particular interface? =A0I > am running Linux 2.6.26 for powerpc.
I discovered that calling neigh_ifdown from linux/net/core/neighbor.c does it. #include <net/neighbour.h> extern struct neigh_table arp_tbl; /* exported in /linux/net/ipv4/ arp.c */ int neigh_ifdown(struct neigh_table *tbl, struct net_device *dev) where: tbl =3D arp_tbl. dev =3D pointer to network device structure of the device that the ARP entries are to be cleared. Thank you for the suggestions.
On Jun 24, 1:54 pm, Rick Jones <rick.jon...@hp.com> wrote:
> In comp.os.linux.networking cs_post...@hotmail.com wrote: > > On Jun 24, 4:03?am, habibielwa7id <fouad...@gmail.com> wrote: > > > -Would you tell me why you want to clear the ARP cache? > > A common reason would be unplugging one embedded device and plugging > > in a different one with the same ip address but a different MAC > > address. If you don't delete the arp entry you have to wait a bit > > before you can talk to it.
> Anyhow wouldn't the problem in that case be the _remote_ ARP caches,
Sorry I wasn't clearer - I meant plugging and unplugging embedded ethernet devices from the network, and neading to flush the corresponding arp entires from the PC's cache. Or maybe the cache of some embedded master controller. As I'm often running linux on both ends of the wire these days (or writing multi-platform code) I sometimes fail to distinguish between the issues of embedded systems and those of talking to embedded systems.... it's gets funny when you type make and get an error and realize you typed it in the telnet session not the local terminal ;-)
[Excessive crossposting without follow-up, so arbitrarily forcing 
follow-up to comp.os.linux.networking]

Hello,

Washington Ratso a &#4294967295;crit :
> Is there a function that can be called in a Linux network device > driver that can clear the ARP entries for a particular interface?
ARP function is part of the OS TCP/IP stack and independent of the network device. So why would such a function be implemented in the device driver ? Yes, some "smart" network adapters do all sorts of offloading (TCP segmentation and so on) and may take care of ARP on behalf of the OS, but this is not a general behaviour for all adapters. If what you want is just flushing the ARP entries related to an interface : ip -4 neigh flush dev <interface> The 'ip' command is in the iproute package. Without -4 it would flush the IPv6 neighbour cache as well.