|
|
@ -32,6 +32,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
typedef enum {
|
|
|
|
ONLY_REFS_FLAG,
|
|
|
|
ONLY_REFS_FLAG,
|
|
|
|
|
|
|
|
OUTPUT_FLAG,
|
|
|
|
|
|
|
|
|
|
|
|
NUM_FLAGS
|
|
|
|
NUM_FLAGS
|
|
|
|
} PeerindexOpt;
|
|
|
|
} PeerindexOpt;
|
|
|
@ -40,6 +41,9 @@ static Optflag options[] = {
|
|
|
|
[ONLY_REFS_FLAG] = {
|
|
|
|
[ONLY_REFS_FLAG] = {
|
|
|
|
'r', "only-refs", NULL, "Only dump peers referenced by RIBs", ARG_NONE
|
|
|
|
'r', "only-refs", NULL, "Only dump peers referenced by RIBs", ARG_NONE
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[OUTPUT_FLAG] = {
|
|
|
|
|
|
|
|
'o', NULL, "file", "Write output to file", ARG_REQ
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
[NUM_FLAGS] = { '\0' }
|
|
|
|
[NUM_FLAGS] = { '\0' }
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -64,6 +68,21 @@ static void Peerindex_SetupCommandLine(char *argv0)
|
|
|
|
"Any diagnostic message is logged to stderr.";
|
|
|
|
"Any diagnostic message is logged to stderr.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void Peerindex_Fatal(const char *fmt, ...)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sys_Print(STDERR, com_progName);
|
|
|
|
|
|
|
|
Sys_Print(STDERR, ": ERROR: ");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
va_start(va, fmt);
|
|
|
|
|
|
|
|
Sys_VPrintf(STDERR, fmt, va);
|
|
|
|
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sys_Print(STDERR, "\n");
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void Peerindex_Warning(const char *fmt, ...)
|
|
|
|
static void Peerindex_Warning(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
va_list va;
|
|
|
@ -180,6 +199,20 @@ static void Peerindex_ApplyProgramOptions(void)
|
|
|
|
S.peerIndexClearVal = 0;
|
|
|
|
S.peerIndexClearVal = 0;
|
|
|
|
else
|
|
|
|
else
|
|
|
|
S.peerIndexClearVal = 0xff; // so we always print the full table
|
|
|
|
S.peerIndexClearVal = 0xff; // so we always print the full table
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (options[OUTPUT_FLAG].flagged) {
|
|
|
|
|
|
|
|
const char *filename = options[OUTPUT_FLAG].optarg;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Fildes fd = Sys_Fopen(filename, FM_WRITE, /*hints=*/0);
|
|
|
|
|
|
|
|
if (fd == FILDES_BAD)
|
|
|
|
|
|
|
|
Peerindex_Fatal("Can't open output file \"%s\"", filename);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
S.outf = STM_FILDES(fd);
|
|
|
|
|
|
|
|
S.outfOps = Stm_FildesOps;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
S.outf = STM_CONHN(STDOUT);
|
|
|
|
|
|
|
|
S.outfOps = Stm_ConOps;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void Peerindex_Init(void)
|
|
|
|
static void Peerindex_Init(void)
|
|
|
@ -267,7 +300,7 @@ static void Peerindex_FlushPeerIndexTable(void)
|
|
|
|
|
|
|
|
|
|
|
|
Uint16 idx = 0;
|
|
|
|
Uint16 idx = 0;
|
|
|
|
|
|
|
|
|
|
|
|
Bufio_Init(&sb, STM_CONHN(STDOUT), Stm_ConOps);
|
|
|
|
Bufio_Init(&sb, S.outf, S.outfOps);
|
|
|
|
|
|
|
|
|
|
|
|
Bgp_StartMrtPeersv2(&it, &S.peerIndex);
|
|
|
|
Bgp_StartMrtPeersv2(&it, &S.peerIndex);
|
|
|
|
while ((peer = Bgp_NextMrtPeerv2(&it)) != NULL) {
|
|
|
|
while ((peer = Bgp_NextMrtPeerv2(&it)) != NULL) {
|
|
|
@ -389,5 +422,7 @@ int main(int argc, char **argv)
|
|
|
|
while (i < argc)
|
|
|
|
while (i < argc)
|
|
|
|
Peerindex_ProcessMrtDump(argv[i++]);
|
|
|
|
Peerindex_ProcessMrtDump(argv[i++]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (S.outfOps->Close) S.outfOps->Close(S.outf);
|
|
|
|
|
|
|
|
|
|
|
|
return (S.nerrors > 0) ? EXIT_FAILURE : EXIT_SUCCESS;
|
|
|
|
return (S.nerrors > 0) ? EXIT_FAILURE : EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|