Commit Graph

55 Commits

Author SHA1 Message Date
Lennart Poettering 6333aa9d46 sd-radv: fix indentation
Fix-up for 97efde65d8
2020-09-23 13:44:26 +02:00
Zbigniew Jędrzejewski-Szmek afa8ffae99 various: remove assignments of unread variables 2020-09-22 17:58:11 +02:00
Michael Marley 97efde65d8 network: radv: Send RA on newly-added dynamic prefix
When a prefix is delegated to an interface that is already sending
RAs, send an RA immediately to inform clients of the new prefix.
This allows them to start using it immediately instead of waiting
up to nearly 10 minutes (depending on when the last timed RA was
sent).  This type of situation might occur if, for example, an
outage of the WAN connection caused the addresses and prefixes to
be lost and later regained after service was restored.  The
condition for the number of RAs sent being above 0 simultaneously
ensures that RADV is already running and that this code doesn't
send any RAs before the timed RAs have started when the interface
first comes up.
2020-07-27 05:28:33 +09:00
Yu Watanabe 96fe813c42 radv: introduce sd_radv_is_running() 2020-07-20 15:29:12 +09:00
Yu Watanabe 290696e512 Revert "network: Don't send RA with zero router lifetime when restarting radv"
This reverts commit d469cea3bd.
2020-07-07 11:06:08 +09:00
Michael Marley d469cea3bd network: Don't send RA with zero router lifetime when restarting radv
While investigating https://github.com/systemd/systemd/issues/16356, I
discovered that networkd stops the radv service before adding or updating
prefixes and then starts it again.  This causes networkd to send an RA with
a router lifetime of zero, causing the routes to flap on systems receiving
the RA for a fraction of a second before radv is started again and proper
RAs are sent.  That has the potential to cause issues with latency-sensitive
traffic like gaming or VoIP.  This patch adds a boolean argument to the
sd_radv_stop() function to control this behavior.  The zero lifetime RA is
still sent whenever radv is actually being stopped, but when it is being
restarted for a prefix update (from networkd-dhcp6.c), the final RA is no
longer sent to avoid the route flapping.
2020-07-07 10:49:25 +09:00
Yu Watanabe 7fa69c0a6f dhcp6, radv: only accept valid ifindex 2020-07-02 16:58:06 +09:00
Benjamin Robin 81c5a5961f network: 'cur' variable cannot be null, so simplify code 2020-05-13 22:56:42 +02:00
Susant Sahani 34332af2bc network: radv introduce sd_radv_prefix_get_prefix 2020-03-01 00:16:51 +09:00
Yu Watanabe 69d7eba188 sd-radv: fix memleak 2019-11-05 13:30:00 +09:00
Georg Müller ef90b6a4fb sd-radv: if lifetime < SD_RADV_DEFAULT_MAX_TIMEOUT_USEC, adjust timeout (#13491)
The RFC states that lifetime (AdvDefaultLifetime) must be at least
MaxRtrAdvInterval (which more or less corresponds to SD_RADV_DEFAULT_MAX_TIMEOUT_USEC
in systemd).

To fulfill this limit, virtually lower MaxRtrAdvInterval and MinRtrAdvInterval
accordingly.

Also check that min is not lower than 3s and max is not lower than 4s.
2019-09-20 13:52:29 +00:00
Susant Sahani 203d4df573 network: Add support to advertie ipv6 route
Implements https://tools.ietf.org/html/rfc4191

cat veth99.network
```
[Match]
Name=veth99

[Network]
DHCP=no
IPv6PrefixDelegation=yes
Address=2001:db8:0:1::1/64

[IPv6Prefix]
Prefix=2001:db8:0:1::4/64

[IPv6RoutePrefix]
Route=2001:db0:fff::/48

```
Wireshark

```
Frame 481: 142 bytes on wire (1136 bits), 142 bytes captured (1136 bits) on interface 0
Ethernet II, Src: 1e:04:f8:b8:2f:d4 (1e:04:f8:b8:2f:d4), Dst: IPv6mcast_01 (33:33:00:00:00:01)
Internet Protocol Version 6, Src: fe80::1c04:f8ff:feb8:2fd4, Dst: ff02::1
Internet Control Message Protocol v6
    Type: Router Advertisement (134)
    Code: 0
    Checksum: 0xec77 [correct]
    [Checksum Status: Good]
    Cur hop limit: 0
    Flags: 0x00, Prf (Default Router Preference): Medium
    Router lifetime (s): 0
    Reachable time (ms): 0
    Retrans timer (ms): 0
    ICMPv6 Option (Source link-layer address : 1e:04:f8:b8:2f:d4)
        Type: Source link-layer address (1)
        Length: 1 (8 bytes)
        Link-layer address: 1e:04:f8:b8:2f:d4 (1e:04:f8:b8:2f:d4)
    ICMPv6 Option (MTU : 1500)
        Type: MTU (5)
        Length: 1 (8 bytes)
        Reserved
        MTU: 1500
    ICMPv6 Option (Prefix information : 2001:db8:0:1::4/64)
        Type: Prefix information (3)
        Length: 4 (32 bytes)
        Prefix Length: 64
        Flag: 0xc0, On-link flag(L), Autonomous address-configuration flag(A)
        Valid Lifetime: 2592000
        Preferred Lifetime: 604800
        Reserved
        Prefix: 2001:db8:0:1::4
    ICMPv6 Option (Route Information : Medium 2001:db0:fff::/48)
        Type: Route Information (24)
        Length: 3 (24 bytes)
        Prefix Length: 48
        Flag: 0x00, Route Preference: Medium
            ...0 0... = Route Preference: Medium (0)
            000. .000 = Reserved: 0
        Route Lifetime: 604800
        Prefix: 2001:db0:fff::
```
2019-09-17 12:09:59 +02:00
Yu Watanabe 62bbbedf73 sd-radv: fix memleak
Fixes one memleak found in #12452.
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
Lennart Poettering 59ea6e57a5 networkd: refuse IPv6 RADV prefixes that lack Prefix= setting
Fixes: #9589
2018-11-30 22:19:28 +01:00
Lennart Poettering 5cfa2c3dc0 tree-wide: use IOVEC_MAKE() at many places 2018-11-27 10:12:27 +01:00
Lennart Poettering d2c8eed219 sd-radv: use struct initializers 2018-11-26 22:31:15 +01:00
Lennart Poettering a3a98776ff sd-radv: per our CODING_STYLE don't use 'bool' in public headers 2018-11-26 22:31:15 +01:00
Lennart Poettering f474884cb9 sd-radv: no need to initialize r to zero 2018-11-26 22:31:15 +01:00
Lennart Poettering 5a9fca258b sd-radv: make sure we can deal with in_addr_to_string() failing 2018-11-26 22:31:15 +01:00
Lennart Poettering cfffddeac5 sd-radv: when receiving a too short packet, make sure we dequeue it 2018-11-26 22:31:15 +01:00
Lennart Poettering e55a6eaeb9 sd-radv: propagate OOM, it's reason to fail 2018-11-26 22:31:15 +01:00
Lennart Poettering e866e17b0f sd-radv: follow our usualy rule that destructors can take NULL 2018-11-26 22:31:15 +01:00
Lennart Poettering dc0ec5e251 sd-radv: simplify IPv6 address is-null check 2018-11-26 22:31:15 +01:00
Lennart Poettering 83ef9d141b sd-radv: drop const from non-ptr argument 2018-11-26 22:31:15 +01:00
Lennart Poettering ae25915d24 sd-radv: use ether_addr_is_null() where appropriate 2018-11-26 22:31:15 +01:00
Yu Watanabe 807a8edeb1 sd-radv: do not unref() event sources when update or disable them 2018-11-16 22:57:42 +09:00
Yu Watanabe 78f9d24f7b sd-radv: use structured initializer at one more place 2018-11-16 22:57:42 +09:00
Lennart Poettering 8eb41f4c08 sd-radv: EAGAIN is not really unexpected, distinguishit from other errors when logging 2018-10-02 16:26:50 +02:00
Lennart Poettering fdc2afc102 sd-radv: remove log_radv_warning_errno()
According to our CODING_STYLE our library code should generally not log
beyond LOG_DEBUG. Let's hence get rid of log_radv_warning_errno() and
just use log_radv_errno() instead.
2018-10-02 16:22:54 +02:00
Yu Watanabe 8301aa0bf1 tree-wide: use DEFINE_TRIVIAL_REF_UNREF_FUNC() macro or friends where applicable 2018-08-27 14:01:46 +09:00
Chris Lamb 3fe910794b Correct a number of trivial typos. 2018-06-18 22:44:44 +02:00
Lennart Poettering 810adae9e9 tree-wide: use proper unicode © instead of (C) where we can
Let's use a proper unicode copyright symbol where we can, it's prettier.

This important patch is very important.
2018-06-14 10:20:20 +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 97d7974b18 sd-radv: use strv_isempty() where we can 2018-06-13 17:48:15 +02:00
Lennart Poettering f5a5706ace sd-radv: normalize function parameters a bit
Let's add "const" where we don't change structures passed.

Also, we generally use "unsigned char" for IP prefix length values, do
so here too. Previously different parts of the sd-radv.h API used
different types for this.
2018-06-13 17:48:15 +02:00
Lennart Poettering c4b6dda07f sd-radv: close fd when destroying object 2018-06-13 17:48:15 +02:00
Susant Sahani 6f8a8b84f2 networkd: Don't try to close fd in sd_radv_stop if fd is closed.
sd_radv_stop is called from two places. if sd_radv_stop is alrady
success then just don't try to close it .
```
systemd-networkd[604]: RADV: Stopping IPv6 Router Advertisement daemon
systemd-networkd[604]: RADV: Unable to send last Router Advertisement with router lifetime set to zero: Bad file descriptor <==================HERE
systemd-networkd[604]: RADV: Updated prefix 2a0a:*:*:fc::/64 preferred 1h valid 2h
systemd-networkd[604]: RADV: Started IPv6 Router Advertisement daemon
```

Closes one of the issue #8960
2018-06-13 17:14:47 +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
Lennart Poettering 38edb7674b
Merge pull request #7582 from pfl/dhcp6_prefix_delegation
DHCPv6 prefix delegation
2018-01-15 12:02:37 +01:00
Hans-Christian Noren Egtvedt 8a2b193a55 sd-radv: avoid redefinition of struct in6_addr
Both netinet/icmp6.h and linux/in6.h will define struct in6_addr, and in
user space we want to use the netinet/icmp6.h variant.

Fixes build problem:
In file included from src/libsystemd-network/sd-radv.c:23:0:
/home/hegtvedt/work/os/product/sunrise/root/_build/v2/include/linux/in6.h:30:8:
error: redefinition of 'struct in6_addr'
2018-01-10 12:32:03 +01:00
Patrik Flykt de661ccec7 radv: Allow setting MTU in all cases
Setting MTU is allowed in all cases and the MTU value will be
announced in the subsequent Router Advertisements.
2018-01-04 15:22:44 +02:00
Patrik Flykt 34c169c462 radv: Add function to remove prefixes
As DHCPv6 leases may expire at some point, the delegated prefixes
have to be removed. Add a prefix removal function to the Router
Advertisement handling code.
2018-01-04 15:22:44 +02:00
Patrik Flykt d601b56687 radv: Add prefixes with dynamically updated lifetimes
Add a boolean that indicates whether the prefixes will always exist
or if they will time out after the assigned valid lifetime. In the
latter case calculate the expiry times for both preferred and valid
lifetimes for the prefixes, and decrease the remaining lifetimes
each time when a Router Advertisement is sent.

Should the prefix be updated, re-calculate the prefix lifetime. When
updating, update the existing entry, if any, with the lifetimes of
the added entry as the existing entry has its lifetimes set
according to its previously calculated expiry times.
2018-01-04 15:22:44 +02: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
Patrik Flykt 6852c0f6b0 sd-radv: Allocate space also for DNSSL iov option (#7144)
The iov array needs to hold five entries in addition to the number
of prefixes.
2017-10-20 10:59:15 +02:00
Patrik Flykt f9aa5417d1 sd-radv: Free DNS domain search list on unref (#6858) 2017-09-18 12:09:44 +02:00
Patrik Flykt e965d6aba3 sd-radv: Add Router Advertisement DNS Search List option
Add Router Advertisement DNS Search List option as specified
in RFC 8106. The search list option uses and identical option
header as the RDNSS option and therefore the option header
structure can be reused.

If systemd is compiled with IDNA support, internationalization
of the provided search domain is applied, after which the search
list is written in wire format into the DNSSL option.
2017-09-15 10:34:57 +03:00
Patrik Flykt e9c6da3868 sd-radv: Add Router Advertisement DNS information
Add Router Advertisement Recursive DNS Server information as specified
in RFC 8106.
2017-09-07 09:51:26 +03:00