Blame view

RIOT/sys/include/net/gnrc/ndp/internal.h 7.74 KB
a752c7ab   elopes   add first test an...
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
  /*
   * Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
   *
   * 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.
   */
  
  /**
   * @defgroup    net_gnrc_ndp_internal Internal functions for neighbor discovery.
   * @ingroup     net_gnrc_ndp
   * @brief       Internal functions for neighbor discovery.
   * @internal
   * @note        Only for use with a neighbor discovery implementations.
   * @{
   *
   * @file
   * @brief   Internal neighbor discovery functions for neighbor discovery.
   *
   * @author  Martine Lenders <mlenders@inf.fu-berlin.de>
   */
  #ifndef NET_GNRC_NDP_INTERNAL_H
  #define NET_GNRC_NDP_INTERNAL_H
  
  #include "kernel_types.h"
  #include "net/gnrc/ipv6/nc.h"
  #include "net/ipv6/addr.h"
  #include "net/ipv6/hdr.h"
  #include "net/ndp.h"
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  /**
   * @brief   Get best match from default router list.
   *
   * @internal
   *
   * @see <a href="https://tools.ietf.org/html/rfc4861#section-6.3.6">
   *          RFC 4861, section 6.3.6
   *      </a>
   *
   * @return  Address to a default router.
   * @return  NULL, if the default router list is empty.
   */
  ipv6_addr_t *gnrc_ndp_internal_default_router(void);
  
  /**
   * @brief   Sets state of a neighbor cache entry and triggers required actions.
   *
   * @internal
   *
   * @param[in] nc_entry  A neighbor cache entry.
   * @param[in] state     The new state for the neighbor cache entry.
   */
  void gnrc_ndp_internal_set_state(gnrc_ipv6_nc_t *nc_entry, uint8_t state);
  
  /**
   * @brief   Send precompiled neighbor solicitation.
   *
   * @internal
   *
   * @param[in] iface Interface to send over. May not be KERNEL_PID_UNDEF.
   * @param[in] src   Source address for the neighbor solicitation. Will be chosen from the
   *                  interface according to @p dst, if NULL.
   * @param[in] tgt   Target address for the neighbor solicitation. May not be
   *                  NULL.
   * @param[in] dst   Destination address for neighbor solicitation. May not be
   *                  NULL.
   */
  void gnrc_ndp_internal_send_nbr_sol(kernel_pid_t iface, ipv6_addr_t *src, ipv6_addr_t *tgt,
                                      ipv6_addr_t *dst);
  
  /**
   * @brief   Send precompiled neighbor advertisement.
   *
   * @internal
   *
   * @param[in] iface         Interface to send over. May not be KERNEL_PID_UNDEF.
   * @param[in] tgt           Target address for the neighbor solicitation. May
   *                          not be NULL.
   * @param[in] dst           Destination address for neighbor solicitation. May
   *                          not be NULL.
   * @param[in] supply_tl2a   Add target link-layer address option to neighbor
   *                          advertisement if link-layer has addresses.
   * @param[in] ext_opts      External options for the neighbor advertisement. Leave NULL for none.
   *                          **Warning:** these are not tested if they are suitable for a
   *                          neighbor advertisement so be sure to check that.
   *                          **Will be released** in an error case.
   */
  void gnrc_ndp_internal_send_nbr_adv(kernel_pid_t iface, ipv6_addr_t *tgt, ipv6_addr_t *dst,
                                      bool supply_tl2a, gnrc_pktsnip_t *ext_opts);
  
  /**
   * @brief   Send precompiled router solicitation to @p dst.
   *
   * @internal
   *
   * @param[in] iface Interface to send over. May not be KERNEL_PID_UNDEF.
   * @param[in] dst   Destination for the router solicitation. ff02::2 if NULL.
   */
  void gnrc_ndp_internal_send_rtr_sol(kernel_pid_t iface, ipv6_addr_t *dst);
  
  #if (defined(MODULE_GNRC_NDP_ROUTER) || defined(MODULE_GNRC_SIXLOWPAN_ND_ROUTER))
  /**
   * @brief   Handles received router solicitations.
   *
   * @param[in] iface         Interface to send over. May not be KERNEL_PID_UNDEF.
   * @param[in] src           Source address for the router advertisement. May be NULL to be determined
   *                          by source address selection (:: if no @p iface has no address).
   * @param[in] dst           Destination address for router advertisement.
   *                          @ref IPV6_ADDR_ALL_NODES_LINK_LOCAL if NULL.
   * @param[in] fin           This is part of the router's final batch of router advertisements
   *                          before ceising to be a router (set's router lifetime field to 0).
   */
  void gnrc_ndp_internal_send_rtr_adv(kernel_pid_t iface, ipv6_addr_t *src,
                                      ipv6_addr_t *dst, bool fin);
  #else
  /**
   * @brief   A host *must not* send router advertisements at any time.
   *
   * This macro is primarily an optimization to not go into the function defined
   * above.
   */
  #define gnrc_ndp_internal_send_rtr_adv(iface, src, dst, fin)
  #endif
  
  /**
   * @brief   Handles a SL2A option.
   *
   * @param[in] pkt           Packet the option was received in.
   * @param[in] ipv6          IPv6 header of @p pkt
   * @param[in] icmpv6_type   ICMPv6 type of the message carrying the option.
   * @param[in] tl2a_opt      The TL2A option.
   * @param[out] l2addr       The L2 address carried in the SL2A option.
   *
   * @return  length of the L2 address, on success.
   * @return  -EINVAL, if SL2A was not valid.
   * @return  -ENOTSUP, if node should silently ignore the option.
   */
  int gnrc_ndp_internal_sl2a_opt_handle(gnrc_pktsnip_t *pkt, ipv6_hdr_t *ipv6, uint8_t icmpv6_type,
                                        ndp_opt_t *sl2a_opt, uint8_t *l2addr);
  
  /**
   * @brief   Handles a TL2A option.
   *
   * @param[in] pkt           Packet the option was received in.
   * @param[in] ipv6          IPv6 header of @p pkt
   * @param[in] icmpv6_type   ICMPv6 type of the message carrying the option.
   * @param[in] tl2a_opt      The TL2A option.
   * @param[out] l2addr       The L2 address carried in the TL2A option.
   *
   * @return  length of the L2 address, on success.
   * @return  -EINVAL, if TL2A was not valid.
   * @return  -ENOTSUP, if node should silently ignore the option.
   */
  int gnrc_ndp_internal_tl2a_opt_handle(gnrc_pktsnip_t *pkt, ipv6_hdr_t *ipv6,
                                        uint8_t icmpv6_type, ndp_opt_t *tl2a_opt,
                                        uint8_t *l2addr);
  
  /**
   * @brief   Handles a MTU option.
   *
   * @internal
   *
   * @param[in] iface         Interface the MTU option was received on.
   * @param[in] icmpv6_type   ICMPv6 type of the message carrying the option.
   * @param[in] mtu_opt       A MTU option.
   *
   * @return  true, on success (or if the node should silently ignore the option).
   * @return  false, if MTU option was not valid.
   */
  bool gnrc_ndp_internal_mtu_opt_handle(kernel_pid_t iface, uint8_t icmpv6_type,
                                        ndp_opt_mtu_t *mtu_opt);
  
  /**
   * @brief   Handles a PI option.
   *
   * @internal
   *
   * @param[in] iface         Interface the PI option was received on.
   * @param[in] icmpv6_type   ICMPv6 type of the message carrying the option.
   * @param[in] pi_opt        A PI option.
   *
   * @return  true, on success (or if the node should silently ignore the option).
   * @return  false, if PIO was not valid.
   */
  bool gnrc_ndp_internal_pi_opt_handle(kernel_pid_t iface, uint8_t icmpv6_type,
                                       ndp_opt_pi_t *pi_opt);
  
  /**
   * @brief   Resets the gnrc_ipv6_nc_t::nbr_sol_timer.
   *
   * @internal
   *
   * @param[in] nc_entry      A neighbor cache entry.
   * @param[in] delay         The delay when the timer should fire.
   * @param[in] type          The msg_t::type for the timer.
   * @param[in] pid           The pid of the receiver thread of the msg_t
   */
  static inline void gnrc_ndp_internal_reset_nbr_sol_timer(gnrc_ipv6_nc_t *nc_entry, uint32_t delay,
                                                           uint16_t type, kernel_pid_t pid)
  {
      xtimer_remove(&nc_entry->nbr_sol_timer);
      nc_entry->nbr_sol_msg.type = type;
      xtimer_set_msg(&nc_entry->nbr_sol_timer, delay, &nc_entry->nbr_sol_msg, pid);
  }
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* NET_GNRC_NDP_INTERNAL_H */
  /** @} */