lifecycle: simplify netmask fallback path

This commit is contained in:
Ariadne Conill 2020-07-25 01:02:05 -06:00
parent 60633e4acb
commit d582e405b6

View file

@ -74,13 +74,9 @@ static bool
handle_address(const struct lif_execute_opts *opts, struct lif_address *addr, const char *cmd, const char *lifname, struct lif_interface *iface) handle_address(const struct lif_execute_opts *opts, struct lif_address *addr, const char *cmd, const char *lifname, struct lif_interface *iface)
{ {
char addrbuf[4096]; char addrbuf[4096];
size_t orig_netmask = addr->netmask;
if (addr->netmask) if (!addr->netmask)
{
if (!lif_address_unparse(addr, addrbuf, sizeof addrbuf, true))
return false;
}
else
{ {
/* if fallback netmask is not set, default to 255.255.255.0 */ /* if fallback netmask is not set, default to 255.255.255.0 */
addr->netmask = 24; addr->netmask = 24;
@ -88,13 +84,13 @@ handle_address(const struct lif_execute_opts *opts, struct lif_address *addr, co
struct lif_dict_entry *entry = lif_dict_find(&iface->vars, "netmask"); struct lif_dict_entry *entry = lif_dict_find(&iface->vars, "netmask");
if (entry != NULL) if (entry != NULL)
addr->netmask = count_set_bits(entry->data); addr->netmask = count_set_bits(entry->data);
}
if (!lif_address_unparse(addr, addrbuf, sizeof addrbuf, false)) if (!lif_address_unparse(addr, addrbuf, sizeof addrbuf, true))
return false; return false;
/* reset cidrlen */ /* reset the netmask */
addr->netmask = 0; addr->netmask = orig_netmask;
}
return lif_execute_fmt(opts, NULL, "/sbin/ip -%d addr %s %s dev %s", return lif_execute_fmt(opts, NULL, "/sbin/ip -%d addr %s %s dev %s",
addr->domain == AF_INET ? 4 : 6, cmd, addrbuf, lifname); addr->domain == AF_INET ? 4 : 6, cmd, addrbuf, lifname);