File: iso.c

package info (click to toggle)
frr 10.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 76,324 kB
  • sloc: ansic: 686,900; python: 225,905; perl: 6,379; sh: 2,627; cpp: 1,883; makefile: 670; yacc: 397; lex: 363; lisp: 66; xml: 35; javascript: 8
file content (129 lines) | stat: -rw-r--r-- 2,927 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * ISO Network functions - iso_net.c
 *
 * Author: Olivier Dugeon <olivier.dugeon@orange.com>
 *
 * Copyright (C) 2023 Orange http://www.orange.com
 */

#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;
}