1
0
Fork 0
mirror of https://passt.top/passt synced 2025-06-19 13:35:34 +02:00

netlink: Add functionality to copy addresses from outer namespace

Similarly to what we've just done with routes, support NL_DUP for
addresses (currently not exposed): nl_addr() can optionally copy
mulitple addresses to the target namespace, by fixing up data from
the dump with appropriate flags and interface index, and repeating
it back to the kernel on the socket opened in the target namespace.

Link-local addresses are not copied: the family is set to AF_UNSPEC,
which means the kernel will ignore them. Same for addresses from a
mismatching address (pre-4.19 kernels without support for
NETLINK_GET_STRICT_CHK).

Ignore IFA_LABEL attributes by changing their type to IFA_UNSPEC,
because in general they will report mismatching names, and we don't
really need to use labels as we already know the interface index.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
Stefano Brivio 2023-05-14 18:44:53 +02:00
parent a7359f0948
commit e89da3cf03
4 changed files with 58 additions and 24 deletions

8
conf.c
View file

@ -645,8 +645,10 @@ static unsigned int conf_ip4(unsigned int ifi,
if (IN4_IS_ADDR_UNSPECIFIED(&ip4->gw))
nl_route(NL_GET, ifi, 0, AF_INET, &ip4->gw);
if (IN4_IS_ADDR_UNSPECIFIED(&ip4->addr))
nl_addr(0, ifi, AF_INET, &ip4->addr, &ip4->prefix_len, NULL);
if (IN4_IS_ADDR_UNSPECIFIED(&ip4->addr)) {
nl_addr(NL_GET, ifi, 0, AF_INET,
&ip4->addr, &ip4->prefix_len, NULL);
}
if (!ip4->prefix_len) {
in_addr_t addr = ntohl(ip4->addr.s_addr);
@ -696,7 +698,7 @@ static unsigned int conf_ip6(unsigned int ifi,
if (IN6_IS_ADDR_UNSPECIFIED(&ip6->gw))
nl_route(NL_GET, ifi, 0, AF_INET6, &ip6->gw);
nl_addr(0, ifi, AF_INET6,
nl_addr(NL_GET, ifi, 0, AF_INET6,
IN6_IS_ADDR_UNSPECIFIED(&ip6->addr) ? &ip6->addr : NULL,
&prefix_len, &ip6->addr_ll);