Coverage Report

Created: 2026-02-21 06:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/frr/ospfd/ospf_dump_api.c
Line
Count
Source
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
/*
3
 * OSPFd dump routine (parts used by ospfclient).
4
 * Copyright (C) 1999, 2000 Toshiaki Takada
5
 */
6
7
#include <zebra.h>
8
9
#include "log.h"
10
#include "prefix.h"
11
12
#include "ospf_dump_api.h"
13
#include "ospfd.h"
14
#include "ospf_asbr.h"
15
#include "ospf_lsa.h"
16
#include "ospf_nsm.h"
17
#include "ospf_ism.h"
18
19
const struct message ospf_ism_state_msg[] = {
20
  {ISM_DependUpon, "DependUpon"},
21
  {ISM_Down, "Down"},
22
  {ISM_Loopback, "Loopback"},
23
  {ISM_Waiting, "Waiting"},
24
  {ISM_PointToPoint, "Point-To-Point"},
25
  {ISM_DROther, "DROther"},
26
  {ISM_Backup, "Backup"},
27
  {ISM_DR, "DR"},
28
  {0}};
29
30
const struct message ospf_nsm_state_msg[] = {{NSM_DependUpon, "DependUpon"},
31
               {NSM_Deleted, "Deleted"},
32
               {NSM_Down, "Down"},
33
               {NSM_Attempt, "Attempt"},
34
               {NSM_Init, "Init"},
35
               {NSM_TwoWay, "2-Way"},
36
               {NSM_ExStart, "ExStart"},
37
               {NSM_Exchange, "Exchange"},
38
               {NSM_Loading, "Loading"},
39
               {NSM_Full, "Full"},
40
               {0}};
41
42
const struct message ospf_lsa_type_msg[] = {
43
  {OSPF_UNKNOWN_LSA, "unknown"},
44
  {OSPF_ROUTER_LSA, "router-LSA"},
45
  {OSPF_NETWORK_LSA, "network-LSA"},
46
  {OSPF_SUMMARY_LSA, "summary-LSA"},
47
  {OSPF_ASBR_SUMMARY_LSA, "summary-LSA"},
48
  {OSPF_AS_EXTERNAL_LSA, "AS-external-LSA"},
49
  {OSPF_GROUP_MEMBER_LSA, "GROUP MEMBER LSA"},
50
  {OSPF_AS_NSSA_LSA, "NSSA-LSA"},
51
  {8, "Type-8 LSA"},
52
  {OSPF_OPAQUE_LINK_LSA, "Link-Local Opaque-LSA"},
53
  {OSPF_OPAQUE_AREA_LSA, "Area-Local Opaque-LSA"},
54
  {OSPF_OPAQUE_AS_LSA, "AS-external Opaque-LSA"},
55
  {0}};
56
57
const struct message ospf_link_state_id_type_msg[] = {
58
  {OSPF_UNKNOWN_LSA, "(unknown)"},
59
  {OSPF_ROUTER_LSA, ""},
60
  {OSPF_NETWORK_LSA, "(address of Designated Router)"},
61
  {OSPF_SUMMARY_LSA, "(summary Network Number)"},
62
  {OSPF_ASBR_SUMMARY_LSA, "(AS Boundary Router address)"},
63
  {OSPF_AS_EXTERNAL_LSA, "(External Network Number)"},
64
  {OSPF_GROUP_MEMBER_LSA, "(Group membership information)"},
65
  {OSPF_AS_NSSA_LSA, "(External Network Number for NSSA)"},
66
  {8, "(Type-8 LSID)"},
67
  {OSPF_OPAQUE_LINK_LSA, "(Link-Local Opaque-Type/ID)"},
68
  {OSPF_OPAQUE_AREA_LSA, "(Area-Local Opaque-Type/ID)"},
69
  {OSPF_OPAQUE_AS_LSA, "(AS-external Opaque-Type/ID)"},
70
  {0}};
71
72
const struct message ospf_network_type_msg[] = {
73
  {OSPF_IFTYPE_NONE, "NONE"},
74
  {OSPF_IFTYPE_POINTOPOINT, "Point-to-Point"},
75
  {OSPF_IFTYPE_BROADCAST, "Broadcast"},
76
  {OSPF_IFTYPE_NBMA, "NBMA"},
77
  {OSPF_IFTYPE_POINTOMULTIPOINT, "Point-to-MultiPoint"},
78
  {OSPF_IFTYPE_VIRTUALLINK, "Virtual-Link"},
79
  {0}};
80
81
/* AuType */
82
const struct message ospf_auth_type_str[] = {
83
  {OSPF_AUTH_NULL, "Null"},
84
  {OSPF_AUTH_SIMPLE, "Simple"},
85
  {OSPF_AUTH_CRYPTOGRAPHIC, "Cryptographic"},
86
  {0}};
87
88
#define OSPF_OPTION_STR_MAXLEN    24
89
90
char *ospf_options_dump(uint8_t options)
91
0
{
92
0
  static char buf[OSPF_OPTION_STR_MAXLEN];
93
94
0
  snprintf(buf, sizeof(buf), "*|%s|%s|%s|%s|%s|%s|%s",
95
0
     (options & OSPF_OPTION_O) ? "O" : "-",
96
0
     (options & OSPF_OPTION_DC) ? "DC" : "-",
97
0
     (options & OSPF_OPTION_EA) ? "EA" : "-",
98
0
     (options & OSPF_OPTION_NP) ? "N/P" : "-",
99
0
     (options & OSPF_OPTION_MC) ? "MC" : "-",
100
0
     (options & OSPF_OPTION_E) ? "E" : "-",
101
0
     (options & OSPF_OPTION_MT) ? "M/T" : "-");
102
103
0
  return buf;
104
0
}
105
106
void ospf_lsa_header_dump(struct lsa_header *lsah)
107
0
{
108
0
  const char *lsah_type = lookup_msg(ospf_lsa_type_msg, lsah->type, NULL);
109
110
0
  zlog_debug("  LSA Header");
111
0
  zlog_debug("    LS age %d", ntohs(lsah->ls_age));
112
0
  zlog_debug("    Options %d (%s)", lsah->options,
113
0
       ospf_options_dump(lsah->options));
114
0
  zlog_debug("    LS type %d (%s)", lsah->type,
115
0
       (lsah->type ? lsah_type : "unknown type"));
116
0
  zlog_debug("    Link State ID %pI4", &lsah->id);
117
0
  zlog_debug("    Advertising Router %pI4", &lsah->adv_router);
118
0
  zlog_debug("    LS sequence number 0x%lx",
119
0
       (unsigned long)ntohl(lsah->ls_seqnum));
120
0
  zlog_debug("    LS checksum 0x%x", ntohs(lsah->checksum));
121
0
  zlog_debug("    length %d", ntohs(lsah->length));
122
0
}