Commit Graph

247 Commits

Author SHA1 Message Date
Yu Watanabe e1fc2c4371 network: move manager_rtnl_process_address() 2020-10-07 02:44:43 +09:00
Yu Watanabe d7fbb9f50c network: introduce link_drop_addresses() 2020-10-07 02:44:43 +09:00
Yu Watanabe f8f2f880d4 network: introduce link_drop_foreign_addresses() 2020-10-07 02:44:43 +09:00
Yu Watanabe 682c65b04c network: introduce link_set_addresses() 2020-10-07 02:44:43 +09:00
Zbigniew Jędrzejewski-Szmek 90e74a66e6 tree-wide: define iterator inside of the macro 2020-09-08 12:14:05 +02:00
Yu Watanabe 50550722e3 network: fix NDisc handling for the case when multiple routers exist
69203fba70 does not consider the case that
multiple routers exist, and causes #16719.

Fixes #16719.
2020-09-08 02:30:04 +09:00
Yu Watanabe 99a2878457 network: expose address_{hash,compare}_func() 2020-09-08 02:30:04 +09:00
Yu Watanabe fb282d4e25 network: only process non-error message 2020-08-08 12:31:12 +09:00
Yu Watanabe ea121d8f25 network: update address infomation even if link is in failed or linger state
As the link may be reconfigured later. If we do not update the address
information, then its setup state or operstate may not be updated
correctly.
2020-07-29 02:05:05 +09:00
Yu Watanabe e55265184b network: do not assume static addresses are configured
link_request_set_routes() is also called when a dynamic address is
configured. At that time, static addresses may not be configured yet.

Fixes #16546.
2020-07-29 02:05:05 +09:00
Yu Watanabe 1633c45731 network: dhcp6: drop addresses and delegated prefixes on client stop
Previously, we did not drop addresses and delegated prefixes when
DHCP6 client is stopped.

Fixes #15455.
Fixes #13564.
2020-07-29 02:05:05 +09:00
Yu Watanabe 69203fba70 network: ndisc: remove old addresses and routes after at least one SLAAC address becomes ready
Otherwise, the old addresses will exist in deperecated state.
2020-07-29 02:05:05 +09:00
Yu Watanabe 6e537f62d7 network: dhcp4: release old lease after the new address become ready
Previously, on DHCPv4 address renewal, the old address may be removed
while the new address is not ready yet.

This also simplifies the logic of removing address and routes.
2020-07-29 02:05:05 +09:00
Yu Watanabe 80b0e86084 network: make address/route_configure optionally return created Address/Route object 2020-07-29 02:05:05 +09:00
Yu Watanabe 8eec0b9da5 network: set key destructor in several hash_ops 2020-07-29 02:05:05 +09:00
Yu Watanabe 97f000744f network: introduce callback called when an address becomes ready 2020-07-29 02:05:00 +09:00
Yu Watanabe 3606ca659e network: add debug log for configuring address 2020-07-29 01:50:54 +09:00
Yu Watanabe 5eec0a0810 network: introduce address_exists() helper function 2020-07-18 05:51:41 +09:00
Yu Watanabe d96edb2c6e network: downgrade log level in conf parsers 2020-07-17 00:40:09 +09:00
Yu Watanabe 93b0b88c3a network: free address when it is removed 2020-07-15 17:15:25 +09:00
Zbigniew Jędrzejewski-Szmek de7fef4b6e tree-wide: use set_ensure_put()
Patch contains a coccinelle script, but it only works in some cases. Many
parts were converted by hand.

Note: I did not fix errors in return value handing. This will be done separate
to keep the patch comprehensible. No functional change is intended in this
patch.
2020-06-22 16:32:37 +02:00
Zbigniew Jędrzejewski-Szmek 10b20e5a93 network: allow empty assignment to PreferredLifetime=
Users might want to use that to unset a previous setting. The docs seem OK as
they are: we don't need to explictly mention the empty value, since it is
almost always allowed.
2020-05-25 14:52:04 +02:00
Zbigniew Jędrzejewski-Szmek d273579667 network: use consistent type when parsing lifetimes
Those fields are both uint32_t, so we should use the same type when parsing.
Having a different type didn't change the result, but let's be consistent.
2020-05-25 14:52:00 +02:00
Susant Sahani 5ead535224 network: Introduce method to generate EUI-64 addresses 2020-03-01 00:16:51 +09:00
Yu Watanabe 07336a0672 network: assume Scope=host when Address= is loopback address
Fixes #14903.
2020-02-28 09:53:36 +01:00
Kevin P. Fleming 8a98f11ed0 network: Make address_hash_ops available outside of networkd-address.c
In order to allow other parts of systemd-networkd to use sets/hashmaps
of Address objects, the address_hash_ops structure needs to be made
available to them.
2020-02-10 15:37:37 +09:00
Yu Watanabe 98b0299479 network: append INTERFACE= attributes for logs corresponds to a netif 2020-01-07 22:20:43 +09:00
Yu Watanabe de697db05b network: introduce AddPrefixRoute= and deprecate PrefixRoute=
PrefixRoute= was added by e63be0847c,
but unfortunately, the meaning of PrefixRoute= is inverted; when true
IFA_F_NOPREFIXROUTE flag is added. This introduces AddPrefixRoute=
setting.
2019-12-18 16:32:31 +01:00
AJ Bagwell e92b60b20f ipv4ll: do not reset conflict counter on restart
Don't reset the conflict counter when trying a new pseudo random
address, so that after trying 10 addresses the londer timeout is used in
accordance with the RFC

Fixes #14299.
2019-12-11 13:26:31 +09:00
Susant Sahani 051e77cac1 network: introduce DAD for static address
Closes #2527.
2019-12-06 23:29:07 +09:00
Yu Watanabe 5ecb131d94 network: include NLMSGERR_ATTR_MSG attribute in error message 2019-11-30 16:14:02 +09:00
Zbigniew Jędrzejewski-Szmek 24be91817f networkd: split out helper function for address extraction 2019-09-17 19:09:57 +02:00
Zbigniew Jędrzejewski-Szmek 57ad760746 network: drop all checks of ipv6_disabled sysctl
*We* control the sysctl setting. If the user configured IPv6, then we apply the
settings, and just make sure that at some point during the configuration the
sysctl is disabled (i.e. ipv6 enabled) if we have IPv6 configured.

Replaces #13283.
2019-08-27 15:31:48 +02:00
Yu Watanabe ce158189a8 network: do not check deprecated flag in address_is_ready()
Without this change, the address with PreferredLifetime=0 cannot be ready,
and thus, no consequent setting up process does not start.
The bug was introduced by 6aa5773.

Follow-up for b7ed5384ab.

Fixes #13341.
2019-08-19 00:04:42 +09:00
Yu Watanabe 75a302b561 network: fix potential memleaks related to set_put() 2019-08-11 08:57:01 +09:00
Yu Watanabe fe2e4b6961 tree-wide: use htobe{32,16}() instead of hton{l,s}() 2019-06-20 06:34:05 +09:00
Yu Watanabe bafa964144 network: read link specific sysctl value
This introduce link_sysctl_ipv6_enabled() and replaces
manager_sysctl_ipv6_enabled() with it.
2019-06-15 14:56:42 +02:00
Yu Watanabe 54a1a535bd network: ignore requested ipv6 addresses when ipv6 is disabled by sysctl 2019-06-12 11:02:33 +09:00
Yu Watanabe 3681d63935 network: fix UBSAN issue
Closes #12724.
2019-06-04 09:12:44 +02:00
Yu Watanabe 67a4683364 network: use IN_ADDR_NULL and ETHER_ADDR_NULL
The change in manager_rtnl_process_address() may not be necessary,
but for safety, let's initialize the value.
2019-05-07 16:55:19 +02:00
Lennart Poettering 0a9707187b util: split out memcmp()/memset() related calls into memory-util.[ch]
Just some source rearranging.
2019-03-13 12:16:43 +01:00
Yu Watanabe fcbf4cb727 network: drop sections contain invalid settings in network_verify()
If e.g., an [Address] section has an invalid setting, then
previously assigned settings in the section is freed, and
only later settings are stored. That may cause partially broken
section stored in Network object.

