IFF_NOARP & broadcasting
Subsystems (2)
Hello!
Is there any serious reason why when device has IFF_NOARP set, devices ll address is used as destination address even for broadcasts (and even when devices broadcast address is valid)? Currently it is impossible to send out correct broadcast over ethernet when IFF_NOARP is set.
The code in question is in net/ipv4/arp.c, function arp_constructor:
if (neigh->type == RTN_MULTICAST) {
neigh->nud_state = NUD_NOARP;
arp_mc_map(addr, neigh->ha, dev, 1);
} else if (dev->flags&(IFF_NOARP|IFF_LOOPBACK)) {
^^^^^^^^^
neigh->nud_state = NUD_NOARP;
memcpy(neigh->ha, dev->dev_addr, dev->addr_len);
} else if (neigh->type == RTN_BROADCAST ||
dev->flags&IFF_POINT neigh->nud_state = NUD_NOARP;
memcpy(neigh->ha, dev->broadcast, dev->addr_len);
}Is it ok to apply following patch and not break anything:
arp.c renamed from arp.c.orig +1 -1
@@ -289,12 +289,15 @@if (neigh->type ==RTN_MULTICAST ) { neigh->nud_state =NUD_NOARP ;arp_mc_map (addr, neigh->ha, dev,1 ); - }else if (dev->flags&(IFF_NOARP |IFF_LOOPBACK )) { + }else if (dev->flags&IFF_LOOPBACK ) { neigh->nud_state =NUD_NOARP ;memcpy (neigh->ha, dev->dev_addr, dev->addr_len); } else if (neigh->type == RTN_BROADCAST ||
dev->flags&IFF_POINTOPOINT) {
neigh->nud_state = NUD_NOARP; memcpy(neigh->ha, dev->broadcast, dev->addr_len);
+ } else if (dev->flags & IFF_NOARP) {
+ neigh->nud_state = NUD_NOARP;
+ memcpy(neigh->ha, dev->dev_addr, dev->addr_len);
}
if (dev->hard_header_cache)
neigh->ops = &arp_hh_ops;
Hello!
Quoted 3 lines
Is there any serious reason why when device has
IFF_NOARPset, devices ll address is used as destination address even for broadcasts (and even when devices broadcast address is valid)?
No reasons, I think. Instead of that your patch, it may be better just exchange order of tests. As I remember, ll addr is initialized to dev_addr for NOARP just to get a valid unicast address as destination for eth_type_trans() to work correctly.
Quoted 2 lines
Currently it is impossible to send out correct broadcast over ethernet when
IFF_NOARPis set.
No, it is surely not impossible. f.e.
ip neigh add 255.255.255.255 dev dummy0 lladdr ff:ff:ff:ff:ff:ff
works.
Alexey
Quoted 6 lines · On Wed, 24 Jul 2002 [email protected] wrote:
Quoted 3 lines
Is there any serious reason why when device has
IFF_NOARPset, devices ll address is used as destination address even for broadcasts (and even when devices broadcast address is valid)?No reasons, I think. Instead of that your patch, it may be better just exchange order of tests. As I remember, ll addr is initialized
Ok, please consider the attached patch.
Quoted 3 lines
No, it is surely not impossible. f.e.
ip neigh add 255.255.255.255 dev dummy0 lladdr ff:ff:ff:ff:ff:ff
Umm, did not think of this. Anyway, this forces to add one neigh for each broadcast address in use on interface.
Here comes the patch:
arp.c renamed from arp.c.orig +3 -3
@@ -289,12 +289,12 @@if (neigh->type ==RTN_MULTICAST ) { neigh->nud_state =NUD_NOARP ;arp_mc_map (addr, neigh->ha, dev,1 ); - }else if (dev->flags&(IFF_NOARP |IFF_LOOPBACK )) { - neigh->nud_state =NUD_NOARP ; -memcpy (neigh->ha, dev->dev_addr, dev->addr_len); }else if (neigh->type ==RTN_BROADCAST || dev->flags&IFF_POINTOPOINT ) { neigh->nud_state =NUD_NOARP ;memcpy (neigh->ha, dev->broadcast, dev->addr_len); + }else if (dev->flags&(IFF_NOARP |IFF_LOOPBACK )) { + neigh->nud_state =NUD_NOARP ; +memcpy (neigh->ha, dev->dev_addr, dev->addr_len); }if (dev->hard_header_cache) neigh->ops = &arp_hh_ops;
Karlis
Re: IFF_NOARP & broadcasting [2]
In reply to [email protected]Quoted 3 lines · On 2002.07.24 19:52 [email protected] wrote:
No, it is surely not impossible. f.e.
ip neigh add 255.255.255.255 dev dummy0 lladdr ff:ff:ff:ff:ff:ff
Ok, but even in this case there is minor problem. And it lies in net/ethernet/eth.c - eth_header.
neigh_resolve_output creates header cache with correct ll source and ll destination as in neighbour, but uses dev->hard_header to build header for first packet. And eth_header has code:
if (dev->flags & (IFF_LOOPBACK|IFF_NOARP))
{
memset(eth->h_dest, 0, dev->addr_len);
return(dev->hard_header_len);
}which explicitly sets ll destination to all 0s. For all next packets hh_cache is used and they get correct ll address (as in neighbour).
Please comment on this patch :) :
eth.c renamed from eth.c.orig +0 -0
@@ -100,7 +100,7 @@* Anyway, the loopback-device should never use this
function...
*/
- if (dev->flags & (IFF_LOOPBACK|IFF_NOARP))
+ if (dev->flags & IFF_LOOPBACK)
{
memset(eth->h_dest, 0, dev->addr_len); return(dev->hard_header_len);
Karlis
Re: IFF_NOARP & broadcasting [2]
Hello!
Quoted 2 lines
Ok, but even in this case there is minor problem. And it lies in
net/ethernet/eth.c-eth_header.
You have just made great discovery. :-)
It was big puzzle why people blame that they see packets with zero MAC, sometimes. Apparently, this happens on the first packet, when hh cache is still not created. :-)
Quoted 1 line
Please comment on this patch :) :
I am not sure that this is right. Protocols using neighbour cache will work, but anothers will fail on NOARP devices.
It is safer just to reorder two ifs, checking for daddr!=NULL first.
Alexey
Re: IFF_NOARP & broadcasting [2]
Quoted 5 lines · On 2002.07.25 17:02 [email protected] wrote:
You have just made great discovery. :-)
It was big puzzle why people blame that they see packets with zero MAC, sometimes. Apparently, this happens on the first packet, when hh cache is still not created. :-)
Yes, this was killing me too.
Quoted 4 lines
I am not sure that this is right. Protocols using neighbour cache will work, but anothers will fail on NOARP devices.
It is safer just to reorder two ifs, checking for daddr!=NULL first.
You mean like this:
eth.c renamed from eth.c.orig +6 -0
@@ -96,6 +96,12 @@else memcpy (eth->h_source,dev->dev_addr,dev->addr_len); +if (daddr) + { +memcpy (eth->h_dest,daddr,dev->addr_len); +return dev->hard_header_len; + } +/* * Anyway, the loopback-device should never use this
function...
*/
@@ -106,12 +112,6 @@
return(dev->hard_header_len);
}
- if(daddr)
- {
- memcpy(eth->h_dest,daddr,dev->addr_len);
- return dev->hard_header_len;
- }
-
return -dev->hard_header_len;
}
Karlis