netlink: Split nl_addr() into separate operation functions
nl_addr() can perform three quite different operations based on the 'op' parameter, each of which uses a different subset of the parameters. Split them up into a function for each operation. This does use more lines of code, but the overlap wasn't that great, and the separated logic is much easier to follow. It's also clearer in the callers what we expect the netlink operations to do, and what information it uses. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> [sbrivio: Minor formatting fixes in pasta_ns_conf()] Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:

committed by
Stefano Brivio

parent
e96182e9c2
commit
eff3bcb245
12
conf.c
12
conf.c
@@ -651,10 +651,8 @@ 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(NL_GET, ifi, 0, AF_INET,
|
||||
&ip4->addr, &ip4->prefix_len, NULL);
|
||||
}
|
||||
if (IN4_IS_ADDR_UNSPECIFIED(&ip4->addr))
|
||||
nl_addr_get(ifi, AF_INET, &ip4->addr, &ip4->prefix_len, NULL);
|
||||
|
||||
if (!ip4->prefix_len) {
|
||||
in_addr_t addr = ntohl(ip4->addr.s_addr);
|
||||
@@ -704,9 +702,9 @@ 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(NL_GET, ifi, 0, AF_INET6,
|
||||
IN6_IS_ADDR_UNSPECIFIED(&ip6->addr) ? &ip6->addr : NULL,
|
||||
&prefix_len, &ip6->addr_ll);
|
||||
nl_addr_get(ifi, AF_INET6,
|
||||
IN6_IS_ADDR_UNSPECIFIED(&ip6->addr) ? &ip6->addr : NULL,
|
||||
&prefix_len, &ip6->addr_ll);
|
||||
|
||||
memcpy(&ip6->addr_seen, &ip6->addr, sizeof(ip6->addr));
|
||||
memcpy(&ip6->addr_ll_seen, &ip6->addr_ll, sizeof(ip6->addr_ll));
|
||||
|
Reference in New Issue
Block a user