Driver function to clear ARP entries?

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.

Reply to
Washington Ratso
Loading thread data ...

Since arp(8) can do this, I assume yes... use the source?

Reply to
larwe

-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,

Reply to
habibielwa7id

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.

Reply to
cs_posting

Here's one really good reason:

Reply to
Thad Floryan

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...
Reply to
Rick Jones

I discovered that calling neigh_ifdown from linux/net/core/neighbor.c does it.

#include 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.

Reply to
Washington Ratso

I discovered that calling neigh_ifdown from linux/net/core/neighbor.c does it.

#include 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.

Reply to
Washington Ratso

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 ;-)

Reply to
cs_posting
[Excessive crossposting without follow-up, so arbitrarily forcing follow-up to comp.os.linux.networking]

Hello,

Washington Ratso a écrit :

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

The 'ip' command is in the iproute package. Without -4 it would flush the IPv6 neighbour cache as well.

Reply to
Pascal Hambourg

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.