Compare commits

...

9 Commits

Author SHA1 Message Date
Christian Ehrhardt eae1ef076d test: increase qemu timeout for TEST-08 and TEST-09
These tests two have shown to be flaky in Ubuntu test infrastructure,
but got more reliable with increased timeouts of 300 seconds each.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2019-12-12 19:42:04 +01:00
Shengjing Zhu 679ecd3616 nspawn: allow combination of private-network and network-namespace-path
Fixes: #14289
2019-12-12 19:26:32 +01:00
Lennart Poettering 3e761fe2c9
Merge pull request #14321 from yuwata/network-generator-14319
network-generator: allow empty hostname
2019-12-12 17:52:09 +01:00
Yu Watanabe 3d85f19ced
Merge pull request #14305 from ssahani/tc-fq
network tc: inroduce FQ - Fair Queue traffic policing
2019-12-12 21:16:38 +09:00
Yu Watanabe dd1e09971b test: add a test case for network-generator 2019-12-12 19:02:25 +09:00
Yu Watanabe 21a925a4ac network-generator: allow empty hostname
Fixes #14319.
2019-12-12 19:01:24 +09:00
Yu Watanabe 0baddbd5ee test-network: add a test case for FQ 2019-12-12 17:26:31 +09:00
Susant Sahani 7234b91596 network tc: inroduce FQ - Fair Queue traffic policing
Please see http://man7.org/linux/man-pages/man8/tc-fq.8.html
2019-12-12 17:26:20 +09:00
Yu Watanabe eb34f4b3d2 sd-netlink: add attributes for FQ 2019-12-12 16:23:26 +09:00
19 changed files with 208 additions and 22 deletions

View File

@ -2450,6 +2450,14 @@
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><varname>FairQueueTrafficPolicingPacketLimit=</varname></term>
<listitem>
<para>Specifies the hard limit on the real queue size. When this limit is reached, incoming packets are
dropped. Defaults to unset and kernel's default is used.</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</refsect1> </refsect1>

View File

