forked from Mirror/frr
zebra: check at startup if the kernel supports MPLS
Replace all HAVE_MPLS #ifdef's by a run-time check if MPLS is supported by the kernel or not. This way we don't need to create multiple packages for each OS distribution. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
parent
a4b46f4c16
commit
fe6c7157bf
37
configure.ac
37
configure.ac
|
@ -309,8 +309,6 @@ AC_ARG_ENABLE(systemd,
|
|||
AS_HELP_STRING([--enable-systemd], [enable Systemd support]))
|
||||
AC_ARG_ENABLE(poll,
|
||||
AS_HELP_STRING([--enable-poll], [enable usage of Poll instead of select]))
|
||||
AC_ARG_ENABLE(mpls,
|
||||
AS_HELP_STRING([--enable-mpls], [enable MPLS support - requires compatible kernel]))
|
||||
AC_ARG_ENABLE(werror,
|
||||
AS_HELP_STRING([--enable-werror], [enable -Werror (recommended for developers only)]))
|
||||
AC_ARG_ENABLE(cumulus,
|
||||
|
@ -367,27 +365,20 @@ dnl MPLS check
|
|||
dnl ----------
|
||||
MPLS_METHOD=""
|
||||
AC_MSG_CHECKING(whether this OS has MPLS stack)
|
||||
if test "x${enable_mpls}" = "xyes"; then
|
||||
case "$host" in
|
||||
*-linux*)
|
||||
AC_DEFINE(HAVE_MPLS,,Enable MPLS)
|
||||
MPLS_METHOD="zebra_mpls_netlink.o"
|
||||
AC_MSG_RESULT(Linux MPLS)
|
||||
;;
|
||||
*-openbsd*)
|
||||
AC_DEFINE(HAVE_MPLS,,Enable MPLS)
|
||||
MPLS_METHOD="zebra_mpls_openbsd.o"
|
||||
AC_MSG_RESULT(OpenBSD MPLS)
|
||||
;;
|
||||
*)
|
||||
AC_MSG_RESULT(Unsupported kernel)
|
||||
MPLS_METHOD="zebra_mpls_null.o"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
AC_MSG_RESULT(disabled)
|
||||
MPLS_METHOD="zebra_mpls_null.o"
|
||||
fi
|
||||
case "$host" in
|
||||
*-linux*)
|
||||
MPLS_METHOD="zebra_mpls_netlink.o"
|
||||
AC_MSG_RESULT(Linux MPLS)
|
||||
;;
|
||||
*-openbsd*)
|
||||
MPLS_METHOD="zebra_mpls_openbsd.o"
|
||||
AC_MSG_RESULT(OpenBSD MPLS)
|
||||
;;
|
||||
*)
|
||||
MPLS_METHOD="zebra_mpls_null.o"
|
||||
AC_MSG_RESULT(Unsupported kernel)
|
||||
;;
|
||||
esac
|
||||
AC_SUBST(MPLS_METHOD)
|
||||
|
||||
if test "${enable_cumulus}" = "yes" ; then
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include "privs.h"
|
||||
#include "if.h"
|
||||
#if defined HAVE_MPLS && defined __OpenBSD__
|
||||
#ifdef __OpenBSD__
|
||||
#include <netmpls/mpls.h>
|
||||
#endif
|
||||
|
||||
|
@ -34,7 +34,7 @@ union sockunion
|
|||
struct sockaddr sa;
|
||||
struct sockaddr_in sin;
|
||||
struct sockaddr_in6 sin6;
|
||||
#if defined HAVE_MPLS && defined __OpenBSD__
|
||||
#ifdef __OpenBSD__
|
||||
struct sockaddr_mpls smpls;
|
||||
#endif
|
||||
};
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
#include <zebra.h>
|
||||
#include <net/if_types.h>
|
||||
#if defined HAVE_MPLS && defined __OpenBSD__
|
||||
#ifdef __OpenBSD__
|
||||
#include <netmpls/mpls.h>
|
||||
#endif
|
||||
|
||||
|
@ -1101,7 +1101,7 @@ rtm_write (int message,
|
|||
msg.rtm.rtm_addrs = RTA_DST;
|
||||
msg.rtm.rtm_addrs |= RTA_GATEWAY;
|
||||
msg.rtm.rtm_flags = RTF_UP;
|
||||
#if defined HAVE_MPLS && defined __OpenBSD__
|
||||
#ifdef __OpenBSD__
|
||||
msg.rtm.rtm_flags |= RTF_MPATH;
|
||||
msg.rtm.rtm_fmask = RTF_MPLS;
|
||||
#endif
|
||||
|
@ -1150,7 +1150,7 @@ rtm_write (int message,
|
|||
else if (message == RTM_ADD)
|
||||
msg.rtm.rtm_flags |= RTF_HOST;
|
||||
|
||||
#if defined HAVE_MPLS && defined __OpenBSD__
|
||||
#ifdef __OpenBSD__
|
||||
if (mpls)
|
||||
{
|
||||
msg.rtm.rtm_addrs |= RTA_SRC;
|
||||
|
@ -1185,7 +1185,7 @@ rtm_write (int message,
|
|||
SOCKADDRSET (dest, RTA_DST);
|
||||
SOCKADDRSET (gate, RTA_GATEWAY);
|
||||
SOCKADDRSET (mask, RTA_NETMASK);
|
||||
#if defined HAVE_MPLS && defined __OpenBSD__
|
||||
#ifdef __OpenBSD__
|
||||
SOCKADDRSET (mpls, RTA_SRC);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -350,9 +350,6 @@ main (int argc, char **argv)
|
|||
zebra_debug_init ();
|
||||
router_id_cmd_init ();
|
||||
zebra_vty_init ();
|
||||
#if defined(HAVE_MPLS)
|
||||
zebra_mpls_vty_init ();
|
||||
#endif
|
||||
access_list_init ();
|
||||
prefix_list_init ();
|
||||
#if defined (HAVE_RTADV)
|
||||
|
@ -367,6 +364,7 @@ main (int argc, char **argv)
|
|||
#endif
|
||||
|
||||
zebra_mpls_init ();
|
||||
zebra_mpls_vty_init ();
|
||||
|
||||
/* For debug purpose. */
|
||||
/* SET_FLAG (zebra_debug_event, ZEBRA_DEBUG_EVENT); */
|
||||
|
|
|
@ -44,6 +44,6 @@ extern int kernel_delete_ipv6 (struct prefix *, struct rib *);
|
|||
extern int kernel_add_lsp (zebra_lsp_t *);
|
||||
extern int kernel_upd_lsp (zebra_lsp_t *);
|
||||
extern int kernel_del_lsp (zebra_lsp_t *);
|
||||
extern void mpls_kernel_init (void);
|
||||
extern int mpls_kernel_init (void);
|
||||
|
||||
#endif /* _ZEBRA_RT_H */
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*/
|
||||
|
||||
#include <zebra.h>
|
||||
#if defined HAVE_MPLS && defined __OpenBSD__
|
||||
#ifdef __OpenBSD__
|
||||
#include <netmpls/mpls.h>
|
||||
#endif
|
||||
|
||||
|
@ -78,7 +78,7 @@ kernel_rtm_ipv4 (int cmd, struct prefix *p, struct rib *rib, int family)
|
|||
{
|
||||
struct sockaddr_in *mask = NULL;
|
||||
struct sockaddr_in sin_dest, sin_mask, sin_gate;
|
||||
#if defined HAVE_MPLS && defined __OpenBSD__
|
||||
#ifdef __OpenBSD__
|
||||
struct sockaddr_mpls smpls;
|
||||
#endif
|
||||
union sockunion *smplsp = NULL;
|
||||
|
@ -156,7 +156,7 @@ kernel_rtm_ipv4 (int cmd, struct prefix *p, struct rib *rib, int family)
|
|||
mask = &sin_mask;
|
||||
}
|
||||
|
||||
#if defined HAVE_MPLS && defined __OpenBSD__
|
||||
#ifdef __OpenBSD__
|
||||
if (nexthop->nh_label)
|
||||
{
|
||||
memset (&smpls, 0, sizeof (smpls));
|
||||
|
|
|
@ -53,6 +53,8 @@ DEFINE_MTYPE_STATIC(ZEBRA, NHLFE, "MPLS nexthop object")
|
|||
DEFINE_MTYPE_STATIC(ZEBRA, SNHLFE, "MPLS static nexthop object")
|
||||
DEFINE_MTYPE_STATIC(ZEBRA, SNHLFE_IFNAME, "MPLS static nexthop ifname")
|
||||
|
||||
int mpls_enabled;
|
||||
|
||||
/* Default rtm_table for all clients */
|
||||
extern struct zebra_t zebrad;
|
||||
|
||||
|
@ -1902,6 +1904,12 @@ zebra_mpls_init_tables (struct zebra_vrf *zvrf)
|
|||
void
|
||||
zebra_mpls_init (void)
|
||||
{
|
||||
mpls_kernel_init ();
|
||||
if (mpls_kernel_init () < 0)
|
||||
{
|
||||
zlog_warn ("Disabling MPLS support (no kernel support)");
|
||||
return;
|
||||
}
|
||||
|
||||
mpls_enabled = 1;
|
||||
mpls_processq_init (&zebrad);
|
||||
}
|
||||
|
|
|
@ -292,6 +292,12 @@ zebra_mpls_init_tables (struct zebra_vrf *zvrf);
|
|||
void
|
||||
zebra_mpls_init (void);
|
||||
|
||||
/*
|
||||
* MPLS VTY.
|
||||
*/
|
||||
void
|
||||
zebra_mpls_vty_init (void);
|
||||
|
||||
/* Inline functions. */
|
||||
|
||||
/*
|
||||
|
@ -364,4 +370,7 @@ mpls_should_lsps_be_processed(struct zebra_vrf *zvrf)
|
|||
return ((zvrf->mpls_flags & MPLS_FLAG_SCHEDULE_LSPS) ? 1 : 0);
|
||||
}
|
||||
|
||||
/* Global variables. */
|
||||
extern int mpls_enabled;
|
||||
|
||||
#endif /*_ZEBRA_MPLS_H */
|
||||
|
|
|
@ -77,4 +77,16 @@ kernel_del_lsp (zebra_lsp_t *lsp)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void mpls_kernel_init (void) {};
|
||||
int
|
||||
mpls_kernel_init (void)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
/*
|
||||
* Check if the MPLS module is loaded in the kernel.
|
||||
*/
|
||||
if (stat ("/proc/sys/net/mpls", &st) != 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
|
|
@ -5,4 +5,4 @@
|
|||
int kernel_add_lsp (zebra_lsp_t *lsp) { return 0; }
|
||||
int kernel_upd_lsp (zebra_lsp_t *lsp) { return 0; }
|
||||
int kernel_del_lsp (zebra_lsp_t *lsp) { return 0; }
|
||||
void mpls_kernel_init (void) {};
|
||||
int mpls_kernel_init (void) { return -1; };
|
||||
|
|
|
@ -178,15 +178,15 @@ kernel_del_lsp (zebra_lsp_t *lsp)
|
|||
}
|
||||
|
||||
#define MAX_RTSOCK_BUF 128 * 1024
|
||||
void
|
||||
int
|
||||
mpls_kernel_init (void)
|
||||
{
|
||||
int rcvbuf, default_rcvbuf;
|
||||
socklen_t optlen;
|
||||
|
||||
if ((kr_state.fd = socket(AF_ROUTE, SOCK_RAW, 0)) == -1) {
|
||||
zlog_warn("kr_init: socket");
|
||||
return;
|
||||
zlog_warn("%s: socket", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* grow receive buffer, don't wanna miss messages */
|
||||
|
@ -203,4 +203,6 @@ mpls_kernel_init (void)
|
|||
; /* nothing */
|
||||
|
||||
kr_state.rtseq = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
|
||||
#include <zebra.h>
|
||||
|
||||
#if defined(HAVE_MPLS)
|
||||
|
||||
#include "memory.h"
|
||||
#include "if.h"
|
||||
#include "prefix.h"
|
||||
|
@ -810,6 +808,18 @@ DEFUN (show_mpls_table_lsp,
|
|||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN (show_mpls_status,
|
||||
show_mpls_status_cmd,
|
||||
"show mpls status",
|
||||
SHOW_STR
|
||||
"MPLS information\n"
|
||||
"MPLS status\n")
|
||||
{
|
||||
vty_out (vty, "MPLS support enabled: %s%s", (mpls_enabled) ? "yes" :
|
||||
"no (mpls kernel extensions not detected)", VTY_NEWLINE);
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
/* MPLS node for MPLS LSP. */
|
||||
static struct cmd_node mpls_node = { MPLS_NODE, "", 1 };
|
||||
|
||||
|
@ -817,6 +827,12 @@ static struct cmd_node mpls_node = { MPLS_NODE, "", 1 };
|
|||
void
|
||||
zebra_mpls_vty_init (void)
|
||||
{
|
||||
install_element (VIEW_NODE, &show_mpls_status_cmd);
|
||||
install_element (ENABLE_NODE, &show_mpls_status_cmd);
|
||||
|
||||
if (! mpls_enabled)
|
||||
return;
|
||||
|
||||
install_node (&mpls_node, zebra_mpls_config);
|
||||
|
||||
install_element (CONFIG_NODE, &ip_route_label_cmd);
|
||||
|
@ -863,5 +879,3 @@ zebra_mpls_vty_init (void)
|
|||
install_element (VIEW_NODE, &show_mpls_table_lsp_cmd);
|
||||
install_element (ENABLE_NODE, &show_mpls_table_lsp_cmd);
|
||||
}
|
||||
|
||||
#endif /* HAVE_MPLS */
|
||||
|
|
|
@ -1676,6 +1676,9 @@ zread_mpls_labels (int command, struct zserv *client, u_short length,
|
|||
in_label = stream_getl (s);
|
||||
out_label = stream_getl (s);
|
||||
|
||||
if (! mpls_enabled)
|
||||
return;
|
||||
|
||||
if (command == ZEBRA_MPLS_LABELS_ADD)
|
||||
{
|
||||
mpls_lsp_install (zvrf, type, in_label, out_label, gtype, &gate,
|
||||
|
|
|
@ -149,9 +149,6 @@ extern void kernel_terminate (struct zebra_ns *);
|
|||
extern void zebra_route_map_init (void);
|
||||
extern void zebra_snmp_init (void);
|
||||
extern void zebra_vty_init (void);
|
||||
#if defined(HAVE_MPLS)
|
||||
extern void zebra_mpls_vty_init (void);
|
||||
#endif
|
||||
|
||||
extern int zsend_vrf_add (struct zserv *, struct zebra_vrf *);
|
||||
extern int zsend_vrf_delete (struct zserv *, struct zebra_vrf *);
|
||||
|
|
Loading…
Reference in a new issue