]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/radv-internal.h
Merge pull request #11647 from thom311/hashmap-avoid-compiler-warning
[thirdparty/systemd.git] / src / libsystemd-network / radv-internal.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 Copyright © 2017 Intel Corporation. All rights reserved.
6 ***/
7
8 #include "sd-radv.h"
9
10 #include "log.h"
11 #include "list.h"
12 #include "sparse-endian.h"
13
14 assert_cc(SD_RADV_DEFAULT_MIN_TIMEOUT_USEC <= SD_RADV_DEFAULT_MAX_TIMEOUT_USEC)
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
22 #define SD_RADV_OPT_RDNSS 25
23 #define SD_RADV_OPT_DNSSL 31
24
25 enum RAdvState {
26 SD_RADV_STATE_IDLE = 0,
27 SD_RADV_STATE_ADVERTISING = 1,
28 };
29 typedef enum RAdvState RAdvState;
30
31 struct sd_radv_opt_dns {
32 uint8_t type;
33 uint8_t length;
34 uint16_t reserved;
35 be32_t lifetime;
36 } _packed_;
37
38 struct sd_radv {
39 unsigned n_ref;
40 RAdvState state;
41
42 int ifindex;
43
44 sd_event *event;
45 int event_priority;
46
47 struct ether_addr mac_addr;
48 uint8_t hop_limit;
49 uint8_t flags;
50 uint32_t mtu;
51 uint16_t lifetime;
52
53 int fd;
54 unsigned ra_sent;
55 sd_event_source *recv_event_source;
56 sd_event_source *timeout_event_source;
57
58 unsigned n_prefixes;
59 LIST_HEAD(sd_radv_prefix, prefixes);
60
61 size_t n_rdnss;
62 struct sd_radv_opt_dns *rdnss;
63 struct sd_radv_opt_dns *dnssl;
64 };
65
66 #define radv_prefix_opt__contents { \
67 uint8_t type; \
68 uint8_t length; \
69 uint8_t prefixlen; \
70 uint8_t flags; \
71 be32_t valid_lifetime; \
72 be32_t preferred_lifetime; \
73 uint32_t reserved; \
74 struct in6_addr in6_addr; \
75 }
76
77 struct radv_prefix_opt radv_prefix_opt__contents;
78
79 /* We need the opt substructure to be packed, because we use it in send(). But
80 * if we use _packed_, this means that the structure cannot be used directly in
81 * normal code in general, because the fields might not be properly aligned.
82 * But in this particular case, the structure is defined in a way that gives
83 * proper alignment, even without the explicit _packed_ attribute. To appease
84 * the compiler we use the "unpacked" structure, but we also verify that
85 * structure contains no holes, so offsets are the same when _packed_ is used.
86 */
87 struct radv_prefix_opt__packed radv_prefix_opt__contents _packed_;
88 assert_cc(sizeof(struct radv_prefix_opt) == sizeof(struct radv_prefix_opt__packed));
89
90 struct sd_radv_prefix {
91 unsigned n_ref;
92
93 struct radv_prefix_opt opt;
94
95 LIST_FIELDS(struct sd_radv_prefix, prefix);
96
97 usec_t valid_until;
98 usec_t preferred_until;
99 };
100
101 #define log_radv_full(level, error, fmt, ...) log_internal(level, error, __FILE__, __LINE__, __func__, "RADV: " fmt, ##__VA_ARGS__)
102 #define log_radv_errno(error, fmt, ...) log_radv_full(LOG_DEBUG, error, fmt, ##__VA_ARGS__)
103 #define log_radv(fmt, ...) log_radv_errno(0, fmt, ##__VA_ARGS__)