mirror of
https://github.com/systemd/systemd.git
synced 2025-01-12 13:18:14 +03:00
tree-wide: use af_to_ipv4_ipv6() + af_from_ipv4_ipv6() helpers at various places
This commit is contained in:
parent
23118193d2
commit
a481753648
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "sd-messages.h"
|
#include "sd-messages.h"
|
||||||
|
|
||||||
|
#include "af-list.h"
|
||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "blockdev-util.h"
|
#include "blockdev-util.h"
|
||||||
#include "bpf-devices.h"
|
#include "bpf-devices.h"
|
||||||
@ -594,17 +595,18 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cgroup_context_dump_socket_bind_item(const CGroupSocketBindItem *item, FILE *f) {
|
void cgroup_context_dump_socket_bind_item(const CGroupSocketBindItem *item, FILE *f) {
|
||||||
const char *family =
|
const char *family, *colon;
|
||||||
item->address_family == AF_INET ? "ipv4:" :
|
|
||||||
item->address_family == AF_INET6 ? "ipv6:" : "";
|
family = strempty(af_to_ipv4_ipv6(item->address_family));
|
||||||
|
colon = isempty(family) ? "" : ":";
|
||||||
|
|
||||||
if (item->nr_ports == 0)
|
if (item->nr_ports == 0)
|
||||||
fprintf(f, " %sany", family);
|
fprintf(f, " %s%sany", family, colon);
|
||||||
else if (item->nr_ports == 1)
|
else if (item->nr_ports == 1)
|
||||||
fprintf(f, " %s%" PRIu16, family, item->port_min);
|
fprintf(f, " %s%s%" PRIu16, family, colon, item->port_min);
|
||||||
else {
|
else {
|
||||||
uint16_t port_max = item->port_min + item->nr_ports - 1;
|
uint16_t port_max = item->port_min + item->nr_ports - 1;
|
||||||
fprintf(f, " %s%" PRIu16 "-%" PRIu16, family, item->port_min, port_max);
|
fprintf(f, " %s%s%" PRIu16 "-%" PRIu16, family, colon, item->port_min, port_max);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5661,11 +5661,8 @@ int config_parse_cgroup_socket_bind(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rvalue) {
|
if (rvalue) {
|
||||||
if (streq(word, "ipv4"))
|
af = af_from_ipv4_ipv6(word);
|
||||||
af = AF_INET;
|
if (af == AF_UNSPEC) {
|
||||||
else if (streq(word, "ipv6"))
|
|
||||||
af = AF_INET6;
|
|
||||||
else {
|
|
||||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||||
"Only \"ipv4\" and \"ipv6\" protocols are supported, ignoring.");
|
"Only \"ipv4\" and \"ipv6\" protocols are supported, ignoring.");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "sd-daemon.h"
|
#include "sd-daemon.h"
|
||||||
|
|
||||||
|
#include "af-list.h"
|
||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "def.h"
|
#include "def.h"
|
||||||
#include "errno-util.h"
|
#include "errno-util.h"
|
||||||
@ -498,7 +499,7 @@ static int accept_connection(
|
|||||||
|
|
||||||
log_debug("Accepted %s %s connection from %s",
|
log_debug("Accepted %s %s connection from %s",
|
||||||
type,
|
type,
|
||||||
socket_address_family(addr) == AF_INET ? "IP" : "IPv6",
|
af_to_ipv4_ipv6(socket_address_family(addr)),
|
||||||
a);
|
a);
|
||||||
|
|
||||||
*hostname = b;
|
*hostname = b;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "sd-bus.h"
|
#include "sd-bus.h"
|
||||||
|
|
||||||
|
#include "af-list.h"
|
||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "bus-container.h"
|
#include "bus-container.h"
|
||||||
#include "bus-control.h"
|
#include "bus-control.h"
|
||||||
@ -821,11 +822,8 @@ static int parse_tcp_address(sd_bus *b, const char **p, char **guid) {
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (family) {
|
if (family) {
|
||||||
if (streq(family, "ipv4"))
|
hints.ai_family = af_from_ipv4_ipv6(family);
|
||||||
hints.ai_family = AF_INET;
|
if (hints.ai_family == AF_UNSPEC)
|
||||||
else if (streq(family, "ipv6"))
|
|
||||||
hints.ai_family = AF_INET6;
|
|
||||||
else
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||||
|
|
||||||
|
#include "af-list.h"
|
||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "bus-error.h"
|
#include "bus-error.h"
|
||||||
#include "bus-unit-util.h"
|
#include "bus-unit-util.h"
|
||||||
@ -879,11 +880,8 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
|
|||||||
|
|
||||||
address_family = eq ? word : NULL;
|
address_family = eq ? word : NULL;
|
||||||
if (address_family) {
|
if (address_family) {
|
||||||
if (streq(address_family, "ipv4"))
|
family = af_from_ipv4_ipv6(address_family);
|
||||||
family = AF_INET;
|
if (family == AF_UNSPEC)
|
||||||
else if (streq(address_family, "ipv6"))
|
|
||||||
family = AF_INET6;
|
|
||||||
else
|
|
||||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
||||||
"Only \"ipv4\" and \"ipv6\" protocols are supported");
|
"Only \"ipv4\" and \"ipv6\" protocols are supported");
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
|
||||||
|
#include "af-list.h"
|
||||||
#include "bus-error.h"
|
#include "bus-error.h"
|
||||||
#include "bus-locator.h"
|
#include "bus-locator.h"
|
||||||
#include "bus-map-properties.h"
|
#include "bus-map-properties.h"
|
||||||
@ -1710,22 +1711,25 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
|
|||||||
return 1;
|
return 1;
|
||||||
} else if (STR_IN_SET(name, "SocketBindAllow", "SocketBindDeny")) {
|
} else if (STR_IN_SET(name, "SocketBindAllow", "SocketBindDeny")) {
|
||||||
uint16_t nr_ports, port_min;
|
uint16_t nr_ports, port_min;
|
||||||
const char *family;
|
|
||||||
int af;
|
int af;
|
||||||
|
|
||||||
r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(iqq)");
|
r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, "(iqq)");
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return bus_log_parse_error(r);
|
return bus_log_parse_error(r);
|
||||||
while ((r = sd_bus_message_read(m, "(iqq)", &af, &nr_ports, &port_min)) > 0) {
|
while ((r = sd_bus_message_read(m, "(iqq)", &af, &nr_ports, &port_min)) > 0) {
|
||||||
family = af == AF_INET ? "ipv4:" : af == AF_INET6 ? "ipv6:" : "";
|
const char *family, *colon;
|
||||||
|
|
||||||
|
family = strempty(af_to_ipv4_ipv6(af));
|
||||||
|
colon = isempty(family) ? "" : ":";
|
||||||
|
|
||||||
if (nr_ports == 0)
|
if (nr_ports == 0)
|
||||||
bus_print_property_valuef(name, expected_value, flags, "%sany", family);
|
bus_print_property_valuef(name, expected_value, flags, "%s%sany", family, colon);
|
||||||
else if (nr_ports == 1)
|
else if (nr_ports == 1)
|
||||||
bus_print_property_valuef(
|
bus_print_property_valuef(
|
||||||
name, expected_value, flags, "%s%hu", family, port_min);
|
name, expected_value, flags, "%s%s%hu", family, colon, port_min);
|
||||||
else
|
else
|
||||||
bus_print_property_valuef(
|
bus_print_property_valuef(
|
||||||
name, expected_value, flags, "%s%hu-%hu", family, port_min,
|
name, expected_value, flags, "%s%s%hu-%hu", family, colon, port_min,
|
||||||
(uint16_t) (port_min + nr_ports - 1));
|
(uint16_t) (port_min + nr_ports - 1));
|
||||||
}
|
}
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user