STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
nd6.c
Go to the documentation of this file.
1 
9 /*
10  * Copyright (c) 2010 Inico Technologies Ltd.
11  * All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without modification,
14  * are permitted provided that the following conditions are met:
15  *
16  * 1. Redistributions of source code must retain the above copyright notice,
17  * this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright notice,
19  * this list of conditions and the following disclaimer in the documentation
20  * and/or other materials provided with the distribution.
21  * 3. The name of the author may not be used to endorse or promote products
22  * derived from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33  * OF SUCH DAMAGE.
34  *
35  * This file is part of the lwIP TCP/IP stack.
36  *
37  * Author: Ivan Delamer <delamer@inicotech.com>
38  *
39  *
40  * Please coordinate changes and requests with Ivan Delamer
41  * <delamer@inicotech.com>
42  */
43 
44 #include "lwip/opt.h"
45 
46 #if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */
47 
48 #include "lwip/nd6.h"
49 #include "lwip/pbuf.h"
50 #include "lwip/mem.h"
51 #include "lwip/memp.h"
52 #include "lwip/ip6.h"
53 #include "lwip/ip6_addr.h"
54 #include "lwip/inet_chksum.h"
55 #include "lwip/netif.h"
56 #include "lwip/icmp6.h"
57 #include "lwip/mld6.h"
58 #include "lwip/ip.h"
59 #include "lwip/stats.h"
60 
61 #include <string.h>
62 
63 
64 /* Router tables. */
65 struct nd6_neighbor_cache_entry neighbor_cache[LWIP_ND6_NUM_NEIGHBORS];
66 struct nd6_destination_cache_entry destination_cache[LWIP_ND6_NUM_DESTINATIONS];
67 struct nd6_prefix_list_entry prefix_list[LWIP_ND6_NUM_PREFIXES];
68 struct nd6_router_list_entry default_router_list[LWIP_ND6_NUM_ROUTERS];
69 
70 /* Default values, can be updated by a RA message. */
71 u32_t reachable_time = LWIP_ND6_REACHABLE_TIME;
72 u32_t retrans_timer = LWIP_ND6_RETRANS_TIMER; /* TODO implement this value in timer */
73 
74 /* Index for cache entries. */
75 static u8_t nd6_cached_neighbor_index;
76 static u8_t nd6_cached_destination_index;
77 
78 /* Multicast address holder. */
79 static ip6_addr_t multicast_address;
80 
81 /* Static buffer to parse RA packet options (size of a prefix option, biggest option) */
82 static u8_t nd6_ra_buffer[sizeof(struct prefix_option)];
83 
84 /* Forward declarations. */
85 static s8_t nd6_find_neighbor_cache_entry(const ip6_addr_t * ip6addr);
86 static s8_t nd6_new_neighbor_cache_entry(void);
87 static void nd6_free_neighbor_cache_entry(s8_t i);
88 static s8_t nd6_find_destination_cache_entry(const ip6_addr_t * ip6addr);
89 static s8_t nd6_new_destination_cache_entry(void);
90 static s8_t nd6_is_prefix_in_netif(const ip6_addr_t * ip6addr, struct netif * netif);
91 static s8_t nd6_get_router(const ip6_addr_t * router_addr, struct netif * netif);
92 static s8_t nd6_new_router(const ip6_addr_t * router_addr, struct netif * netif);
93 static s8_t nd6_get_onlink_prefix(ip6_addr_t * prefix, struct netif * netif);
94 static s8_t nd6_new_onlink_prefix(ip6_addr_t * prefix, struct netif * netif);
95 
96 #define ND6_SEND_FLAG_MULTICAST_DEST 0x01
97 #define ND6_SEND_FLAG_ALLNODES_DEST 0x02
98 static void nd6_send_ns(struct netif * netif, const ip6_addr_t * target_addr, u8_t flags);
99 static void nd6_send_na(struct netif * netif, const ip6_addr_t * target_addr, u8_t flags);
100 #if LWIP_IPV6_SEND_ROUTER_SOLICIT
101 static err_t nd6_send_rs(struct netif * netif);
102 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
103 
104 #if LWIP_ND6_QUEUEING
105 static void nd6_free_q(struct nd6_q_entry *q);
106 #else /* LWIP_ND6_QUEUEING */
107 #define nd6_free_q(q) pbuf_free(q)
108 #endif /* LWIP_ND6_QUEUEING */
109 static void nd6_send_q(s8_t i);
110 
111 
118 void
119 nd6_input(struct pbuf *p, struct netif *inp)
120 {
121  u8_t msg_type;
122  s8_t i;
123 
124  ND6_STATS_INC(nd6.recv);
125 
126  msg_type = *((u8_t *)p->payload);
127  switch (msg_type) {
128  case ICMP6_TYPE_NA: /* Neighbor Advertisement. */
129  {
130  struct na_header * na_hdr;
131  struct lladdr_option * lladdr_opt;
132 
133  /* Check that na header fits in packet. */
134  if (p->len < (sizeof(struct na_header))) {
135  /* TODO debug message */
136  pbuf_free(p);
137  ND6_STATS_INC(nd6.lenerr);
138  ND6_STATS_INC(nd6.drop);
139  return;
140  }
141 
142  na_hdr = (struct na_header *)p->payload;
143 
144  /* Unsolicited NA?*/
145  if (ip6_addr_ismulticast(ip6_current_dest_addr())) {
146  /* This is an unsolicited NA.
147  * link-layer changed?
148  * part of DAD mechanism? */
149 
150  /* Check that link-layer address option also fits in packet. */
151  if (p->len < (sizeof(struct na_header) + 2)) {
152  /* TODO debug message */
153  pbuf_free(p);
154  ND6_STATS_INC(nd6.lenerr);
155  ND6_STATS_INC(nd6.drop);
156  return;
157  }
158 
159  lladdr_opt = (struct lladdr_option *)((u8_t*)p->payload + sizeof(struct na_header));
160 
161  if (p->len < (sizeof(struct na_header) + (lladdr_opt->length << 3))) {
162  /* TODO debug message */
163  pbuf_free(p);
164  ND6_STATS_INC(nd6.lenerr);
165  ND6_STATS_INC(nd6.drop);
166  return;
167  }
168 
169  /* Override ip6_current_dest_addr() so that we have an aligned copy. */
170  ip6_addr_set(ip6_current_dest_addr(), &(na_hdr->target_address));
171 
172 #if LWIP_IPV6_DUP_DETECT_ATTEMPTS
173  /* If the target address matches this netif, it is a DAD response. */
174  for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
175  if (!ip6_addr_isinvalid(netif_ip6_addr_state(inp, i)) &&
176  ip6_addr_cmp(ip6_current_dest_addr(), netif_ip6_addr(inp, i))) {
177  /* We are using a duplicate address. */
178  netif_ip6_addr_set_state(inp, i, IP6_ADDR_INVALID);
179 
180 #if LWIP_IPV6_MLD
181  /* Leave solicited node multicast group. */
182  ip6_addr_set_solicitednode(&multicast_address, netif_ip6_addr(inp, i)->addr[3]);
183  mld6_leavegroup(netif_ip6_addr(inp, i), &multicast_address);
184 #endif /* LWIP_IPV6_MLD */
185 
186 #if LWIP_IPV6_AUTOCONFIG
187  /* Check to see if this address was autoconfigured. */
188  if (!ip6_addr_islinklocal(ip6_current_dest_addr())) {
189  i = nd6_get_onlink_prefix(ip6_current_dest_addr(), inp);
190  if (i >= 0) {
191  /* Mark this prefix as duplicate, so that we don't use it
192  * to generate this address again. */
193  prefix_list[i].flags |= ND6_PREFIX_AUTOCONFIG_ADDRESS_DUPLICATE;
194  }
195  }
196 #endif /* LWIP_IPV6_AUTOCONFIG */
197 
198  pbuf_free(p);
199  return;
200  }
201  }
202 #endif /* LWIP_IPV6_DUP_DETECT_ATTEMPTS */
203 
204  /* This is an unsolicited NA, most likely there was a LLADDR change. */
205  i = nd6_find_neighbor_cache_entry(ip6_current_dest_addr());
206  if (i >= 0) {
207  if (na_hdr->flags & ND6_FLAG_OVERRIDE) {
208  MEMCPY(neighbor_cache[i].lladdr, lladdr_opt->addr, inp->hwaddr_len);
209  }
210  }
211  } else {
212  /* This is a solicited NA.
213  * neighbor address resolution response?
214  * neighbor unreachability detection response? */
215 
216  /* Override ip6_current_dest_addr() so that we have an aligned copy. */
217  ip6_addr_set(ip6_current_dest_addr(), &(na_hdr->target_address));
218 
219  /* Find the cache entry corresponding to this na. */
220  i = nd6_find_neighbor_cache_entry(ip6_current_dest_addr());
221  if (i < 0) {
222  /* We no longer care about this target address. drop it. */
223  pbuf_free(p);
224  return;
225  }
226 
227  /* Update cache entry. */
228  neighbor_cache[i].netif = inp;
229  neighbor_cache[i].counter.reachable_time = reachable_time;
230  if ((na_hdr->flags & ND6_FLAG_OVERRIDE) ||
231  (neighbor_cache[i].state == ND6_INCOMPLETE)) {
232  /* Check that link-layer address option also fits in packet. */
233  if (p->len < (sizeof(struct na_header) + 2)) {
234  /* TODO debug message */
235  pbuf_free(p);
236  ND6_STATS_INC(nd6.lenerr);
237  ND6_STATS_INC(nd6.drop);
238  return;
239  }
240 
241  lladdr_opt = (struct lladdr_option *)((u8_t*)p->payload + sizeof(struct na_header));
242 
243  if (p->len < (sizeof(struct na_header) + (lladdr_opt->length << 3))) {
244  /* TODO debug message */
245  pbuf_free(p);
246  ND6_STATS_INC(nd6.lenerr);
247  ND6_STATS_INC(nd6.drop);
248  return;
249  }
250 
251  MEMCPY(neighbor_cache[i].lladdr, lladdr_opt->addr, inp->hwaddr_len);
252  }
253  neighbor_cache[i].state = ND6_REACHABLE;
254 
255  /* Send queued packets, if any. */
256  if (neighbor_cache[i].q != NULL) {
257  nd6_send_q(i);
258  }
259  }
260 
261  break; /* ICMP6_TYPE_NA */
262  }
263  case ICMP6_TYPE_NS: /* Neighbor solicitation. */
264  {
265  struct ns_header * ns_hdr;
266  struct lladdr_option * lladdr_opt;
267  u8_t accepted;
268 
269  /* Check that ns header fits in packet. */
270  if (p->len < sizeof(struct ns_header)) {
271  /* TODO debug message */
272  pbuf_free(p);
273  ND6_STATS_INC(nd6.lenerr);
274  ND6_STATS_INC(nd6.drop);
275  return;
276  }
277 
278  ns_hdr = (struct ns_header *)p->payload;
279 
280  /* Check if there is a link-layer address provided. Only point to it if in this buffer. */
281  if (p->len >= (sizeof(struct ns_header) + 2)) {
282  lladdr_opt = (struct lladdr_option *)((u8_t*)p->payload + sizeof(struct ns_header));
283  if (p->len < (sizeof(struct ns_header) + (lladdr_opt->length << 3))) {
284  lladdr_opt = NULL;
285  }
286  } else {
287  lladdr_opt = NULL;
288  }
289 
290  /* Check if the target address is configured on the receiving netif. */
291  accepted = 0;
292  for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; ++i) {
293  if ((ip6_addr_isvalid(netif_ip6_addr_state(inp, i)) ||
294  (ip6_addr_istentative(netif_ip6_addr_state(inp, i)) &&
295  ip6_addr_isany(ip6_current_src_addr()))) &&
296  ip6_addr_cmp(&(ns_hdr->target_address), netif_ip6_addr(inp, i))) {
297  accepted = 1;
298  break;
299  }
300  }
301 
302  /* NS not for us? */
303  if (!accepted) {
304  pbuf_free(p);
305  return;
306  }
307 
308  /* Check for ANY address in src (DAD algorithm). */
309  if (ip6_addr_isany(ip6_current_src_addr())) {
310  /* Sender is validating this address. */
311  for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; ++i) {
312  if (!ip6_addr_isinvalid(netif_ip6_addr_state(inp, i)) &&
313  ip6_addr_cmp(&(ns_hdr->target_address), netif_ip6_addr(inp, i))) {
314  /* Send a NA back so that the sender does not use this address. */
315  nd6_send_na(inp, netif_ip6_addr(inp, i), ND6_FLAG_OVERRIDE | ND6_SEND_FLAG_ALLNODES_DEST);
316  if (ip6_addr_istentative(netif_ip6_addr_state(inp, i))) {
317  /* We shouldn't use this address either. */
318  netif_ip6_addr_set_state(inp, i, IP6_ADDR_INVALID);
319  }
320  }
321  }
322  } else {
323  /* Sender is trying to resolve our address. */
324  /* Verify that they included their own link-layer address. */
325  if (lladdr_opt == NULL) {
326  /* Not a valid message. */
327  pbuf_free(p);
328  ND6_STATS_INC(nd6.proterr);
329  ND6_STATS_INC(nd6.drop);
330  return;
331  }
332 
333  i = nd6_find_neighbor_cache_entry(ip6_current_src_addr());
334  if (i>= 0) {
335  /* We already have a record for the solicitor. */
336  if (neighbor_cache[i].state == ND6_INCOMPLETE) {
337  neighbor_cache[i].netif = inp;
338  MEMCPY(neighbor_cache[i].lladdr, lladdr_opt->addr, inp->hwaddr_len);
339 
340  /* Delay probe in case we get confirmation of reachability from upper layer (TCP). */
341  neighbor_cache[i].state = ND6_DELAY;
342  neighbor_cache[i].counter.delay_time = LWIP_ND6_DELAY_FIRST_PROBE_TIME;
343  }
344  } else {
345  /* Add their IPv6 address and link-layer address to neighbor cache.
346  * We will need it at least to send a unicast NA message, but most
347  * likely we will also be communicating with this node soon. */
348  i = nd6_new_neighbor_cache_entry();
349  if (i < 0) {
350  /* We couldn't assign a cache entry for this neighbor.
351  * we won't be able to reply. drop it. */
352  pbuf_free(p);
353  ND6_STATS_INC(nd6.memerr);
354  return;
355  }
356  neighbor_cache[i].netif = inp;
357  MEMCPY(neighbor_cache[i].lladdr, lladdr_opt->addr, inp->hwaddr_len);
358  ip6_addr_set(&(neighbor_cache[i].next_hop_address), ip6_current_src_addr());
359 
360  /* Receiving a message does not prove reachability: only in one direction.
361  * Delay probe in case we get confirmation of reachability from upper layer (TCP). */
362  neighbor_cache[i].state = ND6_DELAY;
363  neighbor_cache[i].counter.delay_time = LWIP_ND6_DELAY_FIRST_PROBE_TIME;
364  }
365 
366  /* Override ip6_current_dest_addr() so that we have an aligned copy. */
367  ip6_addr_set(ip6_current_dest_addr(), &(ns_hdr->target_address));
368 
369  /* Send back a NA for us. Allocate the reply pbuf. */
370  nd6_send_na(inp, ip6_current_dest_addr(), ND6_FLAG_SOLICITED | ND6_FLAG_OVERRIDE);
371  }
372 
373  break; /* ICMP6_TYPE_NS */
374  }
375  case ICMP6_TYPE_RA: /* Router Advertisement. */
376  {
377  struct ra_header * ra_hdr;
378  u8_t * buffer; /* Used to copy options. */
379  u16_t offset;
380 
381  /* Check that RA header fits in packet. */
382  if (p->len < sizeof(struct ra_header)) {
383  /* TODO debug message */
384  pbuf_free(p);
385  ND6_STATS_INC(nd6.lenerr);
386  ND6_STATS_INC(nd6.drop);
387  return;
388  }
389 
390  ra_hdr = (struct ra_header *)p->payload;
391 
392  /* If we are sending RS messages, stop. */
394  /* ensure at least one solicitation is sent */
395  if ((inp->rs_count < LWIP_ND6_MAX_MULTICAST_SOLICIT) ||
396  (nd6_send_rs(inp) == ERR_OK)) {
397  inp->rs_count = 0;
398  }
399 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
400 
401  /* Get the matching default router entry. */
402  i = nd6_get_router(ip6_current_src_addr(), inp);
403  if (i < 0) {
404  /* Create a new router entry. */
405  i = nd6_new_router(ip6_current_src_addr(), inp);
406  }
407 
408  if (i < 0) {
409  /* Could not create a new router entry. */
410  pbuf_free(p);
411  ND6_STATS_INC(nd6.memerr);
412  return;
413  }
414 
415  /* Re-set invalidation timer. */
416  default_router_list[i].invalidation_timer = htons(ra_hdr->router_lifetime);
417 
418  /* Re-set default timer values. */
419 #if LWIP_ND6_ALLOW_RA_UPDATES
420  if (ra_hdr->retrans_timer > 0) {
421  retrans_timer = htonl(ra_hdr->retrans_timer);
422  }
423  if (ra_hdr->reachable_time > 0) {
424  reachable_time = htonl(ra_hdr->reachable_time);
425  }
426 #endif /* LWIP_ND6_ALLOW_RA_UPDATES */
427 
428  /* TODO set default hop limit... */
429  /* ra_hdr->current_hop_limit;*/
430 
431  /* Update flags in local entry (incl. preference). */
432  default_router_list[i].flags = ra_hdr->flags;
433 
434  /* Offset to options. */
435  offset = sizeof(struct ra_header);
436 
437  /* Process each option. */
438  while ((p->tot_len - offset) > 0) {
439  if (p->len == p->tot_len) {
440  /* no need to copy from contiguous pbuf */
441  buffer = &((u8_t*)p->payload)[offset];
442  } else {
443  buffer = nd6_ra_buffer;
444  pbuf_copy_partial(p, buffer, sizeof(struct prefix_option), offset);
445  }
446  switch (buffer[0]) {
447  case ND6_OPTION_TYPE_SOURCE_LLADDR:
448  {
449  struct lladdr_option * lladdr_opt;
450  lladdr_opt = (struct lladdr_option *)buffer;
451  if ((default_router_list[i].neighbor_entry != NULL) &&
452  (default_router_list[i].neighbor_entry->state == ND6_INCOMPLETE)) {
453  SMEMCPY(default_router_list[i].neighbor_entry->lladdr, lladdr_opt->addr, inp->hwaddr_len);
454  default_router_list[i].neighbor_entry->state = ND6_REACHABLE;
455  default_router_list[i].neighbor_entry->counter.reachable_time = reachable_time;
456  }
457  break;
458  }
459  case ND6_OPTION_TYPE_MTU:
460  {
461  struct mtu_option * mtu_opt;
462  mtu_opt = (struct mtu_option *)buffer;
463  if (htonl(mtu_opt->mtu) >= 1280) {
464 #if LWIP_ND6_ALLOW_RA_UPDATES
465  inp->mtu = (u16_t)htonl(mtu_opt->mtu);
466 #endif /* LWIP_ND6_ALLOW_RA_UPDATES */
467  }
468  break;
469  }
470  case ND6_OPTION_TYPE_PREFIX_INFO:
471  {
472  struct prefix_option * prefix_opt;
473  prefix_opt = (struct prefix_option *)buffer;
474 
475  if (prefix_opt->flags & ND6_PREFIX_FLAG_ON_LINK) {
476  /* Add to on-link prefix list. */
477  s8_t prefix;
478 
479  /* Get a memory-aligned copy of the prefix. */
480  ip6_addr_set(ip6_current_dest_addr(), &(prefix_opt->prefix));
481 
482  /* find cache entry for this prefix. */
483  prefix = nd6_get_onlink_prefix(ip6_current_dest_addr(), inp);
484  if (prefix < 0) {
485  /* Create a new cache entry. */
486  prefix = nd6_new_onlink_prefix(ip6_current_dest_addr(), inp);
487  }
488  if (prefix >= 0) {
489  prefix_list[prefix].invalidation_timer = htonl(prefix_opt->valid_lifetime);
490 
491 #if LWIP_IPV6_AUTOCONFIG
492  if (prefix_opt->flags & ND6_PREFIX_FLAG_AUTONOMOUS) {
493  /* Mark prefix as autonomous, so that address autoconfiguration can take place.
494  * Only OR flag, so that we don't over-write other flags (such as ADDRESS_DUPLICATE)*/
495  prefix_list[prefix].flags |= ND6_PREFIX_AUTOCONFIG_AUTONOMOUS;
496  }
497 #endif /* LWIP_IPV6_AUTOCONFIG */
498  }
499  }
500 
501  break;
502  }
503  case ND6_OPTION_TYPE_ROUTE_INFO:
504  /* TODO implement preferred routes.
505  struct route_option * route_opt;
506  route_opt = (struct route_option *)buffer;*/
507 
508  break;
509  default:
510  /* Unrecognized option, abort. */
511  ND6_STATS_INC(nd6.proterr);
512  break;
513  }
514  offset += 8 * ((u16_t)buffer[1]);
515  }
516 
517  break; /* ICMP6_TYPE_RA */
518  }
519  case ICMP6_TYPE_RD: /* Redirect */
520  {
521  struct redirect_header * redir_hdr;
522  struct lladdr_option * lladdr_opt;
523 
524  /* Check that Redir header fits in packet. */
525  if (p->len < sizeof(struct redirect_header)) {
526  /* TODO debug message */
527  pbuf_free(p);
528  ND6_STATS_INC(nd6.lenerr);
529  ND6_STATS_INC(nd6.drop);
530  return;
531  }
532 
533  redir_hdr = (struct redirect_header *)p->payload;
534 
535  if (p->len >= (sizeof(struct redirect_header) + 2)) {
536  lladdr_opt = (struct lladdr_option *)((u8_t*)p->payload + sizeof(struct redirect_header));
537  if (p->len < (sizeof(struct redirect_header) + (lladdr_opt->length << 3))) {
538  lladdr_opt = NULL;
539  }
540  } else {
541  lladdr_opt = NULL;
542  }
543 
544  /* Copy original destination address to current source address, to have an aligned copy. */
545  ip6_addr_set(ip6_current_src_addr(), &(redir_hdr->destination_address));
546 
547  /* Find dest address in cache */
548  i = nd6_find_destination_cache_entry(ip6_current_src_addr());
549  if (i < 0) {
550  /* Destination not in cache, drop packet. */
551  pbuf_free(p);
552  return;
553  }
554 
555  /* Set the new target address. */
556  ip6_addr_set(&(destination_cache[i].next_hop_addr), &(redir_hdr->target_address));
557 
558  /* If Link-layer address of other router is given, try to add to neighbor cache. */
559  if (lladdr_opt != NULL) {
560  if (lladdr_opt->type == ND6_OPTION_TYPE_TARGET_LLADDR) {
561  /* Copy target address to current source address, to have an aligned copy. */
562  ip6_addr_set(ip6_current_src_addr(), &(redir_hdr->target_address));
563 
564  i = nd6_find_neighbor_cache_entry(ip6_current_src_addr());
565  if (i < 0) {
566  i = nd6_new_neighbor_cache_entry();
567  if (i >= 0) {
568  neighbor_cache[i].netif = inp;
569  MEMCPY(neighbor_cache[i].lladdr, lladdr_opt->addr, inp->hwaddr_len);
570  ip6_addr_set(&(neighbor_cache[i].next_hop_address), ip6_current_src_addr());
571 
572  /* Receiving a message does not prove reachability: only in one direction.
573  * Delay probe in case we get confirmation of reachability from upper layer (TCP). */
574  neighbor_cache[i].state = ND6_DELAY;
575  neighbor_cache[i].counter.delay_time = LWIP_ND6_DELAY_FIRST_PROBE_TIME;
576  }
577  }
578  if (i >= 0) {
579  if (neighbor_cache[i].state == ND6_INCOMPLETE) {
580  MEMCPY(neighbor_cache[i].lladdr, lladdr_opt->addr, inp->hwaddr_len);
581  /* Receiving a message does not prove reachability: only in one direction.
582  * Delay probe in case we get confirmation of reachability from upper layer (TCP). */
583  neighbor_cache[i].state = ND6_DELAY;
584  neighbor_cache[i].counter.delay_time = LWIP_ND6_DELAY_FIRST_PROBE_TIME;
585  }
586  }
587  }
588  }
589  break; /* ICMP6_TYPE_RD */
590  }
591  case ICMP6_TYPE_PTB: /* Packet too big */
592  {
593  struct icmp6_hdr *icmp6hdr; /* Packet too big message */
594  struct ip6_hdr * ip6hdr; /* IPv6 header of the packet which caused the error */
595  u32_t pmtu;
596 
597  /* Check that ICMPv6 header + IPv6 header fit in payload */
598  if (p->len < (sizeof(struct icmp6_hdr) + IP6_HLEN)) {
599  /* drop short packets */
600  pbuf_free(p);
601  ND6_STATS_INC(nd6.lenerr);
602  ND6_STATS_INC(nd6.drop);
603  return;
604  }
605 
606  icmp6hdr = (struct icmp6_hdr *)p->payload;
607  ip6hdr = (struct ip6_hdr *)((u8_t*)p->payload + sizeof(struct icmp6_hdr));
608 
609  /* Copy original destination address to current source address, to have an aligned copy. */
610  ip6_addr_set(ip6_current_src_addr(), &(ip6hdr->dest));
611 
612  /* Look for entry in destination cache. */
613  i = nd6_find_destination_cache_entry(ip6_current_src_addr());
614  if (i < 0) {
615  /* Destination not in cache, drop packet. */
616  pbuf_free(p);
617  return;
618  }
619 
620  /* Change the Path MTU. */
621  pmtu = htonl(icmp6hdr->data);
622  destination_cache[i].pmtu = (u16_t)LWIP_MIN(pmtu, 0xFFFF);
623 
624  break; /* ICMP6_TYPE_PTB */
625  }
626 
627  default:
628  ND6_STATS_INC(nd6.proterr);
629  ND6_STATS_INC(nd6.drop);
630  break; /* default */
631  }
632 
633  pbuf_free(p);
634 }
635 
636 
646 void
647 nd6_tmr(void)
648 {
649  s8_t i;
650  struct netif * netif;
651 
652  /* Process neighbor entries. */
653  for (i = 0; i < LWIP_ND6_NUM_NEIGHBORS; i++) {
654  switch (neighbor_cache[i].state) {
655  case ND6_INCOMPLETE:
656  if (neighbor_cache[i].counter.probes_sent >= LWIP_ND6_MAX_MULTICAST_SOLICIT) {
657  /* Retries exceeded. */
658  nd6_free_neighbor_cache_entry(i);
659  } else {
660  /* Send a NS for this entry. */
661  neighbor_cache[i].counter.probes_sent++;
662  nd6_send_ns(neighbor_cache[i].netif, &(neighbor_cache[i].next_hop_address), ND6_SEND_FLAG_MULTICAST_DEST);
663  }
664  break;
665  case ND6_REACHABLE:
666  /* Send queued packets, if any are left. Should have been sent already. */
667  if (neighbor_cache[i].q != NULL) {
668  nd6_send_q(i);
669  }
670  if (neighbor_cache[i].counter.reachable_time <= ND6_TMR_INTERVAL) {
671  /* Change to stale state. */
672  neighbor_cache[i].state = ND6_STALE;
673  neighbor_cache[i].counter.stale_time = 0;
674  } else {
675  neighbor_cache[i].counter.reachable_time -= ND6_TMR_INTERVAL;
676  }
677  break;
678  case ND6_STALE:
679  neighbor_cache[i].counter.stale_time += ND6_TMR_INTERVAL;
680  break;
681  case ND6_DELAY:
682  if (neighbor_cache[i].counter.delay_time <= ND6_TMR_INTERVAL) {
683  /* Change to PROBE state. */
684  neighbor_cache[i].state = ND6_PROBE;
685  neighbor_cache[i].counter.probes_sent = 0;
686  } else {
687  neighbor_cache[i].counter.delay_time -= ND6_TMR_INTERVAL;
688  }
689  break;
690  case ND6_PROBE:
691  if (neighbor_cache[i].counter.probes_sent >= LWIP_ND6_MAX_MULTICAST_SOLICIT) {
692  /* Retries exceeded. */
693  nd6_free_neighbor_cache_entry(i);
694  } else {
695  /* Send a NS for this entry. */
696  neighbor_cache[i].counter.probes_sent++;
697  nd6_send_ns(neighbor_cache[i].netif, &(neighbor_cache[i].next_hop_address), 0);
698  }
699  break;
700  case ND6_NO_ENTRY:
701  default:
702  /* Do nothing. */
703  break;
704  }
705  }
706 
707  /* Process destination entries. */
708  for (i = 0; i < LWIP_ND6_NUM_DESTINATIONS; i++) {
709  destination_cache[i].age++;
710  }
711 
712  /* Process router entries. */
713  for (i = 0; i < LWIP_ND6_NUM_ROUTERS; i++) {
714  if (default_router_list[i].neighbor_entry != NULL) {
715  /* Active entry. */
716  if (default_router_list[i].invalidation_timer > 0) {
717  default_router_list[i].invalidation_timer -= ND6_TMR_INTERVAL / 1000;
718  }
719  if (default_router_list[i].invalidation_timer < ND6_TMR_INTERVAL / 1000) {
720  /* Less than 1 second remaining. Clear this entry. */
721  default_router_list[i].neighbor_entry->isrouter = 0;
722  default_router_list[i].neighbor_entry = NULL;
723  default_router_list[i].invalidation_timer = 0;
724  default_router_list[i].flags = 0;
725  }
726  }
727  }
728 
729  /* Process prefix entries. */
730  for (i = 0; i < LWIP_ND6_NUM_PREFIXES; i++) {
731  if (prefix_list[i].netif != NULL) {
732  if (prefix_list[i].invalidation_timer < ND6_TMR_INTERVAL / 1000) {
733  /* Entry timed out, remove it */
734  prefix_list[i].invalidation_timer = 0;
735 
736 #if LWIP_IPV6_AUTOCONFIG
737  /* If any addresses were configured with this prefix, remove them */
738  if (prefix_list[i].flags & ND6_PREFIX_AUTOCONFIG_ADDRESS_GENERATED)
739  {
740  s8_t j;
741 
742  for (j = 1; j < LWIP_IPV6_NUM_ADDRESSES; j++) {
743  if ((netif_ip6_addr_state(prefix_list[i].netif, j) != IP6_ADDR_INVALID) &&
744  ip6_addr_netcmp(&prefix_list[i].prefix, netif_ip6_addr(prefix_list[i].netif, j))) {
745  netif_ip6_addr_set_state(prefix_list[i].netif, j, IP6_ADDR_INVALID);
746  prefix_list[i].flags = 0;
747 
748  /* Exit loop. */
749  break;
750  }
751  }
752  }
753 #endif /* LWIP_IPV6_AUTOCONFIG */
754 
755  prefix_list[i].netif = NULL;
756  prefix_list[i].flags = 0;
757  } else {
758  prefix_list[i].invalidation_timer -= ND6_TMR_INTERVAL / 1000;
759 
760 #if LWIP_IPV6_AUTOCONFIG
761  /* Initiate address autoconfiguration for this prefix, if conditions are met. */
762  if (prefix_list[i].netif->ip6_autoconfig_enabled &&
763  (prefix_list[i].flags & ND6_PREFIX_AUTOCONFIG_AUTONOMOUS) &&
764  !(prefix_list[i].flags & ND6_PREFIX_AUTOCONFIG_ADDRESS_GENERATED)) {
765  s8_t j;
766  /* Try to get an address on this netif that is invalid.
767  * Skip 0 index (link-local address) */
768  for (j = 1; j < LWIP_IPV6_NUM_ADDRESSES; j++) {
769  if (netif_ip6_addr_state(prefix_list[i].netif, j) == IP6_ADDR_INVALID) {
770  /* Generate an address using this prefix and interface ID from link-local address. */
771  IP_ADDR6(&prefix_list[i].netif->ip6_addr[j],
772  prefix_list[i].prefix.addr[0], prefix_list[i].prefix.addr[1],
773  netif_ip6_addr(prefix_list[i].netif, 0)->addr[2], netif_ip6_addr(prefix_list[i].netif, 0)->addr[3]);
774 
775  /* Mark it as tentative (DAD will be performed if configured). */
776  netif_ip6_addr_set_state(prefix_list[i].netif, j, IP6_ADDR_TENTATIVE);
777 
778  /* Mark this prefix with ADDRESS_GENERATED, so that we don't try again. */
779  prefix_list[i].flags |= ND6_PREFIX_AUTOCONFIG_ADDRESS_GENERATED;
780 
781  /* Exit loop. */
782  break;
783  }
784  }
785  }
786 #endif /* LWIP_IPV6_AUTOCONFIG */
787  }
788  }
789  }
790 
791 
792  /* Process our own addresses, if DAD configured. */
793  for (netif = netif_list; netif != NULL; netif = netif->next) {
794  for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; ++i) {
795  if (ip6_addr_istentative(netif->ip6_addr_state[i])) {
796  if ((netif->ip6_addr_state[i] & 0x07) >= LWIP_IPV6_DUP_DETECT_ATTEMPTS) {
797  /* No NA received in response. Mark address as valid. */
798  netif->ip6_addr_state[i] = IP6_ADDR_PREFERRED;
799  /* TODO implement preferred and valid lifetimes. */
800  } else if (netif->flags & NETIF_FLAG_UP) {
801 #if LWIP_IPV6_MLD
802  if ((netif->ip6_addr_state[i] & 0x07) == 0) {
803  /* Join solicited node multicast group. */
804  ip6_addr_set_solicitednode(&multicast_address, netif_ip6_addr(netif, i)->addr[3]);
805  mld6_joingroup(netif_ip6_addr(netif, i), &multicast_address);
806  }
807 #endif /* LWIP_IPV6_MLD */
808  /* Send a NS for this address. */
809  nd6_send_ns(netif, netif_ip6_addr(netif, i), ND6_SEND_FLAG_MULTICAST_DEST);
810  (netif->ip6_addr_state[i])++;
811  /* TODO send max 1 NS per tmr call? enable return*/
812  /*return;*/
813  }
814  }
815  }
816  }
817 
818 #if LWIP_IPV6_SEND_ROUTER_SOLICIT
819  /* Send router solicitation messages, if necessary. */
820  for (netif = netif_list; netif != NULL; netif = netif->next) {
821  if ((netif->rs_count > 0) && (netif->flags & NETIF_FLAG_UP) &&
822  (!ip6_addr_isinvalid(netif_ip6_addr_state(netif, 0)))) {
823  if (nd6_send_rs(netif) == ERR_OK) {
824  netif->rs_count--;
825  }
826  }
827  }
828 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
829 
830 }
831 
839 static void
840 nd6_send_ns(struct netif * netif, const ip6_addr_t * target_addr, u8_t flags)
841 {
842  struct ns_header * ns_hdr;
843  struct lladdr_option * lladdr_opt;
844  struct pbuf * p;
845  const ip6_addr_t * src_addr;
846  u16_t lladdr_opt_len;
847 
848  if (ip6_addr_isvalid(netif_ip6_addr_state(netif,0))) {
849  /* Use link-local address as source address. */
850  src_addr = netif_ip6_addr(netif, 0);
851  } else {
852  src_addr = IP6_ADDR_ANY6;
853  }
854 
855  /* Allocate a packet. */
856  lladdr_opt_len = ((netif->hwaddr_len + 2) >> 3) + (((netif->hwaddr_len + 2) & 0x07) ? 1 : 0);
857  p = pbuf_alloc(PBUF_IP, sizeof(struct ns_header) + (lladdr_opt_len << 3), PBUF_RAM);
858  if (p == NULL) {
859  ND6_STATS_INC(nd6.memerr);
860  return;
861  }
862 
863  /* Set fields. */
864  ns_hdr = (struct ns_header *)p->payload;
865  lladdr_opt = (struct lladdr_option *)((u8_t*)p->payload + sizeof(struct ns_header));
866 
867  ns_hdr->type = ICMP6_TYPE_NS;
868  ns_hdr->code = 0;
869  ns_hdr->chksum = 0;
870  ns_hdr->reserved = 0;
871  ip6_addr_set(&(ns_hdr->target_address), target_addr);
872 
873  lladdr_opt->type = ND6_OPTION_TYPE_SOURCE_LLADDR;
874  lladdr_opt->length = (u8_t)lladdr_opt_len;
875  SMEMCPY(lladdr_opt->addr, netif->hwaddr, netif->hwaddr_len);
876 
877  /* Generate the solicited node address for the target address. */
878  if (flags & ND6_SEND_FLAG_MULTICAST_DEST) {
879  ip6_addr_set_solicitednode(&multicast_address, target_addr->addr[3]);
880  target_addr = &multicast_address;
881  }
882 
883 #if CHECKSUM_GEN_ICMP6
884  IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_ICMP6) {
885  ns_hdr->chksum = ip6_chksum_pseudo(p, IP6_NEXTH_ICMP6, p->len, src_addr,
886  target_addr);
887  }
888 #endif /* CHECKSUM_GEN_ICMP6 */
889 
890  /* Send the packet out. */
891  ND6_STATS_INC(nd6.xmit);
892  ip6_output_if(p, (src_addr == IP6_ADDR_ANY6) ? NULL : src_addr, target_addr,
893  LWIP_ICMP6_HL, 0, IP6_NEXTH_ICMP6, netif);
894  pbuf_free(p);
895 }
896 
904 static void
905 nd6_send_na(struct netif * netif, const ip6_addr_t * target_addr, u8_t flags)
906 {
907  struct na_header * na_hdr;
908  struct lladdr_option * lladdr_opt;
909  struct pbuf * p;
910  const ip6_addr_t * src_addr;
911  const ip6_addr_t * dest_addr;
912  u16_t lladdr_opt_len;
913 
914  /* Use link-local address as source address. */
915  /* src_addr = &(netif->ip6_addr[0]); */
916  /* Use target address as source address. */
917  src_addr = target_addr;
918 
919  /* Allocate a packet. */
920  lladdr_opt_len = ((netif->hwaddr_len + 2) >> 3) + (((netif->hwaddr_len + 2) & 0x07) ? 1 : 0);
921  p = pbuf_alloc(PBUF_IP, sizeof(struct na_header) + (lladdr_opt_len << 3), PBUF_RAM);
922  if (p == NULL) {
923  ND6_STATS_INC(nd6.memerr);
924  return;
925  }
926 
927  /* Set fields. */
928  na_hdr = (struct na_header *)p->payload;
929  lladdr_opt = (struct lladdr_option *)((u8_t*)p->payload + sizeof(struct na_header));
930 
931  na_hdr->type = ICMP6_TYPE_NA;
932  na_hdr->code = 0;
933  na_hdr->chksum = 0;
934  na_hdr->flags = flags & 0xf0;
935  na_hdr->reserved[0] = 0;
936  na_hdr->reserved[1] = 0;
937  na_hdr->reserved[2] = 0;
938  ip6_addr_set(&(na_hdr->target_address), target_addr);
939 
940  lladdr_opt->type = ND6_OPTION_TYPE_TARGET_LLADDR;
941  lladdr_opt->length = (u8_t)lladdr_opt_len;
942  SMEMCPY(lladdr_opt->addr, netif->hwaddr, netif->hwaddr_len);
943 
944  /* Generate the solicited node address for the target address. */
945  if (flags & ND6_SEND_FLAG_MULTICAST_DEST) {
946  ip6_addr_set_solicitednode(&multicast_address, target_addr->addr[3]);
947  dest_addr = &multicast_address;
948  } else if (flags & ND6_SEND_FLAG_ALLNODES_DEST) {
949  ip6_addr_set_allnodes_linklocal(&multicast_address);
950  dest_addr = &multicast_address;
951  } else {
952  dest_addr = ip6_current_src_addr();
953  }
954 
955 #if CHECKSUM_GEN_ICMP6
956  IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_ICMP6) {
957  na_hdr->chksum = ip6_chksum_pseudo(p, IP6_NEXTH_ICMP6, p->len, src_addr,
958  dest_addr);
959  }
960 #endif /* CHECKSUM_GEN_ICMP6 */
961 
962  /* Send the packet out. */
963  ND6_STATS_INC(nd6.xmit);
964  ip6_output_if(p, src_addr, dest_addr,
965  LWIP_ICMP6_HL, 0, IP6_NEXTH_ICMP6, netif);
966  pbuf_free(p);
967 }
968 
969 #if LWIP_IPV6_SEND_ROUTER_SOLICIT
970 
975 static err_t
976 nd6_send_rs(struct netif * netif)
977 {
978  struct rs_header * rs_hdr;
979  struct lladdr_option * lladdr_opt;
980  struct pbuf * p;
981  const ip6_addr_t * src_addr;
982  err_t err;
983  u16_t lladdr_opt_len = 0;
984 
985  /* Link-local source address, or unspecified address? */
986  if (ip6_addr_isvalid(netif_ip6_addr_state(netif, 0))) {
987  src_addr = netif_ip6_addr(netif, 0);
988  } else {
989  src_addr = IP6_ADDR_ANY6;
990  }
991 
992  /* Generate the all routers target address. */
993  ip6_addr_set_allrouters_linklocal(&multicast_address);
994 
995  /* Allocate a packet. */
996  if (src_addr != IP6_ADDR_ANY6) {
997  lladdr_opt_len = ((netif->hwaddr_len + 2) >> 3) + (((netif->hwaddr_len + 2) & 0x07) ? 1 : 0);
998  }
999  p = pbuf_alloc(PBUF_IP, sizeof(struct rs_header) + (lladdr_opt_len << 3), PBUF_RAM);
1000  if (p == NULL) {
1001  ND6_STATS_INC(nd6.memerr);
1002  return ERR_BUF;
1003  }
1004 
1005  /* Set fields. */
1006  rs_hdr = (struct rs_header *)p->payload;
1007 
1008  rs_hdr->type = ICMP6_TYPE_RS;
1009  rs_hdr->code = 0;
1010  rs_hdr->chksum = 0;
1011  rs_hdr->reserved = 0;
1012 
1013  if (src_addr != IP6_ADDR_ANY6) {
1014  /* Include our hw address. */
1015  lladdr_opt = (struct lladdr_option *)((u8_t*)p->payload + sizeof(struct rs_header));
1016  lladdr_opt->type = ND6_OPTION_TYPE_SOURCE_LLADDR;
1017  lladdr_opt->length = (u8_t)lladdr_opt_len;
1018  SMEMCPY(lladdr_opt->addr, netif->hwaddr, netif->hwaddr_len);
1019  }
1020 
1021 #if CHECKSUM_GEN_ICMP6
1022  IF__NETIF_CHECKSUM_ENABLED(netif, NETIF_CHECKSUM_GEN_ICMP6) {
1023  rs_hdr->chksum = ip6_chksum_pseudo(p, IP6_NEXTH_ICMP6, p->len, src_addr,
1024  &multicast_address);
1025  }
1026 #endif /* CHECKSUM_GEN_ICMP6 */
1027 
1028  /* Send the packet out. */
1029  ND6_STATS_INC(nd6.xmit);
1030 
1031  err = ip6_output_if(p, (src_addr == IP6_ADDR_ANY6) ? NULL : src_addr, &multicast_address,
1032  LWIP_ICMP6_HL, 0, IP6_NEXTH_ICMP6, netif);
1033  pbuf_free(p);
1034 
1035  return err;
1036 }
1037 #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
1038 
1046 static s8_t
1047 nd6_find_neighbor_cache_entry(const ip6_addr_t * ip6addr)
1048 {
1049  s8_t i;
1050  for (i = 0; i < LWIP_ND6_NUM_NEIGHBORS; i++) {
1051  if (ip6_addr_cmp(ip6addr, &(neighbor_cache[i].next_hop_address))) {
1052  return i;
1053  }
1054  }
1055  return -1;
1056 }
1057 
1067 static s8_t
1068 nd6_new_neighbor_cache_entry(void)
1069 {
1070  s8_t i;
1071  s8_t j;
1072  u32_t time;
1073 
1074 
1075  /* First, try to find an empty entry. */
1076  for (i = 0; i < LWIP_ND6_NUM_NEIGHBORS; i++) {
1077  if (neighbor_cache[i].state == ND6_NO_ENTRY) {
1078  return i;
1079  }
1080  }
1081 
1082  /* We need to recycle an entry. in general, do not recycle if it is a router. */
1083 
1084  /* Next, try to find a Stale entry. */
1085  for (i = 0; i < LWIP_ND6_NUM_NEIGHBORS; i++) {
1086  if ((neighbor_cache[i].state == ND6_STALE) &&
1087  (!neighbor_cache[i].isrouter)) {
1088  nd6_free_neighbor_cache_entry(i);
1089  return i;
1090  }
1091  }
1092 
1093  /* Next, try to find a Probe entry. */
1094  for (i = 0; i < LWIP_ND6_NUM_NEIGHBORS; i++) {
1095  if ((neighbor_cache[i].state == ND6_PROBE) &&
1096  (!neighbor_cache[i].isrouter)) {
1097  nd6_free_neighbor_cache_entry(i);
1098  return i;
1099  }
1100  }
1101 
1102  /* Next, try to find a Delayed entry. */
1103  for (i = 0; i < LWIP_ND6_NUM_NEIGHBORS; i++) {
1104  if ((neighbor_cache[i].state == ND6_DELAY) &&
1105  (!neighbor_cache[i].isrouter)) {
1106  nd6_free_neighbor_cache_entry(i);
1107  return i;
1108  }
1109  }
1110 
1111  /* Next, try to find the oldest reachable entry. */
1112  time = 0xfffffffful;
1113  j = -1;
1114  for (i = 0; i < LWIP_ND6_NUM_NEIGHBORS; i++) {
1115  if ((neighbor_cache[i].state == ND6_REACHABLE) &&
1116  (!neighbor_cache[i].isrouter)) {
1117  if (neighbor_cache[i].counter.reachable_time < time) {
1118  j = i;
1119  time = neighbor_cache[i].counter.reachable_time;
1120  }
1121  }
1122  }
1123  if (j >= 0) {
1124  nd6_free_neighbor_cache_entry(j);
1125  return j;
1126  }
1127 
1128  /* Next, find oldest incomplete entry without queued packets. */
1129  time = 0;
1130  j = -1;
1131  for (i = 0; i < LWIP_ND6_NUM_NEIGHBORS; i++) {
1132  if (
1133  (neighbor_cache[i].q == NULL) &&
1134  (neighbor_cache[i].state == ND6_INCOMPLETE) &&
1135  (!neighbor_cache[i].isrouter)) {
1136  if (neighbor_cache[i].counter.probes_sent >= time) {
1137  j = i;
1138  time = neighbor_cache[i].counter.probes_sent;
1139  }
1140  }
1141  }
1142  if (j >= 0) {
1143  nd6_free_neighbor_cache_entry(j);
1144  return j;
1145  }
1146 
1147  /* Next, find oldest incomplete entry with queued packets. */
1148  time = 0;
1149  j = -1;
1150  for (i = 0; i < LWIP_ND6_NUM_NEIGHBORS; i++) {
1151  if ((neighbor_cache[i].state == ND6_INCOMPLETE) &&
1152  (!neighbor_cache[i].isrouter)) {
1153  if (neighbor_cache[i].counter.probes_sent >= time) {
1154  j = i;
1155  time = neighbor_cache[i].counter.probes_sent;
1156  }
1157  }
1158  }
1159  if (j >= 0) {
1160  nd6_free_neighbor_cache_entry(j);
1161  return j;
1162  }
1163 
1164  /* No more entries to try. */
1165  return -1;
1166 }
1167 
1174 static void
1175 nd6_free_neighbor_cache_entry(s8_t i)
1176 {
1177  if ((i < 0) || (i >= LWIP_ND6_NUM_NEIGHBORS)) {
1178  return;
1179  }
1180 
1181  /* Free any queued packets. */
1182  if (neighbor_cache[i].q != NULL) {
1183  nd6_free_q(neighbor_cache[i].q);
1184  neighbor_cache[i].q = NULL;
1185  }
1186 
1187  neighbor_cache[i].state = ND6_NO_ENTRY;
1188  neighbor_cache[i].isrouter = 0;
1189  neighbor_cache[i].netif = NULL;
1190  neighbor_cache[i].counter.reachable_time = 0;
1191  ip6_addr_set_zero(&(neighbor_cache[i].next_hop_address));
1192 }
1193 
1201 static s8_t
1202 nd6_find_destination_cache_entry(const ip6_addr_t * ip6addr)
1203 {
1204  s8_t i;
1205  for (i = 0; i < LWIP_ND6_NUM_DESTINATIONS; i++) {
1206  if (ip6_addr_cmp(ip6addr, &(destination_cache[i].destination_addr))) {
1207  return i;
1208  }
1209  }
1210  return -1;
1211 }
1212 
1220 static s8_t
1221 nd6_new_destination_cache_entry(void)
1222 {
1223  s8_t i, j;
1224  u32_t age;
1225 
1226  /* Find an empty entry. */
1227  for (i = 0; i < LWIP_ND6_NUM_DESTINATIONS; i++) {
1228  if (ip6_addr_isany(&(destination_cache[i].destination_addr))) {
1229  return i;
1230  }
1231  }
1232 
1233  /* Find oldest entry. */
1234  age = 0;
1235  j = LWIP_ND6_NUM_DESTINATIONS - 1;
1236  for (i = 0; i < LWIP_ND6_NUM_DESTINATIONS; i++) {
1237  if (destination_cache[i].age > age) {
1238  j = i;
1239  }
1240  }
1241 
1242  return j;
1243 }
1244 
1251 static s8_t
1252 nd6_is_prefix_in_netif(const ip6_addr_t * ip6addr, struct netif * netif)
1253 {
1254  s8_t i;
1255  for (i = 0; i < LWIP_ND6_NUM_PREFIXES; i++) {
1256  if ((prefix_list[i].netif == netif) &&
1257  (prefix_list[i].invalidation_timer > 0) &&
1258  ip6_addr_netcmp(ip6addr, &(prefix_list[i].prefix))) {
1259  return 1;
1260  }
1261  }
1262  /* Check to see if address prefix matches a (manually?) configured address. */
1263  for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
1264  if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) &&
1265  ip6_addr_netcmp(ip6addr, netif_ip6_addr(netif, i))) {
1266  return 1;
1267  }
1268  }
1269  return 0;
1270 }
1271 
1280 s8_t
1281 nd6_select_router(const ip6_addr_t * ip6addr, struct netif * netif)
1282 {
1283  s8_t i;
1284  /* last_router is used for round-robin router selection (as recommended
1285  * in RFC). This is more robust in case one router is not reachable,
1286  * we are not stuck trying to resolve it. */
1287  static s8_t last_router;
1288  (void)ip6addr; /* TODO match preferred routes!! (must implement ND6_OPTION_TYPE_ROUTE_INFO) */
1289 
1290  /* TODO: implement default router preference */
1291 
1292  /* Look for reachable routers. */
1293  for (i = 0; i < LWIP_ND6_NUM_ROUTERS; i++) {
1294  if (++last_router >= LWIP_ND6_NUM_ROUTERS) {
1295  last_router = 0;
1296  }
1297  if ((default_router_list[i].neighbor_entry != NULL) &&
1298  (netif != NULL ? netif == default_router_list[i].neighbor_entry->netif : 1) &&
1299  (default_router_list[i].invalidation_timer > 0) &&
1300  (default_router_list[i].neighbor_entry->state == ND6_REACHABLE)) {
1301  return i;
1302  }
1303  }
1304 
1305  /* Look for router in other reachability states, but still valid according to timer. */
1306  for (i = 0; i < LWIP_ND6_NUM_ROUTERS; i++) {
1307  if (++last_router >= LWIP_ND6_NUM_ROUTERS) {
1308  last_router = 0;
1309  }
1310  if ((default_router_list[i].neighbor_entry != NULL) &&
1311  (netif != NULL ? netif == default_router_list[i].neighbor_entry->netif : 1) &&
1312  (default_router_list[i].invalidation_timer > 0)) {
1313  return i;
1314  }
1315  }
1316 
1317  /* Look for any router for which we have any information at all. */
1318  for (i = 0; i < LWIP_ND6_NUM_ROUTERS; i++) {
1319  if (++last_router >= LWIP_ND6_NUM_ROUTERS) {
1320  last_router = 0;
1321  }
1322  if (default_router_list[i].neighbor_entry != NULL &&
1323  (netif != NULL ? netif == default_router_list[i].neighbor_entry->netif : 1)) {
1324  return i;
1325  }
1326  }
1327 
1328  /* no suitable router found. */
1329  return -1;
1330 }
1331 
1339 static s8_t
1340 nd6_get_router(const ip6_addr_t * router_addr, struct netif * netif)
1341 {
1342  s8_t i;
1343 
1344  /* Look for router. */
1345  for (i = 0; i < LWIP_ND6_NUM_ROUTERS; i++) {
1346  if ((default_router_list[i].neighbor_entry != NULL) &&
1347  ((netif != NULL) ? netif == default_router_list[i].neighbor_entry->netif : 1) &&
1348  ip6_addr_cmp(router_addr, &(default_router_list[i].neighbor_entry->next_hop_address))) {
1349  return i;
1350  }
1351  }
1352 
1353  /* router not found. */
1354  return -1;
1355 }
1356 
1364 static s8_t
1365 nd6_new_router(const ip6_addr_t * router_addr, struct netif * netif)
1366 {
1367  s8_t router_index;
1368  s8_t neighbor_index;
1369 
1370  /* Do we have a neighbor entry for this router? */
1371  neighbor_index = nd6_find_neighbor_cache_entry(router_addr);
1372  if (neighbor_index < 0) {
1373  /* Create a neighbor entry for this router. */
1374  neighbor_index = nd6_new_neighbor_cache_entry();
1375  if (neighbor_index < 0) {
1376  /* Could not create neighbor entry for this router. */
1377  return -1;
1378  }
1379  ip6_addr_set(&(neighbor_cache[neighbor_index].next_hop_address), router_addr);
1380  neighbor_cache[neighbor_index].netif = netif;
1381  neighbor_cache[neighbor_index].q = NULL;
1382  neighbor_cache[neighbor_index].state = ND6_INCOMPLETE;
1383  neighbor_cache[neighbor_index].counter.probes_sent = 0;
1384  }
1385 
1386  /* Mark neighbor as router. */
1387  neighbor_cache[neighbor_index].isrouter = 1;
1388 
1389  /* Look for empty entry. */
1390  for (router_index = 0; router_index < LWIP_ND6_NUM_ROUTERS; router_index++) {
1391  if (default_router_list[router_index].neighbor_entry == NULL) {
1392  default_router_list[router_index].neighbor_entry = &(neighbor_cache[neighbor_index]);
1393  return router_index;
1394  }
1395  }
1396 
1397  /* Could not create a router entry. */
1398 
1399  /* Mark neighbor entry as not-router. Entry might be useful as neighbor still. */
1400  neighbor_cache[neighbor_index].isrouter = 0;
1401 
1402  /* router not found. */
1403  return -1;
1404 }
1405 
1413 static s8_t
1414 nd6_get_onlink_prefix(ip6_addr_t * prefix, struct netif * netif)
1415 {
1416  s8_t i;
1417 
1418  /* Look for prefix in list. */
1419  for (i = 0; i < LWIP_ND6_NUM_PREFIXES; ++i) {
1420  if ((ip6_addr_netcmp(&(prefix_list[i].prefix), prefix)) &&
1421  (prefix_list[i].netif == netif)) {
1422  return i;
1423  }
1424  }
1425 
1426  /* Entry not available. */
1427  return -1;
1428 }
1429 
1437 static s8_t
1438 nd6_new_onlink_prefix(ip6_addr_t * prefix, struct netif * netif)
1439 {
1440  s8_t i;
1441 
1442  /* Create new entry. */
1443  for (i = 0; i < LWIP_ND6_NUM_PREFIXES; ++i) {
1444  if ((prefix_list[i].netif == NULL) ||
1445  (prefix_list[i].invalidation_timer == 0)) {
1446  /* Found empty prefix entry. */
1447  prefix_list[i].netif = netif;
1448  ip6_addr_set(&(prefix_list[i].prefix), prefix);
1449 #if LWIP_IPV6_AUTOCONFIG
1450  prefix_list[i].flags = 0;
1451 #endif /* LWIP_IPV6_AUTOCONFIG */
1452  return i;
1453  }
1454  }
1455 
1456  /* Entry not available. */
1457  return -1;
1458 }
1459 
1472 s8_t
1473 nd6_get_next_hop_entry(const ip6_addr_t * ip6addr, struct netif * netif)
1474 {
1475  s8_t i;
1476 
1477 #if LWIP_NETIF_HWADDRHINT
1478  if (netif->addr_hint != NULL) {
1479  /* per-pcb cached entry was given */
1480  u8_t addr_hint = *(netif->addr_hint);
1481  if (addr_hint < LWIP_ND6_NUM_DESTINATIONS) {
1482  nd6_cached_destination_index = addr_hint;
1483  }
1484  }
1485 #endif /* LWIP_NETIF_HWADDRHINT */
1486 
1487  /* Look for ip6addr in destination cache. */
1488  if (ip6_addr_cmp(ip6addr, &(destination_cache[nd6_cached_destination_index].destination_addr))) {
1489  /* the cached entry index is the right one! */
1490  /* do nothing. */
1491  ND6_STATS_INC(nd6.cachehit);
1492  } else {
1493  /* Search destination cache. */
1494  i = nd6_find_destination_cache_entry(ip6addr);
1495  if (i >= 0) {
1496  /* found destination entry. make it our new cached index. */
1497  nd6_cached_destination_index = i;
1498  } else {
1499  /* Not found. Create a new destination entry. */
1500  i = nd6_new_destination_cache_entry();
1501  if (i >= 0) {
1502  /* got new destination entry. make it our new cached index. */
1503  nd6_cached_destination_index = i;
1504  } else {
1505  /* Could not create a destination cache entry. */
1506  return ERR_MEM;
1507  }
1508 
1509  /* Copy dest address to destination cache. */
1510  ip6_addr_set(&(destination_cache[nd6_cached_destination_index].destination_addr), ip6addr);
1511 
1512  /* Now find the next hop. is it a neighbor? */
1513  if (ip6_addr_islinklocal(ip6addr) ||
1514  nd6_is_prefix_in_netif(ip6addr, netif)) {
1515  /* Destination in local link. */
1516  destination_cache[nd6_cached_destination_index].pmtu = netif->mtu;
1517  ip6_addr_copy(destination_cache[nd6_cached_destination_index].next_hop_addr, destination_cache[nd6_cached_destination_index].destination_addr);
1518  } else {
1519  /* We need to select a router. */
1520  i = nd6_select_router(ip6addr, netif);
1521  if (i < 0) {
1522  /* No router found. */
1523  ip6_addr_set_any(&(destination_cache[nd6_cached_destination_index].destination_addr));
1524  return ERR_RTE;
1525  }
1526  destination_cache[nd6_cached_destination_index].pmtu = netif->mtu; /* Start with netif mtu, correct through ICMPv6 if necessary */
1527  ip6_addr_copy(destination_cache[nd6_cached_destination_index].next_hop_addr, default_router_list[i].neighbor_entry->next_hop_address);
1528  }
1529  }
1530  }
1531 
1532 #if LWIP_NETIF_HWADDRHINT
1533  if (netif->addr_hint != NULL) {
1534  /* per-pcb cached entry was given */
1535  *(netif->addr_hint) = nd6_cached_destination_index;
1536  }
1537 #endif /* LWIP_NETIF_HWADDRHINT */
1538 
1539  /* Look in neighbor cache for the next-hop address. */
1540  if (ip6_addr_cmp(&(destination_cache[nd6_cached_destination_index].next_hop_addr),
1541  &(neighbor_cache[nd6_cached_neighbor_index].next_hop_address))) {
1542  /* Cache hit. */
1543  /* Do nothing. */
1544  ND6_STATS_INC(nd6.cachehit);
1545  } else {
1546  i = nd6_find_neighbor_cache_entry(&(destination_cache[nd6_cached_destination_index].next_hop_addr));
1547  if (i >= 0) {
1548  /* Found a matching record, make it new cached entry. */
1549  nd6_cached_neighbor_index = i;
1550  } else {
1551  /* Neighbor not in cache. Make a new entry. */
1552  i = nd6_new_neighbor_cache_entry();
1553  if (i >= 0) {
1554  /* got new neighbor entry. make it our new cached index. */
1555  nd6_cached_neighbor_index = i;
1556  } else {
1557  /* Could not create a neighbor cache entry. */
1558  return ERR_MEM;
1559  }
1560 
1561  /* Initialize fields. */
1562  ip6_addr_copy(neighbor_cache[i].next_hop_address,
1563  destination_cache[nd6_cached_destination_index].next_hop_addr);
1564  neighbor_cache[i].isrouter = 0;
1565  neighbor_cache[i].netif = netif;
1566  neighbor_cache[i].state = ND6_INCOMPLETE;
1567  neighbor_cache[i].counter.probes_sent = 0;
1568  }
1569  }
1570 
1571  /* Reset this destination's age. */
1572  destination_cache[nd6_cached_destination_index].age = 0;
1573 
1574  return nd6_cached_neighbor_index;
1575 }
1576 
1584 err_t
1585 nd6_queue_packet(s8_t neighbor_index, struct pbuf * q)
1586 {
1587  err_t result = ERR_MEM;
1588  struct pbuf *p;
1589  int copy_needed = 0;
1590 #if LWIP_ND6_QUEUEING
1591  struct nd6_q_entry *new_entry, *r;
1592 #endif /* LWIP_ND6_QUEUEING */
1593 
1594  if ((neighbor_index < 0) || (neighbor_index >= LWIP_ND6_NUM_NEIGHBORS)) {
1595  return ERR_ARG;
1596  }
1597 
1598  /* IF q includes a PBUF_REF, PBUF_POOL or PBUF_RAM, we have no choice but
1599  * to copy the whole queue into a new PBUF_RAM (see bug #11400)
1600  * PBUF_ROMs can be left as they are, since ROM must not get changed. */
1601  p = q;
1602  while (p) {
1603  if (p->type != PBUF_ROM) {
1604  copy_needed = 1;
1605  break;
1606  }
1607  p = p->next;
1608  }
1609  if (copy_needed) {
1610  /* copy the whole packet into new pbufs */
1612  while ((p == NULL) && (neighbor_cache[neighbor_index].q != NULL)) {
1613  /* Free oldest packet (as per RFC recommendation) */
1614 #if LWIP_ND6_QUEUEING
1615  r = neighbor_cache[neighbor_index].q;
1616  neighbor_cache[neighbor_index].q = r->next;
1617  r->next = NULL;
1618  nd6_free_q(r);
1619 #else /* LWIP_ND6_QUEUEING */
1620  pbuf_free(neighbor_cache[neighbor_index].q);
1621  neighbor_cache[neighbor_index].q = NULL;
1622 #endif /* LWIP_ND6_QUEUEING */
1624  }
1625  if (p != NULL) {
1626  if (pbuf_copy(p, q) != ERR_OK) {
1627  pbuf_free(p);
1628  p = NULL;
1629  }
1630  }
1631  } else {
1632  /* referencing the old pbuf is enough */
1633  p = q;
1634  pbuf_ref(p);
1635  }
1636  /* packet was copied/ref'd? */
1637  if (p != NULL) {
1638  /* queue packet ... */
1639 #if LWIP_ND6_QUEUEING
1640  /* allocate a new nd6 queue entry */
1641  new_entry = (struct nd6_q_entry *)memp_malloc(MEMP_ND6_QUEUE);
1642  if ((new_entry == NULL) && (neighbor_cache[neighbor_index].q != NULL)) {
1643  /* Free oldest packet (as per RFC recommendation) */
1644  r = neighbor_cache[neighbor_index].q;
1645  neighbor_cache[neighbor_index].q = r->next;
1646  r->next = NULL;
1647  nd6_free_q(r);
1648  new_entry = (struct nd6_q_entry *)memp_malloc(MEMP_ND6_QUEUE);
1649  }
1650  if (new_entry != NULL) {
1651  new_entry->next = NULL;
1652  new_entry->p = p;
1653  if (neighbor_cache[neighbor_index].q != NULL) {
1654  /* queue was already existent, append the new entry to the end */
1655  r = neighbor_cache[neighbor_index].q;
1656  while (r->next != NULL) {
1657  r = r->next;
1658  }
1659  r->next = new_entry;
1660  } else {
1661  /* queue did not exist, first item in queue */
1662  neighbor_cache[neighbor_index].q = new_entry;
1663  }
1664  LWIP_DEBUGF(LWIP_DBG_TRACE, ("ipv6: queued packet %p on neighbor entry %"S16_F"\n", (void *)p, (s16_t)neighbor_index));
1665  result = ERR_OK;
1666  } else {
1667  /* the pool MEMP_ND6_QUEUE is empty */
1668  pbuf_free(p);
1669  LWIP_DEBUGF(LWIP_DBG_TRACE, ("ipv6: could not queue a copy of packet %p (out of memory)\n", (void *)p));
1670  /* { result == ERR_MEM } through initialization */
1671  }
1672 #else /* LWIP_ND6_QUEUEING */
1673  /* Queue a single packet. If an older packet is already queued, free it as per RFC. */
1674  if (neighbor_cache[neighbor_index].q != NULL) {
1675  pbuf_free(neighbor_cache[neighbor_index].q);
1676  }
1677  neighbor_cache[neighbor_index].q = p;
1678  LWIP_DEBUGF(LWIP_DBG_TRACE, ("ipv6: queued packet %p on neighbor entry %"S16_F"\n", (void *)p, (s16_t)neighbor_index));
1679  result = ERR_OK;
1680 #endif /* LWIP_ND6_QUEUEING */
1681  } else {
1682  LWIP_DEBUGF(LWIP_DBG_TRACE, ("ipv6: could not queue a copy of packet %p (out of memory)\n", (void *)q));
1683  /* { result == ERR_MEM } through initialization */
1684  }
1685 
1686  return result;
1687 }
1688 
1689 #if LWIP_ND6_QUEUEING
1690 
1695 static void
1696 nd6_free_q(struct nd6_q_entry *q)
1697 {
1698  struct nd6_q_entry *r;
1699  LWIP_ASSERT("q != NULL", q != NULL);
1700  LWIP_ASSERT("q->p != NULL", q->p != NULL);
1701  while (q) {
1702  r = q;
1703  q = q->next;
1704  LWIP_ASSERT("r->p != NULL", (r->p != NULL));
1705  pbuf_free(r->p);
1706  memp_free(MEMP_ND6_QUEUE, r);
1707  }
1708 }
1709 #endif /* LWIP_ND6_QUEUEING */
1710 
1716 static void
1717 nd6_send_q(s8_t i)
1718 {
1719  struct ip6_hdr *ip6hdr;
1720 #if LWIP_ND6_QUEUEING
1721  struct nd6_q_entry *q;
1722 #endif /* LWIP_ND6_QUEUEING */
1723 
1724  if ((i < 0) || (i >= LWIP_ND6_NUM_NEIGHBORS)) {
1725  return;
1726  }
1727 
1728 #if LWIP_ND6_QUEUEING
1729  while (neighbor_cache[i].q != NULL) {
1730  /* remember first in queue */
1731  q = neighbor_cache[i].q;
1732  /* pop first item off the queue */
1733  neighbor_cache[i].q = q->next;
1734  /* Get ipv6 header. */
1735  ip6hdr = (struct ip6_hdr *)(q->p->payload);
1736  /* Override ip6_current_dest_addr() so that we have an aligned copy. */
1737  ip6_addr_set(ip6_current_dest_addr(), &(ip6hdr->dest));
1738  /* send the queued IPv6 packet */
1739  (neighbor_cache[i].netif)->output_ip6(neighbor_cache[i].netif, q->p, ip6_current_dest_addr());
1740  /* free the queued IP packet */
1741  pbuf_free(q->p);
1742  /* now queue entry can be freed */
1743  memp_free(MEMP_ND6_QUEUE, q);
1744  }
1745 #else /* LWIP_ND6_QUEUEING */
1746  if (neighbor_cache[i].q != NULL) {
1747  /* Get ipv6 header. */
1748  ip6hdr = (struct ip6_hdr *)(neighbor_cache[i].q->payload);
1749  /* Override ip6_current_dest_addr() so that we have an aligned copy. */
1750  ip6_addr_set(ip6_current_dest_addr(), &(ip6hdr->dest));
1751  /* send the queued IPv6 packet */
1752  (neighbor_cache[i].netif)->output_ip6(neighbor_cache[i].netif, neighbor_cache[i].q, ip6_current_dest_addr());
1753  /* free the queued IP packet */
1754  pbuf_free(neighbor_cache[i].q);
1755  neighbor_cache[i].q = NULL;
1756  }
1757 #endif /* LWIP_ND6_QUEUEING */
1758 }
1759 
1760 
1768 u16_t
1769 nd6_get_destination_mtu(const ip6_addr_t * ip6addr, struct netif * netif)
1770 {
1771  s8_t i;
1772 
1773  i = nd6_find_destination_cache_entry(ip6addr);
1774  if (i >= 0) {
1775  if (destination_cache[i].pmtu > 0) {
1776  return destination_cache[i].pmtu;
1777  }
1778  }
1779 
1780  if (netif != NULL) {
1781  return netif->mtu;
1782  }
1783 
1784  return 1280; /* Minimum MTU */
1785 }
1786 
1787 
1788 #if LWIP_ND6_TCP_REACHABILITY_HINTS
1789 
1798 void
1799 nd6_reachability_hint(const ip6_addr_t * ip6addr)
1800 {
1801  s8_t i;
1802 
1803  /* Find destination in cache. */
1804  if (ip6_addr_cmp(ip6addr, &(destination_cache[nd6_cached_destination_index].destination_addr))) {
1805  i = nd6_cached_destination_index;
1806  ND6_STATS_INC(nd6.cachehit);
1807  } else {
1808  i = nd6_find_destination_cache_entry(ip6addr);
1809  }
1810  if (i < 0) {
1811  return;
1812  }
1813 
1814  /* Find next hop neighbor in cache. */
1815  if (ip6_addr_cmp(&(destination_cache[i].next_hop_addr), &(neighbor_cache[nd6_cached_neighbor_index].next_hop_address))) {
1816  i = nd6_cached_neighbor_index;
1817  ND6_STATS_INC(nd6.cachehit);
1818  } else {
1819  i = nd6_find_neighbor_cache_entry(&(destination_cache[i].next_hop_addr));
1820  }
1821  if (i < 0) {
1822  return;
1823  }
1824 
1825  /* For safety: don't set as reachable if we don't have a LL address yet. Misuse protection. */
1826  if (neighbor_cache[i].state == ND6_INCOMPLETE || neighbor_cache[i].state == ND6_NO_ENTRY) {
1827  return;
1828  }
1829 
1830  /* Set reachability state. */
1831  neighbor_cache[i].state = ND6_REACHABLE;
1832  neighbor_cache[i].counter.reachable_time = reachable_time;
1833 }
1834 #endif /* LWIP_ND6_TCP_REACHABILITY_HINTS */
1835 
1836 #endif /* LWIP_IPV6 */
1837 
#define LWIP_ND6_NUM_PREFIXES
Definition: opt.h:2544
u8_t flags
Definition: netif.h:269
struct netif * netif_list
Definition: netif.c:84
void * state
Definition: netif.h:234
signed char s8_t
Definition: cc.h:39
signed short s16_t
Definition: cc.h:41
u8_t hwaddr[NETIF_MAX_HWADDR_LEN]
Definition: netif.h:267
#define NETIF_FLAG_UP
Definition: netif.h:77
struct netif * next
Definition: netif.h:184
u16_t mtu
Definition: netif.h:263
#define htons(x)
Definition: def.h:86
#define SMEMCPY(dst, src, len)
Definition: opt.h:92
#define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
Definition: netif.h:313
#define MEMCPY(dst, src, len)
Definition: opt.h:84
if(LCD_Lock==DISABLE)
Definition: lcd_log.c:249
void memp_free(memp_t type, void *mem)
Definition: memp.c:399
u16_t len
Definition: pbuf.h:125
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
Definition: pbuf.c:199
Definition: pbuf.h:77
Definition: pbuf.h:66
#define LWIP_MIN(x, y)
Definition: def.h:50
#define LWIP_ND6_NUM_DESTINATIONS
Definition: opt.h:2537
#define NULL
Definition: usbd_def.h:53
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:652
err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from)
Definition: pbuf.c:886
unsigned long u32_t
Definition: cc.h:42
#define ERR_RTE
Definition: err.h:56
#define ERR_OK
Definition: err.h:52
u16_t tot_len
Definition: pbuf.h:122
#define LWIP_DBG_TRACE
Definition: debug.h:57
Definition: pbuf.h:108
#define LWIP_ICMP6_HL
Definition: opt.h:2480
s8_t err_t
Definition: err.h:47
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:70
Definition: netif.h:182
u8_t hwaddr_len
Definition: netif.h:265
#define LWIP_ND6_NUM_NEIGHBORS
Definition: opt.h:2530
Definition: pbuf.h:81
#define IP_ADDR6(ipaddr, i0, i1, i2, i3)
Definition: ip_addr.h:201
struct pbuf * next
Definition: pbuf.h:110
void pbuf_ref(struct pbuf *p)
Definition: pbuf.c:757
#define LWIP_ND6_NUM_ROUTERS
Definition: opt.h:2551
#define LWIP_ND6_RETRANS_TIMER
Definition: opt.h:2596
#define ND6_STATS_INC(x)
Definition: stats.h:400
#define S16_F
Definition: cc.h:49
#define LWIP_IPV6_NUM_ADDRESSES
Definition: opt.h:2451
#define ERR_ARG
Definition: err.h:71
u8_t type
Definition: pbuf.h:128
u16_t pbuf_copy_partial(struct pbuf *buf, void *dataptr, u16_t len, u16_t offset)
Definition: pbuf.c:952
#define LWIP_ND6_REACHABLE_TIME
Definition: opt.h:2589
#define LWIP_ND6_MAX_MULTICAST_SOLICIT
Definition: opt.h:2559
unsigned char u8_t
Definition: cc.h:38
#define LWIP_ND6_DELAY_FIRST_PROBE_TIME
Definition: opt.h:2604
#define LWIP_IPV6_SEND_ROUTER_SOLICIT
Definition: opt.h:2620
Definition: pbuf.h:65
#define LWIP_IPV6_DUP_DETECT_ATTEMPTS
Definition: opt.h:2643
void * memp_malloc(memp_t type)
Definition: memp.c:303
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:113
#define ERR_MEM
Definition: err.h:53
#define htonl(x)
Definition: def.h:88
unsigned short u16_t
Definition: cc.h:40
void * payload
Definition: pbuf.h:113
#define ERR_BUF
Definition: err.h:54