1 #pragma GCC diagnostic ignored "-Wredundant-decls"
2 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
3 #pragma GCC diagnostic ignored "-Wcast-align"
4 #pragma GCC diagnostic ignored "-Wcast-qual"
7 * Copyright (c) 2006, Swedish Institute of Computer Science.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the Institute nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * This file is part of the uIP TCP/IP stack
36 * $Id: uip-neighbor.c,v 1.2 2006/06/12 08:00:30 adam Exp $
41 * Database of link-local neighbors, used by IPv6 code and
42 * to be used by a future ARP code rewrite.
44 * Adam Dunkels <adam@sics.se>
47 #include "uip-neighbor.h"
54 #ifdef UIP_NEIGHBOR_CONF_ENTRIES
55 #define ENTRIES UIP_NEIGHBOR_CONF_ENTRIES
56 #else /* UIP_NEIGHBOR_CONF_ENTRIES */
58 #endif /* UIP_NEIGHBOR_CONF_ENTRIES */
60 struct neighbor_entry
{
62 struct uip_neighbor_addr addr
;
65 static struct neighbor_entry entries
[ENTRIES
] __attribute__ ((section ("AHBSRAM1")));
67 /*---------------------------------------------------------------------------*/
69 uip_neighbor_init(void)
73 for(i
= 0; i
< ENTRIES
; ++i
) {
74 entries
[i
].time
= MAX_TIME
;
77 /*---------------------------------------------------------------------------*/
79 uip_neighbor_periodic(void)
83 for(i
= 0; i
< ENTRIES
; ++i
) {
84 if(entries
[i
].time
< MAX_TIME
) {
89 /*---------------------------------------------------------------------------*/
91 uip_neighbor_add(uip_ipaddr_t ipaddr
, struct uip_neighbor_addr
*addr
)
96 printf("Adding neighbor with link address %02x:%02x:%02x:%02x:%02x:%02x\n",
97 addr
->addr
.addr
[0], addr
->addr
.addr
[1], addr
->addr
.addr
[2], addr
->addr
.addr
[3],
98 addr
->addr
.addr
[4], addr
->addr
.addr
[5]);
100 /* Find the first unused entry or the oldest used entry. */
103 for(i
= 0; i
< ENTRIES
; ++i
) {
104 if(entries
[i
].time
== MAX_TIME
) {
108 if(uip_ipaddr_cmp(entries
[i
].ipaddr
, addr
)) {
112 if(entries
[i
].time
> oldest_time
) {
114 oldest_time
= entries
[i
].time
;
118 /* Use the oldest or first free entry (either pointed to by the
119 "oldest" variable). */
120 entries
[oldest
].time
= 0;
121 uip_ipaddr_copy(entries
[oldest
].ipaddr
, ipaddr
);
122 memcpy(&entries
[oldest
].addr
, addr
, sizeof(struct uip_neighbor_addr
));
124 /*---------------------------------------------------------------------------*/
125 static struct neighbor_entry
*
126 find_entry(uip_ipaddr_t ipaddr
)
130 for(i
= 0; i
< ENTRIES
; ++i
) {
131 if(uip_ipaddr_cmp(entries
[i
].ipaddr
, ipaddr
)) {
137 /*---------------------------------------------------------------------------*/
139 uip_neighbor_update(uip_ipaddr_t ipaddr
)
141 struct neighbor_entry
*e
;
143 e
= find_entry(ipaddr
);
148 /*---------------------------------------------------------------------------*/
149 struct uip_neighbor_addr
*
150 uip_neighbor_lookup(uip_ipaddr_t ipaddr
)
152 struct neighbor_entry
*e
;
154 e
= find_entry(ipaddr
);
156 /* printf("Lookup neighbor with link address %02x:%02x:%02x:%02x:%02x:%02x\n",
157 e->addr.addr.addr[0], e->addr.addr.addr[1], e->addr.addr.addr[2], e->addr.addr.addr[3],
158 e->addr.addr.addr[4], e->addr.addr.addr[5]);*/
164 /*---------------------------------------------------------------------------*/