}
if (!STR_IN_SET(action, "add", "change")) {
- log_device_debug(device, "Ignoring udev %s event for device: %m", action);
+ log_device_debug(device, "Ignoring udev %s event for device.", action);
return 0;
}
if (r < 0)
return log_error_errno(r, "Could not add device monitor filter: %m");
- r = sd_device_monitor_attach_event(m->device_monitor, m->event, 0);
+ r = sd_device_monitor_attach_event(m->device_monitor, m->event);
if (r < 0)
return log_error_errno(r, "Failed to attach event to device monitor: %m");
- r = sd_device_monitor_start(m->device_monitor, manager_udev_process_link, m, "networkd-device-monitor");
+ r = sd_device_monitor_start(m->device_monitor, manager_udev_process_link, m);
if (r < 0)
return log_error_errno(r, "Failed to start device monitor: %m");
}
int manager_rtnl_process_rule(sd_netlink *rtnl, sd_netlink_message *message, void *userdata) {
- uint8_t tos = 0, to_prefixlen = 0, from_prefixlen = 0;
+ uint8_t tos = 0, to_prefixlen = 0, from_prefixlen = 0, protocol = 0;
+ struct fib_rule_port_range sport = {}, dport = {};
union in_addr_union to = {}, from = {};
RoutingPolicyRule *rule = NULL;
uint32_t fwmark = 0, table = 0;
return 0;
}
- (void) routing_policy_rule_get(m, family, &from, from_prefixlen, &to, to_prefixlen, tos, fwmark, table, iif, oif, &rule);
+ r = sd_netlink_message_read_u8(message, FRA_IP_PROTO, &protocol);
+ if (r < 0 && r != -ENODATA) {
+ log_warning_errno(r, "rtnl: could not get FRA_IP_PROTO attribute, ignoring: %m");
+ return 0;
+ }
+
+ r = sd_netlink_message_read(message, FRA_SPORT_RANGE, sizeof(sport), (void *) &sport);
+ if (r < 0 && r != -ENODATA) {
+ log_warning_errno(r, "rtnl: could not get FRA_SPORT_RANGE attribute, ignoring: %m");
+ return 0;
+ }
+
+ r = sd_netlink_message_read(message, FRA_DPORT_RANGE, sizeof(dport), (void *) &dport);
+ if (r < 0 && r != -ENODATA) {
+ log_warning_errno(r, "rtnl: could not get FRA_DPORT_RANGE attribute, ignoring: %m");
+ return 0;
+ }
+
+ (void) routing_policy_rule_get(m, family, &from, from_prefixlen, &to, to_prefixlen, tos, fwmark, table, iif, oif, protocol, &sport, &dport, &rule);
switch (type) {
case RTM_NEWRULE:
if (!rule) {
- r = routing_policy_rule_add_foreign(m, family, &from, from_prefixlen, &to, to_prefixlen, tos, fwmark, table, iif, oif, &rule);
+ r = routing_policy_rule_add_foreign(m, family, &from, from_prefixlen, &to, to_prefixlen, tos, fwmark, table, iif, oif, protocol, &sport, &dport, &rule);
if (r < 0) {
log_warning_errno(r, "Could not add rule, ignoring: %m");
return 0;
Manager *m = userdata;
Link *link;
Iterator i;
- int r;
assert(m);
if (m->dirty)
manager_save(m);
- SET_FOREACH(link, m->dirty_links, i) {
- r = link_save(link);
- if (r >= 0)
+ SET_FOREACH(link, m->dirty_links, i)
+ if (link_save(link) >= 0)
link_clean(link);
- }
return 1;
}
Link *manager_dhcp6_prefix_get(Manager *m, struct in6_addr *addr) {
assert_return(m, NULL);
- assert_return(m->dhcp6_prefixes, NULL);
assert_return(addr, NULL);
return hashmap_get(m->dhcp6_prefixes, addr);
return 0;
}
+static void dhcp6_prefixes_hash_func(const void *p, struct siphash *state) {
+ const struct in6_addr *addr = p;
+
+ assert(p);
+
+ siphash24_compress(addr, sizeof(*addr), state);
+}
+
+static int dhcp6_prefixes_compare_func(const void *_a, const void *_b) {
+ const struct in6_addr *a = _a, *b = _b;
+
+ return memcmp(a, b, sizeof(*a));
+}
+
+static const struct hash_ops dhcp6_prefixes_hash_ops = {
+ .hash = dhcp6_prefixes_hash_func,
+ .compare = dhcp6_prefixes_compare_func,
+};
+
int manager_dhcp6_prefix_add(Manager *m, struct in6_addr *addr, Link *link) {
- int r;
- Route *route;
_cleanup_free_ char *buf = NULL;
+ Route *route;
+ int r;
assert_return(m, -EINVAL);
- assert_return(m->dhcp6_prefixes, -ENODATA);
assert_return(addr, -EINVAL);
r = route_add(link, AF_INET6, (union in_addr_union *) addr, 64,
(void) in_addr_to_string(AF_INET6, (union in_addr_union *) addr, &buf);
log_link_debug(link, "Adding prefix route %s/64", strnull(buf));
+ r = hashmap_ensure_allocated(&m->dhcp6_prefixes, &dhcp6_prefixes_hash_ops);
+ if (r < 0)
+ return r;
+
return hashmap_put(m->dhcp6_prefixes, addr, link);
}
}
static int manager_dhcp6_prefix_remove(Manager *m, struct in6_addr *addr) {
+ _cleanup_free_ char *buf = NULL;
+ Route *route;
Link *l;
int r;
- Route *route;
- _cleanup_free_ char *buf = NULL;
assert_return(m, -EINVAL);
- assert_return(m->dhcp6_prefixes, -ENODATA);
assert_return(addr, -EINVAL);
l = hashmap_remove(m->dhcp6_prefixes, addr);
}
int manager_dhcp6_prefix_remove_all(Manager *m, Link *link) {
+ struct in6_addr *addr;
Iterator i;
Link *l;
- struct in6_addr *addr;
assert_return(m, -EINVAL);
assert_return(link, -EINVAL);
return 0;
}
-static void dhcp6_prefixes_hash_func(const void *p, struct siphash *state) {
- const struct in6_addr *addr = p;
-
- assert(p);
-
- siphash24_compress(addr, sizeof(*addr), state);
-}
-
-static int dhcp6_prefixes_compare_func(const void *_a, const void *_b) {
- const struct in6_addr *a = _a, *b = _b;
-
- return memcmp(a, b, sizeof(*a));
-}
-
-static const struct hash_ops dhcp6_prefixes_hash_ops = {
- .hash = dhcp6_prefixes_hash_func,
- .compare = dhcp6_prefixes_compare_func,
-};
-
int manager_new(Manager **ret) {
_cleanup_(manager_freep) Manager *m = NULL;
int r;
if (r < 0)
return r;
- m->netdevs = hashmap_new(&string_hash_ops);
- if (!m->netdevs)
- return -ENOMEM;
-
LIST_HEAD_INIT(m->networks);
r = sd_resolve_default(&m->resolve);
if (r < 0)
return r;
- m->dhcp6_prefixes = hashmap_new(&dhcp6_prefixes_hash_ops);
- if (!m->dhcp6_prefixes)
- return -ENOMEM;
-
m->duid.type = DUID_TYPE_EN;
(void) routing_policy_load_rules(m->state_file, &m->rules_saved);
sd_netlink_unref(m->rtnl);
sd_netlink_unref(m->genl);
+ sd_resolve_unref(m->resolve);
while ((network = m->networks))
network_free(network);
manager_dhcp6_prefix_remove_all(m, link);
hashmap_free(m->dhcp6_prefixes);
- while ((link = hashmap_first(m->links))) {
+ while ((link = hashmap_steal_first(m->links))) {
if (link->dhcp6_client)
- (void) dhcp6_lease_pd_prefix_lost(link->dhcp6_client,
- link);
-
- hashmap_remove(m->links, INT_TO_PTR(link->ifindex));
-
+ (void) dhcp6_lease_pd_prefix_lost(link->dhcp6_client, link);
link_unref(link);
}
sd_event_unref(m->event);
- sd_resolve_unref(m->resolve);
-
sd_device_monitor_unref(m->device_monitor);
sd_bus_unref(m->bus);