This makes if an invalid setting is found, then set 'invalid' flag
instead of freeing it. And invalid sections are dropped later by
network_verify().
2019-03-13 11:59:18 +09:00
Yu Watanabe 9560e5b323 network: make all xxx_new_static() static
These functions are called from only config parsers, and the parsers are
in the same files. So, let's make them static.
2019-03-13 11:59:18 +09:00
Yu Watanabe 7750b79695 network: update logs 2019-03-11 08:10:50 +01:00
Yu Watanabe 7e43ebfbf9 network: propagate error from in_addr_is_null() 2019-03-01 15:55:55 +09:00
Yu Watanabe c9207ff3a4 network: check prefixlen when null address is specified to Address= 2019-03-01 15:52:12 +09:00
Yu Watanabe 2850cd40ee network: wrap long lines 2019-02-28 10:57:20 +09:00
Yu Watanabe 33680b0a26 network: simplify config_parse_lifetime() 2019-02-28 10:56:33 +09:00
Yu Watanabe 4aa4c4b0f4 network: avoid address section freed
Otherwise, if HomeAddress= or friends are specified at the first line of
a section, then its assignment will be ignored.
2019-02-28 10:54:20 +09:00
Yu Watanabe 959f65d32e network: make bond master follow operstates of slaves
If one of bond slaves is in off, no-carrier, or dormant, then
bond master is set to degraded.
2019-02-18 18:04:11 +09:00
Yu Watanabe 434094864c network: use netlink_message_append_{in_addr,sockaddr}_union() 2019-02-11 01:28:09 +09:00
Yu Watanabe d40b01e44b network: in_addr_is_null() may return negative errno
So, do not silently cast the returned value to boolean.
Exception is the case that family is trivially AF_INET or AF_INET6.
2019-02-11 01:28:09 +09:00
Fabrice Fontaine 081aea2502 networkd-address.c: fix build without IFA_F_NOPREFIXROUTE
systemd fails to build on kernel without IFA_F_NOPREFIXROUTE
since 9714c02

So put include missing_network.h

Fixes:
 - http://autobuild.buildroot.org/results/970b09e1d49b53dff12a07ca4ad424ef9dd29a69

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2019-02-03 18:34:36 +01:00
Yu Watanabe 0f707207b9 network: warn if Address= is specified without prefixlen
This is the first step for #11307.
2019-01-29 07:36:35 +01:00
Yu Watanabe 9e0fdc211b util: add a new mode for in_addr_prefix_from_string_auto_internal() which refuses address without prefixlen
This also drops in_addr_default_prefix_from_string(), as it is only
used by test-in-addr.
2019-01-29 07:35:17 +01:00
Susant Sahani dfef713f3e networkd: wait for kernel to reply ipv6 peer address
When we configure address with peer, peer address is repliedby kernel.
Hence add the peer when it is available.

