1 /*
2  * The olsr.org Optimized Link-State Routing daemon (olsrd)
3  *
4  * (c) by the OLSR project
5  *
6  * See our Git repository to find out who worked on this file
7  * and thus is a copyright holder on it.
8  *
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * * Redistributions of source code must retain the above copyright
16  *   notice, this list of conditions and the following disclaimer.
17  * * Redistributions in binary form must reproduce the above copyright
18  *   notice, this list of conditions and the following disclaimer in
19  *   the documentation and/or other materials provided with the
20  *   distribution.
21  * * Neither the name of olsr.org, olsrd nor the names of its
22  *   contributors may be used to endorse or promote products derived
23  *   from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  *
38  * Visit http://www.olsr.org for more information.
39  *
40  * If you find this software useful feel free to make a donation
41  * to the project. For more information see the website or contact
42  * the copyright holders.
43  *
44  */
45 
46 #ifndef _OLSR_NEIGH_TBL
47 #define _OLSR_NEIGH_TBL
48 
49 #include "olsr_types.h"
50 #include "hashing.h"
51 #include "two_hop_neighbor_table.h"
52 
53 struct neighbor_2_list_entry {
54   struct neighbor_entry *nbr2_nbr;     /* backpointer to owning nbr entry */
55   struct neighbor_2_entry *neighbor_2;
56   struct timer_entry *nbr2_list_timer;
57   struct neighbor_2_list_entry *next;
58   struct neighbor_2_list_entry *prev;
59 };
60 
61 #define OLSR_NBR2_LIST_JITTER 5 /* percent */
62 
63 struct neighbor_entry {
64   union olsr_ip_addr neighbor_main_addr;
65   uint8_t status;
66   uint8_t willingness;
67   bool is_mpr;
68   bool was_mpr;                        /* Used to detect changes in MPR */
69   bool skip;
70   int neighbor_2_nocov;
71   int linkcount;
72   struct neighbor_2_list_entry neighbor_2_list;
73   struct neighbor_entry *next;
74   struct neighbor_entry *prev;
75 };
76 
77 #define OLSR_FOR_ALL_NBR_ENTRIES(nbr) \
78 { \
79   int _idx; \
80   for (_idx = 0; _idx < HASHSIZE; _idx++) { \
81     for(nbr = neighbortable[_idx].next; \
82         nbr != &neighbortable[_idx]; \
83         nbr = nbr->next)
84 #define OLSR_FOR_ALL_NBR_ENTRIES_END(nbr) }}
85 
86 /*
87  * The neighbor table
88  */
89 extern struct neighbor_entry neighbortable[HASHSIZE];
90 
91 void olsr_init_neighbor_table(void);
92 
93 int olsr_delete_neighbor_2_pointer(struct neighbor_entry *, struct neighbor_2_entry *);
94 
95 struct neighbor_2_list_entry *olsr_lookup_my_neighbors(const struct neighbor_entry *, const union olsr_ip_addr *);
96 
97 int olsr_delete_neighbor_table(const union olsr_ip_addr *);
98 
99 struct neighbor_entry *olsr_insert_neighbor_table(const union olsr_ip_addr *);
100 
101 struct neighbor_entry *olsr_lookup_neighbor_table(const union olsr_ip_addr *);
102 
103 struct neighbor_entry *olsr_lookup_neighbor_table_alias(const union olsr_ip_addr *);
104 
105 void olsr_time_out_two_hop_neighbors(struct neighbor_entry *);
106 
107 void olsr_time_out_neighborhood_tables(void);
108 void olsr_expire_nbr2_list(void *);
109 
110 #ifndef NODEBUG
111 void olsr_print_neighbor_table(void);
112 #else
113 #define olsr_print_neighbor_table() do { } while(0)
114 #endif
115 
116 void olsr_update_neighbor_main_addr(struct neighbor_entry *, const union olsr_ip_addr *);
117 
118 int update_neighbor_status(struct neighbor_entry *, int);
119 
120 #endif /* _OLSR_NEIGH_TBL */
121 
122 /*
123  * Local Variables:
124  * c-basic-offset: 2
125  * indent-tabs-mode: nil
126  * End:
127  */
128