networkd: store ifindex as int
This commit is contained in:
parent
527503444e
commit
ae06ab1014
|
@ -46,7 +46,6 @@ static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
|
||||||
int r, ifindex;
|
int r, ifindex;
|
||||||
|
|
||||||
assert(manager);
|
assert(manager);
|
||||||
assert(manager->links);
|
|
||||||
assert(message);
|
assert(message);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
|
@ -82,17 +81,19 @@ static int link_new(Manager *manager, sd_rtnl_message *message, Link **ret) {
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_debug_link(link, "MAC address not found for new device, continuing without");
|
log_debug_link(link, "MAC address not found for new device, continuing without");
|
||||||
|
|
||||||
r = asprintf(&link->state_file, "/run/systemd/netif/links/%"PRIu64,
|
r = asprintf(&link->state_file, "/run/systemd/netif/links/%d", link->ifindex);
|
||||||
link->ifindex);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
r = asprintf(&link->lease_file, "/run/systemd/netif/leases/%"PRIu64,
|
r = asprintf(&link->lease_file, "/run/systemd/netif/leases/%d", link->ifindex);
|
||||||
link->ifindex);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return -ENOMEM;
|
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)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
@ -129,7 +130,7 @@ static void link_free(Link *link) {
|
||||||
sd_icmp6_nd_unref(link->icmp6_router_discovery);
|
sd_icmp6_nd_unref(link->icmp6_router_discovery);
|
||||||
|
|
||||||
if (link->manager)
|
if (link->manager)
|
||||||
hashmap_remove(link->manager->links, &link->ifindex);
|
hashmap_remove(link->manager->links, INT_TO_PTR(link->ifindex));
|
||||||
|
|
||||||
free(link->ifname);
|
free(link->ifname);
|
||||||
|
|
||||||
|
@ -157,15 +158,12 @@ Link *link_ref(Link *link) {
|
||||||
|
|
||||||
int link_get(Manager *m, int ifindex, Link **ret) {
|
int link_get(Manager *m, int ifindex, Link **ret) {
|
||||||
Link *link;
|
Link *link;
|
||||||
uint64_t ifindex_64;
|
|
||||||
|
|
||||||
assert(m);
|
assert(m);
|
||||||
assert(m->links);
|
|
||||||
assert(ifindex);
|
assert(ifindex);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
ifindex_64 = ifindex;
|
link = hashmap_get(m->links, INT_TO_PTR(ifindex));
|
||||||
link = hashmap_get(m->links, &ifindex_64);
|
|
||||||
if (!link)
|
if (!link)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
|
@ -2282,7 +2280,7 @@ int link_add(Manager *m, sd_rtnl_message *message, Link **ret) {
|
||||||
|
|
||||||
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);
|
r = sd_rtnl_message_new_addr(m->rtnl, &req, RTM_GETADDR, link->ifindex, 0);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
@ -2296,7 +2294,7 @@ int link_add(Manager *m, sd_rtnl_message *message, Link **ret) {
|
||||||
|
|
||||||
if (detect_container(NULL) <= 0) {
|
if (detect_container(NULL) <= 0) {
|
||||||
/* not in a container, udev will be around */
|
/* 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);
|
device = udev_device_new_from_device_id(m->udev, ifindex_str);
|
||||||
if (!device) {
|
if (!device) {
|
||||||
log_warning_link(link, "could not find udev device");
|
log_warning_link(link, "could not find udev device");
|
||||||
|
|
|
@ -114,10 +114,6 @@ int manager_new(Manager **ret) {
|
||||||
return -ENOMEM;
|
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);
|
m->netdevs = hashmap_new(string_hash_func, string_compare_func);
|
||||||
if (!m->netdevs)
|
if (!m->netdevs)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
|
@ -173,7 +173,7 @@ struct Link {
|
||||||
|
|
||||||
int n_ref;
|
int n_ref;
|
||||||
|
|
||||||
uint64_t ifindex;
|
int ifindex;
|
||||||
char *ifname;
|
char *ifname;
|
||||||
char *state_file;
|
char *state_file;
|
||||||
struct ether_addr mac;
|
struct ether_addr mac;
|
||||||
|
|
Loading…
Reference in a new issue