internal.h
12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
/*
* Copyright (C) 2017 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @addtogroup net_gnrc_netif
* @internal
* @attention **FOR GNRC-INTERNAL USE ONLY. PLEASE USE @ref net_gnrc_netapi
* "NETAPI" (WITH THE INTERFACE'S PID) FOR EXTERNAL MANIPULATION**
* @{
*
* @file
* @brief GNRC-internal network interface definitions
*
* @author Martine Lenders <m.lenders@fu-berlin.de>
*/
#ifndef NET_GNRC_NETIF2_INTERNAL_H
#define NET_GNRC_NETIF2_INTERNAL_H
#include "net/gnrc/netif2.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Message type for @ref netdev_event_t "netdev events"
*/
#define NETDEV_MSG_TYPE_EVENT (0x1234)
/**
* @brief Acquires exclusive access to the interface
*
* @param[in] netif the network interface
*
* @internal
*/
static inline void gnrc_netif2_acquire(gnrc_netif2_t *netif)
{
if (netif && (netif->ops)) {
rmutex_lock(&netif->mutex);
}
}
/**
* @brief Releases exclusive access to the interface
*
* @param[in] netif the network interface
*
* @internal
*/
static inline void gnrc_netif2_release(gnrc_netif2_t *netif)
{
if (netif && (netif->ops)) {
rmutex_unlock(&netif->mutex);
}
}
#if defined(MODULE_GNRC_IPV6) || DOXYGEN
/**
* @brief Adds an IPv6 address to the interface
*
* @pre `(netif != NULL) && (addr != NULL)`
* @pre @p addr is not multicast (starts with `ff00::/8`), unspecified (`::`),
* or loopback
* @pre `(pfx_len > 0) && (pfx_len <= 128)`
*
* @param[in,out] netif the network interface. May not be NULL.
* @param[in] addr the address to add. If the address is already on the
* interface the function will return 0, but @p flags
* will be ignored. May not be NULL and may not be
* link-local or multicast
* @param[in] pfx_len length in bits of the prefix of @p addr
* @param[in] flags initial flags for the address.
* - Setting the address' state to
* @ref GNRC_NETIF2_IPV6_ADDRS_FLAGS_STATE_TENTATIVE
* means that this address is assumed to be added due to
* stateless auto-address configuration and actions
* related to that may be performed in the background.
* - Setting the address' state to
* @ref GNRC_NETIF2_IPV6_ADDRS_FLAGS_STATE_VALID means
* that the address is assumed to be manually configured
* and its prefix will be added to the node's prefix
* list (valid and preferred lifetime will be set to
* infinite, but can be changed using
* @ref gnrc_ipv6_nib_pl_set()).
*
*
* @note Only available with @ref net_gnrc_ipv6 "gnrc_ipv6".
*
* @return >= 0, on success
* @return -ENOMEM, when no space for new addresses is left on the interface
*/
int gnrc_netif2_ipv6_addr_add(gnrc_netif2_t *netif, const ipv6_addr_t *addr,
unsigned pfx_len, uint8_t flags);
/**
* @brief Removes an IPv6 address from the interface
*
* @pre `(netif != NULL) && (addr != NULL)`
*
* @param[in,out] netif the network interface
* @param[in] addr the address to remove
*
* @note Only available with @ref net_gnrc_ipv6 "gnrc_ipv6".
*/
void gnrc_netif2_ipv6_addr_remove(gnrc_netif2_t *netif,
const ipv6_addr_t *addr);
/**
* @brief Returns the index of @p addr in gnrc_netif2_t::ipv6_addrs of @p
* netif
*
* @pre `(netif != NULL) && (addr != NULL)`
*
* Can be used to check if an address is assigned to an interface.
*
* @param[in] netif the network interface
* @param[in] addr the address to check
*
* @note Only available with @ref net_gnrc_ipv6 "gnrc_ipv6".
*
* @return index of @p addr in gnrc_netif2_t::ipv6_addrs of @p netif
* @return -1, if @p addr isn't assigned to @p netif
*/
int gnrc_netif2_ipv6_addr_idx(gnrc_netif2_t *netif,
const ipv6_addr_t *addr);
/**
* @brief Gets state from address flags
*
* @param[in] netif the network interface
* @param[in] idx index of the address flags
*
* @return the state of the address at @p idx
*/
static inline uint8_t gnrc_netif2_ipv6_addr_get_state(const gnrc_netif2_t *netif,
int idx)
{
return netif->ipv6.addrs_flags[idx] & GNRC_NETIF2_IPV6_ADDRS_FLAGS_STATE_MASK;
}
/**
* @brief Gets number of duplicate address detection transmissions already
* performed for an address
*
* @param[in] netif the network interface
* @param[in] idx index of the address (and its flags)
*
* @return the number of duplicate address detection transmissions already
* performed
*/
static inline uint8_t gnrc_netif2_ipv6_addr_dad_trans(const gnrc_netif2_t *netif,
int idx)
{
return netif->ipv6.addrs_flags[idx] & GNRC_NETIF2_IPV6_ADDRS_FLAGS_STATE_TENTATIVE;
}
/**
* @brief Returns the index of an address in gnrc_netif2_t::ipv6_addrs of @p
* netif that matches @p addr best
*
* @pre `(netif != NULL) && (addr != NULL)`
*
* Can be used to check if a prefix is assigned to an interface.
*
* @param[in] netif the network interface
* @param[in] addr the prefix to match
*
*
* @note Only available with @ref net_gnrc_ipv6 "gnrc_ipv6".
*
* @return index of an address in gnrc_netif2_t::ipv6_addrs of @p netif that
* best matches @p addr.
* @return -1, if no address on @p netif matches @p addr
*/
int gnrc_netif2_ipv6_addr_match(gnrc_netif2_t *netif,
const ipv6_addr_t *addr);
/**
* @brief Searches for the best address on an interface usable as a source
* address for a given destination address.
*
* @pre `(netif != NULL) && (dst != NULL)`
*
* @param[in] netif the network interface
* @param[in] dst the destination address you want to find a source for.
* @param[in] ll_only only link local addresses qualify
*
* @see [RFC 6724](https://tools.ietf.org/html/rfc6724)
*
* @note Only available with @ref net_gnrc_ipv6 "gnrc_ipv6".
*
* @todo Rule 4 from RFC 6724 is currently not implemented. Has to updated as
* soon as gnrc supports Mobile IP.
*
* @todo Rule 6 from RFC 6724 is currently not implemented. Has to updated as
* soon as gnrc supports flow labels.
*
* @todo Rule 7 from RFC 6724 is currently not implemented. Has to updated as
* soon as gnrc supports temporary addresses.
*
* @return The best source address for a packet addressed to @p dst
* @return NULL, if no matching address can be found on the interface.
*/
ipv6_addr_t *gnrc_netif2_ipv6_addr_best_src(gnrc_netif2_t *netif,
const ipv6_addr_t *dst,
bool ll_only);
/**
* @brief Gets an interface by an address (incl. multicast groups) assigned
* to it.
*
* @pre `addr != NULL`
*
* @param[in] addr an IPv6 address
*
* @return The network interface that has @p addr assigned
* @return NULL, if no interface has @p addr assigned
*/
gnrc_netif2_t *gnrc_netif2_get_by_ipv6_addr(const ipv6_addr_t *addr);
/**
* @brief Gets an interface by an address matching a given prefix best
*
* @param[in] prefix an IPv6 address or prefix
*
* @return The network interface that has an address assigned, that matches
* @p prefix best
* @return NULL, if there is no address on any interface that matches @prefix
*/
gnrc_netif2_t *gnrc_netif2_get_by_prefix(const ipv6_addr_t *prefix);
/**
* @brief Joins interface to an IPv6 multicast group
*
* @pre `(netif != NULL) && (addr != NULL)`
* @pre @p addr is a multicast address (starts with `ff00::/8`)
*
* @param[in,out] netif the network interface
* @param[in] addr the address of the multicast group
*
* @note Only available with @ref net_gnrc_ipv6 "gnrc_ipv6".
*
* @return 0, on success
* @return -ENOMEM, when no space for new addresses is left on the interface
*/
int gnrc_netif2_ipv6_group_join(gnrc_netif2_t *netif,
const ipv6_addr_t *addr);
/**
* @brief Let interface leave from an IPv6 multicast group
*
* @pre `(netif != NULL) && (addr != NULL)`
*
* @param[in,out] netif the network interface
* @param[in] addr the address of the multicast group
*
* @note Only available with @ref net_gnrc_ipv6 "gnrc_ipv6".
*/
void gnrc_netif2_ipv6_group_leave(gnrc_netif2_t *netif,
const ipv6_addr_t *addr);
/**
* @brief Returns the index of @p addr in gnrc_netif2_t::ipv6_groups of @p
* netif
*
* @pre `(netif != NULL) && (addr != NULL)`
*
* Can be used to check if a multicast address is assigned to an interface.
*
* @param[in] netif the network interface
* @param[in] addr the multicast address to check
*
* @note Only available with @ref net_gnrc_ipv6 "gnrc_ipv6".
*
* @return index of @p addr in gnrc_netif2_t::ipv6_groups of @p netif
* @return -1, if @p netif is not in group @p addr
*/
int gnrc_netif2_ipv6_group_idx(gnrc_netif2_t *netif,
const ipv6_addr_t *addr);
/**
* @brief Gets interface identifier (IID) of an interface's link-layer address
*
* @param[in] netif the network interface
* @param[out] eui64 the IID
*
* @return 0, on success
* @return -ENOTSUP, if interface has no link-layer address or if
* gnrc_netif2_t::device_type is not supported.
*/
int gnrc_netif2_ipv6_get_iid(gnrc_netif2_t *netif, eui64_t *eui64);
#endif /* MODULE_GNRC_IPV6 */
/**
* @brief Checks if the interface represents a router according to RFC 4861
*
* @attention Requires prior locking
*
* @param[in] netif the network interface
*
* @see [RFC 4861, section 2.1](https://tools.ietf.org/html/rfc4861#section-2.1)
*
* @return true, if the interface represents a router
* @return false, if the interface does not represent a router
*/
static inline bool gnrc_netif2_is_rtr(const gnrc_netif2_t *netif)
{
return (netif->flags & GNRC_NETIF2_FLAGS_IPV6_FORWARDING);
}
/**
* @brief Checks if the interface is allowed to send out router advertisements
*
* @attention Requires prior locking
*
* @param[in] netif the network interface
*
* @return true, if the interface is allowed to send out router advertisements
* @return false, if the interface is not allowed to send out router
* advertisements
*/
static inline bool gnrc_netif2_is_rtr_adv(const gnrc_netif2_t *netif)
{
return (netif->flags & GNRC_NETIF2_FLAGS_IPV6_RTR_ADV);
}
/**
* @brief Checks if the interface represents a 6Lo node (6LN) according to
* RFC 6775
*
* @attention Requires prior locking
*
* @param[in] netif the network interface
*
* @see [RFC 6775, section 2](https://tools.ietf.org/html/rfc6775#section-2)
*
* @return true, if the interface represents a 6LN
* @return false, if the interface does not represent a 6LN
*/
static inline bool gnrc_netif2_is_6ln(const gnrc_netif2_t *netif)
{
switch (netif->device_type) {
case NETDEV_TYPE_IEEE802154:
case NETDEV_TYPE_CC110X:
case NETDEV_TYPE_NRFMIN:
return true;
default:
return false;
}
}
/**
* @brief Checks if the interface represents a 6Lo router (6LR) according to
* RFC 6775
*
* @attention Requires prior locking
*
* @param[in] netif the network interface
*
* @see [RFC 6775, section 2](https://tools.ietf.org/html/rfc6775#section-2)
*
* @return true, if the interface represents a 6LR
* @return false, if the interface does not represent a 6LR
*/
static inline bool gnrc_netif2_is_6lr(const gnrc_netif2_t *netif)
{
return gnrc_netif2_is_rtr(netif) && gnrc_netif2_is_6ln(netif);
}
/**
* @brief Checks if the interface represents a 6Lo border router (6LBR)
* according to RFC 6775
*
* @attention Requires prior locking
*
* @param[in] netif the network interface
*
* @see [RFC 6775, section 2](https://tools.ietf.org/html/rfc6775#section-2)
*
* @return true, if the interface represents a 6LBR
* @return false, if the interface does not represent a 6LBR
*/
static inline bool gnrc_netif2_is_6lbr(const gnrc_netif2_t *netif)
{
return (netif->flags & GNRC_NETIF2_FLAGS_6LO_ABR) &&
gnrc_netif2_is_6lr(netif);
}
#ifdef __cplusplus
}
#endif
#endif /* NET_GNRC_NETIF2_INTERNAL_H */
/** @} */