Permalink
Browse files

Fix building on Centos 7/RHEL 7 re lightweight tunnel encapsulation

RedHat have partially backported lightweight tunnel encapsulation
into their kernel, but not included MPLS or ILA. We need to have
conditional compilation for LWTUNNEL_ENCAP_MPLS and LWTUNNEL_ENCAP_ILA
rather than just checking for RTA_ENCAP.

Signed-off-by: Quentin Armitage <quentin@armitage.org.uk>
1 parent 4923844 commit c134bf4f13bb57e5b5c77a608ef5699d4eb34582 @pqarmitage pqarmitage committed Dec 14, 2016
View
@@ -7093,6 +7093,38 @@ for flag in RTA_ENCAP RTA_EXPIRES RTA_NEWDST RTA_PREF RTA_VIA FRA_OIFNAME FRA_SU
fi
done
+ac_fn_c_check_decl "$LINENO" "LWTUNNEL_ENCAP_MPLS" "ac_cv_have_decl_LWTUNNEL_ENCAP_MPLS" "#include <linux/lwtunnel.h>
+"
+if test "x$ac_cv_have_decl_LWTUNNEL_ENCAP_MPLS" = xyes; then :
+ ac_have_decl=1
+else
+ ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_LWTUNNEL_ENCAP_MPLS $ac_have_decl
+_ACEOF
+ac_fn_c_check_decl "$LINENO" "LWTUNNEL_ENCAP_ILA" "ac_cv_have_decl_LWTUNNEL_ENCAP_ILA" "#include <linux/lwtunnel.h>
+"
+if test "x$ac_cv_have_decl_LWTUNNEL_ENCAP_ILA" = xyes; then :
+ ac_have_decl=1
+else
+ ac_have_decl=0
+fi
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_DECL_LWTUNNEL_ENCAP_ILA $ac_have_decl
+_ACEOF
+
+if test ${ac_cv_have_decl_RTA_ENCAP}; then
+ for flag in LWTUNNEL_ENCAP_MPLS LWTUNNEL_ENCAP_ILA; do
+ eval decl_var=\$ac_cv_have_decl_$flag
+ if test ${decl_var} = yes; then
+ BUILD_OPTIONS="$BUILD_OPTIONS "${flag}
+ fi
+ done
+fi
+
if test $NETLINK_VER -eq 3; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for net/if.h and libnl3/netlink/route/link.h namespace collision" >&5
$as_echo_n "checking for net/if.h and libnl3/netlink/route/link.h namespace collision... " >&6; }
View
@@ -428,6 +428,18 @@ for flag in RTA_ENCAP RTA_EXPIRES RTA_NEWDST RTA_PREF RTA_VIA FRA_OIFNAME FRA_SU
fi
done
+dnl -- RedHat backported ENCAP_IP and ENCAP_IP6 without MPLS and ILA
+AC_CHECK_DECLS([LWTUNNEL_ENCAP_MPLS, LWTUNNEL_ENCAP_ILA], [], [],
+ [[#include <linux/lwtunnel.h>]])
+if test ${ac_cv_have_decl_RTA_ENCAP}; then
+ for flag in LWTUNNEL_ENCAP_MPLS LWTUNNEL_ENCAP_ILA; do
+ AS_VAR_COPY([decl_var], [ac_cv_have_decl_$flag])
+ if test ${decl_var} = yes; then
+ add_build_opt[${flag}]
+ fi
+ done
+fi
+
dnl ----[Check if have net/if.h and netlink/route/link.h namespace collision]----
dnl -- Resolved in libnl3-3.2.26 (release 30/3/2015)
if test $NETLINK_VER -eq 3; then
@@ -26,7 +26,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <linux/rtnetlink.h>
-#if HAVE_DECL_RTA_ENCAP
+#if HAVE_DECL_LWTUNNEL_ENCAP_MPLS
#include "vrrp_iproute.h"
#endif
@@ -37,7 +37,7 @@ extern bool get_u16(uint16_t *, const char *, uint16_t, const char*);
extern bool get_u64(uint64_t *, const char *, uint64_t, const char*);
extern bool get_time_rtt(uint32_t *, const char *, bool *);
extern bool get_addr64(uint64_t *, const char *);
-#if HAVE_DECL_RTA_ENCAP
+#if HAVE_DECL_LWTUNNEL_ENCAP_MPLS
extern bool parse_mpls_address(const char *, encap_mpls_t *);
#endif
@@ -28,7 +28,7 @@
#include <stdlib.h>
#include <arpa/inet.h>
//#include <linux/rtnetlink.h>
-#if HAVE_DECL_RTA_ENCAP
+#if HAVE_DECL_LWTUNNEL_ENCAP_MPLS
#include <linux/mpls.h>
#endif
#include <stdbool.h>
@@ -57,13 +57,15 @@ enum iproute_encap {
#define IPROUTE_BIT_ENCAP_TTL (1<<IPROUTE_ENCAP_TTL)
#define IPROUTE_BIT_ENCAP_FLAGS (1<<IPROUTE_ENCAP_FLAGS)
+#if HAVE_DECL_LWTUNNEL_ENCAP_MPLS
#define MAX_MPLS_LABELS 2
typedef struct mpls_label mpls_labels[MAX_MPLS_LABELS];
typedef struct _encap_mpls {
mpls_labels addr;
size_t num_labels;
} encap_mpls_t;
+#endif
typedef struct _encap_ip {
uint64_t id;
@@ -74,9 +76,11 @@ typedef struct _encap_ip {
uint8_t ttl;
} encap_ip_t;
+#if HAVE_DECL_LWTUNNEL_ENCAP_ILA
typedef struct _encap_ila {
uint64_t locator;
} encap_ila_t;
+#endif
typedef struct _encap_ip6 {
uint64_t id;
@@ -91,9 +95,13 @@ typedef struct _encap {
uint16_t type;
uint32_t flags;
union {
+#if HAVE_DECL_LWTUNNEL_ENCAP_MPLS
encap_mpls_t mpls;
+#endif
encap_ip_t ip;
+#if HAVE_DECL_LWTUNNEL_ENCAP_ILA
encap_ila_t ila;
+#endif
encap_ip6_t ip6;
};
} encap_t;
@@ -254,7 +254,7 @@ get_addr64(uint64_t *ap, const char *cp)
return false;
}
-#if HAVE_DECL_RTA_ENCAP
+#if HAVE_DECL_LWTUNNEL_ENCAP_MPLS
bool
parse_mpls_address(const char *str, encap_mpls_t *mpls)
{
@@ -39,9 +39,13 @@
#include <linux/rtnetlink.h>
#if HAVE_DECL_RTA_ENCAP
#include <linux/lwtunnel.h>
+#if HAVE_DECL_LWTUNNEL_ENCAP_MPLS
#include <linux/mpls_iptunnel.h>
+#endif
+#if HAVE_DECL_LWTUNNEL_ENCAP_ILA
#include <linux/ila.h>
#endif
+#endif
/* Buffer sizes for netlink messages. Increase if needed. */
#define RTM_SIZE 1024
@@ -144,11 +148,13 @@ add_addrfam2rta(struct rtattr *rta, size_t maxlen, unsigned short type, ip_addre
#endif
#if HAVE_DECL_RTA_ENCAP
+#if HAVE_DECL_LWTUNNEL_ENCAP_MPLS
static void
add_encap_mpls(struct rtattr *rta, size_t len, const encap_t *encap)
{
rta_addattr_l(rta, len, MPLS_IPTUNNEL_DST, &encap->mpls.addr, encap->mpls.num_labels * sizeof(encap->mpls.addr[0]));
}
+#endif
static void
add_encap_ip(struct rtattr *rta, size_t len, const encap_t *encap)
@@ -167,11 +173,13 @@ add_encap_ip(struct rtattr *rta, size_t len, const encap_t *encap)
rta_addattr16(rta, len, LWTUNNEL_IP_FLAGS, encap->ip.flags);
}
+#if HAVE_DECL_LWTUNNEL_ENCAP_ILA
static void
add_encap_ila(struct rtattr *rta, size_t len, const encap_t *encap)
{
rta_addattr64(rta, len, ILA_ATTR_LOCATOR, encap->ila.locator);
}
+#endif
static void
add_encap_ip6(struct rtattr *rta, size_t len, const encap_t *encap)
@@ -197,15 +205,19 @@ add_encap(struct rtattr *rta, size_t len, encap_t *encap)
nest = rta_nest(rta, len, RTA_ENCAP);
switch (encap->type) {
+#if HAVE_DECL_LWTUNNEL_ENCAP_MPLS
case LWTUNNEL_ENCAP_MPLS:
add_encap_mpls(rta, len, encap);
break;
+#endif
case LWTUNNEL_ENCAP_IP:
add_encap_ip(rta, len, encap);
break;
+#if HAVE_DECL_LWTUNNEL_ENCAP_ILA
case LWTUNNEL_ENCAP_ILA:
add_encap_ila(rta, len, encap);
break;
+#endif
case LWTUNNEL_ENCAP_IP6:
add_encap_ip6(rta, len, encap);
break;
@@ -563,6 +575,7 @@ free_iproute(void *rt_data)
}
#if HAVE_DECL_RTA_ENCAP
+#if HAVE_DECL_LWTUNNEL_ENCAP_MPLS
static size_t
print_encap_mpls(char *op, size_t len, const encap_t* encap)
{
@@ -576,6 +589,7 @@ print_encap_mpls(char *op, size_t len, const encap_t* encap)
return (size_t)(op - buf);
}
+#endif
static size_t
print_encap_ip(char *op, size_t len, const encap_t* encap)
@@ -601,11 +615,13 @@ print_encap_ip(char *op, size_t len, const encap_t* encap)
return (size_t)(op - buf);
}
+#if HAVE_DECL_LWTUNNEL_ENCAP_ILA
static size_t
print_encap_ila(char *op, size_t len, const encap_t* encap)
{
return (size_t)snprintf(op, len, " encap ila %" PRIu64, encap->ila.locator);
}
+#endif
static size_t
print_encap_ip6(char *op, size_t len, const encap_t* encap)
@@ -635,12 +651,16 @@ static size_t
print_encap(char *op, size_t len, const encap_t* encap)
{
switch (encap->type) {
+#if HAVE_DECL_LWTUNNEL_ENCAP_MPLS
case LWTUNNEL_ENCAP_MPLS:
return print_encap_mpls(op, len, encap);
+#endif
case LWTUNNEL_ENCAP_IP:
return print_encap_ip(op, len, encap);
+#if HAVE_DECL_LWTUNNEL_ENCAP_ILA
case LWTUNNEL_ENCAP_ILA:
return print_encap_ila(op, len, encap);
+#endif
case LWTUNNEL_ENCAP_IP6:
return print_encap_ip6(op, len, encap);
}
@@ -867,6 +887,7 @@ dump_iproute(void *rt_data)
}
#if HAVE_DECL_RTA_ENCAP
+#if HAVE_DECL_LWTUNNEL_ENCAP_MPLS
static int parse_encap_mpls(vector_t *strvec, unsigned int *i_ptr, encap_t *encap)
{
char *str;
@@ -886,6 +907,7 @@ static int parse_encap_mpls(vector_t *strvec, unsigned int *i_ptr, encap_t *enca
return false;
}
+#endif
static int parse_encap_ip(vector_t *strvec, unsigned int *i_ptr, encap_t *encap)
{
@@ -963,6 +985,7 @@ static int parse_encap_ip(vector_t *strvec, unsigned int *i_ptr, encap_t *encap)
return true;
}
+#if HAVE_DECL_LWTUNNEL_ENCAP_ILA
static
int parse_encap_ila(vector_t *strvec, unsigned int *i_ptr, encap_t *encap)
{
@@ -984,6 +1007,7 @@ int parse_encap_ila(vector_t *strvec, unsigned int *i_ptr, encap_t *encap)
return false;
}
+#endif
static
int parse_encap_ip6(vector_t *strvec, unsigned int *i_ptr, encap_t *encap)
@@ -1072,14 +1096,18 @@ parse_encap(vector_t *strvec, unsigned int *i, encap_t *encap)
str = strvec_slot(strvec, (*i)++);
- if (!strcmp(str, "mpls"))
- parse_encap_mpls(strvec, i, encap);
- else if (!strcmp(str, "ip"))
+ if (!strcmp(str, "ip"))
parse_encap_ip(strvec, i, encap);
else if (!strcmp(str, "ip6"))
parse_encap_ip6(strvec, i, encap);
+#if HAVE_DECL_LWTUNNEL_ENCAP_MPLS
+ else if (!strcmp(str, "mpls"))
+ parse_encap_mpls(strvec, i, encap);
+#endif
+#if HAVE_DECL_LWTUNNEL_ENCAP_ILA
else if (!strcmp(str, "ila"))
parse_encap_ila(strvec, i, encap);
+#endif
else {
log_message(LOG_INFO, "Unknown encap type - %s", str);
return false;
Oops, something went wrong.

0 comments on commit c134bf4

Please sign in to comment.