Commit Graph

366 Commits

Author SHA1 Message Date
Yu Watanabe eeab051b28 network: strdup iif and oif when creating RoutingPolicyRule object 2018-09-27 17:48:34 +09:00
Yu Watanabe 1b3194d8f2 network: fix memleak about routing policy 2018-09-27 17:48:34 +09:00
Zbigniew Jędrzejewski-Szmek 696fc8360d Revert "network: set DynamicUser= to systemd-networkd.service"
This reverts commit d4e9e574ea.
(systemd.conf.m4 part was already reverted in 5b5d82615011b9827466b7cd5756da35627a1608.)

Together those reverts should "fix" #10025 and #10011. ("fix" is in quotes
because this doesn't really fix the underlying issue, which is combining
DynamicUser= with strict container sandbox, but it avoids the problem by not
using that feature in our default installation.)

Dynamic users don't work well if the service requires matching configuration in
other places, for example dbus policy. This is true for those three services.
In effect, distros create the user statically [1, 2]. Dynamic users make more
sense for "add-on" services where not creating the user, or more precisely,
creating the user lazily, can save resources. For "basic" services, if we are
going to create the user on package installation anyway, setting DynamicUser=
just creates unneeded confusion. The only case where it is actually used is
when somebody forgets to do system configuration. But it's better to have the
service fail cleanly in this case too. If we want to turn on some side-effect
of DynamicUser=yes for those services, we should just do that directly through
fine-grained options. By not using DynamicUser= we also avoid the need to
restart dbus.

[1] bd9bf30727
[2] 48ac1cebde/f/systemd.spec (_473)
(Fedora does not create systemd-timesync user.)
2018-09-20 16:52:02 +02:00
Patrik Flykt 65dd5e3105 networkd-manager: Fix route removals on shutdown
In order to shut down networkd properly, the delegated routes added
need to be removed properly, and as error reporting is wanted, the
network link is needed in the debug output.

Solve this by calling manager_dhcp6_prefix_remove_all(), which will
remove each prefix stored in the Manager structure, and while doing
that reference each link so that it isn't freed before the route
removal callback is called. This in turn causes the network link to
be referenced once more, and an explicit hashmap_remove() must be
called to remove the network link from the m->links hashmap.

Also, since the registered callback is not called when the DHCPv6
client is stopped with sd_dhcp6_client_stop(), an explicit call
to dhcp6_lease_pd_prefix_lost() needs to be made to clean up any
unreachable routes set up for the delegated prefixes.
2018-09-19 13:45:18 -06:00
Patrik Flykt e1d737ef9d networkd-manager: Update logging of route additions and removals
Log route additions and removals when the action is to be done, as
the reply rtnl message may contain only a success or failure.
2018-09-19 13:45:18 -06:00
Zbigniew Jędrzejewski-Szmek c07fe6d0df Merge pull request #9406 from yuwata/rfe-9228
Trivial conflict solved in merge and include net/if_arp.h added.
2018-08-23 11:11:13 +02:00
Yu Watanabe 51517f9e09 network: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Yu Watanabe 27dfc98275 network: request product UUID when DUIDType=uuid but DUIDRawData= is not set
Closes #9228.
2018-08-08 10:15:00 +09:00
Yu Watanabe e0d95f039a network: make log level lower when operations are automatically re-tried later
When networkd has not connected and setting hostname/timezone is
requested, the operation is delayed, not canceled. So, logging in
debug level is sufficient for the corresponding log message.

Closes #9699.
2018-07-25 12:21:53 +02:00
Yu Watanabe 05e2162773 network: voidify sd_event_add_signal() and sd_event_set_watchdog() 2018-07-20 11:29:49 +09:00
Yu Watanabe e42699438a network: add missing sd_netlink_unref() 2018-07-20 11:23:24 +09:00
Yu Watanabe 3534a04300 network: move sd_event initialization to manager_new() 2018-07-18 12:37:50 +09:00
Yu Watanabe cad4359568 network: drop unused slots 2018-07-17 12:40:04 +02:00
Zbigniew Jędrzejewski-Szmek d9b02e1697 tree-wide: drop copyright headers from frequent contributors
Fixes #9320.

for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do
  git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms'
