Commit Graph
4919 Commits
Author SHA1 Message Date
Mike Yuan bdd2036e81 hexdecoct: make unbase64mem and unhexmem always use SIZE_MAX 2024-01-09 03:59:15 +09:00
Lennart Poettering 1a30285590 network-generator: pick up .netdev/.link/.network configuration via credentials
To me this is the last major basic functionality that couldn't be
configured via credentials: the network.

We do not invent any new format for this, but simply copy relevant creds
1:1 into /run/systemd/network/ to open up the full functionality of
networkd to VM hosts.
2024-01-08 12:59:08 +01:00
Yu Watanabe 0417d1d0e8 Merge pull request #30803 from yuwata/network-route-parser-trivial-cleanups
network/route: trivial cleanups for conf parsers
2024-01-07 05:26:06 +09:00
Yu Watanabe 74e95e3a81 network/link: always join to the main interface when we receive IFLA_MASTER attribute
Otherwise, e.g. when we enumerate a bridge port first, then the bridge
main interface, then the port cannot be managed by the main interface.

Fixes #30682.
2024-01-07 05:25:55 +09:00
Yu Watanabe 5c64017aa8 network/route-metric: unify error messages 2024-01-07 01:39:58 +09:00
Yu Watanabe e2126e235e network/route-metric: pass attribute type to conf parsers
The passed attribute type will be used later.

This also
- rename conf parsers,
- sort gperf entries by the attr type.

No functional change, just refactoring and preparation for later commits.
2024-01-07 01:39:58 +09:00
Yu Watanabe df8767fc8d network/route: move several conf parsers to networkd-route-metric.c and networkd-route-nexthop.c
This also split config_parse_route_boolean() into two:
for GatewayOnline= and boolean route metrics.

No functional change, just refactoring and preparation for later commits.
2024-01-07 01:39:58 +09:00
Yu Watanabe f48e52bda8 network/route: rename n -> route in conf parsers 2024-01-07 01:39:58 +09:00
Yu Watanabe d2bec2426f network/route: do not invalidate [Route] section when an empty string is assigned to MultiPathRoute= 2024-01-07 01:39:58 +09:00
Yu Watanabe 0d1706b5fa Merge pull request #30775 from yuwata/network-nexthop-is-ready
network: introduce nexthop_is_ready() helper function and use it
2024-01-06 08:27:35 +09:00
networkException dcfac3a3f9 parse-helpers: allow port 0 for socket bind items
This patch adds a new parameter to parse_ip_port_range, giving callers
the option to allow ranges to have their min be 0 instead of 1.

This is then used by parse_ip_ports_token, intern used by
parse_socket_bind_item to allow port 0 when restricting bind system
calls with SocketBindDeny / SocketBindAllow.

With this, users running server software written using the golang
standard library will be able to effectively sandbox their software,
albeit with a small loss in security protections by allowing the
process to bind on a random port in the
/proc/sys/net/ipv4/ip_local_port_range.
2024-01-06 08:27:14 +09:00
Lennart Poettering f0e4244b2f tree-wide: use JSON_ALLOW_EXTENSIONS when disptching at various places
If we want to allow method replies to be extended without this breaking
compat, then we should set this flag. Do so at various method call
replies hence.

Also do it when parsing user/group records, which are expressly
documented to be extensible, as well as the hibernate JSON record.
2024-01-05 12:43:06 +01:00
Yu Watanabe 2743854540 network: do not make the implied default have the first priority
Follow-up for b732606950 and
6706ce2fd2.

If Network.ignore_carrier_loss_set flag is set, then the timeout value
is always used, hence the logic implemented by
b732606950 never worked.
2024-01-05 18:04:18 +09:00
Yu Watanabe b87ffa9b5a network/route: use nexthop_is_ready() 2024-01-05 05:33:49 +09:00
Yu Watanabe ccc55b5ec5 network/nexthop: wait for requests for group members being processed
This also split out the check as nexthop_is_ready().
2024-01-05 05:33:49 +09:00
Yu Watanabe 338fb16ad5 network/nexthop: refuse id == 0 earlier
All requested nexthop has a non-zero ID.
2024-01-05 05:33:49 +09:00
Yu Watanabe 18c4c5d84f network/route: make the route section invalid when an invalid MTUBytes= is specified
We usually set the invalid flag for a section if a setting in the section has
an invalid value. Let's also do the same thing for MTUBytes= in [Route].
2024-01-04 23:18:28 +09:00
Lennart Poettering 96fc8cab2a Merge pull request #30578 from bluca/polkit-varlink
varlink: add glue to allow authenticating varlink connections via polkit
2024-01-04 15:15:45 +01:00
Yu Watanabe f475584ebf network/netdev: call done() per netdev kind before freeing netdev name or so
Otherwise, log_netdev_xyz() does not provide netdev name if it is called
in done(). It is hard to debug.

