Skip to content

Commit

Permalink
isisd: Add isis_errors and generate custom Error Codes
Browse files Browse the repository at this point in the history
Generate appropriate error codes for ISIS.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
  • Loading branch information
donaldsharp committed Jun 18, 2018
1 parent 6b29bfa commit 8578990
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 39 deletions.
8 changes: 6 additions & 2 deletions isisd/isis_circuit.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "isisd/isis_events.h"
#include "isisd/isis_te.h"
#include "isisd/isis_mt.h"
#include "isisd/isis_errors.h"

DEFINE_QOBJ_TYPE(isis_circuit)

Expand Down Expand Up @@ -566,7 +567,8 @@ int isis_circuit_up(struct isis_circuit *circuit)
return ISIS_OK;

if (circuit->area->lsp_mtu > isis_circuit_pdu_size(circuit)) {
zlog_err(
zlog_ferr(
ISIS_ERR_CONFIG,
"Interface MTU %zu on %s is too low to support area lsp mtu %u!",
isis_circuit_pdu_size(circuit),
circuit->interface->name, circuit->area->lsp_mtu);
Expand All @@ -577,7 +579,9 @@ int isis_circuit_up(struct isis_circuit *circuit)
if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
circuit->circuit_id = isis_circuit_id_gen(isis, circuit->interface);
if (!circuit->circuit_id) {
zlog_err("There are already 255 broadcast circuits active!");
zlog_ferr(
ISIS_ERR_CONFIG,
"There are already 255 broadcast circuits active!");
return ISIS_ERROR;
}

Expand Down
7 changes: 5 additions & 2 deletions isisd/isis_csm.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "isisd/isisd.h"
#include "isisd/isis_csm.h"
#include "isisd/isis_events.h"
#include "isisd/isis_errors.h"

extern struct isis *isis;

Expand Down Expand Up @@ -137,10 +138,12 @@ isis_csm_state_change(int event, struct isis_circuit *circuit, void *arg)
case IF_UP_FROM_Z:
isis_circuit_if_add(circuit, (struct interface *)arg);
if (isis_circuit_up(circuit) != ISIS_OK) {
zlog_err(
zlog_ferr(
ISIS_ERR_CONFIG,
"Could not bring up %s because of invalid config.",
circuit->interface->name);
zlog_err(
zlog_ferr(
ISIS_ERR_CONFIG,
"Clearing config for %s. Please re-examine it.",
circuit->interface->name);
if (circuit->ip_router) {
Expand Down
48 changes: 48 additions & 0 deletions isisd/isis_errors.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* isis_errors - code for error messages that may occur in the
* isis process
* Copyright (C) 2018 Cumulus Networks, Inc.
* Donald Sharp
*
* FRR is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* FRR is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>

#include "isis_errors.h"

static struct ferr_ref ferr_isis_err[] = {
{
.code = ISIS_ERR_PACKET,
.title = "ISIS Packet Error",
.description = "Isis has detected an error with a packet from a peer",
.suggestion = "Gather log information and open an issue then restart FRR"
},
{
.code = ISIS_ERR_CONFIG,
.title = "ISIS Configuration Error",
.description = "Isis has detected an error within configuration for the router",
.suggestion = "Ensure configuration is correct"
},
{
.code = END_FERR,
}
};

void isis_error_init(void)
{
ferr_ref_init();

ferr_ref_add(ferr_isis_err);
}
33 changes: 33 additions & 0 deletions isisd/isis_errors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* isis_errors - header for error messages that may occur in the isis process
* Copyright (C) 2018 Cumulus Networks, Inc.
* Donald Sharp
*
* FRR is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* FRR is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __ISIS_ERRORS_H__
#define __ISIS_ERRORS_H__

#include "ferr.h"
#include "isis_errors.h"

enum isis_ferr_refs {
ISIS_ERR_PACKET = ISIS_FERR_START,
ISIS_ERR_CONFIG,
};

extern void isis_error_init(void);

#endif
7 changes: 4 additions & 3 deletions isisd/isis_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "isisd/isis_csm.h"
#include "isisd/isis_events.h"
#include "isisd/isis_spf.h"
#include "isisd/isis_errors.h"

/* debug isis-spf spf-events
4w4d: ISIS-Spf (tlt): L2 SPF needed, new adjacency, from 0x609229F4
Expand Down Expand Up @@ -156,9 +157,9 @@ void isis_circuit_is_type_set(struct isis_circuit *circuit, int newtype)
return; /* No change */

if (!(newtype & circuit->area->is_type)) {
zlog_err(
"ISIS-Evt (%s) circuit type change - invalid level %s because"
" area is %s",
zlog_ferr(
ISIS_ERR_CONFIG,
"ISIS-Evt (%s) circuit type change - invalid level %s because area is %s",
circuit->area->area_tag, circuit_t2string(newtype),
circuit_t2string(circuit->area->is_type));
return;
Expand Down
10 changes: 6 additions & 4 deletions isisd/isis_lsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1233,8 +1233,9 @@ static int lsp_regenerate(struct isis_area *area, int level)
lsp = lsp_search(lspid, lspdb);

if (!lsp) {
zlog_err("ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!",
area->area_tag, level);
zlog_ferr(LIB_ERR_DEVELOPMENT,
"ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!",
area->area_tag, level);
return ISIS_ERROR;
}

Expand Down Expand Up @@ -1601,8 +1602,9 @@ static int lsp_regenerate_pseudo(struct isis_circuit *circuit, int level)
lsp = lsp_search(lsp_id, lspdb);

if (!lsp) {
zlog_err("lsp_regenerate_pseudo: no l%d LSP %s found!", level,
rawlspid_print(lsp_id));
zlog_ferr(LIB_ERR_DEVELOPMENT,
"lsp_regenerate_pseudo: no l%d LSP %s found!", level,
rawlspid_print(lsp_id));
return ISIS_ERROR;
}

Expand Down
2 changes: 2 additions & 0 deletions isisd/isis_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "isisd/isis_routemap.h"
#include "isisd/isis_zebra.h"
#include "isisd/isis_te.h"
#include "isisd/isis_errors.h"

/* Default configuration file name */
#define ISISD_DEFAULT_CONFIG "isisd.conf"
Expand Down Expand Up @@ -189,6 +190,7 @@ int main(int argc, char **argv, char **envp)
/*
* initializations
*/
isis_error_init();
access_list_init();
vrf_init(NULL, NULL, NULL, NULL);
prefix_list_init();
Expand Down
69 changes: 41 additions & 28 deletions isisd/isis_pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "isisd/isis_te.h"
#include "isisd/isis_mt.h"
#include "isisd/isis_tlvs.h"
#include "isisd/isis_errors.h"

static int ack_lsp(struct isis_lsp_hdr *hdr, struct isis_circuit *circuit,
int level)
Expand Down Expand Up @@ -87,9 +88,10 @@ static int ack_lsp(struct isis_lsp_hdr *hdr, struct isis_circuit *circuit,

retval = circuit->tx(circuit, level);
if (retval != ISIS_OK)
zlog_err("ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
circuit->area->area_tag, level,
circuit->interface->name);
zlog_ferr(ISIS_ERR_PACKET,
"ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
circuit->area->area_tag, level,
circuit->interface->name);

return retval;
}
Expand Down Expand Up @@ -615,8 +617,9 @@ static int process_hello(uint8_t pdu_type, struct isis_circuit *circuit,
}

if (!p2p_hello && !(level & iih.circ_type)) {
zlog_err("Level %d LAN Hello with Circuit Type %d", level,
iih.circ_type);
zlog_ferr(ISIS_ERR_PACKET,
"Level %d LAN Hello with Circuit Type %d", level,
iih.circ_type);
return ISIS_ERROR;
}

Expand Down Expand Up @@ -1344,7 +1347,7 @@ int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa)

/* Verify that at least the 8 bytes fixed header have been received */
if (stream_get_endp(circuit->rcv_stream) < ISIS_FIXED_HDR_LEN) {
zlog_err("PDU is too short to be IS-IS.");
zlog_ferr(ISIS_ERR_PACKET, "PDU is too short to be IS-IS.");
return ISIS_ERROR;
}

Expand All @@ -1365,7 +1368,8 @@ int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa)
}

if (idrp != ISO10589_ISIS) {
zlog_err("Not an IS-IS packet IDRP=%" PRIx8, idrp);
zlog_ferr(ISIS_ERR_PACKET, "Not an IS-IS packet IDRP=%" PRIx8,
idrp);
return ISIS_ERROR;
}

Expand All @@ -1375,7 +1379,8 @@ int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa)
}

if (id_len != 0 && id_len != ISIS_SYS_ID_LEN) {
zlog_err(
zlog_ferr(
ISIS_ERR_PACKET,
"IDFieldLengthMismatch: ID Length field in a received PDU %" PRIu8
", while the parameter for this IS is %u",
id_len, ISIS_SYS_ID_LEN);
Expand All @@ -1389,14 +1394,16 @@ int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa)
}

if (length != expected_length) {
zlog_err("Exepected fixed header length = %" PRIu8
" but got %" PRIu8,
expected_length, length);
zlog_ferr(ISIS_ERR_PACKET,
"Exepected fixed header length = %" PRIu8
" but got %" PRIu8,
expected_length, length);
return ISIS_ERROR;
}

if (stream_get_endp(circuit->rcv_stream) < length) {
zlog_err(
zlog_ferr(
ISIS_ERR_PACKET,
"PDU is too short to contain fixed header of given PDU type.");
return ISIS_ERROR;
}
Expand All @@ -1414,7 +1421,8 @@ int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa)

/* either 3 or 0 */
if (max_area_addrs != 0 && max_area_addrs != isis->max_area_addrs) {
zlog_err(
zlog_ferr(
ISIS_ERR_PACKET,
"maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %" PRIu8
" while the parameter for this IS is %u",
max_area_addrs, isis->max_area_addrs);
Expand Down Expand Up @@ -1638,9 +1646,10 @@ int send_hello(struct isis_circuit *circuit, int level)

retval = circuit->tx(circuit, level);
if (retval != ISIS_OK)
zlog_err("ISIS-Adj (%s): Send L%d IIH on %s failed",
circuit->area->area_tag, level,
circuit->interface->name);
zlog_ferr(ISIS_ERR_PACKET,
"ISIS-Adj (%s): Send L%d IIH on %s failed",
circuit->area->area_tag, level,
circuit->interface->name);

return retval;
}
Expand Down Expand Up @@ -1835,9 +1844,10 @@ int send_csnp(struct isis_circuit *circuit, int level)

int retval = circuit->tx(circuit, level);
if (retval != ISIS_OK) {
zlog_err("ISIS-Snp (%s): Send L%d CSNP on %s failed",
circuit->area->area_tag, level,
circuit->interface->name);
zlog_ferr(ISIS_ERR_PACKET,
"ISIS-Snp (%s): Send L%d CSNP on %s failed",
circuit->area->area_tag, level,
circuit->interface->name);
isis_free_tlvs(tlvs);
return retval;
}
Expand Down Expand Up @@ -1999,9 +2009,10 @@ static int send_psnp(int level, struct isis_circuit *circuit)

int retval = circuit->tx(circuit, level);
if (retval != ISIS_OK) {
zlog_err("ISIS-Snp (%s): Send L%d PSNP on %s failed",
circuit->area->area_tag, level,
circuit->interface->name);
zlog_ferr(ISIS_ERR_PACKET,
"ISIS-Snp (%s): Send L%d PSNP on %s failed",
circuit->area->area_tag, level,
circuit->interface->name);
isis_free_tlvs(tlvs);
return retval;
}
Expand Down Expand Up @@ -2106,7 +2117,8 @@ int send_lsp(struct thread *thread)
* than
* the circuit's MTU. So handle and log this case here. */
if (stream_get_endp(lsp->pdu) > stream_get_size(circuit->snd_stream)) {
zlog_err(
zlog_ferr(
ISIS_ERR_PACKET,
"ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08" PRIx32
", cksum 0x%04" PRIx16 ", lifetime %" PRIu16
"s on %s. LSP Size is %zu while interface stream size is %zu.",
Expand Down Expand Up @@ -2141,11 +2153,12 @@ int send_lsp(struct thread *thread)
clear_srm = 0;
retval = circuit->tx(circuit, lsp->level);
if (retval != ISIS_OK) {
zlog_err("ISIS-Upd (%s): Send L%d LSP on %s failed %s",
circuit->area->area_tag, lsp->level,
circuit->interface->name,
(retval == ISIS_WARNING) ? "temporarily"
: "permanently");
zlog_ferr(ISIS_ERR_PACKET,
"ISIS-Upd (%s): Send L%d LSP on %s failed %s",
circuit->area->area_tag, lsp->level,
circuit->interface->name,
(retval == ISIS_WARNING) ? "temporarily"
: "permanently");
}

out:
Expand Down
2 changes: 2 additions & 0 deletions isisd/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ isisd_libisis_a_SOURCES = \
isisd/isis_csm.c \
isisd/isis_dr.c \
isisd/isis_dynhn.c \
isisd/isis_errors.c \
isisd/isis_events.c \
isisd/isis_flags.c \
isisd/isis_lsp.c \
Expand Down Expand Up @@ -44,6 +45,7 @@ noinst_HEADERS += \
isisd/isis_csm.h \
isisd/isis_dr.h \
isisd/isis_dynhn.h \
isisd/isis_errors.h \
isisd/isis_events.h \
isisd/isis_flags.h \
isisd/isis_lsp.h \
Expand Down

0 comments on commit 8578990

Please sign in to comment.