]> git.saurik.com Git - apple/mdnsresponder.git/blob - ServiceRegistration/route.h
mDNSResponder-1310.40.42.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
140 typedef enum icmp_option_type {
141 icmp_option_source_link_layer_address = 1,
142 icmp_option_target_link_layer_address = 2,
143 icmp_option_prefix_information = 3,
144 icmp_option_redirected_header = 4,
145 icmp_option_mtu = 5,
146 icmp_option_route_information = 24,
147 } icmp_option_type_t;
148
149 typedef enum icmp_type {
150 icmp_type_echo_request = 128,
151 icmp_type_echo_reply = 129,
152 icmp_type_router_solicitation = 133,
153 icmp_type_router_advertisement = 134,
154 icmp_type_neighbor_solicitation = 135,
155 icmp_type_neighbor_advertisement = 136,
156 icmp_type_redirect = 137,
157 } icmp_type_t;
158
159 typedef struct link_layer_address {
160 uint16_t length;
161 uint8_t address[32];
162 } link_layer_address_t;
163
164 typedef struct prefix_information {
165 struct in6_addr prefix;
166 uint8_t length;
167 uint8_t flags;
168 uint32_t valid_lifetime;
169 uint32_t preferred_lifetime;
170 } prefix_information_t;
171
172 typedef struct route_information {
173 struct in6_addr prefix;
174 uint8_t length;
175 uint8_t flags;
176 uint32_t route_lifetime;
177 } route_information_t;
178
179 typedef struct icmp_option {
180 icmp_option_type_t type;
181 union {
182 link_layer_address_t link_layer_address;
183 prefix_information_t prefix_information;
184 route_information_t route_information;
185 } option;
186 } icmp_option_t;
187
188 struct icmp_message {
189 icmp_message_t *NULLABLE next;
190 interface_t *NULLABLE interface;
191 icmp_option_t *NULLABLE options;
192 bool new_router; // If this router information is a newly recevied one.
193 bool received_time_already_adjusted; // if the received time of the message is already adjusted by
194 // vicarious mode
195 struct in6_addr source;
196 struct in6_addr destination;
197
198 uint64_t received_time;
199
200 uint32_t reachable_time;
201 uint32_t retransmission_timer;
202 uint8_t cur_hop_limit; // Current hop limit for Router Advertisement messages.
203 uint8_t flags;
204 uint8_t type;
205 uint8_t code;
206 uint16_t checksum; // We hope the kernel figures this out for us.
207 uint16_t router_lifetime;
208
209 int num_options;
210 int hop_limit; // Hop limit provided by the kernel, must be 255.
211 };
212
213 void ula_generate(void);
214 bool start_route_listener(void);
215 bool start_icmp_listener(void);
216 void icmp_leave_join(int sock, int ifindex, bool join);
217
218 #define interface_create(name, iface) interface_create_(name, iface, __FILE__, __LINE__)
219 interface_t *NULLABLE interface_create_(const char *NONNULL name, int ifindex,
220 const char *NONNULL file, int line);
221 #define interface_retain(interface) interface_retain_(interface, __FILE__, __LINE__)
222 void interface_retain_(interface_t *NONNULL interface, const char *NONNULL file, int line);
223 #define interface_release(interface) interface_release_(interface, __FILE__, __LINE__)
224 void interface_release_(interface_t *NONNULL interface, const char *NONNULL file, int line);
225 bool interface_monitor_start(void);
226 void thread_network_startup(void);
227 void thread_network_shutdown(void);
228 void partition_stop_advertising_pref_id(void);
229 void partition_start_srp_listener(void);
230 #endif // __SERVICE_REGISTRATION_ROUTE_H
231
232 // Local Variables:
233 // mode: C
234 // tab-width: 4
235 // c-file-style: "bsd"
236 // c-basic-offset: 4
237 // fill-column: 120
238 // indent-tabs-mode: nil
239 // End: