Commit Graph

234 Commits

Author SHA1 Message Date
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