Re: [RFC][2.4 PATCH] source address selection for ARP requests

From: Willy Tarreau
Date: Wed Aug 20 2003 - 18:05:14 EST


On Wed, Aug 20, 2003 at 03:35:48PM -0700, David S. Miller wrote:
> On Thu, 21 Aug 2003 00:27:10 +0200
> Willy Tarreau <willy@xxxxxxxxx> wrote:
>
> > + if (in_dev == NULL)
> > + in_dev_put(in_dev);
>
> What the heck is this? :-)

Hmmm... don't you see ? A copy-paste bug, of course ! Sorry for this, I hope
noone's fool enough to use it as-is. I guess it's becoming late, and I'm a bit
weak in front of my temptations to use 'dd' .... 'P' in vi !

Here's the fixed one (hand-edited, not tested). At least, I'm happy to see that
I'm not the only one reading other's patches :-)

BTW, you didn't tell me if it's necessary to test in_dev->ifa_list. I see that
I kept the test in patch 1 but removed it in patch 2.

Willy

patch 1 :

diff -urN linux-2.4.22-rc2/net/ipv4/arp.c linux-2.4.22-rc2-arp/net/ipv4/arp.c
--- linux-2.4.22-rc2/net/ipv4/arp.c Fri Aug 1 23:06:29 2003
+++ linux-2.4.22-rc2-arp/net/ipv4/arp.c Thu Aug 21 00:20:19 2003
@@ -320,13 +320,20 @@
u32 saddr;
u8 *dst_ha = NULL;
struct net_device *dev = neigh->dev;
+ struct in_device *in_dev = in_dev_get(dev);
u32 target = *(u32*)neigh->primary_key;
int probes = atomic_read(&neigh->probes);

- if (skb && inet_addr_type(skb->nh.iph->saddr) == RTN_LOCAL)
+ if (in_dev == NULL || in_dev->ifa_list == NULL ||
+ (skb && inet_addr_type(skb->nh.iph->saddr) == RTN_LOCAL &&
+ (IN_DEV_SHARED_MEDIA(in_dev) ||
+ inet_addr_onlink(in_dev, skb->nh.iph->saddr, 0))))
saddr = skb->nh.iph->saddr;
else
saddr = inet_select_addr(dev, target, RT_SCOPE_LINK);
+
+ if (in_dev != NULL)
+ in_dev_put(in_dev);

if ((probes -= neigh->parms->ucast_probes) < 0) {
if (!(neigh->nud_state&NUD_VALID))


patch 2 :

diff -urN linux-2.4.22-rc2/net/ipv4/arp.c linux-2.4.22-rc2-arp2/net/ipv4/arp.c
--- linux-2.4.22-rc2/net/ipv4/arp.c Fri Aug 1 23:06:29 2003
+++ linux-2.4.22-rc2-arp2/net/ipv4/arp.c Thu Aug 21 00:24:25 2003
@@ -320,13 +320,19 @@
u32 saddr;
u8 *dst_ha = NULL;
struct net_device *dev = neigh->dev;
+ struct in_device *in_dev = in_dev_get(dev);
u32 target = *(u32*)neigh->primary_key;
int probes = atomic_read(&neigh->probes);

- if (skb && inet_addr_type(skb->nh.iph->saddr) == RTN_LOCAL)
- saddr = skb->nh.iph->saddr;
+ if (skb && inet_addr_type(skb->nh.iph->saddr) == RTN_LOCAL &&
+ (in_dev == NULL || IN_DEV_SHARED_MEDIA(in_dev) ||
+ (saddr = inet_select_addr(dev, target, RT_SCOPE_LINK)) == 0))
+ saddr = skb->nh.iph->saddr;
else
saddr = inet_select_addr(dev, target, RT_SCOPE_LINK);
+
+ if (in_dev != NULL)
+ in_dev_put(in_dev);

if ((probes -= neigh->parms->ucast_probes) < 0) {
if (!(neigh->nud_state&NUD_VALID))


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/