]> git.saurik.com Git - apple/mdnsresponder.git/blob - ServiceRegistration/route.h
mDNSResponder-1310.60.4.tar.gz
[apple/mdnsresponder.git] / ServiceRegistration / route.h
1 /* route.h
2 *
3 * Copyright (c) 2019-2020 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #ifndef __SERVICE_REGISTRATION_ROUTE_H
19 #define __SERVICE_REGISTRATION_ROUTE_H
20 #if defined(USE_IPCONFIGURATION_SERVICE)
21 #include <SystemConfiguration/SystemConfiguration.h>
22 #include "IPConfigurationService.h"
23 #endif
24
25 #define MIN_DELAY_BETWEEN_RAS 4000
26 #define MSEC_PER_SEC (NSEC_PER_SEC / NSEC_PER_MSEC)
27 #define MAX_ROUTER_RECEIVED_TIME_GAP_BEFORE_STALE 600 * MSEC_PER_SEC
28
29 // Fix this
30 #ifndef IPV6_ROUTER_MODE_EXCLUSIVE
31 #define IPV6_ROUTER_MODE_DISABLED 0
32 #define IPV6_ROUTER_MODE_EXCLUSIVE 1
33 #define IPV6_ROUTER_MODE_HYBRID 2
34 #endif
35
36
37 typedef struct interface interface_t;
38 typedef struct icmp_message icmp_message_t;
39 typedef struct network_link network_link_t;
40 struct interface {
41 int ref_count;
42
43 interface_t *NULLABLE next;
44 char *NONNULL name;
45
46 // Wakeup event for next beacon.
47 wakeup_t *NULLABLE beacon_wakeup;
48
49 // Wakeup event called after we're done sending solicits. At this point we delete all routes more than 10 minutes
50 // old; if none are left, then we assume there's no IPv6 service on the interface.
51 wakeup_t *NULLABLE post_solicit_wakeup;
52
53 // Wakeup event to trigger the next router solicit to be sent.
54 wakeup_t *NULLABLE router_solicit_wakeup;
55
56 // Wakeup event to deconfigure the on-link prefix after it is no longer valid.
57 wakeup_t *NULLABLE deconfigure_wakeup;
58
59 // Wakeup event to detect that vicarious router discovery is complete
60 wakeup_t *NULLABLE vicarious_discovery_complete;
61
62 // List of ICMP messages from different routers.
63 icmp_message_t *NULLABLE routers;
64
65 // The link to which this interface is connected.
66 network_link_t *NULLABLE link;
67
68 #if defined(USE_IPCONFIGURATION_SERVICE)
69 // The service used to configure this interface with an address in the on-link prefix
70 IPConfigurationServiceRef NULLABLE ip_configuration_service;
71
72 // SCDynamicStoreRef
73 SCDynamicStoreRef NULLABLE ip_configuration_store;
74 #endif
75
76 struct in6_addr link_local; // Link-local address
77 struct in6_addr ipv6_prefix; // This is the prefix we advertise, if advertise_ipv6_prefix is true.
78
79 // Absolute time of last beacon, and of next beacon.
80 uint64_t last_beacon, next_beacon;
81
82 // Absolute deadline for deprecating the on-link prefix we've been announcing
83 uint64_t deprecate_deadline;
84
85 // Preferred lifetime for the on-link prefix
86 uint32_t preferred_lifetime;
87
88 // Valid lifetime for the on-link prefix
89 uint32_t valid_lifetime;
90
91 // When the interface becomes active, we send up to three solicits.
92 int num_solicits_sent;
93
94 // The interface index according to the operating systme.
95 int index;
96
97 // Number of IPv4 addresses configured on link.
98 int num_ipv4_addresses;
99
100 // Number of beacons sent. After the first three, the inter-beacon interval goes up.
101 int num_beacons_sent;
102
103 // The interface link layer address, if known.
104 uint8_t link_layer[6];
105
106 // True if the interface is not usable.
107 bool inactive;
108
109 // True if this interface can never be used for routing to the thread network (e.g., loopback, tunnels, etc.)
110 bool ineligible;
111
112 // True if we've determined that it's the thread interface.
113 bool is_thread;
114
115 // True if we should advertise an on-link prefix.
116 bool advertise_ipv6_prefix;
117
118 // True if we've gotten a link-layer address.
119 bool have_link_layer_address;
120
121 // True if the on-link prefix is configured on the interface.
122 bool on_link_prefix_configured;
123
124 // True if we've sent our first beacon since the interface came up.
125 bool sent_first_beacon;
126
127 // Indicates whether or not router discovery has completed for this interface.
128 bool router_discovery_complete;
129
130 // Indicates whether we're currently doing router discovery, so that we don't
131 // restart it when we're already doing it.
132 bool router_discovery_in_progress;
133
134 // Indicates that we've received a router discovery message from some other host,
135 // and are waiting 20 seconds to snoop for replies to that RD message that are
136 // multicast. If we hear no replies during that time, we trigger router discovery.
137 bool vicarious_router_discovery_in_progress;
138
139 // Indicates that we have received an interface removal event, it is useful when srp-mdns-proxy is changed to a new
140 // network where the network signature are the same and they both have no IPv6 service (so no IPv6 prefix will be
141 // removed), in such case there will be no change from srp-mdns-proxy's point of view. However, configd may still
142 // flush the IPv6 routing since changing network would cause interface up/down. When the flushing happens,
143 // srp-mdns-proxy should be able to reconfigure the IPv6 routing by reconfiguring IPv6 prefix. By setting
144 // need_reconfigure_prefix only when interface address removal happens and check it during the routing evaluation
145 // srp-mdns-proxy can reconfigure it after the routing evaluation finishes, like router discovery.
146 bool need_reconfigure_prefix;
147 };
148
149 typedef enum icmp_option_type {
150 icmp_option_source_link_layer_address = 1,
151 icmp_option_target_link_layer_address = 2,
152 icmp_option_prefix_information = 3,
153 icmp_option_redirected_header = 4,
154 icmp_option_mtu = 5,
155 icmp_option_route_information = 24,
156 } icmp_option_type_t;
157
158 typedef enum icmp_type {
159 icmp_type_echo_request = 128,
160 icmp_type_echo_reply = 129,
161 icmp_type_router_solicitation = 133,
162 icmp_type_router_advertisement = 134,
163 icmp_type_neighbor_solicitation = 135,
164 icmp_type_neighbor_advertisement = 136,
165 icmp_type_redirect = 137,
166 } icmp_type_t;
167
168 typedef struct link_layer_address {
169 uint16_t length;
170 uint8_t address[32];
171 } link_layer_address_t;
172
173 typedef struct prefix_information {
174 struct in6_addr prefix;
175 uint8_t length;
176 uint8_t flags;
177 uint32_t valid_lifetime;
178 uint32_t preferred_lifetime;
179 } prefix_information_t;
180
181 typedef struct route_information {
182 struct in6_addr prefix;
183 uint8_t length;
184 uint8_t flags;
185 uint32_t route_lifetime;
186 } route_information_t;
187
188 typedef struct icmp_option {
189 icmp_option_type_t type;
190 union {
191 link_layer_address_t link_layer_address;
192 prefix_information_t prefix_information;
193 route_information_t route_information;
194 } option;
195 } icmp_option_t;
196
197 struct icmp_message {
198 icmp_message_t *NULLABLE next;
199 interface_t *NULLABLE interface;
200 icmp_option_t *NULLABLE options;
201 bool new_router; // If this router information is a newly recevied one.
202 bool received_time_already_adjusted; // if the received time of the message is already adjusted by
203 // vicarious mode
204 struct in6_addr source;
205 struct in6_addr destination;
206
207 uint64_t received_time;
208
209 uint32_t reachable_time;
210 uint32_t retransmission_timer;
211 uint8_t cur_hop_limit; // Current hop limit for Router Advertisement messages.
212 uint8_t flags;
213 uint8_t type;
214 uint8_t code;
215 uint16_t checksum; // We hope the kernel figures this out for us.
216 uint16_t router_lifetime;
217
218 int num_options;
219 int hop_limit; // Hop limit provided by the kernel, must be 255.
220 };
221
222 void ula_generate(void);
223 bool start_route_listener(void);
224 bool start_icmp_listener(void);
225 void icmp_leave_join(int sock, int ifindex, bool join);
226
227 #define interface_create(name, iface) interface_create_(name, iface, __FILE__, __LINE__)
228 interface_t *NULLABLE interface_create_(const char *NONNULL name, int ifindex,
229 const char *NONNULL file, int line);
230 #define interface_retain(interface) interface_retain_(interface, __FILE__, __LINE__)
231 void interface_retain_(interface_t *NONNULL interface, const char *NONNULL file, int line);
232 #define interface_release(interface) interface_release_(interface, __FILE__, __LINE__)
233 void interface_release_(interface_t *NONNULL interface, const char *NONNULL file, int line);
234 bool interface_monitor_start(void);
235 void thread_network_startup(void);
236 void thread_network_shutdown(void);
237 void partition_stop_advertising_pref_id(void);
238 void partition_start_srp_listener(void);
239 #endif // __SERVICE_REGISTRATION_ROUTE_H
240
241 // Local Variables:
242 // mode: C
243 // tab-width: 4
244 // c-file-style: "bsd"
245 // c-basic-offset: 4
246 // fill-column: 120
247 // indent-tabs-mode: nil
248 // End: