]> git.proxmox.com Git - mirror_frr.git/blob - lib/asn.h
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / lib / asn.h
1 /*
2 * AS number structure
3 * Copyright 2022 6WIND
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2, or (at your
10 * option) any later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef _FRR_ASN_H
23 #define _FRR_ASN_H
24
25 #include "zebra.h"
26 #include "command_match.h"
27 #include "json.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #define ASN_STRING_MAX_SIZE 12
34
35 enum asnotation_mode {
36 ASNOTATION_PLAIN = 0,
37 ASNOTATION_DOT,
38 ASNOTATION_DOTPLUS,
39 ASNOTATION_UNDEFINED,
40 };
41
42 typedef uint32_t as_t;
43
44 extern bool asn_str2asn(const char *asstring, as_t *asn);
45 extern const char *asn_asn2asplain(as_t asn);
46 extern const char *asn_str2asn_parse(const char *asstring, as_t *asn,
47 bool *found_ptr);
48 extern enum match_type asn_str2asn_match(const char *str);
49 extern bool asn_str2asn_notation(const char *asstring, as_t *asn,
50 enum asnotation_mode *asnotation);
51 extern const char *asn_mode2str(enum asnotation_mode asnotation);
52 void asn_asn2json_array(json_object *jseg_list, as_t asn,
53 enum asnotation_mode asnotation);
54 void asn_asn2json(json_object *jseg_list, const char *attr,
55 as_t asn, enum asnotation_mode asnotation);
56 extern char *asn_asn2string(const as_t *as, char *buf, size_t len,
57 enum asnotation_mode asnotation);
58 /* display AS in appropriate format */
59 #ifdef _FRR_ATTRIBUTE_PRINTFRR
60 #pragma FRR printfrr_ext "%pASP" (as_t *)
61 #pragma FRR printfrr_ext "%pASD" (as_t *)
62 #pragma FRR printfrr_ext "%pASE" (as_t *)
63 #endif
64
65 #define ASN_FORMAT(mode) \
66 ((mode == ASNOTATION_DOT) ? "%pASD" : \
67 ((mode == ASNOTATION_DOTPLUS) ? "%pASE" : \
68 "%pASP"))
69 #define ASN_FORMAT_SPACE(mode) \
70 ((mode == ASNOTATION_DOT) ? "%10pASD" : \
71 ((mode == ASNOTATION_DOTPLUS) ? "%10pASE" : \
72 "%10pASP"))
73
74 /* for test */
75 extern void asn_relax_as_zero(bool relax);
76
77 #ifdef __cplusplus
78 }
79 #endif
80
81 #endif /* _FRR_ASN_H */