Commit Graph
503 Commits
Author SHA1 Message Date
Lennart Poettering b71a721fbc parse-util: add parse_tristate() and use it everywhere
We parse tristates all the time, let's add an explicit parser for them.
2023-11-02 04:52:16 +09:00
Yu Watanabe 4ed95fafad network: set maximum length to be read by read_full_file_full()
Fixes #29264 and oss-fuzz#62556
(https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=62556).
2023-10-02 10:36:43 +09:00
Zbigniew Jędrzejewski-Szmek f75921c7fd netdev/wireguard: define iterator variable in the loop 2023-09-22 08:17:42 +02:00
Zbigniew Jędrzejewski-Szmek 117843fe95 network: make DEFINE_NETDEV_CAST() assert on input and output
The macro used to return NULL if input was NULL or had the wrong type. Now
it asserts that input is nonnull and it has the expected type.

There are a few places where a missing or mismatched type was OK, but in a
majority of places, we would do both of the asserts. In various places we'd
only do one, but that was by ommission/mistake. So moving the asserts into the
macro allows us to save some lines.
2023-09-22 08:17:42 +02:00
Zbigniew Jędrzejewski-Szmek 6c9935ba87 network/netdev: align tables 2023-09-22 08:17:42 +02:00
Zbigniew Jędrzejewski-Szmek 6fded8dced network/netdev: fix resetting of 'inherit' field
We have two fields: inherit and ttl, and ttl is ignored if inherit is true.
Setting TTL=inherit and later TTL=n would not work because we didn't unset
inherit.
2023-09-22 08:17:42 +02:00
Zbigniew Jędrzejewski-Szmek af14281d2c network: refusing parsing negative flow labels
The docs for FlowLabel= said that the range is 0..1048575, but the code did not
reject negative numbers.
2023-09-22 08:17:42 +02:00
Zbigniew Jędrzejewski-Szmek a893c121ed network/fou-tunnel: simplify parsing of protocol number
Previously, we would call parse_ip_protocol(), which internally calls
safe_atoi(), and then call safe_atou(). This isn't terrible, but it's also
slightly confusing. Use parse_ip_protocol_full() to avoid the second call.
2023-09-22 08:17:42 +02:00
Zbigniew Jędrzejewski-Szmek 04c2a002e6 network/vxlan: avoid unneccesary temporary variables
parse_ip_port_range() DTRT and only sets the output on success.
2023-09-22 08:17:42 +02:00
Zbigniew Jędrzejewski-Szmek 257cebb67a network/netdev: use ASSERT_PTR() more, adjust indentation 2023-09-22 08:17:42 +02:00
Zbigniew Jędrzejewski-Szmek 851cdffd1b network: use a common helper to parse bounded ranges
This compresses repetetive code and makes it easier to add new options
in networkd. The formatting of error messages becomes uniform. The
error message always specifies the rvalue literally, instead of using
a "descriptive name". This makes the message much easier to handle for
the user.

I opted to add just one parser, and wrap it with inline functions to proxy
the type. This is less verbose than copying functions for each type
separately, and the compiler should be able to get rid of the inline wrapper
almost entirely.

asserts are reordered to use the same order as the parameter list.
This makes the code easier to read.