done
2018-06-20 11:58:53 +02:00
Chris Lamb 3fe910794b Correct a number of trivial typos. 2018-06-18 22:44:44 +02:00
Lennart Poettering 96b2fb93c5 tree-wide: beautify remaining copyright statements
Let's unify an beautify our remaining copyright statements, with a
unicode ©. This means our copyright statements are now always formatted
the same way. Yay.
2018-06-14 10:20:21 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Yu Watanabe d4e9e574ea network: set DynamicUser= to systemd-networkd.service 2018-05-22 22:37:34 +09:00
Lennart Poettering 8e766630f0 tree-wide: drop redundant _cleanup_ macros (#8810)
This drops a good number of type-specific _cleanup_ macros, and patches
all users to just use the generic ones.

In most recent code we abstained from defining type-specific macros, and
this basically removes all those added already, with the exception of
the really low-level ones.

Having explicit macros for this is not too useful, as the expression
without the extra macro is generally just 2ch wider. We should generally
emphesize generic code, unless there are really good reasons for
specific code, hence let's follow this in this case too.

Note that _cleanup_free_ and similar really low-level, libc'ish, Linux
API'ish macros continue to be defined, only the really high-level OO
ones are dropped. From now on this should really be the rule: for really
low-level stuff, such as memory allocation, fd handling and so one, go
ahead and define explicit per-type macros, but for high-level, specific
program code, just use the generic _cleanup_() macro directly, in order
to keep things simple and as readable as possible for the uninitiated.

Note that before this patch some of the APIs (notable libudev ones) were
already used with the high-level macros at some places and with the
generic _cleanup_ macro at others. With this patch we hence unify on the
latter.
2018-04-25 12:31:45 +02:00
Yu Watanabe 621e450980 network: set description to bus 2018-04-17 23:55:27 +09:00
Yu Watanabe 79a4beb39f network,resolve: remove unused variables (#8738)
Follow-up for d7afd945b5.
2018-04-17 12:40:45 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Yu Watanabe 1cc6c93a95 tree-wide: use TAKE_PTR() and TAKE_FD() macros 2018-04-05 14:26:26 +09:00
Yu Watanabe 3d282fff06 network: fix typo in log message 2018-04-05 10:20:13 +09:00
Yu Watanabe aa18944d39 networkd: fix dhcp6_prefixes_compare_func()
Found by the following warning by gcc.
```
../src/network/networkd-manager.c: In function 'dhcp6_prefixes_compare_func':
../src/network/networkd-manager.c:1383:16: warning: 'memcmp' reading 16 bytes from a region of size 8 [-Wstringop-overflow=]
         return memcmp(&a, &b, sizeof(*a));
                ^
```
2018-02-06 17:06:01 +09:00
Yu Watanabe b7d16a91d6 networkd: fix wrong argument check 2018-01-17 01:29:13 +09:00
Lennart Poettering 38edb7674b
Merge pull request #7582 from pfl/dhcp6_prefix_delegation
DHCPv6 prefix delegation
2018-01-15 12:02:37 +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 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 d7afd945b5 networkd,resolved: make use of watch_bind feature to connect to the bus
The changes both networkd and resolved to make use of the watch_bind
feature of sd-bus to connect to the system bus. This way, both daemons
can be started during early boot, and automatically and instantly
connect to the system bus as it becomes available.

This replaces prior code that used a time-based retry logic to connect
to the bus.
2018-01-05 13:58:32 +01:00
Lennart Poettering 75152a4d6a tree-wide: install matches asynchronously
Let's remove a number of synchronization points from our service
startups: let's drop synchronous match installation, and let's opt for
asynchronous instead.

Also, let's use sd_bus_match_signal() instead of sd_bus_add_match()
where we can.
2018-01-05 13:58:32 +01:00
Lennart Poettering 0c0b930647 tree-wide: make name requesting asynchronous in all our services
This optimizes service startup a bit, and makes it less prone to
deadlocks.
2018-01-05 13:58:32 +01:00
Patrik Flykt 9f386c6d3b manager: Add and remove routes for DHCPv6 Prefix Delegation
Configure routes to the links they are delegated to. Remove routes
once the delegation itself or the link is removed.
2018-01-04 15:22:44 +02:00
Patrik Flykt e133b289aa networkd: Add hashmap to store prefixes and associated link
Add a hashmap to the Manager struct that stores the association
between an IPv6 prefix and the network Link it is assigned to.
This is added in order to keep assigning the same prefixes with
the same links even though they are delegated at different times
or by different DHCPv6 clients.
2018-01-04 15:22:44 +02:00
Yu Watanabe e1694a752f networkd: show warning on error or cast to void when error is ignored (#7716) 2017-12-21 19:07:23 +01:00
Susant Sahani 36e6e28bce Fix #7704 and #7708. (#7712)
Init rule variable iif oif and to, from

While foreign rules are added the network part is not attached.
attach manager to rules and use it in routing_policy_rule_free.
2017-12-21 21:27:45 +09:00
Lennart Poettering 0d53667334 tree-wide: use __fsetlocking() instead of fxyz_unlocked()
Let's replace usage of fputc_unlocked() and friends by __fsetlocking(f,
FSETLOCKING_BYCALLER). This turns off locking for the entire FILE*,
instead of doing individual per-call decision whether to use normal
calls or _unlocked() calls.

This has various benefits:

1. It's easier to read and easier not to forget

2. It's more comprehensive, as fprintf() and friends are covered too
   (as these functions have no _unlocked() counterpart)

3. Philosophically, it's a bit more correct, because it's more a
   property of the file handle really whether we ever pass it on to another
   thread, not of the operations we then apply to it.

This patch reworks all pieces of codes that so far used fxyz_unlocked()
calls to use __fsetlocking() instead. It also reworks all places that
use open_memstream(), i.e. use stdio FILE* for string manipulations.

Note that this in some way a revert of 4b61c87511.
2017-12-14 10:42:25 +01:00
Vito Caputo 508f63b411 *: fix some inconsistent control statement style 2017-12-01 16:49:52 -08:00
Zbigniew Jędrzejewski-Szmek b921fcb2ac networkd: fix memleak of Rules
This was the issue mentioned in 93f9da6e0a.
2017-11-28 21:34:50 +01:00
Zbigniew Jędrzejewski-Szmek 1e40b7490a networkd: remove dead code
Found by coverity.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek bbd1590085 networkd: fix reversed arguments
Found by coverity.

Also drop unused return value while at it.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek 458d8ae302 networkd: move rule loading to a separate function
No functional change.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek cfc4529b01 networkd: unbork rule serialization
We'd write something like

RULE=from=250.250.240.0/24 to=(null)/0 tos=0 fwmark=0/0 table=12
RULE=from=250.250.250.0/24 to=(null)/0 tos=0 fwmark=0/0 table=11
2017-11-27 10:06:55 +00:00
Daniel Lockyer 87e4e28dcf Replace empty ternary with helper method 2017-11-24 09:31:08 +00:00
Susant Sahani 762e2659b9 networkd: support incoming/outgoing device for rule matching (#7223)
Closes #7210
2017-11-21 11:51:50 +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
Zbigniew Jędrzejewski-Szmek ecc3f340ab networkd: fix two format string mismatches
../src/network/networkd-link.c:3577:84: warning: format specifies type 'unsigned char' but the argument has type 'uint32_t' (aka 'unsigned int') [-Wformat]
                                route->dst_prefixlen, route->tos, route->priority, route->table, route->lifetime);
                                                                                   ^~~~~~~~~~~~
../src/network/networkd-manager.c:1146:132: warning: format specifies type 'unsigned char' but the argument has type 'uint32_t' (aka 'unsigned int') [-Wformat]
                        rule->from_prefixlen, space ? " " : "", to_str, rule->to_prefixlen, rule->tos, rule->fwmark, rule->fwmask, rule->table);
                                                                                                                                   ^~~~~~~~~~~

Also add some line breaks to make it easier to see which argument is for which
part of the format string.
2017-11-01 23:10:21 +01:00
Susant Sahani 6acbbdd4da networkd: Don't stop networkd if CONFIG_FIB_RULES=n in kernel (#7030)
If FIB Rules are not supported by the kernel then networkd fails to
start as it retuns error=-EOPNOTSUPP.
In this case just ignore and let start networkd.

```
sendto(5, {{len=28, type=RTM_GETRULE, flags=NLM_F_REQUEST|NLM_F_ACK|NLM_F_DUMP, seq=8, pid=0}, {family=AF_UNSPEC, dst_len=0, src_len=0, tos=0, table=RT_TABLE_UNSPEC, action=FR_ACT_TO_TBL, flags=0}}, 28, 0, {sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, 16) = 28
recvmsg(5, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=128->12, msg_iov=[{iov_base=NULL, iov_len=0}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_NETLINK, cmsg_type=0x3}], msg_controllen=24, msg_flags=MSG_TRUNC}, MSG_PEEK|MSG_TRUNC) = 48
recvmsg(5, {msg_name={sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, msg_namelen=128->12, msg_iov=[{iov_base={{len=48, type=NLMSG_ERROR, flags=0, seq=8, pid=8856}, {error=-EOPNOTSUPP, msg={{len=28, type=RTM_GETRULE, flags=NLM_F_REQUEST|NLM_F_ACK|NLM_F_DUMP, seq=8, pid=0}, {family=AF_UNSPEC, dst_len=0, src_len=0, tos=0, table=RT_TABLE_UNSPEC, action=FR_ACT_TO_TBL, flags=0}}}}, iov_len=7416}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_NETLINK, cmsg_type=0x3}], msg_controllen=24, msg_flags=0}, MSG_TRUNC) = 48
```

```
Oct 08 10:22:24 naomi systemd[1]: Starting Network Service...
Oct 08 10:22:24 naomi systemd-networkd[983]: Could not enumerate rules: Operation not supported
Oct 08 10:22:24 naomi systemd[1]: systemd-networkd.service: Main process exited, code=exited, status=1/FAILURE
```

Fixes #7027
2017-10-18 08:25:57 +02:00
Zbigniew Jędrzejewski-Szmek 349cc4a507 build-sys: use #if Y instead of #ifdef Y everywhere
The advantage is that is the name is mispellt, cpp will warn us.

$ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/"
$ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;'
$ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g'
$ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g'
+ manual changes to meson.build

squash! build-sys: use #if Y instead of #ifdef Y everywhere

v2:
- fix incorrect setting of HAVE_LIBIDN2
2017-10-04 12:09:29 +02:00
Yu Watanabe 74dead3461 networkd: use assert_not_reached() 2017-09-28 15:38:50 +09:00
Yu Watanabe 25a1bffc8f networkd: use IN_SET macro 2017-09-28 15:37:38 +09:00
Yu Watanabe 615ded6233 network: change log level when sd_rtnl_message_get_family() returns invalid family (#6923)
From bce67bbee3, systemd-networkd always shows
```
rtnl: received address with invalid family type 32, ignoring.
```
during boot-up. In the code, there are log_warning() and log_debug() for the
same situation, and the log_debug() is never called. So, let's lower the
log level and remove never called function.
2017-09-27 17:55:13 +02:00
Susant Sahani 983226f35a networkd: route - support unicast,blackhole,unreachable and prohibited (#6861)
Resolves issues #797 and #967.

Conf

```
[Route]
Type=blackhole
Destination=202.54.1.2
```

ip route

```
blackhole 202.54.1.2 proto static
2017-09-19 16:28:26 +02:00
Susant Sahani bce67bbee3 networkd: add support to configure IP Rule (#5725)
Routing Policy rule manipulates rules in the routing policy database control the
route selection algorithm.

This work supports to configure Rule
```
[RoutingPolicyRule]
TypeOfService=0x08
Table=7
From= 192.168.100.18

```

```
ip rule show
0:	from all lookup local
0:	from 192.168.100.18 tos 0x08 lookup 7
```

V2 changes:

1. Added logic to handle duplicate rules.
2. If rules are changed or deleted and networkd restarted
   then those are deleted when networkd restarts next time

V3:

1. Add parse_fwmark_fwmask
2017-09-14 21:51:39 +02:00
Yu Watanabe d7ea7bb8a8 network,resolve: remove comments related to kdbus 2017-08-23 12:42:35 +09:00
Yu Watanabe fb72b1d99f networkd: do not fail manager_connect_bus() if dbus is not active yet
Fixes #6618.
2017-08-23 12:42:22 +09:00
Lennart Poettering 4b61c87511 tree-wide: fput[cs]() → fput[cs]_unlocked() wherever that makes sense (#6396)
As a follow-up for db3f45e2d2 let's do the
same for all other cases where we create a FILE* with local scope and
know that no other threads hence can have access to it.

For most cases this shouldn't change much really, but this should speed
dbus introspection and calender time formatting up a bit.
2017-07-21 10:35:45 +02:00
Daniel Wang b85bc551c3 network: Implement DHCP Option 119 (Domain Search List) (#5932)
This adds a modified version of dhcp6_option_parse_domainname() that is
able to parse compressed domain names, borrowing the idea from
dns_packet_read_name(). It also adds pieces in networkd-link and
networkd-manager to properly save/load the added option field.

Resolves #2710.
2017-05-13 10:19:32 -04:00
Tom Gundersen b76d99d9e6 networkd: move event loop handling out of the manager (#4723)
This will allow us to have several managers sharing an event loop
and running in parallel, as if they were running in separate processes.

The long term-aim is to allow networkd to be split into separate
processes, so restructure the code to make this simpler.

For now we drop the exit-on-idle logic, as this was anyway severely
restricted at the moment. Once split, we will revisit this as it may
then make more sense again.
2016-11-28 20:42:40 +01:00
Martin Pitt 7901cea199 networkd: set DHCP-acquired timezone and hostname after connecting to D-Bus
If setting the received timezone or transient hostname fails because D-Bus is
not (yet) up, store the data in the Manager object and try again after
connecting to D-Bus.
2016-11-23 17:05:10 +01:00
Martin Pitt 59eb33e0fe networkd: move setting hostname and timezone to Manager
Hostname and time zone are global settings, not link specific.  Move these
methods from Link into Manager.
2016-11-23 16:32:06 +01:00
Lennart Poettering 5512a96316 networkd: store DNS servers configured per-network as parsed addresses
DNS servers must be specified as IP addresses, hence let's store them as that
internally, so that they are guaranteed to be fully normalized always, and
invalid data cannot be stored.
2016-11-21 22:58:26 +01:00
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
Zbigniew Jędrzejewski-Szmek 75e2089581 Revert "add networkd dbus lease info" (#4435) 2016-10-21 08:17:16 +02:00
Andrew Jeddeloh 9f1008d513 networkd: add dbus interface for lease raw options (#3528)
Add a dbus object to represent dhcp leases and their raw options (i.e.
options 224-254).
2016-10-11 21:28:22 -04:00
Zbigniew Jędrzejewski-Szmek b9642f4199 networkd: drop route_drop
It is just an alias for route_free which requires that route is not null,
but it was only used in one place where it was checked that route is not
null anyway. Let's just call route_free instead.
2016-05-14 16:46:01 -04:00
Zbigniew Jędrzejewski-Szmek 8341a5c381 networkd: rework duid_{type,duid_type,duid,duid_len} setting
Separate fields are replaced  with a struct.

Second second duid type field is removed. The first field was used to carry
the result of DUIDType= configuration, and the second was either a copy of
this, or contained the type extracted from DuidRawData. The semantics are changed
so that the type specified in DUIDType is always used. DUIDRawData= no longer
overrides the type setting.

The networkd code is now more constrained than the sd-dhcp code:
DUIDRawData cannot have 0 length, length 0 is treated the same as unsetting.
Likewise, it is not possible to set a DUIDType=0. If it ever becomes necessary
to set type=0 or a zero-length duid, the code can be changed to support that.
Nevertheless, I think that's unlikely.

This addresses #3127 § 1 and 3.

v2:
- rename DUID.duid, DUID.duid_len to DUID.raw_data, DUID.raw_data_len
2016-05-03 12:23:01 -04:00
Zbigniew Jędrzejewski-Szmek d7df2fd317 dh-dhcp{,6}-client: change the semantics of DUID setting
Both versions of the code are changed to allow the caller to override
DUID using simple rules: duid type and value may be specified, in
which case the caller is responsible to providing the contents,
or just duid type may be specified as DUID_TYPE_EN, in which case we
we fill in the values. In the future more support for other types may
be added, e.g. DUID_TYPE_LLT.

There still remains and ugly discrepancy between dhcp4 and dhcp6 code:
dhcp6 has sd_dhcp6_client_set_duid and sd_dhcp6_client_set_iaid and
requires client->state to be DHCP6_STATE_STOPPED, while dhcp4 has
sd_dhcp_client_set_iaid_duid and will reconfigure the client if it
is not stopped. This commit doesn't touch that part.

This addresses #3127 § 2.
2016-05-03 12:12:04 -04:00
Vinay Kulkarni 413708d106 DHCP DUID, IAID configuration options 2016-03-30 16:33:55 -07:00
Zbigniew Jędrzejewski-Szmek afec45395f Revert "DHCP DUID and IAID configurability" 2016-03-21 18:24:24 -04:00
Vinay Kulkarni c83321e6d4 DHCP DUID and IAID configurability 2016-03-09 21:58:44 -08:00
Lennart Poettering 9dc907f9c9 networkd: rework idle detection logic of networkd
This patch makes networkd stay around as long as there is more than just a
loopback interface around, or the loopback device isn't fully probed yet, or
the loopback device has a .network file attached.

In essence, this means networkd stays around now continously as it should,
unless it is running in some (container?) environment that really has no
interface except a loopback device.

Fixes #2577.
2016-02-16 15:22:06 +01:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Lennart Poettering d390f8ef2d util: introduce fputs_with_space() and make use of it at various places
The call combines outputing a string with prefixing it with a space, optionally. This is useful to shorten the logic
for outputing lists of strings, that are space separated.
2016-01-26 14:42:04 +01:00
Lennart Poettering b2a81c0b52 networkd: optinally use DHCP lease domain info for routing only
This changes the UseDomains= setting of .network files to take an optional third value "route", in addition to the
boolean values. If set, the passed domain information is used for routing rules only, but not for the search path
logic.
2016-01-26 14:42:04 +01:00
Lennart Poettering 27cb34f574 networkd: rename a few Network object properties to be more like the configuration settings
All booleans called dhcp_xyz are now called ".dhcp_use_xyz", to match their respective configuration file settings. This
should clarify things a bit, in particular as there is a DHCP hostname that was previously called just ".hostname"
because ".dhcp_hostname" was already existing as a bool. Since this confusion is removed now because the bool is called
".dhcp_use_hostname", the string field is now renamed to ".dhcp_hostname".
2016-01-26 14:42:04 +01:00
Lennart Poettering 482d1aeb67 networkd: when filtering out duplicate domain names use DNS comparison
When we collect the domain names of the various links and other sources in one ordered set, make sure to use proper DNS
name comparison to filter out duplicates.
2016-01-26 14:42:03 +01:00
Lennart Poettering 0061695507 networkd: use an OrderedSet instead of Set to collect link domains
For the search domain logic the order is highly relevant, hence make sure when collecting the various search domains to
add them to an ordered set, so that the order between search domains of a specific link is retained.
2016-01-26 14:42:03 +01:00
Lennart Poettering 3df9bec57c networkd: rework Domains= setting
Previously, .network files only knew a vaguely defined "Domains=" concept, for which the documentation declared it was
the "DNS domain" for the network connection, without specifying what that means.

With this the Domains setting is reworked, so that there are now "routing" domains and "search" domains. The former are
to be used by resolved to route DNS request to specific network interfaces, the latter is to be used for searching
single-label hostnames with (in addition to being used for routing). Both settings are configured in the "Domains="
setting. Normal domain names listed in it are now considered search domains (for compatibility with existing setups),
while those prefixed with "~" are considered routing domains only. To route all lookups to a specific interface the
routing domain "." may be used, referring to the root domain. An alternative syntax for this is the "*", as was already
implemented before using the "wildcard" domain concept.

This commit adds proper parsers for this new logic, and exposes this via the sd-network API. This information is not
used by resolved yet, this will be added in a later commit.
2016-01-26 14:42:03 +01:00
Zbigniew Jędrzejewski-Szmek a0db8e46e5 networkd: use (void) to mark ignored values
Null link or netdev are handled fine.

CID #1338084.
2016-01-20 18:55:55 -05:00
Lennart Poettering 4afd3348c7 tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.

With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.

The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).

This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.

Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:

       #define _cleanup_(function) __attribute__((cleanup(function)))

Or similar, to make the gcc feature easier to use.

Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.

See #2008.
2015-11-27 19:19:36 +01:00
Tom Gundersen 4058d339f5 networkd: improve logging 2015-11-11 15:42:38 +01:00
Tom Gundersen f5a8c43f39 networkd: IPv6 router discovery - follow IPv6AcceptRouterAdvertisemnt=
The previous behavior:
When DHCPv6 was enabled, router discover was performed first, and then DHCPv6 was
enabled only if the relevant flags were passed in the Router Advertisement message.
Moreover, router discovery was performed even if AcceptRouterAdvertisements=false,
moreover, even if router advertisements were accepted (by the kernel) the flags
indicating that DHCPv6 should be performed were ignored.

New behavior:
If RouterAdvertisements are accepted, and either no routers are found, or an
advertisement is received indicating DHCPv6 should be performed, the DHCPv6
client is started. Moreover, the DHCP option now truly enables the DHCPv6
client regardless of router discovery (though it will probably not be
very useful to get a lease withotu any routes, this seems the more consistent
approach).

The recommended default setting should be to set DHCP=ipv4 and to leave
IPv6AcceptRouterAdvertisements unset.
2015-11-11 15:42:38 +01:00
Tom Gundersen 1c8e710c2b networkd: route - track routes 2015-10-30 12:32:48 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 0d39fa9c69 util-lib: move more file I/O related calls into fileio.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
reverendhomer 58fda79c0b networkd-manager: fix swapped arguments
fixes Coverity #1328493
2015-10-22 10:36:07 +03:00
Tom Gundersen 84de38c569 networkd: manager/link - only serialize once per event-loop iteration
Every time the state is written out we may trigger third-party apps, so
let's be a bit more careful about writing this out unnecessarily.
2015-10-21 03:24:23 +02:00
Tom Gundersen adda1ed94a networkd: address - distinguish between addresses added by us and by others
We only keep the addresses that we added ourselves in link->addresses, and
introduce a new set link->addresses_foreign to keep addresses of unknown
origin.

Only functional change is that "foreign" addresses no longer prevent a link
from entering "configured" state.
2015-10-21 02:35:31 +02:00
Tom Gundersen 36c32f6120 networkd: address - factor out address_update()
Call back into link_check_ready() whenever an address state change may have
made a link ready.
2015-10-21 02:35:31 +02:00
Tom Gundersen 8012cd3919 networkd: link - only consider configured when all addresses are ready
We were considering a link configured whilst its IPv6 addresses were still
tentative.

Fixes issue #650.
2015-10-21 02:35:31 +02:00
Tom Gundersen 91b5f99731 networkd: make address_{establish,release}() static
No need to expose these functions, but rather call them from address_{add,drop}.
2015-10-11 15:04:16 +02:00
Tom Gundersen 054f0db487 networkd: manager - avoid unnecessary memory allocation
Don't allocate Address objects only to free them again when processing
rtnl events.
2015-10-11 15:04:16 +02:00
Tom Gundersen cf1d700da3 networkd: address - store active addresses in a Set rather than a List
We need to be able to look these things up quickly as we will be updating them
continuously and there can in principle be many of them.
2015-10-11 15:04:16 +02:00
Tom Gundersen 200a0868fc networkd: address - process in manager.c rather than link.c 2015-10-11 15:04:16 +02:00
Tom Gundersen 7d20d3759e networkd: manager - free bus after own objects
Freeing links/addresses may trigger sending signals over the bus, so let's make sure
the bus stays around until our own objects have been freed.
2015-10-11 14:21:41 +02:00
Lennart Poettering 75f86906c5 basic: rework virtualization detection API
Introduce a proper enum, and don't pass around string ids anymore. This
simplifies things quite a bit, and makes virtualization detection more
similar to architecture detection.
2015-09-07 13:42:47 +02:00
Martin Pitt 397d15fd39 networkd: adjust error codes for nonexisting DHCP data
Commit 0339cd770 changed libsystemd-network's error code for missing DHCP lease
data from ENOENT to ENODATA. Adjust networkd accordingly.

This fixes interfaces being stuck in "degraded/configuring" mode forever.

https://github.com/systemd/systemd/issues/1147
2015-09-04 21:22:44 +02:00
Lennart Poettering c2c940bda0 networkd: s/now/know 2015-08-27 20:23:17 +02:00
Lennart Poettering 2f5b4a774a networkd: make sure we remove udev fd from epoll *before* closing it
Otherwise we'll try to remove an invalid fd from epoll all the time.
2015-08-27 17:38:05 +02:00
Lennart Poettering 4f5f911e81 networkd: propagate DNS/NTP server from uplink to dhcp server
When handing out DHCP leases, try to propagate DNS/NTP server
information from "uplink". The "uplink" is automatically determined as
the network interface with the highest priority default route on it.
2015-08-27 16:45:24 +02:00
Lennart Poettering fc2f9534d0 networkd: split up networkd.h into per-object header files
No functional changes, just moving definitions into separate header
files.
2015-08-27 14:01:23 +02:00
Lennart Poettering 2f3cf1f9e1 networkd: let's uppercase the first character in log messages
Let's try to generate log messages that resemble english language
sentences, hence uppercase the first character.
2015-08-26 20:45:29 +02:00
Thomas Hindoe Paaboel Andersen 7d6884b65e tree-wide: fix indentation 2015-08-06 00:44:19 +02:00
Lennart Poettering dacd6cee76 tree-wide: port everything over to fflush_and_check()
Some places invoked fflush() directly with their own manual error
checking, let's unify all that by using fflush_and_check().

This also unifies the general error paths of fflush()+rename() file
writers.
2015-07-29 20:31:07 +02:00
Tom Gundersen 1c4baffc18 sd-netlink: rename from sd-rtnl 2015-06-13 19:52:54 +02:00
Tom Gundersen 31710be527 sd-rtnl: make joining broadcast groups implicit 2015-06-11 17:47:40 +02:00
Lennart Poettering ee0eb1d891 Revert "networkd: create "kernel" setting for IPForwarding" 2015-06-08 23:24:32 +02:00
Nick Owens a70ec7f19f networkd: create "kernel" setting for IPForwarding
In 5a8bcb674f, IPForwarding was introduced
to set forwarding flags on interfaces in .network files. networkd sets
forwarding options regardless of the previous setting, even if it was
set by e.g. sysctl. This commit creates a new option for IPForwarding,
"kernel", that preserves the sysctl settings rather than always setting
them.

See https://bugs.freedesktop.org/show_bug.cgi?id=89509 for the initial
bug report.
2015-06-02 15:31:48 -07:00
Lennart Poettering 190700621f sd-bus: drop bus parameter from message callback prototype
This should simplify the prototype a bit. The bus parameter is redundant
in most cases, and in the few where it matters it can be derived from
the message via sd_bus_message_get_bus().
2015-04-29 18:36:25 +02:00
Tom Gundersen cdfee94318 networkd: improve logging when processing links and addresses 2015-04-03 15:35:07 +02:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Tom Gundersen f806f64c74 networkd: don't do exit-on-idle if there is something wrong with the dbus connection
Just fall back to plain old event loop in this (highly unlikely) case.

In the glorious future when kdbus is upstream we can of course drop all this.
2015-02-11 13:13:49 +01:00
Tom Gundersen 3175fcdec5 networkd: add basic org.freedesktop.network1.Network interface 2015-02-08 20:15:37 +01:00
Tom Gundersen dbffab87f1 networkd: add network_get_by_name 2015-02-08 20:15:37 +01:00
Tom Gundersen 8f203c166e networkd: move the connection to the bus out of manager_new (again)
This would otherwise make the tests fail as we cannot grab the bus name.
2015-02-05 18:02:42 +01:00
Tom Gundersen a97dcc12e4 networkd: exit on idle
We will be woken up on rtnl or dbus activity, so let's just quit if some time has passed and that is the only thing that can happen.

Note that we will always stay around if we expect network activity (e.g. DHCP is enabled), as we are not restarted on that.
2015-02-05 12:04:19 +01:00
Tom Gundersen e331e24649 networkd: add basic dbus API
Only the very basics, more to come.

For now:

$ busctl tree org.freedesktop.network1
└─/org/freedesktop/network1
  └─/org/freedesktop/network1/link
    ├─/org/freedesktop/network1/link/1
    ├─/org/freedesktop/network1/link/2
    ├─/org/freedesktop/network1/link/3
    ├─/org/freedesktop/network1/link/4
    ├─/org/freedesktop/network1/link/5
    ├─/org/freedesktop/network1/link/6
    ├─/org/freedesktop/network1/link/7
    ├─/org/freedesktop/network1/link/8
    └─/org/freedesktop/network1/link/9

$ busctl introspect org.freedesktop.network1 /org/freedesktop/network1
NAME                                TYPE      SIGNATURE RESULT/VALUE FLAGS
org.freedesktop.network1.Manager    interface -         -            -
.OperationalState                   property  s         "carrier" emits-change

$ busctl introspect org.freedesktop.network1 /org/freedesktop/network1/link/1
NAME                                TYPE      SIGNATURE RESULT/VALUE FLAGS
org.freedesktop.network1.Link       interface -         -            -
.AdministrativeState                property  s         "unmanaged" emits-change
.OperationalState                   property  s         "carrier" emits-change
2015-02-05 11:50:34 +01:00
Tom Gundersen 6a24f1484f networkd: don't warn about missing links unnecessarily
If we get a NEWLINK + NEWADDR between enumerating the links and enumerating the addresses, we
would get a warning that the link corresponding to the address does not exist. This is a false
warning as both the NEWLINK and NEWADDR would be processed after enumerating completed, so drop
it.
2015-02-05 11:50:34 +01:00
Tom Gundersen 5fae368bda networkd: refactor socket activation a bit 2015-02-03 22:20:38 +01:00
Tom Gundersen 9c0a72f961 networkd: handle suspend events 2015-02-03 22:20:38 +01:00
Lennart Poettering 44de0efc6e networkd: minor simplification
Let's return the fd we found as return value in systemd_netlink_fd(),
instead of using call-by-reference.
2015-02-02 23:27:33 +01:00
Tom Gundersen 5544ee8516 networkd: support socket activation
Still keep the non-socket activation code around for starting from the commandline, but
will likely drop that too in the future.
2015-02-02 11:57:52 +01:00
Lennart Poettering 769d324c99 networkd: make IP forwarding for IPv4 and IPv6 individually configurable 2015-01-13 20:17:07 +01:00
Lennart Poettering cb9fc36a12 networkd: introduce an AddressFamilyBoolean enum type
This introduces am AddressFamilyBoolean type that works more or less
like a booleaan, but can optionally turn on/off things for ipv4 and ipv6
independently. THis also ports the DHCP field over to it.
2015-01-13 20:17:06 +01:00
Tom Gundersen 17d1f37d0d networkd: failing to track links is a serious problem so log at warning level rather than debug 2014-12-15 17:57:51 +01:00
Tom Gundersen 45af44d47d networkd: manager - enumerate addresses globally, rather than per-link
The kernel always returns all addresses, rather than only for the given link, so let's only enumerate once.
2014-12-08 22:13:40 +01:00
Michal Schmidt f647962d64 treewide: yet more log_*_errno + return simplifications
Using:
find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
 'local $/;
  local $_=<>;
  s/(if\s*\([^\n]+\))\s*{\n(\s*)(log_[a-z_]*_errno\(\s*([->a-zA-Z_]+)\s*,[^;]+);\s*return\s+\g4;\s+}/\1\n\2return \3;/msg;
  print;'
 $f
done

And a couple of manual whitespace fixups.
2014-11-28 18:56:16 +01:00
Michal Schmidt c33b329709 treewide: more log_*_errno() conversions, multiline calls
Basically:

find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
'local $/;
 local $_=<>;
 s/log_(debug|info|notice|warning|error|emergency)\("([^"]*)%s"([^;]*),\s*strerror\(-?([->a-zA-Z_]+)\)\);/log_\1_errno(\4, "\2%m"\3);/gms;print;' \
 $f; done

Plus manual indentation fixups.
2014-11-28 17:17:51 +01:00
Michal Schmidt da927ba997 treewide: no need to negate errno for log_*_errno()
It corrrectly handles both positive and negative errno values.
2014-11-28 13:29:21 +01:00
Michal Schmidt 0a1beeb642 treewide: auto-convert the simple cases to log_*_errno()
As a followup to 086891e5c1 "log: add an "error" parameter to all
low-level logging calls and intrdouce log_error_errno() as log calls
that take error numbers", use sed to convert the simple cases to use
the new macros:

find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/'

Multi-line log_*() invocations are not covered.
And we also should add log_unit_*_errno().
2014-11-28 12:04:41 +01:00
Alin Rauta be660c371b networkd: fix kernel rtnl receive buffer overrun error
We got the following error when running systemd on a device  with many ports:

"rtnl: kernel receive buffer overrun
Event source 'rtnl-receive-message' returned error, disabling: No buffer space
available"

I think the kernel socket receive buffer queue should be increased. The default
value is taken from:
"/proc/sys/net/core/rmem_default", but we can overwrite it using SO_RCVBUF
socket option.

This is already done in networkd for other sockets.
For example, the bus socket (sd-bus/bus-socket.c) has a receive queue of 8MB.
In our case, the default is 208KB.

Increasing the buffer receive queue for manager socket to 512KB should be enough
to get rid of the above error.

[tomegun: bump the limit even higher to 8M]
2014-11-27 18:59:47 +01:00
Lennart Poettering 356779df90 sd-event: rename sd_event_source_set_name() to sd_event_source_get_name()
To mirror the recent name change of the concept for sd_bus objects,
follow the same logic for sd_event_source objects, too.
2014-11-04 18:09:19 +01:00
Michal Schmidt d5099efc47 hashmap: introduce hash_ops to make struct Hashmap smaller
It is redundant to store 'hash' and 'compare' function pointers in
struct Hashmap separately. The functions always comprise a pair.
Store a single pointer to struct hash_ops instead.

systemd keeps hundreds of hashmaps, so this saves a little bit of
memory.
2014-09-15 16:08:50 +02:00
Dave Reisner 124f09e812 networkd: remove vestigial event sources
187fe1db took advantage of floating events, but didn't remove pointers
it made superfluous.
2014-09-13 14:18:20 -04:00
Tom Gundersen 9021bb9f93 sd-event: name event sources used in libraries
This should help in debugging failing event sources.
2014-08-28 21:19:17 +02:00
Lennart Poettering 8612e93653 sd-network: add system-wide sd_network_get_domains() API 2014-08-15 16:02:14 +02:00
Tom Gundersen d3df0e3982 sd-network: rename operstates 'down' -> 'off' and 'up' -> 'no-carrier'
Suggested by Lennart and Kay.
2014-08-13 22:44:41 +02:00
Tom Gundersen 54cba0b16c sd-network: split the operstate 'unknown' into 'down' and 'up' 2014-08-12 20:42:59 +02:00
Tom Gundersen 0b1831c20c networkd: split out networkd-link.h 2014-08-12 20:42:59 +02:00
Lennart Poettering c0c743cb3d networkd: expose a global list of DNS and NTP servers in the state file 2014-08-12 13:02:27 +02:00
Lennart Poettering c2d6bd61ee networkd: update manager_save() to use fflush_and_check() to simplify things a bit 2014-08-12 13:02:27 +02:00
Tom Gundersen ae06ab1014 networkd: store ifindex as int 2014-07-28 11:46:57 +02:00
Lennart Poettering 0dd25fb9f0 change type for address family to "int"
Let's settle on a single type for all address family values, even if
UNIX is very inconsitent on the precise type otherwise. Given that
socket() is the primary entrypoint for the sockets API, and that uses
"int", and "int" is relatively simple and generic, we settle on "int"
for this.
2014-07-18 16:10:51 +02:00
Lennart Poettering ca4e095ab9 sd-rtnl: make string returned by sd_rtnl_message_read_string() const 2014-07-18 12:38:32 +02:00
Tom Gundersen 3be1d7e0c5 networkd: netdev - introduce vtable for netdev kinds
Split each netdev kind into its own .h/.c.
2014-07-14 16:49:41 +02:00
Lennart Poettering 186fe1db20 networkd: simplify signal handling of SIGTERM/SIGINT
sd-event makes handling SIGTERM/SIGINT a lot easier than it used to,
let's make use of this
2014-07-07 23:11:03 +02:00
Tom Gundersen 1a941ac4b6 networkd: link - ignore missing MAC address
Currently DHCP/IPv4LL only works on ethernet devices, but no reason not to otherwise
manage them.
2014-07-01 12:55:05 +02:00
Tom Gundersen 5da8149fd3 networkd: link - improve refcounting
We failed to take a ref when waiting for udev synchronization. Fix that and also
make unreffing in callbacks simpler throughout by using _cleanup_ macros.

Fixes <https://bugs.freedesktop.org/show_bug.cgi?id=80556>.
2014-07-01 10:21:18 +02:00
Lennart Poettering 11bf3cced1 networkd: add address pool support
When an address is configured to be all zeroes, networkd will now
automatically find a locally unused network of the right size from a
list of pre-configured pools. Currently those pools are 10.0.0.0/8,
172.16.0.0/12, 192.168.0.0/16 and fc00::/7, i.e. the network ranges for
private networks. They are compiled in, but should be configurable
eventually.

This allows applying the same configuration to a large number of
interfaces with each time a different IP range block, and management of
these IP ranges is fully automatic.

When allocating an address range from the pool it is made sure the range
is not used otherwise.
2014-06-18 18:28:29 +02:00
Tom Gundersen 85b5673b33 networkd: split runtime config dir from state dir
Configuration will be in

root:root /run/systemd/network

and state will be in

systemd-network:systemd-network /run/systemd/netif

This matches what we do for logind's seat/session state.
2014-06-03 18:58:00 +02:00
Tom Gundersen bddfc8afd3 networkd: drop CAP_SYS_MODULE
Rely on modules being built-in or autoloaded on-demand.

As networkd is a network facing service, we want to limits its capabilities,
as much as possible. Also, we may not have CAP_SYS_MODULE in a container,
and we want networkd to work the same there.

Module autoloading does not always work, but should be fixed by the kernel
patch f98f89a0104454f35a: 'net: tunnels - enable module autoloading', which
is currently in net-next and which people may consider backporting if they
want tunneling support without compiling in the modules.

Early adopters may also use a module-load.d snippet and order
systemd-modules-load.service before networkd to force the module
loading of tunneling modules.

This sholud fix the various build issues people have reported.
2014-06-03 00:40:23 +02:00
Tom Gundersen e375dcde72 networkd/sd-network: extend operational states
Expose states 'degraded' or 'routable' if a link has a site/link-local or a routable address, respectively.
2014-05-19 20:44:21 +02:00
Tom Gundersen 091a364c80 resolved: add daemon to manage resolv.conf
Also remove the equivalent functionality from networkd.
2014-05-19 18:14:56 +02:00
Tom Gundersen 2dcf7ec6ec networkd: manager - read fallback DNS servers from config file
We will still use the compiled-in defaults if no DNS entry exists in the config file.
2014-05-16 19:48:25 +02:00
Tom Gundersen d4920165fe networkd: network - store DNS servers in List rather than Set
This way we preserve the order of preference.
2014-05-16 19:48:25 +02:00
Tom Gundersen e16cb2e4ef networkd: hardcode a set of default dns servers
Similarly to NTP servers, this can be set at compile-time.
2014-05-16 17:19:04 +02:00
Tom Gundersen 0b44d8c3d7 networkd: manager - don't leak kmod context
Also, keep the kmod_new internal to networkd-manager.c
2014-05-12 17:37:58 +02:00
Susant Sahani 7951dea209 networkd: introduce ipip tunnel
This patch enables basic ipip tunnel support.
It works with kernel module ipip

example conf:

file: ipip.netdev

[NetDev]
Name=ipip-tun
Kind=ipip
MTUBytes=1480

[Tunnel]
Local=192.168.223.238
Remote=192.169.224.239
TTL=64

file: ipip.network

[Match]
Name=em1

[Network]
Tunnel=ipip-tun

[tomegun:
         - drop unused variable
         - take ref when enslaving]
2014-05-12 17:37:12 +02:00
Tom Gundersen fbbeb65a93 networkd: get preexiting addresses when a link is added 2014-05-11 14:26:10 +02:00
Tom Gundersen 2e9f08eaf1 networkd: listen for address changes
This is proof-of-concept only, as we only log the changes but don't do anything
with it.
2014-05-10 20:56:37 +02:00
Tom Gundersen 897e184c7d rtnl: change from bitmask to enum for rtnl groups
The bitmask is deprecated in the kernel, so move to the new interface. At the moment
this does not make a difference for us, but it avoids having to change the API in the future.
2014-05-10 20:56:37 +02:00
Tom Gundersen 86e6e5d1b4 networkd: manager - initialize variables 2014-05-10 20:56:37 +02:00
Tom Gundersen 4d473d5dde networkd: manager - refactor link tracking a bit 2014-05-10 20:56:37 +02:00
Tom Gundersen f22364691b networkd: manager - drop links and netdevs when we receive DELLINK 2014-05-09 14:41:27 +02:00
Tom Gundersen 14b746f721 networkd: introduce refcounting for Links and NetDevs 2014-05-09 14:41:27 +02:00
Tom Gundersen bbf7c04821 sd-network: expose global operational state 2014-05-08 17:21:37 +02:00
Tom Gundersen 667fcc6d7d networkd: manager - add a bit of debug output to udev ADD events 2014-04-19 21:41:40 +02:00
Tom Gundersen 505f8da732 networkd: tie links to rtnl rather than udev
This essentially swaps the roles of rtnl and udev in networkd. After this
change libudev is only used for waiting for udev to initialize devices and
to get udev-specific information needed for some [Match] attributes.

This in particular simplifies the code in containers where udev is not really
useful, but also simplifies things and reduces round-trips in the non-container
case.
2014-04-19 18:41:58 +02:00
Tom Gundersen 208612034e networkd: rewind rtnl message between passing it to functions
This makes updating link status on netdev links work again.
2014-03-31 17:17:56 +02:00
Tom Gundersen 2292547af9 networkd: fix use-after-free
Free networks before links (the reverse of creation order).
2014-03-31 10:01:59 +02:00
Tom Gundersen ba5596ec2e networkd: netdev - improve logging when setting ifindex 2014-03-28 19:16:21 +01:00
Tom Gundersen d39edfc72f networkd: netdev - verify that newlink messages has the expected kind
We match 'newlink' messages with expected netdev's based on their names. Now also
make sure that the receieved link has the expected kind.
2014-03-24 16:59:30 +01:00
Tom Gundersen c49b33aca6 networkd: update mac address in clients when it changes
Pass the mac address on to ipv4ll and dhcp clients so they always have
up-to-date information, and may react appropriately to the change.

Also drop setting the mac address from uevent, and only log when the
address actually changes.
2014-03-20 20:18:15 +01:00
Michael Olbrich eed0eee85a networkd: fix typo
It's HAVE_SPLIT_USR not HAVE_SPLIT_USER
2014-03-14 18:51:41 +01:00
Tom Gundersen 06f021a804 networkd: allow more than one static DNS server 2014-03-14 12:44:17 +01:00
Tom Gundersen 0ea51a1129 networkd: fix creation of runtime dirs at startup
This allows us to drop the repeated attempted creations of the runtime dirs during runtime.
2014-03-14 12:44:17 +01:00
Tom Gundersen d22f1006a1 sd-rtnl/networkd: use new rtnl_message_read() API and drop helper
With the new sd_rtnl_message_read_string(), there is no longer a need for
rtnl_message_get_ifname().
2014-03-06 19:44:37 +01:00
Tom Gundersen 0c2f9b8469 networkd: handle SIGINT and SIGTERM 2014-02-22 21:24:36 +01:00
Lennart Poettering 151b9b9662 api: in constructor function calls, always put the returned object pointer first (or second)
Previously the returned object of constructor functions where sometimes
returned as last, sometimes as first and sometimes as second parameter.
Let's clean this up a bit. Here are the new rules:

1. The object the new object is derived from is put first, if there is any

2. The object we are creating will be returned in the next arguments

3. This is followed by any additional arguments

Rationale:

For functions that operate on an object we always put that object first.
Constructors should probably not be too different in this regard. Also,
if the additional parameters might want to use varargs which suggests to
put them last.

Note that this new scheme only applies to constructor functions, not to
all other functions. We do give a lot of freedom for those.

Note that this commit only changes the order of the new functions we
added, for old ones we accept the wrong order and leave it like that.
2014-02-20 00:03:10 +01:00
Tom Gundersen 11a7f22939 networkd: refactor link_add() :(
Don't set set **ret when returning r < 0, as matching on the errno may easily
give false positives in the future leading to null pointer dereference.

Reported-by: David Herrmann <dh.herrmann@gmail.com>
2014-02-18 22:34:26 +01:00
Tom Gundersen 624b5a636f networkd: correctly handle manager_free(NULL) 2014-02-13 01:41:32 +01:00
Tom Gundersen 60ad0c85e5 networkd: work inside containers
Udev does not run in containers, so instead of relying on it to tell us when a
network device is ready to be used by networkd, we simply assume that any
device was fully initialized before being added to the container.
2014-02-12 17:04:35 +01:00
Tom Gundersen 1a43680949 networkd: netdev - rename Netdev to NetDev
Both in the configuration file format and everywhere else in the code.
2014-02-07 17:07:11 +01:00
Tom Gundersen a6cc569e33 sd-dhcp-client: split sd_dhcp_lease from sd_dhcp_client
This allows us users of the library to keep copies of old leases. This is
used by networkd to know what addresses to drop (if any) when the lease
expires.

In the future this may be used by DNAv4 and sd-dhcp-server.
2014-02-07 15:48:35 +01:00
Tom Gundersen 50add2909c networkd: netdev - reduce chance of race when receiving netdev's ifindex
When creating a new link, the kernel will not inform us about the new ifindex
in its ack. We have to listen for newly created devices and deduce the new
ifindex by matching on the ifname.

We used to do this by waiting for a new device from libudev, but that is asking
for trouble, as udev will happily rename the device before handing it to us.
Listen on rtnl instead, the chance of the name being changed before reaching us
is much smaller (if not nil).

Kernel patch in the works to make this unneccessary.
2014-01-30 14:30:39 +01:00
Tom Gundersen 52433f6b65 networkd: add basic bonding support
Refactor bridging support to be generic netdev support and extend it to
cover bonding as well.
2014-01-22 17:56:49 +01:00
Tom Gundersen 039ebe6aeb sd-dhcp-client/networkd: add domainname support 2014-01-18 17:52:10 +01:00
Tom Gundersen bcbca8291f networkd: don't hard depend on system bus
We may not have a dbus daemon in the initrd (until we can rely on kdbus). In
this case, simply ignore any attempts at using the bus. There is only one user
for now, but surely more to come.

In order to work reliably in the real root without kdbus, but at the same time
don't delay boot when kdbus is in use, order ourselves after dbus.service.
2014-01-18 01:56:41 +01:00
Tom Gundersen b2ad8a16ee networkd: resolv.conf - reword comment
Take into account that users may want to use resolvconf(8), or similar. Also,
avoid repeated calls to fputs().
2014-01-18 00:59:07 +01:00
Tom Gundersen 5d8364b3c5 networkd: resolv.conf - extend the comment a bit 2014-01-16 20:32:09 +01:00
Tom Gundersen 7ae4ef6d23 sd-dhcp-client: refactor DNS support
Rather than keeping an array of pointers to addresses, just keep an array of addresses.
2014-01-16 20:32:08 +01:00
Tom Gundersen 1346b1f038 sd-dhcp-client/networkd: add transient hostname support 2014-01-16 20:32:08 +01:00
Tom Gundersen f3621dec52 networkd: fix wording 2014-01-12 15:44:40 +01:00
Tom Gundersen 3bef724f7e networkd: generate resolv.conf
This adds support to generate a basic resolv.conf in /run/systemd/network.
This file will not take any effect unless a symlink is created from
/etc/resolv.conf.

Nameservers received over DHCP takes precedence over statically configured ones.

Note: /etc/resolv.conf is severely limited, so in the future we will likely
rather provide a much more powerfull nss plugin (or something to that effect),
but this should allow current users to function without any loss of
functionality.
2014-01-12 15:37:21 +01:00
Zbigniew Jędrzejewski-Szmek 2ad8416dd0 No need to canonicalize fixed paths 2014-01-08 22:15:27 -05:00
Tom Gundersen 8b264404b6 networkd: link hash uses 64, not 32 bit keys 2014-01-03 18:27:26 +01:00
Tom Gundersen aa3437a573 networkd: print the ifindex of added links
This debug information may be useful when comapring to dropped rtnetlink messages.
2014-01-03 18:20:11 +01:00