Commit Graph

17 Commits

Author SHA1 Message Date
Lennart Poettering ae2a15bc14 macro: introduce TAKE_PTR() macro
This macro will read a pointer of any type, return it, and set the
pointer to NULL. This is useful as an explicit concept of passing
ownership of a memory area between pointers.

This takes inspiration from Rust:

https://doc.rust-lang.org/std/option/enum.Option.html#method.take

and was suggested by Alan Jenkins (@sourcejedi).

It drops ~160 lines of code from our codebase, which makes me like it.
Also, I think it clarifies passing of ownership, and thus helps
readability a bit (at least for the initiated who know the new macro)
2018-03-22 20:21:42 +01:00
Zbigniew Jędrzejewski-Szmek 5360d77131 netdev: use "relaxed" parsing
We parse each netdev file twice: once to determine the type and match conditions,
and then the second time properly. In bcde742e78
the flags for the first parsing were (inadvertently I assume) were changed to
emit warnings. But this first pass is called with only [Match] and [NetDev] sections,
so we'd get warnings about all other section types. The obvious solution would be
to remove CONFIG_PARSE_WARN again, but I think it's better to keep the warnings
and set CONFIG_PARSE_RELAXED: we do want to get warnings about malformed lines and
such, and _RELAXED is enough to kill warnings about unknown sections.
2018-01-11 13:04:11 +01:00
Zbigniew Jędrzejewski-Szmek 2269954112 Merge pull request #7191 from Mic92/systemd
The change in netdev.c done in the merge is necessary to avoid crashing in
cleanup. This is a follow-up for f3c33b234d.
2018-01-09 14:35:54 +01:00
Jörg Thalheim e5719363f5 networkd: add support for wireguard interface type
More information may be found at wireguard.com.
2018-01-09 14:00:49 +01:00
Jörg Thalheim 05d0c2e3cf sd-netlink: add generic netlink support
This also adds the ability to incorporate arrays into netlink messages
and to determine when a netlink message is too big, used by some generic
netlink protocols.
2018-01-09 14:00:49 +01:00
Lennart Poettering f3c33b234d networkd: fix memory corruption
When loading .netdev files we parse them twice: first we do one parsing
iteration to figure out their "kind", and then we do it again to parse
out the kind's parameters. The first iteration is run with a "short"
NetDev structure, that only covers the generic NetDev properties. Which
should be enough, as we don't parse the per-kind properties. However,
before this patch we'd still try to destruct the per-kind properties
which resulted in memory corruption. With this change we distuingish the
two iterations by the state field, so that the destruction only happens
when the state signals we are running with a full NetDev structure.

Since this is not obvious, let's add a lot of comments.
2018-01-05 13:59:12 +01:00
Lennart Poettering 5022f08a23 core,udev,networkd: add ConditionKernelVersion=
This adds a simple condition/assert/match to the service manager, to
udev's .link handling and to networkd, for matching the kernel version
string.

In this version we only do fnmatch() based globbing, but we might want
to extend that to version comparisons later on, if we like, by slightly
extending the syntax with ">=", "<=", ">", "<" and "==" expressions.
2017-12-26 17:39:44 +01:00
Zbigniew Jędrzejewski-Szmek 281bb5c110 network: fix memory leak when an netdev was skipped
In general we'd leak anything that was allocated in the first parsing of
netdev, e.g. netdev name, host name, etc. Use normal netdev_unref to make sure
everything is freed.

--- command ---
/home/zbyszek/src/systemd/build2/test-network
--- stderr ---
/etc/systemd/network/wg0.netdev:3: Failed to parse netdev kind, ignoring: wireguard
/etc/systemd/network/wg0.netdev:5: Unknown section 'WireGuard'. Ignoring.
/etc/systemd/network/wg0.netdev:9: Unknown section 'WireGuardPeer'. Ignoring.
NetDev has no Kind configured in /etc/systemd/network/wg0.netdev. Ignoring
/etc/systemd/network/br0.network:13: Unknown lvalue 'NetDev' in section 'Network'
br0: netdev ready

