summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-07-28 11:39:37 +0200
committerTom Gundersen <teg@jklm.no>2014-07-28 11:46:57 +0200
commitae06ab1014641feb83ffd0d08f0957e69bbbae08 (patch)
treeffa48da764daaefe1263094c836fb7c3b5c6fca7 /src
parent527503444ef24ae03c73cf85128c7acbb1146f3c (diff)
networkd: store ifindex as int
Diffstat (limited to 'src')
-rw-r--r--src/network/networkd-link.c24
-rw-r--r--src/network/networkd-manager.c4
-rw-r--r--src/network/networkd.h2
3 files changed, 12 insertions, 18 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index ac9f4737ef..5eeeb3d29e 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -46,7 +46,6 @@ static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
int r, ifindex;
assert(manager);
- assert(manager->links);
assert(message);
assert(ret);
@@ -82,17 +81,19 @@ static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
if (r < 0)
log_debug_link(link, "MAC address not found for new device, continuing without");
- r = asprintf(&link->state_file, "/run/systemd/netif/links/%"PRIu64,
- link->ifindex);
+ r = asprintf(&link->state_file, "/run/systemd/netif/links/%d", link->ifindex);
if (r < 0)
return -ENOMEM;
- r = asprintf(&link->lease_file, "/run/systemd/netif/leases/%"PRIu64,
- link->ifindex);
+ r = asprintf(&link->lease_file, "/run/systemd/netif/leases/%d", link->ifindex);
if (r < 0)
return -ENOMEM;
- r = hashmap_put(manager->links, &link->ifindex, link);
+ r = hashmap_ensure_allocated(&manager->links, NULL, NULL);
+ if (r < 0)
+ return r;
+
+ r = hashmap_put(manager->links, INT_TO_PTR(link->ifindex), link);
if (r < 0)
return r;
@@ -129,7 +130,7 @@ static void link_free(Link *link) {
sd_icmp6_nd_unref(link->icmp6_router_discovery);
if (link->manager)
- hashmap_remove(link->manager->links, &link->ifindex);
+ hashmap_remove(link->manager->links, INT_TO_PTR(link->ifindex));
free(link->ifname);
@@ -157,15 +158,12 @@ Link *link_ref(Link *link) {
int link_get(Manager *m, int ifindex, Link **ret) {
Link *link;
- uint64_t ifindex_64;
assert(m);
- assert(m->links);
assert(ifindex);
assert(ret);
- ifindex_64 = ifindex;
- link = hashmap_get(m->links, &ifindex_64);
+ link = hashmap_get(m->links, INT_TO_PTR(ifindex));
if (!link)
return -ENODEV;
@@ -2282,7 +2280,7 @@ int link_add(Manager *m, sd_rtnl_message *message, Link **ret) {
link = *ret;
- log_debug_link(link, "link %"PRIu64" added", link->ifindex);
+ log_debug_link(link, "link %d added", link->ifindex);
r = sd_rtnl_message_new_addr(m->rtnl, &req, RTM_GETADDR, link->ifindex, 0);
if (r < 0)
@@ -2296,7 +2294,7 @@ int link_add(Manager *m, sd_rtnl_message *message, Link **ret) {
if (detect_container(NULL) <= 0) {
/* not in a container, udev will be around */
- sprintf(ifindex_str, "n%"PRIu64, link->ifindex);
+ sprintf(ifindex_str, "n%d", link->ifindex);
device = udev_device_new_from_device_id(m->udev, ifindex_str);
if (!device) {
log_warning_link(link, "could not find udev device");
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index b0e3191a00..223cb2a75a 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -114,10 +114,6 @@ int manager_new(Manager **ret) {
return -ENOMEM;
}
- m->links = hashmap_new(uint64_hash_func, uint64_compare_func);
- if (!m->links)
- return -ENOMEM;
-
m->netdevs = hashmap_new(string_hash_func, string_compare_func);
if (!m->netdevs)
return -ENOMEM;
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 138b82d786..fe63cfbd4e 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -173,7 +173,7 @@ struct Link {
int n_ref;
- uint64_t ifindex;
+ int ifindex;
char *ifname;
char *state_file;
struct ether_addr mac;