Commit Graph

234 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek d84ed2bd13 networkd: pretiffy message about invalid prefix
We know how the field we are parsing is called, let's put this information in
the error message:
"Route Source= prefix is invalid, ignoring assignment: ..."
"Route Destination= prefix is invalid, ignoring assignment: ..."
2017-05-11 14:01:14 -04:00
Susant Sahani 36423ff433 networkd: route replace parse prefix with generic in_addr_prefix_from_string 2017-05-11 10:12:54 +05:30
Susant Sahani c83ecc04d9 networkd: add support to configure route protocol. (#5890)
Closes: #5889
2017-05-09 20:01:25 +02:00
Zbigniew Jędrzejewski-Szmek ab8ee0f259 tree-wide: use SET_FLAG in more places (#5892) 2017-05-07 07:03:28 -04:00
Susant Sahani 4c7bd9cf6b networkd: route add missing search for route object.
Probaly this happened during rebase.
2017-04-25 19:59:39 +05:30
Susant Sahani b5bf6f645e networkd: make IPv6 route preference configurable (#5700)
The work supports route preference configurable.
i.e. able to set low, medium and high.
2017-04-25 09:32:59 +02:00
Susant Sahani 28959f7d3e networkd: route - support 'onlink' routes (#5734)
This work based on Tom's original patch
teg@1312172

By setting GatewayOnlink=yes, the kernel will assume that the gateway is onlink
even if there is no route to it.

Resolves issue #1283.
2017-04-21 11:22:30 +02:00
Susant Sahani fcc48287eb networkd: Do not set config to NULL immediately.
fd45e52 sets
n to NULL which leads to crash.

fixes: #5418
2017-02-22 10:55:03 +05:30
Zbigniew Jędrzejewski-Szmek 48317c39e2 network: change condition in if testing section presence
section_line and filename should be set together or not at all. Change the
if to test filename, since it's the first of the pair and it seems more natural
to test that.
2017-02-17 09:34:25 -05:00
Zbigniew Jędrzejewski-Szmek fd45e522dd networkd: immediately transfer ownership of route->section
The code was not incorrect previously, but I think it's easier to follow the
ownership (and the code is more likely to remain correct when updated later on),
if freeing of NetworkConfigSection* is immediately made the responsibility of
route_free(), so instead of relying on route_free() not freeing ->section
if adding to the network hashmap failed, make this freeing unconditional.
2017-02-17 09:28:17 -05:00
Susant Sahani f4859fc74c networkd: fix drop-in conf directory configs overwriting each other
Now we track the sections for example [Address] via line number.
Which was fine till we din't had dropins dir. If we have multiple
sections which have the ideantical line number in diffrent files
we are overwriting these since line number is the key.

This patch fixes this by taking filename and line number as key.
This fixes [Address] and [Route] section overwriting.

fixes: #5141
2017-02-16 10:31:42 +05:30
Susant Sahani d6fceaf1f7 networkd: handle MTU field in IPv6 RA (#4719)
This patch handles the custom MTU field in IPv6 RA.

fixes RFE #4464
2016-11-23 22:32:19 +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 47d2d30d83 networkd: limit the number of routes to the kernel limit (#4007)
Fixes #3922.
2016-08-21 15:06:28 +02:00
Michael Chapman a0d95bbc38 networkd: use RT_TABLE_MAIN by default
The default route table used by sd-netlink (and iproute2) is
RT_TABLE_MAIN, not RT_TABLE_DEFAULT. Ensure networkd has the same idea.
2016-08-18 17:54:12 +10:00
Michael Chapman 3bdccf69ca networkd: do not touch link_messages when expiring routes
link_messages is used during link configuration to advance the link
state machine through SETTING_ADDRESSES -> SETTING_ROUTES -> CONFIGURED.

If a route expires in the middle of this, it is possible for
link_messages to hit zero inside route_expire_callback, rather than in
route_handler or address_handler where it would trigger the next step in
configuration. Should this happen, the link will not complete
configuration, and it may not have its static routes configured.

Since route_expire_callback does not need to do anything once the
expired route has been removed from the kernel, it is safe to simply not
account for the netlink request.
2016-08-18 17:53:53 +10:00
Michael Chapman 856e309d7b networkd: avoid NULL pointer dereference in route_add
If no result parameter is provided, do not attempt to write the
found/newly-created route to it. This is presently not an issue as all
callers currently provide a non-NULL result parameter, however we should
do this for symmetry with address_add and future code robustness.
2016-08-16 19:07:42 +10:00
Susant Sahani 1c4b11794b networkd: route priority replace parsing config_parse_uint32 with safe_atou32 (#3522) 2016-06-13 15:57:17 +02:00
Lennart Poettering e373507d25 networkd: fix bad memory access for routes that are note attached to a link yet (#3499)
Corrects: 1b566071

Also see: https://github.com/systemd/systemd/pull/3478#issuecomment-225008542
2016-06-10 23:26:24 +02:00
Lennart Poettering 889b550f2d networkd: constify more things 2016-06-03 19:54:35 +02:00
Lennart Poettering 1b56607157 networkd: also enforce limit on total number of address/routes
This covers the address/routers acquire dynamically.
2016-06-03 19:53:43 +02:00
Lennart Poettering 8c34b96307 networkd: enforce a limit on the number of statically assigned addresses/routes/fdb entries
We should put a limit on everything, hence also on these resources.
2016-06-03 19:14:12 +02:00
Susant Sahani fe7ca21acf networkd: add route expiration handler (#3242)
Fix for #3232.
2016-05-17 21:36:43 -04:00
Zbigniew Jędrzejewski-Szmek d9d9439347 networkd: fix copy-pasto in error message 2016-05-14 16:47:59 -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
Susant Sahani 06976f5b2a networkd: route fix comment 2016-05-06 09:49:49 +05:30
Susant Sahani c953b24c65 networkd: add support to set route table
networkd: add support to set route table
1. add support to configure the table id.
   if id is less than 256 we can fit this in the header of route as
   netlink property is a char. But in kernel this proepty is a
   unsigned 32. Hence if greater that 256 add this as RTA_TABLE
attribute.

2. we are not setting the address family now. Now set this property.
2016-05-03 23:18:21 +05:30
Susant Sahani cacc1dbf17 networkd: Fix route properties.
We are not able to add multiple properties.

wlp3s0.network:
[Match]
Name=wlp3s0

[Route]
Gateway=10.68.5.26
Metric=10

 sudo ./systemd-networkd
Failed to parse file '/usr/lib/systemd/network/wlp3s0.network': File
exists
Could not load configuration files: File exists

This patch fixes it.
2016-04-25 12:37:10 +05:30
Lennart Poettering 21b3926840 network: hashmap_put() can fail
Let's properly handle hashmap_put() failing.
2016-04-12 13:43:30 +02: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 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 3b015d40c1 networkd: ndisc - handle router advertisement in userspace
Router Discovery is a core part of IPv6, which by default is handled by the kernel.
However, the kernel implementation is meant as a fall-back, and to fully support
the protocol a userspace implementation is desired.

The protocol essentially listens for Router Advertisement packets from routers
on the local link and use these to configure the client automatically. The four
main pieces of information are: what kind (if any) of DHCPv6 configuration should
be performed; a default gateway; the prefixes that should be considered to be on
the local link; and the prefixes with which we can preform SLAAC in order to pick
a global IPv6 address.

A lot of additional information is also available, which we do not yet fully
support, but which will eventually allow us to avoid the need for DHCPv6 in the
common case.

Short-term, the reason for wanting this is in userspace was the desire to fully
track all the addresses on links we manage, and that is not possible for addresses
managed by the kernel (as the kernel does not expose to us the fact that it
manages these addresses). Moreover, we would like to support stable privacy
addresses, which will soon be mandated and the legacy MAC-based global addresses
deprecated, to do this well we need to handle the generation in userspace. Lastly,
more long-term we wish to support more RA options than what the kernel exposes.
2015-11-11 15:42:38 +01:00
Tom Gundersen f833694d4f networkd: route - add expiration support
This should really live in the kernel, but the netlink API currently
does not support it. Until support has been added, expire the route
from userspace.
2015-10-30 12:32:49 +01:00
Tom Gundersen 1c8e710c2b networkd: route - track routes 2015-10-30 12:32:48 +01:00
Tom Gundersen 86655331bc networkd: route - clean up confusion between 'metric' and 'priority'
Different tools use different terms for the same concept, let's try
to stick with 'priority', as that is what the netlink API uses.
2015-10-30 12:32:48 +01:00
Tom Gundersen 2ce4095690 networkd: route - rename fields in struct 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 6bedfcbb29 util-lib: split string parsing related calls from util.[ch] into parse-util.[ch] 2015-10-27 13:25:55 +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
Tom Gundersen bb7ae737a3 networkd: route - add hash_ops 2015-10-21 03:24:23 +02:00
Tom Gundersen ed9e361a8a networkd: route - simplify route_new() 2015-10-21 03:24:23 +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 f0213e3796 networkd: route/address - simplify and unify creators
Rename new_dynamic() to simply _new() and reuse that from new_static().
2015-10-11 14:21:41 +02:00
Tom Gundersen 2b22ffaf60 Merge pull request #1372 from jemk/prefsrc
networkd: add support to configure preferred source of static routes
2015-10-05 22:42:44 +02:00
Lennart Poettering 12ca818ffd tree-wide: clean up log_syntax() usage
- Rely everywhere that we use abs() on the error code passed in anyway,
  thus don't need to explicitly negate what we pass in

- Never attach synthetic error number information to log messages. Only
  log about errors we *receive* with the error number we got there,
  don't log any synthetic error, that don#t even propagate, but just eat
  up.

- Be more careful with attaching exactly the error we get, instead of
  errno or unrelated errors randomly.

- Fix one occasion where the error number and line number got swapped.

- Make sure we never tape over OOM issues, or inability to resolve
  specifiers
2015-09-30 22:26:16 +02:00
Jens Kuske 0d07e595cc networkd: add support to configure preferred source of static routes 2015-09-24 14:04:51 +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
Tom Gundersen 1c4baffc18 sd-netlink: rename from sd-rtnl 2015-06-13 19:52:54 +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 769b56a308 networkd: support route scopes
For now we only support the hardcoded values RT_SCOPE_{UNIVERSE,LOCAL,HOST},
and not numerical values or values from /etc/iproute2/rt_scopes.

This addresses https://bugs.freedesktop.org/show_bug.cgi?id=88508.
2015-02-09 16:53:54 +01:00
Tom Gundersen 935c0d26f7 networkd: route - ignore unknown address family 2014-12-08 18:38:55 +01:00
Tom Gundersen 9e7e440835 networkd: add support for source routing 2014-12-04 16:02:05 +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 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
Gavin Li 59580681f5 networkd: route - allow routes without a gateway
For IPv6, the kernel returns EINVAL if a route is added with the
RTA_GATEWAY attribute set to in6addr_any (::). A route without a
gateway is useful in some situations, such as layer 3 tunneling
(sit, gre, etc.).

This patch prevents the RTA_GATEWAY attribute from being added
when route.in_addr is ip6addr_any (::).
2014-11-27 00:24:52 -05:00
Emil Renner Berthing 46b0c76e2c networkd: add preferred source to dhcp4 gateway route
This makes DHCPv4 and IPv4LL coexist peacefully.

[tomegun: apply to both the dhcp routes, use in_addr_is_null() rather than a
separate variable to indicate when prefsrc should be applied]
2014-09-08 15:08:27 +02:00
Tom Gundersen 0b1831c20c networkd: split out networkd-link.h 2014-08-12 20:42:59 +02:00
Lennart Poettering 44e7b94926 networkd: monopolize in_addr utility functions in shared/in-addr-util.h
Primarily, this means we get rid of net_parse_inaddr(), and replace it
everywhere with in_addr_from_string() and in_addr_from_string_auto().
These functions do not clobber the callers arguments on failure, which
is more close to our usual coding style.
2014-08-11 22:46:42 +02:00
Tom Gundersen 16aa63a00b networkd: route/address - use trivial hash functions 2014-07-28 12:21:51 +02:00
Dan Williams 28cc555d85 networkd: set route protocol
All routes added by networkd are currently set RTPROT_BOOT, which according
to the kernel means "Route installed during boot" (rtnetlink.h).  But this
is not always the case as networkd changes routing after boot too.  Since
the kernel gives more detailed protocols, use them.

With this patch, user-configured static routes now use RTPROT_STATIC (which
they are) and DHCP routes use RTPROT_DHCP.  There is no define for IPv4LL
yet, so those are installed as RTPROT_STATIC (though perhaps RTPROT_RA is
better?).

[tomegun: fixup
src/network/networkd-link.c:972:33: error: too few arguments to function 'route_new_dynamic']
2014-07-23 09:19:32 +02:00
Thomas Hindoe Paaboel Andersen 337ede5693 networkd: remove unused variable 2014-07-15 20:38:49 +02:00
Susant Sahani 5d8e593dce networkd: make metric of routes configurable
Now route metric can be configuted via conf file:

example conf:

[Match]
Name=em1

[Route]
Gateway=192.168.1.12
Metric=10

Test:
ip route output
default via 192.168.1.12 dev em1 metric 10

[tomegun: squash TODO update and reword man page a bit]
2014-07-14 11:39:20 +02:00
Tom Gundersen 563c69c6b2 networkd: netdev - take ref immediately after calling out
Keeping the refcounting next to the sd_bus_call_async() makes it easier to check.
2014-07-03 11:00:01 +02:00
Tom Gundersen 3d3d425547 networkd: rename Address and Route list fields 2014-05-16 14:52:02 +02:00
Tom Gundersen c6f7c917a1 libsystemd-network: move network-utils from src/shared
This does not belong in shared as it is mostly a detail of our networking subsystem.

Moreover, now we can use libudev here, which will simplify things.
2014-03-21 21:54:37 +01:00
Umut Tezduyar Lindskog 5c1d3fc93d sd-network: IPv4 link-local support [v2]
Implements IPv4LL with respect to RFC 3927
(http://tools.ietf.org/rfc/rfc3927.txt) and integrates it
with networkd. Majority of the IPv4LL state machine is
taken from avahi (http://avahi.org/) project's autoip.

IPv4LL can be enabled by IPv4LL=yes under [Network]
section of .network file.

IPv4LL works independent of DHCP but if DHCP lease is
aquired, then LL address will be dropped.

[tomegun: removed a trailing newline and a compiler warning]
2014-03-03 23:24:34 +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 4fb7242cbb sd-rtnl-message: store reference to the bus in the message
This mimics the sd-bus api, as we may need it in the future.
2014-02-18 11:21:22 +01:00
Lennart Poettering d595c5cc9e rtnl: rename constructors from the form sd_rtnl_xxx_yyy_new() to sd_rtnl_xxx_new_yyy()
So far we followed the rule to always indicate the "flavour" of
constructors after the "_new_" or "_open_" in the function name, so
let's keep things in sync here for rtnl and do the same.
2014-02-13 13:53:25 +01:00
Lennart Poettering cf6a891173 rtnl: drop "sd_" prefix from cleanup macros
The "sd_" prefix is supposed to be used on exported symbols only, and
not in the middle of names. Let's drop it from the cleanup macros hence,
to make things simpler.

The bus cleanup macros don't carry the "sd_" either, so this brings the
APIs a bit nearer.
2014-02-13 03:44:14 +01:00
Tom Gundersen 801bd9e859 net-util: verify the address family
Error out if the address family is already set to something incompatible with the
address being parsed.
2014-01-30 14:30:39 +01:00
Tom Gundersen b3070dc025 networkd: refuse to use .network files with missing Address/Gateway key
These keys are mandatory in [Address]/[Route] sections. Otherwise, we
hit an assert:

ens3: setting addresses
Assertion 'address->family == 2 || address->family == 10' failed at /build/amd64-generic/tmp/portage/sys-apps/systemd-9999-r1/work/systemd-9999/src/network/networkd-address.c:137, function address_configure(). Aborting.

Reported-by: Alex Polvi <alex.polvi@coreos.com>

At the same time make sure Route's Destination and Gateway uses the same address family.
2014-01-05 00:32:31 +01:00
Tom Gundersen f048a16b46 networkd: distinguish between static and dynamic addresses/routes
Static addresses/routes are associated with a network. Dynamic
addresses/routes are associtade with links (as the corresponding network
may be shared by several links).
2014-01-01 16:23:00 +01:00
Tom Gundersen ae4c67a7c6 networkd: add support for Route sections 2013-12-17 09:24:57 +01:00
Tom Gundersen 0a0dc69b65 rtnl: replace message_append by typesafe versions 2013-12-16 17:28:18 +01:00
Tom Gundersen 1f01fb4f29 rtnl: simplify route_new()
Drop most of the arguments and instead introduce set_dst_prefixlen().
2013-12-16 17:28:18 +01:00
Tom Gundersen 92fe133abf networkd: fix several Address entries in [Network] section 2013-11-28 17:17:04 +01:00
Tom Gundersen c166a07055 networkd: minor fixes
In particular, store the ifname, though we should only use it carefully, as
it is not guaranteed to be stable. Using it for logging is fine though.
2013-11-26 01:32:25 +01:00
Tom Gundersen 6ae115c1fe networkd: add support for [Address] sections
This will allow specifying more options per address than the
simple Address= entry in the [Network] section.

Preliminary support for the same functionality for [Route] sections
are added, but not yet hooked up, as more testing is needed.
2013-11-25 19:35:44 +01:00
Tom Gundersen 71a6151083 conf-parser: distinguish between multiple sections with the same name
Pass on the line on which a section was decleared to the parsers, so they
can distinguish between multiple sections (if they chose to). Currently
no parsers take advantage of this, but a follow-up patch will do that
to distinguish

[Address]
Address=192.168.0.1/24
Label=one

[Address]
Address=192.168.0.2/24
Label=two

from

[Address]
Address=192.168.0.1/24
Label=one
Address=192.168.0.2/24
Label=two
2013-11-25 19:35:44 +01:00
Tom Gundersen f882c247ad networkd: make all calls async 2013-11-17 23:12:27 +01:00
Tom Gundersen fe4824e065 rtnl: rename rtnl_bus_send_with_reply_and_block() to rtnl_bus_call()
Follow the equivalent rename in sd-bus to stay as similar as possible.
2013-11-13 19:48:44 +01:00
Tom Gundersen f579559b3a networkd: add a basic network daemon
This daemon listens for and configures network devices tagged with
'systemd-networkd'. By default, no devices are tagged so this daemon
can safely run in parallel with existing network daemons/scripts.

Networks are configured in /etc/systemd/network/*.network. The first .network
file that matches a given link is applied. The matching logic is similar to
the one for .link files, but additionally supports matching on interface name.

The mid-term aim is to provide an alternative to ad-hoc scripts currently used
in initrd's and for wired setups that don't change much (e.g., as seen on
servers/and some embedded systems).

Currently, static addresses and a gateway can be configured.

Example .network file:

[Match]
Name=wlp2s0

[Network]
Description=My Network
Gateway=192.168.1.1
Address=192.168.1.23/24
Address=fe80::9aee:94ff:fe3f:c618/64
2013-11-09 23:41:17 +01:00