Skip to content

Commit 7b13118

Browse files
Paolo Abenidavem330
authored andcommitted
ipv4: implement support for NOPREFIXROUTE ifa flag for ipv4 address
Currently adding a new ipv4 address always cause the creation of the related network route, with default metric. When a host has multiple interfaces on the same network, multiple routes with the same metric are created. If the userspace wants to set specific metric on each routes, i.e. giving better metric to ethernet links in respect to Wi-Fi ones, the network routes must be deleted and recreated, which is error-prone. This patch implements the support for IFA_F_NOPREFIXROUTE for ipv4 address. When an address is added with such flag set, no associated network route is created, no network route is deleted when said IP is gone and it's up to the user space manage such route. Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c0c050c commit 7b13118

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

net/ipv4/fib_frontend.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -867,9 +867,10 @@ void fib_add_ifaddr(struct in_ifaddr *ifa)
867867

868868
if (!ipv4_is_zeronet(prefix) && !(ifa->ifa_flags & IFA_F_SECONDARY) &&
869869
(prefix != addr || ifa->ifa_prefixlen < 32)) {
870-
fib_magic(RTM_NEWROUTE,
871-
dev->flags & IFF_LOOPBACK ? RTN_LOCAL : RTN_UNICAST,
872-
prefix, ifa->ifa_prefixlen, prim);
870+
if (!(ifa->ifa_flags & IFA_F_NOPREFIXROUTE))
871+
fib_magic(RTM_NEWROUTE,
872+
dev->flags & IFF_LOOPBACK ? RTN_LOCAL : RTN_UNICAST,
873+
prefix, ifa->ifa_prefixlen, prim);
873874

874875
/* Add network specific broadcasts, when it takes a sense */
875876
if (ifa->ifa_prefixlen < 31) {
@@ -914,9 +915,10 @@ void fib_del_ifaddr(struct in_ifaddr *ifa, struct in_ifaddr *iprim)
914915
}
915916
} else if (!ipv4_is_zeronet(any) &&
916917
(any != ifa->ifa_local || ifa->ifa_prefixlen < 32)) {
917-
fib_magic(RTM_DELROUTE,
918-
dev->flags & IFF_LOOPBACK ? RTN_LOCAL : RTN_UNICAST,
919-
any, ifa->ifa_prefixlen, prim);
918+
if (!(ifa->ifa_flags & IFA_F_NOPREFIXROUTE))
919+
fib_magic(RTM_DELROUTE,
920+
dev->flags & IFF_LOOPBACK ? RTN_LOCAL : RTN_UNICAST,
921+
any, ifa->ifa_prefixlen, prim);
920922
subnet = 1;
921923
}
922924

0 commit comments

Comments
 (0)