Closes #9130.
2019-01-15 07:36:14 +09:00
Yu Watanabe c8f7123e00 network: always check link is ready when address is updated 2018-12-23 08:04:36 +09:00
Yu Watanabe 66e0bb336e network: decrease and fix indentation 2018-12-23 07:38:55 +09:00
Lennart Poettering 76b31bbb24
Merge pull request #10920 from yuwata/hashmap-destructor
hashmap: make hashmap_free() call destructors of key or value
2018-12-03 17:59:44 +01:00
Yu Watanabe 7a08d314f2 tree-wide: make hash_ops typesafe 2018-12-02 07:53:27 +01:00
Yu Watanabe 302a796f5a network: use typesafe netlink_call_async() macro where applicable 2018-12-02 06:29:32 +01:00
Yu Watanabe bd1175bc46 network: add assertions
As they do not have default callback functions.
2018-12-02 06:23:45 +01:00
Yu Watanabe 63ae056909 network: use address_remove_handler() as the default callback of address_remove() 2018-12-02 06:23:45 +01:00
Yu Watanabe 3e5700428e network: allocate hashmap objects when they are required 2018-11-12 16:32:11 +09:00
Yu Watanabe 0f7f27694e network: fixes related to NetworkConfigSection
- Do not allocate NetworkConfigSection when filename == NULL
- set .network element before calling hashmap_put()
- Always free NetworkConfigSection in each object.
2018-11-12 16:32:11 +09:00
Yu Watanabe 17f9c355d5 network: use structured initializers 2018-11-12 16:32:10 +09:00
Tobias Jungel 30226d2718 networkd: don't remove ip address
In case networkd is restarted this prevents a removal of an already existing IP
address that would be configured using networkd. With the proposed changes the
IP address will be kept on the interface without removing. This happens only on
physical hosts or VMs since networkd handles interface configuration slightly
different in containers.
2018-11-06 13:26:37 +01:00
Lennart Poettering a54e373163
Merge pull request #10618 from yuwata/fix-10615
network: fix several issues in config parser
2018-11-05 17:37:25 +03:00
Yu Watanabe b7cb445235 network: use in_addr_default_prefix_from_string_auto() in config_parse_address() 2018-11-05 16:46:26 +09:00
Yu Watanabe de4224aa22 network: fix memleak abot Address.label
Also fix possible memleak about Address.section.
Fixes #10628.
2018-11-04 00:31:46 +09:00
Yu Watanabe 8190a388a6 sd-netlink: make sd_netlink_slot take its description 2018-10-16 18:42:23 +09:00
Yu Watanabe ee38400bba sd-netlink: introduce sd_netlink_slot 2018-10-15 18:10:04 +09:00
Yu Watanabe 1046bf9b1a network: add destroy callbacks for asynchronous netlink calls 2018-10-10 14:43:05 +09:00
Yu Watanabe 545bab1f0a sd-netlink: add destroy_callback argument to sd_netlink_call_async() 2018-10-10 14:43:05 +09:00
Yu Watanabe 51517f9e09 network: replace udev_device by sd_device 2018-08-23 04:57:39 +09:00
Filipe Brandenburger a0edd02e43 tree-wide: Convert compare_func's to use CMP() macro wherever possible.
Looked for definitions of functions using the *_compare_func() suffix.

