]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/radv-internal.h
b21d4e54cbd798ebb76eeb31219d6276936a342e
[thirdparty/systemd.git] / src / libsystemd-network / radv-internal.h
1 #pragma once
2
3 /***
4 This file is part of systemd.
5
6 Copyright (C) 2017 Intel Corporation. All rights reserved.
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include "sd-radv.h"
23
24 #include "log.h"
25 #include "list.h"
26 #include "sparse-endian.h"
27
28 #define SD_RADV_DEFAULT_MIN_TIMEOUT_USEC (200*USEC_PER_SEC)
29 #define SD_RADV_DEFAULT_MAX_TIMEOUT_USEC (600*USEC_PER_SEC)
30 assert_cc(SD_RADV_DEFAULT_MIN_TIMEOUT_USEC <= SD_RADV_DEFAULT_MAX_TIMEOUT_USEC)
31
32 #define SD_RADV_MAX_INITIAL_RTR_ADVERT_INTERVAL_USEC (16*USEC_PER_SEC)
33 #define SD_RADV_MAX_INITIAL_RTR_ADVERTISEMENTS 3
34 #define SD_RADV_MAX_FINAL_RTR_ADVERTISEMENTS 3
35 #define SD_RADV_MIN_DELAY_BETWEEN_RAS 3
36 #define SD_RADV_MAX_RA_DELAY_TIME_USEC (500*USEC_PER_MSEC)
37
38 enum RAdvState {
39 SD_RADV_STATE_IDLE = 0,
40 SD_RADV_STATE_ADVERTISING = 1,
41 };
42 typedef enum RAdvState RAdvState;
43
44 struct sd_radv {
45 unsigned n_ref;
46 RAdvState state;
47
48 int ifindex;
49
50 sd_event *event;
51 int event_priority;
52
53 struct ether_addr mac_addr;
54 uint8_t hop_limit;
55 uint8_t flags;
56 uint32_t mtu;
57 uint16_t lifetime;
58
59 int fd;
60 unsigned ra_sent;
61 sd_event_source *recv_event_source;
62 sd_event_source *timeout_event_source;
63
64 unsigned n_prefixes;
65 LIST_HEAD(sd_radv_prefix, prefixes);
66 };
67
68 struct sd_radv_prefix {
69 unsigned n_ref;
70
71 struct {
72 uint8_t type;
73 uint8_t length;
74 uint8_t prefixlen;
75 uint8_t flags;
76 be32_t valid_lifetime;
77 be32_t preferred_lifetime;
78 uint32_t reserved;
79 struct in6_addr in6_addr;
80 } _packed_ opt;
81
82 LIST_FIELDS(struct sd_radv_prefix, prefix);
83 };
84
85 #define log_radv_full(level, error, fmt, ...) log_internal(level, error, __FILE__, __LINE__, __func__, "RADV: " fmt, ##__VA_ARGS__)
86 #define log_radv_errno(error, fmt, ...) log_radv_full(LOG_DEBUG, error, fmt, ##__VA_ARGS__)
87 #define log_radv_warning_errno(error, fmt, ...) log_radv_full(LOG_WARNING, error, fmt, ##__VA_ARGS__)
88 #define log_radv(fmt, ...) log_radv_errno(0, fmt, ##__VA_ARGS__)