mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-15 08:00:37 +01:00
platform: generate IFA_BROADCAST address based on the peer IFA_ADDRESS
This is also what iproute2 does ([1]) when creating a default broadcast address
with `ip addr add 192.168.1.5/24 brd + dev eth0`.
Also, kernel does in fib_add_ifaddr() ([2]):
```
__be32 addr = ifa->ifa_local;
__be32 prefix = ifa->ifa_address & mask;
...
/* Add broadcast address, if it is explicitly assigned. */
if (ifa->ifa_broadcast && ifa->ifa_broadcast != htonl(0xFFFFFFFF))
fib_magic(RTM_NEWROUTE, RTN_BROADCAST, ifa->ifa_broadcast, 32,
prim, 0);
if (!ipv4_is_zeronet(prefix) && !(ifa->ifa_flags & IFA_F_SECONDARY) &&
(prefix != addr || ifa->ifa_prefixlen < 32)) {
if (!(ifa->ifa_flags & IFA_F_NOPREFIXROUTE))
fib_magic(RTM_NEWROUTE,
dev->flags & IFF_LOOPBACK ? RTN_LOCAL : RTN_UNICAST,
prefix, ifa->ifa_prefixlen, prim,
ifa->ifa_rt_priority);
/* Add network specific broadcasts, when it takes a sense */
if (ifa->ifa_prefixlen < 31) {
fib_magic(RTM_NEWROUTE, RTN_BROADCAST, prefix, 32,
prim, 0);
fib_magic(RTM_NEWROUTE, RTN_BROADCAST, prefix | ~mask,
32, prim, 0);
}
}
```
Which means by default kernel already adds those special broadcast routes which
are identical to what we configure with IFA_BROADCAST. However, kernel too bases
them on the peer (IFA_ADDRESS).
[1] https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/tree/ip/ipaddress.c?id=d5391e186f04214315a5a80797c78e50ad9f5271#n2380
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/ipv4/fib_frontend.c?id=bef1d88263ff769f15aa0e1515cdcede84e61d15#n1109
This commit is contained in:
parent
71d5550547
commit
7910333527
1 changed files with 4 additions and 3 deletions
|
|
@ -1175,10 +1175,11 @@ nm_platform_ip4_broadcast_address_from_addr (const NMPlatformIP4Address *addr)
|
|||
if (addr->use_ip4_broadcast_address)
|
||||
return addr->broadcast_address;
|
||||
|
||||
/* the set broadcast-address gets ignored, and we determine a default brd. */
|
||||
if ( addr->address != 0u
|
||||
/* the set broadcast-address gets ignored, and we determine a default brd base
|
||||
* on the peer IFA_ADDRESS. */
|
||||
if ( addr->peer_address != 0u
|
||||
&& addr->plen < 31 /* RFC3021 */)
|
||||
return nm_platform_ip4_broadcast_address_create (addr->address, addr->plen);
|
||||
return nm_platform_ip4_broadcast_address_create (addr->peer_address, addr->plen);
|
||||
return 0u;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue