Commit Graph

124 Commits

Author SHA1 Message Date
Lennart Poettering
59577d2416 network: add AF_TO_ADDRESS_FAMILY() helper
Make some code a bit shorter.
2024-10-15 20:44:39 +09:00
Mike Yuan
cd7d732dc5 path-lookup: move NETWORK_DIRS to network-util.h 2024-10-06 19:27:11 +02:00
Mike Yuan
4591c89a15 sd-network: introduce sd_network_link_get_netdev_file{,_dropins} 2024-09-09 23:20:42 +02:00
Yu Watanabe
2db2979505 sd-network: modernize parse_operational_state_range()
- rename 'out' -> 'ret',
- introduce LINK_OPERSTATE_RANGE_INVALID,
- constify LINK_OPERSTATE_RANGE_DEFAULT,
- drop spurious const specifier for allocated string,
- etc,.
2024-01-17 04:05:43 +09:00
Yu Watanabe
15f624f80f sd-network: introduce three helper functions for LinkOperationalState 2024-01-17 04:05:43 +09:00
Mike Yuan
da6c52c57c various: don't use close_nointr if retval is not checked anyway 2023-12-28 20:44:01 +08:00
Ronan Pigott
edb88a7201 network: Introduce UseCaptivePortal DHCPv4 option
Accepts a boolean. When enabled, UseCaptivePortal will request and
retain the captive portal configuration from the DHCP server.
2023-07-02 01:13:43 -07:00
Daan De Meyer
a2640646f1 network: Show network and link file dropins in networkctl status
Fixes #24428
2023-01-12 13:44:52 +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
Yu Watanabe
e05dd7718d sd-network: make sd_network_link_get_dns() or friends return -ENODATA
To make them consistent with other functions.
2022-09-27 10:42:31 +09:00
Yu Watanabe
778e3da95e sd-network: drop fallback values
This drops spurious lines in `networkctl status` for unmanaged interfaces.
Before:
```
$ networkctl status --lines 0 lo
● 1: lo
                     Link File: n/a
                  Network File: n/a
                          Type: loopback
                         State: carrier (unmanaged)
                  Online state: unknown
                    HW Address: 00:00:00:00:00:00
                           MTU: 65536
                         QDisc: noqueue
  IPv6 Address Generation Mode: eui64
          Queue Length (Tx/Rx): 1/1
                       Address: 127.0.0.1
                                ::1
             Activation Policy: up
           Required For Online: yes
```
After:
```
$ networkctl status --lines 0 lo
● 1: lo
                     Link File: n/a
                  Network File: n/a
                         State: carrier (unmanaged)
                  Online state: unknown
                          Type: loopback
              Hardware Address: 00:00:00:00:00:00
                           MTU: 65536
                         QDisc: noqueue
  IPv6 Address Generation Mode: eui64
      Number of Queues (Tx/Rx): 1/1
                       Address: 127.0.0.1
                                ::1
```

That is, the lines for Activation Policy and Required For Online are
dropped.
2022-09-27 10:42:31 +09:00
Yu Watanabe
c9d22489ca sd-network: introduce network_link_get_boolean() helper function 2022-09-27 10:42:31 +09:00
Yu Watanabe
27b13df45a sd-network: accept all space-like separators 2022-09-27 10:42:31 +09:00
Yu Watanabe
ce2e75021c sd-network: propagate -ENOENT
On -ENOENT, it suggests that network-manager is not running, and
interfaces are not unmanaged. Such information may be useful for
callers.
2022-09-27 10:42:31 +09:00
Yu Watanabe
e7c1b3f73a sd-network: rename function arguments for storing return value 2022-09-27 10:42:27 +09:00
Daan De Meyer
206c0897a2 sd-network: Keep inotify watch if watch descriptor didn't change
In sd_network_monitor_flush(), we shouldn't remove the inotify
watch for the current directory if the directory the network
monitor is waiting for wasn't created yet.

inotify_add_watch() returns the same unique watch descriptor if a
path is already being watched. Let's return the watch descriptor
from monitor_add_inotify_watch() so we can check if it's the same
as the watch descriptor of the inotify event. If they are equal,
we're still watching the same path and we don't need to remove the
inotify watch just yet.
2022-05-04 07:00:56 +09:00
Yu Watanabe
00adc340bb inotify-util: declare iterator in FOREACH_INOTIFY_EVENT()
This also makes the macro check if the event is actually in the buffer,
and if it is not, then log about that and finish the loop.
2022-03-24 23:12:34 +00:00
Yu Watanabe
61dc4b9ea9 network-util: introduce network_link_get_operational_state() 2022-01-21 06:22:21 +09:00
Yu Watanabe
8e0bacab6e sd-network: introduce sd_network_link_get_stat() 2021-12-08 18:34:04 +09:00
Yu Watanabe
f4af5f0010 sd-network: drop unnecessary +1 for buffer size 2021-12-08 18:33:35 +09:00
Yu Watanabe
73fc85227d sd-network: drop _public_ attribute
sd-network is not public yet.
2021-12-08 03:06:44 +09:00
Yu Watanabe
8add30a03c tree-wide: use ERRNO_IS_TRANSIENT() 2021-11-30 23:06:43 +09:00
Yu Watanabe
b5cc5591fa netif-util: move several functions from network-util.[ch] to shared/netif-util.[ch]
These functions are not relevant to sd-network, and only used by
networkd, networkctl, and udevd.
2021-11-09 08:24:10 +09:00
Yu Watanabe
f09d20256a arphrd-util: rename arphrd-list.[ch] -> arphrd-util.[ch] 2021-11-09 08:24:10 +09:00
Lennart Poettering
9e5fd71799 basic: split out inotify-related calls from fs-util.h → inotify-util.h 2021-10-05 16:14:37 +02:00
Luca Boccassi
b87dfaa2fa tree-wide: voidify unchecked close_nointr calls
These have ignored the return value forever. Two are public APIs so
we can't really change what they return anyway, and the other one is
a cleanup path and the existing error code is more important.

CID#1461274
CID#1461275
CID#1461276
2021-08-03 15:02:19 +01:00
Lennart Poettering
319a4f4bc4 alloc-util: simplify GREEDY_REALLOC() logic by relying on malloc_usable_size()
We recently started making more use of malloc_usable_size() and rely on
it (see the string_erase() story). Given that we don't really support
sytems where malloc_usable_size() cannot be trusted beyond statistics
anyway, let's go fully in and rework GREEDY_REALLOC() on top of it:
instead of passing around and maintaining the currenly allocated size
everywhere, let's just derive it automatically from
malloc_usable_size().

I am mostly after this for the simplicity this brings. It also brings
minor efficiency improvements I guess, but things become so much nicer
to look at if we can avoid these allocation size variables everywhere.

Note that the malloc_usable_size() man page says relying on it wasn't
"good programming practice", but I think it does this for reasons that
don't apply here: the greedy realloc logic specifically doesn't rely on
the returned extra size, beyond the fact that it is equal or larger than
what was requested.

(This commit was supposed to be a quick patch btw, but apparently we use
the greedy realloc stuff quite a bit across the codebase, so this ends
up touching *a*lot* of code.)
2021-05-19 16:42:37 +02:00
Alvin Šipraga
84a257ab65 network: use the overall online state in network_is_online()
Since networkd advertises a reliable online state, use it in
network_is_online(). If for some reason networkd does not know the
online state (e.g. it does not manage any of the network interfaces),
fall back to the original best-guess logic.
2021-05-19 10:34:06 +09:00
Alvin Šipraga
bcdcc59648 network: add an online state for links and manager
Add a new state of type LinkOnlineState which indicates whether a link
is online or not. The state is also used by networkd's manager to expose
the overall online state of the system.

The possible states are:

  offline  the link (or system) is offline
  partial  at least one required link is online (see below)
  online   all required links are online

For links, a link is defined to be "online" if:
  - it is managed; and
  - its operational state is within the range defined by
    RequiredForOnline=; and
  - it has an IPv4 address if RequiredFamilyForOnline=ipv4 or =both; and
  - it has an IPv6 address if RequiredFamilyForOnline=ipv6 or =both.

A link is defined to be "offline" if:
  - it is managed; and
  - it is not online, i.e. its operational state is not within the range
    defined by RequiredForOnline=, and/or it is missing an IP address in
    a required address family.

Otherwise, the link online state is undefined (represented internally as
_LINK_ONLINE_STATUS_INVALID or -EINVAL). Put another way, networkd will
only offer a meaningful online state for managed links where
RequiredForOnline=yes.

For the manager, the online state is a function of the online state of
all links which are requried for online, i.e. RequiredForOnline=yes. If
all required links are online, then the manager online state is defined
to be "online". If at least one of the required links is online, then
the manager online state is defined to be "partial". If none of
the required links are online, then the manager online state is defined
to be "offline". If there are no managed links, or RequiredForOnline=no
for all managed links, then the manager online state is undefined as
above.

The purpose of the "partial" state is analogous to the --any switch in
systemd-networkd-wait-online.service(8). For example, a required link
which lacks a carrier on boot will not force the overall (manager)
online state to "offline" if there is an alternative link available.
2021-05-19 10:33:55 +09:00
Yu Watanabe
1a3caa49d7 udev,network: make link_get_type_string() return negative errno on failure
And make net_match_config() propagate the error.
2021-05-14 09:18:29 +09:00
LetzteInstanz
bbea881312 sd-network: read IPv4/IPv6 address states from state files 2021-04-14 08:51:08 +09:00
LetzteInstanz
8430841b5e network: save IPv4/IPv6 address states into state file
This also introduces RequiredFamilyForOnline= setting to .network file,
and IPv4AddressState/IPv6AddressState DBus properties.
2021-04-14 08:51:02 +09:00
LetzteInstanz
86ae2d69a3 network: move AddressFamily into network-util for the use by wait-online later 2021-04-14 08:30:18 +09:00
Yu Watanabe
f5fbe71d95 tree-wide: use UINT64_MAX or friends 2021-03-05 07:10:13 +09:00
Zbigniew Jędrzejewski-Szmek
2d93c20e5f tree-wide: use -EINVAL for enum invalid values
As suggested in https://github.com/systemd/systemd/pull/11484#issuecomment-775288617.

This does not touch anything exposed in src/systemd. Changing the defines there
would be a compatibility break.

Note that tests are broken after this commit. They will be fixed in the next one.
2021-02-10 14:46:59 +01:00
Dan Streetman
a853652ae9 save link activation policy to state file and display in networkctl 2021-01-21 12:05:17 -05:00
Yu Watanabe
0d5eb02134 Merge pull request #17478 from yuwata/split-network-internal
libsystemd-network: split network-internal.c
2020-11-27 09:04:19 +09:00
Yu Watanabe
db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Yu Watanabe
dc7f6c9b94 sd-network: move net_get_unique_predictable_data() and net_get_name_persisten() 2020-10-29 14:23:49 +09:00
Yu Watanabe
1929ed0e58 sd-network: move link_get_type_string() 2020-10-29 14:23:49 +09:00
Zbigniew Jędrzejewski-Szmek
d52e1c420c sd-{login,netlink,network}: use TAKE_FD() in more places 2020-09-22 18:00:44 +02:00
Yu Watanabe
5202be27ee sd-network: drop unused functions 2020-06-23 19:13:05 +09:00
Lennart Poettering
2a71d57f4e network: clean-up DHCP lease server data configuration
This is an attempt to clean up the POP3/SMTP/LPR/… DHCP lease server
data logic in networkd. This reduces code duplication and fixes a number
of bugs.

This removes any support for collecting POP3/SMPT/LPR servers acquired
via local DHCP client releases since noone uses that, and given how old
these protocols are I doubt this will change. It keeps support for
configuring them for the dhcp server however.

The differences between the DNS/NTP/SIP/POP3/SMTP/LPR configuration
logics are minimized.

This removes the relevant symbols from sd-network.h (which is an
internal API only at this point after all).

This is unfortunately not well test, given the old code for this had
barely any tests. But the new code should not perform worse at least,
and allow us to release, since it corrects some interfaces visible in
the .network configuration format.

Fixes: #15943
2020-06-18 13:08:18 +09:00
Susant Sahani
a9deab2eec sd-network: Introduce APIs to get DHCP6 DUID 2020-06-10 19:21:21 +02:00
Susant Sahani
01dd138031 sd-network: Introduce API to get DHCPv6 IAID 2020-06-09 19:58:36 +09:00
Susant Sahani
daec96821d sd-network: Introduce API to access DHCP4 client ID 2020-06-08 07:09:24 +02:00
Susant Sahani
d64cc72e80 sd-network: Add support to retrive LPR servers 2020-04-22 14:49:52 +02:00
Susant Sahani
c1c6ff10a1 sd-network: Add support to emit and receive SMTP server information 2020-03-29 22:59:18 +02:00
Susant Sahani
8102b9e710 sd-network: Add support to emit and receive pop3 server information 2020-03-28 03:34:27 +01:00