#include "utf8.h"
#include "util.h"
-const char *net_get_name(sd_device *device) {
+const char *net_get_name_persistent(sd_device *device) {
const char *name, *field;
assert(device);
#define HASH_KEY SD_ID128_MAKE(d3,1e,48,fa,90,fe,4b,4c,9d,af,d5,d7,a1,b1,2e,8a)
-int net_get_unique_predictable_data(sd_device *device, uint64_t *result) {
+int net_get_unique_predictable_data(sd_device *device, bool use_sysname, uint64_t *result) {
size_t l, sz = 0;
const char *name;
int r;
assert(device);
- /* net_get_name() will return one of the device names based on stable information about the
- * device. If this is not available, we fall back to using the device name. */
- name = net_get_name(device);
- if (!name)
+ /* net_get_name_persistent() will return one of the device names based on stable information about
+ * the device. If this is not available, we fall back to using the actual device name. */
+ name = net_get_name_persistent(device);
+ if (!name && use_sysname)
(void) sd_device_get_sysname(device, &name);
if (!name)
return log_device_debug_errno(device, SYNTHETIC_ERRNO(ENODATA),
char * const *match_drivers,
char * const *match_types,
char * const *match_names,
- Condition *match_host,
- Condition *match_virt,
- Condition *match_kernel_cmdline,
- Condition *match_kernel_version,
- Condition *match_arch,
const struct ether_addr *dev_mac,
const char *dev_path,
- const char *dev_parent_driver,
const char *dev_driver,
const char *dev_type,
const char *dev_name) {
- if (match_host && condition_test(match_host) <= 0)
- return false;
-
- if (match_virt && condition_test(match_virt) <= 0)
- return false;
-
- if (match_kernel_cmdline && condition_test(match_kernel_cmdline) <= 0)
- return false;
-
- if (match_kernel_version && condition_test(match_kernel_version) <= 0)
- return false;
-
- if (match_arch && condition_test(match_arch) <= 0)
- return false;
-
if (match_mac && (!dev_mac || !set_contains(match_mac, dev_mac)))
return false;
void *userdata) {
ConditionType cond = ltype;
- Condition **ret = data;
+ Condition **list = data, *c;
bool negate;
- Condition *c;
- _cleanup_free_ char *s = NULL;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
+ if (isempty(rvalue)) {
+ *list = condition_free_list_type(*list, cond);
+ return 0;
+ }
+
negate = rvalue[0] == '!';
if (negate)
rvalue++;
- s = strdup(rvalue);
- if (!s)
- return log_oom();
-
- c = condition_new(cond, s, false, negate);
+ c = condition_new(cond, rvalue, false, negate);
if (!c)
return log_oom();
- if (*ret)
- condition_free(*ret);
+ /* Drop previous assignment. */
+ *list = condition_free_list_type(*list, cond);
- *ret = c;
+ LIST_PREPEND(conditions, *list, c);
return 0;
}
return 0;
}
-void serialize_in_addrs(FILE *f, const struct in_addr *addresses, size_t size) {
- unsigned i;
+size_t serialize_in_addrs(FILE *f,
+ const struct in_addr *addresses,
+ size_t size,
+ bool with_leading_space,
+ bool (*predicate)(const struct in_addr *addr)) {
+ size_t count;
+ size_t i;
assert(f);
assert(addresses);
- assert(size);
- for (i = 0; i < size; i++)
- fprintf(f, "%s%s", inet_ntoa(addresses[i]),
- (i < (size - 1)) ? " ": "");
+ count = 0;
+
+ for (i = 0; i < size; i++) {
+ char sbuf[INET_ADDRSTRLEN];
+
+ if (predicate && !predicate(&addresses[i]))
+ continue;
+ if (with_leading_space)
+ fputc(' ', f);
+ else
+ with_leading_space = true;
+ fputs(inet_ntop(AF_INET, &addresses[i], sbuf, sizeof(sbuf)), f);
+ count++;
+ }
+
+ return count;
}
int deserialize_in_addrs(struct in_addr **ret, const char *string) {
size++;
}
- *ret = TAKE_PTR(addresses);
+ *ret = size > 0 ? TAKE_PTR(addresses) : NULL;
return size;
}
fprintf(f, "%s=", key);
for (i = 0; i < size; i++) {
+ char sbuf[INET_ADDRSTRLEN];
struct in_addr dest, gw;
uint8_t length;
assert_se(sd_dhcp_route_get_gateway(routes[i], &gw) >= 0);
assert_se(sd_dhcp_route_get_destination_prefix_length(routes[i], &length) >= 0);
- fprintf(f, "%s/%" PRIu8, inet_ntoa(dest), length);
- fprintf(f, ",%s%s", inet_ntoa(gw), (i < (size - 1)) ? " ": "");
+ fprintf(f, "%s/%" PRIu8, inet_ntop(AF_INET, &dest, sbuf, sizeof(sbuf)), length);
+ fprintf(f, ",%s%s", inet_ntop(AF_INET, &gw, sbuf, sizeof(sbuf)), (i < (size - 1)) ? " ": "");
}
fputs("\n", f);
assert(data);
hex_buf = hexmem(data, size);
- if (hex_buf == NULL)
+ if (!hex_buf)
return -ENOMEM;
fprintf(f, "%s=%s\n", key, hex_buf);