]> git.proxmox.com Git - mirror_frr.git/blame - lib/iso.c
ripd: Make sure we do not overuse higher values for ECMP count
[mirror_frr.git] / lib / iso.c
CommitLineData
7f9ab3b0
OD
1/*
2 * ISO Network functions - iso_net.c
3 *
4 * Author: Olivier Dugeon <olivier.dugeon@orange.com>
5 *
6 * Copyright (C) 2023 Orange http://www.orange.com
7 *
8 * This file is part of Free Range Routing (FRR).
9 *
10 * FRR is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2, or (at your option) any
13 * later version.
14 *
15 * FRR is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; see the file COPYING; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#ifdef HAVE_CONFIG_H
26#include "config.h"
27#endif
28
29#include "compiler.h"
30
31#include <string.h>
32#include <ctype.h>
33#include <time.h>
34
35#include "printfrr.h"
36#include "iso.h"
37
38/**
39 * Print ISO System ID as 0000.0000.0000
40 *
41 * @param Print buffer
42 * @param Print argument
43 * @param Pointer to the System ID to be printed
44 *
45 * @return Number of printed characters
46 */
47printfrr_ext_autoreg_p("SY", printfrr_iso_sysid);
48static ssize_t printfrr_iso_sysid(struct fbuf *buf, struct printfrr_eargs *ea,
49 const void *vptr)
50{
51 const uint8_t *id = vptr;
52
53 if (!id)
54 return bputs(buf, "(null)");
55
56 return bprintfrr(buf, "%02x%02x.%02x%02x.%02x%02x",
57 id[0], id[1], id[2], id[3], id[4], id[5]);
58}
59
60/**
61 * Print ISO Pseudo Node system ID as 0000.0000.0000.00
62 *
63 * @param Print buffer
64 * @param Print argument
65 * @param Pointer to the System ID to be printed
66 *
67 * @return Number of printed characters
68 */
69printfrr_ext_autoreg_p("PN", printfrr_iso_pseudo);
70static ssize_t printfrr_iso_pseudo(struct fbuf *buf, struct printfrr_eargs *ea,
71 const void *vptr)
72{
73 const uint8_t *id = vptr;
74
75 if (!id)
76 return bputs(buf, "(null)");
77
78 return bprintfrr(buf, "%02x%02x.%02x%02x.%02x%02x.%02x",
79 id[0], id[1], id[2], id[3], id[4], id[5], id[6]);
80}
81
82/**
83 * Print ISO LSP Fragment System ID as 0000.0000.0000.00-00
84 *
85 * @param Print buffer
86 * @param Print argument
87 * @param Pointer to the System ID to be printed
88 *
89 * @return Number of printed characters
90 */
91printfrr_ext_autoreg_p("LS", printfrr_iso_frag_id);
92static ssize_t printfrr_iso_frag_id(struct fbuf *buf, struct printfrr_eargs *ea,
93 const void *vptr)
94{
95 const uint8_t *id = vptr;
96
97 if (!id)
98 return bputs(buf, "(null)");
99
100 return bprintfrr(buf, "%02x%02x.%02x%02x.%02x%02x.%02x-%02x",
101 id[0], id[1], id[2], id[3], id[4], id[5], id[6],
102 id[7]);
103}
104
105/**
106 * Print ISO Network address as 00.0000.0000.0000 ... with the System ID
107 * as 0000.0000.0000.00 when long 'l' option is added to '%pIS'
108 *
109 * @param Print buffer
110 * @param Print argument
111 * @param Pointer to the ISO Network address
112 *
113 * @return Number of printed characters
114 */
115printfrr_ext_autoreg_p("IS", printfrr_iso_addr);
116static ssize_t printfrr_iso_addr(struct fbuf *buf, struct printfrr_eargs *ea,
117 const void *vptr)
118{
119 const struct iso_address *ia = vptr;
120 uint8_t len = 0;
121 int i = 0;
122 ssize_t ret = 0;
123
124 if (ea->fmt[0] == 'l') {
125 len = 7; /* ISO SYSTEM ID + 1 */
126 ea->fmt++;
127 }
128
129 if (!ia)
130 return bputs(buf, "(null)");
131
132 len += ia->addr_len;
133 while (i < len) {
134 /* No dot for odd index and at the end of address */
135 if ((i & 1) || (i == (len - 1)))
136 ret += bprintfrr(buf, "%02x", ia->area_addr[i]);
137 else
138 ret += bprintfrr(buf, "%02x.", ia->area_addr[i]);
139 i++;
140 }
141
142 return ret;
143}
144