Line | Count | Source (jump to first uncovered line) |
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 | | */ |
47 | | printfrr_ext_autoreg_p("SY", printfrr_iso_sysid); |
48 | | static ssize_t printfrr_iso_sysid(struct fbuf *buf, struct printfrr_eargs *ea, |
49 | | const void *vptr) |
50 | 0 | { |
51 | 0 | const uint8_t *id = vptr; |
52 | |
|
53 | 0 | if (!id) |
54 | 0 | return bputs(buf, "(null)"); |
55 | | |
56 | 0 | return bprintfrr(buf, "%02x%02x.%02x%02x.%02x%02x", |
57 | 0 | id[0], id[1], id[2], id[3], id[4], id[5]); |
58 | 0 | } |
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 | | */ |
69 | | printfrr_ext_autoreg_p("PN", printfrr_iso_pseudo); |
70 | | static ssize_t printfrr_iso_pseudo(struct fbuf *buf, struct printfrr_eargs *ea, |
71 | | const void *vptr) |
72 | 0 | { |
73 | 0 | const uint8_t *id = vptr; |
74 | |
|
75 | 0 | if (!id) |
76 | 0 | return bputs(buf, "(null)"); |
77 | | |
78 | 0 | return bprintfrr(buf, "%02x%02x.%02x%02x.%02x%02x.%02x", |
79 | 0 | id[0], id[1], id[2], id[3], id[4], id[5], id[6]); |
80 | 0 | } |
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 | | */ |
91 | | printfrr_ext_autoreg_p("LS", printfrr_iso_frag_id); |
92 | | static ssize_t printfrr_iso_frag_id(struct fbuf *buf, struct printfrr_eargs *ea, |
93 | | const void *vptr) |
94 | 0 | { |
95 | 0 | const uint8_t *id = vptr; |
96 | |
|
97 | 0 | if (!id) |
98 | 0 | return bputs(buf, "(null)"); |
99 | | |
100 | 0 | return bprintfrr(buf, "%02x%02x.%02x%02x.%02x%02x.%02x-%02x", |
101 | 0 | id[0], id[1], id[2], id[3], id[4], id[5], id[6], |
102 | 0 | id[7]); |
103 | 0 | } |
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 | | */ |
115 | | printfrr_ext_autoreg_p("IS", printfrr_iso_addr); |
116 | | static ssize_t printfrr_iso_addr(struct fbuf *buf, struct printfrr_eargs *ea, |
117 | | const void *vptr) |
118 | 0 | { |
119 | 0 | const struct iso_address *ia = vptr; |
120 | 0 | uint8_t len = 0; |
121 | 0 | int i = 0; |
122 | 0 | ssize_t ret = 0; |
123 | |
|
124 | 0 | if (ea->fmt[0] == 'l') { |
125 | 0 | len = 7; /* ISO SYSTEM ID + 1 */ |
126 | 0 | ea->fmt++; |
127 | 0 | } |
128 | |
|
129 | 0 | if (!ia) |
130 | 0 | return bputs(buf, "(null)"); |
131 | | |
132 | 0 | len += ia->addr_len; |
133 | 0 | while (i < len) { |
134 | | /* No dot for odd index and at the end of address */ |
135 | 0 | if ((i & 1) || (i == (len - 1))) |
136 | 0 | ret += bprintfrr(buf, "%02x", ia->area_addr[i]); |
137 | 0 | else |
138 | 0 | ret += bprintfrr(buf, "%02x.", ia->area_addr[i]); |
139 | 0 | i++; |
140 | 0 | } |
141 | |
|
142 | 0 | return ret; |
143 | 0 | } |
144 | | |