mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-04-28 13:20:12 +00:00
lib: Add ISO System & Network format to printfrr
Like for IP addresses, this patch add a new format for printfrr collection to print ISO System ID and Network address a.k.a IS-IS system ID & Network. This new format is added to the library instead of isisd because other daemons and tools need to print ISO System ID & Network Address. Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
This commit is contained in:
parent
2e1ea89222
commit
7f9ab3b0bb
@ -502,6 +502,51 @@ General utility formats
|
||||
representation for a hexdump. Non-printable characters are replaced with
|
||||
a dot.
|
||||
|
||||
.. frrfmt:: %pIS (struct iso_address *)
|
||||
|
||||
([IS]o Network address) - Format ISO Network Address
|
||||
|
||||
``%pIS``: :frrfmtout:`01.0203.04O5`
|
||||
ISO Network address is printed as separated byte. The number of byte of the
|
||||
address is embeded in the `iso_net` structure.
|
||||
|
||||
``%pISl``: :frrfmtout:`01.0203.04O5.0607.0809.1011.1213.14` - long format to
|
||||
print the long version of the ISO Network address which include the System
|
||||
ID and the PSEUDO-ID of the IS-IS system
|
||||
|
||||
Note that the `ISO_ADDR_STRLEN` define gives the total size of the string
|
||||
that could be used in conjunction to snprintfrr. Use like::
|
||||
|
||||
char buf[ISO_ADDR_STRLEN];
|
||||
struct iso_net addr = {.len = 4, .addr = {1, 2, 3, 4}};
|
||||
snprintfrr(buf, ISO_ADDR_STRLEN, "%pIS", &addr);
|
||||
|
||||
.. frrfmt:: %pSY (uint8_t *)
|
||||
|
||||
(IS-IS [SY]stem ID) - Format IS-IS System ID
|
||||
|
||||
``%pSY``: :frrfmtout:`0102.0304.0506`
|
||||
|
||||
.. frrfmt:: %pPN (uint8_t *)
|
||||
|
||||
(IS-IS [P]seudo [N]ode System ID) - Format IS-IS Pseudo Node System ID
|
||||
|
||||
``%pPN``: :frrfmtout:`0102.0304.0506.07`
|
||||
|
||||
.. frrfmt:: %pLS (uint8_t *)
|
||||
|
||||
(IS-IS [L]sp fragment [S]ystem ID) - Format IS-IS Pseudo System ID
|
||||
|
||||
``%pLS``: :frrfmtout:`0102.0304.0506.07-08`
|
||||
|
||||
Note that the `ISO_SYSID_STRLEN` define gives the total size of the string
|
||||
that could be used in conjunction to snprintfrr. Use like::
|
||||
|
||||
char buf[ISO_SYSID_STRLEN];
|
||||
uint8_t id[8] = {1, 2, 3, 4 , 5 , 6 , 7, 8};
|
||||
snprintfrr(buf, SYS_ID_SIZE, "%pSY", id);
|
||||
|
||||
|
||||
Integer formats
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
|
144
lib/iso.c
Normal file
144
lib/iso.c
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* ISO Network functions - iso_net.c
|
||||
*
|
||||
* Author: Olivier Dugeon <olivier.dugeon@orange.com>
|
||||
*
|
||||
* Copyright (C) 2023 Orange http://www.orange.com
|
||||
*
|
||||
* This file is part of Free Range Routing (FRR).
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "printfrr.h"
|
||||
#include "iso.h"
|
||||
|
||||
/**
|
||||
* Print ISO System ID as 0000.0000.0000
|
||||
*
|
||||
* @param Print buffer
|
||||
* @param Print argument
|
||||
* @param Pointer to the System ID to be printed
|
||||
*
|
||||
* @return Number of printed characters
|
||||
*/
|
||||
printfrr_ext_autoreg_p("SY", printfrr_iso_sysid);
|
||||
static ssize_t printfrr_iso_sysid(struct fbuf *buf, struct printfrr_eargs *ea,
|
||||
const void *vptr)
|
||||
{
|
||||
const uint8_t *id = vptr;
|
||||
|
||||
if (!id)
|
||||
return bputs(buf, "(null)");
|
||||
|
||||
return bprintfrr(buf, "%02x%02x.%02x%02x.%02x%02x",
|
||||
id[0], id[1], id[2], id[3], id[4], id[5]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print ISO Pseudo Node system ID as 0000.0000.0000.00
|
||||
*
|
||||
* @param Print buffer
|
||||
* @param Print argument
|
||||
* @param Pointer to the System ID to be printed
|
||||
*
|
||||
* @return Number of printed characters
|
||||
*/
|
||||
printfrr_ext_autoreg_p("PN", printfrr_iso_pseudo);
|
||||
static ssize_t printfrr_iso_pseudo(struct fbuf *buf, struct printfrr_eargs *ea,
|
||||
const void *vptr)
|
||||
{
|
||||
const uint8_t *id = vptr;
|
||||
|
||||
if (!id)
|
||||
return bputs(buf, "(null)");
|
||||
|
||||
return bprintfrr(buf, "%02x%02x.%02x%02x.%02x%02x.%02x",
|
||||
id[0], id[1], id[2], id[3], id[4], id[5], id[6]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print ISO LSP Fragment System ID as 0000.0000.0000.00-00
|
||||
*
|
||||
* @param Print buffer
|
||||
* @param Print argument
|
||||
* @param Pointer to the System ID to be printed
|
||||
*
|
||||
* @return Number of printed characters
|
||||
*/
|
||||
printfrr_ext_autoreg_p("LS", printfrr_iso_frag_id);
|
||||
static ssize_t printfrr_iso_frag_id(struct fbuf *buf, struct printfrr_eargs *ea,
|
||||
const void *vptr)
|
||||
{
|
||||
const uint8_t *id = vptr;
|
||||
|
||||
if (!id)
|
||||
return bputs(buf, "(null)");
|
||||
|
||||
return bprintfrr(buf, "%02x%02x.%02x%02x.%02x%02x.%02x-%02x",
|
||||
id[0], id[1], id[2], id[3], id[4], id[5], id[6],
|
||||
id[7]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print ISO Network address as 00.0000.0000.0000 ... with the System ID
|
||||
* as 0000.0000.0000.00 when long 'l' option is added to '%pIS'
|
||||
*
|
||||
* @param Print buffer
|
||||
* @param Print argument
|
||||
* @param Pointer to the ISO Network address
|
||||
*
|
||||
* @return Number of printed characters
|
||||
*/
|
||||
printfrr_ext_autoreg_p("IS", printfrr_iso_addr);
|
||||
static ssize_t printfrr_iso_addr(struct fbuf *buf, struct printfrr_eargs *ea,
|
||||
const void *vptr)
|
||||
{
|
||||
const struct iso_address *ia = vptr;
|
||||
uint8_t len = 0;
|
||||
int i = 0;
|
||||
ssize_t ret = 0;
|
||||
|
||||
if (ea->fmt[0] == 'l') {
|
||||
len = 7; /* ISO SYSTEM ID + 1 */
|
||||
ea->fmt++;
|
||||
}
|
||||
|
||||
if (!ia)
|
||||
return bputs(buf, "(null)");
|
||||
|
||||
len += ia->addr_len;
|
||||
while (i < len) {
|
||||
/* No dot for odd index and at the end of address */
|
||||
if ((i & 1) || (i == (len - 1)))
|
||||
ret += bprintfrr(buf, "%02x", ia->area_addr[i]);
|
||||
else
|
||||
ret += bprintfrr(buf, "%02x.", ia->area_addr[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
49
lib/iso.h
Normal file
49
lib/iso.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* ISO Network definition - iso_net.h
|
||||
*
|
||||
* Author: Olivier Dugeon <olivier.dugeon@orange.com>
|
||||
*
|
||||
* Copyright (C) 2023 Orange http://www.orange.com
|
||||
*
|
||||
* This file is part of Free Range Routing (FRR).
|
||||
*
|
||||
* 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 LIB_ISO_H_
|
||||
#define LIB_ISO_H_
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
/* len of "xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xx" + '\0' */
|
||||
#define ISO_ADDR_STRLEN 51
|
||||
#define ISO_ADDR_MIN 8
|
||||
#define ISO_ADDR_SIZE 20
|
||||
struct iso_address {
|
||||
uint8_t addr_len;
|
||||
uint8_t area_addr[ISO_ADDR_SIZE];
|
||||
};
|
||||
|
||||
/* len of "xxxx.xxxx.xxxx.xx-xx" + '\0' */
|
||||
#define ISO_SYSID_STRLEN 21
|
||||
|
||||
#ifdef _FRR_ATTRIBUTE_PRINTFRR
|
||||
#pragma FRR printfrr_ext "%pSY" (uint8_t *)
|
||||
#pragma FRR printfrr_ext "%pPN" (uint8_t *)
|
||||
#pragma FRR printfrr_ext "%pLS" (uint8_t *)
|
||||
#pragma FRR printfrr_ext "%pIS" (struct iso_address *)
|
||||
#endif
|
||||
|
||||
#endif /* LIB_ISO_H_ */
|
@ -26,6 +26,7 @@
|
||||
#include "printfrr.h"
|
||||
#include <lib/json.h>
|
||||
#include "link_state.h"
|
||||
#include "iso.h"
|
||||
|
||||
/* Link State Memory allocation */
|
||||
DEFINE_MTYPE_STATIC(LIB, LS_DB, "Link State Database");
|
||||
@ -1965,13 +1966,9 @@ static const char *const status2txt[] = {
|
||||
static const char *ls_node_id_to_text(struct ls_node_id lnid, char *str,
|
||||
size_t size)
|
||||
{
|
||||
if (lnid.origin == ISIS_L1 || lnid.origin == ISIS_L2) {
|
||||
uint8_t *id;
|
||||
|
||||
id = lnid.id.iso.sys_id;
|
||||
snprintfrr(str, size, "%02x%02x.%02x%02x.%02x%02x", id[0],
|
||||
id[1], id[2], id[3], id[4], id[5]);
|
||||
} else
|
||||
if (lnid.origin == ISIS_L1 || lnid.origin == ISIS_L2)
|
||||
snprintfrr(str, size, "%pSY", lnid.id.iso.sys_id);
|
||||
else
|
||||
snprintfrr(str, size, "%pI4", &lnid.id.ip.addr);
|
||||
|
||||
return str;
|
||||
|
@ -49,6 +49,7 @@ lib_libfrr_la_SOURCES = \
|
||||
lib/if_rmap.c \
|
||||
lib/imsg-buffer.c \
|
||||
lib/imsg.c \
|
||||
lib/iso.c \
|
||||
lib/jhash.c \
|
||||
lib/json.c \
|
||||
lib/keychain.c \
|
||||
@ -207,6 +208,7 @@ pkginclude_HEADERS += \
|
||||
lib/if_rmap.h \
|
||||
lib/imsg.h \
|
||||
lib/ipaddr.h \
|
||||
lib/iso.h \
|
||||
lib/jhash.h \
|
||||
lib/json.h \
|
||||
lib/keychain.h \
|
||||
|
Loading…
Reference in New Issue
Block a user