Commit graph

2207 commits

Author SHA1 Message Date
Yu Watanabe 14b6e6b6f3 sd-netlink: use uint8_t* for non-character data 2020-01-06 14:50:41 +01:00
Lennart Poettering dc5737470e
Merge pull request #14194 from yuwata/network-multipath-routing-12541
network: introduce multipath routing
2020-01-03 15:38:03 +01:00
Lennart Poettering 49d418d4ab
Merge pull request #14444 from yuwata/network-codel-more
network: more CoDel settings
2020-01-02 14:51:55 +01:00
Frantisek Sumsal e514aa1eea tree-wide: yet another batch of coccinelle recommendations
Prettify certain parts of the codebase using coccinelle transformations
(no functional changes).
2020-01-02 13:32:55 +01:00
Yu Watanabe b078e52855 network: add more settings for CoDel 2019-12-28 22:25:12 +09:00
Susant Sahani a9a5d632da network: tc introduce codel
Please see http://man7.org/linux/man-pages/man8/tc-codel.8.html
2019-12-28 21:35:39 +09:00
Lennart Poettering ecb040643d
Merge pull request #14376 from poettering/sd-event-no-stack
sd-event: don't use stack for event queue array
2019-12-18 17:18:07 +01:00
Lennart Poettering 0c8e33b6e9
Merge pull request #14377 from keszybz/fixups
Fixups
2019-12-18 16:21:20 +01:00
Yu Watanabe 6497a8aa9b sd-netlink: introduce rtattr_append_attribute()
It will be used in later commit.
2019-12-18 22:12:57 +09:00
Lennart Poettering 5cddd924aa sd-event: don't allocate event queue array on stack
We might have quite a number of event sources, hence allocate this in a
buffer we can reuse on the heap, rather than on the stack.
2019-12-18 10:59:27 +01:00
Zbigniew Jędrzejewski-Szmek 4023637a8a Restore silent handling of BUS_ERROR_SPEED_METER_INACTIVE
This only matters for the case where new networkctl is running against older
networkd. We should still handle the old error to avoid unnecessary warning
about speedmeeter being disabled.

This partially reverts commit e813de549b.
2019-12-18 08:48:33 +01:00
Yu Watanabe b04c5e51da sd-netlink: introduce rtnl_resolve_link_alternative_names() 2019-12-18 00:05:50 +09:00
Yu Watanabe 6e5df4036f
Merge pull request #14337 from yuwata/network-tc-fq-more
network: tc: introduce more FQ settings
2019-12-17 23:30:10 +09:00
Yu Watanabe 6d185cffb1 sd-netlink: add a whitespce between cast operator and variable 2019-12-17 17:36:08 +09:00
Yu Watanabe f501c25151 sd-netlink: make netlink_container_parse() takes size_t for rt_len
And use another unsigned short variable for RTA_OK() macro.
2019-12-17 17:35:25 +09:00
Yu Watanabe a5053a158b udev: support AlternativeName= setting in .link file 2019-12-16 10:52:22 +09:00
Yu Watanabe d08d92d5ee test: add a test for sd_netlink_message_{append,read}_strv() 2019-12-16 10:52:22 +09:00
Yu Watanabe 6d725977c4 sd-netlink: introduce sd_netlink_message_append_strv() 2019-12-16 10:52:22 +09:00
Yu Watanabe 8f3c185966 sd-netlink: introduce sd_netlink_message_read_strv()
The combination of sd_netlink_message_enter_container() and
sd_netlink_message_read_string() only reads the last element if the attribute is
duplicated, such a situation easily happens for IFLA_ALT_IFNAME.
The function introduced here reads all matched attributes.
2019-12-16 10:52:17 +09:00
Yu Watanabe ffeb16f5d8 sd-netlink: support IFLA_PROP_LIST and IFLA_ALT_IFNAME attributes 2019-12-16 04:37:50 +09:00
Yu Watanabe e83562e51e network: tc: add more settings for FQ 2019-12-13 23:36:17 +09:00
Yu Watanabe eb34f4b3d2 sd-netlink: add attributes for FQ 2019-12-12 16:23:26 +09:00
Yu Watanabe 42b5f7dd32 sd-netlink: make TCA_OPTIONS take NETLINK_TYPE_UNION 2019-12-11 16:30:39 +09:00
Lennart Poettering 5905d7cf5b tree-wide: use SD_ID128_STRING_MAX where appropriate 2019-12-10 11:56:18 +01:00
Lennart Poettering b5ea030d65 id128: introduce ID128_UUID_STRING_MAX for sizing UUID buffers 2019-12-10 11:56:18 +01:00
Yu Watanabe 8ee08dc564 test: do not fail if new device is plugged during enumeration 2019-12-09 08:45:25 +00:00
Susant Sahani cec1552ad4 sd-netlink: add support for ifb device 2019-12-07 14:35:23 +01:00
Zbigniew Jędrzejewski-Szmek 9142bbd19c
Merge pull request #14209 from poettering/sd-bus-sensitive
sd-bus bits from homed PR
2019-12-05 10:22:01 +01:00
Anita Zhang da4dd97405
Merge pull request #14173 from ssahani/tc-sfq
network: tc: introduce sfq and tbf
2019-12-04 16:14:11 -08:00
Lennart Poettering 6f0245b342 sd-bus: don't include properties maked as "emit-invalidation" in InterfacesAdded signals
Properties marked this way really shouldn't be sent around willy-nilly,
that's what the flag is about, hence exclude it from InterfacesAdded
signals (and in fact anything that is a signal).
2019-12-04 13:46:23 +01:00
Lennart Poettering 7a77d2a41c sd-bus: add new call sd_bus_message_sensitive() and SD_BUS_VTABLE_SENSITIVE
This allows marking messages that contain "sensitive" data with a flag.
If it's set then the messages are erased from memory when the message is
freed.

Similar, a flag may be set on vtable entries: incoming/outgoing message
matching the entry will then automatically be flagged this way.

This is supposed to be an easy method to mark messages containing
potentially sensitive data (such as passwords) for proper destruction.

(Note that this of course is only is as safe as the broker in between is
doing something similar. But let's at least not be the ones at fault
here.)
2019-12-04 13:46:23 +01:00
Susant Sahani ba5841b520 networkd tc: introduce tbf
See https://linux.die.net/man/8/tc-tbf
2019-12-04 20:55:48 +09:00
Lennart Poettering e544601536 sd-event: refuse running default event loops in any other thread than the one they are default for 2019-12-04 10:36:28 +01:00
Lennart Poettering 3ecb3bdc93 test: add test for pidfd support in sd-event 2019-12-04 10:35:39 +01:00
Lennart Poettering ee880b37c1 sd-event: refuse sd_event_add_child() if SIGCHLD is not blocked
We already refuse sd_event_add_signal() if the specified signal is not
blocked, let's do this also for sd_event_add_child(), since we might
need signalfd() to implement this, and this means the signal needs to be
blocked.
2019-12-04 10:35:27 +01:00
Lennart Poettering d1b75241ba sd-event: make use of new signal_is_blocked() helper 2019-12-04 10:35:16 +01:00
Lennart Poettering f8f3f9263e sd-event: add pidfd support
This adds support for watching for process exits via Linux new pidfd
concept. This makes watching processes and killing them race-free if
properly used, fixing a long-standing UNIX misdesign.

This patch adds implicit and explicit pidfd support to sd-event: if a
process shall be watched and is specified by PID we will now internally
create a pidfd for it and use that, if available. Alternatively a new
constructor for child process event sources is added that takes pidfds
as input.

Besides mere watching of child processes via pidfd two additional
features are added:

→ sd_event_source_send_child_signal() allows sending a signal to the
  process being watched in the safest way possible (wrapping
  the new pidfd_send_signal() syscall).

→ sd_event_source_set_child_process_own() allows marking a process
  watched for destruction as soon as the event source is freed. This is
  currently implemented in userspace, but hopefully will become a kernel
  feature eventually.

Altogether this means an sd_event_source object is now a safe and stable
concept for referencing processes in race-free way, with automatic
fallback to pre-pidfd kernels.

Note that this patch adds support for this only to sd-event, not to PID
1. That's because PID 1 needs to use waitid(P_ALL) for reaping any
process that might get reparented to it. This currently semantically
conflicts with pidfd use for watching processes since we P_ALL is
undirected and thus might reap process earlier than the pidfd notifies
process end, which is hard to handle. The kernel will likely gain a
concept for excluding specific pidfds from P_ALL watching, as soon as
that is around we can start making use of this in PID 1 too.
2019-12-04 10:34:41 +01:00
Lennart Poettering 5a795bff38 sd-event: (void)ify some epoll_ctl() syscall invocations 2019-12-04 10:33:38 +01:00
Lennart Poettering d1cf202374 sd-event: drop unnecessary local variable 2019-12-04 10:32:59 +01:00
Zbigniew Jędrzejewski-Szmek 206056cf01
Merge pull request #14211 from yuwata/support-nlmsgerr_attr_msg
Support NLMSGERR_ATTR_MSG
2019-12-04 09:15:23 +01:00
Yu Watanabe e813de549b network: do not return error but return UINT64_MAX if speed meter is disabled
Fixes #14222.
2019-12-04 09:11:34 +01:00
Yu Watanabe e4a1e68d7a sd-netlink: support NLMSGERR_ATTR_MSG
From v4.12 the kernel appends some attributes to netlink acks
containing a textual description of the error and other fields.
This makes sd-netlink parse the attributes.
2019-11-30 16:13:51 +09:00
Lennart Poettering 19fa17c7c4 sd-bus: invalidate connection when Hello() fails
Fixes: #13969
2019-11-16 13:47:32 +01:00
Yu Watanabe 3126d64e5f sd-device-enumerator: do not return error when a device is removed
Fixes #13814.
2019-11-05 22:13:11 +01:00
Yu Watanabe 8e1e87a5de tree-wide: drop double newline 2019-11-04 00:30:32 +09:00
Yu Watanabe 92133d2878 tree-wide: drop socket.h when socket-util.h is included 2019-11-04 00:30:32 +09:00
Yu Watanabe 455fa9610c tree-wide: drop string.h when string-util.h or friends are included 2019-11-04 00:30:32 +09:00
Yu Watanabe f5947a5e92 tree-wide: drop missing.h 2019-10-31 17:57:03 +09:00
Lennart Poettering f598255951 sd-event: don't invalidate source type on disconnect
This fixes fd closing if fd ownership is requested.
2019-10-30 17:43:57 +01:00
Susant Sahani 0f5bd7fe24 network: introduce TrafficControl
Add network delay to a interface
2019-10-30 09:33:51 +09:00
Franck Bui 21b40f1662 fileio: introduce read_full_virtual_file() for reading virtual files in sysfs, procfs
Virtual filesystems such as sysfs or procfs use kernfs, and kernfs can work
with two sorts of virtual files.

One sort uses "seq_file", and the results of the first read are buffered for
the second read. The other sort uses "raw" reads which always go direct to the
device.

In the later case, the content of the virtual file must be retrieved with a
single read otherwise subsequent read might get the new value instead of
finding EOF immediately. That's the reason why the usage of fread(3) is
prohibited in this case as it always performs a second call to read(2) looking
for EOF which is subject to the race described previously.

Fixes: #13585.
2019-10-25 15:24:49 +02:00
Yu Watanabe 78404d22cc network: support matching based on wifi interfece type 2019-10-25 16:43:18 +09:00
Yu Watanabe f2106b1789
Merge pull request #13836 from systemd/assert-cleanups-and-constification
Assert cleanups and constification
2019-10-25 13:36:00 +09:00
Zbigniew Jędrzejewski-Szmek a5648b8094 basic/fs-util: change CHASE_OPEN flag into a separate output parameter
chase_symlinks() would return negative on error, and either a non-negative status
or a non-negative fd when CHASE_OPEN was given. This made the interface quite
complicated, because dependning on the flags used, we would get two different
"types" of return object. Coverity was always confused by this, and flagged
every use of chase_symlinks() without CHASE_OPEN as a resource leak (because it
would this that an fd is returned). This patch uses a saparate output parameter,
so there is no confusion.

(I think it is OK to have functions which return either an error or an fd. It's
only returning *either* an fd or a non-fd that is confusing.)
2019-10-24 22:44:24 +09:00
Zbigniew Jędrzejewski-Szmek de157fe2a7 sd-netlink: constify object pointers passed to getters
sd-netlink is not public yet, so we can change the interface.

I did not touch interfaces of functions like sd_netlink_wait() and
sd_rtnl_message_new_link() which do not modify the object that is passed in,
because in the future we might want to change the code to e.g. take a
reference to the parent object or otherwise require a non-const reference.
2019-10-24 11:48:08 +02:00
Zbigniew Jędrzejewski-Szmek 730b76bd2c sd-device: allow sd_device_get_devtype to be called with NULL arg and do not assert
We shouldn't call assert() on user-specified arguments in public functions.
While at it, let's return 1 if the type exists, and 0 otherwise.
2019-10-24 11:48:08 +02:00
Yu Watanabe a1d736e25c sd-netlink: add nl80211 type systems 2019-10-15 01:57:19 +09:00
Yu Watanabe 31e78d1042 sd-netlink: introduce sd_genl_message_get_family() 2019-10-15 01:57:19 +09:00
Yu Watanabe 2be081ffd6 sd-netlink: support NLMSG_DONE 2019-10-15 01:57:19 +09:00
Yu Watanabe 4e8f0ef921 sd-netlink: save dynamic general netlink message type 2019-10-15 01:57:19 +09:00
Yu Watanabe 2cac03f71d sd-netlink: drop unnecessarily exported variables 2019-10-15 01:57:19 +09:00
Yu Watanabe 59d4103fd5 sd-netlink: introduce sd_netlink_message_read_string_strdup() 2019-10-15 01:57:19 +09:00
Yu Watanabe 6bf8e24bad sd-netlink: use structured initializer 2019-10-15 01:57:19 +09:00
Yu Watanabe ddcda37016 sd-netlink: drop unused variable 2019-10-15 01:57:19 +09:00
Yu Watanabe 338ff28d5f sd-netlink: add missing license identifier 2019-10-15 01:57:19 +09:00
Susant Sahani c16c780804 network: introduce ip nexthop routing
Used to manipulate entries in the kernel's nexthop tables.
Example:
```
[NextHop]
Id=3
Gateway=192.168.5.1
```
2019-10-14 21:32:48 +09:00
Zbigniew Jędrzejewski-Szmek 86e94d95d0
Merge pull request #13246 from keszybz/add-SystemdOptions-efi-variable
Add efi variable to augment /proc/cmdline
2019-10-03 12:19:44 +02:00
Frantisek Sumsal a5d27871f7 sd-event: explicitly ignore waitipid()'s return value
Fixes CID#1393252
2019-10-01 10:25:12 +02:00
Yu Watanabe 82d1264048
Merge pull request #11883 from yuwata/network-dhcp-renew
network: dhcp renew
2019-09-22 07:44:23 +02:00
Yu Watanabe ae65d7dbe3 network: introduce new bus method Renew() and RenewLink() 2019-09-21 20:27:36 +09:00
Susant Sahani 299d578f7f network: DHCP server Add support to transmit SIP server
1. DHCP server trasmit
2. Client parses and saves in leases
Implements http://www.rfc-editor.org/rfc/rfc3361.txt

```
Frame 134: 348 bytes on wire (2784 bits), 348 bytes captured (2784 bits) on interface 0
Ethernet II, Src: 42:65:85:d6:4e:32 (42:65:85:d6:4e:32), Dst: 1e:04:f8:b8:2f:d4 (1e:04:f8:b8:2f:d4)
Internet Protocol Version 4, Src: 192.168.5.1, Dst: 192.168.5.11
User Datagram Protocol, Src Port: 67, Dst Port: 68
Dynamic Host Configuration Protocol (ACK)
    Message type: Boot Reply (2)
    Hardware type: Ethernet (0x01)
    Hardware address length: 6
    Hops: 0
    Transaction ID: 0x7cc87cb4
    Seconds elapsed: 0
    Bootp flags: 0x0000 (Unicast)
    Client IP address: 0.0.0.0
    Your (client) IP address: 192.168.5.11
    Next server IP address: 0.0.0.0
    Relay agent IP address: 0.0.0.0
    Client MAC address: 1e:04:f8:b8:2f:d4 (1e:04:f8:b8:2f:d4)
    Client hardware address padding: 00000000000000000000
    Server host name not given
    Boot file name not given
    Magic cookie: DHCP
    Option: (53) DHCP Message Type (ACK)
        Length: 1
        DHCP: ACK (5)
    Option: (51) IP Address Lease Time
        Length: 4
        IP Address Lease Time: (3600s) 1 hour
    Option: (1) Subnet Mask (255.255.255.0)
        Length: 4
        Subnet Mask: 255.255.255.0
    Option: (3) Router
        Length: 4
        Router: 192.168.5.1
    Option: (6) Domain Name Server
        Length: 4
        Domain Name Server: 192.168.5.1
    Option: (42) Network Time Protocol Servers
        Length: 4
        Network Time Protocol Server: 192.168.1.1
    Option: (120) SIP Servers <=====here
        Length: 9
        SIP Server Encoding: IPv4 Address (1)
        SIP Server Address: 192.168.1.1
        SIP Server Address: 192.168.5.2
    Option: (101) TCode
        Length: 13
        TZ TCode: Europe/Berlin
    Option: (54) DHCP Server Identifier (192.168.5.1)
        Length: 4
        DHCP Server Identifier: 192.168.5.1
    Option: (255) End
        Option End: 255
```

```
cat /run/systemd/netif/state                                                                                                   ✔    3148  16:40:51
OPER_STATE=routable
CARRIER_STATE=carrier
ADDRESS_STATE=routable
DNS=192.168.94.2 192.168.5.1
NTP=192.168.5.1
SIP=192.168.1.1 192.168.5.2

```

aa
2019-09-20 21:22:23 +09:00
Yu Watanabe 48fb0d1301 sd-netlink: fix invalid assertion
It is natural that n_attiributes is less than type. But in that case,
the message does not contain any message about the type. So, we should
not abort execution with assertion, but just return -ENODATA.
2019-09-17 21:53:42 +09:00
Zbigniew Jędrzejewski-Szmek d4d99bc6e4 basic/cgroup-util: let cgroup_unified_flush() return the detected hierarchy
This avoid the use of the global variable.

Also rename cgroup_unified_update() to cgroup_unified_cached() and
cgroup_unified_flush() to cgroup_unified() to better reflect their new roles.
2019-09-16 18:06:20 +02:00
Susant Sahani 611224d9fe sd-network: add support to get DHCP4 address 2019-09-09 20:01:33 +05:30
Zbigniew Jędrzejewski-Szmek 61252bae91 sd-bus: adjust indentation of comments 2019-08-27 19:49:09 +02:00
Zbigniew Jędrzejewski-Szmek 11791cdecc test-bus-vtable: also print introspection for the fallback vtable
This doesn't really test anything, it's just a trivial test that we
get the expected output for a fallback vtable.
2019-08-27 19:49:09 +02:00
Zbigniew Jędrzejewski-Szmek d0696f3b75
Merge pull request #13365 from keszybz/fix-commits-from-pr-13246
Fix commits from #13246
2019-08-22 09:13:25 +02:00
Zbigniew Jędrzejewski-Szmek 8788a56863 test-event: stop debugging spew
Ubuntu autopkgtests print output from all tests, and test-event produces
a lot of it. Let's cut it down to reasonable size.
2019-08-20 12:01:23 +02:00
William A. Kennington III d1bdafd214 networkd: Keep track of static neighbors
We need to keep track of the static neighbors that are configured on the
interface so that we can delete stale entries that were removed.
2019-08-12 20:28:19 +09:00
Zbigniew Jędrzejewski-Szmek 5d276aa201 sd-hwdb: use return value from ordered_hashmap_iterate()
Why not? Coverity CID#1402329.
2019-08-03 17:43:51 +02:00
Shreyas Behera 037dbb80d1 Add IFLA_BR_MCAST_IGMP_VERSION 2019-07-25 09:54:52 +09:00
Lennart Poettering 733cbd00b0 netlink: move local-addresses.[ch] to src/shared
This code is not part of the public API of sd-netlink, nor used by it
internally and hence should not be in the sd-netlink directory.

Also, move the test case for it to src/test/.
2019-07-24 09:06:50 +02:00
Yu Watanabe 1647f24100 sd-netlink: update comment 2019-07-19 07:14:58 +09:00
Zbigniew Jędrzejewski-Szmek 7b9103a622 sd-device: voidify and simplify calls to ordered_hashmap_iterate()
Coverity CID#1402356 and CID#1402335.
2019-07-17 11:35:04 +02:00
Zbigniew Jędrzejewski-Szmek 3d4d5abf2a sd-bus: voidify two calls to hashmap_iterate()
Coverity CID#1402304 and CID#1402307.
2019-07-17 11:35:04 +02:00
Yu Watanabe 8cec0a5c32 tree-wide: drop duplicated blank lines
```
$ for i in */*.[ch] */*/*.[ch]; do sed -e '/^$/ {N; s/\n$//g}' -i $i; done
$ git checkout HEAD -- basic/linux shared/linux
```
2019-07-15 18:41:27 +02:00
Lennart Poettering b910cc72c0 tree-wide: get rid of strappend()
It's a special case of strjoin(), so no need to keep both. In particular
as typing strjoin() is even shoert than strappend().
2019-07-12 14:31:12 +09:00
Lennart Poettering be9d8212a5
Merge pull request #13017 from yuwata/network-neighbor-lladdr-13015
network: rename Neighbor.MACAddress= and also support IPv4 address
2019-07-11 19:23:29 +02:00
Yu Watanabe 49808e0e2d network: NDA_LLADDR attribute can also take struct in_addr 2019-07-11 22:22:29 +09:00
Yu Watanabe 5dc3dbe855 sd-netlink: make sd_netlink_message_read() returns size of read data 2019-07-11 22:22:29 +09:00
Lennart Poettering 4d3bac5645 core: expose new clean operation on the bus
This adds CanClean() and Clean() as new methods on the Unit object that
initiate the cleaning operation.
2019-07-11 12:18:51 +02:00
Lennart Poettering 6b39223cd3 sd-bus: when installing a match make sure not to apply it to already queued messages
This tweaks match installation a bit: the match callbacks are now only
called for messages read after the AddMatch() reply was received and
never anything already read before. Thus, installing a match gives you a
time guarantee: only messages received after it will be matched.

This is useful when listening to PropertiesChanged signals as an example
to ensure that only changes after the point the match was installed are
honoured, nothing before.
2019-07-11 12:18:51 +02:00
Lennart Poettering 3cf8dd5359 sd-bus: destroy AddMatch() reply slot in failure case too
If AddMatch() doesn't work, let's destroy the slot for it too as soon as
we received the failure for it.

This way the mere existance of the slot tells us whether the AddMatch()
method call is still pending or is complete.
2019-07-11 12:18:51 +02:00
Lennart Poettering f1617a3b61 sd-bus: maintain a counter for incoming msgs
Let's count incoming messages and attach the current counter when we
first read them to the message objects. This allows us to nicely order
messages later on.
2019-07-11 12:18:51 +02:00
Lennart Poettering 08945b59d1
Merge pull request #12926 from keszybz/urlify-logs
Urlify CONFIG_FILE and improve SYSTEMD_LOG_LOCATION
2019-07-11 00:00:34 +02:00
Yu Watanabe f392c06566
Merge pull request #12863 from 1848/if_xfrm
Added support for xfrm interfaces
2019-07-10 23:04:49 +09:00
1848 98d20a17a9 Added support for xfrm interfaces 2019-07-10 23:02:19 +09:00
Yu Watanabe 4bbccb02ea tree-wide: introduce strerror_safe() 2019-07-05 02:43:56 +09:00
Yu Watanabe 442ac2692a sd-event: replace snprintf() with strpcpyf() 2019-07-05 02:43:56 +09:00
Yu Watanabe 9104009e5e test: add test for sd_netlink_message_enter_array() 2019-07-04 17:36:09 +09:00
Zbigniew Jędrzejewski-Szmek 62c6bbbc09 tree-wide: use PROJECT_FILE instead of __FILE__
This replaces the internal uses of __FILE__ with the new macro.
2019-07-04 10:36:00 +02:00
Yu Watanabe 8fab27472b sd-netlink: add CTRL_ATTR_MCAST_GROUPS 2019-07-04 17:11:14 +09:00
Yu Watanabe 620fd5d433 sd-netlink: drop unnecessary 'else' 2019-07-04 17:11:05 +09:00
Yu Watanabe 5fc5e2f524 sd-netlink: introduce sd_netlink_message_enter_array() 2019-07-04 17:09:11 +09:00
Yu Watanabe 3bbe178466 sd-netlink: fix inverted log message 2019-07-04 13:46:11 +09:00
Yu Watanabe 9e0196b1e2 sd-device: introduce dump_device_action_table()
Will be used in later commits.
2019-06-29 04:10:14 +09:00
Lennart Poettering 05b2ace147
Merge pull request #12870 from yuwata/tree-wide-further-path-join-cleanups
tree-wide: further path_join() and path_joina() cleanups
2019-06-25 09:27:01 +02:00
Lubomir Rintel c4f885e7e0 sd-device: don't accept /sys as a device path
Because it's not a device path and (slightly) bad things happen if it
gets confused with one:

  $ udevadm info /sys/
  Assertion 'device->devpath[0] == '/'' failed at
      ../src/libsystemd/sd-device/sd-device.c:958,
      function sd_device_get_devpath(). Aborting.
  Aborted (core dumped)
