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
|
|
|
|
*
|
|
|
|
* This file is part of GNU Zebra.
|
|
|
|
*
|
|
|
|
* GNU Zebra is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* GNU Zebra is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
2017-05-13 10:25:29 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; see the file COPYING; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-12-13 21:15:29 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zebra.h>
|
2017-07-26 19:49:15 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_NETLINK
|
|
|
|
|
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>
|
|
|
|
#include <linux/neighbour.h>
|
|
|
|
#include <linux/rtnetlink.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"
|
|
|
|
#include "connected.h"
|
|
|
|
#include "table.h"
|
2012-03-22 09:09:21 +01:00
|
|
|
#include "memory.h"
|
2015-05-29 05:48:31 +02:00
|
|
|
#include "zebra_memory.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "rib.h"
|
From havanna_moon@gmx.net Fri Jan 17 23:37:49 2003
Date: Sat, 11 Jan 2003 23:26:28 +0100 (CET)
From: Yon Uriarte <havanna_moon@gmx.net>
To: "the list(tm) Zebra" <zebra@zebra.org>
Subject: [zebra 17217] [PATCH] show thread CPU
Hi,
a little patch from the 'stupid preprocessor tricks' collection to record
thread statistics.
Usage: "show thread cpu [r][w][t][e][x]"
Output Fields: self explaining I hope. Type is one of RWTEX for:
Read, Write (fd threads), Timer, Event, Execute.
Overhead vs. vanilla zebra: almost nothing. Vanilla CVS zebra already
collects thread run times.
Caveats: Under linux getrusage has a granularity of 10ms, which is almost
useless in this case. Run ./configure, edit config.h and comment out
"#define HAVE_RUSAGE", this way it will use getimeofday which has a much
better granularity. IMHO this is better, as cooperative threads are
effectively running during all that wall time (dont care if CPU
utilization was 3% or 99% during the time the thread was running (an
effective rusage combined with getimeofday could give that info)).
Maybe someone can give tips for other platforms on API granularity.
TODO: change some of the calls to thread_add_$KIND to
funcname_thread_add_$KIND with a meaningfull funcname, so users will get a
better idea of what's going on.
F.ex. (AFAIK):
ospf_spf_calculate_timer -> "Routes Step 1, areas SPF"
ospf_ase_calculate_timer -> "Routes Step 2, externals"
Could this be added to the unofficial patch collection?
Could someone with BGP keepalive problems run their bgpd with this patch
and post the results?
TIA, HTH, HAND, regards
yon
Example output:
--------------------------------
ospfd# show thread cpu
Runtime(ms) Invoked Avg uSecs Max uSecs Type Thread
14.829 31 478 585 T ospf_ase_calculate_timer
82.132 9838 8 291 EX ospf_nsm_event
0.029 1 29 29 E ospf_default_originate_timer
0.254 9 28 34 T ospf_db_desc_timer
0.026 7 3 11 T ospf_wait_timer
669.015 523 1279 490696 R vty_read
4.415 45 98 173 TE ospf_network_lsa_refresh_timer
15.026 31 484 588 T ospf_spf_calculate_timer
29.478 1593 18 122 E ospf_ls_upd_send_queue_event
0.173 1 173 173 T vty_timeout
4.173 242 17 58 E ospf_ls_ack_send_event
637.767 121223 5 55 T ospf_ls_ack_timer
39.373 244 161 2691 R zclient_read
12.169 98 124 726 EX ospf_ism_event
0.226 2 113 125 R vty_accept
537.776 14256 37 3813 W ospf_write
4.967 41 121 250 T ospf_router_lsa_timer
0.672 1 672 672 E zclient_connect
7.901 1658 4 26 T ospf_ls_req_timer
0.459 2 229 266 E ospf_external_lsa_originate_timer
3.203 60 53 305 T ospf_maxage_lsa_remover
108.341 9772 11 65 T ospf_ls_upd_timer
33.302 525 63 8628 W vty_flush
0.101 1 101 101 T ospf_router_lsa_update_timer
0.016 1 16 16 T ospf_router_id_update_timer
26.970 407 66 176 T ospf_lsa_maxage_walker
381.949 12244 31 69 T ospf_hello_timer
0.114 22 5 14 T ospf_inactivity_timer
34.290 1223 28 310 T ospf_lsa_refresh_walker
470.645 6592 71 665 R ospf_read
3119.791 180693 17 490696 RWTEX TOTAL
ospfd#
bgpd# sh t c TeX
Runtime(ms) Invoked Avg uSecs Max uSecs Type Thread
21.504 476 45 71 T bgp_keepalive_timer
17.784 1157 15 131 T bgp_reuse_timer
29.080 193 150 249 T bgp_scan
23.606 995 23 420 E bgp_event
317.734 28572 11 69 T bgp_routeadv_timer
0.084 1 84 84 E zlookup_connect
0.526 1 526 526 E zclient_connect
1.348 13 103 147 T bgp_start_timer
19.443 142 136 420 T bgp_connect_timer
16.032 772 20 27 T bgp_import
447.141 32322 13 526 TEX TOTAL
bgpd#
bgpd# show thread cpu rw
Runtime(ms) Invoked Avg uSecs Max uSecs Type Thread
155.043 7 22149 150659 R bgp_accept
129.638 180 720 53844 R vty_read
1.734 56 30 129 R zclient_read
0.255 2 127 148 R vty_accept
58.483 983 59 340 R bgp_read
171.495 29190 5 245 W bgp_write
13.884 181 76 2542 W vty_flush
530.532 30599 17 150659 RW TOTAL
bgpd#
--------------------------------
2003-01-18 00:47:00 +01:00
|
|
|
#include "thread.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"
|
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"
|
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"
|
2016-08-11 02:04:20 +02:00
|
|
|
|
2016-04-16 04:19:37 +02:00
|
|
|
#ifndef AF_MPLS
|
|
|
|
#define AF_MPLS 28
|
|
|
|
#endif
|
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
static vlanid_t filter_vlan = 0;
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
struct gw_family_t {
|
2018-03-27 21:13:34 +02:00
|
|
|
uint16_t filler;
|
|
|
|
uint16_t family;
|
2017-07-17 14:03:14 +02:00
|
|
|
union g_addr gate;
|
2016-04-16 04:19:37 +02:00
|
|
|
};
|
|
|
|
|
2017-05-26 03:11:24 +02:00
|
|
|
char ipv4_ll_buf[16] = "169.254.0.1";
|
|
|
|
struct in_addr ipv4_ll;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
void rt_netlink_init(void)
|
2017-05-26 03:11:24 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
inet_pton(AF_INET, ipv4_ll_buf, &ipv4_ll);
|
2017-05-26 03:11:24 +02:00
|
|
|
}
|
|
|
|
|
2017-01-11 23:33:39 +01:00
|
|
|
static inline int is_selfroute(int proto)
|
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if ((proto == RTPROT_BGP) || (proto == RTPROT_OSPF)
|
2018-05-25 20:36:12 +02:00
|
|
|
|| (proto == RTPROT_ZSTATIC) || (proto == RTPROT_ZEBRA)
|
2017-07-17 14:03:14 +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)
|
|
|
|
|| (proto == RTPROT_PBR)) {
|
2017-07-17 14:03:14 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2017-01-11 23:33:39 +01:00
|
|
|
}
|
|
|
|
|
2017-09-01 16:28:19 +02:00
|
|
|
static inline int zebra2proto(int proto)
|
2017-01-11 23:33:39 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
switch (proto) {
|
|
|
|
case ZEBRA_ROUTE_BABEL:
|
|
|
|
proto = RTPROT_BABEL;
|
|
|
|
break;
|
|
|
|
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-07-17 14:03:14 +02: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;
|
|
|
|
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;
|
2017-07-17 14:03:14 +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
|
|
|
|
*/
|
|
|
|
zlog_warn("%s: Please add this protocol(%d) to proper rt_netlink.c handling",
|
|
|
|
__PRETTY_FUNCTION__, proto);
|
2017-07-17 14:03:14 +02:00
|
|
|
proto = RTPROT_ZEBRA;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return proto;
|
2017-01-11 23:33:39 +01:00
|
|
|
}
|
|
|
|
|
2017-09-01 16:28:19 +02:00
|
|
|
static inline int proto2zebra(int proto, int family)
|
|
|
|
{
|
|
|
|
switch (proto) {
|
|
|
|
case RTPROT_BABEL:
|
|
|
|
proto = ZEBRA_ROUTE_BABEL;
|
|
|
|
break;
|
|
|
|
case RTPROT_BGP:
|
|
|
|
proto = ZEBRA_ROUTE_BGP;
|
|
|
|
break;
|
|
|
|
case RTPROT_OSPF:
|
2018-03-06 20:02:52 +01:00
|
|
|
proto = (family == AFI_IP) ? 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;
|
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
|
|
|
|
*/
|
|
|
|
zlog_warn("%s: Please add this protocol(%d) to proper rt_netlink.c handling",
|
|
|
|
__PRETTY_FUNCTION__,
|
|
|
|
proto);
|
2017-09-01 16:28:19 +02:00
|
|
|
proto = ZEBRA_ROUTE_KERNEL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return proto;
|
|
|
|
}
|
|
|
|
|
2016-02-01 19:55:42 +01:00
|
|
|
/*
|
|
|
|
Pending: create an efficient table_id (in a tree/hash) based lookup)
|
|
|
|
*/
|
2018-03-27 21:13:34 +02:00
|
|
|
static vrf_id_t vrf_lookup_by_table(uint32_t table_id, ns_id_t ns_id)
|
2016-02-01 19:55:42 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct vrf *vrf;
|
|
|
|
struct zebra_vrf *zvrf;
|
2016-02-01 19:55:42 +01:00
|
|
|
|
2017-09-15 17:47:35 +02:00
|
|
|
RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
|
2018-01-22 09:42:53 +01:00
|
|
|
zvrf = vrf->info;
|
|
|
|
if (zvrf == NULL)
|
2017-07-17 14:03:14 +02:00
|
|
|
continue;
|
2018-01-22 09:42:53 +01:00
|
|
|
/* case vrf with netns : match the netnsid */
|
|
|
|
if (vrf_is_backend_netns()) {
|
|
|
|
if (ns_id == zvrf_id(zvrf))
|
|
|
|
return zvrf_id(zvrf);
|
|
|
|
} else {
|
|
|
|
/* VRF is VRF_BACKEND_VRF_LITE */
|
|
|
|
if (zvrf->table_id != table_id)
|
|
|
|
continue;
|
|
|
|
return zvrf_id(zvrf);
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2016-02-01 19:55:42 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return VRF_DEFAULT;
|
2016-02-01 19:55:42 +01:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Looking up routing table by netlink interface. */
|
2018-05-23 15:37:06 +02:00
|
|
|
static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id,
|
2017-07-17 14:03:14 +02:00
|
|
|
int startup)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int len;
|
|
|
|
struct rtmsg *rtm;
|
|
|
|
struct rtattr *tb[RTA_MAX + 1];
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t flags = 0;
|
2017-07-17 14:03:14 +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;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
char anyaddr[16] = {0};
|
|
|
|
|
2017-09-01 16:28:19 +02:00
|
|
|
int proto = ZEBRA_ROUTE_KERNEL;
|
2017-07-17 14:03:14 +02:00
|
|
|
int index = 0;
|
|
|
|
int table;
|
|
|
|
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;
|
2017-07-17 14:03:14 +02: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
|
|
|
|
|
|
|
rtm = NLMSG_DATA(h);
|
|
|
|
|
|
|
|
if (startup && h->nlmsg_type != RTM_NEWROUTE)
|
|
|
|
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:
|
2017-07-17 14:03:14 +02:00
|
|
|
return 0;
|
2010-02-05 04:58:46 +01:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg));
|
2018-06-22 20:22:02 +02:00
|
|
|
if (len < 0) {
|
|
|
|
zlog_err("%s: Message received from netlink is of a broken size %d %zu",
|
|
|
|
__PRETTY_FUNCTION__, h->nlmsg_len,
|
|
|
|
(size_t)NLMSG_LENGTH(sizeof(struct rtmsg)));
|
2017-07-17 14:03:14 +02:00
|
|
|
return -1;
|
2018-06-22 20:22:02 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
memset(tb, 0, sizeof tb);
|
|
|
|
netlink_parse_rtattr(tb, RTA_MAX, RTM_RTA(rtm), len);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (!startup && is_selfroute(rtm->rtm_protocol)
|
2018-05-25 20:45:16 +02:00
|
|
|
&& h->nlmsg_type == RTM_NEWROUTE) {
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("Route type: %d Received that we think we have originated, ignoring",
|
|
|
|
rtm->rtm_protocol);
|
2017-07-17 14:03:14 +02:00
|
|
|
return 0;
|
2018-05-25 20:45:16 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
/* We don't care about change notifications for the MPLS table. */
|
|
|
|
/* TODO: Revisit this. */
|
|
|
|
if (rtm->rtm_family == AF_MPLS)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Table corresponding to route. */
|
|
|
|
if (tb[RTA_TABLE])
|
|
|
|
table = *(int *)RTA_DATA(tb[RTA_TABLE]);
|
|
|
|
else
|
|
|
|
table = rtm->rtm_table;
|
|
|
|
|
|
|
|
/* Map to VRF */
|
2018-01-22 09:42:53 +01:00
|
|
|
vrf_id = vrf_lookup_by_table(table, ns_id);
|
2017-07-17 14:03:14 +02:00
|
|
|
if (vrf_id == VRF_DEFAULT) {
|
|
|
|
if (!is_zebra_valid_kernel_table(table)
|
|
|
|
&& !is_zebra_main_routing_table(table))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Route which inserted by Zebra. */
|
2017-09-01 16:28:19 +02:00
|
|
|
if (is_selfroute(rtm->rtm_protocol)) {
|
2017-07-17 14:03:14 +02:00
|
|
|
flags |= ZEBRA_FLAG_SELFROUTE;
|
2017-09-01 16:28:19 +02:00
|
|
|
proto = proto2zebra(rtm->rtm_protocol, rtm->rtm_family);
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
if (tb[RTA_OIF])
|
|
|
|
index = *(int *)RTA_DATA(tb[RTA_OIF]);
|
|
|
|
|
|
|
|
if (tb[RTA_DST])
|
|
|
|
dest = RTA_DATA(tb[RTA_DST]);
|
|
|
|
else
|
|
|
|
dest = anyaddr;
|
|
|
|
|
|
|
|
if (tb[RTA_SRC])
|
|
|
|
src = RTA_DATA(tb[RTA_SRC]);
|
|
|
|
else
|
|
|
|
src = anyaddr;
|
|
|
|
|
|
|
|
if (tb[RTA_PREFSRC])
|
|
|
|
prefsrc = RTA_DATA(tb[RTA_PREFSRC]);
|
|
|
|
|
|
|
|
if (tb[RTA_GATEWAY])
|
|
|
|
gate = RTA_DATA(tb[RTA_GATEWAY]);
|
|
|
|
|
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
|
|
|
memset(mxrta, 0, sizeof mxrta);
|
2018-03-06 20:02:52 +01:00
|
|
|
netlink_parse_rtattr(mxrta, RTAX_MAX, RTA_DATA(tb[RTA_METRICS]),
|
2017-08-09 15:13:33 +02:00
|
|
|
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]);
|
2017-07-17 14:03:14 +02: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) {
|
|
|
|
zlog_warn(
|
|
|
|
"Invalid destination prefix length: %d received from kernel route change",
|
|
|
|
rtm->rtm_dst_len);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
memcpy(&p.u.prefix4, dest, 4);
|
|
|
|
p.prefixlen = rtm->rtm_dst_len;
|
|
|
|
|
|
|
|
src_p.prefixlen =
|
|
|
|
0; // Forces debug below to not display anything
|
2018-07-21 05:20:28 +02:00
|
|
|
|
2017-07-17 14:03:14 +02: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) {
|
|
|
|
zlog_warn(
|
|
|
|
"Invalid destination prefix length: %d received from kernel route change",
|
|
|
|
rtm->rtm_dst_len);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
memcpy(&p.u.prefix6, dest, 16);
|
|
|
|
p.prefixlen = rtm->rtm_dst_len;
|
|
|
|
|
|
|
|
src_p.family = AF_INET6;
|
2018-07-21 05:20:28 +02:00
|
|
|
if (rtm->rtm_src_len > IPV6_MAX_BITLEN) {
|
|
|
|
zlog_warn(
|
|
|
|
"Invalid source prefix length: %d received from kernel route change",
|
|
|
|
rtm->rtm_src_len);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
memcpy(&src_p.prefix, src, 16);
|
|
|
|
src_p.prefixlen = rtm->rtm_src_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rtm->rtm_src_len != 0) {
|
|
|
|
char buf[PREFIX_STRLEN];
|
|
|
|
zlog_warn(
|
|
|
|
"unsupported IPv[4|6] sourcedest route (dest %s vrf %u)",
|
|
|
|
prefix2str(&p, buf, sizeof(buf)), vrf_id);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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;
|
2018-03-06 20:02:52 +01:00
|
|
|
metric = (metric & 0x00FFFFFF);
|
2017-09-25 14:37:04 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL) {
|
|
|
|
char buf[PREFIX_STRLEN];
|
|
|
|
char buf2[PREFIX_STRLEN];
|
2018-04-09 20:09:35 +02:00
|
|
|
zlog_debug("%s %s%s%s vrf %u(%u) metric: %d Admin Distance: %d",
|
2018-03-06 20:02:52 +01:00
|
|
|
nl_msg_type_to_str(h->nlmsg_type),
|
|
|
|
prefix2str(&p, buf, sizeof(buf)),
|
|
|
|
src_p.prefixlen ? " from " : "",
|
|
|
|
src_p.prefixlen
|
|
|
|
? prefix2str(&src_p, buf2, sizeof(buf2))
|
|
|
|
: "",
|
2018-04-09 20:09:35 +02:00
|
|
|
vrf_id, table, metric, distance);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
afi_t afi = AFI_IP;
|
|
|
|
if (rtm->rtm_family == AF_INET6)
|
|
|
|
afi = AFI_IP6;
|
|
|
|
|
|
|
|
if (h->nlmsg_type == RTM_NEWROUTE) {
|
2018-01-08 16:21:09 +01:00
|
|
|
struct interface *ifp;
|
|
|
|
vrf_id_t nh_vrf_id = vrf_id;
|
|
|
|
|
2017-08-28 01:30:16 +02:00
|
|
|
if (!tb[RTA_MULTIPATH]) {
|
|
|
|
struct nexthop nh;
|
|
|
|
size_t sz = (afi == AFI_IP) ? 4 : 16;
|
|
|
|
|
|
|
|
memset(&nh, 0, sizeof(nh));
|
2017-08-31 01:38:22 +02:00
|
|
|
|
|
|
|
if (bh_type == BLACKHOLE_UNSPEC) {
|
|
|
|
if (index && !gate)
|
|
|
|
nh.type = NEXTHOP_TYPE_IFINDEX;
|
|
|
|
else if (index && gate)
|
2018-03-06 20:02:52 +01:00
|
|
|
nh.type =
|
|
|
|
(afi == AFI_IP)
|
|
|
|
? NEXTHOP_TYPE_IPV4_IFINDEX
|
|
|
|
: NEXTHOP_TYPE_IPV6_IFINDEX;
|
2017-08-31 01:38:22 +02:00
|
|
|
else if (!index && gate)
|
2017-09-01 01:58:16 +02:00
|
|
|
nh.type = (afi == AFI_IP)
|
|
|
|
? NEXTHOP_TYPE_IPV4
|
|
|
|
: NEXTHOP_TYPE_IPV6;
|
2017-08-31 01:38:22 +02:00
|
|
|
else {
|
|
|
|
nh.type = NEXTHOP_TYPE_BLACKHOLE;
|
|
|
|
nh.bh_type = bh_type;
|
|
|
|
}
|
|
|
|
} else {
|
2017-08-28 01:30:16 +02:00
|
|
|
nh.type = NEXTHOP_TYPE_BLACKHOLE;
|
2010-02-05 04:58:46 +01:00
|
|
|
nh.bh_type = bh_type;
|
|
|
|
}
|
2017-08-28 01:30:16 +02:00
|
|
|
nh.ifindex = index;
|
|
|
|
if (prefsrc)
|
|
|
|
memcpy(&nh.src, prefsrc, sz);
|
|
|
|
if (gate)
|
|
|
|
memcpy(&nh.gate, gate, sz);
|
2017-09-01 16:28:19 +02:00
|
|
|
|
2018-01-08 16:21:09 +01:00
|
|
|
if (index) {
|
2018-07-02 10:33:00 +02:00
|
|
|
ifp = if_lookup_by_index_per_ns(
|
|
|
|
zebra_ns_lookup(ns_id),
|
|
|
|
index);
|
2018-01-08 16:21:09 +01:00
|
|
|
if (ifp)
|
|
|
|
nh_vrf_id = ifp->vrf_id;
|
|
|
|
}
|
2018-02-08 15:12:12 +01:00
|
|
|
nh.vrf_id = nh_vrf_id;
|
2018-01-08 16:21:09 +01:00
|
|
|
|
2018-02-08 15:12:12 +01:00
|
|
|
rib_add(afi, SAFI_UNICAST, vrf_id, proto, 0, flags, &p,
|
|
|
|
NULL, &nh, table, metric, mtu, distance, tag);
|
2017-08-28 01:30:16 +02:00
|
|
|
} else {
|
2017-07-17 14:03:14 +02:00
|
|
|
/* This is a multipath route */
|
|
|
|
|
|
|
|
struct route_entry *re;
|
|
|
|
struct rtnexthop *rtnh =
|
|
|
|
(struct rtnexthop *)RTA_DATA(tb[RTA_MULTIPATH]);
|
|
|
|
|
|
|
|
len = RTA_PAYLOAD(tb[RTA_MULTIPATH]);
|
|
|
|
|
|
|
|
re = XCALLOC(MTYPE_RE, sizeof(struct route_entry));
|
2017-09-01 16:28:19 +02:00
|
|
|
re->type = proto;
|
2017-09-25 14:37:04 +02:00
|
|
|
re->distance = distance;
|
2017-07-17 14:03:14 +02:00
|
|
|
re->flags = flags;
|
|
|
|
re->metric = metric;
|
|
|
|
re->mtu = mtu;
|
|
|
|
re->vrf_id = vrf_id;
|
|
|
|
re->table = table;
|
|
|
|
re->nexthop_num = 0;
|
|
|
|
re->uptime = time(NULL);
|
2017-12-08 20:44:15 +01:00
|
|
|
re->tag = tag;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
for (;;) {
|
2018-02-08 15:12:12 +01:00
|
|
|
vrf_id_t nh_vrf_id;
|
2017-07-17 14:03:14 +02:00
|
|
|
if (len < (int)sizeof(*rtnh)
|
|
|
|
|| rtnh->rtnh_len > len)
|
|
|
|
break;
|
|
|
|
|
|
|
|
index = rtnh->rtnh_ifindex;
|
2018-01-08 16:21:09 +01:00
|
|
|
if (index) {
|
|
|
|
/*
|
|
|
|
* Yes we are looking this up
|
|
|
|
* for every nexthop and just
|
|
|
|
* using the last one looked
|
|
|
|
* up right now
|
|
|
|
*/
|
2018-07-02 10:33:00 +02:00
|
|
|
ifp = if_lookup_by_index_per_ns(
|
|
|
|
zebra_ns_lookup(ns_id),
|
|
|
|
index);
|
2018-01-08 16:21:09 +01:00
|
|
|
if (ifp)
|
2018-02-08 15:12:12 +01:00
|
|
|
nh_vrf_id = ifp->vrf_id;
|
|
|
|
else {
|
|
|
|
zlog_warn(
|
|
|
|
"%s: Unknown interface %u specified, defaulting to VRF_DEFAULT",
|
|
|
|
__PRETTY_FUNCTION__,
|
|
|
|
index);
|
|
|
|
nh_vrf_id = VRF_DEFAULT;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
nh_vrf_id = vrf_id;
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
gate = 0;
|
|
|
|
if (rtnh->rtnh_len > sizeof(*rtnh)) {
|
|
|
|
memset(tb, 0, sizeof(tb));
|
|
|
|
netlink_parse_rtattr(
|
|
|
|
tb, RTA_MAX, RTNH_DATA(rtnh),
|
|
|
|
rtnh->rtnh_len - sizeof(*rtnh));
|
|
|
|
if (tb[RTA_GATEWAY])
|
|
|
|
gate = RTA_DATA(
|
|
|
|
tb[RTA_GATEWAY]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gate) {
|
|
|
|
if (rtm->rtm_family == AF_INET) {
|
|
|
|
if (index)
|
|
|
|
route_entry_nexthop_ipv4_ifindex_add(
|
|
|
|
re, gate,
|
2018-02-08 15:12:12 +01:00
|
|
|
prefsrc, index,
|
|
|
|
nh_vrf_id);
|
2017-07-17 14:03:14 +02:00
|
|
|
else
|
|
|
|
route_entry_nexthop_ipv4_add(
|
|
|
|
re, gate,
|
2018-02-08 15:12:12 +01:00
|
|
|
prefsrc,
|
|
|
|
nh_vrf_id);
|
2017-07-17 14:03:14 +02:00
|
|
|
} else if (rtm->rtm_family
|
|
|
|
== AF_INET6) {
|
|
|
|
if (index)
|
|
|
|
route_entry_nexthop_ipv6_ifindex_add(
|
2018-02-08 15:12:12 +01:00
|
|
|
re, gate, index,
|
|
|
|
nh_vrf_id);
|
2017-07-17 14:03:14 +02:00
|
|
|
else
|
|
|
|
route_entry_nexthop_ipv6_add(
|
2018-02-08 15:12:12 +01:00
|
|
|
re, gate,
|
|
|
|
nh_vrf_id);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
} else
|
2018-02-08 15:12:12 +01:00
|
|
|
route_entry_nexthop_ifindex_add(
|
|
|
|
re, index, nh_vrf_id);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
len -= NLMSG_ALIGN(rtnh->rtnh_len);
|
|
|
|
rtnh = RTNH_NEXT(rtnh);
|
|
|
|
}
|
|
|
|
|
|
|
|
zserv_nexthop_num_warn(__func__,
|
|
|
|
(const struct prefix *)&p,
|
|
|
|
re->nexthop_num);
|
|
|
|
if (re->nexthop_num == 0)
|
|
|
|
XFREE(MTYPE_RE, re);
|
|
|
|
else
|
2018-03-06 20:02:52 +01:00
|
|
|
rib_add_multipath(afi, SAFI_UNICAST, &p, NULL,
|
|
|
|
re);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-08-28 01:30:16 +02:00
|
|
|
if (!tb[RTA_MULTIPATH]) {
|
|
|
|
struct nexthop nh;
|
|
|
|
size_t sz = (afi == AFI_IP) ? 4 : 16;
|
|
|
|
|
|
|
|
memset(&nh, 0, sizeof(nh));
|
2017-09-01 02:13:23 +02:00
|
|
|
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
|
2017-08-30 17:23:01 +02:00
|
|
|
: NEXTHOP_TYPE_IPV6;
|
2017-09-01 02:13:23 +02:00
|
|
|
else {
|
|
|
|
nh.type = NEXTHOP_TYPE_BLACKHOLE;
|
|
|
|
nh.bh_type = BLACKHOLE_UNSPEC;
|
|
|
|
}
|
|
|
|
} else {
|
2017-08-28 01:30:16 +02:00
|
|
|
nh.type = NEXTHOP_TYPE_BLACKHOLE;
|
2017-09-01 02:13:23 +02:00
|
|
|
nh.bh_type = bh_type;
|
|
|
|
}
|
2017-08-28 01:30:16 +02:00
|
|
|
nh.ifindex = index;
|
|
|
|
if (gate)
|
|
|
|
memcpy(&nh.gate, gate, sz);
|
2018-03-06 20:02:52 +01:00
|
|
|
rib_delete(afi, SAFI_UNICAST, vrf_id, proto, 0, flags,
|
2017-11-29 08:40:30 +01:00
|
|
|
&p, NULL, &nh, table, metric, true);
|
2017-08-28 01:30:16 +02:00
|
|
|
} else {
|
|
|
|
/* XXX: need to compare the entire list of nexthops
|
|
|
|
* here for NLM_F_APPEND stupidity */
|
2018-03-06 20:02:52 +01:00
|
|
|
rib_delete(afi, SAFI_UNICAST, vrf_id, proto, 0, flags,
|
2017-11-29 08:40:30 +01:00
|
|
|
&p, NULL, NULL, table, metric, true);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
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-07-17 14:03:14 +02:00
|
|
|
ns_id_t ns_id, int startup)
|
2016-08-04 01:53:42 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int len;
|
|
|
|
struct rtmsg *rtm;
|
|
|
|
struct rtattr *tb[RTA_MAX + 1];
|
|
|
|
struct mcast_route_data *m;
|
|
|
|
struct mcast_route_data mr;
|
|
|
|
int iif = 0;
|
|
|
|
int count;
|
|
|
|
int oif[256];
|
|
|
|
int oif_count = 0;
|
|
|
|
char sbuf[40];
|
|
|
|
char gbuf[40];
|
|
|
|
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
|
|
|
|
|
|
|
if (mroute)
|
|
|
|
m = mroute;
|
|
|
|
else {
|
|
|
|
memset(&mr, 0, sizeof(mr));
|
|
|
|
m = &mr;
|
|
|
|
}
|
|
|
|
|
|
|
|
rtm = NLMSG_DATA(h);
|
|
|
|
|
|
|
|
len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg));
|
|
|
|
|
|
|
|
memset(tb, 0, sizeof tb);
|
|
|
|
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;
|
|
|
|
|
2018-01-22 09:42:53 +01:00
|
|
|
vrf = vrf_lookup_by_table(table, ns_id);
|
2017-06-06 16:18:17 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (tb[RTA_IIF])
|
|
|
|
iif = *(int *)RTA_DATA(tb[RTA_IIF]);
|
|
|
|
|
|
|
|
if (tb[RTA_SRC])
|
2017-07-05 17:53:29 +02:00
|
|
|
m->sg.src = *(struct in_addr *)RTA_DATA(tb[RTA_SRC]);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
if (tb[RTA_DST])
|
2017-07-05 17:53:29 +02:00
|
|
|
m->sg.grp = *(struct in_addr *)RTA_DATA(tb[RTA_DST]);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
if ((RTA_EXPIRES <= RTA_MAX) && tb[RTA_EXPIRES])
|
|
|
|
m->lastused = *(unsigned long long *)RTA_DATA(tb[RTA_EXPIRES]);
|
|
|
|
|
|
|
|
if (tb[RTA_MULTIPATH]) {
|
|
|
|
struct rtnexthop *rtnh =
|
|
|
|
(struct rtnexthop *)RTA_DATA(tb[RTA_MULTIPATH]);
|
|
|
|
|
|
|
|
len = RTA_PAYLOAD(tb[RTA_MULTIPATH]);
|
|
|
|
for (;;) {
|
|
|
|
if (len < (int)sizeof(*rtnh) || rtnh->rtnh_len > len)
|
|
|
|
break;
|
|
|
|
|
|
|
|
oif[oif_count] = rtnh->rtnh_ifindex;
|
|
|
|
oif_count++;
|
|
|
|
|
|
|
|
len -= NLMSG_ALIGN(rtnh->rtnh_len);
|
|
|
|
rtnh = RTNH_NEXT(rtnh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL) {
|
|
|
|
struct interface *ifp;
|
2017-08-25 02:43:29 +02:00
|
|
|
strlcpy(sbuf, inet_ntoa(m->sg.src), sizeof(sbuf));
|
|
|
|
strlcpy(gbuf, inet_ntoa(m->sg.grp), sizeof(gbuf));
|
2017-07-17 14:03:14 +02:00
|
|
|
for (count = 0; count < oif_count; count++) {
|
|
|
|
ifp = if_lookup_by_index(oif[count], vrf);
|
|
|
|
char temp[256];
|
|
|
|
|
|
|
|
sprintf(temp, "%s ", ifp->name);
|
|
|
|
strcat(oif_list, temp);
|
|
|
|
}
|
2017-06-06 16:18:17 +02:00
|
|
|
struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(vrf);
|
2017-07-17 14:03:14 +02:00
|
|
|
ifp = if_lookup_by_index(iif, vrf);
|
2017-06-06 16:18:17 +02:00
|
|
|
zlog_debug(
|
|
|
|
"MCAST VRF: %s(%d) %s (%s,%s) IIF: %s OIF: %s jiffies: %lld",
|
|
|
|
zvrf->vrf->name, vrf, nl_msg_type_to_str(h->nlmsg_type),
|
|
|
|
sbuf, gbuf, ifp->name, oif_list, m->lastused);
|
2016-08-10 14:54:58 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
return 0;
|
2016-08-04 01:53:42 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int len;
|
|
|
|
struct rtmsg *rtm;
|
|
|
|
|
|
|
|
rtm = NLMSG_DATA(h);
|
|
|
|
|
|
|
|
if (!(h->nlmsg_type == RTM_NEWROUTE || h->nlmsg_type == RTM_DELROUTE)) {
|
|
|
|
/* If this is not route add/delete message print warning. */
|
2018-01-22 09:42:53 +01:00
|
|
|
zlog_warn("Kernel message: %d NS %u\n", h->nlmsg_type, ns_id);
|
2017-07-17 14:03:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Connected route. */
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
2018-01-22 09:42:53 +01:00
|
|
|
zlog_debug("%s %s %s proto %s NS %u",
|
2017-07-17 14:03:14 +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
|
|
|
|
|
|
|
/* We don't care about change notifications for the MPLS table. */
|
|
|
|
/* TODO: Revisit this. */
|
|
|
|
if (rtm->rtm_family == AF_MPLS)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg));
|
2018-06-22 20:22:02 +02:00
|
|
|
if (len < 0) {
|
|
|
|
zlog_err("%s: Message received from netlink is of a broken size: %d %zu",
|
|
|
|
__PRETTY_FUNCTION__,
|
|
|
|
h->nlmsg_len,
|
|
|
|
(size_t)NLMSG_LENGTH(sizeof(struct rtmsg)));
|
2017-07-17 14:03:14 +02:00
|
|
|
return -1;
|
2018-06-22 20:22:02 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2010-02-05 04:58:46 +01:00
|
|
|
if (rtm->rtm_type == RTN_MULTICAST)
|
2018-05-23 15:37:06 +02:00
|
|
|
netlink_route_change_read_multicast(h, ns_id, startup);
|
2010-02-05 04:58:46 +01:00
|
|
|
else
|
2018-05-23 15:37:06 +02:00
|
|
|
netlink_route_change_read_unicast(h, ns_id, startup);
|
2017-07-17 14:03:14 +02:00
|
|
|
return 0;
|
2016-08-04 01:53:42 +02:00
|
|
|
}
|
|
|
|
|
2017-05-15 07:28:32 +02:00
|
|
|
/* Request for specific route information from the kernel */
|
2017-07-17 14:03:14 +02:00
|
|
|
static int netlink_request_route(struct zebra_ns *zns, int family, int type)
|
2017-05-15 07:28:32 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct rtmsg rtm;
|
|
|
|
} req;
|
|
|
|
|
|
|
|
/* Form the request, specifying filter (rtattr) if needed. */
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
req.n.nlmsg_type = type;
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
|
|
|
|
req.rtm.rtm_family = family;
|
|
|
|
|
|
|
|
return netlink_request(&zns->netlink_cmd, &req.n);
|
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. */
|
2017-07-17 14:03:14 +02:00
|
|
|
int netlink_route_read(struct zebra_ns *zns)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Get IPv4 routing table. */
|
|
|
|
ret = netlink_request_route(zns, AF_INET, RTM_GETROUTE);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
ret = netlink_parse_info(netlink_route_change_read_unicast,
|
|
|
|
&zns->netlink_cmd, zns, 0, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Get IPv6 routing table. */
|
|
|
|
ret = netlink_request_route(zns, AF_INET6, RTM_GETROUTE);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
ret = netlink_parse_info(netlink_route_change_read_unicast,
|
|
|
|
&zns->netlink_cmd, zns, 0, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2018-03-27 21:13:34 +02:00
|
|
|
static void _netlink_route_nl_add_gateway_info(uint8_t route_family,
|
|
|
|
uint8_t gw_family,
|
2017-07-17 14:03:14 +02:00
|
|
|
struct nlmsghdr *nlmsg,
|
|
|
|
size_t req_size, int bytelen,
|
|
|
|
struct nexthop *nexthop)
|
2016-04-16 04:19:37 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if (route_family == AF_MPLS) {
|
|
|
|
struct gw_family_t gw_fam;
|
|
|
|
|
|
|
|
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);
|
|
|
|
addattr_l(nlmsg, req_size, RTA_VIA, &gw_fam.family,
|
|
|
|
bytelen + 2);
|
|
|
|
} else {
|
|
|
|
if (gw_family == AF_INET)
|
|
|
|
addattr_l(nlmsg, req_size, RTA_GATEWAY,
|
|
|
|
&nexthop->gate.ipv4, bytelen);
|
|
|
|
else
|
|
|
|
addattr_l(nlmsg, req_size, RTA_GATEWAY,
|
|
|
|
&nexthop->gate.ipv6, bytelen);
|
|
|
|
}
|
2016-04-16 04:19:37 +02:00
|
|
|
}
|
|
|
|
|
2018-03-27 21:13:34 +02:00
|
|
|
static void _netlink_route_rta_add_gateway_info(uint8_t route_family,
|
|
|
|
uint8_t gw_family,
|
2017-07-17 14:03:14 +02:00
|
|
|
struct rtattr *rta,
|
|
|
|
struct rtnexthop *rtnh,
|
|
|
|
size_t req_size, int bytelen,
|
|
|
|
struct nexthop *nexthop)
|
2016-04-16 04:19:37 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if (route_family == AF_MPLS) {
|
|
|
|
struct gw_family_t gw_fam;
|
|
|
|
|
|
|
|
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);
|
|
|
|
rta_addattr_l(rta, req_size, RTA_VIA, &gw_fam.family,
|
|
|
|
bytelen + 2);
|
|
|
|
rtnh->rtnh_len += RTA_LENGTH(bytelen + 2);
|
|
|
|
} else {
|
|
|
|
if (gw_family == AF_INET)
|
|
|
|
rta_addattr_l(rta, req_size, RTA_GATEWAY,
|
|
|
|
&nexthop->gate.ipv4, bytelen);
|
|
|
|
else
|
|
|
|
rta_addattr_l(rta, req_size, RTA_GATEWAY,
|
|
|
|
&nexthop->gate.ipv6, bytelen);
|
|
|
|
rtnh->rtnh_len += sizeof(struct rtattr) + bytelen;
|
|
|
|
}
|
2016-04-16 04:19:37 +02:00
|
|
|
}
|
|
|
|
|
2013-07-05 17:35:37 +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.
|
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
static void _netlink_route_build_singlepath(const char *routedesc, int bytelen,
|
|
|
|
struct nexthop *nexthop,
|
|
|
|
struct nlmsghdr *nlmsg,
|
|
|
|
struct rtmsg *rtmsg,
|
|
|
|
size_t req_size, int cmd)
|
2013-07-05 17:35:37 +02:00
|
|
|
{
|
2018-01-21 22:11:50 +01:00
|
|
|
struct mpls_label_stack *nh_label;
|
2017-07-17 14:03:14 +02:00
|
|
|
mpls_lse_t out_lse[MPLS_MAX_LABELS];
|
2017-09-20 05:05:25 +02:00
|
|
|
int num_labels = 0;
|
2017-09-20 05:02:01 +02:00
|
|
|
char label_buf[256];
|
2017-07-17 14:03:14 +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
|
|
|
|
*/
|
|
|
|
label_buf[0] = '\0';
|
|
|
|
|
2017-09-20 05:05:25 +02:00
|
|
|
assert(nexthop);
|
|
|
|
for (struct nexthop *nh = nexthop; nh; nh = nh->rparent) {
|
2017-07-17 14:03:14 +02:00
|
|
|
char label_buf1[20];
|
|
|
|
|
2017-09-20 05:05:25 +02:00
|
|
|
nh_label = nh->nh_label;
|
|
|
|
if (!nh_label || !nh_label->num_labels)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (int i = 0; i < nh_label->num_labels; i++) {
|
|
|
|
if (nh_label->label[i] == MPLS_LABEL_IMPLICIT_NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL) {
|
|
|
|
if (!num_labels)
|
|
|
|
sprintf(label_buf, "label %u",
|
|
|
|
nh_label->label[i]);
|
|
|
|
else {
|
|
|
|
sprintf(label_buf1, "/%u",
|
|
|
|
nh_label->label[i]);
|
|
|
|
strlcat(label_buf, label_buf1,
|
|
|
|
sizeof(label_buf));
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-20 05:05:25 +02:00
|
|
|
|
|
|
|
out_lse[num_labels] =
|
|
|
|
mpls_lse_encode(nh_label->label[i], 0, 0, 0);
|
|
|
|
num_labels++;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2017-09-20 05:05:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (num_labels) {
|
|
|
|
/* Set the BoS bit */
|
|
|
|
out_lse[num_labels - 1] |= htonl(1 << MPLS_LS_S_SHIFT);
|
|
|
|
|
|
|
|
if (rtmsg->rtm_family == AF_MPLS)
|
|
|
|
addattr_l(nlmsg, req_size, RTA_NEWDST, &out_lse,
|
|
|
|
num_labels * sizeof(mpls_lse_t));
|
|
|
|
else {
|
|
|
|
struct rtattr *nest;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint16_t encap = LWTUNNEL_ENCAP_MPLS;
|
2017-09-20 05:05:25 +02:00
|
|
|
|
|
|
|
addattr_l(nlmsg, req_size, RTA_ENCAP_TYPE, &encap,
|
2018-03-27 21:13:34 +02:00
|
|
|
sizeof(uint16_t));
|
2017-09-20 05:05:25 +02:00
|
|
|
nest = addattr_nest(nlmsg, req_size, RTA_ENCAP);
|
|
|
|
addattr_l(nlmsg, req_size, MPLS_IPTUNNEL_DST, &out_lse,
|
|
|
|
num_labels * sizeof(mpls_lse_t));
|
|
|
|
addattr_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
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK))
|
|
|
|
rtmsg->rtm_flags |= RTNH_F_ONLINK;
|
|
|
|
|
|
|
|
if (rtmsg->rtm_family == AF_INET
|
|
|
|
&& (nexthop->type == NEXTHOP_TYPE_IPV6
|
|
|
|
|| nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX)) {
|
|
|
|
rtmsg->rtm_flags |= RTNH_F_ONLINK;
|
|
|
|
addattr_l(nlmsg, req_size, RTA_GATEWAY, &ipv4_ll, 4);
|
|
|
|
addattr32(nlmsg, req_size, RTA_OIF, nexthop->ifindex);
|
|
|
|
|
|
|
|
if (nexthop->rmap_src.ipv4.s_addr && (cmd == RTM_NEWROUTE))
|
|
|
|
addattr_l(nlmsg, req_size, RTA_PREFSRC,
|
|
|
|
&nexthop->rmap_src.ipv4, bytelen);
|
|
|
|
else if (nexthop->src.ipv4.s_addr && (cmd == RTM_NEWROUTE))
|
|
|
|
addattr_l(nlmsg, req_size, RTA_PREFSRC,
|
|
|
|
&nexthop->src.ipv4, bytelen);
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
|
|
|
" 5549: _netlink_route_build_singlepath() (%s): "
|
2018-03-29 14:58:45 +02:00
|
|
|
"nexthop via %s %s if %u(%u)",
|
2017-07-17 14:03:14 +02:00
|
|
|
routedesc, ipv4_ll_buf, label_buf,
|
2018-03-29 14:58:45 +02:00
|
|
|
nexthop->ifindex, nexthop->vrf_id);
|
2017-07-17 14:03:14 +02:00
|
|
|
return;
|
2015-09-16 08:48:00 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (nexthop->type == NEXTHOP_TYPE_IPV4
|
|
|
|
|| nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX) {
|
|
|
|
/* Send deletes to the kernel without specifying the next-hop */
|
|
|
|
if (cmd != RTM_DELROUTE)
|
|
|
|
_netlink_route_nl_add_gateway_info(
|
|
|
|
rtmsg->rtm_family, AF_INET, nlmsg, req_size,
|
|
|
|
bytelen, nexthop);
|
|
|
|
|
|
|
|
if (cmd == RTM_NEWROUTE) {
|
|
|
|
if (nexthop->rmap_src.ipv4.s_addr)
|
|
|
|
addattr_l(nlmsg, req_size, RTA_PREFSRC,
|
|
|
|
&nexthop->rmap_src.ipv4, bytelen);
|
|
|
|
else if (nexthop->src.ipv4.s_addr)
|
|
|
|
addattr_l(nlmsg, req_size, RTA_PREFSRC,
|
|
|
|
&nexthop->src.ipv4, bytelen);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
|
|
|
"netlink_route_multipath() (%s): "
|
2018-03-29 14:58:45 +02:00
|
|
|
"nexthop via %s %s if %u(%u)",
|
2017-07-17 14:03:14 +02:00
|
|
|
routedesc, inet_ntoa(nexthop->gate.ipv4),
|
2018-03-29 14:58:45 +02:00
|
|
|
label_buf, nexthop->ifindex, nexthop->vrf_id);
|
2015-09-16 08:48:00 +02:00
|
|
|
}
|
2013-07-05 17:35:37 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (nexthop->type == NEXTHOP_TYPE_IPV6
|
|
|
|
|| nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) {
|
|
|
|
_netlink_route_nl_add_gateway_info(rtmsg->rtm_family, AF_INET6,
|
|
|
|
nlmsg, req_size, bytelen,
|
|
|
|
nexthop);
|
|
|
|
|
|
|
|
if (cmd == RTM_NEWROUTE) {
|
|
|
|
if (!IN6_IS_ADDR_UNSPECIFIED(&nexthop->rmap_src.ipv6))
|
|
|
|
addattr_l(nlmsg, req_size, RTA_PREFSRC,
|
|
|
|
&nexthop->rmap_src.ipv6, bytelen);
|
|
|
|
else if (!IN6_IS_ADDR_UNSPECIFIED(&nexthop->src.ipv6))
|
|
|
|
addattr_l(nlmsg, req_size, RTA_PREFSRC,
|
|
|
|
&nexthop->src.ipv6, bytelen);
|
|
|
|
}
|
2013-07-05 17:35:37 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
|
|
|
"netlink_route_multipath() (%s): "
|
2018-03-29 14:58:45 +02:00
|
|
|
"nexthop via %s %s if %u(%u)",
|
2017-07-17 14:03:14 +02:00
|
|
|
routedesc, inet6_ntoa(nexthop->gate.ipv6),
|
2018-03-29 14:58:45 +02:00
|
|
|
label_buf, nexthop->ifindex, 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.
|
|
|
|
*/
|
|
|
|
if (nexthop->type != NEXTHOP_TYPE_BLACKHOLE)
|
2017-07-17 14:03:14 +02:00
|
|
|
addattr32(nlmsg, req_size, RTA_OIF, nexthop->ifindex);
|
|
|
|
|
2018-01-11 17:47:04 +01:00
|
|
|
if (nexthop->type == NEXTHOP_TYPE_IFINDEX
|
|
|
|
|| nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX) {
|
2017-07-17 14:03:14 +02:00
|
|
|
if (cmd == RTM_NEWROUTE) {
|
|
|
|
if (nexthop->rmap_src.ipv4.s_addr)
|
|
|
|
addattr_l(nlmsg, req_size, RTA_PREFSRC,
|
|
|
|
&nexthop->rmap_src.ipv4, bytelen);
|
|
|
|
else if (nexthop->src.ipv4.s_addr)
|
|
|
|
addattr_l(nlmsg, req_size, RTA_PREFSRC,
|
|
|
|
&nexthop->src.ipv4, bytelen);
|
|
|
|
}
|
2013-07-05 17:35:37 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
|
|
|
"netlink_route_multipath() (%s): "
|
2018-03-29 14:58:45 +02:00
|
|
|
"nexthop via if %u(%u)",
|
|
|
|
routedesc, nexthop->ifindex, nexthop->vrf_id);
|
2015-09-16 08:48:00 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) {
|
|
|
|
if (cmd == RTM_NEWROUTE) {
|
|
|
|
if (!IN6_IS_ADDR_UNSPECIFIED(&nexthop->rmap_src.ipv6))
|
|
|
|
addattr_l(nlmsg, req_size, RTA_PREFSRC,
|
|
|
|
&nexthop->rmap_src.ipv6, bytelen);
|
|
|
|
else if (!IN6_IS_ADDR_UNSPECIFIED(&nexthop->src.ipv6))
|
|
|
|
addattr_l(nlmsg, req_size, RTA_PREFSRC,
|
|
|
|
&nexthop->src.ipv6, bytelen);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
|
|
|
"netlink_route_multipath() (%s): "
|
2018-03-29 14:58:45 +02:00
|
|
|
"nexthop via if %u(%u)",
|
|
|
|
routedesc, nexthop->ifindex, nexthop->vrf_id);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2013-07-05 17:35:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function takes a nexthop as argument and
|
|
|
|
* appends to the given rtattr/rtnexthop pair the
|
|
|
|
* representation of the nexthop. If the nexthop
|
|
|
|
* 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
|
|
|
|
* @param rta: rtnetlink attribute structure
|
|
|
|
* @param rtnh: pointer to an rtnetlink nexthop structure
|
|
|
|
* @param src: pointer pointing to a location where
|
|
|
|
* the prefsrc should be stored.
|
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
static void _netlink_route_build_multipath(const char *routedesc, int bytelen,
|
|
|
|
struct nexthop *nexthop,
|
|
|
|
struct rtattr *rta,
|
|
|
|
struct rtnexthop *rtnh,
|
|
|
|
struct rtmsg *rtmsg,
|
|
|
|
union g_addr **src)
|
2013-07-05 17:35:37 +02:00
|
|
|
{
|
2018-01-21 22:11:50 +01:00
|
|
|
struct mpls_label_stack *nh_label;
|
2017-07-17 14:03:14 +02:00
|
|
|
mpls_lse_t out_lse[MPLS_MAX_LABELS];
|
2017-09-20 05:05:25 +02:00
|
|
|
int num_labels = 0;
|
2017-09-20 05:02:01 +02:00
|
|
|
char label_buf[256];
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
rtnh->rtnh_len = sizeof(*rtnh);
|
|
|
|
rtnh->rtnh_flags = 0;
|
|
|
|
rtnh->rtnh_hops = 0;
|
|
|
|
rta->rta_len += rtnh->rtnh_len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
label_buf[0] = '\0';
|
|
|
|
|
2017-09-20 05:05:25 +02:00
|
|
|
assert(nexthop);
|
|
|
|
for (struct nexthop *nh = nexthop; nh; nh = nh->rparent) {
|
2017-07-17 14:03:14 +02:00
|
|
|
char label_buf1[20];
|
|
|
|
|
2017-09-20 05:05:25 +02:00
|
|
|
nh_label = nh->nh_label;
|
|
|
|
if (!nh_label || !nh_label->num_labels)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (int i = 0; i < nh_label->num_labels; i++) {
|
|
|
|
if (nh_label->label[i] == MPLS_LABEL_IMPLICIT_NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL) {
|
|
|
|
if (!num_labels)
|
|
|
|
sprintf(label_buf, "label %u",
|
|
|
|
nh_label->label[i]);
|
|
|
|
else {
|
|
|
|
sprintf(label_buf1, "/%u",
|
|
|
|
nh_label->label[i]);
|
|
|
|
strlcat(label_buf, label_buf1,
|
|
|
|
sizeof(label_buf));
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-20 05:05:25 +02:00
|
|
|
|
|
|
|
out_lse[num_labels] =
|
|
|
|
mpls_lse_encode(nh_label->label[i], 0, 0, 0);
|
|
|
|
num_labels++;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2017-09-20 05:05:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (num_labels) {
|
|
|
|
/* Set the BoS bit */
|
|
|
|
out_lse[num_labels - 1] |= htonl(1 << MPLS_LS_S_SHIFT);
|
|
|
|
|
|
|
|
if (rtmsg->rtm_family == AF_MPLS) {
|
|
|
|
rta_addattr_l(rta, NL_PKT_BUF_SIZE, RTA_NEWDST,
|
|
|
|
&out_lse,
|
|
|
|
num_labels * sizeof(mpls_lse_t));
|
|
|
|
rtnh->rtnh_len +=
|
|
|
|
RTA_LENGTH(num_labels * sizeof(mpls_lse_t));
|
|
|
|
} else {
|
|
|
|
struct rtattr *nest;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint16_t encap = LWTUNNEL_ENCAP_MPLS;
|
2017-09-20 05:05:25 +02:00
|
|
|
int len = rta->rta_len;
|
|
|
|
|
|
|
|
rta_addattr_l(rta, NL_PKT_BUF_SIZE, RTA_ENCAP_TYPE,
|
2018-03-27 21:13:34 +02:00
|
|
|
&encap, sizeof(uint16_t));
|
2017-09-20 05:05:25 +02:00
|
|
|
nest = rta_nest(rta, NL_PKT_BUF_SIZE, RTA_ENCAP);
|
|
|
|
rta_addattr_l(rta, NL_PKT_BUF_SIZE, MPLS_IPTUNNEL_DST,
|
|
|
|
&out_lse,
|
|
|
|
num_labels * sizeof(mpls_lse_t));
|
|
|
|
rta_nest_end(rta, nest);
|
|
|
|
rtnh->rtnh_len += rta->rta_len - len;
|
2017-05-26 03:22:03 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK))
|
|
|
|
rtnh->rtnh_flags |= RTNH_F_ONLINK;
|
|
|
|
|
|
|
|
if (rtmsg->rtm_family == AF_INET
|
|
|
|
&& (nexthop->type == NEXTHOP_TYPE_IPV6
|
|
|
|
|| nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX)) {
|
|
|
|
bytelen = 4;
|
|
|
|
rtnh->rtnh_flags |= RTNH_F_ONLINK;
|
|
|
|
rta_addattr_l(rta, NL_PKT_BUF_SIZE, RTA_GATEWAY, &ipv4_ll,
|
|
|
|
bytelen);
|
|
|
|
rtnh->rtnh_len += sizeof(struct rtattr) + bytelen;
|
|
|
|
rtnh->rtnh_ifindex = nexthop->ifindex;
|
|
|
|
|
|
|
|
if (nexthop->rmap_src.ipv4.s_addr)
|
|
|
|
*src = &nexthop->rmap_src;
|
|
|
|
else if (nexthop->src.ipv4.s_addr)
|
|
|
|
*src = &nexthop->src;
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
|
|
|
" 5549: netlink_route_build_multipath() (%s): "
|
|
|
|
"nexthop via %s %s if %u",
|
|
|
|
routedesc, ipv4_ll_buf, label_buf,
|
|
|
|
nexthop->ifindex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nexthop->type == NEXTHOP_TYPE_IPV4
|
|
|
|
|| nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX) {
|
|
|
|
_netlink_route_rta_add_gateway_info(rtmsg->rtm_family, AF_INET,
|
|
|
|
rta, rtnh, NL_PKT_BUF_SIZE,
|
|
|
|
bytelen, nexthop);
|
|
|
|
if (nexthop->rmap_src.ipv4.s_addr)
|
|
|
|
*src = &nexthop->rmap_src;
|
|
|
|
else if (nexthop->src.ipv4.s_addr)
|
|
|
|
*src = &nexthop->src;
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
|
|
|
"netlink_route_multipath() (%s): "
|
|
|
|
"nexthop via %s %s if %u",
|
|
|
|
routedesc, inet_ntoa(nexthop->gate.ipv4),
|
|
|
|
label_buf, nexthop->ifindex);
|
|
|
|
}
|
|
|
|
if (nexthop->type == NEXTHOP_TYPE_IPV6
|
|
|
|
|| nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) {
|
|
|
|
_netlink_route_rta_add_gateway_info(rtmsg->rtm_family, AF_INET6,
|
|
|
|
rta, rtnh, NL_PKT_BUF_SIZE,
|
|
|
|
bytelen, nexthop);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
|
|
|
"netlink_route_multipath() (%s): "
|
|
|
|
"nexthop via %s %s if %u",
|
|
|
|
routedesc, inet6_ntoa(nexthop->gate.ipv6),
|
|
|
|
label_buf, nexthop->ifindex);
|
|
|
|
}
|
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;
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* ifindex */
|
|
|
|
if (nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX
|
|
|
|
|| nexthop->type == NEXTHOP_TYPE_IFINDEX) {
|
|
|
|
if (nexthop->rmap_src.ipv4.s_addr)
|
|
|
|
*src = &nexthop->rmap_src;
|
|
|
|
else if (nexthop->src.ipv4.s_addr)
|
|
|
|
*src = &nexthop->src;
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
|
|
|
"netlink_route_multipath() (%s): "
|
|
|
|
"nexthop via if %u",
|
|
|
|
routedesc, nexthop->ifindex);
|
|
|
|
}
|
2013-07-05 17:35:37 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static inline void _netlink_mpls_build_singlepath(const char *routedesc,
|
|
|
|
zebra_nhlfe_t *nhlfe,
|
|
|
|
struct nlmsghdr *nlmsg,
|
|
|
|
struct rtmsg *rtmsg,
|
|
|
|
size_t req_size, int cmd)
|
2016-04-16 04:19:37 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int bytelen;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t family;
|
2016-04-16 04:19:37 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
family = NHLFE_FAMILY(nhlfe);
|
|
|
|
bytelen = (family == AF_INET ? 4 : 16);
|
|
|
|
_netlink_route_build_singlepath(routedesc, bytelen, nhlfe->nexthop,
|
|
|
|
nlmsg, rtmsg, req_size, cmd);
|
2016-04-16 04:19:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void
|
2017-07-17 14:03:14 +02:00
|
|
|
_netlink_mpls_build_multipath(const char *routedesc, zebra_nhlfe_t *nhlfe,
|
|
|
|
struct rtattr *rta, struct rtnexthop *rtnh,
|
|
|
|
struct rtmsg *rtmsg, union g_addr **src)
|
2016-04-16 04:19:37 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int bytelen;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t family;
|
2016-04-16 04:19:37 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
family = NHLFE_FAMILY(nhlfe);
|
|
|
|
bytelen = (family == AF_INET ? 4 : 16);
|
|
|
|
_netlink_route_build_multipath(routedesc, bytelen, nhlfe->nexthop, rta,
|
|
|
|
rtnh, rtmsg, src);
|
2016-04-16 04:19:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-05 17:35:37 +02:00
|
|
|
/* Log debug information for netlink_route_multipath
|
|
|
|
* if debug logging is enabled.
|
|
|
|
*
|
|
|
|
* @param cmd: Netlink command which is to be processed
|
|
|
|
* @param p: Prefix for which the change is due
|
|
|
|
* @param family: Address family which the change concerns
|
2018-04-09 20:09:35 +02:00
|
|
|
* @param zvrf: The vrf we are in
|
|
|
|
* @param tableid: The table we are working on
|
2013-07-05 17:35:37 +02:00
|
|
|
*/
|
2018-07-10 22:02:03 +02:00
|
|
|
static void _netlink_route_debug(int cmd, const struct prefix *p,
|
|
|
|
int family, vrf_id_t vrfid,
|
2018-03-29 14:58:45 +02:00
|
|
|
uint32_t tableid)
|
2013-07-05 17:35:37 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL) {
|
|
|
|
char buf[PREFIX_STRLEN];
|
|
|
|
zlog_debug(
|
2018-04-09 20:09:35 +02:00
|
|
|
"netlink_route_multipath(): %s %s vrf %u(%u)",
|
|
|
|
nl_msg_type_to_str(cmd),
|
|
|
|
prefix2str(p, buf, sizeof(buf)),
|
2018-07-10 22:02:03 +02:00
|
|
|
vrfid, tableid);
|
2017-07-17 14:03:14 +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
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("netlink_mpls_multipath() (%s): %s %u/20", routedesc,
|
|
|
|
nl_msg_type_to_str(cmd), label);
|
2013-07-05 17:35:37 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static int netlink_neigh_update(int cmd, int ifindex, uint32_t addr, char *lla,
|
2017-12-19 12:23:32 +01:00
|
|
|
int llalen, ns_id_t ns_id)
|
2015-06-11 18:19:59 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct ndmsg ndm;
|
|
|
|
char buf[256];
|
|
|
|
} req;
|
2015-06-11 18:19:59 +02:00
|
|
|
|
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
|
|
|
|
2017-07-17 14:03:14 +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
|
|
|
|
req.n.nlmsg_pid = zns->netlink_cmd.snl.nl_pid;
|
2017-06-12 19:38:51 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
req.ndm.ndm_family = AF_INET;
|
|
|
|
req.ndm.ndm_state = NUD_PERMANENT;
|
|
|
|
req.ndm.ndm_ifindex = ifindex;
|
|
|
|
req.ndm.ndm_type = RTN_UNICAST;
|
2015-06-11 18:19:59 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
addattr_l(&req.n, sizeof(req), NDA_DST, &addr, 4);
|
|
|
|
addattr_l(&req.n, sizeof(req), NDA_LLADDR, lla, llalen);
|
2015-06-11 18:19:59 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
|
|
|
|
0);
|
2015-06-11 18:19:59 +02:00
|
|
|
}
|
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
/* Routing table change via netlink interface. */
|
2015-06-11 18:11:12 +02:00
|
|
|
/* Update flag indicates whether this is a "replace" or not. */
|
2018-07-10 22:02:03 +02:00
|
|
|
static int netlink_route_multipath(int cmd, const struct prefix *p,
|
|
|
|
const struct prefix *src_p,
|
|
|
|
struct route_entry *re,
|
2017-07-17 14:03:14 +02:00
|
|
|
int update)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int bytelen;
|
|
|
|
struct sockaddr_nl snl;
|
|
|
|
struct nexthop *nexthop = NULL;
|
|
|
|
unsigned int nexthop_num;
|
|
|
|
int family = PREFIX_FAMILY(p);
|
|
|
|
const char *routedesc;
|
|
|
|
int setsrc = 0;
|
|
|
|
union g_addr src;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct rtmsg r;
|
|
|
|
char buf[NL_PKT_BUF_SIZE];
|
|
|
|
} req;
|
|
|
|
|
2017-12-11 15:19:15 +01:00
|
|
|
struct zebra_ns *zns;
|
2017-07-17 14:03:14 +02:00
|
|
|
struct zebra_vrf *zvrf = vrf_info_lookup(re->vrf_id);
|
|
|
|
|
2018-02-13 10:48:48 +01:00
|
|
|
zns = zvrf->zns;
|
2017-07-17 14:03:14 +02:00
|
|
|
memset(&req, 0, sizeof req - NL_PKT_BUF_SIZE);
|
|
|
|
|
|
|
|
bytelen = (family == AF_INET ? 4 : 16);
|
|
|
|
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
|
|
|
|
req.n.nlmsg_flags = NLM_F_CREATE | NLM_F_REQUEST;
|
|
|
|
if ((cmd == RTM_NEWROUTE) && update)
|
|
|
|
req.n.nlmsg_flags |= NLM_F_REPLACE;
|
|
|
|
req.n.nlmsg_type = cmd;
|
|
|
|
req.n.nlmsg_pid = zns->netlink_cmd.snl.nl_pid;
|
|
|
|
|
|
|
|
req.r.rtm_family = family;
|
|
|
|
req.r.rtm_dst_len = p->prefixlen;
|
|
|
|
req.r.rtm_src_len = src_p ? src_p->prefixlen : 0;
|
2017-09-01 16:28:19 +02:00
|
|
|
req.r.rtm_protocol = zebra2proto(re->type);
|
2017-07-17 14:03:14 +02:00
|
|
|
req.r.rtm_scope = RT_SCOPE_UNIVERSE;
|
2018-04-17 00:42:40 +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)
|
|
|
|
req.r.rtm_type = RTN_UNICAST;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
addattr_l(&req.n, sizeof req, RTA_DST, &p->u.prefix, bytelen);
|
|
|
|
if (src_p)
|
|
|
|
addattr_l(&req.n, sizeof req, RTA_SRC, &src_p->u.prefix,
|
|
|
|
bytelen);
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
addattr32(&req.n, sizeof req, RTA_PRIORITY, NL_DEFAULT_ROUTE_METRIC);
|
2017-12-08 20:44:15 +01:00
|
|
|
#if defined(SUPPORT_REALMS)
|
|
|
|
if (re->tag > 0 && re->tag <= 255)
|
|
|
|
addattr32(&req.n, sizeof req, RTA_FLOW, re->tag);
|
|
|
|
#endif
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Table corresponding to this route. */
|
|
|
|
if (re->table < 256)
|
|
|
|
req.r.rtm_table = re->table;
|
|
|
|
else {
|
|
|
|
req.r.rtm_table = RT_TABLE_UNSPEC;
|
|
|
|
addattr32(&req.n, sizeof req, RTA_TABLE, re->table);
|
2015-09-16 08:48:00 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2018-07-10 22:02:03 +02:00
|
|
|
_netlink_route_debug(cmd, p, family, zvrf_id(zvrf), re->table);
|
2018-04-09 20:09:35 +02:00
|
|
|
|
2018-04-09 20:16:00 +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.
|
|
|
|
*/
|
|
|
|
if (!update && cmd == RTM_DELROUTE)
|
2010-02-05 04:31:56 +01:00
|
|
|
goto skip;
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (re->mtu || re->nexthop_mtu) {
|
|
|
|
char buf[NL_PKT_BUF_SIZE];
|
|
|
|
struct rtattr *rta = (void *)buf;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint32_t mtu = re->mtu;
|
2017-07-17 14:03:14 +02:00
|
|
|
if (!mtu || (re->nexthop_mtu && re->nexthop_mtu < mtu))
|
|
|
|
mtu = re->nexthop_mtu;
|
|
|
|
rta->rta_type = RTA_METRICS;
|
|
|
|
rta->rta_len = RTA_LENGTH(0);
|
|
|
|
rta_addattr_l(rta, NL_PKT_BUF_SIZE, RTAX_MTU, &mtu, sizeof mtu);
|
|
|
|
addattr_l(&req.n, NL_PKT_BUF_SIZE, RTA_METRICS, RTA_DATA(rta),
|
|
|
|
RTA_PAYLOAD(rta));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Count overall nexthops so we can decide whether to use singlepath
|
|
|
|
* or multipath case. */
|
|
|
|
nexthop_num = 0;
|
2018-01-26 16:12:35 +01:00
|
|
|
for (ALL_NEXTHOPS(re->ng, nexthop)) {
|
2017-07-17 14:03:14 +02:00
|
|
|
if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
|
|
|
|
continue;
|
2018-03-06 20:02:52 +01:00
|
|
|
if (cmd == RTM_NEWROUTE && !NEXTHOP_IS_ACTIVE(nexthop->flags))
|
2017-07-17 14:03:14 +02:00
|
|
|
continue;
|
|
|
|
if (cmd == RTM_DELROUTE
|
|
|
|
&& !CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nexthop_num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Singlepath case. */
|
|
|
|
if (nexthop_num == 1 || multipath_num == 1) {
|
|
|
|
nexthop_num = 0;
|
2018-01-26 16:12:35 +01:00
|
|
|
for (ALL_NEXTHOPS(re->ng, nexthop)) {
|
2017-09-12 14:14:50 +02:00
|
|
|
/*
|
|
|
|
* So we want to cover 2 types of blackhole
|
|
|
|
* routes here:
|
|
|
|
* 1) A normal blackhole route( ala from a static
|
|
|
|
* install.
|
|
|
|
* 2) A recursively resolved blackhole route
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
default:
|
|
|
|
req.r.rtm_type = RTN_BLACKHOLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
goto skip;
|
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
if (CHECK_FLAG(nexthop->flags,
|
|
|
|
NEXTHOP_FLAG_RECURSIVE)) {
|
|
|
|
if (!setsrc) {
|
|
|
|
if (family == AF_INET) {
|
|
|
|
if (nexthop->rmap_src.ipv4
|
|
|
|
.s_addr
|
|
|
|
!= 0) {
|
|
|
|
src.ipv4 =
|
|
|
|
nexthop->rmap_src
|
|
|
|
.ipv4;
|
|
|
|
setsrc = 1;
|
|
|
|
} else if (nexthop->src.ipv4
|
|
|
|
.s_addr
|
|
|
|
!= 0) {
|
|
|
|
src.ipv4 =
|
|
|
|
nexthop->src
|
|
|
|
.ipv4;
|
|
|
|
setsrc = 1;
|
|
|
|
}
|
|
|
|
} else if (family == AF_INET6) {
|
|
|
|
if (!IN6_IS_ADDR_UNSPECIFIED(
|
|
|
|
&nexthop->rmap_src
|
|
|
|
.ipv6)) {
|
|
|
|
src.ipv6 =
|
|
|
|
nexthop->rmap_src
|
|
|
|
.ipv6;
|
|
|
|
setsrc = 1;
|
|
|
|
} else if (
|
|
|
|
!IN6_IS_ADDR_UNSPECIFIED(
|
|
|
|
&nexthop->src
|
|
|
|
.ipv6)) {
|
|
|
|
src.ipv6 =
|
|
|
|
nexthop->src
|
|
|
|
.ipv6;
|
|
|
|
setsrc = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cmd == RTM_NEWROUTE
|
2017-05-30 16:14:42 +02:00
|
|
|
&& NEXTHOP_IS_ACTIVE(nexthop->flags))
|
2017-07-17 14:03:14 +02:00
|
|
|
|| (cmd == RTM_DELROUTE
|
|
|
|
&& CHECK_FLAG(nexthop->flags,
|
|
|
|
NEXTHOP_FLAG_FIB))) {
|
|
|
|
routedesc = nexthop->rparent
|
2017-09-20 18:59:30 +02:00
|
|
|
? "recursive, single-path"
|
|
|
|
: "single-path";
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
_netlink_route_build_singlepath(
|
|
|
|
routedesc, bytelen, nexthop, &req.n,
|
|
|
|
&req.r, sizeof req, cmd);
|
|
|
|
nexthop_num++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (setsrc && (cmd == RTM_NEWROUTE)) {
|
|
|
|
if (family == AF_INET)
|
|
|
|
addattr_l(&req.n, sizeof req, RTA_PREFSRC,
|
|
|
|
&src.ipv4, bytelen);
|
|
|
|
else if (family == AF_INET6)
|
|
|
|
addattr_l(&req.n, sizeof req, RTA_PREFSRC,
|
|
|
|
&src.ipv6, bytelen);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
char buf[NL_PKT_BUF_SIZE];
|
|
|
|
struct rtattr *rta = (void *)buf;
|
|
|
|
struct rtnexthop *rtnh;
|
|
|
|
union g_addr *src1 = NULL;
|
|
|
|
|
|
|
|
rta->rta_type = RTA_MULTIPATH;
|
|
|
|
rta->rta_len = RTA_LENGTH(0);
|
|
|
|
rtnh = RTA_DATA(rta);
|
|
|
|
|
|
|
|
nexthop_num = 0;
|
2018-01-26 16:12:35 +01:00
|
|
|
for (ALL_NEXTHOPS(re->ng, nexthop)) {
|
2017-07-17 14:03:14 +02:00
|
|
|
if (nexthop_num >= multipath_num)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (CHECK_FLAG(nexthop->flags,
|
|
|
|
NEXTHOP_FLAG_RECURSIVE)) {
|
|
|
|
/* This only works for IPv4 now */
|
|
|
|
if (!setsrc) {
|
|
|
|
if (family == AF_INET) {
|
|
|
|
if (nexthop->rmap_src.ipv4
|
|
|
|
.s_addr
|
|
|
|
!= 0) {
|
|
|
|
src.ipv4 =
|
|
|
|
nexthop->rmap_src
|
|
|
|
.ipv4;
|
|
|
|
setsrc = 1;
|
|
|
|
} else if (nexthop->src.ipv4
|
|
|
|
.s_addr
|
|
|
|
!= 0) {
|
|
|
|
src.ipv4 =
|
|
|
|
nexthop->src
|
|
|
|
.ipv4;
|
|
|
|
setsrc = 1;
|
|
|
|
}
|
|
|
|
} else if (family == AF_INET6) {
|
|
|
|
if (!IN6_IS_ADDR_UNSPECIFIED(
|
|
|
|
&nexthop->rmap_src
|
|
|
|
.ipv6)) {
|
|
|
|
src.ipv6 =
|
|
|
|
nexthop->rmap_src
|
|
|
|
.ipv6;
|
|
|
|
setsrc = 1;
|
|
|
|
} else if (
|
|
|
|
!IN6_IS_ADDR_UNSPECIFIED(
|
|
|
|
&nexthop->src
|
|
|
|
.ipv6)) {
|
|
|
|
src.ipv6 =
|
|
|
|
nexthop->src
|
|
|
|
.ipv6;
|
|
|
|
setsrc = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((cmd == RTM_NEWROUTE
|
2017-05-30 16:14:42 +02:00
|
|
|
&& NEXTHOP_IS_ACTIVE(nexthop->flags))
|
2017-07-17 14:03:14 +02:00
|
|
|
|| (cmd == RTM_DELROUTE
|
|
|
|
&& CHECK_FLAG(nexthop->flags,
|
|
|
|
NEXTHOP_FLAG_FIB))) {
|
|
|
|
routedesc = nexthop->rparent
|
2017-09-20 18:59:30 +02:00
|
|
|
? "recursive, multipath"
|
|
|
|
: "multipath";
|
2017-07-17 14:03:14 +02:00
|
|
|
nexthop_num++;
|
|
|
|
|
|
|
|
_netlink_route_build_multipath(
|
|
|
|
routedesc, bytelen, nexthop, rta, rtnh,
|
|
|
|
&req.r, &src1);
|
|
|
|
rtnh = RTNH_NEXT(rtnh);
|
|
|
|
|
|
|
|
if (!setsrc && src1) {
|
|
|
|
if (family == AF_INET)
|
|
|
|
src.ipv4 = src1->ipv4;
|
|
|
|
else if (family == AF_INET6)
|
|
|
|
src.ipv6 = src1->ipv6;
|
|
|
|
|
|
|
|
setsrc = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (setsrc && (cmd == RTM_NEWROUTE)) {
|
|
|
|
if (family == AF_INET)
|
|
|
|
addattr_l(&req.n, sizeof req, RTA_PREFSRC,
|
|
|
|
&src.ipv4, bytelen);
|
|
|
|
else if (family == AF_INET6)
|
|
|
|
addattr_l(&req.n, sizeof req, RTA_PREFSRC,
|
|
|
|
&src.ipv6, bytelen);
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("Setting source");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rta->rta_len > RTA_LENGTH(0))
|
|
|
|
addattr_l(&req.n, NL_PKT_BUF_SIZE, RTA_MULTIPATH,
|
|
|
|
RTA_DATA(rta), RTA_PAYLOAD(rta));
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* If there is no useful nexthop then return. */
|
|
|
|
if (nexthop_num == 0) {
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
|
|
|
"netlink_route_multipath(): No useful nexthop.");
|
|
|
|
return 0;
|
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2003-07-15 14:52:22 +02:00
|
|
|
skip:
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Destination netlink address. */
|
|
|
|
memset(&snl, 0, sizeof snl);
|
|
|
|
snl.nl_family = AF_NETLINK;
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Talk to netlink socket. */
|
|
|
|
return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
|
|
|
|
0);
|
2002-12-13 21:15:29 +01: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
|
|
|
{
|
2017-07-17 14:03:14 +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;
|
|
|
|
struct ndmsg ndm;
|
|
|
|
char buf[256];
|
|
|
|
} req;
|
2016-08-11 02:04:20 +02:00
|
|
|
|
2017-07-17 14:03:14 +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
|
|
|
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
|
|
|
|
req.n.nlmsg_flags = NLM_F_REQUEST;
|
|
|
|
req.n.nlmsg_pid = zns->netlink_cmd.snl.nl_pid;
|
|
|
|
|
|
|
|
req.ndm.ndm_family = RTNL_FAMILY_IPMR;
|
|
|
|
req.n.nlmsg_type = RTM_GETROUTE;
|
|
|
|
|
|
|
|
addattr_l(&req.n, sizeof(req), RTA_IIF, &mroute->ifindex, 4);
|
|
|
|
addattr_l(&req.n, sizeof(req), RTA_OIF, &mroute->ifindex, 4);
|
|
|
|
addattr_l(&req.n, sizeof(req), RTA_SRC, &mroute->sg.src.s_addr, 4);
|
|
|
|
addattr_l(&req.n, sizeof(req), RTA_DST, &mroute->sg.grp.s_addr, 4);
|
|
|
|
addattr_l(&req.n, sizeof(req), RTA_TABLE, &zvrf->table_id, 4);
|
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,
|
|
|
|
&zns->netlink_cmd, zns, 0);
|
2016-08-11 02:04:20 +02:00
|
|
|
|
2017-07-05 17:53:29 +02:00
|
|
|
mroute = NULL;
|
2017-07-17 14:03:14 +02:00
|
|
|
return suc;
|
2016-08-11 02:04:20 +02:00
|
|
|
}
|
|
|
|
|
2018-05-25 16:47:40 +02:00
|
|
|
enum dp_req_result kernel_route_rib(struct route_node *rn,
|
2018-07-10 22:02:03 +02:00
|
|
|
const struct prefix *p,
|
|
|
|
const struct prefix *src_p,
|
2018-05-25 16:37:48 +02:00
|
|
|
struct route_entry *old,
|
|
|
|
struct route_entry *new)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-11-14 15:57:37 +01:00
|
|
|
int ret = 0;
|
|
|
|
|
2017-08-25 02:43:29 +02:00
|
|
|
assert(old || new);
|
|
|
|
|
2017-11-14 15:57:37 +01:00
|
|
|
if (new) {
|
2018-05-18 21:41:46 +02:00
|
|
|
if (p->family == AF_INET || v6_rr_semantics)
|
2017-11-14 15:57:37 +01:00
|
|
|
ret = netlink_route_multipath(RTM_NEWROUTE, p, src_p,
|
|
|
|
new, (old) ? 1 : 0);
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* So v6 route replace semantics are not in
|
|
|
|
* the kernel at this point as I understand it.
|
|
|
|
* So let's do a delete than 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.
|
|
|
|
*/
|
|
|
|
if (old)
|
2018-03-06 20:02:52 +01:00
|
|
|
netlink_route_multipath(RTM_DELROUTE, p, src_p,
|
|
|
|
old, 0);
|
|
|
|
ret = netlink_route_multipath(RTM_NEWROUTE, p, src_p,
|
|
|
|
new, 0);
|
2017-11-14 15:57:37 +01:00
|
|
|
}
|
2018-01-24 14:22:57 +01:00
|
|
|
kernel_route_rib_pass_fail(rn, p, new,
|
2018-05-25 16:37:48 +02:00
|
|
|
(!ret) ? DP_INSTALL_SUCCESS
|
|
|
|
: DP_INSTALL_FAILURE);
|
2018-05-25 16:47:40 +02:00
|
|
|
return DP_REQUEST_SUCCESS;
|
2017-11-14 15:57:37 +01:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-11-14 15:57:37 +01:00
|
|
|
if (old) {
|
|
|
|
ret = netlink_route_multipath(RTM_DELROUTE, p, src_p, old, 0);
|
2017-11-17 17:01:44 +01:00
|
|
|
|
2018-01-24 14:22:57 +01:00
|
|
|
kernel_route_rib_pass_fail(rn, p, old,
|
2018-05-25 16:37:48 +02:00
|
|
|
(!ret) ? DP_DELETE_SUCCESS
|
|
|
|
: DP_DELETE_FAILURE);
|
2017-11-14 15:57:37 +01:00
|
|
|
}
|
2018-05-25 16:37:48 +02:00
|
|
|
|
2018-05-25 16:47:40 +02:00
|
|
|
return DP_REQUEST_SUCCESS;
|
2002-12-13 21:15:29 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
int kernel_neigh_update(int add, int ifindex, uint32_t addr, char *lla,
|
2017-12-19 12:23:32 +01:00
|
|
|
int llalen, ns_id_t ns_id)
|
2016-08-04 15:07:32 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return netlink_neigh_update(add ? RTM_NEWNEIGH : RTM_DELNEIGH, ifindex,
|
2017-12-19 12:23:32 +01:00
|
|
|
addr, lla, llalen, ns_id);
|
2016-08-04 15:07:32 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-05-15 07:38:26 +02: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.
|
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
static int netlink_vxlan_flood_list_update(struct interface *ifp,
|
|
|
|
struct in_addr *vtep_ip, int cmd)
|
2017-05-15 07:38:26 +02:00
|
|
|
{
|
2017-12-19 12:23:32 +01:00
|
|
|
struct zebra_ns *zns;
|
2017-07-17 14:03:14 +02:00
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct ndmsg ndm;
|
|
|
|
char buf[256];
|
|
|
|
} req;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t dst_mac[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
|
2018-02-13 10:48:48 +01:00
|
|
|
struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
|
2017-07-17 14:03:14 +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-17 14:03:14 +02:00
|
|
|
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
|
|
|
|
req.n.nlmsg_flags = NLM_F_REQUEST;
|
|
|
|
if (cmd == RTM_NEWNEIGH)
|
|
|
|
req.n.nlmsg_flags |= (NLM_F_CREATE | NLM_F_APPEND);
|
|
|
|
req.n.nlmsg_type = cmd;
|
|
|
|
req.ndm.ndm_family = PF_BRIDGE;
|
|
|
|
req.ndm.ndm_state = NUD_NOARP | NUD_PERMANENT;
|
|
|
|
req.ndm.ndm_flags |= NTF_SELF; // Handle by "self", not "master"
|
|
|
|
|
|
|
|
|
|
|
|
addattr_l(&req.n, sizeof(req), NDA_LLADDR, &dst_mac, 6);
|
|
|
|
req.ndm.ndm_ifindex = ifp->ifindex;
|
|
|
|
addattr_l(&req.n, sizeof(req), NDA_DST, &vtep_ip->s_addr, 4);
|
|
|
|
|
|
|
|
return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
|
|
|
|
0);
|
2017-05-15 07:38:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-07-17 14:03:14 +02:00
|
|
|
* Add remote VTEP for this VxLAN interface (VNI). In Linux, this involves
|
|
|
|
* adding
|
2017-05-15 07:38:26 +02:00
|
|
|
* a "flood" MAC FDB entry.
|
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
int kernel_add_vtep(vni_t vni, struct interface *ifp, struct in_addr *vtep_ip)
|
2017-05-15 07:38:26 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_VXLAN)
|
|
|
|
zlog_debug("Install %s into flood list for VNI %u intf %s(%u)",
|
|
|
|
inet_ntoa(*vtep_ip), vni, ifp->name, ifp->ifindex);
|
2017-05-15 07:38:26 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return netlink_vxlan_flood_list_update(ifp, vtep_ip, RTM_NEWNEIGH);
|
2017-05-15 07:38:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove remote VTEP for this VxLAN interface (VNI). In Linux, this involves
|
|
|
|
* deleting the "flood" MAC FDB entry.
|
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
int kernel_del_vtep(vni_t vni, struct interface *ifp, struct in_addr *vtep_ip)
|
2017-05-15 07:38:26 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if (IS_ZEBRA_DEBUG_VXLAN)
|
|
|
|
zlog_debug(
|
|
|
|
"Uninstall %s from flood list for VNI %u intf %s(%u)",
|
|
|
|
inet_ntoa(*vtep_ip), vni, ifp->name, ifp->ifindex);
|
2017-05-15 07:38:26 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return netlink_vxlan_flood_list_update(ifp, vtep_ip, RTM_DELNEIGH);
|
2017-05-15 07:38:26 +02:00
|
|
|
}
|
|
|
|
|
2017-05-15 07:44:13 +02:00
|
|
|
#ifndef NDA_RTA
|
2017-07-17 14:03:14 +02:00
|
|
|
#define NDA_RTA(r) \
|
|
|
|
((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
|
2017-05-15 07:44:13 +02:00
|
|
|
#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
|
|
|
{
|
2017-07-17 14:03:14 +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;
|
|
|
|
struct prefix vtep_ip;
|
|
|
|
int vid_present = 0, dst_present = 0;
|
|
|
|
char buf[ETHER_ADDR_STRLEN];
|
|
|
|
char vid_buf[20];
|
|
|
|
char dst_buf[30];
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t sticky = 0;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
ndm = NLMSG_DATA(h);
|
|
|
|
|
2017-09-18 23:45:34 +02:00
|
|
|
/* We only process macfdb notifications if EVPN is enabled */
|
|
|
|
if (!is_evpn_enabled())
|
|
|
|
return 0;
|
|
|
|
|
2017-07-17 14:03:14 +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-07-17 14:03:14 +02:00
|
|
|
ndm->ndm_ifindex);
|
2017-09-18 23:45:34 +02:00
|
|
|
if (!ifp || !ifp->info)
|
2017-07-17 14:03:14 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* The interface should be something we're interested in. */
|
|
|
|
if (!IS_ZEBRA_IF_BRIDGE_SLAVE(ifp))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Drop "permanent" entries. */
|
|
|
|
if (ndm->ndm_state & NUD_PERMANENT)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
zif = (struct zebra_if *)ifp->info;
|
|
|
|
if ((br_if = zif->brslave_info.br_if) == NULL) {
|
|
|
|
zlog_warn("%s family %s IF %s(%u) brIF %u - no bridge master",
|
|
|
|
nl_msg_type_to_str(h->nlmsg_type),
|
|
|
|
nl_family_to_str(ndm->ndm_family), ifp->name,
|
|
|
|
ndm->ndm_ifindex, zif->brslave_info.bridge_ifindex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse attributes and extract fields of interest. */
|
|
|
|
memset(tb, 0, sizeof tb);
|
|
|
|
netlink_parse_rtattr(tb, NDA_MAX, NDA_RTA(ndm), len);
|
|
|
|
|
|
|
|
if (!tb[NDA_LLADDR]) {
|
|
|
|
zlog_warn("%s family %s IF %s(%u) brIF %u - no LLADDR",
|
|
|
|
nl_msg_type_to_str(h->nlmsg_type),
|
|
|
|
nl_family_to_str(ndm->ndm_family), ifp->name,
|
|
|
|
ndm->ndm_ifindex, zif->brslave_info.bridge_ifindex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-03 14:43:56 +02:00
|
|
|
if (RTA_PAYLOAD(tb[NDA_LLADDR]) != ETH_ALEN) {
|
2017-07-17 14:03:14 +02:00
|
|
|
zlog_warn(
|
2017-07-25 11:46:01 +02:00
|
|
|
"%s family %s IF %s(%u) brIF %u - LLADDR is not MAC, len %lu",
|
2017-07-17 14:03:14 +02:00
|
|
|
nl_msg_type_to_str(h->nlmsg_type),
|
|
|
|
nl_family_to_str(ndm->ndm_family), ifp->name,
|
|
|
|
ndm->ndm_ifindex, zif->brslave_info.bridge_ifindex,
|
2017-07-25 11:46:01 +02:00
|
|
|
(unsigned long)RTA_PAYLOAD(tb[NDA_LLADDR]));
|
2017-07-17 14:03:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
if ((NDA_VLAN <= NDA_MAX) && tb[NDA_VLAN]) {
|
|
|
|
vid_present = 1;
|
2018-03-27 21:13:34 +02:00
|
|
|
vid = *(uint16_t *)RTA_DATA(tb[NDA_VLAN]);
|
2017-07-17 14:03:14 +02:00
|
|
|
sprintf(vid_buf, " VLAN %u", vid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tb[NDA_DST]) {
|
|
|
|
/* TODO: Only IPv4 supported now. */
|
|
|
|
dst_present = 1;
|
|
|
|
vtep_ip.family = AF_INET;
|
|
|
|
vtep_ip.prefixlen = IPV4_MAX_BITLEN;
|
|
|
|
memcpy(&(vtep_ip.u.prefix4.s_addr), RTA_DATA(tb[NDA_DST]),
|
|
|
|
IPV4_MAX_BYTELEN);
|
|
|
|
sprintf(dst_buf, " dst %s", inet_ntoa(vtep_ip.u.prefix4));
|
|
|
|
}
|
|
|
|
|
|
|
|
sticky = (ndm->ndm_state & NUD_NOARP) ? 1 : 0;
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("Rx %s family %s IF %s(%u)%s %sMAC %s%s",
|
|
|
|
nl_msg_type_to_str(h->nlmsg_type),
|
|
|
|
nl_family_to_str(ndm->ndm_family), ifp->name,
|
|
|
|
ndm->ndm_ifindex, vid_present ? vid_buf : "",
|
|
|
|
sticky ? "sticky " : "",
|
|
|
|
prefix_mac2str(&mac, buf, sizeof(buf)),
|
|
|
|
dst_present ? dst_buf : "");
|
|
|
|
|
|
|
|
if (filter_vlan && vid != filter_vlan)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* 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) {
|
|
|
|
/* Drop "permanent" entries. */
|
|
|
|
if (ndm->ndm_state & NUD_PERMANENT)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (IS_ZEBRA_IF_VXLAN(ifp))
|
|
|
|
return zebra_vxlan_check_del_local_mac(ifp, br_if, &mac,
|
|
|
|
vid);
|
|
|
|
|
|
|
|
return zebra_vxlan_local_mac_add_update(ifp, br_if, &mac, vid,
|
|
|
|
sticky);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is a delete notification.
|
|
|
|
* 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.
|
|
|
|
* Ignore the notification from VxLan driver as it is also generated
|
|
|
|
* when mac moves from remote to local.
|
|
|
|
*/
|
|
|
|
if (dst_present)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (IS_ZEBRA_IF_VXLAN(ifp))
|
|
|
|
return zebra_vxlan_check_readd_remote_mac(ifp, br_if, &mac,
|
|
|
|
vid);
|
|
|
|
|
|
|
|
return zebra_vxlan_local_mac_del(ifp, br_if, &mac, vid);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int len;
|
|
|
|
struct ndmsg *ndm;
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (h->nlmsg_type != RTM_NEWNEIGH)
|
|
|
|
return 0;
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Length validity. */
|
|
|
|
len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ndmsg));
|
|
|
|
if (len < 0)
|
|
|
|
return -1;
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* We are interested only in AF_BRIDGE notifications. */
|
|
|
|
ndm = NLMSG_DATA(h);
|
|
|
|
if (ndm->ndm_family != AF_BRIDGE)
|
|
|
|
return 0;
|
2017-05-15 07:44:13 +02:00
|
|
|
|
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 */
|
2017-07-17 14:03:14 +02:00
|
|
|
static int netlink_request_macs(struct zebra_ns *zns, int family, int type,
|
|
|
|
ifindex_t master_ifindex)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct ifinfomsg ifm;
|
|
|
|
char buf[256];
|
|
|
|
} req;
|
|
|
|
|
|
|
|
/* Form the request, specifying filter (rtattr) if needed. */
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
req.n.nlmsg_type = type;
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
|
|
|
req.ifm.ifi_family = family;
|
|
|
|
if (master_ifindex)
|
|
|
|
addattr32(&req.n, sizeof(req), IFLA_MASTER, master_ifindex);
|
|
|
|
|
|
|
|
return netlink_request(&zns->netlink_cmd, &req.n);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MAC forwarding database read using netlink interface. This is invoked
|
|
|
|
* at startup.
|
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
int netlink_macfdb_read(struct zebra_ns *zns)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Get bridge FDB table. */
|
|
|
|
ret = netlink_request_macs(zns, AF_BRIDGE, RTM_GETNEIGH, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
/* We are reading entire table. */
|
|
|
|
filter_vlan = 0;
|
|
|
|
ret = netlink_parse_info(netlink_macfdb_table, &zns->netlink_cmd, zns,
|
|
|
|
0, 1);
|
|
|
|
|
|
|
|
return ret;
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MAC forwarding database read using netlink interface. This is for a
|
|
|
|
* specific bridge and matching specific access VLAN (if VLAN-aware bridge).
|
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
int netlink_macfdb_read_for_bridge(struct zebra_ns *zns, struct interface *ifp,
|
|
|
|
struct interface *br_if)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct zebra_if *br_zif;
|
|
|
|
struct zebra_if *zif;
|
|
|
|
struct zebra_l2info_vxlan *vxl;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/* Save VLAN we're filtering on, if needed. */
|
|
|
|
br_zif = (struct zebra_if *)br_if->info;
|
|
|
|
zif = (struct zebra_if *)ifp->info;
|
|
|
|
vxl = &zif->l2info.vxl;
|
|
|
|
if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif))
|
|
|
|
filter_vlan = vxl->access_vlan;
|
|
|
|
|
|
|
|
/* Get bridge FDB table for specific bridge - we do the VLAN filtering.
|
|
|
|
*/
|
|
|
|
ret = netlink_request_macs(zns, AF_BRIDGE, RTM_GETNEIGH,
|
|
|
|
br_if->ifindex);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
ret = netlink_parse_info(netlink_macfdb_table, &zns->netlink_cmd, zns,
|
|
|
|
0, 0);
|
|
|
|
|
|
|
|
/* Reset VLAN filter. */
|
|
|
|
filter_vlan = 0;
|
|
|
|
return ret;
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static int netlink_macfdb_update(struct interface *ifp, vlanid_t vid,
|
|
|
|
struct ethaddr *mac, struct in_addr vtep_ip,
|
2018-03-27 21:13:34 +02:00
|
|
|
int local, int cmd, uint8_t sticky)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
2017-12-19 12:23:32 +01:00
|
|
|
struct zebra_ns *zns;
|
2017-07-17 14:03:14 +02:00
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct ndmsg ndm;
|
|
|
|
char buf[256];
|
|
|
|
} req;
|
|
|
|
int dst_alen;
|
|
|
|
struct zebra_if *zif;
|
|
|
|
struct interface *br_if;
|
|
|
|
struct zebra_if *br_zif;
|
|
|
|
char buf[ETHER_ADDR_STRLEN];
|
|
|
|
int vid_present = 0, dst_present = 0;
|
|
|
|
char vid_buf[20];
|
|
|
|
char dst_buf[30];
|
2018-02-13 10:48:48 +01:00
|
|
|
struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
|
2017-07-17 14:03:14 +02:00
|
|
|
|
2018-02-13 10:48:48 +01:00
|
|
|
zns = zvrf->zns;
|
2017-07-17 14:03:14 +02:00
|
|
|
zif = ifp->info;
|
|
|
|
if ((br_if = zif->brslave_info.br_if) == NULL) {
|
|
|
|
zlog_warn("MAC %s on IF %s(%u) - no mapping to bridge",
|
|
|
|
(cmd == RTM_NEWNEIGH) ? "add" : "del", ifp->name,
|
|
|
|
ifp->ifindex);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-05-18 00:46:14 +02:00
|
|
|
memset(&req, 0, sizeof(req));
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
|
|
|
|
req.n.nlmsg_flags = NLM_F_REQUEST;
|
|
|
|
if (cmd == RTM_NEWNEIGH)
|
|
|
|
req.n.nlmsg_flags |= (NLM_F_CREATE | NLM_F_REPLACE);
|
|
|
|
req.n.nlmsg_type = cmd;
|
|
|
|
req.ndm.ndm_family = AF_BRIDGE;
|
|
|
|
req.ndm.ndm_flags |= NTF_SELF | NTF_MASTER;
|
|
|
|
req.ndm.ndm_state = NUD_REACHABLE;
|
|
|
|
|
|
|
|
if (sticky)
|
|
|
|
req.ndm.ndm_state |= NUD_NOARP;
|
|
|
|
else
|
|
|
|
req.ndm.ndm_flags |= NTF_EXT_LEARNED;
|
|
|
|
|
|
|
|
addattr_l(&req.n, sizeof(req), NDA_LLADDR, mac, 6);
|
|
|
|
req.ndm.ndm_ifindex = ifp->ifindex;
|
|
|
|
if (!local) {
|
|
|
|
dst_alen = 4; // TODO: hardcoded
|
|
|
|
addattr_l(&req.n, sizeof(req), NDA_DST, &vtep_ip, dst_alen);
|
|
|
|
dst_present = 1;
|
|
|
|
sprintf(dst_buf, " dst %s", inet_ntoa(vtep_ip));
|
|
|
|
}
|
|
|
|
br_zif = (struct zebra_if *)br_if->info;
|
|
|
|
if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif) && vid > 0) {
|
|
|
|
addattr16(&req.n, sizeof(req), NDA_VLAN, vid);
|
|
|
|
vid_present = 1;
|
|
|
|
sprintf(vid_buf, " VLAN %u", vid);
|
|
|
|
}
|
|
|
|
addattr32(&req.n, sizeof(req), NDA_MASTER, br_if->ifindex);
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("Tx %s family %s IF %s(%u)%s %sMAC %s%s",
|
|
|
|
nl_msg_type_to_str(cmd),
|
|
|
|
nl_family_to_str(req.ndm.ndm_family), ifp->name,
|
|
|
|
ifp->ifindex, vid_present ? vid_buf : "",
|
|
|
|
sticky ? "sticky " : "",
|
|
|
|
prefix_mac2str(mac, buf, sizeof(buf)),
|
|
|
|
dst_present ? dst_buf : "");
|
|
|
|
|
|
|
|
return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
|
|
|
|
0);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
#define NUD_VALID \
|
|
|
|
(NUD_PERMANENT | NUD_NOARP | NUD_REACHABLE | NUD_PROBE | NUD_STALE \
|
|
|
|
| NUD_DELAY)
|
2017-05-15 07:44:13 +02:00
|
|
|
|
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
|
|
|
{
|
2017-07-17 14:03:14 +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];
|
|
|
|
char buf2[INET6_ADDRSTRLEN];
|
|
|
|
int mac_present = 0;
|
2018-03-27 21:13:34 +02:00
|
|
|
uint8_t ext_learned;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
ndm = NLMSG_DATA(h);
|
|
|
|
|
|
|
|
/* 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-07-17 14:03:14 +02:00
|
|
|
ndm->ndm_ifindex);
|
2017-09-18 23:45:34 +02:00
|
|
|
if (!ifp || !ifp->info)
|
2017-07-17 14:03:14 +02:00
|
|
|
return 0;
|
|
|
|
|
2018-04-09 14:04:39 +02:00
|
|
|
zif = (struct zebra_if *)ifp->info;
|
|
|
|
|
|
|
|
/* Parse attributes and extract fields of interest. */
|
|
|
|
memset(tb, 0, sizeof tb);
|
|
|
|
netlink_parse_rtattr(tb, NDA_MAX, NDA_RTA(ndm), len);
|
|
|
|
|
|
|
|
if (!tb[NDA_DST]) {
|
|
|
|
zlog_warn("%s family %s IF %s(%u) - no DST",
|
|
|
|
nl_msg_type_to_str(h->nlmsg_type),
|
|
|
|
nl_family_to_str(ndm->ndm_family), ifp->name,
|
|
|
|
ndm->ndm_ifindex);
|
2017-07-17 14:03:14 +02:00
|
|
|
return 0;
|
2018-04-09 14:04:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(&ip, 0, sizeof(struct ipaddr));
|
|
|
|
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]));
|
|
|
|
|
|
|
|
/* Drop some "permanent" entries. */
|
|
|
|
if (ndm->ndm_state & NUD_PERMANENT) {
|
|
|
|
char buf[16] = "169.254.0.1";
|
|
|
|
struct in_addr ipv4_ll;
|
|
|
|
|
|
|
|
if (ndm->ndm_family != AF_INET)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!zif->v6_2_v4_ll_neigh_entry)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (h->nlmsg_type != RTM_DELNEIGH)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
inet_pton(AF_INET, buf, &ipv4_ll);
|
|
|
|
if (ipv4_ll.s_addr != ip.ip._v4_addr.s_addr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if_nbr_ipv6ll_to_ipv4ll_neigh_update(
|
|
|
|
ifp, &zif->v6_2_v4_ll_addr6, true);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-07-17 14:03:14 +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
|
|
|
|
* inteface
|
|
|
|
* 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-07-17 14:03:14 +02:00
|
|
|
if (!link_if)
|
|
|
|
return 0;
|
|
|
|
} else if (IS_ZEBRA_IF_BRIDGE(ifp))
|
|
|
|
link_if = ifp;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
memset(&mac, 0, sizeof(struct ethaddr));
|
|
|
|
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) {
|
2017-07-17 14:03:14 +02:00
|
|
|
zlog_warn(
|
2017-07-25 11:46:01 +02:00
|
|
|
"%s family %s IF %s(%u) - LLADDR is not MAC, len %lu",
|
2017-07-17 14:03:14 +02:00
|
|
|
nl_msg_type_to_str(h->nlmsg_type),
|
|
|
|
nl_family_to_str(ndm->ndm_family),
|
|
|
|
ifp->name, ndm->ndm_ifindex,
|
2018-03-06 20:02:52 +01:00
|
|
|
(unsigned long)RTA_PAYLOAD(
|
|
|
|
tb[NDA_LLADDR]));
|
2017-07-17 14:03:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
mac_present = 1;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
ext_learned = (ndm->ndm_flags & NTF_EXT_LEARNED) ? 1 : 0;
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug(
|
|
|
|
"Rx %s family %s IF %s(%u) IP %s MAC %s state 0x%x flags 0x%x",
|
|
|
|
nl_msg_type_to_str(h->nlmsg_type),
|
|
|
|
nl_family_to_str(ndm->ndm_family), ifp->name,
|
|
|
|
ndm->ndm_ifindex,
|
|
|
|
ipaddr2str(&ip, buf2, sizeof(buf2)),
|
|
|
|
mac_present
|
|
|
|
? prefix_mac2str(&mac, buf, sizeof(buf))
|
|
|
|
: "",
|
|
|
|
ndm->ndm_state, ndm->ndm_flags);
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
if (ndm->ndm_state & NUD_VALID)
|
2018-03-03 00:28:33 +01:00
|
|
|
return zebra_vxlan_handle_kernel_neigh_update(
|
2017-07-17 14:03:14 +02:00
|
|
|
ifp, link_if, &ip, &mac, ndm->ndm_state,
|
|
|
|
ext_learned);
|
|
|
|
|
2018-03-03 00:28:33 +01:00
|
|
|
return zebra_vxlan_handle_kernel_neigh_del(ifp, link_if, &ip);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("Rx %s family %s IF %s(%u) IP %s",
|
|
|
|
nl_msg_type_to_str(h->nlmsg_type),
|
|
|
|
nl_family_to_str(ndm->ndm_family), ifp->name,
|
|
|
|
ndm->ndm_ifindex,
|
|
|
|
ipaddr2str(&ip, buf2, sizeof(buf2)));
|
|
|
|
|
|
|
|
/* Process the delete - it may result in re-adding the neighbor if it is
|
|
|
|
* a valid "remote" neighbor.
|
|
|
|
*/
|
2018-03-03 00:28:33 +01:00
|
|
|
return zebra_vxlan_handle_kernel_neigh_del(ifp, link_if, &ip);
|
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
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int len;
|
|
|
|
struct ndmsg *ndm;
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (h->nlmsg_type != RTM_NEWNEIGH)
|
|
|
|
return 0;
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Length validity. */
|
|
|
|
len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ndmsg));
|
|
|
|
if (len < 0)
|
|
|
|
return -1;
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* 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;
|
2017-05-15 07:44:13 +02:00
|
|
|
|
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 */
|
2017-07-17 14:03:14 +02:00
|
|
|
static int netlink_request_neigh(struct zebra_ns *zns, int family, int type,
|
|
|
|
ifindex_t ifindex)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct ndmsg ndm;
|
|
|
|
char buf[256];
|
|
|
|
} req;
|
|
|
|
|
|
|
|
/* Form the request, specifying filter (rtattr) if needed. */
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
req.n.nlmsg_type = type;
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
|
|
|
|
req.ndm.ndm_family = family;
|
|
|
|
if (ifindex)
|
|
|
|
addattr32(&req.n, sizeof(req), NDA_IFINDEX, ifindex);
|
|
|
|
|
|
|
|
return netlink_request(&zns->netlink_cmd, &req.n);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IP Neighbor table read using netlink interface. This is invoked
|
|
|
|
* at startup.
|
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
int netlink_neigh_read(struct zebra_ns *zns)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int ret;
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Get IP neighbor table. */
|
|
|
|
ret = netlink_request_neigh(zns, AF_UNSPEC, RTM_GETNEIGH, 0);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
ret = netlink_parse_info(netlink_neigh_table, &zns->netlink_cmd, zns, 0,
|
|
|
|
1);
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return ret;
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IP Neighbor table read using netlink interface. This is for a specific
|
|
|
|
* VLAN device.
|
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
int netlink_neigh_read_for_vlan(struct zebra_ns *zns, struct interface *vlan_if)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int ret = 0;
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
ret = netlink_request_neigh(zns, AF_UNSPEC, RTM_GETNEIGH,
|
|
|
|
vlan_if->ifindex);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
ret = netlink_parse_info(netlink_neigh_table, &zns->netlink_cmd, zns, 0,
|
|
|
|
0);
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return ret;
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int len;
|
|
|
|
struct ndmsg *ndm;
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (!(h->nlmsg_type == RTM_NEWNEIGH || h->nlmsg_type == RTM_DELNEIGH))
|
|
|
|
return 0;
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Length validity. */
|
|
|
|
len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct ndmsg));
|
2018-06-22 20:22:02 +02:00
|
|
|
if (len < 0) {
|
|
|
|
zlog_err("%s: Message received from netlink is of a broken size %d %zu",
|
|
|
|
__PRETTY_FUNCTION__, h->nlmsg_len,
|
|
|
|
(size_t)NLMSG_LENGTH(sizeof(struct ndmsg)));
|
2017-07-17 14:03:14 +02:00
|
|
|
return -1;
|
2018-06-22 20:22:02 +02:00
|
|
|
}
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2017-07-17 14:03:14 +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
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
if (ndm->ndm_type != RTN_UNICAST)
|
|
|
|
return 0;
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
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);
|
2017-05-15 07:44:13 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return 0;
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static int netlink_neigh_update2(struct interface *ifp, struct ipaddr *ip,
|
2018-03-27 21:13:34 +02:00
|
|
|
struct ethaddr *mac, uint32_t flags, int cmd)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct ndmsg ndm;
|
|
|
|
char buf[256];
|
|
|
|
} req;
|
|
|
|
int ipa_len;
|
|
|
|
|
2017-12-19 12:23:32 +01:00
|
|
|
struct zebra_ns *zns;
|
2017-07-17 14:03:14 +02:00
|
|
|
char buf[INET6_ADDRSTRLEN];
|
|
|
|
char buf2[ETHER_ADDR_STRLEN];
|
2018-02-13 10:48:48 +01:00
|
|
|
struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
|
2017-07-17 14:03:14 +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-17 14:03:14 +02:00
|
|
|
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ndmsg));
|
|
|
|
req.n.nlmsg_flags = NLM_F_REQUEST;
|
|
|
|
if (cmd == RTM_NEWNEIGH)
|
|
|
|
req.n.nlmsg_flags |= (NLM_F_CREATE | NLM_F_REPLACE);
|
|
|
|
req.n.nlmsg_type = cmd; // RTM_NEWNEIGH or RTM_DELNEIGH
|
|
|
|
req.ndm.ndm_family = IS_IPADDR_V4(ip) ? AF_INET : AF_INET6;
|
|
|
|
req.ndm.ndm_state = flags;
|
|
|
|
req.ndm.ndm_ifindex = ifp->ifindex;
|
|
|
|
req.ndm.ndm_type = RTN_UNICAST;
|
|
|
|
req.ndm.ndm_flags = NTF_EXT_LEARNED;
|
|
|
|
|
|
|
|
|
|
|
|
ipa_len = IS_IPADDR_V4(ip) ? IPV4_MAX_BYTELEN : IPV6_MAX_BYTELEN;
|
|
|
|
addattr_l(&req.n, sizeof(req), NDA_DST, &ip->ip.addr, ipa_len);
|
|
|
|
if (mac)
|
|
|
|
addattr_l(&req.n, sizeof(req), NDA_LLADDR, mac, 6);
|
|
|
|
|
|
|
|
if (IS_ZEBRA_DEBUG_KERNEL)
|
|
|
|
zlog_debug("Tx %s family %s IF %s(%u) Neigh %s MAC %s",
|
|
|
|
nl_msg_type_to_str(cmd),
|
|
|
|
nl_family_to_str(req.ndm.ndm_family), ifp->name,
|
|
|
|
ifp->ifindex, ipaddr2str(ip, buf, sizeof(buf)),
|
|
|
|
mac ? prefix_mac2str(mac, buf2, sizeof(buf2))
|
|
|
|
: "null");
|
|
|
|
|
|
|
|
return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
|
|
|
|
0);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
int kernel_add_mac(struct interface *ifp, vlanid_t vid, struct ethaddr *mac,
|
2018-03-27 21:13:34 +02:00
|
|
|
struct in_addr vtep_ip, uint8_t sticky)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return netlink_macfdb_update(ifp, vid, mac, vtep_ip, 0, RTM_NEWNEIGH,
|
|
|
|
sticky);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
int kernel_del_mac(struct interface *ifp, vlanid_t vid, struct ethaddr *mac,
|
|
|
|
struct in_addr vtep_ip, int local)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return netlink_macfdb_update(ifp, vid, mac, vtep_ip, local,
|
|
|
|
RTM_DELNEIGH, 0);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
int kernel_add_neigh(struct interface *ifp, struct ipaddr *ip,
|
|
|
|
struct ethaddr *mac)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
2018-02-26 23:10:50 +01:00
|
|
|
return netlink_neigh_update2(ifp, ip, mac, NUD_NOARP, RTM_NEWNEIGH);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
int kernel_del_neigh(struct interface *ifp, struct ipaddr *ip)
|
2017-05-15 07:44:13 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return netlink_neigh_update2(ifp, ip, NULL, 0, RTM_DELNEIGH);
|
2017-05-15 07:44:13 +02:00
|
|
|
}
|
|
|
|
|
2016-04-16 04:19:37 +02:00
|
|
|
/*
|
|
|
|
* MPLS label forwarding table change via netlink interface.
|
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
int netlink_mpls_multipath(int cmd, zebra_lsp_t *lsp)
|
2016-04-16 04:19:37 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
mpls_lse_t lse;
|
|
|
|
zebra_nhlfe_t *nhlfe;
|
|
|
|
struct nexthop *nexthop = NULL;
|
|
|
|
unsigned int nexthop_num;
|
|
|
|
const char *routedesc;
|
|
|
|
struct zebra_ns *zns = zebra_ns_lookup(NS_DEFAULT);
|
2017-09-16 02:25:32 +02:00
|
|
|
int route_type;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
struct {
|
|
|
|
struct nlmsghdr n;
|
|
|
|
struct rtmsg r;
|
|
|
|
char buf[NL_PKT_BUF_SIZE];
|
|
|
|
} req;
|
|
|
|
|
|
|
|
memset(&req, 0, sizeof req - NL_PKT_BUF_SIZE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Count # nexthops so we can decide whether to use singlepath
|
|
|
|
* or multipath case.
|
|
|
|
*/
|
|
|
|
nexthop_num = 0;
|
|
|
|
for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe->next) {
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-16 18:07:15 +02:00
|
|
|
if ((nexthop_num == 0) || (!lsp->best_nhlfe && (cmd != RTM_DELROUTE)))
|
2017-07-17 14:03:14 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
|
|
|
|
req.n.nlmsg_flags = NLM_F_CREATE | NLM_F_REQUEST;
|
|
|
|
req.n.nlmsg_type = cmd;
|
|
|
|
req.n.nlmsg_pid = zns->netlink_cmd.snl.nl_pid;
|
|
|
|
|
|
|
|
req.r.rtm_family = AF_MPLS;
|
|
|
|
req.r.rtm_table = RT_TABLE_MAIN;
|
|
|
|
req.r.rtm_dst_len = MPLS_LABEL_LEN_BITS;
|
|
|
|
req.r.rtm_scope = RT_SCOPE_UNIVERSE;
|
|
|
|
req.r.rtm_type = RTN_UNICAST;
|
|
|
|
|
2017-10-16 18:07:15 +02:00
|
|
|
if (cmd == RTM_NEWROUTE) {
|
2017-07-17 14:03:14 +02:00
|
|
|
/* We do a replace to handle update. */
|
|
|
|
req.n.nlmsg_flags |= NLM_F_REPLACE;
|
|
|
|
|
2017-10-16 18:07:15 +02:00
|
|
|
/* set the protocol value if installing */
|
|
|
|
route_type = re_type_from_lsp_type(lsp->best_nhlfe->type);
|
|
|
|
req.r.rtm_protocol = zebra2proto(route_type);
|
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/* Fill destination */
|
|
|
|
lse = mpls_lse_encode(lsp->ile.in_label, 0, 0, 1);
|
|
|
|
addattr_l(&req.n, sizeof req, RTA_DST, &lse, sizeof(mpls_lse_t));
|
|
|
|
|
|
|
|
/* Fill nexthops (paths) based on single-path or multipath. The paths
|
|
|
|
* chosen depend on the operation.
|
|
|
|
*/
|
|
|
|
if (nexthop_num == 1 || multipath_num == 1) {
|
2017-09-20 18:59:30 +02:00
|
|
|
routedesc = "single-path";
|
2017-07-17 14:03:14 +02:00
|
|
|
_netlink_mpls_debug(cmd, lsp->ile.in_label, routedesc);
|
|
|
|
|
|
|
|
nexthop_num = 0;
|
|
|
|
for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe->next) {
|
|
|
|
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 */
|
|
|
|
_netlink_mpls_build_singlepath(routedesc, nhlfe,
|
|
|
|
&req.n, &req.r,
|
|
|
|
sizeof req, cmd);
|
|
|
|
nexthop_num++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else /* Multipath case */
|
|
|
|
{
|
|
|
|
char buf[NL_PKT_BUF_SIZE];
|
|
|
|
struct rtattr *rta = (void *)buf;
|
|
|
|
struct rtnexthop *rtnh;
|
|
|
|
union g_addr *src1 = NULL;
|
|
|
|
|
|
|
|
rta->rta_type = RTA_MULTIPATH;
|
|
|
|
rta->rta_len = RTA_LENGTH(0);
|
|
|
|
rtnh = RTA_DATA(rta);
|
|
|
|
|
2017-09-20 18:59:30 +02:00
|
|
|
routedesc = "multipath";
|
2017-07-17 14:03:14 +02:00
|
|
|
_netlink_mpls_debug(cmd, lsp->ile.in_label, routedesc);
|
|
|
|
|
|
|
|
nexthop_num = 0;
|
|
|
|
for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe->next) {
|
|
|
|
nexthop = nhlfe->nexthop;
|
|
|
|
if (!nexthop)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (nexthop_num >= multipath_num)
|
|
|
|
break;
|
|
|
|
|
|
|
|
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 */
|
|
|
|
_netlink_mpls_build_multipath(routedesc, nhlfe,
|
|
|
|
rta, rtnh, &req.r,
|
|
|
|
&src1);
|
|
|
|
rtnh = RTNH_NEXT(rtnh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the multipath */
|
|
|
|
if (rta->rta_len > RTA_LENGTH(0))
|
|
|
|
addattr_l(&req.n, NL_PKT_BUF_SIZE, RTA_MULTIPATH,
|
|
|
|
RTA_DATA(rta), RTA_PAYLOAD(rta));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Talk to netlink socket. */
|
|
|
|
return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
|
|
|
|
0);
|
2016-04-16 04:19:37 +02:00
|
|
|
}
|
2017-07-26 19:49:15 +02:00
|
|
|
#endif /* HAVE_NETLINK */
|