2023-02-08 13:17:09 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Kernel routing table updates using netlink over GNU/Linux system.
|
|
|
|
* Copyright (C) 1997, 98, 99 Kunihiro Ishiguro
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zebra.h>
|
2017-07-26 19:49:15 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_NETLINK
|
|
|
|
|
2020-12-06 00:01:39 +01:00
|
|
|
/* The following definition is to workaround an issue in the Linux kernel
|
|
|
|
* header files with redefinition of 'struct in6_addr' in both
|
|
|
|
* netinet/in.h and linux/in6.h.
|
|
|
|
* Reference - https://sourceware.org/ml/libc-alpha/2013-01/msg00599.html
|
|
|
|
*/
|
|
|
|
#define _LINUX_IN6_H
|
|
|
|
|
2016-01-15 16:36:33 +01:00
|
|
|
#include <net/if_arp.h>
|
2017-09-21 03:12:56 +02:00
|
|
|
#include <linux/lwtunnel.h>
|
|
|
|
#include <linux/mpls_iptunnel.h>
|
2020-12-06 00:01:39 +01:00
|
|
|
#include <linux/seg6_iptunnel.h>
|
|
|
|
#include <linux/seg6_local.h>
|
2017-09-21 03:12:56 +02:00
|
|
|
#include <linux/neighbour.h>
|
|
|
|
#include <linux/rtnetlink.h>
|
2019-02-26 00:18:07 +01:00
|
|
|
#include <linux/nexthop.h>
|
2002-12-13 21:15:29 +01:00
|
|
|
|
|
|
|
/* Hack for GNU libc version 2. */
|
|
|
|
#ifndef MSG_TRUNC
|
|
|
|
#define MSG_TRUNC 0x20
|
|
|
|
#endif /* MSG_TRUNC */
|
|
|
|
|
|
|
|
#include "linklist.h"
|
|
|
|
#include "if.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "prefix.h"
|
2020-12-06 00:01:39 +01:00
|
|
|
#include "plist.h"
|
|
|
|
#include "plist_int.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "connected.h"
|
|
|
|
#include "table.h"
|
2012-03-22 09:09:21 +01:00
|
|
|
#include "memory.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "rib.h"
|
2023-03-07 20:22:48 +01:00
|
|
|
#include "frrevent.h"
|
2003-06-04 15:59:38 +02:00
|
|
|
#include "privs.h"
|
2015-05-20 02:40:34 +02:00
|
|
|
#include "nexthop.h"
|
2015-05-22 11:40:02 +02:00
|
|
|
#include "vrf.h"
|
2016-10-06 22:23:13 +02:00
|
|
|
#include "vty.h"
|
2016-04-16 04:19:37 +02:00
|
|
|
#include "mpls.h"
|
2017-05-15 07:38:26 +02:00
|
|
|
#include "vxlan.h"
|
2019-08-12 21:46:22 +02:00
|
|
|
#include "printfrr.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2018-04-22 22:01:20 +02:00
|
|
|
#include "zebra/zapi_msg.h"
|
2016-04-14 04:40:18 +02:00
|
|
|
#include "zebra/zebra_ns.h"
|
2016-04-14 15:20:47 +02:00
|
|
|
#include "zebra/zebra_vrf.h"
|
[zebra] fix some small compile errors, mark several functions static
2005-11-23 Paul Jakma <paul.jakma@sun.com>
* (general) fix some small compile errors, and mark several
functions as static.
* kernel_socket.c: (ifan_read) should be static.
fix missing brackets.
(ifm_read,ifam_read,rtm_read_mesg,kernel_read) Make static
(ifam_read_mesg) make static. fix incorrect variable name.
(rtm_read) make static. Fix call to rib_delete_ipv4 which
should be rib_delete_ipv6.
(routing_socket,kernel_init) should be static. Void argument
should be specified as such, not left incomplete.
* rt_netlink.c: rt.h should be included, contains prototypes of
exported functions.
(kernel_delete_ipv6_old) fix sign of index argument.
* rt_socket.c: Exact same as previous. Also, make various
functions static.
* rtread_getmsg.c: Include zserv.h, which prototypes
route_read. Make static.
* rtread_sysctl.c: zserv.h and rt.h should be included.
fix definition of route_read.
2005-11-23 14:02:08 +01:00
|
|
|
#include "zebra/rt.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "zebra/redistribute.h"
|
|
|
|
#include "zebra/interface.h"
|
|
|
|
#include "zebra/debug.h"
|
2016-02-01 19:55:42 +01:00
|
|
|
#include "zebra/rtadv.h"
|
2016-05-09 05:11:18 +02:00
|
|
|
#include "zebra/zebra_ptm.h"
|
2016-04-16 04:19:37 +02:00
|
|
|
#include "zebra/zebra_mpls.h"
|
2016-10-17 21:39:55 +02:00
|
|
|
#include "zebra/kernel_netlink.h"
|
|
|
|
#include "zebra/rt_netlink.h"
|
2019-02-26 00:18:07 +01:00
|
|
|
#include "zebra/zebra_nhg.h"
|
2016-08-11 02:04:20 +02:00
|
|
|
#include "zebra/zebra_mroute.h"
|
2017-05-15 07:44:13 +02:00
|
|
|
#include "zebra/zebra_vxlan.h"
|
2018-08-24 19:14:09 +02:00
|
|
|
#include "zebra/zebra_errors.h"
|
2020-03-28 00:36:24 +01:00
|
|
|
#include "zebra/zebra_evpn_mh.h"
|
2021-10-06 14:49:58 +02:00
|
|
|
#include "zebra/zebra_trace.h"
|
2021-12-18 20:28:49 +01:00
|
|
|
#include "zebra/zebra_neigh.h"
|
2023-07-26 17:56:32 +02:00
|
|
|
#include "lib/srv6.h"
|
2016-08-11 02:04:20 +02:00
|
|
|
|
2016-04-16 04:19:37 +02:00
|
|
|
#ifndef AF_MPLS
|
|
|
|
#define AF_MPLS 28
|
|
|
|
#endif
|
|
|
|
|
2020-04-17 20:37:42 +02:00
|
|
|
/* Re-defining as I am unable to include <linux/if_bridge.h> which has the
|
|
|
|
* UAPI for MAC sync. */
|
|
|
|
#ifndef _UAPI_LINUX_IF_BRIDGE_H
|
2020-07-15 16:59:12 +02:00
|
|
|
#define BR_SPH_LIST_SIZE 10
|
2020-04-17 20:37:42 +02:00
|
|
|
#endif
|
|
|
|
|
2023-07-26 17:56:32 +02:00
|
|
|
DEFINE_MTYPE_STATIC(LIB, NH_SRV6, "Nexthop srv6");
|
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
static vlanid_t filter_vlan = 0;
|
|
|
|
|
2020-01-28 17:00:42 +01:00
|
|
|
/* We capture whether the current kernel supports nexthop ids; by
|
|
|
|
* default, we'll use them if possible. There's also a configuration
|
|
|
|
* available to _disable_ use of kernel nexthops.
|
|
|
|
*/
|
2019-09-03 22:12:06 +02:00
|
|
|
static bool supports_nh;
|
2019-08-01 20:53:06 +02:00
|
|
|
|
2016-04-16 04:19:37 +02:00
|
|
|
struct gw_family_t {
|
2018-03-27 21:13:34 +02:00
|
|
|
uint16_t filler;
|
|
|
|
uint16_t family;
|
2016-04-16 04:19:37 +02:00
|
|
|
union g_addr gate;
|
|
|
|
};
|
|
|
|
|
2019-11-20 17:26:59 +01:00
|
|
|
static const char ipv4_ll_buf[16] = "169.254.0.1";
|
|
|
|
static struct in_addr ipv4_ll;
|
2017-05-26 03:11:24 +02:00
|
|
|
|
2020-05-05 21:05:30 +02:00
|
|
|
/* Is this a ipv4 over ipv6 route? */
|
|
|
|
static bool is_route_v4_over_v6(unsigned char rtm_family,
|
|
|
|
enum nexthop_types_t nexthop_type)
|
|
|
|
{
|
|
|
|
if (rtm_family == AF_INET
|
|
|
|
&& (nexthop_type == NEXTHOP_TYPE_IPV6
|
|
|
|
|| nexthop_type == NEXTHOP_TYPE_IPV6_IFINDEX))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-28 17:00:42 +01:00
|
|
|
/* Helper to control use of kernel-level nexthop ids */
|
|
|
|
static bool kernel_nexthops_supported(void)
|
|
|
|
{
|
2020-05-01 18:34:43 +02:00
|
|
|
return (supports_nh && !vrf_is_backend_netns()
|
|
|
|
&& zebra_nhg_kernel_nexthops_enabled());
|
2020-01-28 17:00:42 +01:00
|
|
|
}
|
|
|
|
|
2020-05-13 21:50:14 +02:00
|
|
|
/*
|
|
|
|
* Some people may only want to use NHGs created by protos and not
|
|
|
|
* implicitly created by Zebra. This check accounts for that.
|
|
|
|
*/
|
|
|
|
static bool proto_nexthops_only(void)
|
|
|
|
{
|
|
|
|
return zebra_nhg_proto_nexthops_only();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is this a proto created NHG? */
|
|
|
|
static bool is_proto_nhg(uint32_t id, int type)
|
|
|
|
{
|
|
|
|
/* If type is available, use it as the source of truth */
|
|
|
|
if (type) {
|
|
|
|
if (type != ZEBRA_ROUTE_NHG)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-13 20:32:13 +02:00
|
|
|
if (id >= ZEBRA_NHG_PROTO_LOWER)
|
2020-05-13 21:50:14 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-07-27 09:47:52 +02:00
|
|
|
/* Is vni mcast group */
|
|
|
|
static bool is_mac_vni_mcast_group(struct ethaddr *mac, vni_t vni,
|
|
|
|
struct in_addr grp_addr)
|
|
|
|
{
|
|
|
|
if (!vni)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!is_zero_mac(mac))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!IN_MULTICAST(ntohl(grp_addr.s_addr)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-26 03:11:24 +02:00
|
|
|
/*
|
|
|
|
* The ipv4_ll data structure is used for all 5549
|
|
|
|
* additions to the kernel. Let's figure out the
|
|
|
|
* correct value one time instead for every
|
|
|
|
* install/remove of a 5549 type route
|
|
|
|
*/
|
|
|
|
void rt_netlink_init(void)
|
|
|
|
{
|
|
|
|
inet_pton(AF_INET, ipv4_ll_buf, &ipv4_ll);
|
|
|
|
}
|
|
|
|
|
2019-08-23 19:59:10 +02:00
|
|
|
/*
|
|
|
|
* Mapping from dataplane neighbor flags to netlink flags
|
|
|
|
*/
|
|
|
|
static uint8_t neigh_flags_to_netlink(uint8_t dplane_flags)
|
|
|
|
{
|
|
|
|
uint8_t flags = 0;
|
|
|
|
|
|
|
|
if (dplane_flags & DPLANE_NTF_EXT_LEARNED)
|
|
|
|
flags |= NTF_EXT_LEARNED;
|
|
|
|
if (dplane_flags & DPLANE_NTF_ROUTER)
|
|
|
|
flags |= NTF_ROUTER;
|
2020-08-06 13:07:01 +02:00
|
|
|
if (dplane_flags & DPLANE_NTF_USE)
|
|
|
|
flags |= NTF_USE;
|
2019-08-23 19:59:10 +02:00
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mapping from dataplane neighbor state to netlink state
|
|
|
|
*/
|
|
|
|
static uint16_t neigh_state_to_netlink(uint16_t dplane_state)
|
|
|
|
{
|
|
|
|
uint16_t state = 0;
|
|
|
|
|
|
|
|
if (dplane_state & DPLANE_NUD_REACHABLE)
|
|
|
|
state |= NUD_REACHABLE;
|
|
|
|
if (dplane_state & DPLANE_NUD_STALE)
|
|
|
|
state |= NUD_STALE;
|
|
|
|
if (dplane_state & DPLANE_NUD_NOARP)
|
|
|
|
state |= NUD_NOARP;
|
|
|
|
if (dplane_state & DPLANE_NUD_PROBE)
|
|
|
|
state |= NUD_PROBE;
|
2020-08-06 13:07:01 +02:00
|
|
|
if (dplane_state & DPLANE_NUD_INCOMPLETE)
|
|
|
|
state |= NUD_INCOMPLETE;
|
2021-02-25 11:12:34 +01:00
|
|
|
if (dplane_state & DPLANE_NUD_PERMANENT)
|
|
|
|
state |= NUD_PERMANENT;
|
|
|
|
if (dplane_state & DPLANE_NUD_FAILED)
|
|
|
|
state |= NUD_FAILED;
|
2019-08-23 19:59:10 +02:00
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-11 19:20:41 +01:00
|
|
|
static inline bool is_selfroute(int proto)
|
2017-01-11 23:33:39 +01:00
|
|
|
{
|
|
|
|
if ((proto == RTPROT_BGP) || (proto == RTPROT_OSPF)
|
2018-05-25 20:36:12 +02:00
|
|
|
|| (proto == RTPROT_ZSTATIC) || (proto == RTPROT_ZEBRA)
|
2017-06-08 14:48:10 +02:00
|
|
|
|| (proto == RTPROT_ISIS) || (proto == RTPROT_RIPNG)
|
|
|
|
|| (proto == RTPROT_NHRP) || (proto == RTPROT_EIGRP)
|
2017-09-01 16:28:19 +02:00
|
|
|
|| (proto == RTPROT_LDP) || (proto == RTPROT_BABEL)
|
2018-04-27 20:53:46 +02:00
|
|
|
|| (proto == RTPROT_RIP) || (proto == RTPROT_SHARP)
|
2020-07-20 13:43:54 +02:00
|
|
|
|| (proto == RTPROT_PBR) || (proto == RTPROT_OPENFABRIC)
|
|
|
|
|| (proto == RTPROT_SRTE)) {
|
2020-03-11 19:20:41 +01:00
|
|
|
return true;
|
2017-01-11 23:33:39 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-03-11 19:20:41 +01:00
|
|
|
return false;
|
2017-01-11 23:33:39 +01:00
|
|
|
}
|
|
|
|
|
zebra_fpm: Add support for other protocols in fpm:netlink
fpm:netlink format doesn't indicate the protocol information
in routes of BGP, OSPF and other protocols. Routes of those
protocols just indicate protocol as zebra.
The below route is actually BGP route but 'proto': 11
indicates that it is zebra.
{'attrs': [('RTA_DST', 'dummy'),
('RTA_PRIORITY', 0),
('RTA_GATEWAY', 'dummy'),
('RTA_OIF', 2)],
'dst_len': 32,
'family': 2,
'flags': 0,
'header': {'flags': 1025,
'length': 60,
'pid': 3160253895,
'sequence_number': 0,
'type': 24},
'proto': 11,
'scope': 0,
'src_len': 0,
'table': 254,
'tos': 0,
'type': 1}
with this change it is now seen with 'proto': 186
indicates that it is BGP.
{'attrs': [('RTA_DST', 'dummy'),
('RTA_PRIORITY', 0),
('RTA_GATEWAY', 'dummy'),
('RTA_OIF', 2)],
'dst_len': 32,
'family': 2,
'flags': 0,
'header': {'flags': 1025,
'length': 60,
'pid': 3160253895,
'sequence_number': 0,
'type': 24},
'proto': 186,
'scope': 0,
'src_len': 0,
'table': 254,
'tos': 0,
'type': 1}
Signed-off-by: Spoorthi K <spk@redhat.com>
2023-01-23 04:34:04 +01:00
|
|
|
int zebra2proto(int proto)
|
2017-01-11 23:33:39 +01:00
|
|
|
{
|
|
|
|
switch (proto) {
|
2017-06-08 14:56:36 +02:00
|
|
|
case ZEBRA_ROUTE_BABEL:
|
|
|
|
proto = RTPROT_BABEL;
|
|
|
|
break;
|
2017-01-11 23:33:39 +01:00
|
|
|
case ZEBRA_ROUTE_BGP:
|
|
|
|
proto = RTPROT_BGP;
|
|
|
|
break;
|
|
|
|
case ZEBRA_ROUTE_OSPF:
|
|
|
|
case ZEBRA_ROUTE_OSPF6:
|
|
|
|
proto = RTPROT_OSPF;
|
|
|
|
break;
|
|
|
|
case ZEBRA_ROUTE_STATIC:
|
2018-05-25 20:36:12 +02:00
|
|
|
proto = RTPROT_ZSTATIC;
|
2017-01-11 23:33:39 +01:00
|
|
|
break;
|
|
|
|
case ZEBRA_ROUTE_ISIS:
|
|
|
|
proto = RTPROT_ISIS;
|
|
|
|
break;
|
|
|
|
case ZEBRA_ROUTE_RIP:
|
|
|
|
proto = RTPROT_RIP;
|
|
|
|
break;
|
|
|
|
case ZEBRA_ROUTE_RIPNG:
|
|
|
|
proto = RTPROT_RIPNG;
|
|
|
|
break;
|
2017-06-08 14:48:10 +02:00
|
|
|
case ZEBRA_ROUTE_NHRP:
|
|
|
|
proto = RTPROT_NHRP;
|
|
|
|
break;
|
|
|
|
case ZEBRA_ROUTE_EIGRP:
|
|
|
|
proto = RTPROT_EIGRP;
|
|
|
|
break;
|
|
|
|
case ZEBRA_ROUTE_LDP:
|
|
|
|
proto = RTPROT_LDP;
|
|
|
|
break;
|
2017-11-10 18:55:16 +01:00
|
|
|
case ZEBRA_ROUTE_SHARP:
|
|
|
|
proto = RTPROT_SHARP;
|
|
|
|
break;
|
2018-04-27 20:53:46 +02:00
|
|
|
case ZEBRA_ROUTE_PBR:
|
|
|
|
proto = RTPROT_PBR;
|
|
|
|
break;
|
2018-06-11 14:09:23 +02:00
|
|
|
case ZEBRA_ROUTE_OPENFABRIC:
|
|
|
|
proto = RTPROT_OPENFABRIC;
|
|
|
|
break;
|
2020-07-20 13:43:54 +02:00
|
|
|
case ZEBRA_ROUTE_SRTE:
|
|
|
|
proto = RTPROT_SRTE;
|
|
|
|
break;
|
2019-06-25 23:47:51 +02:00
|
|
|
case ZEBRA_ROUTE_TABLE:
|
2019-08-01 20:07:04 +02:00
|
|
|
case ZEBRA_ROUTE_NHG:
|
2019-06-25 23:47:51 +02:00
|
|
|
proto = RTPROT_ZEBRA;
|
|
|
|
break;
|
2020-12-22 22:23:43 +01:00
|
|
|
case ZEBRA_ROUTE_CONNECT:
|
|
|
|
case ZEBRA_ROUTE_KERNEL:
|
|
|
|
proto = RTPROT_KERNEL;
|
|
|
|
break;
|
2017-01-11 23:33:39 +01:00
|
|
|
default:
|
2018-04-27 20:53:46 +02:00
|
|
|
/*
|
|
|
|
* When a user adds a new protocol this will show up
|
|
|
|
* to let them know to do something about it. This
|
|
|
|
* is intentionally a warn because we should see
|
|
|
|
* this as part of development of a new protocol
|
|
|
|
*/
|
2018-08-16 22:10:32 +02:00
|
|
|
zlog_debug(
|
|
|
|
"%s: Please add this protocol(%d) to proper rt_netlink.c handling",
|
2020-03-05 19:17:54 +01:00
|
|
|
__func__, proto);
|
2017-01-11 23:33:39 +01:00
|
|
|
proto = RTPROT_ZEBRA;
|
|
|
|
break;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-01-11 23:33:39 +01:00
|
|
|
return proto;
|
|
|
|
}
|
|
|
|
|
2019-08-01 20:07:04 +02:00
|
|
|
static inline int proto2zebra(int proto, int family, bool is_nexthop)
|
2017-09-01 16:28:19 +02:00
|
|
|
{
|
|
|
|
switch (proto) {
|
|
|
|
case RTPROT_BABEL:
|
|
|
|
proto = ZEBRA_ROUTE_BABEL;
|
|
|
|
break;
|
|
|
|
case RTPROT_BGP:
|
|
|
|
proto = ZEBRA_ROUTE_BGP;
|
|
|
|
break;
|
|
|
|
case RTPROT_OSPF:
|
2021-02-16 21:54:08 +01:00
|
|
|
proto = (family == AF_INET) ? ZEBRA_ROUTE_OSPF
|
|
|
|
: ZEBRA_ROUTE_OSPF6;
|
2017-09-01 16:28:19 +02:00
|
|
|
break;
|
|
|
|
case RTPROT_ISIS:
|
|
|
|
proto = ZEBRA_ROUTE_ISIS;
|
|
|
|
break;
|
|
|
|
case RTPROT_RIP:
|
|
|
|
proto = ZEBRA_ROUTE_RIP;
|
|
|
|
break;
|
|
|
|
case RTPROT_RIPNG:
|
|
|
|
proto = ZEBRA_ROUTE_RIPNG;
|
|
|
|
break;
|
|
|
|
case RTPROT_NHRP:
|
|
|
|
proto = ZEBRA_ROUTE_NHRP;
|
|
|
|
break;
|
|
|
|
case RTPROT_EIGRP:
|
|
|
|
proto = ZEBRA_ROUTE_EIGRP;
|
|
|
|
break;
|
|
|
|
case RTPROT_LDP:
|
|
|
|
proto = ZEBRA_ROUTE_LDP;
|
|
|
|
break;
|
|
|
|
case RTPROT_STATIC:
|
2018-05-25 20:36:12 +02:00
|
|
|
case RTPROT_ZSTATIC:
|
2017-09-01 16:28:19 +02:00
|
|
|
proto = ZEBRA_ROUTE_STATIC;
|
|
|
|
break;
|
2018-04-27 20:53:46 +02:00
|
|
|
case RTPROT_SHARP:
|
|
|
|
proto = ZEBRA_ROUTE_SHARP;
|
|
|
|
break;
|
|
|
|
case RTPROT_PBR:
|
|
|
|
proto = ZEBRA_ROUTE_PBR;
|
|
|
|
break;
|
2018-06-11 14:09:23 +02:00
|
|
|
case RTPROT_OPENFABRIC:
|
|
|
|
proto = ZEBRA_ROUTE_OPENFABRIC;
|
|
|
|
break;
|
2020-07-20 13:43:54 +02:00
|
|
|
case RTPROT_SRTE:
|
|
|
|
proto = ZEBRA_ROUTE_SRTE;
|
|
|
|
break;
|
2022-06-30 15:03:12 +02:00
|
|
|
case RTPROT_UNSPEC:
|
|
|
|
case RTPROT_REDIRECT:
|
|
|
|
case RTPROT_KERNEL:
|
|
|
|
case RTPROT_BOOT:
|
|
|
|
case RTPROT_GATED:
|
|
|
|
case RTPROT_RA:
|
|
|
|
case RTPROT_MRT:
|
|
|
|
case RTPROT_BIRD:
|
|
|
|
case RTPROT_DNROUTED:
|
|
|
|
case RTPROT_XORP:
|
|
|
|
case RTPROT_NTK:
|
|
|
|
case RTPROT_MROUTED:
|
|
|
|
case RTPROT_KEEPALIVED:
|
|
|
|
case RTPROT_OPENR:
|
|
|
|
proto = ZEBRA_ROUTE_KERNEL;
|
|
|
|
break;
|
2019-08-01 20:07:04 +02:00
|
|
|
case RTPROT_ZEBRA:
|
|
|
|
if (is_nexthop) {
|
|
|
|
proto = ZEBRA_ROUTE_NHG;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Intentional fall thru */
|
2017-09-01 16:28:19 +02:00
|
|
|
default:
|
2018-04-27 20:53:46 +02:00
|
|
|
/*
|
|
|
|
* When a user adds a new protocol this will show up
|
|
|
|
* to let them know to do something about it. This
|
|
|
|
* is intentionally a warn because we should see
|
|
|
|
* this as part of development of a new protocol
|
|
|
|
*/
|
2018-08-16 22:10:32 +02:00
|
|
|
zlog_debug(
|
|
|
|
"%s: Please add this protocol(%d) to proper rt_netlink.c handling",
|
2020-03-05 19:17:54 +01:00
|
|
|
__func__, proto);
|
2017-09-01 16:28:19 +02:00
|
|
|
proto = ZEBRA_ROUTE_KERNEL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return proto;
|
|
|
|
}
|
|
|
|
|
2018-08-12 00:36:22 +02:00
|
|
|
/**
|
|
|
|
* @parse_encap_mpls() - Parses encapsulated mpls attributes
|
|
|
|
* @tb: Pointer to rtattr to look for nested items in.
|
|
|
|
* @labels: Pointer to store labels in.
|
|
|
|
*
|
|
|
|
* Return: Number of mpls labels found.
|
|
|
|
*/
|
|
|
|
static int parse_encap_mpls(struct rtattr *tb, mpls_label_t *labels)
|
|
|
|
{
|
|
|
|
struct rtattr *tb_encap[MPLS_IPTUNNEL_MAX + 1] = {0};
|
|
|
|
mpls_lse_t *lses = NULL;
|
|
|
|
int num_labels = 0;
|
|
|
|
uint32_t ttl = 0;
|
|
|
|
uint32_t bos = 0;
|
|
|
|
uint32_t exp = 0;
|
|
|
|
mpls_label_t label = 0;
|
|
|
|
|
|
|
|
netlink_parse_rtattr_nested(tb_encap, MPLS_IPTUNNEL_MAX, tb);
|
|
|
|
lses = (mpls_lse_t *)RTA_DATA(tb_encap[MPLS_IPTUNNEL_DST]);
|
|
|
|
while (!bos && num_labels < MPLS_MAX_LABELS) {
|
|
|
|
mpls_lse_decode(lses[num_labels], &label, &ttl, &exp, &bos);
|
|
|
|
labels[num_labels++] = label;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_labels;
|
|
|
|
}
|
|
|
|
|
2023-03-20 21:35:04 +01:00
|
|
|
/**
|
|
|
|
* @parse_encap_seg6local_flavors() - Parses encapsulated SRv6 flavors
|
|
|
|
* attributes
|
|
|
|
* @tb: Pointer to rtattr to look for nested items in.
|
|
|
|
* @flv: Pointer to store SRv6 flavors info in.
|
|
|
|
*
|
|
|
|
* Return: 0 on success, non-zero on error
|
|
|
|
*/
|
|
|
|
static int parse_encap_seg6local_flavors(struct rtattr *tb,
|
|
|
|
struct seg6local_flavors_info *flv)
|
|
|
|
{
|
|
|
|
struct rtattr *tb_encap[SEG6_LOCAL_FLV_MAX + 1] = {};
|
|
|
|
|
|
|
|
netlink_parse_rtattr_nested(tb_encap, SEG6_LOCAL_FLV_MAX, tb);
|
|
|
|
|
|
|
|
if (tb_encap[SEG6_LOCAL_FLV_OPERATION])
|
|
|
|
flv->flv_ops = *(uint32_t *)RTA_DATA(
|
|
|
|
tb_encap[SEG6_LOCAL_FLV_OPERATION]);
|
|
|
|
|
|
|
|
if (tb_encap[SEG6_LOCAL_FLV_LCBLOCK_BITS])
|
|
|
|
flv->lcblock_len = *(uint8_t *)RTA_DATA(
|
|
|
|
tb_encap[SEG6_LOCAL_FLV_LCBLOCK_BITS]);
|
|
|
|
|
|
|
|
if (tb_encap[SEG6_LOCAL_FLV_LCNODE_FN_BITS])
|
|
|
|
flv->lcnode_func_len = *(uint8_t *)RTA_DATA(
|
|
|
|
tb_encap[SEG6_LOCAL_FLV_LCNODE_FN_BITS]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-18 14:39:25 +01:00
|
|
|
static enum seg6local_action_t
|
|
|
|
parse_encap_seg6local(struct rtattr *tb,
|
|
|
|
struct seg6local_context *ctx)
|
|
|
|
{
|
2022-07-17 21:31:48 +02:00
|
|
|
struct rtattr *tb_encap[SEG6_LOCAL_MAX + 1] = {};
|
2020-12-18 14:39:25 +01:00
|
|
|
enum seg6local_action_t act = ZEBRA_SEG6_LOCAL_ACTION_UNSPEC;
|
|
|
|
|
2022-07-17 21:31:48 +02:00
|
|
|
netlink_parse_rtattr_nested(tb_encap, SEG6_LOCAL_MAX, tb);
|
2020-12-18 14:39:25 +01:00
|
|
|
|
|
|
|
if (tb_encap[SEG6_LOCAL_ACTION])
|
|
|
|
act = *(uint32_t *)RTA_DATA(tb_encap[SEG6_LOCAL_ACTION]);
|
|
|
|
|
|
|
|
if (tb_encap[SEG6_LOCAL_NH4])
|
|
|
|
ctx->nh4 = *(struct in_addr *)RTA_DATA(
|
|
|
|
tb_encap[SEG6_LOCAL_NH4]);
|
|
|
|
|
|
|
|
if (tb_encap[SEG6_LOCAL_NH6])
|
|
|
|
ctx->nh6 = *(struct in6_addr *)RTA_DATA(
|
|
|
|
tb_encap[SEG6_LOCAL_NH6]);
|
|
|
|
|
|
|
|
if (tb_encap[SEG6_LOCAL_TABLE])
|
|
|
|
ctx->table = *(uint32_t *)RTA_DATA(tb_encap[SEG6_LOCAL_TABLE]);
|
|
|
|
|
2021-11-22 14:50:48 +01:00
|
|
|
if (tb_encap[SEG6_LOCAL_VRFTABLE])
|
|
|
|
ctx->table =
|
|
|
|
*(uint32_t *)RTA_DATA(tb_encap[SEG6_LOCAL_VRFTABLE]);
|
|
|
|
|
2023-03-20 21:35:04 +01:00
|
|
|
if (tb_encap[SEG6_LOCAL_FLAVORS]) {
|
|
|
|
parse_encap_seg6local_flavors(tb_encap[SEG6_LOCAL_FLAVORS],
|
|
|
|
&ctx->flv);
|
|
|
|
}
|
|
|
|
|
2020-12-18 14:39:25 +01:00
|
|
|
return act;
|
|
|
|
}
|
|
|
|
|
2020-12-18 13:41:19 +01:00
|
|
|
static int parse_encap_seg6(struct rtattr *tb, struct in6_addr *segs)
|
|
|
|
{
|
2022-07-17 21:31:48 +02:00
|
|
|
struct rtattr *tb_encap[SEG6_IPTUNNEL_MAX + 1] = {};
|
2020-12-18 13:41:19 +01:00
|
|
|
struct seg6_iptunnel_encap *ipt = NULL;
|
2023-07-26 17:56:32 +02:00
|
|
|
int i;
|
2020-12-18 13:41:19 +01:00
|
|
|
|
2022-07-17 21:31:48 +02:00
|
|
|
netlink_parse_rtattr_nested(tb_encap, SEG6_IPTUNNEL_MAX, tb);
|
2020-12-18 13:41:19 +01:00
|
|
|
|
|
|
|
if (tb_encap[SEG6_IPTUNNEL_SRH]) {
|
|
|
|
ipt = (struct seg6_iptunnel_encap *)
|
|
|
|
RTA_DATA(tb_encap[SEG6_IPTUNNEL_SRH]);
|
2023-07-26 17:56:32 +02:00
|
|
|
|
|
|
|
for (i = ipt->srh[0].first_segment; i >= 0; i--)
|
|
|
|
memcpy(&segs[i], &ipt->srh[0].segments[i],
|
|
|
|
sizeof(struct in6_addr));
|
|
|
|
|
|
|
|
return ipt->srh[0].first_segment + 1;
|
2020-12-18 13:41:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-11 15:52:33 +01:00
|
|
|
static struct nexthop
|
|
|
|
parse_nexthop_unicast(ns_id_t ns_id, struct rtmsg *rtm, struct rtattr **tb,
|
|
|
|
enum blackhole_type bh_type, int index, void *prefsrc,
|
2019-03-29 15:56:52 +01:00
|
|
|
void *gate, afi_t afi, vrf_id_t vrf_id)
|
2019-03-11 15:52:33 +01:00
|
|
|
{
|
|
|
|
struct interface *ifp = NULL;
|
|
|
|
struct nexthop nh = {0};
|
|
|
|
mpls_label_t labels[MPLS_MAX_LABELS] = {0};
|
|
|
|
int num_labels = 0;
|
2021-03-22 10:28:32 +01:00
|
|
|
enum seg6local_action_t seg6l_act = ZEBRA_SEG6_LOCAL_ACTION_UNSPEC;
|
2021-03-22 01:31:56 +01:00
|
|
|
struct seg6local_context seg6l_ctx = {};
|
2023-07-26 17:56:32 +02:00
|
|
|
struct in6_addr segs[SRV6_MAX_SIDS] = {};
|
2020-12-18 13:41:19 +01:00
|
|
|
int num_segs = 0;
|
2019-03-11 15:52:33 +01:00
|
|
|
|
2019-03-29 15:56:52 +01:00
|
|
|
vrf_id_t nh_vrf_id = vrf_id;
|
2019-03-11 15:52:33 +01:00
|
|
|
size_t sz = (afi == AFI_IP) ? 4 : 16;
|
|
|
|
|
|
|
|
if (bh_type == BLACKHOLE_UNSPEC) {
|
|
|
|
if (index && !gate)
|
|
|
|
nh.type = NEXTHOP_TYPE_IFINDEX;
|
|
|
|
else if (index && gate)
|
|
|
|
nh.type = (afi == AFI_IP) ? NEXTHOP_TYPE_IPV4_IFINDEX
|
|
|
|
: NEXTHOP_TYPE_IPV6_IFINDEX;
|
|
|
|
else if (!index && gate)
|
|
|
|
nh.type = (afi == AFI_IP) ? NEXTHOP_TYPE_IPV4
|
|
|
|
: NEXTHOP_TYPE_IPV6;
|
|
|
|
else {
|
|
|
|
nh.type = NEXTHOP_TYPE_BLACKHOLE;
|
|
|
|
nh.bh_type = bh_type;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nh.type = NEXTHOP_TYPE_BLACKHOLE;
|
|
|
|
nh.bh_type = bh_type;
|
|
|
|
}
|
|
|
|
nh.ifindex = index;
|
|
|
|
if (prefsrc)
|
|
|
|
memcpy(&nh.src, prefsrc, sz);
|
|
|
|
if (gate)
|
|
|
|
memcpy(&nh.gate, gate, sz);
|
|
|
|
|
|
|
|
if (index) {
|
|
|
|
ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id), index);
|
|
|
|
if (ifp)
|
2021-10-22 00:17:40 +02:00
|
|
|
nh_vrf_id = ifp->vrf->vrf_id;
|
2019-03-11 15:52:33 +01:00
|
|
|
}
|
|
|
|
nh.vrf_id = nh_vrf_id;
|
|
|
|
|
|
|
|
if (tb[RTA_ENCAP] && tb[RTA_ENCAP_TYPE]
|
|
|
|
&& *(uint16_t *)RTA_DATA(tb[RTA_ENCAP_TYPE])
|
|
|
|
== LWTUNNEL_ENCAP_MPLS) {
|
|
|
|
num_labels = parse_encap_mpls(tb[RTA_ENCAP], labels);
|
|
|
|
}
|
2020-12-18 14:39:25 +01:00
|
|
|
if (tb[RTA_ENCAP] && tb[RTA_ENCAP_TYPE]
|
|
|
|
&& *(uint16_t *)RTA_DATA(tb[RTA_ENCAP_TYPE])
|
|
|
|
== LWTUNNEL_ENCAP_SEG6_LOCAL) {
|
|
|
|
seg6l_act = parse_encap_seg6local(tb[RTA_ENCAP], &seg6l_ctx);
|
|
|
|
}
|
2020-12-18 13:41:19 +01:00
|
|
|
if (tb[RTA_ENCAP] && tb[RTA_ENCAP_TYPE]
|
|
|
|
&& *(uint16_t *)RTA_DATA(tb[RTA_ENCAP_TYPE])
|
|
|
|
== LWTUNNEL_ENCAP_SEG6) {
|
2023-07-26 17:56:32 +02:00
|
|
|
num_segs = parse_encap_seg6(tb[RTA_ENCAP], segs);
|
2020-12-18 13:41:19 +01:00
|
|
|
}
|
2019-03-11 15:52:33 +01:00
|
|
|
|
|
|
|
if (rtm->rtm_flags & RTNH_F_ONLINK)
|
|
|
|
SET_FLAG(nh.flags, NEXTHOP_FLAG_ONLINK);
|
|
|
|
|
2022-06-23 16:27:56 +02:00
|
|
|
if (rtm->rtm_flags & RTNH_F_LINKDOWN)
|
|
|
|
SET_FLAG(nh.flags, NEXTHOP_FLAG_LINKDOWN);
|
|
|
|
|
2019-03-11 15:52:33 +01:00
|
|
|
if (num_labels)
|
|
|
|
nexthop_add_labels(&nh, ZEBRA_LSP_STATIC, num_labels, labels);
|
|
|
|
|
2023-03-20 21:49:07 +01:00
|
|
|
/* Resolve default values for SRv6 flavors */
|
|
|
|
if (seg6l_ctx.flv.flv_ops != ZEBRA_SEG6_LOCAL_FLV_OP_UNSPEC) {
|
|
|
|
if (seg6l_ctx.flv.lcblock_len == 0)
|
|
|
|
seg6l_ctx.flv.lcblock_len =
|
|
|
|
ZEBRA_DEFAULT_SEG6_LOCAL_FLV_LCBLOCK_LEN;
|
|
|
|
if (seg6l_ctx.flv.lcnode_func_len == 0)
|
|
|
|
seg6l_ctx.flv.lcnode_func_len =
|
|
|
|
ZEBRA_DEFAULT_SEG6_LOCAL_FLV_LCNODE_FN_LEN;
|
|
|
|
}
|
|
|
|
|
2020-12-18 14:39:25 +01:00
|
|
|
if (seg6l_act != ZEBRA_SEG6_LOCAL_ACTION_UNSPEC)
|
2021-04-05 15:29:12 +02:00
|
|
|
nexthop_add_srv6_seg6local(&nh, seg6l_act, &seg6l_ctx);
|
2020-12-18 14:39:25 +01:00
|
|
|
|
2020-12-18 13:41:19 +01:00
|
|
|
if (num_segs)
|
2023-07-26 17:56:32 +02:00
|
|
|
nexthop_add_srv6_seg6(&nh, segs, num_segs);
|
2020-12-18 13:41:19 +01:00
|
|
|
|
2019-03-11 15:52:33 +01:00
|
|
|
return nh;
|
|
|
|
}
|
|
|
|
|
2019-03-29 15:56:52 +01:00
|
|
|
static uint8_t parse_multipath_nexthops_unicast(ns_id_t ns_id,
|
2019-11-22 21:30:53 +01:00
|
|
|
struct nexthop_group *ng,
|
2019-03-29 15:56:52 +01:00
|
|
|
struct rtmsg *rtm,
|
|
|
|
struct rtnexthop *rtnh,
|
|
|
|
struct rtattr **tb,
|
|
|
|
void *prefsrc, vrf_id_t vrf_id)
|
|
|
|
{
|
|
|
|
void *gate = NULL;
|
|
|
|
struct interface *ifp = NULL;
|
|
|
|
int index = 0;
|
|
|
|
/* MPLS labels */
|
|
|
|
mpls_label_t labels[MPLS_MAX_LABELS] = {0};
|
|
|
|
int num_labels = 0;
|
2021-03-22 10:28:32 +01:00
|
|
|
enum seg6local_action_t seg6l_act = ZEBRA_SEG6_LOCAL_ACTION_UNSPEC;
|
2021-03-22 01:31:56 +01:00
|
|
|
struct seg6local_context seg6l_ctx = {};
|
2023-07-26 17:56:32 +02:00
|
|
|
struct in6_addr segs[SRV6_MAX_SIDS] = {};
|
2020-12-18 13:41:19 +01:00
|
|
|
int num_segs = 0;
|
2019-03-29 15:56:52 +01:00
|
|
|
struct rtattr *rtnh_tb[RTA_MAX + 1] = {};
|
|
|
|
|
|
|
|
int len = RTA_PAYLOAD(tb[RTA_MULTIPATH]);
|
|
|
|
vrf_id_t nh_vrf_id = vrf_id;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
struct nexthop *nh = NULL;
|
|
|
|
|
|
|
|
if (len < (int)sizeof(*rtnh) || rtnh->rtnh_len > len)
|
|
|
|
break;
|
|
|
|
|
|
|
|
index = rtnh->rtnh_ifindex;
|
|
|
|
if (index) {
|
|
|
|
/*
|
|
|
|
* Yes we are looking this up
|
|
|
|
* for every nexthop and just
|
|
|
|
* using the last one looked
|
|
|
|
* up right now
|
|
|
|
*/
|
|
|
|
ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id),
|
|
|
|
index);
|
|
|
|
if (ifp)
|
2021-10-22 00:17:40 +02:00
|
|
|
nh_vrf_id = ifp->vrf->vrf_id;
|
2019-03-29 15:56:52 +01:00
|
|
|
else {
|
|
|
|
flog_warn(
|
|
|
|
EC_ZEBRA_UNKNOWN_INTERFACE,
|
|
|
|
"%s: Unknown interface %u specified, defaulting to VRF_DEFAULT",
|
2020-03-05 19:17:54 +01:00
|
|
|
__func__, index);
|
2019-03-29 15:56:52 +01:00
|
|
|
nh_vrf_id = VRF_DEFAULT;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
nh_vrf_id = vrf_id;
|
|
|
|
|
|
|
|
if (rtnh->rtnh_len > sizeof(*rtnh)) {
|
|
|
|
netlink_parse_rtattr(rtnh_tb, RTA_MAX, RTNH_DATA(rtnh),
|
|
|
|
rtnh->rtnh_len - sizeof(*rtnh));
|
|
|
|
if (rtnh_tb[RTA_GATEWAY])
|
|
|
|
gate = RTA_DATA(rtnh_tb[RTA_GATEWAY]);
|
|
|
|
if (rtnh_tb[RTA_ENCAP] && rtnh_tb[RTA_ENCAP_TYPE]
|
|
|
|
&& *(uint16_t *)RTA_DATA(rtnh_tb[RTA_ENCAP_TYPE])
|
|
|
|
== LWTUNNEL_ENCAP_MPLS) {
|
|
|
|
num_labels = parse_encap_mpls(
|
|
|
|
rtnh_tb[RTA_ENCAP], labels);
|
|
|
|
}
|
2020-12-18 14:39:25 +01:00
|
|
|
if (rtnh_tb[RTA_ENCAP] && rtnh_tb[RTA_ENCAP_TYPE]
|
|
|
|
&& *(uint16_t *)RTA_DATA(rtnh_tb[RTA_ENCAP_TYPE])
|
|
|
|
== LWTUNNEL_ENCAP_SEG6_LOCAL) {
|
|
|
|
seg6l_act = parse_encap_seg6local(
|
|
|
|
rtnh_tb[RTA_ENCAP], &seg6l_ctx);
|
|
|
|
}
|
2020-12-18 13:41:19 +01:00
|
|
|
if (rtnh_tb[RTA_ENCAP] && rtnh_tb[RTA_ENCAP_TYPE]
|
|
|
|
&& *(uint16_t *)RTA_DATA(rtnh_tb[RTA_ENCAP_TYPE])
|
|
|
|
== LWTUNNEL_ENCAP_SEG6) {
|
|
|
|
num_segs = parse_encap_seg6(rtnh_tb[RTA_ENCAP],
|
2023-07-26 17:56:32 +02:00
|
|
|
segs);
|
2020-12-18 13:41:19 +01:00
|
|
|
}
|
2019-03-29 15:56:52 +01:00
|
|
|
}
|
|
|
|
|
2019-10-25 17:11:06 +02:00
|
|
|
if (gate && rtm->rtm_family == AF_INET) {
|
|
|
|
if (index)
|
2019-11-22 21:30:53 +01:00
|
|
|
nh = nexthop_from_ipv4_ifindex(
|
|
|
|
gate, prefsrc, index, nh_vrf_id);
|
2019-10-25 17:11:06 +02:00
|
|
|
else
|
2019-11-22 21:30:53 +01:00
|
|
|
nh = nexthop_from_ipv4(gate, prefsrc,
|
|
|
|
nh_vrf_id);
|
2019-10-25 17:11:06 +02:00
|
|
|
} else if (gate && rtm->rtm_family == AF_INET6) {
|
|
|
|
if (index)
|
2019-11-22 21:30:53 +01:00
|
|
|
nh = nexthop_from_ipv6_ifindex(
|
|
|
|
gate, index, nh_vrf_id);
|
2019-10-25 17:11:06 +02:00
|
|
|
else
|
2019-11-22 21:30:53 +01:00
|
|
|
nh = nexthop_from_ipv6(gate, nh_vrf_id);
|
2019-03-29 15:56:52 +01:00
|
|
|
} else
|
2019-11-22 21:30:53 +01:00
|
|
|
nh = nexthop_from_ifindex(index, nh_vrf_id);
|
2019-03-29 15:56:52 +01:00
|
|
|
|
|
|
|
if (nh) {
|
2019-12-06 14:58:47 +01:00
|
|
|
nh->weight = rtnh->rtnh_hops + 1;
|
|
|
|
|
2019-03-29 15:56:52 +01:00
|
|
|
if (num_labels)
|
|
|
|
nexthop_add_labels(nh, ZEBRA_LSP_STATIC,
|
|
|
|
num_labels, labels);
|
|
|
|
|
2023-03-20 21:53:49 +01:00
|
|
|
/* Resolve default values for SRv6 flavors */
|
|
|
|
if (seg6l_ctx.flv.flv_ops !=
|
|
|
|
ZEBRA_SEG6_LOCAL_FLV_OP_UNSPEC) {
|
|
|
|
if (seg6l_ctx.flv.lcblock_len == 0)
|
|
|
|
seg6l_ctx.flv.lcblock_len =
|
|
|
|
ZEBRA_DEFAULT_SEG6_LOCAL_FLV_LCBLOCK_LEN;
|
|
|
|
if (seg6l_ctx.flv.lcnode_func_len == 0)
|
|
|
|
seg6l_ctx.flv.lcnode_func_len =
|
|
|
|
ZEBRA_DEFAULT_SEG6_LOCAL_FLV_LCNODE_FN_LEN;
|
|
|
|
}
|
|
|
|
|
2020-12-18 14:39:25 +01:00
|
|
|
if (seg6l_act != ZEBRA_SEG6_LOCAL_ACTION_UNSPEC)
|
2021-04-05 15:29:12 +02:00
|
|
|
nexthop_add_srv6_seg6local(nh, seg6l_act,
|
|
|
|
&seg6l_ctx);
|
2020-12-18 14:39:25 +01:00
|
|
|
|
2020-12-18 13:41:19 +01:00
|
|
|
if (num_segs)
|
2023-07-26 17:56:32 +02:00
|
|
|
nexthop_add_srv6_seg6(nh, segs, num_segs);
|
2020-12-18 13:41:19 +01:00
|
|
|
|
2019-03-29 15:56:52 +01:00
|
|
|
if (rtnh->rtnh_flags & RTNH_F_ONLINK)
|
|
|
|
SET_FLAG(nh->flags, NEXTHOP_FLAG_ONLINK);
|
2019-11-22 21:30:53 +01:00
|
|
|
|
|
|
|
/* Add to temporary list */
|
|
|
|
nexthop_group_add_sorted(ng, nh);
|
2019-03-29 15:56:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rtnh->rtnh_len == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
len -= NLMSG_ALIGN(rtnh->rtnh_len);
|
|
|
|
rtnh = RTNH_NEXT(rtnh);
|
|
|
|
}
|
|
|
|
|
2019-11-22 21:30:53 +01:00
|
|
|
uint8_t nhop_num = nexthop_group_nexthop_num(ng);
|
2019-03-29 15:56:52 +01:00
|
|
|
|
|
|
|
return nhop_num;
|
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Looking up routing table by netlink interface. */
|
2022-10-04 21:41:36 +02:00
|
|
|
int netlink_route_change_read_unicast_internal(struct nlmsghdr *h,
|
|
|
|
ns_id_t ns_id, int startup,
|
|
|
|
struct zebra_dplane_ctx *ctx)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
struct rtmsg *rtm;
|
2003-07-15 14:52:22 +02:00
|
|
|
struct rtattr *tb[RTA_MAX + 1];
|
2020-10-15 19:41:30 +02:00
|
|
|
uint32_t flags = 0;
|
2016-08-24 08:20:47 +02:00
|
|
|
struct prefix p;
|
2017-10-08 23:47:43 +02:00
|
|
|
struct prefix_ipv6 src_p = {};
|
2018-01-22 09:42:53 +01:00
|
|
|
vrf_id_t vrf_id;
|
2020-03-11 19:20:41 +01:00
|
|
|
bool selfroute;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-07-15 14:52:22 +02:00
|
|
|
char anyaddr[16] = {0};
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-09-01 16:28:19 +02:00
|
|
|
int proto = ZEBRA_ROUTE_KERNEL;
|
2016-12-05 20:05:30 +01:00
|
|
|
int index = 0;
|
2002-12-13 21:15:29 +01:00
|
|
|
int table;
|
2016-12-05 20:05:30 +01:00
|
|
|
int metric = 0;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint32_t mtu = 0;
|
2017-09-25 14:37:04 +02:00
|
|
|
uint8_t distance = 0;
|
2017-12-08 20:44:15 +01:00
|
|
|
route_tag_t tag = 0;
|
2019-03-11 15:46:25 +01:00
|
|
|
uint32_t nhe_id = 0;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-12-05 20:05:30 +01:00
|
|
|
void *dest = NULL;
|
|
|
|
void *gate = NULL;
|
|
|
|
void *prefsrc = NULL; /* IPv4 preferred source host address */
|
|
|
|
void *src = NULL; /* IPv6 srcdest source prefix */
|
2010-02-05 04:58:46 +01:00
|
|
|
enum blackhole_type bh_type = BLACKHOLE_UNSPEC;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2021-10-06 14:56:46 +02:00
|
|
|
frrtrace(3, frr_zebra, netlink_route_change_read_unicast, h, ns_id,
|
|
|
|
startup);
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
rtm = NLMSG_DATA(h);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-01-30 20:40:14 +01:00
|
|
|
if (startup && h->nlmsg_type != RTM_NEWROUTE)
|
2002-12-13 21:15:29 +01:00
|
|
|
return 0;
|
2010-02-05 04:58:46 +01:00
|
|
|
switch (rtm->rtm_type) {
|
|
|
|
case RTN_UNICAST:
|
|
|
|
break;
|
|
|
|
case RTN_BLACKHOLE:
|
|
|
|
bh_type = BLACKHOLE_NULL;
|
|
|
|
break;
|
|
|
|
case RTN_UNREACHABLE:
|
|
|
|
bh_type = BLACKHOLE_REJECT;
|
|
|
|
break;
|
|
|
|
case RTN_PROHIBIT:
|
|
|
|
bh_type = BLACKHOLE_ADMINPROHIB;
|
|
|
|
break;
|
|
|
|
default:
|
2019-06-18 14:47:28 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("Route rtm_type: %s(%d) intentionally ignoring",
|
|
|
|
nl_rttype_to_str(rtm->rtm_type),
|
|
|
|
rtm->rtm_type);
|
2002-12-13 21:15:29 +01:00
|
|
|
return 0;
|
2010-02-05 04:58:46 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2003-07-15 14:52:22 +02:00
|
|
|
len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg));
|
2018-06-22 20:22:02 +02:00
|
|
|
if (len < 0) {
|
2020-03-05 19:17:54 +01:00
|
|
|
zlog_err(
|
|
|
|
"%s: Message received from netlink is of a broken size %d %zu",
|
|
|
|
__func__, h->nlmsg_len,
|
|
|
|
(size_t)NLMSG_LENGTH(sizeof(struct rtmsg)));
|
2002-12-13 21:15:29 +01:00
|
|
|
return -1;
|
2018-06-22 20:22:02 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
netlink_parse_rtattr(tb, RTA_MAX, RTM_RTA(rtm), len);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (rtm->rtm_flags & RTM_F_CLONED)
|
|
|
|
return 0;
|
|
|
|
if (rtm->rtm_protocol == RTPROT_REDIRECT)
|
|
|
|
return 0;
|
|
|
|
if (rtm->rtm_protocol == RTPROT_KERNEL)
|
|
|
|
return 0;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-03-11 19:20:41 +01:00
|
|
|
selfroute = is_selfroute(rtm->rtm_protocol);
|
|
|
|
|
2022-10-04 21:41:36 +02:00
|
|
|
if (!startup && selfroute && h->nlmsg_type == RTM_NEWROUTE &&
|
|
|
|
!zrouter.asic_offloaded && !ctx) {
|
2018-05-25 20:45:16 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("Route type: %d Received that we think we have originated, ignoring",
|
|
|
|
rtm->rtm_protocol);
|
2017-01-30 20:40:14 +01:00
|
|
|
return 0;
|
2018-05-25 20:45:16 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-04-16 04:19:37 +02:00
|
|
|
/* We don't care about change notifications for the MPLS table. */
|
|
|
|
/* TODO: Revisit this. */
|
|
|
|
if (rtm->rtm_family == AF_MPLS)
|
|
|
|
return 0;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-03-25 06:01:11 +01:00
|
|
|
/* Table corresponding to route. */
|
|
|
|
if (tb[RTA_TABLE])
|
|
|
|
table = *(int *)RTA_DATA(tb[RTA_TABLE]);
|
|
|
|
else
|
|
|
|
table = rtm->rtm_table;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-03-25 06:01:11 +01:00
|
|
|
/* Map to VRF */
|
2023-04-27 05:25:27 +02:00
|
|
|
vrf_id = zebra_vrf_lookup_by_table(table, ns_id);
|
2016-03-25 06:01:11 +01:00
|
|
|
if (vrf_id == VRF_DEFAULT) {
|
|
|
|
if (!is_zebra_valid_kernel_table(table)
|
|
|
|
&& !is_zebra_main_routing_table(table))
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-09-18 21:47:27 +02:00
|
|
|
if (rtm->rtm_flags & RTM_F_TRAP)
|
|
|
|
flags |= ZEBRA_FLAG_TRAPPED;
|
|
|
|
if (rtm->rtm_flags & RTM_F_OFFLOAD)
|
|
|
|
flags |= ZEBRA_FLAG_OFFLOADED;
|
2020-10-26 13:46:57 +01:00
|
|
|
if (rtm->rtm_flags & RTM_F_OFFLOAD_FAILED)
|
|
|
|
flags |= ZEBRA_FLAG_OFFLOAD_FAILED;
|
2020-09-18 21:47:27 +02:00
|
|
|
|
2022-11-01 13:00:14 +01:00
|
|
|
if (h->nlmsg_flags & NLM_F_APPEND)
|
|
|
|
flags |= ZEBRA_FLAG_OUTOFSYNC;
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Route which inserted by Zebra. */
|
2020-03-11 19:20:41 +01:00
|
|
|
if (selfroute) {
|
2002-12-13 21:15:29 +01:00
|
|
|
flags |= ZEBRA_FLAG_SELFROUTE;
|
2019-08-01 20:07:04 +02:00
|
|
|
proto = proto2zebra(rtm->rtm_protocol, rtm->rtm_family, false);
|
2017-09-01 16:28:19 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
if (tb[RTA_OIF])
|
|
|
|
index = *(int *)RTA_DATA(tb[RTA_OIF]);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (tb[RTA_DST])
|
|
|
|
dest = RTA_DATA(tb[RTA_DST]);
|
|
|
|
else
|
|
|
|
dest = anyaddr;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-12-05 20:05:30 +01:00
|
|
|
if (tb[RTA_SRC])
|
|
|
|
src = RTA_DATA(tb[RTA_SRC]);
|
|
|
|
else
|
|
|
|
src = anyaddr;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2007-05-02 18:05:35 +02:00
|
|
|
if (tb[RTA_PREFSRC])
|
2016-12-05 20:05:30 +01:00
|
|
|
prefsrc = RTA_DATA(tb[RTA_PREFSRC]);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (tb[RTA_GATEWAY])
|
|
|
|
gate = RTA_DATA(tb[RTA_GATEWAY]);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-03-11 15:46:25 +01:00
|
|
|
if (tb[RTA_NH_ID])
|
|
|
|
nhe_id = *(uint32_t *)RTA_DATA(tb[RTA_NH_ID]);
|
|
|
|
|
2017-08-09 15:13:33 +02:00
|
|
|
if (tb[RTA_PRIORITY])
|
|
|
|
metric = *(int *)RTA_DATA(tb[RTA_PRIORITY]);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-12-08 20:44:15 +01:00
|
|
|
#if defined(SUPPORT_REALMS)
|
|
|
|
if (tb[RTA_FLOW])
|
|
|
|
tag = *(uint32_t *)RTA_DATA(tb[RTA_FLOW]);
|
|
|
|
#endif
|
|
|
|
|
2017-08-09 15:13:33 +02:00
|
|
|
if (tb[RTA_METRICS]) {
|
|
|
|
struct rtattr *mxrta[RTAX_MAX + 1];
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-08-09 15:13:33 +02:00
|
|
|
netlink_parse_rtattr(mxrta, RTAX_MAX, RTA_DATA(tb[RTA_METRICS]),
|
|
|
|
RTA_PAYLOAD(tb[RTA_METRICS]));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-08-09 15:13:33 +02:00
|
|
|
if (mxrta[RTAX_MTU])
|
2018-03-27 21:13:34 +02:00
|
|
|
mtu = *(uint32_t *)RTA_DATA(mxrta[RTAX_MTU]);
|
2015-11-02 15:50:07 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
if (rtm->rtm_family == AF_INET) {
|
|
|
|
p.family = AF_INET;
|
2018-07-21 05:20:28 +02:00
|
|
|
if (rtm->rtm_dst_len > IPV4_MAX_BITLEN) {
|
2018-07-26 21:10:53 +02:00
|
|
|
zlog_err(
|
2018-07-24 17:14:07 +02:00
|
|
|
"Invalid destination prefix length: %u received from kernel route change",
|
2018-07-21 05:20:28 +02:00
|
|
|
rtm->rtm_dst_len);
|
2018-07-26 21:10:53 +02:00
|
|
|
return -1;
|
2018-07-21 05:20:28 +02:00
|
|
|
}
|
2016-08-24 07:39:08 +02:00
|
|
|
memcpy(&p.u.prefix4, dest, 4);
|
2002-12-13 21:15:29 +01:00
|
|
|
p.prefixlen = rtm->rtm_dst_len;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-07-23 03:40:42 +02:00
|
|
|
if (rtm->rtm_src_len != 0) {
|
2018-08-16 22:10:32 +02:00
|
|
|
flog_warn(
|
2018-09-13 21:21:05 +02:00
|
|
|
EC_ZEBRA_UNSUPPORTED_V4_SRCDEST,
|
2020-10-18 13:33:54 +02:00
|
|
|
"unsupported IPv4 sourcedest route (dest %pFX vrf %u)",
|
|
|
|
&p, vrf_id);
|
2018-07-23 03:40:42 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2018-07-21 05:20:28 +02:00
|
|
|
|
2018-07-23 03:40:42 +02:00
|
|
|
/* Force debug below to not display anything for source */
|
|
|
|
src_p.prefixlen = 0;
|
2017-01-30 20:50:06 +01:00
|
|
|
} else if (rtm->rtm_family == AF_INET6) {
|
|
|
|
p.family = AF_INET6;
|
2018-07-21 05:20:28 +02:00
|
|
|
if (rtm->rtm_dst_len > IPV6_MAX_BITLEN) {
|
2018-07-26 21:10:53 +02:00
|
|
|
zlog_err(
|
2018-07-24 17:14:07 +02:00
|
|
|
"Invalid destination prefix length: %u received from kernel route change",
|
2018-07-21 05:20:28 +02:00
|
|
|
rtm->rtm_dst_len);
|
2018-07-26 21:10:53 +02:00
|
|
|
return -1;
|
2018-07-21 05:20:28 +02:00
|
|
|
}
|
2017-01-30 20:50:06 +01:00
|
|
|
memcpy(&p.u.prefix6, dest, 16);
|
|
|
|
p.prefixlen = rtm->rtm_dst_len;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-01-30 20:50:06 +01:00
|
|
|
src_p.family = AF_INET6;
|
2018-07-21 05:20:28 +02:00
|
|
|
if (rtm->rtm_src_len > IPV6_MAX_BITLEN) {
|
2018-07-26 21:10:53 +02:00
|
|
|
zlog_err(
|
2018-07-24 17:14:07 +02:00
|
|
|
"Invalid source prefix length: %u received from kernel route change",
|
2018-07-21 05:20:28 +02:00
|
|
|
rtm->rtm_src_len);
|
2018-07-26 21:10:53 +02:00
|
|
|
return -1;
|
2018-07-21 05:20:28 +02:00
|
|
|
}
|
2017-01-30 20:50:06 +01:00
|
|
|
memcpy(&src_p.prefix, src, 16);
|
|
|
|
src_p.prefixlen = rtm->rtm_src_len;
|
2021-08-10 17:44:08 +02:00
|
|
|
} else {
|
|
|
|
/* We only handle the AFs we handle... */
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("%s: unknown address-family %u", __func__,
|
|
|
|
rtm->rtm_family);
|
|
|
|
return 0;
|
2017-01-30 20:50:06 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-09-25 14:37:04 +02:00
|
|
|
/*
|
|
|
|
* For ZEBRA_ROUTE_KERNEL types:
|
|
|
|
*
|
|
|
|
* The metric/priority of the route received from the kernel
|
|
|
|
* is a 32 bit number. We are going to interpret the high
|
|
|
|
* order byte as the Admin Distance and the low order 3 bytes
|
|
|
|
* as the metric.
|
|
|
|
*
|
|
|
|
* This will allow us to do two things:
|
|
|
|
* 1) Allow the creation of kernel routes that can be
|
|
|
|
* overridden by zebra.
|
|
|
|
* 2) Allow the old behavior for 'most' kernel route types
|
|
|
|
* if a user enters 'ip route ...' v4 routes get a metric
|
|
|
|
* of 0 and v6 routes get a metric of 1024. Both of these
|
|
|
|
* values will end up with a admin distance of 0, which
|
|
|
|
* will cause them to win for the purposes of zebra.
|
|
|
|
*/
|
|
|
|
if (proto == ZEBRA_ROUTE_KERNEL) {
|
|
|
|
distance = (metric >> 24) & 0xFF;
|
|
|
|
metric = (metric & 0x00FFFFFF);
|
|
|
|
}
|
|
|
|
|
2017-01-30 20:50:06 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL) {
|
|
|
|
char buf2[PREFIX_STRLEN];
|
2020-10-18 13:33:54 +02:00
|
|
|
|
2020-03-15 19:42:30 +01:00
|
|
|
zlog_debug(
|
2020-10-18 13:33:54 +02:00
|
|
|
"%s %pFX%s%s vrf %s(%u) table_id: %u metric: %d Admin Distance: %d",
|
|
|
|
nl_msg_type_to_str(h->nlmsg_type), &p,
|
2020-03-15 19:42:30 +01:00
|
|
|
src_p.prefixlen ? " from " : "",
|
|
|
|
src_p.prefixlen ? prefix2str(&src_p, buf2, sizeof(buf2))
|
|
|
|
: "",
|
|
|
|
vrf_id_to_name(vrf_id), vrf_id, table, metric,
|
|
|
|
distance);
|
2017-01-30 20:50:06 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-01-30 20:50:06 +01:00
|
|
|
afi_t afi = AFI_IP;
|
|
|
|
if (rtm->rtm_family == AF_INET6)
|
|
|
|
afi = AFI_IP6;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-01-30 20:50:06 +01:00
|
|
|
if (h->nlmsg_type == RTM_NEWROUTE) {
|
2022-08-10 02:07:09 +02:00
|
|
|
struct route_entry *re;
|
|
|
|
struct nexthop_group *ng = NULL;
|
|
|
|
|
|
|
|
re = zebra_rib_route_entry_new(vrf_id, proto, 0, flags, nhe_id,
|
|
|
|
table, metric, mtu, distance,
|
|
|
|
tag);
|
|
|
|
if (!nhe_id)
|
|
|
|
ng = nexthop_group_new();
|
2018-01-08 16:21:09 +01:00
|
|
|
|
2017-08-28 01:30:16 +02:00
|
|
|
if (!tb[RTA_MULTIPATH]) {
|
2022-08-10 02:07:09 +02:00
|
|
|
struct nexthop *nexthop, nh;
|
2018-01-08 16:21:09 +01:00
|
|
|
|
2019-03-11 15:52:33 +01:00
|
|
|
if (!nhe_id) {
|
|
|
|
nh = parse_nexthop_unicast(
|
|
|
|
ns_id, rtm, tb, bh_type, index, prefsrc,
|
2019-03-29 15:56:52 +01:00
|
|
|
gate, afi, vrf_id);
|
2022-08-10 02:07:09 +02:00
|
|
|
|
|
|
|
nexthop = nexthop_new();
|
|
|
|
*nexthop = nh;
|
|
|
|
nexthop_group_add_sorted(ng, nexthop);
|
2018-08-12 00:36:22 +02:00
|
|
|
}
|
2017-08-28 01:30:16 +02:00
|
|
|
} else {
|
2017-01-30 20:50:06 +01:00
|
|
|
/* This is a multipath route */
|
|
|
|
struct rtnexthop *rtnh =
|
|
|
|
(struct rtnexthop *)RTA_DATA(tb[RTA_MULTIPATH]);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-03-29 15:56:52 +01:00
|
|
|
if (!nhe_id) {
|
2019-11-22 21:30:53 +01:00
|
|
|
uint8_t nhop_num;
|
|
|
|
|
|
|
|
/* Use temporary list of nexthops; parse
|
|
|
|
* message payload's nexthops.
|
|
|
|
*/
|
|
|
|
nhop_num =
|
2019-03-29 15:56:52 +01:00
|
|
|
parse_multipath_nexthops_unicast(
|
2019-11-22 21:30:53 +01:00
|
|
|
ns_id, ng, rtm, rtnh, tb,
|
2019-03-29 15:56:52 +01:00
|
|
|
prefsrc, vrf_id);
|
|
|
|
|
|
|
|
zserv_nexthop_num_warn(
|
|
|
|
__func__, (const struct prefix *)&p,
|
|
|
|
nhop_num);
|
2019-11-22 21:30:53 +01:00
|
|
|
|
|
|
|
if (nhop_num == 0) {
|
|
|
|
nexthop_group_delete(&ng);
|
|
|
|
ng = NULL;
|
|
|
|
}
|
2017-01-30 20:50:06 +01:00
|
|
|
}
|
2022-08-10 02:07:09 +02:00
|
|
|
}
|
2022-12-14 18:30:43 +01:00
|
|
|
if (nhe_id || ng) {
|
2022-10-04 21:41:36 +02:00
|
|
|
dplane_rib_add_multipath(afi, SAFI_UNICAST, &p, &src_p,
|
|
|
|
re, ng, startup, ctx);
|
2022-12-14 18:30:43 +01:00
|
|
|
if (ng)
|
|
|
|
nexthop_group_delete(&ng);
|
|
|
|
} else {
|
2022-08-10 02:07:09 +02:00
|
|
|
/*
|
|
|
|
* I really don't see how this is possible
|
|
|
|
* but since we are testing for it let's
|
|
|
|
* let the end user know why the route
|
|
|
|
* that was just received was swallowed
|
|
|
|
* up and forgotten
|
|
|
|
*/
|
|
|
|
zlog_err(
|
|
|
|
"%s: %pFX multipath RTM_NEWROUTE has a invalid nexthop group from the kernel",
|
|
|
|
__func__, &p);
|
|
|
|
XFREE(MTYPE_RE, re);
|
2003-07-15 14:52:22 +02:00
|
|
|
}
|
2017-01-30 20:50:06 +01:00
|
|
|
} else {
|
2022-10-04 21:41:36 +02:00
|
|
|
if (ctx) {
|
|
|
|
zlog_err(
|
|
|
|
"%s: %pFX RTM_DELROUTE received but received a context as well",
|
|
|
|
__func__, &p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-01 23:36:56 +02:00
|
|
|
if (nhe_id) {
|
|
|
|
rib_delete(afi, SAFI_UNICAST, vrf_id, proto, 0, flags,
|
|
|
|
&p, &src_p, NULL, nhe_id, table, metric,
|
2020-12-10 16:24:47 +01:00
|
|
|
distance, true);
|
2019-08-01 23:36:56 +02:00
|
|
|
} else {
|
|
|
|
if (!tb[RTA_MULTIPATH]) {
|
|
|
|
struct nexthop nh;
|
2019-12-18 10:05:59 +01:00
|
|
|
|
|
|
|
nh = parse_nexthop_unicast(
|
|
|
|
ns_id, rtm, tb, bh_type, index, prefsrc,
|
|
|
|
gate, afi, vrf_id);
|
2019-08-01 23:36:56 +02:00
|
|
|
rib_delete(afi, SAFI_UNICAST, vrf_id, proto, 0,
|
|
|
|
flags, &p, &src_p, &nh, 0, table,
|
2020-12-10 16:24:47 +01:00
|
|
|
metric, distance, true);
|
2017-09-01 02:13:23 +02:00
|
|
|
} else {
|
2019-08-01 23:36:56 +02:00
|
|
|
/* XXX: need to compare the entire list of
|
|
|
|
* nexthops here for NLM_F_APPEND stupidity */
|
|
|
|
rib_delete(afi, SAFI_UNICAST, vrf_id, proto, 0,
|
|
|
|
flags, &p, &src_p, NULL, 0, table,
|
2020-12-10 16:24:47 +01:00
|
|
|
metric, distance, true);
|
2017-09-01 02:13:23 +02:00
|
|
|
}
|
2017-02-16 22:59:20 +01:00
|
|
|
}
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-10-04 21:41:36 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id,
|
|
|
|
int startup)
|
|
|
|
{
|
|
|
|
return netlink_route_change_read_unicast_internal(h, ns_id, startup,
|
|
|
|
NULL);
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2016-08-11 02:04:20 +02:00
|
|
|
static struct mcast_route_data *mroute = NULL;
|
|
|
|
|
2018-05-23 15:37:06 +02:00
|
|
|
static int netlink_route_change_read_multicast(struct nlmsghdr *h,
|
2017-01-27 19:33:08 +01:00
|
|
|
ns_id_t ns_id, int startup)
|
2016-08-04 01:53:42 +02:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
struct rtmsg *rtm;
|
|
|
|
struct rtattr *tb[RTA_MAX + 1];
|
2016-08-11 02:04:20 +02:00
|
|
|
struct mcast_route_data *m;
|
2016-08-10 14:54:58 +02:00
|
|
|
int iif = 0;
|
|
|
|
int count;
|
|
|
|
int oif[256];
|
|
|
|
int oif_count = 0;
|
2016-08-11 02:04:20 +02:00
|
|
|
char oif_list[256] = "\0";
|
2018-01-22 09:42:53 +01:00
|
|
|
vrf_id_t vrf;
|
2017-06-06 16:18:17 +02:00
|
|
|
int table;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-07-06 11:19:05 +02:00
|
|
|
assert(mroute);
|
|
|
|
m = mroute;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-08-10 14:54:58 +02:00
|
|
|
rtm = NLMSG_DATA(h);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-08-10 14:54:58 +02:00
|
|
|
len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-08-11 02:04:20 +02:00
|
|
|
netlink_parse_rtattr(tb, RTA_MAX, RTM_RTA(rtm), len);
|
2016-08-10 14:54:58 +02:00
|
|
|
|
2017-06-06 16:18:17 +02:00
|
|
|
if (tb[RTA_TABLE])
|
|
|
|
table = *(int *)RTA_DATA(tb[RTA_TABLE]);
|
|
|
|
else
|
|
|
|
table = rtm->rtm_table;
|
|
|
|
|
2023-04-27 05:25:27 +02:00
|
|
|
vrf = zebra_vrf_lookup_by_table(table, ns_id);
|
2017-06-06 16:18:17 +02:00
|
|
|
|
2016-08-10 14:54:58 +02:00
|
|
|
if (tb[RTA_IIF])
|
|
|
|
iif = *(int *)RTA_DATA(tb[RTA_IIF]);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-04-04 13:05:07 +02:00
|
|
|
if (tb[RTA_SRC]) {
|
|
|
|
if (rtm->rtm_family == RTNL_FAMILY_IPMR)
|
|
|
|
m->src.ipaddr_v4 =
|
|
|
|
*(struct in_addr *)RTA_DATA(tb[RTA_SRC]);
|
|
|
|
else
|
|
|
|
m->src.ipaddr_v6 =
|
|
|
|
*(struct in6_addr *)RTA_DATA(tb[RTA_SRC]);
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-04-04 13:05:07 +02:00
|
|
|
if (tb[RTA_DST]) {
|
|
|
|
if (rtm->rtm_family == RTNL_FAMILY_IPMR)
|
|
|
|
m->grp.ipaddr_v4 =
|
|
|
|
*(struct in_addr *)RTA_DATA(tb[RTA_DST]);
|
|
|
|
else
|
|
|
|
m->grp.ipaddr_v6 =
|
|
|
|
*(struct in6_addr *)RTA_DATA(tb[RTA_DST]);
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-15 14:55:34 +01:00
|
|
|
if (tb[RTA_EXPIRES])
|
2016-08-11 02:04:20 +02:00
|
|
|
m->lastused = *(unsigned long long *)RTA_DATA(tb[RTA_EXPIRES]);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-08-10 14:54:58 +02:00
|
|
|
if (tb[RTA_MULTIPATH]) {
|
|
|
|
struct rtnexthop *rtnh =
|
|
|
|
(struct rtnexthop *)RTA_DATA(tb[RTA_MULTIPATH]);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-08-10 14:54:58 +02:00
|
|
|
len = RTA_PAYLOAD(tb[RTA_MULTIPATH]);
|
2017-07-17 14:03:14 +02:00
|
|
|
for (;;) {
|
2016-08-10 14:54:58 +02:00
|
|
|
if (len < (int)sizeof(*rtnh) || rtnh->rtnh_len > len)
|
2017-07-17 14:03:14 +02:00
|
|
|
break;
|
|
|
|
|
2016-08-10 14:54:58 +02:00
|
|
|
oif[oif_count] = rtnh->rtnh_ifindex;
|
|
|
|
oif_count++;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-07-24 00:33:53 +02:00
|
|
|
if (rtnh->rtnh_len == 0)
|
|
|
|
break;
|
|
|
|
|
2016-08-04 01:53:42 +02:00
|
|
|
len -= NLMSG_ALIGN(rtnh->rtnh_len);
|
2016-08-10 14:54:58 +02:00
|
|
|
rtnh = RTNH_NEXT(rtnh);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-04 13:05:07 +02:00
|
|
|
if (rtm->rtm_family == RTNL_FAMILY_IPMR) {
|
|
|
|
SET_IPADDR_V4(&m->src);
|
|
|
|
SET_IPADDR_V4(&m->grp);
|
|
|
|
} else if (rtm->rtm_family == RTNL_FAMILY_IP6MR) {
|
|
|
|
SET_IPADDR_V6(&m->src);
|
|
|
|
SET_IPADDR_V6(&m->grp);
|
|
|
|
} else {
|
|
|
|
zlog_warn("%s: Invalid rtm_family received", __func__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-10 14:54:58 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL) {
|
2019-07-09 17:10:49 +02:00
|
|
|
struct interface *ifp = NULL;
|
|
|
|
struct zebra_vrf *zvrf = NULL;
|
|
|
|
|
2016-08-10 14:54:58 +02:00
|
|
|
for (count = 0; count < oif_count; count++) {
|
2017-03-10 21:45:28 +01:00
|
|
|
ifp = if_lookup_by_index(oif[count], vrf);
|
2016-08-10 14:54:58 +02:00
|
|
|
char temp[256];
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-04-20 20:12:38 +02:00
|
|
|
snprintf(temp, sizeof(temp), "%s(%d) ",
|
|
|
|
ifp ? ifp->name : "Unknown", oif[count]);
|
2019-05-07 00:55:59 +02:00
|
|
|
strlcat(oif_list, temp, sizeof(oif_list));
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2019-07-09 17:10:49 +02:00
|
|
|
zvrf = zebra_vrf_lookup_by_id(vrf);
|
2017-03-10 21:45:28 +01:00
|
|
|
ifp = if_lookup_by_index(iif, vrf);
|
2019-07-09 17:10:49 +02:00
|
|
|
zlog_debug(
|
2022-04-04 13:05:07 +02:00
|
|
|
"MCAST VRF: %s(%d) %s (%pIA,%pIA) IIF: %s(%d) OIF: %s jiffies: %lld",
|
2020-03-15 19:42:30 +01:00
|
|
|
zvrf_name(zvrf), vrf, nl_msg_type_to_str(h->nlmsg_type),
|
2022-04-04 13:05:07 +02:00
|
|
|
&m->src, &m->grp, ifp ? ifp->name : "Unknown", iif,
|
|
|
|
oif_list, m->lastused);
|
2016-08-10 14:54:58 +02:00
|
|
|
}
|
2016-08-04 01:53:42 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-05-23 15:37:06 +02:00
|
|
|
int netlink_route_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
|
2016-08-04 01:53:42 +02:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
struct rtmsg *rtm;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-08-04 01:53:42 +02:00
|
|
|
rtm = NLMSG_DATA(h);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-08-04 01:53:42 +02:00
|
|
|
if (!(h->nlmsg_type == RTM_NEWROUTE || h->nlmsg_type == RTM_DELROUTE)) {
|
|
|
|
/* If this is not route add/delete message print warning. */
|
2019-03-14 19:41:15 +01:00
|
|
|
zlog_debug("Kernel message: %s NS %u",
|
2018-09-14 23:48:51 +02:00
|
|
|
nl_msg_type_to_str(h->nlmsg_type), ns_id);
|
2016-08-04 01:53:42 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-07-06 11:19:05 +02:00
|
|
|
switch (rtm->rtm_family) {
|
|
|
|
case AF_INET:
|
|
|
|
case AF_INET6:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RTNL_FAMILY_IPMR:
|
|
|
|
case RTNL_FAMILY_IP6MR:
|
|
|
|
/* notifications on IPMR are irrelevant to zebra, we only care
|
|
|
|
* about responses to RTM_GETROUTE requests we sent.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
2018-08-16 22:10:32 +02:00
|
|
|
flog_warn(
|
2018-09-13 21:21:05 +02:00
|
|
|
EC_ZEBRA_UNKNOWN_FAMILY,
|
2018-09-14 23:48:51 +02:00
|
|
|
"Invalid address family: %u received from kernel route change: %s",
|
|
|
|
rtm->rtm_family, nl_msg_type_to_str(h->nlmsg_type));
|
2018-07-19 23:29:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-08-04 01:53:42 +02:00
|
|
|
/* Connected route. */
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2018-01-22 09:42:53 +01:00
|
|
|
zlog_debug("%s %s %s proto %s NS %u",
|
2016-08-10 14:54:58 +02:00
|
|
|
nl_msg_type_to_str(h->nlmsg_type),
|
|
|
|
nl_family_to_str(rtm->rtm_family),
|
|
|
|
nl_rttype_to_str(rtm->rtm_type),
|
2018-01-22 09:42:53 +01:00
|
|
|
nl_rtproto_to_str(rtm->rtm_protocol), ns_id);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
|
2016-08-04 01:53:42 +02:00
|
|
|
len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg));
|
2018-06-22 20:22:02 +02:00
|
|
|
if (len < 0) {
|
2020-03-05 19:17:54 +01:00
|
|
|
zlog_err(
|
|
|
|
"%s: Message received from netlink is of a broken size: %d %zu",
|
|
|
|
__func__, h->nlmsg_len,
|
|
|
|
(size_t)NLMSG_LENGTH(sizeof(struct rtmsg)));
|
2016-08-04 01:53:42 +02:00
|
|
|
return -1;
|
2018-06-22 20:22:02 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-07-06 11:19:05 +02:00
|
|
|
/* these are "magic" kernel-managed *unicast* routes used for
|
|
|
|
* outputting locally generated multicast traffic (which uses unicast
|
|
|
|
* handling on Linux because ~reasons~.
|
|
|
|
*/
|
2010-02-05 04:58:46 +01:00
|
|
|
if (rtm->rtm_type == RTN_MULTICAST)
|
2022-07-06 11:19:05 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
netlink_route_change_read_unicast(h, ns_id, startup);
|
2016-08-04 01:53:42 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-15 07:28:32 +02:00
|
|
|
/* Request for specific route information from the kernel */
|
|
|
|
static int netlink_request_route(struct zebra_ns *zns, int family, int type)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct rtmsg rtm;
|
|
|
|
} req;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:28:32 +02:00
|
|
|
/* Form the request, specifying filter (rtattr) if needed. */
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
req.n.nlmsg_type = type;
|
2018-12-11 06:33:16 +01:00
|
|
|
req.n.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST;
|
2017-05-15 07:28:32 +02:00
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
|
|
|
|
req.rtm.rtm_family = family;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-04-15 14:56:03 +02:00
|
|
|
return netlink_request(&zns->netlink_cmd, &req);
|
2017-05-15 07:28:32 +02:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Routing table read function using netlink interface. Only called
|
|
|
|
bootstrap time. */
|
2016-02-01 19:55:42 +01:00
|
|
|
int netlink_route_read(struct zebra_ns *zns)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
|
|
|
int ret;
|
2018-09-12 20:59:57 +02:00
|
|
|
struct zebra_dplane_info dp_info;
|
|
|
|
|
|
|
|
zebra_dplane_info_from_zns(&dp_info, zns, true /*is_cmd*/);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Get IPv4 routing table. */
|
2017-05-15 07:28:32 +02:00
|
|
|
ret = netlink_request_route(zns, AF_INET, RTM_GETROUTE);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2017-01-30 20:40:14 +01:00
|
|
|
ret = netlink_parse_info(netlink_route_change_read_unicast,
|
2021-10-05 02:26:38 +02:00
|
|
|
&zns->netlink_cmd, &dp_info, 0, true);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Get IPv6 routing table. */
|
2017-05-15 07:28:32 +02:00
|
|
|
ret = netlink_request_route(zns, AF_INET6, RTM_GETROUTE);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2017-01-30 20:40:14 +01:00
|
|
|
ret = netlink_parse_info(netlink_route_change_read_unicast,
|
2021-10-05 02:26:38 +02:00
|
|
|
&zns->netlink_cmd, &dp_info, 0, true);
|
2002-12-13 21:15:29 +01:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
/*
|
|
|
|
* The function returns true if the gateway info could be added
|
|
|
|
* to the message, otherwise false is returned.
|
|
|
|
*/
|
|
|
|
static bool _netlink_route_add_gateway_info(uint8_t route_family,
|
2020-06-08 23:37:26 +02:00
|
|
|
uint8_t gw_family,
|
|
|
|
struct nlmsghdr *nlmsg,
|
|
|
|
size_t req_size, int bytelen,
|
|
|
|
const struct nexthop *nexthop)
|
2016-04-16 04:19:37 +02:00
|
|
|
{
|
|
|
|
if (route_family == AF_MPLS) {
|
|
|
|
struct gw_family_t gw_fam;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-04-16 04:19:37 +02:00
|
|
|
gw_fam.family = gw_family;
|
|
|
|
if (gw_family == AF_INET)
|
|
|
|
memcpy(&gw_fam.gate.ipv4, &nexthop->gate.ipv4, bytelen);
|
|
|
|
else
|
|
|
|
memcpy(&gw_fam.gate.ipv6, &nexthop->gate.ipv6, bytelen);
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!nl_attr_put(nlmsg, req_size, RTA_VIA, &gw_fam.family,
|
|
|
|
bytelen + 2))
|
|
|
|
return false;
|
2016-04-16 04:19:37 +02:00
|
|
|
} else {
|
2020-07-29 17:48:57 +02:00
|
|
|
if (!(nexthop->rparent
|
|
|
|
&& IS_MAPPED_IPV6(&nexthop->rparent->gate.ipv6))) {
|
|
|
|
if (gw_family == AF_INET) {
|
|
|
|
if (!nl_attr_put(nlmsg, req_size, RTA_GATEWAY,
|
|
|
|
&nexthop->gate.ipv4, bytelen))
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if (!nl_attr_put(nlmsg, req_size, RTA_GATEWAY,
|
|
|
|
&nexthop->gate.ipv6, bytelen))
|
|
|
|
return false;
|
|
|
|
}
|
2020-06-10 11:44:31 +02:00
|
|
|
}
|
2016-04-16 04:19:37 +02:00
|
|
|
}
|
2020-06-10 11:44:31 +02:00
|
|
|
|
|
|
|
return true;
|
2016-04-16 04:19:37 +02:00
|
|
|
}
|
|
|
|
|
2019-08-12 18:35:58 +02:00
|
|
|
static int build_label_stack(struct mpls_label_stack *nh_label,
|
2021-04-01 17:50:31 +02:00
|
|
|
enum lsp_types_t nh_label_type,
|
2019-08-12 18:35:58 +02:00
|
|
|
mpls_lse_t *out_lse, char *label_buf,
|
|
|
|
size_t label_buf_size)
|
|
|
|
{
|
|
|
|
char label_buf1[20];
|
|
|
|
int num_labels = 0;
|
|
|
|
|
|
|
|
for (int i = 0; nh_label && i < nh_label->num_labels; i++) {
|
2022-12-10 00:51:22 +01:00
|
|
|
if (nh_label_type != ZEBRA_LSP_EVPN &&
|
|
|
|
nh_label->label[i] == MPLS_LABEL_IMPLICIT_NULL)
|
2019-08-12 18:35:58 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL) {
|
|
|
|
if (!num_labels)
|
2021-02-08 04:39:42 +01:00
|
|
|
snprintf(label_buf, label_buf_size, "label %u",
|
|
|
|
nh_label->label[i]);
|
2019-08-12 18:35:58 +02:00
|
|
|
else {
|
2020-04-20 20:12:38 +02:00
|
|
|
snprintf(label_buf1, sizeof(label_buf1), "/%u",
|
|
|
|
nh_label->label[i]);
|
2019-08-12 18:35:58 +02:00
|
|
|
strlcat(label_buf, label_buf1, label_buf_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-01 17:50:31 +02:00
|
|
|
if (nh_label_type == ZEBRA_LSP_EVPN)
|
|
|
|
out_lse[num_labels] = label2vni(&nh_label->label[i]);
|
|
|
|
else
|
|
|
|
out_lse[num_labels] =
|
|
|
|
mpls_lse_encode(nh_label->label[i], 0, 0, 0);
|
2019-08-12 18:35:58 +02:00
|
|
|
num_labels++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_labels;
|
|
|
|
}
|
|
|
|
|
2022-11-21 17:23:18 +01:00
|
|
|
static bool _netlink_nexthop_encode_dvni_label(const struct nexthop *nexthop,
|
|
|
|
struct nlmsghdr *nlmsg,
|
|
|
|
mpls_lse_t *out_lse,
|
|
|
|
size_t buflen, char *label_buf)
|
|
|
|
{
|
|
|
|
struct in_addr ipv4;
|
|
|
|
|
|
|
|
if (!nl_attr_put64(nlmsg, buflen, LWTUNNEL_IP_ID,
|
|
|
|
htonll((uint64_t)out_lse[0])))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX) {
|
|
|
|
if (!nl_attr_put(nlmsg, buflen, LWTUNNEL_IP_DST,
|
|
|
|
&nexthop->gate.ipv4, 4))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} else if (nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) {
|
|
|
|
if (IS_MAPPED_IPV6(&nexthop->gate.ipv6)) {
|
|
|
|
ipv4_mapped_ipv6_to_ipv4(&nexthop->gate.ipv6, &ipv4);
|
|
|
|
if (!nl_attr_put(nlmsg, buflen, LWTUNNEL_IP_DST, &ipv4,
|
|
|
|
4))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (!nl_attr_put(nlmsg, buflen, LWTUNNEL_IP_DST,
|
|
|
|
&nexthop->gate.ipv6, 16))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
|
|
|
"%s: nexthop %pNHv %s must NEXTHOP_TYPE_IPV*_IFINDEX to be vxlan encapped",
|
|
|
|
__func__, nexthop, label_buf);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-01 17:50:31 +02:00
|
|
|
static bool _netlink_route_encode_label_info(const struct nexthop *nexthop,
|
2020-06-13 13:31:13 +02:00
|
|
|
struct nlmsghdr *nlmsg,
|
|
|
|
size_t buflen, struct rtmsg *rtmsg,
|
|
|
|
char *label_buf,
|
|
|
|
size_t label_buf_size)
|
2013-07-05 17:35:37 +02:00
|
|
|
{
|
2016-04-20 01:08:10 +02:00
|
|
|
mpls_lse_t out_lse[MPLS_MAX_LABELS];
|
2020-06-13 13:31:13 +02:00
|
|
|
int num_labels;
|
2021-04-01 17:50:31 +02:00
|
|
|
struct rtattr *nest;
|
|
|
|
struct mpls_label_stack *nh_label;
|
|
|
|
enum lsp_types_t nh_label_type;
|
|
|
|
|
|
|
|
nh_label = nexthop->nh_label;
|
|
|
|
nh_label_type = nexthop->nh_label_type;
|
2020-03-15 19:42:30 +01:00
|
|
|
|
2017-05-26 03:22:03 +02:00
|
|
|
/*
|
|
|
|
* label_buf is *only* currently used within debugging.
|
|
|
|
* As such when we assign it we are guarding it inside
|
|
|
|
* a debug test. If you want to change this make sure
|
|
|
|
* you fix this assumption
|
|
|
|
*/
|
2016-04-16 04:19:37 +02:00
|
|
|
label_buf[0] = '\0';
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2021-04-01 17:50:31 +02:00
|
|
|
num_labels = build_label_stack(nh_label, nh_label_type, out_lse,
|
|
|
|
label_buf, label_buf_size);
|
|
|
|
|
|
|
|
if (num_labels && nh_label_type == ZEBRA_LSP_EVPN) {
|
|
|
|
if (!nl_attr_put16(nlmsg, buflen, RTA_ENCAP_TYPE,
|
|
|
|
LWTUNNEL_ENCAP_IP))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
nest = nl_attr_nest(nlmsg, buflen, RTA_ENCAP);
|
|
|
|
if (!nest)
|
|
|
|
return false;
|
|
|
|
|
2022-11-21 17:23:18 +01:00
|
|
|
if (_netlink_nexthop_encode_dvni_label(nexthop, nlmsg, out_lse,
|
|
|
|
buflen,
|
|
|
|
label_buf) == false)
|
2021-04-01 17:50:31 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
nl_attr_nest_end(nlmsg, nest);
|
|
|
|
|
|
|
|
} else if (num_labels) {
|
2017-09-20 05:05:25 +02:00
|
|
|
/* Set the BoS bit */
|
|
|
|
out_lse[num_labels - 1] |= htonl(1 << MPLS_LS_S_SHIFT);
|
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
if (rtmsg->rtm_family == AF_MPLS) {
|
2020-06-13 13:31:13 +02:00
|
|
|
if (!nl_attr_put(nlmsg, buflen, RTA_NEWDST, &out_lse,
|
2020-06-10 11:44:31 +02:00
|
|
|
num_labels * sizeof(mpls_lse_t)))
|
|
|
|
return false;
|
|
|
|
} else {
|
2020-06-13 13:31:13 +02:00
|
|
|
if (!nl_attr_put16(nlmsg, buflen, RTA_ENCAP_TYPE,
|
|
|
|
LWTUNNEL_ENCAP_MPLS))
|
2020-06-10 11:44:31 +02:00
|
|
|
return false;
|
|
|
|
|
2020-06-13 13:31:13 +02:00
|
|
|
nest = nl_attr_nest(nlmsg, buflen, RTA_ENCAP);
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!nest)
|
|
|
|
return false;
|
|
|
|
|
2020-06-13 13:31:13 +02:00
|
|
|
if (!nl_attr_put(nlmsg, buflen, MPLS_IPTUNNEL_DST,
|
2020-06-10 11:44:31 +02:00
|
|
|
&out_lse,
|
|
|
|
num_labels * sizeof(mpls_lse_t)))
|
|
|
|
return false;
|
2020-06-08 23:37:26 +02:00
|
|
|
nl_attr_nest_end(nlmsg, nest);
|
2017-05-26 03:22:03 +02:00
|
|
|
}
|
2015-09-16 08:48:00 +02:00
|
|
|
}
|
2013-07-05 17:35:37 +02:00
|
|
|
|
2020-06-13 13:31:13 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool _netlink_route_encode_nexthop_src(const struct nexthop *nexthop,
|
|
|
|
int family,
|
|
|
|
struct nlmsghdr *nlmsg,
|
|
|
|
size_t buflen, int bytelen)
|
|
|
|
{
|
|
|
|
if (family == AF_INET) {
|
|
|
|
if (nexthop->rmap_src.ipv4.s_addr != INADDR_ANY) {
|
|
|
|
if (!nl_attr_put(nlmsg, buflen, RTA_PREFSRC,
|
|
|
|
&nexthop->rmap_src.ipv4, bytelen))
|
|
|
|
return false;
|
|
|
|
} else if (nexthop->src.ipv4.s_addr != INADDR_ANY) {
|
|
|
|
if (!nl_attr_put(nlmsg, buflen, RTA_PREFSRC,
|
|
|
|
&nexthop->src.ipv4, bytelen))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (family == AF_INET6) {
|
|
|
|
if (!IN6_IS_ADDR_UNSPECIFIED(&nexthop->rmap_src.ipv6)) {
|
|
|
|
if (!nl_attr_put(nlmsg, buflen, RTA_PREFSRC,
|
|
|
|
&nexthop->rmap_src.ipv6, bytelen))
|
|
|
|
return false;
|
|
|
|
} else if (!IN6_IS_ADDR_UNSPECIFIED(&nexthop->src.ipv6)) {
|
|
|
|
if (!nl_attr_put(nlmsg, buflen, RTA_PREFSRC,
|
|
|
|
&nexthop->src.ipv6, bytelen))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-03-22 14:58:20 +01:00
|
|
|
static ssize_t fill_seg6ipt_encap(char *buffer, size_t buflen,
|
2023-07-26 17:56:32 +02:00
|
|
|
struct seg6_seg_stack *segs)
|
2020-12-17 15:43:01 +01:00
|
|
|
{
|
|
|
|
struct seg6_iptunnel_encap *ipt;
|
|
|
|
struct ipv6_sr_hdr *srh;
|
2023-07-26 17:56:32 +02:00
|
|
|
size_t srhlen;
|
|
|
|
int i;
|
2021-02-24 11:47:05 +01:00
|
|
|
|
2023-07-26 17:56:32 +02:00
|
|
|
if (segs->num_segs > SRV6_MAX_SEGS) {
|
|
|
|
/* Exceeding maximum supported SIDs */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
srhlen = SRH_BASE_HEADER_LENGTH + SRH_SEGMENT_LENGTH * segs->num_segs;
|
|
|
|
|
|
|
|
if (buflen < (sizeof(struct seg6_iptunnel_encap) + srhlen))
|
2021-03-22 14:58:20 +01:00
|
|
|
return -1;
|
|
|
|
|
2020-12-17 15:43:01 +01:00
|
|
|
memset(buffer, 0, buflen);
|
|
|
|
|
|
|
|
ipt = (struct seg6_iptunnel_encap *)buffer;
|
|
|
|
ipt->mode = SEG6_IPTUN_MODE_ENCAP;
|
2023-07-26 17:56:32 +02:00
|
|
|
|
|
|
|
srh = (struct ipv6_sr_hdr *)&ipt->srh;
|
2020-12-17 15:43:01 +01:00
|
|
|
srh->hdrlen = (srhlen >> 3) - 1;
|
|
|
|
srh->type = 4;
|
2023-07-26 17:56:32 +02:00
|
|
|
srh->segments_left = segs->num_segs - 1;
|
|
|
|
srh->first_segment = segs->num_segs - 1;
|
|
|
|
|
|
|
|
for (i = 0; i < segs->num_segs; i++) {
|
|
|
|
memcpy(&srh->segments[i], &segs->seg[i],
|
|
|
|
sizeof(struct in6_addr));
|
|
|
|
}
|
2020-12-17 15:43:01 +01:00
|
|
|
|
2023-07-26 17:56:32 +02:00
|
|
|
return sizeof(struct seg6_iptunnel_encap) + srhlen;
|
2020-12-17 15:43:01 +01:00
|
|
|
}
|
|
|
|
|
2023-03-20 22:32:01 +01:00
|
|
|
static bool
|
|
|
|
_netlink_nexthop_encode_seg6local_flavor(const struct nexthop *nexthop,
|
|
|
|
struct nlmsghdr *nlmsg, size_t buflen)
|
|
|
|
{
|
|
|
|
struct rtattr *nest;
|
|
|
|
struct seg6local_flavors_info *flv;
|
|
|
|
|
|
|
|
assert(nexthop);
|
|
|
|
|
|
|
|
if (!nexthop->nh_srv6)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
flv = &nexthop->nh_srv6->seg6local_ctx.flv;
|
|
|
|
|
|
|
|
if (flv->flv_ops == ZEBRA_SEG6_LOCAL_FLV_OP_UNSPEC)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
nest = nl_attr_nest(nlmsg, buflen, SEG6_LOCAL_FLAVORS);
|
|
|
|
if (!nest)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!nl_attr_put32(nlmsg, buflen, SEG6_LOCAL_FLV_OPERATION,
|
|
|
|
flv->flv_ops))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (flv->lcblock_len)
|
|
|
|
if (!nl_attr_put8(nlmsg, buflen, SEG6_LOCAL_FLV_LCBLOCK_BITS,
|
|
|
|
flv->lcblock_len))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (flv->lcnode_func_len)
|
|
|
|
if (!nl_attr_put8(nlmsg, buflen, SEG6_LOCAL_FLV_LCNODE_FN_BITS,
|
|
|
|
flv->lcnode_func_len))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
nl_attr_nest_end(nlmsg, nest);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-13 13:31:13 +02:00
|
|
|
/* This function takes a nexthop as argument and adds
|
|
|
|
* the appropriate netlink attributes to an existing
|
|
|
|
* netlink message.
|
|
|
|
*
|
|
|
|
* @param routedesc: Human readable description of route type
|
|
|
|
* (direct/recursive, single-/multipath)
|
|
|
|
* @param bytelen: Length of addresses in bytes.
|
|
|
|
* @param nexthop: Nexthop information
|
|
|
|
* @param nlmsg: nlmsghdr structure to fill in.
|
|
|
|
* @param req_size: The size allocated for the message.
|
|
|
|
*
|
|
|
|
* The function returns true if the nexthop could be added
|
|
|
|
* to the message, otherwise false is returned.
|
|
|
|
*/
|
|
|
|
static bool _netlink_route_build_singlepath(const struct prefix *p,
|
|
|
|
const char *routedesc, int bytelen,
|
|
|
|
const struct nexthop *nexthop,
|
|
|
|
struct nlmsghdr *nlmsg,
|
|
|
|
struct rtmsg *rtmsg,
|
|
|
|
size_t req_size, int cmd)
|
|
|
|
{
|
|
|
|
|
|
|
|
char label_buf[256];
|
|
|
|
struct vrf *vrf;
|
|
|
|
char addrstr[INET6_ADDRSTRLEN];
|
|
|
|
|
|
|
|
assert(nexthop);
|
|
|
|
|
|
|
|
vrf = vrf_lookup_by_id(nexthop->vrf_id);
|
|
|
|
|
2021-04-01 17:50:31 +02:00
|
|
|
if (!_netlink_route_encode_label_info(nexthop, nlmsg, req_size, rtmsg,
|
|
|
|
label_buf, sizeof(label_buf)))
|
2020-06-13 13:31:13 +02:00
|
|
|
return false;
|
|
|
|
|
2021-04-05 15:29:12 +02:00
|
|
|
if (nexthop->nh_srv6) {
|
|
|
|
if (nexthop->nh_srv6->seg6local_action !=
|
|
|
|
ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) {
|
|
|
|
struct rtattr *nest;
|
|
|
|
const struct seg6local_context *ctx;
|
2021-03-22 11:36:17 +01:00
|
|
|
|
2021-04-05 15:29:12 +02:00
|
|
|
ctx = &nexthop->nh_srv6->seg6local_ctx;
|
|
|
|
if (!nl_attr_put16(nlmsg, req_size, RTA_ENCAP_TYPE,
|
|
|
|
LWTUNNEL_ENCAP_SEG6_LOCAL))
|
2021-03-22 11:36:17 +01:00
|
|
|
return false;
|
2021-04-05 15:29:12 +02:00
|
|
|
|
|
|
|
nest = nl_attr_nest(nlmsg, req_size, RTA_ENCAP);
|
|
|
|
if (!nest)
|
2021-03-22 11:36:17 +01:00
|
|
|
return false;
|
2021-04-05 15:29:12 +02:00
|
|
|
|
|
|
|
switch (nexthop->nh_srv6->seg6local_action) {
|
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_END:
|
|
|
|
if (!nl_attr_put32(nlmsg, req_size,
|
|
|
|
SEG6_LOCAL_ACTION,
|
|
|
|
SEG6_LOCAL_ACTION_END))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_END_X:
|
|
|
|
if (!nl_attr_put32(nlmsg, req_size,
|
|
|
|
SEG6_LOCAL_ACTION,
|
|
|
|
SEG6_LOCAL_ACTION_END_X))
|
|
|
|
return false;
|
|
|
|
if (!nl_attr_put(nlmsg, req_size,
|
|
|
|
SEG6_LOCAL_NH6, &ctx->nh6,
|
|
|
|
sizeof(struct in6_addr)))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_END_T:
|
|
|
|
if (!nl_attr_put32(nlmsg, req_size,
|
|
|
|
SEG6_LOCAL_ACTION,
|
|
|
|
SEG6_LOCAL_ACTION_END_T))
|
|
|
|
return false;
|
|
|
|
if (!nl_attr_put32(nlmsg, req_size,
|
|
|
|
SEG6_LOCAL_TABLE,
|
|
|
|
ctx->table))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_END_DX4:
|
|
|
|
if (!nl_attr_put32(nlmsg, req_size,
|
|
|
|
SEG6_LOCAL_ACTION,
|
|
|
|
SEG6_LOCAL_ACTION_END_DX4))
|
|
|
|
return false;
|
|
|
|
if (!nl_attr_put(nlmsg, req_size,
|
|
|
|
SEG6_LOCAL_NH4, &ctx->nh4,
|
|
|
|
sizeof(struct in_addr)))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_END_DT6:
|
|
|
|
if (!nl_attr_put32(nlmsg, req_size,
|
|
|
|
SEG6_LOCAL_ACTION,
|
|
|
|
SEG6_LOCAL_ACTION_END_DT6))
|
|
|
|
return false;
|
|
|
|
if (!nl_attr_put32(nlmsg, req_size,
|
|
|
|
SEG6_LOCAL_TABLE,
|
|
|
|
ctx->table))
|
|
|
|
return false;
|
|
|
|
break;
|
2021-11-22 14:50:48 +01:00
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_END_DT4:
|
|
|
|
if (!nl_attr_put32(nlmsg, req_size,
|
|
|
|
SEG6_LOCAL_ACTION,
|
|
|
|
SEG6_LOCAL_ACTION_END_DT4))
|
|
|
|
return false;
|
|
|
|
if (!nl_attr_put32(nlmsg, req_size,
|
|
|
|
SEG6_LOCAL_VRFTABLE,
|
|
|
|
ctx->table))
|
|
|
|
return false;
|
|
|
|
break;
|
2022-07-23 01:32:04 +02:00
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_END_DT46:
|
|
|
|
if (!nl_attr_put32(nlmsg, req_size,
|
|
|
|
SEG6_LOCAL_ACTION,
|
|
|
|
SEG6_LOCAL_ACTION_END_DT46))
|
|
|
|
return false;
|
|
|
|
if (!nl_attr_put32(nlmsg, req_size,
|
|
|
|
SEG6_LOCAL_VRFTABLE,
|
|
|
|
ctx->table))
|
|
|
|
return false;
|
|
|
|
break;
|
2023-01-30 16:05:58 +01:00
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_END_DX2:
|
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_END_DX6:
|
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_END_B6:
|
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_END_B6_ENCAP:
|
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_END_BM:
|
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_END_S:
|
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_END_AS:
|
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_END_AM:
|
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_END_BPF:
|
|
|
|
case ZEBRA_SEG6_LOCAL_ACTION_UNSPEC:
|
2021-04-05 15:29:12 +02:00
|
|
|
zlog_err("%s: unsupport seg6local behaviour action=%u",
|
|
|
|
__func__,
|
|
|
|
nexthop->nh_srv6->seg6local_action);
|
2021-04-23 13:27:41 +02:00
|
|
|
return false;
|
2021-04-05 15:29:12 +02:00
|
|
|
}
|
2023-03-20 22:32:01 +01:00
|
|
|
|
|
|
|
if (!_netlink_nexthop_encode_seg6local_flavor(
|
|
|
|
nexthop, nlmsg, req_size))
|
|
|
|
return false;
|
|
|
|
|
2021-04-05 15:29:12 +02:00
|
|
|
nl_attr_nest_end(nlmsg, nest);
|
|
|
|
}
|
|
|
|
|
2023-07-26 17:56:32 +02:00
|
|
|
if (nexthop->nh_srv6->seg6_segs &&
|
|
|
|
nexthop->nh_srv6->seg6_segs->num_segs &&
|
|
|
|
!sid_zero(nexthop->nh_srv6->seg6_segs)) {
|
2021-04-05 15:29:12 +02:00
|
|
|
char tun_buf[4096];
|
|
|
|
ssize_t tun_len;
|
|
|
|
struct rtattr *nest;
|
|
|
|
|
|
|
|
if (!nl_attr_put16(nlmsg, req_size, RTA_ENCAP_TYPE,
|
|
|
|
LWTUNNEL_ENCAP_SEG6))
|
2021-03-22 11:36:17 +01:00
|
|
|
return false;
|
2021-04-05 15:29:12 +02:00
|
|
|
nest = nl_attr_nest(nlmsg, req_size, RTA_ENCAP);
|
|
|
|
if (!nest)
|
2021-03-22 11:36:17 +01:00
|
|
|
return false;
|
2023-07-26 17:56:32 +02:00
|
|
|
tun_len =
|
|
|
|
fill_seg6ipt_encap(tun_buf, sizeof(tun_buf),
|
|
|
|
nexthop->nh_srv6->seg6_segs);
|
2021-04-05 15:29:12 +02:00
|
|
|
if (tun_len < 0)
|
2021-03-22 11:36:17 +01:00
|
|
|
return false;
|
2021-04-05 15:29:12 +02:00
|
|
|
if (!nl_attr_put(nlmsg, req_size, SEG6_IPTUNNEL_SRH,
|
|
|
|
tun_buf, tun_len))
|
2021-03-22 11:36:17 +01:00
|
|
|
return false;
|
2021-04-05 15:29:12 +02:00
|
|
|
nl_attr_nest_end(nlmsg, nest);
|
2020-12-06 00:01:39 +01:00
|
|
|
}
|
2020-12-17 15:43:01 +01:00
|
|
|
}
|
|
|
|
|
2013-07-05 17:35:37 +02:00
|
|
|
if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK))
|
2016-04-16 04:19:37 +02:00
|
|
|
rtmsg->rtm_flags |= RTNH_F_ONLINK;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-05-05 21:05:30 +02:00
|
|
|
if (is_route_v4_over_v6(rtmsg->rtm_family, nexthop->type)) {
|
2016-04-16 04:19:37 +02:00
|
|
|
rtmsg->rtm_flags |= RTNH_F_ONLINK;
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!nl_attr_put(nlmsg, req_size, RTA_GATEWAY, &ipv4_ll, 4))
|
|
|
|
return false;
|
|
|
|
if (!nl_attr_put32(nlmsg, req_size, RTA_OIF, nexthop->ifindex))
|
|
|
|
return false;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-06-13 13:31:13 +02:00
|
|
|
if (cmd == RTM_NEWROUTE) {
|
|
|
|
if (!_netlink_route_encode_nexthop_src(
|
|
|
|
nexthop, AF_INET, nlmsg, req_size, bytelen))
|
2020-06-10 11:44:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-30 00:48:11 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2019-11-29 22:15:02 +01:00
|
|
|
zlog_debug("%s: 5549 (%s): %pFX nexthop via %s %s if %u vrf %s(%u)",
|
|
|
|
__func__, routedesc, p, ipv4_ll_buf,
|
|
|
|
label_buf, nexthop->ifindex,
|
|
|
|
VRF_LOGNAME(vrf), nexthop->vrf_id);
|
2020-06-10 11:44:31 +02:00
|
|
|
return true;
|
2015-09-16 08:48:00 +02:00
|
|
|
}
|
|
|
|
|
2013-07-05 17:35:37 +02:00
|
|
|
if (nexthop->type == NEXTHOP_TYPE_IPV4
|
|
|
|
|| nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX) {
|
|
|
|
/* Send deletes to the kernel without specifying the next-hop */
|
2020-06-10 11:44:31 +02:00
|
|
|
if (cmd != RTM_DELROUTE) {
|
|
|
|
if (!_netlink_route_add_gateway_info(
|
|
|
|
rtmsg->rtm_family, AF_INET, nlmsg, req_size,
|
|
|
|
bytelen, nexthop))
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-09-16 08:48:00 +02:00
|
|
|
if (cmd == RTM_NEWROUTE) {
|
2020-06-13 13:31:13 +02:00
|
|
|
if (!_netlink_route_encode_nexthop_src(
|
|
|
|
nexthop, AF_INET, nlmsg, req_size, bytelen))
|
|
|
|
return false;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 22:15:02 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL) {
|
|
|
|
inet_ntop(AF_INET, &nexthop->gate.ipv4, addrstr,
|
|
|
|
sizeof(addrstr));
|
|
|
|
zlog_debug("%s: (%s): %pFX nexthop via %s %s if %u vrf %s(%u)",
|
|
|
|
__func__, routedesc, p, addrstr, label_buf,
|
|
|
|
nexthop->ifindex, VRF_LOGNAME(vrf),
|
|
|
|
nexthop->vrf_id);
|
|
|
|
}
|
2015-09-16 08:48:00 +02:00
|
|
|
}
|
2013-07-05 17:35:37 +02:00
|
|
|
|
|
|
|
if (nexthop->type == NEXTHOP_TYPE_IPV6
|
|
|
|
|| nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) {
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!_netlink_route_add_gateway_info(rtmsg->rtm_family,
|
|
|
|
AF_INET6, nlmsg, req_size,
|
|
|
|
bytelen, nexthop))
|
|
|
|
return false;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2013-07-05 17:35:37 +02:00
|
|
|
if (cmd == RTM_NEWROUTE) {
|
2020-06-13 13:31:13 +02:00
|
|
|
if (!_netlink_route_encode_nexthop_src(
|
|
|
|
nexthop, AF_INET6, nlmsg, req_size,
|
|
|
|
bytelen))
|
|
|
|
return false;
|
2013-07-05 17:35:37 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 22:15:02 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL) {
|
|
|
|
inet_ntop(AF_INET6, &nexthop->gate.ipv6, addrstr,
|
|
|
|
sizeof(addrstr));
|
|
|
|
zlog_debug("%s: (%s): %pFX nexthop via %s %s if %u vrf %s(%u)",
|
|
|
|
__func__, routedesc, p, addrstr, label_buf,
|
|
|
|
nexthop->ifindex, VRF_LOGNAME(vrf),
|
|
|
|
nexthop->vrf_id);
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2018-01-11 17:47:04 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We have the ifindex so we should always send it
|
|
|
|
* This is especially useful if we are doing route
|
|
|
|
* leaking.
|
|
|
|
*/
|
2020-06-10 11:44:31 +02:00
|
|
|
if (nexthop->type != NEXTHOP_TYPE_BLACKHOLE) {
|
|
|
|
if (!nl_attr_put32(nlmsg, req_size, RTA_OIF, nexthop->ifindex))
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-01-30 02:17:36 +01:00
|
|
|
if (nexthop->type == NEXTHOP_TYPE_IFINDEX) {
|
2015-09-16 08:48:00 +02:00
|
|
|
if (cmd == RTM_NEWROUTE) {
|
2020-06-13 13:31:13 +02:00
|
|
|
if (!_netlink_route_encode_nexthop_src(
|
|
|
|
nexthop, AF_INET, nlmsg, req_size, bytelen))
|
|
|
|
return false;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2013-07-05 17:35:37 +02:00
|
|
|
|
2015-09-16 08:48:00 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2019-11-29 22:15:02 +01:00
|
|
|
zlog_debug("%s: (%s): %pFX nexthop via if %u vrf %s(%u)",
|
|
|
|
__func__, routedesc, p, nexthop->ifindex,
|
|
|
|
VRF_LOGNAME(vrf), nexthop->vrf_id);
|
2015-09-16 08:48:00 +02:00
|
|
|
}
|
2020-06-10 11:44:31 +02:00
|
|
|
|
|
|
|
return true;
|
2013-07-05 17:35:37 +02:00
|
|
|
}
|
|
|
|
|
2022-06-21 21:13:08 +02:00
|
|
|
/* This function appends tag value as rtnl flow attribute
|
|
|
|
* to the given netlink msg only if value is less than 256.
|
|
|
|
* Used only if SUPPORT_REALMS enabled.
|
|
|
|
*
|
|
|
|
* @param nlmsg: nlmsghdr structure to fill in.
|
|
|
|
* @param maxlen: The size allocated for the message.
|
|
|
|
* @param tag: The route tag.
|
|
|
|
*
|
|
|
|
* The function returns true if the flow attribute could
|
|
|
|
* be added to the message, otherwise false is returned.
|
|
|
|
*/
|
|
|
|
static inline bool _netlink_set_tag(struct nlmsghdr *n, unsigned int maxlen,
|
|
|
|
route_tag_t tag)
|
|
|
|
{
|
|
|
|
if (tag > 0 && tag <= 255) {
|
|
|
|
if (!nl_attr_put32(n, maxlen, RTA_FLOW, tag))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-05 17:35:37 +02:00
|
|
|
/* This function takes a nexthop as argument and
|
2020-06-08 23:37:26 +02:00
|
|
|
* appends to the given netlink msg. If the nexthop
|
2013-07-05 17:35:37 +02:00
|
|
|
* defines a preferred source, the src parameter
|
|
|
|
* will be modified to point to that src, otherwise
|
|
|
|
* it will be kept unmodified.
|
|
|
|
*
|
|
|
|
* @param routedesc: Human readable description of route type
|
|
|
|
* (direct/recursive, single-/multipath)
|
|
|
|
* @param bytelen: Length of addresses in bytes.
|
|
|
|
* @param nexthop: Nexthop information
|
2020-06-08 23:37:26 +02:00
|
|
|
* @param nlmsg: nlmsghdr structure to fill in.
|
|
|
|
* @param req_size: The size allocated for the message.
|
2013-07-05 17:35:37 +02:00
|
|
|
* @param src: pointer pointing to a location where
|
|
|
|
* the prefsrc should be stored.
|
2020-06-10 11:44:31 +02:00
|
|
|
*
|
|
|
|
* The function returns true if the nexthop could be added
|
|
|
|
* to the message, otherwise false is returned.
|
2013-07-05 17:35:37 +02:00
|
|
|
*/
|
2022-06-21 21:13:08 +02:00
|
|
|
static bool _netlink_route_build_multipath(
|
|
|
|
const struct prefix *p, const char *routedesc, int bytelen,
|
|
|
|
const struct nexthop *nexthop, struct nlmsghdr *nlmsg, size_t req_size,
|
|
|
|
struct rtmsg *rtmsg, const union g_addr **src, route_tag_t tag)
|
2013-07-05 17:35:37 +02:00
|
|
|
{
|
2017-09-20 05:02:01 +02:00
|
|
|
char label_buf[256];
|
2020-03-15 19:42:30 +01:00
|
|
|
struct vrf *vrf;
|
2020-06-08 23:37:26 +02:00
|
|
|
struct rtnexthop *rtnh;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-06-08 23:37:26 +02:00
|
|
|
rtnh = nl_attr_rtnh(nlmsg, req_size);
|
2020-06-10 11:44:31 +02:00
|
|
|
if (rtnh == NULL)
|
|
|
|
return false;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-08-12 18:35:58 +02:00
|
|
|
assert(nexthop);
|
|
|
|
|
2020-03-15 19:42:30 +01:00
|
|
|
vrf = vrf_lookup_by_id(nexthop->vrf_id);
|
|
|
|
|
2021-04-01 17:50:31 +02:00
|
|
|
if (!_netlink_route_encode_label_info(nexthop, nlmsg, req_size, rtmsg,
|
|
|
|
label_buf, sizeof(label_buf)))
|
2020-06-13 13:31:13 +02:00
|
|
|
return false;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2016-04-20 01:08:10 +02:00
|
|
|
if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK))
|
2017-05-30 00:48:11 +02:00
|
|
|
rtnh->rtnh_flags |= RTNH_F_ONLINK;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-05-05 21:05:30 +02:00
|
|
|
if (is_route_v4_over_v6(rtmsg->rtm_family, nexthop->type)) {
|
2016-04-20 01:08:10 +02:00
|
|
|
rtnh->rtnh_flags |= RTNH_F_ONLINK;
|
2020-06-13 13:31:13 +02:00
|
|
|
if (!nl_attr_put(nlmsg, req_size, RTA_GATEWAY, &ipv4_ll, 4))
|
2020-06-10 11:44:31 +02:00
|
|
|
return false;
|
2016-04-20 01:08:10 +02:00
|
|
|
rtnh->rtnh_ifindex = nexthop->ifindex;
|
2020-03-18 03:25:13 +01:00
|
|
|
if (nexthop->weight)
|
|
|
|
rtnh->rtnh_hops = nexthop->weight - 1;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-02-06 07:49:02 +01:00
|
|
|
if (nexthop->rmap_src.ipv4.s_addr != INADDR_ANY)
|
2015-05-20 02:47:24 +02:00
|
|
|
*src = &nexthop->rmap_src;
|
2020-02-06 07:49:02 +01:00
|
|
|
else if (nexthop->src.ipv4.s_addr != INADDR_ANY)
|
2015-05-20 02:47:24 +02:00
|
|
|
*src = &nexthop->src;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-26 03:22:03 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2013-07-05 17:35:39 +02:00
|
|
|
zlog_debug(
|
2019-11-29 22:15:02 +01:00
|
|
|
"%s: 5549 (%s): %pFX nexthop via %s %s if %u vrf %s(%u)",
|
|
|
|
__func__, routedesc, p, ipv4_ll_buf, label_buf,
|
2020-03-15 19:42:30 +01:00
|
|
|
nexthop->ifindex, VRF_LOGNAME(vrf),
|
|
|
|
nexthop->vrf_id);
|
2020-06-08 23:37:26 +02:00
|
|
|
nl_attr_rtnh_end(nlmsg, rtnh);
|
2020-06-10 11:44:31 +02:00
|
|
|
return true;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
2017-05-30 00:48:11 +02:00
|
|
|
if (nexthop->type == NEXTHOP_TYPE_IPV4
|
|
|
|
|| nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX) {
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!_netlink_route_add_gateway_info(rtmsg->rtm_family, AF_INET,
|
|
|
|
nlmsg, req_size, bytelen,
|
|
|
|
nexthop))
|
|
|
|
return false;
|
|
|
|
|
2020-02-06 07:49:02 +01:00
|
|
|
if (nexthop->rmap_src.ipv4.s_addr != INADDR_ANY)
|
2017-05-30 00:48:11 +02:00
|
|
|
*src = &nexthop->rmap_src;
|
2020-02-06 07:49:02 +01:00
|
|
|
else if (nexthop->src.ipv4.s_addr != INADDR_ANY)
|
2017-05-30 00:48:11 +02:00
|
|
|
*src = &nexthop->src;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-02-10 22:40:43 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("%s: (%s): %pFX nexthop via %pI4 %s if %u vrf %s(%u)",
|
|
|
|
__func__, routedesc, p, &nexthop->gate.ipv4,
|
|
|
|
label_buf, nexthop->ifindex,
|
|
|
|
VRF_LOGNAME(vrf), nexthop->vrf_id);
|
2017-05-30 00:48:11 +02:00
|
|
|
}
|
2013-07-05 17:35:37 +02:00
|
|
|
if (nexthop->type == NEXTHOP_TYPE_IPV6
|
|
|
|
|| nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) {
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!_netlink_route_add_gateway_info(rtmsg->rtm_family,
|
|
|
|
AF_INET6, nlmsg, req_size,
|
|
|
|
bytelen, nexthop))
|
|
|
|
return false;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2015-09-16 08:48:00 +02:00
|
|
|
if (!IN6_IS_ADDR_UNSPECIFIED(&nexthop->rmap_src.ipv6))
|
|
|
|
*src = &nexthop->rmap_src;
|
|
|
|
else if (!IN6_IS_ADDR_UNSPECIFIED(&nexthop->src.ipv6))
|
|
|
|
*src = &nexthop->src;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-02-10 22:40:43 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("%s: (%s): %pFX nexthop via %pI6 %s if %u vrf %s(%u)",
|
|
|
|
__func__, routedesc, p, &nexthop->gate.ipv6,
|
|
|
|
label_buf, nexthop->ifindex,
|
|
|
|
VRF_LOGNAME(vrf), nexthop->vrf_id);
|
2013-07-05 17:35:37 +02:00
|
|
|
}
|
2018-01-11 17:47:04 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We have figured out the ifindex so we should always send it
|
|
|
|
* This is especially useful if we are doing route
|
|
|
|
* leaking.
|
|
|
|
*/
|
|
|
|
if (nexthop->type != NEXTHOP_TYPE_BLACKHOLE)
|
|
|
|
rtnh->rtnh_ifindex = nexthop->ifindex;
|
|
|
|
|
2013-07-05 17:35:37 +02:00
|
|
|
/* ifindex */
|
2019-01-30 02:17:36 +01:00
|
|
|
if (nexthop->type == NEXTHOP_TYPE_IFINDEX) {
|
2020-02-06 07:49:02 +01:00
|
|
|
if (nexthop->rmap_src.ipv4.s_addr != INADDR_ANY)
|
2015-05-20 02:47:24 +02:00
|
|
|
*src = &nexthop->rmap_src;
|
2020-02-06 07:49:02 +01:00
|
|
|
else if (nexthop->src.ipv4.s_addr != INADDR_ANY)
|
2013-07-05 17:35:37 +02:00
|
|
|
*src = &nexthop->src;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2013-07-05 17:35:37 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2019-11-29 22:15:02 +01:00
|
|
|
zlog_debug("%s: (%s): %pFX nexthop via if %u vrf %s(%u)",
|
|
|
|
__func__, routedesc, p, nexthop->ifindex,
|
|
|
|
VRF_LOGNAME(vrf), nexthop->vrf_id);
|
2013-07-05 17:35:37 +02:00
|
|
|
}
|
2019-12-06 14:58:47 +01:00
|
|
|
|
|
|
|
if (nexthop->weight)
|
|
|
|
rtnh->rtnh_hops = nexthop->weight - 1;
|
2020-06-10 11:44:31 +02:00
|
|
|
|
2022-06-21 21:13:08 +02:00
|
|
|
if (!_netlink_set_tag(nlmsg, req_size, tag))
|
|
|
|
return false;
|
|
|
|
|
2020-06-08 23:37:26 +02:00
|
|
|
nl_attr_rtnh_end(nlmsg, rtnh);
|
2020-06-10 11:44:31 +02:00
|
|
|
return true;
|
2013-07-05 17:35:37 +02:00
|
|
|
}
|
|
|
|
|
2021-08-20 15:08:25 +02:00
|
|
|
static inline bool
|
|
|
|
_netlink_mpls_build_singlepath(const struct prefix *p, const char *routedesc,
|
|
|
|
const struct zebra_nhlfe *nhlfe,
|
|
|
|
struct nlmsghdr *nlmsg, struct rtmsg *rtmsg,
|
|
|
|
size_t req_size, int cmd)
|
2016-04-16 04:19:37 +02:00
|
|
|
{
|
|
|
|
int bytelen;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t family;
|
2016-04-16 04:19:37 +02:00
|
|
|
|
|
|
|
family = NHLFE_FAMILY(nhlfe);
|
|
|
|
bytelen = (family == AF_INET ? 4 : 16);
|
2020-06-10 11:44:31 +02:00
|
|
|
return _netlink_route_build_singlepath(p, routedesc, bytelen,
|
|
|
|
nhlfe->nexthop, nlmsg, rtmsg,
|
|
|
|
req_size, cmd);
|
2016-04-16 04:19:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
static inline bool
|
2020-03-18 15:31:34 +01:00
|
|
|
_netlink_mpls_build_multipath(const struct prefix *p, const char *routedesc,
|
2021-08-20 15:08:25 +02:00
|
|
|
const struct zebra_nhlfe *nhlfe,
|
2020-06-08 23:37:26 +02:00
|
|
|
struct nlmsghdr *nlmsg, size_t req_size,
|
|
|
|
struct rtmsg *rtmsg, const union g_addr **src)
|
2016-04-16 04:19:37 +02:00
|
|
|
{
|
|
|
|
int bytelen;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t family;
|
2016-04-16 04:19:37 +02:00
|
|
|
|
|
|
|
family = NHLFE_FAMILY(nhlfe);
|
|
|
|
bytelen = (family == AF_INET ? 4 : 16);
|
2020-06-10 11:44:31 +02:00
|
|
|
return _netlink_route_build_multipath(p, routedesc, bytelen,
|
|
|
|
nhlfe->nexthop, nlmsg, req_size,
|
2022-06-21 21:13:08 +02:00
|
|
|
rtmsg, src, 0);
|
2016-04-16 04:19:37 +02:00
|
|
|
}
|
|
|
|
|
2018-03-27 21:13:34 +02:00
|
|
|
static void _netlink_mpls_debug(int cmd, uint32_t label, const char *routedesc)
|
2016-04-16 04:19:37 +02:00
|
|
|
{
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2020-06-10 11:44:31 +02:00
|
|
|
zlog_debug("netlink_mpls_multipath_msg_encode() (%s): %s %u/20",
|
|
|
|
routedesc, nl_msg_type_to_str(cmd), label);
|
2013-07-05 17:35:37 +02:00
|
|
|
}
|
|
|
|
|
2019-12-13 18:09:11 +01:00
|
|
|
static int netlink_neigh_update(int cmd, int ifindex, void *addr, char *lla,
|
|
|
|
int llalen, ns_id_t ns_id, uint8_t family,
|
|
|
|
bool permanent, uint8_t protocol)
|
2015-06-11 18:19:59 +02:00
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct ndmsg ndm;
|
|
|
|
char buf[256];
|
|
|
|
} req;
|
|
|
|
|
2017-12-19 12:23:32 +01:00
|
|
|
struct zebra_ns *zns = zebra_ns_lookup(ns_id);
|
2014-07-03 12:23:09 +02:00
|
|
|
|
2018-05-18 00:46:14 +02:00
|
|
|
memset(&req, 0, sizeof(req));
|
2015-06-11 18:19:59 +02:00
|
|
|
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
|
|
|
|
req.n.nlmsg_flags = NLM_F_CREATE | NLM_F_REQUEST;
|
|
|
|
req.n.nlmsg_type = cmd; // RTM_NEWNEIGH or RTM_DELNEIGH
|
2017-06-12 19:38:51 +02:00
|
|
|
req.n.nlmsg_pid = zns->netlink_cmd.snl.nl_pid;
|
|
|
|
|
2019-12-13 18:09:11 +01:00
|
|
|
req.ndm.ndm_family = family;
|
2015-06-11 18:19:59 +02:00
|
|
|
req.ndm.ndm_ifindex = ifindex;
|
|
|
|
req.ndm.ndm_type = RTN_UNICAST;
|
2019-12-13 18:09:11 +01:00
|
|
|
if (cmd == RTM_NEWNEIGH) {
|
|
|
|
if (!permanent)
|
|
|
|
req.ndm.ndm_state = NUD_REACHABLE;
|
|
|
|
else
|
|
|
|
req.ndm.ndm_state = NUD_PERMANENT;
|
|
|
|
} else
|
|
|
|
req.ndm.ndm_state = NUD_FAILED;
|
2015-06-11 18:19:59 +02:00
|
|
|
|
2020-06-08 23:37:26 +02:00
|
|
|
nl_attr_put(&req.n, sizeof(req), NDA_PROTOCOL, &protocol,
|
|
|
|
sizeof(protocol));
|
2019-12-13 18:09:11 +01:00
|
|
|
req.ndm.ndm_type = RTN_UNICAST;
|
2021-02-25 15:06:23 +01:00
|
|
|
nl_attr_put(&req.n, sizeof(req), NDA_DST, addr,
|
|
|
|
family2addrsize(family));
|
2019-12-13 18:09:11 +01:00
|
|
|
if (lla)
|
|
|
|
nl_attr_put(&req.n, sizeof(req), NDA_LLADDR, lla, llalen);
|
2015-06-11 18:19:59 +02:00
|
|
|
|
2023-02-15 12:15:47 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL) {
|
|
|
|
char ip_str[INET6_ADDRSTRLEN + 8];
|
|
|
|
struct interface *ifp = if_lookup_by_index_per_ns(
|
|
|
|
zebra_ns_lookup(ns_id), ifindex);
|
|
|
|
if (ifp) {
|
|
|
|
if (family == AF_INET6)
|
|
|
|
snprintfrr(ip_str, sizeof(ip_str), "ipv6 %pI6",
|
|
|
|
(struct in6_addr *)addr);
|
|
|
|
else
|
|
|
|
snprintfrr(ip_str, sizeof(ip_str), "ipv4 %pI4",
|
|
|
|
(in_addr_t *)addr);
|
|
|
|
zlog_debug(
|
|
|
|
"%s: %s ifname %s ifindex %u addr %s mac %pEA vrf %s(%u)",
|
|
|
|
__func__, nl_msg_type_to_str(cmd), ifp->name,
|
|
|
|
ifindex, ip_str, (struct ethaddr *)lla,
|
|
|
|
vrf_id_to_name(ifp->vrf->vrf_id),
|
|
|
|
ifp->vrf->vrf_id);
|
|
|
|
}
|
|
|
|
}
|
2017-01-27 19:33:08 +01:00
|
|
|
return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
|
2021-10-05 02:26:38 +02:00
|
|
|
false);
|
2015-06-11 18:19:59 +02:00
|
|
|
}
|
|
|
|
|
2020-03-24 22:10:08 +01:00
|
|
|
static bool nexthop_set_src(const struct nexthop *nexthop, int family,
|
|
|
|
union g_addr *src)
|
|
|
|
{
|
|
|
|
if (family == AF_INET) {
|
|
|
|
if (nexthop->rmap_src.ipv4.s_addr != INADDR_ANY) {
|
|
|
|
src->ipv4 = nexthop->rmap_src.ipv4;
|
|
|
|
return true;
|
|
|
|
} else if (nexthop->src.ipv4.s_addr != INADDR_ANY) {
|
|
|
|
src->ipv4 = nexthop->src.ipv4;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (family == AF_INET6) {
|
|
|
|
if (!IN6_IS_ADDR_UNSPECIFIED(&nexthop->rmap_src.ipv6)) {
|
|
|
|
src->ipv6 = nexthop->rmap_src.ipv6;
|
|
|
|
return true;
|
|
|
|
} else if (!IN6_IS_ADDR_UNSPECIFIED(&nexthop->src.ipv6)) {
|
|
|
|
src->ipv6 = nexthop->src.ipv6;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
/*
|
|
|
|
* The function returns true if the attribute could be added
|
|
|
|
* to the message, otherwise false is returned.
|
|
|
|
*/
|
|
|
|
static int netlink_route_nexthop_encap(struct nlmsghdr *n, size_t nlen,
|
|
|
|
struct nexthop *nh)
|
2020-01-13 20:34:03 +01:00
|
|
|
{
|
|
|
|
struct rtattr *nest;
|
|
|
|
|
|
|
|
switch (nh->nh_encap_type) {
|
|
|
|
case NET_VXLAN:
|
2020-06-13 13:31:13 +02:00
|
|
|
if (!nl_attr_put16(n, nlen, RTA_ENCAP_TYPE, nh->nh_encap_type))
|
2020-06-10 11:44:31 +02:00
|
|
|
return false;
|
2020-01-13 20:34:03 +01:00
|
|
|
|
2020-06-08 23:37:26 +02:00
|
|
|
nest = nl_attr_nest(n, nlen, RTA_ENCAP);
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!nest)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!nl_attr_put32(n, nlen, 0 /* VXLAN_VNI */,
|
|
|
|
nh->nh_encap.vni))
|
|
|
|
return false;
|
2020-06-08 23:37:26 +02:00
|
|
|
nl_attr_nest_end(n, nest);
|
2020-01-13 20:34:03 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-06-10 11:44:31 +02:00
|
|
|
|
|
|
|
return true;
|
2020-01-13 20:34:03 +01:00
|
|
|
}
|
|
|
|
|
2018-05-23 18:20:43 +02:00
|
|
|
/*
|
|
|
|
* Routing table change via netlink interface, using a dataplane context object
|
2020-06-10 11:44:31 +02:00
|
|
|
*
|
|
|
|
* Returns -1 on failure, 0 when the msg doesn't fit entirely in the buffer
|
|
|
|
* otherwise the number of bytes written to buf.
|
2018-05-23 18:20:43 +02:00
|
|
|
*/
|
2023-07-26 22:30:07 +02:00
|
|
|
ssize_t netlink_route_multipath_msg_encode(int cmd, struct zebra_dplane_ctx *ctx,
|
2020-06-10 11:44:31 +02:00
|
|
|
uint8_t *data, size_t datalen,
|
2023-07-26 22:30:07 +02:00
|
|
|
bool fpm, bool force_nhg,
|
|
|
|
bool force_rr)
|
2018-05-23 18:20:43 +02:00
|
|
|
{
|
|
|
|
int bytelen;
|
|
|
|
struct nexthop *nexthop = NULL;
|
|
|
|
unsigned int nexthop_num;
|
|
|
|
const char *routedesc;
|
2020-03-24 22:10:08 +01:00
|
|
|
bool setsrc = false;
|
2018-05-23 18:20:43 +02:00
|
|
|
union g_addr src;
|
|
|
|
const struct prefix *p, *src_p;
|
|
|
|
uint32_t table_id;
|
2022-02-02 19:21:52 +01:00
|
|
|
struct nlsock *nl;
|
2022-06-21 21:13:08 +02:00
|
|
|
route_tag_t tag = 0;
|
2018-05-23 18:20:43 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct rtmsg r;
|
2019-11-29 19:19:47 +01:00
|
|
|
char buf[];
|
|
|
|
} *req = (void *)data;
|
2018-05-23 18:20:43 +02:00
|
|
|
|
|
|
|
p = dplane_ctx_get_dest(ctx);
|
|
|
|
src_p = dplane_ctx_get_src(ctx);
|
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
if (datalen < sizeof(*req))
|
|
|
|
return 0;
|
|
|
|
|
2022-02-02 19:21:52 +01:00
|
|
|
nl = kernel_netlink_nlsock_lookup(dplane_ctx_get_ns_sock(ctx));
|
|
|
|
|
2019-11-29 19:19:47 +01:00
|
|
|
memset(req, 0, sizeof(*req));
|
2018-05-23 18:20:43 +02:00
|
|
|
|
2019-12-02 17:03:35 +01:00
|
|
|
bytelen = (p->family == AF_INET ? 4 : 16);
|
2018-05-23 18:20:43 +02:00
|
|
|
|
2019-11-29 19:19:47 +01:00
|
|
|
req->n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
|
|
|
|
req->n.nlmsg_flags = NLM_F_CREATE | NLM_F_REQUEST;
|
2018-05-23 18:20:43 +02:00
|
|
|
|
2023-07-26 22:30:07 +02:00
|
|
|
if (((cmd == RTM_NEWROUTE) &&
|
|
|
|
((p->family == AF_INET) || v6_rr_semantics)) ||
|
|
|
|
force_rr)
|
2019-11-29 19:19:47 +01:00
|
|
|
req->n.nlmsg_flags |= NLM_F_REPLACE;
|
2018-05-23 18:20:43 +02:00
|
|
|
|
2019-11-29 19:19:47 +01:00
|
|
|
req->n.nlmsg_type = cmd;
|
2018-05-23 18:20:43 +02:00
|
|
|
|
2022-02-02 19:21:52 +01:00
|
|
|
req->n.nlmsg_pid = nl->snl.nl_pid;
|
2018-05-23 18:20:43 +02:00
|
|
|
|
2019-12-02 17:03:35 +01:00
|
|
|
req->r.rtm_family = p->family;
|
2019-11-29 19:19:47 +01:00
|
|
|
req->r.rtm_dst_len = p->prefixlen;
|
|
|
|
req->r.rtm_src_len = src_p ? src_p->prefixlen : 0;
|
|
|
|
req->r.rtm_scope = RT_SCOPE_UNIVERSE;
|
2018-05-23 18:20:43 +02:00
|
|
|
|
2018-07-11 17:08:47 +02:00
|
|
|
if (cmd == RTM_DELROUTE)
|
2019-11-29 19:19:47 +01:00
|
|
|
req->r.rtm_protocol = zebra2proto(dplane_ctx_get_old_type(ctx));
|
2018-07-11 17:08:47 +02:00
|
|
|
else
|
2019-11-29 19:19:47 +01:00
|
|
|
req->r.rtm_protocol = zebra2proto(dplane_ctx_get_type(ctx));
|
2018-05-23 18:20:43 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* blackhole routes are not RTN_UNICAST, they are
|
|
|
|
* RTN_ BLACKHOLE|UNREACHABLE|PROHIBIT
|
|
|
|
* so setting this value as a RTN_UNICAST would
|
|
|
|
* cause the route lookup of just the prefix
|
|
|
|
* to fail. So no need to specify this for
|
|
|
|
* the RTM_DELROUTE case
|
|
|
|
*/
|
|
|
|
if (cmd != RTM_DELROUTE)
|
2019-11-29 19:19:47 +01:00
|
|
|
req->r.rtm_type = RTN_UNICAST;
|
2018-05-23 18:20:43 +02:00
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!nl_attr_put(&req->n, datalen, RTA_DST, &p->u.prefix, bytelen))
|
|
|
|
return 0;
|
|
|
|
if (src_p) {
|
|
|
|
if (!nl_attr_put(&req->n, datalen, RTA_SRC, &src_p->u.prefix,
|
|
|
|
bytelen))
|
|
|
|
return 0;
|
|
|
|
}
|
2018-05-23 18:20:43 +02:00
|
|
|
|
|
|
|
/* Metric. */
|
|
|
|
/* Hardcode the metric for all routes coming from zebra. Metric isn't
|
|
|
|
* used
|
|
|
|
* either by the kernel or by zebra. Its purely for calculating best
|
|
|
|
* path(s)
|
|
|
|
* by the routing protocol and for communicating with protocol peers.
|
|
|
|
*/
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!nl_attr_put32(&req->n, datalen, RTA_PRIORITY,
|
2023-01-05 20:27:28 +01:00
|
|
|
ROUTE_INSTALLATION_METRIC))
|
2020-06-10 11:44:31 +02:00
|
|
|
return 0;
|
2018-05-23 18:20:43 +02:00
|
|
|
|
|
|
|
#if defined(SUPPORT_REALMS)
|
2022-06-21 21:13:08 +02:00
|
|
|
if (cmd == RTM_DELROUTE)
|
|
|
|
tag = dplane_ctx_get_old_tag(ctx);
|
|
|
|
else
|
|
|
|
tag = dplane_ctx_get_tag(ctx);
|
2018-05-23 18:20:43 +02:00
|
|
|
#endif
|
2022-06-21 21:13:08 +02:00
|
|
|
|
2018-05-23 18:20:43 +02:00
|
|
|
/* Table corresponding to this route. */
|
|
|
|
table_id = dplane_ctx_get_table(ctx);
|
|
|
|
if (table_id < 256)
|
2019-11-29 19:19:47 +01:00
|
|
|
req->r.rtm_table = table_id;
|
2018-05-23 18:20:43 +02:00
|
|
|
else {
|
2019-11-29 19:19:47 +01:00
|
|
|
req->r.rtm_table = RT_TABLE_UNSPEC;
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!nl_attr_put32(&req->n, datalen, RTA_TABLE, table_id))
|
|
|
|
return 0;
|
2018-05-23 18:20:43 +02:00
|
|
|
}
|
|
|
|
|
2019-11-29 22:15:02 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
|
|
|
"%s: %s %pFX vrf %u(%u)", __func__,
|
|
|
|
nl_msg_type_to_str(cmd), p, dplane_ctx_get_vrf(ctx),
|
|
|
|
table_id);
|
2018-05-23 18:20:43 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we are not updating the route and we have received
|
|
|
|
* a route delete, then all we need to fill in is the
|
|
|
|
* prefix information to tell the kernel to schwack
|
|
|
|
* it.
|
|
|
|
*/
|
2022-06-21 21:13:08 +02:00
|
|
|
if (cmd == RTM_DELROUTE) {
|
|
|
|
if (!_netlink_set_tag(&req->n, datalen, tag))
|
|
|
|
return 0;
|
2020-06-10 11:44:31 +02:00
|
|
|
return NLMSG_ALIGN(req->n.nlmsg_len);
|
2022-06-21 21:13:08 +02:00
|
|
|
}
|
2018-05-23 18:20:43 +02:00
|
|
|
|
|
|
|
if (dplane_ctx_get_mtu(ctx) || dplane_ctx_get_nh_mtu(ctx)) {
|
2020-06-08 23:37:26 +02:00
|
|
|
struct rtattr *nest;
|
2018-05-23 18:20:43 +02:00
|
|
|
uint32_t mtu = dplane_ctx_get_mtu(ctx);
|
|
|
|
uint32_t nexthop_mtu = dplane_ctx_get_nh_mtu(ctx);
|
2018-07-11 17:08:47 +02:00
|
|
|
|
2018-05-23 18:20:43 +02:00
|
|
|
if (!mtu || (nexthop_mtu && nexthop_mtu < mtu))
|
|
|
|
mtu = nexthop_mtu;
|
2020-06-08 23:37:26 +02:00
|
|
|
|
|
|
|
nest = nl_attr_nest(&req->n, datalen, RTA_METRICS);
|
2020-06-10 11:44:31 +02:00
|
|
|
if (nest == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!nl_attr_put(&req->n, datalen, RTAX_MTU, &mtu, sizeof(mtu)))
|
|
|
|
return 0;
|
2020-06-08 23:37:26 +02:00
|
|
|
nl_attr_nest_end(&req->n, nest);
|
2018-05-23 18:20:43 +02:00
|
|
|
}
|
|
|
|
|
2021-02-25 16:28:51 +01:00
|
|
|
/*
|
|
|
|
* Always install blackhole routes without using nexthops, because of
|
|
|
|
* the following kernel problems:
|
|
|
|
* 1. Kernel nexthops don't suport unreachable/prohibit route types.
|
|
|
|
* 2. Blackhole kernel nexthops are deleted when loopback is down.
|
|
|
|
*/
|
|
|
|
nexthop = dplane_ctx_get_ng(ctx)->nexthop;
|
|
|
|
if (nexthop) {
|
|
|
|
if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
|
|
|
|
nexthop = nexthop->resolved;
|
|
|
|
|
|
|
|
if (nexthop->type == NEXTHOP_TYPE_BLACKHOLE) {
|
|
|
|
switch (nexthop->bh_type) {
|
|
|
|
case BLACKHOLE_ADMINPROHIB:
|
|
|
|
req->r.rtm_type = RTN_PROHIBIT;
|
|
|
|
break;
|
|
|
|
case BLACKHOLE_REJECT:
|
|
|
|
req->r.rtm_type = RTN_UNREACHABLE;
|
|
|
|
break;
|
2023-01-30 16:05:58 +01:00
|
|
|
case BLACKHOLE_UNSPEC:
|
|
|
|
case BLACKHOLE_NULL:
|
2021-02-25 16:28:51 +01:00
|
|
|
req->r.rtm_type = RTN_BLACKHOLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NLMSG_ALIGN(req->n.nlmsg_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-13 21:50:14 +02:00
|
|
|
if ((!fpm && kernel_nexthops_supported()
|
|
|
|
&& (!proto_nexthops_only()
|
|
|
|
|| is_proto_nhg(dplane_ctx_get_nhe_id(ctx), 0)))
|
|
|
|
|| (fpm && force_nhg)) {
|
2020-03-24 22:32:21 +01:00
|
|
|
/* Kernel supports nexthop objects */
|
2020-03-18 15:31:34 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2020-06-10 11:44:31 +02:00
|
|
|
zlog_debug("%s: %pFX nhg_id is %u", __func__, p,
|
|
|
|
dplane_ctx_get_nhe_id(ctx));
|
2019-11-29 19:19:47 +01:00
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!nl_attr_put32(&req->n, datalen, RTA_NH_ID,
|
|
|
|
dplane_ctx_get_nhe_id(ctx)))
|
|
|
|
return 0;
|
2020-03-24 22:32:21 +01:00
|
|
|
|
|
|
|
/* Have to determine src still */
|
|
|
|
for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx), nexthop)) {
|
|
|
|
if (setsrc)
|
|
|
|
break;
|
|
|
|
|
2019-11-29 19:19:47 +01:00
|
|
|
setsrc = nexthop_set_src(nexthop, p->family, &src);
|
2020-03-24 22:32:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (setsrc) {
|
2020-06-10 11:44:31 +02:00
|
|
|
if (p->family == AF_INET) {
|
|
|
|
if (!nl_attr_put(&req->n, datalen, RTA_PREFSRC,
|
|
|
|
&src.ipv4, bytelen))
|
|
|
|
return 0;
|
|
|
|
} else if (p->family == AF_INET6) {
|
|
|
|
if (!nl_attr_put(&req->n, datalen, RTA_PREFSRC,
|
|
|
|
&src.ipv6, bytelen))
|
|
|
|
return 0;
|
|
|
|
}
|
2020-03-24 22:32:21 +01:00
|
|
|
}
|
2019-12-04 14:37:40 +01:00
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
return NLMSG_ALIGN(req->n.nlmsg_len);
|
2019-05-15 01:42:39 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 18:20:43 +02:00
|
|
|
/* Count overall nexthops so we can decide whether to use singlepath
|
2018-07-11 17:08:47 +02:00
|
|
|
* or multipath case.
|
|
|
|
*/
|
2018-05-23 18:20:43 +02:00
|
|
|
nexthop_num = 0;
|
|
|
|
for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx), nexthop)) {
|
|
|
|
if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
|
|
|
|
continue;
|
2019-12-02 17:03:35 +01:00
|
|
|
if (!NEXTHOP_IS_ACTIVE(nexthop->flags))
|
2018-05-23 18:20:43 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
nexthop_num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Singlepath case. */
|
zebra: Allow zebra to only mark up to multipath_num nexthops as ACTIVE
NEXTHOP_FLAG_ACTIVE currently means that the nexthop is considered
good enough to be installed. With current ecmp restrictions this
translation from multipath_num is enforced in the data plane.
The problem with this is of course that every data plane now
becomes concerned about the multipath num and must enforce it
independently. Currently *bsd does not honor multipath_num at
all and linux marks all nexthops as being installed even when
it honors a multipath_num that is less than the total.
This code change moves the multipath_num enforcement from a dataplane
decision to a zebra nexthop decision. Thus dataplanes now can
just install those nexthops marked as NEXTHOP_FLAG_ACTIVE
without having to worry about multipath_num.
*BSD will now respect multipath_num and Linux now properly notes
which routes are actually installed or not:
sharpd@donna ~/f/t/topotests> ps -ef | grep frr
frr 6261 1556 0 09:12 ? 00:00:00 /usr/lib/frr/zebra -e 2 --daemon -A 127.0.0.1
frr 6279 1556 0 09:12 ? 00:00:00 /usr/lib/frr/staticd --daemon -A 127.0.0.1
donna.cumulusnetworks.com(config)# do show ip route
Codes: K - kernel route, C - connected, S - static, R - RIP,
O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,
T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP,
F - PBR, f - OpenFabric,
> - selected route, * - FIB route
K>* 0.0.0.0/0 [0/106] via 10.0.2.2, enp0s3, 00:00:45
S>* 4.4.4.4/32 [1/0] via 10.0.2.1, enp0s3, 00:00:02
* via 192.168.209.1, enp0s8, 00:00:02
via 192.168.210.1, enp0s9 inactive, 00:00:02
C>* 10.0.2.0/24 is directly connected, enp0s3, 00:00:45
C>* 192.168.209.0/24 is directly connected, enp0s8, 00:00:45
C>* 192.168.210.0/24 is directly connected, enp0s9, 00:00:45
donna.cumulusnetworks.com(config)#
sharpd@donna ~/f/t/topotests> ip route show
default via 10.0.2.2 dev enp0s3 proto dhcp metric 106
4.4.4.4 proto 196 metric 20
nexthop via 10.0.2.1 dev enp0s3 weight 1
nexthop via 192.168.209.1 dev enp0s8 weight 1
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15 metric 106
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown
192.168.209.0/24 dev enp0s8 proto kernel scope link src 192.168.209.2 metric 105
192.168.210.0/24 dev enp0s9 proto kernel scope link src 192.168.210.2 metric 103
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-12-13 15:21:26 +01:00
|
|
|
if (nexthop_num == 1) {
|
2018-05-23 18:20:43 +02:00
|
|
|
nexthop_num = 0;
|
|
|
|
for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx), nexthop)) {
|
|
|
|
if (CHECK_FLAG(nexthop->flags,
|
|
|
|
NEXTHOP_FLAG_RECURSIVE)) {
|
2018-07-11 17:08:47 +02:00
|
|
|
|
|
|
|
if (setsrc)
|
|
|
|
continue;
|
|
|
|
|
2019-12-02 17:03:35 +01:00
|
|
|
setsrc = nexthop_set_src(nexthop, p->family,
|
|
|
|
&src);
|
2018-08-17 22:53:24 +02:00
|
|
|
continue;
|
2018-05-23 18:20:43 +02:00
|
|
|
}
|
|
|
|
|
2019-12-02 17:03:35 +01:00
|
|
|
if (NEXTHOP_IS_ACTIVE(nexthop->flags)) {
|
2018-05-23 18:20:43 +02:00
|
|
|
routedesc = nexthop->rparent
|
|
|
|
? "recursive, single-path"
|
|
|
|
: "single-path";
|
|
|
|
|
2022-06-21 21:13:08 +02:00
|
|
|
if (!_netlink_set_tag(&req->n, datalen, tag))
|
|
|
|
return 0;
|
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!_netlink_route_build_singlepath(
|
|
|
|
p, routedesc, bytelen, nexthop,
|
|
|
|
&req->n, &req->r, datalen, cmd))
|
|
|
|
return 0;
|
2018-05-23 18:20:43 +02:00
|
|
|
nexthop_num++;
|
|
|
|
break;
|
|
|
|
}
|
2020-01-13 20:34:03 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add encapsulation information when installing via
|
|
|
|
* FPM.
|
|
|
|
*/
|
2020-06-10 11:44:31 +02:00
|
|
|
if (fpm) {
|
|
|
|
if (!netlink_route_nexthop_encap(
|
|
|
|
&req->n, datalen, nexthop))
|
|
|
|
return 0;
|
|
|
|
}
|
2018-05-23 18:20:43 +02:00
|
|
|
}
|
2020-01-13 20:34:03 +01:00
|
|
|
|
2020-03-26 15:39:16 +01:00
|
|
|
if (setsrc) {
|
2020-06-10 11:44:31 +02:00
|
|
|
if (p->family == AF_INET) {
|
|
|
|
if (!nl_attr_put(&req->n, datalen, RTA_PREFSRC,
|
|
|
|
&src.ipv4, bytelen))
|
|
|
|
return 0;
|
|
|
|
} else if (p->family == AF_INET6) {
|
|
|
|
if (!nl_attr_put(&req->n, datalen, RTA_PREFSRC,
|
|
|
|
&src.ipv6, bytelen))
|
|
|
|
return 0;
|
|
|
|
}
|
2018-05-23 18:20:43 +02:00
|
|
|
}
|
|
|
|
} else { /* Multipath case */
|
2020-06-08 23:37:26 +02:00
|
|
|
struct rtattr *nest;
|
2019-03-07 19:09:51 +01:00
|
|
|
const union g_addr *src1 = NULL;
|
2018-05-23 18:20:43 +02:00
|
|
|
|
2020-06-08 23:37:26 +02:00
|
|
|
nest = nl_attr_nest(&req->n, datalen, RTA_MULTIPATH);
|
2020-06-10 11:44:31 +02:00
|
|
|
if (nest == NULL)
|
|
|
|
return 0;
|
2018-05-23 18:20:43 +02:00
|
|
|
|
|
|
|
nexthop_num = 0;
|
|
|
|
for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx), nexthop)) {
|
|
|
|
if (CHECK_FLAG(nexthop->flags,
|
|
|
|
NEXTHOP_FLAG_RECURSIVE)) {
|
|
|
|
/* This only works for IPv4 now */
|
2018-07-11 17:08:47 +02:00
|
|
|
if (setsrc)
|
|
|
|
continue;
|
|
|
|
|
2019-12-02 17:03:35 +01:00
|
|
|
setsrc = nexthop_set_src(nexthop, p->family,
|
|
|
|
&src);
|
2018-11-13 16:21:16 +01:00
|
|
|
continue;
|
2018-05-23 18:20:43 +02:00
|
|
|
}
|
|
|
|
|
2019-12-02 17:03:35 +01:00
|
|
|
if (NEXTHOP_IS_ACTIVE(nexthop->flags)) {
|
2018-05-23 18:20:43 +02:00
|
|
|
routedesc = nexthop->rparent
|
|
|
|
? "recursive, multipath"
|
|
|
|
: "multipath";
|
|
|
|
nexthop_num++;
|
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!_netlink_route_build_multipath(
|
|
|
|
p, routedesc, bytelen, nexthop,
|
2022-06-21 21:13:08 +02:00
|
|
|
&req->n, datalen, &req->r, &src1,
|
|
|
|
tag))
|
2020-06-10 11:44:31 +02:00
|
|
|
return 0;
|
2018-05-23 18:20:43 +02:00
|
|
|
|
|
|
|
if (!setsrc && src1) {
|
2019-12-02 17:03:35 +01:00
|
|
|
if (p->family == AF_INET)
|
2018-05-23 18:20:43 +02:00
|
|
|
src.ipv4 = src1->ipv4;
|
2019-12-02 17:03:35 +01:00
|
|
|
else if (p->family == AF_INET6)
|
2018-05-23 18:20:43 +02:00
|
|
|
src.ipv6 = src1->ipv6;
|
|
|
|
|
|
|
|
setsrc = 1;
|
|
|
|
}
|
|
|
|
}
|
2020-06-08 23:37:26 +02:00
|
|
|
}
|
2020-06-10 11:44:31 +02:00
|
|
|
|
2020-06-08 23:37:26 +02:00
|
|
|
nl_attr_nest_end(&req->n, nest);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add encapsulation information when installing via
|
|
|
|
* FPM.
|
|
|
|
*/
|
|
|
|
if (fpm) {
|
|
|
|
for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx),
|
|
|
|
nexthop)) {
|
|
|
|
if (CHECK_FLAG(nexthop->flags,
|
|
|
|
NEXTHOP_FLAG_RECURSIVE))
|
|
|
|
continue;
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!netlink_route_nexthop_encap(
|
|
|
|
&req->n, datalen, nexthop))
|
|
|
|
return 0;
|
2020-06-08 23:37:26 +02:00
|
|
|
}
|
2018-05-23 18:20:43 +02:00
|
|
|
}
|
2020-01-13 20:34:03 +01:00
|
|
|
|
2020-06-08 23:37:26 +02:00
|
|
|
|
2020-03-26 15:39:16 +01:00
|
|
|
if (setsrc) {
|
2020-06-10 11:44:31 +02:00
|
|
|
if (p->family == AF_INET) {
|
|
|
|
if (!nl_attr_put(&req->n, datalen, RTA_PREFSRC,
|
|
|
|
&src.ipv4, bytelen))
|
|
|
|
return 0;
|
|
|
|
} else if (p->family == AF_INET6) {
|
|
|
|
if (!nl_attr_put(&req->n, datalen, RTA_PREFSRC,
|
|
|
|
&src.ipv6, bytelen))
|
|
|
|
return 0;
|
|
|
|
}
|
2018-05-23 18:20:43 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("Setting source");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If there is no useful nexthop then return. */
|
|
|
|
if (nexthop_num == 0) {
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2019-11-29 22:15:02 +01:00
|
|
|
zlog_debug("%s: No useful nexthop.", __func__);
|
2018-05-23 18:20:43 +02:00
|
|
|
}
|
|
|
|
|
2020-06-08 23:37:26 +02:00
|
|
|
return NLMSG_ALIGN(req->n.nlmsg_len);
|
2018-05-23 18:20:43 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 16:18:17 +02:00
|
|
|
int kernel_get_ipmr_sg_stats(struct zebra_vrf *zvrf, void *in)
|
2016-08-11 02:04:20 +02:00
|
|
|
{
|
2018-09-17 15:18:40 +02:00
|
|
|
uint32_t actual_table;
|
2016-08-11 02:04:20 +02:00
|
|
|
int suc = 0;
|
|
|
|
struct mcast_route_data *mr = (struct mcast_route_data *)in;
|
2017-07-05 17:53:29 +02:00
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
2022-07-06 11:22:17 +02:00
|
|
|
struct rtmsg rtm;
|
2017-07-05 17:53:29 +02:00
|
|
|
char buf[256];
|
|
|
|
} req;
|
2016-08-11 02:04:20 +02:00
|
|
|
|
|
|
|
mroute = mr;
|
2017-12-19 12:23:32 +01:00
|
|
|
struct zebra_ns *zns;
|
2017-07-05 17:53:29 +02:00
|
|
|
|
2018-02-13 10:48:48 +01:00
|
|
|
zns = zvrf->zns;
|
2018-05-18 00:46:14 +02:00
|
|
|
memset(&req, 0, sizeof(req));
|
2017-07-05 17:53:29 +02:00
|
|
|
|
2022-07-06 11:22:17 +02:00
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
|
2017-07-05 17:53:29 +02:00
|
|
|
req.n.nlmsg_flags = NLM_F_REQUEST;
|
|
|
|
req.n.nlmsg_pid = zns->netlink_cmd.snl.nl_pid;
|
|
|
|
|
|
|
|
req.n.nlmsg_type = RTM_GETROUTE;
|
|
|
|
|
2022-04-04 13:05:07 +02:00
|
|
|
if (mroute->family == AF_INET) {
|
2022-07-06 11:22:17 +02:00
|
|
|
req.rtm.rtm_family = RTNL_FAMILY_IPMR;
|
2022-07-06 11:26:01 +02:00
|
|
|
req.rtm.rtm_dst_len = IPV4_MAX_BITLEN;
|
|
|
|
req.rtm.rtm_src_len = IPV4_MAX_BITLEN;
|
|
|
|
|
2022-04-04 13:05:07 +02:00
|
|
|
nl_attr_put(&req.n, sizeof(req), RTA_SRC,
|
|
|
|
&mroute->src.ipaddr_v4,
|
|
|
|
sizeof(mroute->src.ipaddr_v4));
|
|
|
|
nl_attr_put(&req.n, sizeof(req), RTA_DST,
|
|
|
|
&mroute->grp.ipaddr_v4,
|
|
|
|
sizeof(mroute->grp.ipaddr_v4));
|
|
|
|
} else {
|
2022-07-06 11:22:17 +02:00
|
|
|
req.rtm.rtm_family = RTNL_FAMILY_IP6MR;
|
2022-07-06 11:26:01 +02:00
|
|
|
req.rtm.rtm_dst_len = IPV6_MAX_BITLEN;
|
|
|
|
req.rtm.rtm_src_len = IPV6_MAX_BITLEN;
|
|
|
|
|
2022-04-04 13:05:07 +02:00
|
|
|
nl_attr_put(&req.n, sizeof(req), RTA_SRC,
|
|
|
|
&mroute->src.ipaddr_v6,
|
|
|
|
sizeof(mroute->src.ipaddr_v6));
|
|
|
|
nl_attr_put(&req.n, sizeof(req), RTA_DST,
|
|
|
|
&mroute->grp.ipaddr_v6,
|
|
|
|
sizeof(mroute->grp.ipaddr_v6));
|
|
|
|
}
|
|
|
|
|
2018-09-17 15:18:40 +02:00
|
|
|
/*
|
|
|
|
* What?
|
|
|
|
*
|
|
|
|
* So during the namespace cleanup we started storing
|
|
|
|
* the zvrf table_id for the default table as RT_TABLE_MAIN
|
|
|
|
* which is what the normal routing table for ip routing is.
|
|
|
|
* This change caused this to break our lookups of sg data
|
|
|
|
* because prior to this change the zvrf->table_id was 0
|
|
|
|
* and when the pim multicast kernel code saw a 0,
|
|
|
|
* it was auto-translated to RT_TABLE_DEFAULT. But since
|
|
|
|
* we are now passing in RT_TABLE_MAIN there is no auto-translation
|
|
|
|
* and the kernel goes screw you and the delicious cookies you
|
|
|
|
* are trying to give me. So now we have this little hack.
|
|
|
|
*/
|
2022-07-06 11:26:01 +02:00
|
|
|
if (mroute->family == AF_INET)
|
2023-08-22 13:27:59 +02:00
|
|
|
actual_table = (zvrf->table_id == rt_table_main_id)
|
2022-07-06 11:26:01 +02:00
|
|
|
? RT_TABLE_DEFAULT
|
|
|
|
: zvrf->table_id;
|
|
|
|
else
|
|
|
|
actual_table = zvrf->table_id;
|
|
|
|
|
2020-06-13 13:31:13 +02:00
|
|
|
nl_attr_put32(&req.n, sizeof(req), RTA_TABLE, actual_table);
|
2016-08-11 02:04:20 +02:00
|
|
|
|
2017-07-05 17:53:29 +02:00
|
|
|
suc = netlink_talk(netlink_route_change_read_multicast, &req.n,
|
2021-10-05 02:26:38 +02:00
|
|
|
&zns->netlink_cmd, zns, false);
|
2016-08-11 02:04:20 +02:00
|
|
|
|
2017-07-05 17:53:29 +02:00
|
|
|
mroute = NULL;
|
2016-08-11 02:04:20 +02:00
|
|
|
return suc;
|
|
|
|
}
|
|
|
|
|
2019-08-12 21:46:22 +02:00
|
|
|
/* Char length to debug ID with */
|
|
|
|
#define ID_LENGTH 10
|
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
static bool _netlink_nexthop_build_group(struct nlmsghdr *n, size_t req_size,
|
2019-08-12 21:46:22 +02:00
|
|
|
uint32_t id,
|
2019-05-15 00:03:29 +02:00
|
|
|
const struct nh_grp *z_grp,
|
2022-10-22 21:37:27 +02:00
|
|
|
const uint8_t count, bool resilient,
|
|
|
|
const struct nhg_resilience *nhgr)
|
2019-03-27 00:35:08 +01:00
|
|
|
{
|
|
|
|
struct nexthop_grp grp[count];
|
2019-08-12 21:46:22 +02:00
|
|
|
/* Need space for max group size, "/", and null term */
|
|
|
|
char buf[(MULTIPATH_NUM * (ID_LENGTH + 1)) + 1];
|
|
|
|
char buf1[ID_LENGTH + 2];
|
|
|
|
|
|
|
|
buf[0] = '\0';
|
2019-03-27 00:35:08 +01:00
|
|
|
|
|
|
|
memset(grp, 0, sizeof(grp));
|
|
|
|
|
|
|
|
if (count) {
|
2019-05-14 02:10:34 +02:00
|
|
|
for (int i = 0; i < count; i++) {
|
2019-05-15 00:03:29 +02:00
|
|
|
grp[i].id = z_grp[i].id;
|
2019-12-06 14:58:47 +01:00
|
|
|
grp[i].weight = z_grp[i].weight - 1;
|
2019-08-12 21:46:22 +02:00
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL) {
|
|
|
|
if (i == 0)
|
|
|
|
snprintf(buf, sizeof(buf1), "group %u",
|
|
|
|
grp[i].id);
|
|
|
|
else {
|
|
|
|
snprintf(buf1, sizeof(buf1), "/%u",
|
|
|
|
grp[i].id);
|
|
|
|
strlcat(buf, buf1, sizeof(buf));
|
|
|
|
}
|
|
|
|
}
|
2019-03-27 00:35:08 +01:00
|
|
|
}
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!nl_attr_put(n, req_size, NHA_GROUP, grp,
|
|
|
|
count * sizeof(*grp)))
|
|
|
|
return false;
|
2022-10-22 21:37:27 +02:00
|
|
|
|
|
|
|
if (resilient) {
|
|
|
|
struct rtattr *nest;
|
|
|
|
|
|
|
|
nest = nl_attr_nest(n, req_size, NHA_RES_GROUP);
|
|
|
|
|
|
|
|
nl_attr_put16(n, req_size, NHA_RES_GROUP_BUCKETS,
|
|
|
|
nhgr->buckets);
|
|
|
|
nl_attr_put32(n, req_size, NHA_RES_GROUP_IDLE_TIMER,
|
|
|
|
nhgr->idle_timer * 1000);
|
|
|
|
nl_attr_put32(n, req_size,
|
|
|
|
NHA_RES_GROUP_UNBALANCED_TIMER,
|
|
|
|
nhgr->unbalanced_timer * 1000);
|
|
|
|
nl_attr_nest_end(n, nest);
|
|
|
|
|
|
|
|
nl_attr_put16(n, req_size, NHA_GROUP_TYPE,
|
|
|
|
NEXTHOP_GRP_TYPE_RES);
|
|
|
|
}
|
2019-03-27 00:35:08 +01:00
|
|
|
}
|
2019-08-12 21:46:22 +02:00
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("%s: ID (%u): %s", __func__, id, buf);
|
2020-06-10 11:44:31 +02:00
|
|
|
|
|
|
|
return true;
|
2019-03-27 00:35:08 +01:00
|
|
|
}
|
|
|
|
|
2019-03-01 23:17:00 +01:00
|
|
|
/**
|
2020-05-05 15:54:06 +02:00
|
|
|
* Next hop packet encoding helper function.
|
2019-03-01 23:17:00 +01:00
|
|
|
*
|
2020-05-05 15:54:06 +02:00
|
|
|
* \param[in] cmd netlink command.
|
|
|
|
* \param[in] ctx dataplane context (information snapshot).
|
|
|
|
* \param[out] buf buffer to hold the packet.
|
|
|
|
* \param[in] buflen amount of buffer bytes.
|
2019-03-01 23:17:00 +01:00
|
|
|
*
|
2020-06-10 11:44:31 +02:00
|
|
|
* \returns -1 on failure, 0 when the msg doesn't fit entirely in the buffer
|
|
|
|
* otherwise the number of bytes written to buf.
|
2019-03-01 23:17:00 +01:00
|
|
|
*/
|
2020-06-10 11:44:31 +02:00
|
|
|
ssize_t netlink_nexthop_msg_encode(uint16_t cmd,
|
|
|
|
const struct zebra_dplane_ctx *ctx,
|
2022-12-25 06:52:57 +01:00
|
|
|
void *buf, size_t buflen, bool fpm)
|
2019-03-01 23:17:00 +01:00
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct nhmsg nhm;
|
2020-05-05 15:54:06 +02:00
|
|
|
char buf[];
|
|
|
|
} *req = buf;
|
2019-03-01 23:17:00 +01:00
|
|
|
|
2019-08-12 21:46:22 +02:00
|
|
|
mpls_lse_t out_lse[MPLS_MAX_LABELS];
|
|
|
|
char label_buf[256];
|
|
|
|
int num_labels = 0;
|
2020-05-28 19:22:18 +02:00
|
|
|
uint32_t id = dplane_ctx_get_nhe_id(ctx);
|
|
|
|
int type = dplane_ctx_get_nhe_type(ctx);
|
2020-10-20 20:04:48 +02:00
|
|
|
struct rtattr *nest;
|
|
|
|
uint16_t encap;
|
2022-02-02 19:21:52 +01:00
|
|
|
struct nlsock *nl =
|
|
|
|
kernel_netlink_nlsock_lookup(dplane_ctx_get_ns_sock(ctx));
|
2020-05-28 19:22:18 +02:00
|
|
|
|
|
|
|
if (!id) {
|
|
|
|
flog_err(
|
|
|
|
EC_ZEBRA_NHG_FIB_UPDATE,
|
|
|
|
"Failed trying to update a nexthop group in the kernel that does not have an ID");
|
|
|
|
return -1;
|
|
|
|
}
|
2019-08-01 20:53:06 +02:00
|
|
|
|
2020-05-13 21:50:14 +02:00
|
|
|
/*
|
|
|
|
* Nothing to do if the kernel doesn't support nexthop objects or
|
2022-12-25 06:52:57 +01:00
|
|
|
* we dont want to install this type of NHG, but FPM may possible to
|
|
|
|
* handle this.
|
2020-05-13 21:50:14 +02:00
|
|
|
*/
|
2022-12-25 06:52:57 +01:00
|
|
|
if (!fpm && !kernel_nexthops_supported()) {
|
2020-05-28 19:22:18 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_NHG)
|
|
|
|
zlog_debug(
|
|
|
|
"%s: nhg_id %u (%s): kernel nexthops not supported, ignoring",
|
|
|
|
__func__, id, zebra_route_string(type));
|
2020-05-13 21:50:14 +02:00
|
|
|
return 0;
|
2020-05-28 19:22:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (proto_nexthops_only() && !is_proto_nhg(id, type)) {
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_NHG)
|
|
|
|
zlog_debug(
|
|
|
|
"%s: nhg_id %u (%s): proto-based nexthops only, ignoring",
|
|
|
|
__func__, id, zebra_route_string(type));
|
|
|
|
return 0;
|
|
|
|
}
|
2020-05-13 21:50:14 +02:00
|
|
|
|
2019-08-12 21:46:22 +02:00
|
|
|
label_buf[0] = '\0';
|
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
if (buflen < sizeof(*req))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
memset(req, 0, sizeof(*req));
|
2019-03-01 23:17:00 +01:00
|
|
|
|
2020-05-05 15:54:06 +02:00
|
|
|
req->n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nhmsg));
|
|
|
|
req->n.nlmsg_flags = NLM_F_CREATE | NLM_F_REQUEST;
|
2019-08-01 20:24:35 +02:00
|
|
|
|
|
|
|
if (cmd == RTM_NEWNEXTHOP)
|
2020-05-05 15:54:06 +02:00
|
|
|
req->n.nlmsg_flags |= NLM_F_REPLACE;
|
2019-08-01 20:24:35 +02:00
|
|
|
|
2020-05-05 15:54:06 +02:00
|
|
|
req->n.nlmsg_type = cmd;
|
2022-02-02 19:21:52 +01:00
|
|
|
req->n.nlmsg_pid = nl->snl.nl_pid;
|
2019-03-01 23:17:00 +01:00
|
|
|
|
2020-05-05 15:54:06 +02:00
|
|
|
req->nhm.nh_family = AF_UNSPEC;
|
2019-09-03 22:12:06 +02:00
|
|
|
/* TODO: Scope? */
|
2019-03-01 23:17:00 +01:00
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!nl_attr_put32(&req->n, buflen, NHA_ID, id))
|
|
|
|
return 0;
|
2019-03-01 23:17:00 +01:00
|
|
|
|
|
|
|
if (cmd == RTM_NEWNEXTHOP) {
|
2020-01-31 19:57:26 +01:00
|
|
|
/*
|
|
|
|
* We distinguish between a "group", which is a collection
|
|
|
|
* of ids, and a singleton nexthop with an id. The
|
|
|
|
* group is installed as an id that just refers to a list of
|
|
|
|
* other ids.
|
|
|
|
*/
|
2020-06-10 11:44:31 +02:00
|
|
|
if (dplane_ctx_get_nhe_nh_grp_count(ctx)) {
|
2022-10-22 21:37:27 +02:00
|
|
|
const struct nexthop_group *nhg;
|
|
|
|
const struct nhg_resilience *nhgr;
|
|
|
|
|
|
|
|
nhg = dplane_ctx_get_nhe_ng(ctx);
|
|
|
|
nhgr = &nhg->nhgr;
|
2020-06-18 05:36:42 +02:00
|
|
|
if (!_netlink_nexthop_build_group(
|
2020-06-10 11:44:31 +02:00
|
|
|
&req->n, buflen, id,
|
|
|
|
dplane_ctx_get_nhe_nh_grp(ctx),
|
2022-10-22 21:37:27 +02:00
|
|
|
dplane_ctx_get_nhe_nh_grp_count(ctx),
|
|
|
|
!!nhgr->buckets, nhgr))
|
2020-06-10 11:44:31 +02:00
|
|
|
return 0;
|
|
|
|
} else {
|
2019-05-14 02:10:34 +02:00
|
|
|
const struct nexthop *nh =
|
|
|
|
dplane_ctx_get_nhe_ng(ctx)->nexthop;
|
|
|
|
afi_t afi = dplane_ctx_get_nhe_afi(ctx);
|
2019-03-20 18:03:22 +01:00
|
|
|
|
2019-05-14 02:10:34 +02:00
|
|
|
if (afi == AFI_IP)
|
2020-05-05 15:54:06 +02:00
|
|
|
req->nhm.nh_family = AF_INET;
|
2019-05-14 02:10:34 +02:00
|
|
|
else if (afi == AFI_IP6)
|
2020-05-05 15:54:06 +02:00
|
|
|
req->nhm.nh_family = AF_INET6;
|
2019-03-01 23:17:00 +01:00
|
|
|
|
2019-03-27 00:35:08 +01:00
|
|
|
switch (nh->type) {
|
2019-04-22 21:42:10 +02:00
|
|
|
case NEXTHOP_TYPE_IPV4:
|
2019-03-27 00:35:08 +01:00
|
|
|
case NEXTHOP_TYPE_IPV4_IFINDEX:
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!nl_attr_put(&req->n, buflen, NHA_GATEWAY,
|
|
|
|
&nh->gate.ipv4,
|
|
|
|
IPV4_MAX_BYTELEN))
|
|
|
|
return 0;
|
2019-03-27 00:35:08 +01:00
|
|
|
break;
|
2019-04-22 21:42:10 +02:00
|
|
|
case NEXTHOP_TYPE_IPV6:
|
2019-03-27 00:35:08 +01:00
|
|
|
case NEXTHOP_TYPE_IPV6_IFINDEX:
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!nl_attr_put(&req->n, buflen, NHA_GATEWAY,
|
|
|
|
&nh->gate.ipv6,
|
|
|
|
IPV6_MAX_BYTELEN))
|
|
|
|
return 0;
|
2019-03-27 00:35:08 +01:00
|
|
|
break;
|
|
|
|
case NEXTHOP_TYPE_BLACKHOLE:
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!nl_attr_put(&req->n, buflen, NHA_BLACKHOLE,
|
|
|
|
NULL, 0))
|
|
|
|
return 0;
|
2019-08-12 21:46:22 +02:00
|
|
|
/* Blackhole shouldn't have anymore attributes
|
|
|
|
*/
|
|
|
|
goto nexthop_done;
|
2019-03-27 00:35:08 +01:00
|
|
|
case NEXTHOP_TYPE_IFINDEX:
|
|
|
|
/* Don't need anymore info for this */
|
|
|
|
break;
|
2019-04-22 21:42:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!nh->ifindex) {
|
2019-03-27 00:35:08 +01:00
|
|
|
flog_err(
|
|
|
|
EC_ZEBRA_NHG_FIB_UPDATE,
|
|
|
|
"Context received for kernel nexthop update without an interface");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!nl_attr_put32(&req->n, buflen, NHA_OIF,
|
|
|
|
nh->ifindex))
|
|
|
|
return 0;
|
2019-08-12 21:46:22 +02:00
|
|
|
|
2019-12-17 20:24:22 +01:00
|
|
|
if (CHECK_FLAG(nh->flags, NEXTHOP_FLAG_ONLINK))
|
2020-05-05 15:54:06 +02:00
|
|
|
req->nhm.nh_flags |= RTNH_F_ONLINK;
|
2019-12-17 20:24:22 +01:00
|
|
|
|
2021-04-01 17:50:31 +02:00
|
|
|
num_labels = build_label_stack(
|
|
|
|
nh->nh_label, nh->nh_label_type, out_lse,
|
|
|
|
label_buf, sizeof(label_buf));
|
2019-08-12 21:46:22 +02:00
|
|
|
|
2022-11-21 17:23:18 +01:00
|
|
|
if (num_labels && nh->nh_label_type == ZEBRA_LSP_EVPN) {
|
|
|
|
if (!nl_attr_put16(&req->n, buflen,
|
|
|
|
NHA_ENCAP_TYPE,
|
|
|
|
LWTUNNEL_ENCAP_IP))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nest = nl_attr_nest(&req->n, buflen, NHA_ENCAP);
|
|
|
|
if (!nest)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (_netlink_nexthop_encode_dvni_label(
|
|
|
|
nh, &req->n, out_lse, buflen,
|
|
|
|
label_buf) == false)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nl_attr_nest_end(&req->n, nest);
|
|
|
|
|
|
|
|
} else if (num_labels) {
|
2019-08-12 21:46:22 +02:00
|
|
|
/* Set the BoS bit */
|
|
|
|
out_lse[num_labels - 1] |=
|
|
|
|
htonl(1 << MPLS_LS_S_SHIFT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: MPLS unsupported for now in kernel.
|
|
|
|
*/
|
2020-05-05 15:54:06 +02:00
|
|
|
if (req->nhm.nh_family == AF_MPLS)
|
2019-08-12 21:46:22 +02:00
|
|
|
goto nexthop_done;
|
2020-10-20 20:04:48 +02:00
|
|
|
|
|
|
|
encap = LWTUNNEL_ENCAP_MPLS;
|
|
|
|
if (!nl_attr_put16(&req->n, buflen,
|
|
|
|
NHA_ENCAP_TYPE, encap))
|
|
|
|
return 0;
|
|
|
|
nest = nl_attr_nest(&req->n, buflen, NHA_ENCAP);
|
|
|
|
if (!nest)
|
|
|
|
return 0;
|
|
|
|
if (!nl_attr_put(
|
|
|
|
&req->n, buflen, MPLS_IPTUNNEL_DST,
|
|
|
|
&out_lse,
|
|
|
|
num_labels * sizeof(mpls_lse_t)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nl_attr_nest_end(&req->n, nest);
|
2019-08-12 21:46:22 +02:00
|
|
|
}
|
|
|
|
|
2021-04-05 15:29:12 +02:00
|
|
|
if (nh->nh_srv6) {
|
|
|
|
if (nh->nh_srv6->seg6local_action !=
|
|
|
|
ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) {
|
|
|
|
uint32_t action;
|
|
|
|
uint16_t encap;
|
|
|
|
struct rtattr *nest;
|
|
|
|
const struct seg6local_context *ctx;
|
|
|
|
|
|
|
|
req->nhm.nh_family = AF_INET6;
|
|
|
|
action = nh->nh_srv6->seg6local_action;
|
|
|
|
ctx = &nh->nh_srv6->seg6local_ctx;
|
|
|
|
encap = LWTUNNEL_ENCAP_SEG6_LOCAL;
|
|
|
|
if (!nl_attr_put(&req->n, buflen,
|
|
|
|
NHA_ENCAP_TYPE,
|
|
|
|
&encap,
|
|
|
|
sizeof(uint16_t)))
|
|
|
|
return 0;
|
2020-12-06 00:01:39 +01:00
|
|
|
|
2021-04-05 15:29:12 +02:00
|
|
|
nest = nl_attr_nest(&req->n, buflen,
|
|
|
|
NHA_ENCAP | NLA_F_NESTED);
|
|
|
|
if (!nest)
|
|
|
|
return 0;
|
2021-03-22 11:36:17 +01:00
|
|
|
|
2021-04-05 15:29:12 +02:00
|
|
|
switch (action) {
|
|
|
|
case SEG6_LOCAL_ACTION_END:
|
|
|
|
if (!nl_attr_put32(
|
|
|
|
&req->n, buflen,
|
2021-03-22 11:36:17 +01:00
|
|
|
SEG6_LOCAL_ACTION,
|
|
|
|
SEG6_LOCAL_ACTION_END))
|
2021-04-05 15:29:12 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case SEG6_LOCAL_ACTION_END_X:
|
|
|
|
if (!nl_attr_put32(
|
|
|
|
&req->n, buflen,
|
2021-03-22 11:36:17 +01:00
|
|
|
SEG6_LOCAL_ACTION,
|
|
|
|
SEG6_LOCAL_ACTION_END_X))
|
2021-04-05 15:29:12 +02:00
|
|
|
return 0;
|
|
|
|
if (!nl_attr_put(
|
|
|
|
&req->n, buflen,
|
2020-12-06 00:01:39 +01:00
|
|
|
SEG6_LOCAL_NH6, &ctx->nh6,
|
2021-03-22 11:36:17 +01:00
|
|
|
sizeof(struct in6_addr)))
|
2021-04-05 15:29:12 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case SEG6_LOCAL_ACTION_END_T:
|
|
|
|
if (!nl_attr_put32(
|
|
|
|
&req->n, buflen,
|
2021-03-22 11:36:17 +01:00
|
|
|
SEG6_LOCAL_ACTION,
|
|
|
|
SEG6_LOCAL_ACTION_END_T))
|
2021-04-05 15:29:12 +02:00
|
|
|
return 0;
|
|
|
|
if (!nl_attr_put32(
|
|
|
|
&req->n, buflen,
|
2021-03-22 11:36:17 +01:00
|
|
|
SEG6_LOCAL_TABLE,
|
|
|
|
ctx->table))
|
2021-04-05 15:29:12 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case SEG6_LOCAL_ACTION_END_DX4:
|
|
|
|
if (!nl_attr_put32(
|
|
|
|
&req->n, buflen,
|
2021-03-22 11:36:17 +01:00
|
|
|
SEG6_LOCAL_ACTION,
|
|
|
|
SEG6_LOCAL_ACTION_END_DX4))
|
2021-04-05 15:29:12 +02:00
|
|
|
return 0;
|
|
|
|
if (!nl_attr_put(
|
|
|
|
&req->n, buflen,
|
2020-12-06 00:01:39 +01:00
|
|
|
SEG6_LOCAL_NH4, &ctx->nh4,
|
2021-03-22 11:36:17 +01:00
|
|
|
sizeof(struct in_addr)))
|
2021-04-05 15:29:12 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case SEG6_LOCAL_ACTION_END_DT6:
|
|
|
|
if (!nl_attr_put32(
|
|
|
|
&req->n, buflen,
|
2021-03-22 11:36:17 +01:00
|
|
|
SEG6_LOCAL_ACTION,
|
|
|
|
SEG6_LOCAL_ACTION_END_DT6))
|
2021-04-05 15:29:12 +02:00
|
|
|
return 0;
|
|
|
|
if (!nl_attr_put32(
|
|
|
|
&req->n, buflen,
|
2021-03-22 11:36:17 +01:00
|
|
|
SEG6_LOCAL_TABLE,
|
|
|
|
ctx->table))
|
2021-04-05 15:29:12 +02:00
|
|
|
return 0;
|
|
|
|
break;
|
2021-11-22 14:50:48 +01:00
|
|
|
case SEG6_LOCAL_ACTION_END_DT4:
|
|
|
|
if (!nl_attr_put32(
|
|
|
|
&req->n, buflen,
|
|
|
|
SEG6_LOCAL_ACTION,
|
|
|
|
SEG6_LOCAL_ACTION_END_DT4))
|
|
|
|
return 0;
|
|
|
|
if (!nl_attr_put32(
|
|
|
|
&req->n, buflen,
|
|
|
|
SEG6_LOCAL_VRFTABLE,
|
|
|
|
ctx->table))
|
|
|
|
return 0;
|
|
|
|
break;
|
2022-07-23 01:32:04 +02:00
|
|
|
case SEG6_LOCAL_ACTION_END_DT46:
|
|
|
|
if (!nl_attr_put32(
|
|
|
|
&req->n, buflen,
|
|
|
|
SEG6_LOCAL_ACTION,
|
|
|
|
SEG6_LOCAL_ACTION_END_DT46))
|
|
|
|
return 0;
|
|
|
|
if (!nl_attr_put32(
|
|
|
|
&req->n, buflen,
|
|
|
|
SEG6_LOCAL_VRFTABLE,
|
|
|
|
ctx->table))
|
|
|
|
return 0;
|
|
|
|
break;
|
2021-04-05 15:29:12 +02:00
|
|
|
default:
|
|
|
|
zlog_err("%s: unsupport seg6local behaviour action=%u",
|
|
|
|
__func__, action);
|
2021-04-23 13:27:41 +02:00
|
|
|
return 0;
|
2021-04-05 15:29:12 +02:00
|
|
|
}
|
2023-03-20 22:32:01 +01:00
|
|
|
|
|
|
|
if (!_netlink_nexthop_encode_seg6local_flavor(
|
|
|
|
nh, &req->n, buflen))
|
|
|
|
return false;
|
|
|
|
|
2021-04-05 15:29:12 +02:00
|
|
|
nl_attr_nest_end(&req->n, nest);
|
2020-12-06 00:01:39 +01:00
|
|
|
}
|
|
|
|
|
2023-07-26 17:56:32 +02:00
|
|
|
if (nh->nh_srv6->seg6_segs &&
|
|
|
|
nh->nh_srv6->seg6_segs->num_segs &&
|
|
|
|
!sid_zero(nh->nh_srv6->seg6_segs)) {
|
2021-04-05 15:29:12 +02:00
|
|
|
char tun_buf[4096];
|
|
|
|
ssize_t tun_len;
|
|
|
|
struct rtattr *nest;
|
2020-12-17 15:43:01 +01:00
|
|
|
|
2021-04-05 15:29:12 +02:00
|
|
|
if (!nl_attr_put16(&req->n, buflen,
|
|
|
|
NHA_ENCAP_TYPE,
|
|
|
|
LWTUNNEL_ENCAP_SEG6))
|
|
|
|
return 0;
|
|
|
|
nest = nl_attr_nest(&req->n, buflen,
|
|
|
|
NHA_ENCAP | NLA_F_NESTED);
|
|
|
|
if (!nest)
|
|
|
|
return 0;
|
2023-07-26 17:56:32 +02:00
|
|
|
tun_len = fill_seg6ipt_encap(
|
|
|
|
tun_buf, sizeof(tun_buf),
|
|
|
|
nh->nh_srv6->seg6_segs);
|
2021-04-05 15:29:12 +02:00
|
|
|
if (tun_len < 0)
|
|
|
|
return 0;
|
|
|
|
if (!nl_attr_put(&req->n, buflen,
|
|
|
|
SEG6_IPTUNNEL_SRH,
|
|
|
|
tun_buf, tun_len))
|
|
|
|
return 0;
|
|
|
|
nl_attr_nest_end(&req->n, nest);
|
|
|
|
}
|
2020-12-17 15:43:01 +01:00
|
|
|
}
|
|
|
|
|
2020-01-31 19:57:26 +01:00
|
|
|
nexthop_done:
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2020-05-01 17:57:02 +02:00
|
|
|
zlog_debug("%s: ID (%u): %pNHv(%d) vrf %s(%u) %s ",
|
|
|
|
__func__, id, nh, nh->ifindex,
|
2020-03-15 19:42:30 +01:00
|
|
|
vrf_id_to_name(nh->vrf_id),
|
|
|
|
nh->vrf_id, label_buf);
|
2020-10-20 20:04:48 +02:00
|
|
|
}
|
2019-03-01 23:17:00 +01:00
|
|
|
|
2020-10-20 20:04:48 +02:00
|
|
|
req->nhm.nh_protocol = zebra2proto(type);
|
2019-03-01 23:17:00 +01:00
|
|
|
|
|
|
|
} else if (cmd != RTM_DELNEXTHOP) {
|
|
|
|
flog_err(
|
|
|
|
EC_ZEBRA_NHG_FIB_UPDATE,
|
|
|
|
"Nexthop group kernel update command (%d) does not exist",
|
|
|
|
cmd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-11-29 22:15:02 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("%s: %s, id=%u", __func__, nl_msg_type_to_str(cmd),
|
|
|
|
id);
|
2019-03-01 23:17:00 +01:00
|
|
|
|
2020-05-05 15:54:06 +02:00
|
|
|
return NLMSG_ALIGN(req->n.nlmsg_len);
|
2019-03-01 23:17:00 +01:00
|
|
|
}
|
|
|
|
|
2020-07-15 15:14:08 +02:00
|
|
|
static ssize_t netlink_nexthop_msg_encoder(struct zebra_dplane_ctx *ctx,
|
|
|
|
void *buf, size_t buflen)
|
2019-03-01 23:17:00 +01:00
|
|
|
{
|
2020-01-31 19:57:26 +01:00
|
|
|
enum dplane_op_e op;
|
2019-05-15 00:27:40 +02:00
|
|
|
int cmd = 0;
|
2019-03-01 23:17:00 +01:00
|
|
|
|
2020-01-31 19:57:26 +01:00
|
|
|
op = dplane_ctx_get_op(ctx);
|
|
|
|
if (op == DPLANE_OP_NH_INSTALL || op == DPLANE_OP_NH_UPDATE)
|
2019-03-01 23:17:00 +01:00
|
|
|
cmd = RTM_NEWNEXTHOP;
|
2020-01-31 19:57:26 +01:00
|
|
|
else if (op == DPLANE_OP_NH_DELETE)
|
|
|
|
cmd = RTM_DELNEXTHOP;
|
|
|
|
else {
|
|
|
|
flog_err(EC_ZEBRA_NHG_FIB_UPDATE,
|
|
|
|
"Context received for kernel nexthop update with incorrect OP code (%u)",
|
|
|
|
op);
|
2020-07-15 15:14:08 +02:00
|
|
|
return -1;
|
2019-03-01 23:17:00 +01:00
|
|
|
}
|
|
|
|
|
2022-12-25 06:52:57 +01:00
|
|
|
return netlink_nexthop_msg_encode(cmd, ctx, buf, buflen, false);
|
2020-07-15 15:14:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
enum netlink_msg_status
|
|
|
|
netlink_put_nexthop_update_msg(struct nl_batch *bth,
|
|
|
|
struct zebra_dplane_ctx *ctx)
|
|
|
|
{
|
2020-05-05 15:54:06 +02:00
|
|
|
/* Nothing to do if the kernel doesn't support nexthop objects */
|
|
|
|
if (!kernel_nexthops_supported())
|
2020-07-15 15:14:08 +02:00
|
|
|
return FRR_NETLINK_SUCCESS;
|
2020-05-05 15:54:06 +02:00
|
|
|
|
2020-07-15 15:14:08 +02:00
|
|
|
return netlink_batch_add_msg(bth, ctx, netlink_nexthop_msg_encoder,
|
|
|
|
false);
|
|
|
|
}
|
2019-03-01 23:17:00 +01:00
|
|
|
|
2020-07-15 15:14:08 +02:00
|
|
|
static ssize_t netlink_newroute_msg_encoder(struct zebra_dplane_ctx *ctx,
|
|
|
|
void *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
return netlink_route_multipath_msg_encode(RTM_NEWROUTE, ctx, buf,
|
2023-07-26 22:30:07 +02:00
|
|
|
buflen, false, false, false);
|
2019-03-01 23:17:00 +01:00
|
|
|
}
|
|
|
|
|
2020-07-15 15:14:08 +02:00
|
|
|
static ssize_t netlink_delroute_msg_encoder(struct zebra_dplane_ctx *ctx,
|
|
|
|
void *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
return netlink_route_multipath_msg_encode(RTM_DELROUTE, ctx, buf,
|
2023-07-26 22:30:07 +02:00
|
|
|
buflen, false, false, false);
|
2020-07-15 15:14:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
enum netlink_msg_status
|
|
|
|
netlink_put_route_update_msg(struct nl_batch *bth, struct zebra_dplane_ctx *ctx)
|
2018-05-23 18:20:43 +02:00
|
|
|
{
|
2020-07-15 15:14:08 +02:00
|
|
|
int cmd;
|
2018-05-23 18:20:43 +02:00
|
|
|
const struct prefix *p = dplane_ctx_get_dest(ctx);
|
|
|
|
|
|
|
|
if (dplane_ctx_get_op(ctx) == DPLANE_OP_ROUTE_DELETE) {
|
|
|
|
cmd = RTM_DELROUTE;
|
|
|
|
} else if (dplane_ctx_get_op(ctx) == DPLANE_OP_ROUTE_INSTALL) {
|
|
|
|
cmd = RTM_NEWROUTE;
|
|
|
|
} else if (dplane_ctx_get_op(ctx) == DPLANE_OP_ROUTE_UPDATE) {
|
|
|
|
|
|
|
|
if (p->family == AF_INET || v6_rr_semantics) {
|
|
|
|
/* Single 'replace' operation */
|
2019-07-29 17:10:25 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* With route replace semantics in place
|
|
|
|
* for v4 routes and the new route is a system
|
|
|
|
* route we do not install anything.
|
|
|
|
* The problem here is that the new system
|
|
|
|
* route should cause us to withdraw from
|
|
|
|
* the kernel the old non-system route
|
|
|
|
*/
|
2020-07-15 15:14:08 +02:00
|
|
|
if (RSYSTEM_ROUTE(dplane_ctx_get_type(ctx))
|
|
|
|
&& !RSYSTEM_ROUTE(dplane_ctx_get_old_type(ctx)))
|
2021-11-03 00:22:15 +01:00
|
|
|
return netlink_batch_add_msg(
|
2020-07-15 15:14:08 +02:00
|
|
|
bth, ctx, netlink_delroute_msg_encoder,
|
|
|
|
true);
|
2018-05-23 18:20:43 +02:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* So v6 route replace semantics are not in
|
|
|
|
* the kernel at this point as I understand it.
|
|
|
|
* so let's do a delete then an add.
|
|
|
|
* In the future once v6 route replace semantics
|
|
|
|
* are in we can figure out what to do here to
|
|
|
|
* allow working with old and new kernels.
|
|
|
|
*
|
|
|
|
* I'm also intentionally ignoring the failure case
|
|
|
|
* of the route delete. If that happens yeah we're
|
|
|
|
* screwed.
|
|
|
|
*/
|
2020-07-15 15:14:08 +02:00
|
|
|
if (!RSYSTEM_ROUTE(dplane_ctx_get_old_type(ctx)))
|
|
|
|
netlink_batch_add_msg(
|
|
|
|
bth, ctx, netlink_delroute_msg_encoder,
|
|
|
|
true);
|
2018-05-23 18:20:43 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 15:14:08 +02:00
|
|
|
cmd = RTM_NEWROUTE;
|
|
|
|
} else
|
|
|
|
return FRR_NETLINK_ERROR;
|
2018-05-23 18:20:43 +02:00
|
|
|
|
2020-07-15 15:14:08 +02:00
|
|
|
if (RSYSTEM_ROUTE(dplane_ctx_get_type(ctx)))
|
|
|
|
return FRR_NETLINK_SUCCESS;
|
2020-06-10 11:44:31 +02:00
|
|
|
|
2020-07-15 15:14:08 +02:00
|
|
|
return netlink_batch_add_msg(bth, ctx,
|
|
|
|
cmd == RTM_NEWROUTE
|
|
|
|
? netlink_newroute_msg_encoder
|
|
|
|
: netlink_delroute_msg_encoder,
|
|
|
|
false);
|
|
|
|
}
|
2018-05-23 18:20:43 +02:00
|
|
|
|
2019-02-26 00:18:07 +01:00
|
|
|
/**
|
|
|
|
* netlink_nexthop_process_nh() - Parse the gatway/if info from a new nexthop
|
|
|
|
*
|
|
|
|
* @tb: Netlink RTA data
|
|
|
|
* @family: Address family in the nhmsg
|
2019-03-11 21:31:44 +01:00
|
|
|
* @ifp: Interface connected - this should be NULL, we fill it in
|
2019-02-26 00:18:07 +01:00
|
|
|
* @ns_id: Namspace id
|
|
|
|
*
|
|
|
|
* Return: New nexthop
|
|
|
|
*/
|
2019-05-15 00:03:29 +02:00
|
|
|
static struct nexthop netlink_nexthop_process_nh(struct rtattr **tb,
|
|
|
|
unsigned char family,
|
|
|
|
struct interface **ifp,
|
|
|
|
ns_id_t ns_id)
|
2019-02-26 00:18:07 +01:00
|
|
|
{
|
2019-05-15 00:03:29 +02:00
|
|
|
struct nexthop nh = {};
|
2019-02-26 00:18:07 +01:00
|
|
|
void *gate = NULL;
|
2019-03-22 18:11:07 +01:00
|
|
|
enum nexthop_types_t type = 0;
|
2019-05-15 00:03:29 +02:00
|
|
|
int if_index = 0;
|
|
|
|
size_t sz = 0;
|
2019-10-29 01:30:06 +01:00
|
|
|
struct interface *ifp_lookup;
|
2019-02-26 00:18:07 +01:00
|
|
|
|
|
|
|
if_index = *(int *)RTA_DATA(tb[NHA_OIF]);
|
|
|
|
|
2019-03-22 18:11:07 +01:00
|
|
|
|
2019-02-26 00:18:07 +01:00
|
|
|
if (tb[NHA_GATEWAY]) {
|
|
|
|
switch (family) {
|
|
|
|
case AF_INET:
|
2019-03-22 18:11:07 +01:00
|
|
|
type = NEXTHOP_TYPE_IPV4_IFINDEX;
|
2019-02-26 00:18:07 +01:00
|
|
|
sz = 4;
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
2019-03-22 18:11:07 +01:00
|
|
|
type = NEXTHOP_TYPE_IPV6_IFINDEX;
|
2019-02-26 00:18:07 +01:00
|
|
|
sz = 16;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
flog_warn(
|
|
|
|
EC_ZEBRA_BAD_NHG_MESSAGE,
|
2019-03-19 21:43:27 +01:00
|
|
|
"Nexthop gateway with bad address family (%d) received from kernel",
|
2019-02-26 00:18:07 +01:00
|
|
|
family);
|
2019-05-15 00:03:29 +02:00
|
|
|
return nh;
|
2019-02-26 00:18:07 +01:00
|
|
|
}
|
|
|
|
gate = RTA_DATA(tb[NHA_GATEWAY]);
|
2019-05-15 00:03:29 +02:00
|
|
|
} else
|
2019-03-22 18:11:07 +01:00
|
|
|
type = NEXTHOP_TYPE_IFINDEX;
|
2019-02-26 00:18:07 +01:00
|
|
|
|
2019-03-22 18:11:07 +01:00
|
|
|
if (type)
|
2019-05-15 00:03:29 +02:00
|
|
|
nh.type = type;
|
2019-03-22 18:11:07 +01:00
|
|
|
|
|
|
|
if (gate)
|
2019-05-15 00:03:29 +02:00
|
|
|
memcpy(&(nh.gate), gate, sz);
|
2019-03-22 18:11:07 +01:00
|
|
|
|
|
|
|
if (if_index)
|
2019-05-15 00:03:29 +02:00
|
|
|
nh.ifindex = if_index;
|
2019-03-22 18:11:07 +01:00
|
|
|
|
2019-10-29 01:30:06 +01:00
|
|
|
ifp_lookup =
|
|
|
|
if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id), nh.ifindex);
|
|
|
|
|
2019-05-15 00:03:29 +02:00
|
|
|
if (ifp)
|
2019-10-29 01:30:06 +01:00
|
|
|
*ifp = ifp_lookup;
|
|
|
|
if (ifp_lookup)
|
2021-10-22 00:17:40 +02:00
|
|
|
nh.vrf_id = ifp_lookup->vrf->vrf_id;
|
2019-05-15 00:03:29 +02:00
|
|
|
else {
|
2019-02-26 00:18:07 +01:00
|
|
|
flog_warn(
|
|
|
|
EC_ZEBRA_UNKNOWN_INTERFACE,
|
|
|
|
"%s: Unknown nexthop interface %u received, defaulting to VRF_DEFAULT",
|
2020-03-05 19:17:54 +01:00
|
|
|
__func__, nh.ifindex);
|
2019-02-26 00:18:07 +01:00
|
|
|
|
2019-05-15 00:03:29 +02:00
|
|
|
nh.vrf_id = VRF_DEFAULT;
|
2019-02-26 00:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tb[NHA_ENCAP] && tb[NHA_ENCAP_TYPE]) {
|
|
|
|
uint16_t encap_type = *(uint16_t *)RTA_DATA(tb[NHA_ENCAP_TYPE]);
|
|
|
|
int num_labels = 0;
|
2019-08-26 23:06:10 +02:00
|
|
|
|
2019-02-26 00:18:07 +01:00
|
|
|
mpls_label_t labels[MPLS_MAX_LABELS] = {0};
|
|
|
|
|
2019-05-15 00:03:29 +02:00
|
|
|
if (encap_type == LWTUNNEL_ENCAP_MPLS)
|
2019-02-26 00:18:07 +01:00
|
|
|
num_labels = parse_encap_mpls(tb[NHA_ENCAP], labels);
|
|
|
|
|
2019-05-15 00:03:29 +02:00
|
|
|
if (num_labels)
|
|
|
|
nexthop_add_labels(&nh, ZEBRA_LSP_STATIC, num_labels,
|
2019-02-26 00:18:07 +01:00
|
|
|
labels);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nh;
|
|
|
|
}
|
|
|
|
|
2019-03-21 15:47:19 +01:00
|
|
|
static int netlink_nexthop_process_group(struct rtattr **tb,
|
2022-10-22 21:37:27 +02:00
|
|
|
struct nh_grp *z_grp, int z_grp_size,
|
|
|
|
struct nhg_resilience *nhgr)
|
2019-02-26 00:18:07 +01:00
|
|
|
{
|
2019-05-15 00:03:29 +02:00
|
|
|
uint8_t count = 0;
|
|
|
|
/* linux/nexthop.h group struct */
|
2019-02-26 00:18:07 +01:00
|
|
|
struct nexthop_grp *n_grp = NULL;
|
|
|
|
|
2019-03-21 15:47:19 +01:00
|
|
|
n_grp = (struct nexthop_grp *)RTA_DATA(tb[NHA_GROUP]);
|
2019-02-26 00:18:07 +01:00
|
|
|
count = (RTA_PAYLOAD(tb[NHA_GROUP]) / sizeof(*n_grp));
|
|
|
|
|
|
|
|
if (!count || (count * sizeof(*n_grp)) != RTA_PAYLOAD(tb[NHA_GROUP])) {
|
|
|
|
flog_warn(EC_ZEBRA_BAD_NHG_MESSAGE,
|
|
|
|
"Invalid nexthop group received from the kernel");
|
2019-03-21 15:47:19 +01:00
|
|
|
return count;
|
2019-02-26 00:18:07 +01:00
|
|
|
}
|
|
|
|
|
2019-10-23 19:08:10 +02:00
|
|
|
for (int i = 0; ((i < count) && (i < z_grp_size)); i++) {
|
2019-05-15 00:03:29 +02:00
|
|
|
z_grp[i].id = n_grp[i].id;
|
2019-12-06 14:58:47 +01:00
|
|
|
z_grp[i].weight = n_grp[i].weight + 1;
|
2019-03-21 15:47:19 +01:00
|
|
|
}
|
2022-10-22 21:37:27 +02:00
|
|
|
|
|
|
|
memset(nhgr, 0, sizeof(*nhgr));
|
|
|
|
if (tb[NHA_RES_GROUP]) {
|
|
|
|
struct rtattr *tbn[NHA_RES_GROUP_MAX + 1];
|
|
|
|
struct rtattr *rta;
|
|
|
|
struct rtattr *res_group = tb[NHA_RES_GROUP];
|
|
|
|
|
|
|
|
netlink_parse_rtattr_nested(tbn, NHA_RES_GROUP_MAX, res_group);
|
|
|
|
|
|
|
|
if (tbn[NHA_RES_GROUP_BUCKETS]) {
|
|
|
|
rta = tbn[NHA_RES_GROUP_BUCKETS];
|
|
|
|
nhgr->buckets = *(uint16_t *)RTA_DATA(rta);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tbn[NHA_RES_GROUP_IDLE_TIMER]) {
|
|
|
|
rta = tbn[NHA_RES_GROUP_IDLE_TIMER];
|
|
|
|
nhgr->idle_timer = *(uint32_t *)RTA_DATA(rta);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tbn[NHA_RES_GROUP_UNBALANCED_TIMER]) {
|
|
|
|
rta = tbn[NHA_RES_GROUP_UNBALANCED_TIMER];
|
|
|
|
nhgr->unbalanced_timer = *(uint32_t *)RTA_DATA(rta);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tbn[NHA_RES_GROUP_UNBALANCED_TIME]) {
|
|
|
|
rta = tbn[NHA_RES_GROUP_UNBALANCED_TIME];
|
|
|
|
nhgr->unbalanced_time = *(uint64_t *)RTA_DATA(rta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 00:18:07 +01:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* netlink_nexthop_change() - Read in change about nexthops from the kernel
|
|
|
|
*
|
|
|
|
* @h: Netlink message header
|
|
|
|
* @ns_id: Namspace id
|
|
|
|
* @startup: Are we reading under startup conditions?
|
|
|
|
*
|
|
|
|
* Return: Result status
|
|
|
|
*/
|
|
|
|
int netlink_nexthop_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
/* nexthop group id */
|
|
|
|
uint32_t id;
|
|
|
|
unsigned char family;
|
2019-08-01 20:07:04 +02:00
|
|
|
int type;
|
2019-03-20 18:03:22 +01:00
|
|
|
afi_t afi = AFI_UNSPEC;
|
2020-01-09 22:57:35 +01:00
|
|
|
vrf_id_t vrf_id = VRF_DEFAULT;
|
2019-03-11 21:31:44 +01:00
|
|
|
struct interface *ifp = NULL;
|
2019-02-26 00:18:07 +01:00
|
|
|
struct nhmsg *nhm = NULL;
|
2019-05-15 00:03:29 +02:00
|
|
|
struct nexthop nh = {};
|
|
|
|
struct nh_grp grp[MULTIPATH_NUM] = {};
|
2019-03-21 15:47:19 +01:00
|
|
|
/* Count of nexthops in group array */
|
2019-05-15 00:03:29 +02:00
|
|
|
uint8_t grp_count = 0;
|
|
|
|
struct rtattr *tb[NHA_MAX + 1] = {};
|
2019-02-26 00:18:07 +01:00
|
|
|
|
2021-10-06 14:49:58 +02:00
|
|
|
frrtrace(3, frr_zebra, netlink_nexthop_change, h, ns_id, startup);
|
|
|
|
|
2019-02-26 00:18:07 +01:00
|
|
|
nhm = NLMSG_DATA(h);
|
|
|
|
|
2020-01-13 22:11:46 +01:00
|
|
|
if (ns_id)
|
|
|
|
vrf_id = ns_id;
|
|
|
|
|
2019-02-26 00:18:07 +01:00
|
|
|
if (startup && h->nlmsg_type != RTM_NEWNEXTHOP)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct nhmsg));
|
|
|
|
if (len < 0) {
|
|
|
|
zlog_warn(
|
|
|
|
"%s: Message received from netlink is of a broken size %d %zu",
|
2020-03-05 19:17:54 +01:00
|
|
|
__func__, h->nlmsg_len,
|
2019-02-26 00:18:07 +01:00
|
|
|
(size_t)NLMSG_LENGTH(sizeof(struct nhmsg)));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-10-28 14:10:28 +02:00
|
|
|
netlink_parse_rtattr_flags(tb, NHA_MAX, RTM_NHA(nhm), len,
|
|
|
|
NLA_F_NESTED);
|
2019-02-26 00:18:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (!tb[NHA_ID]) {
|
|
|
|
flog_warn(
|
|
|
|
EC_ZEBRA_BAD_NHG_MESSAGE,
|
|
|
|
"Nexthop group without an ID received from the kernel");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We use the ID key'd nhg table for kernel updates */
|
|
|
|
id = *((uint32_t *)RTA_DATA(tb[NHA_ID]));
|
|
|
|
|
2020-03-28 00:36:24 +01:00
|
|
|
if (zebra_evpn_mh_is_fdb_nh(id)) {
|
|
|
|
/* If this is a L2 NH just ignore it */
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_EVPN_MH_NH) {
|
|
|
|
zlog_debug("Ignore kernel update (%u) for fdb-nh 0x%x",
|
|
|
|
h->nlmsg_type, id);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-03-20 18:03:22 +01:00
|
|
|
family = nhm->nh_family;
|
|
|
|
afi = family2afi(family);
|
|
|
|
|
2019-08-01 20:07:04 +02:00
|
|
|
type = proto2zebra(nhm->nh_protocol, 0, true);
|
|
|
|
|
2019-03-28 20:18:28 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("%s ID (%u) %s NS %u",
|
|
|
|
nl_msg_type_to_str(h->nlmsg_type), id,
|
|
|
|
nl_family_to_str(family), ns_id);
|
|
|
|
|
|
|
|
|
2019-02-26 00:18:07 +01:00
|
|
|
if (h->nlmsg_type == RTM_NEWNEXTHOP) {
|
2022-10-22 21:37:27 +02:00
|
|
|
struct nhg_resilience nhgr = {};
|
|
|
|
|
2019-02-26 00:18:07 +01:00
|
|
|
if (tb[NHA_GROUP]) {
|
|
|
|
/**
|
|
|
|
* If this is a group message its only going to have
|
|
|
|
* an array of nexthop IDs associated with it
|
|
|
|
*/
|
2019-10-23 19:08:10 +02:00
|
|
|
grp_count = netlink_nexthop_process_group(
|
2022-10-22 21:37:27 +02:00
|
|
|
tb, grp, array_size(grp), &nhgr);
|
2019-03-21 15:47:19 +01:00
|
|
|
} else {
|
|
|
|
if (tb[NHA_BLACKHOLE]) {
|
|
|
|
/**
|
|
|
|
* This nexthop is just for blackhole-ing
|
|
|
|
* traffic, it should not have an OIF, GATEWAY,
|
|
|
|
* or ENCAP
|
|
|
|
*/
|
2019-05-15 00:03:29 +02:00
|
|
|
nh.type = NEXTHOP_TYPE_BLACKHOLE;
|
|
|
|
nh.bh_type = BLACKHOLE_UNSPEC;
|
|
|
|
} else if (tb[NHA_OIF])
|
2019-03-21 15:47:19 +01:00
|
|
|
/**
|
|
|
|
* This is a true new nexthop, so we need
|
|
|
|
* to parse the gateway and device info
|
|
|
|
*/
|
|
|
|
nh = netlink_nexthop_process_nh(tb, family,
|
|
|
|
&ifp, ns_id);
|
2019-05-15 00:03:29 +02:00
|
|
|
else {
|
|
|
|
|
2019-03-22 18:11:07 +01:00
|
|
|
flog_warn(
|
|
|
|
EC_ZEBRA_BAD_NHG_MESSAGE,
|
|
|
|
"Invalid Nexthop message received from the kernel with ID (%u)",
|
|
|
|
id);
|
|
|
|
return -1;
|
|
|
|
}
|
2019-05-15 00:03:29 +02:00
|
|
|
SET_FLAG(nh.flags, NEXTHOP_FLAG_ACTIVE);
|
|
|
|
if (nhm->nh_flags & RTNH_F_ONLINK)
|
|
|
|
SET_FLAG(nh.flags, NEXTHOP_FLAG_ONLINK);
|
|
|
|
vrf_id = nh.vrf_id;
|
2019-02-26 00:18:07 +01:00
|
|
|
}
|
|
|
|
|
2019-08-01 20:07:04 +02:00
|
|
|
if (zebra_nhg_kernel_find(id, &nh, grp, grp_count, vrf_id, afi,
|
2022-10-22 21:37:27 +02:00
|
|
|
type, startup, &nhgr))
|
2019-05-15 00:03:29 +02:00
|
|
|
return -1;
|
2019-03-22 18:11:07 +01:00
|
|
|
|
2019-08-01 20:24:35 +02:00
|
|
|
} else if (h->nlmsg_type == RTM_DELNEXTHOP)
|
2020-01-13 22:11:46 +01:00
|
|
|
zebra_nhg_kernel_del(id, vrf_id);
|
2019-02-26 00:18:07 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* netlink_request_nexthop() - Request nextop information from the kernel
|
|
|
|
* @zns: Zebra namespace
|
|
|
|
* @family: AF_* netlink family
|
|
|
|
* @type: RTM_* route type
|
|
|
|
*
|
|
|
|
* Return: Result status
|
|
|
|
*/
|
|
|
|
static int netlink_request_nexthop(struct zebra_ns *zns, int family, int type)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct nhmsg nhm;
|
|
|
|
} req;
|
|
|
|
|
|
|
|
/* Form the request, specifying filter (rtattr) if needed. */
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
req.n.nlmsg_type = type;
|
|
|
|
req.n.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST;
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nhmsg));
|
|
|
|
req.nhm.nh_family = family;
|
|
|
|
|
2020-04-15 14:56:03 +02:00
|
|
|
return netlink_request(&zns->netlink_cmd, &req);
|
2019-02-26 00:18:07 +01:00
|
|
|
}
|
|
|
|
|
2019-08-28 22:15:17 +02:00
|
|
|
|
2019-02-26 00:18:07 +01:00
|
|
|
/**
|
|
|
|
* netlink_nexthop_read() - Nexthop read function using netlink interface
|
|
|
|
*
|
|
|
|
* @zns: Zebra name space
|
|
|
|
*
|
|
|
|
* Return: Result status
|
|
|
|
* Only called at bootstrap time.
|
|
|
|
*/
|
|
|
|
int netlink_nexthop_read(struct zebra_ns *zns)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct zebra_dplane_info dp_info;
|
|
|
|
|
|
|
|
zebra_dplane_info_from_zns(&dp_info, zns, true /*is_cmd*/);
|
|
|
|
|
|
|
|
/* Get nexthop objects */
|
|
|
|
ret = netlink_request_nexthop(zns, AF_UNSPEC, RTM_GETNEXTHOP);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
ret = netlink_parse_info(netlink_nexthop_change, &zns->netlink_cmd,
|
2021-10-05 02:26:38 +02:00
|
|
|
&dp_info, 0, true);
|
2019-08-01 20:53:06 +02:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
/* If we succesfully read in nexthop objects,
|
|
|
|
* this kernel must support them.
|
|
|
|
*/
|
|
|
|
supports_nh = true;
|
2020-01-28 17:00:42 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_NHG)
|
|
|
|
zlog_debug("Nexthop objects %ssupported on this kernel",
|
|
|
|
supports_nh ? "" : "not ");
|
2022-01-22 13:53:24 +01:00
|
|
|
|
|
|
|
zebra_router_set_supports_nhgs(supports_nh);
|
2019-08-01 20:53:06 +02:00
|
|
|
|
2019-03-06 20:10:08 +01:00
|
|
|
return ret;
|
2019-02-26 00:18:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-13 18:09:11 +01:00
|
|
|
int kernel_neigh_update(int add, int ifindex, void *addr, char *lla, int llalen,
|
|
|
|
ns_id_t ns_id, uint8_t family, bool permanent)
|
2016-08-04 15:07:32 +02:00
|
|
|
{
|
|
|
|
return netlink_neigh_update(add ? RTM_NEWNEIGH : RTM_DELNEIGH, ifindex,
|
2019-12-13 18:09:11 +01:00
|
|
|
addr, lla, llalen, ns_id, family, permanent,
|
|
|
|
RTPROT_ZEBRA);
|
2016-08-04 15:07:32 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2020-03-07 20:07:05 +01:00
|
|
|
/**
|
2020-06-10 11:44:31 +02:00
|
|
|
* netlink_neigh_update_msg_encode() - Common helper api for encoding
|
|
|
|
* evpn neighbor update as netlink messages using dataplane context object.
|
2020-05-15 23:01:59 +02:00
|
|
|
* Here, a neighbor refers to a bridge forwarding database entry for
|
|
|
|
* either unicast forwarding or head-end replication or an IP neighbor
|
|
|
|
* entry.
|
2020-03-07 20:07:05 +01:00
|
|
|
* @ctx: Dataplane context
|
|
|
|
* @cmd: Netlink command (RTM_NEWNEIGH or RTM_DELNEIGH)
|
2021-02-25 11:12:34 +01:00
|
|
|
* @lla: A pointer to neighbor cache link layer address
|
|
|
|
* @llalen: Length of the pointer to neighbor cache link layer
|
|
|
|
* address
|
2020-03-07 20:07:05 +01:00
|
|
|
* @ip: A neighbor cache n/w layer destination address
|
2020-05-15 23:01:59 +02:00
|
|
|
* In the case of bridge FDB, this represnts the remote
|
|
|
|
* VTEP IP.
|
2020-03-07 20:07:05 +01:00
|
|
|
* @replace_obj: Whether NEW request should replace existing object or
|
|
|
|
* add to the end of the list
|
|
|
|
* @family: AF_* netlink family
|
|
|
|
* @type: RTN_* route type
|
|
|
|
* @flags: NTF_* flags
|
|
|
|
* @state: NUD_* states
|
2019-12-09 16:36:18 +01:00
|
|
|
* @data: data buffer pointer
|
|
|
|
* @datalen: total amount of data buffer space
|
2021-02-25 11:12:34 +01:00
|
|
|
* @protocol: protocol information
|
2020-03-07 20:07:05 +01:00
|
|
|
*
|
2020-06-10 11:44:31 +02:00
|
|
|
* Return: 0 when the msg doesn't fit entirely in the buffer
|
|
|
|
* otherwise the number of bytes written to buf.
|
2017-05-15 07:38:26 +02:00
|
|
|
*/
|
2020-06-10 11:44:31 +02:00
|
|
|
static ssize_t netlink_neigh_update_msg_encode(
|
2021-02-25 11:12:34 +01:00
|
|
|
const struct zebra_dplane_ctx *ctx, int cmd, const void *lla,
|
|
|
|
int llalen, const struct ipaddr *ip, bool replace_obj, uint8_t family,
|
|
|
|
uint8_t type, uint8_t flags, uint16_t state, uint32_t nhg_id, bool nfy,
|
2020-05-08 16:42:07 +02:00
|
|
|
uint8_t nfy_flags, bool ext, uint32_t ext_flags, void *data,
|
2021-02-25 11:12:34 +01:00
|
|
|
size_t datalen, uint8_t protocol)
|
2017-05-15 07:38:26 +02:00
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct ndmsg ndm;
|
2019-12-09 16:36:18 +01:00
|
|
|
char buf[];
|
|
|
|
} *req = data;
|
2020-03-07 20:07:05 +01:00
|
|
|
int ipa_len;
|
|
|
|
enum dplane_op_e op;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
if (datalen < sizeof(*req))
|
|
|
|
return 0;
|
2020-07-16 15:49:05 +02:00
|
|
|
memset(req, 0, sizeof(*req));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-03-07 20:07:05 +01:00
|
|
|
op = dplane_ctx_get_op(ctx);
|
|
|
|
|
2019-12-09 16:36:18 +01:00
|
|
|
req->n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
|
|
|
|
req->n.nlmsg_flags = NLM_F_REQUEST;
|
2017-05-15 07:38:26 +02:00
|
|
|
if (cmd == RTM_NEWNEIGH)
|
2019-12-09 16:36:18 +01:00
|
|
|
req->n.nlmsg_flags |=
|
2020-03-07 20:07:05 +01:00
|
|
|
NLM_F_CREATE
|
|
|
|
| (replace_obj ? NLM_F_REPLACE : NLM_F_APPEND);
|
2019-12-09 16:36:18 +01:00
|
|
|
req->n.nlmsg_type = cmd;
|
|
|
|
req->ndm.ndm_family = family;
|
|
|
|
req->ndm.ndm_type = type;
|
|
|
|
req->ndm.ndm_state = state;
|
|
|
|
req->ndm.ndm_flags = flags;
|
|
|
|
req->ndm.ndm_ifindex = dplane_ctx_get_ifindex(ctx);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-07-16 15:49:05 +02:00
|
|
|
if (!nl_attr_put(&req->n, datalen, NDA_PROTOCOL, &protocol,
|
2020-06-10 11:44:31 +02:00
|
|
|
sizeof(protocol)))
|
|
|
|
return 0;
|
|
|
|
|
2021-02-25 11:12:34 +01:00
|
|
|
if (lla) {
|
|
|
|
if (!nl_attr_put(&req->n, datalen, NDA_LLADDR, lla, llalen))
|
2020-06-10 11:44:31 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2017-05-15 07:38:26 +02:00
|
|
|
|
2020-03-28 18:16:30 +01:00
|
|
|
if (nfy) {
|
2020-07-15 16:59:12 +02:00
|
|
|
struct rtattr *nest;
|
|
|
|
|
|
|
|
nest = nl_attr_nest(&req->n, datalen,
|
|
|
|
NDA_FDB_EXT_ATTRS | NLA_F_NESTED);
|
|
|
|
if (!nest)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!nl_attr_put(&req->n, datalen, NFEA_ACTIVITY_NOTIFY,
|
|
|
|
&nfy_flags, sizeof(nfy_flags)))
|
2020-03-28 18:16:30 +01:00
|
|
|
return 0;
|
2020-07-15 16:59:12 +02:00
|
|
|
if (!nl_attr_put(&req->n, datalen, NFEA_DONT_REFRESH, NULL, 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nl_attr_nest_end(&req->n, nest);
|
2020-03-28 18:16:30 +01:00
|
|
|
}
|
2020-03-28 00:36:24 +01:00
|
|
|
|
2020-07-15 16:59:12 +02:00
|
|
|
|
2020-05-08 16:42:07 +02:00
|
|
|
if (ext) {
|
|
|
|
if (!nl_attr_put(&req->n, datalen, NDA_EXT_FLAGS, &ext_flags,
|
|
|
|
sizeof(ext_flags)))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-27 18:50:46 +01:00
|
|
|
if (nhg_id) {
|
|
|
|
if (!nl_attr_put32(&req->n, datalen, NDA_NH_ID, nhg_id))
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
ipa_len =
|
|
|
|
IS_IPADDR_V4(ip) ? IPV4_MAX_BYTELEN : IPV6_MAX_BYTELEN;
|
|
|
|
if (!nl_attr_put(&req->n, datalen, NDA_DST, &ip->ip.addr,
|
|
|
|
ipa_len))
|
|
|
|
return 0;
|
|
|
|
}
|
2020-03-07 20:07:05 +01:00
|
|
|
|
|
|
|
if (op == DPLANE_OP_MAC_INSTALL || op == DPLANE_OP_MAC_DELETE) {
|
|
|
|
vlanid_t vid = dplane_ctx_mac_get_vlan(ctx);
|
2021-07-27 09:52:11 +02:00
|
|
|
vni_t vni = dplane_ctx_mac_get_vni(ctx);
|
2017-05-15 07:38:26 +02:00
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
if (vid > 0) {
|
|
|
|
if (!nl_attr_put16(&req->n, datalen, NDA_VLAN, vid))
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-15 07:38:26 +02:00
|
|
|
|
2021-07-27 09:52:11 +02:00
|
|
|
if (vni > 0) {
|
|
|
|
if (!nl_attr_put32(&req->n, datalen, NDA_SRC_VNI, vni))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!nl_attr_put32(&req->n, datalen, NDA_MASTER,
|
|
|
|
dplane_ctx_mac_get_br_ifindex(ctx)))
|
|
|
|
return 0;
|
2020-03-07 20:07:05 +01:00
|
|
|
}
|
2017-05-15 07:38:26 +02:00
|
|
|
|
2021-07-27 09:52:11 +02:00
|
|
|
if (op == DPLANE_OP_VTEP_ADD || op == DPLANE_OP_VTEP_DELETE) {
|
|
|
|
vni_t vni = dplane_ctx_neigh_get_vni(ctx);
|
|
|
|
|
|
|
|
if (vni > 0) {
|
|
|
|
if (!nl_attr_put32(&req->n, datalen, NDA_SRC_VNI, vni))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-09 16:36:18 +01:00
|
|
|
return NLMSG_ALIGN(req->n.nlmsg_len);
|
2017-05-15 07:38:26 +02:00
|
|
|
}
|
|
|
|
|
2020-03-07 20:07:05 +01:00
|
|
|
/*
|
|
|
|
* Add remote VTEP to the flood list for this VxLAN interface (VNI). This
|
|
|
|
* is done by adding an FDB entry with a MAC of 00:00:00:00:00:00.
|
|
|
|
*/
|
2020-07-15 15:14:08 +02:00
|
|
|
static ssize_t
|
|
|
|
netlink_vxlan_flood_update_ctx(const struct zebra_dplane_ctx *ctx, int cmd,
|
|
|
|
void *buf, size_t buflen)
|
2020-03-07 20:07:05 +01:00
|
|
|
{
|
|
|
|
struct ethaddr dst_mac = {.octet = {0}};
|
2021-04-05 21:40:37 +02:00
|
|
|
int proto = RTPROT_ZEBRA;
|
|
|
|
|
|
|
|
if (dplane_ctx_get_type(ctx) != 0)
|
|
|
|
proto = zebra2proto(dplane_ctx_get_type(ctx));
|
2019-12-09 16:36:18 +01:00
|
|
|
|
2020-07-15 15:14:08 +02:00
|
|
|
return netlink_neigh_update_msg_encode(
|
2021-02-25 11:12:34 +01:00
|
|
|
ctx, cmd, (const void *)&dst_mac, ETH_ALEN,
|
|
|
|
dplane_ctx_neigh_get_ipaddr(ctx), false, PF_BRIDGE, 0, NTF_SELF,
|
|
|
|
(NUD_NOARP | NUD_PERMANENT), 0 /*nhg*/, false /*nfy*/,
|
|
|
|
0 /*nfy_flags*/, false /*ext*/, 0 /*ext_flags*/, buf, buflen,
|
2021-04-05 21:40:37 +02:00
|
|
|
proto);
|
2020-03-07 20:07:05 +01:00
|
|
|
}
|
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
#ifndef NDA_RTA
|
|
|
|
#define NDA_RTA(r) \
|
|
|
|
((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
|
|
|
|
#endif
|
|
|
|
|
2018-05-23 15:37:06 +02:00
|
|
|
static int netlink_macfdb_change(struct nlmsghdr *h, int len, ns_id_t ns_id)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
|
|
|
struct ndmsg *ndm;
|
|
|
|
struct interface *ifp;
|
|
|
|
struct zebra_if *zif;
|
|
|
|
struct rtattr *tb[NDA_MAX + 1];
|
|
|
|
struct interface *br_if;
|
|
|
|
struct ethaddr mac;
|
|
|
|
vlanid_t vid = 0;
|
2019-09-06 06:11:07 +02:00
|
|
|
struct in_addr vtep_ip;
|
2017-05-15 07:44:13 +02:00
|
|
|
int vid_present = 0, dst_present = 0;
|
|
|
|
char vid_buf[20];
|
|
|
|
char dst_buf[30];
|
2018-09-10 19:13:20 +02:00
|
|
|
bool sticky;
|
2020-03-28 18:16:30 +01:00
|
|
|
bool local_inactive = false;
|
|
|
|
bool dp_static = false;
|
2021-07-27 09:47:52 +02:00
|
|
|
vni_t vni = 0;
|
2020-03-28 18:16:30 +01:00
|
|
|
uint32_t nhg_id = 0;
|
2021-07-27 09:47:52 +02:00
|
|
|
bool vni_mcast_grp = false;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
ndm = NLMSG_DATA(h);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-09-18 23:45:34 +02:00
|
|
|
/* We only process macfdb notifications if EVPN is enabled */
|
|
|
|
if (!is_evpn_enabled())
|
|
|
|
return 0;
|
|
|
|
|
2019-09-06 06:11:07 +02:00
|
|
|
/* Parse attributes and extract fields of interest. Do basic
|
|
|
|
* validation of the fields.
|
|
|
|
*/
|
2020-07-15 16:59:12 +02:00
|
|
|
netlink_parse_rtattr_flags(tb, NDA_MAX, NDA_RTA(ndm), len,
|
|
|
|
NLA_F_NESTED);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
if (!tb[NDA_LLADDR]) {
|
2019-03-08 16:46:55 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2019-09-06 06:11:07 +02:00
|
|
|
zlog_debug("%s AF_BRIDGE IF %u - no LLADDR",
|
2019-03-08 16:46:55 +01:00
|
|
|
nl_msg_type_to_str(h->nlmsg_type),
|
2019-09-06 06:11:07 +02:00
|
|
|
ndm->ndm_ifindex);
|
2017-05-15 07:44:13 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-08-03 14:43:56 +02:00
|
|
|
if (RTA_PAYLOAD(tb[NDA_LLADDR]) != ETH_ALEN) {
|
2019-03-08 16:46:55 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
2019-09-06 06:11:07 +02:00
|
|
|
"%s AF_BRIDGE IF %u - LLADDR is not MAC, len %lu",
|
|
|
|
nl_msg_type_to_str(h->nlmsg_type), ndm->ndm_ifindex,
|
2019-03-08 16:46:55 +01:00
|
|
|
(unsigned long)RTA_PAYLOAD(tb[NDA_LLADDR]));
|
2017-05-15 07:44:13 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-08-03 14:43:56 +02:00
|
|
|
memcpy(&mac, RTA_DATA(tb[NDA_LLADDR]), ETH_ALEN);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-03-30 11:44:36 +02:00
|
|
|
if (tb[NDA_VLAN]) {
|
2017-05-15 07:44:13 +02:00
|
|
|
vid_present = 1;
|
2018-03-27 21:13:34 +02:00
|
|
|
vid = *(uint16_t *)RTA_DATA(tb[NDA_VLAN]);
|
2020-04-20 20:12:38 +02:00
|
|
|
snprintf(vid_buf, sizeof(vid_buf), " VLAN %u", vid);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
if (tb[NDA_DST]) {
|
|
|
|
/* TODO: Only IPv4 supported now. */
|
|
|
|
dst_present = 1;
|
2019-09-06 06:11:07 +02:00
|
|
|
memcpy(&vtep_ip.s_addr, RTA_DATA(tb[NDA_DST]),
|
2017-05-15 07:44:13 +02:00
|
|
|
IPV4_MAX_BYTELEN);
|
2020-10-21 19:57:06 +02:00
|
|
|
snprintfrr(dst_buf, sizeof(dst_buf), " dst %pI4",
|
|
|
|
&vtep_ip);
|
2021-08-08 07:58:07 +02:00
|
|
|
} else
|
|
|
|
memset(&vtep_ip, 0, sizeof(vtep_ip));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-03-28 18:16:30 +01:00
|
|
|
if (tb[NDA_NH_ID])
|
|
|
|
nhg_id = *(uint32_t *)RTA_DATA(tb[NDA_NH_ID]);
|
|
|
|
|
|
|
|
if (ndm->ndm_state & NUD_STALE)
|
|
|
|
local_inactive = true;
|
|
|
|
|
2020-07-15 16:59:12 +02:00
|
|
|
if (tb[NDA_FDB_EXT_ATTRS]) {
|
|
|
|
struct rtattr *attr = tb[NDA_FDB_EXT_ATTRS];
|
|
|
|
struct rtattr *nfea_tb[NFEA_MAX + 1] = {0};
|
|
|
|
|
|
|
|
netlink_parse_rtattr_nested(nfea_tb, NFEA_MAX, attr);
|
|
|
|
if (nfea_tb[NFEA_ACTIVITY_NOTIFY]) {
|
|
|
|
uint8_t nfy_flags;
|
2020-03-28 18:16:30 +01:00
|
|
|
|
2020-07-15 16:59:12 +02:00
|
|
|
nfy_flags = *(uint8_t *)RTA_DATA(
|
|
|
|
nfea_tb[NFEA_ACTIVITY_NOTIFY]);
|
|
|
|
if (nfy_flags & FDB_NOTIFY_BIT)
|
|
|
|
dp_static = true;
|
|
|
|
if (nfy_flags & FDB_NOTIFY_INACTIVE_BIT)
|
|
|
|
local_inactive = true;
|
|
|
|
}
|
2020-03-28 18:16:30 +01:00
|
|
|
}
|
|
|
|
|
2021-07-27 09:47:52 +02:00
|
|
|
if (tb[NDA_SRC_VNI])
|
|
|
|
vni = *(vni_t *)RTA_DATA(tb[NDA_SRC_VNI]);
|
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2021-07-27 09:47:52 +02:00
|
|
|
zlog_debug(
|
|
|
|
"Rx %s AF_BRIDGE IF %u%s st 0x%x fl 0x%x MAC %pEA%s nhg %d vni %d",
|
|
|
|
nl_msg_type_to_str(h->nlmsg_type), ndm->ndm_ifindex,
|
|
|
|
vid_present ? vid_buf : "", ndm->ndm_state,
|
|
|
|
ndm->ndm_flags, &mac, dst_present ? dst_buf : "",
|
|
|
|
nhg_id, vni);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-09-06 06:11:07 +02:00
|
|
|
/* The interface should exist. */
|
|
|
|
ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id),
|
|
|
|
ndm->ndm_ifindex);
|
|
|
|
if (!ifp || !ifp->info)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* The interface should be something we're interested in. */
|
|
|
|
if (!IS_ZEBRA_IF_BRIDGE_SLAVE(ifp))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
zif = (struct zebra_if *)ifp->info;
|
|
|
|
if ((br_if = zif->brslave_info.br_if) == NULL) {
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
|
|
|
"%s AF_BRIDGE IF %s(%u) brIF %u - no bridge master",
|
|
|
|
nl_msg_type_to_str(h->nlmsg_type), ifp->name,
|
|
|
|
ndm->ndm_ifindex,
|
|
|
|
zif->brslave_info.bridge_ifindex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-27 09:47:52 +02:00
|
|
|
/* For per vni device, vni comes from device itself */
|
|
|
|
if (IS_ZEBRA_IF_VXLAN(ifp) && IS_ZEBRA_VXLAN_IF_VNI(zif)) {
|
|
|
|
struct zebra_vxlan_vni *vnip;
|
2021-07-27 18:29:00 +02:00
|
|
|
|
2021-07-27 09:47:52 +02:00
|
|
|
vnip = zebra_vxlan_if_vni_find(zif, 0);
|
|
|
|
vni = vnip->vni;
|
|
|
|
}
|
|
|
|
|
2020-03-28 18:16:30 +01:00
|
|
|
sticky = !!(ndm->ndm_flags & NTF_STICKY);
|
2019-09-06 06:11:07 +02:00
|
|
|
|
2019-03-08 16:46:55 +01:00
|
|
|
if (filter_vlan && vid != filter_vlan) {
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2020-03-24 17:38:20 +01:00
|
|
|
zlog_debug(" Filtered due to filter vlan: %d",
|
2019-03-08 16:46:55 +01:00
|
|
|
filter_vlan);
|
2017-05-15 07:44:13 +02:00
|
|
|
return 0;
|
2019-03-08 16:46:55 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2021-07-27 09:47:52 +02:00
|
|
|
/*
|
|
|
|
* Check if this is a mcast group update (svd case)
|
|
|
|
*/
|
|
|
|
vni_mcast_grp = is_mac_vni_mcast_group(&mac, vni, vtep_ip);
|
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
/* If add or update, do accordingly if learnt on a "local" interface; if
|
|
|
|
* the notification is over VxLAN, this has to be related to
|
|
|
|
* multi-homing,
|
|
|
|
* so perform an implicit delete of any local entry (if it exists).
|
|
|
|
*/
|
|
|
|
if (h->nlmsg_type == RTM_NEWNEIGH) {
|
2019-09-06 06:11:07 +02:00
|
|
|
/* Drop "permanent" entries. */
|
2021-07-27 09:47:52 +02:00
|
|
|
if (!vni_mcast_grp && (ndm->ndm_state & NUD_PERMANENT)) {
|
2019-09-06 06:11:07 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2020-03-24 17:38:20 +01:00
|
|
|
zlog_debug(
|
|
|
|
" Dropping entry because of NUD_PERMANENT");
|
|
|
|
return 0;
|
2019-09-06 06:11:07 +02:00
|
|
|
}
|
|
|
|
|
2021-07-27 09:47:52 +02:00
|
|
|
if (IS_ZEBRA_IF_VXLAN(ifp)) {
|
|
|
|
if (!dst_present)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (vni_mcast_grp)
|
2021-10-19 13:01:50 +02:00
|
|
|
return zebra_vxlan_if_vni_mcast_group_add_update(
|
2021-07-27 10:48:05 +02:00
|
|
|
ifp, vni, &vtep_ip);
|
2021-07-27 09:47:52 +02:00
|
|
|
|
2021-07-27 10:48:05 +02:00
|
|
|
return zebra_vxlan_dp_network_mac_add(
|
|
|
|
ifp, br_if, &mac, vid, vni, nhg_id, sticky,
|
|
|
|
!!(ndm->ndm_flags & NTF_EXT_LEARNED));
|
2021-07-27 09:47:52 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 23:42:57 +02:00
|
|
|
return zebra_vxlan_local_mac_add_update(ifp, br_if, &mac, vid,
|
2020-03-28 18:16:30 +01:00
|
|
|
sticky, local_inactive, dp_static);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
/* This is a delete notification.
|
2019-09-06 06:11:07 +02:00
|
|
|
* Ignore the notification with IP dest as it may just signify that the
|
|
|
|
* MAC has moved from remote to local. The exception is the special
|
|
|
|
* all-zeros MAC that represents the BUM flooding entry; we may have
|
|
|
|
* to readd it. Otherwise,
|
2017-05-15 07:44:13 +02:00
|
|
|
* 1. For a MAC over VxLan, check if it needs to be refreshed(readded)
|
|
|
|
* 2. For a MAC over "local" interface, delete the mac
|
|
|
|
* Note: We will get notifications from both bridge driver and VxLAN
|
|
|
|
* driver.
|
|
|
|
*/
|
2020-03-28 18:16:30 +01:00
|
|
|
if (nhg_id)
|
|
|
|
return 0;
|
|
|
|
|
2019-03-08 16:46:55 +01:00
|
|
|
if (dst_present) {
|
2021-07-27 09:47:52 +02:00
|
|
|
if (vni_mcast_grp)
|
2021-10-19 13:01:50 +02:00
|
|
|
return zebra_vxlan_if_vni_mcast_group_del(ifp, vni,
|
|
|
|
&vtep_ip);
|
2021-07-27 09:47:52 +02:00
|
|
|
|
2022-11-22 22:41:54 +01:00
|
|
|
if (is_zero_mac(&mac) && vni)
|
2021-07-27 10:48:05 +02:00
|
|
|
return zebra_vxlan_check_readd_vtep(ifp, vni, vtep_ip);
|
2019-09-06 06:11:07 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
return 0;
|
2019-03-08 16:46:55 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
if (IS_ZEBRA_IF_VXLAN(ifp))
|
2021-07-27 09:47:52 +02:00
|
|
|
return 0;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
return zebra_vxlan_local_mac_del(ifp, br_if, &mac, vid);
|
|
|
|
}
|
|
|
|
|
2018-05-23 15:37:06 +02:00
|
|
|
static int netlink_macfdb_table(struct nlmsghdr *h, ns_id_t ns_id, int startup)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
struct ndmsg *ndm;
|
|
|
|
|
|
|
|
if (h->nlmsg_type != RTM_NEWNEIGH)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Length validity. */
|
|
|
|
len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ndmsg));
|
|
|
|
if (len < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* We are interested only in AF_BRIDGE notifications. */
|
|
|
|
ndm = NLMSG_DATA(h);
|
|
|
|
if (ndm->ndm_family != AF_BRIDGE)
|
|
|
|
return 0;
|
|
|
|
|
2018-05-23 15:37:06 +02:00
|
|
|
return netlink_macfdb_change(h, len, ns_id);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Request for MAC FDB information from the kernel */
|
2018-09-12 20:59:57 +02:00
|
|
|
static int netlink_request_macs(struct nlsock *netlink_cmd, int family,
|
|
|
|
int type, ifindex_t master_ifindex)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct ifinfomsg ifm;
|
|
|
|
char buf[256];
|
|
|
|
} req;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
/* Form the request, specifying filter (rtattr) if needed. */
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
req.n.nlmsg_type = type;
|
2018-12-11 06:33:16 +01:00
|
|
|
req.n.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST;
|
2017-05-15 07:44:13 +02:00
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
|
|
|
req.ifm.ifi_family = family;
|
|
|
|
if (master_ifindex)
|
2020-06-08 23:37:26 +02:00
|
|
|
nl_attr_put32(&req.n, sizeof(req), IFLA_MASTER, master_ifindex);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-04-15 14:56:03 +02:00
|
|
|
return netlink_request(netlink_cmd, &req);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MAC forwarding database read using netlink interface. This is invoked
|
|
|
|
* at startup.
|
|
|
|
*/
|
|
|
|
int netlink_macfdb_read(struct zebra_ns *zns)
|
|
|
|
{
|
|
|
|
int ret;
|
2018-09-12 20:59:57 +02:00
|
|
|
struct zebra_dplane_info dp_info;
|
|
|
|
|
|
|
|
zebra_dplane_info_from_zns(&dp_info, zns, true /*is_cmd*/);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
/* Get bridge FDB table. */
|
2018-09-12 20:59:57 +02:00
|
|
|
ret = netlink_request_macs(&zns->netlink_cmd, AF_BRIDGE, RTM_GETNEIGH,
|
|
|
|
0);
|
2017-05-15 07:44:13 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
/* We are reading entire table. */
|
|
|
|
filter_vlan = 0;
|
2018-09-12 20:59:57 +02:00
|
|
|
ret = netlink_parse_info(netlink_macfdb_table, &zns->netlink_cmd,
|
2021-10-05 02:26:38 +02:00
|
|
|
&dp_info, 0, true);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MAC forwarding database read using netlink interface. This is for a
|
|
|
|
* specific bridge and matching specific access VLAN (if VLAN-aware bridge).
|
|
|
|
*/
|
|
|
|
int netlink_macfdb_read_for_bridge(struct zebra_ns *zns, struct interface *ifp,
|
2021-07-27 09:47:52 +02:00
|
|
|
struct interface *br_if, vlanid_t vid)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
|
|
|
struct zebra_if *br_zif;
|
2018-09-12 20:59:57 +02:00
|
|
|
struct zebra_dplane_info dp_info;
|
2017-05-15 07:44:13 +02:00
|
|
|
int ret = 0;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-09-12 20:59:57 +02:00
|
|
|
zebra_dplane_info_from_zns(&dp_info, zns, true /*is_cmd*/);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
/* Save VLAN we're filtering on, if needed. */
|
|
|
|
br_zif = (struct zebra_if *)br_if->info;
|
|
|
|
if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif))
|
2021-07-27 09:47:52 +02:00
|
|
|
filter_vlan = vid;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
/* Get bridge FDB table for specific bridge - we do the VLAN filtering.
|
|
|
|
*/
|
2018-09-12 20:59:57 +02:00
|
|
|
ret = netlink_request_macs(&zns->netlink_cmd, AF_BRIDGE, RTM_GETNEIGH,
|
2017-05-15 07:44:13 +02:00
|
|
|
br_if->ifindex);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2018-09-12 20:59:57 +02:00
|
|
|
ret = netlink_parse_info(netlink_macfdb_table, &zns->netlink_cmd,
|
2021-10-05 02:26:38 +02:00
|
|
|
&dp_info, 0, false);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
/* Reset VLAN filter. */
|
|
|
|
filter_vlan = 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-12-11 06:33:16 +01:00
|
|
|
|
|
|
|
/* Request for MAC FDB for a specific MAC address in VLAN from the kernel */
|
2021-07-27 18:29:00 +02:00
|
|
|
static int netlink_request_specific_mac(struct zebra_ns *zns, int family,
|
|
|
|
int type, struct interface *ifp,
|
|
|
|
const struct ethaddr *mac, vlanid_t vid,
|
|
|
|
vni_t vni, uint8_t flags)
|
2018-12-11 06:33:16 +01:00
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct ndmsg ndm;
|
|
|
|
char buf[256];
|
|
|
|
} req;
|
2021-07-27 18:29:00 +02:00
|
|
|
struct zebra_if *zif;
|
2018-12-11 06:33:16 +01:00
|
|
|
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
|
|
|
|
req.n.nlmsg_type = type; /* RTM_GETNEIGH */
|
|
|
|
req.n.nlmsg_flags = NLM_F_REQUEST;
|
|
|
|
req.ndm.ndm_family = family; /* AF_BRIDGE */
|
2021-07-27 18:29:00 +02:00
|
|
|
req.ndm.ndm_flags = flags;
|
2018-12-11 06:33:16 +01:00
|
|
|
/* req.ndm.ndm_state = NUD_REACHABLE; */
|
|
|
|
|
2020-06-08 23:37:26 +02:00
|
|
|
nl_attr_put(&req.n, sizeof(req), NDA_LLADDR, mac, 6);
|
2018-12-11 06:33:16 +01:00
|
|
|
|
2021-07-27 18:29:00 +02:00
|
|
|
zif = (struct zebra_if *)ifp->info;
|
|
|
|
/* Is this a read on a VXLAN interface? */
|
|
|
|
if (IS_ZEBRA_IF_VXLAN(ifp)) {
|
|
|
|
nl_attr_put32(&req.n, sizeof(req), NDA_VNI, vni);
|
|
|
|
/* TBD: Why is ifindex not filled in the non-vxlan case? */
|
|
|
|
req.ndm.ndm_ifindex = ifp->ifindex;
|
|
|
|
} else {
|
|
|
|
if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(zif) && vid > 0)
|
|
|
|
nl_attr_put16(&req.n, sizeof(req), NDA_VLAN, vid);
|
|
|
|
nl_attr_put32(&req.n, sizeof(req), NDA_MASTER, ifp->ifindex);
|
|
|
|
}
|
2018-12-11 06:33:16 +01:00
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2021-07-27 18:29:00 +02:00
|
|
|
zlog_debug("Tx %s %s IF %s(%u) MAC %pEA vid %u vni %u",
|
|
|
|
nl_msg_type_to_str(type),
|
|
|
|
nl_family_to_str(req.ndm.ndm_family), ifp->name,
|
|
|
|
ifp->ifindex, mac, vid, vni);
|
2018-12-11 06:33:16 +01:00
|
|
|
|
2020-04-15 14:56:03 +02:00
|
|
|
return netlink_request(&zns->netlink_cmd, &req);
|
2018-12-11 06:33:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int netlink_macfdb_read_specific_mac(struct zebra_ns *zns,
|
|
|
|
struct interface *br_if,
|
2021-04-19 20:26:57 +02:00
|
|
|
const struct ethaddr *mac, vlanid_t vid)
|
2018-12-11 06:33:16 +01:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct zebra_dplane_info dp_info;
|
|
|
|
|
|
|
|
zebra_dplane_info_from_zns(&dp_info, zns, true /*is_cmd*/);
|
|
|
|
|
|
|
|
/* Get bridge FDB table for specific bridge - we do the VLAN filtering.
|
|
|
|
*/
|
2021-07-27 18:29:00 +02:00
|
|
|
ret = netlink_request_specific_mac(zns, AF_BRIDGE, RTM_GETNEIGH, br_if,
|
|
|
|
mac, vid, 0, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = netlink_parse_info(netlink_macfdb_table, &zns->netlink_cmd,
|
|
|
|
&dp_info, 1, 0);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int netlink_macfdb_read_mcast_for_vni(struct zebra_ns *zns,
|
|
|
|
struct interface *ifp, vni_t vni)
|
|
|
|
{
|
|
|
|
struct zebra_if *zif;
|
2022-12-10 00:51:22 +01:00
|
|
|
struct ethaddr mac = {.octet = {0}};
|
2021-07-27 18:29:00 +02:00
|
|
|
struct zebra_dplane_info dp_info;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
zif = ifp->info;
|
|
|
|
if (IS_ZEBRA_VXLAN_IF_VNI(zif))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
zebra_dplane_info_from_zns(&dp_info, zns, true /*is_cmd*/);
|
|
|
|
|
|
|
|
/* Get specific FDB entry for BUM handling, if any */
|
|
|
|
ret = netlink_request_specific_mac(zns, AF_BRIDGE, RTM_GETNEIGH, ifp,
|
|
|
|
&mac, 0, vni, NTF_SELF);
|
2018-12-11 06:33:16 +01:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = netlink_parse_info(netlink_macfdb_table, &zns->netlink_cmd,
|
2021-10-05 02:26:38 +02:00
|
|
|
&dp_info, 1, false);
|
2018-12-11 06:33:16 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2019-07-30 17:54:07 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Netlink-specific handler for MAC updates using dataplane context object.
|
|
|
|
*/
|
2020-07-15 15:14:08 +02:00
|
|
|
ssize_t netlink_macfdb_update_ctx(struct zebra_dplane_ctx *ctx, void *data,
|
|
|
|
size_t datalen)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
2020-03-07 20:07:05 +01:00
|
|
|
struct ipaddr vtep_ip;
|
2019-07-30 17:54:07 +02:00
|
|
|
vlanid_t vid;
|
2019-12-09 16:36:18 +01:00
|
|
|
ssize_t total;
|
|
|
|
int cmd;
|
2020-03-07 20:07:05 +01:00
|
|
|
uint8_t flags;
|
|
|
|
uint16_t state;
|
2020-03-28 00:36:24 +01:00
|
|
|
uint32_t nhg_id;
|
2020-03-28 18:16:30 +01:00
|
|
|
uint32_t update_flags;
|
|
|
|
bool nfy = false;
|
|
|
|
uint8_t nfy_flags = 0;
|
2021-04-05 21:40:37 +02:00
|
|
|
int proto = RTPROT_ZEBRA;
|
|
|
|
|
|
|
|
if (dplane_ctx_get_type(ctx) != 0)
|
|
|
|
proto = zebra2proto(dplane_ctx_get_type(ctx));
|
2019-12-09 16:36:18 +01:00
|
|
|
|
|
|
|
cmd = dplane_ctx_get_op(ctx) == DPLANE_OP_MAC_INSTALL
|
|
|
|
? RTM_NEWNEIGH : RTM_DELNEIGH;
|
2019-07-30 17:54:07 +02:00
|
|
|
|
2020-03-28 18:16:30 +01:00
|
|
|
flags = NTF_MASTER;
|
2020-03-07 20:07:05 +01:00
|
|
|
state = NUD_REACHABLE;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-03-28 18:16:30 +01:00
|
|
|
update_flags = dplane_ctx_mac_get_update_flags(ctx);
|
|
|
|
if (update_flags & DPLANE_MAC_REMOTE) {
|
|
|
|
flags |= NTF_SELF;
|
2020-05-09 04:53:36 +02:00
|
|
|
if (dplane_ctx_mac_is_sticky(ctx)) {
|
|
|
|
/* NUD_NOARP prevents the entry from expiring */
|
|
|
|
state |= NUD_NOARP;
|
|
|
|
/* sticky the entry from moving */
|
2020-03-28 18:16:30 +01:00
|
|
|
flags |= NTF_STICKY;
|
2020-05-09 04:53:36 +02:00
|
|
|
} else {
|
2020-03-28 18:16:30 +01:00
|
|
|
flags |= NTF_EXT_LEARNED;
|
2020-05-09 04:53:36 +02:00
|
|
|
}
|
2020-03-28 18:16:30 +01:00
|
|
|
/* if it was static-local previously we need to clear the
|
|
|
|
* notify flags on replace with remote
|
|
|
|
*/
|
|
|
|
if (update_flags & DPLANE_MAC_WAS_STATIC)
|
|
|
|
nfy = true;
|
|
|
|
} else {
|
|
|
|
/* local mac */
|
|
|
|
if (update_flags & DPLANE_MAC_SET_STATIC) {
|
2020-07-15 16:59:12 +02:00
|
|
|
nfy_flags |= FDB_NOTIFY_BIT;
|
2020-03-28 18:16:30 +01:00
|
|
|
state |= NUD_NOARP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_flags & DPLANE_MAC_SET_INACTIVE)
|
2020-07-15 16:59:12 +02:00
|
|
|
nfy_flags |= FDB_NOTIFY_INACTIVE_BIT;
|
2020-03-28 18:16:30 +01:00
|
|
|
|
|
|
|
nfy = true;
|
|
|
|
}
|
2019-09-05 18:58:58 +02:00
|
|
|
|
2020-03-28 00:36:24 +01:00
|
|
|
nhg_id = dplane_ctx_mac_get_nhg_id(ctx);
|
2020-03-07 20:07:05 +01:00
|
|
|
vtep_ip.ipaddr_v4 = *(dplane_ctx_mac_get_vtep_ip(ctx));
|
|
|
|
SET_IPADDR_V4(&vtep_ip);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-07-30 17:54:07 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL) {
|
2019-09-05 18:58:58 +02:00
|
|
|
char vid_buf[20];
|
2020-03-28 00:36:24 +01:00
|
|
|
const struct ethaddr *mac = dplane_ctx_mac_get_addr(ctx);
|
2019-09-05 18:58:58 +02:00
|
|
|
|
2020-03-07 20:07:05 +01:00
|
|
|
vid = dplane_ctx_mac_get_vlan(ctx);
|
|
|
|
if (vid > 0)
|
2019-09-05 18:58:58 +02:00
|
|
|
snprintf(vid_buf, sizeof(vid_buf), " VLAN %u", vid);
|
|
|
|
else
|
|
|
|
vid_buf[0] = '\0';
|
2019-07-30 17:54:07 +02:00
|
|
|
|
2020-05-08 16:42:07 +02:00
|
|
|
zlog_debug(
|
2021-03-12 02:44:45 +01:00
|
|
|
"Tx %s family %s IF %s(%u)%s %sMAC %pEA dst %pIA nhg %u%s%s%s%s%s",
|
2020-05-08 16:42:07 +02:00
|
|
|
nl_msg_type_to_str(cmd), nl_family_to_str(AF_BRIDGE),
|
|
|
|
dplane_ctx_get_ifname(ctx), dplane_ctx_get_ifindex(ctx),
|
|
|
|
vid_buf, dplane_ctx_mac_is_sticky(ctx) ? "sticky " : "",
|
2021-03-12 02:44:45 +01:00
|
|
|
mac, &vtep_ip, nhg_id,
|
2020-05-08 16:42:07 +02:00
|
|
|
(update_flags & DPLANE_MAC_REMOTE) ? " rem" : "",
|
|
|
|
(update_flags & DPLANE_MAC_WAS_STATIC) ? " clr_sync"
|
|
|
|
: "",
|
|
|
|
(update_flags & DPLANE_MAC_SET_STATIC) ? " static" : "",
|
|
|
|
(update_flags & DPLANE_MAC_SET_INACTIVE) ? " inactive"
|
|
|
|
: "",
|
|
|
|
nfy ? " nfy" : "");
|
2019-07-30 17:54:07 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
total = netlink_neigh_update_msg_encode(
|
2021-02-25 11:12:34 +01:00
|
|
|
ctx, cmd, (const void *)dplane_ctx_mac_get_addr(ctx), ETH_ALEN,
|
|
|
|
&vtep_ip, true, AF_BRIDGE, 0, flags, state, nhg_id, nfy,
|
|
|
|
nfy_flags, false /*ext*/, 0 /*ext_flags*/, data, datalen,
|
2021-04-05 21:40:37 +02:00
|
|
|
proto);
|
2019-12-09 16:36:18 +01:00
|
|
|
|
|
|
|
return total;
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
2018-11-28 16:57:01 +01:00
|
|
|
/*
|
|
|
|
* In the event the kernel deletes ipv4 link-local neighbor entries created for
|
|
|
|
* 5549 support, re-install them.
|
|
|
|
*/
|
|
|
|
static void netlink_handle_5549(struct ndmsg *ndm, struct zebra_if *zif,
|
2019-06-20 11:37:17 +02:00
|
|
|
struct interface *ifp, struct ipaddr *ip,
|
|
|
|
bool handle_failed)
|
2018-11-28 16:57:01 +01:00
|
|
|
{
|
|
|
|
if (ndm->ndm_family != AF_INET)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!zif->v6_2_v4_ll_neigh_entry)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ipv4_ll.s_addr != ip->ip._v4_addr.s_addr)
|
|
|
|
return;
|
|
|
|
|
2019-06-20 11:37:17 +02:00
|
|
|
if (handle_failed && ndm->ndm_state & NUD_FAILED) {
|
|
|
|
zlog_info("Neighbor Entry for %s has entered a failed state, not reinstalling",
|
|
|
|
ifp->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-28 16:57:01 +01:00
|
|
|
if_nbr_ipv6ll_to_ipv4ll_neigh_update(ifp, &zif->v6_2_v4_ll_addr6, true);
|
|
|
|
}
|
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
#define NUD_VALID \
|
|
|
|
(NUD_PERMANENT | NUD_NOARP | NUD_REACHABLE | NUD_PROBE | NUD_STALE \
|
|
|
|
| NUD_DELAY)
|
2020-03-28 18:16:30 +01:00
|
|
|
#define NUD_LOCAL_ACTIVE \
|
|
|
|
(NUD_PERMANENT | NUD_NOARP | NUD_REACHABLE)
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2021-08-25 11:46:42 +02:00
|
|
|
static int netlink_nbr_entry_state_to_zclient(int nbr_state)
|
|
|
|
{
|
|
|
|
/* an exact match is done between
|
|
|
|
* - netlink neighbor state values: NDM_XXX (see in linux/neighbour.h)
|
|
|
|
* - zclient neighbor state values: ZEBRA_NEIGH_STATE_XXX
|
|
|
|
* (see in lib/zclient.h)
|
|
|
|
*/
|
|
|
|
return nbr_state;
|
|
|
|
}
|
2018-05-23 15:37:06 +02:00
|
|
|
static int netlink_ipneigh_change(struct nlmsghdr *h, int len, ns_id_t ns_id)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
|
|
|
struct ndmsg *ndm;
|
|
|
|
struct interface *ifp;
|
|
|
|
struct zebra_if *zif;
|
|
|
|
struct rtattr *tb[NDA_MAX + 1];
|
|
|
|
struct interface *link_if;
|
|
|
|
struct ethaddr mac;
|
|
|
|
struct ipaddr ip;
|
|
|
|
char buf[ETHER_ADDR_STRLEN];
|
|
|
|
int mac_present = 0;
|
2018-09-10 19:13:20 +02:00
|
|
|
bool is_ext;
|
|
|
|
bool is_router;
|
2020-03-28 18:16:30 +01:00
|
|
|
bool local_inactive;
|
2020-08-08 03:32:52 +02:00
|
|
|
uint32_t ext_flags = 0;
|
|
|
|
bool dp_static = false;
|
2019-12-12 16:06:59 +01:00
|
|
|
int l2_len = 0;
|
|
|
|
int cmd;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
ndm = NLMSG_DATA(h);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
/* The interface should exist. */
|
2017-12-19 12:23:32 +01:00
|
|
|
ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id),
|
2017-05-15 07:44:13 +02:00
|
|
|
ndm->ndm_ifindex);
|
2017-09-18 23:45:34 +02:00
|
|
|
if (!ifp || !ifp->info)
|
2017-05-15 07:44:13 +02:00
|
|
|
return 0;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-04-09 14:04:39 +02:00
|
|
|
zif = (struct zebra_if *)ifp->info;
|
|
|
|
|
|
|
|
/* Parse attributes and extract fields of interest. */
|
|
|
|
netlink_parse_rtattr(tb, NDA_MAX, NDA_RTA(ndm), len);
|
|
|
|
|
|
|
|
if (!tb[NDA_DST]) {
|
2020-03-15 19:42:30 +01:00
|
|
|
zlog_debug("%s family %s IF %s(%u) vrf %s(%u) - no DST",
|
2018-08-16 22:10:32 +02:00
|
|
|
nl_msg_type_to_str(h->nlmsg_type),
|
|
|
|
nl_family_to_str(ndm->ndm_family), ifp->name,
|
2021-10-22 00:17:40 +02:00
|
|
|
ndm->ndm_ifindex, ifp->vrf->name, ifp->vrf->vrf_id);
|
2017-05-15 07:44:13 +02:00
|
|
|
return 0;
|
2018-04-09 14:04:39 +02:00
|
|
|
}
|
|
|
|
|
2022-05-11 12:16:44 +02:00
|
|
|
memset(&ip, 0, sizeof(ip));
|
2018-04-09 14:04:39 +02:00
|
|
|
ip.ipa_type = (ndm->ndm_family == AF_INET) ? IPADDR_V4 : IPADDR_V6;
|
|
|
|
memcpy(&ip.ip.addr, RTA_DATA(tb[NDA_DST]), RTA_PAYLOAD(tb[NDA_DST]));
|
|
|
|
|
2018-11-28 16:57:01 +01:00
|
|
|
/* if kernel deletes our rfc5549 neighbor entry, re-install it */
|
|
|
|
if (h->nlmsg_type == RTM_DELNEIGH && (ndm->ndm_state & NUD_PERMANENT)) {
|
2019-06-20 11:37:17 +02:00
|
|
|
netlink_handle_5549(ndm, zif, ifp, &ip, false);
|
2019-03-08 16:46:55 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
2021-02-14 15:35:07 +01:00
|
|
|
" Neighbor Entry Received is a 5549 entry, finished");
|
2018-04-09 14:04:39 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-11-28 16:57:01 +01:00
|
|
|
/* if kernel marks our rfc5549 neighbor entry invalid, re-install it */
|
2019-06-20 11:37:17 +02:00
|
|
|
if (h->nlmsg_type == RTM_NEWNEIGH && !(ndm->ndm_state & NUD_VALID))
|
|
|
|
netlink_handle_5549(ndm, zif, ifp, &ip, true);
|
2018-11-28 16:57:01 +01:00
|
|
|
|
2019-12-12 16:06:59 +01:00
|
|
|
/* we send link layer information to client:
|
|
|
|
* - nlmsg_type = RTM_DELNEIGH|NEWNEIGH|GETNEIGH
|
|
|
|
* - struct ipaddr ( for DEL and GET)
|
|
|
|
* - struct ethaddr mac; (for NEW)
|
|
|
|
*/
|
|
|
|
if (h->nlmsg_type == RTM_NEWNEIGH)
|
|
|
|
cmd = ZEBRA_NHRP_NEIGH_ADDED;
|
|
|
|
else if (h->nlmsg_type == RTM_GETNEIGH)
|
|
|
|
cmd = ZEBRA_NHRP_NEIGH_GET;
|
|
|
|
else if (h->nlmsg_type == RTM_DELNEIGH)
|
|
|
|
cmd = ZEBRA_NHRP_NEIGH_REMOVED;
|
|
|
|
else {
|
|
|
|
zlog_debug("%s(): unknown nlmsg type %u", __func__,
|
|
|
|
h->nlmsg_type);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (tb[NDA_LLADDR]) {
|
|
|
|
/* copy LLADDR information */
|
|
|
|
l2_len = RTA_PAYLOAD(tb[NDA_LLADDR]);
|
|
|
|
}
|
2021-03-17 18:12:26 +01:00
|
|
|
if (l2_len == IPV4_MAX_BYTELEN || l2_len == 0) {
|
|
|
|
union sockunion link_layer_ipv4;
|
|
|
|
|
|
|
|
if (l2_len) {
|
|
|
|
sockunion_family(&link_layer_ipv4) = AF_INET;
|
|
|
|
memcpy((void *)sockunion_get_addr(&link_layer_ipv4),
|
2021-09-28 14:44:51 +02:00
|
|
|
RTA_DATA(tb[NDA_LLADDR]), l2_len);
|
2021-03-17 18:12:26 +01:00
|
|
|
} else
|
|
|
|
sockunion_family(&link_layer_ipv4) = AF_UNSPEC;
|
2021-08-25 11:46:42 +02:00
|
|
|
zsend_nhrp_neighbor_notify(
|
|
|
|
cmd, ifp, &ip,
|
|
|
|
netlink_nbr_entry_state_to_zclient(ndm->ndm_state),
|
|
|
|
&link_layer_ipv4);
|
2021-03-17 18:12:26 +01:00
|
|
|
}
|
2019-12-12 16:06:59 +01:00
|
|
|
|
|
|
|
if (h->nlmsg_type == RTM_GETNEIGH)
|
|
|
|
return 0;
|
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
/* The neighbor is present on an SVI. From this, we locate the
|
|
|
|
* underlying
|
|
|
|
* bridge because we're only interested in neighbors on a VxLAN bridge.
|
|
|
|
* The bridge is located based on the nature of the SVI:
|
|
|
|
* (a) In the case of a VLAN-aware bridge, the SVI is a L3 VLAN
|
|
|
|
* interface
|
|
|
|
* and is linked to the bridge
|
|
|
|
* (b) In the case of a VLAN-unaware bridge, the SVI is the bridge
|
2022-04-19 14:21:31 +02:00
|
|
|
* interface
|
2017-05-15 07:44:13 +02:00
|
|
|
* itself
|
|
|
|
*/
|
|
|
|
if (IS_ZEBRA_IF_VLAN(ifp)) {
|
2017-12-19 12:23:32 +01:00
|
|
|
link_if = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id),
|
2017-08-20 02:28:58 +02:00
|
|
|
zif->link_ifindex);
|
2017-05-15 07:44:13 +02:00
|
|
|
if (!link_if)
|
|
|
|
return 0;
|
|
|
|
} else if (IS_ZEBRA_IF_BRIDGE(ifp))
|
|
|
|
link_if = ifp;
|
2019-03-08 16:46:55 +01:00
|
|
|
else {
|
2021-12-18 20:28:49 +01:00
|
|
|
link_if = NULL;
|
2019-03-08 16:46:55 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
2021-02-14 15:35:07 +01:00
|
|
|
" Neighbor Entry received is not on a VLAN or a BRIDGE, ignoring");
|
2019-03-08 16:46:55 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2022-05-11 12:16:44 +02:00
|
|
|
memset(&mac, 0, sizeof(mac));
|
2017-05-15 07:44:13 +02:00
|
|
|
if (h->nlmsg_type == RTM_NEWNEIGH) {
|
|
|
|
if (tb[NDA_LLADDR]) {
|
2017-08-03 14:43:56 +02:00
|
|
|
if (RTA_PAYLOAD(tb[NDA_LLADDR]) != ETH_ALEN) {
|
2019-03-08 16:46:55 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
2020-03-15 19:42:30 +01:00
|
|
|
"%s family %s IF %s(%u) vrf %s(%u) - LLADDR is not MAC, len %lu",
|
2019-03-08 16:46:55 +01:00
|
|
|
nl_msg_type_to_str(
|
|
|
|
h->nlmsg_type),
|
|
|
|
nl_family_to_str(
|
|
|
|
ndm->ndm_family),
|
|
|
|
ifp->name, ndm->ndm_ifindex,
|
2021-10-22 00:17:40 +02:00
|
|
|
ifp->vrf->name,
|
|
|
|
ifp->vrf->vrf_id,
|
2019-03-08 16:46:55 +01:00
|
|
|
(unsigned long)RTA_PAYLOAD(
|
|
|
|
tb[NDA_LLADDR]));
|
2017-05-15 07:44:13 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
mac_present = 1;
|
2017-08-03 14:43:56 +02:00
|
|
|
memcpy(&mac, RTA_DATA(tb[NDA_LLADDR]), ETH_ALEN);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-09-10 19:13:20 +02:00
|
|
|
is_ext = !!(ndm->ndm_flags & NTF_EXT_LEARNED);
|
|
|
|
is_router = !!(ndm->ndm_flags & NTF_ROUTER);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-08-08 03:32:52 +02:00
|
|
|
if (tb[NDA_EXT_FLAGS]) {
|
|
|
|
ext_flags = *(uint32_t *)RTA_DATA(tb[NDA_EXT_FLAGS]);
|
|
|
|
if (ext_flags & NTF_E_MH_PEER_SYNC)
|
|
|
|
dp_static = true;
|
|
|
|
}
|
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
2021-03-12 02:44:45 +01:00
|
|
|
"Rx %s family %s IF %s(%u) vrf %s(%u) IP %pIA MAC %s state 0x%x flags 0x%x ext_flags 0x%x",
|
2017-05-15 07:44:13 +02:00
|
|
|
nl_msg_type_to_str(h->nlmsg_type),
|
|
|
|
nl_family_to_str(ndm->ndm_family), ifp->name,
|
2021-10-22 00:17:40 +02:00
|
|
|
ndm->ndm_ifindex, ifp->vrf->name,
|
|
|
|
ifp->vrf->vrf_id, &ip,
|
2017-05-15 07:44:13 +02:00
|
|
|
mac_present
|
|
|
|
? prefix_mac2str(&mac, buf, sizeof(buf))
|
|
|
|
: "",
|
2020-08-08 03:32:52 +02:00
|
|
|
ndm->ndm_state, ndm->ndm_flags, ext_flags);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
/* If the neighbor state is valid for use, process as an add or
|
|
|
|
* update
|
|
|
|
* else process as a delete. Note that the delete handling may
|
|
|
|
* result
|
|
|
|
* in re-adding the neighbor if it is a valid "remote" neighbor.
|
|
|
|
*/
|
2020-03-28 18:16:30 +01:00
|
|
|
if (ndm->ndm_state & NUD_VALID) {
|
2020-07-07 03:01:41 +02:00
|
|
|
if (zebra_evpn_mh_do_adv_reachable_neigh_only())
|
|
|
|
local_inactive =
|
|
|
|
!(ndm->ndm_state & NUD_LOCAL_ACTIVE);
|
|
|
|
else
|
|
|
|
/* If EVPN-MH is not enabled we treat STALE
|
|
|
|
* neighbors as locally-active and advertise
|
|
|
|
* them
|
|
|
|
*/
|
|
|
|
local_inactive = false;
|
2020-03-28 18:16:30 +01:00
|
|
|
|
2021-12-18 20:28:49 +01:00
|
|
|
/* Add local neighbors to the l3 interface database */
|
|
|
|
if (is_ext)
|
|
|
|
zebra_neigh_del(ifp, &ip);
|
|
|
|
else
|
|
|
|
zebra_neigh_add(ifp, &ip, &mac);
|
|
|
|
|
|
|
|
if (link_if)
|
|
|
|
zebra_vxlan_handle_kernel_neigh_update(
|
|
|
|
ifp, link_if, &ip, &mac, ndm->ndm_state,
|
|
|
|
is_ext, is_router, local_inactive,
|
|
|
|
dp_static);
|
|
|
|
return 0;
|
2020-03-28 18:16:30 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2021-12-18 20:28:49 +01:00
|
|
|
|
|
|
|
zebra_neigh_del(ifp, &ip);
|
|
|
|
if (link_if)
|
|
|
|
zebra_vxlan_handle_kernel_neigh_del(ifp, link_if, &ip);
|
|
|
|
return 0;
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2021-03-12 02:44:45 +01:00
|
|
|
zlog_debug("Rx %s family %s IF %s(%u) vrf %s(%u) IP %pIA",
|
2017-05-15 07:44:13 +02:00
|
|
|
nl_msg_type_to_str(h->nlmsg_type),
|
|
|
|
nl_family_to_str(ndm->ndm_family), ifp->name,
|
2021-10-22 00:17:40 +02:00
|
|
|
ndm->ndm_ifindex, ifp->vrf->name, ifp->vrf->vrf_id,
|
2021-03-12 02:44:45 +01:00
|
|
|
&ip);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
/* Process the delete - it may result in re-adding the neighbor if it is
|
|
|
|
* a valid "remote" neighbor.
|
|
|
|
*/
|
2021-12-18 20:28:49 +01:00
|
|
|
zebra_neigh_del(ifp, &ip);
|
|
|
|
if (link_if)
|
|
|
|
zebra_vxlan_handle_kernel_neigh_del(ifp, link_if, &ip);
|
|
|
|
|
|
|
|
return 0;
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 15:37:06 +02:00
|
|
|
static int netlink_neigh_table(struct nlmsghdr *h, ns_id_t ns_id, int startup)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
struct ndmsg *ndm;
|
|
|
|
|
|
|
|
if (h->nlmsg_type != RTM_NEWNEIGH)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Length validity. */
|
|
|
|
len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ndmsg));
|
|
|
|
if (len < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* We are interested only in AF_INET or AF_INET6 notifications. */
|
|
|
|
ndm = NLMSG_DATA(h);
|
|
|
|
if (ndm->ndm_family != AF_INET && ndm->ndm_family != AF_INET6)
|
|
|
|
return 0;
|
|
|
|
|
2018-05-23 15:37:06 +02:00
|
|
|
return netlink_neigh_change(h, len);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Request for IP neighbor information from the kernel */
|
2018-09-12 20:59:57 +02:00
|
|
|
static int netlink_request_neigh(struct nlsock *netlink_cmd, int family,
|
|
|
|
int type, ifindex_t ifindex)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct ndmsg ndm;
|
|
|
|
char buf[256];
|
|
|
|
} req;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
/* Form the request, specifying filter (rtattr) if needed. */
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
req.n.nlmsg_type = type;
|
2018-12-11 06:33:16 +01:00
|
|
|
req.n.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST;
|
2017-05-15 07:44:13 +02:00
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
|
|
|
|
req.ndm.ndm_family = family;
|
|
|
|
if (ifindex)
|
2020-06-08 23:37:26 +02:00
|
|
|
nl_attr_put32(&req.n, sizeof(req), NDA_IFINDEX, ifindex);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-04-15 14:56:03 +02:00
|
|
|
return netlink_request(netlink_cmd, &req);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IP Neighbor table read using netlink interface. This is invoked
|
|
|
|
* at startup.
|
|
|
|
*/
|
|
|
|
int netlink_neigh_read(struct zebra_ns *zns)
|
|
|
|
{
|
|
|
|
int ret;
|
2018-09-12 20:59:57 +02:00
|
|
|
struct zebra_dplane_info dp_info;
|
|
|
|
|
|
|
|
zebra_dplane_info_from_zns(&dp_info, zns, true /*is_cmd*/);
|
2017-05-15 07:44:13 +02:00
|
|
|
|
|
|
|
/* Get IP neighbor table. */
|
2018-09-12 20:59:57 +02:00
|
|
|
ret = netlink_request_neigh(&zns->netlink_cmd, AF_UNSPEC, RTM_GETNEIGH,
|
|
|
|
0);
|
2017-05-15 07:44:13 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2018-09-12 20:59:57 +02:00
|
|
|
ret = netlink_parse_info(netlink_neigh_table, &zns->netlink_cmd,
|
2021-10-05 02:26:38 +02:00
|
|
|
&dp_info, 0, true);
|
2017-05-15 07:44:13 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IP Neighbor table read using netlink interface. This is for a specific
|
|
|
|
* VLAN device.
|
|
|
|
*/
|
|
|
|
int netlink_neigh_read_for_vlan(struct zebra_ns *zns, struct interface *vlan_if)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2018-09-12 20:59:57 +02:00
|
|
|
struct zebra_dplane_info dp_info;
|
|
|
|
|
|
|
|
zebra_dplane_info_from_zns(&dp_info, zns, true /*is_cmd*/);
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2018-09-12 20:59:57 +02:00
|
|
|
ret = netlink_request_neigh(&zns->netlink_cmd, AF_UNSPEC, RTM_GETNEIGH,
|
2017-05-15 07:44:13 +02:00
|
|
|
vlan_if->ifindex);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2018-09-12 20:59:57 +02:00
|
|
|
ret = netlink_parse_info(netlink_neigh_table, &zns->netlink_cmd,
|
2021-10-05 02:26:38 +02:00
|
|
|
&dp_info, 0, false);
|
2017-05-15 07:44:13 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-12-11 06:33:16 +01:00
|
|
|
/*
|
|
|
|
* Request for a specific IP in VLAN (SVI) device from IP Neighbor table,
|
|
|
|
* read using netlink interface.
|
|
|
|
*/
|
|
|
|
static int netlink_request_specific_neigh_in_vlan(struct zebra_ns *zns,
|
2021-04-19 20:26:57 +02:00
|
|
|
int type,
|
|
|
|
const struct ipaddr *ip,
|
2018-12-11 06:33:16 +01:00
|
|
|
ifindex_t ifindex)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct ndmsg ndm;
|
|
|
|
char buf[256];
|
|
|
|
} req;
|
|
|
|
int ipa_len;
|
|
|
|
|
|
|
|
/* Form the request, specifying filter (rtattr) if needed. */
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
|
|
|
|
req.n.nlmsg_flags = NLM_F_REQUEST;
|
|
|
|
req.n.nlmsg_type = type; /* RTM_GETNEIGH */
|
|
|
|
req.ndm.ndm_ifindex = ifindex;
|
|
|
|
|
|
|
|
if (IS_IPADDR_V4(ip)) {
|
|
|
|
ipa_len = IPV4_MAX_BYTELEN;
|
|
|
|
req.ndm.ndm_family = AF_INET;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ipa_len = IPV6_MAX_BYTELEN;
|
|
|
|
req.ndm.ndm_family = AF_INET6;
|
|
|
|
}
|
|
|
|
|
2020-06-08 23:37:26 +02:00
|
|
|
nl_attr_put(&req.n, sizeof(req), NDA_DST, &ip->ip.addr, ipa_len);
|
2018-12-11 06:33:16 +01:00
|
|
|
|
2021-03-12 02:44:45 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("%s: Tx %s family %s IF %u IP %pIA flags 0x%x",
|
2019-03-27 02:23:58 +01:00
|
|
|
__func__, nl_msg_type_to_str(type),
|
2021-03-12 02:44:45 +01:00
|
|
|
nl_family_to_str(req.ndm.ndm_family), ifindex, ip,
|
|
|
|
req.n.nlmsg_flags);
|
2019-03-27 02:23:58 +01:00
|
|
|
|
2020-04-15 14:56:03 +02:00
|
|
|
return netlink_request(&zns->netlink_cmd, &req);
|
2018-12-11 06:33:16 +01:00
|
|
|
}
|
|
|
|
|
2021-04-19 20:26:57 +02:00
|
|
|
int netlink_neigh_read_specific_ip(const struct ipaddr *ip,
|
|
|
|
struct interface *vlan_if)
|
2018-12-11 06:33:16 +01:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct zebra_ns *zns;
|
2021-10-22 00:17:40 +02:00
|
|
|
struct zebra_vrf *zvrf = vlan_if->vrf->info;
|
2018-12-11 06:33:16 +01:00
|
|
|
struct zebra_dplane_info dp_info;
|
|
|
|
|
|
|
|
zns = zvrf->zns;
|
|
|
|
|
|
|
|
zebra_dplane_info_from_zns(&dp_info, zns, true /*is_cmd*/);
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2021-03-12 02:44:45 +01:00
|
|
|
zlog_debug("%s: neigh request IF %s(%u) IP %pIA vrf %s(%u)",
|
|
|
|
__func__, vlan_if->name, vlan_if->ifindex, ip,
|
2021-10-22 00:17:40 +02:00
|
|
|
vlan_if->vrf->name, vlan_if->vrf->vrf_id);
|
2018-12-11 06:33:16 +01:00
|
|
|
|
|
|
|
ret = netlink_request_specific_neigh_in_vlan(zns, RTM_GETNEIGH, ip,
|
|
|
|
vlan_if->ifindex);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = netlink_parse_info(netlink_neigh_table, &zns->netlink_cmd,
|
2021-10-05 02:26:38 +02:00
|
|
|
&dp_info, 1, false);
|
2018-12-11 06:33:16 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-05-23 15:37:06 +02:00
|
|
|
int netlink_neigh_change(struct nlmsghdr *h, ns_id_t ns_id)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
struct ndmsg *ndm;
|
|
|
|
|
2019-12-12 16:06:59 +01:00
|
|
|
if (!(h->nlmsg_type == RTM_NEWNEIGH || h->nlmsg_type == RTM_DELNEIGH
|
|
|
|
|| h->nlmsg_type == RTM_GETNEIGH))
|
2017-05-15 07:44:13 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Length validity. */
|
|
|
|
len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ndmsg));
|
2018-06-22 20:22:02 +02:00
|
|
|
if (len < 0) {
|
2020-03-05 19:17:54 +01:00
|
|
|
zlog_err(
|
|
|
|
"%s: Message received from netlink is of a broken size %d %zu",
|
|
|
|
__func__, h->nlmsg_len,
|
|
|
|
(size_t)NLMSG_LENGTH(sizeof(struct ndmsg)));
|
2017-05-15 07:44:13 +02:00
|
|
|
return -1;
|
2018-06-22 20:22:02 +02:00
|
|
|
}
|
2017-05-15 07:44:13 +02:00
|
|
|
|
|
|
|
/* Is this a notification for the MAC FDB or IP neighbor table? */
|
|
|
|
ndm = NLMSG_DATA(h);
|
|
|
|
if (ndm->ndm_family == AF_BRIDGE)
|
2018-05-23 15:37:06 +02:00
|
|
|
return netlink_macfdb_change(h, len, ns_id);
|
2017-05-15 07:44:13 +02:00
|
|
|
|
|
|
|
if (ndm->ndm_type != RTN_UNICAST)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ndm->ndm_family == AF_INET || ndm->ndm_family == AF_INET6)
|
2018-05-23 15:37:06 +02:00
|
|
|
return netlink_ipneigh_change(h, len, ns_id);
|
2018-07-19 23:29:16 +02:00
|
|
|
else {
|
2018-08-16 22:10:32 +02:00
|
|
|
flog_warn(
|
2018-09-13 21:21:05 +02:00
|
|
|
EC_ZEBRA_UNKNOWN_FAMILY,
|
2018-09-14 23:48:51 +02:00
|
|
|
"Invalid address family: %u received from kernel neighbor change: %s",
|
|
|
|
ndm->ndm_family, nl_msg_type_to_str(h->nlmsg_type));
|
2018-07-19 23:29:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2017-05-15 07:44:13 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-23 19:59:10 +02:00
|
|
|
/*
|
|
|
|
* Utility neighbor-update function, using info from dplane context.
|
|
|
|
*/
|
2020-07-15 15:14:08 +02:00
|
|
|
static ssize_t netlink_neigh_update_ctx(const struct zebra_dplane_ctx *ctx,
|
|
|
|
int cmd, void *buf, size_t buflen)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
2019-08-23 19:59:10 +02:00
|
|
|
const struct ipaddr *ip;
|
2021-02-25 11:12:34 +01:00
|
|
|
const struct ethaddr *mac = NULL;
|
|
|
|
const struct ipaddr *link_ip = NULL;
|
|
|
|
const void *link_ptr = NULL;
|
|
|
|
char buf2[ETHER_ADDR_STRLEN];
|
|
|
|
|
|
|
|
int llalen;
|
2019-08-23 19:59:10 +02:00
|
|
|
uint8_t flags;
|
|
|
|
uint16_t state;
|
2020-03-07 20:07:05 +01:00
|
|
|
uint8_t family;
|
2020-05-08 16:42:07 +02:00
|
|
|
uint32_t update_flags;
|
|
|
|
uint32_t ext_flags = 0;
|
|
|
|
bool ext = false;
|
2021-04-05 21:40:37 +02:00
|
|
|
int proto = RTPROT_ZEBRA;
|
|
|
|
|
|
|
|
if (dplane_ctx_get_type(ctx) != 0)
|
|
|
|
proto = zebra2proto(dplane_ctx_get_type(ctx));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2019-08-23 19:59:10 +02:00
|
|
|
ip = dplane_ctx_neigh_get_ipaddr(ctx);
|
|
|
|
|
2021-02-25 11:12:34 +01:00
|
|
|
if (dplane_ctx_get_op(ctx) == DPLANE_OP_NEIGH_IP_INSTALL
|
|
|
|
|| dplane_ctx_get_op(ctx) == DPLANE_OP_NEIGH_IP_DELETE) {
|
|
|
|
link_ip = dplane_ctx_neigh_get_link_ip(ctx);
|
|
|
|
llalen = IPADDRSZ(link_ip);
|
|
|
|
link_ptr = (const void *)&(link_ip->ip.addr);
|
|
|
|
ipaddr2str(link_ip, buf2, sizeof(buf2));
|
|
|
|
} else {
|
|
|
|
mac = dplane_ctx_neigh_get_mac(ctx);
|
|
|
|
llalen = ETH_ALEN;
|
|
|
|
link_ptr = (const void *)mac;
|
|
|
|
if (is_zero_mac(mac))
|
|
|
|
mac = NULL;
|
|
|
|
if (mac)
|
|
|
|
prefix_mac2str(mac, buf2, sizeof(buf2));
|
|
|
|
else
|
|
|
|
snprintf(buf2, sizeof(buf2), "null");
|
|
|
|
}
|
2020-05-08 16:42:07 +02:00
|
|
|
update_flags = dplane_ctx_neigh_get_update_flags(ctx);
|
2019-08-23 19:59:10 +02:00
|
|
|
flags = neigh_flags_to_netlink(dplane_ctx_neigh_get_flags(ctx));
|
|
|
|
state = neigh_state_to_netlink(dplane_ctx_neigh_get_state(ctx));
|
|
|
|
|
2020-03-07 20:07:05 +01:00
|
|
|
family = IS_IPADDR_V4(ip) ? AF_INET : AF_INET6;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-05-08 16:42:07 +02:00
|
|
|
if (update_flags & DPLANE_NEIGH_REMOTE) {
|
|
|
|
flags |= NTF_EXT_LEARNED;
|
|
|
|
/* if it was static-local previously we need to clear the
|
|
|
|
* ext flags on replace with remote
|
|
|
|
*/
|
|
|
|
if (update_flags & DPLANE_NEIGH_WAS_STATIC)
|
|
|
|
ext = true;
|
2021-02-25 11:12:34 +01:00
|
|
|
} else if (!(update_flags & DPLANE_NEIGH_NO_EXTENSION)) {
|
2020-05-08 16:42:07 +02:00
|
|
|
ext = true;
|
|
|
|
/* local neigh */
|
|
|
|
if (update_flags & DPLANE_NEIGH_SET_STATIC)
|
|
|
|
ext_flags |= NTF_E_MH_PEER_SYNC;
|
|
|
|
}
|
2021-03-12 02:44:45 +01:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2020-03-07 20:07:05 +01:00
|
|
|
zlog_debug(
|
2021-02-25 11:12:34 +01:00
|
|
|
"Tx %s family %s IF %s(%u) Neigh %pIA %s %s flags 0x%x state 0x%x %sext_flags 0x%x",
|
2020-03-07 20:07:05 +01:00
|
|
|
nl_msg_type_to_str(cmd), nl_family_to_str(family),
|
|
|
|
dplane_ctx_get_ifname(ctx), dplane_ctx_get_ifindex(ctx),
|
2023-01-09 08:24:33 +01:00
|
|
|
ip, link_ip ? "Link" : "MAC", buf2, flags, state,
|
2021-02-25 11:12:34 +01:00
|
|
|
ext ? "ext " : "", ext_flags);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2020-07-31 00:15:51 +02:00
|
|
|
return netlink_neigh_update_msg_encode(
|
2021-02-25 11:12:34 +01:00
|
|
|
ctx, cmd, link_ptr, llalen, ip, true, family, RTN_UNICAST,
|
|
|
|
flags, state, 0 /*nhg*/, false /*nfy*/, 0 /*nfy_flags*/, ext,
|
2021-04-05 21:40:37 +02:00
|
|
|
ext_flags, buf, buflen, proto);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
2021-02-26 10:04:25 +01:00
|
|
|
static int netlink_neigh_table_update_ctx(const struct zebra_dplane_ctx *ctx,
|
|
|
|
void *data, size_t datalen)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct ndtmsg ndtm;
|
|
|
|
char buf[];
|
|
|
|
} *req = data;
|
|
|
|
struct rtattr *nest;
|
|
|
|
uint8_t family;
|
|
|
|
ifindex_t idx;
|
|
|
|
uint32_t val;
|
|
|
|
|
|
|
|
if (datalen < sizeof(*req))
|
|
|
|
return 0;
|
|
|
|
memset(req, 0, sizeof(*req));
|
|
|
|
family = dplane_ctx_neightable_get_family(ctx);
|
|
|
|
idx = dplane_ctx_get_ifindex(ctx);
|
|
|
|
|
|
|
|
req->n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndtmsg));
|
|
|
|
req->n.nlmsg_flags = NLM_F_REQUEST | NLM_F_REPLACE;
|
|
|
|
req->n.nlmsg_type = RTM_SETNEIGHTBL;
|
|
|
|
req->ndtm.ndtm_family = family;
|
|
|
|
|
|
|
|
nl_attr_put(&req->n, datalen, NDTA_NAME,
|
|
|
|
family == AF_INET ? "arp_cache" : "ndisc_cache", 10);
|
|
|
|
nest = nl_attr_nest(&req->n, datalen, NDTA_PARMS);
|
|
|
|
if (nest == NULL)
|
|
|
|
return 0;
|
|
|
|
if (!nl_attr_put(&req->n, datalen, NDTPA_IFINDEX, &idx, sizeof(idx)))
|
|
|
|
return 0;
|
|
|
|
val = dplane_ctx_neightable_get_app_probes(ctx);
|
|
|
|
if (!nl_attr_put(&req->n, datalen, NDTPA_APP_PROBES, &val, sizeof(val)))
|
|
|
|
return 0;
|
|
|
|
val = dplane_ctx_neightable_get_mcast_probes(ctx);
|
|
|
|
if (!nl_attr_put(&req->n, datalen, NDTPA_MCAST_PROBES, &val,
|
|
|
|
sizeof(val)))
|
|
|
|
return 0;
|
|
|
|
val = dplane_ctx_neightable_get_ucast_probes(ctx);
|
|
|
|
if (!nl_attr_put(&req->n, datalen, NDTPA_UCAST_PROBES, &val,
|
|
|
|
sizeof(val)))
|
|
|
|
return 0;
|
|
|
|
nl_attr_nest_end(&req->n, nest);
|
|
|
|
|
|
|
|
return NLMSG_ALIGN(req->n.nlmsg_len);
|
|
|
|
}
|
|
|
|
|
2020-07-15 15:14:08 +02:00
|
|
|
static ssize_t netlink_neigh_msg_encoder(struct zebra_dplane_ctx *ctx,
|
|
|
|
void *buf, size_t buflen)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
2023-01-30 16:05:58 +01:00
|
|
|
ssize_t ret = 0;
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2019-08-23 19:59:10 +02:00
|
|
|
switch (dplane_ctx_get_op(ctx)) {
|
|
|
|
case DPLANE_OP_NEIGH_INSTALL:
|
|
|
|
case DPLANE_OP_NEIGH_UPDATE:
|
2020-08-06 13:07:01 +02:00
|
|
|
case DPLANE_OP_NEIGH_DISCOVER:
|
2021-02-25 11:12:34 +01:00
|
|
|
case DPLANE_OP_NEIGH_IP_INSTALL:
|
2020-07-15 15:14:08 +02:00
|
|
|
ret = netlink_neigh_update_ctx(ctx, RTM_NEWNEIGH, buf, buflen);
|
2019-08-23 19:59:10 +02:00
|
|
|
break;
|
|
|
|
case DPLANE_OP_NEIGH_DELETE:
|
2021-02-25 11:12:34 +01:00
|
|
|
case DPLANE_OP_NEIGH_IP_DELETE:
|
2020-07-15 15:14:08 +02:00
|
|
|
ret = netlink_neigh_update_ctx(ctx, RTM_DELNEIGH, buf, buflen);
|
2019-08-23 19:59:10 +02:00
|
|
|
break;
|
2019-08-26 21:44:54 +02:00
|
|
|
case DPLANE_OP_VTEP_ADD:
|
2020-07-15 15:14:08 +02:00
|
|
|
ret = netlink_vxlan_flood_update_ctx(ctx, RTM_NEWNEIGH, buf,
|
|
|
|
buflen);
|
2019-08-26 21:44:54 +02:00
|
|
|
break;
|
|
|
|
case DPLANE_OP_VTEP_DELETE:
|
2020-07-15 15:14:08 +02:00
|
|
|
ret = netlink_vxlan_flood_update_ctx(ctx, RTM_DELNEIGH, buf,
|
|
|
|
buflen);
|
2019-08-26 21:44:54 +02:00
|
|
|
break;
|
2021-02-26 10:04:25 +01:00
|
|
|
case DPLANE_OP_NEIGH_TABLE_UPDATE:
|
|
|
|
ret = netlink_neigh_table_update_ctx(ctx, buf, buflen);
|
|
|
|
break;
|
2023-01-30 16:05:58 +01:00
|
|
|
case DPLANE_OP_ROUTE_INSTALL:
|
|
|
|
case DPLANE_OP_ROUTE_UPDATE:
|
|
|
|
case DPLANE_OP_ROUTE_DELETE:
|
|
|
|
case DPLANE_OP_ROUTE_NOTIFY:
|
|
|
|
case DPLANE_OP_NH_INSTALL:
|
|
|
|
case DPLANE_OP_NH_UPDATE:
|
|
|
|
case DPLANE_OP_NH_DELETE:
|
|
|
|
case DPLANE_OP_LSP_INSTALL:
|
|
|
|
case DPLANE_OP_LSP_UPDATE:
|
|
|
|
case DPLANE_OP_LSP_DELETE:
|
|
|
|
case DPLANE_OP_LSP_NOTIFY:
|
|
|
|
case DPLANE_OP_PW_INSTALL:
|
|
|
|
case DPLANE_OP_PW_UNINSTALL:
|
|
|
|
case DPLANE_OP_SYS_ROUTE_ADD:
|
|
|
|
case DPLANE_OP_SYS_ROUTE_DELETE:
|
|
|
|
case DPLANE_OP_ADDR_INSTALL:
|
|
|
|
case DPLANE_OP_ADDR_UNINSTALL:
|
|
|
|
case DPLANE_OP_MAC_INSTALL:
|
|
|
|
case DPLANE_OP_MAC_DELETE:
|
|
|
|
case DPLANE_OP_RULE_ADD:
|
|
|
|
case DPLANE_OP_RULE_DELETE:
|
|
|
|
case DPLANE_OP_RULE_UPDATE:
|
|
|
|
case DPLANE_OP_BR_PORT_UPDATE:
|
|
|
|
case DPLANE_OP_IPTABLE_ADD:
|
|
|
|
case DPLANE_OP_IPTABLE_DELETE:
|
|
|
|
case DPLANE_OP_IPSET_ADD:
|
|
|
|
case DPLANE_OP_IPSET_DELETE:
|
|
|
|
case DPLANE_OP_IPSET_ENTRY_ADD:
|
|
|
|
case DPLANE_OP_IPSET_ENTRY_DELETE:
|
|
|
|
case DPLANE_OP_GRE_SET:
|
|
|
|
case DPLANE_OP_INTF_ADDR_ADD:
|
|
|
|
case DPLANE_OP_INTF_ADDR_DEL:
|
|
|
|
case DPLANE_OP_INTF_NETCONFIG:
|
|
|
|
case DPLANE_OP_INTF_INSTALL:
|
|
|
|
case DPLANE_OP_INTF_UPDATE:
|
|
|
|
case DPLANE_OP_INTF_DELETE:
|
|
|
|
case DPLANE_OP_TC_QDISC_INSTALL:
|
|
|
|
case DPLANE_OP_TC_QDISC_UNINSTALL:
|
|
|
|
case DPLANE_OP_TC_CLASS_ADD:
|
|
|
|
case DPLANE_OP_TC_CLASS_DELETE:
|
|
|
|
case DPLANE_OP_TC_CLASS_UPDATE:
|
|
|
|
case DPLANE_OP_TC_FILTER_ADD:
|
|
|
|
case DPLANE_OP_TC_FILTER_DELETE:
|
|
|
|
case DPLANE_OP_TC_FILTER_UPDATE:
|
|
|
|
case DPLANE_OP_NONE:
|
2023-04-20 14:51:42 +02:00
|
|
|
case DPLANE_OP_STARTUP_STAGE:
|
2020-07-15 15:14:08 +02:00
|
|
|
ret = -1;
|
2019-08-23 19:59:10 +02:00
|
|
|
}
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2020-07-15 15:14:08 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update MAC, using dataplane context object.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum netlink_msg_status netlink_put_mac_update_msg(struct nl_batch *bth,
|
|
|
|
struct zebra_dplane_ctx *ctx)
|
|
|
|
{
|
|
|
|
return netlink_batch_add_msg(bth, ctx, netlink_macfdb_update_ctx,
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum netlink_msg_status
|
|
|
|
netlink_put_neigh_update_msg(struct nl_batch *bth, struct zebra_dplane_ctx *ctx)
|
|
|
|
{
|
|
|
|
return netlink_batch_add_msg(bth, ctx, netlink_neigh_msg_encoder,
|
|
|
|
false);
|
2019-01-29 00:32:45 +01:00
|
|
|
}
|
|
|
|
|
2018-10-23 16:57:01 +02:00
|
|
|
/*
|
|
|
|
* MPLS label forwarding table change via netlink interface, using dataplane
|
|
|
|
* context information.
|
|
|
|
*/
|
2020-06-10 11:44:31 +02:00
|
|
|
ssize_t netlink_mpls_multipath_msg_encode(int cmd, struct zebra_dplane_ctx *ctx,
|
|
|
|
void *buf, size_t buflen)
|
2018-10-23 16:57:01 +02:00
|
|
|
{
|
|
|
|
mpls_lse_t lse;
|
2020-05-19 20:11:32 +02:00
|
|
|
const struct nhlfe_list_head *head;
|
2021-08-20 15:08:25 +02:00
|
|
|
const struct zebra_nhlfe *nhlfe;
|
2018-10-23 16:57:01 +02:00
|
|
|
struct nexthop *nexthop = NULL;
|
|
|
|
unsigned int nexthop_num;
|
|
|
|
const char *routedesc;
|
|
|
|
int route_type;
|
2020-03-18 15:31:34 +01:00
|
|
|
struct prefix p = {0};
|
2022-02-02 19:21:52 +01:00
|
|
|
struct nlsock *nl =
|
|
|
|
kernel_netlink_nlsock_lookup(dplane_ctx_get_ns_sock(ctx));
|
2018-10-23 16:57:01 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct rtmsg r;
|
2020-06-10 11:44:31 +02:00
|
|
|
char buf[0];
|
|
|
|
} *req = buf;
|
|
|
|
|
|
|
|
if (buflen < sizeof(*req))
|
|
|
|
return 0;
|
2018-10-23 16:57:01 +02:00
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
memset(req, 0, sizeof(*req));
|
2018-10-23 16:57:01 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Count # nexthops so we can decide whether to use singlepath
|
|
|
|
* or multipath case.
|
|
|
|
*/
|
|
|
|
nexthop_num = 0;
|
2020-05-19 20:11:32 +02:00
|
|
|
head = dplane_ctx_get_nhlfe_list(ctx);
|
|
|
|
frr_each(nhlfe_list_const, head, nhlfe) {
|
2018-10-23 16:57:01 +02:00
|
|
|
nexthop = nhlfe->nexthop;
|
|
|
|
if (!nexthop)
|
|
|
|
continue;
|
|
|
|
if (cmd == RTM_NEWROUTE) {
|
|
|
|
/* Count all selected NHLFEs */
|
|
|
|
if (CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_SELECTED)
|
|
|
|
&& CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE))
|
|
|
|
nexthop_num++;
|
|
|
|
} else { /* DEL */
|
|
|
|
/* Count all installed NHLFEs */
|
|
|
|
if (CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED)
|
|
|
|
&& CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB))
|
|
|
|
nexthop_num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((nexthop_num == 0) ||
|
|
|
|
(!dplane_ctx_get_best_nhlfe(ctx) && (cmd != RTM_DELROUTE)))
|
|
|
|
return 0;
|
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
req->n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
|
|
|
|
req->n.nlmsg_flags = NLM_F_CREATE | NLM_F_REQUEST;
|
|
|
|
req->n.nlmsg_type = cmd;
|
2022-02-02 19:21:52 +01:00
|
|
|
req->n.nlmsg_pid = nl->snl.nl_pid;
|
2018-10-23 16:57:01 +02:00
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
req->r.rtm_family = AF_MPLS;
|
2023-08-22 13:27:59 +02:00
|
|
|
req->r.rtm_table = rt_table_main_id;
|
2020-06-10 11:44:31 +02:00
|
|
|
req->r.rtm_dst_len = MPLS_LABEL_LEN_BITS;
|
|
|
|
req->r.rtm_scope = RT_SCOPE_UNIVERSE;
|
|
|
|
req->r.rtm_type = RTN_UNICAST;
|
2018-10-23 16:57:01 +02:00
|
|
|
|
|
|
|
if (cmd == RTM_NEWROUTE) {
|
|
|
|
/* We do a replace to handle update. */
|
2020-06-10 11:44:31 +02:00
|
|
|
req->n.nlmsg_flags |= NLM_F_REPLACE;
|
2018-10-23 16:57:01 +02:00
|
|
|
|
|
|
|
/* set the protocol value if installing */
|
|
|
|
route_type = re_type_from_lsp_type(
|
|
|
|
dplane_ctx_get_best_nhlfe(ctx)->type);
|
2020-06-10 11:44:31 +02:00
|
|
|
req->r.rtm_protocol = zebra2proto(route_type);
|
2018-10-23 16:57:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill destination */
|
|
|
|
lse = mpls_lse_encode(dplane_ctx_get_in_label(ctx), 0, 0, 1);
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!nl_attr_put(&req->n, buflen, RTA_DST, &lse, sizeof(mpls_lse_t)))
|
|
|
|
return 0;
|
2018-10-23 16:57:01 +02:00
|
|
|
|
|
|
|
/* Fill nexthops (paths) based on single-path or multipath. The paths
|
|
|
|
* chosen depend on the operation.
|
|
|
|
*/
|
2018-11-26 22:08:55 +01:00
|
|
|
if (nexthop_num == 1) {
|
2018-10-23 16:57:01 +02:00
|
|
|
routedesc = "single-path";
|
|
|
|
_netlink_mpls_debug(cmd, dplane_ctx_get_in_label(ctx),
|
|
|
|
routedesc);
|
|
|
|
|
|
|
|
nexthop_num = 0;
|
2020-05-19 20:11:32 +02:00
|
|
|
frr_each(nhlfe_list_const, head, nhlfe) {
|
2018-10-23 16:57:01 +02:00
|
|
|
nexthop = nhlfe->nexthop;
|
|
|
|
if (!nexthop)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((cmd == RTM_NEWROUTE
|
|
|
|
&& (CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_SELECTED)
|
|
|
|
&& CHECK_FLAG(nexthop->flags,
|
|
|
|
NEXTHOP_FLAG_ACTIVE)))
|
|
|
|
|| (cmd == RTM_DELROUTE
|
|
|
|
&& (CHECK_FLAG(nhlfe->flags,
|
|
|
|
NHLFE_FLAG_INSTALLED)
|
|
|
|
&& CHECK_FLAG(nexthop->flags,
|
|
|
|
NEXTHOP_FLAG_FIB)))) {
|
|
|
|
/* Add the gateway */
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!_netlink_mpls_build_singlepath(
|
|
|
|
&p, routedesc, nhlfe, &req->n,
|
|
|
|
&req->r, buflen, cmd))
|
|
|
|
return false;
|
2018-10-23 16:57:01 +02:00
|
|
|
|
|
|
|
nexthop_num++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { /* Multipath case */
|
2020-06-08 23:37:26 +02:00
|
|
|
struct rtattr *nest;
|
2019-03-07 19:09:51 +01:00
|
|
|
const union g_addr *src1 = NULL;
|
2018-10-23 16:57:01 +02:00
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
nest = nl_attr_nest(&req->n, buflen, RTA_MULTIPATH);
|
|
|
|
if (!nest)
|
|
|
|
return 0;
|
2018-10-23 16:57:01 +02:00
|
|
|
|
|
|
|
routedesc = "multipath";
|
|
|
|
_netlink_mpls_debug(cmd, dplane_ctx_get_in_label(ctx),
|
|
|
|
routedesc);
|
|
|
|
|
|
|
|
nexthop_num = 0;
|
2020-05-19 20:11:32 +02:00
|
|
|
frr_each(nhlfe_list_const, head, nhlfe) {
|
2018-10-23 16:57:01 +02:00
|
|
|
nexthop = nhlfe->nexthop;
|
|
|
|
if (!nexthop)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((cmd == RTM_NEWROUTE
|
|
|
|
&& (CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_SELECTED)
|
|
|
|
&& CHECK_FLAG(nexthop->flags,
|
|
|
|
NEXTHOP_FLAG_ACTIVE)))
|
|
|
|
|| (cmd == RTM_DELROUTE
|
|
|
|
&& (CHECK_FLAG(nhlfe->flags,
|
|
|
|
NHLFE_FLAG_INSTALLED)
|
|
|
|
&& CHECK_FLAG(nexthop->flags,
|
|
|
|
NEXTHOP_FLAG_FIB)))) {
|
|
|
|
nexthop_num++;
|
|
|
|
|
|
|
|
/* Build the multipath */
|
2020-06-10 11:44:31 +02:00
|
|
|
if (!_netlink_mpls_build_multipath(
|
|
|
|
&p, routedesc, nhlfe, &req->n,
|
|
|
|
buflen, &req->r, &src1))
|
|
|
|
return 0;
|
2018-10-23 16:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the multipath */
|
2020-06-10 11:44:31 +02:00
|
|
|
nl_attr_nest_end(&req->n, nest);
|
2018-10-23 16:57:01 +02:00
|
|
|
}
|
|
|
|
|
2020-06-10 11:44:31 +02:00
|
|
|
return NLMSG_ALIGN(req->n.nlmsg_len);
|
2018-10-23 16:57:01 +02:00
|
|
|
}
|
2020-03-28 00:36:24 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* This code was developed in a branch that didn't have dplane APIs for
|
|
|
|
* MAC updates. Hence the use of the legacy style. It will be moved to
|
|
|
|
* the new dplane style pre-merge to master. XXX
|
|
|
|
*/
|
|
|
|
static int netlink_fdb_nh_update(uint32_t nh_id, struct in_addr vtep_ip)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct nhmsg nhm;
|
|
|
|
char buf[256];
|
|
|
|
} req;
|
|
|
|
int cmd = RTM_NEWNEXTHOP;
|
|
|
|
struct zebra_vrf *zvrf;
|
|
|
|
struct zebra_ns *zns;
|
|
|
|
|
|
|
|
zvrf = zebra_vrf_get_evpn();
|
|
|
|
zns = zvrf->zns;
|
|
|
|
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nhmsg));
|
|
|
|
req.n.nlmsg_flags = NLM_F_REQUEST;
|
|
|
|
req.n.nlmsg_flags |= (NLM_F_CREATE | NLM_F_REPLACE);
|
|
|
|
req.n.nlmsg_type = cmd;
|
|
|
|
req.nhm.nh_family = AF_INET;
|
|
|
|
|
|
|
|
if (!nl_attr_put32(&req.n, sizeof(req), NHA_ID, nh_id))
|
|
|
|
return -1;
|
|
|
|
if (!nl_attr_put(&req.n, sizeof(req), NHA_FDB, NULL, 0))
|
|
|
|
return -1;
|
|
|
|
if (!nl_attr_put(&req.n, sizeof(req), NHA_GATEWAY,
|
|
|
|
&vtep_ip, IPV4_MAX_BYTELEN))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_EVPN_MH_NH) {
|
2020-10-21 19:57:06 +02:00
|
|
|
zlog_debug("Tx %s fdb-nh 0x%x %pI4",
|
|
|
|
nl_msg_type_to_str(cmd), nh_id, &vtep_ip);
|
2020-03-28 00:36:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
|
2021-10-05 02:26:38 +02:00
|
|
|
false);
|
2020-03-28 00:36:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int netlink_fdb_nh_del(uint32_t nh_id)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct nhmsg nhm;
|
|
|
|
char buf[256];
|
|
|
|
} req;
|
|
|
|
int cmd = RTM_DELNEXTHOP;
|
|
|
|
struct zebra_vrf *zvrf;
|
|
|
|
struct zebra_ns *zns;
|
|
|
|
|
|
|
|
zvrf = zebra_vrf_get_evpn();
|
|
|
|
zns = zvrf->zns;
|
|
|
|
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nhmsg));
|
|
|
|
req.n.nlmsg_flags = NLM_F_REQUEST;
|
|
|
|
req.n.nlmsg_type = cmd;
|
|
|
|
req.nhm.nh_family = AF_UNSPEC;
|
|
|
|
|
|
|
|
if (!nl_attr_put32(&req.n, sizeof(req), NHA_ID, nh_id))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_EVPN_MH_NH) {
|
|
|
|
zlog_debug("Tx %s fdb-nh 0x%x",
|
|
|
|
nl_msg_type_to_str(cmd), nh_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
|
2021-10-05 02:26:38 +02:00
|
|
|
false);
|
2020-03-28 00:36:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int netlink_fdb_nhg_update(uint32_t nhg_id, uint32_t nh_cnt,
|
|
|
|
struct nh_grp *nh_ids)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct nhmsg nhm;
|
|
|
|
char buf[256];
|
|
|
|
} req;
|
|
|
|
int cmd = RTM_NEWNEXTHOP;
|
|
|
|
struct zebra_vrf *zvrf;
|
|
|
|
struct zebra_ns *zns;
|
|
|
|
struct nexthop_grp grp[nh_cnt];
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
zvrf = zebra_vrf_get_evpn();
|
|
|
|
zns = zvrf->zns;
|
|
|
|
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct nhmsg));
|
|
|
|
req.n.nlmsg_flags = NLM_F_REQUEST;
|
|
|
|
req.n.nlmsg_flags |= (NLM_F_CREATE | NLM_F_REPLACE);
|
|
|
|
req.n.nlmsg_type = cmd;
|
|
|
|
req.nhm.nh_family = AF_UNSPEC;
|
|
|
|
|
|
|
|
if (!nl_attr_put32(&req.n, sizeof(req), NHA_ID, nhg_id))
|
|
|
|
return -1;
|
|
|
|
if (!nl_attr_put(&req.n, sizeof(req), NHA_FDB, NULL, 0))
|
|
|
|
return -1;
|
|
|
|
memset(&grp, 0, sizeof(grp));
|
|
|
|
for (i = 0; i < nh_cnt; ++i) {
|
|
|
|
grp[i].id = nh_ids[i].id;
|
|
|
|
grp[i].weight = nh_ids[i].weight;
|
|
|
|
}
|
|
|
|
if (!nl_attr_put(&req.n, sizeof(req), NHA_GROUP,
|
|
|
|
grp, nh_cnt * sizeof(struct nexthop_grp)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_EVPN_MH_NH) {
|
|
|
|
char vtep_str[ES_VTEP_LIST_STR_SZ];
|
2020-06-16 02:24:39 +02:00
|
|
|
char nh_buf[16];
|
2020-03-28 00:36:24 +01:00
|
|
|
|
|
|
|
vtep_str[0] = '\0';
|
|
|
|
for (i = 0; i < nh_cnt; ++i) {
|
2020-06-16 02:24:39 +02:00
|
|
|
snprintf(nh_buf, sizeof(nh_buf), "%u ",
|
2020-03-28 00:36:24 +01:00
|
|
|
grp[i].id);
|
2020-06-16 02:24:39 +02:00
|
|
|
strlcat(vtep_str, nh_buf, sizeof(vtep_str));
|
2020-03-28 00:36:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
zlog_debug("Tx %s fdb-nhg 0x%x %s",
|
|
|
|
nl_msg_type_to_str(cmd), nhg_id, vtep_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
|
2021-10-05 02:26:38 +02:00
|
|
|
false);
|
2020-03-28 00:36:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int netlink_fdb_nhg_del(uint32_t nhg_id)
|
|
|
|
{
|
|
|
|
return netlink_fdb_nh_del(nhg_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
int kernel_upd_mac_nh(uint32_t nh_id, struct in_addr vtep_ip)
|
|
|
|
{
|
|
|
|
return netlink_fdb_nh_update(nh_id, vtep_ip);
|
|
|
|
}
|
|
|
|
|
|
|
|
int kernel_del_mac_nh(uint32_t nh_id)
|
|
|
|
{
|
|
|
|
return netlink_fdb_nh_del(nh_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
int kernel_upd_mac_nhg(uint32_t nhg_id, uint32_t nh_cnt,
|
|
|
|
struct nh_grp *nh_ids)
|
|
|
|
{
|
|
|
|
return netlink_fdb_nhg_update(nhg_id, nh_cnt, nh_ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
int kernel_del_mac_nhg(uint32_t nhg_id)
|
|
|
|
{
|
|
|
|
return netlink_fdb_nhg_del(nhg_id);
|
|
|
|
}
|
|
|
|
|
2017-07-26 19:49:15 +02:00
|
|
|
#endif /* HAVE_NETLINK */
|