diff options
author | Thomas Haller <thaller@redhat.com> | 2020-01-10 16:06:39 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-01-10 16:06:46 +0100 |
commit | e5f74cdf87973ba1ae3afd75f70bb2461715715d (patch) | |
tree | c95333a242363baa4433e93defcc6953ef204012 | |
parent | 930b97492e35d7480d50c2fbd29213eacdeac887 (diff) | |
download | NetworkManager-th/ifa-broadcast.tar.gz |
platform: generate IFA_BROADCAST address based on the peer IFA_ADDRESSth/ifa-broadcast
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
-rw-r--r-- | src/platform/nm-platform.h | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index f1acd1df1e..bd99052b3e 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -1171,10 +1171,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; } |