2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2002-12-13 21:15:29 +01:00
|
|
|
/*
|
|
|
|
* Prefix structure.
|
|
|
|
* Copyright (C) 1998 Kunihiro Ishiguro
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ZEBRA_PREFIX_H
|
|
|
|
#define _ZEBRA_PREFIX_H
|
|
|
|
|
2016-04-19 22:08:59 +02:00
|
|
|
#ifdef GNU_LINUX
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#else
|
|
|
|
#include <netinet/if_ether.h>
|
|
|
|
#endif
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
#include "sockunion.h"
|
2017-05-15 07:20:33 +02:00
|
|
|
#include "ipaddr.h"
|
2017-08-23 20:22:31 +02:00
|
|
|
#include "compiler.h"
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
|
2019-02-07 23:10:31 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-08-03 14:42:29 +02:00
|
|
|
#ifndef ETH_ALEN
|
|
|
|
#define ETH_ALEN 6
|
|
|
|
#endif
|
|
|
|
|
2020-07-14 03:21:27 +02:00
|
|
|
/* EVPN route types. */
|
|
|
|
typedef enum {
|
|
|
|
BGP_EVPN_AD_ROUTE = 1, /* Ethernet Auto-Discovery (A-D) route */
|
|
|
|
BGP_EVPN_MAC_IP_ROUTE, /* MAC/IP Advertisement route */
|
|
|
|
BGP_EVPN_IMET_ROUTE, /* Inclusive Multicast Ethernet Tag route */
|
|
|
|
BGP_EVPN_ES_ROUTE, /* Ethernet Segment route */
|
|
|
|
BGP_EVPN_IP_PREFIX_ROUTE, /* IP Prefix route */
|
|
|
|
} bgp_evpn_route_type;
|
|
|
|
|
2020-03-25 14:37:24 +01:00
|
|
|
/* value of first byte of ESI */
|
|
|
|
#define ESI_TYPE_ARBITRARY 0 /* */
|
|
|
|
#define ESI_TYPE_LACP 1 /* <> */
|
|
|
|
#define ESI_TYPE_BRIDGE 2 /* <Root bridge Mac-6B>:<Root Br Priority-2B>:00 */
|
|
|
|
#define ESI_TYPE_MAC 3 /* <Syst Mac Add-6B>:<Local Discriminator Value-3B> */
|
|
|
|
#define ESI_TYPE_ROUTER 4 /* <RouterId-4B>:<Local Discriminator Value-4B> */
|
|
|
|
#define ESI_TYPE_AS 5 /* <AS-4B>:<Local Discriminator Value-4B> */
|
|
|
|
|
|
|
|
#define MAX_ESI {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
|
|
|
|
|
|
|
|
|
bgpd: support for Ethernet Segments and Type-1/EAD routes
This is the base patch that brings in support for Type-1 routes.
It includes support for -
- Ethernet Segment (ES) management
- EAD route handling
- MAC-IP (Type-2) routes with a non-zero ESI i.e. Aliasing for
active-active multihoming
- Initial infra for consistency checking. Consistency checking
is a fundamental feature for active-active solutions like MLAG.
We will try to levarage the info in the EAD-ES/EAD-EVI routes to
detect inconsitencies in access config across VTEPs attached to
the same Ethernet Segment.
Functionality Overview -
========================
1. Ethernet segments are created in zebra and associated with
access VLANs. zebra sends that info as ES and ES-EVI objects to BGP.
2. BGP advertises EAD-ES and EAD-EVI routes for the locally attached
ethernet segments.
3. Similarly BGP processes EAD-ES and EAD-EVI routes from peers
and translates them into ES-VTEP objects which are then sent to zebra
as remote ESs.
4. Each ES in zebra is associated with a list of active VTEPs which
is then translated into a L2-NHG (nexthop group). This is the ES
"Alias" entry
5. MAC-IP routes with a non-zero ESI use the alias entry created in
(4.) to forward traffic i.e. a MAC-ECMP is done to these remote-ES
destinations.
EAD route management (route table and key) -
============================================
1. Local EAD-ES routes
a. route-table: per-ES route-table
key: {RD=ES-RD, ESI, ET=0xffffffff, VTEP-IP)
b. route-table: per-VNI route-table
Not added
c. route-table: global route-table
key: {RD=ES-RD, ESI, ET=0xffffffff)
2. Remote EAD-ES routes
a. route-table: per-ES route-table
Not added
b. route-table: per-VNI route-table
key: {RD=ES-RD, ESI, ET=0xffffffff, VTEP-IP)
c. route-table: global route-table
key: {RD=ES-RD, ESI, ET=0xffffffff)
3. Local EAD-EVI routes
a. route-table: per-ES route-table
Not added
b. route-table: per-VNI route-table
key: {RD=0, ESI, ET=0, VTEP-IP)
c. route-table: global route-table
key: {RD=L2-VNI-RD, ESI, ET=0)
4. Remote EAD-EVI routes
a. route-table: per-ES route-table
Not added
b. route-table: per-VNI route-table
key: {RD=0, ESI, ET=0, VTEP-IP)
c. route-table: global route-table
key: {RD=L2-VNI-RD, ESI, ET=0)
Please refer to bgp_evpn_mh.h for info on how the data-structures are
organized.
Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2020-03-27 22:43:50 +01:00
|
|
|
#define EVPN_ETH_TAG_BYTES 4
|
2018-04-14 00:01:12 +02:00
|
|
|
#define ESI_BYTES 10
|
2018-05-16 14:17:53 +02:00
|
|
|
#define ESI_STR_LEN (3 * ESI_BYTES)
|
2020-05-09 01:35:09 +02:00
|
|
|
#define EVPN_DF_ALG_STR_LEN 24
|
2018-04-14 00:01:12 +02:00
|
|
|
|
2020-03-25 14:37:24 +01:00
|
|
|
/* Maximum number of VTEPs per-ES -
|
|
|
|
* XXX - temporary limit for allocating strings etc.
|
|
|
|
*/
|
|
|
|
#define ES_VTEP_MAX_CNT 10
|
|
|
|
#define ES_VTEP_LIST_STR_SZ (ES_VTEP_MAX_CNT * 16)
|
|
|
|
|
2017-08-03 14:42:29 +02:00
|
|
|
#define ETHER_ADDR_STRLEN (3*ETH_ALEN)
|
2016-04-19 22:08:59 +02:00
|
|
|
/*
|
|
|
|
* there isn't a portable ethernet address type. We define our
|
|
|
|
* own to simplify internal handling
|
|
|
|
*/
|
|
|
|
struct ethaddr {
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t octet[ETH_ALEN];
|
2016-10-27 10:24:44 +02:00
|
|
|
} __attribute__((packed));
|
2016-04-19 22:08:59 +02:00
|
|
|
|
|
|
|
|
2016-07-27 19:20:47 +02:00
|
|
|
/* length is the number of valuable bits of prefix structure
|
2017-07-22 14:52:33 +02:00
|
|
|
* 18 bytes is current length in structure, if address is ipv4
|
|
|
|
* 30 bytes is in case of ipv6
|
|
|
|
*/
|
2016-07-27 19:20:47 +02:00
|
|
|
#define PREFIX_LEN_ROUTE_TYPE_5_IPV4 (18*8)
|
|
|
|
#define PREFIX_LEN_ROUTE_TYPE_5_IPV6 (30*8)
|
|
|
|
|
2018-04-14 00:37:30 +02:00
|
|
|
typedef struct esi_t_ {
|
2020-03-25 14:37:24 +01:00
|
|
|
uint8_t val[ESI_BYTES];
|
2018-04-14 00:37:30 +02:00
|
|
|
} esi_t;
|
|
|
|
|
|
|
|
struct evpn_ead_addr {
|
|
|
|
esi_t esi;
|
|
|
|
uint32_t eth_tag;
|
2020-03-25 14:37:24 +01:00
|
|
|
struct ipaddr ip;
|
lib, bgpd: changes for EAD-per-ES fragmentation
The EAD-per-ES route carries ECs for all the ES-EVI RTs. As the number of VNIs
increase all RTs do not fit into a standard BGP UPDATE (4K) so the route needs
to be fragmented.
Each fragment is associated with a separate RD and frag-id -
1. Local ES-per-EAD -
ES route table - {ES-frag-ID, ESI, ET=0xffffffff, VTEP-IP}
global route table - {RD-=ES-frag-RD, ESI, ET=0xffffffff}
2. Remote ES-per-EAD -
VNI route table - {ESI, ET=0xffffffff, VTEP-IP}
global route table - {RD-=ES-frag-RD, ESI, ET=0xffffffff}
Note: The fragment ID is abandoned in the per-VNI routing table. At this
point that is acceptable as we dont expect more than one-ES-per-EAD fragment
to be imported into the per-VNI routing table. But that may need to be
re-worked at a later point.
CLI changes (sample with 4 VNIs per-fragment for experimental pruposes) -
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
root@torm-11:mgmt:~# vtysh -c "show bgp l2vpn evpn es 03:44:38:39:ff:ff:01:00:00:01"
ESI: 03:44:38:39:ff:ff:01:00:00:01
Type: LR
RD: 27.0.0.21:3
Originator-IP: 27.0.0.21
Local ES DF preference: 50000
VNI Count: 10
Remote VNI Count: 10
VRF Count: 3
MACIP EVI Path Count: 33
MACIP Global Path Count: 198
Inconsistent VNI VTEP Count: 0
Inconsistencies: -
Fragments: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
27.0.0.21:3 EVIs: 4
27.0.0.21:13 EVIs: 4
27.0.0.21:22 EVIs: 2
VTEPs:
27.0.0.22 flags: EA df_alg: preference df_pref: 32767
27.0.0.23 flags: EA df_alg: preference df_pref: 32767
root@torm-11:mgmt:~# vtysh -c "show bgp l2vpn evpn es-evi vni 1002 detail"
VNI: 1002 ESI: 03:44:38:39:ff:ff:01:00:00:01
Type: LR
ES fragment RD: 27.0.0.21:13 >>>>>>>>>>>>>>>>>>>>>>>>>
Inconsistencies: -
VTEPs: 27.0.0.22(EV),27.0.0.23(EV)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
PS: The number of EVIs per-fragment has been set to 128 and may need further
tuning.
Ticket: #2632967
Signed-off-by: Anuradha Karuppiah <anuradhak@nvidia.com>
2021-06-04 02:28:43 +02:00
|
|
|
uint16_t frag_id;
|
2018-04-14 00:37:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct evpn_macip_addr {
|
|
|
|
uint32_t eth_tag;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t ip_prefix_length;
|
2016-07-27 19:20:47 +02:00
|
|
|
struct ethaddr mac;
|
2018-04-14 00:37:30 +02:00
|
|
|
struct ipaddr ip;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct evpn_imet_addr {
|
2016-07-27 19:20:47 +02:00
|
|
|
uint32_t eth_tag;
|
2018-04-14 00:37:30 +02:00
|
|
|
uint8_t ip_prefix_length;
|
|
|
|
struct ipaddr ip;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct evpn_es_addr {
|
|
|
|
esi_t esi;
|
|
|
|
uint8_t ip_prefix_length;
|
2017-05-26 19:44:29 +02:00
|
|
|
struct ipaddr ip;
|
2016-07-27 19:20:47 +02:00
|
|
|
};
|
|
|
|
|
2018-04-14 00:37:30 +02:00
|
|
|
struct evpn_prefix_addr {
|
|
|
|
uint32_t eth_tag;
|
|
|
|
uint8_t ip_prefix_length;
|
|
|
|
struct ipaddr ip;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* EVPN address (RFC 7432) */
|
|
|
|
struct evpn_addr {
|
|
|
|
uint8_t route_type;
|
|
|
|
union {
|
|
|
|
struct evpn_ead_addr _ead_addr;
|
|
|
|
struct evpn_macip_addr _macip_addr;
|
|
|
|
struct evpn_imet_addr _imet_addr;
|
|
|
|
struct evpn_es_addr _es_addr;
|
|
|
|
struct evpn_prefix_addr _prefix_addr;
|
|
|
|
} u;
|
|
|
|
#define ead_addr u._ead_addr
|
|
|
|
#define macip_addr u._macip_addr
|
|
|
|
#define imet_addr u._imet_addr
|
|
|
|
#define es_addr u._es_addr
|
|
|
|
#define prefix_addr u._prefix_addr
|
|
|
|
};
|
2016-07-27 19:20:47 +02:00
|
|
|
|
2004-01-13 15:55:40 +01:00
|
|
|
/*
|
|
|
|
* A struct prefix contains an address family, a prefix length, and an
|
|
|
|
* address. This can represent either a 'network prefix' as defined
|
|
|
|
* by CIDR, where the 'host bits' of the prefix are 0
|
|
|
|
* (e.g. AF_INET:10.0.0.0/8), or an address and netmask
|
|
|
|
* (e.g. AF_INET:10.0.0.9/8), such as might be configured on an
|
|
|
|
* interface.
|
|
|
|
*/
|
|
|
|
|
2016-04-19 22:08:59 +02:00
|
|
|
/* different OSes use different names */
|
|
|
|
#if defined(AF_PACKET)
|
|
|
|
#define AF_ETHERNET AF_PACKET
|
|
|
|
#else
|
|
|
|
#if defined(AF_LINK)
|
|
|
|
#define AF_ETHERNET AF_LINK
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-08-08 16:16:12 +02:00
|
|
|
/* The 'family' in the prefix structure is internal to FRR and need not
|
|
|
|
* map to standard OS AF_ definitions except where needed for interacting
|
|
|
|
* with the kernel. However, AF_ definitions are currently in use and
|
|
|
|
* prevalent across the code. Define a new FRR-specific AF for EVPN to
|
|
|
|
* distinguish between 'ethernet' (MAC-only) and 'evpn' prefixes and
|
|
|
|
* ensure it does not conflict with any OS AF_ definition.
|
|
|
|
*/
|
|
|
|
#if !defined(AF_EVPN)
|
|
|
|
#define AF_EVPN (AF_MAX + 1)
|
|
|
|
#endif
|
|
|
|
|
2018-01-10 19:13:27 +01:00
|
|
|
#if !defined(AF_FLOWSPEC)
|
|
|
|
#define AF_FLOWSPEC (AF_MAX + 2)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct flowspec_prefix {
|
2019-10-15 15:01:39 +02:00
|
|
|
uint8_t family;
|
2018-01-10 19:13:27 +01:00
|
|
|
uint16_t prefixlen; /* length in bytes */
|
|
|
|
uintptr_t ptr;
|
|
|
|
};
|
|
|
|
|
2017-08-08 16:16:12 +02:00
|
|
|
/* FRR generic prefix structure. */
|
2002-12-13 21:15:29 +01:00
|
|
|
struct prefix {
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t family;
|
2018-07-27 02:11:13 +02:00
|
|
|
uint16_t prefixlen;
|
2002-12-13 21:15:29 +01:00
|
|
|
union {
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t prefix;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct in_addr prefix4;
|
|
|
|
struct in6_addr prefix6;
|
|
|
|
struct {
|
|
|
|
struct in_addr id;
|
|
|
|
struct in_addr adv_router;
|
|
|
|
} lp;
|
2016-04-19 22:08:59 +02:00
|
|
|
struct ethaddr prefix_eth; /* AF_ETHERNET */
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t val[16];
|
2019-01-10 00:28:10 +01:00
|
|
|
uint32_t val32[4];
|
2014-04-28 12:58:06 +02:00
|
|
|
uintptr_t ptr;
|
2017-08-08 16:16:12 +02:00
|
|
|
struct evpn_addr prefix_evpn; /* AF_EVPN */
|
2018-01-10 19:13:27 +01:00
|
|
|
struct flowspec_prefix prefix_flowspec; /* AF_FLOWSPEC */
|
2002-12-13 21:15:29 +01:00
|
|
|
} u __attribute__((aligned(8)));
|
|
|
|
};
|
|
|
|
|
|
|
|
/* IPv4 prefix structure. */
|
|
|
|
struct prefix_ipv4 {
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t family;
|
2018-07-27 02:11:13 +02:00
|
|
|
uint16_t prefixlen;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct in_addr prefix __attribute__((aligned(8)));
|
|
|
|
};
|
|
|
|
|
|
|
|
/* IPv6 prefix structure. */
|
|
|
|
struct prefix_ipv6 {
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t family;
|
2018-07-27 02:11:13 +02:00
|
|
|
uint16_t prefixlen;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct in6_addr prefix __attribute__((aligned(8)));
|
|
|
|
};
|
|
|
|
|
|
|
|
struct prefix_ls {
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t family;
|
2018-07-27 02:11:13 +02:00
|
|
|
uint16_t prefixlen;
|
2002-12-13 21:15:29 +01:00
|
|
|
struct in_addr id __attribute__((aligned(8)));
|
|
|
|
struct in_addr adv_router;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Prefix for routing distinguisher. */
|
|
|
|
struct prefix_rd {
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t family;
|
2018-07-27 02:11:13 +02:00
|
|
|
uint16_t prefixlen;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t val[8] __attribute__((aligned(8)));
|
2002-12-13 21:15:29 +01:00
|
|
|
};
|
|
|
|
|
2016-04-19 22:08:59 +02:00
|
|
|
/* Prefix for ethernet. */
|
|
|
|
struct prefix_eth {
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t family;
|
2018-07-27 02:11:13 +02:00
|
|
|
uint16_t prefixlen;
|
2016-04-19 22:08:59 +02:00
|
|
|
struct ethaddr eth_addr __attribute__((aligned(8))); /* AF_ETHERNET */
|
|
|
|
};
|
|
|
|
|
2017-05-15 07:20:33 +02:00
|
|
|
/* EVPN prefix structure. */
|
|
|
|
struct prefix_evpn {
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t family;
|
2018-07-27 02:11:13 +02:00
|
|
|
uint16_t prefixlen;
|
2017-05-15 07:20:33 +02:00
|
|
|
struct evpn_addr prefix __attribute__((aligned(8)));
|
|
|
|
};
|
|
|
|
|
2018-04-14 00:37:30 +02:00
|
|
|
static inline int is_evpn_prefix_ipaddr_none(const struct prefix_evpn *evp)
|
|
|
|
{
|
2020-07-14 03:21:27 +02:00
|
|
|
if (evp->prefix.route_type == BGP_EVPN_AD_ROUTE)
|
2020-03-25 14:37:24 +01:00
|
|
|
return IS_IPADDR_NONE(&(evp)->prefix.ead_addr.ip);
|
2020-07-14 03:21:27 +02:00
|
|
|
if (evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE)
|
2018-04-14 00:37:30 +02:00
|
|
|
return IS_IPADDR_NONE(&(evp)->prefix.macip_addr.ip);
|
2020-07-14 03:21:27 +02:00
|
|
|
if (evp->prefix.route_type == BGP_EVPN_IMET_ROUTE)
|
2018-04-14 00:37:30 +02:00
|
|
|
return IS_IPADDR_NONE(&(evp)->prefix.imet_addr.ip);
|
2020-07-14 03:21:27 +02:00
|
|
|
if (evp->prefix.route_type == BGP_EVPN_ES_ROUTE)
|
2018-04-14 00:01:12 +02:00
|
|
|
return IS_IPADDR_NONE(&(evp)->prefix.es_addr.ip);
|
2020-07-14 03:21:27 +02:00
|
|
|
if (evp->prefix.route_type == BGP_EVPN_IP_PREFIX_ROUTE)
|
2018-04-14 00:37:30 +02:00
|
|
|
return IS_IPADDR_NONE(&(evp)->prefix.prefix_addr.ip);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int is_evpn_prefix_ipaddr_v4(const struct prefix_evpn *evp)
|
|
|
|
{
|
2020-07-14 03:21:27 +02:00
|
|
|
if (evp->prefix.route_type == BGP_EVPN_AD_ROUTE)
|
2020-03-25 14:37:24 +01:00
|
|
|
return IS_IPADDR_V4(&(evp)->prefix.ead_addr.ip);
|
2020-07-14 03:21:27 +02:00
|
|
|
if (evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE)
|
2018-04-14 00:37:30 +02:00
|
|
|
return IS_IPADDR_V4(&(evp)->prefix.macip_addr.ip);
|
2020-07-14 03:21:27 +02:00
|
|
|
if (evp->prefix.route_type == BGP_EVPN_IMET_ROUTE)
|
2018-04-14 00:37:30 +02:00
|
|
|
return IS_IPADDR_V4(&(evp)->prefix.imet_addr.ip);
|
2020-07-14 03:21:27 +02:00
|
|
|
if (evp->prefix.route_type == BGP_EVPN_ES_ROUTE)
|
2018-04-14 00:01:12 +02:00
|
|
|
return IS_IPADDR_V4(&(evp)->prefix.es_addr.ip);
|
2020-07-14 03:21:27 +02:00
|
|
|
if (evp->prefix.route_type == BGP_EVPN_IP_PREFIX_ROUTE)
|
2018-04-14 00:37:30 +02:00
|
|
|
return IS_IPADDR_V4(&(evp)->prefix.prefix_addr.ip);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int is_evpn_prefix_ipaddr_v6(const struct prefix_evpn *evp)
|
|
|
|
{
|
2020-07-14 03:21:27 +02:00
|
|
|
if (evp->prefix.route_type == BGP_EVPN_AD_ROUTE)
|
2020-03-25 14:37:24 +01:00
|
|
|
return IS_IPADDR_V6(&(evp)->prefix.ead_addr.ip);
|
2020-07-14 03:21:27 +02:00
|
|
|
if (evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE)
|
2018-04-14 00:37:30 +02:00
|
|
|
return IS_IPADDR_V6(&(evp)->prefix.macip_addr.ip);
|
2020-07-14 03:21:27 +02:00
|
|
|
if (evp->prefix.route_type == BGP_EVPN_IMET_ROUTE)
|
2018-04-14 00:37:30 +02:00
|
|
|
return IS_IPADDR_V6(&(evp)->prefix.imet_addr.ip);
|
2020-07-14 03:21:27 +02:00
|
|
|
if (evp->prefix.route_type == BGP_EVPN_ES_ROUTE)
|
2018-04-14 00:01:12 +02:00
|
|
|
return IS_IPADDR_V6(&(evp)->prefix.es_addr.ip);
|
2020-07-14 03:21:27 +02:00
|
|
|
if (evp->prefix.route_type == BGP_EVPN_IP_PREFIX_ROUTE)
|
2018-04-14 00:37:30 +02:00
|
|
|
return IS_IPADDR_V6(&(evp)->prefix.prefix_addr.ip);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-10 19:13:27 +01:00
|
|
|
/* Prefix for a Flowspec entry */
|
|
|
|
struct prefix_fs {
|
|
|
|
uint8_t family;
|
2018-07-27 02:11:13 +02:00
|
|
|
uint16_t prefixlen; /* unused */
|
2018-01-10 19:13:27 +01:00
|
|
|
struct flowspec_prefix prefix __attribute__((aligned(8)));
|
|
|
|
};
|
|
|
|
|
2016-07-22 11:58:08 +02:00
|
|
|
struct prefix_sg {
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t family;
|
2018-07-27 02:11:13 +02:00
|
|
|
uint16_t prefixlen;
|
2017-05-17 19:19:56 +02:00
|
|
|
struct in_addr src __attribute__((aligned(8)));
|
2016-07-22 11:58:08 +02:00
|
|
|
struct in_addr grp;
|
|
|
|
};
|
|
|
|
|
2016-08-10 00:55:51 +02:00
|
|
|
union prefixptr {
|
2019-02-11 11:41:26 +01:00
|
|
|
prefixtype(prefixptr, struct prefix, p)
|
|
|
|
prefixtype(prefixptr, struct prefix_ipv4, p4)
|
|
|
|
prefixtype(prefixptr, struct prefix_ipv6, p6)
|
|
|
|
prefixtype(prefixptr, struct prefix_evpn, evp)
|
|
|
|
prefixtype(prefixptr, struct prefix_fs, fs)
|
2020-06-15 15:21:19 +02:00
|
|
|
prefixtype(prefixptr, struct prefix_rd, rd)
|
2021-03-27 20:55:42 +01:00
|
|
|
} TRANSPARENT_UNION;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-08-10 00:55:51 +02:00
|
|
|
union prefixconstptr {
|
2019-02-11 11:41:26 +01:00
|
|
|
prefixtype(prefixconstptr, const struct prefix, p)
|
|
|
|
prefixtype(prefixconstptr, const struct prefix_ipv4, p4)
|
|
|
|
prefixtype(prefixconstptr, const struct prefix_ipv6, p6)
|
|
|
|
prefixtype(prefixconstptr, const struct prefix_evpn, evp)
|
|
|
|
prefixtype(prefixconstptr, const struct prefix_fs, fs)
|
2020-06-15 15:21:19 +02:00
|
|
|
prefixtype(prefixconstptr, const struct prefix_rd, rd)
|
2021-03-27 20:55:42 +01:00
|
|
|
} TRANSPARENT_UNION;
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
#ifndef INET_ADDRSTRLEN
|
|
|
|
#define INET_ADDRSTRLEN 16
|
|
|
|
#endif /* INET_ADDRSTRLEN */
|
|
|
|
|
|
|
|
#ifndef INET6_ADDRSTRLEN
|
2018-07-27 02:11:13 +02:00
|
|
|
/* dead:beef:dead:beef:dead:beef:dead:beef + \0 */
|
2002-12-13 21:15:29 +01:00
|
|
|
#define INET6_ADDRSTRLEN 46
|
|
|
|
#endif /* INET6_ADDRSTRLEN */
|
|
|
|
|
|
|
|
#ifndef INET6_BUFSIZ
|
2018-07-27 02:11:13 +02:00
|
|
|
#define INET6_BUFSIZ 53
|
2002-12-13 21:15:29 +01:00
|
|
|
#endif /* INET6_BUFSIZ */
|
|
|
|
|
2018-10-25 22:24:25 +02:00
|
|
|
/* Maximum string length of the result of prefix2str */
|
|
|
|
#define PREFIX_STRLEN 80
|
2015-05-23 10:08:39 +02:00
|
|
|
|
2019-03-19 19:36:41 +01:00
|
|
|
/*
|
2022-07-11 13:56:29 +02:00
|
|
|
* Longest possible length of a (S,G) string is 34 bytes
|
2019-04-20 16:34:03 +02:00
|
|
|
* 123.123.123.123 = 15 * 2
|
2019-03-19 19:36:41 +01:00
|
|
|
* (,) = 3
|
|
|
|
* NULL Character at end = 1
|
|
|
|
* (123.123.123.123,123.123.123.123)
|
|
|
|
*/
|
2019-04-20 16:34:03 +02:00
|
|
|
#define PREFIX_SG_STR_LEN 34
|
2019-03-19 19:36:41 +01:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Max bit/byte length of IPv4 address. */
|
|
|
|
#define IPV4_MAX_BYTELEN 4
|
|
|
|
#define IPV4_MAX_BITLEN 32
|
|
|
|
#define IPV4_ADDR_CMP(D,S) memcmp ((D), (S), IPV4_MAX_BYTELEN)
|
2017-08-09 13:57:49 +02:00
|
|
|
|
|
|
|
static inline bool ipv4_addr_same(const struct in_addr *a,
|
|
|
|
const struct in_addr *b)
|
|
|
|
{
|
|
|
|
return (a->s_addr == b->s_addr);
|
|
|
|
}
|
|
|
|
#define IPV4_ADDR_SAME(A,B) ipv4_addr_same((A), (B))
|
|
|
|
|
|
|
|
static inline void ipv4_addr_copy(struct in_addr *dst,
|
|
|
|
const struct in_addr *src)
|
|
|
|
{
|
|
|
|
dst->s_addr = src->s_addr;
|
|
|
|
}
|
|
|
|
#define IPV4_ADDR_COPY(D,S) ipv4_addr_copy((D), (S))
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2018-03-27 21:13:34 +02:00
|
|
|
#define IPV4_NET0(a) ((((uint32_t)(a)) & 0xff000000) == 0x00000000)
|
|
|
|
#define IPV4_NET127(a) ((((uint32_t)(a)) & 0xff000000) == 0x7f000000)
|
|
|
|
#define IPV4_LINKLOCAL(a) ((((uint32_t)(a)) & 0xffff0000) == 0xa9fe0000)
|
2022-07-01 22:26:24 +02:00
|
|
|
#define IPV4_CLASS_D(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000)
|
|
|
|
#define IPV4_CLASS_E(a) ((((uint32_t)(a)) & 0xf0000000) == 0xf0000000)
|
2018-03-27 21:13:34 +02:00
|
|
|
#define IPV4_CLASS_DE(a) ((((uint32_t)(a)) & 0xe0000000) == 0xe0000000)
|
|
|
|
#define IPV4_MC_LINKLOCAL(a) ((((uint32_t)(a)) & 0xffffff00) == 0xe0000000)
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Max bit/byte length of IPv6 address. */
|
|
|
|
#define IPV6_MAX_BYTELEN 16
|
|
|
|
#define IPV6_MAX_BITLEN 128
|
|
|
|
#define IPV6_ADDR_CMP(D,S) memcmp ((D), (S), IPV6_MAX_BYTELEN)
|
|
|
|
#define IPV6_ADDR_SAME(D,S) (memcmp ((D), (S), IPV6_MAX_BYTELEN) == 0)
|
|
|
|
#define IPV6_ADDR_COPY(D,S) memcpy ((D), (S), IPV6_MAX_BYTELEN)
|
|
|
|
|
|
|
|
/* Count prefix size from mask length */
|
|
|
|
#define PSIZE(a) (((a) + 7) / (8))
|
|
|
|
|
2017-03-09 15:54:20 +01:00
|
|
|
#define BSIZE(a) ((a) * (8))
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Prefix's family member. */
|
|
|
|
#define PREFIX_FAMILY(p) ((p)->family)
|
|
|
|
|
2015-05-20 22:34:56 +02:00
|
|
|
/* glibc defines s6_addr32 to __in6_u.__u6_addr32 if __USE_{MISC || GNU} */
|
|
|
|
#ifndef s6_addr32
|
|
|
|
#define s6_addr32 __u6_addr.__u6_addr32
|
|
|
|
#endif /*s6_addr32*/
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Prototypes. */
|
2023-09-07 21:10:42 +02:00
|
|
|
extern int str2family(const char *string);
|
|
|
|
extern int afi2family(afi_t afi);
|
|
|
|
extern afi_t family2afi(int family);
|
2018-03-28 18:56:45 +02:00
|
|
|
extern const char *family2str(int family);
|
2016-01-12 19:41:50 +01:00
|
|
|
extern const char *safi2str(safi_t safi);
|
2016-04-19 22:08:59 +02:00
|
|
|
extern const char *afi2str(afi_t afi);
|
2023-02-23 20:22:33 +01:00
|
|
|
extern const char *afi2str_lower(afi_t afi);
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
|
2022-04-24 15:46:33 +02:00
|
|
|
static inline afi_t prefix_afi(union prefixconstptr pu)
|
|
|
|
{
|
|
|
|
return family2afi(pu.p->family);
|
|
|
|
}
|
|
|
|
|
2020-06-22 19:59:01 +02:00
|
|
|
/*
|
|
|
|
* Check bit of the prefix.
|
|
|
|
*
|
|
|
|
* prefix
|
|
|
|
* byte buffer
|
|
|
|
*
|
|
|
|
* bit_index
|
|
|
|
* which bit to fetch from byte buffer, 0 indexed.
|
|
|
|
*/
|
|
|
|
extern unsigned int prefix_bit(const uint8_t *prefix, const uint16_t bit_index);
|
2011-04-08 13:44:43 +02:00
|
|
|
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
extern struct prefix *prefix_new(void);
|
2019-10-30 01:05:27 +01:00
|
|
|
extern void prefix_free(struct prefix **p);
|
|
|
|
/*
|
|
|
|
* Function to handle prefix_free being used as a del function.
|
|
|
|
*/
|
|
|
|
extern void prefix_free_lists(void *arg);
|
2022-04-08 18:17:38 +02:00
|
|
|
extern const char *prefix_family_str(union prefixconstptr pu);
|
|
|
|
extern int prefix_blen(union prefixconstptr pu);
|
2023-09-07 21:10:42 +02:00
|
|
|
extern int str2prefix(const char *string, struct prefix *prefix);
|
2015-11-23 21:44:34 +01:00
|
|
|
|
2016-08-10 00:54:14 +02:00
|
|
|
#define PREFIX2STR_BUFFER PREFIX_STRLEN
|
|
|
|
|
2019-03-19 19:36:41 +01:00
|
|
|
extern void prefix_mcast_inet4_dump(const char *onfail, struct in_addr addr,
|
|
|
|
char *buf, int buf_size);
|
|
|
|
extern const char *prefix_sg2str(const struct prefix_sg *sg, char *str);
|
2023-09-07 21:10:42 +02:00
|
|
|
extern const char *prefix2str(union prefixconstptr upfx, char *buffer,
|
|
|
|
int size);
|
2019-09-11 09:01:39 +02:00
|
|
|
extern int evpn_type5_prefix_match(const struct prefix *evpn_pfx,
|
|
|
|
const struct prefix *match_pfx);
|
2022-04-08 18:17:38 +02:00
|
|
|
extern int prefix_match(union prefixconstptr unet, union prefixconstptr upfx);
|
|
|
|
extern int prefix_match_network_statement(union prefixconstptr unet,
|
|
|
|
union prefixconstptr upfx);
|
|
|
|
extern int prefix_same(union prefixconstptr ua, union prefixconstptr ub);
|
|
|
|
extern int prefix_cmp(union prefixconstptr ua, union prefixconstptr ub);
|
|
|
|
extern int prefix_common_bits(union prefixconstptr ua, union prefixconstptr ub);
|
|
|
|
extern void prefix_copy(union prefixptr udst, union prefixconstptr usrc);
|
|
|
|
extern void apply_mask(union prefixptr pu);
|
2022-05-30 15:42:06 +02:00
|
|
|
extern bool evpn_addr_same(const struct evpn_addr *e1, const struct evpn_addr *e2);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-07-29 15:49:49 +02:00
|
|
|
#ifdef __clang_analyzer__
|
|
|
|
/* clang-SA doesn't understand transparent unions, making it think that the
|
|
|
|
* target of prefix_copy is uninitialized. So just memset the target.
|
|
|
|
* cf. https://bugs.llvm.org/show_bug.cgi?id=42811
|
|
|
|
*/
|
|
|
|
#define prefix_copy(a, b) ({ memset(a, 0, sizeof(*a)); prefix_copy(a, b); })
|
|
|
|
#endif
|
|
|
|
|
2023-09-07 21:10:42 +02:00
|
|
|
extern struct prefix *sockunion2hostprefix(const union sockunion *su,
|
2015-05-22 12:40:57 +02:00
|
|
|
struct prefix *p);
|
2023-09-07 21:10:42 +02:00
|
|
|
extern void prefix2sockunion(const struct prefix *p, union sockunion *su);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2023-09-07 21:10:42 +02:00
|
|
|
extern int str2prefix_eth(const char *string, struct prefix_eth *p);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
extern struct prefix_ipv4 *prefix_ipv4_new(void);
|
2019-10-30 01:05:27 +01:00
|
|
|
extern void prefix_ipv4_free(struct prefix_ipv4 **p);
|
2023-09-07 21:10:42 +02:00
|
|
|
extern int str2prefix_ipv4(const char *string, struct prefix_ipv4 *p);
|
|
|
|
extern void apply_mask_ipv4(struct prefix_ipv4 *p);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2023-09-07 21:10:42 +02:00
|
|
|
extern int prefix_ipv4_any(const struct prefix_ipv4 *p);
|
|
|
|
extern void apply_classful_mask_ipv4(struct prefix_ipv4 *p);
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
|
2023-09-07 21:10:42 +02:00
|
|
|
extern uint8_t ip_masklen(struct in_addr addr);
|
|
|
|
extern void masklen2ip(const int length, struct in_addr *addr);
|
2004-10-19 21:44:43 +02:00
|
|
|
/* given the address of a host on a network and the network mask length,
|
|
|
|
* calculate the broadcast address for that network;
|
2019-08-01 12:19:34 +02:00
|
|
|
* special treatment for /31 according to RFC3021 section 3.3 */
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
extern in_addr_t ipv4_broadcast_addr(in_addr_t hostaddr, int masklen);
|
2004-10-19 21:44:43 +02:00
|
|
|
|
2023-09-07 21:10:42 +02:00
|
|
|
extern int netmask_str2prefix_str(const char *net_str, const char *mask_str,
|
|
|
|
char *prefix_str, size_t prefix_str_len);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
header.
Cleanup any definitions with unspecified arguments.
Add casts for callback assignments where the callback is defined,
typically, as passing void *, but the function being assigned has
some other pointer type defined as its argument, as gcc complains
about casts from void * to X* via function arguments.
Fix some old K&R style function argument definitions.
Add noreturn gcc attribute to some functions, as appropriate.
Add unused gcc attribute to some functions (eg ones meant to help
while debugging)
Add guard defines to headers which were missing them.
* command.c: (install_node) add const qualifier, still doesnt shut
up the warning though, because of the double pointer.
(cmp_node) ditto
* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
fromn vty.h ones to fix some of the (long) < 0 warnings.
* thread.c: (various) use thread_empty
(cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
removed from ospfd/ospf_vty.h
* zebra.h: Move definition of ZEBRA_PORT to here, to remove
dependence of lib on zebra/zserv.h
2005-05-06 23:25:49 +02:00
|
|
|
extern struct prefix_ipv6 *prefix_ipv6_new(void);
|
2019-10-30 01:05:27 +01:00
|
|
|
extern void prefix_ipv6_free(struct prefix_ipv6 **p);
|
2023-09-07 21:10:42 +02:00
|
|
|
extern int str2prefix_ipv6(const char *str, struct prefix_ipv6 *p);
|
|
|
|
extern void apply_mask_ipv6(struct prefix_ipv6 *p);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2023-09-07 21:10:42 +02:00
|
|
|
extern int ip6_masklen(struct in6_addr netmask);
|
|
|
|
extern void masklen2ip6(const int masklen, struct in6_addr *netmask);
|
2004-10-04 21:10:31 +02:00
|
|
|
|
2019-08-22 14:36:59 +02:00
|
|
|
extern int is_zero_mac(const struct ethaddr *mac);
|
2020-02-10 20:38:27 +01:00
|
|
|
extern bool is_mcast_mac(const struct ethaddr *mac);
|
|
|
|
extern bool is_bcast_mac(const struct ethaddr *mac);
|
2017-02-09 08:42:32 +01:00
|
|
|
extern int prefix_str2mac(const char *str, struct ethaddr *mac);
|
|
|
|
extern char *prefix_mac2str(const struct ethaddr *mac, char *buf, int size);
|
2017-02-01 18:26:34 +01:00
|
|
|
|
2019-05-01 01:40:11 +02:00
|
|
|
extern unsigned prefix_hash_key(const void *pp);
|
2017-08-03 13:37:38 +02:00
|
|
|
|
2018-04-14 00:01:12 +02:00
|
|
|
extern int str_to_esi(const char *str, esi_t *esi);
|
|
|
|
extern char *esi_to_str(const esi_t *esi, char *buf, int size);
|
2020-05-09 01:35:09 +02:00
|
|
|
extern char *evpn_es_df_alg2str(uint8_t df_alg, char *buf, int buf_len);
|
2018-04-14 00:01:12 +02:00
|
|
|
extern void prefix_evpn_hexdump(const struct prefix_evpn *p);
|
2022-07-01 22:26:24 +02:00
|
|
|
extern bool ipv4_unicast_valid(const struct in_addr *addr);
|
2021-03-10 00:59:09 +01:00
|
|
|
extern int evpn_prefix2prefix(const struct prefix *evpn, struct prefix *to);
|
2022-06-06 09:47:27 +02:00
|
|
|
|
2021-07-08 16:10:14 +02:00
|
|
|
static inline int ipv6_martian(const struct in6_addr *addr)
|
2015-05-20 02:47:23 +02:00
|
|
|
{
|
|
|
|
struct in6_addr localhost_addr;
|
|
|
|
|
|
|
|
inet_pton(AF_INET6, "::1", &localhost_addr);
|
|
|
|
|
|
|
|
if (IPV6_ADDR_SAME(&localhost_addr, addr))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-21 10:02:46 +02:00
|
|
|
extern int macstr2prefix_evpn(const char *str, struct prefix_evpn *p);
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2015-05-20 02:47:23 +02:00
|
|
|
/* NOTE: This routine expects the address argument in network byte order. */
|
2022-07-01 22:27:56 +02:00
|
|
|
static inline bool ipv4_martian(const struct in_addr *addr)
|
2014-01-12 19:30:13 +01:00
|
|
|
{
|
2023-02-20 16:34:26 +01:00
|
|
|
if (!ipv4_unicast_valid(addr))
|
2022-07-01 22:27:56 +02:00
|
|
|
return true;
|
|
|
|
return false;
|
2014-01-12 19:30:13 +01:00
|
|
|
}
|
|
|
|
|
2021-07-08 19:09:20 +02:00
|
|
|
static inline bool is_default_prefix4(const struct prefix_ipv4 *p)
|
2015-06-11 18:11:12 +02:00
|
|
|
{
|
2021-07-08 19:09:20 +02:00
|
|
|
return p && p->family == AF_INET && p->prefixlen == 0
|
|
|
|
&& p->prefix.s_addr == INADDR_ANY;
|
|
|
|
}
|
2015-06-11 18:11:12 +02:00
|
|
|
|
2021-07-08 19:09:20 +02:00
|
|
|
static inline bool is_default_prefix6(const struct prefix_ipv6 *p)
|
|
|
|
{
|
|
|
|
return p && p->family == AF_INET6 && p->prefixlen == 0
|
|
|
|
&& memcmp(&p->prefix, &in6addr_any, sizeof(struct in6_addr))
|
|
|
|
== 0;
|
|
|
|
}
|
2017-08-31 21:58:31 +02:00
|
|
|
|
2021-07-08 19:09:20 +02:00
|
|
|
static inline bool is_default_prefix(const struct prefix *p)
|
|
|
|
{
|
|
|
|
if (p == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (p->family) {
|
|
|
|
case AF_INET:
|
|
|
|
return is_default_prefix4((const struct prefix_ipv4 *)p);
|
|
|
|
case AF_INET6:
|
|
|
|
return is_default_prefix6((const struct prefix_ipv6 *)p);
|
|
|
|
}
|
2015-06-11 18:11:12 +02:00
|
|
|
|
2021-07-08 19:09:20 +02:00
|
|
|
return false;
|
2015-06-11 18:11:12 +02:00
|
|
|
}
|
|
|
|
|
2019-08-08 01:00:58 +02:00
|
|
|
static inline int is_host_route(const struct prefix *p)
|
2017-11-06 02:11:43 +01:00
|
|
|
{
|
|
|
|
if (p->family == AF_INET)
|
|
|
|
return (p->prefixlen == IPV4_MAX_BITLEN);
|
|
|
|
else if (p->family == AF_INET6)
|
|
|
|
return (p->prefixlen == IPV6_MAX_BITLEN);
|
|
|
|
return 0;
|
|
|
|
}
|
2019-02-07 23:10:31 +01:00
|
|
|
|
2020-03-22 22:14:32 +01:00
|
|
|
static inline int is_default_host_route(const struct prefix *p)
|
2019-04-03 03:47:46 +02:00
|
|
|
{
|
|
|
|
if (p->family == AF_INET) {
|
|
|
|
return (p->u.prefix4.s_addr == INADDR_ANY &&
|
|
|
|
p->prefixlen == IPV4_MAX_BITLEN);
|
|
|
|
} else if (p->family == AF_INET6) {
|
|
|
|
return ((!memcmp(&p->u.prefix6, &in6addr_any,
|
|
|
|
sizeof(struct in6_addr))) &&
|
|
|
|
p->prefixlen == IPV6_MAX_BITLEN);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-16 05:08:35 +02:00
|
|
|
static inline bool is_ipv6_global_unicast(const struct in6_addr *p)
|
|
|
|
{
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(p) || IN6_IS_ADDR_LOOPBACK(p) ||
|
|
|
|
IN6_IS_ADDR_LINKLOCAL(p) || IN6_IS_ADDR_MULTICAST(p))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-04-07 13:47:37 +02:00
|
|
|
/* IPv6 scope values, usable for IPv4 too (cf. below) */
|
|
|
|
/* clang-format off */
|
|
|
|
enum {
|
|
|
|
/* 0: reserved */
|
|
|
|
MCAST_SCOPE_IFACE = 0x1,
|
|
|
|
MCAST_SCOPE_LINK = 0x2,
|
|
|
|
MCAST_SCOPE_REALM = 0x3,
|
|
|
|
MCAST_SCOPE_ADMIN = 0x4,
|
|
|
|
MCAST_SCOPE_SITE = 0x5,
|
|
|
|
/* 6-7: unassigned */
|
|
|
|
MCAST_SCOPE_ORG = 0x8,
|
|
|
|
/* 9-d: unassigned */
|
|
|
|
MCAST_SCOPE_GLOBAL = 0xe,
|
|
|
|
/* f: reserved */
|
|
|
|
};
|
|
|
|
/* clang-format on */
|
|
|
|
|
|
|
|
static inline uint8_t ipv6_mcast_scope(const struct in6_addr *addr)
|
|
|
|
{
|
|
|
|
return addr->s6_addr[1] & 0xf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool ipv6_mcast_nofwd(const struct in6_addr *addr)
|
|
|
|
{
|
|
|
|
return (addr->s6_addr[1] & 0xf) <= MCAST_SCOPE_LINK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool ipv6_mcast_ssm(const struct in6_addr *addr)
|
|
|
|
{
|
|
|
|
uint32_t bits = ntohl(addr->s6_addr32[0]);
|
|
|
|
|
|
|
|
/* ff3x:0000::/32 */
|
|
|
|
return (bits & 0xfff0ffff) == 0xff300000;
|
|
|
|
}
|
|
|
|
|
2022-12-14 07:34:25 +01:00
|
|
|
static inline bool ipv6_mcast_reserved(const struct in6_addr *addr)
|
|
|
|
{
|
|
|
|
uint32_t bits = ntohl(addr->s6_addr32[0]);
|
|
|
|
|
|
|
|
/* ffx2::/16 */
|
|
|
|
return (bits & 0xff0fffff) == 0xff020000;
|
|
|
|
}
|
|
|
|
|
2022-04-07 13:47:37 +02:00
|
|
|
static inline uint8_t ipv4_mcast_scope(const struct in_addr *addr)
|
|
|
|
{
|
|
|
|
uint32_t bits = ntohl(addr->s_addr);
|
|
|
|
|
|
|
|
/* 224.0.0.0/24 - link scope */
|
|
|
|
if ((bits & 0xffffff00) == 0xe0000000)
|
|
|
|
return MCAST_SCOPE_LINK;
|
|
|
|
/* 239.0.0.0/8 - org scope */
|
|
|
|
if ((bits & 0xff000000) == 0xef000000)
|
|
|
|
return MCAST_SCOPE_ORG;
|
|
|
|
|
|
|
|
return MCAST_SCOPE_GLOBAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool ipv4_mcast_nofwd(const struct in_addr *addr)
|
|
|
|
{
|
|
|
|
uint32_t bits = ntohl(addr->s_addr);
|
|
|
|
|
|
|
|
/* 224.0.0.0/24 */
|
|
|
|
return (bits & 0xffffff00) == 0xe0000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool ipv4_mcast_ssm(const struct in_addr *addr)
|
|
|
|
{
|
|
|
|
uint32_t bits = ntohl(addr->s_addr);
|
|
|
|
|
|
|
|
/* 232.0.0.0/8 */
|
|
|
|
return (bits & 0xff000000) == 0xe8000000;
|
|
|
|
}
|
|
|
|
|
2019-08-02 17:42:06 +02:00
|
|
|
#ifdef _FRR_ATTRIBUTE_PRINTFRR
|
2020-03-29 11:39:12 +02:00
|
|
|
#pragma FRR printfrr_ext "%pEA" (struct ethaddr *)
|
|
|
|
|
2019-08-02 17:42:06 +02:00
|
|
|
#pragma FRR printfrr_ext "%pI4" (struct in_addr *)
|
|
|
|
#pragma FRR printfrr_ext "%pI4" (in_addr_t *)
|
|
|
|
|
|
|
|
#pragma FRR printfrr_ext "%pI6" (struct in6_addr *)
|
|
|
|
|
|
|
|
#pragma FRR printfrr_ext "%pFX" (struct prefix *)
|
|
|
|
#pragma FRR printfrr_ext "%pFX" (struct prefix_ipv4 *)
|
|
|
|
#pragma FRR printfrr_ext "%pFX" (struct prefix_ipv6 *)
|
|
|
|
#pragma FRR printfrr_ext "%pFX" (struct prefix_eth *)
|
|
|
|
#pragma FRR printfrr_ext "%pFX" (struct prefix_evpn *)
|
|
|
|
#pragma FRR printfrr_ext "%pFX" (struct prefix_fs *)
|
2022-11-22 09:57:10 +01:00
|
|
|
#pragma FRR printfrr_ext "%pRDP" (struct prefix_rd *)
|
|
|
|
/* RD with AS4B with dot and dot+ format */
|
|
|
|
#pragma FRR printfrr_ext "%pRDD" (struct prefix_rd *)
|
|
|
|
#pragma FRR printfrr_ext "%pRDE" (struct prefix_rd *)
|
2019-08-02 17:42:06 +02:00
|
|
|
|
2022-01-04 16:50:53 +01:00
|
|
|
#pragma FRR printfrr_ext "%pPSG4" (struct prefix_sg *)
|
2019-08-02 17:42:06 +02:00
|
|
|
#endif
|
|
|
|
|
2019-02-07 23:10:31 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
#endif /* _ZEBRA_PREFIX_H */
|