]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-network/radv-internal.h
Merge pull request #17549 from yuwata/tiny-fixes
[thirdparty/systemd.git] / src / libsystemd-network / radv-internal.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
04473969
PF
2#pragma once
3
4/***
810adae9 5 Copyright © 2017 Intel Corporation. All rights reserved.
04473969
PF
6***/
7
8#include "sd-radv.h"
9
10#include "log.h"
11#include "list.h"
12#include "sparse-endian.h"
13
ab1a1ba5 14assert_cc(SD_RADV_DEFAULT_MIN_TIMEOUT_USEC <= SD_RADV_DEFAULT_MAX_TIMEOUT_USEC);
204fb681
PF
15
16#define SD_RADV_MAX_INITIAL_RTR_ADVERT_INTERVAL_USEC (16*USEC_PER_SEC)
17#define SD_RADV_MAX_INITIAL_RTR_ADVERTISEMENTS 3
18#define SD_RADV_MAX_FINAL_RTR_ADVERTISEMENTS 3
19#define SD_RADV_MIN_DELAY_BETWEEN_RAS 3
20#define SD_RADV_MAX_RA_DELAY_TIME_USEC (500*USEC_PER_MSEC)
21
203d4df5 22#define SD_RADV_OPT_ROUTE_INFORMATION 24
e9c6da38 23#define SD_RADV_OPT_RDNSS 25
e965d6ab 24#define SD_RADV_OPT_DNSSL 31
e9c6da38 25
204f99d2
PF
26enum RAdvState {
27 SD_RADV_STATE_IDLE = 0,
28 SD_RADV_STATE_ADVERTISING = 1,
29};
30typedef enum RAdvState RAdvState;
31
e9c6da38
PF
32struct sd_radv_opt_dns {
33 uint8_t type;
34 uint8_t length;
35 uint16_t reserved;
36 be32_t lifetime;
37} _packed_;
38
204f99d2
PF
39struct sd_radv {
40 unsigned n_ref;
41 RAdvState state;
42
43 int ifindex;
44
45 sd_event *event;
46 int event_priority;
47
48 struct ether_addr mac_addr;
49 uint8_t hop_limit;
50 uint8_t flags;
51 uint32_t mtu;
52 uint16_t lifetime;
53
77baf5ae 54 int fd;
204fb681 55 unsigned ra_sent;
88d5a3db 56 sd_event_source *recv_event_source;
204fb681
PF
57 sd_event_source *timeout_event_source;
58
204f99d2
PF
59 unsigned n_prefixes;
60 LIST_HEAD(sd_radv_prefix, prefixes);
e9c6da38 61
203d4df5
SS
62 unsigned n_route_prefixes;
63 LIST_HEAD(sd_radv_route_prefix, route_prefixes);
64
e9c6da38
PF
65 size_t n_rdnss;
66 struct sd_radv_opt_dns *rdnss;
e965d6ab 67 struct sd_radv_opt_dns *dnssl;
204f99d2
PF
68};
69
e27b9aba
ZJS
70#define radv_prefix_opt__contents { \
71 uint8_t type; \
72 uint8_t length; \
73 uint8_t prefixlen; \
74 uint8_t flags; \
75 be32_t valid_lifetime; \
76 be32_t preferred_lifetime; \
77 uint32_t reserved; \
78 struct in6_addr in6_addr; \
79}
80
81struct radv_prefix_opt radv_prefix_opt__contents;
82
83/* We need the opt substructure to be packed, because we use it in send(). But
84 * if we use _packed_, this means that the structure cannot be used directly in
85 * normal code in general, because the fields might not be properly aligned.
86 * But in this particular case, the structure is defined in a way that gives
87 * proper alignment, even without the explicit _packed_ attribute. To appease
88 * the compiler we use the "unpacked" structure, but we also verify that
89 * structure contains no holes, so offsets are the same when _packed_ is used.
90 */
91struct radv_prefix_opt__packed radv_prefix_opt__contents _packed_;
92assert_cc(sizeof(struct radv_prefix_opt) == sizeof(struct radv_prefix_opt__packed));
93
04473969
PF
94struct sd_radv_prefix {
95 unsigned n_ref;
96
e27b9aba 97 struct radv_prefix_opt opt;
04473969
PF
98
99 LIST_FIELDS(struct sd_radv_prefix, prefix);
d601b566
PF
100
101 usec_t valid_until;
102 usec_t preferred_until;
04473969
PF
103};
104
203d4df5
SS
105#define radv_route_prefix_opt__contents { \
106 uint8_t type; \
107 uint8_t length; \
108 uint8_t prefixlen; \
109 uint8_t flags_reserved; \
110 be32_t lifetime; \
111 struct in6_addr in6_addr; \
112}
113
114struct radv_route_prefix_opt radv_route_prefix_opt__contents;
115
116struct radv_route_prefix_opt__packed radv_route_prefix_opt__contents _packed_;
117assert_cc(sizeof(struct radv_route_prefix_opt) == sizeof(struct radv_route_prefix_opt__packed));
118
119struct sd_radv_route_prefix {
120 unsigned n_ref;
121
122 struct radv_route_prefix_opt opt;
123
124 LIST_FIELDS(struct sd_radv_route_prefix, prefix);
125};
126
62c6bbbc 127#define log_radv_full(level, error, fmt, ...) log_internal(level, error, PROJECT_FILE, __LINE__, __func__, "RADV: " fmt, ##__VA_ARGS__)
04473969 128#define log_radv_errno(error, fmt, ...) log_radv_full(LOG_DEBUG, error, fmt, ##__VA_ARGS__)
04473969 129#define log_radv(fmt, ...) log_radv_errno(0, fmt, ##__VA_ARGS__)