This should not change any effective behavior, at least with the current
implementation of done() per netdev kind.
2024-01-04 20:34:14 +08:00
Dmitry Konishchev 0e1ab2261c Fix KeepCarrier tun/tap device option
When KeepCarrier is set, networkd doesn't close tun/tap file descriptor
preserving the active interface state, but doesn't disable its queue
which makes kernel to think that it's still active and send packets to
it.

This patch disables the created queue right after tun/tap interface
creation.

Here is the steps to reproduce the bug:

Having:

systemd/network/10-tun-test.netdev:

    [NetDev]
    Name=tun-test
    Kind=tun

    [Tun]
    MultiQueue=yes
    KeepCarrier=yes

systemd/network/10-tun-test.network:

    [Match]
    Name=tun-test

    [Network]
    DHCP=no
    IPv6AcceptRA=false

    LLMNR=false
    MulticastDNS=false

    Address=172.31.0.1/24

app.c:

    #include <fcntl.h>
    #include <stdio.h>
    #include <string.h>
    #include <unistd.h>
    #include <linux/if.h>
    #include <sys/ioctl.h>
    #include <linux/if_tun.h>

    int main() {
        int fd;
        struct ifreq ifr;

        memset(&ifr, 0, sizeof ifr);
        strcpy(ifr.ifr_name, "tun-test");
        ifr.ifr_flags = IFF_TUN | IFF_NO_PI | IFF_MULTI_QUEUE;

        if((fd = open("/dev/net/tun", O_RDWR)) < 0) {
            perror("Open error");
            return 1;
        }

        if(ioctl(fd, TUNSETIFF, &ifr)) {
            perror("Configure error");
            return 1;
        }

        puts("Ready.");

        char buf[1500];

        while(1) {
            int size = read(fd, buf, sizeof buf);
            if(size < 0) {
                perror("Read error");
                return 1;
            }
            printf("Read %d bytes.\n", size);
        }

        return 0;
    }

Run:
* gcc -o app app.c && ./app
* ping -I tun-test 172.31.0.2

Before the patch the app shows no pings, but after it works properly.
2024-01-04 04:37:39 +09:00
Lennart Poettering 56f20e3a46 Merge pull request #30704 from yuwata/sd-dhcp-server-lease
dhcp-server: use sd_dhcp_client_id and split out lease handling to sd-dhcp-server-lease.[ch]
2024-01-03 13:58:30 +01:00
Lennart Poettering 52be84f52c Merge pull request #30697 from yuwata/network-address-remove-and-cancel
network/address: several cleanups for address removal
2024-01-03 13:55:26 +01:00
Lennart Poettering 2a1ffd3e3a bus-polkit: port polkit_registry to use value destructors in hash_ops 2024-01-03 11:53:52 +01:00
Mike Yuan 7c2e495c75 Merge pull request #30694 from yuwata/sd-netlink-move-macro-and-introduce-tos-getter
sd-netlink: two cleanups
2024-01-03 18:47:12 +08:00
Yu Watanabe dd8ab4a206 sd-dhcp-server: rename DHCPLease -> sd_dhcp_server_lease
Then, move basic functions for the object to sd-dhcp-server-lease.[ch].

No effective funcional changes.
2024-01-03 15:20:31 +09:00
Yu Watanabe 95c48613f4 sd-dhcp-server: use sd_dhcp_client_id 2024-01-03 15:20:31 +09:00
Yu Watanabe 12fb1fc5dd Merge pull request #30702 from yuwata/sd-dhcp-client-id
dhcp: introduce sd_dhcp_client_id and relevant functions
2024-01-03 15:10:46 +09:00
Yu Watanabe cb0a3b8c14 network/route: drop TTL propagate support for MPLS routes
This effectively reverts 9b88f20aba.

We do not support MPLS routes, only IPv4 or IPv6 routes are supported.
2024-01-03 08:41:53 +09:00
Yu Watanabe 6ba147485e network/queue: fix potential double-free on oom
Currently, link_queue_request_safe(), which is a wrapper of
request_new(), is called with a free function at
- link_request_stacked_netdev() at netdev/netdev.c,
- link_request_address() at networkd-address.c,
- link_request_nexthop() at networkd-nexthop.c,
- link_request_neighbor() at networkd-networkd.c.

For the netdev case, the reference counter of the passed object is increased
only when the function returns 1. So, on failure (with -ENOMEM)
previously we unexpectedly dropped the reference of the NetDev object.
Similarly, for Address and friends, the ownership of the object is moved to the
Request object only when the function returns 1. And on failure, previously
the object was freed twice.

Also, netdev_queue_request(), which is another wrapper of request_new()
potentially leaks memory when the same NetDev object is queued twice.
Fortunately, that should not happen as the function is called only once
per object.

This fixes the above issue, and now the ownership or the reference
counter of the object is changed only when it is succeeded with 1.
2024-01-03 08:41:36 +09:00
Yu Watanabe d59a2b3bf5 sd-dhcp-lease: use sd_dhcp_client_id 2024-01-03 06:06:39 +09:00
Yu Watanabe 1809132064 dhcp: move sd_dhcp_client_id_to_string() to sd-dhcp-client-id.[ch]
Then, this makes it take sd_dhcp_client_id object, and introduce
sd_dhcp_client_id_to_string_from_raw().
2024-01-03 06:06:36 +09:00
Yu Watanabe f22b586a21 network/address: introduce address_remove_and_cancel()
Then, replace address_remove_and_drop() with it.

If an address is requested, and the request is already called,
we may not received its reply and notification from the kernel, and
the corresponding address object may not be remmbered. Even in such
case, we need to remove the address, otherwise the address will come
later after the function called.
2024-01-03 04:43:34 +09:00
Yu Watanabe f1b73dbbc9 network/address: not necessary to remmber address before remove 2024-01-03 04:43:34 +09:00
Yu Watanabe 7f74b00ab0 network/address: make address_remove() take Link object that the address assigned to
No functional change. Preparation for later commits.
2024-01-03 04:43:34 +09:00
Yu Watanabe 8f8b39c86b sd-netlink: move definitions of RTA_TYPE() and RTA_FLAGS() to netlink-util.h 2024-01-03 04:21:28 +09:00
Luca Boccassi 86b8b66675 Merge pull request #30591 from yuwata/device-util
device-util: introduce device_in_subsystem() and device_is_devtype() helper functions
2024-01-01 19:26:39 +01:00
Luca Boccassi 9d75598bc4 Merge pull request #30593 from yuwata/sd-dhcp-duid
dhcp: introduce sd_dhcp_duid and relevant functions
2024-01-01 19:24:31 +01:00
Yu Watanabe 1a4b0459f6 network/address: unconditionally check if address is ready
Previously, we checked if the address is ready only when it is an IPv6
address. But, IPv4 address never enter tentative state, hence the check
for an IPv4 address is effectively equivalent to the one for IPv6.
So, let's unify the check. This does not change any effective behavior.
2023-12-28 07:08:37 +09:00
Luca Boccassi 74ce6bbdee Merge pull request #30631 from yuwata/network-address-free
network/address: tiny cleanups for address_free()
2023-12-26 19:21:15 +01:00
Yu Watanabe fe3fcb9492 Merge pull request #30633 from mrc0mmand/cocci-shenanigans
coccinelle: rework how we run the Coccinelle transformations
2023-12-26 05:45:58 +09:00
Frantisek Sumsal 50f605bfe6 network: use timestamp_is_set() in one more place 2023-12-25 18:26:59 +01:00
Frantisek Sumsal 4b68f70829 network: ENOTSUP -> EOPNOTSUPP 2023-12-25 18:26:59 +01:00
Yu Watanabe 372acaad58 network: use RET_GATHER() macro 2023-12-25 22:02:14 +08:00
Yu Watanabe f089d3ebd5 network/address: move post-processes on address removal to address_drop()
For consistency with other follow-up processes after address removal.

No functional change, just refactoring and preparation for later
commits.
2023-12-25 20:19:40 +09:00
Yu Watanabe 8ae3a4f5e2 network/address: also drop reference for DHCP server address
The Address object should never freed after it is referenced.
So, this should not change any behavior. Just for safety.
2023-12-25 20:19:40 +09:00
Mike Yuan 0a0f49556f Merge pull request #30622 from yuwata/space
tree-wide: drop unnecessary space or insert missing space
2023-12-25 17:52:48 +08:00
Yu Watanabe c01a5c0527 siphash24: introduce siphash24_compress_typesafe() macro
To prevent copy-and-paste mistake.

This also introduce in_addr_hash_func().

No functional change, just refactoring.
2023-12-25 15:38:59 +09:00
Yu Watanabe b3a9d980f3 tree-wide: drop space between variable and an increment/decrement 2023-12-25 01:56:40 +09:00
Yu Watanabe 6ae5d4b52f coccinelle: convert hashmap_size() == 0 or friends
Addresses https://github.com/systemd/systemd/pull/30567#issuecomment-1866631816.
2023-12-25 00:47:42 +09:00
Raito Bezarius b49595503d networkd: support proxy_arp_pvlan sysctl
The proxy ARP private VLAN sysctl is useful for VLAN aggregation, see
https://sysctl-explorer.net/net/ipv4/proxy_arp_pvlan/ for details.
2023-12-24 03:40:03 +09:00