@ -734,14 +734,18 @@ static const NLTypeSystem rtnl_nexthop_type_system = {
.types = rtnl_nexthop_types, .types = rtnl_nexthop_types,
}; };
static const NLType rtnl_tca_option_data_tbf_types[] = { static const NLType rtnl_tca_option_data_fq_types[] = {
[TCA_TBF_PARMS] = { .size = sizeof(struct tc_tbf_qopt) }, [TCA_FQ_PLIMIT] = { .type = NETLINK_TYPE_U32 },
[TCA_TBF_RTAB] = { .size = TC_RTAB_SIZE }, [TCA_FQ_FLOW_PLIMIT] = { .type = NETLINK_TYPE_U32 },
[TCA_TBF_PTAB] = { .size = TC_RTAB_SIZE }, [TCA_FQ_QUANTUM] = { .type = NETLINK_TYPE_U32 },
[TCA_TBF_RATE64] = { .type = NETLINK_TYPE_U64 }, [TCA_FQ_INITIAL_QUANTUM] = { .type = NETLINK_TYPE_U32 },
[TCA_TBF_PRATE64] = { .type = NETLINK_TYPE_U64 }, [TCA_FQ_RATE_ENABLE] = { .type = NETLINK_TYPE_U32 },
[TCA_TBF_BURST] = { .type = NETLINK_TYPE_U32 }, [TCA_FQ_FLOW_DEFAULT_RATE] = { .type = NETLINK_TYPE_U32 },
[TCA_TBF_PBURST] = { .type = NETLINK_TYPE_U32 }, [TCA_FQ_FLOW_MAX_RATE] = { .type = NETLINK_TYPE_U32 },
[TCA_FQ_BUCKETS_LOG] = { .type = NETLINK_TYPE_U32 },
[TCA_FQ_FLOW_REFILL_DELAY] = { .type = NETLINK_TYPE_U32 },
[TCA_FQ_LOW_RATE_THRESHOLD] = { .type = NETLINK_TYPE_U32 },
[TCA_FQ_CE_THRESHOLD] = { .type = NETLINK_TYPE_U32 },
}; };
static const NLType rtnl_tca_option_data_fq_codel_types[] = { static const NLType rtnl_tca_option_data_fq_codel_types[] = {
@ -756,18 +760,31 @@ static const NLType rtnl_tca_option_data_fq_codel_types[] = {
[TCA_FQ_CODEL_MEMORY_LIMIT] = { .type = NETLINK_TYPE_U32 }, [TCA_FQ_CODEL_MEMORY_LIMIT] = { .type = NETLINK_TYPE_U32 },
}; };
static const NLType rtnl_tca_option_data_tbf_types[] = {
[TCA_TBF_PARMS] = { .size = sizeof(struct tc_tbf_qopt) },
[TCA_TBF_RTAB] = { .size = TC_RTAB_SIZE },
[TCA_TBF_PTAB] = { .size = TC_RTAB_SIZE },
[TCA_TBF_RATE64] = { .type = NETLINK_TYPE_U64 },
[TCA_TBF_PRATE64] = { .type = NETLINK_TYPE_U64 },
[TCA_TBF_BURST] = { .type = NETLINK_TYPE_U32 },
[TCA_TBF_PBURST] = { .type = NETLINK_TYPE_U32 },
};
static const char* const nl_union_tca_option_data_table[] = { static const char* const nl_union_tca_option_data_table[] = {
[NL_UNION_TCA_OPTION_DATA_TBF] = "tbf", [NL_UNION_TCA_OPTION_DATA_FQ] = "fq",
[NL_UNION_TCA_OPTION_DATA_FQ_CODEL] = "fq_codel", [NL_UNION_TCA_OPTION_DATA_FQ_CODEL] = "fq_codel",
[NL_UNION_TCA_OPTION_DATA_TBF] = "tbf",
}; };
DEFINE_STRING_TABLE_LOOKUP(nl_union_tca_option_data, NLUnionTCAOptionData); DEFINE_STRING_TABLE_LOOKUP(nl_union_tca_option_data, NLUnionTCAOptionData);
static const NLTypeSystem rtnl_tca_option_data_type_systems[] = { static const NLTypeSystem rtnl_tca_option_data_type_systems[] = {
[NL_UNION_TCA_OPTION_DATA_TBF] = { .count = ELEMENTSOF(rtnl_tca_option_data_tbf_types), [NL_UNION_TCA_OPTION_DATA_FQ] = { .count = ELEMENTSOF(rtnl_tca_option_data_fq_types),
.types = rtnl_tca_option_data_tbf_types }, .types = rtnl_tca_option_data_fq_types },
[NL_UNION_TCA_OPTION_DATA_FQ_CODEL] = { .count = ELEMENTSOF(rtnl_tca_option_data_fq_codel_types), [NL_UNION_TCA_OPTION_DATA_FQ_CODEL] = { .count = ELEMENTSOF(rtnl_tca_option_data_fq_codel_types),
.types = rtnl_tca_option_data_fq_codel_types }, .types = rtnl_tca_option_data_fq_codel_types },
[NL_UNION_TCA_OPTION_DATA_TBF] = { .count = ELEMENTSOF(rtnl_tca_option_data_tbf_types),
.types = rtnl_tca_option_data_tbf_types },
}; };
static const NLTypeSystemUnion rtnl_tca_option_data_type_system_union = { static const NLTypeSystemUnion rtnl_tca_option_data_type_system_union = {

View File

@ -92,8 +92,9 @@ const char *nl_union_link_info_data_to_string(NLUnionLinkInfoData p) _const_;
NLUnionLinkInfoData nl_union_link_info_data_from_string(const char *p) _pure_; NLUnionLinkInfoData nl_union_link_info_data_from_string(const char *p) _pure_;
typedef enum NLUnionTCAOptionData { typedef enum NLUnionTCAOptionData {
NL_UNION_TCA_OPTION_DATA_TBF, NL_UNION_TCA_OPTION_DATA_FQ,
NL_UNION_TCA_OPTION_DATA_FQ_CODEL, NL_UNION_TCA_OPTION_DATA_FQ_CODEL,
NL_UNION_TCA_OPTION_DATA_TBF,
_NL_UNION_TCA_OPTION_DATA_MAX, _NL_UNION_TCA_OPTION_DATA_MAX,
_NL_UNION_TCA_OPTION_DATA_INVALID = -1, _NL_UNION_TCA_OPTION_DATA_INVALID = -1,
} NLUnionTCAOptionData; } NLUnionTCAOptionData;

View File

@ -574,7 +574,7 @@ static int parse_netmask_or_prefixlen(int family, const char **value, unsigned c
static int parse_cmdline_ip_address(Context *context, int family, const char *value) { static int parse_cmdline_ip_address(Context *context, int family, const char *value) {
union in_addr_union addr = {}, peer = {}, gateway = {}; union in_addr_union addr = {}, peer = {}, gateway = {};
const char *hostname, *ifname, *dhcp_type, *dns, *p; const char *hostname = NULL, *ifname, *dhcp_type, *dns, *p;
unsigned char prefixlen; unsigned char prefixlen;
int r; int r;
@ -599,9 +599,11 @@ static int parse_cmdline_ip_address(Context *context, int family, const char *va
if (!p) if (!p)
return -EINVAL; return -EINVAL;
hostname = strndupa(value, p - value); if (p != value) {
if (!hostname_is_valid(hostname, false)) hostname = strndupa(value, p - value);
return -EINVAL; if (!hostname_is_valid(hostname, false))
return -EINVAL;
}
value = p + 1; value = p + 1;

View File

@ -107,6 +107,8 @@ sources = files('''
networkd-util.h networkd-util.h
networkd-wifi.c networkd-wifi.c
networkd-wifi.h networkd-wifi.h
tc/fq.c
tc/fq.h
tc/fq-codel.c tc/fq-codel.c
tc/fq-codel.h tc/fq-codel.h
tc/netem.c tc/netem.c

View File

@ -259,6 +259,7 @@ TrafficControlQueueingDiscipline.TokenBufferFilterPeakRate, con
TrafficControlQueueingDiscipline.TokenBufferFilterLatencySec, config_parse_tc_token_buffer_filter_latency, 0, 0 TrafficControlQueueingDiscipline.TokenBufferFilterLatencySec, config_parse_tc_token_buffer_filter_latency, 0, 0
TrafficControlQueueingDiscipline.StochasticFairnessQueueingPerturbPeriodSec, config_parse_tc_stochastic_fairness_queueing_perturb_period, 0, 0 TrafficControlQueueingDiscipline.StochasticFairnessQueueingPerturbPeriodSec, config_parse_tc_stochastic_fairness_queueing_perturb_period, 0, 0
TrafficControlQueueingDiscipline.FairQueuingControlledDelayPacketLimit, config_parse_tc_fair_queuing_controlled_delay_limit, 0, 0 TrafficControlQueueingDiscipline.FairQueuingControlledDelayPacketLimit, config_parse_tc_fair_queuing_controlled_delay_limit, 0, 0
TrafficControlQueueingDiscipline.FairQueueTrafficPolicingPacketLimit, config_parse_tc_fair_queue_traffic_policing_packet_limit, 0, 0
/* backwards compatibility: do not add new entries to this section */ /* backwards compatibility: do not add new entries to this section */
Network.IPv4LL, config_parse_ipv4ll, 0, offsetof(Network, link_local) Network.IPv4LL, config_parse_ipv4ll, 0, offsetof(Network, link_local)
DHCP.ClientIdentifier, config_parse_dhcp_client_identifier, 0, offsetof(Network, dhcp_client_identifier) DHCP.ClientIdentifier, config_parse_dhcp_client_identifier, 0, offsetof(Network, dhcp_client_identifier)

93
src/network/tc/fq.c Normal file
View File

@ -0,0 +1,93 @@
/* SPDX-License-Identifier: LGPL-2.1+
* Copyright © 2019 VMware, Inc. */
#include <linux/pkt_sched.h>
#include "alloc-util.h"
#include "conf-parser.h"
#include "fq.h"
#include "netlink-util.h"
#include "parse-util.h"
#include "string-util.h"
static int fair_queue_traffic_policing_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) {
FairQueueTrafficPolicing *fq;
int r;
assert(link);
assert(qdisc);
assert(req);
fq = FQ(qdisc);
r = sd_netlink_message_open_container_union(req, TCA_OPTIONS, "fq");
if (r < 0)
return log_link_error_errno(link, r, "Could not open container TCA_OPTIONS: %m");
r = sd_netlink_message_append_u32(req, TCA_FQ_PLIMIT, fq->limit);
if (r < 0)
return log_link_error_errno(link, r, "Could not append TCA_FQ_PLIMIT attribute: %m");
r = sd_netlink_message_close_container(req);
if (r < 0)
return log_link_error_errno(link, r, "Could not close container TCA_OPTIONS: %m");
return 0;
}
int config_parse_tc_fair_queue_traffic_policing_packet_limit(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
_cleanup_(qdisc_free_or_set_invalidp) QDisc *qdisc = NULL;
FairQueueTrafficPolicing *fq;
Network *network = data;
int r;
assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);
r = qdisc_new_static(QDISC_KIND_FQ, network, filename, section_line, &qdisc);
if (r == -ENOMEM)
return log_oom();
if (r < 0)
return log_syntax(unit, LOG_ERR, filename, line, r,
"More than one kind of queueing discipline, ignoring assignment: %m");
fq = FQ(qdisc);
if (isempty(rvalue)) {
fq->limit = 0;
qdisc = NULL;
return 0;
}
r = safe_atou32(rvalue, &fq->limit);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Failed to parse '%s=', ignoring assignment: %s",
lvalue, rvalue);
return 0;
}
qdisc = NULL;
return 0;
}
const QDiscVTable fq_vtable = {
.object_size = sizeof(FairQueueTrafficPolicing),
.tca_kind = "fq",
.fill_message = fair_queue_traffic_policing_fill_message,
};

17
src/network/tc/fq.h Normal file
View File

@ -0,0 +1,17 @@
/* SPDX-License-Identifier: LGPL-2.1+
* Copyright © 2019 VMware, Inc. */
#pragma once
#include "conf-parser.h"
#include "qdisc.h"
typedef struct FairQueueTrafficPolicing {
QDisc meta;
uint32_t limit;
} FairQueueTrafficPolicing;
DEFINE_QDISC_CAST(FQ, FairQueueTrafficPolicing);
extern const QDiscVTable fq_vtable;
CONFIG_PARSER_PROTOTYPE(config_parse_tc_fair_queue_traffic_policing_packet_limit);

View File

@ -14,6 +14,7 @@
#include "string-util.h" #include "string-util.h"
const QDiscVTable * const qdisc_vtable[_QDISC_KIND_MAX] = { const QDiscVTable * const qdisc_vtable[_QDISC_KIND_MAX] = {
[QDISC_KIND_FQ] = &fq_vtable,
[QDISC_KIND_FQ_CODEL] = &fq_codel_vtable, [QDISC_KIND_FQ_CODEL] = &fq_codel_vtable,
[QDISC_KIND_NETEM] = &netem_vtable, [QDISC_KIND_NETEM] = &netem_vtable,
[QDISC_KIND_SFQ] = &sfq_vtable, [QDISC_KIND_SFQ] = &sfq_vtable,

View File

@ -8,6 +8,7 @@
#include "networkd-util.h" #include "networkd-util.h"
typedef enum QDiscKind { typedef enum QDiscKind {
QDISC_KIND_FQ,
QDISC_KIND_FQ_CODEL, QDISC_KIND_FQ_CODEL,
QDISC_KIND_NETEM, QDISC_KIND_NETEM,
QDISC_KIND_SFQ, QDISC_KIND_SFQ,
@ -62,6 +63,7 @@ DEFINE_NETWORK_SECTION_FUNCTIONS(QDisc, qdisc_free);
CONFIG_PARSER_PROTOTYPE(config_parse_tc_qdiscs_parent); CONFIG_PARSER_PROTOTYPE(config_parse_tc_qdiscs_parent);
#include "fq-codel.h" #include "fq-codel.h"
#include "fq.h"
#include "netem.h" #include "netem.h"
#include "sfq.h" #include "sfq.h"
#include "tbf.h" #include "tbf.h"

View File

@ -1562,13 +1562,13 @@ static int verify_arguments(void) {
if (arg_userns_chown && arg_volatile_mode != VOLATILE_NO) if (arg_userns_chown && arg_volatile_mode != VOLATILE_NO)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--volatile= and --private-users-chown may not be combined."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--volatile= and --private-users-chown may not be combined.");
/* If --network-namespace-path is given with any other network-related option, we need to error out, /* If --network-namespace-path is given with any other network-related option (except --private-network),
* to avoid conflicts between different network options. */ * we need to error out, to avoid conflicts between different network options. */
if (arg_network_namespace_path && if (arg_network_namespace_path &&
(arg_network_interfaces || arg_network_macvlan || (arg_network_interfaces || arg_network_macvlan ||
arg_network_ipvlan || arg_network_veth_extra || arg_network_ipvlan || arg_network_veth_extra ||
arg_network_bridge || arg_network_zone || arg_network_bridge || arg_network_zone ||
arg_network_veth || arg_private_network)) arg_network_veth))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--network-namespace-path= cannot be combined with other network options."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "--network-namespace-path= cannot be combined with other network options.");
if (arg_network_bridge && arg_network_zone) if (arg_network_bridge && arg_network_zone)

View File

@ -4,7 +4,7 @@ TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2730"
TEST_NO_NSPAWN=1 TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions . $TEST_BASE_DIR/test-functions
QEMU_TIMEOUT=180 QEMU_TIMEOUT=300
FSTYPE=ext4 FSTYPE=ext4
test_setup() { test_setup() {

View File

@ -4,7 +4,7 @@ TEST_DESCRIPTION="https://github.com/systemd/systemd/issues/2691"
TEST_NO_NSPAWN=1 TEST_NO_NSPAWN=1
. $TEST_BASE_DIR/test-functions . $TEST_BASE_DIR/test-functions
QEMU_TIMEOUT=180 QEMU_TIMEOUT=300
test_setup() { test_setup() {
create_empty_image_rootdir create_empty_image_rootdir

View File

@ -150,7 +150,8 @@ function run {
return 1 return 1
fi fi
if SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --private-network -b; then # allow combination of --network-namespace-path and --private-network
if ! SYSTEMD_NSPAWN_UNIFIED_HIERARCHY="$1" SYSTEMD_NSPAWN_USE_CGNS="$2" SYSTEMD_NSPAWN_API_VFS_WRITABLE="$3" systemd-nspawn --register=no -D "$_root" "$_netns_opt" --private-network -b; then
return 1 return 1
fi fi

View File

@ -0,0 +1,17 @@
# Automatically generated by systemd-network-generator
[Match]
Name=enp3s0
[Link]
[Network]
DHCP=no
[DHCP]
[Address]
Address=10.99.37.44/16
[Route]
Gateway=10.99.10.1

View File

@ -0,0 +1 @@
root=/dev/nfs nfsroot=10.99.37.240:/srv/netroot,v3,tcp ip=10.99.37.44::10.99.10.1:255.255.0.0::enp3s0:off

View File

@ -279,3 +279,4 @@ TokenBufferFilterPeakRate=
TokenBufferFilterLatencySec= TokenBufferFilterLatencySec=
StochasticFairnessQueueingPerturbPeriodSec= StochasticFairnessQueueingPerturbPeriodSec=
FairQueuingControlledDelayPacketLimit= FairQueuingControlledDelayPacketLimit=
FairQueueTrafficPolicingPacketLimit=

View File

@ -0,0 +1,10 @@
[Match]
Name=dummy98
[Network]
IPv6AcceptRA=no
Address=10.1.2.3/16
[TrafficControlQueueingDiscipline]
Parent=root
FairQueueTrafficPolicingPacketLimit=1000

View File

@ -1509,6 +1509,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
'25-neighbor-ip-dummy.network', '25-neighbor-ip-dummy.network',
'25-neighbor-ip.network', '25-neighbor-ip.network',
'25-nexthop.network', '25-nexthop.network',
'25-qdisc-fq.network',
'25-qdisc-netem-and-fqcodel.network', '25-qdisc-netem-and-fqcodel.network',
'25-qdisc-tbf-and-sfq.network', '25-qdisc-tbf-and-sfq.network',
'25-route-ipv6-src.network', '25-route-ipv6-src.network',
@ -2102,6 +2103,17 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
self.assertRegex(output, 'qdisc sfq') self.assertRegex(output, 'qdisc sfq')
self.assertRegex(output, 'perturb 5sec') self.assertRegex(output, 'perturb 5sec')
def test_qdisc2(self):
copy_unit_to_networkd_unit_path('25-qdisc-fq.network', '12-dummy.netdev')
start_networkd()
self.wait_online(['dummy98:routable'])
output = check_output('tc qdisc show dev dummy98')
print(output)
self.assertRegex(output, 'qdisc fq')
self.assertRegex(output, 'limit 1000p')
class NetworkdStateFileTests(unittest.TestCase, Utilities): class NetworkdStateFileTests(unittest.TestCase, Utilities):
links = [ links = [
'dummy98', 'dummy98',