Discussion:
Driver function to clear ARP entries?
(too old to reply)
Washington Ratso
2009-06-24 00:41:17 UTC
Permalink
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.
larwe
2009-06-24 01:31:11 UTC
Permalink
Post by Washington Ratso
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
Since arp(8) can do this, I assume yes... use the source?
habibielwa7id
2009-06-24 08:03:39 UTC
Permalink
Post by Washington Ratso
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.
-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,
c***@hotmail.com
2009-06-24 14:20:40 UTC
Permalink
Post by habibielwa7id
-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.
Rick Jones
2009-06-24 17:54:38 UTC
Permalink
Post by c***@hotmail.com
Post by habibielwa7id
-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...
c***@hotmail.com
2009-06-25 03:00:01 UTC
Permalink
Post by Rick Jones
Post by c***@hotmail.com
Post by habibielwa7id
-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 ;-)
Thad Floryan
2009-06-24 14:53:45 UTC
Permalink
Post by habibielwa7id
[...]
-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>
Washington Ratso
2009-06-24 21:47:11 UTC
Permalink
Post by Washington Ratso
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.
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 = arp_tbl.
dev = pointer to network device structure of the device
that the ARP entries are to be cleared.



Thank you for the suggestions.
Washington Ratso
2009-06-24 21:47:30 UTC
Permalink
Post by Washington Ratso
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.
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 = arp_tbl.
dev = pointer to network device structure of the device
that the ARP entries are to be cleared.



Thank you for the suggestions.
Pascal Hambourg
2009-06-25 09:52:47 UTC
Permalink
[Excessive crossposting without follow-up, so arbitrarily forcing
follow-up to comp.os.linux.networking]

Hello,
Post by Washington Ratso
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.

Loading...