Skip to content

Commit

Permalink
iflist: fixed to use proper kind mapping, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mtomaschewski committed Jul 10, 2014
1 parent 24f782f commit e5aa1f5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 30 deletions.
33 changes: 15 additions & 18 deletions src/iflist.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,14 +740,14 @@ __ni_process_ifinfomsg_linkinfo(ni_linkinfo_t *link, const char *ifname,
ni_debug_verbose(NI_LOG_DEBUG2, NI_TRACE_IFCONFIG,
"%s: extended link-info without kind", ifname);

} else {
if ((tmp_link_type = ni_linktype_name_to_type(link->kind)) < 0)
tmp_link_type = NI_IFTYPE_UNKNOWN;
} else
if (!__ni_linkinfo_kind_to_type(link->kind, &tmp_link_type)) {
ni_debug_verbose(NI_LOG_DEBUG2, NI_TRACE_IFCONFIG,
"%s: unknown link-info kind: %s", ifname, link->kind);
}
}

/* If link type is still unknown, try to determine via main arp type.
*/
/* If link type is still unknown, try to determine based on arp type. */
struct ethtool_drvinfo drv_info;
const char *driver = NULL;
char *path = NULL;
Expand Down Expand Up @@ -844,24 +844,21 @@ __ni_process_ifinfomsg_linkinfo(ni_linkinfo_t *link, const char *ifname,
if (link->type == NI_IFTYPE_UNKNOWN) {
if (tmp_link_type == NI_IFTYPE_UNKNOWN) {
/* We've failed to discover a link type, leave as is. */
ni_info("%s: Failed to discover link type, arp type is 0x%x, kind %s",
ni_debug_ifconfig("%s: Failed to discover link type, arp type is 0x%x, kind %s",
ifname, link->hwaddr.type, link->kind);
}
else {
} else {
/* Our link has no type yet, so let's assign. */
ni_debug_ifconfig("%s: Setting interface link type to %s",
ni_debug_verbose(NI_LOG_DEBUG2, NI_TRACE_IFCONFIG,
"%s: Setting interface link type to %s",
ifname, ni_linktype_type_to_name(tmp_link_type));
link->type = tmp_link_type;
}
} else {
if (link->type == tmp_link_type) {
/* No need to assign the same link type. */
} else {
/* We're trying to re-assign a link type, Disallow. */
ni_error("%s: Ignoring attempt to reset existing interface link type from %s to %s",
ifname, ni_linktype_type_to_name(link->type),
ni_linktype_type_to_name(tmp_link_type));
}
} else
if (link->type != tmp_link_type) {
/* We're trying to re-assign a link type, Disallow. */
ni_error("%s: Ignoring attempt to reset existing interface link type from %s to %s",
ifname, ni_linktype_type_to_name(link->type),
ni_linktype_type_to_name(tmp_link_type));
}

return 0;
Expand Down
21 changes: 9 additions & 12 deletions src/names.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ ni_linktype_type_to_name(unsigned int type)
}

/*
* Map interface link layer types to strings and vice versa
* Map kernel kind to type
*
* Note: this is an initial, incomplete, one-direction match!
*/
static const ni_intmap_t __linkinfo_kind_names[] = {
{ "bridge", NI_IFTYPE_BRIDGE },
Expand All @@ -112,20 +114,15 @@ static const ni_intmap_t __linkinfo_kind_names[] = {
{ NULL }
};

int
ni_linkinfo_kind_to_type(const char *name)
ni_bool_t
__ni_linkinfo_kind_to_type(const char *name, ni_iftype_t *iftype)
{
unsigned int value;

if (ni_parse_uint_mapped(name, __linkinfo_kind_names, &value) < 0)
return -1;
return value;
}

const char *
ni_linkinfo_type_to_kind(unsigned int type)
{
return ni_format_uint_mapped(type, __linkinfo_kind_names);
if (!iftype || ni_parse_uint_mapped(name, __linkinfo_kind_names, &value) < 0)
return FALSE;
*iftype = value;
return TRUE;
}

/*
Expand Down
2 changes: 2 additions & 0 deletions src/netinfo_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ extern void ni_netconfig_device_remove(ni_netconfig_t *, ni_netdev_t *);
extern ni_netdev_t ** ni_netconfig_device_list_head(ni_netconfig_t *);
extern void ni_netconfig_modem_append(ni_netconfig_t *, ni_modem_t *);

extern ni_bool_t __ni_linkinfo_kind_to_type(const char *, ni_iftype_t *);

extern void __ni_netdev_list_append(ni_netdev_t **, ni_netdev_t *);
extern void __ni_netdev_list_destroy(ni_netdev_t **);
extern ni_addrconf_lease_t *__ni_netdev_find_lease(ni_netdev_t *, unsigned int, ni_addrconf_mode_t, int);
Expand Down

0 comments on commit e5aa1f5

Please sign in to comment.