Skip to content

Commit

Permalink
Merge pull request #658 from mtomaschewski/ip-opts
Browse files Browse the repository at this point in the history
  • Loading branch information
mtomaschewski committed Jul 1, 2016
2 parents 9516121 + 75d9045 commit 91f3c3b
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
20 changes: 20 additions & 0 deletions client/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,7 @@ __ni_compat_generate_static_address_list(xml_node_t *afnode, ni_address_t *addr_
{
ni_address_t *ap;
xml_node_t *anode;
const char *ptr;

for (ap = addr_list; ap; ap = ap->next) {
if (ap->family != af)
Expand All @@ -1832,6 +1833,25 @@ __ni_compat_generate_static_address_list(xml_node_t *afnode, ni_address_t *addr_
xml_node_new_element("broadcast", anode, ni_sockaddr_print(&ap->bcast_addr));
if (af == AF_INET && ap->label)
xml_node_new_element("label", anode, ap->label);

if (ap->scope >= 0 && (ptr = ni_route_scope_type_to_name(ap->scope)))
xml_node_new_element("scope", anode, ptr);

if (ap->flags)
xml_node_new_element_uint("flags", anode, ap->flags);

/* We are applying static address, but at least valid_lft=infinite,
* preferred_lft=0 is a valid case to apply deprecated addresses...
*/
if ((ap->ipv6_cache_info.valid_lft || ap->ipv6_cache_info.preferred_lft)) {
xml_node_t *cache_info = xml_node_new("cache-info", afnode);
if (cache_info) {
xml_node_new_element_uint("valid-lifetime", cache_info,
ap->ipv6_cache_info.valid_lft);
xml_node_new_element_uint("preferred-lifetime", cache_info,
ap->ipv6_cache_info.preferred_lft);
}
}
}
}

Expand Down
84 changes: 84 additions & 0 deletions client/suse/compat-suse.c
Original file line number Diff line number Diff line change
Expand Up @@ -4198,6 +4198,71 @@ try_tunnel(const ni_sysconfig_t *sc, ni_compat_netdev_t *compat)
* BROADCAST_x
* REMOTE_IPADDR_x
*/
static ni_bool_t
__get_ipaddr_lft(const char *val, unsigned int *lft)
{
if (ni_string_eq(val, "forever") || ni_string_eq(val, "infinite"))
*lft = NI_LIFETIME_INFINITE;
else
if (!ni_parse_uint(val, lft, 0))
return FALSE;
return TRUE;
}

static ni_bool_t
__get_ipaddr_opts(const char *value, ni_address_t *ap)
{
ni_string_array_t opts = NI_STRING_ARRAY_INIT;
const char *opt, *val;
unsigned int pos = 0;
ni_bool_t ret = TRUE;

/*
* All about ipv6 -- anything useful to consider for ipv4?
*/
if (ap->family != AF_INET6)
return TRUE;

ni_string_split(&opts, value, " \t", 0);
ap->ipv6_cache_info.valid_lft = NI_LIFETIME_INFINITE;
ap->ipv6_cache_info.preferred_lft = NI_LIFETIME_INFINITE;

while ((opt = ni_string_array_at(&opts, pos++))) {
if (ni_string_eq(opt, "valid_lft")) {
val = ni_string_array_at(&opts, pos++);
if (!__get_ipaddr_lft(val, &ap->ipv6_cache_info.valid_lft))
ret = FALSE;
}
else
if (ni_string_eq(opt, "preferred_lft")) {
val = ni_string_array_at(&opts, pos++);
if (!__get_ipaddr_lft(val, &ap->ipv6_cache_info.preferred_lft))
ret = FALSE;
}
else
if (ni_string_eq(opt, "nodad"))
ap->flags |= IFA_F_NODAD;
else
if (ni_string_eq(opt, "noprefixroute"))
ap->flags |= IFA_F_NOPREFIXROUTE;
else
if (ni_string_eq(opt, "autojoin"))
ap->flags |= IFA_F_MCAUTOJOIN;
else
if (ni_string_eq(opt, "home") || ni_string_eq(opt, "homeaddress"))
ap->flags |= IFA_F_HOMEADDRESS;
else
ret = FALSE;
}

if ((ap->ipv6_cache_info.valid_lft || ap->ipv6_cache_info.preferred_lft) &&
(ap->ipv6_cache_info.valid_lft < ap->ipv6_cache_info.preferred_lft)) {
ap->ipv6_cache_info.preferred_lft = ap->ipv6_cache_info.valid_lft;
ret = FALSE;
}
return ret;
}

static ni_bool_t
__get_ipaddr(const ni_sysconfig_t *sc, const char *ifname, const char *suffix, ni_address_t **list)
{
Expand Down Expand Up @@ -4284,6 +4349,25 @@ __get_ipaddr(const ni_sysconfig_t *sc, const char *ifname, const char *suffix, n
}
}

var = __find_indexed_variable(sc, "SCOPE", suffix);
if (var && !ni_string_empty(var->value)) {
unsigned int scope;
if (!ni_route_scope_name_to_type(var->value, &scope)) {
ni_info("ifcfg-%s: ignoring %s='%s' unknown scope",
ifname, var->name, var->value);
} else {
ap->scope = scope;
}
}

var = __find_indexed_variable(sc, "IP_OPTIONS", suffix);
if (var && !ni_string_empty(var->value)) {
if (!__get_ipaddr_opts(var->value, ap)) {
ni_info("ifcfg-%s: %s='%s' contains unsupported options",
ifname, var->name, var->value);
}
}

return TRUE;
}

Expand Down
4 changes: 4 additions & 0 deletions src/ifconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -3630,6 +3630,7 @@ __ni_rtnl_send_newaddr(ni_netdev_t *dev, const ni_address_t *ap, int flags)
ifa.ifa_index = dev->link.ifindex;
ifa.ifa_family = ap->family;
ifa.ifa_prefixlen = ap->prefixlen;
ifa.ifa_flags = ap->flags & 0xff;

/* Handle ifa_scope */
if (ap->scope >= 0)
Expand All @@ -3643,6 +3644,9 @@ __ni_rtnl_send_newaddr(ni_netdev_t *dev, const ni_address_t *ap, int flags)
if (nlmsg_append(msg, &ifa, sizeof(ifa), NLMSG_ALIGNTO) < 0)
goto nla_put_failure;

if (ap->flags)
NLA_PUT_U32(msg, IFA_FLAGS, ap->flags);

if (addattr_sockaddr(msg, IFA_LOCAL, &ap->local_addr) < 0)
goto nla_put_failure;

Expand Down
1 change: 1 addition & 0 deletions src/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ static const ni_intmap_t ni_route_table_names[] = {
*/
static const ni_intmap_t ni_route_scope_names[] = {
{ "universe", RT_SCOPE_UNIVERSE },
{ "global", RT_SCOPE_UNIVERSE },
{ "site", RT_SCOPE_SITE },
{ "link", RT_SCOPE_LINK },
{ "host", RT_SCOPE_HOST },
Expand Down

0 comments on commit 91f3c3b

Please sign in to comment.