Deleted Added
full compact
print-ospf6.c (190207) print-ospf6.c (241235)
1/*
2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and

--- 146 unchanged lines hidden (view full) ---

155 ospf6_print_ls_type(EXTRACT_16BITS(&lshp->ls_type), &lshp->ls_stateid);
156
157 return (0);
158trunc:
159 return (1);
160}
161
162static int
1/*
2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and

--- 146 unchanged lines hidden (view full) ---

155 ospf6_print_ls_type(EXTRACT_16BITS(&lshp->ls_type), &lshp->ls_stateid);
156
157 return (0);
158trunc:
159 return (1);
160}
161
162static int
163ospf6_print_lsaprefix(register const struct lsa6_prefix *lsapp)
163ospf6_print_lsaprefix(const u_int8_t *tptr, u_int lsa_length)
164{
164{
165 const struct lsa6_prefix *lsapp = (struct lsa6_prefix *)tptr;
165 u_int wordlen;
166 struct in6_addr prefix;
167
166 u_int wordlen;
167 struct in6_addr prefix;
168
168 TCHECK(*lsapp);
169 if (lsa_length < sizeof (*lsapp) - 4)
170 goto trunc;
171 lsa_length -= sizeof (*lsapp) - 4;
172 TCHECK2(*lsapp, sizeof (*lsapp) - 4);
169 wordlen = (lsapp->lsa_p_len + 31) / 32;
170 if (wordlen * 4 > sizeof(struct in6_addr)) {
171 printf(" bogus prefixlen /%d", lsapp->lsa_p_len);
172 goto trunc;
173 }
173 wordlen = (lsapp->lsa_p_len + 31) / 32;
174 if (wordlen * 4 > sizeof(struct in6_addr)) {
175 printf(" bogus prefixlen /%d", lsapp->lsa_p_len);
176 goto trunc;
177 }
178 if (lsa_length < wordlen * 4)
179 goto trunc;
180 lsa_length -= wordlen * 4;
181 TCHECK2(lsapp->lsa_p_prefix, wordlen * 4);
174 memset(&prefix, 0, sizeof(prefix));
175 memcpy(&prefix, lsapp->lsa_p_prefix, wordlen * 4);
176 printf("\n\t\t%s/%d", ip6addr_string(&prefix),
177 lsapp->lsa_p_len);
178 if (lsapp->lsa_p_opt) {
179 printf(", Options [%s]",
180 bittok2str(ospf6_lsa_prefix_option_values,
181 "none", lsapp->lsa_p_opt));

--- 7 unchanged lines hidden (view full) ---

189
190
191/*
192 * Print a single link state advertisement. If truncated return 1, else 0.
193 */
194static int
195ospf6_print_lsa(register const struct lsa6 *lsap)
196{
182 memset(&prefix, 0, sizeof(prefix));
183 memcpy(&prefix, lsapp->lsa_p_prefix, wordlen * 4);
184 printf("\n\t\t%s/%d", ip6addr_string(&prefix),
185 lsapp->lsa_p_len);
186 if (lsapp->lsa_p_opt) {
187 printf(", Options [%s]",
188 bittok2str(ospf6_lsa_prefix_option_values,
189 "none", lsapp->lsa_p_opt));

--- 7 unchanged lines hidden (view full) ---

197
198
199/*
200 * Print a single link state advertisement. If truncated return 1, else 0.
201 */
202static int
203ospf6_print_lsa(register const struct lsa6 *lsap)
204{
197 register const u_char *ls_end, *ls_opt;
198 register const struct rlalink6 *rlp;
199#if 0
200 register const struct tos_metric *tosp;
201#endif
202 register const rtrid_t *ap;
203#if 0
204 register const struct aslametric *almp;
205 register const struct mcla *mcp;
206#endif
207 register const struct llsa *llsap;
208 register const struct lsa6_prefix *lsapp;
209#if 0
210 register const u_int32_t *lp;
211#endif
212 register u_int prefixes;
205 register const struct rlalink6 *rlp;
206#if 0
207 register const struct tos_metric *tosp;
208#endif
209 register const rtrid_t *ap;
210#if 0
211 register const struct aslametric *almp;
212 register const struct mcla *mcp;
213#endif
214 register const struct llsa *llsap;
215 register const struct lsa6_prefix *lsapp;
216#if 0
217 register const u_int32_t *lp;
218#endif
219 register u_int prefixes;
213 register int bytelen, length, lsa_length;
220 register int bytelen;
221 register u_int length, lsa_length;
214 u_int32_t flags32;
222 u_int32_t flags32;
215 u_int8_t *tptr;
223 const u_int8_t *tptr;
216
217 if (ospf6_print_lshdr(&lsap->ls_hdr))
218 return (1);
219 TCHECK(lsap->ls_hdr.ls_length);
220 length = EXTRACT_16BITS(&lsap->ls_hdr.ls_length);
224
225 if (ospf6_print_lshdr(&lsap->ls_hdr))
226 return (1);
227 TCHECK(lsap->ls_hdr.ls_length);
228 length = EXTRACT_16BITS(&lsap->ls_hdr.ls_length);
229
230 /*
231 * The LSA length includes the length of the header;
232 * it must have a value that's at least that length.
233 * If it does, find the length of what follows the
234 * header.
235 */
236 if (length < sizeof(struct lsa6_hdr))
237 return (1);
221 lsa_length = length - sizeof(struct lsa6_hdr);
238 lsa_length = length - sizeof(struct lsa6_hdr);
222 ls_end = (u_char *)lsap + length;
223 tptr = (u_int8_t *)lsap+sizeof(struct lsa6_hdr);
224
225 switch (EXTRACT_16BITS(&lsap->ls_hdr.ls_type)) {
226 case LS_TYPE_ROUTER | LS_SCOPE_AREA:
239 tptr = (u_int8_t *)lsap+sizeof(struct lsa6_hdr);
240
241 switch (EXTRACT_16BITS(&lsap->ls_hdr.ls_type)) {
242 case LS_TYPE_ROUTER | LS_SCOPE_AREA:
243 if (lsa_length < sizeof (lsap->lsa_un.un_rla.rla_options))
244 return (1);
245 lsa_length -= sizeof (lsap->lsa_un.un_rla.rla_options);
227 TCHECK(lsap->lsa_un.un_rla.rla_options);
228 printf("\n\t Options [%s]",
229 bittok2str(ospf6_option_values, "none",
230 EXTRACT_32BITS(&lsap->lsa_un.un_rla.rla_options)));
246 TCHECK(lsap->lsa_un.un_rla.rla_options);
247 printf("\n\t Options [%s]",
248 bittok2str(ospf6_option_values, "none",
249 EXTRACT_32BITS(&lsap->lsa_un.un_rla.rla_options)));
231
232 TCHECK(lsap->lsa_un.un_rla.rla_flags);
233 printf(", RLA-Flags [%s]",
234 bittok2str(ospf6_rla_flag_values, "none",
235 lsap->lsa_un.un_rla.rla_flags));
236
250 printf(", RLA-Flags [%s]",
251 bittok2str(ospf6_rla_flag_values, "none",
252 lsap->lsa_un.un_rla.rla_flags));
253
237
238 TCHECK(lsap->lsa_un.un_rla.rla_link);
239 rlp = lsap->lsa_un.un_rla.rla_link;
254 rlp = lsap->lsa_un.un_rla.rla_link;
240 while (rlp + 1 <= (struct rlalink6 *)ls_end) {
255 while (lsa_length != 0) {
256 if (lsa_length < sizeof (*rlp))
257 return (1);
258 lsa_length -= sizeof (*rlp);
241 TCHECK(*rlp);
242 switch (rlp->link_type) {
243
244 case RLA_TYPE_VIRTUAL:
245 printf("\n\t Virtual Link: Neighbor Router-ID %s"
246 "\n\t Neighbor Interface-ID %s, Interface %s",
247 ipaddr_string(&rlp->link_nrtid),
248 ipaddr_string(&rlp->link_nifid),

--- 22 unchanged lines hidden (view full) ---

271 return (0);
272 }
273 printf(", metric %d", EXTRACT_16BITS(&rlp->link_metric));
274 rlp++;
275 }
276 break;
277
278 case LS_TYPE_NETWORK | LS_SCOPE_AREA:
259 TCHECK(*rlp);
260 switch (rlp->link_type) {
261
262 case RLA_TYPE_VIRTUAL:
263 printf("\n\t Virtual Link: Neighbor Router-ID %s"
264 "\n\t Neighbor Interface-ID %s, Interface %s",
265 ipaddr_string(&rlp->link_nrtid),
266 ipaddr_string(&rlp->link_nifid),

--- 22 unchanged lines hidden (view full) ---

289 return (0);
290 }
291 printf(", metric %d", EXTRACT_16BITS(&rlp->link_metric));
292 rlp++;
293 }
294 break;
295
296 case LS_TYPE_NETWORK | LS_SCOPE_AREA:
297 if (lsa_length < sizeof (lsap->lsa_un.un_nla.nla_options))
298 return (1);
299 lsa_length -= sizeof (lsap->lsa_un.un_nla.nla_options);
279 TCHECK(lsap->lsa_un.un_nla.nla_options);
280 printf("\n\t Options [%s]",
281 bittok2str(ospf6_option_values, "none",
282 EXTRACT_32BITS(&lsap->lsa_un.un_nla.nla_options)));
300 TCHECK(lsap->lsa_un.un_nla.nla_options);
301 printf("\n\t Options [%s]",
302 bittok2str(ospf6_option_values, "none",
303 EXTRACT_32BITS(&lsap->lsa_un.un_nla.nla_options)));
304
283 printf("\n\t Connected Routers:");
284 ap = lsap->lsa_un.un_nla.nla_router;
305 printf("\n\t Connected Routers:");
306 ap = lsap->lsa_un.un_nla.nla_router;
285 while ((u_char *)ap < ls_end) {
307 while (lsa_length != 0) {
308 if (lsa_length < sizeof (*ap))
309 return (1);
310 lsa_length -= sizeof (*ap);
286 TCHECK(*ap);
287 printf("\n\t\t%s", ipaddr_string(ap));
288 ++ap;
289 }
290 break;
291
292 case LS_TYPE_INTER_AP | LS_SCOPE_AREA:
311 TCHECK(*ap);
312 printf("\n\t\t%s", ipaddr_string(ap));
313 ++ap;
314 }
315 break;
316
317 case LS_TYPE_INTER_AP | LS_SCOPE_AREA:
318 if (lsa_length < sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric))
319 return (1);
320 lsa_length -= sizeof (lsap->lsa_un.un_inter_ap.inter_ap_metric);
293 TCHECK(lsap->lsa_un.un_inter_ap.inter_ap_metric);
294 printf(", metric %u",
295 EXTRACT_32BITS(&lsap->lsa_un.un_inter_ap.inter_ap_metric) & SLA_MASK_METRIC);
321 TCHECK(lsap->lsa_un.un_inter_ap.inter_ap_metric);
322 printf(", metric %u",
323 EXTRACT_32BITS(&lsap->lsa_un.un_inter_ap.inter_ap_metric) & SLA_MASK_METRIC);
296 lsapp = lsap->lsa_un.un_inter_ap.inter_ap_prefix;
297 while (lsapp + sizeof(lsapp) <= (struct lsa6_prefix *)ls_end) {
298 bytelen = ospf6_print_lsaprefix(lsapp);
299 if (bytelen)
324
325 tptr = (u_int8_t *)lsap->lsa_un.un_inter_ap.inter_ap_prefix;
326 while (lsa_length != 0) {
327 bytelen = ospf6_print_lsaprefix(tptr, lsa_length);
328 if (bytelen < 0)
300 goto trunc;
329 goto trunc;
301 lsapp = (struct lsa6_prefix *)(((u_char *)lsapp) + bytelen);
330 lsa_length -= bytelen;
331 tptr += bytelen;
302 }
303 break;
332 }
333 break;
304 case LS_SCOPE_AS | LS_TYPE_ASE:
334
335 case LS_TYPE_ASE | LS_SCOPE_AS:
336 if (lsa_length < sizeof (lsap->lsa_un.un_asla.asla_metric))
337 return (1);
338 lsa_length -= sizeof (lsap->lsa_un.un_asla.asla_metric);
305 TCHECK(lsap->lsa_un.un_asla.asla_metric);
306 flags32 = EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric);
307 printf("\n\t Flags [%s]",
308 bittok2str(ospf6_asla_flag_values, "none", flags32));
309 printf(" metric %u",
310 EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric) &
311 ASLA_MASK_METRIC);
339 TCHECK(lsap->lsa_un.un_asla.asla_metric);
340 flags32 = EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric);
341 printf("\n\t Flags [%s]",
342 bittok2str(ospf6_asla_flag_values, "none", flags32));
343 printf(" metric %u",
344 EXTRACT_32BITS(&lsap->lsa_un.un_asla.asla_metric) &
345 ASLA_MASK_METRIC);
312 lsapp = lsap->lsa_un.un_asla.asla_prefix;
313 bytelen = ospf6_print_lsaprefix(lsapp);
346
347 tptr = (u_int8_t *)lsap->lsa_un.un_asla.asla_prefix;
348 lsapp = (struct lsa6_prefix *)tptr;
349 bytelen = ospf6_print_lsaprefix(tptr, lsa_length);
314 if (bytelen < 0)
315 goto trunc;
350 if (bytelen < 0)
351 goto trunc;
316 if ((ls_opt = (u_char *)(((u_char *)lsapp) + bytelen)) < ls_end) {
352 lsa_length -= bytelen;
353 tptr += bytelen;
354
355 if ((flags32 & ASLA_FLAG_FWDADDR) != 0) {
317 struct in6_addr *fwdaddr6;
318
356 struct in6_addr *fwdaddr6;
357
319 if ((flags32 & ASLA_FLAG_FWDADDR) != 0) {
320 fwdaddr6 = (struct in6_addr *)ls_opt;
321 TCHECK(*fwdaddr6);
322 printf(" forward %s",
323 ip6addr_string(fwdaddr6));
358 fwdaddr6 = (struct in6_addr *)tptr;
359 if (lsa_length < sizeof (*fwdaddr6))
360 return (1);
361 lsa_length -= sizeof (*fwdaddr6);
362 TCHECK(*fwdaddr6);
363 printf(" forward %s",
364 ip6addr_string(fwdaddr6));
365 tptr += sizeof(*fwdaddr6);
366 }
324
367
325 ls_opt += sizeof(struct in6_addr);
326 }
368 if ((flags32 & ASLA_FLAG_ROUTETAG) != 0) {
369 if (lsa_length < sizeof (u_int32_t))
370 return (1);
371 lsa_length -= sizeof (u_int32_t);
372 TCHECK(*(u_int32_t *)tptr);
373 printf(" tag %s",
374 ipaddr_string((u_int32_t *)tptr));
375 tptr += sizeof(u_int32_t);
376 }
327
377
328 if ((flags32 & ASLA_FLAG_ROUTETAG) != 0) {
329 TCHECK(*(u_int32_t *)ls_opt);
330 printf(" tag %s",
331 ipaddr_string((u_int32_t *)ls_opt));
332
333 ls_opt += sizeof(u_int32_t);
334 }
335
336 if (lsapp->lsa_p_metric) {
337 TCHECK(*(u_int32_t *)ls_opt);
338 printf(" RefLSID: %s",
339 ipaddr_string((u_int32_t *)ls_opt));
340
341 ls_opt += sizeof(u_int32_t);
342 }
378 if (lsapp->lsa_p_metric) {
379 if (lsa_length < sizeof (u_int32_t))
380 return (1);
381 lsa_length -= sizeof (u_int32_t);
382 TCHECK(*(u_int32_t *)tptr);
383 printf(" RefLSID: %s",
384 ipaddr_string((u_int32_t *)tptr));
385 tptr += sizeof(u_int32_t);
343 }
344 break;
345
346 case LS_TYPE_LINK:
347 /* Link LSA */
348 llsap = &lsap->lsa_un.un_llsa;
386 }
387 break;
388
389 case LS_TYPE_LINK:
390 /* Link LSA */
391 llsap = &lsap->lsa_un.un_llsa;
349 TCHECK(llsap->llsa_options);
392 if (lsa_length < sizeof (llsap->llsa_priandopt))
393 return (1);
394 lsa_length -= sizeof (llsap->llsa_priandopt);
395 TCHECK(llsap->llsa_priandopt);
350 printf("\n\t Options [%s]",
351 bittok2str(ospf6_option_values, "none",
352 EXTRACT_32BITS(&llsap->llsa_options)));
396 printf("\n\t Options [%s]",
397 bittok2str(ospf6_option_values, "none",
398 EXTRACT_32BITS(&llsap->llsa_options)));
353 TCHECK(llsap->llsa_nprefix);
399
400 if (lsa_length < sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix))
401 return (1);
402 lsa_length -= sizeof (llsap->llsa_lladdr) + sizeof (llsap->llsa_nprefix);
354 prefixes = EXTRACT_32BITS(&llsap->llsa_nprefix);
355 printf("\n\t Priority %d, Link-local address %s, Prefixes %d:",
356 llsap->llsa_priority,
357 ip6addr_string(&llsap->llsa_lladdr),
358 prefixes);
359
360 tptr = (u_int8_t *)llsap->llsa_prefix;
403 prefixes = EXTRACT_32BITS(&llsap->llsa_nprefix);
404 printf("\n\t Priority %d, Link-local address %s, Prefixes %d:",
405 llsap->llsa_priority,
406 ip6addr_string(&llsap->llsa_lladdr),
407 prefixes);
408
409 tptr = (u_int8_t *)llsap->llsa_prefix;
361 while (prefixes > 0) {
362 lsapp = (struct lsa6_prefix *)tptr;
363 if ((bytelen = ospf6_print_lsaprefix(lsapp)) == -1) {
364 goto trunc;
365 }
366 prefixes--;
367 tptr += bytelen;
368 }
410 while (prefixes > 0) {
411 bytelen = ospf6_print_lsaprefix(tptr, lsa_length);
412 if (bytelen < 0)
413 goto trunc;
414 prefixes--;
415 lsa_length -= bytelen;
416 tptr += bytelen;
417 }
369 break;
370
371 case LS_TYPE_INTRA_AP | LS_SCOPE_AREA:
372 /* Intra-Area-Prefix LSA */
418 break;
419
420 case LS_TYPE_INTRA_AP | LS_SCOPE_AREA:
421 /* Intra-Area-Prefix LSA */
422 if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid))
423 return (1);
424 lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_rtid);
373 TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_rtid);
374 ospf6_print_ls_type(
375 EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_lstype),
376 &lsap->lsa_un.un_intra_ap.intra_ap_lsid);
425 TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_rtid);
426 ospf6_print_ls_type(
427 EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_lstype),
428 &lsap->lsa_un.un_intra_ap.intra_ap_lsid);
429
430 if (lsa_length < sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix))
431 return (1);
432 lsa_length -= sizeof (lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
377 TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
378 prefixes = EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
379 printf("\n\t Prefixes %d:", prefixes);
380
433 TCHECK(lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
434 prefixes = EXTRACT_16BITS(&lsap->lsa_un.un_intra_ap.intra_ap_nprefix);
435 printf("\n\t Prefixes %d:", prefixes);
436
381 tptr = (u_int8_t *)lsap->lsa_un.un_intra_ap.intra_ap_prefix;
382
383 while (prefixes > 0) {
384 lsapp = (struct lsa6_prefix *)tptr;
385 if ((bytelen = ospf6_print_lsaprefix(lsapp)) == -1) {
386 goto trunc;
387 }
388 prefixes--;
389 tptr += bytelen;
390 }
437 tptr = (u_int8_t *)lsap->lsa_un.un_intra_ap.intra_ap_prefix;
438 while (prefixes > 0) {
439 bytelen = ospf6_print_lsaprefix(tptr, lsa_length);
440 if (bytelen < 0)
441 goto trunc;
442 prefixes--;
443 lsa_length -= bytelen;
444 tptr += bytelen;
445 }
391 break;
392
393 case LS_TYPE_GRACE | LS_SCOPE_LINKLOCAL:
394 if (ospf_print_grace_lsa(tptr, lsa_length) == -1) {
395 return 1;
396 }
446 break;
447
448 case LS_TYPE_GRACE | LS_SCOPE_LINKLOCAL:
449 if (ospf_print_grace_lsa(tptr, lsa_length) == -1) {
450 return 1;
451 }
397
398 break;
452 break;
399
400 case LS_TYPE_INTRA_ATE | LS_SCOPE_LINKLOCAL:
453
454 case LS_TYPE_INTRA_ATE | LS_SCOPE_LINKLOCAL:
401 if (ospf_print_te_lsa(tptr, lsa_length) == -1) {
402 return 1;
403 }
404 break;
455 if (ospf_print_te_lsa(tptr, lsa_length) == -1) {
456 return 1;
457 }
458 break;
405
406 default:
459
460 default:
407 if(!print_unknown_data(tptr,
408 "\n\t ",
409 lsa_length)) {
410 return (1);
411 }
461 if(!print_unknown_data(tptr,
462 "\n\t ",
463 lsa_length)) {
464 return (1);
465 }
466 break;
412 }
413
414 return (0);
415trunc:
416 return (1);
417}
418
419static int

--- 170 unchanged lines hidden ---
467 }
468
469 return (0);
470trunc:
471 return (1);
472}
473
474static int

--- 170 unchanged lines hidden ---