diff options
| author | Donatas Abraitis <donatas@opensourcerouting.org> | 2022-10-31 22:23:51 +0200 | 
|---|---|---|
| committer | Donatas Abraitis <donatas@opensourcerouting.org> | 2022-11-07 21:23:53 +0200 | 
| commit | 061f5d1cb43938c30847e0ebb49e2b43be3aa4c2 (patch) | |
| tree | 5651724c843b645650c1a025c4223f6b29eeddfe | |
| parent | 54757dc1795c5fca93bed9a850be77baa36ff408 (diff) | |
lib: Add PCRE2 support
Some results:
```
====
PCRE
====
% ./a.out "^65001" "65001"
comparing: ^65001 / 65001
ret status: 0
[14:31] donatas-pc donatas /home/donatas
% ./a.out "^65001_" "65001"
comparing: ^65001_ / 65001
ret status: 0
=====
PCRE2
=====
% ./a.out "^65001" "65001"
comparing: ^65001 / 65001
ret status: 0
[14:30] donatas-pc donatas /home/donatas
% ./a.out "^65001_" "65001"
comparing: ^65001_ / 65001
ret status: 1
```
Seems that if using PCRE2, we need to escape outer `()` chars and `|`. Sounds
like a bug.
But this is only with some older PCRE2 versions. With >= 10.36, I wasn't able
to reproduce this, everything is fine and working as expected.
Adding _FRR_PCRE2_POSIX definition because pcre2posix.h does not have
include's guard.
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
| -rw-r--r-- | bgpd/bgp_regex.h | 15 | ||||
| -rw-r--r-- | bgpd/bgp_routemap.c | 9 | ||||
| -rw-r--r-- | configure.ac | 12 | ||||
| -rw-r--r-- | doc/user/installation.rst | 7 | ||||
| -rw-r--r-- | lib/frrstr.c | 9 | ||||
| -rw-r--r-- | lib/frrstr.h | 9 | ||||
| -rw-r--r-- | lib/vty.c | 9 | ||||
| -rw-r--r-- | lib/vty.h | 9 | 
8 files changed, 64 insertions, 15 deletions
diff --git a/bgpd/bgp_regex.h b/bgpd/bgp_regex.h index 43ebb9ac91..e07b7f911b 100644 --- a/bgpd/bgp_regex.h +++ b/bgpd/bgp_regex.h @@ -18,19 +18,24 @@   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA   */ -#ifndef _QUAGGA_BGP_REGEX_H -#define _QUAGGA_BGP_REGEX_H +#ifndef _FRR_BGP_REGEX_H +#define _FRR_BGP_REGEX_H  #include <zebra.h> -#ifdef HAVE_LIBPCREPOSIX +#ifdef HAVE_LIBPCRE2_POSIX +#ifndef _FRR_PCRE2_POSIX +#define _FRR_PCRE2_POSIX +#include <pcre2posix.h> +#endif /* _FRR_PCRE2_POSIX */ +#elif defined(HAVE_LIBPCREPOSIX)  #include <pcreposix.h>  #else  #include <regex.h> -#endif /* HAVE_LIBPCREPOSIX */ +#endif /* HAVE_LIBPCRE2_POSIX */  extern void bgp_regex_free(regex_t *regex);  extern regex_t *bgp_regcomp(const char *str);  extern int bgp_regexec(regex_t *regex, struct aspath *aspath); -#endif /* _QUAGGA_BGP_REGEX_H */ +#endif /* _FRR_BGP_REGEX_H */ diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index aff09206e4..b736e6c38a 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -30,11 +30,16 @@  #include "log.h"  #include "frrlua.h"  #include "frrscript.h" -#ifdef HAVE_LIBPCREPOSIX +#ifdef HAVE_LIBPCRE2_POSIX +#ifndef _FRR_PCRE2_POSIX +#define _FRR_PCRE2_POSIX +#include <pcre2posix.h> +#endif /* _FRR_PCRE2_POSIX */ +#elif defined(HAVE_LIBPCREPOSIX)  #include <pcreposix.h>  #else  #include <regex.h> -#endif /* HAVE_LIBPCREPOSIX */ +#endif /* HAVE_LIBPCRE2_POSIX */  #include "buffer.h"  #include "sockunion.h"  #include "hash.h" diff --git a/configure.ac b/configure.ac index 1a481ecd79..97c8ca451b 100644 --- a/configure.ac +++ b/configure.ac @@ -712,6 +712,8 @@ AC_ARG_ENABLE([cpu-time],    AS_HELP_STRING([--disable-cpu-time], [disable cpu usage data gathering]))  AC_ARG_ENABLE([pcreposix],    AS_HELP_STRING([--enable-pcreposix], [enable using PCRE Posix libs for regex functions])) +AC_ARG_ENABLE([pcre2posix], +  AS_HELP_STRING([--enable-pcre2posix], [enable using PCRE2 Posix libs for regex functions]))  AC_ARG_ENABLE([fpm],    AS_HELP_STRING([--enable-fpm], [enable Forwarding Plane Manager support]))  AC_ARG_ENABLE([werror], @@ -1659,6 +1661,16 @@ if test "$enable_pcreposix" = "yes"; then  fi  AC_SUBST([HAVE_LIBPCREPOSIX]) +dnl --------------------------- +dnl check system has PCRE2 regexp +dnl --------------------------- +if test "$enable_pcre2posix" = "yes"; then +  AC_CHECK_LIB([pcre2-posix], [regexec], [], [ +    AC_MSG_ERROR([--enable-pcre2posix given but unable to find libpcre2-posix]) +  ]) +fi +AC_SUBST([HAVE_LIBPCRE2_POSIX]) +  dnl ##########################################################################  dnl test "$enable_clippy_only" != "yes"  fi diff --git a/doc/user/installation.rst b/doc/user/installation.rst index ba35facf2a..8f89c6c4f8 100644 --- a/doc/user/installation.rst +++ b/doc/user/installation.rst @@ -368,6 +368,13 @@ options from the list below.     Turn on the usage of PCRE Posix libs for regex functionality. +.. option:: --enable-pcre2posix + +   Turn on the usage of PCRE2 Posix libs for regex functionality. + +   PCRE2 versions <= 10.31 work a bit differently. We suggest using at least +   >= 10.36. +  .. option:: --enable-rpath     Set hardcoded rpaths in the executable [default=yes]. diff --git a/lib/frrstr.c b/lib/frrstr.c index 1b98b224cc..d66c6f8c16 100644 --- a/lib/frrstr.c +++ b/lib/frrstr.c @@ -23,11 +23,16 @@  #include <string.h>  #include <ctype.h>  #include <sys/types.h> -#ifdef HAVE_LIBPCREPOSIX +#ifdef HAVE_LIBPCRE2_POSIX +#ifndef _FRR_PCRE2_POSIX +#define _FRR_PCRE2_POSIX +#include <pcre2posix.h> +#endif /* _FRR_PCRE2_POSIX */ +#elif defined(HAVE_LIBPCREPOSIX)  #include <pcreposix.h>  #else  #include <regex.h> -#endif /* HAVE_LIBPCREPOSIX */ +#endif /* HAVE_LIBPCRE2_POSIX */  #include "frrstr.h"  #include "memory.h" diff --git a/lib/frrstr.h b/lib/frrstr.h index d52d6a4482..f0066d0fc5 100644 --- a/lib/frrstr.h +++ b/lib/frrstr.h @@ -23,11 +23,16 @@  #include <sys/types.h>  #include <sys/types.h> -#ifdef HAVE_LIBPCREPOSIX +#ifdef HAVE_LIBPCRE2_POSIX +#ifndef _FRR_PCRE2_POSIX +#define _FRR_PCRE2_POSIX +#include <pcre2posix.h> +#endif /* _FRR_PCRE2_POSIX */ +#elif defined(HAVE_LIBPCREPOSIX)  #include <pcreposix.h>  #else  #include <regex.h> -#endif /* HAVE_LIBPCREPOSIX */ +#endif /* HAVE_LIBPCRE2_POSIX */  #include <stdbool.h>  #include "vector.h" @@ -24,11 +24,16 @@  #include <lib/version.h>  #include <sys/types.h>  #include <sys/types.h> -#ifdef HAVE_LIBPCREPOSIX +#ifdef HAVE_LIBPCRE2_POSIX +#ifndef _FRR_PCRE2_POSIX +#define _FRR_PCRE2_POSIX +#include <pcre2posix.h> +#endif /* _FRR_PCRE2_POSIX */ +#elif defined(HAVE_LIBPCREPOSIX)  #include <pcreposix.h>  #else  #include <regex.h> -#endif /* HAVE_LIBPCREPOSIX */ +#endif /* HAVE_LIBPCRE2_POSIX */  #include <stdio.h>  #include "linklist.h" @@ -22,11 +22,16 @@  #define _ZEBRA_VTY_H  #include <sys/types.h> -#ifdef HAVE_LIBPCREPOSIX +#ifdef HAVE_LIBPCRE2_POSIX +#ifndef _FRR_PCRE2_POSIX +#define _FRR_PCRE2_POSIX +#include <pcre2posix.h> +#endif /* _FRR_PCRE2_POSIX */ +#elif defined(HAVE_LIBPCREPOSIX)  #include <pcreposix.h>  #else  #include <regex.h> -#endif /* HAVE_LIBPCREPOSIX */ +#endif /* HAVE_LIBPCRE2_POSIX */  #include "thread.h"  #include "log.h"  | 
