Commits
Denis Ovsienko authored 0342b76cfbf Merge
118 118 | route_node_free (tmp_node); |
119 119 | break; |
120 120 | } |
121 121 | } |
122 122 | |
123 123 | XFREE (MTYPE_ROUTE_TABLE, rt); |
124 124 | return; |
125 125 | } |
126 126 | |
127 127 | /* Utility mask array. */ |
128 - | static u_char maskbit[] = |
128 + | static const u_char maskbit[] = |
129 129 | { |
130 130 | 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff |
131 131 | }; |
132 132 | |
133 133 | /* Common prefix route genaration. */ |
134 134 | static void |
135 135 | route_common (struct prefix *n, struct prefix *p, struct prefix *new) |
136 136 | { |
137 137 | int i; |
138 138 | u_char diff; |
163 163 | } |
164 164 | newp[i] = np[i] & maskbit[new->prefixlen % 8]; |
165 165 | } |
166 166 | } |
167 167 | |
168 168 | /* Macro version of check_bit (). */ |
169 169 | |
170 170 | |
171 171 | /* Check bit of the prefix. */ |
172 172 | static int |
173 - | check_bit (u_char *prefix, u_char prefixlen) |
173 + | check_bit (const u_char *prefix, u_char prefixlen) |
174 174 | { |
175 - | int offset; |
176 - | int shift; |
177 - | u_char *p = (u_char *)prefix; |
175 + | unsigned int offset; |
176 + | unsigned int shift; |
177 + | const u_char *p = prefix; |
178 178 | |
179 179 | assert (prefixlen <= 128); |
180 180 | |
181 181 | offset = prefixlen / 8; |
182 182 | shift = 7 - (prefixlen % 8); |
183 183 | |
184 184 | return (p[offset] >> shift & 1); |
185 185 | } |
186 186 | |
187 187 | /* Macro version of set_link (). */ |
214 214 | route_unlock_node (struct route_node *node) |
215 215 | { |
216 216 | node->lock--; |
217 217 | |
218 218 | if (node->lock == 0) |
219 219 | route_node_delete (node); |
220 220 | } |
221 221 | |
222 222 | /* Find matched prefix. */ |
223 223 | struct route_node * |
224 - | route_node_match (struct route_table *table, struct prefix *p) |
224 + | route_node_match (const struct route_table *table, const struct prefix *p) |
225 225 | { |
226 226 | struct route_node *node; |
227 227 | struct route_node *matched; |
228 228 | |
229 229 | matched = NULL; |
230 230 | node = table->top; |
231 231 | |
232 232 | /* Walk down tree. If there is matched route then store it to |
233 233 | matched. */ |
234 234 | while (node && node->p.prefixlen <= p->prefixlen && |
240 240 | } |
241 241 | |
242 242 | /* If matched route found, return it. */ |
243 243 | if (matched) |
244 244 | return route_lock_node (matched); |
245 245 | |
246 246 | return NULL; |
247 247 | } |
248 248 | |
249 249 | struct route_node * |
250 - | route_node_match_ipv4 (struct route_table *table, struct in_addr *addr) |
250 + | route_node_match_ipv4 (const struct route_table *table, |
251 + | const struct in_addr *addr) |
251 252 | { |
252 253 | struct prefix_ipv4 p; |
253 254 | |
254 255 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
255 256 | p.family = AF_INET; |
256 257 | p.prefixlen = IPV4_MAX_PREFIXLEN; |
257 258 | p.prefix = *addr; |
258 259 | |
259 260 | return route_node_match (table, (struct prefix *) &p); |
260 261 | } |
261 262 | |
262 263 | |
263 264 | struct route_node * |
264 - | route_node_match_ipv6 (struct route_table *table, struct in6_addr *addr) |
265 + | route_node_match_ipv6 (const struct route_table *table, |
266 + | const struct in6_addr *addr) |
265 267 | { |
266 268 | struct prefix_ipv6 p; |
267 269 | |
268 270 | memset (&p, 0, sizeof (struct prefix_ipv6)); |
269 271 | p.family = AF_INET6; |
270 272 | p.prefixlen = IPV6_MAX_PREFIXLEN; |
271 273 | p.prefix = *addr; |
272 274 | |
273 275 | return route_node_match (table, (struct prefix *) &p); |
274 276 | } |