No functional change intended, apart from the difference in error message
formatting.
2023-09-22 08:16:47 +02:00
David Tardon 9aad490e53 tree-wide: use LIST_CLEAR() 2023-08-17 09:48:17 +02:00
Yu Watanabe d256945fd0 network/queue: free assigned userdata only when a new request is queued 2023-07-29 23:27:19 +09:00
Yuxiang Zhu b67e8a4e3e network: Add IgnoreDdontFragment= option for Fragmentation control (#28131)
From `ip-link(8)`:
> [no]ignore-df - enables/disables IPv4 DF
                      suppression on this tunnel.  Normally datagrams
                      that exceed the MTU will be fragmented; the
                      presence of the DF flag inhibits this, resulting
                      instead in an ICMP Unreachable (Fragmentation
                      Required) message.  Enabling this attribute causes
                      the DF flag to be ignored.

If this option is enabled for a GRE/GRETAP tunnel, the `DF` flag in the outer IP header
will not inherit the inner IP header's `DF` flag.

This is useful to transfer packets that exceed the MTU of the underlay
network.
2023-06-29 12:11:52 +02:00
Yu Watanabe 4194478af8 network/vlan: paranoia about type safety
No functional change, as the struct is defined as the following:
```
struct ifla_vlan_qos_mapping {
      __u32 from;
      __u32 to;
};
```
2023-05-24 11:06:43 +09:00
Yu Watanabe 4d13d175f8 network/vlan: drop unnecessary restriction for QoS mapping
Fixes #27460.
2023-05-24 11:02:39 +09:00
Yu Watanabe 54189b2ec3 network/wireguard: make AllowedIPs= cleared by specifying an empty string 2023-05-22 14:15:49 +09:00
Daan De Meyer 947f59ba2b conf-parser: Add root argument to config_parse_many() 2023-05-12 17:52:32 +02:00
Josef Miegl 417283c5c3 network: geneve: add InheritInnerProtocol flag 2023-03-06 20:58:30 +00:00
Yu Watanabe bf4a5ac804 network/l2tp: parse address or address type from correct string
Fixes a bug introduced by 8b49ee2dcd.

Fixes #26011.
2023-01-11 13:20:14 +09:00
Yu Watanabe 4da53043a6 network/l2tp: fix error code in log message 2023-01-11 13:11:00 +09:00
Zbigniew Jędrzejewski-Szmek 254d1313ae tree-wide: use -EBADF for fd initialization
-1 was used everywhere, but -EBADF or -EBADFD started being used in various
places. Let's make things consistent in the new style.

Note that there are two candidates:
EBADF 9 Bad file descriptor
EBADFD 77 File descriptor in bad state

Since we're initializating the fd, we're just assigning a value that means
"no fd yet", so it's just a bad file descriptor, and the first errno fits
better. If instead we had a valid file descriptor that became invalid because
of some operation or state change, the other errno would fit better.

In some places, initialization is dropped if unnecessary.
2022-12-19 15:00:57 +01:00
Zbigniew Jędrzejewski-Szmek 3ae6b3bf72 basic: rename util.h to logarithm.h
util.h is now about logarithms only, so we can rename it. Many files included
util.h for no apparent reason… Those includes are dropped.
2022-11-08 18:21:10 +01:00
David Tardon 995340074e tree-wide: use ASSERT_PTR more 2022-09-13 08:13:27 +02:00
Jan Janssen 63b9838639 tree-wide: Mark some constants as unsigned
All these are really unsigned and used as such. This silences some
-Wformat-signedness warnings with gcc.
2022-08-30 12:03:33 +02:00
Jan Janssen c0f86d66f3 tree-wide: Use correct format specifiers
gcc will complain about all these with -Wformat-signedness.
2022-08-30 12:03:28 +02:00
Yu Watanabe af7a86b8a6 network/tuntap: save tun or tap file descriptor in fd store 2022-08-16 21:57:35 +09:00
Yu Watanabe f8b7c17764 network/tuntap: introduce KeepCarrier= setting
Closes #24267.
2022-08-16 21:57:31 +09:00
Yu Watanabe 8f388c4e46 network/tuntap: code cleanups
- merge unnecessarily split functions,
- drop unnecessary initializations,
- tighten variable scopes,
- introduce TUNTAP() helper function.
2022-08-16 21:49:04 +09:00
Richard Phibel ead3a3fc87 config-parser: Add list of drop-in files as return argument of config_parse_many
This will be used to save the list of drop-in files for each partition
2022-08-12 12:48:29 +02:00
Yu Watanabe e33232d405 network: also check SR-IOV PF port and other VF ports before configuring
When a PF port becomes down (this can happens e.g. the PF port is joining
a bond interface), some drivers make its VF ports also become down, and
may cause failures in configuring VF ports.

Similary, when a VF port become down, some drivers make its PF port and
other VF ports down.

Let's configure SR-IOV ports (both PF and VFs) after all link-layer
settings of all ports being applied.

Fixes #23315.
2022-08-05 21:49:27 +09:00
Yu Watanabe 00117f8811 network: split out link_is_ready_to_create_stacked_netdev()
Preparation for later commits.
2022-08-05 21:49:27 +09:00
Yu Watanabe 4b482e8bf4 network: check link state with link_is_ready_to_configure() before configuring DHCP client or friends
Otherwise, DHCP client or friends may started before link-layer properties,
e.g. MAC address, being configured or the link being activated.
2022-08-05 21:49:27 +09:00
Lennart Poettering 4f80cfca5e pid1: add mechanism for conditionalizing units/network/netdev/link based on credentials passed in
This is useful when provisioning systems via nspawn/qemu and running
specific services only if specific data is passed into the system.
2022-07-15 10:53:45 +02:00
Yu Watanabe d5ad2ec1d4 network: drop redundant warning
If file is world readable, then `read_full_file_full()` will warn
about that.
2022-07-09 01:09:23 +01:00
Zbigniew Jędrzejewski-Szmek 71193c0b62 sd-event: allow sd_event_source_is_enabled() to return false for NULL
This is a natural use case, and instead of defining a wrapper to do this
for us, let's just make this part of the API. Calling with NULL was not
allowed, so this is not a breaking change to the interface.

(After sd_event_source_is_enabled was originally added, we introduced
sd_event_source_disable_unref() and other similar functions which accept
NULL. So not accepting NULL here is likely to confuse people. Let's just
make the API usable with minimal fuss.)
2022-06-30 10:35:27 +02:00
Shreenidhi Shedi a4433b4532 network: l2tp: initialize a to NULL
Fixes: CID#1475788
2022-06-13 08:41:52 +09:00
Zbigniew Jędrzejewski-Szmek c71384a9ee basic/in-addr-util: add IN_ADDR_PREFIX_TO_STRING 2022-06-06 09:52:52 +02:00
Zbigniew Jędrzejewski-Szmek 84dbb3fd83 basic/in-addr-util: add IN_ADDR_TO_STRING
Since we don't need the error value, and the buffer is allocated with a fixed
size, the whole logic provided by in_addr_to_string() becomes unnecessary, so
it's enough to wrap inet_ntop() directly.

inet_ntop() can only fail with ENOSPC. But we specify a buffer that is supposed
to be large enough, so this should never fail. A bunch of tests of this are added.
This allows all the wrappers like strna(), strnull(), strempty() to be dropped.

The guard of 'if (DEBUG_LOGGING)' can be dropped from around log_debug(),
because log_debug() implements the check outside of the function call. But
log_link_debug() does not, so it we need it to avoid unnecessary evaluation of
the formatting.
2022-06-06 09:52:52 +02:00
Yu Watanabe 98406eda8a network/erspan: support erspan version 0 and 2
This also makes networkd accepts erspan index 0.

Closes #23570.
2022-06-01 04:02:48 +09:00
Yu Watanabe 5984b92726 network: l2tp: refuse null address 2022-04-17 09:31:35 +09:00
Yu Watanabe 96d96ec4e7 network: tunnel: handle null address as "any"
Fixes oss-fuzz#44881 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=44881).

Fixes #23098.
2022-04-17 09:31:30 +09:00
Zbigniew Jędrzejewski-Szmek c3eaba2d3d Move path_simplify_and_warn() to new shared/parse-helpers.c
This is a high-level function, and it belongs in libsystemd-shared. This way we
don't end up linking a separate copy into various binaries. It would even end
up in libsystemd, where it is not needed. (Maybe it'd be removed in some
optimization phase, but it's better to not rely on that.)

$ grep -l -r -a 'path is not absolute%s' build/
build/libnss_systemd.so.2
build/pam_systemd_home.so
build/test-dlopen
build/src/basic/libbasic.a.p/path-util.c.o
build/src/basic/libbasic.a
build/src/shared/libsystemd-shared-249.so
build/test-bus-error
build/libnss_mymachines.so.2
build/pam_systemd.so
build/libnss_resolve.so.2
build/libnss_myhostname.so.2
build/libsystemd.so.0.32.0
build/libudev.so.1.7.2

$ grep -l -r -a 'path is not absolute%s' build/
build/src/shared/libsystemd-shared-251.a.p/parse-helpers.c.o
build/src/shared/libsystemd-shared-251.a
build/src/shared/libsystemd-shared-251.so

No functional change.
2022-04-07 18:25:55 +02:00
Yu Watanabe 61ec7beaf5 network: always log error in network_load_one() and netdev_load_one() 2022-04-05 02:02:42 +09:00
Lennart Poettering ba4e0427e9 time-util: assume CLOCK_BOOTTIME always exists
Let's raise our supported baseline a bit: CLOCK_BOOTTIME started to work
with timerfd in kernel 3.15 (i.e. back in 2014), let's require support
for it now.

This will raise our baseline only modestly from 3.13 → 3.15.
2022-03-28 16:55:41 +02:00
Yu Watanabe ec4954d934 network: rename netdev kind virtual-wlan -> wlan
The Kind= setting in [Match] section of .network files takes "wlan".
This makes the same setting in .netdev files matches the one in .network
files.
2022-03-28 23:53:12 +09:00
Yu Watanabe de010b0b2e strv: make iterator in STRV_FOREACH() declaread in the loop
This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
2022-03-19 08:33:33 +09:00
Yu Watanabe 80a226b26b list: make LIST_FOREACH() and LIST_FOREACH_BACKWARDS() safer 2022-03-19 08:10:29 +09:00
Yu Watanabe 03677889f0 list: declare iterator of LIST_FOREACH() in the loop 2022-03-19 08:10:29 +09:00
Luca Boccassi 1bd29614ff Merge pull request #22631 from yuwata/network-redesign-request-queue
network: re-design request queue
2022-03-11 10:48:45 +00:00