=================================================================
==11666==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x7f3a314cf238 in __interceptor_strdup (/lib64/libasan.so.4+0x77238)
    #1 0x7f3a30e71ad1 in free_and_strdup ../src/basic/string-util.c:870
    #2 0x7f3a30d34fba in config_parse_ifname ../src/shared/conf-parser.c:981
    #3 0x7f3a30d2f5b0 in next_assignment ../src/shared/conf-parser.c:155
    #4 0x7f3a30d30303 in parse_line ../src/shared/conf-parser.c:273
    #5 0x7f3a30d30dee in config_parse ../src/shared/conf-parser.c:390
    #6 0x7f3a30d310a5 in config_parse_many_files ../src/shared/conf-parser.c:428
    #7 0x7f3a30d3181c in config_parse_many ../src/shared/conf-parser.c:487
    #8 0x55b4200f9b00 in netdev_load_one ../src/network/netdev/netdev.c:634
    #9 0x55b4200fb562 in netdev_load ../src/network/netdev/netdev.c:778
    #10 0x55b4200c607a in manager_load_config ../src/network/networkd-manager.c:1299
    #11 0x55b4200818e0 in test_load_config ../src/network/test-network.c:128
    #12 0x55b42008343b in main ../src/network/test-network.c:254
    #13 0x7f3a305f8889 in __libc_start_main (/lib64/libc.so.6+0x20889)

SUMMARY: AddressSanitizer: 4 byte(s) leaked in 1 allocation(s).
-------
2017-12-20 16:17:29 +01:00
Susant Sahani d6df583c87 networkd: introduce vxcan netdev. (#7150)
Similar to the virtual ethernet driver veth, vxcan implements a
local CAN traffic tunnel between two virtual CAN network devices.
When creating a vxcan, two vxcan devices are created as pair
When one end receives the packet it appears on its pair and vice
versa. The vxcan can be used for cross namespace communication.
2017-11-22 08:23:22 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Lennart Poettering bcde742e78 conf-parser: turn three bool function params into a flags fields
This makes things more readable and fixes some issues with incorrect
flag propagation between the various flavours of config_parse().
2017-11-13 10:24:03 +01:00
Lennart Poettering b50846055e exec-util,conf-files: skip non-executable files in execute_directories()
Fixes: #6787
2017-09-13 11:42:31 +02:00
Susant Sahani 4d7fa6de3b networkd: Allow tunnels to be created without .network (#6701)
Now we don't support tunnels to be created without a .network file
that is we need a interface index.

This work allows tunnel to be created without a ifindex.

Closes #6695
2017-08-31 18:51:03 +02:00
Roelf Wichertjes 14b6bb7762 networkd: Add check to ensure link is down before attempting to enslave (#5853)
netdev to bond.

There are situations where a link can be in an "UP" state when
 systemd-networkd attempts to add the link to a bond device.
This is a problem because the bonding driver will refuse to
 enslave a link if it is in the "UP" state.
This check ensures systemd-networkd sets the link to "DOWN"
 before attempting to add the link to the bond.

Fixes #5838.
2017-04-30 13:12:32 +02:00
Susant Sahani 6598e04641 networkd: Introduce GENEVE netdev
This work enables cration of geneve tunnel
2017-04-25 10:34:15 +05:30
Tom Gundersen 23f53b99b1 networkd: clean up main header file a bit
Rename networkd.h to networkd-manager.h, to more accurately describe what it
contains.
2016-11-14 01:05:06 +01:00
Tom Gundersen 441e9ae4d9 networkd: netdev - move to separate subdirectory
This could (and should) be made into a separate daemon, at least move
the sourcefiles out for now.
2016-11-13 05:16:49 +01:00
Renamed from src/network/networkd-netdev.c (Browse further)