203d4df573
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:: ```
130 lines
4.1 KiB
C
130 lines
4.1 KiB
C
/* SPDX-License-Identifier: LGPL-2.1+ */
|
|
#pragma once
|
|
|
|
/***
|
|
Copyright © 2017 Intel Corporation. All rights reserved.
|
|
***/
|
|
|
|
#include "sd-radv.h"
|
|
|
|
#include "log.h"
|
|
#include "list.h"
|
|
#include "sparse-endian.h"
|
|
|
|
assert_cc(SD_RADV_DEFAULT_MIN_TIMEOUT_USEC <= SD_RADV_DEFAULT_MAX_TIMEOUT_USEC);
|
|
|
|
#define SD_RADV_MAX_INITIAL_RTR_ADVERT_INTERVAL_USEC (16*USEC_PER_SEC)
|
|
#define SD_RADV_MAX_INITIAL_RTR_ADVERTISEMENTS 3
|
|
#define SD_RADV_MAX_FINAL_RTR_ADVERTISEMENTS 3
|
|
#define SD_RADV_MIN_DELAY_BETWEEN_RAS 3
|
|
#define SD_RADV_MAX_RA_DELAY_TIME_USEC (500*USEC_PER_MSEC)
|
|
|
|
#define SD_RADV_OPT_ROUTE_INFORMATION 24
|
|
#define SD_RADV_OPT_RDNSS 25
|
|
#define SD_RADV_OPT_DNSSL 31
|
|
|
|
enum RAdvState {
|
|
SD_RADV_STATE_IDLE = 0,
|
|
SD_RADV_STATE_ADVERTISING = 1,
|
|
};
|
|
typedef enum RAdvState RAdvState;
|
|
|
|
struct sd_radv_opt_dns {
|
|
uint8_t type;
|
|
uint8_t length;
|
|
uint16_t reserved;
|
|
be32_t lifetime;
|
|
} _packed_;
|
|
|
|
struct sd_radv {
|
|
unsigned n_ref;
|
|
RAdvState state;
|
|
|
|
int ifindex;
|
|
|
|
sd_event *event;
|
|
int event_priority;
|
|
|
|
struct ether_addr mac_addr;
|
|
uint8_t hop_limit;
|
|
uint8_t flags;
|
|
uint32_t mtu;
|
|
uint16_t lifetime;
|
|
|
|
int fd;
|
|
unsigned ra_sent;
|
|
sd_event_source *recv_event_source;
|
|
sd_event_source *timeout_event_source;
|
|
|
|
unsigned n_prefixes;
|
|
LIST_HEAD(sd_radv_prefix, prefixes);
|
|
|
|
unsigned n_route_prefixes;
|
|
LIST_HEAD(sd_radv_route_prefix, route_prefixes);
|
|
|
|
size_t n_rdnss;
|
|
struct sd_radv_opt_dns *rdnss;
|
|
struct sd_radv_opt_dns *dnssl;
|
|
};
|
|
|
|
#define radv_prefix_opt__contents { \
|
|
uint8_t type; \
|
|
uint8_t length; \
|
|
uint8_t prefixlen; \
|
|
uint8_t flags; \
|
|
be32_t valid_lifetime; \
|
|
be32_t preferred_lifetime; \
|
|
uint32_t reserved; \
|
|
struct in6_addr in6_addr; \
|
|
}
|
|
|
|
struct radv_prefix_opt radv_prefix_opt__contents;
|
|
|
|
/* We need the opt substructure to be packed, because we use it in send(). But
|
|
* if we use _packed_, this means that the structure cannot be used directly in
|
|
* normal code in general, because the fields might not be properly aligned.
|
|
* But in this particular case, the structure is defined in a way that gives
|
|
* proper alignment, even without the explicit _packed_ attribute. To appease
|
|
* the compiler we use the "unpacked" structure, but we also verify that
|
|
* structure contains no holes, so offsets are the same when _packed_ is used.
|
|
*/
|
|
struct radv_prefix_opt__packed radv_prefix_opt__contents _packed_;
|
|
assert_cc(sizeof(struct radv_prefix_opt) == sizeof(struct radv_prefix_opt__packed));
|
|
|
|
struct sd_radv_prefix {
|
|
unsigned n_ref;
|
|
|
|
struct radv_prefix_opt opt;
|
|
|
|
LIST_FIELDS(struct sd_radv_prefix, prefix);
|
|
|
|
usec_t valid_until;
|
|
usec_t preferred_until;
|
|
};
|
|
|
|
#define radv_route_prefix_opt__contents { \
|
|
uint8_t type; \
|
|
uint8_t length; \
|
|
uint8_t prefixlen; \
|
|
uint8_t flags_reserved; \
|
|
be32_t lifetime; \
|
|
struct in6_addr in6_addr; \
|
|
}
|
|
|
|
struct radv_route_prefix_opt radv_route_prefix_opt__contents;
|
|
|
|
struct radv_route_prefix_opt__packed radv_route_prefix_opt__contents _packed_;
|
|
assert_cc(sizeof(struct radv_route_prefix_opt) == sizeof(struct radv_route_prefix_opt__packed));
|
|
|
|
struct sd_radv_route_prefix {
|
|
unsigned n_ref;
|
|
|
|
struct radv_route_prefix_opt opt;
|
|
|
|
LIST_FIELDS(struct sd_radv_route_prefix, prefix);
|
|
};
|
|
|
|
#define log_radv_full(level, error, fmt, ...) log_internal(level, error, PROJECT_FILE, __LINE__, __func__, "RADV: " fmt, ##__VA_ARGS__)
|
|
#define log_radv_errno(error, fmt, ...) log_radv_full(LOG_DEBUG, error, fmt, ##__VA_ARGS__)
|
|
#define log_radv(fmt, ...) log_radv_errno(0, fmt, ##__VA_ARGS__)
|