2019-06-25 10:22:18 +09:00
Yu Watanabe 270384b2d4 tree-wide: replace strjoina() with prefix_roota() 2019-06-25 01:31:26 +09:00
Yu Watanabe 623550aff7 sd-path: use _cleanup_strv_free_ attribute 2019-06-24 14:57:50 +09:00
Lennart Poettering cee97d5768
Merge pull request #12836 from yuwata/tree-wide-replace-strjoin
tree-wide: replace strjoin() with path_join()
2019-06-22 20:02:46 +02:00
Yu Watanabe a13de89d36 sd-path: use _cleanup_ attribute 2019-06-21 03:26:23 +09:00
Yu Watanabe 657ee2d82b tree-wide: replace strjoin() with path_join() 2019-06-21 03:26:16 +09:00
Lennart Poettering 3972004297 bus-creds: fix size calculation for storing caps data
This is a bit confusing, hence let's at an example comment.
2019-06-20 14:55:30 +02:00
Lennart Poettering 762267cdc1
Merge pull request #12762 from yuwata/network-introduce-carrier-and-network-state-12752
network: introduce carrier and address state to fix network_is_online()
2019-06-20 13:36:30 +02:00
Yu Watanabe 6d946490ba tree-wide: drop alloca() in loop 2019-06-20 06:29:19 +09:00
Frantisek Sumsal f9dc94408d sd-resolve: suppress false positive MSan warnings
MSan dislikes structured initializers for nested structures.
2019-06-19 15:48:36 +02:00
Yu Watanabe bccd916292 sd-bus: use memdup_suffix0() instead of strndup() 2019-06-19 14:29:00 +09:00
Yu Watanabe 1a65093774 timesync: judging if network is online by networkd's address state
Closes #12752.
2019-06-16 23:17:28 +09:00
Yu Watanabe ac999bf07d sd-network: introduce functions for new link and manager states 2019-06-16 23:17:28 +09:00
Yu Watanabe 35c5a9cae4 network: expose carrier and address states over dbus
Previously, when a bridge or bonding interface is in degraded-carrier
state, then we cannot judge the interface has addresses or not.
By using the new states, dbus clients can distinguish such situation.
2019-06-16 23:17:28 +09:00
Yu Watanabe 1678fbb3c5 network: split operational states into carrier and address states
This should not change any behavior. The new states will be exposed by
later commits.
2019-06-16 23:17:23 +09:00
Zbigniew Jędrzejewski-Szmek e213e309fa test-bus-marshall: add a hopefully helpful comment 2019-06-12 17:27:19 +02:00
Zbigniew Jędrzejewski-Szmek 58cf79c224
Merge pull request #12424 from poettering/logind-brightness
logind: add SetBrightness() bus call as minimal API for setting "leds" and "backlight" kernel class device brightness
2019-06-12 14:28:09 +02:00
Zbigniew Jędrzejewski-Szmek 9e5205d2f7 sd-bus: improve bus error message for uknown properties
"Unknown interface or property." →
"Unknown interface org.freedesktop.network1.Link or property BitRates."
(I don't think the quotes are necessary. Dbus names have pretty strict rules.)
2019-06-04 08:37:04 +02:00
Yu Watanabe a879e1a46e network: monitor link bit rates 2019-06-01 10:24:47 +09:00
Yu Watanabe c095e5b02b netlink: set attribute size of IFLA_STATS and IFLA_STATS64 2019-06-01 10:24:47 +09:00
Yu Watanabe d61e4c5b6e network: add nlmon support
nlmon is a Netlink monitor device.
2019-05-28 22:47:15 +09:00
Lennart Poettering 2a66c2a1ed logind: add SetBrightness() bus call for setting brightness of leds/backlight devices associated with a seat
This augments the drm/input device management by adding a single method
call for setting the brightness of an "leds" or "backlight" kernel class
device.

This method call requires no privileges to call, but a caller can only
change the brightness on sessions that are currently active, and they
must own the session.

This does not do enumeration of such class devices, feature or range
probing, chnage notification; it doesn't help associating graphics or
input devices with their backlight or leds devices. For all that clients
should go directly to udev/sysfs. The SetBrightness() call is just for
executing the actual change operation, that is otherwise privileged.

Example line:

   busctl call org.freedesktop.login1 /org/freedesktop/login1/session/self org.freedesktop.login1.Session SetBrightness ssu "backlight" "intel_backlight" 200

The parameter the SetBrightness() call takes are the kernel subsystem
(i.e. "leds" or "backlight"), the device name, and the brightness
value.

On some hw setting the brightness is slow, and implementation and write
access to the sysfs knobs exposes this slowness. Due to this we'll fork
off a writer process in the background so that logind doesn't have to
block. Moreover, write requestes are coalesced: when a write request is
enqueued while one is already being executed it is queued. When another
write reques is then enqueued the earlier one is replaced by the newer
one, so that only one queued write request per device remains at any
time. Method replies are sent as soon as the first write request that
happens after the request was received is completed.

It is recommended that bus clients turn off the "expect_reply" flag on
the dbus messages they send though, that relieves logind from sending
completion notification and is particularly a good idea if clients
implement reactive UI sliders that send a quick secession of write
requests.

Replaces: #12413
2019-05-24 15:05:27 +02:00
Lennart Poettering 93d70b6cf2
Merge pull request #12631 from keszybz/doc-and-error-message-tweaks
Doc and error message tweaks
2019-05-22 19:00:10 +02:00
Zbigniew Jędrzejewski-Szmek 8da24acad5 sd-bus: improve error message for invalid org.freedesktop.DBus.Properties.Set signature
Fixes #12551.
2019-05-22 16:28:02 +02:00
Susant Sahani 61de0c42f3 sd-netlink: Add netlink property IFLA_MIN_MTU and IFLA_MAX_MTU, 2019-05-21 17:43:56 +05:30
Susant Sahani cb7e98ab05 sd-netlink: add route netlink properties 2019-05-17 13:44:33 +05:30
Yu Watanabe db439337f9
Merge pull request #12576 from ssahani/fou
networkd: FOU tunnel support Local and Peer tunnel addresses
2019-05-16 05:10:35 +02:00
Susant Sahani 397a74ddea sd-netlink: Add Fou properties FOU_ATTR_LOCAL_V4/FOU_ATTR_PEER_V4
FOU_ATTR_LOCAL_V6
FOU_ATTR_PEER_V6
FOU_ATTR_PEER_PORT
FOU_ATTR_IFINDEX
2019-05-16 10:24:48 +09:00
Susant Sahani 69c317a07f networkd: introduce netdev ipvtap
This patch adds netdev ipvtap that is based on the
IP-VLAN network interface, called ipvtap. An ipvtap device can be created
in the same way as an ipvlan device, using 'kind ipvtap', and then accessed
using the tap user space interface.
2019-05-16 09:48:53 +09:00
Susant Sahani f4679bcb57 sd-netlink: support RTAX_FASTOPEN_NO_COOKIE 2019-05-13 16:44:55 +05:30
Yu Watanabe cd43199671
Merge pull request #12520 from ssahani/geneve
networkd: Geneve add DF feature and allow TTL to bechosen by kernel
2019-05-10 19:47:19 +02:00
Zbigniew Jędrzejewski-Szmek afd15bbb4b sd-event: add sd_event_source_disable_unref() helper 2019-05-10 16:55:35 +02:00
Susant Sahani 469fd84866 sd-netlink: Add supprt for geneve properties
IFLA_GENEVE_TTL_INHERIT and
IFLA_GENEVE_DF
2019-05-10 22:45:26 +09:00
Susant Sahani 2a36d4006d sd-netlink: Add VXLAN netlink properties
Add IFLA_VXLAN_DF and IFLA_VXLAN_TTL_INHERIT
2019-05-09 06:40:33 +02:00
Lennart Poettering 0892f3f999
Merge pull request #12420 from mrc0mmand/coccinelle-tweaks
Coccinelle improvements
2019-04-30 11:37:19 +02:00
Ben Boeckel 5238e95759 codespell: fix spelling errors 2019-04-29 16:47:18 +02:00
Frantisek Sumsal 4e361acc06 tree-wide: replace explicit NULL checks with their shorter variants
Done by coccinelle/equals-null.cocci
2019-04-28 14:28:49 +02:00
Franck Bui 83a32ea7b0 sd-bus: bump message queue size again
Simliarly to issue #4068, the current limit turns out to be too small for a
big storage setup that uses many small disks. Let's bump it further.
2019-04-26 09:59:02 +02:00
Zbigniew Jędrzejewski-Szmek bf135d288d sd-bus: when running user find function don't trust the value to be initialized
The find function is externally provided, and we shouldn't trust that the
authors remember to set the output parameter in all cases.
2019-04-23 22:58:39 +02:00
Zbigniew Jędrzejewski-Szmek d603324b4b test-bus-{vtable,introspect}: share data and test introspect_path()
test-bus-introspect is also applied to the tables from test-bus-vtable.c.

test-bus-vtable.c is also used as C++ sources to produce test-bus-vtable-cc,
and our hashmap headers are not C++ compatible. So let's do the introspection
part only in the C version.
2019-04-23 22:58:26 +02:00
Zbigniew Jędrzejewski-Szmek dff9e25a76 sd-bus: split introspection into the content creation and reply creation parts
Just moving code around, in preparation to allow the content creation
part to be used in other places.

On the surface of things, introspect_path() should be in bus-introspect.c, but
introspect_path() uses many static helper functions in bus-objects.c, so moving
it would require all of them to be exposed, which is too much trouble.

test-bus-introspect is updated to actually write the closing bracket.
2019-04-23 12:23:15 +02:00
Zbigniew Jędrzejewski-Szmek 2abda6d1e4 sd-bus: use _cleanup_ for struct introspect 2019-04-23 12:23:15 +02:00
Zbigniew Jędrzejewski-Szmek 2caef9fba4 sd-bus: allow vtable format structure to grow in the future
We would check the size of sd_bus_vtable entries, requring one of the two known
sizes. But we should be able to extend the structure in the future, by adding
new fields, without breaking backwards compatiblity.

Incidentally, this check was what caused -EINVAL failures before, when programs
were compiled with systemd-242 and run with older libsystemd.
2019-04-23 12:23:15 +02:00
Zbigniew Jędrzejewski-Szmek 8dd8a286d1 sd-bus: add symbol to tell linker that new vtable functions are used
In 856ad2a86b sd_bus_add_object_vtable() and
sd_bus_add_fallback_vtable() were changed to take an updated sd_bus_vtable[]
array with additional 'features' and 'names' fields in the union.

The commit tried to check whether the old or the new table format is used, by
looking at the vtable[0].x.start.element_size field, on the assumption that the
added fields caused the structure size to grow. Unfortunately, this assumption
was false, and on arm32 (at least), the structure size is unchanged.

In libsystemd we use symbol versioning and a major.minor.patch semantic
versioning of the library name (major equals the number in the so-name).  When
systemd-242 was released, the minor number was (correctly) bumped, but this is
not enough, because no new symbols were added or symbol versions changed. This
means that programs compiled with the new systemd headers and library could be
successfully linked to older versions of the library. For example rpm only
looks at the so-name and the list of versioned symbols, completely ignoring the
major.minor numbers in the library name. But the older library does not
understand the new vtable format, and would return -EINVAL after failing the
size check (on those architectures where the structure size did change, i.e.
all 64 bit architectures).

To force new libsystemd (with the functions that take the updated
sd_bus_vtable[] format) to be used, let's pull in a dummy symbol from the table
definition. This is a bit wasteful, because a dummy pointer has to be stored,
but the effect is negligible. In particular, the pointer doesn't even change
the size of the structure because if fits in an unused area in the union.

The number stored in the new unsigned integer is not checked anywhere. If the
symbol exists, we already know we have the new version of the library, so an
additional check would not tell us anything.

An alternative would be to make sd_bus_add_{object,fallback}_vtable() versioned
symbols, using .symver linker annotations. We would provide
sd_bus_add_{object,fallback}_vtable@LIBSYSTEMD_221 (for backwards
compatibility) and e.g. sd_bus_add_{object,fallback}_vtable@@LIBSYSTEMD_242
(the default) with the new implementation. This would work too, but is more
work. We would have to version at least those two functions. And it turns out
that the .symver linker instructions have to located in the same compilation
unit as the function being annotated. We first compile libsystemd.a, and then
link it into libsystemd.so and various other targets, including
libsystemd-shared.so, and the nss modules. If the .symver annotations were
placed next to the function definitions (in bus-object.c), they would influence
all targets that link libsystemd.a, and cause problems, because those functions
should not be exported there. To export them only in libsystemd.so, compilation
would have to be rearranged, so that the functions exported in libsystemd.so
would not be present in libsystemd.a, but a separate compilation unit containg
them and the .symver annotations would be linked solely into libsystemd.so.
This is certainly possible, but more work than the approach in this patch.

856ad2a86b has one more issue: it relies on the
undefined fields in sd_bus_vtable[] array to be zeros. But the structure
contains a union, and fields of the union do not have to be zero-initalized by
the compiler. This means that potentially, we could have garbarge values there,
for example when reading the old vtable format definition from the new function
implementation. In practice this should not be an issue at all, because vtable
definitions are static data and are placed in the ro-data section, which is
fully initalized, so we know that those undefined areas will be zero. Things
would be different if somebody defined the vtable array on the heap or on the
stack. Let's just document that they should zero-intialize the unused areas
in this case.

The symbol checking code had to be updated because otherwise gcc warns about a
cast from unsigned to a pointer.
2019-04-23 12:23:12 +02:00
Zbigniew Jędrzejewski-Szmek b48ccda84f sd-netlink: align table 2019-04-13 11:57:42 +02:00
Lennart Poettering b51629ad84
Merge pull request #12222 from yuwata/macsec
network: introduce MACsec
2019-04-12 13:59:30 +02:00
Zbigniew Jędrzejewski-Szmek 673a1e6fb9 Add fmemopen_unlocked() and use unlocked ops in fuzzers and some other tests
This might make things marginially faster. I didn't benchmark though.
2019-04-12 11:44:57 +02:00
Zbigniew Jędrzejewski-Szmek 2fe21124a6 Add open_memstream_unlocked() wrapper 2019-04-12 11:44:57 +02:00
Susant Sahani 81962db798 network: Introduce MACsec
Media Access Control Security (MACsec) is an 802.1AE IEEE
industry-standard security technology that provides secure
communication for all traffic on Ethernet links.
MACsec provides point-to-point security on Ethernet links between
directly connected nodes and is capable of identifying and preventing
most security threats, including denial of service, intrusion,
man-in-the-middle, masquerading, passive wiretapping, and playback attacks.

Closes #5754
2019-04-12 10:12:41 +09:00
Yu Watanabe 01234e1fe7 tree-wide: drop several missing_*.h and import relevant headers from kernel-5.0 2019-04-11 19:00:37 +02:00
Lennart Poettering 3b21fd06ed
Merge pull request #12219 from keszybz/bootctl-check-entries
bootctl: check entries when showing them
2019-04-11 18:57:18 +02:00
Zbigniew Jędrzejewski-Szmek fb270a26b2 sd-bus: add define for the maximum name length
Less magic numbers in the code…
2019-04-11 14:07:22 +02:00
Zbigniew Jędrzejewski-Szmek cfcc0059bf sd-bus: add define for the maximum signature length
Less magic numbers in the code…
2019-04-11 14:02:59 +02:00
Zbigniew Jędrzejewski-Szmek f0ae945ecc bus-message: validate signature in gvariant messages
We would accept a message with 40k signature and spend a lot of time iterating
over the nested arrays. Let's just reject it early, as we do for !gvariant
messages.
2019-04-11 14:01:38 +02:00
Zbigniew Jędrzejewski-Szmek 38df8d3f52 sd-id128: expose ID128_UUID_FORMAT_STR
It is generally useful, and can be made public in the same manner that
SD_ID128_FORMAT_STR is.
2019-04-05 13:47:54 +02:00
Lennart Poettering bab4820ee2 sd-event: use DIV_ROUND_UP where appropriate 2019-04-02 14:54:42 +02:00
Lennart Poettering 39f2bc6e7e sd-device: use xsprintf() where appropriate 2019-04-02 14:54:42 +02:00
Lennart Poettering a7798cd81b tree-wide: use reallocarray() where appropriate 2019-04-02 14:54:42 +02:00
Lennart Poettering c0b471e197 sd-bus: add missing empty line 2019-04-01 20:56:19 +02:00
Lennart Poettering b8a736d7a0 sd-bus: change "int" → "signed int" on bitfield
Apparently by the C standard "int" bitfields can have any signedness
(unlike non-bitfield declarations which are "signed" if the signedness
is not specified).

Let's fix the LGTM warning about this hence and be explicit that we mean
"signed" here.
2019-03-28 19:07:51 +01:00
Zbigniew Jędrzejewski-Szmek 10c353e1c5 Remove variable only used for an assert
When compiled with -DNDEBUG, we get warnings about set-but-unused variables.
In general, it's not something we care about, but since removing those
variables arguably makes the code nicer, let's just to it in this case.
2019-03-28 09:03:06 +01:00
Lennart Poettering 0a6991e0bb tree-wide: reorder various structures to make them smaller and use fewer cache lines
Some "pahole" spelunking.
2019-03-27 18:11:11 +01:00
Lennart Poettering 6990fb6bc6 tree-wide: (void)ify a few unlink() and rmdir()
Let's be helpful to static analyzers which care about whether we
knowingly ignore return values. We do in these cases, since they are
usually part of error paths.
2019-03-27 18:09:56 +01:00
Zbigniew Jędrzejewski-Szmek ca78ad1de9 headers: remove unneeded includes from util.h
This means we need to include many more headers in various files that simply
included util.h before, but it seems cleaner to do it this way.
2019-03-27 11:53:12 +01:00
Lennart Poettering e947830460
Merge pull request #12046 from keszybz/simplify-invocation-id-check
sd-id128: look for invocation id in environment first, keyring second
2019-03-21 19:15:49 +01:00
Zbigniew Jędrzejewski-Szmek c924888ffd sd-id128: look for invocation id in environment first, keyring second
As general principle, we generally check command line args first, the
enviroment second, and external configuration and system state only later.
In case of the invocation ID, checking the keyring before the environment
was implemented as a poor-man's security measure. But this is not really
useful, since we're moving within the same security boundary. So let's just
do the expected thing, and check environment first.

Prompted by https://github.com/systemd/systemd/pull/11991#issuecomment-474647652.
2019-03-21 12:06:15 +01:00
Lennart Poettering 4bf953d91b
Merge pull request #12049 from keszybz/assorted-fixups
Assorted fixups
2019-03-20 18:27:34 +01:00
Zbigniew Jędrzejewski-Szmek afd5c1e373 sd-bus: reduce scope of variable 2019-03-20 13:34:35 +01:00
Zbigniew Jędrzejewski-Szmek 96d2e0978d sd-bus: avoid IN_SET() invocation with two identical values
Fixes #12036.

../../../src/systemd/src/libsystemd/sd-bus/bus-objects.c: In function ‘add_object_vtable_internal’:
../../../src/systemd/src/basic/macro.h:423:19: error: duplicate case value
2019-03-20 13:28:29 +01:00
Lennart Poettering f60a028a4e tree-wide: use ERRNO_IS_DISCONNECT() at more places 2019-03-19 15:41:30 +01:00
Zbigniew Jędrzejewski-Szmek 3dec520197 bus: fix memleak on invalid message
Introduced in 6d586a1371.
Reported by Felix Riemann in https://bugzilla.redhat.com/show_bug.cgi?id=1685286.

Reproducer:
for i in `seq 1 100`; do gdbus call --session -d org.freedesktop.systemd1 -m org.freedesktop.systemd1.Manager.StartUnit -o "/$(for x in `seq 0 28000`; do echo -n $x; done)" & done
2019-03-18 15:25:26 +01:00
Yu Watanabe 8efb042e0c sd-id128: split the logic obtaining invocation ID from sd_id128_get_invocation() 2019-03-15 18:53:23 +09:00
Lennart Poettering beb6196982
Merge pull request #11785 from dvdhrm/implicit-sasl
sd-bus: allow cross-uid-namespace connections
2019-03-14 15:42:03 +01:00
David Rheinsberg 1ed4723d38 sd-bus: skip sending formatted UIDs via SASL
The dbus external authentication takes as optional argument the UID the
sender wants to authenticate as. This uid is purely optional. The
AF_UNIX socket already conveys the same information through the
auxiliary socket data, so we really don't have to provide that
information.

Unfortunately, there is no way to send empty arguments, since they are
interpreted as "missing argument", which has a different meaning. The
SASL negotiation thus changes from:

    AUTH EXTERNAL <uid>
    NEGOTIATE_UNIX_FD                   (optional)
    BEGIN

to:

    AUTH EXTERNAL
    DATA
    NEGOTIATE_UNIX_FD                   (optional)
    BEGIN

And thus the replies we expect as a client change from:

    OK <server-id>
    AGREE_UNIX_FD                       (optional)

to:

    DATA
    OK <server-id>
    AGREE_UNIX_FD                       (optional)

Since the old sd-bus server implementation used the wrong reply for
"AUTH" requests that do not carry the arguments inlined, we decided to
make sd-bus clients accept this as well. Hence, sd-bus now allows
"OK <server-id>\r\n" replies instead of "DATA\r\n" replies.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2019-03-14 13:34:13 +01:00
David Rheinsberg 2010873b4b sd-bus: fix SASL reply to empty AUTH
The correct way to reply to "AUTH <protocol>" without any payload is to
send "DATA" rather than "OK". The "DATA" reply triggers the client to
respond with the requested payload.

In fact, adding the data as hex-encoded argument like
"AUTH <protocol> <hex-data>" is an optimization that skips the "DATA"
roundtrip. The standard way to perform an authentication is to send the
"DATA" line.

This commit fixes sd-bus to properly send the "DATA" line. Surprisingly
no existing implementation depends on this, as they all pass the data
directly as argument to "AUTH". This will not work if we want to pass
an empty argument, though.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2019-03-14 13:33:28 +01:00
David Rheinsberg 3cacdab925 sd-bus: avoid magic number in SASL length calculation
Lets avoid magic numbers and use a constant `strlen()` instead.

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>
2019-03-14 13:31:14 +01:00
Lennart Poettering d8b4d14df4 util: split out nulstr related stuff to nulstr-util.[ch] 2019-03-14 13:25:52 +01:00
Lennart Poettering 47094ce067 util: move dbus specific definition into bus-internal.h
It shouldn't be defined globally, since it's pretty much an
implementation detail of DBus.
2019-03-14 13:25:51 +01:00
Lennart Poettering 2b2fec7db0 util: split out errno related stuff 2019-03-14 13:25:51 +01:00
Yu Watanabe 0aa2fe6f9b netlink: support NLMSG_ERROR message in genl
This resolves the following log message after L2TP tunnel or session is
created:
```
sd-netlink: ignored message with unknown type: 2
```
2019-03-14 10:57:41 +09:00
Susant Sahani 3a56e697c8 networkd: Introduce l2tp tunnel
This works allows networkd to configure l2tp tunnel.
See http://man7.org/linux/man-pages/man8/ip-l2tp.8.html
2019-03-14 10:57:41 +09:00
Lennart Poettering 760877e90c util: split out sorting related calls to new sort-util.[ch] 2019-03-13 12:16:43 +01:00
Lennart Poettering 0a9707187b util: split out memcmp()/memset() related calls into memory-util.[ch]
Just some source rearranging.
2019-03-13 12:16:43 +01:00
Lennart Poettering 0cb8e3d118 util: split out namespace related stuff into a new namespace-util.[ch] pair
Just some minor reorganiztion.
2019-03-13 12:16:38 +01:00
Yu Watanabe 22eab27caa sd-network: add sd_network_link_get_required_operstate_for_online()
It reads $REQUIRED_OPER_STATE_FOR_ONLINE in serialized link data.
2019-03-13 14:29:03 +09:00
Yu Watanabe c9cc038343 network: introduce 'degraded-carrier' operstate to order all states
Previously, 'degraded' state is ambiguous for bonding or bridge master:
1. one or more slave interfaces does not have carrier,
2. no link local address is assigned to the master,
3. combination of the above two.

This makes the above case 1 and 3 are in the new 'degraded-carrier'
state, and makes 'degraded' state as all slaves are active but no
link local address on master.
2019-03-13 14:29:00 +09:00
Yu Watanabe 2cd6b9326c network: move LinkOperationalState and relevant functions to network-util.[ch] 2019-03-13 14:28:38 +09:00
Yu Watanabe 5ebd3fc3c1 sd-device: store parsed ACTION= and SEQNUM= udev properties 2019-03-12 03:49:53 +09:00
Clemens Gruber c423be28a0 network: introduce TripleSampling= option in CAN section
When enabled, three samples are used to determine the value of a
received bit by majority rule.

This patch adds support for the TripleSampling= option in the [CAN]
section of .network files.
2019-03-11 17:15:47 +01:00
Yu Watanabe 08caaee0ac sd-device: move device_action_from_string() and friends to device-private.h 2019-03-07 15:18:49 +09:00
Yu Watanabe 4d64309955 netlink: check new interface name is valid or not before sending request 2019-03-05 10:02:09 +09:00
Zbigniew Jędrzejewski-Szmek 756479043d sd-hwdb: fix off_t vs. size_t confusion in cast
> on 32bit, size_t is 32bit, but .st_size is off_t hence 64bit
2019-03-04 15:42:58 +01:00
Zbigniew Jędrzejewski-Szmek 311b63fef8 Remove now-unused refcnt.h 2019-03-04 14:16:39 +01:00
Zbigniew Jędrzejewski-Szmek f23ab4dc3c sd-netlink: do not use atomic reference counters
Same as with the other users, any non-trivial use of the objects requires
use from a single thread only or external locking. Using atomic operations
just for reference counts is not useful.
2019-03-04 14:16:39 +01:00
Zbigniew Jędrzejewski-Szmek af40711050 sd-hwdb: some minor logging and style updates 2019-03-04 14:16:39 +01:00
Zbigniew Jędrzejewski-Szmek 468905cac8 sd-hwdb: use non-atomic reference counters
The sd-hwdb objects cannot be used concurrently from two threads in any
meaningful way, because query and iteration operations modify the object.
Thus atomic reference counts are pointless.
2019-03-04 14:16:39 +01:00
Zbigniew Jędrzejewski-Szmek 42541a71a2 bus: make reference counting non-atomic
We had atomic counters, but all other operations were non-serialized. This
means that concurrent access to the bus object was only safe if _all_ threads
were doing read-only access. Even sending of messages from threads would not be
possible, because after sending of the message we usually want to remove it
from the send queue in the bus object, which would race. Let's just kill this.
2019-03-04 14:16:24 +01:00
Zbigniew Jędrzejewski-Szmek f68a26221c tests: use the test helpers in more places
This is mostly cosmetic. It makes those test binaries support SYSTEMD_LOG_*
environment variables.
2019-03-04 14:15:38 +01:00
Lennart Poettering 4b70aedc4a test: add test for new sd-bus refcnt logic 2019-03-01 15:37:39 +01:00
Lennart Poettering c1757a70ea sd-bus: use "queue" message references for managing r/w message queues in connection objects
Let's make use of the new concept the previous commit added.

See: #4846
2019-03-01 15:37:39 +01:00
Lennart Poettering 1b3f9dd759 bus-message: introduce two kinds of references to bus messages
Before this commit bus messages had a single reference count: when it
reached zero the message would be freed. This simple approach meant a
cyclic dependency was typically seen: a message that was enqueued in a
bus connection object would reference the bus connection object but also
itself be referenced by the bus connection object. So far out strategy
to avoid cases like this was: make sure to process the bus connection
regularly so that messages don#t stay queued, and at exit flush/close
the connection so that the message queued would be emptied, and thus the
cyclic dependencies resolved. Im many cases this isn't done properly
however.

With this change, let's address the issue more systematically: let's
break the reference cycle. Specifically, there are now two types of
references to a bus message:

1. A regular one, which keeps both the message and the bus object it is
   associated with pinned.

2. A "queue" reference, which is weaker: it pins the message, but not
   the bus object it is associated with.

The idea is then that regular user handling uses regular references, but
when a message is enqueued on its connection, then this takes a "queue"
reference instead. This then means that a queued message doesn't imply
the connection itself remains pinned, only regular references to the
connection or a message associated with it do. Thus, if we end up in the
situation where a user allocates a bus and a message and enqueues the
latter in the former and drops all refs to both, then this will detect
this case and free both.

Note that this scheme isn't perfect, it only covers references between
messages and the busses they are associated with. If OTOH a bus message
is enqueued on a different bus than it is associated with cyclic deps
cannot be recognized with this simple algorithm, and thus if you enqueue
a message associated with a bus A on a bus B, and another message
associated with bus B on a bus A, a cyclic ref will be in effect and not
be discovered. However, given that this is an exotic case (though one
that happens, consider systemd-bus-stdio-bridge), it should be OK not to
cover with this, and people have to explicit flush all queues on exit in
that case.

Note that this commit only establishes the separate reference counters
per message. A follow-up commit will start making use of this from the
bus connection object.
2019-03-01 15:37:39 +01:00
Lennart Poettering b41812d1e3 sd-bus: always go through sd_bus_unref() to free messages
Don't try to be smart, don't bypass the ref counting logic if there's no
real reason to.

This matters if we want to tweak the ref counting logic later.
2019-03-01 15:19:45 +01:00
Lennart Poettering 39feb2ce41 sd-bus: drop two inappropriate empty lines 2019-03-01 15:19:45 +01:00
Lennart Poettering c0bc4ec5cc sd-bus: make sure dispatch_rqueue() initializes return parameter on all types of success
Let's make sure our own code follows coding style and initializes all
return values on all types of success (and leaves it uninitialized in
all types of failure).
2019-03-01 15:19:45 +01:00
Lennart Poettering e593b6a87a sd-bus: reorder bus ref and bus message ref handling
Let's always place handling of these references together, so that all
reference counting during allocation is at a single place.
2019-03-01 15:19:45 +01:00
Lennart Poettering 143d4e045a sd-bus: make rqueue/wqueue sizes of type size_t
Let's do this like we usually do and size arrays with size_t.

We already do this for the "allocated" counter correctly, and externally
we expose the queue sizes as uint64_t anyway, hence there's really no
point in usigned "unsigned" internally.
2019-03-01 15:19:45 +01:00
Lennart Poettering 2fe9a10d76 sd-bus: initialize mutex after we allocated the wqueue
That way the mutex doesn't have to be destroyed when we exit early due
to OOM.
2019-03-01 15:19:45 +01:00
Lennart Poettering 8f37636d91 test: fix indenting off by one 2019-03-01 15:19:45 +01:00
Lennart Poettering 1f82f5bb42 sd-bus: deal with cookie overruns
Apparently this happens IRL. Let's carefully deal with issues like this:
when we overrun, let's not go back to zero but instead leave the highest
cookie bit set. We use that as indication that we are in "overrun
territory", and then are particularly careful with checking cookies,
i.e. that they haven't been used for still outstanding replies yet. This
should retain the quick cookie generation behaviour we used to have, but
permits dealing with overruns.

Replaces: #11804
Fixes: #11809
2019-02-28 13:44:05 +01:00
Lennart Poettering 88a56c7670
Merge pull request #11357 from GiacintoCifelli/dbus_labels
sd-bus: add methods and signals parameter names
2019-02-26 17:22:04 +01:00
Giacinto Cifelli 856ad2a86b sd-bus: add methods and signals parameter names. Fixes: #1564 2019-02-26 12:55:02 +01:00
Yu Watanabe b07d0f2a85 sd-device: split device_read_db_internal() into two part
The new device_read_db_internal_filename() will be used by a fuzzer.
2019-02-26 12:55:43 +09:00
Riccardo Schirone f519a19bcd Allocate temporary strings to hold dbus paths on the heap
Paths are limited to BUS_PATH_SIZE_MAX but the maximum size is anyway too big
to be allocated on the stack, so let's switch to the heap where there is a
clear way to understand if the allocation fails.
2019-02-18 20:07:45 +01:00
Riccardo Schirone 61397a60d9 Refuse dbus message paths longer than BUS_PATH_SIZE_MAX limit.
Even though the dbus specification does not enforce any length limit on the
path of a dbus message, having to analyze too long strings in PID1 may be
time-consuming and it may have security impacts.

In any case, the limit is set so high that real-life applications should not
have a problem with it.
2019-02-18 20:07:45 +01:00
Lennart Poettering 5f06ba8018
Merge pull request #11478 from yuwata/enumerate-match-parent
sd-device-enumerator: support multiple parents
2019-02-18 18:35:47 +01:00
Lennart Poettering 9c5675af76
Merge pull request #11729 from yuwata/fix-11721
sd-device: also store properties read from udev database to sd_device::properties_db
2019-02-18 16:02:26 +01:00
Thomas Haller 202aa15976 netlink: fix routing-policy-rule integer type for FRA_TUN_ID
FRA_TUN_ID is a 64 big endian integer. Fix the policy.

FRA_TUN_ID is unused by networkd, hence I think this bug
has no actual consequences.

Fixes: bce67bbee3
2019-02-18 15:23:35 +01:00
Thomas Haller 8abd60c18b netlink: fix routing-policy-rule netlink type for FRA_GOTO/FRA_UNUSED2
- RTA_OIF has no business in the routing-rule policy. It is numerical
  identical to FRA_GOTO. Fix using the correct enum value. Note that
  RTA_OIF/FRA_GOTO was not used by networkd, and the type was already
  correct at uint32. So, there is no change in behavior.

- RTA_GATEWAY also does not belong to the routing-rules. It is numerical
  identical to FRA_UNUSED2. Obviously, that value is unused as well,
  so there is no actual change in behavior either. In particular
  that is because:
    - kernel would not send messages with FRA_UNUSED2 attribute.
    - networkd would not try to parse/send RTA_GATEWAY/FRA_UNUSED2
      attributes.

Fixes: bce67bbee3
2019-02-18 12:49:31 +01:00
Yu Watanabe 03dd7b7dde sd-device: also store properties read from udev database to sd_device::properties_db
Follow-up for a3ce813697 and
5ce41697bd.

Before a3ce813697, all properties in
src->properties and src->properties_db are mixed and copied to
dst->properties_db by device_copy_properties().
So, it is not necessary to store data from udev database file to
sd_device::properties_db before copying properties.

But now, properties are not mixed. So, the read data need to be
stored to also ::properties_db.

Fixes #11721.
2019-02-17 00:43:38 +09:00
Thomas Haller a15ff62d76 netlink: fix netlink type for routing-rule FRA_L3MDEV
Fixes: bce67bbee3
2019-02-15 20:18:27 +09:00
Lennart Poettering 8e6b3f49fe
Merge pull request #11636 from yuwata/network-in-addr-is-null
network, sd-netlink: unify several functions and fixes coding style
2019-02-15 11:40:34 +01:00
Lennart Poettering 6d586a1371 sd-bus: if we receive an invalid dbus message, ignore and proceeed
dbus-daemon might have a slightly different idea of what a valid msg is
than us (for example regarding valid msg and field sizes). Let's hence
try to proceed if we can and thus drop messages rather than fail the
connection if we fail to validate a message.

Hopefully the differences in what is considered valid are not visible
for real-life usecases, but are specific to exploit attempts only.
2019-02-14 10:27:37 +01:00
Peter Hutterer dc4b6f8d2c sd-hwdb: fix matching for characters with an ord > 127
Devices like the "Microsoft Microsoft® 2.4GHz Transceiver v9.0 Mouse" contain
characters higher than 127. That ® is correctly stored in the hwdb and passed
into the search field during query, but the comparison fails.

Our search string is a const char *, trie_string() returns a const char * but
the current character is cast to uint8_t. This causes anything over 127 to
fail the match. Fix this, we're dealing with characters everywhere here after
all.
2019-02-13 23:19:20 +01:00
Yu Watanabe 67b19a4961 sd-netlink: unify sd_netlink_message_append_in{,6}_addr() and _sockaddr_in{,6}() 2019-02-11 01:28:09 +09:00
Lennart Poettering ad28cfebc1
Merge pull request #11655 from yuwata/fix-11652
sd-device: fix device_copy_properties()
2019-02-07 15:01:31 +01:00
Yu Watanabe 21042737f0 sd-daemon: make sd_booted() return negative errno on unexpected error 2019-02-07 14:44:44 +01:00
Yu Watanabe 9ffb90964f test: add a test case for issue #11652 2019-02-06 08:43:34 +01:00
Yu Watanabe 5ce41697bd sd-device: fix device_copy_properties()
This fixes a bug introduced by a3ce813697.

Fixes #11652.
2019-02-06 08:36:52 +01:00
Lennart Poettering 9066811e5a
Merge pull request #11580 from yuwata/fix-11579
network/wireguard: fix sending wireguard peers
2019-01-28 16:57:08 +01:00
Yu Watanabe abd48ec87f sd-netlink: introduce sd_netlink_message_append_sockaddr_in{,6}() 2019-01-28 12:19:29 +01:00
Lennart Poettering 6e9417f5b4 tree-wide: use newa() instead of alloca() wherever we can
Typesafety is nice. And this way we can take benefit of the new size
assert() the previous commit added.
2019-01-26 16:17:04 +01:00
Yu Watanabe e022bf664c sd-device-enumerator: support multiple parents
When sd_device_enumerator_add_match_parent() is called
multiple times, then previously set parents are discarded.

This adds device_enumerator_add_match_parent_incremental() to make
sd-device-enumerator scan devices under all specified parents.

Note that for backward compatibility, sd_device_enumerator_add_match_parent()
and udev_enumerate_add_match_parent() still discard previous assignments.
2019-01-23 15:15:56 +09:00
Yu Watanabe aa6c83e60e test: add test for sd_device_monitor_filter_remove() 2019-01-23 15:11:53 +09:00
Yu Watanabe b07571735a sd-device-monitor: use SO_DETACH_FILTER to remove BPF program
Fixes #11529.
2019-01-23 15:11:47 +09:00
Yu Watanabe a3ce813697 sd-device: do not save e.g., DEVPATH or INTERFACE properties to udev database
Previously, device_copy_properties() copies all properties to both
sd_device::properties and ::properties_db. Thus, on move uevent,
also tentative properties, e.g. DEVPATH or INTERFACE, are stored to
::properties_db, and saved to udev database.

This makes such tentative properties be copied to only ::properties,
and thus not saved to udev database.

Fixes #9426.
2019-01-22 14:51:02 +09:00
Yu Watanabe 3e4eb8e73d sd-event: introduce event_free_signal_data()
We already have event_free_inotify_data() and event_free_inode_data().
2019-01-18 13:53:43 +01:00
Lennart Poettering bd62b74486 sd-bus: add sd_bus_close_unref() helper
It's similar to sd_bus_flush_close_unref() but doesn't do the flushing.
This is useful since this will still discnnect the connection properly
but not synchronously wait for the peer to take our messages.

Primary usecase is within _cleanup_() expressions where synchronously
waiting on the peer is not OK.
2019-01-17 16:12:38 +01:00
Zbigniew Jędrzejewski-Szmek 29a93cb19d
Merge pull request #11418 from yuwata/fix-11404
network: fix infinite loop in setting up wireguard
2019-01-15 21:04:32 +01:00
Topi Miettinen a1e92eee3e Remove 'inline' attributes from static functions in .c files (#11426)
Let the compiler perform inlining (see #11397).
2019-01-15 08:12:28 +01:00
Yu Watanabe 33c2ea8019 netlink: set maximum size of WGDEVICE_A_IFNAME 2019-01-14 09:47:31 +09:00
Topi Miettinen 7ae3561a5a Delete duplicate lines
Found by inspecting results of running this small program:

int main(int argc, const char **argv) {
	for (int i = 1; i < argc; i++) {
		FILE *f;
		char line[1024], prev[1024], *r;
		int lineno;

		prev[0] = '\0';
		lineno = 1;
		f = fopen(argv[i], "r");
		if (!f)
			exit(1);
		do {
			r = fgets(line, sizeof(line), f);
			if (!r)
				break;
			if (strcmp(line, prev) == 0)
				printf("%s:%d: error: dup %s", argv[i], lineno, line);
			lineno++;
			strcpy(prev, line);
		} while (!feof(f));
		fclose(f);
	}
}
2019-01-12 16:02:26 +01:00
Yu Watanabe ee0b9e721a sd-device-monitor: fix ordering of setting buffer size
By b1c097af8d (#10239), the receive buffer
size for uevents was set by SO_RCVBUF at first, and fallback to
use SO_RCVBUFFORCE. So, as SO_RCVBUF limits to the buffer size
net.core.rmem_max, which is usually much smaller than 128MB udevd requests,
uevents buffer size was not sufficient.

This fixes the ordering of the request: SO_RCVBUFFORCE first, and
fallback to SO_RCVBUF. Then, udevd's uevent buffer size can be set to
128MB.

This also revert 903893237a.

Fixes #11314 and #10754.
2019-01-11 21:52:23 +01:00
Zbigniew Jędrzejewski-Szmek 2cfb197890 sd-device: modernize code a bit
Empty line between setting the output parameter and return is removed. I like
to think about both steps as part of returning from the function, and there's
no need to separate them.

Similarly, if we need to unset a pointer after successfully passing ownership,
use TAKE_PTR and do it immediately after the ownership change, without an empty
line inbetween.
2019-01-08 22:14:06 +01:00