]> git.proxmox.com Git - mirror_frr.git/blame - lib/zebra.h
lib: Allow adding arrays of ferr's
[mirror_frr.git] / lib / zebra.h
CommitLineData
718e3744 1/* Zebra common header.
896014f4
DL
2 * Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
718e3744 20
21#ifndef _ZEBRA_H
22#define _ZEBRA_H
23
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif /* HAVE_CONFIG_H */
27
ef7eec74
QY
28#include "compiler.h"
29
718e3744 30#ifdef SUNOS_5
31#define _XPG4_2
d7c0a89a
QY
32typedef unsigned int uint32_t;
33typedef unsigned short uint16_t;
34typedef unsigned char uint8_t;
718e3744 35#endif /* SUNOS_5 */
36
37#include <unistd.h>
38#include <stdio.h>
39#include <stdlib.h>
c423d413 40#include <stddef.h>
718e3744 41#include <ctype.h>
42#include <errno.h>
43#include <fcntl.h>
44#include <signal.h>
45#include <string.h>
edd7c245 46#include <pwd.h>
47#include <grp.h>
718e3744 48#ifdef HAVE_STROPTS_H
49#include <stropts.h>
50#endif /* HAVE_STROPTS_H */
718e3744 51#include <sys/select.h>
718e3744 52#include <sys/stat.h>
718e3744 53#include <sys/types.h>
54#include <sys/param.h>
55#ifdef HAVE_SYS_SYSCTL_H
0dc0b708
AS
56#ifdef GNU_LINUX
57#include <linux/types.h>
58#endif
718e3744 59#include <sys/sysctl.h>
60#endif /* HAVE_SYS_SYSCTL_H */
61#include <sys/ioctl.h>
62#ifdef HAVE_SYS_CONF_H
63#include <sys/conf.h>
64#endif /* HAVE_SYS_CONF_H */
65#ifdef HAVE_SYS_KSYM_H
66#include <sys/ksym.h>
67#endif /* HAVE_SYS_KSYM_H */
68#include <syslog.h>
24f5e2fc
DL
69#include <sys/time.h>
70#include <time.h>
718e3744 71#include <sys/uio.h>
72#include <sys/utsname.h>
718e3744 73#include <sys/resource.h>
a58c25b6 74#include <limits.h>
35cfc90c 75#include <inttypes.h>
63a13864 76#include <stdbool.h>
718e3744 77
78/* machine dependent includes */
79#ifdef SUNOS_5
718e3744 80#include <strings.h>
81#endif /* SUNOS_5 */
82
83/* machine dependent includes */
84#ifdef HAVE_LINUX_VERSION_H
85#include <linux/version.h>
86#endif /* HAVE_LINUX_VERSION_H */
87
ba965c6c 88#ifdef HAVE_ASM_TYPES_H
89#include <asm/types.h>
90#endif /* HAVE_ASM_TYPES_H */
91
718e3744 92/* misc include group */
93#include <stdarg.h>
4cf0d0df 94#if !(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
95/* Not C99; do we need to define va_copy? */
e22f5516 96#ifndef va_copy
97#ifdef __va_copy
4cf0d0df 98#define va_copy(DST,SRC) __va_copy(DST,SRC)
e22f5516 99#else
d62a17ae 100/* Now we are desperate; this should work on many typical platforms.
e22f5516 101 But this is slightly dangerous, because the standard does not require
102 va_copy to be a macro. */
103#define va_copy(DST,SRC) memcpy(&(DST), &(SRC), sizeof(va_list))
104#warning "Not C99 and no va_copy macro available, falling back to memcpy"
105#endif /* __va_copy */
106#endif /* !va_copy */
4cf0d0df 107#endif /* !C99 */
db8eaac6 108
718e3744 109
ba3a0bc5 110#ifdef HAVE_LCAPS
111#include <sys/capability.h>
112#include <sys/prctl.h>
113#endif /* HAVE_LCAPS */
114
ceacedba 115#ifdef HAVE_SOLARIS_CAPABILITIES
116#include <priv.h>
117#endif /* HAVE_SOLARIS_CAPABILITIES */
118
718e3744 119/* network include group */
120
121#include <sys/socket.h>
122
123#ifdef HAVE_SYS_SOCKIO_H
124#include <sys/sockio.h>
125#endif /* HAVE_SYS_SOCKIO_H */
126
ea057677
HT
127#ifdef __APPLE__
128#define __APPLE_USE_RFC_3542
129#endif
130
f9e75524 131#ifndef HAVE_LIBCRYPT
996c9314
LB
132#ifdef HAVE_LIBCRYPTO
133#include <openssl/des.h>
f9e75524 134# define crypt DES_crypt
996c9314 135#endif
f9e75524
JAG
136#endif
137
8d8763f4 138#include "openbsd-tree.h"
6021c8d3 139
718e3744 140#include <netinet/in.h>
718e3744 141#include <netinet/in_systm.h>
142#include <netinet/ip.h>
143#include <netinet/tcp.h>
144
145#ifdef HAVE_NET_NETOPT_H
146#include <net/netopt.h>
147#endif /* HAVE_NET_NETOPT_H */
148
149#include <net/if.h>
150
151#ifdef HAVE_NET_IF_DL_H
152#include <net/if_dl.h>
153#endif /* HAVE_NET_IF_DL_H */
154
155#ifdef HAVE_NET_IF_VAR_H
156#include <net/if_var.h>
157#endif /* HAVE_NET_IF_VAR_H */
158
159#include <net/route.h>
160
161#ifdef HAVE_NETLINK
162#include <linux/netlink.h>
163#include <linux/rtnetlink.h>
768a27ea 164#include <linux/filter.h>
718e3744 165#else
166#define RT_TABLE_MAIN 0
167#endif /* HAVE_NETLINK */
168
718e3744 169#include <netdb.h>
718e3744 170#include <arpa/inet.h>
718e3744 171
172#ifdef HAVE_INET_ND_H
173#include <inet/nd.h>
174#endif /* HAVE_INET_ND_H */
175
176#ifdef HAVE_NETINET_IN_VAR_H
177#include <netinet/in_var.h>
178#endif /* HAVE_NETINET_IN_VAR_H */
179
726f9b2b 180#ifdef HAVE_NETINET6_IN6_VAR_H
181#include <netinet6/in6_var.h>
182#endif /* HAVE_NETINET6_IN6_VAR_H */
183
718e3744 184#ifdef HAVE_NETINET_IN6_VAR_H
185#include <netinet/in6_var.h>
186#endif /* HAVE_NETINET_IN6_VAR_H */
187
188#ifdef HAVE_NETINET6_IN_H
189#include <netinet6/in.h>
190#endif /* HAVE_NETINET6_IN_H */
191
192
193#ifdef HAVE_NETINET6_IP6_H
194#include <netinet6/ip6.h>
195#endif /* HAVE_NETINET6_IP6_H */
196
718e3744 197#include <netinet/icmp6.h>
718e3744 198
199#ifdef HAVE_NETINET6_ND6_H
200#include <netinet6/nd6.h>
201#endif /* HAVE_NETINET6_ND6_H */
202
35cfc90c
PJ
203/* Some systems do not define UINT32_MAX, etc.. from inttypes.h
204 * e.g. this makes life easier for FBSD 4.11 users.
205 */
206#ifndef INT8_MAX
207#define INT8_MAX (127)
208#endif
209#ifndef INT16_MAX
210#define INT16_MAX (32767)
211#endif
212#ifndef INT32_MAX
213#define INT32_MAX (2147483647)
214#endif
215#ifndef UINT8_MAX
216#define UINT8_MAX (255U)
217#endif
218#ifndef UINT16_MAX
219#define UINT16_MAX (65535U)
220#endif
3b424979 221#ifndef UINT32_MAX
35cfc90c
PJ
222#define UINT32_MAX (4294967295U)
223#endif
3b424979 224
fb2d1502 225#ifdef HAVE_GLIBC_BACKTRACE
226#include <execinfo.h>
227#endif /* HAVE_GLIBC_BACKTRACE */
228
db8eaac6 229/* Local includes: */
d62a17ae 230#if !(defined(__GNUC__) || defined(VTYSH_EXTRACT_PL))
db8eaac6 231#define __attribute__(x)
d62a17ae 232#endif /* !__GNUC__ || VTYSH_EXTRACT_PL */
db8eaac6 233
234#include "zassert.h"
235
c5d9d3bb 236#ifndef HAVE_STRLCAT
c9a164df
DS
237size_t strlcat(char *__restrict dest,
238 const char *__restrict src, size_t destsize);
c5d9d3bb
DL
239#endif
240#ifndef HAVE_STRLCPY
c9a164df
DS
241size_t strlcpy(char *__restrict dest,
242 const char *__restrict src, size_t destsize);
c5d9d3bb 243#endif
db8eaac6 244
b99760ab 245#ifdef HAVE_BROKEN_CMSG_FIRSTHDR
246/* This bug is present in Solaris 8 and pre-patch Solaris 9 <sys/socket.h>;
247 please refer to http://bugzilla.quagga.net/show_bug.cgi?id=142 */
248
249/* Check that msg_controllen is large enough. */
d62a17ae 250#define ZCMSG_FIRSTHDR(mhdr) \
251 (((size_t)((mhdr)->msg_controllen) >= sizeof(struct cmsghdr)) \
252 ? CMSG_FIRSTHDR(mhdr) \
253 : (struct cmsghdr *)NULL)
b99760ab 254
255#warning "CMSG_FIRSTHDR is broken on this platform, using a workaround"
256
d62a17ae 257#else /* HAVE_BROKEN_CMSG_FIRSTHDR */
b99760ab 258#define ZCMSG_FIRSTHDR(M) CMSG_FIRSTHDR(M)
259#endif /* HAVE_BROKEN_CMSG_FIRSTHDR */
260
261
fe232cf8
QY
262/* GCC have printf type attribute check. */
263#ifdef __GNUC__
264#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
265#else
266#define PRINTF_ATTRIBUTE(a,b)
267#endif /* __GNUC__ */
b99760ab 268
d62a17ae 269/*
69e1325f 270 * RFC 3542 defines several macros for using struct cmsghdr.
271 * Here, we define those that are not present
272 */
273
274/*
275 * Internal defines, for use only in this file.
276 * These are likely wrong on other than ILP32 machines, so warn.
02ff83c5 277 */
278#ifndef _CMSG_DATA_ALIGN
279#define _CMSG_DATA_ALIGN(n) (((n) + 3) & ~3)
280#endif /* _CMSG_DATA_ALIGN */
281
282#ifndef _CMSG_HDR_ALIGN
283#define _CMSG_HDR_ALIGN(n) (((n) + 3) & ~3)
284#endif /* _CMSG_HDR_ALIGN */
285
69e1325f 286/*
287 * CMSG_SPACE and CMSG_LEN are required in RFC3542, but were new in that
288 * version.
289 */
02ff83c5 290#ifndef CMSG_SPACE
d62a17ae 291#define CMSG_SPACE(l) \
292 (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + _CMSG_HDR_ALIGN(l))
69e1325f 293#warning "assuming 4-byte alignment for CMSG_SPACE"
d62a17ae 294#endif /* CMSG_SPACE */
02ff83c5 295
296
297#ifndef CMSG_LEN
298#define CMSG_LEN(l) (_CMSG_DATA_ALIGN(sizeof(struct cmsghdr)) + (l))
69e1325f 299#warning "assuming 4-byte alignment for CMSG_LEN"
02ff83c5 300#endif /* CMSG_LEN */
301
69e1325f 302
718e3744 303/* The definition of struct in_pktinfo is missing in old version of
304 GLIBC 2.1 (Redhat 6.1). */
d62a17ae 305#if defined(GNU_LINUX) && !defined(HAVE_STRUCT_IN_PKTINFO)
306struct in_pktinfo {
307 int ipi_ifindex;
308 struct in_addr ipi_spec_dst;
309 struct in_addr ipi_addr;
718e3744 310};
311#endif
312
d62a17ae 313/*
9172ee0e 314 * IP_HDRINCL / struct ip byte order
315 *
316 * Linux: network byte order
317 * *BSD: network, except for length and offset. (cf Stevens)
318 * SunOS: nominally as per BSD. but bug: network order on LE.
d62a17ae 319 * OpenBSD: network byte order, apart from older versions which are as per
9172ee0e 320 * *BSD
321 */
d62a17ae 322#if defined(__NetBSD__) \
323 || (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) \
324 || (defined(__OpenBSD__) && (OpenBSD < 200311)) \
325 || (defined(__APPLE__)) \
326 || (defined(SUNOS_5) && defined(WORDS_BIGENDIAN))
9172ee0e 327#define HAVE_IP_HDRINCL_BSD_ORDER
328#endif
329
34204aac 330/* Define BYTE_ORDER, if not defined. Useful for compiler conditional
331 * code, rather than preprocessor conditional.
332 * Not all the world has this BSD define.
333 */
334#ifndef BYTE_ORDER
335#define BIG_ENDIAN 4321 /* least-significant byte first (vax, pc) */
336#define LITTLE_ENDIAN 1234 /* most-significant byte first (IBM, net) */
337#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp) */
338
339#if defined(WORDS_BIGENDIAN)
340#define BYTE_ORDER BIG_ENDIAN
d62a17ae 341#else /* !WORDS_BIGENDIAN */
34204aac 342#define BYTE_ORDER LITTLE_ENDIAN
343#endif /* WORDS_BIGENDIAN */
344
345#endif /* ndef BYTE_ORDER */
346
efba6ce9 347/* MAX / MIN are not commonly defined, but useful */
6b143a68
DL
348/* note: glibc sys/param.h has #define MIN(a,b) (((a)<(b))?(a):(b)) */
349#ifdef MAX
350#undef MAX
351#endif
d62a17ae 352#define MAX(a, b) \
353 ({ \
354 typeof(a) _a = (a); \
355 typeof(b) _b = (b); \
356 _a > _b ? _a : _b; \
357 })
6b143a68
DL
358#ifdef MIN
359#undef MIN
8a0bebfc 360#endif
d62a17ae 361#define MIN(a, b) \
362 ({ \
363 typeof(a) _a = (a); \
364 typeof(b) _b = (b); \
365 _a < _b ? _a : _b; \
366 })
efba6ce9 367
d43d2df5
CF
368#ifndef offsetof
369#ifdef __compiler_offsetof
370#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
371#else
372#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
373#endif
374#endif
375
376#ifndef container_of
377#define container_of(ptr, type, member) \
378 ({ \
379 const typeof(((type *)0)->member) *__mptr = (ptr); \
380 (type *)((char *)__mptr - offsetof(type, member)); \
381 })
382#endif
383
0915bb0c
AS
384#define ZEBRA_NUM_OF(x) (sizeof (x) / sizeof (x[0]))
385
718e3744 386/* For old definition. */
387#ifndef IN6_ARE_ADDR_EQUAL
388#define IN6_ARE_ADDR_EQUAL IN6_IS_ADDR_EQUAL
389#endif /* IN6_ARE_ADDR_EQUAL */
390
8cc4198f 391/* default zebra TCP port for zclient */
392#define ZEBRA_PORT 2600
393
c1b9800a 394/* Marker value used in new Zserv, in the byte location corresponding
395 * the command value in the old zserv header. To allow old and new
396 * Zserv headers to be distinguished from each other.
397 */
80e71dcd 398#define ZEBRA_HEADER_MARKER 254
c1b9800a 399
e0ca5fde
DL
400/* Zebra route's types are defined in route_types.h */
401#include "route_types.h"
718e3744 402
d6d672aa
PJ
403/* Note: whenever a new route-type or zserv-command is added the
404 * corresponding {command,route}_types[] table in lib/log.c MUST be
405 * updated! */
f52d13cb 406
407/* Map a route type to a string. For example, ZEBRA_ROUTE_RIPNG -> "ripng". */
b6026073 408extern const char *zebra_route_string(unsigned int route_type);
f52d13cb 409/* Map a route type to a char. For example, ZEBRA_ROUTE_RIPNG -> 'R'. */
b6026073 410extern char zebra_route_char(unsigned int route_type);
d62a17ae 411/* Map a zserv command type to the same string,
d6d672aa 412 * e.g. ZEBRA_INTERFACE_ADD -> "ZEBRA_INTERFACE_ADD" */
7514fb77
PJ
413/* Map a protocol name to its number. e.g. ZEBRA_ROUTE_BGP->9*/
414extern int proto_name2num(const char *s);
e0ca5fde
DL
415/* Map redistribute X argument to protocol number.
416 * unlike proto_name2num, this accepts shorthands and takes
417 * an AFI value to restrict input */
418extern int proto_redistnum(int afi, const char *s);
7514fb77 419
d62a17ae 420extern const char *zserv_command_string(unsigned int command);
f52d13cb 421
bf31fc81
DL
422#define strmatch(a,b) (!strcmp((a), (b)))
423
718e3744 424/* Zebra message flags */
4e8b02f4 425#define ZEBRA_FLAG_ALLOW_RECURSION 0x01
718e3744 426#define ZEBRA_FLAG_SELFROUTE 0x02
718e3744 427#define ZEBRA_FLAG_IBGP 0x08
428#define ZEBRA_FLAG_SELECTED 0x10
718e3744 429#define ZEBRA_FLAG_STATIC 0x40
525c1839 430#define ZEBRA_FLAG_SCOPE_LINK 0x100
446bb95e 431#define ZEBRA_FLAG_FIB_OVERRIDE 0x200
90264d64 432#define ZEBRA_FLAG_EVPN_ROUTE 0x400
40ecd8e4 433#define ZEBRA_FLAG_RR_USE_DISTANCE 0x800
a8309422
DL
434/* ZEBRA_FLAG_BLACKHOLE was 0x04 */
435/* ZEBRA_FLAG_REJECT was 0x80 */
718e3744 436
28d58fd7
VV
437/* Zebra FEC flags. */
438#define ZEBRA_FEC_REGISTER_LABEL_INDEX 0x1
439
718e3744 440#ifndef INADDR_LOOPBACK
441#define INADDR_LOOPBACK 0x7f000001 /* Internet address 127.0.0.1. */
442#endif
443
444/* Address family numbers from RFC1700. */
d62a17ae 445typedef enum { AFI_IP = 1, AFI_IP6 = 2, AFI_L2VPN = 3, AFI_MAX = 4 } afi_t;
718e3744 446
447/* Subsequent Address Family Identifier. */
5c525538
RW
448typedef enum {
449 SAFI_UNICAST = 1,
450 SAFI_MULTICAST = 2,
451 SAFI_MPLS_VPN = 3,
452 SAFI_ENCAP = 4,
453 SAFI_EVPN = 5,
454 SAFI_LABELED_UNICAST = 6,
b98f7728
PG
455 SAFI_FLOWSPEC = 7,
456 SAFI_MAX = 8
5c525538 457} safi_t;
718e3744 458
90d82769
DS
459/*
460 * The above AFI and SAFI definitions are for internal use. The protocol
461 * definitions (IANA values) as for example used in BGP protocol packets
462 * are defined below and these will get mapped to/from the internal values
463 * in the appropriate places.
464 * The rationale is that the protocol (IANA) values may be sparse and are
465 * not optimal for use in data-structure sizing.
466 * Note: Only useful (i.e., supported) values are defined below.
467 */
468typedef enum {
d62a17ae 469 IANA_AFI_RESERVED = 0,
470 IANA_AFI_IPV4 = 1,
471 IANA_AFI_IPV6 = 2,
472 IANA_AFI_L2VPN = 25,
473 IANA_AFI_IPMR = 128,
474 IANA_AFI_IP6MR = 129
90d82769
DS
475} iana_afi_t;
476
5c525538
RW
477typedef enum {
478 IANA_SAFI_RESERVED = 0,
479 IANA_SAFI_UNICAST = 1,
480 IANA_SAFI_MULTICAST = 2,
481 IANA_SAFI_LABELED_UNICAST = 4,
482 IANA_SAFI_ENCAP = 7,
483 IANA_SAFI_EVPN = 70,
7c40bf39 484 IANA_SAFI_MPLS_VPN = 128,
485 IANA_SAFI_FLOWSPEC = 133
5c525538 486} iana_safi_t;
718e3744 487
718e3744 488/* Default Administrative Distance of each protocol. */
489#define ZEBRA_KERNEL_DISTANCE_DEFAULT 0
490#define ZEBRA_CONNECT_DISTANCE_DEFAULT 0
491#define ZEBRA_STATIC_DISTANCE_DEFAULT 1
492#define ZEBRA_RIP_DISTANCE_DEFAULT 120
493#define ZEBRA_RIPNG_DISTANCE_DEFAULT 120
494#define ZEBRA_OSPF_DISTANCE_DEFAULT 110
495#define ZEBRA_OSPF6_DISTANCE_DEFAULT 110
9e867fe6 496#define ZEBRA_ISIS_DISTANCE_DEFAULT 115
718e3744 497#define ZEBRA_IBGP_DISTANCE_DEFAULT 200
498#define ZEBRA_EBGP_DISTANCE_DEFAULT 20
7ab5795a 499#define ZEBRA_TABLE_DISTANCE_DEFAULT 15
718e3744 500
501/* Flag manipulation macros. */
502#define CHECK_FLAG(V,F) ((V) & (F))
548e6f7d 503#define SET_FLAG(V,F) (V) |= (F)
504#define UNSET_FLAG(V,F) (V) &= ~(F)
fb018d25 505#define RESET_FLAG(V) (V) = 0
9fb964de 506#define COND_FLAG(V, F, C) ((C) ? (SET_FLAG(V, F)) : (UNSET_FLAG(V, F)))
718e3744 507
f765d422
QY
508/* Atomic flag manipulation macros. */
509#define CHECK_FLAG_ATOMIC(PV, F) \
510 ((atomic_load_explicit(PV, memory_order_seq_cst)) & (F))
511#define SET_FLAG_ATOMIC(PV, F) \
512 ((atomic_fetch_or_explicit(PV, (F), memory_order_seq_cst)))
513#define UNSET_FLAG_ATOMIC(PV, F) \
514 ((atomic_fetch_and_explicit(PV, ~(F), memory_order_seq_cst)))
515#define RESET_FLAG_ATOMIC(PV) \
516 ((atomic_store_explicit(PV, 0, memory_order_seq_cst)))
517
c1b9800a 518/* Zebra types. Used in Zserv message header. */
d7c0a89a
QY
519typedef uint16_t zebra_size_t;
520typedef uint16_t zebra_command_t;
718e3744 521
b72ede27 522/* VRF ID type. */
a9ff90c4 523typedef uint32_t vrf_id_t;
b72ede27 524
dc9ffce8
CF
525typedef uint32_t route_tag_t;
526#define ROUTE_TAG_MAX UINT32_MAX
527#define ROUTE_TAG_PRI PRIu32
528
d62a17ae 529static inline afi_t afi_iana2int(iana_afi_t afi)
9cabb64b 530{
085347cf
RW
531 switch (afi) {
532 case IANA_AFI_IPV4:
d62a17ae 533 return AFI_IP;
085347cf 534 case IANA_AFI_IPV6:
d62a17ae 535 return AFI_IP6;
085347cf 536 case IANA_AFI_L2VPN:
d62a17ae 537 return AFI_L2VPN;
085347cf
RW
538 default:
539 return AFI_MAX;
540 }
9cabb64b 541}
542
d62a17ae 543static inline iana_afi_t afi_int2iana(afi_t afi)
9cabb64b 544{
085347cf
RW
545 switch (afi) {
546 case AFI_IP:
d62a17ae 547 return IANA_AFI_IPV4;
085347cf 548 case AFI_IP6:
d62a17ae 549 return IANA_AFI_IPV6;
085347cf 550 case AFI_L2VPN:
d62a17ae 551 return IANA_AFI_L2VPN;
085347cf
RW
552 default:
553 return IANA_AFI_RESERVED;
554 }
9cabb64b 555}
556
5c525538 557static inline safi_t safi_iana2int(iana_safi_t safi)
9cabb64b 558{
085347cf
RW
559 switch (safi) {
560 case IANA_SAFI_UNICAST:
d62a17ae 561 return SAFI_UNICAST;
085347cf 562 case IANA_SAFI_MULTICAST:
d62a17ae 563 return SAFI_MULTICAST;
085347cf 564 case IANA_SAFI_MPLS_VPN:
d62a17ae 565 return SAFI_MPLS_VPN;
085347cf 566 case IANA_SAFI_ENCAP:
d62a17ae 567 return SAFI_ENCAP;
085347cf 568 case IANA_SAFI_EVPN:
d62a17ae 569 return SAFI_EVPN;
085347cf 570 case IANA_SAFI_LABELED_UNICAST:
d62a17ae 571 return SAFI_LABELED_UNICAST;
7c40bf39 572 case IANA_SAFI_FLOWSPEC:
573 return SAFI_FLOWSPEC;
085347cf
RW
574 default:
575 return SAFI_MAX;
576 }
9cabb64b 577}
578
5c525538 579static inline iana_safi_t safi_int2iana(safi_t safi)
9cabb64b 580{
085347cf
RW
581 switch (safi) {
582 case SAFI_UNICAST:
d62a17ae 583 return IANA_SAFI_UNICAST;
085347cf 584 case SAFI_MULTICAST:
d62a17ae 585 return IANA_SAFI_MULTICAST;
085347cf 586 case SAFI_MPLS_VPN:
d62a17ae 587 return IANA_SAFI_MPLS_VPN;
085347cf 588 case SAFI_ENCAP:
d62a17ae 589 return IANA_SAFI_ENCAP;
085347cf 590 case SAFI_EVPN:
d62a17ae 591 return IANA_SAFI_EVPN;
085347cf 592 case SAFI_LABELED_UNICAST:
d62a17ae 593 return IANA_SAFI_LABELED_UNICAST;
7c40bf39 594 case SAFI_FLOWSPEC:
595 return IANA_SAFI_FLOWSPEC;
085347cf
RW
596 default:
597 return IANA_SAFI_RESERVED;
598 }
9cabb64b 599}
600
718e3744 601#endif /* _ZEBRA_H */