Tested:
- Unit tests passed (ninja -C build/ test)
- Installed this build and booted with it.
2018-08-06 19:26:35 -07: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
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
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
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
Zbigniew Jędrzejewski-Szmek 87ac8d998f tree-wide: use "cannot" instead of "can not"
This is the usual spelling, and a bit shorter.
2018-02-08 10:34:52 +01:00
Patrik Flykt 6e849e95ad networkd: Move Router Advertisement functionality to a single file
Centralize Router Advertisement functionality in networkd-radv instead
of keeping it in networkd-address.
2018-01-04 15:22:43 +02:00
Patrik Flykt a86d329f22 networkd: Free Prefix in case allocation fails (#7480)
Set the code to call _cleanup_prefix_free_ in case the next allocation
fails so that Prefix does not leak memory.

Reported by evverx.
2017-11-27 13:07:22 +01:00
Shawn Landden 4831981d89 tree-wide: adjust fall through comments so that gcc is happy
Distcc removes comments, making the comment silencing
not work.

I know there was a decision against a macro in commit
ec251fe7d5
2017-11-20 13:06:25 -08:00
Lennart Poettering 8c6f6a2f91
Merge pull request #6910 from ssahani/issue-6359
networkd: For IPv6 addresses do not treat IFA_F_DEPRECATED as not ready. (Fix #6359)
2017-11-20 19:21:36 +01:00
Susant Sahani e87e2b78f7 networkd: address - support for /31 IPv4 addresses (rfc3021) (#6938)
When configuring a network address with /31 using networkd, a /31 without a
broadcast specified should be present.

 A /31 which has neither a network nor a broadcast address. See
https://tools.ietf.org/html/rfc3021

Fixes #4038
2017-11-20 19:16:01 +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
Yu Watanabe 4c70109600 tree-wide: use IN_SET macro (#6977) 2017-10-04 16:01:32 +02:00
Susant Sahani b7ed5384ab networkd: Do not treat IPv6 addresses IFA_F_DEPRECATED as not ready.
When we are receiving address lifetime valid and lifetime preferred
'0' we set them via ndisc. That makes is shows as depricated and we
treat this as not ready.

In link_check_ready we look for whether address is depricated and
since this is depricated we never configure this link.

Thanks to Marc Haber <mh+github@zugschlus.de>

lifetime 0 a valid, and common, use case. It enables an installation to
autoconfigure systems in a way that they become immediately reachable
without needing local configuration after they have been turned on (for
example, for remote configuration).  The local admin can then configure
additional, static IP addresses to be used for the server's service (and
the IP adress _only_, while the rest of network configuration still comes
from autoconfiguration), while _KEEPING_ the possibiltiy to reach the
system over the autoconfigured address in the case that static
configuration fails.

The correct way is to handle the announcement exactly as it is correctly
handled in the released software: It configures the address as
"deprecated", causing the kernel to accept packets addresses to it, and
not to use it for outgoing packets/connections _UNLESS_ there is no other
way to send the packet out.

The only change that is needed is that systemd-networkd should not wedge
itself in that case, it should just continue working (with two IP
addresses configured on the interface).

An IPv6 address with a remamining lifetime of zero is _NOT_ like an
expired IPv4 DHCP lease, it's still a valid and useable IP address. It
is just that the network advises the host not to use the address any
more for outgoing traffic _UNLESS_ there is no other way to send the
traffic.

Fixes #6359
2017-09-26 16:24:26 +05:30
Lennart Poettering 5a941f5f21 in-addr-util: be more systematic with naming our functions
Let's rename all our functions that process IPv4 in_addr structures
in4_addr_xyz(), following the already establishing naming logic for
this.

Leave the in_addr_xyz() prefix for functions that process the IPv4/IPv6
in_addr_union union instead.
2017-09-22 15:24:54 +02:00
Susant Sahani 2959fb07cb networkd: add scope to address section (#6449)
This work allows to configure address Scope to

host | link | global or a number.

Closes #6446
2017-08-01 09:44:08 +02:00
Patrik Flykt 6abd0ef387 networkd-address: Use DIV_ROUND_UP for consistency
Use DIV_ROUND_UP for consistency instead of the previous construct.
2017-06-16 09:46:25 +03:00
Patrik Flykt 301a2fb99a networkd: Fix comment
Comment about not being a router is in the wrong place. Router lifetime
is assigned with config_parse_sec().
2017-06-16 09:44:45 +03:00
Patrik Flykt 7d5cac19b5 networkd: Add Router Advertisement variables
Add variables for enabling Router Advertisements, router lifetime as
well as managed and other information flags indicating use of DHCPv6.
Add configuration of default router preferences as defined in RFC 4191.

IPv6PrefixDelegation in the [Network] section has to be set in order
to enable prefix delegation. The rest of the prefix delegation values
are stored in the [IPv6PrefixDelegation] section. The host will act as
a default router if it is given a non-zero lifetime with
RouterLifetimeSec. Managed and OtherInformation booleans set the level
of DHCPv6 support, and the RouterPreference configures the router's
preference between low, medium and high. Words 'normal' and 'default'
are added as synonyms for 'medium' just to make configuration simpler.

This adds a section like the following to .network configuration files:
[Network]
IPv6PrefixDelegation=true

[IPv6PrefixDelegation]
RouterLifetimeSec=2000
Managed=false
OtherInformation=true
RouterPreference=medium
2017-05-15 14:49:50 +03:00
Patrik Flykt 9d5d0090ca networkd: Add IPv6Prefix sections to the network configuration files
Support zero or more [IPv6Prefix] sections in the network configuration
files. Each section can have one Prefix=<subnet>[/<prefixlength>]
option, with the preferred and valid lifetimes specified by
ValidLifetimeSec and PreferredLifetimeSec measured in seconds, and
with onlink and address autoconfiguration booleans specified by
OnLink and AddressAutoconfiguration variables.

This adds a section like the following to .network configuration files:
[IPv6Prefix]
Prefix=2001:db8:dead:beef::/64
OnLink=true
AddressAutoconfiguration=true
ValidLifetimeSec=1500
PreferredLifetimeSec=1000
2017-05-15 14:49:50 +03:00
Patrik Flykt 057abfd88a networkd: Add initial prefix handling for network configuration
Add initial code for handling prefixes in network configuration files.
Add hash map and list storing the information in systemd-networkd.
2017-05-15 14:49:50 +03:00
Susant Sahani a87d19fe0a networkd: use address_label_valid for label validation 2017-02-28 16:54:33 +05:30
Susant Sahani f7fe70ea31 networkd: address config add error checking
We not looking for hashmap_put return error code.
2017-02-22 11:11:28 +05:30